Manta Interactive Ray Tracer Development Mailing List

Text archives Help


[Manta] r1869 - in trunk: . Core Core/Color Core/Containers Core/Exceptions Core/Geometry Core/Math Core/Persistent Core/Thread Core/Util Core/XUtils DynLT Engine Engine/Control Engine/Display Engine/Factory Engine/IdleModes Engine/ImageTraversers Engine/LoadBalancers Engine/PixelSamplers Engine/Renderers Engine/SampleGenerators Engine/Shadows Image Interface Model/AmbientLights Model/Backgrounds Model/Cameras Model/Groups Model/Instances Model/Materials Model/MiscObjects Model/Primitives Model/Readers Model/TexCoordMappers Model/Textures SCIRun StandAlone SwigInterface UserInterface scenes scenes/galileo tests


Chronological Thread 
  • From: sparker@sci.utah.edu
  • To: manta@sci.utah.edu
  • Subject: [Manta] r1869 - in trunk: . Core Core/Color Core/Containers Core/Exceptions Core/Geometry Core/Math Core/Persistent Core/Thread Core/Util Core/XUtils DynLT Engine Engine/Control Engine/Display Engine/Factory Engine/IdleModes Engine/ImageTraversers Engine/LoadBalancers Engine/PixelSamplers Engine/Renderers Engine/SampleGenerators Engine/Shadows Image Interface Model/AmbientLights Model/Backgrounds Model/Cameras Model/Groups Model/Instances Model/Materials Model/MiscObjects Model/Primitives Model/Readers Model/TexCoordMappers Model/Textures SCIRun StandAlone SwigInterface UserInterface scenes scenes/galileo tests
  • Date: Mon, 26 Nov 2007 21:57:56 -0700 (MST)

Author: sparker
Date: Mon Nov 26 21:56:50 2007
New Revision: 1869

Added:
   trunk/Core/Containers/
   trunk/Core/Containers/Array1.h
   trunk/Core/Containers/Array2.h
   trunk/Core/Containers/Array3.h
   trunk/Core/Containers/StringUtil.cc
   trunk/Core/Containers/StringUtil.h
   trunk/Core/Exceptions/ArrayIndexOutOfBounds.cc
   trunk/Core/Exceptions/ArrayIndexOutOfBounds.h
   trunk/Core/Exceptions/AssertionFailed.cc
   trunk/Core/Exceptions/AssertionFailed.h
   trunk/Core/Exceptions/ErrnoException.cc
   trunk/Core/Exceptions/ErrnoException.h
   trunk/Core/Exceptions/Exception.cc
   trunk/Core/Exceptions/Exception.h
   trunk/Core/Exceptions/FileNotFound.cc
   trunk/Core/Exceptions/FileNotFound.h
   trunk/Core/Exceptions/IllegalValue.h
   trunk/Core/Exceptions/InternalError.cc
   trunk/Core/Exceptions/InternalError.h
   trunk/Core/Exceptions/InvalidState.cc
   trunk/Core/Exceptions/InvalidState.h
   trunk/Core/Exceptions/StackWalker.cc
   trunk/Core/Exceptions/StackWalker.h
   trunk/Core/Exceptions/UnknownPixelFormat.cc
      - copied, changed from r1868, trunk/Core/Exceptions/UnknownPixel.cc
   trunk/Core/Exceptions/UnknownPixelFormat.h
      - copied, changed from r1868, trunk/Core/Exceptions/UnknownPixel.h
   trunk/Core/Math/Expon.h
   trunk/Core/Math/MinMax.h
   trunk/Core/Math/MiscMath.cc
   trunk/Core/Math/MiscMath.h
   trunk/Core/Math/Trig.h
   trunk/Core/Thread/
   trunk/Core/Thread/AtomicCounter.h
   trunk/Core/Thread/AtomicCounter_default.cc
   trunk/Core/Thread/Barrier.h
   trunk/Core/Thread/Barrier_default.cc
   trunk/Core/Thread/CleanupManager.cc
   trunk/Core/Thread/CleanupManager.h
   trunk/Core/Thread/ConditionVariable.h
   trunk/Core/Thread/CrowdMonitor.h
   trunk/Core/Thread/CrowdMonitor_default.cc
   trunk/Core/Thread/CrowdMonitor_pthreads.cc
   trunk/Core/Thread/FutureValue.h
   trunk/Core/Thread/Guard.cc
   trunk/Core/Thread/Guard.h
   trunk/Core/Thread/Mailbox.h
   trunk/Core/Thread/Mutex.h
   trunk/Core/Thread/MutexPool.cc
   trunk/Core/Thread/MutexPool.h
   trunk/Core/Thread/Parallel.h
   trunk/Core/Thread/Parallel1.h
   trunk/Core/Thread/Parallel2.h
   trunk/Core/Thread/Parallel3.h
   trunk/Core/Thread/ParallelBase.cc
   trunk/Core/Thread/ParallelBase.h
   trunk/Core/Thread/RecursiveMutex.h
   trunk/Core/Thread/RecursiveMutex_default.cc
   trunk/Core/Thread/Reducer.h
   trunk/Core/Thread/Runnable.cc
   trunk/Core/Thread/Runnable.h
   trunk/Core/Thread/Semaphore.h
   trunk/Core/Thread/SimpleReducer.cc
   trunk/Core/Thread/SimpleReducer.h
   trunk/Core/Thread/Thread.cc
   trunk/Core/Thread/Thread.h
   trunk/Core/Thread/ThreadError.cc
   trunk/Core/Thread/ThreadError.h
   trunk/Core/Thread/ThreadGroup.cc
   trunk/Core/Thread/ThreadGroup.h
   trunk/Core/Thread/ThreadLock.cc
   trunk/Core/Thread/ThreadLock.h
   trunk/Core/Thread/ThreadPool.cc
   trunk/Core/Thread/ThreadPool.h
   trunk/Core/Thread/Thread_none.cc
   trunk/Core/Thread/Thread_pthreads.cc
   trunk/Core/Thread/Thread_unix.cc
   trunk/Core/Thread/Thread_unix.h
   trunk/Core/Thread/Thread_win32.cc
   trunk/Core/Thread/Time.h
   trunk/Core/Thread/Time_altix.cc
   trunk/Core/Thread/Time_irix.cc
   trunk/Core/Thread/Time_unix.cc
   trunk/Core/Thread/Time_win32.cc
   trunk/Core/Thread/WorkQueue.cc
   trunk/Core/Thread/WorkQueue.h
   trunk/Core/Util/Assert.h
   trunk/Core/Util/FancyAssert.h
   trunk/Core/Util/NotFinished.h
   trunk/Core/Util/Timer.cc
   trunk/Core/Util/Timer.h
Removed:
   trunk/Core/Exceptions/UnknownPixel.cc
   trunk/Core/Exceptions/UnknownPixel.h
   trunk/SCIRun/
Modified:
   trunk/CMakeLists.txt
   trunk/Core/CMakeLists.txt
   trunk/Core/Color/ColorDB.cc
   trunk/Core/Color/ColorDB.h
   trunk/Core/Color/ColorSpace.h
   trunk/Core/Color/ColorSpace_fancy.h
   trunk/Core/Color/GrayColor.cc
   trunk/Core/Color/GrayColor.h
   trunk/Core/Color/RGBColor.cc
   trunk/Core/Color/RGBColor.h
   trunk/Core/Color/RegularColorMap.cc
   trunk/Core/Color/RegularColorMap.h
   trunk/Core/Color/Spectrum.cc
   trunk/Core/Color/Spectrum.h
   trunk/Core/Exceptions/BadPrimitive.h
   trunk/Core/Exceptions/IllegalArgument.cc
   trunk/Core/Exceptions/IllegalArgument.h
   trunk/Core/Exceptions/InputError.h
   trunk/Core/Exceptions/OutputError.h
   trunk/Core/Exceptions/SerializationError.h
   trunk/Core/Exceptions/UnknownColor.h
   trunk/Core/Exceptions/UnknownComponent.cc
   trunk/Core/Exceptions/UnknownComponent.h
   trunk/Core/Geometry/AffineTransform.h
   trunk/Core/Geometry/AffineTransformT.h
   trunk/Core/Geometry/BBox.h
   trunk/Core/Geometry/ScalarTransform1D.h
   trunk/Core/Geometry/Vector.cc
   trunk/Core/Geometry/Vector.h
   trunk/Core/Geometry/VectorT.cc
   trunk/Core/Geometry/VectorT.h
   trunk/Core/Math/KorobovRNG.h
   trunk/Core/Math/Noise.cc
   trunk/Core/Math/ReflectRefract.h
   trunk/Core/Persistent/Archive.cc
   trunk/Core/Persistent/ArchiveElement.cc
   trunk/Core/Persistent/MantaRTTI.h
   trunk/Core/Persistent/XMLArchive.cc
   trunk/Core/Util/AlignedAllocator.h
   trunk/Core/Util/ApproximatePriorityQueue.h
   trunk/Core/Util/Args.cc
   trunk/Core/Util/Args.h
   trunk/Core/Util/CPUTime.cc
   trunk/Core/Util/MemoryPool.h
   trunk/Core/Util/Stat.h
   trunk/Core/Util/ThreadStorage.cc
   trunk/Core/Util/ThreadStorage.h
   trunk/Core/Util/UpdateGraph.h
   trunk/Core/XUtils/XHelper.cc
   trunk/Core/XUtils/XHelper.h
   trunk/DynLT/CMakeLists.txt
   trunk/DynLT/DynLTContext.cc
   trunk/DynLT/DynLTGridSpheres.cc
   trunk/DynLT/DynLTGridSpheres.h
   trunk/DynLT/DynLTQueue.h
   trunk/DynLT/DynLTWorker.cc
   trunk/DynLT/DynLTWorker.h
   trunk/Engine/CMakeLists.txt
   trunk/Engine/Control/RTRT.cc
   trunk/Engine/Control/RTRT.h
   trunk/Engine/Display/FileDisplay.cc
   trunk/Engine/Display/FileDisplay.h
   trunk/Engine/Display/GLXImageDisplay.cc
   trunk/Engine/Display/NullDisplay.h
   trunk/Engine/Display/OpenGLDisplay.cc
   trunk/Engine/Display/OpenGLDisplay.h
   trunk/Engine/Display/PureOpenGLDisplay.cc
   trunk/Engine/Display/PureOpenGLDisplay.h
   trunk/Engine/Display/SyncDisplay.cc
   trunk/Engine/Display/SyncDisplay.h
   trunk/Engine/Factory/CMakeLists.txt
   trunk/Engine/Factory/Factory.cc
   trunk/Engine/IdleModes/ZoomIdleMode.cc
   trunk/Engine/IdleModes/ZoomIdleMode.h
   trunk/Engine/ImageTraversers/DeadlineImageTraverser.cc
   trunk/Engine/ImageTraversers/DeadlineImageTraverser.h
   trunk/Engine/ImageTraversers/DissolveImageTraverser.cc
   trunk/Engine/ImageTraversers/DissolveImageTraverser.h
   trunk/Engine/ImageTraversers/DissolveTiledImageTraverser.cc
   trunk/Engine/ImageTraversers/DissolveTiledImageTraverser.h
   trunk/Engine/ImageTraversers/FilteredImageTraverser.cc
   trunk/Engine/ImageTraversers/NullImageTraverser.h
   trunk/Engine/ImageTraversers/TiledImageTraverser.cc
   trunk/Engine/ImageTraversers/TiledImageTraverser.h
   trunk/Engine/LoadBalancers/CyclicLoadBalancer.h
   trunk/Engine/LoadBalancers/SimpleLoadBalancer.h
   trunk/Engine/LoadBalancers/WQLoadBalancer.h
   trunk/Engine/PixelSamplers/FastSampler.h
   trunk/Engine/PixelSamplers/JitterSampler.cc
   trunk/Engine/PixelSamplers/JitterSampler.h
   trunk/Engine/PixelSamplers/NullSampler.h
   trunk/Engine/PixelSamplers/SingleSampler.h
   trunk/Engine/PixelSamplers/TimeViewSampler.cc
   trunk/Engine/PixelSamplers/TimeViewSampler.h
   trunk/Engine/Renderers/KajiyaPathtracer.cc
   trunk/Engine/Renderers/KajiyaPathtracer.h
   trunk/Engine/Renderers/Moire.h
   trunk/Engine/Renderers/Noise.h
   trunk/Engine/Renderers/NullRenderer.h
   trunk/Engine/Renderers/RayGen.h
   trunk/Engine/Renderers/Raydumper.cc
   trunk/Engine/Renderers/Raytracer.h
   trunk/Engine/SampleGenerators/Stratified2D.cc
   trunk/Engine/Shadows/HardShadows.cc
   trunk/Engine/Shadows/HardShadows.h
   trunk/Engine/Shadows/NoDirect.h
   trunk/Engine/Shadows/NoShadows.h
   trunk/Image/CMakeLists.txt
   trunk/Image/ImageMagickFile-stub.cc
   trunk/Image/ImageMagickFile.cc
   trunk/Image/NRRDFile-stub.cc
   trunk/Image/NRRDFile.cc
   trunk/Image/NullImage.cc
   trunk/Image/NullImage.h
   trunk/Image/PPMFile.cc
   trunk/Image/RGBEFile.cc
   trunk/Image/SimpleImage.h
   trunk/Image/TGAFile.cc
   trunk/Interface/AmbientLight.h
   trunk/Interface/CMakeLists.txt
   trunk/Interface/Camera.h
   trunk/Interface/Context.cc
   trunk/Interface/Context.h
   trunk/Interface/LightSet.cc
   trunk/Interface/LightSet.h
   trunk/Interface/MantaInterface.h
   trunk/Interface/Material.cc
   trunk/Interface/MeshTriangle.h
   trunk/Interface/Primitive.cc
   trunk/Interface/RayPacket.cc
   trunk/Interface/RayPacket.h
   trunk/Interface/ShadowAlgorithm.h
   trunk/Interface/Task.h
   trunk/Model/AmbientLights/ArcAmbient.cc
   trunk/Model/AmbientLights/ArcAmbient.h
   trunk/Model/AmbientLights/ConstantAmbient.cc
   trunk/Model/AmbientLights/ConstantAmbient.h
   trunk/Model/Backgrounds/EnvMapBackground.cc
   trunk/Model/Backgrounds/TextureBackground.cc
   trunk/Model/Cameras/EnvironmentCamera.cc
   trunk/Model/Cameras/EnvironmentCamera.h
   trunk/Model/Cameras/FisheyeCamera.cc
   trunk/Model/Cameras/FisheyeCamera.h
   trunk/Model/Cameras/OrthogonalCamera.cc
   trunk/Model/Cameras/OrthogonalCamera.h
   trunk/Model/Cameras/PinholeCamera.cc
   trunk/Model/Cameras/PinholeCamera.h
   trunk/Model/Cameras/ThinLensCamera.cc
   trunk/Model/Cameras/ThinLensCamera.h
   trunk/Model/Groups/DynBVH.cc
   trunk/Model/Groups/DynBVH.h
   trunk/Model/Groups/GriddedGroup.cc
   trunk/Model/Groups/Group.cc
   trunk/Model/Groups/Group.h
   trunk/Model/Groups/KDTree.cc
   trunk/Model/Groups/Mesh.cc
   trunk/Model/Groups/Mesh.h
   trunk/Model/Groups/MovingMesh.cc
   trunk/Model/Groups/MovingMesh.h
   trunk/Model/Groups/ObjGroup.cc
   trunk/Model/Groups/TimeSteppedParticles.h
   trunk/Model/Instances/Instance.cc
   trunk/Model/Instances/InstanceRST.cc
   trunk/Model/Instances/InstanceRT.cc
   trunk/Model/Materials/AmbientOcclusion.cc
   trunk/Model/Materials/AmbientOcclusion.h
   trunk/Model/Materials/Dielectric.cc
   trunk/Model/Materials/Lambertian.cc
   trunk/Model/Materials/OrenNayar.cc
   trunk/Model/Materials/Phong.cc
   trunk/Model/Materials/ThinDielectric.cc
   trunk/Model/MiscObjects/CuttingPlane.cc
   trunk/Model/MiscObjects/Difference.cc
   trunk/Model/MiscObjects/KeyFrameAnimation.cc
   trunk/Model/MiscObjects/KeyFrameAnimation.h
   trunk/Model/Primitives/BumpPrimitive.cc
   trunk/Model/Primitives/Cone.cc
   trunk/Model/Primitives/Cube.cc
   trunk/Model/Primitives/Cylinder.cc
   trunk/Model/Primitives/GridSpheres.cc
   trunk/Model/Primitives/Heightfield.cc
   trunk/Model/Primitives/Heightfield.h
   trunk/Model/Primitives/Hemisphere.cc
   trunk/Model/Primitives/IsosurfaceGridVolume.cc
   trunk/Model/Primitives/IsosurfaceGridVolume.h
   trunk/Model/Primitives/KenslerShirleyTriangle.cc
   trunk/Model/Primitives/MovingKSTriangle.cc
   trunk/Model/Primitives/OctreeVolume.cc
   trunk/Model/Primitives/OctreeVolume.h
   trunk/Model/Primitives/Parallelogram.cc
   trunk/Model/Primitives/Plane.cc
   trunk/Model/Primitives/Ring.cc
   trunk/Model/Primitives/Sphere.cc
   trunk/Model/Primitives/SuperEllipsoid.cc
   trunk/Model/Primitives/Torus.cc
   trunk/Model/Primitives/WaldTriangle.cc
   trunk/Model/Readers/ParticleNRRD.cc
   trunk/Model/Readers/PlyReader.cc
   trunk/Model/Readers/PlyReader.h
   trunk/Model/Readers/V3C1.cc
   trunk/Model/Readers/V3C1.h
   trunk/Model/TexCoordMappers/SphericalMapper.cc
   trunk/Model/Textures/CloudTexture.h
   trunk/Model/Textures/ColorMap.cc
   trunk/Model/Textures/ImageTexture.h
   trunk/Model/Textures/MarbleTexture.h
   trunk/Model/Textures/OakTexture.h
   trunk/Model/Textures/WoodTexture.h
   trunk/StandAlone/CMakeLists.txt
   trunk/StandAlone/displaytest.cc
   trunk/StandAlone/frust-test.cc
   trunk/StandAlone/manta.cc
   trunk/StandAlone/octvol_build.cc
   trunk/StandAlone/savescene.cc
   trunk/SwigInterface/CMakeLists.txt
   trunk/SwigInterface/python.cc
   trunk/UserInterface/AutomatorUI.cc
   trunk/UserInterface/AutomatorUI.h
   trunk/UserInterface/CameraPathAutomator.cc
   trunk/UserInterface/CameraPathAutomator.h
   trunk/UserInterface/NullUI.h
   trunk/UserInterface/PromptUI.cc
   trunk/UserInterface/SyncFrameAutomator.cc
   trunk/UserInterface/SyncFrameAutomator.h
   trunk/UserInterface/XWindowUI.cc
   trunk/UserInterface/XWindowUI.h
   trunk/scenes/0.cc
   trunk/scenes/complexitytest.cc
   trunk/scenes/dynlt.cc
   trunk/scenes/galileo/galileo.cc
   trunk/scenes/gridisovol.cc
   trunk/scenes/octisovol.cc
   trunk/scenes/primtest.cc
   trunk/scenes/volumeTest.cc
   trunk/scenes/vorpal.cc
   trunk/tests/atomic_counter.cc
Log:
Remove dependency on SCIRun classes
Imported thread library and other classes


Modified: trunk/CMakeLists.txt
==============================================================================
--- trunk/CMakeLists.txt        (original)
+++ trunk/CMakeLists.txt        Mon Nov 26 21:56:50 2007
@@ -76,9 +76,6 @@
 # Locate libxml2
 INCLUDE (${CMAKE_CURRENT_SOURCE_DIR}/CMake/FindLibXML2.cmake)
 
-## We need SCI_NOPERSISTENT to be defined
-FORCE_ADD_FLAGS(CMAKE_CXX_FLAGS "-DSCI_NOPERSISTENT")
-
 SET(USE_STATS_COLLECTOR 0 CACHE BOOL "Enable stats collection")
 
 
###############################################################################
@@ -92,8 +89,6 @@
 
 INCLUDE_DIRECTORIES(
   ${CMAKE_CURRENT_SOURCE_DIR} 
-  ${CMAKE_CURRENT_SOURCE_DIR}/SCIRun 
-  ${CMAKE_CURRENT_SOURCE_DIR}/SCIRun/include
   ${CMAKE_BINARY_DIR}/include
   ${OPENGL_INCLUDE_PATH}
   )
@@ -107,13 +102,10 @@
   Manta_Interface
   Manta_Core_XUtils
   Manta_Core
-  SCIRun_Core
   About
   )
 
 SUBDIRS(
-  SCIRun/Core
-  SCIRun/include/sci_defs
   Core
   include
   Interface

Modified: trunk/Core/CMakeLists.txt
==============================================================================
--- trunk/Core/CMakeLists.txt   (original)
+++ trunk/Core/CMakeLists.txt   Mon Nov 26 21:56:50 2007
@@ -1,6 +1,10 @@
 
 SET (CORE_SOURCES)
 SET (CORE_SOURCES ${CORE_SOURCES}
+     Containers/StringUtil.h
+     Containers/StringUtil.cc)
+
+SET (CORE_SOURCES ${CORE_SOURCES}
      Color/ColorDB.h
      Color/ColorDB.cc
      Color/ColorSpace.h
@@ -15,22 +19,32 @@
      Color/RegularColorMap.h
      Color/RegularColorMap.cc)
 SET (CORE_SOURCES ${CORE_SOURCES}
-     Exceptions/BadPrimitive.h
      Exceptions/BadPrimitive.cc
-     Exceptions/IllegalArgument.h
+     Exceptions/BadPrimitive.h
+     Exceptions/ErrnoException.cc
+     Exceptions/ErrnoException.h
+     Exceptions/Exception.cc
+     Exceptions/Exception.h
+     Exceptions/FileNotFound.cc
+     Exceptions/FileNotFound.h
      Exceptions/IllegalArgument.cc
-     Exceptions/UnknownColor.h
-     Exceptions/UnknownColor.cc
-     Exceptions/UnknownComponent.h
-     Exceptions/UnknownComponent.cc
-     Exceptions/UnknownPixel.h
-     Exceptions/UnknownPixel.cc
-     Exceptions/InputError.h
+     Exceptions/IllegalArgument.h
      Exceptions/InputError.cc
-     Exceptions/OutputError.h
+     Exceptions/InputError.h
+     Exceptions/InternalError.cc
+     Exceptions/InternalError.h
+     Exceptions/InvalidState.cc
+     Exceptions/InvalidState.h
      Exceptions/OutputError.cc
-     Exceptions/SerializationError.h
+     Exceptions/OutputError.h
      Exceptions/SerializationError.cc
+     Exceptions/SerializationError.h
+     Exceptions/UnknownColor.cc
+     Exceptions/UnknownColor.h
+     Exceptions/UnknownComponent.cc
+     Exceptions/UnknownComponent.h
+     Exceptions/UnknownPixelFormat.cc
+     Exceptions/UnknownPixelFormat.h
      )
 SET (CORE_SOURCES ${CORE_SOURCES}
      Geometry/AffineTransform.h
@@ -57,6 +71,8 @@
      Math/HaltonSequence.h
      Math/KorobovRNG.cc
      Math/KorobovRNG.h
+     Math/MiscMath.cc
+     Math/MiscMath.h
      Math/MT_RNG.cc
      Math/MT_RNG.h
      Math/Noise.cc
@@ -83,6 +99,40 @@
      INCLUDE_DIRECTORIES(${LIBXML2_INCLUDE})
 ENDIF (LIBXML2_INCLUDE)
 
+# Sources of Core/Thread classes
+SET(CORE_SOURCES ${CORE_SOURCES}
+  Thread/CleanupManager.cc 
+  Thread/Guard.cc 
+  Thread/MutexPool.cc 
+  Thread/ParallelBase.cc 
+  Thread/Runnable.cc 
+  Thread/Thread.cc 
+  Thread/ThreadError.cc 
+  Thread/SimpleReducer.cc 
+  Thread/ThreadLock.cc 
+  Thread/ThreadGroup.cc 
+  Thread/Thread_unix.cc 
+  Thread/ThreadPool.cc 
+  Thread/WorkQueue.cc 
+)
+
+# If we are using PTHREADS then add these files
+IF (CMAKE_USE_PTHREADS_INIT)
+  # MESSAGE("Using Pthreads")
+  SET (CORE_SOURCES ${CORE_SOURCES}
+      Thread/Thread_pthreads.cc)
+
+  # Check to see if mmtimer is available.
+  IF(EXISTS /usr/include/sn/mmtimer.h)
+    SET(CORE_SOURCES ${CORE_SOURCES}
+                       Thread/Time_altix.cc)
+  ELSE(EXISTS /usr/include/sn/mmtimer.h)
+    SET(CORE_SOURCES ${CORE_SOURCES}
+                       Thread/Time_unix.cc)
+  ENDIF(EXISTS /usr/include/sn/mmtimer.h)
+
+ENDIF (CMAKE_USE_PTHREADS_INIT)
+
 SET (CORE_SOURCES ${CORE_SOURCES}
      Util/AlignedAllocator.h
      Util/AlignedAllocator.cc
@@ -103,15 +153,16 @@
      Util/StaticCheck.h
      Util/ThreadStorage.h
      Util/ThreadStorage.cc
+     Util/Timer.h
+     Util/Timer.cc
      Util/UpdateGraph.h
      )
 
 ADD_LIBRARY (Manta_Core ${CORE_SOURCES})
 
-TARGET_LINK_LIBRARIES(Manta_Core SCIRun_Core)
 TARGET_LINK_LIBRARIES(Manta_Core ${LIBXML2_LIBRARY})
 
 # The Manta_Core_XUtils library
 ADD_LIBRARY (Manta_Core_XUtils XUtils/XHelper.cc)
-TARGET_LINK_LIBRARIES(Manta_Core_XUtils Manta_Core SCIRun_Core)
+TARGET_LINK_LIBRARIES(Manta_Core_XUtils Manta_Core)
 TARGET_LINK_LIBRARIES(Manta_Core_XUtils ${OPENGL_LIBRARIES} ${X11_LIBRARIES})

Modified: trunk/Core/Color/ColorDB.cc
==============================================================================
--- trunk/Core/Color/ColorDB.cc (original)
+++ trunk/Core/Color/ColorDB.cc Mon Nov 26 21:56:50 2007
@@ -2,9 +2,7 @@
 #include <Core/Color/ColorDB.h>
 #include <Core/Exceptions/UnknownColor.h>
 
-#include <sgi_stl_warnings_off.h>
 #include <iostream>
-#include <sgi_stl_warnings_on.h>
 
 using namespace Manta;
 using namespace std;

Modified: trunk/Core/Color/ColorDB.h
==============================================================================
--- trunk/Core/Color/ColorDB.h  (original)
+++ trunk/Core/Color/ColorDB.h  Mon Nov 26 21:56:50 2007
@@ -3,9 +3,7 @@
 #define Manta_Core_ColorDB_h
 
 #include <Core/Color/Color.h>
-#include <sgi_stl_warnings_off.h>
 #include <string>
-#include <sgi_stl_warnings_on.h>
 
 namespace Manta {
   class RGBColor;

Modified: trunk/Core/Color/ColorSpace.h
==============================================================================
--- trunk/Core/Color/ColorSpace.h       (original)
+++ trunk/Core/Color/ColorSpace.h       Mon Nov 26 21:56:50 2007
@@ -11,9 +11,7 @@
 #include <Core/Persistent/ArchiveElement.h>
 #include <Core/Persistent/MantaRTTI.h>
 
-#include <sgi_stl_warnings_off.h>
 #include <string>
-#include <sgi_stl_warnings_on.h>
 
 namespace Manta {
   template<typename Traits> class ColorSpace {
@@ -218,7 +216,6 @@
 
     // Apply functor
     ColorSpace<Traits> attenuate(ComponentType scale) const {
-      using SCIRun::Exp;
       ColorSpace<Traits> returnValue;
       for(int i=0;i<NumComponents;i++)
         returnValue.data[i] = Exp(scale*data[i]);
@@ -236,10 +233,9 @@
     template<typename Scalar>
     ColorSpace<Traits> Pow(Scalar exponent) const
     {
-      using SCIRun::Pow;
       ColorSpace<Traits> returnValue;
       for (int i=0; i < NumComponents; i++)
-        returnValue.data[i] = SCIRun::Pow(data[i], exponent);
+        returnValue.data[i] = Manta::Pow(data[i], 
static_cast<ComponentType>(exponent));
       return returnValue;
     }
 
@@ -253,7 +249,6 @@
 
     ColorSpace<Traits> attenuate(const ColorSpace<Traits> &scale) const
     {
-      using SCIRun::Exp;
       ColorSpace<Traits> returnValue;
       for(int i=0;i<NumComponents;i++)
         returnValue.data[i] = Exp(scale.data[i]*data[i]);

Modified: trunk/Core/Color/ColorSpace_fancy.h
==============================================================================
--- trunk/Core/Color/ColorSpace_fancy.h (original)
+++ trunk/Core/Color/ColorSpace_fancy.h Mon Nov 26 21:56:50 2007
@@ -2,11 +2,8 @@
 #define MANTA_CORE_COLOR_COLORSPACE_FANCY_H_
 
 #include <Core/Color/ColorSpace.h>
-
-#include <sgi_stl_warnings_off.h>
 #include <string>
 #include <sstream>
-#include <sgi_stl_warnings_on.h>
 
 namespace Manta {
 

Modified: trunk/Core/Color/GrayColor.cc
==============================================================================
--- trunk/Core/Color/GrayColor.cc       (original)
+++ trunk/Core/Color/GrayColor.cc       Mon Nov 26 21:56:50 2007
@@ -1,10 +1,8 @@
 
 #include <Core/Color/GrayColor.h>
 
-#include <sgi_stl_warnings_off.h>
 #include <sstream>
 #include <string>
-#include <sgi_stl_warnings_on.h>
 
 using namespace Manta;
 using namespace std;

Modified: trunk/Core/Color/GrayColor.h
==============================================================================
--- trunk/Core/Color/GrayColor.h        (original)
+++ trunk/Core/Color/GrayColor.h        Mon Nov 26 21:56:50 2007
@@ -2,9 +2,7 @@
 #ifndef Manta_Core_GrayColor_h
 #define Manta_Core_GrayColor_h
 
-#include <sgi_stl_warnings_off.h>
 #include <string>
-#include <sgi_stl_warnings_on.h>
 
 namespace Manta {
   class GrayColor {

Modified: trunk/Core/Color/RGBColor.cc
==============================================================================
--- trunk/Core/Color/RGBColor.cc        (original)
+++ trunk/Core/Color/RGBColor.cc        Mon Nov 26 21:56:50 2007
@@ -2,12 +2,10 @@
 #include <Core/Color/RGBColor.h>
 #include <Core/Color/ColorDB.h>
 
-#include <sgi_stl_warnings_off.h>
 #include <sstream>
 #include <string>
 #include <iomanip>
 #include <ctype.h>
-#include <sgi_stl_warnings_on.h>
 
 using namespace Manta;
 using namespace std;

Modified: trunk/Core/Color/RGBColor.h
==============================================================================
--- trunk/Core/Color/RGBColor.h (original)
+++ trunk/Core/Color/RGBColor.h Mon Nov 26 21:56:50 2007
@@ -2,9 +2,7 @@
 #ifndef Manta_Core_RGBColor_h
 #define Manta_Core_RGBColor_h
 
-#include <sgi_stl_warnings_off.h>
 #include <string>
-#include <sgi_stl_warnings_on.h>
 
 namespace Manta {
   class RGBColor {

Modified: trunk/Core/Color/RegularColorMap.cc
==============================================================================
--- trunk/Core/Color/RegularColorMap.cc (original)
+++ trunk/Core/Color/RegularColorMap.cc Mon Nov 26 21:56:50 2007
@@ -1,7 +1,7 @@
 
 #include <Core/Color/Color.h>
 #include <Core/Color/RegularColorMap.h>
-#include <SCIRun/Core/Math/MinMax.h>
+#include <Core/Math/MinMax.h>
 
 #include <fstream>
 using std::ifstream;

Modified: trunk/Core/Color/RegularColorMap.h
==============================================================================
--- trunk/Core/Color/RegularColorMap.h  (original)
+++ trunk/Core/Color/RegularColorMap.h  Mon Nov 26 21:56:50 2007
@@ -3,7 +3,7 @@
 #define Manta_Core_RegularColorMap_h
 
 #include <Core/Geometry/ScalarTransform1D.h>
-#include <SCIRun/Core/Containers/Array1.h>
+#include <Core/Containers/Array1.h>
 #include <MantaTypes.h>
 #include <Core/Color/ColorSpace.h>
 
@@ -43,7 +43,7 @@
     const Color &normalized( const Real &normalized ) const {
 
       const int ncolors = blended.size() - 1;
-      const int idx = SCIRun::Clamp(static_cast<int>(normalized*ncolors), 0, 
ncolors);
+      const int idx = Clamp(static_cast<int>(normalized*ncolors), 0, 
ncolors);
       return blended[idx];
     }
 

Modified: trunk/Core/Color/Spectrum.cc
==============================================================================
--- trunk/Core/Color/Spectrum.cc        (original)
+++ trunk/Core/Color/Spectrum.cc        Mon Nov 26 21:56:50 2007
@@ -3,16 +3,13 @@
 #include <Core/Exceptions/SerializationError.h>
 #include <Core/Math/MinMax.h>
 
-#include <sgi_stl_warnings_off.h>
 #include <sstream>
 #include <string>
 #include <iomanip>
 #include <ctype.h>
-#include <sgi_stl_warnings_on.h>
 
 using namespace Manta;
 using namespace std;
-using SCIRun::Min;
 
 typedef float MatchSample[4];
 

Modified: trunk/Core/Color/Spectrum.h
==============================================================================
--- trunk/Core/Color/Spectrum.h (original)
+++ trunk/Core/Color/Spectrum.h Mon Nov 26 21:56:50 2007
@@ -2,11 +2,9 @@
 #ifndef Manta_Core_Spectrum_h
 #define Manta_Core_Spectrum_h
 
-#include <sgi_stl_warnings_off.h>
 #include <Core/Color/RGBColor.h>
 #include <string>
 #include <vector>
-#include <sgi_stl_warnings_on.h>
 
 namespace Manta {
   class Spectrum {

Added: trunk/Core/Containers/Array1.h
==============================================================================
--- (empty file)
+++ trunk/Core/Containers/Array1.h      Mon Nov 26 21:56:50 2007
@@ -0,0 +1,390 @@
+/*
+   For more information, please see: http://software.sci.utah.edu
+
+   The MIT License
+
+   Copyright (c) 2004 Scientific Computing and Imaging Institute,
+   University of Utah.
+
+   License for the specific language governing rights and limitations under
+   Permission is hereby granted, free of charge, to any person obtaining a
+   copy of this software and associated documentation files (the "Software"),
+   to deal in the Software without restriction, including without limitation
+   the rights to use, copy, modify, merge, publish, distribute, sublicense,
+   and/or sell copies of the Software, and to permit persons to whom the
+   Software is furnished to do so, subject to the following conditions:
+
+   The above copyright notice and this permission notice shall be included
+   in all copies or substantial portions of the Software.
+
+   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+   OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 
MERCHANTABILITY,
+   FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+   THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+   LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+   FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+   DEALINGS IN THE SOFTWARE.
+*/
+
+
+
+/*
+ *  Array1.h: Interface to dynamic 1D array class
+ *
+ *  Written by:
+ *   Steven G. Parker
+ *   Department of Computer Science
+ *   University of Utah
+ *   March 1994
+ *
+ *  Copyright (C) 1994 SCI Group
+ */
+
+#ifndef Manta_Array1_h
+#define Manta_Array1_h 1
+
+#include <Core/Util/Assert.h>
+
+namespace Manta {
+
+/**************************************
+
+  CLASS
+  Array1
+
+  KEYWORDS
+  Array1
+
+  DESCRIPTION
+  Array1.h: Interface to dynamic 1D array class
+
+  Written by:
+  Steven G. Parker
+  Department of Computer Science
+  University of Utah
+  March 1994
+
+  Copyright (C) 1994 SCI Group
+  PATTERNS
+
+  WARNING
+  
+****************************************/
+template<class T> class Array1 {
+  T* objs;
+  int _size;
+  int nalloc;
+  int default_grow_size;
+public:
+
+  //////////
+  //Copy the array - this can be costly, so try to avoid it.
+  Array1(const Array1&);
+
+  //////////
+  //Make a new array 1. <i>size</i> gives the initial size of the array,
+  //<i>default_grow_size</i> indicates the minimum number of objects that
+  //should be added to the array at a time.  <i>asize</i> tells how many
+  //objects should be allocated initially
+  Array1(int size=0, int default_grow_size=10, int asize=-1);
+
+  //////////
+  //Copy over the array - this can be costly, so try to avoid it.
+  Array1<T>& operator=(const Array1&);
+
+  //////////
+  //Compare over the array - this can be costly, so try to avoid it.
+  int operator==(const Array1<T>&) const;
+  int operator!=(const Array1<T>&) const;
+
+  //////////
+  //Deletes the array and frees the associated memory
+  ~Array1();
+    
+  //////////
+  // Accesses the nth element of the array
+  inline const T& operator[](int n) const {
+    CHECKARRAYBOUNDS(n, 0, _size);
+    return objs[n];
+  }
+
+  //////////
+  // Accesses the nth element of the array
+  inline T& operator[](int n) {
+    CHECKARRAYBOUNDS(n, 0, _size);
+    return objs[n];
+  }
+    
+  //////////
+  // Returns the size of the array
+  inline int size() const{ return _size;}
+
+
+  //////////
+  // Make the array larger by count elements
+  void grow(int count, int grow_size=10);
+
+  //////////
+  // set allocated size 
+  void reserve(int n);
+
+  //////////
+  // Add one element to the array.  equivalent to:
+  //  grow(1)
+  //  array[array.size()-1]=data
+  void add(const T&);
+
+  //////////
+  // Insert one element into the array.  This is very inefficient
+  // if you insert anything besides the (new) last element.
+  void insert(int, const T&);
+
+
+  //////////
+  // Remove one element from the array.  This is very inefficient
+  // if you remove anything besides the last element.
+  void remove(int);
+
+
+  //////////
+  // Remove all elements in the array.  The array is not freed,
+  // and the number of allocated elements remains the same.
+  void remove_all();
+
+
+  //////////
+  // Change the size of the array.
+  void resize(int newsize);
+
+  //////////
+  // Changes size, makes exact if currently smaller...
+  void setsize(int newsize);
+
+  //////////
+  // This will allocate an array which is equal to the number of
+  // elements in the array and copy the values over.
+  //
+  // _size is not changed.
+  //
+  // newsize is an optional parameter which indicates the desired
+  // size.  If newsize is greater than _size the new array will have
+  // newsize elements in it (nalloc = newsize).  If newsize is less
+  // than _size then _size elemets will be allocated (nalloc = _size).
+  void trim(int newsize=0);
+
+  //////////
+  // Initialize all elements of the array
+  void initialize(const T& val);
+
+
+  //////////
+  // Get the array information
+  T* get_objs();
+
+};
+
+template<class T>
+Array1<T>::Array1(const Array1<T>& a)
+{
+  _size=a._size;
+  nalloc=_size;
+  objs=new T[_size];
+  for(int i=0;i<_size;i++)objs[i]=a.objs[i];
+  nalloc=_size;
+  default_grow_size=a.default_grow_size;
+}
+
+template<class T>
+Array1<T>& Array1<T>::operator=(const Array1<T>& copy)
+{
+  if (&copy == this)
+    // Doing A=A, so don't do anything
+    return (*this);
+  setsize(copy._size);
+  for(int i=0;i<_size;i++)objs[i]=copy.objs[i];
+  default_grow_size=copy.default_grow_size;
+  return(*this);
+}
+
+template<class T>
+int Array1<T>::operator==(const Array1<T>& a) const
+{
+  for(int i=0;i<_size;i++)
+    if( objs[i]!=a.objs[i] )
+      return false;
+
+  return true;
+}
+
+template<class T>
+int Array1<T>::operator!=(const Array1<T>& a) const
+{
+  for(int i=0;i<_size;i++)
+    if( objs[i]!=a.objs[i] )
+      return true;
+
+  return false;
+}
+
+template<class T>
+Array1<T>::Array1(int size, int gs, int asize)
+{
+  ASSERT(size >= 0);
+  default_grow_size=gs;
+  _size=size;
+  if(size){
+    if(asize <= size){
+      objs=new T[size];
+      nalloc=_size;
+    } else {
+      objs=new T[asize];
+      nalloc=asize;
+    }
+  } else {
+    if(asize > 0){
+      objs=new T[asize];
+      nalloc=asize;
+    } else {
+      objs=0;
+      nalloc=0;
+    }
+  }
+}      
+
+template<class T>
+Array1<T>::~Array1()
+{
+  if(objs)delete [] objs;
+}
+
+template<class T>
+void Array1<T>::grow(int count, int grow_size)
+{
+  int newsize=_size+count;
+  if(newsize>nalloc){
+    // Reallocate...
+    int gs1=newsize>>2;
+    int gs=gs1>grow_size?gs1:grow_size;
+    int newalloc=newsize+gs;
+    T* newobjs=new T[newalloc];
+    if(objs){
+      for(int i=0;i<_size;i++){
+       newobjs[i]=objs[i];
+      }
+      delete[] objs;
+    }
+    objs=newobjs;
+    nalloc=newalloc;
+  }
+  _size=newsize;
+}
+
+template<class T>
+void Array1<T>::reserve(int n)
+{
+  if(n>nalloc){
+    // Reallocate...
+    T* newobjs=new T[n];
+    if(objs){
+      for(int i=0;i<_size;i++){
+       newobjs[i]=objs[i];
+      }
+      delete[] objs;
+    }
+    objs=newobjs;
+    nalloc=n;
+  }
+}
+
+template<class T>
+void Array1<T>::add(const T& obj)
+{
+  grow(1, default_grow_size);
+  objs[_size-1]=obj;
+}
+
+template<class T>
+void Array1<T>::insert(int idx, const T& obj)
+{
+  grow(1, default_grow_size);
+  for(int i=_size-1;i>idx;i--)objs[i]=objs[i-1];
+  objs[idx]=obj;
+}
+
+template<class T>
+void Array1<T>::remove(int idx)
+{
+  _size--;
+  for(int i=idx;i<_size;i++)objs[i]=objs[i+1];
+}
+
+template<class T>
+void Array1<T>::remove_all()
+{
+  _size=0;
+}
+
+template<class T>
+void Array1<T>::resize(int newsize)
+{
+  if(newsize > _size)
+    grow(newsize-_size);
+  else
+    _size=newsize;
+}
+
+template<class T>
+void Array1<T>::setsize(int newsize)
+{ 
+  if(newsize > nalloc) { // have to reallocate...
+    T* newobjs=new T[newsize];     // make it exact!
+    if (objs) {
+      for(int i=0;i<_size;i++){
+       newobjs[i]=objs[i];
+      }
+      delete[] objs;
+    }          
+    objs = newobjs;
+    nalloc = newsize;
+      
+  }
+  _size=newsize;
+}
+
+template<class T>
+void Array1<T>::trim(int newsize)
+{
+  if (newsize < _size || newsize <= 0)
+    newsize = _size;
+  if (newsize == nalloc)
+    // We already have the correct number allocated
+    return;
+  T* newobjs = new T[newsize];
+  if (objs) {
+    // Copy the data
+    for(int i=0;i<_size;i++){
+      newobjs[i]=objs[i];
+    }
+    // Delete the old bit of memory
+    delete[] objs;
+  }            
+  objs = newobjs;
+  nalloc = newsize;
+}
+
+template<class T>
+void Array1<T>::initialize(const T& val) {
+  for (int i=0;i<_size;i++)objs[i]=val;
+}
+
+template<class T>
+T* Array1<T>::get_objs()
+{
+  return objs;
+}
+
+} // End namespace Manta
+
+
+#endif /* SCI_Containers_Array1_h */
+

Added: trunk/Core/Containers/Array2.h
==============================================================================
--- (empty file)
+++ trunk/Core/Containers/Array2.h      Mon Nov 26 21:56:50 2007
@@ -0,0 +1,227 @@
+/*
+   For more information, please see: http://software.sci.utah.edu
+
+   The MIT License
+
+   Copyright (c) 2004 Scientific Computing and Imaging Institute,
+   University of Utah.
+
+   License for the specific language governing rights and limitations under
+   Permission is hereby granted, free of charge, to any person obtaining a
+   copy of this software and associated documentation files (the "Software"),
+   to deal in the Software without restriction, including without limitation
+   the rights to use, copy, modify, merge, publish, distribute, sublicense,
+   and/or sell copies of the Software, and to permit persons to whom the
+   Software is furnished to do so, subject to the following conditions:
+
+   The above copyright notice and this permission notice shall be included
+   in all copies or substantial portions of the Software.
+
+   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+   OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 
MERCHANTABILITY,
+   FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+   THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+   LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+   FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+   DEALINGS IN THE SOFTWARE.
+*/
+
+
+
+/*
+ *  Array2.h: Interface to dynamic 2D array class
+ *
+ *  Written by:
+ *   Steven G. Parker
+ *   Department of Computer Science
+ *   University of Utah
+ *   March 1994
+ *
+ *  Copyright (C) 1994 SCI Group
+ */
+
+#ifndef SCI_Containers_Array2_h
+#define SCI_Containers_Array2_h 1
+
+#include <Core/Util/Assert.h>
+
+namespace Manta {
+
+/**************************************
+
+ CLASS
+ Array2
+
+ KEYWORDS
+ Array2
+
+ DESCRIPTION
+ Array2.h: Interface to dynamic 2D array class
+
+ Written by:
+ Steven G. Parker
+ Department of Computer Science
+ University of Utah
+ March 1994
+
+ Copyright (C) 1994 SCI Group
+ PATTERNS
+
+ WARNING
+  
+****************************************/
+template<class T>
+class Array2 {
+  T** objs;
+  int dm1;
+  int dm2;
+  void allocate();
+
+  // The copy constructor and the assignment operator have been
+  // privatized on purpose -- no one should use these.  Instead,
+  // use the default constructor and the copy method.
+  //////////
+  //Array2 Copy Constructor
+  Array2(const Array2&);
+  //////////
+  //Assignment Operator
+  Array2<T>& operator=(const Array2&);
+public:
+  //////////
+  //Create a 0X0 Array
+  Array2();
+    
+  //////////
+  //Create an n by n array
+  Array2(int, int);
+
+  //////////
+  //Class Destructor
+  virtual ~Array2();
+
+  //////////
+  //Used for accessing elements in the Array
+  inline T& operator()(int d1, int d2) const
+  {
+    ASSERTL3(d1>=0 && d1<dm1);
+    ASSERTL3(d2>=0 && d2<dm2);
+    return objs[d1][d2];
+  }
+    
+  //////////
+  //Array2 Copy Method
+  void copy(const Array2&);
+    
+  //////////
+  //Returns number of rows
+  inline int dim1() const {return dm1;}
+    
+  //////////
+  //Returns number of cols
+  inline int dim2() const {return dm2;}
+    
+  //////////
+  //Resize Array
+  void resize(int, int);
+    
+  //////////
+  //Initialize all values in an array
+  void initialize(const T&);
+
+  inline T** get_dataptr() {return objs;}
+
+#ifndef SCI_NOPERSISTENT
+#if defined(_AIX)
+  template <typename Type> 
+  friend void TEMPLATE_TAG Pio TEMPLATE_BOX (Piostream&, Array2<Type>&);
+  template <typename Type> 
+  friend void TEMPLATE_TAG Pio TEMPLATE_BOX (Piostream&, Array2<Type>*&);
+#else
+  friend void TEMPLATE_TAG Pio TEMPLATE_BOX (Piostream&, Array2<T>&);
+  friend void TEMPLATE_TAG Pio TEMPLATE_BOX (Piostream&, Array2<T>*&);
+#endif
+#endif // #ifndef SCI_NOPERSISTENT
+};
+
+template<class T>
+Array2<T>::Array2()
+{
+  dm1=dm2=0;
+  objs=0;
+}
+
+template<class T>
+void Array2<T>::allocate()
+{
+  if(dm1 == 0 || dm2 == 0){
+    objs=0;
+  } else {
+    objs=new T*[dm1];
+    T* p=new T[dm1*dm2];
+    for(int i=0;i<dm1;i++){
+      objs[i]=p;
+      p+=dm2;
+    }
+  }
+}
+
+template<class T>
+void Array2<T>::resize(int d1, int d2)
+{
+  if(objs && dm1==d1 && dm2==d2)return;
+  dm1=d1;
+  dm2=d2;
+  if(objs){
+    delete[] objs[0];
+    delete[] objs;
+  }
+  allocate();
+}
+
+template<class T>
+Array2<T>::Array2(const Array2<T>& a)
+  : dm1(a.dm1), dm2(a.dm2)
+{
+  allocate();
+}
+
+template<class T>
+Array2<T>::Array2(int dm1, int dm2)
+  : dm1(dm1), dm2(dm2)
+{
+  allocate();
+}
+
+template<class T>
+Array2<T>::~Array2()
+{
+  if(objs){
+    delete[] objs[0];
+    delete[] objs;
+  }
+}
+
+template<class T>
+void Array2<T>::initialize(const T& t)
+{
+  ASSERT(dm1==0 || dm2==0 || objs != 0);
+  for(int i=0;i<dm1;i++){
+    for(int j=0;j<dm2;j++){
+      objs[i][j]=t;
+    }
+  }
+}
+
+template<class T>
+void Array2<T>::copy(const Array2<T> &copy)
+{
+  resize( copy.dim1(), copy.dim2() );
+  for(int i=0;i<dm1;i++)
+    for(int j=0;j<dm2;j++)
+      objs[i][j] = copy.objs[i][j];
+}
+
+}
+
+#endif
+

Added: trunk/Core/Containers/Array3.h
==============================================================================
--- (empty file)
+++ trunk/Core/Containers/Array3.h      Mon Nov 26 21:56:50 2007
@@ -0,0 +1,343 @@
+/*
+   For more information, please see: http://software.sci.utah.edu
+
+   The MIT License
+
+   Copyright (c) 2004 Scientific Computing and Imaging Institute,
+   University of Utah.
+
+   License for the specific language governing rights and limitations under
+   Permission is hereby granted, free of charge, to any person obtaining a
+   copy of this software and associated documentation files (the "Software"),
+   to deal in the Software without restriction, including without limitation
+   the rights to use, copy, modify, merge, publish, distribute, sublicense,
+   and/or sell copies of the Software, and to permit persons to whom the
+   Software is furnished to do so, subject to the following conditions:
+
+   The above copyright notice and this permission notice shall be included
+   in all copies or substantial portions of the Software.
+
+   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+   OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 
MERCHANTABILITY,
+   FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+   THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+   LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+   FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+   DEALINGS IN THE SOFTWARE.
+*/
+
+
+
+/*
+ *  Array3.h: Interface to dynamic 3D array class
+ *
+ *  Written by:
+ *   Steven G. Parker
+ *   Department of Computer Science
+ *   University of Utah
+ *   March 1994
+ *
+ *  Copyright (C) 1994 SCI Group
+ */
+
+#ifndef SCI_Containers_Array3_h
+#define SCI_Containers_Array3_h 1
+
+#include <iostream>
+#include <stdio.h>
+#include <errno.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <Core/Util/Assert.h>
+
+namespace Manta {
+
+/**************************************
+
+ CLASS
+ Array3
+
+ KEYWORDS
+ Array3
+
+ DESCRIPTION
+ Array3.h: Interface to dynamic 3D array class
+
+ Written by:
+ Steven G. Parker
+ Department of Computer Science
+ University of Utah
+ March 1994
+
+ Copyright (C) 1994 SCI Group
+ PATTERNS
+
+ WARNING
+  
+****************************************/
+
+template<class T> class Array3 {
+  T*** objs;
+  int dm1;
+  int dm2;
+  int dm3;
+  void allocate();
+
+  // The copy constructor and the assignment operator have been
+  // privatized on purpose -- no one should use these.  Instead,
+  // use the default constructor and the copy method.
+  //////////
+  //Copy Constructor
+  Array3(const Array3&);
+  //////////
+  //Assignment Operator
+  Array3<T>& operator=(const Array3&);
+public:
+  //////////
+  //Default Constructor
+  Array3();
+    
+  //////////
+  //Constructor
+  Array3(int, int, int);
+    
+  //////////
+  //Class Destructor
+  virtual ~Array3();
+    
+  //////////
+  //Access the nXnXn element of the array
+  inline T& operator()(int d1, int d2, int d3) const
+  {
+    ASSERTL3(d1>=0 && d1<dm1);
+    ASSERTL3(d2>=0 && d2<dm2);
+    ASSERTL3(d3>=0 && d3<dm3);
+    return objs[d1][d2][d3];
+  }
+    
+  //////////
+  //Array2 Copy Method
+  void copy(const Array3&);
+
+  //////////
+  //Returns the number of spaces in dim1           
+  inline int dim1() const {return dm1;}
+  //////////
+  //Returns the number of spaces in dim2
+  inline int dim2() const {return dm2;}
+  //////////
+  //Returns the number of spaces in dim3
+  inline int dim3() const {return dm3;}
+  
+  inline long get_datasize() const { return dm1*long(dm2*dm3*sizeof(T)); }
+    
+  //////////
+  //Re-size the Array
+  void resize(int, int, int);
+
+  //////////
+  //Initialize all elements to T
+  void initialize(const T&);
+
+  T* get_onedim();
+  void get_onedim_byte( unsigned char *v );
+
+  inline T*** get_dataptr() {return objs;}
+
+  //////////
+  //read/write from a separate raw file
+  int input( const std::string& );
+  int output( const std::string&);
+
+};
+
+template<class T>
+Array3<T>::Array3()
+{
+  objs=0;
+  dm1 = dm2 = dm3 = 0;
+}
+
+template<class T>
+void Array3<T>::allocate()
+{
+  if( dm1 && dm2 && dm3 ){
+    objs=new T**[dm1];
+    T** p=new T*[dm1*dm2];
+    T* pp=new T[dm1*long(dm2*dm3)];
+    for(int i=0;i<dm1;i++){
+      objs[i]=p;
+      p+=dm2;
+      for(int j=0;j<dm2;j++){
+       objs[i][j]=pp;
+       pp+=dm3;
+      }
+    }
+  } else {
+    objs = 0;
+  }
+}
+
+template<class T>
+void Array3<T>::resize(int d1, int d2, int d3)
+{
+  if(objs && dm1==d1 && dm2==d2 && dm3==d3)return;
+  dm1=d1;
+  dm2=d2;
+  dm3=d3;
+  if(objs){
+    delete[] objs[0][0];
+    delete[] objs[0];
+    delete[] objs;
+  }
+  allocate();
+}
+
+template<class T>
+Array3<T>::Array3(int dm1, int dm2, int dm3)
+  : dm1(dm1), dm2(dm2),dm3(dm3)
+{
+  allocate();
+}
+
+template<class T>
+Array3<T>::~Array3()
+{
+  if(objs){
+    delete[] objs[0][0];
+    delete[] objs[0];
+    delete[] objs;
+  }
+}
+
+template<class T>
+void Array3<T>::initialize(const T& t)
+{
+  ASSERT(objs != 0);
+  for(int i=0;i<dm1;i++){
+    for(int j=0;j<dm2;j++){
+      for(int k=0;k<dm3;k++){
+       objs[i][j][k]=t;
+      }
+    }
+  }
+}
+
+template<class T>
+void Array3<T>::copy(const Array3<T> &copy)
+{
+  resize( copy.dim1(), copy.dim2(), copy.dim3() );
+  for(int i=0;i<dm1;i++)
+    for(int j=0;j<dm2;j++)
+      for(int k=0;k<dm3;k++)
+        objs[i][j][k] = copy.objs[i][j][k];
+}
+
+template<class T>
+T* Array3<T>::get_onedim()
+{
+  int i,j,k, index;
+  T* a = new T[dm1*long(dm2*dm3)];
+  
+  index=0;
+  for( i=0; i<dm1; i++)
+    for( j=0; j<dm2; j++ )
+      for( k=0; k<dm3; k++ )
+       a[index++] = objs[i][j][k];
+  return a;
+}
+
+template<class T>
+void
+Array3<T>::get_onedim_byte( unsigned char *v )
+{
+  int i,j,k, index;
+  index = 0;
+  
+  for( k=0; k<dm3; k++ )
+    for( j=0; j<dm2; j++ )
+      for( i=0; i<dm1; i++)
+       v[index++] = objs[i][j][k];
+}
+
+template<class T>
+int
+Array3<T>::input( const std::string &filename ) 
+{
+  std::cerr << "Array3: Split input\n";
+
+  // get raw data
+  int file=open( filename.c_str(), O_RDONLY, 0666);
+  if ( file == -1 ) {
+    printf("can not open file %s\n", filename.c_str());
+    return 0;
+  }
+  
+  int maxiosz=1024*1024;
+  long size = dm1*long(dm2*dm3*sizeof(T));
+  int n = int(size / maxiosz);
+  std::cerr << "grid size = " << size << std::endl;
+  char *p = (char *) objs[0][0];
+
+  for ( ; n> 0 ; n--, p+= maxiosz) {
+    int i = read( file, p, maxiosz);
+    if ( i != maxiosz ) 
+      perror( "io read ");
+  }
+  int i =  read( file, p, size % maxiosz);
+  if ( i != (size % maxiosz) ) 
+    perror("on last io");
+        
+  fsync(file);
+  close(file);
+
+  return 1;
+}
+
+template<class T>
+int
+Array3<T>::output( const std::string &filename ) 
+{
+  std::cerr << "Array3 output to " << filename << std::endl;
+  // get raw data
+  //  printf("output [%s] [%s]\n", filename.c_str(), rawfile() );
+  int file=open( filename.c_str(), O_WRONLY|O_CREAT|O_TRUNC, 0666);
+  if ( file == -1 ) {
+    perror("open file");
+    return 0;
+  }
+  
+  int maxiosz=1024*1024;
+
+  long size = dm1*long(dm2*dm3*sizeof(T));
+  int n = size / maxiosz;
+  char *p = (char *)objs[0][0];
+
+  printf("Start writing...%d %d %d\n", size, maxiosz, n);
+
+  for ( ; n> 0 ; n--, p+= maxiosz) {
+    int l = write( file, p, maxiosz);
+    if ( l != maxiosz ) 
+      perror("write ");
+  }
+  int sz = (size % maxiosz );
+  int l = write( file, p, sz); 
+  if ( l != (size % maxiosz ) ) {
+    printf("Error: wrote %d / %d\n", l,(size % maxiosz )); 
+    perror("write ");
+  }
+        
+  fsync(file);
+  close(file);
+
+  return 1;
+} 
+
+}
+
+
+#endif
+
+

Added: trunk/Core/Containers/StringUtil.cc
==============================================================================
--- (empty file)
+++ trunk/Core/Containers/StringUtil.cc Mon Nov 26 21:56:50 2007
@@ -0,0 +1,232 @@
+ /*
+   For more information, please see: http://software.sci.utah.edu
+
+   The MIT License
+
+   Copyright (c) 2004 Scientific Computing and Imaging Institute,
+   University of Utah.
+
+   License for the specific language governing rights and limitations under
+   Permission is hereby granted, free of charge, to any person obtaining a
+   copy of this software and associated documentation files (the "Software"),
+   to deal in the Software without restriction, including without limitation
+   the rights to use, copy, modify, merge, publish, distribute, sublicense,
+   and/or sell copies of the Software, and to permit persons to whom the
+   Software is furnished to do so, subject to the following conditions:
+
+   The above copyright notice and this permission notice shall be included
+   in all copies or substantial portions of the Software.
+
+   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+   OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 
MERCHANTABILITY,
+   FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+   THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+   LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+   FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+   DEALINGS IN THE SOFTWARE.
+*/
+
+
+
+/*
+ *  StringUtil.c: Some useful string functions
+ *
+ *  Written by:
+ *   Michael Callahan
+ *   Department of Computer Science
+ *   University of Utah
+ *   April 2001
+ *
+ *  Copyright (C) 2001 SCI Group
+ */
+
+#include <Core/Util/Assert.h>
+#include <Core/Containers/StringUtil.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <ctype.h> // for toupper() (at least for linux RH8)
+
+namespace Manta {
+
+bool
+string_to_int(const string &str, int &result)
+{
+  return sscanf(str.c_str(), "%d", &result) == 1;
+}
+
+bool
+string_to_double(const string &str, double &result)
+{
+  return sscanf(str.c_str(), "%lf", &result) == 1;
+}
+
+bool
+string_to_unsigned_long(const string &str, unsigned long &result)
+{
+  return sscanf(str.c_str(), "%lu", &result) == 1;
+}
+
+
+string
+to_string(int val)
+{
+  char s[50];
+  sprintf(s, "%d", val);
+  return string(s);
+}
+
+string
+to_string(unsigned int val)
+{
+  char s[50];
+  sprintf(s, "%u", val);
+  return string(s);
+}
+
+string
+to_string(unsigned long val)
+{
+  char s[50];
+  sprintf(s, "%lu", val);
+  return string(s);
+}
+
+string
+to_string(double val)
+{
+  char s[50];
+  sprintf(s, "%g", val);
+  return string(s);
+}
+
+string
+basename(const string &path)
+{
+  return path.substr(path.rfind('/')+1);
+}
+
+string
+pathname(const string &path)
+{
+  return path.substr(0, path.rfind('/')+1);
+}
+
+
+char *
+ccast_unsafe(const string &str)
+{
+  char *result = const_cast<char *>(str.c_str());
+  ASSERT(result);
+  return result;
+}
+
+
+vector<string>
+split_string(const std::string& str, char sep)
+{
+  vector<string> result;
+  string s(str);
+  while(s != ""){
+    unsigned long first = s.find(sep);
+    if(first < s.size()){
+      result.push_back(s.substr(0, first));
+      s = s.substr(first+1);
+    } else {
+      result.push_back(s);
+      break;
+    }
+  }
+  return result;
+}
+
+
+/////////
+// C++ify a string, turn newlines into \n, use \t, \r, \\ \", etc.
+string
+string_Cify(const string &str)
+{
+  string result("");
+  for (string::size_type i = 0; i < str.size(); i++)
+  {
+    switch(str[i])
+    {
+    case '\n':
+      result.push_back('\\');
+      result.push_back('n');
+      break;
+
+    case '\r':
+      result.push_back('\\');
+      result.push_back('r');
+      break;
+
+    case '\t':
+      result.push_back('\\');
+      result.push_back('t');
+      break;
+
+    case '"':
+      result.push_back('\\');
+      result.push_back('"');
+      break;
+
+    case '\\':
+      result.push_back('\\');
+      result.push_back('\\');
+      break;
+
+    default:
+      result.push_back(str[i]);
+    }
+  }
+  return result;
+}
+
+
+// replaces all occurances of 'substr' in 'str' with 'replacement'
+string 
+replace_substring(string str, 
+                 const string &substr, 
+                 const string &replacement) 
+{
+  string::size_type pos;
+  do {
+    pos = str.find(substr);
+    if (pos != string::npos)
+      str = str.replace(str.begin()+pos, 
+                        str.begin()+pos+substr.length(), 
+                        replacement);
+  } while (pos != string::npos);
+  return str;
+}
+
+
+bool
+ends_with(const string &str, const string &substr)
+{
+  return str.rfind(substr) == str.size()-substr.size();
+}  
+
+
+string
+string_toupper(string str) 
+{
+  for (unsigned int i = 0; i < str.length(); ++i)
+    str[i] = toupper(str[i]);
+  return str;
+}
+
+string
+string_tolower(string str) 
+{
+  for (unsigned int i = 0; i < str.length(); ++i)
+    str[i] = tolower(str[i]);
+  return str;
+}
+
+  
+
+
+
+} // End namespace Manta
+

Added: trunk/Core/Containers/StringUtil.h
==============================================================================
--- (empty file)
+++ trunk/Core/Containers/StringUtil.h  Mon Nov 26 21:56:50 2007
@@ -0,0 +1,95 @@
+/*
+   For more information, please see: http://software.sci.utah.edu
+
+   The MIT License
+
+   Copyright (c) 2004 Scientific Computing and Imaging Institute,
+   University of Utah.
+
+   License for the specific language governing rights and limitations under
+   Permission is hereby granted, free of charge, to any person obtaining a
+   copy of this software and associated documentation files (the "Software"),
+   to deal in the Software without restriction, including without limitation
+   the rights to use, copy, modify, merge, publish, distribute, sublicense,
+   and/or sell copies of the Software, and to permit persons to whom the
+   Software is furnished to do so, subject to the following conditions:
+
+   The above copyright notice and this permission notice shall be included
+   in all copies or substantial portions of the Software.
+
+   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+   OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 
MERCHANTABILITY,
+   FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+   THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+   LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+   FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+   DEALINGS IN THE SOFTWARE.
+*/
+
+
+
+/*
+ *  StringUtil.h: some useful string functions
+ *
+ *  Written by:
+ *   Michael Callahan
+ *   Department of Computer Science
+ *   University of Utah
+ *   April 2001
+ *
+ *  Copyright (C) 2001 SCI Group
+ */
+
+#ifndef SCI_Core_StringUtil_h
+#define SCI_Core_StringUtil_h 1
+
+#include <string>
+#include <vector>
+
+namespace Manta {
+  using std::string;
+  using std::vector;
+
+  bool string_to_int(const string &str, int &result);
+  bool string_to_double(const string &str, double &result);
+  bool string_to_unsigned_long(const string &str, unsigned long &res);
+
+  string to_string(int val);
+  string to_string(unsigned int val);
+  string to_string(unsigned long val);
+  string to_string(double val);
+
+  string string_toupper(string);
+  string string_tolower(string);
+
+//////////
+// Remove directory name
+  string basename(const string &path);
+
+//////////
+// Return directory name
+  string pathname(const string &path);
+
+// Split a string into multiple parts, separated by the character sep
+  vector<string> split_string(const string& str, char sep);
+
+/////////
+// C++ify a string, turn newlines into \n, use \t, \r, \\ \", etc.
+  string string_Cify(const string &str);
+
+//////////
+// Unsafe cast from string to char *, used to export strings to C functions.
+  char* ccast_unsafe(const string &str);
+
+// replaces all occurances of 'substr' in 'str' with 'replacement'
+  string replace_substring(string str, 
+                                  const string &substr, 
+                                  const string &replacement);
+
+// Returns true if 'str' ends with the string 'substr'
+  bool ends_with(const string &str, const string &substr);
+
+
+} // End namespace Manta
+
+#endif

Added: trunk/Core/Exceptions/ArrayIndexOutOfBounds.cc
==============================================================================
--- (empty file)
+++ trunk/Core/Exceptions/ArrayIndexOutOfBounds.cc      Mon Nov 26 21:56:50 
2007
@@ -0,0 +1,86 @@
+/*
+   For more information, please see: http://software.sci.utah.edu
+
+   The MIT License
+
+   Copyright (c) 2004 Scientific Computing and Imaging Institute,
+   University of Utah.
+
+   License for the specific language governing rights and limitations under
+   Permission is hereby granted, free of charge, to any person obtaining a
+   copy of this software and associated documentation files (the "Software"),
+   to deal in the Software without restriction, including without limitation
+   the rights to use, copy, modify, merge, publish, distribute, sublicense,
+   and/or sell copies of the Software, and to permit persons to whom the
+   Software is furnished to do so, subject to the following conditions:
+
+   The above copyright notice and this permission notice shall be included
+   in all copies or substantial portions of the Software.
+
+   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+   OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 
MERCHANTABILITY,
+   FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+   THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+   LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+   FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+   DEALINGS IN THE SOFTWARE.
+*/
+
+
+
+/*
+ *  ArrayIndexOutOfBounds.h: Exception to indicate a failed bounds check
+ *
+ *  Written by:
+ *   Steven G. Parker
+ *   Department of Computer Science
+ *   University of Utah
+ *   March 2000
+ *
+ *  Copyright (C) 2000 SCI Group
+ */
+
+#include <Core/Exceptions/ArrayIndexOutOfBounds.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <iostream>
+#include <sstream>
+
+namespace Manta {
+
+ArrayIndexOutOfBounds::ArrayIndexOutOfBounds(long value, long lower, long 
upper,
+                                             const char* file, int line)
+    : value(value), lower(lower), upper(upper)
+{
+  std::ostringstream s;
+  s << "An ArrayIndexOutOfBounds exception was thrown.\n"
+    << file << ":" << line << "\n"
+    << "Array index " << value << " out of range ["
+    << lower << ", " << upper << ")";
+  msg = (char*)(s.str().c_str());
+#ifdef EXCEPTIONS_CRASH
+    std::cout << msg << "\n";
+#endif
+}
+
+ArrayIndexOutOfBounds::ArrayIndexOutOfBounds(const ArrayIndexOutOfBounds& 
copy)
+  : value(copy.value), lower(copy.lower), upper(copy.upper), 
msg(strdup(copy.msg))
+{
+}
+    
+ArrayIndexOutOfBounds::~ArrayIndexOutOfBounds()
+{
+}
+
+const char* ArrayIndexOutOfBounds::message() const
+{
+    return msg;
+}
+
+const char* ArrayIndexOutOfBounds::type() const
+{
+    return "ArrayIndexOutOfBounds";
+}
+
+} // End namespace Manta

Added: trunk/Core/Exceptions/ArrayIndexOutOfBounds.h
==============================================================================
--- (empty file)
+++ trunk/Core/Exceptions/ArrayIndexOutOfBounds.h       Mon Nov 26 21:56:50 
2007
@@ -0,0 +1,68 @@
+/*
+   For more information, please see: http://software.sci.utah.edu
+
+   The MIT License
+
+   Copyright (c) 2004 Scientific Computing and Imaging Institute,
+   University of Utah.
+
+   License for the specific language governing rights and limitations under
+   Permission is hereby granted, free of charge, to any person obtaining a
+   copy of this software and associated documentation files (the "Software"),
+   to deal in the Software without restriction, including without limitation
+   the rights to use, copy, modify, merge, publish, distribute, sublicense,
+   and/or sell copies of the Software, and to permit persons to whom the
+   Software is furnished to do so, subject to the following conditions:
+
+   The above copyright notice and this permission notice shall be included
+   in all copies or substantial portions of the Software.
+
+   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+   OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 
MERCHANTABILITY,
+   FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+   THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+   LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+   FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+   DEALINGS IN THE SOFTWARE.
+*/
+
+
+
+/*
+ *  ArrayIndexOutOfBounds.h: Exception to indicate a failed bounds check
+ *
+ *  Written by:
+ *   Steven G. Parker
+ *   Department of Computer Science
+ *   University of Utah
+ *   July 1999
+ *
+ *  Copyright (C) 1999 SCI Group
+ */
+
+#ifndef Core_Exceptions_ArrayIndexOutOfBounds_h
+#define Core_Exceptions_ArrayIndexOutOfBounds_h
+
+#include <Core/Exceptions/Exception.h>
+
+namespace Manta {
+  class ArrayIndexOutOfBounds : public Exception {
+  public:
+    ArrayIndexOutOfBounds(long value, long lower, long upper, 
+                          const char* file, int line);
+    ArrayIndexOutOfBounds(const ArrayIndexOutOfBounds&);
+    virtual ~ArrayIndexOutOfBounds();
+    virtual const char* message() const;
+    virtual const char* type() const;
+  protected:
+  private:
+    long value, lower, upper;
+    char* msg;
+
+    ArrayIndexOutOfBounds& operator=(const ArrayIndexOutOfBounds);
+  };
+}
+
+#endif
+
+

Added: trunk/Core/Exceptions/AssertionFailed.cc
==============================================================================
--- (empty file)
+++ trunk/Core/Exceptions/AssertionFailed.cc    Mon Nov 26 21:56:50 2007
@@ -0,0 +1,82 @@
+/*
+   For more information, please see: http://software.sci.utah.edu
+
+   The MIT License
+
+   Copyright (c) 2004 Scientific Computing and Imaging Institute,
+   University of Utah.
+
+   License for the specific language governing rights and limitations under
+   Permission is hereby granted, free of charge, to any person obtaining a
+   copy of this software and associated documentation files (the "Software"),
+   to deal in the Software without restriction, including without limitation
+   the rights to use, copy, modify, merge, publish, distribute, sublicense,
+   and/or sell copies of the Software, and to permit persons to whom the
+   Software is furnished to do so, subject to the following conditions:
+
+   The above copyright notice and this permission notice shall be included
+   in all copies or substantial portions of the Software.
+
+   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+   OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 
MERCHANTABILITY,
+   FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+   THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+   LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+   FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+   DEALINGS IN THE SOFTWARE.
+*/
+
+
+
+/*
+ *  AssertionFailed.h: Generic exception for internal errors
+ *
+ *  Written by:
+ *   Steven G. Parker
+ *   Department of Computer Science
+ *   University of Utah
+ *   July 1999
+ *
+ *  Copyright (C) 1999 SCI Group
+ */
+
+#include <Core/Exceptions/AssertionFailed.h>
+#include <sstream>
+
+namespace Manta {
+
+AssertionFailed::AssertionFailed(const char* message,
+                                const char* file,
+                                int line) : 
+  Exception()
+{ 
+  std::ostringstream s;
+  s << "An AssertionFailed exception was thrown from file:\n  "
+    << file << ":" << line << "\n  " << message;
+  message_ = s.str();
+
+#ifdef EXCEPTIONS_CRASH
+  std::cout << message_ << "\n";
+#endif
+}
+
+AssertionFailed::AssertionFailed(const AssertionFailed& copy)
+    : message_(copy.message_)
+{
+}
+
+AssertionFailed::~AssertionFailed()
+{
+}
+
+const char* AssertionFailed::message() const
+{
+    return message_.c_str();
+}
+
+const char* AssertionFailed::type() const
+{
+    return "AssertionFailed";
+}
+
+} // End namespace Manta

Added: trunk/Core/Exceptions/AssertionFailed.h
==============================================================================
--- (empty file)
+++ trunk/Core/Exceptions/AssertionFailed.h     Mon Nov 26 21:56:50 2007
@@ -0,0 +1,72 @@
+/*
+   For more information, please see: http://software.sci.utah.edu
+
+   The MIT License
+
+   Copyright (c) 2004 Scientific Computing and Imaging Institute,
+   University of Utah.
+
+   License for the specific language governing rights and limitations under
+   Permission is hereby granted, free of charge, to any person obtaining a
+   copy of this software and associated documentation files (the "Software"),
+   to deal in the Software without restriction, including without limitation
+   the rights to use, copy, modify, merge, publish, distribute, sublicense,
+   and/or sell copies of the Software, and to permit persons to whom the
+   Software is furnished to do so, subject to the following conditions:
+
+   The above copyright notice and this permission notice shall be included
+   in all copies or substantial portions of the Software.
+
+   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+   OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 
MERCHANTABILITY,
+   FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+   THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+   LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+   FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+   DEALINGS IN THE SOFTWARE.
+*/
+
+
+
+
+/*
+ *  AssertionFailed.h: Exception for a failed assertion.  Note - this
+ *    version takes only a char*.  There is a FancyAssertionFailed that
+ *    takes std::string.  This is done to prevent include file pollution
+ *    with std::string
+ *
+ *  Written by:
+ *   Steven G. Parker
+ *   Department of Computer Science
+ *   University of Utah
+ *   July 1999
+ *
+ *  Copyright (C) 1999 SCI Group
+ */
+
+#ifndef Core_Exceptions_AssertionFailed_h
+#define Core_Exceptions_AssertionFailed_h
+
+#include <Core/Exceptions/Exception.h>
+#include <string>
+
+namespace Manta {
+class AssertionFailed : public Exception {
+public:
+  AssertionFailed(const char* msg,
+                 const char* file,
+                 int line);
+  AssertionFailed(const AssertionFailed&);
+  virtual ~AssertionFailed();
+  virtual const char* message() const;
+  virtual const char* type() const;
+protected:
+private:
+  std::string message_;
+  AssertionFailed& operator=(const AssertionFailed&);
+};
+}
+
+#endif
+
+

Modified: trunk/Core/Exceptions/BadPrimitive.h
==============================================================================
--- trunk/Core/Exceptions/BadPrimitive.h        (original)
+++ trunk/Core/Exceptions/BadPrimitive.h        Mon Nov 26 21:56:50 2007
@@ -3,13 +3,11 @@
 #define Manta_Core_BadPrimitive_h
 
 #include <Core/Exceptions/Exception.h>
-#include <sgi_stl_warnings_off.h>
 #include <string>
-#include <sgi_stl_warnings_on.h>
 
 namespace Manta {
   using namespace std;
-  class BadPrimitive : public SCIRun::Exception {
+  class BadPrimitive : public Exception {
   public:
     BadPrimitive(const std::string&);
     BadPrimitive(const BadPrimitive&);

Added: trunk/Core/Exceptions/ErrnoException.cc
==============================================================================
--- (empty file)
+++ trunk/Core/Exceptions/ErrnoException.cc     Mon Nov 26 21:56:50 2007
@@ -0,0 +1,92 @@
+/*
+   For more information, please see: http://software.sci.utah.edu
+
+   The MIT License
+
+   Copyright (c) 2004 Scientific Computing and Imaging Institute,
+   University of Utah.
+
+   License for the specific language governing rights and limitations under
+   Permission is hereby granted, free of charge, to any person obtaining a
+   copy of this software and associated documentation files (the "Software"),
+   to deal in the Software without restriction, including without limitation
+   the rights to use, copy, modify, merge, publish, distribute, sublicense,
+   and/or sell copies of the Software, and to permit persons to whom the
+   Software is furnished to do so, subject to the following conditions:
+
+   The above copyright notice and this permission notice shall be included
+   in all copies or substantial portions of the Software.
+
+   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+   OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 
MERCHANTABILITY,
+   FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+   THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+   LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+   FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+   DEALINGS IN THE SOFTWARE.
+*/
+
+
+
+/*
+ *  ErrnoException.h: Generic exception for internal errors
+ *
+ *  Written by:
+ *   Steven G. Parker
+ *   Department of Computer Science
+ *   University of Utah
+ *   July 1999
+ *
+ *  Copyright (C) 1999 SCI Group
+ */
+
+#include <Core/Exceptions/ErrnoException.h>
+#include <sstream>
+#include <iostream>
+
+namespace Manta {
+
+using namespace std;
+
+ErrnoException::ErrnoException(const std::string& message, int err, const 
char* file, int line)
+   : errno_(err)
+{
+   ostringstream str;
+   const char* s = strerror(err);
+   if(!s)
+      s="(none)";
+   str << "An ErrnoException was thrown.\n"
+       << file << ":" << line << "\n"
+       << message << " (errno=" << err << ": " << s << ")";
+   message_ = str.str();
+
+#ifdef EXCEPTIONS_CRASH
+   std::cout << message_ << "\n";
+#endif
+}
+
+ErrnoException::ErrnoException(const ErrnoException& copy)
+   : message_(copy.message_), errno_(copy.errno_)
+{
+}
+
+ErrnoException::~ErrnoException()
+{
+}
+
+const char* ErrnoException::message() const
+{
+   return message_.c_str();
+}
+
+const char* ErrnoException::type() const
+{
+   return "ErrnoException";
+}
+
+int ErrnoException::getErrno() const
+{
+   return errno_;
+}
+
+} // End namespace Manta

Added: trunk/Core/Exceptions/ErrnoException.h
==============================================================================
--- (empty file)
+++ trunk/Core/Exceptions/ErrnoException.h      Mon Nov 26 21:56:50 2007
@@ -0,0 +1,69 @@
+/*
+   For more information, please see: http://software.sci.utah.edu
+
+   The MIT License
+
+   Copyright (c) 2004 Scientific Computing and Imaging Institute,
+   University of Utah.
+
+   License for the specific language governing rights and limitations under
+   Permission is hereby granted, free of charge, to any person obtaining a
+   copy of this software and associated documentation files (the "Software"),
+   to deal in the Software without restriction, including without limitation
+   the rights to use, copy, modify, merge, publish, distribute, sublicense,
+   and/or sell copies of the Software, and to permit persons to whom the
+   Software is furnished to do so, subject to the following conditions:
+
+   The above copyright notice and this permission notice shall be included
+   in all copies or substantial portions of the Software.
+
+   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+   OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 
MERCHANTABILITY,
+   FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+   THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+   LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+   FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+   DEALINGS IN THE SOFTWARE.
+*/
+
+
+/*
+ *  ErrnoException.h: Generic exception for internal errors
+ *
+ *  Written by:
+ *   Steven G. Parker
+ *   Department of Computer Science
+ *   University of Utah
+ *   May 2000
+ *
+ *  Copyright (C) 2000 SCI Group
+ */
+
+#ifndef Core_Exceptions_ErrnoException_h
+#define Core_Exceptions_ErrnoException_h
+
+#include <Core/Exceptions/Exception.h>
+#include <string>
+
+namespace Manta {
+
+class ErrnoException : public Exception {
+public:
+  ErrnoException(const std::string&, int err, const char* file, int line);
+  ErrnoException(const ErrnoException&);
+  virtual ~ErrnoException();
+  virtual const char* message() const;
+  virtual const char* type() const;
+        
+  int getErrno() const;
+protected:
+private:
+  std::string message_;
+  int errno_;
+
+  ErrnoException& operator=(const ErrnoException&);
+};
+
+} // End namespace Manta
+
+#endif

Added: trunk/Core/Exceptions/Exception.cc
==============================================================================
--- (empty file)
+++ trunk/Core/Exceptions/Exception.cc  Mon Nov 26 21:56:50 2007
@@ -0,0 +1,267 @@
+/*
+   For more information, please see: http://software.sci.utah.edu
+
+   The MIT License
+
+   Copyright (c) 2004 Scientific Computing and Imaging Institute,
+   University of Utah.
+
+   License for the specific language governing rights and limitations under
+   Permission is hereby granted, free of charge, to any person obtaining a
+   copy of this software and associated documentation files (the "Software"),
+   to deal in the Software without restriction, including without limitation
+   the rights to use, copy, modify, merge, publish, distribute, sublicense,
+   and/or sell copies of the Software, and to permit persons to whom the
+   Software is furnished to do so, subject to the following conditions:
+
+   The above copyright notice and this permission notice shall be included
+   in all copies or substantial portions of the Software.
+
+   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+   OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 
MERCHANTABILITY,
+   FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+   THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+   LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+   FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+   DEALINGS IN THE SOFTWARE.
+*/
+
+
+
+/*
+ *  Exception.h: Base exception class
+ *
+ *  Written by:
+ *   Steven G. Parker
+ *   Department of Computer Science
+ *   University of Utah
+ *   March 2000
+ *
+ *  Copyright (C) 2000 SCI Group
+ */
+
+#include <Core/Exceptions/Exception.h>
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#ifndef _WIN32
+#include <unistd.h>
+#else
+#define strcasecmp stricmp
+#include <io.h>
+#include <process.h>
+#include "StackWalker.h"
+#endif
+#include <iostream>
+#include <iomanip>
+#include <sstream>
+#include <string.h>
+#ifdef HAVE_EXC
+#include <libexc.h>
+#elif defined(__GNUC__) && defined(__linux)
+#include <execinfo.h>
+#include <cxxabi.h>
+#include <dlfcn.h>
+#endif
+
+
+#if defined(_AIX)
+// Needed for strcasecmp on aix 4.3 (on 5.1 we don't need this.)
+// currently blue is 4.3.
+#  include <strings.h>
+#endif
+
+namespace Manta {
+
+using namespace std;
+
+Exception::Exception()
+{
+  stacktrace_ = strdup(getStackTrace().c_str());
+}
+
+Exception::~Exception()
+{
+  if(stacktrace_) {
+    free((char*)stacktrace_);
+    stacktrace_ = 0;
+  }
+}
+
+void Exception::sci_throw(const Exception& exc)
+{
+  // This is a function invoked by the SCI_THROW macro.  It
+  // can be useful for tracking down fatal errors, since the
+  // normal exception mechanism will unwind the stack before
+  // you can get anything useful out of it.
+
+  // Set this environment variable if you want to have a default
+  // response to the question below.  Value values are:
+  // ask, dbx, cvd, throw, abort
+  char* emode = getenv("SCI_EXCEPTIONMODE");
+  if(!emode)
+    emode = "dbx"; // Default exceptionmode
+
+  // If the mode is not "throw", we print out a message
+  if(strcasecmp(emode, "throw") != 0){
+    cerr << "\n\nAn exception was thrown.  Msg: " << exc.message() << "\n";
+    if(exc.stacktrace_){
+      cerr << exc.stacktrace_;
+    }
+    // Print out the exception type (clasname) and the message
+    cerr << "\nException type: " << exc.type() << '\n';
+    cerr << "Exception message: " << exc.message() << '\n';
+  }
+  // See what we should do
+  for(;;){
+    if(strcasecmp(emode, "ask") == 0){
+      // Ask the user
+      cerr << "\nthrow(t)/dbx(d)/cvd(c)/abort(a)? ";
+      emode=0;
+      while(!emode){
+        char action;
+        char buf[100];
+        while(read(fileno(stdin), buf, 100) <= 0){
+          if(errno != EINTR){
+            cerr <<  "\nCould not read response, throwing exception\n";
+            emode = "throw";
+            break;
+          }
+        }
+        action=buf[0];
+        switch(action){
+        case 't': case 'T':
+          emode="throw";
+          break;
+        case 'd': case 'D':
+          emode="dbx";
+          break;
+        case 'c': case 'C':
+          emode="cvd";
+          break;
+        case 'a': case 'A':
+          emode="abort";
+          break;
+        default:
+          break;
+        }
+      }
+    }
+
+    if(strcasecmp(emode, "throw") == 0) {
+      // We cannot throw from here, so we just return and the
+      // exception will be thrown by the SCI_THROW macro
+      return;
+    } else if(strcasecmp(emode, "dbx") == 0){
+#if defined( REDSTORM )
+      cout << "Error: running debugger at exception is not supported on 
RedStorm\n";
+#else
+      // Fire up the debugger
+      char command[100];
+      if(getenv("SCI_DBXCOMMAND")){
+        sprintf(command, getenv("SCI_DBXCOMMAND"), getpid());
+      } else {
+      cout << "Error: running debugger at exception is not supported on 
RedStorm\n";
+#ifdef HAVE_EXC
+        sprintf(command, "winterm -c dbx -p %d &", getpid());
+#else
+        sprintf(command, "xterm -e gdb %d&", getpid());
+#endif
+      }
+      cerr << "Starting: " << command << '\n';
+      system(command);
+      emode="ask";
+#endif
+    } else if(strcasecmp(emode, "cvd") == 0){
+#if defined( REDSTORM )
+      cout << "Error: running debugger at exception is not supported on 
RedStorm\n";
+#else
+      // Fire up the slow, fancy debugger
+      char command[100];
+      sprintf(command, "cvd -pid %d &", getpid());
+      cerr << "Starting: " << command << '\n';
+      system(command);
+      emode="ask";
+#endif
+    } else if(strcasecmp(emode, "abort") == 0){
+      // This will trigger the thread library, but we cannot
+      // directly call the thread library here or it would create
+      // a circular dependency
+      abort();
+    } else {
+      cerr << "Unknown exception mode: " << emode << ", aborting\n";
+      abort();
+    }
+  }
+}
+
+string getStackTrace(void* context /*=0*/)
+{
+  ostringstream stacktrace;
+#if defined(HAVE_EXC) || (defined(__GNUC__) && defined(__linux))
+  static const int MAXSTACK = 100;
+#endif
+
+#ifdef HAVE_EXC
+  // Use -lexc to print out a stack trace
+  static const int MAXNAMELEN = 1000;
+  __uint64_t addrs[MAXSTACK];
+  char* cnames_str = new char[MAXSTACK*MAXNAMELEN];
+  char* names[MAXSTACK];
+  for(int i=0;i<MAXSTACK;i++)
+    names[i]=cnames_str+i*MAXNAMELEN;
+  int nframes = trace_back_stack(0, addrs, names, MAXSTACK, MAXNAMELEN);
+  if(nframes == 0){
+    stacktrace << "Backtrace not available!\n";
+  } else {
+    stacktrace << "Backtrace:\n";
+    stacktrace.flags(ios::hex);
+    // Skip the first procedure (us)
+    for(int i=1;i<nframes;i++)
+      stacktrace << "0x" << (void*)addrs[i] << ": " << names[i] << '\n';
+  }
+#elif defined(__GNUC__) && defined(__linux)
+  static void *addresses[MAXSTACK];
+  int n = backtrace( addresses, MAXSTACK );
+  if (n < 2){
+    stacktrace << "Backtrace not available!\n";
+  } else {
+    stacktrace << "Backtrace:\n";
+    stacktrace.flags(ios::hex);
+    char **names = backtrace_symbols( addresses, n );
+    for ( int i = 2; i < n; i++ ) {
+     Dl_info info;
+     char *demangled = NULL;
+
+     //Attempt to demangle this if possible
+     //Get the nearest symbol to feed to demangler
+     if(dladdr(addresses[i], &info) != 0) {
+      int stat;
+      // __cxa_demangle is a naughty obscure backend and no
+      // self-respecting person would ever call it directly. ;-)
+      // However it is a convenient glibc way to demangle syms.
+      demangled = abi::__cxa_demangle(info.dli_sname,0,0,&stat);
+     }
+     if (demangled != NULL) {
+      //Chop off the garbage from the raw symbol
+      char *loc = strchr(names[i], '(');
+      if (loc != NULL) *loc = '\0';
+      
+      stacktrace << i - 1 << ". " << names[i] << '\n';
+      stacktrace << "  in " << demangled << '\n';
+      delete demangled;
+     } else { // Just output the raw symbol
+      stacktrace << i - 1 << ". " << names[i] << '\n';
+     }
+    }
+    free(names);
+  }
+#elif defined(_WIN32)
+  StackWalker sw;
+  stacktrace << sw.GetCallstack(context);
+#endif
+  return stacktrace.str();
+}
+
+} // End namespace Manta

Added: trunk/Core/Exceptions/Exception.h
==============================================================================
--- (empty file)
+++ trunk/Core/Exceptions/Exception.h   Mon Nov 26 21:56:50 2007
@@ -0,0 +1,68 @@
+/*
+   For more information, please see: http://software.sci.utah.edu
+
+   The MIT License
+
+   Copyright (c) 2004 Scientific Computing and Imaging Institute,
+   University of Utah.
+
+   License for the specific language governing rights and limitations under
+   Permission is hereby granted, free of charge, to any person obtaining a
+   copy of this software and associated documentation files (the "Software"),
+   to deal in the Software without restriction, including without limitation
+   the rights to use, copy, modify, merge, publish, distribute, sublicense,
+   and/or sell copies of the Software, and to permit persons to whom the
+   Software is furnished to do so, subject to the following conditions:
+
+   The above copyright notice and this permission notice shall be included
+   in all copies or substantial portions of the Software.
+
+   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+   OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 
MERCHANTABILITY,
+   FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+   THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+   LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+   FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+   DEALINGS IN THE SOFTWARE.
+*/
+
+
+/*
+ *  Exception.h: Base class for all SCI Exceptions
+ *
+ *  Written by:
+ *   Steven G. Parker
+ *   Department of Computer Science
+ *   University of Utah
+ *   July 1999
+ *
+ *  Copyright (C) 1999 SCI Group
+ */
+
+#ifndef Manta_Exception_h
+#define Manta_Exception_h
+
+#include <string>
+
+namespace Manta {
+  class Exception {
+  public:
+    Exception();
+    virtual ~Exception();
+    virtual const char* message() const=0;
+    virtual const char* type() const=0;
+    const char* stackTrace() const {
+      return stacktrace_;
+    }
+
+    static void sci_throw(const Exception& exc);
+  protected:
+    const char* stacktrace_;
+  private:
+    Exception& operator=(const Exception&);
+  };
+
+  std::string getStackTrace(void* context = 0);
+}
+
+#endif

Added: trunk/Core/Exceptions/FileNotFound.cc
==============================================================================
--- (empty file)
+++ trunk/Core/Exceptions/FileNotFound.cc       Mon Nov 26 21:56:50 2007
@@ -0,0 +1,82 @@
+/*
+   For more information, please see: http://software.sci.utah.edu
+
+   The MIT License
+
+   Copyright (c) 2004 Scientific Computing and Imaging Institute,
+   University of Utah.
+
+   License for the specific language governing rights and limitations under
+   Permission is hereby granted, free of charge, to any person obtaining a
+   copy of this software and associated documentation files (the "Software"),
+   to deal in the Software without restriction, including without limitation
+   the rights to use, copy, modify, merge, publish, distribute, sublicense,
+   and/or sell copies of the Software, and to permit persons to whom the
+   Software is furnished to do so, subject to the following conditions:
+
+   The above copyright notice and this permission notice shall be included
+   in all copies or substantial portions of the Software.
+
+   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+   OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 
MERCHANTABILITY,
+   FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+   THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+   LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+   FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+   DEALINGS IN THE SOFTWARE.
+*/
+
+
+/*
+ *  FileNotFound.h: Generic exception for internal errors
+ *
+ *  Written by:
+ *   Steven G. Parker
+ *   Department of Computer Science
+ *   University of Utah
+ *   July 1999
+ *
+ *  Copyright (C) 1999 SCI Group
+ */
+
+#include <Core/Exceptions/FileNotFound.h>
+#include <iostream>
+#include <sstream>
+
+#undef FileNotFound
+
+namespace Manta {
+
+FileNotFound::FileNotFound(const std::string& message, const char* file, int 
line)
+    : message_(message)
+{
+  std::ostringstream s;
+  s << "A FileNotFound exception was thrown\n"
+    << file << ":" << line << "\n" << message_;
+  message_ = (char*)(s.str().c_str());
+
+#ifdef EXCEPTIONS_CRASH
+  std::cout << message_ << "\n";
+#endif
+}
+
+FileNotFound::FileNotFound(const FileNotFound& copy)
+    : message_(copy.message_)
+{
+}
+
+FileNotFound::~FileNotFound()
+{
+}
+
+const char* FileNotFound::message() const
+{
+    return message_.c_str();
+}
+
+const char* FileNotFound::type() const
+{
+    return "FileNotFound";
+}
+
+} // End namespace Manta

Added: trunk/Core/Exceptions/FileNotFound.h
==============================================================================
--- (empty file)
+++ trunk/Core/Exceptions/FileNotFound.h        Mon Nov 26 21:56:50 2007
@@ -0,0 +1,69 @@
+/*
+   For more information, please see: http://software.sci.utah.edu
+
+   The MIT License
+
+   Copyright (c) 2004 Scientific Computing and Imaging Institute,
+   University of Utah.
+
+   License for the specific language governing rights and limitations under
+   Permission is hereby granted, free of charge, to any person obtaining a
+   copy of this software and associated documentation files (the "Software"),
+   to deal in the Software without restriction, including without limitation
+   the rights to use, copy, modify, merge, publish, distribute, sublicense,
+   and/or sell copies of the Software, and to permit persons to whom the
+   Software is furnished to do so, subject to the following conditions:
+
+   The above copyright notice and this permission notice shall be included
+   in all copies or substantial portions of the Software.
+
+   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+   OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 
MERCHANTABILITY,
+   FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+   THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+   LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+   FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+   DEALINGS IN THE SOFTWARE.
+*/
+
+
+
+
+/*
+ *  FileNotFound.h: Exactly what you think
+ *
+ *  Written by:
+ *   Steven G. Parker
+ *   Department of Computer Science
+ *   University of Utah
+ *   July 1999
+ *
+ *  Copyright (C) 1999 SCI Group
+ */
+
+#ifndef Core_Exceptions_FileNotFound_h
+#define Core_Exceptions_FileNotFound_h
+
+#include <Core/Exceptions/Exception.h>
+#include <string>
+
+namespace Manta {
+  class FileNotFound : public Exception {
+  public:
+    FileNotFound(const std::string&, const char* file, int line);
+    FileNotFound(const FileNotFound&);
+    virtual ~FileNotFound();
+    virtual const char* message() const;
+    virtual const char* type() const;
+  protected:
+  private:
+    std::string message_;
+    FileNotFound& operator=(const FileNotFound&);
+  };
+} // End namespace Manta
+
+#define FileNotFound(msg) FileNotFound(msg, __FILE__, __LINE__)
+
+#endif
+
+

Modified: trunk/Core/Exceptions/IllegalArgument.cc
==============================================================================
--- trunk/Core/Exceptions/IllegalArgument.cc    (original)
+++ trunk/Core/Exceptions/IllegalArgument.cc    Mon Nov 26 21:56:50 2007
@@ -1,8 +1,6 @@
 
 #include <Core/Exceptions/IllegalArgument.h>
-#include <sgi_stl_warnings_off.h>
 #include <sstream>
-#include <sgi_stl_warnings_on.h>
 
 using namespace Manta;
 using namespace std;

Modified: trunk/Core/Exceptions/IllegalArgument.h
==============================================================================
--- trunk/Core/Exceptions/IllegalArgument.h     (original)
+++ trunk/Core/Exceptions/IllegalArgument.h     Mon Nov 26 21:56:50 2007
@@ -3,14 +3,12 @@
 #define Manta_Core_IllegalArgument_h
 
 #include <Core/Exceptions/Exception.h>
-#include <sgi_stl_warnings_off.h>
 #include <string>
 #include <vector>
-#include <sgi_stl_warnings_on.h>
 
 namespace Manta {
   using namespace std;
-  class IllegalArgument : public SCIRun::Exception {
+  class IllegalArgument : public Exception {
   public:
     IllegalArgument(const std::string&, int, const vector<string>& args);
     IllegalArgument(const IllegalArgument&);

Added: trunk/Core/Exceptions/IllegalValue.h
==============================================================================
--- (empty file)
+++ trunk/Core/Exceptions/IllegalValue.h        Mon Nov 26 21:56:50 2007
@@ -0,0 +1,102 @@
+/*
+   For more information, please see: http://software.sci.utah.edu
+
+   The MIT License
+
+   Copyright (c) 2004 Scientific Computing and Imaging Institute,
+   University of Utah.
+
+   License for the specific language governing rights and limitations under
+   Permission is hereby granted, free of charge, to any person obtaining a
+   copy of this software and associated documentation files (the "Software"),
+   to deal in the Software without restriction, including without limitation
+   the rights to use, copy, modify, merge, publish, distribute, sublicense,
+   and/or sell copies of the Software, and to permit persons to whom the
+   Software is furnished to do so, subject to the following conditions:
+
+   The above copyright notice and this permission notice shall be included
+   in all copies or substantial portions of the Software.
+
+   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+   OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 
MERCHANTABILITY,
+   FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+   THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+   LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+   FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+   DEALINGS IN THE SOFTWARE.
+*/
+
+
+
+
+/*
+ *  IllegalValue.h: Generic exception for invalid values
+ *
+ *  Written by:
+ *   Steven G. Parker
+ *   Department of Computer Science
+ *   University of Utah
+ *   July 1999
+ *
+ *  Copyright (C) 1999 SCI Group
+ */
+
+#ifndef Manta_IllegalValue_h
+#define Manta_IllegalValue_h
+
+#include <Core/Exceptions/Exception.h>
+#include <string>
+#include <sstream>
+
+namespace Manta {
+  template <class T>
+  class IllegalValue : public Exception {
+  public:
+    IllegalValue(const std::string&, const T& value);
+    IllegalValue(const IllegalValue&);
+    virtual ~IllegalValue();
+    virtual const char* message() const;
+    virtual const char* type() const;
+  protected:
+  private:
+    std::string message_;
+    IllegalValue& operator=(const IllegalValue&);
+  };
+
+  template <class T>
+  IllegalValue<T>::IllegalValue(const std::string& message, const T& value)
+  {
+    std::ostringstream msgbuf;
+    msgbuf << message << ", value=" << value;
+    message_=msgbuf.str();
+  }
+
+  template <class T>
+  IllegalValue<T>::IllegalValue(const IllegalValue& copy)
+    : Exception(),
+      message_(copy.message_)
+  {
+  }
+
+  template <class T>
+  IllegalValue<T>::~IllegalValue()
+  {
+  }
+
+  template <class T>
+  const char* IllegalValue<T>::message() const
+  {
+    return message_.c_str();
+  }
+
+  template <class T>
+  const char* IllegalValue<T>::type() const
+  {
+    return "IllegalValue";
+  }
+
+} // End namespace SCIRun
+
+#endif
+
+

Modified: trunk/Core/Exceptions/InputError.h
==============================================================================
--- trunk/Core/Exceptions/InputError.h  (original)
+++ trunk/Core/Exceptions/InputError.h  Mon Nov 26 21:56:50 2007
@@ -33,16 +33,14 @@
 #define Manta_Core_InputError_h
 
 #include <Core/Exceptions/Exception.h>
-#include <sgi_stl_warnings_off.h>
 #include <string>
-#include <sgi_stl_warnings_on.h>
 
 namespace Manta {
   using namespace std;
 
   // Input Errors are thrown when a problem occurs reading or parsing some 
type
   // of input, such as a texture is encountered.
-  class InputError : public SCIRun::Exception {
+  class InputError : public Exception {
   public:
     InputError(const std::string&);
     InputError(const InputError&);

Added: trunk/Core/Exceptions/InternalError.cc
==============================================================================
--- (empty file)
+++ trunk/Core/Exceptions/InternalError.cc      Mon Nov 26 21:56:50 2007
@@ -0,0 +1,82 @@
+/*
+   For more information, please see: http://software.sci.utah.edu
+
+   The MIT License
+
+   Copyright (c) 2004 Scientific Computing and Imaging Institute,
+   University of Utah.
+
+   License for the specific language governing rights and limitations under
+   Permission is hereby granted, free of charge, to any person obtaining a
+   copy of this software and associated documentation files (the "Software"),
+   to deal in the Software without restriction, including without limitation
+   the rights to use, copy, modify, merge, publish, distribute, sublicense,
+   and/or sell copies of the Software, and to permit persons to whom the
+   Software is furnished to do so, subject to the following conditions:
+
+   The above copyright notice and this permission notice shall be included
+   in all copies or substantial portions of the Software.
+
+   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+   OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 
MERCHANTABILITY,
+   FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+   THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+   LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+   FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+   DEALINGS IN THE SOFTWARE.
+*/
+
+
+/*
+ *  InternalError.h: Generic exception for internal errors
+ *
+ *  Written by:
+ *   Steven G. Parker
+ *   Department of Computer Science
+ *   University of Utah
+ *   July 1999
+ *
+ *  Copyright (C) 1999 SCI Group
+ */
+
+#include <Core/Exceptions/InternalError.h>
+#include <iostream>
+#include <sstream>
+#undef InternalError
+
+namespace Manta {
+
+
+InternalError::InternalError(const std::string& message, const char* file, 
int line)
+    : message_(message)
+{
+  std::ostringstream s;
+  s << "An InternalError exception was thrown (" << message << ").\n"
+    << file << ":" << line << "\n";
+  message_ = s.str();
+
+#ifdef EXCEPTIONS_CRASH
+  std::cout << message_ << "\n";
+#endif
+}
+
+InternalError::InternalError(const InternalError& copy)
+    : message_(copy.message_)
+{
+}
+
+InternalError::~InternalError()
+{
+}
+
+const char* InternalError::message() const
+{
+    return message_.c_str();
+}
+
+const char* InternalError::type() const
+{
+    return "InternalError";
+}
+
+} // End namespace Manta

Added: trunk/Core/Exceptions/InternalError.h
==============================================================================
--- (empty file)
+++ trunk/Core/Exceptions/InternalError.h       Mon Nov 26 21:56:50 2007
@@ -0,0 +1,69 @@
+/*
+   For more information, please see: http://software.sci.utah.edu
+
+   The MIT License
+
+   Copyright (c) 2004 Scientific Computing and Imaging Institute,
+   University of Utah.
+
+   License for the specific language governing rights and limitations under
+   Permission is hereby granted, free of charge, to any person obtaining a
+   copy of this software and associated documentation files (the "Software"),
+   to deal in the Software without restriction, including without limitation
+   the rights to use, copy, modify, merge, publish, distribute, sublicense,
+   and/or sell copies of the Software, and to permit persons to whom the
+   Software is furnished to do so, subject to the following conditions:
+
+   The above copyright notice and this permission notice shall be included
+   in all copies or substantial portions of the Software.
+
+   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+   OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 
MERCHANTABILITY,
+   FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+   THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+   LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+   FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+   DEALINGS IN THE SOFTWARE.
+*/
+
+
+
+
+/*
+ *  InternalError.h: Generic exception for internal errors
+ *
+ *  Written by:
+ *   Steven G. Parker
+ *   Department of Computer Science
+ *   University of Utah
+ *   July 1999
+ *
+ *  Copyright (C) 1999 SCI Group
+ */
+
+#ifndef Manta_InternalError_h
+#define Manta_InternalError_h
+
+#include <Core/Exceptions/Exception.h>
+#include <string>
+
+namespace Manta {
+  class InternalError : public Exception {
+  public:
+    InternalError(const std::string&, const char* file, int line);
+    InternalError(const InternalError&);
+    virtual ~InternalError();
+    virtual const char* message() const;
+    virtual const char* type() const;
+  protected:
+  private:
+    std::string message_;
+    InternalError& operator=(const InternalError&);
+  };
+}
+
+#define InternalError(msg) InternalError(msg, __FILE__, __LINE__)
+
+#endif
+
+

Added: trunk/Core/Exceptions/InvalidState.cc
==============================================================================
--- (empty file)
+++ trunk/Core/Exceptions/InvalidState.cc       Mon Nov 26 21:56:50 2007
@@ -0,0 +1,82 @@
+/*
+   For more information, please see: http://software.sci.utah.edu
+
+   The MIT License
+
+   Copyright (c) 2004 Scientific Computing and Imaging Institute,
+   University of Utah.
+
+   License for the specific language governing rights and limitations under
+   Permission is hereby granted, free of charge, to any person obtaining a
+   copy of this software and associated documentation files (the "Software"),
+   to deal in the Software without restriction, including without limitation
+   the rights to use, copy, modify, merge, publish, distribute, sublicense,
+   and/or sell copies of the Software, and to permit persons to whom the
+   Software is furnished to do so, subject to the following conditions:
+
+   The above copyright notice and this permission notice shall be included
+   in all copies or substantial portions of the Software.
+
+   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+   OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 
MERCHANTABILITY,
+   FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+   THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+   LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+   FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+   DEALINGS IN THE SOFTWARE.
+*/
+
+
+/*
+ *  InvalidState.h: Generic exception for internal errors
+ *
+ *  Written by:
+ *   Steven G. Parker
+ *   Department of Computer Science
+ *   University of Utah
+ *   July 1999
+ *
+ *  Copyright (C) 1999 SCI Group
+ */
+
+#include <Core/Exceptions/InvalidState.h>
+#include <iostream>
+#include <sstream>
+#undef InvalidState
+
+namespace Manta {
+
+
+InvalidState::InvalidState(const std::string& message, const char* file, int 
line)
+    : message_(message)
+{
+  std::ostringstream s;
+  s << "An InvalidState exception was thrown.\n"
+    << file << ":" << line << "\n";
+  message_ = (char*)(s.str().c_str());
+
+#ifdef EXCEPTIONS_CRASH
+  std::cout << message_ << "\n";
+#endif
+}
+
+InvalidState::InvalidState(const InvalidState& copy)
+    : message_(copy.message_)
+{
+}
+
+InvalidState::~InvalidState()
+{
+}
+
+const char* InvalidState::message() const
+{
+    return message_.c_str();
+}
+
+const char* InvalidState::type() const
+{
+    return "InvalidState";
+}
+
+} // End namespace Manta

Added: trunk/Core/Exceptions/InvalidState.h
==============================================================================
--- (empty file)
+++ trunk/Core/Exceptions/InvalidState.h        Mon Nov 26 21:56:50 2007
@@ -0,0 +1,69 @@
+/*
+   For more information, please see: http://software.sci.utah.edu
+
+   The MIT License
+
+   Copyright (c) 2004 Scientific Computing and Imaging Institute,
+   University of Utah.
+
+   License for the specific language governing rights and limitations under
+   Permission is hereby granted, free of charge, to any person obtaining a
+   copy of this software and associated documentation files (the "Software"),
+   to deal in the Software without restriction, including without limitation
+   the rights to use, copy, modify, merge, publish, distribute, sublicense,
+   and/or sell copies of the Software, and to permit persons to whom the
+   Software is furnished to do so, subject to the following conditions:
+
+   The above copyright notice and this permission notice shall be included
+   in all copies or substantial portions of the Software.
+
+   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+   OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 
MERCHANTABILITY,
+   FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+   THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+   LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+   FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+   DEALINGS IN THE SOFTWARE.
+*/
+
+
+
+
+/*
+ *  InvalidState.h: Generic exception for internal errors
+ *
+ *  Written by:
+ *   Steven G. Parker
+ *   Department of Computer Science
+ *   University of Utah
+ *   July 1999
+ *
+ *  Copyright (C) 1999 SCI Group
+ */
+
+#ifndef Core_Exceptions_InvalidState_h
+#define Core_Exceptions_InvalidState_h
+
+#include <Core/Exceptions/Exception.h>
+#include <string>
+
+namespace Manta {
+  class InvalidState : public Exception {
+  public:
+    InvalidState(const std::string&, const char* file, int line);
+    InvalidState(const InvalidState&);
+    virtual ~InvalidState();
+    virtual const char* message() const;
+    virtual const char* type() const;
+  protected:
+  private:
+    std::string message_;
+    InvalidState& operator=(const InvalidState&);
+  };
+} // End namespace Manta
+
+#define InvalidState(msg) InvalidState(msg, __FILE__, __LINE__)
+
+#endif
+
+

Modified: trunk/Core/Exceptions/OutputError.h
==============================================================================
--- trunk/Core/Exceptions/OutputError.h (original)
+++ trunk/Core/Exceptions/OutputError.h Mon Nov 26 21:56:50 2007
@@ -33,16 +33,14 @@
 #define Manta_Core_OutputError_h
 
 #include <Core/Exceptions/Exception.h>
-#include <sgi_stl_warnings_off.h>
 #include <string>
-#include <sgi_stl_warnings_on.h>
 
 namespace Manta {
   using namespace std;
 
   // Output errors are thrown when a non-fatal problem associated
   // with writing out data is encountered.
-  class OutputError : public SCIRun::Exception {
+  class OutputError : public Exception {
   public:
     OutputError(const std::string&);
     OutputError(const OutputError&);

Modified: trunk/Core/Exceptions/SerializationError.h
==============================================================================
--- trunk/Core/Exceptions/SerializationError.h  (original)
+++ trunk/Core/Exceptions/SerializationError.h  Mon Nov 26 21:56:50 2007
@@ -31,15 +31,13 @@
 #define Manta_Core_SerializationError_h
 
 #include <Core/Exceptions/Exception.h>
-#include <sgi_stl_warnings_off.h>
 #include <string>
-#include <sgi_stl_warnings_on.h>
 
 namespace Manta {
 
   // Serialization Errors are thrown when a problem occurs reading or 
parsing some type
   // of input, such as a texture is encountered.
-  class SerializationError : public SCIRun::Exception {
+  class SerializationError : public Exception {
   public:
     SerializationError(const std::string&);
     SerializationError(const SerializationError&);

Added: trunk/Core/Exceptions/StackWalker.cc
==============================================================================
--- (empty file)
+++ trunk/Core/Exceptions/StackWalker.cc        Mon Nov 26 21:56:50 2007
@@ -0,0 +1,1228 @@
+/**********************************************************************
+ * 
+ * StackWalker.cpp
+ *
+ *
+ * History:
+ *  2005-07-27   v1    - First public release on http://www.codeproject.com/
+ *                       http://www.codeproject.com/threads/StackWalker.asp
+ *  2005-07-28   v2    - Changed the params of the constructor and 
ShowCallstack
+ *                       (to simplify the usage)
+ *  2005-08-01   v3    - Changed to use 'CONTEXT_FULL' instead of 
CONTEXT_ALL 
+ *                       (should also be enough)
+ *                     - Changed to compile correctly with the PSDK of VC7.0
+ *                       (GetFileVersionInfoSizeA and GetFileVersionInfoA is 
wrongly defined:
+ *                        it uses LPSTR instead of LPCSTR as first paremeter)
+ *                     - Added declarations to support VC5/6 without using 
'dbghelp.h'
+ *                     - Added a 'pUserData' member to the ShowCallstack 
function and the 
+ *                       PReadProcessMemoryRoutine declaration (to pass some 
user-defined data, 
+ *                       which can be used in the 
readMemoryFunction-callback)
+ *  2005-08-02   v4    - OnSymInit now also outputs the OS-Version by default
+ *                     - Added example for doing an 
exception-callstack-walking in main.cpp
+ *                       (thanks to owillebo: 
http://www.codeproject.com/script/profile/whos_who.asp?id=536268)
+ *  2005-08-05   v5    - Removed most Lint (http://www.gimpel.com/
errors... thanks to Okko Willeboordse!
+ *
+ **********************************************************************/
+#include <windows.h>
+#include <tchar.h>
+#include <stdio.h>
+#pragma comment(lib, "version.lib")  // for "VerQueryValue"
+
+#include "StackWalker.h"
+
+
+// If VC7 and later, then use the shipped 'dbghelp.h'-file
+#if _MSC_VER >= 1300
+#include <dbghelp.h>
+#else
+// inline the important dbghelp.h-declarations...
+typedef enum {
+    SymNone = 0,
+    SymCoff,
+    SymCv,
+    SymPdb,
+    SymExport,
+    SymDeferred,
+    SymSym,
+    SymDia,
+    SymVirtual,
+    NumSymTypes
+} SYM_TYPE;
+typedef struct _IMAGEHLP_LINE64 {
+    DWORD                       SizeOfStruct;           // set to 
sizeof(IMAGEHLP_LINE64)
+    PVOID                       Key;                    // internal
+    DWORD                       LineNumber;             // line number in 
file
+    PCHAR                       FileName;               // full filename
+    DWORD64                     Address;                // first instruction 
of line
+} IMAGEHLP_LINE64, *PIMAGEHLP_LINE64;
+typedef struct _IMAGEHLP_MODULE64 {
+    DWORD                       SizeOfStruct;           // set to 
sizeof(IMAGEHLP_MODULE64)
+    DWORD64                     BaseOfImage;            // base load address 
of module
+    DWORD                       ImageSize;              // virtual size of 
the loaded module
+    DWORD                       TimeDateStamp;          // date/time stamp 
from pe header
+    DWORD                       CheckSum;               // checksum from the 
pe header
+    DWORD                       NumSyms;                // number of symbols 
in the symbol table
+    SYM_TYPE                    SymType;                // type of symbols 
loaded
+    CHAR                        ModuleName[32];         // module name
+    CHAR                        ImageName[256];         // image name
+    CHAR                        LoadedImageName[256];   // symbol file name
+} IMAGEHLP_MODULE64, *PIMAGEHLP_MODULE64;
+typedef struct _IMAGEHLP_SYMBOL64 {
+    DWORD                       SizeOfStruct;           // set to 
sizeof(IMAGEHLP_SYMBOL64)
+    DWORD64                     Address;                // virtual address 
including dll base address
+    DWORD                       Size;                   // estimated size of 
symbol, can be zero
+    DWORD                       Flags;                  // info about the 
symbols, see the SYMF defines
+    DWORD                       MaxNameLength;          // maximum size of 
symbol name in 'Name'
+    CHAR                        Name[1];                // symbol name (null 
terminated string)
+} IMAGEHLP_SYMBOL64, *PIMAGEHLP_SYMBOL64;
+typedef enum {
+    AddrMode1616,
+    AddrMode1632,
+    AddrModeReal,
+    AddrModeFlat
+} ADDRESS_MODE;
+typedef struct _tagADDRESS64 {
+    DWORD64       Offset;
+    WORD          Segment;
+    ADDRESS_MODE  Mode;
+} ADDRESS64, *LPADDRESS64;
+typedef struct _KDHELP64 {
+    DWORD64   Thread;
+    DWORD   ThCallbackStack;
+    DWORD   ThCallbackBStore;
+    DWORD   NextCallback;
+    DWORD   FramePointer;
+    DWORD64   KiCallUserMode;
+    DWORD64   KeUserCallbackDispatcher;
+    DWORD64   SystemRangeStart;
+    DWORD64  Reserved[8];
+} KDHELP64, *PKDHELP64;
+typedef struct _tagSTACKFRAME64 {
+    ADDRESS64   AddrPC;               // program counter
+    ADDRESS64   AddrReturn;           // return address
+    ADDRESS64   AddrFrame;            // frame pointer
+    ADDRESS64   AddrStack;            // stack pointer
+    ADDRESS64   AddrBStore;           // backing store pointer
+    PVOID       FuncTableEntry;       // pointer to pdata/fpo or NULL
+    DWORD64     Params[4];            // possible arguments to the function
+    BOOL        Far;                  // WOW far call
+    BOOL        Virtual;              // is this a virtual frame?
+    DWORD64     Reserved[3];
+    KDHELP64    KdHelp;
+} STACKFRAME64, *LPSTACKFRAME64;
+typedef
+BOOL
+(__stdcall *PREAD_PROCESS_MEMORY_ROUTINE64)(
+    HANDLE      hProcess,
+    DWORD64     qwBaseAddress,
+    PVOID       lpBuffer,
+    DWORD       nSize,
+    LPDWORD     lpNumberOfBytesRead
+    );
+typedef
+PVOID
+(__stdcall *PFUNCTION_TABLE_ACCESS_ROUTINE64)(
+    HANDLE  hProcess,
+    DWORD64 AddrBase
+    );
+typedef
+DWORD64
+(__stdcall *PGET_MODULE_BASE_ROUTINE64)(
+    HANDLE  hProcess,
+    DWORD64 Address
+    );
+typedef
+DWORD64
+(__stdcall *PTRANSLATE_ADDRESS_ROUTINE64)(
+    HANDLE    hProcess,
+    HANDLE    hThread,
+    LPADDRESS64 lpaddr
+    );
+#define SYMOPT_CASE_INSENSITIVE         0x00000001
+#define SYMOPT_UNDNAME                  0x00000002
+#define SYMOPT_DEFERRED_LOADS           0x00000004
+#define SYMOPT_NO_CPP                   0x00000008
+#define SYMOPT_LOAD_LINES               0x00000010
+#define SYMOPT_OMAP_FIND_NEAREST        0x00000020
+#define SYMOPT_LOAD_ANYTHING            0x00000040
+#define SYMOPT_IGNORE_CVREC             0x00000080
+#define SYMOPT_NO_UNQUALIFIED_LOADS     0x00000100
+#define SYMOPT_FAIL_CRITICAL_ERRORS     0x00000200
+#define SYMOPT_EXACT_SYMBOLS            0x00000400
+#define SYMOPT_ALLOW_ABSOLUTE_SYMBOLS   0x00000800
+#define SYMOPT_IGNORE_NT_SYMPATH        0x00001000
+#define SYMOPT_INCLUDE_32BIT_MODULES    0x00002000
+#define SYMOPT_PUBLICS_ONLY             0x00004000
+#define SYMOPT_NO_PUBLICS               0x00008000
+#define SYMOPT_AUTO_PUBLICS             0x00010000
+#define SYMOPT_NO_IMAGE_SEARCH          0x00020000
+#define SYMOPT_SECURE                   0x00040000
+#define SYMOPT_DEBUG                    0x80000000
+#define UNDNAME_COMPLETE                 (0x0000)  // Enable full 
undecoration
+#define UNDNAME_NAME_ONLY                (0x1000)  // Crack only the name 
for primary declaration;
+#endif  // _MSC_VER < 1300
+
+// Some missing defines (for VC5/6):
+#ifndef INVALID_FILE_ATTRIBUTES
+#define INVALID_FILE_ATTRIBUTES ((DWORD)-1)
+#endif  
+
+
+// secure-CRT_functions are only available starting with VC8
+#if _MSC_VER < 1400
+#define strcpy_s strcpy
+#define strcat_s(dst, len, src) strcat(dst, src)
+#define _snprintf_s _snprintf
+#define _tcscat_s _tcscat
+#endif
+
+// Normally it should be enough to use 'CONTEXT_FULL' (better would be 
'CONTEXT_ALL')
+#define USED_CONTEXT_FLAGS CONTEXT_FULL
+
+
+class StackWalkerInternal
+{
+public:
+  StackWalkerInternal(StackWalker *parent, HANDLE hProcess)
+  {
+    m_parent = parent;
+    m_hDbhHelp = NULL;
+    pSC = NULL;
+    m_hProcess = hProcess;
+    m_szSymPath = NULL;
+    pSFTA = NULL;
+    pSGLFA = NULL;
+    pSGMB = NULL;
+    pSGMI = NULL;
+    pSGO = NULL;
+    pSGSFA = NULL;
+    pSI = NULL;
+    pSLM = NULL;
+    pSSO = NULL;
+    pSW = NULL;
+    pUDSN = NULL;
+    pSGSP = NULL;
+  }
+  ~StackWalkerInternal()
+  {
+    if (pSC != NULL)
+      pSC(m_hProcess);  // SymCleanup
+    if (m_hDbhHelp != NULL)
+      FreeLibrary(m_hDbhHelp);
+    m_hDbhHelp = NULL;
+    m_parent = NULL;
+    if(m_szSymPath != NULL)
+      free(m_szSymPath);
+    m_szSymPath = NULL;
+  }
+  BOOL Init(LPCSTR szSymPath)
+  {
+    if (m_parent == NULL)
+      return FALSE;
+    // Dynamically load the Entry-Points for dbghelp.dll:
+    // First try to load the newsest one from
+    TCHAR szTemp[4096];
+    // But before wqe do this, we first check if the ".local" file exists
+    if (GetModuleFileName(NULL, szTemp, 4096) > 0)
+    {
+      _tcscat_s(szTemp, _T(".local"));
+      if (GetFileAttributes(szTemp) == INVALID_FILE_ATTRIBUTES)
+      {
+        // ".local" file does not exist, so we can try to load the 
dbghelp.dll from the "Debugging Tools for Windows"
+        if (GetEnvironmentVariable(_T("ProgramFiles"), szTemp, 4096) > 0)
+        {
+          _tcscat_s(szTemp, _T("\\Debugging Tools for 
Windows\\dbghelp.dll"));
+          // now check if the file exists:
+          if (GetFileAttributes(szTemp) != INVALID_FILE_ATTRIBUTES)
+          {
+            m_hDbhHelp = LoadLibrary(szTemp);
+          }
+        }
+          // Still not found? Then try to load the 64-Bit version:
+        if ( (m_hDbhHelp == NULL) && 
(GetEnvironmentVariable(_T("ProgramFiles"), szTemp, 4096) > 0) )
+        {
+          _tcscat_s(szTemp, _T("\\Debugging Tools for Windows 
64-Bit\\dbghelp.dll"));
+          if (GetFileAttributes(szTemp) != INVALID_FILE_ATTRIBUTES)
+          {
+            m_hDbhHelp = LoadLibrary(szTemp);
+          }
+        }
+      }
+    }
+    if (m_hDbhHelp == NULL)  // if not already loaded, try to load a 
default-one
+      m_hDbhHelp = LoadLibrary( _T("dbghelp.dll") );
+    if (m_hDbhHelp == NULL)
+      return FALSE;
+    pSI = (tSI) GetProcAddress(m_hDbhHelp, "SymInitialize" );
+    pSC = (tSC) GetProcAddress(m_hDbhHelp, "SymCleanup" );
+
+    pSW = (tSW) GetProcAddress(m_hDbhHelp, "StackWalk64" );
+    pSGO = (tSGO) GetProcAddress(m_hDbhHelp, "SymGetOptions" );
+    pSSO = (tSSO) GetProcAddress(m_hDbhHelp, "SymSetOptions" );
+
+    pSFTA = (tSFTA) GetProcAddress(m_hDbhHelp, "SymFunctionTableAccess64" );
+    pSGLFA = (tSGLFA) GetProcAddress(m_hDbhHelp, "SymGetLineFromAddr64" );
+    pSGMB = (tSGMB) GetProcAddress(m_hDbhHelp, "SymGetModuleBase64" );
+    pSGMI = (tSGMI) GetProcAddress(m_hDbhHelp, "SymGetModuleInfo64" );
+    //pSGMI_V3 = (tSGMI_V3) GetProcAddress(m_hDbhHelp, "SymGetModuleInfo64" 
);
+    pSGSFA = (tSGSFA) GetProcAddress(m_hDbhHelp, "SymGetSymFromAddr64" );
+    pUDSN = (tUDSN) GetProcAddress(m_hDbhHelp, "UnDecorateSymbolName" );
+    pSLM = (tSLM) GetProcAddress(m_hDbhHelp, "SymLoadModule64" );
+    pSGSP =(tSGSP) GetProcAddress(m_hDbhHelp, "SymGetSearchPath" );
+
+    if ( pSC == NULL || pSFTA == NULL || pSGMB == NULL || pSGMI == NULL ||
+      pSGO == NULL || pSGSFA == NULL || pSI == NULL || pSSO == NULL ||
+      pSW == NULL || pUDSN == NULL || pSLM == NULL )
+    {
+      FreeLibrary(m_hDbhHelp);
+      m_hDbhHelp = NULL;
+      pSC = NULL;
+      return FALSE;
+    }
+
+    // SymInitialize
+    if (szSymPath != NULL)
+      m_szSymPath = _strdup(szSymPath);
+    if (this->pSI(m_hProcess, m_szSymPath, FALSE) == FALSE)
+      this->m_parent->OnDbgHelpErr("SymInitialize", GetLastError(), 0);
+      
+    DWORD symOptions = this->pSGO();  // SymGetOptions
+    symOptions |= SYMOPT_LOAD_LINES;
+    symOptions |= SYMOPT_FAIL_CRITICAL_ERRORS;
+    //symOptions |= SYMOPT_NO_PROMPTS;
+    // SymSetOptions
+    symOptions = this->pSSO(symOptions);
+
+    char buf[StackWalker::STACKWALK_MAX_NAMELEN] = {0};
+    if (this->pSGSP != NULL)
+    {
+      if (this->pSGSP(m_hProcess, buf, StackWalker::STACKWALK_MAX_NAMELEN) 
== FALSE)
+        this->m_parent->OnDbgHelpErr("SymGetSearchPath", GetLastError(), 0);
+    }
+    char szUserName[1024] = {0};
+    DWORD dwSize = 1024;
+    GetUserNameA(szUserName, &dwSize);
+    this->m_parent->OnSymInit(buf, symOptions, szUserName);
+
+    return TRUE;
+  }
+
+  StackWalker *m_parent;
+
+  HMODULE m_hDbhHelp;
+  HANDLE m_hProcess;
+  LPSTR m_szSymPath;
+
+/*typedef struct IMAGEHLP_MODULE64_V3 {
+    DWORD    SizeOfStruct;           // set to sizeof(IMAGEHLP_MODULE64)
+    DWORD64  BaseOfImage;            // base load address of module
+    DWORD    ImageSize;              // virtual size of the loaded module
+    DWORD    TimeDateStamp;          // date/time stamp from pe header
+    DWORD    CheckSum;               // checksum from the pe header
+    DWORD    NumSyms;                // number of symbols in the symbol table
+    SYM_TYPE SymType;                // type of symbols loaded
+    CHAR     ModuleName[32];         // module name
+    CHAR     ImageName[256];         // image name
+    // new elements: 07-Jun-2002
+    CHAR     LoadedImageName[256];   // symbol file name
+    CHAR     LoadedPdbName[256];     // pdb file name
+    DWORD    CVSig;                  // Signature of the CV record in the 
debug directories
+    CHAR         CVData[MAX_PATH * 3];   // Contents of the CV record
+    DWORD    PdbSig;                 // Signature of PDB
+    GUID     PdbSig70;               // Signature of PDB (VC 7 and up)
+    DWORD    PdbAge;                 // DBI age of pdb
+    BOOL     PdbUnmatched;           // loaded an unmatched pdb
+    BOOL     DbgUnmatched;           // loaded an unmatched dbg
+    BOOL     LineNumbers;            // we have line number information
+    BOOL     GlobalSymbols;          // we have internal symbol information
+    BOOL     TypeInfo;               // we have type information
+    // new elements: 17-Dec-2003
+    BOOL     SourceIndexed;          // pdb supports source server
+    BOOL     Publics;                // contains public symbols
+};
+*/
+typedef struct IMAGEHLP_MODULE64_V2 {
+    DWORD    SizeOfStruct;           // set to sizeof(IMAGEHLP_MODULE64)
+    DWORD64  BaseOfImage;            // base load address of module
+    DWORD    ImageSize;              // virtual size of the loaded module
+    DWORD    TimeDateStamp;          // date/time stamp from pe header
+    DWORD    CheckSum;               // checksum from the pe header
+    DWORD    NumSyms;                // number of symbols in the symbol table
+    SYM_TYPE SymType;                // type of symbols loaded
+    CHAR     ModuleName[32];         // module name
+    CHAR     ImageName[256];         // image name
+    CHAR     LoadedImageName[256];   // symbol file name
+};
+
+
+  // SymCleanup()
+  typedef BOOL (__stdcall *tSC)( IN HANDLE hProcess );
+  tSC pSC;
+
+  // SymFunctionTableAccess64()
+  typedef PVOID (__stdcall *tSFTA)( HANDLE hProcess, DWORD64 AddrBase );
+  tSFTA pSFTA;
+
+  // SymGetLineFromAddr64()
+  typedef BOOL (__stdcall *tSGLFA)( IN HANDLE hProcess, IN DWORD64 dwAddr,
+    OUT PDWORD pdwDisplacement, OUT PIMAGEHLP_LINE64 Line );
+  tSGLFA pSGLFA;
+
+  // SymGetModuleBase64()
+  typedef DWORD64 (__stdcall *tSGMB)( IN HANDLE hProcess, IN DWORD64 dwAddr 
);
+  tSGMB pSGMB;
+
+  // SymGetModuleInfo64()
+  typedef BOOL (__stdcall *tSGMI)( IN HANDLE hProcess, IN DWORD64 dwAddr, 
OUT IMAGEHLP_MODULE64_V2 *ModuleInfo );
+  tSGMI pSGMI;
+
+//  // SymGetModuleInfo64()
+//  typedef BOOL (__stdcall *tSGMI_V3)( IN HANDLE hProcess, IN DWORD64 
dwAddr, OUT IMAGEHLP_MODULE64_V3 *ModuleInfo );
+//  tSGMI_V3 pSGMI_V3;
+
+  // SymGetOptions()
+  typedef DWORD (__stdcall *tSGO)( VOID );
+  tSGO pSGO;
+
+  // SymGetSymFromAddr64()
+  typedef BOOL (__stdcall *tSGSFA)( IN HANDLE hProcess, IN DWORD64 dwAddr,
+    OUT PDWORD64 pdwDisplacement, OUT PIMAGEHLP_SYMBOL64 Symbol );
+  tSGSFA pSGSFA;
+
+  // SymInitialize()
+  typedef BOOL (__stdcall *tSI)( IN HANDLE hProcess, IN PSTR UserSearchPath, 
IN BOOL fInvadeProcess );
+  tSI pSI;
+
+  // SymLoadModule64()
+  typedef DWORD64 (__stdcall *tSLM)( IN HANDLE hProcess, IN HANDLE hFile,
+    IN PSTR ImageName, IN PSTR ModuleName, IN DWORD64 BaseOfDll, IN DWORD 
SizeOfDll );
+  tSLM pSLM;
+
+  // SymSetOptions()
+  typedef DWORD (__stdcall *tSSO)( IN DWORD SymOptions );
+  tSSO pSSO;
+
+  // StackWalk64()
+  typedef BOOL (__stdcall *tSW)( 
+    DWORD MachineType, 
+    HANDLE hProcess,
+    HANDLE hThread, 
+    LPSTACKFRAME64 StackFrame, 
+    PVOID ContextRecord,
+    PREAD_PROCESS_MEMORY_ROUTINE64 ReadMemoryRoutine,
+    PFUNCTION_TABLE_ACCESS_ROUTINE64 FunctionTableAccessRoutine,
+    PGET_MODULE_BASE_ROUTINE64 GetModuleBaseRoutine,
+    PTRANSLATE_ADDRESS_ROUTINE64 TranslateAddress );
+  tSW pSW;
+
+  // UnDecorateSymbolName()
+  typedef DWORD (__stdcall WINAPI *tUDSN)( PCSTR DecoratedName, PSTR 
UnDecoratedName,
+    DWORD UndecoratedLength, DWORD Flags );
+  tUDSN pUDSN;
+
+  typedef BOOL (__stdcall WINAPI *tSGSP)(HANDLE hProcess, PSTR SearchPath, 
DWORD SearchPathLength);
+  tSGSP pSGSP;
+
+
+private:
+  // **************************************** ToolHelp32 
************************
+  #define MAX_MODULE_NAME32 255
+  #define TH32CS_SNAPMODULE   0x00000008
+  #pragma pack( push, 8 )
+  typedef struct tagMODULEENTRY32
+  {
+      DWORD   dwSize;
+      DWORD   th32ModuleID;       // This module
+      DWORD   th32ProcessID;      // owning process
+      DWORD   GlblcntUsage;       // Global usage count on the module
+      DWORD   ProccntUsage;       // Module usage count in th32ProcessID's 
context
+      BYTE  * modBaseAddr;        // Base address of module in 
th32ProcessID's context
+      DWORD   modBaseSize;        // Size in bytes of module starting at 
modBaseAddr
+      HMODULE hModule;            // The hModule of this module in 
th32ProcessID's context
+      char    szModule[MAX_MODULE_NAME32 + 1];
+      char    szExePath[MAX_PATH];
+  } MODULEENTRY32;
+  typedef MODULEENTRY32 *  PMODULEENTRY32;
+  typedef MODULEENTRY32 *  LPMODULEENTRY32;
+  #pragma pack( pop )
+
+  BOOL GetModuleListTH32(HANDLE hProcess, DWORD pid)
+  {
+    // CreateToolhelp32Snapshot()
+    typedef HANDLE (__stdcall *tCT32S)(DWORD dwFlags, DWORD th32ProcessID);
+    // Module32First()
+    typedef BOOL (__stdcall *tM32F)(HANDLE hSnapshot, LPMODULEENTRY32 lpme);
+    // Module32Next()
+    typedef BOOL (__stdcall *tM32N)(HANDLE hSnapshot, LPMODULEENTRY32 lpme);
+
+    // try both dlls...
+    const TCHAR *dllname[] = { _T("kernel32.dll"), _T("tlhelp32.dll") };
+    HINSTANCE hToolhelp = NULL;
+    tCT32S pCT32S = NULL;
+    tM32F pM32F = NULL;
+    tM32N pM32N = NULL;
+
+    HANDLE hSnap;
+    MODULEENTRY32 me;
+    me.dwSize = sizeof(me);
+    BOOL keepGoing;
+    size_t i;
+
+    for (i = 0; i<(sizeof(dllname) / sizeof(dllname[0])); i++ )
+    {
+      hToolhelp = LoadLibrary( dllname[i] );
+      if (hToolhelp == NULL)
+        continue;
+      pCT32S = (tCT32S) GetProcAddress(hToolhelp, 
"CreateToolhelp32Snapshot");
+      pM32F = (tM32F) GetProcAddress(hToolhelp, "Module32First");
+      pM32N = (tM32N) GetProcAddress(hToolhelp, "Module32Next");
+      if ( (pCT32S != NULL) && (pM32F != NULL) && (pM32N != NULL) )
+        break; // found the functions!
+      FreeLibrary(hToolhelp);
+      hToolhelp = NULL;
+    }
+
+    if (hToolhelp == NULL)
+      return FALSE;
+
+    hSnap = pCT32S( TH32CS_SNAPMODULE, pid );
+    if (hSnap == (HANDLE) -1)
+      return FALSE;
+
+    keepGoing = !!pM32F( hSnap, &me );
+    int cnt = 0;
+    while (keepGoing)
+    {
+      // don't know why, but we get problems with this one...
+      if (string(me.szExePath).find("ProblemSpecification") == string::npos 
&& 
+          string(me.szExePath).find("SimulationController") == string::npos) 
{
+        this->LoadModule(hProcess, me.szExePath, me.szModule, (DWORD64) 
me.modBaseAddr, me.modBaseSize);
+        cnt++;
+      }
+      keepGoing = !!pM32N( hSnap, &me );
+    }
+    CloseHandle(hSnap);
+    FreeLibrary(hToolhelp);
+    if (cnt <= 0)
+      return FALSE;
+    return TRUE;
+  }  // GetModuleListTH32
+
+  // **************************************** PSAPI ************************
+  typedef struct _MODULEINFO {
+      LPVOID lpBaseOfDll;
+      DWORD SizeOfImage;
+      LPVOID EntryPoint;
+  } MODULEINFO, *LPMODULEINFO;
+
+  BOOL GetModuleListPSAPI(HANDLE hProcess)
+  {
+    // EnumProcessModules()
+    typedef BOOL (__stdcall *tEPM)(HANDLE hProcess, HMODULE *lphModule, 
DWORD cb, LPDWORD lpcbNeeded );
+    // GetModuleFileNameEx()
+    typedef DWORD (__stdcall *tGMFNE)(HANDLE hProcess, HMODULE hModule, 
LPSTR lpFilename, DWORD nSize );
+    // GetModuleBaseName()
+    typedef DWORD (__stdcall *tGMBN)(HANDLE hProcess, HMODULE hModule, LPSTR 
lpFilename, DWORD nSize );
+    // GetModuleInformation()
+    typedef BOOL (__stdcall *tGMI)(HANDLE hProcess, HMODULE hModule, 
LPMODULEINFO pmi, DWORD nSize );
+
+    HINSTANCE hPsapi;
+    tEPM pEPM;
+    tGMFNE pGMFNE;
+    tGMBN pGMBN;
+    tGMI pGMI;
+
+    DWORD i;
+    //ModuleEntry e;
+    DWORD cbNeeded;
+    MODULEINFO mi;
+    HMODULE *hMods = 0;
+    char *tt = NULL;
+    char *tt2 = NULL;
+    const SIZE_T TTBUFLEN = 8096;
+    int cnt = 0;
+
+    hPsapi = LoadLibrary( _T("psapi.dll") );
+    if (hPsapi == NULL)
+      return FALSE;
+
+    pEPM = (tEPM) GetProcAddress( hPsapi, "EnumProcessModules" );
+    pGMFNE = (tGMFNE) GetProcAddress( hPsapi, "GetModuleFileNameExA" );
+    pGMBN = (tGMFNE) GetProcAddress( hPsapi, "GetModuleBaseNameA" );
+    pGMI = (tGMI) GetProcAddress( hPsapi, "GetModuleInformation" );
+    if ( (pEPM == NULL) || (pGMFNE == NULL) || (pGMBN == NULL) || (pGMI == 
NULL) )
+    {
+      // we couldn�t find all functions
+      FreeLibrary(hPsapi);
+      return FALSE;
+    }
+
+    hMods = (HMODULE*) malloc(sizeof(HMODULE) * (TTBUFLEN / sizeof HMODULE));
+    tt = (char*) malloc(sizeof(char) * TTBUFLEN);
+    tt2 = (char*) malloc(sizeof(char) * TTBUFLEN);
+    if ( (hMods == NULL) || (tt == NULL) || (tt2 == NULL) )
+      goto cleanup;
+
+    if ( ! pEPM( hProcess, hMods, TTBUFLEN, &cbNeeded ) )
+    {
+      //_ftprintf(fLogFile, _T("%lu: EPM failed, GetLastError = %lu\n"), 
g_dwShowCount, gle );
+      goto cleanup;
+    }
+
+    if ( cbNeeded > TTBUFLEN )
+    {
+      //_ftprintf(fLogFile, _T("%lu: More than %lu module handles. Huh?\n"), 
g_dwShowCount, lenof( hMods ) );
+      goto cleanup;
+    }
+
+    for ( i = 0; i < cbNeeded / sizeof hMods[0]; i++ )
+    {
+      // base address, size
+      pGMI(hProcess, hMods[i], &mi, sizeof mi );
+      // image file name
+      tt[0] = 0;
+      pGMFNE(hProcess, hMods[i], tt, TTBUFLEN );
+      // module name
+      tt2[0] = 0;
+      pGMBN(hProcess, hMods[i], tt2, TTBUFLEN );
+
+      DWORD dwRes = this->LoadModule(hProcess, tt, tt2, (DWORD64) 
mi.lpBaseOfDll, mi.SizeOfImage);
+      if (dwRes != ERROR_SUCCESS)
+        this->m_parent->OnDbgHelpErr("LoadModule", dwRes, 0);
+      cnt++;
+    }
+
+  cleanup:
+    if (hPsapi != NULL) FreeLibrary(hPsapi);
+    if (tt2 != NULL) free(tt2);
+    if (tt != NULL) free(tt);
+    if (hMods != NULL) free(hMods);
+
+    return cnt != 0;
+  }  // GetModuleListPSAPI
+
+  DWORD LoadModule(HANDLE hProcess, LPCSTR img, LPCSTR mod, DWORD64 
baseAddr, DWORD size)
+  {
+    CHAR *szImg = _strdup(img);
+    CHAR *szMod = _strdup(mod);
+    DWORD result = ERROR_SUCCESS;
+    if ( (szImg == NULL) || (szMod == NULL) )
+      result = ERROR_NOT_ENOUGH_MEMORY;
+    else
+    {
+      if (pSLM(hProcess, 0, szImg, szMod, baseAddr, size) == 0)
+        result = GetLastError();
+    }
+    ULONGLONG fileVersion = 0;
+    if ( (m_parent != NULL) && (szImg != NULL) )
+    {
+      // try to retrive the file-version:
+      if ( (this->m_parent->m_options & StackWalker::RetrieveFileVersion) != 
0)
+      {
+        VS_FIXEDFILEINFO *fInfo = NULL;
+        DWORD dwHandle;
+        DWORD dwSize = GetFileVersionInfoSizeA(szImg, &dwHandle);
+        if (dwSize > 0)
+        {
+          LPVOID vData = malloc(dwSize);
+          if (vData != NULL)
+          {
+            if (GetFileVersionInfoA(szImg, dwHandle, dwSize, vData) != 0)
+            {
+              UINT len;
+              TCHAR szSubBlock[] = _T("\\");
+              if (VerQueryValue(vData, szSubBlock, (LPVOID*) &fInfo, &len) 
== 0)
+                fInfo = NULL;
+              else
+              {
+                fileVersion = ((ULONGLONG)fInfo->dwFileVersionLS) + 
((ULONGLONG)fInfo->dwFileVersionMS << 32);
+              }
+            }
+            free(vData);
+          }
+        }
+      }
+
+      // Retrive some additional-infos about the module
+      IMAGEHLP_MODULE64_V2 Module;
+      const char *szSymType = "-unknown-";
+      if (this->GetModuleInfo(hProcess, baseAddr, &Module) != FALSE)
+      {
+        switch(Module.SymType)
+        {
+          case SymNone:
+            szSymType = "-nosymbols-";
+            break;
+          case SymCoff:
+            szSymType = "COFF";
+            break;
+          case SymCv:
+            szSymType = "CV";
+            break;
+          case SymPdb:
+            szSymType = "PDB";
+            break;
+          case SymExport:
+            szSymType = "-exported-";
+            break;
+          case SymDeferred:
+            szSymType = "-deferred-";
+            break;
+          case SymSym:
+            szSymType = "SYM";
+            break;
+          case 8: //SymVirtual:
+            szSymType = "Virtual";
+            break;
+          case 9: // SymDia:
+            szSymType = "DIA";
+            break;
+        }
+      }
+      this->m_parent->OnLoadModule(img, mod, baseAddr, size, result, 
szSymType, Module.LoadedImageName, fileVersion);
+    }
+    if (szImg != NULL) free(szImg);
+    if (szMod != NULL) free(szMod);
+    return result;
+  }
+public:
+  BOOL LoadModules(HANDLE hProcess, DWORD dwProcessId)
+  {
+    // first try toolhelp32
+    if (GetModuleListTH32(hProcess, dwProcessId))
+      return true;
+    // then try psapi
+    return GetModuleListPSAPI(hProcess);
+  }
+
+
+  BOOL GetModuleInfo(HANDLE hProcess, DWORD64 baseAddr, IMAGEHLP_MODULE64_V2 
*pModuleInfo)
+  {
+    if(this->pSGMI == NULL)
+    {
+      SetLastError(ERROR_DLL_INIT_FAILED);
+      return FALSE;
+    }
+    // First try to use the larger ModuleInfo-Structure
+//    memset(pModuleInfo, 0, sizeof(IMAGEHLP_MODULE64_V3));
+//    pModuleInfo->SizeOfStruct = sizeof(IMAGEHLP_MODULE64_V3);
+//    if (this->pSGMI_V3 != NULL)
+//    {
+//      if (this->pSGMI_V3(hProcess, baseAddr, pModuleInfo) != FALSE)
+//        return TRUE;
+//      // check if the parameter was wrong (size is bad...)
+//      if (GetLastError() != ERROR_INVALID_PARAMETER)
+//        return FALSE;
+//    }
+    // could not retrive the bigger structure, try with the smaller one (as 
defined in VC7.1)...
+    pModuleInfo->SizeOfStruct = sizeof(IMAGEHLP_MODULE64_V2);
+    void *pData = malloc(4096); // reserve enough memory, so the bug in 
v6.3.5.1 does not lead to memory-overwrites...
+    if (pData == NULL)
+    {
+      SetLastError(ERROR_NOT_ENOUGH_MEMORY);
+      return FALSE;
+    }
+    memcpy(pData, pModuleInfo, sizeof(IMAGEHLP_MODULE64_V2));
+    if (this->pSGMI(hProcess, baseAddr, (IMAGEHLP_MODULE64_V2*) pData) != 
FALSE)
+    {
+      // only copy as much memory as is reserved...
+      memcpy(pModuleInfo, pData, sizeof(IMAGEHLP_MODULE64_V2));
+      pModuleInfo->SizeOfStruct = sizeof(IMAGEHLP_MODULE64_V2);
+      free(pData);
+      return TRUE;
+    }
+    free(pData);
+    SetLastError(ERROR_DLL_INIT_FAILED);
+    return FALSE;
+  }
+};
+
+// #############################################################
+StackWalker::StackWalker(DWORD dwProcessId, HANDLE hProcess)
+{
+  this->m_options = OptionsAll;
+  this->m_modulesLoaded = FALSE;
+  this->m_hProcess = hProcess;
+  this->m_sw = new StackWalkerInternal(this, this->m_hProcess);
+  this->m_dwProcessId = dwProcessId;
+  this->m_szSymPath = NULL;
+}
+StackWalker::StackWalker(int options, LPCSTR szSymPath, DWORD dwProcessId, 
HANDLE hProcess)
+{
+  this->m_options = options;
+  this->m_modulesLoaded = FALSE;
+  this->m_hProcess = hProcess;
+  this->m_sw = new StackWalkerInternal(this, this->m_hProcess);
+  this->m_dwProcessId = dwProcessId;
+  if (szSymPath != NULL)
+  {
+    this->m_szSymPath = _strdup(szSymPath);
+    this->m_options |= SymBuildPath;
+  }
+  else
+    this->m_szSymPath = NULL;
+}
+
+StackWalker::~StackWalker()
+{
+  if (m_szSymPath != NULL)
+    free(m_szSymPath);
+  m_szSymPath = NULL;
+  if (this->m_sw != NULL)
+    delete this->m_sw;
+  this->m_sw = NULL;
+}
+
+BOOL StackWalker::LoadModules()
+{
+  if (this->m_sw == NULL)
+  {
+    SetLastError(ERROR_DLL_INIT_FAILED);
+    return FALSE;
+  }
+  if (m_modulesLoaded != FALSE)
+    return TRUE;
+
+  // Build the sym-path:
+  char *szSymPath = NULL;
+  if ( (this->m_options & SymBuildPath) != 0)
+  {
+    const size_t nSymPathLen = 4096;
+    szSymPath = (char*) malloc(nSymPathLen);
+    if (szSymPath == NULL)
+    {
+      SetLastError(ERROR_NOT_ENOUGH_MEMORY);
+      return FALSE;
+    }
+    szSymPath[0] = 0;
+    // Now first add the (optional) provided sympath:
+    if (this->m_szSymPath != NULL)
+    {
+      strcat_s(szSymPath, nSymPathLen, this->m_szSymPath);
+      strcat_s(szSymPath, nSymPathLen, ";");
+    }
+
+    strcat_s(szSymPath, nSymPathLen, ".;");
+
+    const size_t nTempLen = 1024;
+    char szTemp[nTempLen];
+    // Now add the current directory:
+    if (GetCurrentDirectoryA(nTempLen, szTemp) > 0)
+    {
+      szTemp[nTempLen-1] = 0;
+      strcat_s(szSymPath, nSymPathLen, szTemp);
+      strcat_s(szSymPath, nSymPathLen, ";");
+    }
+
+    // Now add the path for the main-module:
+    if (GetModuleFileNameA(NULL, szTemp, nTempLen) > 0)
+    {
+      szTemp[nTempLen-1] = 0;
+      for (char *p = (szTemp+strlen(szTemp)-1); p >= szTemp; --p)
+      {
+        // locate the rightmost path separator
+        if ( (*p == '\\') || (*p == '/') || (*p == ':') )
+        {
+          *p = 0;
+          break;
+        }
+      }  // for (search for path separator...)
+      if (strlen(szTemp) > 0)
+      {
+        strcat_s(szSymPath, nSymPathLen, szTemp);
+        strcat_s(szSymPath, nSymPathLen, ";");
+      }
+    }
+    if (GetEnvironmentVariableA("_NT_SYMBOL_PATH", szTemp, nTempLen) > 0)
+    {
+      szTemp[nTempLen-1] = 0;
+      strcat_s(szSymPath, nSymPathLen, szTemp);
+      strcat_s(szSymPath, nSymPathLen, ";");
+    }
+    if (GetEnvironmentVariableA("_NT_ALTERNATE_SYMBOL_PATH", szTemp, 
nTempLen) > 0)
+    {
+      szTemp[nTempLen-1] = 0;
+      strcat_s(szSymPath, nSymPathLen, szTemp);
+      strcat_s(szSymPath, nSymPathLen, ";");
+    }
+    if (GetEnvironmentVariableA("SYSTEMROOT", szTemp, nTempLen) > 0)
+    {
+      szTemp[nTempLen-1] = 0;
+      strcat_s(szSymPath, nSymPathLen, szTemp);
+      strcat_s(szSymPath, nSymPathLen, ";");
+      // also add the "system32"-directory:
+      strcat_s(szTemp, nTempLen, "\\system32");
+      strcat_s(szSymPath, nSymPathLen, szTemp);
+      strcat_s(szSymPath, nSymPathLen, ";");
+    }
+
+    if ( (this->m_options & SymBuildPath) != 0)
+    {
+      if (GetEnvironmentVariableA("SYSTEMDRIVE", szTemp, nTempLen) > 0)
+      {
+        szTemp[nTempLen-1] = 0;
+        strcat_s(szSymPath, nSymPathLen, "SRV*");
+        strcat_s(szSymPath, nSymPathLen, szTemp);
+        strcat_s(szSymPath, nSymPathLen, "\\websymbols");
+        strcat_s(szSymPath, nSymPathLen, 
"*http://msdl.microsoft.com/download/symbols;";);
+      }
+      else
+        strcat_s(szSymPath, nSymPathLen, 
"SRV*c:\\websymbols*http://msdl.microsoft.com/download/symbols;";);
+    }
+  }
+
+  // First Init the whole stuff...
+  BOOL bRet = this->m_sw->Init(szSymPath);
+  if (szSymPath != NULL) free(szSymPath); szSymPath = NULL;
+  if (bRet == FALSE)
+  {
+    this->OnDbgHelpErr("Error while initializing dbghelp.dll", 0, 0);
+    SetLastError(ERROR_DLL_INIT_FAILED);
+    return FALSE;
+  }
+
+  bRet = this->m_sw->LoadModules(this->m_hProcess, this->m_dwProcessId);
+  if (bRet != FALSE)
+    m_modulesLoaded = TRUE;
+  return bRet;
+}
+
+
+// The following is used to pass the "userData"-Pointer to the user-provided 
readMemoryFunction
+// This has to be done due to a problem with the "hProcess"-parameter in 
x64...
+// Because this class is in no case multi-threading-enabled (because of the 
limitations 
+// of dbghelp.dll) it is "safe" to use a static-variable
+static StackWalker::PReadProcessMemoryRoutine s_readMemoryFunction = NULL;
+static LPVOID s_readMemoryFunction_UserData = NULL;
+
+BOOL StackWalker::ShowCallstack(HANDLE hThread, const CONTEXT *context, 
PReadProcessMemoryRoutine readMemoryFunction, LPVOID pUserData)
+{
+  ostr.clear(); // BJW
+  CONTEXT c;;
+  CallstackEntry csEntry;
+  IMAGEHLP_SYMBOL64 *pSym = NULL;
+  StackWalkerInternal::IMAGEHLP_MODULE64_V2 Module;
+  IMAGEHLP_LINE64 Line;
+  int frameNum;
+
+  if (m_modulesLoaded == FALSE)
+    this->LoadModules();  // ignore the result...
+
+  if (this->m_sw->m_hDbhHelp == NULL)
+  {
+    SetLastError(ERROR_DLL_INIT_FAILED);
+    return FALSE;
+  }
+
+  s_readMemoryFunction = readMemoryFunction;
+  s_readMemoryFunction_UserData = pUserData;
+
+  if (context == NULL)
+  {
+    // If no context is provided, capture the context
+    if (hThread == GetCurrentThread())
+    {
+      GET_CURRENT_CONTEXT(c, USED_CONTEXT_FLAGS);
+    }
+    else
+    {
+      SuspendThread(hThread);
+      memset(&c, 0, sizeof(CONTEXT));
+      c.ContextFlags = USED_CONTEXT_FLAGS;
+      if (GetThreadContext(hThread, &c) == FALSE)
+      {
+        ResumeThread(hThread);
+        return FALSE;
+      }
+    }
+  }
+  else
+    c = *context;
+
+  // init STACKFRAME for first call
+  STACKFRAME64 s; // in/out stackframe
+  memset(&s, 0, sizeof(s));
+  DWORD imageType;
+#ifdef _M_IX86
+  // normally, call ImageNtHeader() and use machine info from PE header
+  imageType = IMAGE_FILE_MACHINE_I386;
+  s.AddrPC.Offset = c.Eip;
+  s.AddrPC.Mode = AddrModeFlat;
+  s.AddrFrame.Offset = c.Ebp;
+  s.AddrFrame.Mode = AddrModeFlat;
+  s.AddrStack.Offset = c.Esp;
+  s.AddrStack.Mode = AddrModeFlat;
+#elif _M_X64
+  imageType = IMAGE_FILE_MACHINE_AMD64;
+  s.AddrPC.Offset = c.Rip;
+  s.AddrPC.Mode = AddrModeFlat;
+  s.AddrFrame.Offset = c.Rsp;
+  s.AddrFrame.Mode = AddrModeFlat;
+  s.AddrStack.Offset = c.Rsp;
+  s.AddrStack.Mode = AddrModeFlat;
+#elif _M_IA64
+  imageType = IMAGE_FILE_MACHINE_IA64;
+  s.AddrPC.Offset = c.StIIP;
+  s.AddrPC.Mode = AddrModeFlat;
+  s.AddrFrame.Offset = c.IntSp;
+  s.AddrFrame.Mode = AddrModeFlat;
+  s.AddrBStore.Offset = c.RsBSP;
+  s.AddrBStore.Mode = AddrModeFlat;
+  s.AddrStack.Offset = c.IntSp;
+  s.AddrStack.Mode = AddrModeFlat;
+#else
+#error "Platform not supported!"
+#endif
+
+  pSym = (IMAGEHLP_SYMBOL64 *) malloc(sizeof(IMAGEHLP_SYMBOL64) + 
STACKWALK_MAX_NAMELEN);
+  if (!pSym) goto cleanup;  // not enough memory...
+  memset(pSym, 0, sizeof(IMAGEHLP_SYMBOL64) + STACKWALK_MAX_NAMELEN);
+  pSym->SizeOfStruct = sizeof(IMAGEHLP_SYMBOL64);
+  pSym->MaxNameLength = STACKWALK_MAX_NAMELEN;
+
+  memset(&Line, 0, sizeof(Line));
+  Line.SizeOfStruct = sizeof(Line);
+
+  memset(&Module, 0, sizeof(Module));
+  Module.SizeOfStruct = sizeof(Module);
+
+  for (frameNum = 0; ; ++frameNum )
+  {
+    // get next stack frame (StackWalk64(), SymFunctionTableAccess64(), 
SymGetModuleBase64())
+    // if this returns ERROR_INVALID_ADDRESS (487) or ERROR_NOACCESS (998), 
you can
+    // assume that either you are done, or that the stack is so hosed that 
the next
+    // deeper frame could not be found.
+    // CONTEXT need not to be suplied if imageTyp is IMAGE_FILE_MACHINE_I386!
+    if ( ! this->m_sw->pSW(imageType, this->m_hProcess, hThread, &s, &c, 
myReadProcMem, this->m_sw->pSFTA, this->m_sw->pSGMB, NULL) )
+    {
+      this->OnDbgHelpErr("StackWalk64", GetLastError(), s.AddrPC.Offset);
+      break;
+    }
+
+    csEntry.offset = s.AddrPC.Offset;
+    csEntry.name[0] = 0;
+    csEntry.undName[0] = 0;
+    csEntry.undFullName[0] = 0;
+    csEntry.offsetFromSmybol = 0;
+    csEntry.offsetFromLine = 0;
+    csEntry.lineFileName[0] = 0;
+    csEntry.lineNumber = 0;
+    csEntry.loadedImageName[0] = 0;
+    csEntry.moduleName[0] = 0;
+    if (s.AddrPC.Offset == s.AddrReturn.Offset)
+    {
+      this->OnDbgHelpErr("StackWalk64-Endless-Callstack!", 0, 
s.AddrPC.Offset);
+      break;
+    }
+    if (s.AddrPC.Offset != 0)
+    {
+      // we seem to have a valid PC
+      // show procedure info (SymGetSymFromAddr64())
+      if (this->m_sw->pSGSFA(this->m_hProcess, s.AddrPC.Offset, 
&(csEntry.offsetFromSmybol), pSym) != FALSE)
+      {
+        // TODO: Mache dies sicher...!
+        strcpy_s(csEntry.name, pSym->Name);
+        // UnDecorateSymbolName()
+        this->m_sw->pUDSN( pSym->Name, csEntry.undName, 
STACKWALK_MAX_NAMELEN, UNDNAME_NAME_ONLY );
+        this->m_sw->pUDSN( pSym->Name, csEntry.undFullName, 
STACKWALK_MAX_NAMELEN, UNDNAME_COMPLETE );
+      }
+      else
+      {
+        this->OnDbgHelpErr("SymGetSymFromAddr64", GetLastError(), 
s.AddrPC.Offset);
+      }
+
+      // show line number info, NT5.0-method (SymGetLineFromAddr64())
+      if (this->m_sw->pSGLFA != NULL )
+      { // yes, we have SymGetLineFromAddr64()
+        if (this->m_sw->pSGLFA(this->m_hProcess, s.AddrPC.Offset, 
&(csEntry.offsetFromLine), &Line) != FALSE)
+        {
+          csEntry.lineNumber = Line.LineNumber;
+          // TODO: Mache dies sicher...!
+          strcpy_s(csEntry.lineFileName, Line.FileName);
+        }
+        else
+        {
+          this->OnDbgHelpErr("SymGetLineFromAddr64", GetLastError(), 
s.AddrPC.Offset);
+        }
+      } // yes, we have SymGetLineFromAddr64()
+
+      // show module info (SymGetModuleInfo64())
+      if (this->m_sw->GetModuleInfo(this->m_hProcess, s.AddrPC.Offset, 
&Module ) != FALSE)
+      { // got module info OK
+        switch ( Module.SymType )
+        {
+        case SymNone:
+          csEntry.symTypeString = "-nosymbols-";
+          break;
+        case SymCoff:
+          csEntry.symTypeString = "COFF";
+          break;
+        case SymCv:
+          csEntry.symTypeString = "CV";
+          break;
+        case SymPdb:
+          csEntry.symTypeString = "PDB";
+          break;
+        case SymExport:
+          csEntry.symTypeString = "-exported-";
+          break;
+        case SymDeferred:
+          csEntry.symTypeString = "-deferred-";
+          break;
+        case SymSym:
+          csEntry.symTypeString = "SYM";
+          break;
+#if API_VERSION_NUMBER >= 9
+        case SymDia:
+          csEntry.symTypeString = "DIA";
+          break;
+#endif
+        case 8: //SymVirtual:
+          csEntry.symTypeString = "Virtual";
+          break;
+        default:
+          //_snprintf( ty, sizeof ty, "symtype=%ld", (long) Module.SymType );
+          csEntry.symTypeString = NULL;
+          break;
+        }
+
+        // TODO: Mache dies sicher...!
+        strcpy_s(csEntry.moduleName, Module.ModuleName);
+        csEntry.baseOfImage = Module.BaseOfImage;
+        strcpy_s(csEntry.loadedImageName, Module.LoadedImageName);
+      } // got module info OK
+      else
+      {
+        this->OnDbgHelpErr("SymGetModuleInfo64", GetLastError(), 
s.AddrPC.Offset);
+      }
+    } // we seem to have a valid PC
+
+    CallstackEntryType et = nextEntry;
+    if (frameNum == 0)
+      et = firstEntry;
+    this->OnCallstackEntry(et, csEntry);
+    
+    if (s.AddrReturn.Offset == 0)
+    {
+      this->OnCallstackEntry(lastEntry, csEntry);
+      SetLastError(ERROR_SUCCESS);
+      break;
+    }
+  } // for ( frameNum )
+
+  cleanup:
+    if (pSym) free( pSym );
+
+  if (context == NULL)
+    ResumeThread(hThread);
+
+  return TRUE;
+}
+
+BOOL __stdcall StackWalker::myReadProcMem(
+    HANDLE      hProcess,
+    DWORD64     qwBaseAddress,
+    PVOID       lpBuffer,
+    DWORD       nSize,
+    LPDWORD     lpNumberOfBytesRead
+    )
+{
+  if (s_readMemoryFunction == NULL)
+  {
+    SIZE_T st;
+    BOOL bRet = ReadProcessMemory(hProcess, (LPVOID) qwBaseAddress, 
lpBuffer, nSize, &st);
+    *lpNumberOfBytesRead = (DWORD) st;
+    //printf("ReadMemory: hProcess: %p, baseAddr: %p, buffer: %p, size: %d, 
read: %d, result: %d\n", hProcess, (LPVOID) qwBaseAddress, lpBuffer, nSize, 
(DWORD) st, (DWORD) bRet);
+    return bRet;
+  }
+  else
+  {
+    return s_readMemoryFunction(hProcess, qwBaseAddress, lpBuffer, nSize, 
lpNumberOfBytesRead, s_readMemoryFunction_UserData);
+  }
+}
+
+void StackWalker::OnLoadModule(LPCSTR img, LPCSTR mod, DWORD64 baseAddr, 
DWORD size, DWORD result, LPCSTR symType, LPCSTR pdbName, ULONGLONG 
fileVersion)
+{
+  CHAR buffer[STACKWALK_MAX_NAMELEN];
+  if (fileVersion == 0) {
+    //_snprintf_s(buffer, STACKWALK_MAX_NAMELEN, "%s:%s (%p), size: %d 
(result: %d), SymType: '%s', PDB: '%s'\n", img, mod, (LPVOID) baseAddr, size, 
result, symType, pdbName);
+  }
+  else
+  {
+    DWORD v4 = (DWORD) fileVersion & 0xFFFF;
+    DWORD v3 = (DWORD) (fileVersion>>16) & 0xFFFF;
+    DWORD v2 = (DWORD) (fileVersion>>32) & 0xFFFF;
+    DWORD v1 = (DWORD) (fileVersion>>48) & 0xFFFF;
+    _snprintf_s(buffer, STACKWALK_MAX_NAMELEN, "%s:%s (%p), size: %d 
(result: %d), SymType: '%s', PDB: '%s', fileVersion: %d.%d.%d.%d\n", img, 
mod, (LPVOID) baseAddr, size, result, symType, pdbName, v1, v2, v3, v4);
+  }
+  //onoutput(buffer);
+}
+
+void StackWalker::OnCallstackEntry(CallstackEntryType eType, CallstackEntry 
&entry)
+{
+  CHAR buffer[STACKWALK_MAX_NAMELEN];
+  if ( (eType != lastEntry) && (entry.offset != 0) )
+  {
+    if (entry.name[0] == 0)
+      strcpy_s(entry.name, "(function-name not available)");
+    if (entry.undName[0] != 0)
+      strcpy_s(entry.name, entry.undName);
+    if (entry.undFullName[0] != 0)
+      strcpy_s(entry.name, entry.undFullName);
+    if (entry.lineFileName[0] == 0)
+    {
+      strcpy_s(entry.lineFileName, "(filename not available)");
+      if (entry.moduleName[0] == 0)
+        strcpy_s(entry.moduleName, "(module-name not available)");
+      _snprintf_s(buffer, STACKWALK_MAX_NAMELEN, "%p (%s): %s: %s\n", 
(LPVOID) entry.offset, entry.moduleName, entry.lineFileName, entry.name);
+    }
+    else {
+      _snprintf_s(buffer, STACKWALK_MAX_NAMELEN, "%s (%d): %s\n", 
entry.lineFileName, entry.lineNumber, entry.name);
+    }
+    OnOutput(buffer);
+  }
+}
+
+void StackWalker::OnDbgHelpErr(LPCSTR szFuncName, DWORD gle, DWORD64 addr)
+{
+  CHAR buffer[STACKWALK_MAX_NAMELEN];
+  //_snprintf_s(buffer, STACKWALK_MAX_NAMELEN, "ERROR: %s, GetLastError: %d 
(Address: %p)\n", szFuncName, gle, (LPVOID) addr);
+  //OnOutput(buffer);
+}
+
+void StackWalker::OnSymInit(LPCSTR szSearchPath, DWORD symOptions, LPCSTR 
szUserName)
+{
+  CHAR buffer[STACKWALK_MAX_NAMELEN];
+  //_snprintf_s(buffer, STACKWALK_MAX_NAMELEN, "SymInit: Symbol-SearchPath: 
'%s', symOptions: %d, UserName: '%s'\n", szSearchPath, symOptions, 
szUserName);
+  //OnOutput(buffer);
+  // Also display the OS-version
+#if _MSC_VER <= 1200
+  OSVERSIONINFOA ver;
+  ZeroMemory(&ver, sizeof(OSVERSIONINFOA));
+  ver.dwOSVersionInfoSize = sizeof(ver);
+  if (GetVersionExA(&ver) != FALSE)
+  {
+    //_snprintf_s(buffer, STACKWALK_MAX_NAMELEN, "OS-Version: %d.%d.%d 
(%s)\n", 
+      ver.dwMajorVersion, ver.dwMinorVersion, ver.dwBuildNumber,
+      ver.szCSDVersion);
+    //OnOutput(buffer);
+  }
+#else
+  OSVERSIONINFOEXA ver;
+  ZeroMemory(&ver, sizeof(OSVERSIONINFOEXA));
+  ver.dwOSVersionInfoSize = sizeof(ver);
+  if (GetVersionExA( (OSVERSIONINFOA*) &ver) != FALSE)
+  {
+    //_snprintf_s(buffer, STACKWALK_MAX_NAMELEN, "OS-Version: %d.%d.%d (%s) 
0x%x-0x%x\n", 
+      //ver.dwMajorVersion, ver.dwMinorVersion, ver.dwBuildNumber,
+      //ver.szCSDVersion, ver.wSuiteMask, ver.wProductType);
+    //OnOutput(buffer);
+  }
+#endif
+}
+
+void StackWalker::OnOutput(LPCSTR buffer)
+{
+  //fprintf(stderr, buffer);
+  ostr << buffer;
+}

Added: trunk/Core/Exceptions/StackWalker.h
==============================================================================
--- (empty file)
+++ trunk/Core/Exceptions/StackWalker.h Mon Nov 26 21:56:50 2007
@@ -0,0 +1,199 @@
+/**********************************************************************
+ * 
+ * StackWalker.h
+ *
+ *
+ * History:
+ *  2005-07-27   v1    - First public release on http://www.codeproject.com/
+ *  (for additional changes see History in 'StackWalker.cpp'!
+ *
+ **********************************************************************/
+// #pragma once is supported starting with _MCS_VER 1000, 
+// so we need not to check the version (because we only support _MSC_VER >= 
1100)!
+#pragma once
+
+#include <windows.h>
+
+// special defines for VC5/6 (if no actual PSDK is installed):
+#if _MSC_VER < 1300
+typedef unsigned __int64 DWORD64, *PDWORD64;
+#if defined(_WIN64)
+typedef unsigned __int64 SIZE_T, *PSIZE_T;
+#else
+typedef unsigned long SIZE_T, *PSIZE_T;
+#endif
+#endif  // _MSC_VER < 1300
+
+#include <sstream>
+using std::string;
+using std::ostringstream;
+
+class StackWalkerInternal;  // forward
+class StackWalker
+{
+public:
+  typedef enum StackWalkOptions
+  {
+    // No addition info will be retrived 
+    // (only the address is available)
+    RetrieveNone = 0,
+    
+    // Try to get the symbol-name
+    RetrieveSymbol = 1,
+    
+    // Try to get the line for this symbol
+    RetrieveLine = 2,
+    
+    // Try to retrieve the module-infos
+    RetrieveModuleInfo = 4,
+    
+    // Also retrieve the version for the DLL/EXE
+    RetrieveFileVersion = 8,
+    
+    // Contains all the abouve
+    RetrieveVerbose = 0xF,
+    
+    // Generate a "good" symbol-search-path
+    SymBuildPath = 0x10,
+    
+    // Also use the public Microsoft-Symbol-Server
+    SymUseSymSrv = 0x20,
+    
+    // Contains all the abouve "Sym"-options
+    SymAll = 0x30,
+    
+    // Contains all options (default)
+    OptionsAll = 0x3F
+  } StackWalkOptions;
+
+  StackWalker(
+    int options = OptionsAll, // 'int' is by design, to combine the 
enum-flags
+    LPCSTR szSymPath = NULL, 
+    DWORD dwProcessId = GetCurrentProcessId(), 
+    HANDLE hProcess = GetCurrentProcess()
+    );
+  StackWalker(DWORD dwProcessId, HANDLE hProcess);
+  virtual ~StackWalker();
+
+  typedef BOOL (__stdcall *PReadProcessMemoryRoutine)(
+    HANDLE      hProcess,
+    DWORD64     qwBaseAddress,
+    PVOID       lpBuffer,
+    DWORD       nSize,
+    LPDWORD     lpNumberOfBytesRead,
+    LPVOID      pUserData  // optional data, which was passed in 
"ShowCallstack"
+    );
+
+  BOOL LoadModules();
+
+  BOOL ShowCallstack(
+    HANDLE hThread = GetCurrentThread(), 
+    const CONTEXT *context = NULL, 
+    PReadProcessMemoryRoutine readMemoryFunction = NULL,
+    LPVOID pUserData = NULL  // optional to identify some data in the 
'readMemoryFunction'-callback
+    );
+
+  // added by BJW
+  string GetCallstack(void* context = 0) { ShowCallstack(GetCurrentThread(), 
(CONTEXT*)context); return ostr.str(); }
+
+#if _MSC_VER >= 1300
+// due to some reasons, the "STACKWALK_MAX_NAMELEN" must be declared as 
"public" 
+// in older compilers in order to use it... starting with VC7 we can declare 
it as "protected"
+protected:
+#endif
+       enum { STACKWALK_MAX_NAMELEN = 1024 }; // max name length for found 
symbols
+
+protected:
+  // Entry for each Callstack-Entry
+  typedef struct CallstackEntry
+  {
+    DWORD64 offset;  // if 0, we have no valid entry
+    CHAR name[STACKWALK_MAX_NAMELEN];
+    CHAR undName[STACKWALK_MAX_NAMELEN];
+    CHAR undFullName[STACKWALK_MAX_NAMELEN];
+    DWORD64 offsetFromSmybol;
+    DWORD offsetFromLine;
+    DWORD lineNumber;
+    CHAR lineFileName[STACKWALK_MAX_NAMELEN];
+    DWORD symType;
+    LPCSTR symTypeString;
+    CHAR moduleName[STACKWALK_MAX_NAMELEN];
+    DWORD64 baseOfImage;
+    CHAR loadedImageName[STACKWALK_MAX_NAMELEN];
+  } CallstackEntry;
+
+  typedef enum CallstackEntryType {firstEntry, nextEntry, lastEntry};
+
+  virtual void OnSymInit(LPCSTR szSearchPath, DWORD symOptions, LPCSTR 
szUserName);
+  virtual void OnLoadModule(LPCSTR img, LPCSTR mod, DWORD64 baseAddr, DWORD 
size, DWORD result, LPCSTR symType, LPCSTR pdbName, ULONGLONG fileVersion);
+  virtual void OnCallstackEntry(CallstackEntryType eType, CallstackEntry 
&entry);
+  virtual void OnDbgHelpErr(LPCSTR szFuncName, DWORD gle, DWORD64 addr);
+  virtual void OnOutput(LPCSTR szText);
+
+  StackWalkerInternal *m_sw;
+  HANDLE m_hProcess;
+  DWORD m_dwProcessId;
+  BOOL m_modulesLoaded;
+  LPSTR m_szSymPath;
+
+  int m_options;
+
+  static BOOL __stdcall myReadProcMem(HANDLE hProcess, DWORD64 
qwBaseAddress, PVOID lpBuffer, DWORD nSize, LPDWORD lpNumberOfBytesRead);
+
+  friend class StackWalkerInternal;
+
+  // added by BJW
+  ostringstream ostr;
+};
+
+
+// The "ugly" assembler-implementation is needed for systems before XP
+// If you have a new PSDK and you only compile for XP and later, then you 
can use 
+// the "RtlCaptureContext"
+// Currently there is no define which determines the PSDK-Version... 
+// So we just use the compiler-version (and assumes that the PSDK is 
+// the one which was installed by the VS-IDE)
+
+// INFO: If you want, you can use the RtlCaptureContext if you only target 
XP and later...
+//       But I currently use it in x64/IA64 environments...
+//#if defined(_M_IX86) && (_WIN32_WINNT <= 0x0500) && (_MSC_VER < 1400)
+
+#if defined(_M_IX86)
+#ifdef CURRENT_THREAD_VIA_EXCEPTION
+// TODO: The following is not a "good" implementation, 
+// because the callstack is only valid in the "__except" block...
+#define GET_CURRENT_CONTEXT(c, contextFlags) \
+  do { \
+    memset(&c, 0, sizeof(CONTEXT)); \
+    EXCEPTION_POINTERS *pExp = NULL; \
+    __try { \
+      throw 0; \
+    } __except( ( (pExp = GetExceptionInformation()) ? 
EXCEPTION_EXECUTE_HANDLER : EXCEPTION_EXECUTE_HANDLER)) {} \
+    if (pExp != NULL) \
+      memcpy(&c, pExp->ContextRecord, sizeof(CONTEXT)); \
+      c.ContextFlags = contextFlags; \
+  } while(0);
+#else
+// The following should be enough for walking the callstack...
+#define GET_CURRENT_CONTEXT(c, contextFlags) \
+  do { \
+    memset(&c, 0, sizeof(CONTEXT)); \
+    c.ContextFlags = contextFlags; \
+    __asm    call x \
+    __asm x: pop eax \
+    __asm    mov c.Eip, eax \
+    __asm    mov c.Ebp, ebp \
+    __asm    mov c.Esp, esp \
+  } while(0);
+#endif
+
+#else
+
+// The following is defined for x86 (XP and higher), x64 and IA64:
+#define GET_CURRENT_CONTEXT(c, contextFlags) \
+  do { \
+    memset(&c, 0, sizeof(CONTEXT)); \
+    c.ContextFlags = contextFlags; \
+    RtlCaptureContext(&c); \
+} while(0);
+#endif

Modified: trunk/Core/Exceptions/UnknownColor.h
==============================================================================
--- trunk/Core/Exceptions/UnknownColor.h        (original)
+++ trunk/Core/Exceptions/UnknownColor.h        Mon Nov 26 21:56:50 2007
@@ -3,13 +3,11 @@
 #define Manta_Core_UnknownColor_h
 
 #include <Core/Exceptions/Exception.h>
-#include <sgi_stl_warnings_off.h>
 #include <string>
-#include <sgi_stl_warnings_on.h>
 
 namespace Manta {
   using namespace std;
-  class UnknownColor : public SCIRun::Exception {
+  class UnknownColor : public Exception {
   public:
     UnknownColor(const std::string&);
     UnknownColor(const UnknownColor&);

Modified: trunk/Core/Exceptions/UnknownComponent.cc
==============================================================================
--- trunk/Core/Exceptions/UnknownComponent.cc   (original)
+++ trunk/Core/Exceptions/UnknownComponent.cc   Mon Nov 26 21:56:50 2007
@@ -1,9 +1,6 @@
 
 #include <Core/Exceptions/UnknownComponent.h>
-
-#include <sgi_stl_warnings_off.h>
 #include <sstream>
-#include <sgi_stl_warnings_on.h>
 
 using namespace Manta;
 using namespace std;

Modified: trunk/Core/Exceptions/UnknownComponent.h
==============================================================================
--- trunk/Core/Exceptions/UnknownComponent.h    (original)
+++ trunk/Core/Exceptions/UnknownComponent.h    Mon Nov 26 21:56:50 2007
@@ -3,13 +3,11 @@
 #define Manta_Core_UnknownComponent_h
 
 #include <Core/Exceptions/Exception.h>
-#include <sgi_stl_warnings_off.h>
 #include <string>
-#include <sgi_stl_warnings_on.h>
 
 namespace Manta {
   using namespace std;
-  class UnknownComponent : public SCIRun::Exception {
+  class UnknownComponent : public Exception {
   public:
     UnknownComponent(const std::string& error, const std::string& spec);
     UnknownComponent(const UnknownComponent&);

Copied: trunk/Core/Exceptions/UnknownPixelFormat.cc (from r1868, 
trunk/Core/Exceptions/UnknownPixel.cc)
==============================================================================
--- trunk/Core/Exceptions/UnknownPixel.cc       (original)
+++ trunk/Core/Exceptions/UnknownPixelFormat.cc Mon Nov 26 21:56:50 2007
@@ -27,32 +27,32 @@
   DEALINGS IN THE SOFTWARE.
 */
 
-#include <Core/Exceptions/UnknownPixel.h>
+#include <Core/Exceptions/UnknownPixelFormat.h>
 
 using namespace Manta;
 using namespace std;
 
-UnknownPixel::UnknownPixel(const std::string& msg)
+UnknownPixelFormat::UnknownPixelFormat(const std::string& msg)
   : message_(msg)
 {
 }
 
-UnknownPixel::UnknownPixel(const UnknownPixel& copy)
+UnknownPixelFormat::UnknownPixelFormat(const UnknownPixelFormat& copy)
     : message_(copy.message_)
 {
 }
 
-UnknownPixel::~UnknownPixel()
+UnknownPixelFormat::~UnknownPixelFormat()
 {
 }
 
-const char* UnknownPixel::message() const
+const char* UnknownPixelFormat::message() const
 {
     return message_.c_str();
 }
 
-const char* UnknownPixel::type() const
+const char* UnknownPixelFormat::type() const
 {
-    return "UnknownPixel";
+    return "UnknownPixelFormat";
 }
 

Copied: trunk/Core/Exceptions/UnknownPixelFormat.h (from r1868, 
trunk/Core/Exceptions/UnknownPixel.h)
==============================================================================
--- trunk/Core/Exceptions/UnknownPixel.h        (original)
+++ trunk/Core/Exceptions/UnknownPixelFormat.h  Mon Nov 26 21:56:50 2007
@@ -29,13 +29,11 @@
 
 // Abe Stephens, December 2005
 
-#ifndef Manta_Core_UnknownPixel_h
-#define Manta_Core_UnknownPixel_h
+#ifndef Manta_Core_UnknownPixelFormat_h
+#define Manta_Core_UnknownPixelFormat_h
 
 #include <Core/Exceptions/Exception.h>
-#include <sgi_stl_warnings_off.h>
 #include <string>
-#include <sgi_stl_warnings_on.h>
 
 namespace Manta {
   using namespace std;
@@ -43,17 +41,17 @@
   // Unknown pixel error is thrown if an output device is unable to handle
   // a certain pixel type. Usually RGB and RGBA for 8bit and float colors
   // are supported.
-  class UnknownPixel : public SCIRun::Exception {
+  class UnknownPixelFormat : public Exception {
   public:
-    UnknownPixel(const std::string&);
-    UnknownPixel(const UnknownPixel&);
-    virtual ~UnknownPixel();
+    UnknownPixelFormat(const std::string&);
+    UnknownPixelFormat(const UnknownPixelFormat&);
+    virtual ~UnknownPixelFormat();
     virtual const char* message() const;
     virtual const char* type() const;
   protected:
   private:
     std::string message_;
-    UnknownPixel& operator=(const UnknownPixel&);
+    UnknownPixelFormat& operator=(const UnknownPixelFormat&);
   };
 }
 

Modified: trunk/Core/Geometry/AffineTransform.h
==============================================================================
--- trunk/Core/Geometry/AffineTransform.h       (original)
+++ trunk/Core/Geometry/AffineTransform.h       Mon Nov 26 21:56:50 2007
@@ -32,10 +32,7 @@
 #include <MantaTypes.h>
 #include <Core/Geometry/Vector.h>
 #include <Core/Geometry/VectorT.h>
-
-#include <sgi_stl_warnings_off.h>
 #include <iosfwd>
-#include <sgi_stl_warnings_on.h>
 
 namespace Manta {
   /**

Modified: trunk/Core/Geometry/AffineTransformT.h
==============================================================================
--- trunk/Core/Geometry/AffineTransformT.h      (original)
+++ trunk/Core/Geometry/AffineTransformT.h      Mon Nov 26 21:56:50 2007
@@ -30,10 +30,7 @@
 #define Manta_Core_AffineTransformT_h
 
 #include <Core/Geometry/VectorT.h>
-
-#include <sgi_stl_warnings_off.h>
 #include <iosfwd>
-#include <sgi_stl_warnings_on.h>
 
 namespace Manta {
   /**

Modified: trunk/Core/Geometry/BBox.h
==============================================================================
--- trunk/Core/Geometry/BBox.h  (original)
+++ trunk/Core/Geometry/BBox.h  Mon Nov 26 21:56:50 2007
@@ -3,11 +3,9 @@
 #define Manta_Core_BBox_h
 
 #include <Core/Geometry/Vector.h>
-#include <SCIRun/Core/Math/Expon.h>
+#include <Core/Math/Expon.h>
 
-#include <sgi_stl_warnings_off.h>
 #include <limits>
-#include <sgi_stl_warnings_on.h>
 
 namespace Manta {
   class BBox {
@@ -77,9 +75,9 @@
     // n really needs to be normalize, or you could get NaNs when
     // taking the square root of a negative number.
     void extendByDisc(const Vector& p, const Vector& n, Real radius) {
-      Vector v(SCIRun::Sqrt(1-n.x()*n.x())*radius,
-               SCIRun::Sqrt(1-n.y()*n.y())*radius,
-               SCIRun::Sqrt(1-n.z()*n.z())*radius);
+      Vector v(Sqrt(1-n.x()*n.x())*radius,
+               Sqrt(1-n.y()*n.y())*radius,
+               Sqrt(1-n.z()*n.z())*radius);
       bounds[0] = Min(bounds[0], p-v);
       bounds[1] = Max(bounds[1], p+v);
     }

Modified: trunk/Core/Geometry/ScalarTransform1D.h
==============================================================================
--- trunk/Core/Geometry/ScalarTransform1D.h     (original)
+++ trunk/Core/Geometry/ScalarTransform1D.h     Mon Nov 26 21:56:50 2007
@@ -3,10 +3,8 @@
 #define Manta_Core_ScalarTransform1D_h
 
 #include <MantaTypes.h>
-#include <SCIRun/Core/Containers/Array1.h>
-#include <SCIRun/Core/Math/MiscMath.h>
-
-using SCIRun::Array1;
+#include <Core/Containers/Array1.h>
+#include <Core/Math/MiscMath.h>
 
 namespace Manta
 {
@@ -30,7 +28,7 @@
 
     inline int getBoundLookupIndex(const LType value) const {
       int idx=getLookupIndex(value);
-      return SCIRun::Clamp(idx, 0, results->size() - 1);
+      return Clamp(idx, 0, results->size() - 1);
     }
 
     inline RType lookupBound(const LType value) const {
@@ -40,7 +38,7 @@
     inline int getLookupIndex(const LType value, const LType min_,
                               const LType max_) const {
       int idx=static_cast<int>((value - min_)/(max_ - min_)*results->size() 
- 1);
-      return SCIRun::Clamp(index, 0, results->size() - 1);
+      return Clamp(index, 0, results->size() - 1);
     }
 
     inline RType lookup(const LType value, const LType min_,
@@ -49,7 +47,7 @@
     }
 
     inline RType lookupWithIndex(const int idx) const {
-      return (*results)[SCIRun::Clamp(idx, 0, results->size() - 1)];
+      return (*results)[Clamp(idx, 0, results->size() - 1)];
     }
 
     inline RType& operator[](const int idx) const {
@@ -58,7 +56,7 @@
 
     inline RType interpolate(const LType value) const {
       double step=(value - min)*inv_range*(results->size() - 1);
-      int x_low=SCIRun::Clamp((int)step, 0, results->size() - 2);
+      int x_low=Clamp((int)step, 0, results->size() - 2);
       double x_weight_low=(x_low + 1) - step;
       return (*results)[x_low]*x_weight_low +
         (*results)[x_low + 1]*(1 - x_weight_low);

Modified: trunk/Core/Geometry/Vector.cc
==============================================================================
--- trunk/Core/Geometry/Vector.cc       (original)
+++ trunk/Core/Geometry/Vector.cc       Mon Nov 26 21:56:50 2007
@@ -29,10 +29,7 @@
 
 #include <Core/Geometry/Vector.h>
 #include <Core/Persistent/ArchiveElement.h>
-
-#include <sgi_stl_warnings_off.h>
 #include <iostream>
-#include <sgi_stl_warnings_on.h>
 
 using namespace Manta;
 

Modified: trunk/Core/Geometry/Vector.h
==============================================================================
--- trunk/Core/Geometry/Vector.h        (original)
+++ trunk/Core/Geometry/Vector.h        Mon Nov 26 21:56:50 2007
@@ -43,10 +43,7 @@
 #include <Core/Math/MinMax.h>
 #include <Core/Math/MiscMath.h>
 #include <Core/Persistent/MantaRTTI.h>
-
-#include <sgi_stl_warnings_off.h>
 #include <iosfwd>
-#include <sgi_stl_warnings_on.h>
 
 namespace Manta {
   template<typename T, int Dim> class VectorT;
@@ -309,7 +306,7 @@
       Real sum = data[0]*data[0];
       sum += data[1]*data[1];
       sum += data[2]*data[2];
-      return SCIRun::Sqrt(sum);
+      return Sqrt(sum);
     }
     Real length2() const {
       Real sum = data[0]*data[0];
@@ -323,9 +320,9 @@
     // Because of this, we try to minimize the number of function
     // calls we make and do explicit inlining.
     Real normalize() {
-      Real l = SCIRun::Sqrt(data[0]*data[0] +
-                            data[1]*data[1] +
-                            data[2]*data[2]);
+      Real l = Sqrt(data[0]*data[0] +
+                    data[1]*data[1] +
+                    data[2]*data[2]);
       Real scale = 1/l;
       data[0] *= scale;
       data[1] *= scale;
@@ -333,9 +330,9 @@
       return l;
     }
     Vector normal() const {
-      Real l = SCIRun::Sqrt(data[0]*data[0] +
-                            data[1]*data[1] +
-                            data[2]*data[2]);
+      Real l = Sqrt(data[0]*data[0] +
+                    data[1]*data[1] +
+                    data[2]*data[2]);
       Real scale = 1/l;
       Vector result;
       result.data[0] = data[0] * scale;
@@ -406,9 +403,9 @@
 
     Vector absoluteValue() const {
       Vector result;
-      result.data[0] = SCIRun::Abs(data[0]);
-      result.data[1] = SCIRun::Abs(data[1]);
-      result.data[2] = SCIRun::Abs(data[2]);
+      result.data[0] = Abs(data[0]);
+      result.data[1] = Abs(data[1]);
+      result.data[2] = Abs(data[2]);
       return result;
     }
 
@@ -422,9 +419,9 @@
     Vector findPerpendicular() const {
       Vector result;
 #if 0
-      float a0 = SCIRun::Abs(data[0]);
-      float a1 = SCIRun::Abs(data[1]);
-      float a2 = SCIRun::Abs(data[2]);
+      float a0 = Abs(data[0]);
+      float a1 = Abs(data[1]);
+      float a2 = Abs(data[2]);
       if(a0 < a1){
         if(a0 < a2){
           // 0 smallest
@@ -543,7 +540,6 @@
 
   inline Vector Min(const Vector& v1, const Vector& v2)
   {
-    using SCIRun::Min;
     Vector result(Min(v1.data[0], v2.data[0]),
                   Min(v1.data[1], v2.data[1]),
                   Min(v1.data[2], v2.data[2]));
@@ -552,7 +548,6 @@
 
   inline Vector Max(const Vector& v1, const Vector& v2)
   {
-    using SCIRun::Max;
     Vector result(Max(v1.data[0], v2.data[0]),
                   Max(v1.data[1], v2.data[1]),
                   Max(v1.data[2], v2.data[2]));
@@ -561,7 +556,6 @@
 
   inline Vector Interpolate(const Vector& v1, const Vector& v2, Real weight)
   {
-    using SCIRun::Interpolate;
     Vector result(Interpolate(v1.data[0], v2.data[0], weight),
                   Interpolate(v1.data[1], v2.data[1], weight),
                   Interpolate(v1.data[2], v2.data[2], weight));
@@ -570,24 +564,21 @@
 
   inline Vector Interpolate(const Vector& v1, const Vector& v2, const 
Vector& weight)
   {
-    using SCIRun::Interpolate;
     Vector result(Interpolate(v1.data[0], v2.data[0], weight[0]),
                   Interpolate(v1.data[1], v2.data[1], weight[1]),
                   Interpolate(v1.data[2], v2.data[2], weight[2]));
     return result;
   }
 
-  std::ostream& operator<< (std::ostream& os, const Vector& v);
-  std::istream& operator>> (std::istream& is,       Vector& v);
-
-  MANTA_DECLARE_RTTI_BASECLASS(Vector, ConcreteClass, 
readwriteMethod_lightweight);
-}
-
-namespace SCIRun {
   inline Manta::Vector Sqrt(const Manta::Vector& v1)
   {
     return Manta::Vector(Sqrt(v1.data[0]), Sqrt(v1.data[1]), 
Sqrt(v1.data[2]));
   }
+
+  std::ostream& operator<< (std::ostream& os, const Vector& v);
+  std::istream& operator>> (std::istream& is,       Vector& v);
+
+  MANTA_DECLARE_RTTI_BASECLASS(Vector, ConcreteClass, 
readwriteMethod_lightweight);
 }
 
 #endif

Modified: trunk/Core/Geometry/VectorT.cc
==============================================================================
--- trunk/Core/Geometry/VectorT.cc      (original)
+++ trunk/Core/Geometry/VectorT.cc      Mon Nov 26 21:56:50 2007
@@ -28,10 +28,7 @@
 */
 
 #include <Core/Geometry/VectorT.h>
-
-#include <sgi_stl_warnings_off.h>
 #include <iostream>
-#include <sgi_stl_warnings_on.h>
 
 namespace Manta {
   template<typename T, int Dim>

Modified: trunk/Core/Geometry/VectorT.h
==============================================================================
--- trunk/Core/Geometry/VectorT.h       (original)
+++ trunk/Core/Geometry/VectorT.h       Mon Nov 26 21:56:50 2007
@@ -42,10 +42,7 @@
 #include <Core/Math/Expon.h>
 #include <Core/Math/MinMax.h>
 #include <Core/Math/MiscMath.h>
-
-#include <sgi_stl_warnings_off.h>
 #include <iosfwd>
-#include <sgi_stl_warnings_on.h>
 
 namespace Manta {
   template<typename T, int Dim>
@@ -308,7 +305,7 @@
       T sum = 0;
       for(int i=0;i<Dim;i++)
         sum += data[i]*data[i];
-      return SCIRun::Sqrt(sum);
+      return Sqrt(sum);
     }
     T length2() const {
       T sum = 0;
@@ -325,7 +322,7 @@
       T sum = 0;
       for(int i=0;i<Dim;i++)
         sum += data[i]*data[i];
-      T l = SCIRun::Sqrt(sum);
+      T l = Sqrt(sum);
       T scale = 1/l;
       for(int i=0;i<Dim;i++)
         data[i] *= scale;
@@ -335,7 +332,7 @@
       T sum = 0;
       for(int i=0;i<Dim;i++)
         sum += data[i]*data[i];
-      T l = SCIRun::Sqrt(sum);
+      T l = Sqrt(sum);
       T scale = 1/l;
       VectorT<T, Dim> result;
       for(int i=0;i<Dim;i++)
@@ -380,7 +377,7 @@
     VectorT<T, Dim> absoluteValue() const {
       VectorT<T, Dim> result;
       for(int i=0;i<Dim;i++)
-        result.data[i] = SCIRun::Abs(data[i]);
+        result.data[i] = Abs(data[i]);
       return result;
     }
 
@@ -461,7 +458,6 @@
   inline VectorT<T, Dim> Min(const VectorT<T, Dim>& v1,
                              const VectorT<T, Dim>& v2)
   {
-    using SCIRun::Min;
     VectorT<T, Dim> result;
     for(int i=0;i<Dim;i++)
       result[i] = Min(v1[i], v2[i]);
@@ -472,7 +468,6 @@
   inline VectorT<T, Dim> Max(const VectorT<T, Dim>& v1,
                              const VectorT<T, Dim>& v2)
   {
-    using SCIRun::Max;
     VectorT<T, Dim> result;
     for(int i=0;i<Dim;i++)
       result[i] = Max(v1[i], v2[i]);
@@ -484,7 +479,6 @@
                                      const VectorT<T, Dim>& p2,
                                      T weight)
   {
-    using SCIRun::Interpolate;
     VectorT<T, Dim> result;
     for(int i=0;i<Dim;i++)
       result[i] = Interpolate(p1[i], p2[i], weight);
@@ -496,7 +490,6 @@
                                      const VectorT<T, Dim>& p2,
                                      const VectorT<T, Dim>& weight)
   {
-    using SCIRun::Interpolate;
     VectorT<T, Dim> result;
     for(int i=0;i<Dim;i++)
       result[i] = Interpolate(p1[i], p2[i], weight[i]);
@@ -508,9 +501,7 @@
 
   template<typename T, int Dim>
   std::istream& operator>> (std::istream& is, VectorT<T,Dim>& v);
-}
 
-namespace SCIRun {
   template<typename T, int Dim>
     inline Manta::VectorT<T, Dim> Sqrt(const Manta::VectorT<T, Dim>& v1)
   {

Added: trunk/Core/Math/Expon.h
==============================================================================
--- (empty file)
+++ trunk/Core/Math/Expon.h     Mon Nov 26 21:56:50 2007
@@ -0,0 +1,190 @@
+/*
+   For more information, please see: http://software.sci.utah.edu
+
+   The MIT License
+
+   Copyright (c) 2004 Scientific Computing and Imaging Institute,
+   University of Utah.
+
+   License for the specific language governing rights and limitations under
+   Permission is hereby granted, free of charge, to any person obtaining a
+   copy of this software and associated documentation files (the "Software"),
+   to deal in the Software without restriction, including without limitation
+   the rights to use, copy, modify, merge, publish, distribute, sublicense,
+   and/or sell copies of the Software, and to permit persons to whom the
+   Software is furnished to do so, subject to the following conditions:
+
+   The above copyright notice and this permission notice shall be included
+   in all copies or substantial portions of the Software.
+
+   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+   OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 
MERCHANTABILITY,
+   FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+   THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+   LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+   FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+   DEALINGS IN THE SOFTWARE.
+*/
+
+
+
+/*
+ *  Expon.h: Interface to Exponentiation functions...
+ *
+ *  Written by:
+ *   Steven G. Parker
+ *   Department of Computer Science
+ *   University of Utah
+ *   March 1994
+ *
+ *  Copyright (C) 1994 SCI Group
+ */
+
+#ifndef Manta_Expon_h
+#define Manta_Expon_h
+
+#include <math.h>
+
+namespace Manta {
+
+  inline double Pow(double d, double p)
+  {
+    return pow(d,p);
+  }
+
+  inline float Pow(float d, float p)
+  {
+    return powf(d,p);
+  }
+
+  inline double Pow(double x, unsigned int p)
+  {
+    double result=1;
+    while(p){
+      if(p&1)
+        result*=x;
+      x*=x;
+      p>>=1;
+    }
+    return result;
+  }
+
+  inline double Pow(float x, unsigned int p)
+  {
+    float result=1;
+    while(p){
+      if(p&1)
+        result*=x;
+      x*=x;
+      p>>=1;
+    }
+    return result;
+  }
+
+  inline double Pow(double x, int p)
+  {
+    if(p < 0){
+      p=-p;
+      double result=1;
+      while(p){
+        if(p&1)
+          result*=x;
+        x*=x;
+        p>>=1;
+      }
+      return 1./result;
+    } else { 
+      double result=1;
+      while(p){
+        if(p&1)
+          result*=x;
+        x*=x;
+        p>>=1;
+      }
+      return result;
+    }
+  }
+
+  inline float Pow(float x, int p)
+  {
+    if(p < 0){
+      p=-p;
+      float result=1;
+      while(p){
+        if(p&1)
+          result*=x;
+        x*=x;
+        p>>=1;
+      }
+      return 1.f/result;
+    } else { 
+      float result=1;
+      while(p){
+        if(p&1)
+          result*=x;
+        x*=x;
+        p>>=1;
+      }
+      return result;
+    }
+  }
+
+  inline int Sqrt(int i)
+  {
+    return (int)sqrt((double)i);
+  }
+
+  inline long double Sqrt(long double d)
+  {
+    return sqrtl(d);
+  }
+
+  inline double Sqrt(double d)
+  {
+    return sqrt(d);
+  }
+
+  inline float Sqrt(float d)
+  {
+    return sqrtf(d);
+  }
+
+#if defined(linux)||defined(_WIN32)
+  inline double Cbrt(double d)
+  {
+    return pow(d, 1./3.);
+  }
+
+  inline long double Cbrt(long double d)
+  {
+    return powl(d, 1./3.);
+  }
+#else
+  inline double Cbrt(double d)
+  {
+    return cbrt(d);
+  }
+
+  inline long double Cbrt(long double d)
+  {
+    return cbrtl(d);
+  }
+#endif
+
+  inline double Sqr(double x)
+  {
+    return x*x;
+  }
+
+  inline double Exp(double x)
+  {
+    return exp(x);
+  }
+
+  inline float Exp(float x)
+  {
+    return expf(x);
+  }
+}
+
+#endif

Modified: trunk/Core/Math/KorobovRNG.h
==============================================================================
--- trunk/Core/Math/KorobovRNG.h        (original)
+++ trunk/Core/Math/KorobovRNG.h        Mon Nov 26 21:56:50 2007
@@ -102,8 +102,6 @@
       }
       if (packet_depth >= MAX_SAMPLE_DEPTH) {
         packet_depth %= MAX_SAMPLE_DEPTH;
-        //throw SCIRun::InternalError("Went off the deep end of the sample 
list",
-        //                          __FILE__, __LINE__);
       }
       packet_depth++;
     }
@@ -114,8 +112,7 @@
 
     virtual double nextDouble() {
       // TODO(boulos): Add padding (note the sample_depth++)
-      throw SCIRun::InternalError("Korobov::nextDouble is for suckers",
-                                  __FILE__, __LINE__);
+      throw InternalError("Korobov::nextDouble is for suckers");
       return fmod(inv_spp *((sample_index*g_table[sample_depth++])%num_spp),
                   1.0);
     }

Added: trunk/Core/Math/MinMax.h
==============================================================================
--- (empty file)
+++ trunk/Core/Math/MinMax.h    Mon Nov 26 21:56:50 2007
@@ -0,0 +1,198 @@
+/*
+   For more information, please see: http://software.sci.utah.edu
+
+   The MIT License
+
+   Copyright (c) 2004 Scientific Computing and Imaging Institute,
+   University of Utah.
+
+   License for the specific language governing rights and limitations under
+   Permission is hereby granted, free of charge, to any person obtaining a
+   copy of this software and associated documentation files (the "Software"),
+   to deal in the Software without restriction, including without limitation
+   the rights to use, copy, modify, merge, publish, distribute, sublicense,
+   and/or sell copies of the Software, and to permit persons to whom the
+   Software is furnished to do so, subject to the following conditions:
+
+   The above copyright notice and this permission notice shall be included
+   in all copies or substantial portions of the Software.
+
+   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+   OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 
MERCHANTABILITY,
+   FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+   THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+   LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+   FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+   DEALINGS IN THE SOFTWARE.
+*/
+
+
+
+/*
+ *  MinMax.h: Various implementations of Min and Max
+ *
+ *  Written by:
+ *   Steven G. Parker
+ *   Department of Computer Science
+ *   University of Utah
+ *   March 1994
+ *
+ *  Copyright (C) 1994 SCI Group
+ */
+
+
+#ifndef Manta_MinMax_h
+#define Manta_MinMax_h
+
+namespace Manta {
+
+// 2 Integers
+inline int Min(int d1, int d2)
+{
+    return d1<d2?d1:d2;
+}
+
+inline int Max(int d1, int d2)
+{
+    return d1>d2?d1:d2;
+}
+
+// 2 Unsigned Integers
+inline unsigned int Min(unsigned int d1, unsigned int d2)
+{
+    return d1<d2?d1:d2;
+}
+
+inline unsigned int Max(unsigned int d1, unsigned int d2)
+{
+    return d1>d2?d1:d2;
+}
+
+// 2 Long Integers
+inline long Min(long d1, long d2)
+{
+    return d1<d2?d1:d2;
+}
+
+inline long Max(long d1, long d2)
+{
+    return d1>d2?d1:d2;
+}
+
+// 2 floats
+inline float Max(float d1, float d2)
+{
+  return d1>d2?d1:d2;
+}
+
+inline float Min(float d1, float d2)
+{
+  return d1<d2?d1:d2;
+}
+
+// 2 doubles
+inline double Max(double d1, double d2)
+{
+  return d1>d2?d1:d2;
+}
+
+inline double Min(double d1, double d2)
+{
+  return d1<d2?d1:d2;
+}
+
+// 3 doubles
+inline double Min(double d1, double d2, double d3)
+{
+    double m=d1<d2?d1:d2;
+    m=m<d3?m:d3;
+    return m;
+}
+
+inline double Mid(double a, double b, double c)
+{
+  return ((a > b) ? ((a < c) ? a : ((b > c) ? b : c)) : \
+                   ((b < c) ? b : ((a > c) ? a : c)));
+}
+
+inline double Max(double d1, double d2, double d3)
+{
+    double m=d1>d2?d1:d2;
+    m=m>d3?m:d3;
+    return m;
+}
+
+// 3 integers
+inline int Min(int d1, int d2, int d3)
+{
+    int m=d1<d2?d1:d2;
+    m=m<d3?m:d3;
+    return m;
+}
+
+inline int Mid(int a, int b, int c)
+{
+  return ((a > b) ? ((a < c) ? a : ((b > c) ? b : c)) : \
+                   ((b < c) ? b : ((a > c) ? a : c)));
+}
+
+inline int Max(int d1, int d2, int d3)
+{
+    int m=d1>d2?d1:d2;
+    m=m>d3?m:d3;
+    return m;
+}
+
+// 3 unsigned integers
+inline unsigned int Min(unsigned int d1,
+                                    unsigned int d2,
+                                    unsigned int d3)
+{
+    unsigned int m=d1<d2?d1:d2;
+    m=m<d3?m:d3;
+    return m;
+}
+
+inline unsigned int Mid(unsigned int a,
+                                    unsigned int b,
+                                    unsigned int c)
+{
+  return ((a > b) ? ((a < c) ? a : ((b > c) ? b : c)) : \
+                   ((b < c) ? b : ((a > c) ? a : c)));
+}
+
+inline unsigned int Max(unsigned int d1,
+                                    unsigned int d2,
+                                    unsigned int d3)
+{
+    unsigned int m=d1>d2?d1:d2;
+    m=m>d3?m:d3;
+    return m;
+}
+
+// 3 Long Integers
+inline long  Min(long  d1, long  d2, long  d3)
+{
+    long  m=d1<d2?d1:d2;
+    m=m<d3?m:d3;
+    return m;
+}
+
+inline long Mid(long a, long b, long c)
+{
+  return ((a > b) ? ((a < c) ? a : ((b > c) ? b : c)) : \
+                   ((b < c) ? b : ((a > c) ? a : c)));
+}
+
+
+inline long  Max(long  d1, long  d2, long  d3)
+{
+    long  m=d1>d2?d1:d2;
+    m=m>d3?m:d3;
+    return m;
+}
+
+}
+
+
+#endif /* SCI_Math_MinMax_h */

Added: trunk/Core/Math/MiscMath.cc
==============================================================================
--- (empty file)
+++ trunk/Core/Math/MiscMath.cc Mon Nov 26 21:56:50 2007
@@ -0,0 +1,106 @@
+/*
+   For more information, please see: http://software.sci.utah.edu
+
+   The MIT License
+
+   Copyright (c) 2004 Scientific Computing and Imaging Institute,
+   University of Utah.
+
+   License for the specific language governing rights and limitations under
+   Permission is hereby granted, free of charge, to any person obtaining a
+   copy of this software and associated documentation files (the "Software"),
+   to deal in the Software without restriction, including without limitation
+   the rights to use, copy, modify, merge, publish, distribute, sublicense,
+   and/or sell copies of the Software, and to permit persons to whom the
+   Software is furnished to do so, subject to the following conditions:
+
+   The above copyright notice and this permission notice shall be included
+   in all copies or substantial portions of the Software.
+
+   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+   OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 
MERCHANTABILITY,
+   FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+   THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+   LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+   FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+   DEALINGS IN THE SOFTWARE.
+*/
+
+
+
+/*
+ *  MiscMath.cc
+ *
+ *  Written by:
+ *   Michael Callahan
+ *   Department of Computer Science
+ *   University of Utah
+ *   June 2004
+ *
+ *  Copyright (C) 2004 SCI Group
+ */
+
+#include <Core/Math/MiscMath.h>
+#include <Core/Math/Expon.h>
+#include <math.h>
+#ifdef __sgi
+#include <ieeefp.h>
+#endif
+#ifdef __digital__
+#include <fp_class.h>
+#endif
+#ifdef _WIN32
+#include <float.h>
+#define finite _finite
+#endif
+namespace Manta {
+
+double MakeReal(double value)
+{
+  if (!finite(value))
+  {
+    int is_inf = 0;
+#ifdef __digital__
+    // on dec, we have fp_class which can tell us if a number is +/- infinity
+    int fpclass = fp_class(value);
+    if (fpclass == FP_POS_INF) is_inf = 1;
+    if (fpclass == FP_NEG_INF) is_inf = -1;
+#elif defined(__sgi)
+    fpclass_t c = fpclass(value);
+    if (c == FP_PINF) is_inf = 1;
+    if (c == FP_NINF) is_inf = -1;
+#elif defined(_WIN32)
+    int c = _fpclass(value);
+    if (c == _FPCLASS_PINF) is_inf = 1;
+    if (c == _FPCLASS_NINF) is_inf = -1;
+#else
+    is_inf  = isinf(value);
+#endif
+    if (is_inf == 1) value = (double)(0x7fefffffffffffffULL);
+    if (is_inf == -1) value = (double)(0x0010000000000000ULL);
+    else value = 0.0; // Assumed NaN
+  }
+  return value;
+}
+
+void findFactorsNearRoot(const int value, int &factor1, int &factor2) {
+  int f1,f2;
+  f1 = f2 = (int) Sqrt((double)value);
+  // now we are basically looking for a pair of multiples that are closest to
+  // the square root.
+  while ((f1 * f2) != value) {
+    // look for another multiple
+    for(int i = f1+1; i <= value; i++) {
+      if (value%i == 0) {
+        // we've found a root
+        f1 = i;
+        f2 = value/f1;
+        break;
+      }
+    }
+  }
+  factor1 = f1;
+  factor2 = f2;
+}
+
+} // namespace Manta

Added: trunk/Core/Math/MiscMath.h
==============================================================================
--- (empty file)
+++ trunk/Core/Math/MiscMath.h  Mon Nov 26 21:56:50 2007
@@ -0,0 +1,363 @@
+/*
+   For more information, please see: http://software.sci.utah.edu
+
+   The MIT License
+
+   Copyright (c) 2004 Scientific Computing and Imaging Institute,
+   University of Utah.
+
+   License for the specific language governing rights and limitations under
+   Permission is hereby granted, free of charge, to any person obtaining a
+   copy of this software and associated documentation files (the "Software"),
+   to deal in the Software without restriction, including without limitation
+   the rights to use, copy, modify, merge, publish, distribute, sublicense,
+   and/or sell copies of the Software, and to permit persons to whom the
+   Software is furnished to do so, subject to the following conditions:
+
+   The above copyright notice and this permission notice shall be included
+   in all copies or substantial portions of the Software.
+
+   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+   OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 
MERCHANTABILITY,
+   FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+   THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+   LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+   FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+   DEALINGS IN THE SOFTWARE.
+*/
+
+
+
+/*
+ *  MiscMath.h: Assorted mathematical functions
+ *
+ *  Written by:
+ *   Steven G. Parker
+ *   Department of Computer Science
+ *   University of Utah
+ *   March 1994
+ *
+ *  Copyright (C) 1994 SCI Group
+ */
+
+
+#ifndef Manta_MiscMath_h
+#define Manta_MiscMath_h
+
+namespace Manta {
+
+// Absolute value
+inline double Abs(double d)
+{
+  return d<0?-d:d;
+}
+
+inline float Abs(float d)
+{
+  return d<0?-d:d;
+}
+
+inline int Abs(int i)
+{
+    return i<0?-i:i;
+}
+
+// Signs
+inline int Sign(double d)
+{
+  return d<0?-1:1;
+}
+
+inline int Sign(int i)
+{
+  return i<0?-1:1;
+}
+
+// Clamp a number to a specific range
+inline double Clamp(double d, double min, double max)
+{
+  return d<=min?min:d>=max?max:d;
+}
+
+inline float Clamp(float d, float min, float max)
+{
+  return d<=min?min:d>=max?max:d;
+}
+
+inline int Clamp(int i, int min, int max)
+{
+  return i<min?min:i>max?max:i;
+}
+
+// Generate a step between min and max.
+// return:   min - if d<=min
+//           max - if d>=max
+//           hermite curve if d>min && d<max
+//
+// Make sure fixes end up in both the float and double versions.
+inline double SmoothStep(double d, double min, double max)
+{
+  double ret;
+  if(d <= min){
+    ret=0.0;
+  } else if(d >= max){
+    ret=1.0;
+  } else {
+    double dm=max-min;
+    double t=(d-min)/dm;
+    ret=t*t*(3.0-2.0*t);
+  }
+  return ret;
+}
+
+// Make sure fixes end up in both the float and double versions.
+inline float SmoothStep(float d, float min, float max)
+{
+  float ret;
+  if(d <= min){
+    ret=0;
+  } else if(d >= max){
+    ret=1;
+  } else {
+    float dm=max-min;
+    float t=(d-min)/dm;
+    ret=t*t*(3-2*t);
+  }
+  return ret;
+}
+
+// Interpolation:
+template <class T>
+inline T Interpolate(T d1, T d2, double weight)
+{
+  return T(d2*weight+d1*(1.0-weight));
+}
+template <class T>
+inline T Interpolate(T d1, T d2, float weight)
+{
+  return T(d2*weight+d1*(1-weight));
+}
+
+
+
+
+// Integer/double conversions
+
+
+// The mantissa of a double is 52 bits, so in order to subtract out
+// the whole component of the floating point number you need a 64 bit
+// integer.  You can, of course, represent numbers larger than 2^64
+// with a double, but numbers larger than 2^52 (or so) will not have
+// the precision to contain a fractional component.  For such numbers
+// the behavior of this function is undefined.
+
+// This should compute (d - Floor(d)).  Examples of input/output:
+//   0   ->   0
+//   0.5 ->   0.5
+//   0.3 ->   0.3
+//   1   ->   0
+//   1.6 ->   1.6
+//   2   ->   0
+//
+//  -0.5 ->   0.5
+//  -0.3 ->   0.7
+//  -1   ->   0
+//  -1.6 ->   0.4
+//  -2   ->   0
+inline double Fraction(double d)
+{
+  double frac = d-(long long)d;
+  if (frac >= 0)
+    return frac;
+  else
+    return frac+1;
+}
+
+inline float Fraction(float d)
+{
+  float frac = d-(int)d;
+  if (frac >= 0)
+    return frac;
+  else
+    return frac+1;
+}
+
+inline int RoundDown(double d)
+{
+  if(d>=0){
+    return (int)d;
+  } else {
+    if(d==(int)d){
+      return -(int)(-d);
+    } else {
+      return -(int)(-d)-1;
+    }
+  }
+}
+
+inline int RoundUp(double d)
+{
+    if(d>=0){
+        if((d-(int)d) == 0)
+            return (int)d;
+        else
+            return (int)(d+1);
+    } else {
+        return (int)d;
+    }
+}
+
+inline int Round(double d)
+{
+  return (int)(d+0.5);
+}
+
+inline int Floor(double d)
+{
+  if(d<0){
+    int i=-(int)-d;
+    if((double)i == d)
+      return i;
+    else
+      return i-1;
+  } else {
+    return (int)d;
+  }
+}
+
+inline int Floor(float d)
+{
+  if(d<0){
+    int i=-(int)-d;
+    if((float)i == d)
+      return i;
+    else
+      return i-1;
+  } else {
+    return (int)d;
+  }
+}
+
+// this version is twice as fast for negative numbers
+// (on an available Pentium 4 machine, only about 25%
+// faster on Powerbook G4)
+// than the more robust version above, but will only
+//work for fabs(d) <= offset, use with caution
+inline int Floor(double d, int offset)
+{
+   return (int)(d + offset) - offset;
+}
+
+inline int Floor(float d, int offset)
+{
+   return (int)(d + offset) - offset;
+}
+
+inline int Ceil(double d)
+{
+  if(d<0){
+    int i=-(int)-d;
+    return i;
+  } else {
+    int i=(int)d;
+    if((double)i == d)
+      return i;
+    else
+      return i+1;
+  }
+}
+
+inline int Ceil(float d)
+{
+  if(d<0){
+    int i=-(int)-d;
+    return i;
+  } else {
+    int i=(int)d;
+    if((float)i == d)
+      return i;
+    else
+      return i+1;
+  }
+}
+
+// using the same trick as above, this
+// version of Ceil is a bit faster for
+// the architectures it has been tested
+// on (Pentium4, Powerbook G4)
+inline int Ceil(double d, int offset)
+{
+   return (int)(d - offset) + offset;
+}
+
+inline int Ceil(float d, int offset)
+{
+   return (int)(d - offset) + offset;
+}
+
+inline int Tile(int tile, int tf)
+{
+  if(tf<0){
+    // Tile in negative direction
+      if(tile>tf && tile<=0)return 1;
+      else return 0;
+  } else if(tf>0){
+    // Tile in positive direction
+      if(tile<tf && tile>=0)return 1;
+      else return 0;
+  } else {
+    return 1;
+  }
+}
+
+double MakeReal(double value);
+
+
+// Fast way to check for power of two
+inline bool IsPowerOf2(unsigned int n)
+{
+  return (n & (n-1)) == 0;
+}
+
+
+
+// Returns a number Greater Than or Equal to dim
+// that is an exact power of 2
+// Used for determining what size of texture to
+// allocate to store an image
+inline unsigned int
+Pow2(const unsigned int dim) {
+  if (IsPowerOf2(dim)) return dim;
+  unsigned int val = 4;
+  while (val < dim) val = val << 1;;
+  return val;
+}
+
+// Returns a number Less Than or Equal to dim
+// that is an exact power of 2
+inline unsigned int
+LargestPowerOf2(const unsigned int dim) {
+  if (IsPowerOf2(dim)) return dim;
+  return Pow2(dim) >> 1;
+}
+
+
+// Returns the power of 2 of the next higher number thas is a power of 2
+// Log2 of Pow2 funciton above
+inline unsigned int
+Log2(const unsigned int dim) {
+  unsigned int log = 0;
+  unsigned int val = 1;
+  while (val < dim) { val = val << 1; log++; };
+  return log;
+}
+
+// Takes the square root of "value" and tries to find two factors that
+// are closest to that square root.
+void findFactorsNearRoot(const int value, int& factor1, int& factor2);
+
+
+} // End namespace Manta
+
+
+#endif

Modified: trunk/Core/Math/Noise.cc
==============================================================================
--- trunk/Core/Math/Noise.cc    (original)
+++ trunk/Core/Math/Noise.cc    Mon Nov 26 21:56:50 2007
@@ -7,7 +7,6 @@
 #  include <Core/Math/SSEDefs.h>
 #endif
 
-using namespace SCIRun;
 using namespace std;
 
 namespace Manta {
@@ -285,7 +284,6 @@
     int hash_00 = NoiseXPermutationTable[ ( hash_0 + integer_of_y ) & 0xFF ];
     int hash_000 = NoiseXPermutationTable[ ( hash_00 + integer_of_z ) & 0xFF 
];
     int hash_001 = NoiseXPermutationTable[ ( hash_00 + integer_of_z + 1 ) & 
0xFF ];
-    using SCIRun::Interpolate;
     Real value_00 = Interpolate( ( Noise3DValueTable[ hash_000 ][ 0 ] * 
offset_of_x +
                                    Noise3DValueTable[ hash_000 ][ 1 ] * 
offset_of_y +
                                    Noise3DValueTable[ hash_000 ][ 2 ] * 
offset_of_z ),
@@ -468,7 +466,6 @@
     int hash_00 = NoiseXPermutationTable[ ( hash_0 + integer_of_y ) & 0xFF ];
     int hash_000 = NoiseXPermutationTable[ ( hash_00 + integer_of_z ) & 0xFF 
];
     int hash_001 = NoiseXPermutationTable[ ( hash_00 + integer_of_z + 1 ) & 
0xFF ];
-    using SCIRun::Interpolate;
     Real value_00 = Interpolate( ( Noise3DValueTable[ hash_000 ][ 0 ] * 
offset_of_x +
                                    Noise3DValueTable[ hash_000 ][ 1 ] * 
offset_of_y +
                                    Noise3DValueTable[ hash_000 ][ 2 ] * 
offset_of_z ),

Modified: trunk/Core/Math/ReflectRefract.h
==============================================================================
--- trunk/Core/Math/ReflectRefract.h    (original)
+++ trunk/Core/Math/ReflectRefract.h    Mon Nov 26 21:56:50 2007
@@ -1,5 +1,5 @@
 #include <MantaTypes.h>
-#include <SCIRun/Core/Math/MinMax.h>
+#include <Core/Math/MinMax.h>
 #include <Core/Geometry/Vector.h>
 
 namespace Manta {
@@ -22,7 +22,7 @@
   inline Real SchlickReflection(Real costheta, Real costheta2,
                                 Real eta_inverse)
   {
-    Real k = 1 - SCIRun::Min(costheta, costheta2);
+    Real k = 1 - Min(costheta, costheta2);
     Real k5 = (k*k)*(k*k)*k;
     Real r0 = (1 - eta_inverse) / (1 + eta_inverse);
     r0 *= r0;

Added: trunk/Core/Math/Trig.h
==============================================================================
--- (empty file)
+++ trunk/Core/Math/Trig.h      Mon Nov 26 21:56:50 2007
@@ -0,0 +1,154 @@
+/*
+   For more information, please see: http://software.sci.utah.edu
+
+   The MIT License
+
+   Copyright (c) 2004 Scientific Computing and Imaging Institute,
+   University of Utah.
+
+   License for the specific language governing rights and limitations under
+   Permission is hereby granted, free of charge, to any person obtaining a
+   copy of this software and associated documentation files (the "Software"),
+   to deal in the Software without restriction, including without limitation
+   the rights to use, copy, modify, merge, publish, distribute, sublicense,
+   and/or sell copies of the Software, and to permit persons to whom the
+   Software is furnished to do so, subject to the following conditions:
+
+   The above copyright notice and this permission notice shall be included
+   in all copies or substantial portions of the Software.
+
+   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+   OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 
MERCHANTABILITY,
+   FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+   THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+   LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+   FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+   DEALINGS IN THE SOFTWARE.
+*/
+
+
+
+#ifndef Math_Trig_h
+#define Math_Trig_h 1
+
+#include <math.h>
+
+#ifndef M_PI
+#define M_PI 3.14159265358979323846
+#endif
+
+namespace Manta {
+
+  const double Pi=M_PI;
+  
+#ifdef _WIN32
+
+  inline double acosh(double x)
+  {
+    return (x<1) ? log(-1.0) : log(x+sqrt(x*x-1));
+  }
+
+#endif
+
+  inline double Cos(double d)
+  {
+    return cos(d);
+  }
+
+  inline double Sin(double d)
+  {
+    return sin(d);
+  }
+  
+  inline double Asin(double d)
+  {
+    return asin(d);
+  }
+
+  inline double Acos(double d)
+  {
+    return acos(d);
+  }
+
+  inline double Tan(double d)
+  {
+    return tan(d);
+  }
+
+  inline double Cot(double d)
+  {
+    return 1./tan(d);
+  }
+
+  inline double Atan(double d)
+  {
+    return atan(d);
+  }
+
+  inline double Atan2(double y, double x)
+  {
+    return atan2(y, x);
+  }
+
+  inline double DtoR(double d)
+  {
+    return d*(M_PI/180.);
+  }
+
+  inline double RtoD(double r)
+  {
+    return r*(180./M_PI);
+  }
+
+  inline double ACosh(double x)
+  {
+    return acosh(x);
+  }
+
+/////////////////////////////////////////////////////
+//
+// Float versions
+//
+
+  inline float Sin(float d)
+  {
+    return sinf(d);
+  }
+
+  inline float Cos(float d)
+  {
+    return cosf(d);
+  }
+
+  inline float Tan(float d)
+  {
+    return tanf(d);
+  }
+
+  inline float Atan(float d)
+  {
+    return atanf(d);
+  }
+
+  inline float Atan2(float y, float x)
+  {
+    return atan2f(y, x);
+  }
+
+  inline float Acos(float d)
+  {
+    return acosf(d);
+  }
+
+  inline float DtoR(float d)
+  {
+    return d*(float)(M_PI/180.0);
+  }
+
+  inline float RtoD(float r)
+  {
+    return r*(float)(180.0/M_PI);
+  }
+}
+
+#endif

Modified: trunk/Core/Persistent/Archive.cc
==============================================================================
--- trunk/Core/Persistent/Archive.cc    (original)
+++ trunk/Core/Persistent/Archive.cc    Mon Nov 26 21:56:50 2007
@@ -7,7 +7,6 @@
 
 using namespace Manta;
 using namespace std;
-using namespace SCIRun;
 
 struct ArchiveType {
   string name;
@@ -24,7 +23,7 @@
 {
   int maxArchiveTypes = sizeof(archiveTypes)/sizeof(ArchiveType);
   if(numArchiveTypes >= maxArchiveTypes)
-    throw InternalError("Maximum number of archive types exceeded", 
__FILE__, __LINE__);
+    throw InternalError("Maximum number of archive types exceeded");
   archiveTypes[numArchiveTypes] = new ArchiveType();
   archiveTypes[numArchiveTypes]->name = name;
   archiveTypes[numArchiveTypes]->readopener = readopener;

Modified: trunk/Core/Persistent/ArchiveElement.cc
==============================================================================
--- trunk/Core/Persistent/ArchiveElement.cc     (original)
+++ trunk/Core/Persistent/ArchiveElement.cc     Mon Nov 26 21:56:50 2007
@@ -7,7 +7,6 @@
 
 using namespace Manta;
 using namespace std;
-using namespace SCIRun;
 
 ArchiveElement::ArchiveElement(bool isreading)
   : isreading(isreading)

Modified: trunk/Core/Persistent/MantaRTTI.h
==============================================================================
--- trunk/Core/Persistent/MantaRTTI.h   (original)
+++ trunk/Core/Persistent/MantaRTTI.h   Mon Nov 26 21:56:50 2007
@@ -201,8 +201,7 @@
         if(!derivedptr){
           std::string n1 = typeid(Derived).name();
           std::string n2 = typeid(Base).name();
-          throw SCIRun::InternalError("failed dynamic cast from " + n1 + " 
to " + n2 + " in ClassIndex(should not fail)",
-                                      __FILE__, __LINE__);
+          throw InternalError("failed dynamic cast from " + n1 + " to " + n2 
+ " in ClassIndex(should not fail)");
         }
         MantaRTTI<Derived>::readwrite(archive, *derivedptr);
       }
@@ -226,8 +225,7 @@
         if(ti != typeid(Derived)){
           std::string n1 = typeid(Derived).name();
           std::string n2 = ti.name();
-          throw SCIRun::InternalError("Distinct types (" + n1 + " and " + n2 
+ ") registered under the same public classname (" + name + ")",
-                                      __FILE__, __LINE__);
+          throw InternalError("Distinct types (" + n1 + " and " + n2 + ") 
registered under the same public classname (" + name + ")");
         }
       }
 
@@ -240,8 +238,7 @@
         if(ti != typeid(Derived)){
           std::string n1 = typeid(Derived).name();
           std::string n2 = ti.name();
-          throw SCIRun::InternalError("Distinct types (" + n1 + " and " + n2 
+ ") registered under the same C++ type name (" + name + ")",
-                                      __FILE__, __LINE__);
+          throw InternalError("Distinct types (" + n1 + " and " + n2 + ") 
registered under the same C++ type name (" + name + ")");
         }
       }
     }

Modified: trunk/Core/Persistent/XMLArchive.cc
==============================================================================
--- trunk/Core/Persistent/XMLArchive.cc (original)
+++ trunk/Core/Persistent/XMLArchive.cc Mon Nov 26 21:56:50 2007
@@ -3,7 +3,6 @@
 #include <Core/Persistent/ArchiveElement.h>
 #include <Core/Exceptions/InputError.h>
 #include <Core/Exceptions/SerializationError.h>
-#include <Core/Util/NotFinished.h>
 #include <libxml/parser.h>
 #include <libxml/tree.h>
 #include <map>

Added: trunk/Core/Thread/AtomicCounter.h
==============================================================================
--- (empty file)
+++ trunk/Core/Thread/AtomicCounter.h   Mon Nov 26 21:56:50 2007
@@ -0,0 +1,129 @@
+/*
+   For more information, please see: http://software.sci.utah.edu
+
+   The MIT License
+
+   Copyright (c) 2004 Scientific Computing and Imaging Institute,
+   University of Utah.
+
+   License for the specific language governing rights and limitations under
+   Permission is hereby granted, free of charge, to any person obtaining a
+   copy of this software and associated documentation files (the "Software"),
+   to deal in the Software without restriction, including without limitation
+   the rights to use, copy, modify, merge, publish, distribute, sublicense,
+   and/or sell copies of the Software, and to permit persons to whom the
+   Software is furnished to do so, subject to the following conditions:
+
+   The above copyright notice and this permission notice shall be included
+   in all copies or substantial portions of the Software.
+
+   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+   OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 
MERCHANTABILITY,
+   FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+   THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+   LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+   FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+   DEALINGS IN THE SOFTWARE.
+*/
+
+
+
+/*
+ *  AtomicCounter: Thread-safe integer variable
+ *
+ *  Written by:
+ *   Author: Steve Parker
+ *   Department of Computer Science
+ *   University of Utah
+ *   Date: June 1997
+ *
+ *  Copyright (C) 1997 SCI Group
+ */
+
+#ifndef Core_Thread_AtomicCounter_h
+#define Core_Thread_AtomicCounter_h
+
+namespace Manta {
+
+class AtomicCounter_private;
+
+/**************************************

+ CLASS
+ AtomicCounter
+
+ KEYWORDS
+ Thread
+
+ DESCRIPTION
+ Provides a simple atomic counter.  This will work just like an
+ integer, but guarantees atomicty of the ++ and -- operators.
+ Despite their convenience, you do not want to make a large number
+ of these objects.  See also WorkQueue.
+
+ Not that this implementation does not offer an operator=, but
+ instead uses a "set" method.  This is to avoid the inadvertant
+ use of a statement like: x=x+2, which would NOT be thread safe.
+
+****************************************/
+class AtomicCounter {
+public:
+  //////////
+  // Create an atomic counter with an unspecified initial value.
+  // <tt>name</tt> should be a static string which describes the
+  // primitive for debugging purposes.
+  AtomicCounter(const char* name);
+
+  //////////
+  // Create an atomic counter with an initial value.  name should
+  // be a static string which describes the primitive for debugging
+  // purposes.
+  AtomicCounter(const char* name, int value);
+
+  //////////
+  // Destroy the atomic counter.
+  ~AtomicCounter();
+
+  //////////
+  // Allows the atomic counter to be used in expressions like
+  // a normal integer.  Note that multiple calls to this function
+  // may return different values if other threads are manipulating
+  // the counter.
+  operator int() const;
+
+  //////////
+  // Increment the counter and return the new value.
+  // This does not return AtomicCounter& like a normal ++
+  // operator would, because it would destroy atomicity
+  int operator++();
+    
+  //////////
+  //   Increment the counter and return the old value
+  int operator++(int);
+
+  //////////
+  // Decrement the counter and return the new value
+  // This does not return AtomicCounter& like a normal --
+  // operator would, because it would destroy atomicity
+  int operator--();
+    
+  //////////
+  // Decrement the counter and return the old value
+  int operator--(int);
+
+  //////////
+  // Set the counter to a new value
+  void set(int);
+
+private:
+  const char* name_;
+  AtomicCounter_private* priv_;
+
+  // Cannot copy them
+  AtomicCounter(const AtomicCounter&);
+  AtomicCounter& operator=(const AtomicCounter&);
+};
+}
+
+#endif
+

Added: trunk/Core/Thread/AtomicCounter_default.cc
==============================================================================
--- (empty file)
+++ trunk/Core/Thread/AtomicCounter_default.cc  Mon Nov 26 21:56:50 2007
@@ -0,0 +1,145 @@
+/*
+   For more information, please see: http://software.sci.utah.edu
+
+   The MIT License
+
+   Copyright (c) 2004 Scientific Computing and Imaging Institute,
+   University of Utah.
+
+   License for the specific language governing rights and limitations under
+   Permission is hereby granted, free of charge, to any person obtaining a
+   copy of this software and associated documentation files (the "Software"),
+   to deal in the Software without restriction, including without limitation
+   the rights to use, copy, modify, merge, publish, distribute, sublicense,
+   and/or sell copies of the Software, and to permit persons to whom the
+   Software is furnished to do so, subject to the following conditions:
+
+   The above copyright notice and this permission notice shall be included
+   in all copies or substantial portions of the Software.
+
+   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+   OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 
MERCHANTABILITY,
+   FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+   THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+   LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+   FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+   DEALINGS IN THE SOFTWARE.
+*/
+
+
+
+/*
+ *  AtomicCounter: Thread-safe integer variable
+ *
+ *  Written by:
+ *   Author: Steve Parker
+ *   Department of Computer Science
+ *   University of Utah
+ *   Date: June 1997
+ *
+ *  Copyright (C) 1997 SCI Group
+ */
+
+#include <Core/Thread/AtomicCounter.h>
+
+namespace Manta {
+struct AtomicCounter_private {
+  Mutex lock;
+  int value;
+  AtomicCounter_private();
+  ~AtomicCounter_private();
+};
+
+AtomicCounter_private::AtomicCounter_private()
+    : lock("AtomicCounter lock")
+{
+}
+
+AtomicCounter_private::~AtomicCounter_private()
+{
+}
+
+AtomicCounter::AtomicCounter(const char* name)
+    : name_(name)
+{
+  if(!Thread::isInitialized()){
+    if(getenv("THREAD_SHOWINIT"))
+      fprintf(stderr, "AtomicCounter: %s\n", name);
+    Thread::initialize();
+  }
+  priv_=new AtomicCounter_private;
+}
+
+AtomicCounter::AtomicCounter(const char* name, int value)
+    : name_(name)
+{
+  priv_=new AtomicCounter_private;
+  priv_->value=value;
+}
+
+AtomicCounter::~AtomicCounter()
+{
+  delete priv_;
+  priv_=0;
+}
+
+AtomicCounter::operator int() const
+{
+    return priv_->value;
+}
+
+int
+AtomicCounter::operator++()
+{
+  int oldstate = Thread::couldBlock(name_);
+  priv_->lock.lock();
+  int ret=++priv_->value;
+  priv_->lock.unlock();
+  Thread::couldBlockDone(oldstate);
+  return ret;
+}
+
+int
+AtomicCounter::operator++(int)
+{
+  int oldstate = Thread::couldBlock(name_);
+  priv_->lock.lock();
+  int ret=priv_->value++;
+  priv_->lock.unlock();
+  Thread::couldBlockDone(oldstate);
+  return ret;
+}
+
+int
+AtomicCounter::operator--()
+{
+  int oldstate = Thread::couldBlock(name_);
+  priv_->lock.lock();
+  int ret=--priv_->value;      
+  priv_->lock.unlock();
+  Thread::couldBlockDone(oldstate);
+  return ret;
+}
+
+int
+AtomicCounter::operator--(int)
+{
+  int oldstate = Thread::couldBlock(name_);
+  priv_->lock.lock();
+  int ret=priv_->value--;
+  priv_->lock.unlock();
+  Thread::couldBlockDone(oldstate);
+  return ret;
+} 
+
+void
+AtomicCounter::set(int v)
+{
+  int oldstate=Thread::couldBlock(name_);
+  priv_->lock.lock();
+  priv_->value=v;
+  priv_->lock.unlock();
+  Thread::couldBlockDone(oldstate);
+}
+
+}

Added: trunk/Core/Thread/Barrier.h
==============================================================================
--- (empty file)
+++ trunk/Core/Thread/Barrier.h Mon Nov 26 21:56:50 2007
@@ -0,0 +1,102 @@
+/*
+   For more information, please see: http://software.sci.utah.edu
+
+   The MIT License
+
+   Copyright (c) 2004 Scientific Computing and Imaging Institute,
+   University of Utah.
+
+   License for the specific language governing rights and limitations under
+   Permission is hereby granted, free of charge, to any person obtaining a
+   copy of this software and associated documentation files (the "Software"),
+   to deal in the Software without restriction, including without limitation
+   the rights to use, copy, modify, merge, publish, distribute, sublicense,
+   and/or sell copies of the Software, and to permit persons to whom the
+   Software is furnished to do so, subject to the following conditions:
+
+   The above copyright notice and this permission notice shall be included
+   in all copies or substantial portions of the Software.
+
+   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+   OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 
MERCHANTABILITY,
+   FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+   THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+   LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+   FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+   DEALINGS IN THE SOFTWARE.
+*/
+
+
+
+/*
+ *  Barrier: Barrier synchronization primitive
+ *
+ *  Written by:
+ *   Author: Steve Parker
+ *   Department of Computer Science
+ *   University of Utah
+ *   Date: June 1997
+ *
+ *  Copyright (C) 1997 SCI Group
+ */
+
+#ifndef Core_Thread_Barrier_h
+#define Core_Thread_Barrier_h
+
+namespace Manta {
+
+class Barrier_private;
+
+/**************************************

+ CLASS
+ Barrier
+
+ KEYWORDS
+ Thread
+
+ DESCRIPTION
+ Barrier synchronization primitive.  Provides a single wait
+ method to allow a set of threads to block at the barrier until all
+ threads arrive.
+
+ WARNING
+ When the ThreadGroup semantics are used, other threads outside of the
+ ThreadGroup should not access the barrier, or undefined behavior will
+ result. In addition, threads should not be added or removed from the
+ ThreadGroup while the Barrier is being accessed.
+   
+****************************************/
+
+class Barrier {
+public:
+  //////////
+  // Create a barrier which will be used by a variable number
+  // of threads.   <tt>name</tt> should be a static string
+  // which describes the primitive for debugging purposes.
+  Barrier(const char* name);
+    
+  //////////
+  // Destroy the barrier
+  virtual ~Barrier();
+    
+  //////////
+  // This causes all of the threads to block at this method
+  // until all numThreads threads have called the method.
+  // After all threads have arrived, they are all allowed
+  // to return.
+  void wait(int numThreads);
+
+protected:
+private:
+  Barrier_private* priv_;
+  const char* name_;
+
+  // Cannot copy them
+  Barrier(const Barrier&);
+  Barrier& operator=(const Barrier&);
+};
+}
+
+#endif
+

Added: trunk/Core/Thread/Barrier_default.cc
==============================================================================
--- (empty file)
+++ trunk/Core/Thread/Barrier_default.cc        Mon Nov 26 21:56:50 2007
@@ -0,0 +1,105 @@
+/*
+   For more information, please see: http://software.sci.utah.edu
+
+   The MIT License
+
+   Copyright (c) 2004 Scientific Computing and Imaging Institute,
+   University of Utah.
+
+   License for the specific language governing rights and limitations under
+   Permission is hereby granted, free of charge, to any person obtaining a
+   copy of this software and associated documentation files (the "Software"),
+   to deal in the Software without restriction, including without limitation
+   the rights to use, copy, modify, merge, publish, distribute, sublicense,
+   and/or sell copies of the Software, and to permit persons to whom the
+   Software is furnished to do so, subject to the following conditions:
+
+   The above copyright notice and this permission notice shall be included
+   in all copies or substantial portions of the Software.
+
+   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+   OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 
MERCHANTABILITY,
+   FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+   THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+   LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+   FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+   DEALINGS IN THE SOFTWARE.
+*/
+
+
+
+/*
+ *  Barrier: Barrier synchronization primitive
+ *
+ *  Written by:
+ *   Author: Steve Parker
+ *   Department of Computer Science
+ *   University of Utah
+ *   Date: June 1997
+ *
+ *  Copyright (C) 1997 SCI Group
+ */
+
+#include <Core/Thread/Barrier.h>
+#include <Core/Thread/ConditionVariable.h>
+#include <Core/Thread/Mutex.h>
+
+namespace Manta {
+struct Barrier_private {
+  Mutex mutex;
+  ConditionVariable cond0;
+  ConditionVariable cond1;
+  int cc;
+  int nwait;
+  Barrier_private();
+  ~Barrier_private();
+};
+
+Barrier_private::Barrier_private()
+    : mutex("Barrier lock"),
+      cond0("Barrier condition 0"), cond1("Barrier condition 1"),
+      cc(0), nwait(0)
+{
+}
+
+Barrier_private::~Barrier_private()
+{
+}
+
+Barrier::Barrier(const char* name)
+    : name_(name)
+{
+  if(!Thread::isInitialized()){
+    if(getenv("THREAD_SHOWINIT"))
+      fprintf(stderr, "Barrier: %s\n", name);
+    Thread::initialize();
+  }
+  priv_=new Barrier_private;
+}
+
+Barrier::~Barrier()
+{
+    delete priv_;
+    priv_=0;
+}
+
+void
+Barrier::wait(int n)
+{
+    int oldstate=Thread::couldBlock(name_);
+    priv_->mutex.lock();
+    ConditionVariable& cond=priv_->cc?priv_->cond0:priv_->cond1;
+    priv_->nwait++;
+    if(priv_->nwait == n){
+       // Wake everybody up...
+       priv_->nwait=0;
+       priv_->cc=1-priv_->cc;
+       cond.conditionBroadcast();
+    } else {
+       cond.wait(priv_->mutex);
+    }
+    priv_->mutex.unlock();
+    Thread::couldBlockDone(oldstate);
+}
+
+}

Added: trunk/Core/Thread/CleanupManager.cc
==============================================================================
--- (empty file)
+++ trunk/Core/Thread/CleanupManager.cc Mon Nov 26 21:56:50 2007
@@ -0,0 +1,127 @@
+/*
+   For more information, please see: http://software.sci.utah.edu
+
+   The MIT License
+
+   Copyright (c) 2004 Scientific Computing and Imaging Institute,
+   University of Utah.
+
+   License for the specific language governing rights and limitations under
+   Permission is hereby granted, free of charge, to any person obtaining a
+   copy of this software and associated documentation files (the "Software"),
+   to deal in the Software without restriction, including without limitation
+   the rights to use, copy, modify, merge, publish, distribute, sublicense,
+   and/or sell copies of the Software, and to permit persons to whom the
+   Software is furnished to do so, subject to the following conditions:
+
+   The above copyright notice and this permission notice shall be included
+   in all copies or substantial portions of the Software.
+
+   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+   OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 
MERCHANTABILITY,
+   FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+   THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+   LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+   FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+   DEALINGS IN THE SOFTWARE.
+*/
+
+
+
+/*
+ *  CleanupManager.cc: Manage exitAll callbacks.
+ *
+ *  Written by:
+ *   Michael Callahan
+ *   Department of Computer Science
+ *   University of Utah
+ *   November 2004
+ *
+ *  Copyright (C) 2004 SCI Group
+ */
+
+#include <Core/Thread/CleanupManager.h>
+#include <algorithm>
+
+
+namespace Manta {
+
+typedef std::pair<CleanupManagerCallback, void *> CMCPair;
+
+std::vector<CMCPair>* CleanupManager::callbacks_ = NULL;
+bool    CleanupManager::initialized_ = false;
+Mutex * CleanupManager::lock_ = NULL;
+
+void
+CleanupManager::initialize()
+{
+  if( initialized_ )
+    return;
+  initialized_ = true;
+
+  callbacks_ = new std::vector<CMCPair>;
+  lock_ = new Mutex("CleanupManager lock");
+}
+
+void
+CleanupManager::add_callback(CleanupManagerCallback cb, void *data)
+{
+  if( !initialized_ ) initialize();
+
+  lock_->lock();
+  if (std::find(callbacks_->begin(), callbacks_->end(), CMCPair(cb, data))
+      == callbacks_->end())
+    {
+      callbacks_->push_back(CMCPair(cb, data));
+    }
+  lock_->unlock();
+}
+
+void
+CleanupManager::invoke_remove_callback(CleanupManagerCallback callback,
+                                      void *data)
+{
+  if( !initialized_ ) initialize();
+
+  lock_->lock();
+  callback(data);
+  callbacks_->erase(std::remove(callbacks_->begin(), callbacks_->end(),
+                                CMCPair(callback, data)),
+                    callbacks_->end());
+  lock_->unlock();
+}
+
+void
+CleanupManager::remove_callback(CleanupManagerCallback callback, void *data)
+{
+  if( !initialized_ ) initialize();
+
+  lock_->lock();
+  callbacks_->erase(std::remove(callbacks_->begin(), callbacks_->end(),
+                                CMCPair(callback, data)),
+                    callbacks_->end());
+  lock_->unlock();
+}
+
+void
+CleanupManager::call_callbacks()
+{
+  if( !initialized_ ) initialize();
+
+  lock_->lock();
+  for (unsigned int i = 0; i < callbacks_->size(); i++)
+    {
+      (*callbacks_)[i].first((*callbacks_)[i].second);
+    }
+  callbacks_->clear();
+  lock_->unlock();
+
+  // Should memory be cleaned up here?
+//   initialized_ = false;
+//   delete lock_;
+//   delete callbacks_;
+}
+
+
+} // End namespace Manta
+

Added: trunk/Core/Thread/CleanupManager.h
==============================================================================
--- (empty file)
+++ trunk/Core/Thread/CleanupManager.h  Mon Nov 26 21:56:50 2007
@@ -0,0 +1,117 @@
+/*
+   For more information, please see: http://software.sci.utah.edu
+
+   The MIT License
+
+   Copyright (c) 2004 Scientific Computing and Imaging Institute,
+   University of Utah.
+
+   License for the specific language governing rights and limitations under
+   Permission is hereby granted, free of charge, to any person obtaining a
+   copy of this software and associated documentation files (the "Software"),
+   to deal in the Software without restriction, including without limitation
+   the rights to use, copy, modify, merge, publish, distribute, sublicense,
+   and/or sell copies of the Software, and to permit persons to whom the
+   Software is furnished to do so, subject to the following conditions:
+
+   The above copyright notice and this permission notice shall be included
+   in all copies or substantial portions of the Software.
+
+   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+   OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 
MERCHANTABILITY,
+   FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+   THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+   LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+   FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+   DEALINGS IN THE SOFTWARE.
+*/
+
+
+
+/*
+ *  CleanupManager.cc: Manage exitAll callbacks.
+ *
+ *  Written by:
+ *   Michael Callahan
+ *   Department of Computer Science
+ *   University of Utah
+ *   November 2004
+ *
+ *  Copyright (C) 2004 SCI Group
+ */
+
+//  How to use this class:
+//  
+//  #include <Core/Thread/CleanupManager.h>
+//  
+//  Make a callback function that takes zero arguements and returns
+//  void.  Be very careful about introducing crashes into this
+//  callback function as it then becomes difficult to exit from
+//  scirun.  It's recommended that you avoid calling scinew from
+//  within your callback.
+//  
+//  Register with CleanupManager::add_callback(YOUR_CALLBACK_HERE, 
MISC_DATA);
+//  
+//  Your callback will only ever be called once, no matter how many
+//  times you register it.  In addition you can unregister it or
+//  design it such that it doesn't do anything if it doesn't need to.
+//  Here is an example of how this could be used:
+//
+//  class Myclass {
+//  public:
+//    Myclass() {
+//      CleanupManager::add_callback(this->cleanup_wrap, this);
+//    }
+//  
+//    ~Myclass() {
+//      // Need to remove and call callback at same time or else you get
+//      // a race condition and the callback could be called twice.
+//      CleanupManger::invoke_remove_callback(this->cleanup_wrap, this);
+//    }
+//  
+//  private: 
+//    static void cleanup_wrap(void *ptr) {
+//      ((Myclass *)ptr)->cleanup();
+//    }
+//  
+//    void cleanup();
+//  }
+//  
+
+#ifndef SCI_project_CleanupManager_h
+#define SCI_project_CleanupManager_h 1
+
+#include <Core/Thread/Mutex.h>
+#include <vector>
+
+namespace Manta {
+
+typedef void (*CleanupManagerCallback)(void *);
+
+class CleanupManager {
+public:
+  
+  // Initializes the mutex lock for the cleanup manager.  Initialize
+  // is called from the Thread::initialize and is only called once.
+  static void initialize();
+
+  static void add_callback(CleanupManagerCallback cb, void *data);
+  static void invoke_remove_callback(CleanupManagerCallback cb, void *data);
+  static void remove_callback(CleanupManagerCallback cb, void *data);
+
+  // After calling this, all registered functions will be removed.
+  // Should this also delete all the memory allocated by initialize()?
+  static void call_callbacks();
+
+protected:
+  // callbacks_ needs to be allocated off the heap to make sure it's
+  // still around when exitAll is called.
+  static std::vector<std::pair<CleanupManagerCallback, void *> >* callbacks_;
+  static bool    initialized_;
+  static Mutex * lock_;
+};
+
+} // End namespace SCIRun
+
+
+#endif /* SCI_project_CleanupManager_h */

Added: trunk/Core/Thread/ConditionVariable.h
==============================================================================
--- (empty file)
+++ trunk/Core/Thread/ConditionVariable.h       Mon Nov 26 21:56:50 2007
@@ -0,0 +1,130 @@
+/*
+   For more information, please see: http://software.sci.utah.edu
+
+   The MIT License
+
+   Copyright (c) 2004 Scientific Computing and Imaging Institute,
+   University of Utah.
+
+   License for the specific language governing rights and limitations under
+   Permission is hereby granted, free of charge, to any person obtaining a
+   copy of this software and associated documentation files (the "Software"),
+   to deal in the Software without restriction, including without limitation
+   the rights to use, copy, modify, merge, publish, distribute, sublicense,
+   and/or sell copies of the Software, and to permit persons to whom the
+   Software is furnished to do so, subject to the following conditions:
+
+   The above copyright notice and this permission notice shall be included
+   in all copies or substantial portions of the Software.
+
+   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+   OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 
MERCHANTABILITY,
+   FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+   THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+   LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+   FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+   DEALINGS IN THE SOFTWARE.
+*/
+
+
+
+/*
+ *  ConditionVariable: Condition variable primitive
+ *
+ *  Written by:
+ *   Author: Steve Parker
+ *   Department of Computer Science
+ *   University of Utah
+ *   Date: June 1997
+ *
+ *  Copyright (C) 1997 SCI Group
+ */
+
+#ifndef Manta_ConditionVariable_h
+#define Manta_ConditionVariable_h
+
+#include <Core/Thread/Semaphore.h>
+#include <Core/Thread/Mutex.h>
+
+struct timespec;
+
+namespace Manta {
+
+class ConditionVariable_private;
+class CrowdMonitor_private;
+
+/**************************************

+  CLASS
+  ConditionVariable
+
+  KEYWORDS
+  Thread
+
+  DESCRIPTION
+  Condition variable primitive.  When a thread calls the
+  <i>wait</i> method,which will block until another thread calls
+  the <i>conditionSignal</i> or <i>conditionBroadcast</i> methods.  When
+  there are multiple threads waiting, <i>conditionBroadcast</i> will unblock
+  all of them, while <i>conditionSignal</i> will unblock only one (an
+  arbitrary one) of them.  This primitive is used to allow a thread
+  to wait for some condition to exist, such as an available resource.
+  The thread waits for that condition, until it is unblocked by another
+  thread that caused the condition to exist (<i>i.e.</i> freed the
+  resource).
+   
+****************************************/
+
+class ConditionVariable {
+public:
+  //////////
+  // Create a condition variable. <i>name</i> should be a static
+  // string which describes the primitive for debugging purposes.
+  ConditionVariable(const char* name);
+    
+  //////////
+  // Destroy the condition variable
+  ~ConditionVariable();
+    
+  //////////
+  // Wait for a condition.  This method atomically unlocks
+  // <b>mutex</b>, and blocks.  The <b>mutex</b> is typically
+  // used to guard access to the resource that the thread is
+  // waiting for.
+  void wait(Mutex& m);
+
+  //////////
+  // Wait for a condition.  This method atomically unlocks
+  // <b>mutex</b>, and blocks.  The <b>mutex</b> is typically
+  // used to guard access to the resource that the thread is
+  // waiting for.  If the time abstime is reached before
+  // the ConditionVariable is signaled, this will return
+  // false.  Otherewise it will return true.
+  bool timedWait(Mutex& m, const struct ::timespec* abstime);
+    
+  //////////
+  // Signal a condition.  This will unblock one of the waiting
+  // threads. No guarantee is made as to which thread will be
+  // unblocked, but thread implementations typically give
+  // preference to the thread that has waited the longest.
+  void conditionSignal();
+
+  //////////
+  // Signal a condition.  This will unblock all of the waiting
+  // threads. Note that only the number of waiting threads will
+  // be unblocked. No guarantee is made that these are the same
+  // N threads that were blocked at the time of the broadcast.
+  void conditionBroadcast();
+
+private:
+  const char* name_;
+  ConditionVariable_private* priv_;
+
+  // Cannot copy them
+  ConditionVariable(const ConditionVariable&);
+  ConditionVariable& operator=(const ConditionVariable&);
+};
+}
+
+#endif
+

Added: trunk/Core/Thread/CrowdMonitor.h
==============================================================================
--- (empty file)
+++ trunk/Core/Thread/CrowdMonitor.h    Mon Nov 26 21:56:50 2007
@@ -0,0 +1,128 @@
+/*
+   For more information, please see: http://software.sci.utah.edu
+
+   The MIT License
+
+   Copyright (c) 2004 Scientific Computing and Imaging Institute,
+   University of Utah.
+
+   License for the specific language governing rights and limitations under
+   Permission is hereby granted, free of charge, to any person obtaining a
+   copy of this software and associated documentation files (the "Software"),
+   to deal in the Software without restriction, including without limitation
+   the rights to use, copy, modify, merge, publish, distribute, sublicense,
+   and/or sell copies of the Software, and to permit persons to whom the
+   Software is furnished to do so, subject to the following conditions:
+
+   The above copyright notice and this permission notice shall be included
+   in all copies or substantial portions of the Software.
+
+   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+   OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 
MERCHANTABILITY,
+   FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+   THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+   LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+   FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+   DEALINGS IN THE SOFTWARE.
+*/
+
+
+
+/*
+ *  CrowdMonitor: Multiple reader/single writer locks
+ *
+ *  Written by:
+ *   Author: Steve Parker
+ *   Department of Computer Science
+ *   University of Utah
+ *   Date: June 1997
+ *
+ *  Copyright (C) 1997 SCI Group
+ */
+
+#ifndef Manta_CrowdMonitor_h
+#define Manta_CrowdMonitor_h
+
+namespace Manta {
+  class CrowdMonitor_private;
+/**************************************

+CLASS
+   CrowdMonitor
+   
+KEYWORDS
+   Thread
+   
+DESCRIPTION
+   Multiple reader, single writer synchronization primitive.  Some
+   applications do not need the strict level of synchronization
+   provided by the <b>Mutex</b>.  The <b>CrowdMonitor</b> relaxes
+   the synchronization by allowing multiple threads access to a
+   resource (usually a data area), on the condition that the thread
+   will only read the data.  When a thread needs to write the data,
+   it can access the monitor in write mode (using <i>writeLock</i>).
+   At any given time, one writer thread can be active, or multiple
+   reader threads can be active.  <b>CrowdMonitor</b> guards against
+   multiple writers accessing a data, and against a thread writing
+   to the data while other threads are reading it.
+
+WARNING
+   <p> Calling <i>readLock</i> within a <i>writeLock/write_unlock</i>
+   section may result in a deadlock.  Likewise, calling <i>writeLock</i>
+   within a <i>readLock/readUnlock</i> section may result in a deadlock.
+   Calling <i>readUnlock</i> or <i>writeUnlock</i> when the lock is
+   not held is not legal and may result in undefined behavior.
+   
+****************************************/
+
+       class CrowdMonitor {
+       public:
+           //////////
+           // Create and initialize the CrowdMonitor. <i>name</i> should
+           // be a static which describes the primitive for debugging
+           // purposes.
+           CrowdMonitor(const char* name);
+    
+           //////////
+           // Destroy the CrowdMonitor.
+           ~CrowdMonitor();
+    
+           //////////
+           // Acquire the read-only lock associated with this
+           // <b>CrowdMonitor</b>. Multiple threads may hold the
+           // read-only lock simultaneously.
+           void readLock();
+    
+           //////////
+           // Release the read-only lock obtained from <i>readLock</i>.
+           // Undefined behavior may result when <i>readUnlock</i> is
+           // called and a <i>readLock</i> is not held by the calling
+           // Thread.
+           void readUnlock();
+    
+           //////////
+           // Acquire the write lock associated with this
+           // <b>CrowdMonitor</b>. Only one thread may hold the write
+           // lock, and during the time that this lock is not held, no
+           // threads may hold the read-only lock.
+           void writeLock();
+
+           //////////
+           // Release the write-only lock obtained from <i>writeLock</i>.
+           // Undefined behavior may result when <i>writeUnlock</i> is
+           // called and a <i>writeLock</i> is not held by the calling
+           // Thread.
+           void writeUnlock();
+
+       private:
+           const char* name_;
+           CrowdMonitor_private* priv_;
+
+           // Cannot copy them
+           CrowdMonitor(const CrowdMonitor&);
+           CrowdMonitor& operator=(const CrowdMonitor&);
+       };
+}
+
+#endif
+

Added: trunk/Core/Thread/CrowdMonitor_default.cc
==============================================================================
--- (empty file)
+++ trunk/Core/Thread/CrowdMonitor_default.cc   Mon Nov 26 21:56:50 2007
@@ -0,0 +1,148 @@
+/*
+   For more information, please see: http://software.sci.utah.edu
+
+   The MIT License
+
+   Copyright (c) 2004 Scientific Computing and Imaging Institute,
+   University of Utah.
+
+   License for the specific language governing rights and limitations under
+   Permission is hereby granted, free of charge, to any person obtaining a
+   copy of this software and associated documentation files (the "Software"),
+   to deal in the Software without restriction, including without limitation
+   the rights to use, copy, modify, merge, publish, distribute, sublicense,
+   and/or sell copies of the Software, and to permit persons to whom the
+   Software is furnished to do so, subject to the following conditions:
+
+   The above copyright notice and this permission notice shall be included
+   in all copies or substantial portions of the Software.
+
+   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+   OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 
MERCHANTABILITY,
+   FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+   THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+   LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+   FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+   DEALINGS IN THE SOFTWARE.
+*/
+
+
+
+/*
+ *  CrowdMonitor: Multiple reader/single writer locks
+ *
+ *  Written by:
+ *   Author: Steve Parker
+ *   Department of Computer Science
+ *   University of Utah
+ *   Date: June 1997
+ *
+ *  Copyright (C) 1997 SCI Group
+ */
+
+#include <Core/Thread/CrowdMonitor.h>
+
+namespace Manta {
+
+struct CrowdMonitor_private {
+  ConditionVariable write_waiters;
+  ConditionVariable read_waiters;
+  Mutex lock;
+  int num_readers_waiting;
+  int num_writers_waiting;
+  int num_readers;
+  int num_writers;
+  CrowdMonitor_private();
+  ~CrowdMonitor_private();
+};
+
+CrowdMonitor_private::CrowdMonitor_private()
+  : write_waiters("CrowdMonitor write condition"),
+    read_waiters("CrowdMonitor read condition"),
+    lock("CrowdMonitor lock")
+{
+  num_readers_waiting=0;
+  num_writers_waiting=0;
+  num_readers=0;
+  num_writers=0;
+}
+
+CrowdMonitor_private::~CrowdMonitor_private()
+{
+}
+
+CrowdMonitor::CrowdMonitor(const char* name)
+  : name_(name)
+{
+  if(!Thread::isInitialized()){
+    if(getenv("THREAD_SHOWINIT"))
+      fprintf(stderr, "CrowdMonitor: %s\n", name);
+    Thread::initialize();
+  }
+  priv_=new CrowdMonitor_private;
+}
+
+CrowdMonitor::~CrowdMonitor()
+{
+  delete priv_;
+  priv_=0;
+}
+
+void
+CrowdMonitor::readLock()
+{
+  int oldstate=Thread::couldBlock(name_);
+  priv_->lock.lock();
+  while(priv_->num_writers > 0){
+    priv_->num_readers_waiting++;
+    int s=Thread::couldBlock(name_);
+    priv_->read_waiters.wait(priv_->lock);
+    Thread::couldBlockDone(s);
+    priv_->num_readers_waiting--;
+  }
+  priv_->num_readers++;
+  priv_->lock.unlock();
+  Thread::couldBlockDone(oldstate);
+}
+
+void
+CrowdMonitor::readUnlock()
+{
+  priv_->lock.lock();
+  priv_->num_readers--;
+  if(priv_->num_readers == 0 && priv_->num_writers_waiting > 0)
+    priv_->write_waiters.conditionSignal();
+  priv_->lock.unlock();
+}
+
+void
+CrowdMonitor::writeLock()
+{
+  int oldstate=Thread::couldBlock(name_);
+  priv_->lock.lock();
+  while(priv_->num_writers || priv_->num_readers){
+    // Have to wait...
+    priv_->num_writers_waiting++;
+    int s=Thread::couldBlock(name_);
+    priv_->write_waiters.wait(priv_->lock);
+    Thread::couldBlockDone(s);
+    priv_->num_writers_waiting--;
+  }
+  priv_->num_writers++;
+  priv_->lock.unlock();
+  Thread::couldBlockDone(oldstate);
+} // End namespace Manta
+
+void
+CrowdMonitor::writeUnlock()
+{
+  priv_->lock.lock();
+  priv_->num_writers--;
+  if(priv_->num_writers_waiting)
+    priv_->write_waiters.conditionSignal(); // Wake one of them up...
+  else if(priv_->num_readers_waiting)
+    priv_->read_waiters.conditionBroadcast(); // Wake all of them up...
+  priv_->lock.unlock();
+}
+
+} // End namespace Manta

Added: trunk/Core/Thread/CrowdMonitor_pthreads.cc
==============================================================================
--- (empty file)
+++ trunk/Core/Thread/CrowdMonitor_pthreads.cc  Mon Nov 26 21:56:50 2007
@@ -0,0 +1,112 @@
+/*
+   For more information, please see: http://software.sci.utah.edu
+
+   The MIT License
+
+   Copyright (c) 2004 Scientific Computing and Imaging Institute,
+   University of Utah.
+
+   License for the specific language governing rights and limitations under
+   Permission is hereby granted, free of charge, to any person obtaining a
+   copy of this software and associated documentation files (the "Software"),
+   to deal in the Software without restriction, including without limitation
+   the rights to use, copy, modify, merge, publish, distribute, sublicense,
+   and/or sell copies of the Software, and to permit persons to whom the
+   Software is furnished to do so, subject to the following conditions:
+
+   The above copyright notice and this permission notice shall be included
+   in all copies or substantial portions of the Software.
+
+   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+   OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 
MERCHANTABILITY,
+   FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+   THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+   LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+   FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+   DEALINGS IN THE SOFTWARE.
+*/
+
+
+
+/*
+ *  CrowdMonitor: Multiple reader/single writer locks, implementation
+ *   for pthreads simply wrapping pthread_rwlock_t
+ *
+ *  Written by:
+ *   Author:  Wayne Witzel
+ *   Department of Computer Science
+ *   University of Utah
+ *   Date: March 2002
+ *
+ *  Copyright (C) 2002 SCI Group
+ */
+
+#include <Core/Thread/CrowdMonitor.h>
+#include <pthread.h>
+
+/*** WARNING: THIS IMPLEMENTATION HAS NOT BEEN TESTED - 3/6/2002 ***/
+
+namespace Manta {
+
+struct CrowdMonitor_private {
+  pthread_rwlock_t lock_;
+  CrowdMonitor_private();
+  ~CrowdMonitor_private();
+};
+
+CrowdMonitor_private::CrowdMonitor_private()
+{
+  pthread_rwlock_init(&lock_, 0);
+}
+
+CrowdMonitor_private::~CrowdMonitor_private()
+{
+  pthread_rwlock_destroy(&lock_);
+}
+
+CrowdMonitor::CrowdMonitor(const char* name)
+  : name_(name)
+{
+  if(!Thread::isInitialized()){
+    if(getenv("THREAD_SHOWINIT"))
+      fprintf(stderr, "CrowdMonitor: %s\n", name);
+    Thread::initialize();
+  }
+  priv_=new CrowdMonitor_private;
+}
+
+CrowdMonitor::~CrowdMonitor()
+{
+  delete priv_;
+  priv_=0;
+}
+
+void
+CrowdMonitor::readLock()
+{
+  int oldstate=Thread::couldBlock(name_);
+  pthread_rwlock_rdlock(&priv_->lock_);
+  Thread::couldBlockDone(oldstate);
+}
+
+void
+CrowdMonitor::readUnlock()
+{
+  pthread_rwlock_unlock(&priv_->lock_);  
+}
+
+void
+CrowdMonitor::writeLock()
+{
+  int oldstate=Thread::couldBlock(name_);
+  pthread_rwlock_wrlock(&priv_->lock_);
+  Thread::couldBlockDone(oldstate);
+} // End namespace Manta
+
+void
+CrowdMonitor::writeUnlock()
+{
+  pthread_rwlock_unlock(&priv_->lock_);  
+}
+
+} // End namespace Manta

Added: trunk/Core/Thread/FutureValue.h
==============================================================================
--- (empty file)
+++ trunk/Core/Thread/FutureValue.h     Mon Nov 26 21:56:50 2007
@@ -0,0 +1,135 @@
+/*
+   For more information, please see: http://software.sci.utah.edu
+
+   The MIT License
+
+   Copyright (c) 2004 Scientific Computing and Imaging Institute,
+   University of Utah.
+
+   License for the specific language governing rights and limitations under
+   Permission is hereby granted, free of charge, to any person obtaining a
+   copy of this software and associated documentation files (the "Software"),
+   to deal in the Software without restriction, including without limitation
+   the rights to use, copy, modify, merge, publish, distribute, sublicense,
+   and/or sell copies of the Software, and to permit persons to whom the
+   Software is furnished to do so, subject to the following conditions:
+
+   The above copyright notice and this permission notice shall be included
+   in all copies or substantial portions of the Software.
+
+   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+   OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 
MERCHANTABILITY,
+   FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+   THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+   LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+   FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+   DEALINGS IN THE SOFTWARE.
+*/
+
+
+
+/*
+ *  FutureValue: Delayed return values
+ *
+ *  Written by:
+ *   Author: Steve Parker
+ *   Department of Computer Science
+ *   University of Utah
+ *   Date: June 1997
+ *
+ *  Copyright (C) 1997 SCI Group
+ */
+
+#ifndef Manta_FutureValue_h
+#define Manta_FutureValue_h
+
+#include <Core/Thread/Semaphore.h>
+#include <Core/Thread/Thread.h>
+
+namespace Manta {
+/**************************************

+  CLASS
+  FutureValue
+   
+  KEYWORDS
+  Thread
+   
+  DESCRIPTION
+  Creates a single slot for some return value.  The <i>wait</i> method
+  waits for a value to be sent from another thread via the <i>reply</i>
+  method.  This is typically used to provide a simple means of returning
+  data from a server thread.  An <b>FutureValue</b> object is created on the
+  stack, and some request is sent (usually via a <b>Mailbox</b>) to a server
+  thread.  Then the thread will block in <i>wait</i> until the server thread
+  receives the message and responds using <i>reply</i>.
+  
+  <p><b>FutureValue</b> is a one-shot wait/reply pair - a new
+  <b>FutureValue</b> object must be created for each reply, and these are
+  typically created on the stack.  Only a single thread should
+  call <i>wait</i> and a single thread shuold call <i>reply</i>.
+  
+****************************************/
+template<class Item> class FutureValue {
+public:
+  //////////
+  // Create the FutureValue object.  <i>name</i> should be a
+  // static string which describes the primitive for debugging
+  // purposes.
+  FutureValue(const char* name);
+
+  //////////
+  // Destroy the object
+  ~FutureValue();
+
+  //////////
+  // Wait until the reply is sent by anothe thread, then return
+  // that reply.
+  Item receive();
+
+  //////////
+  // Send the reply to the waiting thread.
+  void send(const Item& reply);
+
+private:
+  const char* name;
+  Item value;
+  Semaphore sema;
+
+  // Cannot copy them
+  FutureValue(const FutureValue<Item>&);
+  FutureValue<Item>& operator=(const FutureValue<Item>&);
+};
+
+template<class Item>
+FutureValue<Item>::FutureValue(const char* name)
+    : name(name), sema("FutureValue semaphore", 0)
+{
+}
+
+template<class Item>
+FutureValue<Item>::~FutureValue()
+{
+}
+
+template<class Item>
+Item
+FutureValue<Item>::receive()
+{
+  int s=Thread::couldBlock(name);
+  sema.down();
+  Thread::couldBlockDone(s);
+  return value;
+} 
+
+template<class Item>
+void
+FutureValue<Item>::send(const Item& reply)
+{
+  value=reply;
+  sema.up();
+}
+}
+
+#endif
+

Added: trunk/Core/Thread/Guard.cc
==============================================================================
--- (empty file)
+++ trunk/Core/Thread/Guard.cc  Mon Nov 26 21:56:50 2007
@@ -0,0 +1,75 @@
+/*
+   For more information, please see: http://software.sci.utah.edu
+
+   The MIT License
+
+   Copyright (c) 2004 Scientific Computing and Imaging Institute,
+   University of Utah.
+
+   License for the specific language governing rights and limitations under
+   Permission is hereby granted, free of charge, to any person obtaining a
+   copy of this software and associated documentation files (the "Software"),
+   to deal in the Software without restriction, including without limitation
+   the rights to use, copy, modify, merge, publish, distribute, sublicense,
+   and/or sell copies of the Software, and to permit persons to whom the
+   Software is furnished to do so, subject to the following conditions:
+
+   The above copyright notice and this permission notice shall be included
+   in all copies or substantial portions of the Software.
+
+   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+   OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 
MERCHANTABILITY,
+   FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+   THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+   LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+   FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+   DEALINGS IN THE SOFTWARE.
+*/
+
+
+
+/*
+ *  Guard: Automatically lock/unlock a mutex or crowdmonitor.
+ *
+ *  Written by:
+ *   Author: Steve Parker
+ *   Department of Computer Science
+ *   University of Utah
+ *   Date: June 1997
+ *
+ *  Copyright (C) 1997 SCI Group
+ */
+
+#include <Core/Thread/Guard.h>
+#include <Core/Thread/CrowdMonitor.h>
+#include <Core/Thread/Mutex.h>
+
+namespace Manta {
+
+Guard::Guard(Mutex* mutex)
+    : mutex_(mutex), monitor_(0)
+{
+  mutex_->lock();
+}
+
+Guard::Guard(CrowdMonitor* crowd_monitor, Which action) 
+    : mutex_(0), monitor_(crowd_monitor), action_(action)
+{
+    if(action_ == Read)
+        monitor_->readLock();
+    else
+        monitor_->writeLock();
+}
+
+Guard::~Guard()
+{
+    if (mutex_)
+        mutex_->unlock();
+    else if(action_==Read)
+        monitor_->readUnlock();
+    else
+        monitor_->writeUnlock();
+}
+
+
+} // End namespace Manta

Added: trunk/Core/Thread/Guard.h
==============================================================================
--- (empty file)
+++ trunk/Core/Thread/Guard.h   Mon Nov 26 21:56:50 2007
@@ -0,0 +1,108 @@
+/*
+   For more information, please see: http://software.sci.utah.edu
+
+   The MIT License
+
+   Copyright (c) 2004 Scientific Computing and Imaging Institute,
+   University of Utah.
+
+   License for the specific language governing rights and limitations under
+   Permission is hereby granted, free of charge, to any person obtaining a
+   copy of this software and associated documentation files (the "Software"),
+   to deal in the Software without restriction, including without limitation
+   the rights to use, copy, modify, merge, publish, distribute, sublicense,
+   and/or sell copies of the Software, and to permit persons to whom the
+   Software is furnished to do so, subject to the following conditions:
+
+   The above copyright notice and this permission notice shall be included
+   in all copies or substantial portions of the Software.
+
+   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+   OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 
MERCHANTABILITY,
+   FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+   THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+   LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+   FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+   DEALINGS IN THE SOFTWARE.
+*/
+
+
+
+/*
+ *  Guard: Automatically lock/unlock a mutex or crowdmonitor.
+ *
+ *  Written by:
+ *   Author: Steve Parker
+ *   Department of Computer Science
+ *   University of Utah
+ *   Date: June 1997
+ *
+ *  Copyright (C) 1997 SCI Group
+ */
+
+#ifndef Manta_Guard_h
+#define Manta_Guard_h
+
+namespace Manta {
+
+class Mutex;
+class CrowdMonitor;
+
+/**************************************
+
+  CLASS
+  Guard
+
+  KEYWORDS
+  Thread
+
+  DESCRIPTION
+  Utility class to lock and unlock a <b>Mutex</b> or a <b>CrowdMonitor</b>.
+  The constructor of the <b>Guard</b> object will lock the mutex
+  (or <b>CrowdMonitor</b>), and the destructor will unlock it.
+  <p>
+  This would be used like this:
+  <blockquote><pre>
+  {
+  <blockquote>Guard mlock(&mutex);  // Acquire the mutex
+  ... critical section ...</blockquote>
+  } // mutex is released when mlock goes out of scope
+  </pre></blockquote>
+   
+****************************************/
+class Guard {
+public:
+  //////////
+  // Attach the <b>Guard</b> object to the <i>mutex</i>, and
+  // acquire the mutex.
+  Guard(Mutex* mutex);
+  enum Which {
+    Read,
+    Write
+  };
+    
+  //////////
+  // Attach the <b>Guard</b> to the <i>CrowdMonitor</pre> and
+  // acquire one of the locks.  If <i>action</i> is
+  // <b>Guard::Read</b>, the read lock will be acquired, and if
+  // <i>action</i> is <b>Write</b>, then the write lock will be
+  // acquired.  The appropriate lock will then be released by the
+  // destructor
+  Guard(CrowdMonitor* crowdMonitor, Which action);
+    
+  //////////
+  // Release the lock acquired by the constructor.
+  ~Guard();
+private:
+  Mutex* mutex_;
+  CrowdMonitor* monitor_;
+  Which action_;
+
+  // Cannot copy them
+  Guard(const Guard&);
+  Guard& operator=(const Guard&);
+};
+}
+
+#endif
+

Added: trunk/Core/Thread/Mailbox.h
==============================================================================
--- (empty file)
+++ trunk/Core/Thread/Mailbox.h Mon Nov 26 21:56:50 2007
@@ -0,0 +1,332 @@
+/*
+   For more information, please see: http://software.sci.utah.edu
+
+   The MIT License
+
+   Copyright (c) 2004 Scientific Computing and Imaging Institute,
+   University of Utah.
+
+   License for the specific language governing rights and limitations under
+   Permission is hereby granted, free of charge, to any person obtaining a
+   copy of this software and associated documentation files (the "Software"),
+   to deal in the Software without restriction, including without limitation
+   the rights to use, copy, modify, merge, publish, distribute, sublicense,
+   and/or sell copies of the Software, and to permit persons to whom the
+   Software is furnished to do so, subject to the following conditions:
+
+   The above copyright notice and this permission notice shall be included
+   in all copies or substantial portions of the Software.
+
+   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+   OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 
MERCHANTABILITY,
+   FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+   THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+   LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+   FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+   DEALINGS IN THE SOFTWARE.
+*/
+
+
+
+/*
+ *  Mailbox: Threadsafe FIFO
+ *
+ *  Written by:
+ *   Author: Steve Parker
+ *   Department of Computer Science
+ *   University of Utah
+ *   Date: June 1997
+ *
+ *  Copyright (C) 1997 SCI Group
+ */
+
+#ifndef Core_Thread_Mailbox_h
+#define Core_Thread_Mailbox_h
+
+#include <Core/Thread/ConditionVariable.h>
+#include <Core/Thread/Mutex.h>
+#include <Core/Thread/Semaphore.h>
+#include <Core/Thread/Thread.h>
+#include <vector>
+
+namespace Manta {
+/**************************************
+
+  CLASS
+  Mailbox
+
+  KEYWORDS
+  Thread, FIFO
+
+  DESCRIPTION
+  A thread-safe, fixed-length FIFO queue which allows multiple
+  concurrent senders and receivers.  Multiple threads send <b>Item</b>s
+  to the mailbox, and multiple thread may receive <b>Item</b>s from the
+  mailbox.  Items are typically pointers to a message structure.
+
+****************************************/
+template<class Item> class Mailbox {
+public:
+  //////////
+  // Create a mailbox with a maximum queue size of <i>size</i>
+  // items. If size is zero, then the mailbox will use
+  // <i>rendevous semantics</i>, where a sender will block
+  // until a reciever is waiting for the item.  The item will
+  // be handed off synchronously. <i>name</i> should be a
+  // static string which describes the primitive for debugging
+  // purposes.
+  Mailbox(const char* name, int size);
+    
+  //////////
+  // Destroy the mailbox.  All items in the queue are silently
+  // dropped.
+  ~Mailbox();
+    
+  //////////
+  // Puts <i>msg</i> in the queue.  If the queue is full, the
+  // thread will be blocked until there is room in the queue.
+  // Messages from the same thread will be placed in the
+  // queue in a first-in/first out order. Multiple threads may
+  // call <i>send</i> concurrently, and the messages will be
+  // placed in the queue in an arbitrary order.
+  void send(const Item& msg);
+    
+  //////////
+  // Attempt to send <i>msg</i> to the queue.  If the queue is
+  // full, the thread will not be blocked, and <i>trySend</i>
+  // will return false.  Otherwise, <i>trySend</i> will return
+  // true.  This may never complete if the reciever only uses
+  // <i>tryRecieve</i>.  
+  bool trySend(const Item& msg);
+    
+  
+  //////////
+  // Send <i>msg</i> to the queue only if the <i>checker</i> function
+  // fails to compare the <i>msg</i> to what is already the last item
+  // there.  This is useful if we want to make certain that at least
+  // one of a particular message (like a viewer resize redraw) gets
+  // put on the mailbox without spamming it.  This blocks like
+  // <i>send</i> does.  It returns true if <i>msg</i> was added to the
+  // queue and false if it wasn't.
+  bool sendIfNotSentLast(const Item& msg,
+                         bool (*checker)(const Item &a, const Item &b));
+
+  //////////
+  // Receive an item from the queue.  If the queue is empty,
+  // the thread will block until another thread sends an item.
+  // Multiple threads may call <i>recieve</i> concurrently, but
+  // no guarantee is made as to which thread will recieve the
+  // next token.  However, implementors should give preference
+  // to the thread that has been waiting the longest.
+  Item receive();
+
+  //////////
+  // Attempt to recieve <i>item</i> from the mailbox.  If the
+  // queue is empty, the thread is blocked and <i>tryRecieve</i>
+  // will return false.  Otherwise, <i>tryRecieve</i> returns true.
+  bool tryReceive(Item& item);
+    
+  //////////
+  // Return the maximum size of the mailbox queue, as given in the
+  // constructor.
+  int size() const;
+
+  //////////
+  // Return the number of items currently in the queue.
+  int numItems() const;
+
+private:
+  const char* name_;
+  Mutex mutex_;
+  std::vector<Item> ring_buffer_;
+  int head_;
+  int len_;
+  int max_;
+  ConditionVariable empty_;
+  ConditionVariable full_;
+  Semaphore rendezvous_;
+  int send_wait_;
+  int recv_wait_;
+  inline int ringNext(int inc);
+
+  // Cannot copy them
+  Mailbox(const Mailbox<Item>&);
+  Mailbox<Item> operator=(const Mailbox<Item>&);
+};
+
+template<class Item> inline
+int
+Mailbox<Item>::ringNext(int inc)
+{
+    return max_==0?0:((head_+inc)%max_);
+}
+
+template<class Item>
+Mailbox<Item>::Mailbox(const char* name, int size)
+    : name_(name), mutex_("Mailbox lock"), ring_buffer_(size==0?1:size),
+      empty_("Mailbox empty condition"), full_("Mailbox full condition"),
+      rendezvous_("Mailbox rendezvous semaphore", 0)
+{
+    head_=0;
+    len_=0;
+    send_wait_=0;
+    recv_wait_=0;
+    max_=size;
+}
+
+template<class Item>
+Mailbox<Item>::~Mailbox()
+{
+  // release all waiting threads
+  empty_.conditionBroadcast();
+  full_.conditionBroadcast();
+}
+
+template<class Item>
+void
+Mailbox<Item>::send(const Item& msg)
+{
+    int s=Thread::couldBlock(name_);
+    mutex_.lock();
+    // See if the message buffer is full...
+    int rmax=max_==0?1:max_;
+    while(len_ == rmax){
+        send_wait_++;
+        full_.wait(mutex_);
+        send_wait_--;
+    }
+    ring_buffer_[ringNext(len_)]=msg;
+    len_++;
+    if(recv_wait_)
+        empty_.conditionSignal();
+    mutex_.unlock();
+    if(max_==0)
+        rendezvous_.down();
+    Thread::couldBlockDone(s);
+}
+
+template<class Item>
+bool
+Mailbox<Item>::trySend(const Item& msg)
+{
+    mutex_.lock();
+    // See if the message buffer is full...
+    int rmax=max_==0?1:max_;
+    if(len_ == rmax){
+        mutex_.unlock();
+        return false;
+    }
+    if(max_ == 0 && recv_wait_==0){
+        // No receivers waiting, so rendezvous will fail. Return now.
+        mutex_.unlock();
+        return false;
+    }
+
+    ring_buffer_[ringNext(len_)]=msg;
+    len_++;
+    if(recv_wait_)
+        empty_.conditionSignal();
+    mutex_.unlock();
+    if(max_==0)
+        rendezvous_.down();  // Won't block for long, since a receiver
+                            // will wake us up
+    return true;
+}
+
+
+template<class Item>
+bool
+Mailbox<Item>::sendIfNotSentLast(const Item& msg,
+                                 bool (*checker)(const Item &a, const Item 
&b))
+{
+    int s = Thread::couldBlock(name_);
+    mutex_.lock();
+    // See if the message buffer is full...
+    int rmax=max_==0?1:max_;
+    while(len_ == rmax){
+        send_wait_++;
+        full_.wait(mutex_);
+        send_wait_--;
+    }
+    if (len_ < 1 || checker(ring_buffer_[ringNext(len_-1)], msg))
+    {
+      ring_buffer_[ringNext(len_)]=msg;
+      len_++;
+      if(recv_wait_)
+        empty_.conditionSignal();
+      mutex_.unlock();
+      if(max_==0)
+        rendezvous_.down();
+      Thread::couldBlockDone(s);
+      return true;
+    }
+    else
+    {
+      mutex_.unlock();
+      Thread::couldBlockDone(s);
+      return false;
+    }
+}
+
+
+template<class Item>
+Item
+Mailbox<Item>::receive()
+{
+    int s=Thread::couldBlock(name_);
+    mutex_.lock();
+    while(len_ == 0){
+        recv_wait_++;
+        empty_.wait(mutex_);
+        recv_wait_--;
+    }
+    Item val=ring_buffer_[head_];
+    head_=ringNext(1);
+    len_--;
+    if(send_wait_)
+        full_.conditionSignal();
+    mutex_.unlock();
+    if(max_==0)
+        rendezvous_.up();
+    Thread::couldBlockDone(s);
+    return val;
+}
+
+template<class Item>
+bool
+Mailbox<Item>::tryReceive(Item& item)
+{
+    mutex_.lock();
+    if(len_ == 0){
+        mutex_.unlock();
+        return false;
+    }
+    item=ring_buffer_[head_];
+    head_=ringNext(1);
+    len_--;
+    if(send_wait_)
+        full_.conditionSignal();
+    mutex_.unlock();
+    if(max_==0)
+        rendezvous_.up();
+    return true;
+}
+
+template<class Item>
+int
+Mailbox<Item>::size() const
+{
+    return max_;
+}
+
+template<class Item>
+int
+Mailbox<Item>::numItems() const
+{
+    return len_;
+}
+
+}
+#endif
+
+

Added: trunk/Core/Thread/Mutex.h
==============================================================================
--- (empty file)
+++ trunk/Core/Thread/Mutex.h   Mon Nov 26 21:56:50 2007
@@ -0,0 +1,106 @@
+/*
+   For more information, please see: http://software.sci.utah.edu
+
+   The MIT License
+
+   Copyright (c) 2004 Scientific Computing and Imaging Institute,
+   University of Utah.
+
+   License for the specific language governing rights and limitations under
+   Permission is hereby granted, free of charge, to any person obtaining a
+   copy of this software and associated documentation files (the "Software"),
+   to deal in the Software without restriction, including without limitation
+   the rights to use, copy, modify, merge, publish, distribute, sublicense,
+   and/or sell copies of the Software, and to permit persons to whom the
+   Software is furnished to do so, subject to the following conditions:
+
+   The above copyright notice and this permission notice shall be included
+   in all copies or substantial portions of the Software.
+
+   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+   OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 
MERCHANTABILITY,
+   FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+   THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+   LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+   FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+   DEALINGS IN THE SOFTWARE.
+*/
+
+
+
+/*
+ *  Mutex: Standard locking primitive
+ *
+ *  Written by:
+ *   Author: Steve Parker
+ *   Department of Computer Science
+ *   University of Utah
+ *   Date: June 1997
+ *
+ *  Copyright (C) 1997 SCI Group
+ */
+
+#ifndef Core_Thread_Mutex_h
+#define Core_Thread_Mutex_h
+
+namespace Manta {
+
+struct Mutex_private;
+
+/**************************************
+
+ CLASS
+ Mutex
+
+ KEYWORDS
+ Thread
+
+ DESCRIPTION
+ Provides a simple <b>Mut</b>ual <b>Ex</b>clusion primitive.  Atomic
+ <b>lock()</b> and <b>unlock()</b> will lock and unlock the mutex.
+ This is not a recursive Mutex (See <b>RecursiveMutex</b>), and calling
+ lock() in a nested call will result in an error or deadlock.
+
+****************************************/
+class Mutex {
+public:
+  //////////
+  // Create the mutex.  The mutex is allocated in the unlocked
+  // state. <i>name</i> should be a static string which describes
+  // the primitive for debugging purposes.  
+  Mutex(const char* name);
+
+  //////////
+  // Destroy the mutex.  Destroying the mutex in the locked state
+  // has undefined results.
+  ~Mutex();
+
+  //////////
+  // Acquire the Mutex.  This method will block until the mutex
+  // is acquired.
+  void lock();
+
+  //////////
+  // Attempt to acquire the Mutex without blocking.  Returns
+  // true if the mutex was available and actually acquired.
+  bool tryLock();
+
+  //////////
+  // Release the Mutex, unblocking any other threads that are
+  // blocked waiting for the Mutex.
+  void unlock();
+  friend class ConditionVariable;
+private:
+  Mutex_private* priv_;
+  const char* name_;
+
+  // Cannot copy them
+  Mutex(const Mutex&);
+  Mutex& operator=(const Mutex&);
+};
+
+}
+
+#endif
+
+

Added: trunk/Core/Thread/MutexPool.cc
==============================================================================
--- (empty file)
+++ trunk/Core/Thread/MutexPool.cc      Mon Nov 26 21:56:50 2007
@@ -0,0 +1,94 @@
+/*
+   For more information, please see: http://software.sci.utah.edu
+
+   The MIT License
+
+   Copyright (c) 2004 Scientific Computing and Imaging Institute,
+   University of Utah.
+
+   License for the specific language governing rights and limitations under
+   Permission is hereby granted, free of charge, to any person obtaining a
+   copy of this software and associated documentation files (the "Software"),
+   to deal in the Software without restriction, including without limitation
+   the rights to use, copy, modify, merge, publish, distribute, sublicense,
+   and/or sell copies of the Software, and to permit persons to whom the
+   Software is furnished to do so, subject to the following conditions:
+
+   The above copyright notice and this permission notice shall be included
+   in all copies or substantial portions of the Software.
+
+   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+   OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 
MERCHANTABILITY,
+   FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+   THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+   LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+   FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+   DEALINGS IN THE SOFTWARE.
+*/
+
+
+
+/*
+ *  MutexPool: A set of mutex objects
+ *
+ *  Written by:
+ *   Author: Steve Parker
+ *   Department of Computer Science
+ *   University of Utah
+ *   Date: September 1999
+ *
+ *  Copyright (C) 1999 SCI Group
+ */
+
+#include <Core/Thread/MutexPool.h>
+
+namespace Manta {
+
+
+MutexPool::MutexPool(const char* name, int size)
+    :  nextID_("MutexPool ID lock", 0), size_(size)
+{
+    // Mutex has no default CTOR so we must allocate them
+    // indepdently.
+    pool_=new Mutex*[size_];
+    for(int i=0;i<size_;i++)
+       pool_[i]=new Mutex(name);
+}
+
+MutexPool::~MutexPool()
+{
+    for(int i=0;i<size_;i++)
+       delete pool_[i];
+    delete[] pool_;
+}
+
+int MutexPool::nextIndex()
+{
+    for(;;) {
+       int next=nextID_++;
+       if(next < size_)
+           return next;
+       // The above is atomic, but if it exceeds size, we need to
+       // reset it.
+       nextID_.set(0);
+    }
+}
+
+Mutex* MutexPool::getMutex(int idx)
+{
+    return pool_[idx];
+}
+
+void MutexPool::lockMutex(int idx)
+{
+    pool_[idx]->lock();
+}
+
+void MutexPool::unlockMutex(int idx)
+{
+    pool_[idx]->unlock();
+}
+
+
+} // End namespace Manta
+

Added: trunk/Core/Thread/MutexPool.h
==============================================================================
--- (empty file)
+++ trunk/Core/Thread/MutexPool.h       Mon Nov 26 21:56:50 2007
@@ -0,0 +1,112 @@
+/*
+   For more information, please see: http://software.sci.utah.edu
+
+   The MIT License
+
+   Copyright (c) 2004 Scientific Computing and Imaging Institute,
+   University of Utah.
+
+   License for the specific language governing rights and limitations under
+   Permission is hereby granted, free of charge, to any person obtaining a
+   copy of this software and associated documentation files (the "Software"),
+   to deal in the Software without restriction, including without limitation
+   the rights to use, copy, modify, merge, publish, distribute, sublicense,
+   and/or sell copies of the Software, and to permit persons to whom the
+   Software is furnished to do so, subject to the following conditions:
+
+   The above copyright notice and this permission notice shall be included
+   in all copies or substantial portions of the Software.
+
+   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+   OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 
MERCHANTABILITY,
+   FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+   THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+   LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+   FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+   DEALINGS IN THE SOFTWARE.
+*/
+
+
+
+/*
+ *  MutexPool: A set of mutex objects
+ *
+ *  Written by:
+ *   Author: Steve Parker
+ *   Department of Computer Science
+ *   University of Utah
+ *   Date: September 1999
+ *
+ *  Copyright (C) 1999 SCI Group
+ */
+
+#ifndef Manta_MutexPool_h
+#define Manta_MutexPool_h
+
+#include <Core/Thread/AtomicCounter.h>
+#include <Core/Thread/Mutex.h>
+
+namespace Manta {
+/**************************************

+CLASS
+   MutexPool
+   
+KEYWORDS
+   Thread, Mutex
+   
+DESCRIPTION
+   A container class for a set of Mutex objects.  This can be used to
+   limit the number of active mutexes down to a more reasonable set.
+   However, this must be used very carefully, as it becomes easy to
+   create a hold-and-wait condition.
+****************************************/
+       class MutexPool {
+       public:
+           //////////
+           // Create the mutex pool with size mutex objects.
+           MutexPool(const char* name, int size);
+
+           //////////
+           // Destroy the mutex pool and all mutexes in it.
+           ~MutexPool();
+
+           //////////
+           // return the next index in a round-robin fashion
+           int nextIndex();
+
+           //////////
+           // return the idx'th mutex.
+           Mutex* getMutex(int idx);
+
+           //////////
+           // lock the idx'th mutex.
+           void lockMutex(int idx);
+
+           //////////
+           // unlock the idx'th mutex.
+           void unlockMutex(int idx);
+       private:
+           //////////
+           // The next ID
+           AtomicCounter nextID_;
+
+           //////////
+           // The number of Mutexes in the pool
+           int size_;
+
+           //////////
+           // The array of Mutex objects.
+           Mutex** pool_;
+
+           //////////
+           // Private copy ctor to prevent accidental copying
+           MutexPool(const MutexPool&);
+           //////////
+           // Private assignment operator to prevent accidental assignment
+           MutexPool& operator=(const MutexPool&);
+       };
+}
+
+#endif
+

Added: trunk/Core/Thread/Parallel.h
==============================================================================
--- (empty file)
+++ trunk/Core/Thread/Parallel.h        Mon Nov 26 21:56:50 2007
@@ -0,0 +1,117 @@
+/*
+   For more information, please see: http://software.sci.utah.edu
+
+   The MIT License
+
+   Copyright (c) 2004 Scientific Computing and Imaging Institute,
+   University of Utah.
+
+   License for the specific language governing rights and limitations under
+   Permission is hereby granted, free of charge, to any person obtaining a
+   copy of this software and associated documentation files (the "Software"),
+   to deal in the Software without restriction, including without limitation
+   the rights to use, copy, modify, merge, publish, distribute, sublicense,
+   and/or sell copies of the Software, and to permit persons to whom the
+   Software is furnished to do so, subject to the following conditions:
+
+   The above copyright notice and this permission notice shall be included
+   in all copies or substantial portions of the Software.
+
+   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+   OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 
MERCHANTABILITY,
+   FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+   THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+   LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+   FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+   DEALINGS IN THE SOFTWARE.
+*/
+
+
+
+/*
+ *  Parallel: Automatically instantiate several threads
+ *
+ *  Written by:
+ *   Author: Steve Parker
+ *   Department of Computer Science
+ *   University of Utah
+ *   Date: June 1997
+ *
+ *  Copyright (C) 1997 SCI Group
+ */
+
+#ifndef Manta_Parallel_h
+#define Manta_Parallel_h
+
+#include <Core/Thread/ParallelBase.h>
+#include <Core/Thread/Semaphore.h>
+
+namespace Manta {
+/**************************************

+  CLASS
+  Parallel
+   
+  KEYWORDS
+  Thread
+   
+  DESCRIPTION
+  Helper class to make instantiating threads to perform a parallel
+  task easier.
+   
+****************************************/
+template<class T> class Parallel  : public ParallelBase {
+public:
+  //////////
+  // Create a parallel object, using the specified member
+  // function instead of <i>parallel</i>.  This will
+  // typically be used like:
+  // <b><pre>Thread::parallel(Parallel&lt;MyClass&gt;(this, 
&amp;MyClass::mymemberfn), nthreads);</pre></b>
+  Parallel(T* obj, void (T::*pmf)(int));
+           
+  //////////
+  // Destroy the Parallel object - the threads will remain alive.
+  virtual ~Parallel();
+  T* obj_;
+  void (T::*pmf_)(int);
+protected:
+  virtual void run(int proc);
+private:
+  // Cannot copy them
+  Parallel(const Parallel&);
+  Parallel<T>& operator=(const Parallel<T>&);
+};
+
+template<class T>
+void
+Parallel<T>::run(int proc)
+{
+    // Copy out do make sure that the call is atomic
+    T* obj=obj_;
+    void (T::*pmf)(int) = pmf_;
+    if(wait_)
+       wait_->up();
+    (obj->*pmf)(proc);
+    // Cannot do anything here, since the object may be deleted by the
+    // time we return
+}
+
+template<class T>
+Parallel<T>::Parallel(T* obj, void (T::*pmf)(int))
+    : obj_(obj), pmf_(pmf)
+{
+    wait_=0; // This may be set by Thread::parallel
+}
+
+template<class T>
+Parallel<T>::~Parallel()
+{
+}
+
+}
+
+#endif
+
+
+
+

Added: trunk/Core/Thread/Parallel1.h
==============================================================================
--- (empty file)
+++ trunk/Core/Thread/Parallel1.h       Mon Nov 26 21:56:50 2007
@@ -0,0 +1,118 @@
+/*
+   For more information, please see: http://software.sci.utah.edu
+
+   The MIT License
+
+   Copyright (c) 2004 Scientific Computing and Imaging Institute,
+   University of Utah.
+
+   License for the specific language governing rights and limitations under
+   Permission is hereby granted, free of charge, to any person obtaining a
+   copy of this software and associated documentation files (the "Software"),
+   to deal in the Software without restriction, including without limitation
+   the rights to use, copy, modify, merge, publish, distribute, sublicense,
+   and/or sell copies of the Software, and to permit persons to whom the
+   Software is furnished to do so, subject to the following conditions:
+
+   The above copyright notice and this permission notice shall be included
+   in all copies or substantial portions of the Software.
+
+   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+   OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 
MERCHANTABILITY,
+   FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+   THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+   LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+   FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+   DEALINGS IN THE SOFTWARE.
+*/
+
+
+
+/*
+ *  Parallel1: Automatically instantiate several threads, with 1 argument
+ *
+ *  Written by:
+ *   Author: Steve Parker
+ *   Department of Computer Science
+ *   University of Utah
+ *   Date: June 2000
+ *
+ *  Copyright (C) 2000 SCI Group
+ */
+
+#ifndef Manta_Parallel1_h
+#define Manta_Parallel1_h
+
+#include <Core/Thread/ParallelBase.h>
+#include <Core/Thread/Semaphore.h>
+
+namespace Manta {
+/**************************************
+
+ CLASS
+ Parallel1
+
+ KEYWORDS
+ Thread
+
+ DESCRIPTION
+ Helper class to make instantiating threads to perform a parallel
+ task easier.
+   
+****************************************/
+template<class T, class Arg1> class Parallel1  : public ParallelBase {
+public:
+  //////////
+  // Create a Parallel1 object, using the specified member
+  // function instead of <i>Parallel1</i>.  This will
+  // typically be used like:
+  // <b><pre>Thread::Parallel1(Parallel1&lt;MyClass&gt;(this, 
&amp;MyClass::mymemberfn), nthreads);</pre></b>
+  Parallel1(T* obj, void (T::*pmf)(int, Arg1), Arg1 a1);
+           
+  //////////
+  // Destroy the Parallel1 object - the threads will remain alive.
+  virtual ~Parallel1();
+  T* obj_;
+  void (T::*pmf_)(int, Arg1);
+  Arg1 a1;
+protected:
+  virtual void run(int proc);
+private:
+  // Cannot copy them
+  Parallel1(const Parallel1&);
+  Parallel1<T, Arg1>& operator=(const Parallel1<T, Arg1>&);
+};
+
+template<class T, class Arg1>
+void
+Parallel1<T, Arg1>::run(int proc)
+{
+    // Copy out do make sure that the call is atomic
+    T* obj=obj_;
+    void (T::*pmf)(int, Arg1) = pmf_;
+    if(wait_)
+       wait_->up();
+    (obj->*pmf)(proc, a1);
+    // Cannot do anything here, since the object may be deleted by the
+    // time we return
+}
+
+template<class T, class Arg1>
+Parallel1<T, Arg1>::Parallel1(T* obj,
+                             void (T::*pmf)(int, Arg1),
+                             Arg1 a1)
+  : obj_(obj), pmf_(pmf), a1(a1)
+{
+  wait_=0; // This may be set by Thread::parallel
+}
+
+template<class T, class Arg1>
+Parallel1<T, Arg1>::~Parallel1()
+{
+}
+
+}
+
+#endif
+
+

Added: trunk/Core/Thread/Parallel2.h
==============================================================================
--- (empty file)
+++ trunk/Core/Thread/Parallel2.h       Mon Nov 26 21:56:50 2007
@@ -0,0 +1,121 @@
+/*
+   For more information, please see: http://software.sci.utah.edu
+
+   The MIT License
+
+   Copyright (c) 2004 Scientific Computing and Imaging Institute,
+   University of Utah.
+
+   License for the specific language governing rights and limitations under
+   Permission is hereby granted, free of charge, to any person obtaining a
+   copy of this software and associated documentation files (the "Software"),
+   to deal in the Software without restriction, including without limitation
+   the rights to use, copy, modify, merge, publish, distribute, sublicense,
+   and/or sell copies of the Software, and to permit persons to whom the
+   Software is furnished to do so, subject to the following conditions:
+
+   The above copyright notice and this permission notice shall be included
+   in all copies or substantial portions of the Software.
+
+   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+   OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 
MERCHANTABILITY,
+   FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+   THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+   LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+   FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+   DEALINGS IN THE SOFTWARE.
+*/
+
+
+
+/*
+ *  Parallel2: Automatically instantiate several threads, with 2 arguments
+ *
+ *  Written by:
+ *   Author: Steve Parker
+ *   Department of Computer Science
+ *   University of Utah
+ *   Date: June 2000
+ *
+ *  Copyright (C) 2000 SCI Group
+ */
+
+#ifndef Manta_Parallel2_h
+#define Manta_Parallel2_h
+
+#include <Core/Thread/ParallelBase.h>
+#include <Core/Thread/Semaphore.h>
+
+namespace Manta {
+/**************************************

+ CLASS
+ Parallel2
+
+ KEYWORDS
+ Thread
+
+ DESCRIPTION
+ Helper class to make instantiating threads to perform a parallel
+ task easier.
+   
+****************************************/
+template<class T, class Arg1, class Arg2> class Parallel2  : public 
ParallelBase {
+public:
+  //////////
+  // Create a Parallel2 object, using the specified member
+  // function instead of <i>Parallel2</i>.  This will
+  // typically be used like:
+  // <b><pre>Thread::Parallel2(Parallel2&lt;MyClass&gt;(this, 
&amp;MyClass::mymemberfn), nthreads);</pre></b>
+  Parallel2(T* obj, void (T::*pmf)(int, Arg1, Arg2), Arg1 a1, Arg2 a2);
+           
+  //////////
+  // Destroy the Parallel2 object - the threads will remain alive.
+  virtual ~Parallel2();
+  T* obj_;
+  void (T::*pmf_)(int, Arg1, Arg2);
+  Arg1 a1;
+  Arg2 a2;
+protected:
+  virtual void run(int proc);
+private:
+  // Cannot copy them
+  Parallel2(const Parallel2&);
+  Parallel2<T, Arg1, Arg2>& operator=(const Parallel2<T, Arg1, Arg2>&);
+};
+
+template<class T, class Arg1, class Arg2>
+void
+Parallel2<T, Arg1, Arg2>::run(int proc)
+{
+    // Copy out do make sure that the call is atomic
+    T* obj=obj_;
+    void (T::*pmf)(int, Arg1, Arg2) = pmf_;
+    if(wait_)
+       wait_->up();
+    (obj->*pmf)(proc, a1, a2);
+    // Cannot do anything here, since the object may be deleted by the
+    // time we return
+}
+
+template<class T, class Arg1, class Arg2>
+Parallel2<T, Arg1, Arg2>::Parallel2(T* obj,
+                                                    void (T::*pmf)(int, 
Arg1, Arg2),
+                                                    Arg1 a1, Arg2 a2)
+    : obj_(obj), pmf_(pmf), a1(a1), a2(a2)
+{
+    wait_=0; // This may be set by Thread::parallel
+}
+
+template<class T, class Arg1, class Arg2>
+Parallel2<T, Arg1, Arg2>::~Parallel2()
+{
+}
+
+}
+#endif
+
+
+
+
+

Added: trunk/Core/Thread/Parallel3.h
==============================================================================
--- (empty file)
+++ trunk/Core/Thread/Parallel3.h       Mon Nov 26 21:56:50 2007
@@ -0,0 +1,124 @@
+/*
+   For more information, please see: http://software.sci.utah.edu
+
+   The MIT License
+
+   Copyright (c) 2004 Scientific Computing and Imaging Institute,
+   University of Utah.
+
+   License for the specific language governing rights and limitations under
+   Permission is hereby granted, free of charge, to any person obtaining a
+   copy of this software and associated documentation files (the "Software"),
+   to deal in the Software without restriction, including without limitation
+   the rights to use, copy, modify, merge, publish, distribute, sublicense,
+   and/or sell copies of the Software, and to permit persons to whom the
+   Software is furnished to do so, subject to the following conditions:
+
+   The above copyright notice and this permission notice shall be included
+   in all copies or substantial portions of the Software.
+
+   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+   OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 
MERCHANTABILITY,
+   FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+   THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+   LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+   FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+   DEALINGS IN THE SOFTWARE.
+*/
+
+
+
+/*
+ *  Parallel3: Automatically instantiate several threads, with 3 arguments
+ *
+ *  Written by:
+ *   Author: Steve Parker
+ *   Department of Computer Science
+ *   University of Utah
+ *   Date: June 3997
+ *
+ *  Copyright (C) 3997 SCI Group
+ */
+
+#ifndef Manta_Parallel3_h
+#define Manta_Parallel3_h
+
+#include <Core/Thread/ParallelBase.h>
+#include <Core/Thread/Semaphore.h>
+
+namespace Manta {
+/**************************************
+
+ CLASS
+ Parallel3
+
+ KEYWORDS
+ Thread
+
+ DESCRIPTION
+ Helper class to make instantiating threads to perform a parallel
+ task easier.
+   
+****************************************/
+template<class T, class Arg1, class Arg2, class Arg3> class Parallel3  : 
public ParallelBase {
+public:
+  //////////
+  // Create a Parallel3 object, using the specified member
+  // function instead of <i>Parallel3</i>.  This will
+  // typically be used like:
+  // <b><pre>Thread::Parallel3(Parallel3&lt;MyClass&gt;(this, 
&amp;MyClass::mymemberfn), nthreads);</pre></b>
+  Parallel3(T* obj, void (T::*pmf)(int, Arg1, Arg2, Arg3), Arg1 a1, Arg2 a2, 
Arg3 a3);
+           
+  //////////
+  // Destroy the Parallel3 object - the threads will remain alive.
+  virtual ~Parallel3();
+  T* obj_;
+  void (T::*pmf_)(int, Arg1, Arg2, Arg3);
+  Arg1 a1;
+  Arg2 a2;
+  Arg3 a3;
+protected:
+  virtual void run(int proc);
+private:
+  // Cannot copy them
+  Parallel3(const Parallel3&);
+  Parallel3<T, Arg1, Arg2, Arg3>& operator=(const Parallel3<T, Arg1, Arg2, 
Arg3>&);
+};
+
+template<class T, class Arg1, class Arg2, class Arg3>
+void
+Parallel3<T, Arg1, Arg2, Arg3>::run(int proc)
+{
+    // Copy out do make sure that the call is atomic
+    T* obj=obj_;
+    void (T::*pmf)(int, Arg1, Arg2, Arg3) = pmf_;
+    if(wait_)
+       wait_->up();
+    (obj->*pmf)(proc, a1, a2, a3);
+    // Cannot do anything here, since the object may be deleted by the
+    // time we return
+}
+
+template<class T, class Arg1, class Arg2, class Arg3>
+Parallel3<T, Arg1, Arg2, Arg3>::Parallel3(T* obj,
+                                        void (T::*pmf)(int, Arg1, Arg2, 
Arg3),
+                                        Arg1 a1, Arg2 a2, Arg3 a3) : 
+  obj_(obj), 
+  pmf_(pmf), 
+  a1(a1), 
+  a2(a2), 
+  a3(a3)
+{
+  wait_=0; // This may be set by Thread::parallel
+}
+
+template<class T, class Arg1, class Arg2, class Arg3>
+Parallel3<T, Arg1, Arg2, Arg3>::~Parallel3()
+{
+}
+
+}
+
+#endif
+
+

Added: trunk/Core/Thread/ParallelBase.cc
==============================================================================
--- (empty file)
+++ trunk/Core/Thread/ParallelBase.cc   Mon Nov 26 21:56:50 2007
@@ -0,0 +1,56 @@
+/*
+   For more information, please see: http://software.sci.utah.edu
+
+   The MIT License
+
+   Copyright (c) 2004 Scientific Computing and Imaging Institute,
+   University of Utah.
+
+   License for the specific language governing rights and limitations under
+   Permission is hereby granted, free of charge, to any person obtaining a
+   copy of this software and associated documentation files (the "Software"),
+   to deal in the Software without restriction, including without limitation
+   the rights to use, copy, modify, merge, publish, distribute, sublicense,
+   and/or sell copies of the Software, and to permit persons to whom the
+   Software is furnished to do so, subject to the following conditions:
+
+   The above copyright notice and this permission notice shall be included
+   in all copies or substantial portions of the Software.
+
+   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+   OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 
MERCHANTABILITY,
+   FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+   THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+   LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+   FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+   DEALINGS IN THE SOFTWARE.
+*/
+
+
+
+/*
+ *  ParallelBase: Helper class to instantiate several threads
+ *
+ *  Written by:
+ *   Author: Steve Parker
+ *   Department of Computer Science
+ *   University of Utah
+ *   Date: June 1997
+ *
+ *  Copyright (C) 1997 SCI Group
+ */
+
+#include <Core/Thread/ParallelBase.h>
+namespace Manta {
+
+
+ParallelBase::ParallelBase()
+{
+}
+
+ParallelBase::~ParallelBase()
+{
+}
+
+
+} // End namespace Manta

Added: trunk/Core/Thread/ParallelBase.h
==============================================================================
--- (empty file)
+++ trunk/Core/Thread/ParallelBase.h    Mon Nov 26 21:56:50 2007
@@ -0,0 +1,84 @@
+/*
+   For more information, please see: http://software.sci.utah.edu
+
+   The MIT License
+
+   Copyright (c) 2004 Scientific Computing and Imaging Institute,
+   University of Utah.
+
+   License for the specific language governing rights and limitations under
+   Permission is hereby granted, free of charge, to any person obtaining a
+   copy of this software and associated documentation files (the "Software"),
+   to deal in the Software without restriction, including without limitation
+   the rights to use, copy, modify, merge, publish, distribute, sublicense,
+   and/or sell copies of the Software, and to permit persons to whom the
+   Software is furnished to do so, subject to the following conditions:
+
+   The above copyright notice and this permission notice shall be included
+   in all copies or substantial portions of the Software.
+
+   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+   OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 
MERCHANTABILITY,
+   FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+   THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+   LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+   FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+   DEALINGS IN THE SOFTWARE.
+*/
+
+
+
+/*
+ *  ParallelBase: Helper class to instantiate several threads
+ *
+ *  Written by:
+ *   Author: Steve Parker
+ *   Department of Computer Science
+ *   University of Utah
+ *   Date: June 1997
+ *
+ *  Copyright (C) 1997 SCI Group
+ */
+
+#ifndef Manta_ParallelBase_h
+#define Manta_ParallelBase_h
+
+namespace Manta {
+
+class Semaphore;
+/**************************************
+
+ CLASS
+ ParallelBase
+
+ KEYWORDS
+ Thread
+
+ DESCRIPTION
+ Helper class for Parallel class.  This will never be used
+ by a user program.  See <b>Parallel</b> instead.
+   
+****************************************/
+class ParallelBase {
+public:
+  //////////
+  // <i>The thread body</i>
+  virtual void run(int proc)=0;
+
+protected:
+  ParallelBase();
+  virtual ~ParallelBase();
+  mutable Semaphore* wait_; // This may be modified by Thread::parallel
+  friend class Thread;
+
+private:
+  // Cannot copy them
+  ParallelBase(const ParallelBase&);
+  ParallelBase& operator=(const ParallelBase&);
+};
+}
+
+#endif
+
+
+

Added: trunk/Core/Thread/RecursiveMutex.h
==============================================================================
--- (empty file)
+++ trunk/Core/Thread/RecursiveMutex.h  Mon Nov 26 21:56:50 2007
@@ -0,0 +1,103 @@
+/*
+   For more information, please see: http://software.sci.utah.edu
+
+   The MIT License
+
+   Copyright (c) 2004 Scientific Computing and Imaging Institute,
+   University of Utah.
+
+   License for the specific language governing rights and limitations under
+   Permission is hereby granted, free of charge, to any person obtaining a
+   copy of this software and associated documentation files (the "Software"),
+   to deal in the Software without restriction, including without limitation
+   the rights to use, copy, modify, merge, publish, distribute, sublicense,
+   and/or sell copies of the Software, and to permit persons to whom the
+   Software is furnished to do so, subject to the following conditions:
+
+   The above copyright notice and this permission notice shall be included
+   in all copies or substantial portions of the Software.
+
+   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+   OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 
MERCHANTABILITY,
+   FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+   THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+   LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+   FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+   DEALINGS IN THE SOFTWARE.
+*/
+
+
+
+/*
+ *  Barrier: Barrier synchronization primitive
+ *
+ *  Written by:
+ *   Author: Steve Parker
+ *   Department of Computer Science
+ *   University of Utah
+ *   Date: June 1997
+ *
+ *  Copyright (C) 1997 SCI Group
+ */
+
+#ifndef Core_Thread_RecursiveMutex_h
+#define Core_Thread_RecursiveMutex_h
+
+#include <Core/Thread/Mutex.h>
+
+namespace Manta {
+
+class RecursiveMutex_private;
+/**************************************
+
+ CLASS
+ RecursiveMutex
+
+ KEYWORDS
+ Thread
+
+ DESCRIPTION
+ Provides a recursive <b>Mut</b>ual <b>Ex</b>clusion primitive.  Atomic
+ <b>lock()</b> and <b>unlock()</b> will lock and unlock the mutex.
+ Nested calls to <b>lock()</b> by the same thread are acceptable,
+ but must be matched with calls to <b>unlock()</b>.  This class
+ may be less efficient that the <b>Mutex</b> class, and should not
+ be used unless the recursive lock feature is really required.

+****************************************/
+class RecursiveMutex {
+public:
+  //////////
+  // Create the Mutex.  The Mutex is allocated in the unlocked
+  // state. <i>name</i> should be a static string which describe
+  // the primitive for debugging purposes.
+  RecursiveMutex(const char* name);
+
+  //////////
+  // Destroy the Mutex.  Destroying a Mutex in the locked state
+  // has undefined results.
+  ~RecursiveMutex();
+
+  //////////
+  // Acquire the Mutex.  This method will block until the Mutex
+  // is acquired.
+  void lock();
+
+  //////////
+  // Release the Mutex, unblocking any other threads that are
+  // blocked waiting for the Mutex.
+  void unlock();
+
+private:
+  const char* name_;
+  RecursiveMutex_private* priv_;
+
+  // Cannot copy them
+  RecursiveMutex(const RecursiveMutex&);
+  RecursiveMutex& operator=(const RecursiveMutex&);
+};
+}
+
+#endif
+
+

Added: trunk/Core/Thread/RecursiveMutex_default.cc
==============================================================================
--- (empty file)
+++ trunk/Core/Thread/RecursiveMutex_default.cc Mon Nov 26 21:56:50 2007
@@ -0,0 +1,109 @@
+/*
+   For more information, please see: http://software.sci.utah.edu
+
+   The MIT License
+
+   Copyright (c) 2004 Scientific Computing and Imaging Institute,
+   University of Utah.
+
+   License for the specific language governing rights and limitations under
+   Permission is hereby granted, free of charge, to any person obtaining a
+   copy of this software and associated documentation files (the "Software"),
+   to deal in the Software without restriction, including without limitation
+   the rights to use, copy, modify, merge, publish, distribute, sublicense,
+   and/or sell copies of the Software, and to permit persons to whom the
+   Software is furnished to do so, subject to the following conditions:
+
+   The above copyright notice and this permission notice shall be included
+   in all copies or substantial portions of the Software.
+
+   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+   OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 
MERCHANTABILITY,
+   FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+   THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+   LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+   FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+   DEALINGS IN THE SOFTWARE.
+*/
+
+
+
+/*
+ *  Barrier: Barrier synchronization primitive (default implementation)
+ *
+ *  Written by:
+ *   Author: Steve Parker
+ *   Department of Computer Science
+ *   University of Utah
+ *   Date: June 1997
+ *
+ *  Copyright (C) 1997 SCI Group
+ */
+
+#include <Core/Thread/RecursiveMutex.h>
+#include <Core/Thread/Thread.h>
+
+namespace Manta {
+
+struct RecursiveMutex_private {
+  Mutex mylock;
+  Thread* owner;
+  int lock_count;
+  RecursiveMutex_private(const char* name);
+  ~RecursiveMutex_private();
+};
+
+RecursiveMutex_private::RecursiveMutex_private(const char* name)
+  : mylock(name)
+{
+  owner=0;
+  lock_count=0;
+}
+
+RecursiveMutex_private::~RecursiveMutex_private()
+{
+}
+
+RecursiveMutex::RecursiveMutex(const char* name)
+  : name_(name)
+{
+  if(!Thread::isInitialized()){
+    if(getenv("THREAD_SHOWINIT"))
+      fprintf(stderr, "RecursiveMutex: %s\n", name);
+    Thread::initialize();
+  }
+  priv_=new RecursiveMutex_private(name);
+}
+
+RecursiveMutex::~RecursiveMutex()
+{
+  delete priv_;
+  priv_=0;
+}
+
+void
+RecursiveMutex::lock()
+{
+  int oldstate=Thread::couldBlock(name_);
+  Thread* me=Thread::self();
+  if(priv_->owner == me){
+    priv_->lock_count++;
+    return;
+  }
+  priv_->mylock.lock();
+  priv_->owner=me;
+  priv_->lock_count=1;
+  Thread::couldBlockDone(oldstate);
+}
+
+void
+RecursiveMutex::unlock()
+{
+  if(--priv_->lock_count == 0){
+    priv_->owner=0;
+    priv_->mylock.unlock();
+  }
+}
+
+} // End namespace Manta
+

Added: trunk/Core/Thread/Reducer.h
==============================================================================
--- (empty file)
+++ trunk/Core/Thread/Reducer.h Mon Nov 26 21:56:50 2007
@@ -0,0 +1,190 @@
+/*
+   For more information, please see: http://software.sci.utah.edu
+
+   The MIT License
+
+   Copyright (c) 2004 Scientific Computing and Imaging Institute,
+   University of Utah.
+
+   License for the specific language governing rights and limitations under
+   Permission is hereby granted, free of charge, to any person obtaining a
+   copy of this software and associated documentation files (the "Software"),
+   to deal in the Software without restriction, including without limitation
+   the rights to use, copy, modify, merge, publish, distribute, sublicense,
+   and/or sell copies of the Software, and to permit persons to whom the
+   Software is furnished to do so, subject to the following conditions:
+
+   The above copyright notice and this permission notice shall be included
+   in all copies or substantial portions of the Software.
+
+   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+   OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 
MERCHANTABILITY,
+   FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+   THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+   LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+   FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+   DEALINGS IN THE SOFTWARE.
+*/
+
+
+
+/*
+ *  Reducer: A barrier with reduction operations
+ *
+ *  Written by:
+ *   Author: Steve Parker
+ *   Department of Computer Science
+ *   University of Utah
+ *   Date: June 1997
+ *
+ *  Copyright (C) 1997 SCI Group
+ */
+
+#ifndef Manta_Reducer_h
+#define Manta_Reducer_h
+
+#include <Core/Thread/Barrier.h>
+
+namespace Manta {
+
+/**************************************

+CLASS
+   Reducer
+   
+KEYWORDS
+   Thread
+   
+DESCRIPTION
+   Perform reduction operations over a set of threads.  Reduction
+   operations include things like global sums, global min/max, etc.
+   In these operations, a local sum (operation) is performed on each
+   thread, and these sums are added together.

+****************************************/
+       template<class T> class Reducer : public Barrier {
+       public:
+           //////////
+           // The function that performs the reduction
+           typedef T (*ReductionOp)(const T&, const T&);
+
+           //////////
+           // Create a <b> Reducer</i>.
+           // At each operation, a barrier wait is performed, and the
+           // operation will be performed to compute the global balue.
+           // <i>name</i> should be a static string which describes
+           // the primitive for debugging purposes.
+           // op is a function which will compute a reduced value from
+           // a pair of values.  op should be associative and commutative,
+           // even up to floating point errors.
+           Reducer(const char* name, ReductionOp);
+
+           //////////
+           // Destroy the Reducer and free associated memory.
+           virtual ~Reducer();
+
+           //////////
+           // Performs a global reduction over all of the threads.  As
+           // soon as each thread has called reduce with their local value,
+           // each thread will return the same global reduced value.
+           T reduce(int myrank, int numThreads, const T& value);
+
+       private:
+           T (*f_op)(const T&, const T&);
+           struct DataArray {
+               // We want this on it's own cache line
+               T data_;
+               // Assumes 128 bytes in a cache line...
+               char filler_[128];
+           };
+           DataArray* join_[2];
+
+           struct BufArray {
+               int which;
+               char filler_[128-sizeof(int)];
+           };
+           BufArray* p_;
+
+           int array_size_;
+           void collectiveResize(int proc, int numThreads);
+           void allocate(int size);
+
+           // Cannot copy them
+           Reducer(const Reducer<T>&);
+           Reducer<T>& operator=(const Reducer<T>&);
+       };
+    }
+}
+
+template<class T>
+Reducer<T>::Reducer(const char* name, ReductionOp op)
+    : Barrier(name), f_op(op)
+{
+    array_size_=-1;
+    p_=0;
+}
+
+template<class T>
+void
+Reducer<T>::allocate(int n)
+{
+    join_[0]=new DataArray[2*numThreads+2]-1;
+    join_[1]=join_[0]+numThreads;
+    p_=new BufArray[num_threads_+2]+1;
+    for(int i=0;i<num_threads_;i++)
+        p_[i].whichBuffer_=0;
+    array_size_=n;
+}
+
+template<class T>
+Reducer<T>::~Reducer()
+{
+    if(p_){
+       delete[] (void*)(join_[0]-1);
+       delete[] (void*)(p_-1);
+    }
+}
+
+template<class T>
+void
+Reducer<T>::collectiveResize(int proc, int n)
+{
+    // Extra barrier here to change the array size...
+
+    // We must wait until everybody has seen the array size change,
+    // or they will skip down too soon...
+    wait(n);
+    if(proc==0){
+       delete[] (void*)(join_[0]-1);
+       delete[] (void*)(p_-1);
+       allocate(n);
+       array_size_=n;
+    }
+    wait(n);
+}
+
+template<class T>
+T
+Reducer<T>::reduce(int proc, int n, const T& myresult)
+{
+    if(n != array_size_){
+        collectiveResize(proc, n);
+    }
+    if(n<=1)
+       return myresult;
+
+    int buf=p_[proc].whichBuffer_;
+    p_[proc].whichBuffer_=1-buf;
+
+    dataArray* j=join_[buf];
+    j[proc].data_=myresult;
+    wait(n);
+    T red=j[0].data_;
+    for(int i=1;i<n;i++)
+        red=(*f_op)(red, j[i].data_);
+    return red;
+}
+
+#endif
+
+

Added: trunk/Core/Thread/Runnable.cc
==============================================================================
--- (empty file)
+++ trunk/Core/Thread/Runnable.cc       Mon Nov 26 21:56:50 2007
@@ -0,0 +1,63 @@
+/*
+   For more information, please see: http://software.sci.utah.edu
+
+   The MIT License
+
+   Copyright (c) 2004 Scientific Computing and Imaging Institute,
+   University of Utah.
+
+   License for the specific language governing rights and limitations under
+   Permission is hereby granted, free of charge, to any person obtaining a
+   copy of this software and associated documentation files (the "Software"),
+   to deal in the Software without restriction, including without limitation
+   the rights to use, copy, modify, merge, publish, distribute, sublicense,
+   and/or sell copies of the Software, and to permit persons to whom the
+   Software is furnished to do so, subject to the following conditions:
+
+   The above copyright notice and this permission notice shall be included
+   in all copies or substantial portions of the Software.
+
+   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+   OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 
MERCHANTABILITY,
+   FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+   THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+   LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+   FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+   DEALINGS IN THE SOFTWARE.
+*/
+
+
+
+/*
+ *  Runnable: The base class for all threads
+ *
+ *  Written by:
+ *   Author: Steve Parker
+ *   Department of Computer Science
+ *   University of Utah
+ *   Date: June 1997
+ *
+ *  Copyright (C) 1997 SCI Group
+ */
+
+#include <Core/Thread/Runnable.h>
+#include <Core/Thread/Thread.h>
+#include <Core/Thread/ThreadError.h>
+namespace Manta {
+
+
+Runnable::Runnable(bool delete_on_exit)
+  : delete_on_exit(delete_on_exit)
+{
+  my_thread_=0;
+}
+
+Runnable::~Runnable()
+{
+  if(my_thread_){
+    throw ThreadError("Runnable is being destroyed while thread is still 
running\n");
+  }
+}
+
+
+} // End namespace Manta

Added: trunk/Core/Thread/Runnable.h
==============================================================================
--- (empty file)
+++ trunk/Core/Thread/Runnable.h        Mon Nov 26 21:56:50 2007
@@ -0,0 +1,108 @@
+/*
+   For more information, please see: http://software.sci.utah.edu
+
+   The MIT License
+
+   Copyright (c) 2004 Scientific Computing and Imaging Institute,
+   University of Utah.
+
+   License for the specific language governing rights and limitations under
+   Permission is hereby granted, free of charge, to any person obtaining a
+   copy of this software and associated documentation files (the "Software"),
+   to deal in the Software without restriction, including without limitation
+   the rights to use, copy, modify, merge, publish, distribute, sublicense,
+   and/or sell copies of the Software, and to permit persons to whom the
+   Software is furnished to do so, subject to the following conditions:
+
+   The above copyright notice and this permission notice shall be included
+   in all copies or substantial portions of the Software.
+
+   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+   OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 
MERCHANTABILITY,
+   FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+   THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+   LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+   FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+   DEALINGS IN THE SOFTWARE.
+*/
+
+
+
+/*
+ *  Runnable: The base class for all threads
+ *
+ *  Written by:
+ *   Author: Steve Parker
+ *   Department of Computer Science
+ *   University of Utah
+ *   Date: June 1997
+ *
+ *  Copyright (C) 1997 SCI Group
+ */
+
+#ifndef Manta_Runnable_h
+#define Manta_Runnable_h
+
+namespace Manta {
+
+  class Thread;
+
+/**************************************

+CLASS
+   Runnable
+   
+KEYWORDS
+   Thread
+   
+DESCRIPTION
+   
+   This class should be a base class for any class which is to be
+   attached to a thread.  It provides a <i>run</i> pure virtual method
+   which should be overridden to provide the thread body.  When this
+   method returns, or the thread calls <i>Thread::exit</i>, the
+   thread terminates.  A <b>Runnable</b> should be attached to
+   only one thread.
+  
+   <p> It is very important that the <b>Runnable</b> object (or any
+   object derived from it) is never explicitly deleted.  It will be
+   deleted by the <b>Thread</b> to which it is attached, when the
+   thread terminates.  The destructor will be executed in the context
+   of this same thread.
+   
+****************************************/
+  class Runnable {
+  protected:
+    friend class Thread;
+    Thread* my_thread_;
+    
+    //////////
+    // Create a new runnable, and initialize it's state.
+    Runnable(bool delete_on_exit = true);
+
+    //////////
+    // The runnable destructor.  See the note above about deleting any
+    // object derived from runnable.
+    virtual ~Runnable();
+
+    //////////
+    // This method will be overridden to implement the main body
+    // of the thread.  This method will called when the runnable
+    // is attached to a <b>Thread</b> object, and will be executed
+    // in a new context.
+    virtual void run()=0;
+  private:
+    bool delete_on_exit;
+
+    // Cannot copy them
+    Runnable(const Runnable&);
+    Runnable& operator=(const Runnable&);
+  };
+}
+
+#endif
+
+
+
+
+

Added: trunk/Core/Thread/Semaphore.h
==============================================================================
--- (empty file)
+++ trunk/Core/Thread/Semaphore.h       Mon Nov 26 21:56:50 2007
@@ -0,0 +1,110 @@
+/*
+   For more information, please see: http://software.sci.utah.edu
+
+   The MIT License
+
+   Copyright (c) 2004 Scientific Computing and Imaging Institute,
+   University of Utah.
+
+   License for the specific language governing rights and limitations under
+   Permission is hereby granted, free of charge, to any person obtaining a
+   copy of this software and associated documentation files (the "Software"),
+   to deal in the Software without restriction, including without limitation
+   the rights to use, copy, modify, merge, publish, distribute, sublicense,
+   and/or sell copies of the Software, and to permit persons to whom the
+   Software is furnished to do so, subject to the following conditions:
+
+   The above copyright notice and this permission notice shall be included
+   in all copies or substantial portions of the Software.
+
+   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+   OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 
MERCHANTABILITY,
+   FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+   THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+   LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+   FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+   DEALINGS IN THE SOFTWARE.
+*/
+
+
+
+/*
+ *  Semaphore: Basic semaphore primitive
+ *
+ *  Written by:
+ *   Author: Steve Parker
+ *   Department of Computer Science
+ *   University of Utah
+ *   Date: June 1997
+ *
+ *  Copyright (C) 1997 SCI Group
+ */
+
+#ifndef Manta_Semaphore_h
+#define Manta_Semaphore_h
+
+namespace Manta {
+
+class Semaphore_private;
+
+/**************************************

+ CLASS
+ Semaphore
+
+ KEYWORDS
+ Thread
+
+ DESCRIPTION
+ Counting semaphore synchronization primitive.  A semaphore provides
+ atomic access to a special counter.  The <i>up</i> method is used
+ to increment the counter, and the <i>down</i> method is used to
+ decrement the counter.  If a thread tries to decrement the counter
+ when the counter is zero, that thread will be blocked until another
+ thread calls the <i>up</i> method.
+
+****************************************/
+class Semaphore {
+public:
+  //////////
+  // Create the semaphore, and setup the initial <i>count.name</i>
+  // should be a static string which describes the primitive for
+  // debugging purposes.
+  Semaphore(const char* name, int count);
+
+  //////////
+  // Destroy the semaphore
+  ~Semaphore();
+
+  //////////
+  // Increment the semaphore count, unblocking up to <i>count</i>
+  // threads that may be blocked in the <i>down</i> method.
+  void up(int count=1);
+    
+  //////////
+  // Decrement the semaphore count by <i>count</i>.  If the
+  // count is zero, this thread will be blocked until another
+  // thread calls the <i>up</i> method. The order in which
+  // threads will be unblocked is not defined, but implementors
+  // should give preference to those threads that have waited
+  // the longest.
+  void down(int count=1);
+
+  //////////
+  // Attempt to decrement the semaphore count by one, but will
+  // never block. If the count was zero, <i>tryDown</i> will
+  // return false. Otherwise, <i>tryDown</i> will return true.
+  bool tryDown();
+
+private:
+  Semaphore_private* priv_;
+  const char* name_;
+
+  // Cannot copy them
+  Semaphore(const Semaphore&);
+  Semaphore& operator=(const Semaphore&);
+};
+}
+
+#endif
+

Added: trunk/Core/Thread/SimpleReducer.cc
==============================================================================
--- (empty file)
+++ trunk/Core/Thread/SimpleReducer.cc  Mon Nov 26 21:56:50 2007
@@ -0,0 +1,150 @@
+/*
+   For more information, please see: http://software.sci.utah.edu
+
+   The MIT License
+
+   Copyright (c) 2004 Scientific Computing and Imaging Institute,
+   University of Utah.
+
+   License for the specific language governing rights and limitations under
+   Permission is hereby granted, free of charge, to any person obtaining a
+   copy of this software and associated documentation files (the "Software"),
+   to deal in the Software without restriction, including without limitation
+   the rights to use, copy, modify, merge, publish, distribute, sublicense,
+   and/or sell copies of the Software, and to permit persons to whom the
+   Software is furnished to do so, subject to the following conditions:
+
+   The above copyright notice and this permission notice shall be included
+   in all copies or substantial portions of the Software.
+
+   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+   OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 
MERCHANTABILITY,
+   FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+   THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+   LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+   FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+   DEALINGS IN THE SOFTWARE.
+*/
+
+
+
+/*
+ *  SimpleReducer: A barrier with reduction operations
+ *
+ *  Written by:
+ *   Author: Steve Parker
+ *   Department of Computer Science
+ *   University of Utah
+ *   Date: June 1997
+ *
+ *  Copyright (C) 1997 SCI Group
+ */
+
+#include <Core/Thread/SimpleReducer.h>
+#include <Core/Thread/ThreadGroup.h>
+namespace Manta {
+
+
+SimpleReducer::SimpleReducer(const char* name)
+    : Barrier(name)
+{
+    array_size_=-1;
+    p_=0;
+    join_[0]=0;
+    join_[1]=0;
+}
+
+SimpleReducer::~SimpleReducer()
+{
+    if(p_){
+       delete[] join_[0];
+       delete[] join_[1];
+       delete[] p_;
+    }
+}
+
+void
+SimpleReducer::collectiveResize(int proc, int n)
+{
+    // Extra barrier here to change the array size...
+
+    // We must wait until everybody has seen the array size change,
+    // or they will skip down too soon...
+    wait(n);
+    if(proc==0){
+       if(p_){
+           delete[] join_[0];
+           delete[] join_[1];
+           delete[] p_;
+       }
+        join_[0]=new joinArray[n];
+        join_[1]=new joinArray[n];
+        p_=new pdata[n];
+        for(int i=0;i<n;i++)
+           p_[i].buf_=0;
+        array_size_=n;
+    }
+    wait(n);
+}
+
+double
+SimpleReducer::sum(int proc, int n, double mysum)
+{
+    if(n != array_size_){
+        collectiveResize(proc, n);
+    }
+
+    int buf=p_[proc].buf_;
+    p_[proc].buf_=1-buf;
+
+    joinArray* j=join_[buf];
+    j[proc].d_.d_=mysum;
+    wait(n);
+    double sum=0;
+    for(int i=0;i<n;i++)
+        sum+=j[i].d_.d_;
+    return sum;
+}
+
+double
+SimpleReducer::max(int proc, int n, double mymax)
+{
+    if(n != array_size_){
+        collectiveResize(proc, n);
+    }
+
+    int buf=p_[proc].buf_;
+    p_[proc].buf_=1-buf;
+
+    joinArray* j=join_[buf];
+    j[proc].d_.d_=mymax;
+    Barrier::wait(n);
+    double gmax=j[0].d_.d_;
+    for(int i=1;i<n;i++)
+        if(j[i].d_.d_ > gmax)
+           gmax=j[i].d_.d_;
+    return gmax;
+}
+
+double
+SimpleReducer::min(int proc, int n, double mymin)
+{
+    if(n != array_size_){
+        collectiveResize(proc, n);
+    }
+
+    int buf=p_[proc].buf_;
+    p_[proc].buf_=1-buf;
+
+    joinArray* j=join_[buf];
+    j[proc].d_.d_=mymin;
+    Barrier::wait(n);
+    double gmin=j[0].d_.d_;
+    for(int i=1;i<n;i++)
+        if(j[i].d_.d_ < gmin)
+           gmin=j[i].d_.d_;
+    return gmin;
+}
+
+
+} // End namespace Manta

Added: trunk/Core/Thread/SimpleReducer.h
==============================================================================
--- (empty file)
+++ trunk/Core/Thread/SimpleReducer.h   Mon Nov 26 21:56:50 2007
@@ -0,0 +1,123 @@
+/*
+   For more information, please see: http://software.sci.utah.edu
+
+   The MIT License
+
+   Copyright (c) 2004 Scientific Computing and Imaging Institute,
+   University of Utah.
+
+   License for the specific language governing rights and limitations under
+   Permission is hereby granted, free of charge, to any person obtaining a
+   copy of this software and associated documentation files (the "Software"),
+   to deal in the Software without restriction, including without limitation
+   the rights to use, copy, modify, merge, publish, distribute, sublicense,
+   and/or sell copies of the Software, and to permit persons to whom the
+   Software is furnished to do so, subject to the following conditions:
+
+   The above copyright notice and this permission notice shall be included
+   in all copies or substantial portions of the Software.
+
+   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+   OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 
MERCHANTABILITY,
+   FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+   THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+   LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+   FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+   DEALINGS IN THE SOFTWARE.
+*/
+
+
+
+/*
+ *  SimpleReducer: A barrier with reduction operations
+ *
+ *  Written by:
+ *   Author: Steve Parker
+ *   Department of Computer Science
+ *   University of Utah
+ *   Date: June 1997
+ *
+ *  Copyright (C) 1997 SCI Group
+ */
+
+#ifndef Manta_SimpleReducer_h
+#define Manta_SimpleReducer_h
+
+#include <Core/Thread/Barrier.h>
+
+namespace Manta {
+
+/**************************************

+CLASS
+   SimpleReducer
+   
+KEYWORDS
+   Thread
+   
+DESCRIPTION
+   Perform reduction operations over a set of threads.  Reduction
+   operations include things like global sums, global min/max, etc.
+   In these operations, a local sum (operation) is performed on each
+   thread, and these sums are added together.
+   
+****************************************/
+       class SimpleReducer : public Barrier {
+       public:
+           //////////
+           // Create a <b> SimpleReducer</i>.
+           // At each operation, a barrier wait is performed, and the
+           // operation will be performed to compute the global balue.
+           // <i>name</i> should be a static string which describes
+           // the primitive for debugging purposes.
+           SimpleReducer(const char* name);
+
+           //////////
+           // Destroy the SimpleReducer and free associated memory.
+           virtual ~SimpleReducer();
+
+           //////////
+           // Performs a global sum over all of the threads.  As soon as each
+           // thread has called sum with their local sum, each thread will
+           // return the same global sum.
+           double sum(int myrank, int numThreads, double mysum);
+
+           //////////
+           // Performs a global max over all of the threads.  As soon as each
+           // thread has called max with their local max, each thread will
+           // return the same global max.
+           double max(int myrank, int numThreads, double mymax);
+
+           //////////
+           // Performs a global min over all of the threads.  As soon as each
+           // thread has called min with their local max, each thread will
+           // return the same global max.
+           double min(int myrank, int numThreads, double mymax);
+
+       private:
+           struct data {
+               double d_;
+           };
+           struct joinArray {
+               data d_;
+               // Assumes 128 bytes in a cache line...
+               char filler_[128-sizeof(data)];
+           };
+           struct pdata {
+               int buf_;
+               char filler_[128-sizeof(int)];  
+           };
+           joinArray* join_[2];
+           pdata* p_;
+           int array_size_;
+           void collectiveResize(int proc, int numThreads);
+
+           // Cannot copy them
+           SimpleReducer(const SimpleReducer&);
+           SimpleReducer& operator=(const SimpleReducer&);
+       };
+}
+
+#endif
+
+

Added: trunk/Core/Thread/Thread.cc
==============================================================================
--- (empty file)
+++ trunk/Core/Thread/Thread.cc Mon Nov 26 21:56:50 2007
@@ -0,0 +1,439 @@
+/*
+   For more information, please see: http://software.sci.utah.edu
+
+   The MIT License
+
+   Copyright (c) 2004 Scientific Computing and Imaging Institute,
+   University of Utah.
+
+   License for the specific language governing rights and limitations under
+   Permission is hereby granted, free of charge, to any person obtaining a
+   copy of this software and associated documentation files (the "Software"),
+   to deal in the Software without restriction, including without limitation
+   the rights to use, copy, modify, merge, publish, distribute, sublicense,
+   and/or sell copies of the Software, and to permit persons to whom the
+   Software is furnished to do so, subject to the following conditions:
+
+   The above copyright notice and this permission notice shall be included
+   in all copies or substantial portions of the Software.
+
+   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+   OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 
MERCHANTABILITY,
+   FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+   THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+   LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+   FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+   DEALINGS IN THE SOFTWARE.
+*/
+
+
+
+/*
+ *  Thread: The thread class
+ *
+ *  Written by:
+ *   Author: Steve Parker
+ *   Department of Computer Science
+ *   University of Utah
+ *   Date: June 1997
+ *
+ *  Copyright (C) 1997 SCI Group
+ */
+
+#include <Core/Thread/Thread.h>
+#include <Core/Exceptions/Exception.h>
+#include <Core/Thread/Parallel.h>
+#include <Core/Thread/Runnable.h>
+#include <Core/Thread/ThreadError.h>
+#include <Core/Thread/ThreadGroup.h>
+#include <Core/Thread/Time.h>
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string>
+
+#if defined(_AIX)
+// Needed for strcasecmp on aix 4.3 (on 5.1 we don't need this.)
+// currently blue is 4.3.
+#  include <strings.h>
+#endif
+
+#include <string.h>
+#include <sys/types.h>
+#ifdef _WIN32
+#include <windows.h>
+#include <winnt.h>
+#include <io.h>
+#include <process.h>
+#include <imagehlp.h>
+#include <psapi.h>
+#include <libexc.h>
+#elif defined(__GNUC__) && defined(__linux)
+#include <execinfo.h>
+#endif
+
+
+
+
+
+// provide "C" interface to exitAll
+extern "C" { 
+void exit_all_threads(int rc) {
+  Manta::Thread::exitAll(rc);
+}
+}
+namespace Manta {
+
+class ParallelHelper : public Runnable {
+  ParallelBase &helper_;
+  int proc_;
+public:
+  ParallelHelper(ParallelBase& helper, int proc)
+    : helper_(helper), proc_(proc) {}
+  virtual ~ParallelHelper() {}
+  virtual void run() {
+    helper_.run(proc_);
+  }
+};
+
+bool Thread::initialized = false;
+const char* Thread::defaultAbortMode = "ask";
+bool Thread::callExit = true;
+
+
+bool Thread::isInitialized()
+{
+  return initialized;
+}
+
+void Thread::setDefaultAbortMode(const char* abortMode)
+{
+  defaultAbortMode = abortMode;
+}
+
+Thread::~Thread()
+{
+    if(runner_){
+        runner_->my_thread_=0;
+       if(runner_->delete_on_exit)
+         delete runner_;
+    }
+    free(const_cast<char *>(threadname_));
+}
+
+Thread::Thread(ThreadGroup* g, const char* name)
+{
+    group_=g;
+    g->addme(this);
+    threadname_=strdup(name);
+    daemon_=false;
+    detached_=false;
+    runner_=0;
+    cpu_=-1;
+    stacksize_ = Thread::DEFAULT_STACKSIZE;
+}
+
+void
+Thread::run_body()
+{
+    try {
+       runner_->run();
+    } catch(const ThreadError& e){
+       fprintf(stderr, "Caught unhandled Thread error:\n%s\n",
+               e.message());
+       Thread::niceAbort();
+    } catch(const Exception& e){
+       fprintf(stderr, "Caught unhandled exception:\n%s\n",e.message());
+        const char *trace = e.stackTrace();
+        if (trace)
+          fprintf(stderr, "Exception %s", trace);
+       Thread::niceAbort();
+    } catch(const std::string &e){
+      fprintf(stderr, "Caught unhandled string exception:\n%s\n", e.c_str());
+      Thread::niceAbort();
+    } catch(const char *&e){
+      fprintf(stderr, "Caught unhandled char exception:\n%s\n", e);
+      Thread::niceAbort();
+#ifndef _MSC_VER 
+    // catch these differently with MS compiler, we can get the whole stack 
trace, but it must be done with
+    // an MS-specific exception handler in a different function
+    } catch(...){
+       fprintf(stderr, "Caught unhandled exception of unknown type\n");
+       Thread::niceAbort();
+#endif
+    }
+}
+
+Thread::Thread(Runnable* runner, const char* name,
+              ThreadGroup* group, ActiveState state,
+               unsigned long stacksize)
+    : runner_(runner),
+      threadname_(strdup(name)),
+      group_(group),
+      stacksize_(stacksize),
+      daemon_(false),
+      detached_(false),
+      cpu_(-1)
+{
+    if(group_ == 0){
+        if(!ThreadGroup::s_default_group)
+           Thread::initialize();
+        group_=ThreadGroup::s_default_group;
+    }
+
+    runner_->my_thread_=this;
+    group_->addme(this);
+    switch(state){
+    case Activated:
+       os_start(false);
+       activated_=true;
+       break;
+    case Stopped:
+       os_start(true);
+       activated_=true;
+       break;
+    case NotActivated:
+       activated_=false;
+       priv_=0;
+       break;
+    }
+}
+
+void
+Thread::activate(bool stopped)
+{
+    if(activated_)
+       throw ThreadError("Thread is already activated");
+    activated_=true;
+    os_start(stopped);
+}
+
+ThreadGroup*
+Thread::getThreadGroup()
+{
+    return group_;
+}
+
+Runnable*
+Thread::getRunnable()
+{
+    return runner_;
+}
+
+void
+Thread::setDaemon(bool to)
+{
+    daemon_=to;
+    checkExit();
+}
+
+bool
+Thread::isDaemon() const
+{
+    return daemon_;
+}
+
+bool
+Thread::isDetached() const
+{
+    return detached_;
+}
+
+const char*
+Thread::getThreadName() const
+{
+    return threadname_;
+}
+
+ThreadGroup*
+Thread::parallel(ParallelBase& helper, int nthreads,
+                bool block, ThreadGroup* threadGroup)
+{
+  if (block && nthreads <= 1)
+  {
+    helper.run(0);
+    return 0;
+  }
+
+  ThreadGroup* newgroup=new ThreadGroup("Parallel group", threadGroup);
+  if(!block){
+    // Extra synchronization to make sure that helper doesn't
+    // get destroyed before the threads actually start
+    helper.wait_=new Semaphore("Thread::parallel startup wait", 0);
+  }
+  for(int i=0;i<nthreads;i++){
+    char buf[50];
+    sprintf(buf, "Parallel thread %d of %d", i, nthreads);
+    new Thread(new ParallelHelper(helper, i), buf,
+              newgroup, Thread::Stopped);
+  }
+  newgroup->gangSchedule();
+  newgroup->resume();
+  if(block){
+    newgroup->join();
+    delete newgroup;
+    return 0;
+  } else {
+    helper.wait_->down(nthreads);
+    delete helper.wait_;
+    newgroup->detach();
+  }
+  return newgroup;
+}
+
+void
+Thread::niceAbort(void* context /* = 0 */)
+{
+  fprintf(stderr, getStackTrace(context).c_str());
+  const char* smode = getenv("SCI_SIGNALMODE");
+  if (!smode)
+    smode = defaultAbortMode; //"e"; 
+       
+  Thread* s=Thread::self();
+  print_threads();
+  fprintf(stderr, "\n");
+  fprintf(stderr, "Abort signalled by pid: %d\n", getpid());
+  if(s)
+    fprintf(stderr, "Occured for thread: \"%s\"\n", s->threadname_);
+  else
+    fprintf(stderr, "With NULL thread pointer.\n");
+
+  for (;;) {
+    if (strcasecmp(smode, "ask") == 0) {
+      char buf[100];
+      fprintf(stderr, "resume(r)/dbx(d)/cvd(c)/kill thread(k)/exit(e)? ");
+      fflush(stderr);
+      while(read(fileno(stdin), buf, 100) <= 0){
+       if(errno != EINTR){
+         fprintf(stderr, "\nCould not read response, sleeping for 20 
seconds.\n");
+          Time::waitFor(20.0);
+         buf[0]='e';
+         exitAll(1);
+       }
+      }
+      switch (buf[0]) {
+      case 'r': case 'R':
+       smode = "resume";
+       break;
+      case 'd': case 'D':
+       smode = "dbx";
+       break;
+      case 'c': case 'C':
+       smode = "cvd";
+       break;
+      case 'k': case 'K':
+       smode = "kill";
+       break;
+      case 'e': case 'E':
+       smode = "exit";
+       break;
+      default:
+       break;
+      }
+    }
+
+    if (strcasecmp(smode, "resume") == 0) {
+      return;
+    } else if (strcasecmp(smode, "dbx") == 0) {
+
+#if defined( REDSTORM )
+      printf("Error: running debugger at exception is not supported on 
RedStorm\n");
+#else
+      char command[500];
+      if(getenv("SCI_DBXCOMMAND")){
+       sprintf(command, getenv("SCI_DBXCOMMAND"), getpid());
+      } else {
+#ifdef __sgi
+       sprintf(command, "winterm -c dbx -p %d &", getpid());
+#else
+       sprintf(command, "xterm -e gdb %d &", getpid());
+#endif
+      }
+      system(command);
+      smode = "ask";
+#endif
+    } else if (strcasecmp(smode, "cvd") == 0) {
+#if defined( REDSTORM )
+      printf("Error: running debugger at exception is not supported on 
RedStorm\n");
+#else
+      char command[500];
+      sprintf(command, "cvd -pid %d &", getpid());
+      system(command);
+      smode = "ask";
+#endif
+    } else if (strcasecmp(smode, "kill") == 0) {
+      exit();
+    } else if (strcasecmp(smode, "exit") == 0) {
+      exitAll(1);
+    } else {
+      fprintf(stderr, "Unrecognized option, exiting\n");
+      smode = "exit";
+    }
+  }
+}
+
+int
+Thread::couldBlock(const char* why)
+{
+  if(!initialized)
+    Thread::initialize();
+  Thread_private* p=Thread::self()->priv_;
+  return push_bstack(p, BLOCK_ANY, why);
+}
+
+void
+Thread::couldBlockDone(int restore)
+{
+  Thread_private* p=Thread::self()->priv_;
+  pop_bstack(p, restore);
+}
+
+unsigned long
+Thread::getStackSize() const
+{
+  return stacksize_;
+}
+
+void
+Thread::setStackSize(unsigned long stacksize)
+{
+  if(activated_)
+    throw ThreadError("Cannot change stack size on a running thread");
+  stacksize_=stacksize;
+}
+
+/*
+ * Return the statename for p
+ */
+const char*
+Thread::getStateString(ThreadState state)
+{
+  switch(state) {
+  case STARTUP:
+    return "startup";
+  case RUNNING:
+    return "running";
+  case IDLE:
+    return "idle";
+  case SHUTDOWN:
+    return "shutting down";
+  case BLOCK_SEMAPHORE:
+    return "blocking on semaphore";
+  case PROGRAM_EXIT:
+    return "waiting for program exit";
+  case JOINING:
+    return "joining with thread";
+  case BLOCK_MUTEX:
+    return "blocking on mutex";
+  case BLOCK_ANY:
+    return "blocking";
+  case DIED:
+    return "died";
+  case BLOCK_BARRIER:
+    return "spinning in barrier";
+  default:
+    return "UNKNOWN";
+  }
+}
+
+} // End namespace Manta

Added: trunk/Core/Thread/Thread.h
==============================================================================
--- (empty file)
+++ trunk/Core/Thread/Thread.h  Mon Nov 26 21:56:50 2007
@@ -0,0 +1,376 @@
+/*
+   For more information, please see: http://software.sci.utah.edu
+
+   The MIT License
+
+   Copyright (c) 2004 Scientific Computing and Imaging Institute,
+   University of Utah.
+
+   License for the specific language governing rights and limitations under
+   Permission is hereby granted, free of charge, to any person obtaining a
+   copy of this software and associated documentation files (the "Software"),
+   to deal in the Software without restriction, including without limitation
+   the rights to use, copy, modify, merge, publish, distribute, sublicense,
+   and/or sell copies of the Software, and to permit persons to whom the
+   Software is furnished to do so, subject to the following conditions:
+
+   The above copyright notice and this permission notice shall be included
+   in all copies or substantial portions of the Software.
+
+   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+   OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 
MERCHANTABILITY,
+   FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+   THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+   LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+   FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+   DEALINGS IN THE SOFTWARE.
+*/
+
+
+
+/*
+ *  Thread: The thread class
+ *
+ *  Written by:
+ *   Author: Steve Parker
+ *   Department of Computer Science
+ *   University of Utah
+ *   Date: June 1997
+ *
+ *  Copyright (C) 1997 SCI Group
+ */
+
+#ifndef Manta_Thread_h
+#define Manta_Thread_h
+
+#include <Core/Thread/Parallel.h>
+#include <Core/Thread/Parallel1.h>
+#include <Core/Thread/Parallel2.h>
+#include <Core/Thread/Parallel3.h>
+
+namespace Manta {
+       struct Thread_private;
+       class ParallelBase;
+       class Runnable;
+       class ThreadGroup;
+       
+/**************************************

+CLASS
+   Thread
+   
+KEYWORDS
+   Thread
+   
+DESCRIPTION
+
+   The Thread class provides a new context in which to run.  A single
+   Runnable class is attached to a single Thread class, which are
+   executed in another thread.
+   
+****************************************/
+       class Thread {
+#ifdef SCI_64BITS
+          static const unsigned long DEFAULT_STACKSIZE  = 256 * 1024; // 128 
KB
+#else
+          static const unsigned long DEFAULT_STACKSIZE  = 128 * 1024; // 128 
KB
+#endif
+       public:
+           //////////
+           // Possible thread start states
+           enum ActiveState {
+               Activated,
+               Stopped,
+               NotActivated
+           };
+           
+           //////////
+           // Create a thread, which will execute the <b>run()</b>
+           // method in the <b>runner</b> object. The thread <b>name</b>
+           // is used for identification purposes, and does not need to
+           // be unique with respect to other threads.  <b>Group</b>
+           // specifies the ThreadGroup that to which this thread
+           // should belong.  If no group is specified (group==0),
+           // the default group is used.
+           Thread(Runnable* runner,
+                   const char* name,
+                  ThreadGroup* group=0, 
+                   ActiveState state=Activated,
+                   unsigned long stack_size = DEFAULT_STACKSIZE);
+
+           //////////
+           // Return the <b>ThreadGroup</b> associated with this thread.
+           ThreadGroup* getThreadGroup();
+           
+           //////////
+           // Return the <b>Runnable</b> associated with this thread.
+           Runnable* getRunnable();
+           
+           //////////
+           // Flag the thread as a daemon thread.  When all non-deamon
+           // threads exit, the program will exit.
+           void setDaemon(bool to=true);
+           
+           //////////
+           // Returns true if the thread is tagged as a daemon thread.
+           bool isDaemon() const;
+           
+           //////////
+           // If the thread is started in the the NotActivated state,
+           // use this to activate the thread (the argument should be
+           // false).
+           void activate(bool stopped);
+           
+           //////////
+           // Arrange to have the thread deleted automatically at exit.
+           // The pointer to the thread should not be used by any other
+           // threads once this has been called.
+           void detach();
+           
+           //////////
+           // Returns true if the thread is detached
+           bool isDetached() const;
+           
+           //////////
+           // Set the stack size for a particular thread.  In order
+           // to use this thread, you must create the thread in the
+           // NotActivated state, set the stack size, and then start
+           // the thread using activate(false).  Setting the stack
+           // size for a thread that is running or has ever been run,
+           // will throw an exception.  The units are in bytes.
+           void setStackSize(unsigned long stackSize);
+           
+           //////////
+           // Returns the stack size for the thread
+           unsigned long getStackSize() const;
+           
+           //////////
+           // Kill all threads and exit with <b>code</b>.
+           static void exitAll(int code);
+           
+           //////////
+           // Exit the currently running thread
+           static void exit();
+           
+           //////////
+           // Returns a pointer to the currently running thread.
+           static Thread* self();
+           
+           //////////
+           // Stop the thread.
+           void stop();
+           
+           //////////
+           // Resume the thread
+           void resume();
+           
+           //////////
+           // Blocks the calling thread until this thead has finished
+           // executing. You cannot join detached threads or daemon threads.
+           void join();
+           
+           //////////
+           // Returns the name of the thread
+           const char* getThreadName() const;
+           
+           //////////
+           // Returns the number of processors on the system
+           static int numProcessors();
+           
+           //////////
+           // Request that the thread migrate to processor <i>proc</i>.
+           // If <i>proc</i> is -1, then the thread is free to run
+           // anywhere.
+           void migrate(int proc);
+           
+           //////////
+           // Start up several threads that will run in parallel.  A new
+           // <b>ThreadGroup</b> is created as a child of the optional 
parent.
+           // If <i>block</i> is true, then the caller will block until all
+           // of the threads return.  Otherwise, the call will return
+           // immediately.
+           static ThreadGroup* parallel(ParallelBase& helper,
+                                        int nthreads, bool block,
+                                        ThreadGroup* threadGroup=0);
+
+           //////////
+           // Start up several threads that will run in parallel.
+           // If <i>block</i> is true, then the caller will block until all
+           // of the threads return.  Otherwise, the call will return
+           // immediately.
+           template<class T>
+           static void parallel(T* ptr, void (T::*pmf)(int),
+                                int numThreads)
+            {
+              if (numThreads <= 1) { (ptr->*pmf)(0); }
+              else
+              {
+                Parallel<T> p(ptr, pmf);
+                parallel(p, numThreads, true);
+              }
+           }
+
+           //////////
+           // Another overloaded version of parallel that passes 1 argument
+           template<class T, class Arg1>
+           static void parallel(T* ptr, void (T::*pmf)(int, Arg1),
+                                int numThreads, Arg1 a1)
+            {
+              if (numThreads <= 1) { (ptr->*pmf)(0, a1); }
+              else
+              {
+                Parallel1<T, Arg1> p(ptr, pmf, a1);
+                parallel(p, numThreads, true);
+              }
+           }
+
+           //////////
+           // Another overloaded version of parallel that passes 2 arguments
+           template<class T, class Arg1, class Arg2>
+           static void parallel(T* ptr, void (T::* pmf)(int, Arg1, Arg2),
+                                int numThreads, Arg1 a1, Arg2 a2)
+            {
+              if (numThreads <= 1) { (ptr->*pmf)(0, a1, a2); }
+              else
+              {
+                Parallel2<T, Arg1, Arg2> p(ptr, pmf, a1, a2);
+                parallel(p, numThreads, true);
+              }
+           }
+
+           //////////
+           // Another overloaded version of parallel that passes 3 arguments
+           template<class T, class Arg1, class Arg2, class Arg3>
+           static void parallel(T* ptr, void (T::* pmf)(int, Arg1, Arg2, 
Arg3),
+                                int numThreads, Arg1 a1, Arg2 a2, Arg3 a3)
+            {
+              if (numThreads <= 1) { (ptr->*pmf)(0, a1, a2, a3); }
+              else
+              {
+                Parallel3<T, Arg1, Arg2, Arg3> p(ptr, pmf, a1, a2, a3);
+                parallel(p, numThreads, true);
+              }
+           }
+
+           //////////
+           // Abort the current thread, or the process.  Prints a message on
+           // stderr, and the user may choose one of:
+           // <pre>continue(c)/dbx(d)/cvd(v)/kill thread(k)/exit(e)</pre>
+            // context is necesary on Windows to catch a segfault
+           static void niceAbort(void* Context = 0);
+           
+           //////////
+           // Mark a section as one that could block for debugging purposes.
+           // The <b>int</b> that is returned should be passed into
+           // <i>couldBlockDone(int)</i> when the section has completed.  
This
+           // will typically not be used outside of the thread 
implementation.
+           static int couldBlock(const char* why);
+           
+           //////////
+           // Mark the end of a selection that could block.
+           // <i>restore</i> was returned from a previous invocation
+           // of the above <b>couldBlock</b>.
+           static void couldBlockDone(int restore);
+           
+           //////////
+           // The calling process voluntarily gives up time to another 
process
+           static void yield();
+
+           //////////
+           // Return true if the thread library has been initialized. This
+           // will typically not be used outside of the thread 
implementation.
+           static bool isInitialized();
+
+           //////////
+           // SGI (irix 6.2-6.5.6 at least) maps page 0 for some
+           // OpenGL registers.  This is extremely silly, because now
+           // all programs that dereference null will not crash at
+           // the deref, and will be much harder to debug.  The
+           // thread library mprotects page 0 so that a deref of null
+           // WILL crash.  However, OpenGL programs then break.  This
+           // call unprotects page 0, making OpenGL work and also
+           // making a deref of 0 succeed.  You should call it before
+           // calling your first OpenGL function - usually
+           // glXQueryExtension or glXChooseVisual, glXGetConfig or
+           // similar.  Calling it multiple times is unncessary, but
+           // harmless.
+           static void allow_sgi_OpenGL_page0_sillyness();
+           static void disallow_sgi_OpenGL_page0_sillyness();
+
+            // set to "exit" (or something else) so we don't have to always 
+            // wait for the user to input something
+            static void setDefaultAbortMode(const char* abortMode);
+
+  private:
+    // If you loaded the thread library (via dlopen for example), and
+    // wanted to unload it, the thread library is designed to call
+    // exit for the application.  This is generally undesirable for
+    // plugins that make use of this library.
+    static bool callExit;
+  public:
+    // This only has an effect for the last thread that exits.
+    static void setCallExit(bool new_val) { callExit = new_val; }
+    static bool getCallExit() { return callExit; }
+       private:
+#ifdef _WIN32
+            // in windows, we can't get around this with #define private 
public
+            //   since it knows which symbols at link-time are public and 
private.
+           friend class Runnable;          
+            friend class ConditionVariable;
+            friend void Thread_run(Thread* t);
+            friend void Thread_shutdown(Thread* thread, bool actually_exit);
+           friend unsigned long run_threads(void* priv_v);
+#endif
+            
+           friend struct Thread_private;
+
+           Runnable* runner_;
+           const char* threadname_;
+           ThreadGroup* group_;
+           unsigned long stacksize_;
+           bool daemon_;
+           bool detached_;
+           bool activated_;
+           void os_start(bool stopped);
+           Thread(ThreadGroup* g, const char* name);
+
+           static bool initialized;
+           static void initialize();
+           static void checkExit();
+
+            static const char* defaultAbortMode;
+           int cpu_;
+           ~Thread();
+           Thread_private* priv_;
+           static int id();
+           void run_body();                
+           enum ThreadState {
+               STARTUP,
+               RUNNING,
+               IDLE,
+               SHUTDOWN,
+               DIED,
+               PROGRAM_EXIT,
+               JOINING,
+               BLOCK_ANY,
+               BLOCK_BARRIER,
+               BLOCK_MUTEX,
+               BLOCK_SEMAPHORE,
+               BLOCK_CONDITIONVARIABLE
+           };
+
+           static const char* getStateString(ThreadState);
+           static int push_bstack(Thread_private*, ThreadState s,
+                                  const char* why);
+           static void pop_bstack(Thread_private*, int oldstate);
+           static void print_threads();
+
+           // Cannot copy them
+           Thread(const Thread&);
+           Thread& operator=(const Thread&);
+       };      
+}
+
+#endif
+
+

Added: trunk/Core/Thread/ThreadError.cc
==============================================================================
--- (empty file)
+++ trunk/Core/Thread/ThreadError.cc    Mon Nov 26 21:56:50 2007
@@ -0,0 +1,74 @@
+/*
+   For more information, please see: http://software.sci.utah.edu
+
+   The MIT License
+
+   Copyright (c) 2004 Scientific Computing and Imaging Institute,
+   University of Utah.
+
+   License for the specific language governing rights and limitations under
+   Permission is hereby granted, free of charge, to any person obtaining a
+   copy of this software and associated documentation files (the "Software"),
+   to deal in the Software without restriction, including without limitation
+   the rights to use, copy, modify, merge, publish, distribute, sublicense,
+   and/or sell copies of the Software, and to permit persons to whom the
+   Software is furnished to do so, subject to the following conditions:
+
+   The above copyright notice and this permission notice shall be included
+   in all copies or substantial portions of the Software.
+
+   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+   OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 
MERCHANTABILITY,
+   FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+   THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+   LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+   FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+   DEALINGS IN THE SOFTWARE.
+*/
+
+
+
+/*
+ *  ThreadError: Exception class for unusual errors in the thread library
+ *
+ *  Written by:
+ *   Author: Steve Parker
+ *   Department of Computer Science
+ *   University of Utah
+ *   Date: August 1999
+ *
+ *  Copyright (C) 1999 SCI Group
+ */
+
+#include <Core/Thread/ThreadError.h>
+namespace Manta {
+
+
+ThreadError::ThreadError(const std::string& message)
+    : message_(message)
+{
+}
+
+ThreadError::ThreadError(const ThreadError& copy)
+    : message_(copy.message_)
+{
+}
+
+ThreadError::~ThreadError()
+{
+}
+
+const char*
+ThreadError::message() const
+{
+    return message_.c_str();
+}
+
+const char*
+ThreadError::type() const
+{
+    return "ThreadError";
+}
+
+
+} // End namespace Manta

Added: trunk/Core/Thread/ThreadError.h
==============================================================================
--- (empty file)
+++ trunk/Core/Thread/ThreadError.h     Mon Nov 26 21:56:50 2007
@@ -0,0 +1,96 @@
+/*
+   For more information, please see: http://software.sci.utah.edu
+
+   The MIT License
+
+   Copyright (c) 2004 Scientific Computing and Imaging Institute,
+   University of Utah.
+
+   License for the specific language governing rights and limitations under
+   Permission is hereby granted, free of charge, to any person obtaining a
+   copy of this software and associated documentation files (the "Software"),
+   to deal in the Software without restriction, including without limitation
+   the rights to use, copy, modify, merge, publish, distribute, sublicense,
+   and/or sell copies of the Software, and to permit persons to whom the
+   Software is furnished to do so, subject to the following conditions:
+
+   The above copyright notice and this permission notice shall be included
+   in all copies or substantial portions of the Software.
+
+   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+   OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 
MERCHANTABILITY,
+   FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+   THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+   LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+   FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+   DEALINGS IN THE SOFTWARE.
+*/
+
+
+
+/*
+ *  ThreadError: Exception class for unusual errors in the thread library
+ *
+ *  Written by:
+ *   Author: Steve Parker
+ *   Department of Computer Science
+ *   University of Utah
+ *   Date: August 1999
+ *
+ *  Copyright (C) 1999 SCI Group
+ */
+
+#ifndef Manta_ThreadError_h
+#define Manta_ThreadError_h
+
+#include <Core/Exceptions/Exception.h>
+#include <string>
+
+namespace Manta {
+/**************************************

+CLASS
+   ThreadError
+   
+KEYWORDS
+   Exception, Thread
+   
+DESCRIPTION
+   An exception class for serious thread library errors.  They are
+   often not recoverable.
+
+****************************************/
+       class ThreadError : public Exception {
+       public:
+           //////////
+           // Constructor for the ThreadError class.  Message is
+           // a human readable string that explains the reason for
+           // the error
+           ThreadError(const std::string& message);
+
+           //////////
+           // Copy ctor
+           ThreadError(const ThreadError&);
+
+           //////////
+           // Destructor
+           virtual ~ThreadError();
+
+           //////////
+           // returns the message associated with this error
+           virtual const char* message() const;
+
+           //////////
+           // returns the name of this exception (the name of this class)
+           virtual const char* type() const;
+
+       protected:
+       private:
+           std::string message_;
+
+           ThreadError& operator=(const ThreadError&);
+       };
+}
+
+#endif
+

Added: trunk/Core/Thread/ThreadGroup.cc
==============================================================================
--- (empty file)
+++ trunk/Core/Thread/ThreadGroup.cc    Mon Nov 26 21:56:50 2007
@@ -0,0 +1,167 @@
+/*
+   For more information, please see: http://software.sci.utah.edu
+
+   The MIT License
+
+   Copyright (c) 2004 Scientific Computing and Imaging Institute,
+   University of Utah.
+
+   License for the specific language governing rights and limitations under
+   Permission is hereby granted, free of charge, to any person obtaining a
+   copy of this software and associated documentation files (the "Software"),
+   to deal in the Software without restriction, including without limitation
+   the rights to use, copy, modify, merge, publish, distribute, sublicense,
+   and/or sell copies of the Software, and to permit persons to whom the
+   Software is furnished to do so, subject to the following conditions:
+
+   The above copyright notice and this permission notice shall be included
+   in all copies or substantial portions of the Software.
+
+   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+   OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 
MERCHANTABILITY,
+   FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+   THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+   LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+   FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+   DEALINGS IN THE SOFTWARE.
+*/
+
+
+
+/*
+ *  ThreadGroup: A set of threads
+ *
+ *  Written by:
+ *   Author: Steve Parker
+ *   Department of Computer Science
+ *   University of Utah
+ *   Date: June 1997
+ *
+ *  Copyright (C) 1997 SCI Group
+ */
+
+#include <Core/Thread/ThreadGroup.h>
+#include <Core/Thread/Thread.h>
+#include <stdlib.h>
+#include <string.h>
+
+#ifdef _WIN32
+#define for if(0);else for
+#endif
+
+namespace Manta {
+
+ThreadGroup* ThreadGroup::s_default_group;
+//using std::vector;
+using namespace std;
+
+ThreadGroup::ThreadGroup(const char* name, ThreadGroup* parentGroup)
+    : lock_("ThreadGroup lock"), name_(name), parent_(parentGroup)
+{
+    if(parentGroup==0){
+        parent_=s_default_group;
+        if(parent_) // It could still be null if we are making the first one
+           parent_->addme(this);
+    }
+}
+
+ThreadGroup::~ThreadGroup()
+{
+}
+
+int
+ThreadGroup::numActive(bool countDaemon)
+{
+    lock_.lock();
+    int total=0;
+    if(countDaemon){
+        total=(int)threads_.size();
+    } else {
+       for(vector<Thread*>::iterator iter=threads_.begin();
+           iter != threads_.end();iter++)
+           if((*iter)->isDaemon())
+               total++;
+    }
+    for(vector<ThreadGroup*>::iterator iter=groups_.begin();
+       iter != groups_.end();iter++)
+        total+=(*iter)->numActive(countDaemon);
+    lock_.unlock();
+    return total;
+}
+
+void
+ThreadGroup::stop()
+{
+    lock_.lock();
+    for(vector<ThreadGroup*>::iterator iter=groups_.begin();
+       iter != groups_.end();iter++)
+        (*iter)->stop();
+    for(vector<Thread*>::iterator iter=threads_.begin();
+       iter != threads_.end();iter++)
+        (*iter)->stop();
+    lock_.unlock();
+}
+
+void
+ThreadGroup::resume()
+{
+    lock_.lock();
+    for(vector<ThreadGroup*>::iterator iter=groups_.begin();
+       iter != groups_.end();iter++)
+        (*iter)->resume();
+    for(vector<Thread*>::iterator iter=threads_.begin();
+       iter != threads_.end();iter++)
+        (*iter)->resume();
+    lock_.unlock();
+}
+
+void
+ThreadGroup::join()
+{
+    lock_.lock();
+    for(vector<ThreadGroup*>::iterator iter=groups_.begin();
+       iter != groups_.end();iter++)
+        (*iter)->join();
+    for(vector<Thread*>::iterator iter=threads_.begin();
+       iter != threads_.end();iter++)
+        (*iter)->join();
+    lock_.unlock();
+}
+
+void
+ThreadGroup::detach()
+{
+    lock_.lock();
+    for(vector<ThreadGroup*>::iterator iter=groups_.begin();
+       iter != groups_.end();iter++)
+        (*iter)->detach();
+    for(vector<Thread*>::iterator iter=threads_.begin();
+       iter != threads_.end();iter++)
+        (*iter)->detach();
+    lock_.unlock();
+}
+
+ThreadGroup*
+ThreadGroup::parentGroup()
+{
+    return parent_;
+}
+
+void
+ThreadGroup::addme(ThreadGroup* t)
+{
+    lock_.lock();
+    groups_.push_back(t);
+    lock_.unlock();
+}
+
+void
+ThreadGroup::addme(Thread* t)
+{
+    lock_.lock();
+    threads_.push_back(t);
+    lock_.unlock();
+}
+
+
+} // End namespace Manta

Added: trunk/Core/Thread/ThreadGroup.h
==============================================================================
--- (empty file)
+++ trunk/Core/Thread/ThreadGroup.h     Mon Nov 26 21:56:50 2007
@@ -0,0 +1,139 @@
+/*
+   For more information, please see: http://software.sci.utah.edu
+
+   The MIT License
+
+   Copyright (c) 2004 Scientific Computing and Imaging Institute,
+   University of Utah.
+
+   License for the specific language governing rights and limitations under
+   Permission is hereby granted, free of charge, to any person obtaining a
+   copy of this software and associated documentation files (the "Software"),
+   to deal in the Software without restriction, including without limitation
+   the rights to use, copy, modify, merge, publish, distribute, sublicense,
+   and/or sell copies of the Software, and to permit persons to whom the
+   Software is furnished to do so, subject to the following conditions:
+
+   The above copyright notice and this permission notice shall be included
+   in all copies or substantial portions of the Software.
+
+   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+   OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 
MERCHANTABILITY,
+   FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+   THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+   LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+   FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+   DEALINGS IN THE SOFTWARE.
+*/
+
+
+
+/*
+ *  ThreadGroup: A set of threads
+ *
+ *  Written by:
+ *   Author: Steve Parker
+ *   Department of Computer Science
+ *   University of Utah
+ *   Date: June 1997
+ *
+ *  Copyright (C) 1997 SCI Group
+ */
+
+#ifndef Manta_ThreadGroup_h
+#define Manta_ThreadGroup_h
+
+#include <Core/Thread/Mutex.h>
+#include <vector>
+
+namespace Manta {
+
+class Thread;
+
+/**************************************

+CLASS
+   ThreadGroup
+   
+KEYWORDS
+   Thread
+   
+DESCRIPTION
+   A group of threads that are linked together for scheduling
+   and control purposes.  The threads may be stopped, resumed
+   and alerted simultaneously.

+****************************************/
+       class ThreadGroup {
+       public:
+           
+           //////////
+           // Create a thread group with the specified <i>name</i>.
+           // <i>parentGroup</i> specifies the parent <b>ThreadGroup</b>
+           // which defaults to the default top-level group.
+           ThreadGroup(const char* name, ThreadGroup* parentGroup=0);
+           
+           //////////
+           // Destroy the thread group.  All of the running threads
+           // should be stopped before the <b>ThreadGroup</b> is destroyed.
+           ~ThreadGroup();
+           
+           //////////
+           // Return a snapshot of the number of living threads.  If
+           // <i>countDaemon</i> is true, then daemon threads will be
+           // included in the count.
+           int numActive(bool countDaemon);
+           
+           //////////
+           // Stop all of the threads in this thread group
+           void stop();
+           
+           //////////
+           // Resume all of the threads in this thread group
+           void resume();
+           
+           //////////
+           // Wait until all of the threads have completed.
+           void join();
+           
+           //////////
+           // Detach the thread, joins are no longer possible.
+           void detach();
+           
+           //////////
+           // Return the parent <b>ThreadGroup.</b>  Returns null if
+           // this is the default threadgroup.
+           ThreadGroup* parentGroup();
+           
+           //////////
+           // Arrange to have the threadGroup gang scheduled, so that
+           // all of the threads will be executing at the same time if
+           // multiprocessing resources permit.  This interface will
+           // typically be employed by the <i>Thread::parallel</i>
+           // static method, and will typically not be called directly
+           // by user code.  Threads added to the group after this call
+           // may or may not be included in the schedule gang. 
+           void gangSchedule();
+
+       protected:
+           friend class Thread;
+           static ThreadGroup* s_default_group;
+
+       private:
+           Mutex lock_;
+           const char* name_;
+           ThreadGroup* parent_;
+           std::vector<ThreadGroup*> groups_;
+           std::vector<Thread*> threads_;
+           void addme(ThreadGroup* t);
+           void addme(Thread* t);
+
+           // Cannot copy them
+           ThreadGroup(const ThreadGroup&);
+           ThreadGroup& operator=(const ThreadGroup&);
+       };
+}
+
+#endif
+
+

Added: trunk/Core/Thread/ThreadLock.cc
==============================================================================
--- (empty file)
+++ trunk/Core/Thread/ThreadLock.cc     Mon Nov 26 21:56:50 2007
@@ -0,0 +1,99 @@
+/*
+   For more information, please see: http://software.sci.utah.edu
+
+   The MIT License
+
+   Copyright (c) 2004 Scientific Computing and Imaging Institute,
+   University of Utah.
+
+   License for the specific language governing rights and limitations under
+   Permission is hereby granted, free of charge, to any person obtaining a
+   copy of this software and associated documentation files (the "Software"),
+   to deal in the Software without restriction, including without limitation
+   the rights to use, copy, modify, merge, publish, distribute, sublicense,
+   and/or sell copies of the Software, and to permit persons to whom the
+   Software is furnished to do so, subject to the following conditions:
+
+   The above copyright notice and this permission notice shall be included
+   in all copies or substantial portions of the Software.
+
+   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+   OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 
MERCHANTABILITY,
+   FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+   THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+   LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+   FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+   DEALINGS IN THE SOFTWARE.
+*/
+
+

+/*
+ *  TCLTask.cc:
+ *     Mutex that is lockable multiple times within the same thread
+ *  Written by:
+ *   McKAy Davis / Steven G. Parker
+ *   Department of Computer Science
+ *   University of Utah
+ *   August 1994
+ *
+ *  Copyright (C) 1994 SCI Group
+ */
+
+#include <Core/Thread/ThreadLock.h>
+#include <Core/Util/Assert.h>
+
+namespace Manta {
+  
+ThreadLock::ThreadLock(const char *name) :
+  mutex_(name),
+  owner_(0),
+  count_(0)
+{
+}
+    
+void
+ThreadLock::lock()
+{
+  Thread *self = Thread::self();
+  ASSERT(self != 0);
+  if(owner_ == self) {
+    count_++;
+    return;
+  }
+  mutex_.lock();
+  owner_ = self;
+  count_ = 1;
+}
+
+void
+ThreadLock::unlock()
+{
+  ASSERT(count_ > 0);
+  ASSERT(Thread::self() == owner_);
+
+  if(--count_ == 0) {
+    owner_ = 0;
+    mutex_.unlock();
+  }
+}
+
+int
+ThreadLock::try_lock()
+{
+  Thread *self = Thread::self();
+  if(owner_ == self) {
+    count_++;
+    return 1;
+  }
+  if(mutex_.tryLock()) {
+    owner_ = self;
+    count_ = 1;
+    return 1;
+  }
+  return 0;
+}
+
+
+} // End namespace Manta
+

Added: trunk/Core/Thread/ThreadLock.h
==============================================================================
--- (empty file)
+++ trunk/Core/Thread/ThreadLock.h      Mon Nov 26 21:56:50 2007
@@ -0,0 +1,66 @@
+/*
+   For more information, please see: http://software.sci.utah.edu
+
+   The MIT License
+
+   Copyright (c) 2004 Scientific Computing and Imaging Institute,
+   University of Utah.
+
+   License for the specific language governing rights and limitations under
+   Permission is hereby granted, free of charge, to any person obtaining a
+   copy of this software and associated documentation files (the "Software"),
+   to deal in the Software without restriction, including without limitation
+   the rights to use, copy, modify, merge, publish, distribute, sublicense,
+   and/or sell copies of the Software, and to permit persons to whom the
+   Software is furnished to do so, subject to the following conditions:
+
+   The above copyright notice and this permission notice shall be included
+   in all copies or substantial portions of the Software.
+
+   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+   OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 
MERCHANTABILITY,
+   FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+   THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+   LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+   FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+   DEALINGS IN THE SOFTWARE.
+*/
+
+

+/*
+ *  ThreadLock.h:  
+ *     Mutex that is lockable multiple times within the same thread
+ *  Written by:
+ *   McKay Davis / Steven G. Parker
+ *   Department of Computer Science
+ *   University of Utah
+ *   August 1994
+ *
+ *  Copyright (C) 1994 SCI Group
+ */
+
+#ifndef Manta_ThreadLock_h
+#define Manta_Threadlock_h
+
+#include <Core/Thread/Mutex.h>
+#include <Core/Thread/Thread.h>
+
+namespace Manta {
+
+class ThreadLock {
+public:
+  ThreadLock(const char *);
+  void          lock();
+  int           try_lock();
+  void          unlock();
+private:
+  Mutex         mutex_;
+  Thread *      owner_;
+  int           count_;
+};
+
+}
+
+
+#endif

Added: trunk/Core/Thread/ThreadPool.cc
==============================================================================
--- (empty file)
+++ trunk/Core/Thread/ThreadPool.cc     Mon Nov 26 21:56:50 2007
@@ -0,0 +1,132 @@
+/*
+   For more information, please see: http://software.sci.utah.edu
+
+   The MIT License
+
+   Copyright (c) 2004 Scientific Computing and Imaging Institute,
+   University of Utah.
+
+   License for the specific language governing rights and limitations under
+   Permission is hereby granted, free of charge, to any person obtaining a
+   copy of this software and associated documentation files (the "Software"),
+   to deal in the Software without restriction, including without limitation
+   the rights to use, copy, modify, merge, publish, distribute, sublicense,
+   and/or sell copies of the Software, and to permit persons to whom the
+   Software is furnished to do so, subject to the following conditions:
+
+   The above copyright notice and this permission notice shall be included
+   in all copies or substantial portions of the Software.
+
+   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+   OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 
MERCHANTABILITY,
+   FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+   THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+   LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+   FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+   DEALINGS IN THE SOFTWARE.
+*/
+
+
+
+/*
+ *  ThreadPool: A pool of threads
+ *
+ *  Written by:
+ *   Author: Steve Parker
+ *   Department of Computer Science
+ *   University of Utah
+ *   Date: January 2000
+ *
+ *  Copyright (C) 2000 SCI Group
+ */
+
+#include <Core/Thread/ThreadPool.h>
+#include <Core/Thread/Barrier.h>
+#include <Core/Thread/Runnable.h>
+#include <Core/Thread/Semaphore.h>
+#include <Core/Thread/Thread.h>
+#include <Core/Thread/ThreadGroup.h>
+#include <stdio.h>
+
+namespace Manta {
+
+class ThreadPoolHelper : public Runnable {
+  const ParallelBase* helper;
+  int proc;
+  friend class ThreadPool;
+  ThreadPool* pool;
+  //Semaphore start_sema;      
+  //Semaphore done_sema;
+public:
+  ThreadPoolHelper(int proc, ThreadPool* pool)
+    : helper(0), proc(proc), pool(pool)
+    //start_sema("ThreadPool helper startup semaphore", 0),
+    //done_sema("ThreadPool helper completion semaphore", 0) 
+  {
+  }
+  virtual ~ThreadPoolHelper() {}
+  virtual void run() {
+    for(;;){
+      //start_sema.down();
+      pool->wait();
+      ParallelBase* cheat=(ParallelBase*)helper;
+      cheat->run(proc);
+      //done_sema.up();
+      pool->wait();
+    }
+  }
+};     
+
+ThreadPool::ThreadPool(const char* name)
+  : name_(name), lock_("ThreadPool lock"), barrier("ThreadPool barrier")
+{
+  group_ = 0;
+}
+
+ThreadPool::~ThreadPool()
+{
+  // All of the threads will go away with this
+  delete group_;
+}
+
+void ThreadPool::wait()
+{
+  barrier.wait((int)threads_.size()+1);
+}
+
+void
+ThreadPool::parallel(const ParallelBase& helper, int nthreads)
+{
+  lock_.lock();
+  if(nthreads >= (int)threads_.size()){
+    if(!group_)
+      group_=new ThreadGroup("Parallel group");
+    int oldsize = (int)threads_.size();
+    threads_.resize(nthreads);
+    for(int i=oldsize;i<nthreads;i++){
+      char buf[50];
+      sprintf(buf, "Parallel thread %d of %d", i, nthreads);
+      threads_[i] = new ThreadPoolHelper(i, this);
+      Thread* t = new Thread(threads_[i], buf, group_,
+                            Thread::Stopped);
+      t->setDaemon(true);
+      t->detach();
+      t->migrate(i);
+      t->resume();
+    }
+  }
+  Thread::self()->migrate(nthreads%Thread::numProcessors());
+  for(int i=0;i<nthreads;i++){
+    threads_[i]->helper = &helper;
+    // threads_[i]->start_sema.up();
+  }
+  barrier.wait(nthreads+1);
+  barrier.wait(nthreads+1);
+  for(int i=0;i<nthreads;i++){
+    //threads_[i]->done_sema.down();
+    threads_[i]->helper = 0;
+  }
+  lock_.unlock();
+}
+
+} // End namespace Manta

Added: trunk/Core/Thread/ThreadPool.h
==============================================================================
--- (empty file)
+++ trunk/Core/Thread/ThreadPool.h      Mon Nov 26 21:56:50 2007
@@ -0,0 +1,142 @@
+/*
+   For more information, please see: http://software.sci.utah.edu
+
+   The MIT License
+
+   Copyright (c) 2004 Scientific Computing and Imaging Institute,
+   University of Utah.
+
+   License for the specific language governing rights and limitations under
+   Permission is hereby granted, free of charge, to any person obtaining a
+   copy of this software and associated documentation files (the "Software"),
+   to deal in the Software without restriction, including without limitation
+   the rights to use, copy, modify, merge, publish, distribute, sublicense,
+   and/or sell copies of the Software, and to permit persons to whom the
+   Software is furnished to do so, subject to the following conditions:
+
+   The above copyright notice and this permission notice shall be included
+   in all copies or substantial portions of the Software.
+
+   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+   OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 
MERCHANTABILITY,
+   FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+   THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+   LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+   FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+   DEALINGS IN THE SOFTWARE.
+*/
+
+
+
+/*
+ *  ThreadPool: A pool of threads
+ *
+ *  Written by:
+ *   Author: Steve Parker
+ *   Department of Computer Science
+ *   University of Utah
+ *   Date: January 2000
+ *
+ *  Copyright (C) 2000 SCI Group
+ */
+
+#ifndef Core_Thread_ThreadPool_h
+#define Core_Thread_ThreadPool_h
+
+#include <Core/Thread/Barrier.h>
+#include <Core/Thread/Mutex.h>
+#include <Core/Thread/Parallel.h>
+#include <Core/Thread/Parallel1.h>
+#include <Core/Thread/Parallel2.h>
+#include <Core/Thread/Parallel3.h>
+#include <vector>
+
+namespace Manta {
+  class ThreadGroup;
+class  ThreadPoolHelper;
+/**************************************
+
+ CLASS
+ ThreadPool
+
+ KEYWORDS
+ ThreadPool
+
+ DESCRIPTION
+
+ The ThreadPool class groups a bunch of worker threads.
+   
+****************************************/
+class ThreadPool {
+public:
+  //////////
+  // Create a thread pool.  <tt>name</tt> should be a static
+  // string which describes the primitive for debugging purposes.
+  ThreadPool(const char* name);
+
+  //////////
+  // Destroy the pool and shutdown all threads
+  ~ThreadPool();
+
+  //////////
+  // Start up several threads that will run in parallel.
+  // The caller will block until all of the threads return.
+  void parallel(const ParallelBase& helper, int nthreads);
+
+  //////////
+  // Start up several threads that will run in parallel.
+  // The caller will block until all of the threads return.
+  template<class T>
+  void parallel(T* ptr, void (T::*pmf)(int), int numThreads) {
+    parallel(Parallel<T>(ptr, pmf),
+            numThreads);
+  }
+
+  //////////
+  // Another overloaded version of parallel that passes 1 argument
+  template<class T, class Arg1>
+  void parallel(T* ptr, void (T::*pmf)(int, Arg1),
+               int numThreads,
+               Arg1 a1) {
+    parallel(Parallel1<T, Arg1>(ptr, pmf, a1),
+            numThreads);
+  }
+
+  //////////
+  // Another overloaded version of parallel that passes 2 arguments
+  template<class T, class Arg1, class Arg2>
+  void parallel(T* ptr, void (T::* pmf)(int, Arg1, Arg2),
+               int numThreads,
+               Arg1 a1, Arg2 a2) {
+    parallel(Parallel2<T, Arg1, Arg2>(ptr, pmf, a1, a2),
+            numThreads);
+  }
+
+  //////////
+  // Another overloaded version of parallel that passes 3 arguments
+  template<class T, class Arg1, class Arg2, class Arg3>
+  void parallel(T* ptr, void (T::* pmf)(int, Arg1, Arg2, Arg3),
+               int numThreads,
+               Arg1 a1, Arg2 a2, Arg3 a3) {
+    parallel(Parallel3<T, Arg1, Arg2, Arg3>(ptr, pmf, a1, a2, a3),
+            numThreads);
+  }
+
+private:
+  const char* name_;
+  ThreadGroup* group_;
+  Mutex lock_;
+  std::vector<ThreadPoolHelper*> threads_;
+  int numThreads_;
+  Barrier barrier;
+  friend class ThreadPoolHelper;
+  void wait();
+
+  // Cannot copy them
+  ThreadPool(const ThreadPool&);
+  ThreadPool& operator=(const ThreadPool&);
+};
+}
+
+#endif
+

Added: trunk/Core/Thread/Thread_none.cc
==============================================================================
--- (empty file)
+++ trunk/Core/Thread/Thread_none.cc    Mon Nov 26 21:56:50 2007
@@ -0,0 +1,541 @@
+/*
+   For more information, please see: http://software.sci.utah.edu
+
+   The MIT License
+
+   Copyright (c) 2004 Scientific Computing and Imaging Institute,
+   University of Utah.
+
+   License for the specific language governing rights and limitations under
+   Permission is hereby granted, free of charge, to any person obtaining a
+   copy of this software and associated documentation files (the "Software"),
+   to deal in the Software without restriction, including without limitation
+   the rights to use, copy, modify, merge, publish, distribute, sublicense,
+   and/or sell copies of the Software, and to permit persons to whom the
+   Software is furnished to do so, subject to the following conditions:
+
+   The above copyright notice and this permission notice shall be included
+   in all copies or substantial portions of the Software.
+
+   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+   OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 
MERCHANTABILITY,
+   FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+   THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+   LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+   FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+   DEALINGS IN THE SOFTWARE.
+*/
+
+
+
+/*
+ *  Thread_irix.cc: Irix implementation of the Thread library
+ *
+ *  Written by:
+ *   Author: Steve Parker
+ *   Department of Computer Science
+ *   University of Utah
+ *   Date: June 1997
+ *
+ *  Copyright (C) 1997 SCI Group
+ */
+
+/*
+ * User signals:
+ *    SIGQUIT: Tells all of the processes to quit
+ */
+
+// This is brutal, but effective.  We want this file to have access
+// to the private members of Thread, without having to explicitly
+// declare friendships in the class.
+#include <sci_defs/bits_defs.h>
+
+#define private public
+#define protected public
+#include <Core/Thread/Thread.h>
+#undef private
+#undef protected
+#include <Core/Thread/AtomicCounter.h>
+#include <Core/Thread/Barrier.h>
+#include <Core/Thread/CleanupManager.h>
+#include <Core/Thread/ConditionVariable.h>
+#include <Core/Thread/Mutex.h>
+#include <Core/Thread/Semaphore.h>
+#include <Core/Thread/ThreadError.h>
+#include <Core/Thread/ThreadGroup.h>
+#include <Core/Thread/Time.h>
+#include <Core/Thread/WorkQueue.h>
+#include <Core/Thread/Thread_unix.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <signal.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <sys/errno.h>
+#include <sys/mman.h>
+#include <sys/signal.h>
+#include <sys/time.h>
+#include <sys/types.h>
+
+#include <stack>
+
+/*
+ * This Thread implementation is for no threads.  Creating a Thread will 
throw
+ * an exception, and all other functions will do nothing.
+ */
+
+#include <Core/Thread/CrowdMonitor_default.cc>
+#include <Core/Thread/RecursiveMutex_default.cc>
+
+
+extern "C" int __ateachexit(void(*)());
+
+#define MAXBSTACK 10
+#define MAXTHREADS 4000
+
+#define N_POOLMUTEX 301
+
+namespace Manta {
+
+static Thread *mainthread=0;
+static void install_signal_handlers();
+
+/*
+ * Intialize threads for irix
+ */
+void
+Thread::initialize()
+{
+  if (initialized)
+    return;
+  initialized = true;
+  ThreadGroup::s_default_group=new ThreadGroup("default group", 0);
+  mainthread=new Thread(ThreadGroup::s_default_group, "main");
+  install_signal_handlers();
+}
+
+void
+Thread::allow_sgi_OpenGL_page0_sillyness()
+{
+  // Nothing necessary here
+}
+
+void
+Thread::disallow_sgi_OpenGL_page0_sillyness()
+{
+  // Nothing necessary here
+}
+
+void
+Thread::exit()
+{
+  exitAll(0);
+}
+
+void
+Thread::checkExit()
+{
+  exitAll(0);
+}
+
+void
+Thread::exitAll(int code)
+{
+  CleanupManager::call_callbacks();
+  delete mainthread;
+  delete ThreadGroup::s_default_group; 
+  ::exit(code);
+}
+
+/*
+ * Startup the given thread...
+ */
+void
+Thread::os_start(bool stopped)
+{
+
+}
+
+void
+Thread::stop()
+{
+}
+
+void
+Thread::resume()
+{
+}
+
+void
+Thread::detach()
+{
+
+}
+
+void
+Thread::join()
+{
+
+}
+
+void
+ThreadGroup::gangSchedule()
+{
+}
+
+/*
+ * Thread block stack manipulation
+ */
+int
+Thread::push_bstack(Thread_private* p, Thread::ThreadState state,
+                   const char* name)
+{
+  return 0;
+}
+
+void
+Thread::pop_bstack(Thread_private* p, int oldstate)
+{
+}
+
+/*
+ * Signal handling cruft
+ */
+void
+Thread::print_threads()
+{
+
+}
+
+typedef void (*SIG_HANDLER_T)(int);
+
+/*
+ * Handle sigquit - usually sent by control-C
+ */
+static
+void
+handle_quit(int sig, int /* code */, sigcontext)
+{
+  if(sig==SIGINT){
+    // Print out the thread states...
+    Thread::niceAbort();
+  } else {
+    exit(1);
+  }
+}
+
+/*
+ * Handle an abort signal - like segv, bus error, etc.
+ */
+static
+void
+handle_abort_signals(int sig, int /* code */, sigcontext context)
+{
+#if 0
+  printf ("Ready to handle_abort_signals\n");
+  fflush(stdout);
+  printf("%d\n", (int)*(int*)0x400144080);
+  fflush(stdout);
+#endif
+  struct sigaction action;
+  sigemptyset(&action.sa_mask);
+  action.sa_handler=SIG_DFL;
+  action.sa_flags=0;
+  if(sigaction(sig, &action, NULL) == -1)
+    throw ThreadError(std::string("sigaction (SIG_DFL) failed")
+                     +strerror(errno));
+
+  Thread* self=Thread::self();
+  const char* tname=self?self->getThreadName():"idle or main";
+#if defined(__sgi)
+#  if defined(_LONGLONG)
+     caddr_t addr=(caddr_t)ctx->sc_badvaddr;
+#  else
+     caddr_t addr=(caddr_t)ctx->sc_badvaddr.lo32;
+#  endif
+#else
+#  if defined(PPC)
+    void* addr=(void*)ctx.regs->dsisr;
+#  else
+#    if defined(_AIX)
+       // Not sure if this is correct, but here it is.
+       // On IMB SP2 sigcontext is defined in /usr/include/sys/context.h
+#      if defined(SCI_64BITS)
+         void* addr=(void*)ctx.sc_jmpbuf.jmp_context.except;
+#      else
+         void* addr=(void*)ctx.sc_jmpbuf.jmp_context.o_vaddr;
+#      endif
+#    else
+//     void* addr=(void*)ctx.cr2;
+       void* addr=0;
+#    endif
+#  endif
+#endif
+  char* signam=Core_Thread_signal_name(sig, addr);
+  fprintf(stderr, "%c%c%cThread \"%s\"(pid %d) caught signal %s\n", 
7,7,7,tname, getpid(), signam);
+  Thread::niceAbort();
+
+  action.sa_handler=(SIG_HANDLER_T)handle_abort_signals;
+  action.sa_flags=0;
+  if(sigaction(sig, &action, NULL) == -1)
+    throw ThreadError(std::string("sigaction (restore) failed")
+                     +strerror(errno));
+}
+
+/*
+ * Setup signals for the current thread
+ */
+static
+void
+install_signal_handlers()
+{
+  struct sigaction action;
+  sigemptyset(&action.sa_mask);
+  action.sa_flags=0;
+
+  action.sa_handler=(SIG_HANDLER_T)handle_abort_signals;
+  if(sigaction(SIGILL, &action, NULL) == -1)
+    throw ThreadError(std::string("sigaction(SIGILL) failed")
+                     +strerror(errno));
+  if(sigaction(SIGABRT, &action, NULL) == -1)
+    throw ThreadError(std::string("sigaction(SIGABRT) failed")
+                     +strerror(errno));
+  if(sigaction(SIGTRAP, &action, NULL) == -1)
+    throw ThreadError(std::string("sigaction(SIGTRAP) failed")
+                     +strerror(errno));
+  if(sigaction(SIGBUS, &action, NULL) == -1)
+    throw ThreadError(std::string("sigaction(SIGBUS) failed")
+                     +strerror(errno));
+  if(sigaction(SIGSEGV, &action, NULL) == -1)
+    throw ThreadError(std::string("sigaction(SIGSEGV) failed")
+                     +strerror(errno));
+  if(sigaction(SIGFPE, &action, NULL) == -1)
+    throw ThreadError(std::string("sigaction(SIGFPE) failed")
+                     +strerror(errno));
+
+  action.sa_handler=(SIG_HANDLER_T)handle_quit;
+  if(sigaction(SIGQUIT, &action, NULL) == -1)
+    throw ThreadError(std::string("sigaction(SIGQUIT) failed")
+                     +strerror(errno));
+  if(sigaction(SIGINT, &action, NULL) == -1)
+    throw ThreadError(std::string("sigaction(SIGINT) failed")
+                     +strerror(errno));
+}
+
+/*
+ * Return the current thread...
+ */
+Thread*
+Thread::self()
+{
+  return mainthread;
+}
+
+
+int
+Thread::numProcessors()
+{
+  return 1;
+}
+
+/*
+ * Yield the CPU
+ */
+void
+Thread::yield()
+{
+}
+
+/*
+ * Migrate the thread to a CPU.
+ */
+void
+Thread::migrate(int proc)
+{
+}
+
+/*
+ * Mutex implementation
+ */
+Mutex::Mutex(const char* name)
+  : name_(name)
+{
+}
+
+Mutex::~Mutex()
+{
+}
+
+void
+Mutex::lock()
+{
+}
+
+bool
+Mutex::tryLock()
+{
+  return true;
+}
+
+void
+Mutex::unlock()
+{
+}
+
+/*
+ * Semaphore implementation
+ */
+
+Semaphore::Semaphore(const char* name, int count)
+  : name_(name)
+{
+}
+
+Semaphore::~Semaphore()
+{
+}
+
+void
+Semaphore::down(int count)
+{
+}
+
+bool
+Semaphore::tryDown()
+{
+  return true;
+}
+
+void
+Semaphore::up(int count)
+{
+}
+
+Barrier::Barrier(const char* name)
+  : name_(name)
+{
+}
+
+Barrier::~Barrier()
+{
+}
+
+void
+Barrier::wait(int n)
+{
+}
+
+struct AtomicCounter_private {
+  AtomicCounter_private();
+
+  // These variables used only for non fectchop implementation
+  Mutex lock;
+  int value;
+};
+
+AtomicCounter_private::AtomicCounter_private()
+  : lock("AtomicCounter lock")
+{
+}
+
+AtomicCounter::AtomicCounter(const char* name)
+  : name_(name)
+{
+  priv_=new AtomicCounter_private;
+  priv_->value=0;
+}
+
+AtomicCounter::AtomicCounter(const char* name, int value)
+  : name_(name)
+{
+  priv_=new AtomicCounter_private;
+  priv_->value=value;
+}
+
+AtomicCounter::~AtomicCounter()
+{
+  delete priv_;
+  priv_=0;
+}
+
+AtomicCounter::operator int() const
+{
+  return priv_->value;
+}
+
+int
+AtomicCounter::operator++()
+{
+  int ret=++priv_->value;
+  return ret;
+}
+
+int
+AtomicCounter::operator++(int)
+{
+  int ret=priv_->value++;
+  return ret;
+}
+
+int
+AtomicCounter::operator--()
+{
+  int ret=--priv_->value;      
+  return ret;
+}
+
+int
+AtomicCounter::operator--(int)
+{
+  int ret=priv_->value--;
+  return ret;
+}
+
+void
+AtomicCounter::set(int v)
+{
+    priv_->value=v;
+}
+
+struct ConditionVariable_private {
+  int num_waiters;
+  bool pollsema;
+};
+
+ConditionVariable::ConditionVariable(const char* name)
+  : name_(name)
+{
+  priv_=new ConditionVariable_private();
+  priv_->num_waiters=0;
+  priv_->pollsema=false;
+}
+
+ConditionVariable::~ConditionVariable()
+{
+  delete priv_;
+  priv_=0;
+}
+
+void
+ConditionVariable::wait(Mutex& m)
+{
+}
+
+bool
+ConditionVariable::timedWait(Mutex& m, const struct timespec* abstime)
+{
+  return true;
+}
+
+void
+ConditionVariable::conditionSignal()
+{
+}
+
+void
+ConditionVariable::conditionBroadcast()
+{
+}
+
+} // End namespace Manta

Added: trunk/Core/Thread/Thread_pthreads.cc
==============================================================================
--- (empty file)
+++ trunk/Core/Thread/Thread_pthreads.cc        Mon Nov 26 21:56:50 2007
@@ -0,0 +1,1562 @@
+/*
+  For more information, please see: http://software.sci.utah.edu
+
+  The MIT License
+
+  Copyright (c) 2004 Scientific Computing and Imaging Institute,
+  University of Utah.
+
+  License for the specific language governing rights and limitations under
+  Permission is hereby granted, free of charge, to any person obtaining a
+  copy of this software and associated documentation files (the "Software"),
+  to deal in the Software without restriction, including without limitation
+  the rights to use, copy, modify, merge, publish, distribute, sublicense,
+  and/or sell copies of the Software, and to permit persons to whom the
+  Software is furnished to do so, subject to the following conditions:
+
+  The above copyright notice and this permission notice shall be included
+  in all copies or substantial portions of the Software.
+
+  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+  OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+  THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+  DEALINGS IN THE SOFTWARE.
+*/
+
+
+
+/*
+ *  Thread_pthreads.cc: Posix threads implementation of the thread library
+ *
+ *  Written by:
+ *   Author: Steve Parker
+ *   Department of Computer Science
+ *   University of Utah
+ *   Date: June 1997
+ *
+ *  Copyright (C) 1997 SCI Group
+ */
+
+#ifndef _GNU_SOURCE
+#  define _GNU_SOURCE
+#endif
+
+#define __USE_UNIX98
+#include <pthread.h>
+#ifndef PTHREAD_MUTEX_RECURSIVE
+#  define PTHREAD_MUTEX_RECURSIVE PTHREAD_MUTEX_RECURSIVE_NP
+#endif
+
+//////////////////////////////////////////////////////
+// begin: Danger Will Robinson! Danger Will Robinson!
+
+#define private public
+#define protected public
+
+#include <Core/Thread/Thread.h>
+#include <Core/Thread/Mutex.h> // So ConditionVariable can get to 
Mutex::priv_
+
+#undef private
+#undef protected
+
+// end: Danger Will Robinson! Danger Will Robinson!
+//////////////////////////////////////////////////////
+
+
+#include <Core/Thread/Thread.h>
+#include <Core/Thread/AtomicCounter.h>
+#include <Core/Thread/Barrier.h>
+#include <Core/Thread/CleanupManager.h>
+#include <Core/Thread/ConditionVariable.h>
+#include <Core/Thread/RecursiveMutex.h>
+#include <Core/Thread/Semaphore.h>
+#include <Core/Thread/ThreadError.h>
+#include <Core/Thread/ThreadGroup.h>
+#include <Core/Thread/WorkQueue.h>
+#include <Core/Thread/Thread_unix.h>
+#include <errno.h>
+extern "C" {
+#include <semaphore.h>
+}
+#include <signal.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string>
+#include <unistd.h>
+#include <fstream>
+#include <string>
+#ifdef __APPLE__
+#  include <sys/types.h>
+#  include <sys/sysctl.h>
+#endif
+
+#ifdef __APPLE__
+  #ifdef __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__
+    #if __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ >= 1050
+      #define SigContext ucontext_t
+    #else
+      #define SigContext struct sigcontext
+    #endif
+  #else
+    #define SigContext struct sigcontext
+  #endif
+#else
+  #define SigContext struct sigcontext
+#endif
+
+//#define __ia64__
+#ifdef __ia64__
+#  ifndef __int64
+#    define __int64 long
+#  endif
+#  include <ia64intrin.h>
+#endif
+
+#if defined(_AIX)
+
+#  include <sys/mman.h>
+#  define sem_type msemaphore *
+#  define SEM_UNLOCK(sem)            msem_unlock(*(sem),0)
+#  define SEM_LOCK(sem)              msem_lock(*(sem),0)
+#  define SEM_TRYLOCK(sem)           msem_lock(*(sem), MSEM_IF_NOWAIT)
+#  define SEM_INIT(sem, shared, val) msem_init(*(sem), \
+                                         
((val)==0)?MSEM_UNLOCKED:MSEM_LOCKED)
+#  define SEM_INIT_SUCCESS(val)      (((val)!= 0)?true:false)
+#  define SEM_DESTROY(sem)           msem_remove(*(sem))
+
+#else
+
+#  define sem_type sem_t
+#  define SEM_UNLOCK(sem)            sem_post((sem))
+#  define SEM_TRYLOCK(sem)           sem_trywait((sem))
+#  define SEM_INIT(sem, shared, val) sem_init( (sem), (shared), (val) )
+#  define SEM_INIT_SUCCESS(val)      (((val)== 0)?true:false)
+#  define SEM_DESTROY(sem)           sem_destroy((sem))
+
+// NOTE(boulos): This code is not currently used if __APPLE__ is
+// defined, so defining this function produces a "defined but not used
+// warning"
+#ifndef __APPLE__
+static int SEM_LOCK(sem_type* sem)
+{
+  int returnValue = 0;
+  while ( (returnValue = sem_wait(sem)) == -1 && (errno == EINTR) );
+  return returnValue;
+}
+#endif
+
+#endif
+
+typedef void (*SIG_HANDLER_T)(int);
+
+/*
+ * The pthread implementation uses the default version of AtomicCounter,
+ * Barrier, and CrowdMonitor.  It provides native implementations of
+ * of ConditionVariable, Mutex, RecursiveMutex and Semaphore.
+ *
+ */
+
+#ifndef __ia64__
+#include <Core/Thread/Barrier_default.cc>
+#include <Core/Thread/AtomicCounter_default.cc>
+#endif
+#include <Core/Thread/CrowdMonitor_default.cc>
+
+static bool exiting = false;
+
+#define MAXBSTACK 10
+
+#if defined(_AIX) && defined(MAXTHREADS)
+#  undef MAXTHREADS
+#endif
+
+#define MAXTHREADS 4000
+
+namespace Manta {
+struct Thread_private {
+  Thread_private(bool stopped);
+
+  Thread* thread;
+  pthread_t threadid;
+  Thread::ThreadState state;
+  int bstacksize;
+  const char* blockstack[MAXBSTACK];
+  Semaphore done;
+  Semaphore delete_ready;
+  Semaphore block_sema;
+  bool is_blocked;
+  bool ismain;
+};
+} // end namespace Manta
+
+using namespace Manta;
+
+static const char* bstack_init = "Unused block stack entry";
+
+static Thread_private* active[MAXTHREADS];
+static int numActive = 0;
+
+static pthread_mutex_t sched_lock;
+static pthread_key_t   thread_key;
+
+static Semaphore main_sema("main",0);
+static Semaphore control_c_sema("control-c",1);
+static Thread*  mainthread = 0;
+
+
+Thread_private::Thread_private(bool stopped) :
+  done("done",0),
+  delete_ready("delete_ready",0),
+  block_sema("block_sema",stopped?0:1)
+{
+}
+
+
+static
+void
+lock_scheduler()
+{
+  const int status = pthread_mutex_lock(&sched_lock);
+  if (status)
+  {
+    switch (status)
+    {
+    case EINVAL:
+      throw ThreadError("pthread_mutex_lock:  Uninitialized lock.");
+      break;
+
+    case EDEADLK:
+      throw ThreadError("pthread_mutex_lock:  Calling thread already holds 
this lock.");
+      break;
+
+    default:
+      throw ThreadError("pthread_mutex_lock:  Unknown error.");
+    }
+  }
+}
+
+
+static
+void
+unlock_scheduler()
+{
+  const int status = pthread_mutex_unlock(&sched_lock);
+  if (status)
+  {
+    switch (status)
+    {
+    case EINVAL:
+      throw ThreadError("pthread_mutex_unlock:  Uninitialized lock.");
+      break;
+
+    case EPERM:
+      throw ThreadError("pthread_mutex_unlock:  Unlocker did not lock.");
+      break;
+
+    default:
+      throw ThreadError("pthread_mutex_unlock:  Unknown error.");
+    }
+  }
+}
+
+int
+Thread::push_bstack(Thread_private* p, Thread::ThreadState state,
+                    const char* name)
+{
+  int oldstate = p->state;
+  p->state = state;
+  p->blockstack[p->bstacksize]=name;
+  p->bstacksize++;
+  if (p->bstacksize>=MAXBSTACK){
+    fprintf(stderr, "Blockstack Overflow!\n");
+    Thread::niceAbort();
+  }
+  return oldstate;
+}
+
+
+void
+Thread::pop_bstack(Thread_private* p, int oldstate)
+{
+  p->bstacksize--;
+  p->state = (ThreadState)oldstate;
+}
+
+
+void
+ThreadGroup::gangSchedule()
+{
+  // Cannot do this on pthreads unfortunately
+}
+
+
+static
+void
+Thread_shutdown(Thread* thread)
+{
+  Thread_private* priv = thread->priv_;
+
+  priv->done.up();
+  if (!priv->ismain) priv->delete_ready.down();
+
+  // Allow this thread to run anywhere...
+  if (thread->cpu_ != -1)
+    thread->migrate(-1);
+
+  lock_scheduler();
+  /* Remove it from the active queue */
+  int i;
+  for (i = 0;i<numActive;i++){
+    if (active[i]==priv)
+      break;
+  }
+  for (i++;i<numActive;i++){
+    active[i-1]=active[i];
+  }
+  numActive--;
+
+  // This can't be done in checkExit, because of a potential race
+  // condition.
+  int done = true;
+  for (int i = 0;i<numActive;i++){
+    Thread_private* p = active[i];
+    if (!p->thread->isDaemon()){
+      done = false;
+      break;
+    }
+  }
+  unlock_scheduler();
+
+  bool wait_main = priv->ismain;
+  delete thread;
+  if (pthread_setspecific(thread_key, 0) != 0)
+    fprintf(stderr, "Warning: pthread_setspecific failed");
+  priv->thread = 0;
+  delete priv;
+  if (done)
+    Thread::exitAll(0);
+  if (wait_main) {
+    main_sema.down();
+  }
+  pthread_exit(0);
+}
+
+
+void
+Thread::exit()
+{
+  Thread* self = Thread::self();
+  Thread_shutdown(self);
+}
+
+
+void
+Thread::checkExit()
+{
+  lock_scheduler();
+  int done = true;
+  for (int i = 0;i<numActive;i++)
+  {
+    Thread_private* p = active[i];
+    if (!p->thread->isDaemon())
+    {
+      done = false;
+      break;
+    }
+  }
+  unlock_scheduler();
+
+  if (done)
+    Thread::exitAll(0);
+}
+
+
+Thread*
+Thread::self()
+{
+  void* p = pthread_getspecific(thread_key);
+  return (Thread*)p;
+}
+
+
+void
+Thread::join()
+{
+  pthread_t id = priv_->threadid;
+
+  priv_->delete_ready.up();
+
+  const int status = pthread_join(id, 0);
+  if (status)
+  {
+    switch (status)
+    {
+    case ESRCH:
+      throw ThreadError("pthread_join:  No such thread.");
+      break;
+
+    case EINVAL:
+      throw ThreadError("pthread_join:  Joining detached thread or joining 
same thread twice.");
+      break;
+
+    case EDEADLK:
+      throw ThreadError("pthread_join:  Joining self, deadlock.");
+      break;
+
+    default:
+      throw ThreadError("pthread_join:  Unknown error.");
+    }
+  }
+}
+
+int
+Thread::numProcessors()
+{
+  static int np = 0;
+
+  if (np == 0) {
+#ifdef __APPLE__
+    size_t len = sizeof(np);
+    sysctl((int[2]) {CTL_HW, HW_NCPU}, 2, &np, &len, NULL, 0);
+#else
+    // Linux
+    std::ifstream cpuinfo("/proc/cpuinfo");
+    if (cpuinfo) {
+      int count = 0;
+      while (!cpuinfo.eof()) {
+        std::string str;
+        cpuinfo >> str;
+        if (str == "processor") {
+          ++count;
+        }
+      }
+      np = count;
+    }
+#endif
+    if (np <= 0) np = 1;
+  }
+  return np;
+}
+
+
+static void
+Thread_run(Thread* t)
+{
+  t->run_body();
+}
+
+
+static
+void*
+run_threads(void* priv_v)
+{
+  Thread_private* priv = (Thread_private*)priv_v;
+  if (pthread_setspecific(thread_key, priv->thread))
+  {
+    throw ThreadError("pthread_setspecific: Unknown error.");
+  }
+  priv->is_blocked = true;
+
+  priv->block_sema.down();
+  priv->is_blocked = false;
+  priv->state = Thread::RUNNING;
+  Thread_run(priv->thread);
+  priv->state = Thread::SHUTDOWN;
+  Thread_shutdown(priv->thread);
+  return 0; // Never reached
+}
+
+
+void
+Thread::os_start(bool stopped)
+{
+  if (!initialized)
+    Thread::initialize();
+
+  priv_ = new Thread_private(stopped);
+
+  priv_->state = STARTUP;
+  priv_->bstacksize = 0;
+  for (int i = 0;i<MAXBSTACK;i++)
+    priv_->blockstack[i]=bstack_init;
+
+  priv_->thread = this;
+  priv_->threadid = 0;
+  priv_->is_blocked = false;
+  priv_->ismain = false;
+
+  pthread_attr_t attr;
+  pthread_attr_init(&attr);
+  pthread_attr_setstacksize(&attr, stacksize_);
+
+  lock_scheduler();
+  active[numActive]=priv_;
+  numActive++;
+  if (pthread_create(&priv_->threadid, &attr, run_threads, priv_) != 0)
+  {
+    // Always EAGAIN
+    throw ThreadError("pthread_create:  Out of thread resources.");
+  }
+  unlock_scheduler();
+}
+
+
+void
+Thread::stop()
+{
+  lock_scheduler();
+  if (priv_->block_sema.tryDown() == false)
+  {
+    if (this == self())
+    {
+      priv_->block_sema.down();
+    }
+    else
+    {
+      pthread_kill(priv_->threadid, SIGUSR2);
+    }
+  }
+  unlock_scheduler();
+}
+
+
+void
+Thread::resume()
+{
+  lock_scheduler();
+  priv_->block_sema.up();
+  unlock_scheduler();
+}
+
+
+void
+Thread::detach()
+{
+  detached_=true;
+  pthread_t id = priv_->threadid;
+
+  priv_->delete_ready.up();
+
+  const int status = pthread_detach(id);
+  if (status)
+  {
+    switch (status)
+    {
+    case ESRCH:
+      throw ThreadError("pthread_detach:  Thread does not exist.");
+      break;
+
+    case EINVAL:
+      throw ThreadError("pthread_detach:  Thread is already detached.");
+      break;
+
+    default:
+      throw ThreadError("pthread_detach:  Unknown error.");
+    }
+  }
+}
+
+
+void
+Thread::exitAll(int code)
+{
+  if (getenv("SCIRUN_EXIT_CRASH_WORKAROUND"))
+  {
+    raise(SIGKILL);
+  }
+  CleanupManager::call_callbacks();
+  if (initialized && !exiting){
+    exiting = true;
+    lock_scheduler();
+    if (initialized){
+      // Stop all of the other threads before we die, because
+      // global destructors may destroy primitives that other
+      // threads are using...
+      Thread* me = Thread::self();
+      for (int i = 0;i<numActive;i++){
+        Thread_private* t = active[i];
+        if (t->thread != me){
+          pthread_kill(t->threadid, SIGUSR2);
+        }
+      }
+      // Wait for all threads to be in the signal handler
+      int numtries = 100000;
+      bool done = false;
+      while(--numtries && !done){
+        done = true;
+        for (int i = 0;i<numActive;i++){
+          Thread_private* t = active[i];
+          if (t->thread != me){
+            if (!t->is_blocked)
+              done = false;
+          }
+        }
+        sched_yield();
+        //sleep(1);
+      }
+      if (!numtries){
+        for (int i = 0;i<numActive;i++){
+          Thread_private* t = active[i];
+          if (t->thread != me && !t->is_blocked) {
+            fprintf(stderr, "Thread: %s is slow to stop, giving up\n",
+                    t->thread->getThreadName());
+            //sleep(1000);
+          }
+        }
+      }
+    }
+
+    // See Thread.h for why we are doing this.
+    if (Thread::getCallExit()) ::exit(code);
+  }
+  else if ( !initialized ) {
+    // This case happens if the thread library is not being used.
+    // Just use the normal exit function.
+    ::exit(code);
+  }
+}
+
+
+/*
+ * Handle an abort signal - like segv, bus error, etc.
+ */
+static
+void
+#if defined(__sgi)
+handle_abort_signals(int sig, int, SigContext* ctx)
+#elif defined (__CYGWIN__)
+handle_abort_signals(int sig)
+#else
+handle_abort_signals(int sig, SigContext ctx)
+#endif
+{
+struct sigaction action;
+sigemptyset(&action.sa_mask);
+action.sa_handler = SIG_DFL;
+action.sa_flags = 0;
+if (sigaction(sig, &action, NULL) == -1)
+  throw ThreadError(std::string("sigaction failed")
+    +strerror(errno));
+
+Thread* self = Thread::self();
+const char* tname = self?self->getThreadName():"idle or main";
+#if defined(__sgi)
+#  if defined(_LONGLONG)
+caddr_t addr = (caddr_t)ctx->sc_badvaddr;
+#  else
+caddr_t addr = (caddr_t)ctx->sc_badvaddr.lo32;
+#  endif
+#else
+#  if defined(PPC)
+void* addr = (void*)ctx.regs->dsisr;
+#  else
+#    if defined(_AIX)
+// Not sure if this is correct, but here it is.
+// On IMB SP2 sigcontext is defined in /usr/include/sys/context.h
+#      if defined(SCI_64BITS)
+void* addr = (void*)ctx.sc_jmpbuf.jmp_context.except;
+#      else
+void* addr = (void*)ctx.sc_jmpbuf.jmp_context.o_vaddr;
+#      endif
+#    else
+//     void* addr = (void*)ctx.cr2;
+void* addr = 0;
+#    endif
+#  endif
+#endif
+char* signam = Core_Thread_signal_name(sig, addr);
+fprintf(stderr, "%c%c%cThread \"%s\"(pid %d) caught signal %s\n", 
7,7,7,tname, getpid(), signam);
+Thread::niceAbort();
+
+action.sa_handler = (SIG_HANDLER_T)handle_abort_signals;
+action.sa_flags = 0;
+if (sigaction(sig, &action, NULL) == -1)
+  throw ThreadError(std::string("sigaction failed")
+    +strerror(errno));
+}
+
+
+void
+Thread::print_threads()
+{
+  FILE* fp = stderr;
+  for (int i = 0;i<numActive;i++)
+  {
+    Thread_private* p = active[i];
+    const char* tname = p->thread?p->thread->getThreadName():"???";
+    // NOTE(boulos): On Darwin, pthread_t is an opaque type and so
+    // using it as a thread_id (despite the man page) is a bad idea.
+    // For this purpose (printing out some unique identifier) it
+    // should be fine but requires a C-style cast.
+    long unsigned int tid = (long unsigned int)(p->threadid);
+    fprintf(fp, " %lu: %s (", tid, tname);
+    if (p->thread)
+    {
+      if (p->thread->isDaemon())
+        fprintf(fp, "daemon, ");
+      if (p->thread->isDetached())
+        fprintf(fp, "detached, ");
+    }
+    fprintf(fp, "state = %s", Thread::getStateString(p->state));
+    for (int i = 0;i<p->bstacksize;i++)
+    {
+      fprintf(fp, ", %s", p->blockstack[i]);
+    }
+    fprintf(fp, ")\n");
+  }
+}
+
+
+/*
+ * Handle sigquit - usually sent by control-C
+ */
+static
+void
+#ifdef __CYGWIN__
+// Cygwin's version doesn't take a sigcontext
+handle_quit(int sig)
+#else
+handle_quit(int sig, SigContext /*ctx*/)
+#endif
+{
+  // Try to acquire a lock.  If we can't, then assume that somebody
+  // else already caught the signal...
+  Thread* self = Thread::self();
+  if (self == 0)
+    return; // This is an idle thread...
+  if (!(control_c_sema.tryDown()))
+  {
+    control_c_sema.down();
+    control_c_sema.up();
+  }
+
+  // Otherwise, we got the semaphore and handle the interrupt
+  const char* tname = self?self->getThreadName():"main?";
+
+  // Kill all of the threads...
+  char* signam = Core_Thread_signal_name(sig, 0);
+  int pid = getpid();
+  fprintf(stderr, "Thread \"%s\"(pid %d) caught signal %s\n", tname, pid, 
signam);
+  Thread::niceAbort(); // Enter the monitor
+  control_c_sema.up();
+}
+
+
+/*
+ * Handle siguser1 - for stop/resume
+ */
+static
+void
+handle_siguser2(int)
+{
+  Thread* self = Thread::self();
+  if (!self)
+  {
+    // This can happen if the thread is just started and hasn't had
+    // the opportunity to call setspecific for the thread id yet
+    for (int i = 0;i<numActive;i++)
+      if (pthread_self() == active[i]->threadid)
+        self = active[i]->thread;
+  }
+  self->priv_->is_blocked = true;
+  self->priv_->block_sema.down();
+  self->priv_->is_blocked = false;
+}
+
+
+/*
+ * Setup signals for the current thread
+ */
+static
+void
+install_signal_handlers()
+{
+  struct sigaction action;
+  sigemptyset(&action.sa_mask);
+  action.sa_flags = 0;
+
+  action.sa_handler = (SIG_HANDLER_T)handle_abort_signals;
+  if (sigaction(SIGILL, &action, NULL) == -1)
+    throw ThreadError(std::string("SIGILL failed") + strerror(errno));
+  if (sigaction(SIGABRT, &action, NULL) == -1)
+    throw ThreadError(std::string("SIGABRT failed") + strerror(errno));
+  if (sigaction(SIGTRAP, &action, NULL) == -1)
+    throw ThreadError(std::string("SIGTRAP failed") + strerror(errno));
+  if (sigaction(SIGBUS, &action, NULL) == -1)
+    throw ThreadError(std::string("SIGBUS failed") + strerror(errno));
+  if (sigaction(SIGSEGV, &action, NULL) == -1)
+    throw ThreadError(std::string("SIGSEGV failed") + strerror(errno));
+
+  action.sa_handler = (SIG_HANDLER_T)handle_quit;
+  if (sigaction(SIGQUIT, &action, NULL) == -1)
+    throw ThreadError(std::string("SIGQUIT failed") + strerror(errno));
+  if (sigaction(SIGINT, &action, NULL) == -1)
+    throw ThreadError(std::string("SIGINT failed") + strerror(errno));
+
+  action.sa_handler = (SIG_HANDLER_T)handle_siguser2;
+  if (sigaction(SIGUSR2, &action, NULL) == -1)
+    throw ThreadError(std::string("SIGUSR2 failed") + strerror(errno));
+}
+
+
+static void
+exit_handler()
+{
+  if (exiting)
+    return;
+  Thread_shutdown(Thread::self());
+}
+
+
+void
+Thread::allow_sgi_OpenGL_page0_sillyness()
+{
+  // Nothing necessary here
+}
+
+
+void
+Thread::disallow_sgi_OpenGL_page0_sillyness()
+{
+  // Nothing necessary here
+}
+
+
+void
+Thread::initialize()
+{
+
+  if (initialized)
+    return;
+  if (exiting)
+    abort(); // Something really weird happened!
+
+  CleanupManager::initialize();
+
+  atexit(exit_handler);
+  pthread_mutex_init(&sched_lock, NULL);
+
+  if (pthread_key_create(&thread_key, NULL) != 0)
+  {
+    throw ThreadError("pthread_key_create:  Out of resources.");
+  }
+
+  initialized = true;
+  ThreadGroup::s_default_group = new ThreadGroup("default group", 0);
+  mainthread = new Thread(ThreadGroup::s_default_group, "main");
+  //  mainthread->priv_=new Thread_private(false);
+  mainthread->priv_ = new Thread_private(true);
+  mainthread->priv_->thread = mainthread;
+  mainthread->priv_->state = RUNNING;
+  mainthread->priv_->bstacksize = 0;
+  mainthread->priv_->is_blocked = false;
+  mainthread->priv_->threadid = pthread_self();
+  mainthread->priv_->ismain = true;
+
+  //  mainthread->priv_->block_sema.down();
+
+  for (int i = 0;i<MAXBSTACK;i++)
+    mainthread->priv_->blockstack[i]=bstack_init;
+  if (pthread_setspecific(thread_key, mainthread) != 0)
+  {
+    throw ThreadError("pthread_setspecific:  Failed.");
+  }
+
+  lock_scheduler();
+  active[numActive]=mainthread->priv_;
+  numActive++;
+  unlock_scheduler();
+  if (!getenv("THREAD_NO_CATCH_SIGNALS"))
+    install_signal_handlers();
+  numProcessors();  //initialize the processor count;
+}
+
+
+void
+Thread::yield()
+{
+  sched_yield();
+}
+
+
+void
+Thread::migrate(int /*proc*/)
+{
+  // Nothing for now...
+}
+
+
+namespace Manta {
+struct Mutex_private {
+  pthread_mutex_t mutex;
+};
+} // namespace Manta
+
+
+Mutex::Mutex(const char* name)
+  : name_(name)
+{
+  // DO NOT CALL INITIALIZE in this CTOR!
+  if (this == 0){
+    fprintf(stderr, "WARNING: creation of null mutex\n");
+  }
+
+  priv_ = new Mutex_private;
+
+#ifdef PTHREAD_MUTEX_ERRORCHECK_NP
+  pthread_mutexattr_t attr;
+  pthread_mutexattr_init(&attr); // always returns zero
+  if (pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_ERRORCHECK_NP) != 0)
+    throw ThreadError("pthread_mutexattr_settype:  Bad kind.");
+  pthread_mutex_init(&priv_->mutex, &attr); // always returns zero
+  pthread_mutexattr_destroy(&attr);  // usually noop
+#else
+  pthread_mutex_init(&priv_->mutex, NULL); // always returns zero
+#endif
+}
+
+
+Mutex::~Mutex()
+{
+  // RHE 3.0 pthread_mutex_destroy returns EBUSY if you unlock an
+  // already unlocked thread first.  So we force a lock/unlock before
+  // destroying.  Probably better to just remove the unlock altogether
+  // but this breaks the shutdown behavior.  TODO: This fix doesn't
+  // really work.  Race condition can relock between our unlock and
+  // destroy calls.
+  pthread_mutex_trylock(&priv_->mutex);
+  pthread_mutex_unlock(&priv_->mutex);
+  if (pthread_mutex_destroy(&priv_->mutex) != 0)
+  {
+    // EBUSY
+    fprintf(stderr,"Mutex::~Mutex: Warning: Mutex \"%s\" currently 
locked.\n",
+            name_);
+    priv_ = 0;
+    return;
+    // EBUSY
+    //throw ThreadError("pthread_mutex_destroy: Mutex currently locked.");
+  }
+  delete priv_;
+  priv_ = 0;
+}
+
+void
+Mutex::unlock()
+{
+  int status = pthread_mutex_unlock(&priv_->mutex);
+  if (status)
+  {
+    switch (status)
+    {
+    case EINVAL:
+      ThreadError("pthread_mutex_unlock:  Uninitialized lock.");
+      break;
+
+    case EPERM:
+      ThreadError("pthread_mutex_unlock:  Calling thread did not lock.");
+      break;
+
+    default:
+      ThreadError("pthread_mutex_unlock:  Unknown error.");
+    }
+  }
+}
+
+void
+Mutex::lock()
+{
+  Thread* t = Thread::isInitialized()?Thread::self():0;
+  int oldstate = -1;
+  Thread_private* p = 0;
+  if (t){
+    p = t->priv_;
+    oldstate = Thread::push_bstack(p, Thread::BLOCK_MUTEX, name_);
+  }
+
+#if defined( __APPLE__ ) || defined ( _AIX )
+  // Temporary hack:
+  // On OSX and AIX, this call may come before the constructor (for
+  // static vars) for some reason.  To solve this problem we allocate
+  // priv_ and init it if the constructor was not called yet.
+  // Note:  This would appear to cause a deadlock or crash
+  // if we lock on priv_ and then call the constructor to replace it.
+  if ( !priv_ ) {
+    priv_=new Mutex_private;
+    pthread_mutex_init(&priv_->mutex, NULL);
+  }
+#endif
+
+  int status = pthread_mutex_lock(&priv_->mutex);
+  if (status)
+  {
+    switch (status)
+    {
+    case EINVAL:
+      throw ThreadError("pthread_mutex_lock:  Uninitialized lock.");
+      break;
+
+    case EDEADLK:
+      throw ThreadError("pthread_mutex_lock:  Calling thread already holds 
this lock.");
+      break;
+
+    default:
+      throw ThreadError("pthread_mutex_lock:  Unknown error.");
+    }
+  }
+
+  if (t)
+  {
+    Thread::pop_bstack(p, oldstate);
+  }
+}
+
+
+bool
+Mutex::tryLock()
+{
+  const int status = pthread_mutex_trylock(&priv_->mutex);
+  switch (status)
+  {
+  case 0:
+    return true;
+
+  case EBUSY:
+    return false;
+
+  default: // EINVAL
+    throw ThreadError("pthread_mutex_trylock:  Uninitialized lock.");
+  }
+}
+
+
+namespace Manta {
+struct RecursiveMutex_private {
+  pthread_mutex_t mutex;
+};
+} // namespace Manta
+
+
+RecursiveMutex::RecursiveMutex(const char* name)
+  : name_(name)
+{
+  if (!Thread::initialized)
+    Thread::initialize();
+  priv_ = new RecursiveMutex_private;
+
+  pthread_mutexattr_t attr;
+  pthread_mutexattr_init(&attr);
+  if (pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE) != 0)
+    throw ThreadError("pthread_mutexattr_settype: unknown kind.");
+  pthread_mutex_init(&priv_->mutex, &attr);
+  pthread_mutexattr_destroy(&attr);
+}
+
+
+RecursiveMutex::~RecursiveMutex()
+{
+  // RHE 3.0 pthread_mutex_destroy returns EBUSY if you unlock an
+  // already unlocked thread first.  So we force a lock/unlock before
+  // destroying.  Probably better to just remove the unlock altogether
+  // but this breaks the shutdown behavior.  TODO: This fix doesn't
+  // really work.  Race condition can relock between our unlock and
+  // destroy calls.
+  pthread_mutex_trylock(&priv_->mutex);
+  pthread_mutex_unlock(&priv_->mutex);
+  if (pthread_mutex_destroy(&priv_->mutex) != 0)
+  {
+    // EBUSY
+    fprintf(stderr, "RecursiveMutex::~RecursiveMutex: Warning:  Mutex 
currently locked.\n");
+    priv_ = 0;
+    return;
+    //throw ThreadError("pthread_mutex_destroy: Mutex currently locked.");
+  }
+  delete priv_;
+  priv_=0;
+}
+
+
+void
+RecursiveMutex::unlock()
+{
+  const int status = pthread_mutex_unlock(&priv_->mutex);
+  if (status)
+  {
+    switch (status)
+    {
+    case EINVAL:
+      ThreadError("pthread_mutex_unlock:  Uninitialized lock.");
+      break;
+
+    case EPERM:
+      ThreadError("pthread_mutex_unlock:  Calling thread did not lock.");
+      break;
+
+    default:
+      ThreadError("pthread_mutex_unlock:  Unknown error.");
+    }
+  }
+}
+
+
+void
+RecursiveMutex::lock()
+{
+  Thread* self = Thread::self();
+  int oldstate = 0;
+  Thread_private* p = NULL;
+  if (self) {
+    p = Thread::self()->priv_;
+    oldstate = Thread::push_bstack(p, Thread::BLOCK_ANY, name_);
+  }
+  const int status = pthread_mutex_lock(&priv_->mutex);
+  if (status)
+  {
+    switch (status)
+    {
+    case EINVAL:
+      throw ThreadError("pthread_mutex_lock:  Uninitialized lock.");
+      break;
+
+    case EDEADLK:
+      throw ThreadError("pthread_mutex_lock:  Calling thread already holds 
this lock.");
+      break;
+
+    default:
+      throw ThreadError("pthread_mutex_lock:  Unknown error.");
+    }
+  }
+
+  if (self) Thread::pop_bstack(p, oldstate);
+}
+
+
+namespace Manta {
+#if defined (__APPLE__)
+struct Semaphore_private {
+  Semaphore_private(const char *name, int value);
+  Mutex mutex_;
+  int   cnt_;
+  ConditionVariable cv_;
+};
+
+Semaphore_private::Semaphore_private(const char *name, int value) :
+  mutex_(name),
+  cnt_(value),
+  cv_(name)
+{
+}
+
+#else
+struct Semaphore_private {
+  sem_type sem;
+};
+#endif
+} // namespace Manta
+
+
+
+#if defined(__APPLE__)
+
+Semaphore::Semaphore(const char *name,int value)
+  : name_(name)
+{
+  priv_ = new Semaphore_private(name,value);
+}
+
+
+Semaphore::~Semaphore()
+{
+  if (priv_)
+  {
+    delete priv_;
+    priv_ = 0;
+  }
+}
+
+
+void
+Semaphore::down(int count)
+{
+  for (int p = 0 ; p < count; p++)
+  {
+    priv_->mutex_.lock();
+    priv_->cnt_--;
+    if (priv_->cnt_ < 0) priv_->cv_.wait(priv_->mutex_);
+    priv_->mutex_.unlock();
+  }
+}
+
+
+bool
+Semaphore::tryDown()
+{
+  priv_->mutex_.lock();
+  if (priv_->cnt_ > 0)
+  {
+    priv_->cnt_--;
+    priv_->mutex_.unlock();
+    return(true);
+  }
+  priv_->mutex_.unlock();
+  return(false);
+}
+
+
+void
+Semaphore::up(int count)
+{
+  for (int p = 0;p < count; p++)
+  {
+    priv_->mutex_.lock();
+    priv_->cv_.conditionBroadcast();
+    priv_->cnt_++;
+    priv_->mutex_.unlock();
+  }
+}
+
+#else
+
+Semaphore::Semaphore(const char* name, int value)
+  : name_(name)
+{
+  if (!Thread::initialized)
+    Thread::initialize();
+  priv_=new Semaphore_private;
+
+#if defined(_AIX)
+  priv_->sem =
+    (msemaphore*) mmap(NULL,sizeof(msemaphore),
+                       PROT_READ | PROT_WRITE,
+                       MAP_SHARED | MAP_ANONYMOUS | MAP_VARIABLE, -1, 0 );
+#endif
+
+  if ( !SEM_INIT_SUCCESS( SEM_INIT(&(priv_->sem), 0, value) ) )
+    throw ThreadError(std::string("SEM_INIT: ") + strerror(errno));
+}
+
+
+Semaphore::~Semaphore()
+{
+#if !defined(_AIX)
+  // Dd: Don't know exactly what to do about this for AIX...
+  int val;
+  sem_getvalue(&(priv_->sem),&val);
+  while (val<=0)
+  {
+    SEM_UNLOCK(&(priv_->sem));
+    sem_getvalue(&(priv_->sem),&val);
+  }
+  if (SEM_DESTROY(&priv_->sem) != 0)
+  {
+    throw ThreadError(std::string("sem_destroy: ")
+                      +strerror(errno));
+    perror("Sem destroy" );
+  }
+  delete priv_;
+  priv_=0;
+#endif
+}
+
+
+void
+Semaphore::up(int count)
+{
+  for (int i = 0;i<count;i++)
+  {
+    if (SEM_UNLOCK(&priv_->sem) != 0)
+      throw ThreadError(std::string("SEM_UNLOCK: ") + strerror(errno));
+  }
+}
+
+
+void
+Semaphore::down(int count)
+{
+  Thread* self = Thread::self();
+  int oldstate = 0;
+  Thread_private* p = NULL;
+  if (self) {
+    p = Thread::self()->priv_;
+    oldstate = Thread::push_bstack(p, Thread::BLOCK_SEMAPHORE, name_);
+  }
+  for (int i = 0;i<count;i++)
+  {
+    if (SEM_LOCK(&priv_->sem) != 0)
+    {
+      perror("sem lock");
+      throw ThreadError(std::string("SEM_LOCK: ") + strerror(errno));
+    }
+  }
+  if (self) Thread::pop_bstack(p, oldstate);
+}
+
+
+bool
+Semaphore::tryDown()
+{
+  if (SEM_TRYLOCK(&priv_->sem) != 0)
+  {
+    if (errno == EAGAIN)
+      return false;
+    throw ThreadError(std::string("SEM_TRYLOCK: ") + strerror(errno));
+  }
+  return true;
+}
+
+#endif
+
+namespace Manta {
+struct ConditionVariable_private {
+  pthread_cond_t cond;
+};
+} // namespace Manta
+
+
+ConditionVariable::ConditionVariable(const char* name)
+  : name_(name)
+{
+  if (!Thread::initialized)
+    Thread::initialize();
+  priv_ = new ConditionVariable_private;
+  pthread_cond_init(&priv_->cond, 0);
+}
+
+
+ConditionVariable::~ConditionVariable()
+{
+  if (pthread_cond_destroy(&priv_->cond) != 0)
+  {
+    ThreadError("pthread_cond_destroy:  Threads are currently waiting on 
this condition.");
+  }
+  delete priv_;
+  priv_=0;
+}
+
+
+void
+ConditionVariable::wait(Mutex& m)
+{
+  Thread* self = Thread::self();
+  if (self) {
+    Thread_private* p = Thread::self()->priv_;
+    int oldstate = Thread::push_bstack(p, Thread::BLOCK_ANY, name_);
+
+    pthread_cond_wait(&priv_->cond, &m.priv_->mutex);
+
+    Thread::pop_bstack(p, oldstate);
+  } else {
+
+    pthread_cond_wait(&priv_->cond, &m.priv_->mutex);
+  }
+}
+
+
+bool
+ConditionVariable::timedWait(Mutex& m, const struct timespec* abstime)
+{
+  Thread* self = Thread::self();
+  int oldstate = 0;
+  Thread_private* p = NULL;
+  if (self) {
+    p = Thread::self()->priv_;
+    oldstate = Thread::push_bstack(p, Thread::BLOCK_ANY, name_);
+  }
+  bool success;
+  if (abstime){
+    int err = pthread_cond_timedwait(&priv_->cond, &m.priv_->mutex, abstime);
+    if (err != 0){
+      if (err == ETIMEDOUT)
+        success = false;
+      else
+        throw ThreadError("pthread_cond_timedwait:  Interrupted by a 
signal.");
+    } else {
+      success = true;
+    }
+  } else {
+    pthread_cond_wait(&priv_->cond, &m.priv_->mutex);
+    success = true;
+  }
+  if (self) Thread::pop_bstack(p, oldstate);
+  return success;
+}
+
+
+void
+ConditionVariable::conditionSignal()
+{
+  pthread_cond_signal(&priv_->cond);
+}
+
+
+void
+ConditionVariable::conditionBroadcast()
+{
+  pthread_cond_broadcast(&priv_->cond);
+}
+
+#ifdef __ia64__
+
+namespace Manta {
+struct Barrier_private {
+  Barrier_private();
+
+  //  long long amo_val;
+  char pad0[128];
+  __int64 amo_val;
+  char pad1[128];
+  volatile int flag;
+  char pad2[128];
+};
+} // namespace Manta
+
+
+Barrier_private::Barrier_private()
+{
+  flag = 0;
+  amo_val = 0;
+}
+
+
+Barrier::Barrier(const char* name)
+  : name_(name)
+{
+  if (!Thread::isInitialized())
+  {
+    if (getenv("THREAD_SHOWINIT"))
+      fprintf(stderr, "Barrier: %s\n", name);
+    Thread::initialize();
+  }
+  priv_=new Barrier_private;
+}
+
+
+Barrier::~Barrier()
+{
+  delete priv_;
+  priv_=0;
+}
+
+
+void
+Barrier::wait(int n)
+{
+  Thread* self = Thread::self();
+  int oldstate;
+  Thread_private* p;
+  if (self) {
+    p = Thread::self()->priv_;
+    oldstate = Thread::push_bstack(p, Thread::BLOCK_BARRIER, name_);
+  }
+  int gen = priv_->flag;
+  __int64 val = __sync_fetch_and_add_di(&(priv_->amo_val),1);
+  if (val == n-1){
+    priv_->amo_val = 0;
+    priv_->flag++;
+  }
+  while(priv_->flag==gen)
+    /* spin */ ;
+  if (self) Thread::pop_bstack(p, oldstate);
+}
+
+
+namespace Manta {
+struct AtomicCounter_private {
+  AtomicCounter_private();
+
+  // These variables used only for non fectchop implementation
+  //  long long amo_val;
+  char pad0[128];
+  __int64 amo_val;
+  char pad1[128];
+};
+} // namespace Manta
+
+AtomicCounter_private::AtomicCounter_private()
+{
+}
+
+
+AtomicCounter::AtomicCounter(const char* name)
+  : name_(name)
+{
+  if (!Thread::isInitialized())
+  {
+    if (getenv("THREAD_SHOWINIT"))
+      fprintf(stderr, "AtomicCounter: %s\n", name);
+    Thread::initialize();
+  }
+  priv_=new AtomicCounter_private;
+  priv_->amo_val = 0;
+}
+
+
+AtomicCounter::AtomicCounter(const char* name, int value)
+  : name_(name)
+{
+  if (!Thread::isInitialized())
+  {
+    if (getenv("THREAD_SHOWINIT"))
+      fprintf(stderr, "AtomicCounter: %s\n", name);
+    Thread::initialize();
+  }
+  priv_=new AtomicCounter_private;
+  priv_->amo_val = value;
+}
+
+
+AtomicCounter::~AtomicCounter()
+{
+  delete priv_;
+  priv_=0;
+}
+
+
+AtomicCounter::operator int() const
+{
+  return (int)(priv_->amo_val);
+}
+
+// Preincrement
+int
+AtomicCounter::operator++()
+{
+  __int64 val = __sync_fetch_and_add_di(&(priv_->amo_val),1);
+  return (int)val+1;
+}
+
+
+// Postincrement
+int
+AtomicCounter::operator++(int)
+{
+  __int64 val = __sync_fetch_and_add_di(&(priv_->amo_val),1);
+  return (int)val;
+}
+
+// Predecrement
+int
+AtomicCounter::operator--()
+{
+  __int64 val = __sync_fetch_and_add_di(&(priv_->amo_val),-1);
+  return (int)val-1;
+}
+
+// Postdecrement
+int
+AtomicCounter::operator--(int)
+{
+  __int64 val = __sync_fetch_and_add_di(&(priv_->amo_val),-1);
+  return (int)val;
+}
+
+
+void
+AtomicCounter::set(int v)
+{
+  priv_->amo_val = v;
+}
+
+#endif // end #ifdef __ia64__

Added: trunk/Core/Thread/Thread_unix.cc
==============================================================================
--- (empty file)
+++ trunk/Core/Thread/Thread_unix.cc    Mon Nov 26 21:56:50 2007
@@ -0,0 +1,179 @@
+/*
+   For more information, please see: http://software.sci.utah.edu
+
+   The MIT License
+
+   Copyright (c) 2004 Scientific Computing and Imaging Institute,
+   University of Utah.
+
+   License for the specific language governing rights and limitations under
+   Permission is hereby granted, free of charge, to any person obtaining a
+   copy of this software and associated documentation files (the "Software"),
+   to deal in the Software without restriction, including without limitation
+   the rights to use, copy, modify, merge, publish, distribute, sublicense,
+   and/or sell copies of the Software, and to permit persons to whom the
+   Software is furnished to do so, subject to the following conditions:
+
+   The above copyright notice and this permission notice shall be included
+   in all copies or substantial portions of the Software.
+
+   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+   OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 
MERCHANTABILITY,
+   FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+   THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+   LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+   FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+   DEALINGS IN THE SOFTWARE.
+*/
+
+
+
+/*
+ *  Thread_unix.cc: Utilities for all unix implementations of the
+ *                 the thread library
+ *
+ *  Written by:
+ *   Author: Steve Parker
+ *   Department of Computer Science
+ *   University of Utah
+ *   Date: June 1997
+ *
+ *  Copyright (C) 1997 SCI Group
+ */
+
+#include <Core/Thread/Thread_unix.h>
+#include <stdio.h>
+#ifdef _WIN32
+#include <signal.h>
+#include <errno.h>
+#else
+#include <sys/errno.h>
+#include <sys/signal.h>
+#endif
+
+char*
+Core_Thread_signal_name(int sig, void* addr)
+{
+    static char buf[1000];
+    switch(sig){
+    case SIGINT:
+       sprintf(buf, "SIGINT (interrupt)");
+       break;
+    case SIGILL:
+       sprintf(buf, "SIGILL at address %p (illegal instruction)", addr);
+       break;
+    case SIGABRT:
+       sprintf(buf, "SIGABRT (Abort)");
+       break;
+    case SIGSEGV:
+       sprintf(buf, "SIGSEGV at address %p (segmentation violation)", addr);
+       break;
+    case SIGTERM:
+       sprintf(buf, "SIGTERM (killed)");
+       break;
+    case SIGFPE:
+       sprintf(buf, "SIGFPE (floating point exception)");
+       break;
+#ifdef SIGBREAK
+    case SIGBREAK:
+       sprintf(buf, "SIGBREAK (CTRL-Break sequence)");
+       break;
+#endif
+
+// these signals don't exist in win32
+#ifndef _WIN32 
+    case SIGHUP:
+       sprintf(buf, "SIGHUP (hangup)");
+       break;
+    case SIGQUIT:
+       sprintf(buf, "SIGQUIT (quit)");
+       break;
+    case SIGTRAP:
+       sprintf(buf, "SIGTRAP (trace trap)");
+       break;
+#ifdef SIGEMT
+    case SIGEMT:
+       sprintf(buf, "SIGEMT (Emulation Trap)");
+       break;
+#endif
+#ifdef SIGIOT
+#if SIGEMT != SIGIOT && SIGIOT != SIGABRT
+    case SIGIOT:
+       sprintf(buf, "SIGIOT (IOT Trap)");
+       break;
+#endif
+#endif
+    case SIGBUS:
+       sprintf(buf, "SIGBUS at address %p (bus error)", addr);
+       break;
+    case SIGKILL:
+       sprintf(buf, "SIGKILL (kill)");
+       break;
+#ifdef SIGSYS
+    case SIGSYS:
+       sprintf(buf, "SIGSYS (bad argument to system call)");
+       break;
+#endif
+    case SIGPIPE:
+       sprintf(buf, "SIGPIPE (broken pipe)");
+       break;
+    case SIGALRM:
+       sprintf(buf, "SIGALRM (alarm clock)");
+       break;
+    case SIGUSR1:
+       sprintf(buf, "SIGUSR1 (user defined signal 1)");
+       break;
+    case SIGUSR2:
+       sprintf(buf, "SIGUSR2 (user defined signal 2)");
+       break;
+    case SIGCHLD:
+       sprintf(buf, "SIGCLD (death of a child)");
+       break;
+#ifdef SIGPWR
+    case SIGPWR:
+       sprintf(buf, "SIGPWR (power fail restart)");
+       break;
+#endif
+    case SIGWINCH:
+       sprintf(buf, "SIGWINCH (window size changes)");
+       break;
+    case SIGURG:
+       sprintf(buf, "SIGURG (urgent condition on IO channel)");
+       break;
+    case SIGIO:  // Also SIGPOLL
+       sprintf(buf, "SIGIO/SIGPOLL (i/o possible)");
+       break;
+    case SIGSTOP:
+       sprintf(buf, "SIGSTOP (sendable stop signal)");
+       break;
+    case SIGTSTP:
+       sprintf(buf, "SIGTSTP (TTY stop)");
+       break;
+    case SIGCONT:
+       sprintf(buf, "SIGCONT (continue)");
+       break;
+    case SIGTTIN:
+       sprintf(buf, "SIGTTIN");
+       break;
+    case SIGTTOU:
+       sprintf(buf, "SIGTTOU");
+       break;
+    case SIGVTALRM:
+       sprintf(buf, "SIGVTALRM (virtual time alarm)");
+       break;
+    case SIGPROF:
+       sprintf(buf, "SIGPROF (profiling alarm)");
+       break;
+    case SIGXCPU:
+       sprintf(buf, "SIGXCPU (CPU time limit exceeded)");
+       break;
+    case SIGXFSZ:
+       sprintf(buf, "SIGXFSZ (Filesize limit exceeded)");
+       break;
+#endif
+    default:
+       sprintf(buf, "unknown signal(%d)", sig);
+       break;
+    }
+    return buf;
+}

Added: trunk/Core/Thread/Thread_unix.h
==============================================================================
--- (empty file)
+++ trunk/Core/Thread/Thread_unix.h     Mon Nov 26 21:56:50 2007
@@ -0,0 +1,51 @@
+/*
+   For more information, please see: http://software.sci.utah.edu
+
+   The MIT License
+
+   Copyright (c) 2004 Scientific Computing and Imaging Institute,
+   University of Utah.
+
+   License for the specific language governing rights and limitations under
+   Permission is hereby granted, free of charge, to any person obtaining a
+   copy of this software and associated documentation files (the "Software"),
+   to deal in the Software without restriction, including without limitation
+   the rights to use, copy, modify, merge, publish, distribute, sublicense,
+   and/or sell copies of the Software, and to permit persons to whom the
+   Software is furnished to do so, subject to the following conditions:
+
+   The above copyright notice and this permission notice shall be included
+   in all copies or substantial portions of the Software.
+
+   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+   OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 
MERCHANTABILITY,
+   FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+   THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+   LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+   FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+   DEALINGS IN THE SOFTWARE.
+*/
+
+
+
+/*
+ *  Thread_unix.h:  Header file for utiity functions for unix versions
+ *                 of the thread class
+ *
+ *  Written by:
+ *   Author: Steve Parker
+ *   Department of Computer Science
+ *   University of Utah
+ *   Date: June 1997
+ *
+ *  Copyright (C) 1997 SCI Group
+ */
+
+#ifndef Core_Thread_Thread_unix_h
+#define Core_Thread_Thread_unix_h
+
+#include <sys/types.h>
+
+char* Core_Thread_signal_name(int sig, void* code);
+
+#endif

Added: trunk/Core/Thread/Thread_win32.cc
==============================================================================
--- (empty file)
+++ trunk/Core/Thread/Thread_win32.cc   Mon Nov 26 21:56:50 2007
@@ -0,0 +1,1101 @@
+/*
+   For more information, please see: http://software.sci.utah.edu
+
+   The MIT License
+
+   Copyright (c) 2004 Scientific Computing and Imaging Institute,
+   University of Utah.
+
+   License for the specific language governing rights and limitations under
+   Permission is hereby granted, free of charge, to any person obtaining a
+   copy of this software and associated documentation files (the "Software"),
+   to deal in the Software without restriction, including without limitation
+   the rights to use, copy, modify, merge, publish, distribute, sublicense,
+   and/or sell copies of the Software, and to permit persons to whom the
+   Software is furnished to do so, subject to the following conditions:
+
+   The above copyright notice and this permission notice shall be included
+   in all copies or substantial portions of the Software.
+
+   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+   OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 
MERCHANTABILITY,
+   FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+   THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+   LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+   FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+   DEALINGS IN THE SOFTWARE.
+*/
+
+
+
+/*
+ *  Thread_win32.cc: win32 threads implementation of the thread library
+ *
+ *  Written by:
+ *   Author: Chris Moulding
+ *   Department of Computer Science
+ *   University of Utah
+ *   Date: November 1999
+ *
+ *  Copyright (C) 1999 SCI Group
+ */
+
+#include <Core/Thread/Mutex.h>
+#include <Core/Thread/Semaphore.h>
+#include <Core/Thread/Barrier.h>
+#include <Core/Thread/AtomicCounter.h>
+#include <Core/Thread/CrowdMonitor.h>
+#include <Core/Thread/ConditionVariable.h>
+#include <Core/Thread/Thread.h>
+#include <Core/Thread/Thread_unix.h>
+#include <Core/Thread/ThreadGroup.h>
+#include <Core/Malloc/Allocator.h>
+#include <Core/Thread/ThreadError.h>
+
+// version of windows
+#ifndef _WIN32_WINNT
+#define _WIN32_WINNT 0x0500
+#endif
+
+
+#define __REENTRANT
+#define _WINSOCK2API_
+#include <windows.h>
+#include <excpt.h>
+#include <signal.h>
+#include <string.h>
+#include <stdio.h>
+#include <iostream>
+#include <map>
+#undef private
+#undef public
+
+using std::cerr;
+using std::endl;
+using std::map;
+using std::string;
+
+#define MAX(x,y) ((x>y)?x:y)
+#define MIN(x,y) ((x<y)?x:y)
+
+#define MAXBSTACK 10
+#define MAXTHREADS 4000
+
+namespace Manta {
+  // a naive way to get Thread::self when the compiler 
+  // doesn't support thread-local storage
+  map<int, Thread*> threadids; 
+
+  // NOTE - Do not give semaphores or mutexes names - there's a good chance 
that
+  // if they have the same name they will conflict with each other (multiple 
semaphores
+  // with the same name act as one semaphore).
+  struct Thread_private {
+  public:
+    HANDLE t;                       // native thread
+    Thread* thread;
+    int threadid;
+    Thread::ThreadState state;
+    int bstacksize;
+    const char* blockstack[MAXBSTACK];
+    HANDLE done;                    // native semaphore
+    HANDLE delete_ready;            // native semaphore
+    HANDLE main_sema;
+    HANDLE control_c_sema;
+
+    static void initialize() { Thread::initialize(); }
+  };
+  
+  struct Mutex_private {
+    HANDLE lock;
+  };
+  
+  struct Semaphore_private {
+    HANDLE hSema;
+  };
+
+  struct CrowdMonitor_private {
+    ConditionVariable write_waiters;
+    ConditionVariable read_waiters;
+    Mutex lock;
+    int num_readers_waiting;
+    int num_writers_waiting;
+    int num_readers;
+    int num_writers;
+    CrowdMonitor_private();
+    ~CrowdMonitor_private();
+  };
+
+  // implemented with help from the article at 
+  // http://www.cs.wustl.edu/~schmidt/win32-cv-1.html
+  struct ConditionVariable_private {
+    Mutex waiters_count_lock_;
+    int waiters_count_;     // num waiting threads
+    HANDLE sema_;           // used to queue threads
+    HANDLE waiters_done_;   // auto-reset event used by broadcast/signal
+                            // to wait for waiting threads
+    size_t was_broadcast_;  // whether we're broadcasting or signalling
+    ConditionVariable_private(const char* name);
+    ~ConditionVariable_private();
+  };
+
+  struct Barrier_private {
+    Mutex mutex;
+    ConditionVariable cond0;
+    ConditionVariable cond1;
+    int cc;
+    int nwait;
+    Barrier_private();
+    ~Barrier_private();
+  };
+
+  struct AtomicCounter_private {
+    Mutex lock;
+    int value;
+    AtomicCounter_private();
+    ~AtomicCounter_private();
+  };
+
+  struct ThreadLocalMemory {
+    Thread* current_thread;
+  };
+
+/*  Thread-local storage - not all compilers support it
+#if 1
+  // this is the VC way to give thread-local storage
+__declspec(thread) ThreadLocalMemory* thread_local;
+#else
+__thread ThreadLocalMemory* thread_local; // __attribute__ ((tls_model 
("initial-exec")));
+#endif
+*/
+bool exiting=false;
+
+  char* threadError()
+  {
+    char* lpMsgBuf;
+    FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | 
FORMAT_MESSAGE_FROM_SYSTEM,
+      NULL, GetLastError(), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), 
(LPTSTR) &lpMsgBuf, 0, NULL);
+
+    return lpMsgBuf;
+
+  }
+
+Mutex::Mutex(const char* name)
+{
+       priv_ = scinew Mutex_private;
+       priv_->lock = CreateMutex(NULL,0,0);
+       if (priv_->lock == 0)
+       {
+         throw ThreadError(std::string("CreateMutex failed")
+                           +threadError());
+       }
+
+       if(getenv("THREAD_SHOWINIT"))
+         fprintf(stderr, "Mutex: %s\n", name);
+       int length = strlen(name);
+       name_ = new char[length+1];
+       sprintf((char*)name_,"%s",name);
+}
+
+Mutex::~Mutex()
+{
+    CloseHandle(priv_->lock);
+    delete[] (char*)name_;
+    delete priv_;
+    priv_=0;
+}
+
+void Mutex::lock()
+{
+       WaitForSingleObject(priv_->lock,INFINITE);
+}
+
+void Mutex::unlock()
+{
+       ReleaseMutex(priv_->lock);
+}
+
+bool Mutex::tryLock()
+{
+       int check = WaitForSingleObject(priv_->lock,0);
+       if (check == WAIT_OBJECT_0)
+               return 1;
+       else if (check == WAIT_TIMEOUT)
+               return 0;
+       else 
+       {
+         throw ThreadError(std::string("Mutex::try_lock failed")
+                           +threadError());
+       }
+       return 0; // never happens
+}
+
+static Thread_private* active[MAXTHREADS];
+static int numActive;
+static HANDLE sched_lock;              
+__declspec(dllexport) HANDLE main_sema;         
+//static HANDLE control_c_sema;
+
+Semaphore::Semaphore(const char* name,int count)
+{
+       priv_ = scinew Semaphore_private;
+       priv_->hSema = 
CreateSemaphore(NULL,count,MAX(1000,MIN(2*count,100)),0);
+       if (priv_->hSema == 0)
+       {
+         throw ThreadError(std::string("CreateSemaphore failed")
+                           +threadError());
+       }
+       if(getenv("THREAD_SHOWINIT"))
+         fprintf(stderr, "Semaphore: %s\n", name);
+       int length = strlen(name);
+       name_ = new char[length+1];
+       sprintf((char*)name_,"%s",name);
+}
+
+Semaphore::~Semaphore()
+{
+    CloseHandle(priv_->hSema);
+    delete[] (char*)name_;
+    delete priv_;
+    priv_=0;
+}
+
+void Semaphore::down(int dec)
+{
+       int check;
+       for (int loop = 0;loop<dec;loop++) {
+               check = WaitForSingleObject(priv_->hSema,INFINITE);
+               if (check != WAIT_OBJECT_0)
+               {
+                       if (check == WAIT_ABANDONED);
+                       else if (check == WAIT_TIMEOUT);
+                       else if (check == (int) WAIT_FAILED)
+                       {
+                               throw 
ThreadError(std::string("WaitForSingleObject failed")
+                                                 +threadError());
+                       }
+                       else;
+               }
+       }
+}
+
+bool Semaphore::tryDown()
+{
+       int check = WaitForSingleObject(priv_->hSema,0);
+       if (check == WAIT_OBJECT_0)
+               return 0;
+       else if (check == WAIT_TIMEOUT)
+               return 1;
+       else 
+       {
+         throw ThreadError(std::string("WaitForSingleObject failed")
+                           +threadError());
+       }
+       return 0; // never happens
+}
+
+void Semaphore::up(int inc)
+{
+       long count;
+       ReleaseSemaphore(priv_->hSema,inc,&count);
+}
+
+
+AtomicCounter_private::AtomicCounter_private()
+    : lock("AtomicCounter lock")
+{
+}
+
+AtomicCounter_private::~AtomicCounter_private()
+{
+}
+
+AtomicCounter::AtomicCounter(const char* name)
+    : name_(name)
+{
+  if(!Thread::isInitialized()){
+    if(getenv("THREAD_SHOWINIT"))
+      fprintf(stderr, "AtomicCounter: %s\n", name);
+    Thread_private::initialize();
+  }
+  priv_=new AtomicCounter_private;
+}
+
+AtomicCounter::AtomicCounter(const char* name, int value)
+    : name_(name)
+{
+  priv_=new AtomicCounter_private;
+  priv_->value=value;
+  if(getenv("THREAD_SHOWINIT"))
+    fprintf(stderr, "AtomicCounter: %s\n", name);
+
+}
+
+AtomicCounter::~AtomicCounter()
+{
+  delete priv_;
+  priv_=0;
+}
+
+AtomicCounter::operator int() const
+{
+    return priv_->value;
+}
+
+int
+AtomicCounter::operator++()
+{
+  int oldstate = Thread::couldBlock(name_);
+  priv_->lock.lock();
+  int ret=++priv_->value;
+  priv_->lock.unlock();
+  Thread::couldBlockDone(oldstate);
+  return ret;
+}
+
+int
+AtomicCounter::operator++(int)
+{
+  int oldstate = Thread::couldBlock(name_);
+  priv_->lock.lock();
+  int ret=priv_->value++;
+  priv_->lock.unlock();
+  Thread::couldBlockDone(oldstate);
+  return ret;
+}
+
+int
+AtomicCounter::operator--()
+{
+  int oldstate = Thread::couldBlock(name_);
+  priv_->lock.lock();
+  int ret=--priv_->value;
+  priv_->lock.unlock();
+  Thread::couldBlockDone(oldstate);
+  return ret;
+}
+
+int
+AtomicCounter::operator--(int)
+{
+  int oldstate = Thread::couldBlock(name_);
+  priv_->lock.lock();
+  int ret=priv_->value--;
+  priv_->lock.unlock();
+  Thread::couldBlockDone(oldstate);
+  return ret;
+}
+
+void
+AtomicCounter::set(int v)
+{
+  int oldstate=Thread::couldBlock(name_);
+  priv_->lock.lock();
+  priv_->value=v;
+  priv_->lock.unlock();
+  Thread::couldBlockDone(oldstate);
+}
+
+
+CrowdMonitor_private::CrowdMonitor_private()
+  : write_waiters("CrowdMonitor write condition"),
+    read_waiters("CrowdMonitor read condition"),
+    lock("CrowdMonitor lock")
+{
+  num_readers_waiting=0;
+  num_writers_waiting=0;
+  num_readers=0;
+  num_writers=0;
+}
+
+CrowdMonitor_private::~CrowdMonitor_private()
+{
+}
+
+CrowdMonitor::CrowdMonitor(const char* name)
+  : name_(name)
+{
+  if(!Thread::isInitialized()){
+    if(getenv("THREAD_SHOWINIT"))
+      fprintf(stderr, "CrowdMonitor: %s\n", name);
+
+    Thread_private::initialize();
+  }
+  priv_=new CrowdMonitor_private;
+}
+
+CrowdMonitor::~CrowdMonitor()
+{
+  delete priv_;
+  priv_=0;
+}
+
+void
+CrowdMonitor::readLock()
+{
+  int oldstate=Thread::couldBlock(name_);
+  priv_->lock.lock();
+  while(priv_->num_writers > 0){
+    priv_->num_readers_waiting++;
+    int s=Thread::couldBlock(name_);
+    priv_->read_waiters.wait(priv_->lock);
+    Thread::couldBlockDone(s);
+    priv_->num_readers_waiting--;
+  }
+  priv_->num_readers++;
+  priv_->lock.unlock();
+  Thread::couldBlockDone(oldstate);
+}
+
+void
+CrowdMonitor::readUnlock()
+{
+  priv_->lock.lock();
+  priv_->num_readers--;
+  if(priv_->num_readers == 0 && priv_->num_writers_waiting > 0)
+    priv_->write_waiters.conditionSignal();
+  priv_->lock.unlock();
+}
+
+void
+CrowdMonitor::writeLock()
+{
+  int oldstate=Thread::couldBlock(name_);
+  priv_->lock.lock();
+  while(priv_->num_writers || priv_->num_readers){
+    // Have to wait...
+    priv_->num_writers_waiting++;
+    int s=Thread::couldBlock(name_);
+    priv_->write_waiters.wait(priv_->lock);
+    Thread::couldBlockDone(s);
+    priv_->num_writers_waiting--;
+  }
+  priv_->num_writers++;
+  priv_->lock.unlock();
+  Thread::couldBlockDone(oldstate);
+} 
+
+void
+CrowdMonitor::writeUnlock()
+{
+  priv_->lock.lock();
+  priv_->num_writers--;
+  if(priv_->num_writers_waiting)
+    priv_->write_waiters.conditionSignal(); // Wake one of them up...
+  else if(priv_->num_readers_waiting)
+    priv_->read_waiters.conditionBroadcast(); // Wake all of them up...
+  priv_->lock.unlock();
+}
+
+Barrier_private::Barrier_private()
+  : mutex("Barrier lock"),
+    cond0("Barrier condition 0"), cond1("Barrier condition 1"),
+    cc(0), nwait(0)
+{
+}
+
+Barrier_private::~Barrier_private()
+{
+}
+
+Barrier::Barrier(const char* name)
+  : name_(name)
+{
+  if(!Thread::isInitialized()){
+    if(getenv("THREAD_SHOWINIT"))
+      fprintf(stderr, "Barrier: %s\n", name);
+    Thread_private::initialize();
+  }
+  priv_=new Barrier_private;
+}
+
+Barrier::~Barrier()
+{
+  delete priv_;
+  priv_=0;
+}
+
+void
+Barrier::wait(int n)
+{
+  int oldstate=Thread::couldBlock(name_);
+  priv_->mutex.lock();
+  ConditionVariable& cond=priv_->cc?priv_->cond0:priv_->cond1;
+  priv_->nwait++;
+  if(priv_->nwait == n){
+    // Wake everybody up...
+    priv_->nwait=0;
+    priv_->cc=1-priv_->cc;
+    cond.conditionBroadcast();
+  } else {
+    cond.wait(priv_->mutex);
+  }
+  priv_->mutex.unlock();
+  Thread::couldBlockDone(oldstate);
+}
+
+ConditionVariable_private::ConditionVariable_private(const char* name)
+  : waiters_count_lock_(name), waiters_count_(0), was_broadcast_(0)
+{
+  sema_ = CreateSemaphore(NULL,0,50,NULL);
+  if (sema_ == 0) {
+    throw ThreadError(std::string("CreateSemaphore failed")
+                     +threadError());
+  }
+  
+  waiters_done_ = CreateEvent(NULL, FALSE, FALSE, NULL);
+  if (waiters_done_ == 0) {
+    throw ThreadError(std::string("CreateEvent failed")
+                     +threadError());
+  }
+
+}
+
+ConditionVariable_private::~ConditionVariable_private()
+{
+}
+
+ConditionVariable::ConditionVariable(const char* name)
+  : name_(name)
+{
+  if (!Thread::isInitialized()) 
+    Thread_private::initialize();
+  if(getenv("THREAD_SHOWINIT"))
+    fprintf(stderr, "ConditionVariable: %s\n", name);
+  priv_ = new ConditionVariable_private(name);
+  
+}
+
+ConditionVariable::~ConditionVariable()
+{
+  delete priv_;
+  priv_ = 0;
+}
+
+void
+ConditionVariable::wait(Mutex& m)
+{
+  timedWait(m, 0);
+}
+
+bool
+ConditionVariable::timedWait(Mutex& m, const struct timespec* abstime)
+{
+  bool success = true;
+  DWORD waittime = 0;
+  if (abstime) {
+    // convert abstime to milliseconds
+  } else {
+    waittime = INFINITE;
+  }
+
+  Thread_private* p = Thread::self()->priv_;
+  int oldstate = Thread::push_bstack(p, Thread::BLOCK_ANY, name_);
+
+ priv_->waiters_count_lock_.lock();
+  priv_->waiters_count_++;
+ priv_->waiters_count_lock_.unlock();
+
+  //release m and wait on sema until signal or broadcast called by other 
thread
+  int err = SignalObjectAndWait(m.priv_->lock, priv_->sema_, waittime, 
FALSE);
+  if (err != WAIT_OBJECT_0) {
+    if (err == WAIT_TIMEOUT)
+      success = false;
+    else
+      throw ThreadError(std::string("SignalObjectAndWait failed: ")
+                       +threadError());
+  }
+
+ priv_->waiters_count_lock_.lock();
+  priv_->waiters_count_--;
+
+  // check to see if we're the last waiter after broadcast
+  int last_waiter = priv_->was_broadcast_ && priv_->waiters_count_ == 0;
+ priv_->waiters_count_lock_.unlock();
+  
+  if (last_waiter) {
+    // signal waiters_done and wait for mutex (to ensure fairness)
+    err = SignalObjectAndWait(priv_->waiters_done_, m.priv_->lock, INFINITE, 
FALSE);
+    if (err != WAIT_OBJECT_0)
+      throw ThreadError(std::string("SignalObjectAndWait failed: ")
+                       +threadError());
+  }
+  else
+    m.lock(); 
+  Thread::pop_bstack(p, oldstate);
+
+  
+  return success;
+}
+
+void
+ConditionVariable::conditionSignal()
+{
+  priv_->waiters_count_lock_.lock();
+  int have_waiters = priv_->waiters_count_ > 0;
+ priv_->waiters_count_lock_.unlock(); 

+ if (have_waiters)
+   ReleaseSemaphore(priv_->sema_, 1, 0);
+}
+
+void
+ConditionVariable::conditionBroadcast()
+{
+  priv_->waiters_count_lock_.lock();
+  int have_waiters = 0;
+  
+  if (priv_->waiters_count_ > 0) {
+    // broadcast
+    priv_->was_broadcast_ = 1;
+    have_waiters = 1;
+  }
+
+  if (have_waiters) {
+    // wake up waiting threads
+    ReleaseSemaphore(priv_->sema_, priv_->waiters_count_, 0);
+    
+    priv_->waiters_count_lock_.unlock();
+    
+    // wait for threads to acquire semaphore
+    WaitForSingleObject(priv_->waiters_done_, INFINITE);
+    priv_->was_broadcast_ = 0;
+  }
+  else 
+    priv_->waiters_count_lock_.unlock();
+}
+
+static void lock_scheduler()
+{
+       if(WaitForSingleObject(sched_lock,INFINITE)!=WAIT_OBJECT_0) {
+         throw ThreadError(std::string("lock_scheduler failed")
+                           +threadError());
+       }
+}
+
+static void unlock_scheduler()
+{
+       if(!ReleaseMutex(sched_lock)) {
+         throw ThreadError(std::string("unlock_scheduler failed")
+                           +threadError());
+       }
+}
+
+/*
+ * Handle an abort signal - like segv, bus error, etc.
+ */
+static
+void
+handle_abort_signals(int sig)
+{
+    Thread* self=Thread::self();
+    signal(sig, SIG_DFL);
+
+    const char* tname=self?self->getThreadName():"idle or main";
+    char* signam=Core_Thread_signal_name(sig, 0);
+    fprintf(stderr, "%c%c%cThread \"%s\"(pid %d) caught signal %s\n", 
7,7,7,tname, (int)GetCurrentThreadId(), signam);
+    fflush(stderr);
+    Thread::niceAbort();
+
+    signal(sig, handle_abort_signals);
+}
+
+void
+Thread::print_threads()
+{
+    FILE* fp=stderr;
+    for(int i=0;i<numActive;i++){
+       Thread_private* p=active[i];
+       const char* tname=p->thread?p->thread->getThreadName():"???";
+       fprintf(fp, " %d: %s (", p->threadid, tname);
+       if(p->thread){
+           if(p->thread->isDaemon())
+               fprintf(fp, "daemon, ");
+           if(p->thread->isDetached())
+               fprintf(fp, "detached, ");
+       }
+       fprintf(fp, "state=%s", Thread::getStateString(p->state));
+       for(int i=0;i<p->bstacksize;i++){
+           fprintf(fp, ", %s", p->blockstack[i]);
+       }
+       fprintf(fp, ")\n");
+    }
+}
+
+LONG WINAPI exception_handler(LPEXCEPTION_POINTERS ptr)
+{
+  Thread* self=Thread::self();
+  const char* tname=self?self->getThreadName():"idle or main";
+  char* signam=Core_Thread_signal_name(SIGSEGV, 0);
+  fprintf(stderr, "%c%c%cThread \"%s\"(pid %d) caught signal %s\n", 
7,7,7,tname, (int)GetCurrentThreadId(), signam);
+  fflush(stderr);
+  Thread::niceAbort(ptr->ContextRecord);
+  return 0;
+}
+
+/*
+ * Setup signals for the current thread
+ */
+static
+void
+install_signal_handlers()
+{
+    signal(SIGILL, handle_abort_signals);
+    signal(SIGABRT, handle_abort_signals);
+    signal(SIGTERM, handle_abort_signals);
+    signal(SIGFPE, handle_abort_signals);
+    signal(SIGSEGV, handle_abort_signals);
+    signal(SIGBREAK, handle_abort_signals);
+    signal(SIGINT, handle_abort_signals);
+
+    // NT doesn't generate SIGILL, SIGTERM, or SIGSEGV, so this should catch 
them
+    SetUnhandledExceptionFilter(exception_handler);
+}
+
+#if 0
+static void exit_handler()
+{
+    if(exiting)
+        return;
+
+    // Wait forever...
+       cerr << "waiting forever" << endl;
+       HANDLE wait;
+       wait = CreateSemaphore(0,0,10,0);
+       if(WaitForSingleObject(wait,INFINITE)!=WAIT_OBJECT_0) {
+         throw ThreadError(std::string("WaitForSingleObject (exit_handler) 
failed")
+                           +threadError());
+       }
+       cerr << "didn't wait forever!" << endl;
+}
+#endif
+void Thread::initialize()
+{
+       // atexit() has a semantic bug in win32, so we block in main.cc 
instead.
+    //atexit(exit_handler);
+
+       sched_lock = CreateMutex(0,0,0);
+       if (!sched_lock) {
+         throw ThreadError(std::string("CreateMutex (sched_lock) failed")
+                           +threadError());
+       }
+
+    ThreadGroup::s_default_group=new ThreadGroup("default group", 0);
+    Thread* mainthread=new Thread(ThreadGroup::s_default_group, "main");
+    mainthread->priv_=new Thread_private;
+    mainthread->priv_->thread=mainthread;
+         mainthread->priv_->threadid = GetCurrentThreadId();
+    mainthread->priv_->state=RUNNING;
+    mainthread->priv_->bstacksize=0;
+
+    threadids[mainthread->priv_->threadid] = mainthread;
+
+       cerr << "mainthread id = " << mainthread->priv_->threadid << endl;
+
+       //thread_local = new ThreadLocalMemory;
+       //thread_local->current_thread = mainthread;
+
+        mainthread->priv_->done = CreateSemaphore(0,0,10,0);
+       if (!mainthread->priv_->done) {
+         throw ThreadError(std::string("CreateSemaphore (done) failed")
+                           +threadError());
+       }
+
+       mainthread->priv_->delete_ready = CreateSemaphore(0,0,10,0);
+       if (!mainthread->priv_->delete_ready) {
+         throw ThreadError(std::string("CreateSemaphore (delete_ready) 
failed")
+                           +threadError());
+       }
+
+       mainthread->priv_->main_sema = CreateSemaphore(0,2,MAXTHREADS,0);
+       if (!mainthread->priv_->main_sema) {
+         throw ThreadError(std::string("CreateSemaphore (main_sema) failed")
+                           +threadError());
+       }
+
+       mainthread->priv_->control_c_sema = CreateSemaphore(0,1,MAXTHREADS,0);
+       if (!mainthread->priv_->control_c_sema) {
+         throw ThreadError(std::string("CreateSemaphore (control_c_sema) 
failed")
+                           +threadError());
+       }
+
+    lock_scheduler();
+    active[numActive]=mainthread->priv_;
+    numActive++;
+    unlock_scheduler();
+
+//#if 0
+    if(!getenv("THREAD_NO_CATCH_SIGNALS")) {
+       install_signal_handlers();
+    }
+//#endif
+    Thread::initialized = true;
+
+}
+
+void Thread_run(Thread* t)
+{
+  // in the try-except functionality, we have access to the entire stack 
trace in the except () clause
+  // (it has access to the stack before executing the exception handler 
while it determines where to land
+  // the exception
+#ifdef _MSC_VER 
+  __try {
+#endif
+    t->run_body();
+#ifdef _MSC_VER
+  } 
__except(Thread::niceAbort(((LPEXCEPTION_POINTERS)GetExceptionInformation())->ContextRecord),
 
+      EXCEPTION_CONTINUE_SEARCH) {
+
+  }
+#endif
+}
+
+void Thread::migrate(int proc)
+{
+    // Nothing for now...
+}
+
+void Thread_shutdown(Thread* thread, bool actually_exit)
+{
+    Thread_private* priv=thread->priv_;
+    char name[256];
+    strcpy(name, thread->threadname_);
+
+    ReleaseSemaphore(priv->done, 1, 0);
+
+    // Wait to be deleted...
+       if (WaitForSingleObject(priv->delete_ready,INFINITE)!=WAIT_OBJECT_0) {
+         throw ThreadError(std::string("WaitForSingleObject (delete_ready) 
failed")
+                           +threadError());
+       }
+
+       
+       delete thread;
+
+    // Allow this thread to run anywhere...
+    if(thread->cpu_ != -1)
+       thread->migrate(-1);
+
+    lock_scheduler();
+    //thread_local->current_thread = 0;
+    priv->thread=0;
+    CloseHandle(priv->done);
+    CloseHandle(priv->delete_ready);
+
+    /* Remove it from the active queue */
+    int i;
+    for(i=0;i<numActive;i++){
+       if(active[i]==priv)
+           break;
+    }
+    for(i++;i<numActive;i++){
+       active[i-1]=active[i];
+    }
+    numActive--;
+
+    // This can't be done in checkExit, because of a potential race
+    // condition.
+    int done=true;
+    for(int i=0;i<numActive;i++){
+       Thread_private* p=active[i];
+       if(!p->thread->isDaemon()){
+           done=false;
+           break;
+       }
+    }
+    
+    unlock_scheduler();
+
+    if(done)
+       Thread::exitAll(0);
+
+    if(priv->threadid == 0){
+       priv->state=Thread::PROGRAM_EXIT;
+       if (WaitForSingleObject(main_sema,INFINITE)!=WAIT_OBJECT_0) {
+         throw ThreadError(std::string("WaitForSingleObject (main_sema) 
failed")
+                           +threadError());
+       }
+    }
+    // get rid of the tls hack
+    threadids.erase(GetCurrentThreadId());
+
+    if (actually_exit)
+      ExitThread(0);
+}
+
+unsigned long run_threads(void* priv_v)
+{
+    Thread_private* priv=(Thread_private*)priv_v;
+    threadids[priv->threadid] = priv->thread;
+    //thread_local = new ThreadLocalMemory;
+    //thread_local->current_thread = priv->thread;
+    priv->state=Thread::RUNNING;
+    Thread_run(priv->thread);
+    priv->state=Thread::SHUTDOWN;
+    Thread_shutdown(priv->thread, false);
+    return 0; // Never reached
+}
+
+// matches the callback from CreateThread, use the helper so we can friend it
+unsigned long __stdcall start_threads(void* priv_v)
+{
+  return run_threads(priv_v);
+}
+
+Thread* Thread::self()
+{
+  //return thread_local->current_thread;
+  int threadid = GetCurrentThreadId();
+  map<int, Thread*>::iterator iter = threadids.find(threadid);
+  if (iter == threadids.end()) {
+    printf("Thread::self failed: This thread: %d\n", threadid);
+    printf("Available threads: ");
+    for (iter = threadids.begin(); iter != threadids.end(); iter++) {
+      printf("%d ",iter->first);
+    }
+    printf("\n");
+    return 0;
+  }
+  return iter->second;
+}
+
+void Thread::exitAll(int code)
+{
+    exiting=true;
+    ::exit(code);
+}
+
+void Thread::exit()
+{
+  Thread* self = Thread::self();
+  Thread_shutdown(self, true);
+}
+
+void Thread::os_start(bool stopped)
+{
+    if(!Thread::initialized)
+       Thread_private::initialize();
+
+    priv_=new Thread_private;
+
+    priv_->done = CreateSemaphore(0,0,100,0);
+       if (!priv_->done) {
+         throw ThreadError(std::string("CreateSemaphore (done) failed")
+                           +threadError());
+       }
+       priv_->delete_ready = CreateSemaphore(0,0,100,0);
+       if (!priv_->delete_ready) {
+         throw ThreadError(std::string("CreateSemaphore (delete_ready) 
failed")
+                           +threadError());
+       }
+
+    priv_->state=STARTUP;
+    priv_->bstacksize=0;
+    priv_->thread=this;
+    priv_->threadid=0;
+    priv_->main_sema = main_sema;
+
+    lock_scheduler();
+       priv_->t = 
CreateThread(0,stacksize_,start_threads,priv_,(stopped?CREATE_SUSPENDED:0),(unsigned
 long*)&priv_->threadid);
+  threadids[priv_->threadid] = this;
+       if (!priv_->t) {
+         throw ThreadError(std::string("CreateThread failed")
+                           +threadError());
+       }
+    active[numActive]=priv_;
+    numActive++;
+    unlock_scheduler();
+}
+
+void Thread::checkExit()
+{
+    lock_scheduler();
+    int done=true;
+    for(int i=0;i<numActive;i++){
+       Thread_private* p=active[i];
+       if(!p->thread->isDaemon()){
+           done=false;
+           break;
+       }
+    }
+    unlock_scheduler();
+
+    if(done)
+       Thread::exitAll(0);
+}
+
+void Thread::detach()
+{
+  ReleaseSemaphore(priv_->delete_ready,1,NULL);
+  detached_=true;
+}
+
+void Thread::stop()
+{
+  SuspendThread(priv_->t);
+}
+
+void Thread::resume()
+{
+  ResumeThread(priv_->t);
+}
+
+void Thread::join()
+{
+  // wait for thread to be done - get the handle and release it
+  WaitForSingleObject(priv_->done,INFINITE);
+  ReleaseSemaphore(priv_->done,1,NULL);
+  ReleaseSemaphore(this->priv_->delete_ready,1,NULL);
+}
+
+void Thread::yield()
+{
+       Sleep(0);
+}
+
+int Thread::numProcessors()
+{
+       SYSTEM_INFO sysinfo;
+       GetSystemInfo(&sysinfo);
+       return sysinfo.dwNumberOfProcessors;
+}
+
+int Thread::push_bstack(Thread_private* p, Thread::ThreadState state,
+                   const char* name)
+{
+    int oldstate=p->state;
+    p->state=state;
+    p->blockstack[p->bstacksize]=name;
+    p->bstacksize++;
+    if(p->bstacksize>MAXBSTACK){
+       fprintf(stderr, "Blockstack Overflow!\n");
+       Thread::niceAbort();
+    }
+    return oldstate;
+}
+
+void Thread::pop_bstack(Thread_private* p, int oldstate)
+{
+    p->bstacksize--;
+    p->state=(ThreadState)oldstate;
+} 
+
+void ThreadGroup::gangSchedule()
+{
+}
+
+void
+Thread::allow_sgi_OpenGL_page0_sillyness()
+{
+  // Nothing necessary here
+}
+
+void
+Thread::disallow_sgi_OpenGL_page0_sillyness()
+{
+  // Nothing necessary here
+}
+
+
+} // end namespace Manta
+
+

Added: trunk/Core/Thread/Time.h
==============================================================================
--- (empty file)
+++ trunk/Core/Thread/Time.h    Mon Nov 26 21:56:50 2007
@@ -0,0 +1,108 @@
+/*
+   For more information, please see: http://software.sci.utah.edu
+
+   The MIT License
+
+   Copyright (c) 2004 Scientific Computing and Imaging Institute,
+   University of Utah.
+
+   License for the specific language governing rights and limitations under
+   Permission is hereby granted, free of charge, to any person obtaining a
+   copy of this software and associated documentation files (the "Software"),
+   to deal in the Software without restriction, including without limitation
+   the rights to use, copy, modify, merge, publish, distribute, sublicense,
+   and/or sell copies of the Software, and to permit persons to whom the
+   Software is furnished to do so, subject to the following conditions:
+
+   The above copyright notice and this permission notice shall be included
+   in all copies or substantial portions of the Software.
+
+   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+   OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 
MERCHANTABILITY,
+   FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+   THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+   LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+   FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+   DEALINGS IN THE SOFTWARE.
+*/
+
+
+
+/*
+ *  Time: Utility class for dealing with time
+ *
+ *  Written by:
+ *   Author: Steve Parker
+ *   Department of Computer Science
+ *   University of Utah
+ *   Date: June 1997
+ *
+ *  Copyright (C) 1997 SCI Group
+ */
+
+#ifndef Manta_Time_h
+#define Manta_Time_h
+
+namespace Manta {
+/**************************************
+
+ CLASS
+ Time
+
+ KEYWORDS
+ Thread, Time
+
+ DESCRIPTION
+ Utility class to manage Time.  This class is implemented using
+ high precision counters on the SGI, and standard unix system calls
+ on other machines.
+
+****************************************/
+class Time {
+public:
+  typedef unsigned long long SysClock;
+           
+  //////////
+  // Return the current system time, in terms of clock ticks.
+  // Time zero is at some arbitrary point in the past.
+  static SysClock currentTicks();
+           
+  //////////
+  // Return the current system time, in terms of seconds.
+  // This is slower than currentTicks().  Time zero is at
+  // some arbitrary point in the past.
+  static double currentSeconds();
+           
+  //////////
+  // Return the conversion from seconds to ticks.
+  static double ticksPerSecond();
+           
+  //////////
+  // Return the conversion from ticks to seconds.
+  static double secondsPerTick();
+           
+  //////////
+  // Wait until the specified time in clock ticks.
+  static void waitUntil(SysClock ticks);
+           
+  //////////
+  // Wait until the specified time in seconds.
+  static void waitUntil(double seconds);
+           
+  //////////
+  // Wait for the specified time in clock ticks
+  static void waitFor(SysClock ticks);
+           
+  //////////
+  // Wait for the specified time in seconds
+  static void waitFor(double seconds);
+
+private:
+  Time();
+  static void initialize();
+};
+}
+
+#endif
+
+

Added: trunk/Core/Thread/Time_altix.cc
==============================================================================
--- (empty file)
+++ trunk/Core/Thread/Time_altix.cc     Mon Nov 26 21:56:50 2007
@@ -0,0 +1,176 @@
+
+/*
+ For more information, please see: http://software.sci.utah.edu

+ The MIT License

+ Copyright (c) 2005 Silicon Graphics Inc.

+ License for the specific language governing rights and limitations under
+ Permission is hereby granted, free of charge, to any person obtaining a
+ copy of this software and associated documentation files (the "Software"),
+ to deal in the Software without restriction, including without limitation
+ the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ and/or sell copies of the Software, and to permit persons to whom the
+ Software is furnished to do so, subject to the following conditions:

+ The above copyright notice and this permission notice shall be included
+ in all copies or substantial portions of the Software.

+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ DEALINGS IN THE SOFTWARE.
+ */
+
+
+
+/*
+ *  Time_altix.cc: Timer implementation using memory mapped mmtimer
+ *                 For SGI Altix and Prism systems.
+ *
+ *  Written by:
+ *   Author: Abe Stephens
+ *   Date: July 2005
+ *
+ *   Implementation follows example provided by Brian Sumner (SGI)
+ *
+ *  Copyright (C) 2005 SGI
+ */
+
+
+#include <Core/Thread/Time.h>
+#include <Core/Thread/Thread.h>
+#include <Core/Thread/ThreadError.h>
+
+#include <stdio.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/ioctl.h>
+#include <sys/mman.h>
+#include <fcntl.h>
+#include <errno.h>
+
+#include <sn/mmtimer.h>
+
+#include <string>
+using namespace std;
+
+static bool initialized = false;
+
+typedef Time::SysClock SysClock;
+
+static double             mmtimer_scale;  // Seconds per tick.
+static SysClock           mmtimer_base;   // Tick value at initialization.
+static volatile SysClock *mmtimer_addr;   // Pointer to the memory mapped 
timer.
+
+void Time::initialize() {
+
+       // Only initialize once.
+       if (initialized) 
+               return;
+       initialized = true;
+
+       int fd, offset;
+       unsigned long femtosecs_per_tick;
+       char *m_page;
+
+       // First open the mmtimer, then memory map it.  
+       if ((fd = open( MMTIMER_FULLNAME, O_RDONLY, 0 )) < 0) {
+               throw ThreadError( string("MMTIMER_FULLNAME failed: ") + 
strerror( errno ) );
+       }
+       
+       // Check to see if we can memory map the timer.
+       if (ioctl(fd, MMTIMER_MMAPAVAIL, 0) <= 0) {
+               throw ThreadError( string("MMTIMER_MMAPAVAIL failed: ") + 
strerror( errno ) );
+       }
+
+       
+       // Determine the offset in the mapped page.
+       if ((offset = ioctl(fd, MMTIMER_GETOFFSET, 0)) < 0) {
+               throw ThreadError( string("MMTIMER_GETOFFSET failed: ") + 
strerror( errno ) );
+       }
+       
+       // Determine the timer resolution.
+       if (ioctl(fd, MMTIMER_GETRES, &femtosecs_per_tick) < 0) {
+               throw ThreadError( string("MMTIMER_GETRES failed: ") + 
strerror( errno ) );
+       }
+       
+       // Determine seconds per tick (femto/tick) / (femto/sec)
+       mmtimer_scale = (double)femtosecs_per_tick / 1.0e+15;
+       
+       // Map the timer.
+       if ((m_page = (char *)mmap( 0, getpagesize(), PROT_READ, MAP_SHARED, 
fd, 0 )) == MAP_FAILED) {
+               throw ThreadError( string("mmap of mmtimer failed: ") + 
strerror( errno ) );
+       }
+       
+       // All done with the fd.
+       close( fd );
+       
+       // Determine the timer address.
+       mmtimer_addr  = (volatile SysClock *)(m_page + offset);
+       
+       // Initial time.
+       mmtimer_base  = *mmtimer_addr;
+}
+
+double Time::secondsPerTick() {
+  if (!initialized)
+    initialize();
+  
+       return mmtimer_scale;
+}
+
+double Time::currentSeconds() {
+       if(!initialized)
+               initialize();
+       
+       return (double)((*mmtimer_addr) - mmtimer_base) * mmtimer_scale;
+}
+
+Time::SysClock Time::currentTicks() { 
+       
+       if(!initialized)
+               initialize();
+               
+       return (Time::SysClock)((*mmtimer_addr) - mmtimer_base);
+}
+
+double Time::ticksPerSecond() {
+       return 1.0 / secondsPerTick();
+}
+
+void Time::waitUntil(double seconds) {
+       waitFor(seconds-currentSeconds());
+}
+
+void Time::waitFor(double seconds) {
+       // Convert seconds to ticks.
+       SysClock ticks = ticksPerSecond() * seconds;
+       waitFor( ticks );
+}
+
+void Time::waitUntil(SysClock time) {
+       waitFor(time-currentTicks());
+}
+
+void Time::waitFor(SysClock ticks) {
+       if(!initialized)
+               initialize();
+
+       if(time <= 0)
+               return;
+
+       int oldstate=Thread::couldBlock("Timed wait");
+
+       // Busy wait.
+       SysClock end = (*mmtimer_addr) + ticks;
+       while ((*mmtimer_addr) < end);
+
+       Thread::couldBlockDone(oldstate);
+}
+

Added: trunk/Core/Thread/Time_irix.cc
==============================================================================
--- (empty file)
+++ trunk/Core/Thread/Time_irix.cc      Mon Nov 26 21:56:50 2007
@@ -0,0 +1,281 @@
+/*
+   For more information, please see: http://software.sci.utah.edu
+
+   The MIT License
+
+   Copyright (c) 2004 Scientific Computing and Imaging Institute,
+   University of Utah.
+
+   License for the specific language governing rights and limitations under
+   Permission is hereby granted, free of charge, to any person obtaining a
+   copy of this software and associated documentation files (the "Software"),
+   to deal in the Software without restriction, including without limitation
+   the rights to use, copy, modify, merge, publish, distribute, sublicense,
+   and/or sell copies of the Software, and to permit persons to whom the
+   Software is furnished to do so, subject to the following conditions:
+
+   The above copyright notice and this permission notice shall be included
+   in all copies or substantial portions of the Software.
+
+   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+   OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 
MERCHANTABILITY,
+   FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+   THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+   LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+   FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+   DEALINGS IN THE SOFTWARE.
+*/
+
+
+
+/*
+ *  Time_unix.cc: Generic unix implementation of the Time class
+ *
+ *  Written by:
+ *   Author: Steve Parker
+ *   Department of Computer Science
+ *   University of Utah
+ *   Date: June 1997
+ *
+ *  Copyright (C) 1997 SCI Group
+ */
+
+
+#include <Core/Thread/Time.h>
+#include <Core/Thread/Mutex.h>
+#include <Core/Thread/Thread.h>
+#include <Core/Thread/ThreadError.h>
+#include <fcntl.h>
+#include <signal.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <sys/mman.h>
+#include <sys/syssgi.h>
+#include <sys/time.h>
+#include <errno.h>
+
+static int timer_32bit;
+unsigned int iotimer_high;
+volatile unsigned int* iotimer_addr32;
+#if _MIPS_ISA == _MIPS_ISA_MIPS1 || _MIPS_ISA ==  _MIPS_ISA_MIPS2
+volatile unsigned int* iotimer_addr;
+#define TIMERTYPE unsigned int
+#else
+volatile unsigned long long *iotimer_addr;
+#define TIMERTYPE unsigned long long
+#endif
+static Time::SysClock orig_timer;
+static double ticks_to_seconds;
+static double seconds_to_ticks;
+static int hittimer;
+static bool initialized=false;
+static Mutex initlock("Time initialization lock");
+
+#define TOPBIT ((unsigned int)0x80000000)
+
+
+static
+void
+handle_alrm(int, int, sigcontext_t*)
+{
+    unsigned int t=*iotimer_addr32;
+    unsigned int h=iotimer_high;
+    if((t&TOPBIT) != (h&TOPBIT)){
+       if((t&TOPBIT) == 0){
+           iotimer_high=(h&(~TOPBIT))+1;
+       } else {
+           iotimer_high=h|TOPBIT;
+       }
+    }
+    if(!hittimer)
+       hittimer=1;
+}
+
+void
+Time::initialize()
+{
+    initlock.lock();
+    if(initialized){
+       initlock.unlock();
+       return;
+    }
+    int poffmask = getpagesize() - 1;
+    unsigned int cycleval;
+    __psunsigned_t phys_addr = syssgi(SGI_QUERY_CYCLECNTR, &cycleval);
+    __psunsigned_t raddr = phys_addr & ~poffmask;
+    int fd = open("/dev/mmem", O_RDONLY);
+
+    iotimer_addr = (volatile TIMERTYPE *)mmap(0, poffmask, PROT_READ,
+                                             MAP_PRIVATE, fd, (off_t)raddr);
+    iotimer_addr = (volatile TIMERTYPE *)((__psunsigned_t)iotimer_addr +
+                                        (phys_addr & poffmask));
+    iotimer_addr32 = (volatile unsigned int*)iotimer_addr;
+    ticks_to_seconds=(double)cycleval*1.e-12;
+    seconds_to_ticks=1./ticks_to_seconds;
+
+    long ccsize=syssgi(SGI_CYCLECNTR_SIZE);
+    if(ccsize == 32){
+       timer_32bit=true;
+    }
+
+    double overflow=(65536.*65536.);
+    if(!timer_32bit)
+       overflow=overflow*overflow;
+    overflow*=ticks_to_seconds;
+
+    orig_timer=0;
+
+    if(timer_32bit){
+           unsigned high=0;
+           unsigned low=*iotimer_addr32;
+           orig_timer=((long long)(high&(~TOPBIT))<<32|(long long)low);
+    } else {
+#if _MIPS_ISA == _MIPS_ISA_MIPS1 || _MIPS_ISA ==  _MIPS_ISA_MIPS2
+       for(;;) {
+           unsigned high = *iotimer_addr;
+           unsigned low = *(iotimer_addr + 1);
+           if (high == *iotimer_addr) {
+               orig_timer=((long long)high<<32|(long long)low);
+               break;
+           }
+       }
+#else
+       orig_timer=*iotimer_addr-orig_timer;
+#endif
+    }
+
+    iotimer_high=(*iotimer_addr32)&TOPBIT;
+
+    if(timer_32bit){
+       // Set up sigalrm handler...
+       struct sigaction action;
+       action.sa_flags=0;
+       sigemptyset(&action.sa_mask);
+
+       action.sa_handler=(SIG_PF)handle_alrm;
+       if(sigaction(SIGALRM, &action, NULL) == -1)
+           throw ThreadError(std::string("sigaction failed")
+                             +strerror(errno));
+
+       int ticks=overflow/8;
+       struct itimerval dt;
+       dt.it_interval.tv_sec=ticks;
+       dt.it_interval.tv_usec=0;
+       dt.it_value.tv_sec=0;
+       dt.it_value.tv_usec=1;
+       struct itimerval old;
+       if(setitimer(ITIMER_REAL, &dt, &old) != 0)
+           throw ThreadError(std::string("setitimer failed")
+                             +strerror(errno));
+       while(!hittimer)
+           sigsuspend(0);
+    }
+    initialized=true;
+    initlock.unlock();
+}
+
+Time::SysClock
+Time::currentTicks()
+{
+    if(!initialized)
+       initialize();
+    if(timer_32bit){
+       for(;;){
+           unsigned high=iotimer_high;
+           unsigned ohigh=high;
+           unsigned low=*iotimer_addr32;
+           if((low&TOPBIT) != (high&TOPBIT)){
+               // Possible rollover...
+               if(!(low&TOPBIT))
+                   high++;
+           }
+           if (ohigh == iotimer_high) {
+               return ((long long)(high&(~TOPBIT))<<32|(long 
long)low)-orig_timer;
+           }
+           fprintf(stderr, "ROLLOVER loop around...\n");
+       }
+    } else {
+#if _MIPS_ISA == _MIPS_ISA_MIPS1 || _MIPS_ISA ==  _MIPS_ISA_MIPS2
+       for(;;) {
+           unsigned high = *iotimer_addr;
+           unsigned low = *(iotimer_addr + 1);
+           if (high == *iotimer_addr) {
+               return ((long long)high<<32|(long long)low)-orig_timer;
+           }
+       }
+#else
+       return *iotimer_addr-orig_timer;
+#endif
+    }
+}
+
+double
+Time::currentSeconds()
+{
+    return Time::currentTicks()*ticks_to_seconds;
+}
+
+double
+Time::secondsPerTick()
+{
+    if(!initialized)
+       initialize();
+    return ticks_to_seconds;
+}
+
+double
+Time::ticksPerSecond()
+{
+    if(!initialized)
+       initialize();
+    return seconds_to_ticks;
+}
+
+void
+Time::waitUntil(double seconds)
+{
+    waitFor(seconds-currentSeconds());
+}
+
+void
+Time::waitFor(double seconds)
+{
+    if(!initialized)
+       initialize();
+    if(seconds<=0)
+       return;
+    static long tps=0;
+    if(tps==0)
+       tps=CLK_TCK;
+    long ticks=(long)(seconds*(double)tps);
+    int oldstate=Thread::couldBlock("Timed wait");
+    while (ticks != 0){
+       ticks=sginap(ticks);
+    }
+    Thread::couldBlockDone(oldstate);
+}
+
+void
+Time::waitUntil(SysClock time)
+{
+    waitFor(time-currentTicks());
+}
+
+void
+Time::waitFor(SysClock time)
+{
+    if(!initialized)
+       initialize();
+    if(time<=0)
+       return;
+    static double tps=0;
+    if(tps==0)
+       tps=(double)CLK_TCK*ticks_to_seconds;
+    int ticks=time*tps;
+    int oldstate=Thread::couldBlock("Timed wait");
+    while (ticks != 0){
+       ticks=(int)sginap(ticks);
+    }
+    Thread::couldBlockDone(oldstate);
+}
+

Added: trunk/Core/Thread/Time_unix.cc
==============================================================================
--- (empty file)
+++ trunk/Core/Thread/Time_unix.cc      Mon Nov 26 21:56:50 2007
@@ -0,0 +1,151 @@
+/*
+   For more information, please see: http://software.sci.utah.edu
+
+   The MIT License
+
+   Copyright (c) 2004 Scientific Computing and Imaging Institute,
+   University of Utah.
+
+   License for the specific language governing rights and limitations under
+   Permission is hereby granted, free of charge, to any person obtaining a
+   copy of this software and associated documentation files (the "Software"),
+   to deal in the Software without restriction, including without limitation
+   the rights to use, copy, modify, merge, publish, distribute, sublicense,
+   and/or sell copies of the Software, and to permit persons to whom the
+   Software is furnished to do so, subject to the following conditions:
+
+   The above copyright notice and this permission notice shall be included
+   in all copies or substantial portions of the Software.
+
+   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+   OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 
MERCHANTABILITY,
+   FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+   THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+   LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+   FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+   DEALINGS IN THE SOFTWARE.
+*/
+
+
+
+/*
+ *  Time_unix.cc: Generic unix implementation of the Time class
+ *
+ *  Written by:
+ *   Author: Steve Parker
+ *   Department of Computer Science
+ *   University of Utah
+ *   Date: June 1997
+ *
+ *  Copyright (C) 1997 SCI Group
+ */
+
+
+#include <Core/Thread/Time.h>
+#include <Core/Thread/Thread.h>
+#include <Core/Thread/ThreadError.h>
+#include <stdio.h>
+#include <sys/time.h>
+#include <errno.h>
+#ifdef __linux
+#include <time.h>
+#endif
+
+static bool initialized=false;
+static struct timeval start_time;
+using namespace Manta;
+
+void
+Time::initialize()
+{
+    initialized=true;
+    if(gettimeofday(&start_time, 0) != 0)
+       throw ThreadError(std::string("gettimeofday failed: ")
+                         +strerror(errno));
+}
+
+double
+Time::secondsPerTick()
+{
+    return 1.e-6;
+}
+
+double
+Time::currentSeconds()
+{
+    if(!initialized)
+       initialize();
+    struct timeval now_time;
+    if(gettimeofday(&now_time, 0) != 0)
+       throw ThreadError(std::string("gettimeofday failed: ")
+                         +strerror(errno));
+
+    return 
(now_time.tv_sec-start_time.tv_sec)+(now_time.tv_usec-start_time.tv_usec)*1.e-6;
+}
+
+Time::SysClock
+Time::currentTicks()
+{ 
+    if(!initialized)
+       initialize();
+    struct timeval now_time;
+    if(gettimeofday(&now_time, 0) != 0)
+       throw ThreadError(std::string("gettimeofday failed: ")
+                         +strerror(errno));
+
+    return 
(now_time.tv_sec-start_time.tv_sec)*1000000+(now_time.tv_usec-start_time.tv_usec);
+}
+
+double
+Time::ticksPerSecond()
+{
+    return 1000000;
+}
+
+void
+Time::waitUntil(double seconds)
+{
+    waitFor(seconds-currentSeconds());
+}
+
+void
+Time::waitFor(double seconds)
+{
+  if(!initialized) 
+    initialize();
+
+  if(seconds<=0)
+    return;
+
+  struct timespec ts;
+  ts.tv_sec=(int)seconds;
+  ts.tv_nsec=(int)(1.e9*(seconds-ts.tv_sec));
+
+  int oldstate=Thread::couldBlock("Timed wait");
+  nanosleep(&ts, &ts);
+  //  while (nanosleep(&ts, &ts) == 0) /* Nothing */ ;
+  Thread::couldBlockDone(oldstate);
+}
+
+void
+Time::waitUntil(SysClock time)
+{
+    waitFor(time-currentTicks());
+}
+
+void
+Time::waitFor(SysClock time)
+{
+    if(!initialized)
+       initialize();
+    if(time<=0)
+       return;
+    struct timespec ts;
+    ts.tv_sec=(int)(time*1.e-6);
+    ts.tv_nsec=(int)(1.e9*(time*1.e-6-ts.tv_sec));
+    int oldstate=Thread::couldBlock("Timed wait");
+    nanosleep(&ts, &ts);
+    //while (nanosleep(&ts, &ts) == 0) /* Nothing */ ;
+    Thread::couldBlockDone(oldstate);
+}
+

Added: trunk/Core/Thread/Time_win32.cc
==============================================================================
--- (empty file)
+++ trunk/Core/Thread/Time_win32.cc     Mon Nov 26 21:56:50 2007
@@ -0,0 +1,120 @@
+/*
+  The contents of this file are subject to the University of Utah Public
+  License (the "License"); you may not use this file except in compliance
+  with the License.
+  
+  Software distributed under the License is distributed on an "AS IS"
+  basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+  License for the specific language governing rights and limitations under
+  the License.
+  
+  The Original Source Code is SCIRun, released March 12, 2001.
+  
+  The Original Source Code was developed by the University of Utah.
+  Portions created by UNIVERSITY are Copyright (C) 2001, 1994 
+  University of Utah. All Rights Reserved.
+*/
+
+
+/*
+ *  Time_win32.cc: Generic unix implementation of the Time class
+ *
+ *  Written by:
+ *   Author: Steve Parker
+ *   Department of Computer Science
+ *   University of Utah
+ *   Date: June 1997
+ *
+ *  Copyright (C) 1997 SCI Group
+ */
+
+
+#include <Core/Thread/Time.h>
+#include <Core/Thread/Thread.h>
+#include <Core/Thread/ThreadError.h>
+#include <stdio.h>
+#include <windows.h>
+#include <Mmsystem.h> // windows time functions
+#include <errno.h>
+
+static bool initialized=false;
+static DWORD start_time; // measured in milliseconds
+
+void
+Time::initialize()
+{
+  initialized=true;
+  timeBeginPeriod(1); // give the timer millisecond accuracy
+  start_time = timeGetTime();
+}
+
+double
+Time::secondsPerTick()
+{
+  return 1.e-3;
+}
+
+double
+Time::currentSeconds()
+{
+  if(!initialized)
+    initialize();
+  DWORD now_time = timeGetTime();
+
+  return ((double)(now_time - start_time))*1.e-3; 
+}
+
+Time::SysClock
+Time::currentTicks()
+{ 
+  if(!initialized)
+    initialize();
+  DWORD now_time = timeGetTime();
+
+  return now_time - start_time;
+}
+
+double
+Time::ticksPerSecond()
+{
+    return 1000;
+}
+
+void
+Time::waitUntil(double seconds)
+{
+    waitFor(seconds-currentSeconds());
+}
+
+void
+Time::waitFor(double seconds)
+{
+  if(!initialized) 
+    initialize();
+
+  if(seconds<=0)
+    return;
+
+  int oldstate=Thread::couldBlock("Timed wait");
+  Sleep(seconds*1000); // Sleep is in milliseconds
+  Thread::couldBlockDone(oldstate);
+}
+
+void
+Time::waitUntil(SysClock time)
+{
+    waitFor(time-currentTicks());
+}
+
+void
+Time::waitFor(SysClock time)
+{
+  if(!initialized)
+    initialize();
+  if(time<=0)
+    return;
+  int oldstate=Thread::couldBlock("Timed wait");
+  Sleep(time);
+  Thread::couldBlockDone(oldstate);
+}
+

Added: trunk/Core/Thread/WorkQueue.cc
==============================================================================
--- (empty file)
+++ trunk/Core/Thread/WorkQueue.cc      Mon Nov 26 21:56:50 2007
@@ -0,0 +1,134 @@
+/*
+   For more information, please see: http://software.sci.utah.edu
+
+   The MIT License
+
+   Copyright (c) 2004 Scientific Computing and Imaging Institute,
+   University of Utah.
+
+   License for the specific language governing rights and limitations under
+   Permission is hereby granted, free of charge, to any person obtaining a
+   copy of this software and associated documentation files (the "Software"),
+   to deal in the Software without restriction, including without limitation
+   the rights to use, copy, modify, merge, publish, distribute, sublicense,
+   and/or sell copies of the Software, and to permit persons to whom the
+   Software is furnished to do so, subject to the following conditions:
+
+   The above copyright notice and this permission notice shall be included
+   in all copies or substantial portions of the Software.
+
+   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+   OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 
MERCHANTABILITY,
+   FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+   THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+   LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+   FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+   DEALINGS IN THE SOFTWARE.
+*/
+
+
+
+/*
+ *  WorkQueue: Manage assignments of work
+ *
+ *  Written by:
+ *   Author: Steve Parker
+ *   Department of Computer Science
+ *   University of Utah
+ *   Date: June 1997
+ *
+ *  Copyright (C) 1997 SCI Group
+ */
+
+
+#include <Core/Thread/WorkQueue.h>
+namespace Manta {
+
+WorkQueue::WorkQueue(const char* name)
+  : name_(name),
+    num_threads_(-1),
+    total_assignments_(-1),
+    granularity_(-1),
+    current_assignment_("WorkQueue counter")
+{
+}
+
+WorkQueue::~WorkQueue()
+{
+}
+
+bool
+WorkQueue::nextAssignment(int& start, int& end)
+{
+    int i=current_assignment_++; // Atomic ++
+    if(i >= (int)assignments_.size()-1)
+       return false;
+    start=assignments_[i];
+    end=assignments_[i+1];
+    return true;
+}
+
+void
+WorkQueue::refill(int new_ta, int new_nthreads, int new_granularity)
+{
+    if(new_ta == total_assignments_ && new_nthreads == num_threads_
+       && new_granularity == granularity_){
+       current_assignment_.set(0);
+    } else {
+       total_assignments_=new_ta;
+       num_threads_=new_nthreads;
+       granularity_=new_granularity;
+       fill();
+    }
+}
+
+void
+WorkQueue::fill()
+{
+    current_assignment_.set(0);
+
+    if(total_assignments_==0){
+       assignments_.resize(0);
+       return;
+    }
+
+    // Since we are using push_back every time we call fill (and make
+    // assignments into the array, we need to remove the existing entries,
+    // otherwise we get more assignments then we should.
+    assignments_.clear();
+    // make sure we only allocate memory once for the vector
+    assignments_.reserve(total_assignments_+1);
+    int current_assignment=0;
+    int 
current_assignmentsize=(2*total_assignments_)/(num_threads_*(granularity_+1));
+    int decrement=current_assignmentsize/granularity_;
+    if(current_assignmentsize==0)
+       current_assignmentsize=1;
+    if(decrement==0)
+       decrement=1;
+    for(int i=0;i<granularity_;i++){
+       for(int j=0;j<num_threads_;j++){
+           assignments_.push_back(current_assignment);
+           current_assignment+=current_assignmentsize;
+           if(current_assignment >= total_assignments_){
+               break;
+           }
+       }
+       if(current_assignment >= total_assignments_){
+         break;
+       }
+       current_assignmentsize-=decrement;
+       if(current_assignmentsize<1)
+           current_assignmentsize=1;
+       if(current_assignment >= total_assignments_){
+           break;
+       }
+    }
+    while(current_assignment < total_assignments_){
+       assignments_.push_back(current_assignment);
+       current_assignment+=current_assignmentsize;
+    }
+    assignments_.push_back(total_assignments_);
+}
+
+
+} // End namespace Manta

Added: trunk/Core/Thread/WorkQueue.h
==============================================================================
--- (empty file)
+++ trunk/Core/Thread/WorkQueue.h       Mon Nov 26 21:56:50 2007
@@ -0,0 +1,118 @@
+/*
+   For more information, please see: http://software.sci.utah.edu
+
+   The MIT License
+
+   Copyright (c) 2004 Scientific Computing and Imaging Institute,
+   University of Utah.
+
+   License for the specific language governing rights and limitations under
+   Permission is hereby granted, free of charge, to any person obtaining a
+   copy of this software and associated documentation files (the "Software"),
+   to deal in the Software without restriction, including without limitation
+   the rights to use, copy, modify, merge, publish, distribute, sublicense,
+   and/or sell copies of the Software, and to permit persons to whom the
+   Software is furnished to do so, subject to the following conditions:
+
+   The above copyright notice and this permission notice shall be included
+   in all copies or substantial portions of the Software.
+
+   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+   OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 
MERCHANTABILITY,
+   FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+   THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+   LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+   FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+   DEALINGS IN THE SOFTWARE.
+*/
+
+
+
+/*
+ *  WorkQueue: Manage assignments of work
+ *
+ *  Written by:
+ *   Author: Steve Parker
+ *   Department of Computer Science
+ *   University of Utah
+ *   Date: June 1997
+ *
+ *  Copyright (C) 1997 SCI Group
+ */
+
+#ifndef Core_Thread_WorkQueue_h
+#define Core_Thread_WorkQueue_h
+
+#include <Core/Thread/AtomicCounter.h>
+#include <vector>
+
+namespace Manta {
+  struct WorkQueue_private;
+       
+/**************************************

+CLASS
+   WorkQueue
+   
+KEYWORDS
+   Thread, Work
+   
+DESCRIPTION
+   Doles out work assignment to various worker threads.  Simple
+   attempts are made at evenly distributing the workload.
+   Initially, assignments are relatively large, and will get smaller
+   towards the end in an effort to equalize the total effort.
+   
+****************************************/
+       class WorkQueue {
+       public:
+           //////////
+           // Make an empty work queue with no assignments.
+           WorkQueue(const char* name);
+           
+           //////////
+           // Fill the work queue with the specified total number of work
+           // assignments.  <i>num_threads</i> specifies the approximate
+           // number of threads which will be working from this queue.
+           // The optional <i>granularity</i> specifies the degree to
+           // which the tasks are divided.  A large granularity will
+           // create more assignments with smaller assignments.  A
+           // granularity of zero will recieve a single assignment of
+           // approximately uniform size.  <i>name</i> should be a static
+           // string which describes the primitive for debugging purposes.
+           void refill(int totalAssignments, int nthreads,
+                       int granularity=5);
+           
+           //////////
+           // Destroy the work queue.  Any unassigned work will be lost.  
+           ~WorkQueue();
+           
+           //////////
+           // Called by each thread to get the next assignment.  If
+           // <i>nextAssignment</i> returns true, the thread has a valid
+           // assignment, and then would be responsible for the work 
+           // from the returned <i>start</i> through <i>end-l</i>.
+           // Assignments can range from 0 to  <i>totalAssignments</i>-1.
+           // When <i>nextAssignment</i> returns false, all work has
+           // been assigned.
+           bool nextAssignment(int& start, int& end);
+           
+       private:
+           const char* name_;
+           int num_threads_;
+           int total_assignments_;
+           int granularity_;
+           std::vector<int> assignments_;
+           AtomicCounter current_assignment_;
+           bool dynamic_;
+           
+           void fill();
+
+           // Cannot copy them
+           WorkQueue(const WorkQueue& copy);
+           WorkQueue& operator=(const WorkQueue&);
+       };
+}
+
+#endif
+

Modified: trunk/Core/Util/AlignedAllocator.h
==============================================================================
--- trunk/Core/Util/AlignedAllocator.h  (original)
+++ trunk/Core/Util/AlignedAllocator.h  Mon Nov 26 21:56:50 2007
@@ -30,8 +30,8 @@
 #define _CORE_UTIL_ALIGNCLASS__H
 
 #include <stddef.h> // for size_t definition
-#include <SCIRun/Core/Util/Assert.h>
-#include <SCIRun/Core/Exceptions/InternalError.h>
+#include <Core/Util/Assert.h>
+#include <Core/Exceptions/InternalError.h>
 
 namespace Manta {
 
@@ -61,7 +61,7 @@
       // have unaligned addresses for subsequent elements in the array.
       if (size > sizeof(ParentT))
         if (sizeof(ParentT) % Alignment != 0)
-          throw SCIRun::InternalError("Attempting to allocate an array of 
objects that cannot be aligned.  Please make sizeof(ParentT) a multiple of 
Alignment", __FILE__, __LINE__);
+          throw InternalError("Attempting to allocate an array of objects 
that cannot be aligned.  Please make sizeof(ParentT) a multiple of 
Alignment");
       return allocateAligned(size, Alignment);
     }
     void operator delete[](void * mem)

Modified: trunk/Core/Util/ApproximatePriorityQueue.h
==============================================================================
--- trunk/Core/Util/ApproximatePriorityQueue.h  (original)
+++ trunk/Core/Util/ApproximatePriorityQueue.h  Mon Nov 26 21:56:50 2007
@@ -36,7 +36,7 @@
       for (size_t i = 0; i < num_queues; i++) {
         // TODO(boulos): Number them using ostringstream? Seems pretty
         // heavyweight include...
-        mutexes.push_back(new SCIRun::Mutex("ApproximatePriorityQueue 
mutex"));
+        mutexes.push_back(new Mutex("ApproximatePriorityQueue mutex"));
       }
     }
 
@@ -203,7 +203,7 @@
     size_t max_threads;
     CheapRNG* rngs;
     QueueType* queues;
-    std::vector<SCIRun::Mutex*> mutexes;
+    std::vector<Mutex*> mutexes;
   };
 
 }; // end namespace Manta

Modified: trunk/Core/Util/Args.cc
==============================================================================
--- trunk/Core/Util/Args.cc     (original)
+++ trunk/Core/Util/Args.cc     Mon Nov 26 21:56:50 2007
@@ -5,7 +5,6 @@
 #include <Core/Color/ColorDB.h>
 
 using namespace std;
-using SCIRun::IllegalValue;
 
 namespace Manta {
   bool getStringArg(size_t& i, const vector<string>& args, string& result)
@@ -186,9 +185,7 @@
 
 static int arg_debug = 0;
 
-#include <sgi_stl_warnings_off.h>
 #include <iostream>
-#include <sgi_stl_warnings_on.h>
 using namespace std;
 
 namespace Manta { 

Modified: trunk/Core/Util/Args.h
==============================================================================
--- trunk/Core/Util/Args.h      (original)
+++ trunk/Core/Util/Args.h      Mon Nov 26 21:56:50 2007
@@ -3,11 +3,9 @@
 #define Manta_Core_Args_h
 
 #include <MantaTypes.h>
-#include <sgi_stl_warnings_off.h>
 #include <string>
 #include <vector>
 #include <sstream>
-#include <sgi_stl_warnings_on.h>
 
 namespace Manta {
   class Vector;

Added: trunk/Core/Util/Assert.h
==============================================================================
--- (empty file)
+++ trunk/Core/Util/Assert.h    Mon Nov 26 21:56:50 2007
@@ -0,0 +1,102 @@
+/*
+   For more information, please see: http://software.sci.utah.edu
+
+   The MIT License
+
+   Copyright (c) 2004 Scientific Computing and Imaging Institute,
+   University of Utah.
+
+   License for the specific language governing rights and limitations under
+   Permission is hereby granted, free of charge, to any person obtaining a
+   copy of this software and associated documentation files (the "Software"),
+   to deal in the Software without restriction, including without limitation
+   the rights to use, copy, modify, merge, publish, distribute, sublicense,
+   and/or sell copies of the Software, and to permit persons to whom the
+   Software is furnished to do so, subject to the following conditions:
+
+   The above copyright notice and this permission notice shall be included
+   in all copies or substantial portions of the Software.
+
+   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+   OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 
MERCHANTABILITY,
+   FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+   THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+   LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+   FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+   DEALINGS IN THE SOFTWARE.
+*/
+
+
+
+/*
+ *  Assert.h: Utility for specifying data invariants (Assertions)
+ *
+ *  Written by:
+ *   Steven G. Parker
+ *   Department of Computer Science
+ *   University of Utah
+ *   Feb. 1994
+ *
+ *  Copyright (C) 1994 SCI Group
+ */
+
+#ifndef Manta_Assert_h
+#define Manta_Assert_h 1
+
+#include <Core/Exceptions/AssertionFailed.h>
+#include <Core/Exceptions/ArrayIndexOutOfBounds.h>
+
+
+#if SCI_ASSERTION_LEVEL >= 1
+#  define IFASSERT(x) x
+#  define ASSERTL1(condition) \
+     if(!(condition)){ \
+        SCI_THROW(SCIRun::AssertionFailed(#condition, __FILE__, __LINE__)); \
+     }
+#else
+#  define ASSERTL1(condition)
+#endif
+
+#if SCI_ASSERTION_LEVEL >= 2
+#  define ASSERTL2(condition) \
+     if(!(condition)){ \
+        SCI_THROW(SCIRun::AssertionFailed(#condition, __FILE__, __LINE__)); \
+     }
+#else
+#  define ASSERTL2(condition)
+#endif
+
+#if SCI_ASSERTION_LEVEL >= 3
+#  define ASSERTL3(condition) \
+     if(!(condition)){ \
+        SCI_THROW(SCIRun::AssertionFailed(#condition, __FILE__, __LINE__)); \
+     }
+#  define CHECKARRAYBOUNDS(value, lower, upper) \
+     if(value < lower || value >= upper){ \
+        SCI_THROW(SCIRun::ArrayIndexOutOfBounds(value, lower, upper, 
__FILE__, __LINE__)); \
+     }
+#else
+#  define ASSERTL3(condition)
+#  define CHECKARRAYBOUNDS(value, lower, upper)
+#endif
+
+#if SCI_ASSERTION_LEVEL == 0
+#  define USE_IF_ASSERTS_ON(line)
+#  define ASSERTL1(condition)
+#  define ASSERTL2(condition)
+#  define ASSERTL3(condition)
+#  define ASSERTEQ(c1, c2)
+#  define ASSERTRANGE(c, l, h)
+#  define IFASSERT(x)
+#else
+#  define USE_IF_ASSERTS_ON(line) line
+#endif
+
+/* USE_IF_ASSERTS_ON allows us to remove lines that are necessary for
+   code that is needed if asserts are on but causes warnings if 
+   asserts are off (ie: in optimized builds).  All it does it remove
+   the line or put the line in. */
+
+#define ASSERT(condition) ASSERTL2(condition)
+
+#endif

Modified: trunk/Core/Util/CPUTime.cc
==============================================================================
--- trunk/Core/Util/CPUTime.cc  (original)
+++ trunk/Core/Util/CPUTime.cc  Mon Nov 26 21:56:50 2007
@@ -12,7 +12,7 @@
 #endif
 
 #ifdef __ia64__
-# include <SCIRun/Core/Thread/Time.h>
+# include <Core/Thread/Time.h>
 #endif
 
 using namespace Manta;
@@ -38,12 +38,12 @@
 #elif defined(_WIN32)
   secondsPerTick_val = 1.0/static_cast<double>(CLOCKS_PER_SEC);
 #elif defined(__ia64__)
-  secondsPerTick_val = SCIRun::Time::secondsPerTick();
+  secondsPerTick_val = Time::secondsPerTick();
 #else
   FILE *fp = fopen("/proc/cpuinfo","r");
   char input[255];
   if (!fp)
-    throw SCIRun::ThreadError(std::string("CPUTime::resetScale failed: 
couldn't find /proc/cpuinfo. Is this not a linux machine?"));
+    throw ThreadError(std::string("CPUTime::resetScale failed: couldn't find 
/proc/cpuinfo. Is this not a linux machine?"));
   while (!feof(fp) && fgets(input, 255, fp)) {
     if (strstr(input,"cpu MHz")) {
       char *p = strchr(input,':');
@@ -88,7 +88,7 @@
 #elif defined(__ia64__)
 CPUTime::SysClock CPUTime::currentTicks()
 {
-  return SCIRun::Time::currentTicks();
+  return Time::currentTicks();
 }
 #else
 
@@ -113,7 +113,7 @@
 #ifdef __ia64__
 double CPUTime::currentSeconds()
 {
-  return SCIRun::Time::currentSeconds();
+  return Time::currentSeconds();
 }
 #else
 double CPUTime::currentSeconds()

Added: trunk/Core/Util/FancyAssert.h
==============================================================================
--- (empty file)
+++ trunk/Core/Util/FancyAssert.h       Mon Nov 26 21:56:50 2007
@@ -0,0 +1,82 @@
+/*
+   For more information, please see: http://software.sci.utah.edu
+
+   The MIT License
+
+   Copyright (c) 2004 Scientific Computing and Imaging Institute,
+   University of Utah.
+
+   License for the specific language governing rights and limitations under
+   Permission is hereby granted, free of charge, to any person obtaining a
+   copy of this software and associated documentation files (the "Software"),
+   to deal in the Software without restriction, including without limitation
+   the rights to use, copy, modify, merge, publish, distribute, sublicense,
+   and/or sell copies of the Software, and to permit persons to whom the
+   Software is furnished to do so, subject to the following conditions:
+
+   The above copyright notice and this permission notice shall be included
+   in all copies or substantial portions of the Software.
+
+   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+   OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 
MERCHANTABILITY,
+   FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+   THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+   LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+   FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+   DEALINGS IN THE SOFTWARE.
+*/
+
+
+
+/*
+ *  Assert.h: Utility for specifying data invariants (Assertions)
+ *
+ *  Written by:
+ *   Steven G. Parker
+ *   Department of Computer Science
+ *   University of Utah
+ *   Feb. 1994
+ *
+ *  Copyright (C) 1994 SCI Group
+ */
+
+#ifndef SCI_Containers_FancyAssert_h
+#define SCI_Containers_FancyAssert_h
+
+#include <sci_defs/error_defs.h>
+
+#include <Core/Exceptions/AssertionFailed.h>
+#include <sstream>
+
+/*
+ * Note - a normal AssertionFailed exception cannot be used here.  We
+ * must use one that takes a string
+ */
+
+#if SCI_ASSERTION_LEVEL >= 2
+#define ASSERTEQ(c1, c2) \
+   if(c1 != c2){ \
+      std::ostringstream msg; \
+      msg << #c1 << "(value=" << c1 << ") == " << #c2 << "(value=" << c2 << 
")"; \
+      SCI_THROW(SCIRun::AssertionFailed(msg.str().c_str(), __FILE__, 
__LINE__)); \
+   }
+
+#define ASSERTNE(c1, c2) \
+   if(c1 != c2){ \
+      std::ostringstream msg; \
+      msg << #c1 << "(value=" << c1 << ") != " << #c2 << "(value=" << c2 << 
")"; \
+      SCI_THROW(SCIRun::AssertionFailed(msg.str().c_str(), __FILE__, 
__LINE__)); \
+   }
+
+#define ASSERTRANGE(c, l, h) \
+   if(c < l || c >= h){ \
+      std::ostringstream msg; \
+      msg << #l "(value=" << l << ") <= " #c << "(value=" << c << ") < " << 
#h << "(value=" << h << ")"; \
+      SCI_THROW(SCIRun::AssertionFailed(msg.str().c_str(), __FILE__, 
__LINE__)); \
+   }
+#else
+#define ASSERTEQ(c1, c2)
+#define ASSERTRANGE(c, l, h)
+#endif
+
+#endif

Modified: trunk/Core/Util/MemoryPool.h
==============================================================================
--- trunk/Core/Util/MemoryPool.h        (original)
+++ trunk/Core/Util/MemoryPool.h        Mon Nov 26 21:56:50 2007
@@ -63,7 +63,7 @@
 
         StorageType* result = &(block.data[block.size]);
         if (result == 0) {
-          throw SCIRun::InternalError("Apparently we're holding a NULL 
pointer in our free list.", __FILE__, __LINE__);
+          throw InternalError("Apparently we're holding a NULL pointer in 
our free list.");
         }
         block.size++;
         size++;
@@ -72,8 +72,7 @@
 
       // NOTE(boulos): This shouldn't happen, but not having it will
       // generate compiler warnings.
-      throw SCIRun::InternalError("Unable to allocate a new item",
-                                  __FILE__, __LINE__);
+      throw InternalError("Unable to allocate a new item");
       return 0;
     }
 

Added: trunk/Core/Util/NotFinished.h
==============================================================================
--- (empty file)
+++ trunk/Core/Util/NotFinished.h       Mon Nov 26 21:56:50 2007
@@ -0,0 +1,51 @@
+/*
+   For more information, please see: http://software.sci.utah.edu
+
+   The MIT License
+
+   Copyright (c) 2004 Scientific Computing and Imaging Institute,
+   University of Utah.
+
+   License for the specific language governing rights and limitations under
+   Permission is hereby granted, free of charge, to any person obtaining a
+   copy of this software and associated documentation files (the "Software"),
+   to deal in the Software without restriction, including without limitation
+   the rights to use, copy, modify, merge, publish, distribute, sublicense,
+   and/or sell copies of the Software, and to permit persons to whom the
+   Software is furnished to do so, subject to the following conditions:
+
+   The above copyright notice and this permission notice shall be included
+   in all copies or substantial portions of the Software.
+
+   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+   OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 
MERCHANTABILITY,
+   FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+   THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+   LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+   FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+   DEALINGS IN THE SOFTWARE.
+*/
+
+
+
+/*
+ *  NotFinished.h:  Consistent way to keep track of holes in the code...
+ *
+ *  Written by:
+ *   Steven G. Parker
+ *   Department of Computer Science
+ *   University of Utah
+ *   March 1994
+ *
+ *  Copyright (C) 1994 SCI Group
+ */
+
+#ifndef Manta_NotFinished_h
+#define Manta_NotFinished_h
+
+#include <iostream>
+
+#define NOT_FINISHED(what) std::cerr << "Not finished: " << what << " (" << 
__FILE__ << ", line " << __LINE__ << ") " << std::endl
+
+#endif /* SCI_project_NotFinished_h */
+

Modified: trunk/Core/Util/Stat.h
==============================================================================
--- trunk/Core/Util/Stat.h      (original)
+++ trunk/Core/Util/Stat.h      Mon Nov 26 21:56:50 2007
@@ -2,12 +2,10 @@
 #define Manta_Core_Stat_h
 
 #include <UseStatsCollector.h>
-#include <SCIRun/Core/Thread/Mutex.h>
+#include <Core/Thread/Mutex.h>
 
 #include <float.h>
 #include <math.h>
-
-using namespace SCIRun;
 
 namespace Manta
 {

Modified: trunk/Core/Util/ThreadStorage.cc
==============================================================================
--- trunk/Core/Util/ThreadStorage.cc    (original)
+++ trunk/Core/Util/ThreadStorage.cc    Mon Nov 26 21:56:50 2007
@@ -27,7 +27,6 @@
 */
 
 #include <Core/Util/ThreadStorage.h>
-
 #include <Interface/Context.h>
 
 using namespace Manta;
@@ -73,6 +72,6 @@
   storage[proc] = (char *)malloc(requested);
 
   if (storage[proc] == 0)
-    throw InternalError( "Could not allocate thread local memory", __FILE__, 
__LINE__ );
+    throw InternalError( "Could not allocate thread local memory");
 }
 

Modified: trunk/Core/Util/ThreadStorage.h
==============================================================================
--- trunk/Core/Util/ThreadStorage.h     (original)
+++ trunk/Core/Util/ThreadStorage.h     Mon Nov 26 21:56:50 2007
@@ -31,14 +31,11 @@
 
 // Abe Stephens
 
-#include <SCIRun/Core/Exceptions/InternalError.h>
-#include <SCIRun/Core/Util/Assert.h>
-
+#include <Core/Exceptions/InternalError.h>
+#include <Core/Util/Assert.h>
 #include <vector>
 
 namespace Manta {
-
-  using SCIRun::InternalError;
   using std::vector;
 
   class RenderContext;
@@ -90,7 +87,7 @@
       // Attempt to allocate the specified number of bytes.
       void *check_fit( size_t bytes ) const {
         if (bytes > token.size)
-          throw InternalError( "Requested number of bytes greater than 
allocated.", __FILE__, __LINE__ );
+          throw InternalError( "Requested number of bytes greater than 
allocated.");
 
         return storage.get( proc, token );
       }

Added: trunk/Core/Util/Timer.cc
==============================================================================
--- (empty file)
+++ trunk/Core/Util/Timer.cc    Mon Nov 26 21:56:50 2007
@@ -0,0 +1,272 @@
+/*
+   For more information, please see: http://software.sci.utah.edu
+
+   The MIT License
+
+   Copyright (c) 2004 Scientific Computing and Imaging Institute,
+   University of Utah.
+
+   License for the specific language governing rights and limitations under
+   Permission is hereby granted, free of charge, to any person obtaining a
+   copy of this software and associated documentation files (the "Software"),
+   to deal in the Software without restriction, including without limitation
+   the rights to use, copy, modify, merge, publish, distribute, sublicense,
+   and/or sell copies of the Software, and to permit persons to whom the
+   Software is furnished to do so, subject to the following conditions:
+
+   The above copyright notice and this permission notice shall be included
+   in all copies or substantial portions of the Software.
+
+   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+   OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 
MERCHANTABILITY,
+   FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+   THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+   LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+   FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+   DEALINGS IN THE SOFTWARE.
+*/
+
+
+
+/*
+ *  Timer.h: Implementation of portable timer utility classes
+ *
+ *  Written by:
+ *   Steven G. Parker
+ *   Department of Computer Science
+ *   University of Utah
+ *   Feb. 1994
+ *
+ *  Copyright (C) 1994 SCI Group
+ */
+
+
+#include <Core/Util/Timer.h>
+#include <Core/Util/NotFinished.h>
+#include <Core/Thread/Thread.h>
+#include <Core/Math/MiscMath.h>
+#include <sys/types.h>
+#ifndef _WIN32
+#include <sys/times.h>
+#include <sys/time.h>
+#include <sys/resource.h>
+#include <unistd.h>
+#else
+#include <windows.h>
+#endif
+#include <limits.h>
+#include <iostream>
+using std::cerr;
+using std::endl;
+
+using namespace Manta;
+
+
+#include <time.h>
+#ifdef _WIN32
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#ifndef _CLOCK_T_DEFINED
+#define _CLOCK_T_DEFINED
+typedef long clock_t;
+#endif
+
+struct tms
+{
+    clock_t tms_utime;
+    clock_t tms_stime;
+    clock_t tms_cutime;
+    clock_t tms_cstime;
+};
+
+#ifdef __cplusplus
+}
+#endif
+#include <sys/timeb.h>
+#endif
+
+#if defined(CLK_TCK)
+extern "C" long _sysconf(int);
+#define CLOCK_INTERVAL CLK_TCK
+#elif defined(CLOCKS_PER_SEC)
+#define CLOCK_INTERVAL CLOCKS_PER_SEC
+#else
+#include <sys/param.h>
+#define CLOCK_INTERVAL HZ
+#endif
+
+#ifdef _WIN32
+clock_t times(struct tms* buffer)
+{
+       timeb curtime;
+       ftime(&curtime);
+
+       long ticks = (curtime.time*1000)+curtime.millitm;
+
+       buffer->tms_utime = buffer->tms_cutime = ticks;
+       buffer->tms_stime = buffer->tms_cstime = 0;
+
+       return ticks;
+
+       //cerr << "times() called" << endl;
+}
+#endif
+
+static double ci=0;
+
+Timer::Timer()
+{
+    state=Stopped;
+    total_time=0;
+}
+
+Timer::~Timer()
+{
+#if SCI_ASSERTION_LEVEL >=1  
+    if(state != Stopped){
+       cerr << "Warning: Timer destroyed while it was running" << endl;
+    }
+#endif
+}
+
+void Timer::start()
+{
+    if(state == Stopped){
+       start_time=get_time();
+       state=Running;
+    } else {
+       cerr << "Warning: Timer started while it was already running" << endl;
+    }
+}
+
+void Timer::stop()
+{
+    if(state == Stopped){
+       cerr << "Warning: Timer stopped while it was already stopped" << endl;
+    } else {
+       state=Stopped;
+       double t=get_time();
+       total_time+=t-start_time;
+    }
+}
+
+void Timer::add(double t) {
+    start_time -= t;
+}
+
+void Timer::clear()
+{
+    if(state == Stopped){
+       total_time=0;
+    } else {
+       cerr << "Warning: Timer cleared while it was running" << endl;
+       total_time=0;
+       start_time=get_time();
+    }
+}
+
+double Timer::time()
+{
+    if(state == Running){
+       double t=get_time();
+       return t-start_time+total_time;
+    } else {
+       return total_time;
+    }
+}
+
+
+double CPUTimer::get_time()
+{
+#if 0
+    struct rusage cpu_usage;
+    getrusage(RUSAGE_SELF, &cpu_usage);
+    double cpu_time=
+        double(cpu_usage.ru_utime.tv_sec)
+       +double(cpu_usage.ru_stime.tv_sec)
+       +double(cpu_usage.ru_utime.tv_sec)/1000000.
+       +double(cpu_usage.ru_stime.tv_sec)/1000000.;
+#endif
+    struct tms buffer;
+    times(&buffer);
+    double cpu_time=
+       double(buffer.tms_utime+buffer.tms_stime)/double(CLOCK_INTERVAL);
+    return cpu_time;
+}
+
+WallClockTimer::WallClockTimer()
+{
+#ifdef __sgiasdf
+  if(!checked_cycle_counter){
+    
+
+    if(have_cycle_counter){
+    } else {
+#endif
+      if(ci==0)
+       ci=1./double(CLOCK_INTERVAL);
+#ifdef __sgiasdf
+    }
+#endif
+}
+
+double WallClockTimer::get_time()
+{
+#if 0
+    struct timeval tp;
+    if(gettimeofday(&tp) != 0){
+       cerr << "Time request failed!\n";
+    }
+    double time=double(tp.tv_sec)+double(tp.tv_usec)/1000000.;
+#endif
+    struct tms buffer;
+    double time=double(times(&buffer))*ci;
+    return time;
+}
+
+WallClockTimer::~WallClockTimer()
+{
+}
+
+CPUTimer::~CPUTimer()
+{
+}
+
+TimeThrottle::TimeThrottle()
+{
+}
+
+TimeThrottle::~TimeThrottle()
+{
+}
+
+void TimeThrottle::wait_for_time(double endtime)
+{
+    if(endtime==0)
+       return;
+    double time_now=time();
+    double delta=endtime-time_now;
+    if(delta <=0)
+       return;
+#ifdef __sgi
+    int nticks=delta*CLOCK_INTERVAL;
+    if(nticks<1)return;
+    if(delta > 10){
+       cerr << "WARNING: delta=" << delta << endl;
+    }
+    sginap(nticks);
+#else
+#ifdef _WIN32
+    Sleep(delta*1e3); // windows Sleep is in ms
+#else
+    timespec delay, remaining;
+    remaining.tv_sec = Floor(delta);
+    remaining.tv_nsec = Floor((delta-Floor(delta))*1000000000);
+    do {
+      delay = remaining;
+    } while (nanosleep(&delay,&remaining) != 0);
+#endif
+#endif
+}

Added: trunk/Core/Util/Timer.h
==============================================================================
--- (empty file)
+++ trunk/Core/Util/Timer.h     Mon Nov 26 21:56:50 2007
@@ -0,0 +1,92 @@
+/*
+   For more information, please see: http://software.sci.utah.edu
+
+   The MIT License
+
+   Copyright (c) 2004 Scientific Computing and Imaging Institute,
+   University of Utah.
+
+   License for the specific language governing rights and limitations under
+   Permission is hereby granted, free of charge, to any person obtaining a
+   copy of this software and associated documentation files (the "Software"),
+   to deal in the Software without restriction, including without limitation
+   the rights to use, copy, modify, merge, publish, distribute, sublicense,
+   and/or sell copies of the Software, and to permit persons to whom the
+   Software is furnished to do so, subject to the following conditions:
+
+   The above copyright notice and this permission notice shall be included
+   in all copies or substantial portions of the Software.
+
+   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+   OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 
MERCHANTABILITY,
+   FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+   THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+   LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+   FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+   DEALINGS IN THE SOFTWARE.
+*/
+
+
+
+/*
+ *  Timer.h: Interface to portable timer utility classes
+ *
+ *  Written by:
+ *   Steven G. Parker
+ *   Department of Computer Science
+ *   University of Utah
+ *   Feb. 1994
+ *
+ *  Copyright (C) 1994 SCI Group
+ */
+
+#ifndef Manta_Timer_h
+#define Manta_Timer_h
+
+namespace Manta {
+class Timer {
+public:
+  enum timer_state_e {
+    Stopped,
+    Running
+  };
+
+  Timer();
+  virtual ~Timer();
+  void start();
+  void stop();
+  void clear();
+  double time();
+  void add(double t);
+  timer_state_e current_state() { return state; }
+private:
+  double total_time;
+  double start_time;
+  timer_state_e state;
+  virtual double get_time()=0;
+
+};
+
+class CPUTimer : public Timer {
+    virtual double get_time();
+public:
+    virtual ~CPUTimer();
+};
+
+class WallClockTimer : public Timer {
+    virtual double get_time();
+public:
+    WallClockTimer();
+    virtual ~WallClockTimer();
+};
+
+class TimeThrottle : public WallClockTimer {
+public:
+    TimeThrottle();
+    virtual ~TimeThrottle();
+    void wait_for_time(double time);
+};
+
+}
+
+#endif

Modified: trunk/Core/Util/UpdateGraph.h
==============================================================================
--- trunk/Core/Util/UpdateGraph.h       (original)
+++ trunk/Core/Util/UpdateGraph.h       Mon Nov 26 21:56:50 2007
@@ -36,7 +36,7 @@
     UpdateGraphNode* parent;
     std::vector<UpdateGraphNode*> children;
     bool needs_update;
-    SCIRun::AtomicCounter counter;
+    AtomicCounter counter;
     int active_edges; // NOTE(boulos): We could also increment the
     // atomic counter and decrement it back to 0
     // to determine child completion
@@ -57,8 +57,7 @@
     Node* getNode(KeyType key) {
       node_map_iterator it = node_map.find(key);
       if (it == node_map.end()) {
-        throw SCIRun::InternalError("Asked to mark an object not in the node 
map",
-                                    __FILE__, __LINE__);
+        throw InternalError("Asked to mark an object not in the node map");
       }
 
       return it->second;
@@ -148,7 +147,7 @@
     std::map<KeyType, Node*> node_map;
     std::set<Node*> leaf_nodes;
     Node* root_node;
-    SCIRun::Mutex graph_mutex;
+    Mutex graph_mutex;
   };
 
 } // end namespace Manta

Modified: trunk/Core/XUtils/XHelper.cc
==============================================================================
--- trunk/Core/XUtils/XHelper.cc        (original)
+++ trunk/Core/XUtils/XHelper.cc        Mon Nov 26 21:56:50 2007
@@ -4,14 +4,11 @@
 #include <GL/glx.h>
 
 #include <string.h>
-#include <sgi_stl_warnings_off.h>
 #include <iostream>
-#include <sgi_stl_warnings_on.h>
 
 using namespace Manta;
 using namespace std;
-
-SCIRun::Mutex XHelper::Xlock("XHelper::Xlock");
+Mutex XHelper::Xlock("XHelper::Xlock");
 
 XFontStruct* XHelper::getX11Font(Display* dpy,
                                  const char* fontstring) {

Modified: trunk/Core/XUtils/XHelper.h
==============================================================================
--- trunk/Core/XUtils/XHelper.h (original)
+++ trunk/Core/XUtils/XHelper.h Mon Nov 26 21:56:50 2007
@@ -12,7 +12,7 @@
 #include <GL/gl.h>
 #include <X11/Xlib.h>
 
-#include <SCIRun/Core/Thread/Mutex.h>
+#include <Core/Thread/Mutex.h>
 
 #ifndef Manta_Engine_XHelper_h
 #define Manta_Engine_XHelper_h
@@ -32,7 +32,7 @@
 
     // Use this to make sure that only one X program is opening
     // windows at a time.
-    static SCIRun::Mutex Xlock;
+    static Mutex Xlock;
     
     // If there was an error NULL is returned.
     static XFontStruct* getX11Font(Display* dpy,

Modified: trunk/DynLT/CMakeLists.txt
==============================================================================
--- trunk/DynLT/CMakeLists.txt  (original)
+++ trunk/DynLT/CMakeLists.txt  Mon Nov 26 21:56:50 2007
@@ -28,5 +28,4 @@
 
 TARGET_LINK_LIBRARIES(Manta_DynLT Manta_Engine 
                                   Manta_Model                                
  
-                                  SCIRun_Core
                                   )

Modified: trunk/DynLT/DynLTContext.cc
==============================================================================
--- trunk/DynLT/DynLTContext.cc (original)
+++ trunk/DynLT/DynLTContext.cc Mon Nov 26 21:56:50 2007
@@ -1,10 +1,9 @@
 
 #include <DynLT/DynLTContext.h>
-#include <SCIRun/Core/Math/Expon.h>
-#include <SCIRun/Core/Math/MiscMath.h>
+#include <Core/Math/Expon.h>
+#include <Core/Math/MiscMath.h>
 
 using namespace Manta;
-using namespace SCIRun;
 
 DynLTContext::DynLTContext(MantaInterface* manta_interface,
                            DynLTQueue* queue,

Modified: trunk/DynLT/DynLTGridSpheres.cc
==============================================================================
--- trunk/DynLT/DynLTGridSpheres.cc     (original)
+++ trunk/DynLT/DynLTGridSpheres.cc     Mon Nov 26 21:56:50 2007
@@ -13,7 +13,6 @@
 using std::cerr;
 
 using namespace Manta;
-using namespace SCIRun;
 
 #define UPDATE_TIME 2.5
 

Modified: trunk/DynLT/DynLTGridSpheres.h
==============================================================================
--- trunk/DynLT/DynLTGridSpheres.h      (original)
+++ trunk/DynLT/DynLTGridSpheres.h      Mon Nov 26 21:56:50 2007
@@ -5,8 +5,8 @@
 #include <UseStatsCollector.h>
 #include <DynLT/DynLTStatsCollector.h>
 #include <Model/Primitives/GridSpheres.h>
-#include <SCIRun/Core/Thread/Mailbox.h>
-#include <SCIRun/Core/Thread/Time.h>
+#include <Core/Thread/Mailbox.h>
+#include <Core/Thread/Time.h>
 
 // XXX:  temporary
 #include <iostream>
@@ -15,8 +15,6 @@
 using std::vector;
 
 #include <float.h>
-
-using namespace SCIRun;
 
 #define XRES 16
 #define YRES 16

Modified: trunk/DynLT/DynLTQueue.h
==============================================================================
--- trunk/DynLT/DynLTQueue.h    (original)
+++ trunk/DynLT/DynLTQueue.h    Mon Nov 26 21:56:50 2007
@@ -3,11 +3,9 @@
 #define Manta_DynLT_DynLTQueue_h
 
 #include <MantaTypes.h>
-#include <SCIRun/Core/Thread/Mailbox.h>
-#include <SCIRun/Core/Thread/ConditionVariable.h>
-#include <SCIRun/Core/Thread/Mutex.h>
-
-using namespace SCIRun;
+#include <Core/Thread/Mailbox.h>
+#include <Core/Thread/ConditionVariable.h>
+#include <Core/Thread/Mutex.h>
 
 // #define FIXED_SIZE_QUEUE
 
@@ -54,7 +52,7 @@
   public:
     DynLTFifoQ(int size)
     {
-      mailbox=new SCIRun::Mailbox<DynLTMessage>("DynLT Work Queue", size);
+      mailbox=new Mailbox<DynLTMessage>("DynLT Work Queue", size);
     }
 
     ~DynLTFifoQ(void)
@@ -83,7 +81,7 @@
     }
 
   private:
-    SCIRun::Mailbox<DynLTMessage>* mailbox;
+    Mailbox<DynLTMessage>* mailbox;
   };
 
   class DynLTLifoQ : public DynLTQueue

Modified: trunk/DynLT/DynLTWorker.cc
==============================================================================
--- trunk/DynLT/DynLTWorker.cc  (original)
+++ trunk/DynLT/DynLTWorker.cc  Mon Nov 26 21:56:50 2007
@@ -10,13 +10,12 @@
 #include <Interface/Scene.h>
 #include <Engine/Shadows/HardShadows.h>
 #include <Model/Primitives/Sphere.h>
-#include <SCIRun/Core/Thread/Time.h>
+#include <Core/Thread/Time.h>
 #include <cassert>
 
 #include <string>
 
 using namespace Manta;
-using namespace SCIRun;
 using namespace std;
 
 #define RAND() rng.nextFloat()  //Carson 07/12/07

Modified: trunk/DynLT/DynLTWorker.h
==============================================================================
--- trunk/DynLT/DynLTWorker.h   (original)
+++ trunk/DynLT/DynLTWorker.h   Mon Nov 26 21:56:50 2007
@@ -6,15 +6,13 @@
 #include <Core/Math/vector2d.h>
 #include <Core/Util/Stat.h>
 #include <Interface/MantaInterface.h>
-#include <SCIRun/Core/Containers/Array1.h>
-#include <SCIRun/Core/Containers/Array2.h>
-#include <SCIRun/Core/Thread/Mailbox.h>
-#include <SCIRun/Core/Thread/Runnable.h>
-#include <SCIRun/Core/Thread/Semaphore.h>
+#include <Core/Containers/Array1.h>
+#include <Core/Containers/Array2.h>
+#include <Core/Thread/Mailbox.h>
+#include <Core/Thread/Runnable.h>
+#include <Core/Thread/Semaphore.h>
 
 #include <float.h>
-
-using namespace SCIRun;
 
 namespace Manta
 {

Modified: trunk/Engine/CMakeLists.txt
==============================================================================
--- trunk/Engine/CMakeLists.txt (original)
+++ trunk/Engine/CMakeLists.txt Mon Nov 26 21:56:50 2007
@@ -29,7 +29,6 @@
                                    Manta_Interface
                                    Manta_Core_XUtils
                                    Manta_Core
-                                   SCIRun_Core
                                    )
 
 TARGET_LINK_LIBRARIES(Manta_Engine ${OPENGL_LIBRARIES}

Modified: trunk/Engine/Control/RTRT.cc
==============================================================================
--- trunk/Engine/Control/RTRT.cc        (original)
+++ trunk/Engine/Control/RTRT.cc        Mon Nov 26 21:56:50 2007
@@ -65,10 +65,8 @@
 #include <Core/Util/UpdateGraph.h>
 #include <MantaSSE.h>
 
-#include <sgi_stl_warnings_off.h>
 #include <sstream>
 #include <iostream>
-#include <sgi_stl_warnings_on.h>
 
 
 #include <Interface/Material.h>
@@ -87,11 +85,6 @@
 
 using namespace Manta;
 using namespace std;
-using SCIRun::IllegalValue;
-using SCIRun::InvalidState;
-using SCIRun::InternalError;
-using SCIRun::Thread;
-using SCIRun::Time;
 
 #define RENDER_THREAD_STACKSIZE 8*1024*1024
 
@@ -408,7 +401,7 @@
   NOT_FINISHED("RTRT::setTimeMode");
 }
 
-#define MANTA_CHECK_POINTER(ptr) if (ptr == 0) throw SCIRun::InvalidState( 
#ptr, __FILE__, __LINE__ );
+#define MANTA_CHECK_POINTER(ptr) if (ptr == 0) throw InvalidState( #ptr );
 
 
///////////////////////////////////////////////////////////////////////////////
 
///////////////////////////////////////////////////////////////////////////////
@@ -416,12 +409,11 @@
 
///////////////////////////////////////////////////////////////////////////////
 
///////////////////////////////////////////////////////////////////////////////
 
-void RTRT::beginRendering(bool blockUntilFinished) throw (SCIRun::Exception 
&)
+void RTRT::beginRendering(bool blockUntilFinished) throw (Exception &)
 {
   runningLock.lock();
   if(running)
-    throw InvalidState("renderLoop started while it is already running",
-                       __FILE__, __LINE__);
+    throw InvalidState("renderLoop started while it is already running");
   running=true;
   runningLock.unlock();
 
@@ -597,7 +589,7 @@
 
   // Check to see if an image creator has been specified.
   if(create_image==0)
-    throw InvalidState("Image type was not selected", __FILE__, __LINE__ );
+    throw InvalidState("Image type was not selected" );
 
 #if NOTFINISHED
   check for existence of other components;
@@ -1168,8 +1160,7 @@
 
     // Check to for errors.
     if(!iteration)
-      throw InternalError("Pipeline/resolution negotiation failed",
-                          __FILE__, __LINE__);
+      throw InternalError("Pipeline/resolution negotiation failed");
     context.getResolution(channel->stereo, channel->xres, channel->yres);
 
     if(channel->xres <= 0)
@@ -1177,7 +1168,7 @@
     if(channel->yres <= 0)
       throw IllegalValue<int>("Resolution should be positive", 
channel->yres);
     if(context.getMinDepth() > context.getMaxDepth())
-      throw InternalError("Pipeline depth negotiation failed", __FILE__, 
__LINE__ );
+      throw InternalError("Pipeline depth negotiation failed");
 
     int depth = context.getMinDepth();
     if(depth == 1 && context.getMaxDepth() > 1)
@@ -1399,7 +1390,7 @@
 #include <Interface/RayPacket.h>
 
 //
-SCIRun::Barrier* RTRT::getPreprocessBarrier()
+Barrier* RTRT::getPreprocessBarrier()
 {
   return &preprocess_barrier;
 }

Modified: trunk/Engine/Control/RTRT.h
==============================================================================
--- trunk/Engine/Control/RTRT.h (original)
+++ trunk/Engine/Control/RTRT.h Mon Nov 26 21:56:50 2007
@@ -145,7 +145,7 @@
     virtual TValue<int>& numWorkers();
 
     // Control
-    virtual void beginRendering(bool blockUntilFinished) throw 
(SCIRun::Exception &);
+    virtual void beginRendering(bool blockUntilFinished) throw (Exception &);
     virtual void blockUntilFinished();
     virtual void finish();
 
@@ -182,7 +182,7 @@
     virtual void unregisterCallback(CallbackHandle*);
 
     //
-    virtual SCIRun::Barrier* getPreprocessBarrier();
+    virtual Barrier* getPreprocessBarrier();
 
     
///////////////////////////////////////////////////////////////////////////
     
///////////////////////////////////////////////////////////////////////////
@@ -235,7 +235,7 @@
     // Worker class for the RTRT Pipeline.
     
///////////////////////////////////////////////////////////////////////////
     
///////////////////////////////////////////////////////////////////////////
-    class Worker : public SCIRun::Runnable {
+    class Worker : public Runnable {
     public:
       Worker(RTRT* rtrt, int workerIndex, bool lateComerFlag);
       virtual ~Worker();
@@ -288,19 +288,19 @@
     int workersRendering;
     int workersAnimAndImage;
     bool workersChanged;
-    vector<SCIRun::Thread*> workers;
+    vector<Thread*> workers;
 
     // Running flag.
-    SCIRun::Mutex runningLock;
+    Mutex runningLock;
     bool running;
 
     // Pipeline Synchronization barriers.
-    SCIRun::CrowdMonitor callbackLock;
-    SCIRun::Barrier barrier1;
-    SCIRun::Barrier barrier2;
-    SCIRun::Barrier barrier3;
-    SCIRun::Barrier workers_changed_barrier;
-    SCIRun::Barrier preprocess_barrier;
+    CrowdMonitor callbackLock;
+    Barrier barrier1;
+    Barrier barrier2;
+    Barrier barrier3;
+    Barrier workers_changed_barrier;
+    Barrier preprocess_barrier;
     struct ReductionData {
       bool changed;
       char pad[MAXCACHELINESIZE-sizeof(bool)];
@@ -338,7 +338,7 @@
     typedef list<TransactionBase*> TransactionListType;
 
     TransactionListType transactions;
-    SCIRun::Mutex transaction_lock;
+    Mutex transaction_lock;
 
     // Transaction helper.
     void postTransactions(bool& changed);
@@ -366,7 +366,7 @@
 
     Scene* scene;
 
-    SCIRun::Mutex channel_create_lock;
+    Mutex channel_create_lock;
 
     ObjectUpdateGraph* update_graph;
     TaskQueue* update_work_queue;

Modified: trunk/Engine/Display/FileDisplay.cc
==============================================================================
--- trunk/Engine/Display/FileDisplay.cc (original)
+++ trunk/Engine/Display/FileDisplay.cc Mon Nov 26 21:56:50 2007
@@ -37,7 +37,7 @@
 #include <Image/TGAFile.h>
 #include <Image/NRRDFile.h>
 #include <Interface/Context.h>
-#include <SCIRun/Core/Thread/Time.h>
+#include <Core/Thread/Time.h>
 #include <iostream>
 #include <fstream>
 #include <sstream>
@@ -45,9 +45,7 @@
 
 using namespace Manta;
 using namespace std;
-using SCIRun::IllegalValue;
-using SCIRun::InternalError;
-using SCIRun::Time;
+
 ImageDisplay *FileDisplay::create(
   const vector< string > &args )
 {

Modified: trunk/Engine/Display/FileDisplay.h
==============================================================================
--- trunk/Engine/Display/FileDisplay.h  (original)
+++ trunk/Engine/Display/FileDisplay.h  Mon Nov 26 21:56:50 2007
@@ -31,10 +31,8 @@
 */
 
 #include <Interface/ImageDisplay.h>
-#include <sgi_stl_warnings_off.h>
 #include <string>
 #include <vector>
-#include <sgi_stl_warnings_on.h>
 
 // Abe Stephens
 

Modified: trunk/Engine/Display/GLXImageDisplay.cc
==============================================================================
--- trunk/Engine/Display/GLXImageDisplay.cc     (original)
+++ trunk/Engine/Display/GLXImageDisplay.cc     Mon Nov 26 21:56:50 2007
@@ -2,7 +2,7 @@
 #include <GL/glu.h>
 #include <X11/Xutil.h>
 
-#include <SCIRun/Core/Exceptions/Exception.h>
+#include <Core/Exceptions/Exception.h>
 #include <Core/Exceptions/InternalError.h>
 #include <Engine/Display/GLXImageDisplay.h>
 #include <Image/SimpleImage.h>
@@ -15,7 +15,6 @@
 #include <vector>
 
 using namespace Manta;
-using namespace SCIRun;
 using std::vector;
 
 // Note that the GLXImage display must be passed a GLX context by the

Modified: trunk/Engine/Display/NullDisplay.h
==============================================================================
--- trunk/Engine/Display/NullDisplay.h  (original)
+++ trunk/Engine/Display/NullDisplay.h  Mon Nov 26 21:56:50 2007
@@ -3,10 +3,8 @@
 #define Manta_Engine_NullDisplay_h
 
 #include <Interface/ImageDisplay.h>
-#include <sgi_stl_warnings_off.h>
 #include <string>
 #include <vector>
-#include <sgi_stl_warnings_on.h>
 
 namespace Manta {
   using namespace std;

Modified: trunk/Engine/Display/OpenGLDisplay.cc
==============================================================================
--- trunk/Engine/Display/OpenGLDisplay.cc       (original)
+++ trunk/Engine/Display/OpenGLDisplay.cc       Mon Nov 26 21:56:50 2007
@@ -16,15 +16,10 @@
 #include <GL/gl.h>
 #include <GL/glu.h>
 #include <X11/Xutil.h>
-
-#include <sgi_stl_warnings_off.h>
 #include <typeinfo>
-#include <sgi_stl_warnings_on.h>
 
 using namespace Manta;
 using namespace std;
-using SCIRun::IllegalValue;
-using SCIRun::InternalError;
 
 ImageDisplay* OpenGLDisplay::create(const vector<string>& args)
 {
@@ -139,14 +134,14 @@
   dpy = XOpenDisplay(NULL);
   if(!dpy) {
     XHelper::Xlock.unlock();
-    throw InternalError("Error opening display", __FILE__, __LINE__);
+    throw InternalError("Error opening display");
   }
   int error, event;
   if ( !glXQueryExtension( dpy, &error, &event) ) {
     XCloseDisplay(dpy);
     dpy=0;
     XHelper::Xlock.unlock();
-    throw InternalError("GL extension NOT available!\n", __FILE__, __LINE__);
+    throw InternalError("GL extension NOT available!");
   }
   int screen=DefaultScreen(dpy);
     
@@ -178,7 +173,7 @@
     if(!vi){
       // Cannot find anything suitable
       XHelper::Xlock.unlock();
-      throw InternalError("Error selecting OpenGL visual", __FILE__, 
__LINE__);
+      throw InternalError("Error selecting OpenGL visual");
     }
   }
 
@@ -238,7 +233,7 @@
 
   if(!glXMakeCurrent(dpy, win, cx)) {
     XHelper::Xlock.unlock();
-    throw InternalError("glXMakeCurrent failed!\n", __FILE__, __LINE__);
+    throw InternalError("glXMakeCurrent failed!");
   }
 
   ogl->clearScreen(.05, .1, .2, 0);
@@ -249,19 +244,19 @@
   fontInfo = XHelper::getX11Font(dpy);
   if (!fontInfo) {
     XHelper::Xlock.unlock();
-    throw InternalError("getX11Font failed!\n", __FILE__, __LINE__);
+    throw InternalError("getX11Font failed!");
   }
   fontbase = XHelper::getGLFont(fontInfo);
   if (fontbase == 0) {
     XHelper::Xlock.unlock();
-    throw InternalError("getGLFont failed!\n", __FILE__, __LINE__);
+    throw InternalError("getGLFont failed!");
   }
 
   ogl->init();
   
   if(!glXMakeCurrent(dpy, None, NULL)) {
     XHelper::Xlock.unlock();
-    throw InternalError("glXMakeCurrent failed!\n", __FILE__, __LINE__);
+    throw InternalError("glXMakeCurrent failed!");
   }
 
   XHelper::Xlock.unlock();
@@ -282,11 +277,11 @@
     return;
 
   // Compute the framerate
-  double currentTime = SCIRun::Time::currentSeconds();
+  double currentTime = Time::currentSeconds();
 
   if(!madeCurrent){
     if(!glXMakeCurrent(dpy, win, cx))
-      throw InternalError("glXMakeCurrent failed!\n", __FILE__, __LINE__);
+      throw InternalError("glXMakeCurrent failed!");
     madeCurrent=true;
   }
 

Modified: trunk/Engine/Display/OpenGLDisplay.h
==============================================================================
--- trunk/Engine/Display/OpenGLDisplay.h        (original)
+++ trunk/Engine/Display/OpenGLDisplay.h        Mon Nov 26 21:56:50 2007
@@ -3,15 +3,12 @@
 #define Manta_Engine_OpenGLDisplay_h
 
 #include <Interface/ImageDisplay.h>
-#include <SCIRun/Core/Util/Assert.h>
+#include <Core/Util/Assert.h>
 #include <X11/Xlib.h>
 #include <GL/glx.h>
-
-#include <sgi_stl_warnings_off.h>
 #include <string>
 #include <iostream>
 #include <vector>
-#include <sgi_stl_warnings_on.h>
 
 namespace Manta {
   using namespace std;

Modified: trunk/Engine/Display/PureOpenGLDisplay.cc
==============================================================================
--- trunk/Engine/Display/PureOpenGLDisplay.cc   (original)
+++ trunk/Engine/Display/PureOpenGLDisplay.cc   Mon Nov 26 21:56:50 2007
@@ -41,10 +41,8 @@
 #include <GL/glu.h>
 #include <GL/glext.h>
 
-#include <sgi_stl_warnings_off.h>
 #include <iostream>
 #include <typeinfo>
-#include <sgi_stl_warnings_on.h>
 
 #ifdef __APPLE__
 // For some reason, apple has these extensions but doesn't have the proper
@@ -195,7 +193,6 @@
 
 
 using namespace Manta;
-using namespace SCIRun;
 using namespace std;
 
 PureOpenGLDisplay::PBO::PBO()
@@ -347,8 +344,7 @@
     // Drawn by pixels...
     if (verbose) cerr << "image mode drew it\n";
   } else {
-      throw InternalError("Unknown image type in OpenGLDisplay",
-                          __FILE__, __LINE__);
+    throw InternalError("Unknown image type in OpenGLDisplay");
   }
   gl_print_error(__FILE__,__LINE__);
 }

Modified: trunk/Engine/Display/PureOpenGLDisplay.h
==============================================================================
--- trunk/Engine/Display/PureOpenGLDisplay.h    (original)
+++ trunk/Engine/Display/PureOpenGLDisplay.h    Mon Nov 26 21:56:50 2007
@@ -45,9 +45,7 @@
 #  endif
 // #endif
 
-#include <sgi_stl_warnings_off.h>
 #include <string>
-#include <sgi_stl_warnings_on.h>
 
 /*
   This will only make pure OpenGL calls and should not be dependent on

Modified: trunk/Engine/Display/SyncDisplay.cc
==============================================================================
--- trunk/Engine/Display/SyncDisplay.cc (original)
+++ trunk/Engine/Display/SyncDisplay.cc Mon Nov 26 21:56:50 2007
@@ -30,16 +30,12 @@
 #include <Interface/ImageDisplay.h>
 #include <Interface/Context.h>
 #include <Core/Thread/Semaphore.h>
-
-#include <sgi_stl_warnings_off.h>
 #include <iostream>
-#include <sgi_stl_warnings_on.h>
-
 #include <Core/Thread/Mutex.h>
-SCIRun::Mutex sync_lock("SyncDisplay io lock");
 
 using namespace Manta;
 using namespace std;
+Mutex sync_lock("SyncDisplay io lock");
 
 SyncDisplay::SyncDisplay(const vector<string>& args)
   : child_display(NULL),

Modified: trunk/Engine/Display/SyncDisplay.h
==============================================================================
--- trunk/Engine/Display/SyncDisplay.h  (original)
+++ trunk/Engine/Display/SyncDisplay.h  Mon Nov 26 21:56:50 2007
@@ -32,10 +32,8 @@
 #include <Interface/ImageDisplay.h>
 #include <Core/Thread/Semaphore.h>
 
-#include <sgi_stl_warnings_off.h>
 #include <string>
 #include <vector>
-#include <sgi_stl_warnings_on.h>
 
 /*
   The code that wants to render should have something that looks like this:
@@ -92,8 +90,8 @@
     DisplayContext const* current_context;
     Image const* current_image;
 
-    SCIRun::Semaphore _frameready;
-    SCIRun::Semaphore _framedone;
+    Semaphore _frameready;
+    Semaphore _framedone;
   };
 }
 

Modified: trunk/Engine/Factory/CMakeLists.txt
==============================================================================
--- trunk/Engine/Factory/CMakeLists.txt (original)
+++ trunk/Engine/Factory/CMakeLists.txt Mon Nov 26 21:56:50 2007
@@ -17,5 +17,4 @@
   Manta_Model
   Manta_Image
   Manta_Interface
-  Manta_Core
-  SCIRun_Core)
+  Manta_Core)

Modified: trunk/Engine/Factory/Factory.cc
==============================================================================
--- trunk/Engine/Factory/Factory.cc     (original)
+++ trunk/Engine/Factory/Factory.cc     Mon Nov 26 21:56:50 2007
@@ -50,7 +50,6 @@
 
 
 using namespace Manta;
-using namespace SCIRun;
 
 Factory::~Factory()
 {
@@ -439,8 +438,6 @@
 
 Scene* Factory::readArchiveScene(const string& name, const vector<string>& 
args) const
 {
-  using SCIRun::split_string;
-
   // Determine which directories to search for the scene library.
   string fullname = name;
   vector<string> dirs = split_string(scenePath, ':');
@@ -465,15 +462,13 @@
   Scene* scene = 0;
   root->readwrite("scene", scene);
   if(!scene)
-    throw InternalError("Error reading file: " + fullname, __FILE__, 
__LINE__);
+    throw InternalError("Error reading file: " + fullname);
   return scene;
 }  
 
 Scene* Factory::readMOScene(const string& name, const vector<string>& args,
                             bool printErrors) const
 {
-  using SCIRun::split_string;
-
   // Determine which directories to search for the scene library.
   string fullname = name;
   vector<string> dirs = split_string(scenePath, ':');

Modified: trunk/Engine/IdleModes/ZoomIdleMode.cc
==============================================================================
--- trunk/Engine/IdleModes/ZoomIdleMode.cc      (original)
+++ trunk/Engine/IdleModes/ZoomIdleMode.cc      Mon Nov 26 21:56:50 2007
@@ -5,7 +5,6 @@
 #include <Core/Math/MinMax.h>
 
 using namespace Manta;
-using SCIRun::Max;
 
 IdleMode* ZoomIdleMode::create(const vector<string>& args)
 {

Modified: trunk/Engine/IdleModes/ZoomIdleMode.h
==============================================================================
--- trunk/Engine/IdleModes/ZoomIdleMode.h       (original)
+++ trunk/Engine/IdleModes/ZoomIdleMode.h       Mon Nov 26 21:56:50 2007
@@ -4,10 +4,8 @@
 
 #include <MantaTypes.h>
 #include <Interface/IdleMode.h>
-#include <sgi_stl_warnings_off.h>
 #include <string>
 #include <vector>
-#include <sgi_stl_warnings_on.h>
 
 namespace Manta {
   using namespace std;

Modified: trunk/Engine/ImageTraversers/DeadlineImageTraverser.cc
==============================================================================
--- trunk/Engine/ImageTraversers/DeadlineImageTraverser.cc      (original)
+++ trunk/Engine/ImageTraversers/DeadlineImageTraverser.cc      Mon Nov 26 
21:56:50 2007
@@ -452,7 +452,7 @@
 #endif
         break;
       default:
-        throw SCIRun::InternalError("Expected either 4, 16, 64, 256, or 1024 
spp", __FILE__, __LINE__);
+        throw InternalError("Expected either 4, 16, 64, 256, or 1024 spp");
         break;
       }
 
@@ -464,8 +464,7 @@
         // Handle multiple packets per pixel.
         //cerr << "Multiple packets per pixel (spp = " << samples_per_pixel 
<< ", newxmag = " << newxmag << ")\n";
         if (xs != ys) {
-          throw SCIRun::InternalError("Don't handle non-square refinement 
yet",
-                                      __FILE__, __LINE__);
+          throw InternalError("Don't handle non-square refinement yet");
         }
 
         Fragment frag(Fragment::SquareShape, Fragment::ConstantEye);

Modified: trunk/Engine/ImageTraversers/DeadlineImageTraverser.h
==============================================================================
--- trunk/Engine/ImageTraversers/DeadlineImageTraverser.h       (original)
+++ trunk/Engine/ImageTraversers/DeadlineImageTraverser.h       Mon Nov 26 
21:56:50 2007
@@ -37,10 +37,8 @@
 #include <Core/Util/ApproximatePriorityQueue.h>
 #include <Core/Util/MemoryPool.h>
 
-#include <sgi_stl_warnings_off.h>
 #include <string>
 #include <vector>
-#include <sgi_stl_warnings_on.h>
 #include <MantaSSE.h>
 
 namespace Manta {
@@ -95,7 +93,7 @@
       float ymag;
       int padding; // unfortunately we can't make these 128 bytes wide
     };
-    SCIRun::Mutex qlock;
+    Mutex qlock;
     ApproximatePriorityQueue<Tile*, float> queue;
     static const int kMaxThreads = 32;
     MemoryPool<Tile> tile_pools[kMaxThreads];

Modified: trunk/Engine/ImageTraversers/DissolveImageTraverser.cc
==============================================================================
--- trunk/Engine/ImageTraversers/DissolveImageTraverser.cc      (original)
+++ trunk/Engine/ImageTraversers/DissolveImageTraverser.cc      Mon Nov 26 
21:56:50 2007
@@ -13,7 +13,6 @@
 #include <Core/Util/NotFinished.h>
 
 using namespace Manta;
-using SCIRun::InternalError;
 
 // Use this mask to produce values from 1 to N (in the comments)
 static unsigned int MaskValues[] = {
@@ -104,7 +103,7 @@
   unsigned int num_y_bits = numBinaryDigits(yres-1);
   unsigned int num_all_bits = num_x_bits + num_y_bits;
   if (num_all_bits > 32)
-    throw InternalError("DissolveImageTraverser::setupDisplayChannel::number 
of bits needed for random number exceeds 32", __FILE__, __LINE__);
+    throw InternalError("DissolveImageTraverser::setupDisplayChannel::number 
of bits needed for random number exceeds 32");
 
   ChannelContext& cdata = channel_data[context.channelIndex];
   cdata.mask = MaskValues[num_all_bits];

Modified: trunk/Engine/ImageTraversers/DissolveImageTraverser.h
==============================================================================
--- trunk/Engine/ImageTraversers/DissolveImageTraverser.h       (original)
+++ trunk/Engine/ImageTraversers/DissolveImageTraverser.h       Mon Nov 26 
21:56:50 2007
@@ -25,10 +25,8 @@
 #define Manta_Engine_DissolveImageTraverser_h
 
 #include <Interface/ImageTraverser.h>
-#include <sgi_stl_warnings_off.h>
 #include <string>
 #include <vector>
-#include <sgi_stl_warnings_on.h>
 
 namespace Manta {
   using namespace std;

Modified: trunk/Engine/ImageTraversers/DissolveTiledImageTraverser.cc
==============================================================================
--- trunk/Engine/ImageTraversers/DissolveTiledImageTraverser.cc (original)
+++ trunk/Engine/ImageTraversers/DissolveTiledImageTraverser.cc Mon Nov 26 
21:56:50 2007
@@ -14,7 +14,6 @@
 #include <Core/Util/NotFinished.h>
 
 using namespace Manta;
-using SCIRun::InternalError;
 
 // Use this mask to produce values from 1 to N (in the comments)
 static unsigned int MaskValues[] = {
@@ -126,7 +125,7 @@
     // Figure out the mask
     int num_bits = numBinaryDigits(cdata.numTiles);
     if (num_bits > 32)
-      throw 
InternalError("DissolveTiledImageTraverser::setupDisplayChannel::number of 
bits needed for random number exceeds 32", __FILE__, __LINE__);
+      throw 
InternalError("DissolveTiledImageTraverser::setupDisplayChannel::number of 
bits needed for random number exceeds 32");
     cdata.rng_mask = MaskValues[num_bits];
   }
 

Modified: trunk/Engine/ImageTraversers/DissolveTiledImageTraverser.h
==============================================================================
--- trunk/Engine/ImageTraversers/DissolveTiledImageTraverser.h  (original)
+++ trunk/Engine/ImageTraversers/DissolveTiledImageTraverser.h  Mon Nov 26 
21:56:50 2007
@@ -22,10 +22,8 @@
 #define Manta_Engine_DissolveTiledImageTraverser_h
 
 #include <Interface/ImageTraverser.h>
-#include <sgi_stl_warnings_off.h>
 #include <string>
 #include <vector>
-#include <sgi_stl_warnings_on.h>
 
 namespace Manta {
   using namespace std;

Modified: trunk/Engine/ImageTraversers/FilteredImageTraverser.cc
==============================================================================
--- trunk/Engine/ImageTraversers/FilteredImageTraverser.cc      (original)
+++ trunk/Engine/ImageTraversers/FilteredImageTraverser.cc      Mon Nov 26 
21:56:50 2007
@@ -37,9 +37,7 @@
 #include <Interface/LoadBalancer.h>
 #include <Interface/PixelSampler.h>
 #include <Core/Thread/Mutex.h>
-#include <Core/Util/NotFinished.h>
-
-#include <SCIRun/Core/Util/Assert.h>
+#include <Core/Util/Assert.h>
 
 using namespace Manta;
 

Modified: trunk/Engine/ImageTraversers/NullImageTraverser.h
==============================================================================
--- trunk/Engine/ImageTraversers/NullImageTraverser.h   (original)
+++ trunk/Engine/ImageTraversers/NullImageTraverser.h   Mon Nov 26 21:56:50 
2007
@@ -3,10 +3,8 @@
 #define Manta_Engine_NullImageTraverser_h
 
 #include <Interface/ImageTraverser.h>
-#include <sgi_stl_warnings_off.h>
 #include <string>
 #include <vector>
-#include <sgi_stl_warnings_on.h>
 
 namespace Manta {
   using namespace std;

Modified: trunk/Engine/ImageTraversers/TiledImageTraverser.cc
==============================================================================
--- trunk/Engine/ImageTraversers/TiledImageTraverser.cc (original)
+++ trunk/Engine/ImageTraversers/TiledImageTraverser.cc Mon Nov 26 21:56:50 
2007
@@ -72,7 +72,7 @@
         throw IllegalArgument("TiledImageTraverser -tilesize", i, args);
     } else if (arg == "-square") {
 /*
-        int sqrt_size = static_cast<int>(SCIRun::Sqrt(RayPacket::MaxSize));
+        int sqrt_size = static_cast<int>(Sqrt(RayPacket::MaxSize));
         if (sqrt_size * sqrt_size != RayPacket::MaxSize)
             throw IllegalArgument("TiledImageTraverser -square 
(RayPacket::MaxSize is not square",
                                   i, args);
@@ -157,7 +157,7 @@
       {
           Fragment frag(Fragment::LineShape, 
Fragment::ConsecutiveX|Fragment::ConstantEye);
 
-          int fsize = SCIRun::Min(Fragment::MaxSize, xend-xstart);
+          int fsize = Min(Fragment::MaxSize, xend-xstart);
           for(int eye = 0; eye < numEyes; eye++){
 #ifdef MANTA_SSE
               // This finds the upper bound of the groups of 4.  Even if you
@@ -248,7 +248,7 @@
           Fragment frag(Fragment::SquareShape, Fragment::ConstantEye);
 
           // Square Shaped fragments of about RayPacket::MaxSize each
-          static const int sqrt_size = 
static_cast<int>(SCIRun::Sqrt(RayPacket::MaxSize));
+          static const int sqrt_size = 
static_cast<int>(Sqrt(RayPacket::MaxSize));
           static const int full_size = sqrt_size * sqrt_size;
 
           for(int eye = 0; eye < numEyes; eye++){
@@ -259,8 +259,8 @@
               for (int y = ystart; y < yend; y += sqrt_size) {
                   for (int x = xstart; x < xend; x += sqrt_size) {
 
-                      int j_end = SCIRun::Min(yend - y, sqrt_size);
-                      int i_end = SCIRun::Min(xend - x, sqrt_size);
+                      int j_end = Min(yend - y, sqrt_size);
+                      int i_end = Min(xend - x, sqrt_size);
 
                       for (int j = 0; j < j_end; ++j) {
                           for (int i = 0; i < i_end; ++i) {

Modified: trunk/Engine/ImageTraversers/TiledImageTraverser.h
==============================================================================
--- trunk/Engine/ImageTraversers/TiledImageTraverser.h  (original)
+++ trunk/Engine/ImageTraversers/TiledImageTraverser.h  Mon Nov 26 21:56:50 
2007
@@ -32,10 +32,8 @@
 
 #include <Interface/ImageTraverser.h>
 #include <Interface/Fragment.h>
-#include <sgi_stl_warnings_off.h>
 #include <string>
 #include <vector>
-#include <sgi_stl_warnings_on.h>
 #include <MantaSSE.h>
 
 namespace Manta {

Modified: trunk/Engine/LoadBalancers/CyclicLoadBalancer.h
==============================================================================
--- trunk/Engine/LoadBalancers/CyclicLoadBalancer.h     (original)
+++ trunk/Engine/LoadBalancers/CyclicLoadBalancer.h     Mon Nov 26 21:56:50 
2007
@@ -5,10 +5,8 @@
 #include <Interface/LoadBalancer.h>
 #include <Interface/Parameters.h>
 #include <Core/Thread/WorkQueue.h>
-#include <sgi_stl_warnings_off.h>
 #include <string>
 #include <vector>
-#include <sgi_stl_warnings_on.h>
 
 namespace Manta {
 

Modified: trunk/Engine/LoadBalancers/SimpleLoadBalancer.h
==============================================================================
--- trunk/Engine/LoadBalancers/SimpleLoadBalancer.h     (original)
+++ trunk/Engine/LoadBalancers/SimpleLoadBalancer.h     Mon Nov 26 21:56:50 
2007
@@ -5,10 +5,8 @@
 #include <Interface/LoadBalancer.h>
 #include <Interface/Parameters.h>
 #include <Core/Thread/WorkQueue.h>
-#include <sgi_stl_warnings_off.h>
 #include <string>
 #include <vector>
-#include <sgi_stl_warnings_on.h>
 
 namespace Manta {
 

Modified: trunk/Engine/LoadBalancers/WQLoadBalancer.h
==============================================================================
--- trunk/Engine/LoadBalancers/WQLoadBalancer.h (original)
+++ trunk/Engine/LoadBalancers/WQLoadBalancer.h Mon Nov 26 21:56:50 2007
@@ -4,10 +4,8 @@
 
 #include <Interface/LoadBalancer.h>
 #include <Core/Thread/WorkQueue.h>
-#include <sgi_stl_warnings_off.h>
 #include <string>
 #include <vector>
-#include <sgi_stl_warnings_on.h>
 
 namespace Manta {
 
@@ -32,7 +30,7 @@
     struct ChannelInfo {
       ChannelInfo();
       ~ChannelInfo();
-      SCIRun::WorkQueue workq;
+      WorkQueue workq;
       int numAssignments;
     };
     vector<ChannelInfo*> channelInfo;

Modified: trunk/Engine/PixelSamplers/FastSampler.h
==============================================================================
--- trunk/Engine/PixelSamplers/FastSampler.h    (original)
+++ trunk/Engine/PixelSamplers/FastSampler.h    Mon Nov 26 21:56:50 2007
@@ -4,10 +4,8 @@
 
 #include <MantaTypes.h>
 #include <Interface/PixelSampler.h>
-#include <sgi_stl_warnings_off.h>
 #include <string>
 #include <vector>
-#include <sgi_stl_warnings_on.h>
 
 namespace Manta {
   using namespace std;

Modified: trunk/Engine/PixelSamplers/JitterSampler.cc
==============================================================================
--- trunk/Engine/PixelSamplers/JitterSampler.cc (original)
+++ trunk/Engine/PixelSamplers/JitterSampler.cc Mon Nov 26 21:56:50 2007
@@ -12,9 +12,7 @@
 
 using namespace Manta;
 
-#include <sgi_stl_warnings_off.h>
 #include <iostream>
-#include <sgi_stl_warnings_on.h>
 using namespace std;
 
 PixelSampler* JitterSampler::create(const vector<string>& args)
@@ -44,7 +42,7 @@
   }
 
   // Compute nx and ny
-  SCIRun::findFactorsNearRoot(num_samples, nx, ny);
+  findFactorsNearRoot(num_samples, nx, ny);
 }
 
 JitterSampler::~JitterSampler()

Modified: trunk/Engine/PixelSamplers/JitterSampler.h
==============================================================================
--- trunk/Engine/PixelSamplers/JitterSampler.h  (original)
+++ trunk/Engine/PixelSamplers/JitterSampler.h  Mon Nov 26 21:56:50 2007
@@ -6,10 +6,8 @@
 #include <Core/Math/MT_RNG.h>
 #include <Core/Geometry/vecdefs.h>
 
-#include <sgi_stl_warnings_off.h>
 #include <string>
 #include <vector>
-#include <sgi_stl_warnings_on.h>
 
 
 namespace Manta {

Modified: trunk/Engine/PixelSamplers/NullSampler.h
==============================================================================
--- trunk/Engine/PixelSamplers/NullSampler.h    (original)
+++ trunk/Engine/PixelSamplers/NullSampler.h    Mon Nov 26 21:56:50 2007
@@ -3,10 +3,8 @@
 #define Manta_Engine_NullSampler_h
 
 #include <Interface/PixelSampler.h>
-#include <sgi_stl_warnings_off.h>
 #include <string>
 #include <vector>
-#include <sgi_stl_warnings_on.h>
 
 namespace Manta {
   using namespace std;

Modified: trunk/Engine/PixelSamplers/SingleSampler.h
==============================================================================
--- trunk/Engine/PixelSamplers/SingleSampler.h  (original)
+++ trunk/Engine/PixelSamplers/SingleSampler.h  Mon Nov 26 21:56:50 2007
@@ -4,10 +4,8 @@
 
 #include <MantaTypes.h>
 #include <Interface/PixelSampler.h>
-#include <sgi_stl_warnings_off.h>
 #include <string>
 #include <vector>
-#include <sgi_stl_warnings_on.h>
 
 namespace Manta {
   using namespace std;

Modified: trunk/Engine/PixelSamplers/TimeViewSampler.cc
==============================================================================
--- trunk/Engine/PixelSamplers/TimeViewSampler.cc       (original)
+++ trunk/Engine/PixelSamplers/TimeViewSampler.cc       Mon Nov 26 21:56:50 
2007
@@ -11,7 +11,7 @@
 
 #define USE_SCIRUN_TIME 0
 #if USE_SCIRUN_TIME
-#  include <SCIRun/Core/Thread/Time.h>
+#  include <Core/Thread/Time.h>
 #else
 #  include <Core/Util/CPUTime.h>
 #endif
@@ -77,7 +77,7 @@
   double startTime = 0;
   if (active) {
 #if USE_SCIRUN_TIME
-    startTime = SCIRun::Time::currentSeconds();
+    startTime = Time::currentSeconds();
 #else
     startTime = CPUTime::currentSeconds();
 #endif
@@ -85,7 +85,7 @@
   if (child) child->renderFragment(context, fragment);
   if (active) {
 #if USE_SCIRUN_TIME
-    double endTime = SCIRun::Time::currentSeconds();
+    double endTime = Time::currentSeconds();
 #else
     double endTime = CPUTime::currentSeconds();
 #endif

Modified: trunk/Engine/PixelSamplers/TimeViewSampler.h
==============================================================================
--- trunk/Engine/PixelSamplers/TimeViewSampler.h        (original)
+++ trunk/Engine/PixelSamplers/TimeViewSampler.h        Mon Nov 26 21:56:50 
2007
@@ -5,10 +5,8 @@
 #include <Interface/PixelSampler.h>
 #include <Model/Textures/HeightColorMap.h>
 
-#include <sgi_stl_warnings_off.h>
 #include <string>
 #include <vector>
-#include <sgi_stl_warnings_on.h>
 
 namespace Manta {
 

Modified: trunk/Engine/Renderers/KajiyaPathtracer.cc
==============================================================================
--- trunk/Engine/Renderers/KajiyaPathtracer.cc  (original)
+++ trunk/Engine/Renderers/KajiyaPathtracer.cc  Mon Nov 26 21:56:50 2007
@@ -18,7 +18,6 @@
 using namespace std;
 
 using namespace Manta;
-using SCIRun::Abs;
 
 Renderer* KajiyaPathtracer::create(const vector<string>& args)
 {

Modified: trunk/Engine/Renderers/KajiyaPathtracer.h
==============================================================================
--- trunk/Engine/Renderers/KajiyaPathtracer.h   (original)
+++ trunk/Engine/Renderers/KajiyaPathtracer.h   Mon Nov 26 21:56:50 2007
@@ -4,10 +4,8 @@
 
 #include <Interface/Renderer.h>
 #include <Interface/Packet.h>
-#include <sgi_stl_warnings_off.h>
 #include <string>
 #include <vector>
-#include <sgi_stl_warnings_on.h>
 
 namespace Manta {
   using namespace std;

Modified: trunk/Engine/Renderers/Moire.h
==============================================================================
--- trunk/Engine/Renderers/Moire.h      (original)
+++ trunk/Engine/Renderers/Moire.h      Mon Nov 26 21:56:50 2007
@@ -3,10 +3,8 @@
 #define Manta_Engine_Moire_h
 
 #include <Interface/Renderer.h>
-#include <sgi_stl_warnings_off.h>
 #include <string>
 #include <vector>
-#include <sgi_stl_warnings_on.h>
 
 namespace Manta {
   using namespace std;

Modified: trunk/Engine/Renderers/Noise.h
==============================================================================
--- trunk/Engine/Renderers/Noise.h      (original)
+++ trunk/Engine/Renderers/Noise.h      Mon Nov 26 21:56:50 2007
@@ -3,10 +3,8 @@
 #define Manta_Engine_Noise_h
 
 #include <Interface/Renderer.h>
-#include <sgi_stl_warnings_off.h>
 #include <string>
 #include <vector>
-#include <sgi_stl_warnings_on.h>
 
 namespace Manta {
   using namespace std;

Modified: trunk/Engine/Renderers/NullRenderer.h
==============================================================================
--- trunk/Engine/Renderers/NullRenderer.h       (original)
+++ trunk/Engine/Renderers/NullRenderer.h       Mon Nov 26 21:56:50 2007
@@ -4,10 +4,8 @@
 
 #include <Interface/Renderer.h>
 #include <Core/Color/Color.h>
-#include <sgi_stl_warnings_off.h>
 #include <string>
 #include <vector>
-#include <sgi_stl_warnings_on.h>
 
 namespace Manta {
   using namespace std;

Modified: trunk/Engine/Renderers/RayGen.h
==============================================================================
--- trunk/Engine/Renderers/RayGen.h     (original)
+++ trunk/Engine/Renderers/RayGen.h     Mon Nov 26 21:56:50 2007
@@ -4,10 +4,8 @@
 
 #include <Interface/Renderer.h>
 #include <Core/Color/Color.h>
-#include <sgi_stl_warnings_off.h>
 #include <string>
 #include <vector>
-#include <sgi_stl_warnings_on.h>
 
 namespace Manta {
   using namespace std;

Modified: trunk/Engine/Renderers/Raydumper.cc
==============================================================================
--- trunk/Engine/Renderers/Raydumper.cc (original)
+++ trunk/Engine/Renderers/Raydumper.cc Mon Nov 26 21:56:50 2007
@@ -13,7 +13,6 @@
 #include <cfloat>
 
 using namespace Manta;
-using namespace SCIRun;
 
 // TODO:  Allow multi-threaded rendering
 //        Construct actual ray trees

Modified: trunk/Engine/Renderers/Raytracer.h
==============================================================================
--- trunk/Engine/Renderers/Raytracer.h  (original)
+++ trunk/Engine/Renderers/Raytracer.h  Mon Nov 26 21:56:50 2007
@@ -3,10 +3,8 @@
 #define Manta_Engine_Raytracer_h
 
 #include <Interface/Renderer.h>
-#include <sgi_stl_warnings_off.h>
 #include <string>
 #include <vector>
-#include <sgi_stl_warnings_on.h>
 
 namespace Manta {
   using namespace std;

Modified: trunk/Engine/SampleGenerators/Stratified2D.cc
==============================================================================
--- trunk/Engine/SampleGenerators/Stratified2D.cc       (original)
+++ trunk/Engine/SampleGenerators/Stratified2D.cc       Mon Nov 26 21:56:50 
2007
@@ -5,12 +5,11 @@
 #include <Interface/RenderParameters.h>
 #include <Interface/RandomNumberGenerator.h>
 #include <Interface/RayPacket.h>
-#include <SCIRun/Core/Math/Expon.h>
-#include <SCIRun/Core/Exceptions/InternalError.h>
+#include <Core/Math/Expon.h>
+#include <Core/Exceptions/InternalError.h>
 
 #include <iostream>
 using namespace Manta;
-using SCIRun::Sqrt;
 
 Stratified2D::Stratified2D(unsigned int spp) :
   spp(spp), thread_samples(0), max_depth(0), num_threads(0),
@@ -18,8 +17,7 @@
   xres(0), yres(0) {
   sqrt_spp = static_cast<unsigned int>(Sqrt(static_cast<double>(spp)));
   if (sqrt_spp * sqrt_spp != spp) {
-    throw SCIRun::InternalError("Stratified2D expects spp to be a perfect 
square",
-                                __FILE__, __LINE__);
+    throw InternalError("Stratified2D expects spp to be a perfect square");
   }
   inv_spp = 1.f/static_cast<float>(spp);
   inv_sqrt_spp = 1.f/static_cast<float>(sqrt_spp);
@@ -171,8 +169,7 @@
   bool stereo;
   int width, height;
   context.getResolution(stereo, width, height);
-  if (stereo) throw SCIRun::InternalError("Stratified2D doesn't handle 
stereo yet",
-                                          __FILE__, __LINE__);
+  if (stereo) throw InternalError("Stratified2D doesn't handle stereo yet");
   xres = width;
   yres = height;
 }

Modified: trunk/Engine/Shadows/HardShadows.cc
==============================================================================
--- trunk/Engine/Shadows/HardShadows.cc (original)
+++ trunk/Engine/Shadows/HardShadows.cc Mon Nov 26 21:56:50 2007
@@ -52,7 +52,7 @@
   int debugFlag = sourceRays.getAllFlags() & RayPacket::DebugPacket;
   if (debugFlag) {
     cerr << "HardShadows::computeShadows called\n";
-    //    cerr << SCIRun::getStackTrace();
+    //    cerr << getStackTrace();
   }
 
   int nlights = lights->numLights();

Modified: trunk/Engine/Shadows/HardShadows.h
==============================================================================
--- trunk/Engine/Shadows/HardShadows.h  (original)
+++ trunk/Engine/Shadows/HardShadows.h  Mon Nov 26 21:56:50 2007
@@ -3,10 +3,8 @@
 #define Manta_Engine_HardShadows_h
 
 #include <Interface/ShadowAlgorithm.h>
-#include <sgi_stl_warnings_off.h>
 #include <vector>
 #include <string>
-#include <sgi_stl_warnings_on.h>
 
 namespace Manta {
   using namespace std;

Modified: trunk/Engine/Shadows/NoDirect.h
==============================================================================
--- trunk/Engine/Shadows/NoDirect.h     (original)
+++ trunk/Engine/Shadows/NoDirect.h     Mon Nov 26 21:56:50 2007
@@ -3,10 +3,8 @@
 #define Manta_Engine_NoDirect_h
 
 #include <Interface/ShadowAlgorithm.h>
-#include <sgi_stl_warnings_off.h>
 #include <vector>
 #include <string>
-#include <sgi_stl_warnings_on.h>
 
 namespace Manta {
   using namespace std;

Modified: trunk/Engine/Shadows/NoShadows.h
==============================================================================
--- trunk/Engine/Shadows/NoShadows.h    (original)
+++ trunk/Engine/Shadows/NoShadows.h    Mon Nov 26 21:56:50 2007
@@ -3,10 +3,8 @@
 #define Manta_Engine_NoShadows_h
 
 #include <Interface/ShadowAlgorithm.h>
-#include <sgi_stl_warnings_off.h>
 #include <vector>
 #include <string>
-#include <sgi_stl_warnings_on.h>
 
 namespace Manta {
   using namespace std;

Modified: trunk/Image/CMakeLists.txt
==============================================================================
--- trunk/Image/CMakeLists.txt  (original)
+++ trunk/Image/CMakeLists.txt  Mon Nov 26 21:56:50 2007
@@ -67,7 +67,6 @@
 TARGET_LINK_LIBRARIES(Manta_Image
                       Manta_Interface 
                       Manta_Core
-                      SCIRun_Core 
                       )
 
 # Link against optional libraries

Modified: trunk/Image/ImageMagickFile-stub.cc
==============================================================================
--- trunk/Image/ImageMagickFile-stub.cc (original)
+++ trunk/Image/ImageMagickFile-stub.cc Mon Nov 26 21:56:50 2007
@@ -37,7 +37,6 @@
 #include <Core/Exceptions/OutputError.h>
 
 using namespace Manta;
-using namespace SCIRun;
 
 extern "C" void writeImageMagick( Image const *image, std::string const 
&file_name, int which ) {
   throw OutputError( "ImageMagick writing not supported by this build.  
Perhaps you need to add the path to the ImageMagick++ libraries.");

Modified: trunk/Image/ImageMagickFile.cc
==============================================================================
--- trunk/Image/ImageMagickFile.cc      (original)
+++ trunk/Image/ImageMagickFile.cc      Mon Nov 26 21:56:50 2007
@@ -32,7 +32,7 @@
 #include <Image/Pixel.h>
 #include <Image/SimpleImage.h>
 
-#include <Core/Exceptions/UnknownPixel.h>
+#include <Core/Exceptions/UnknownPixelFormat.h>
 #include <Core/Exceptions/InputError.h>
 #include <Core/Exceptions/OutputError.h>
 
@@ -41,7 +41,6 @@
 #include <iostream>
 
 using namespace Manta;
-using namespace SCIRun;
 
 using MagickLib::Quantum;
 using MagickLib::MagickRealType;

Modified: trunk/Image/NRRDFile-stub.cc
==============================================================================
--- trunk/Image/NRRDFile-stub.cc        (original)
+++ trunk/Image/NRRDFile-stub.cc        Mon Nov 26 21:56:50 2007
@@ -38,7 +38,6 @@
 #include <Core/Exceptions/OutputError.h>
 
 using namespace Manta;
-using namespace SCIRun;
 
 extern "C" void writeNRRD( Image const *image, std::string const &file_name, 
int which ) {
   throw OutputError( "Nrrd writing not supported by this build.  Perhaps you 
need to add the path to the Teem libraries.");

Modified: trunk/Image/NRRDFile.cc
==============================================================================
--- trunk/Image/NRRDFile.cc     (original)
+++ trunk/Image/NRRDFile.cc     Mon Nov 26 21:56:50 2007
@@ -39,7 +39,6 @@
 #include <teem/nrrd.h>
 
 using namespace Manta;
-using namespace SCIRun;
 
 extern "C" void writeNRRD( Image const *image, std::string const &file_name, 
int eye ) {
   // Create a nrrd to save the image.

Modified: trunk/Image/NullImage.cc
==============================================================================
--- trunk/Image/NullImage.cc    (original)
+++ trunk/Image/NullImage.cc    Mon Nov 26 21:56:50 2007
@@ -3,7 +3,6 @@
 #include <Core/Exceptions/IllegalValue.h>
 
 using namespace Manta;
-using SCIRun::IllegalValue;
 
 Image* NullImage::create(const vector<string>& args, bool stereo,
                         int xres, int yres)

Modified: trunk/Image/NullImage.h
==============================================================================
--- trunk/Image/NullImage.h     (original)
+++ trunk/Image/NullImage.h     Mon Nov 26 21:56:50 2007
@@ -3,10 +3,8 @@
 #define Manta_Image_NullImage_h
 
 #include <Interface/Image.h>
-#include <sgi_stl_warnings_off.h>
 #include <string>
 #include <vector>
-#include <sgi_stl_warnings_on.h>
 
 namespace Manta {
   using namespace std;

Modified: trunk/Image/PPMFile.cc
==============================================================================
--- trunk/Image/PPMFile.cc      (original)
+++ trunk/Image/PPMFile.cc      Mon Nov 26 21:56:50 2007
@@ -1,4 +1,4 @@
-#include <Core/Exceptions/UnknownPixel.h>
+#include <Core/Exceptions/UnknownPixelFormat.h>
 #include <Core/Exceptions/InputError.h>
 #include <Core/Exceptions/OutputError.h>
 #include <Image/PPMFile.h>
@@ -16,7 +16,6 @@
 using std::string;
 
 using namespace Manta;
-using namespace SCIRun;
 
 void eatPPMCommentsWhitespace(ifstream& str)
 {
@@ -42,7 +41,7 @@
 {
   // Validate image type
   if (typeid(*image) != typeid(SimpleImage<RGB8Pixel>)) {
-    throw UnknownPixel("Unsupported image type for PPM output");
+    throw UnknownPixelFormat("Unsupported image type for PPM output");
   }
 
   // Open PPM file and write header

Modified: trunk/Image/RGBEFile.cc
==============================================================================
--- trunk/Image/RGBEFile.cc     (original)
+++ trunk/Image/RGBEFile.cc     Mon Nov 26 21:56:50 2007
@@ -4,7 +4,7 @@
 
 #include <Image/Pixel.h>
 #include <Image/SimpleImage.h>
-#include <SCIRun/Core/Exceptions/InternalError.h>
+#include <Core/Exceptions/InternalError.h>
 #include <Core/Exceptions/OutputError.h>
 
 #include <stdio.h>
@@ -12,21 +12,18 @@
 #include <string.h>
 
 using namespace Manta;
-using SCIRun::InternalError;
 
 Image* Manta::readRGBE(const std::string& filename) {
     FILE* file = fopen(filename.c_str(), "rb");
     if (!file) {
-      throw InternalError("Couldn't open RGBE file for reading: " + filename,
-                          __FILE__, __LINE__);
+      throw InternalError("Couldn't open RGBE file for reading: " + 
filename);
     }
 
     int width, height;
     int error = RGBE_ReadHeader(file, &width, &height, NULL);
     if ( error != RGBE_RETURN_SUCCESS ) {
       fclose(file);
-      throw InternalError("RGBE_ReadHeader failed for file: " + filename,
-                          __FILE__, __LINE__);
+      throw InternalError("RGBE_ReadHeader failed for file: " + filename);
     }
 
     unsigned int w = (unsigned int)width;
@@ -36,15 +33,14 @@
     if (!image) {
       fclose(file);
       throw InternalError("RGBEFile::readRGBE failed to allocate temporary \
-          raster for file: " + filename, __FILE__, __LINE__);
+          raster for file: " + filename);
     }
 
     error = RGBE_ReadPixels_RLE(file, image, w, h);
     if ( error != RGBE_RETURN_SUCCESS ) {
       delete[] image;
       fclose(file);
-      throw InternalError("RGBE_ReadPixels_RLE failed for file: " + filename,
-                          __FILE__, __LINE__);
+      throw InternalError("RGBE_ReadPixels_RLE failed for file: " + 
filename);
     }
 
     fclose(file);
@@ -53,8 +49,8 @@
       new SimpleImage< RGBfloatPixel >( false, width, height );
     if (!result) {
       delete[] image;
-      throw InternalError("RGBEFile::readRGBE failed to allocate Image" + 
-          filename, __FILE__, __LINE__);
+      throw InternalError("RGBEFile::readRGBE failed to allocate Image" + 
filename );
+
     }
 
     for (unsigned int y = 0; y < h; y++ ) {
@@ -87,15 +83,14 @@
     float* raster = new(std::nothrow)float[3*w*h];
     if (!raster) {
       fclose(out);
-      throw InternalError("RGBEIO::writeImage failed to allocate raster.",
-          __FILE__, __LINE__ );
+      throw InternalError("RGBEIO::writeImage failed to allocate raster.");
     }
 
     const SimpleImage<RGBAfloatPixel>* si = 
       dynamic_cast<const SimpleImage<RGBAfloatPixel> *>(image);
     if ( !si ) {
       throw InternalError("RGBEIO::writeImage only Simple RGBAfloatPixel \
-          images supported.", __FILE__, __LINE__ );
+          images supported.");
     }
 
     

Modified: trunk/Image/SimpleImage.h
==============================================================================
--- trunk/Image/SimpleImage.h   (original)
+++ trunk/Image/SimpleImage.h   Mon Nov 26 21:56:50 2007
@@ -34,10 +34,8 @@
 #include <Core/Exceptions/IllegalValue.h>
 #include <Image/Pixel.h>
 #include <Interface/Parameters.h>
-#include <sgi_stl_warnings_off.h>
 #include <string>
 #include <vector>
-#include <sgi_stl_warnings_on.h>
 
 namespace Manta {
   template<class Pixel> class SimpleImage : public SimpleImageBase {
@@ -74,7 +72,7 @@
                                     bool stereo, int xres, int yres)
   {
     if(args.size() != 0)
-      throw SCIRun::IllegalValue<std::string>
+      throw IllegalValue<std::string>
         ("Illegal argument to SimpleImage create", args[0]);
     return new SimpleImage<Pixel>(stereo, xres, yres);
   }

Modified: trunk/Image/TGAFile.cc
==============================================================================
--- trunk/Image/TGAFile.cc      (original)
+++ trunk/Image/TGAFile.cc      Mon Nov 26 21:56:50 2007
@@ -33,14 +33,9 @@
 #include <Image/Pixel.h>
 #include <Image/SimpleImage.h>
 #include <Image/TGAFile.h>
-
-#include <sgi_stl_warnings_off.h>
 #include <fstream>
-#include <sgi_stl_warnings_on.h>
 
 using namespace std;
-using SCIRun::IllegalValue;
-using SCIRun::InternalError;
 using namespace Manta;
 
 static void writePixel(ofstream& out, unsigned char r, unsigned char g,
@@ -163,7 +158,7 @@
   {
     ofstream out( filename.c_str(), ios::out | ios::binary );
     if ( !out )
-      throw InternalError( "Couldn't open TGA file for writing: " + 
filename, __FILE__, __LINE__  );
+      throw InternalError( "Couldn't open TGA file for writing: " + 
filename);
     out.put( 0 );                 // ID length: 0
     out.put( 0 );                 // Color map type: None
     out.put( 2 );                 // Image type: uncompressed, true-color 
image
@@ -252,14 +247,14 @@
   {
     ifstream in( filename.c_str(), ios::in | ios::binary );
     if ( !in )
-      throw InternalError( "Couldn't open TGA file for reading: " + 
filename, __FILE__, __LINE__  );
+      throw InternalError( "Couldn't open TGA file for reading: " + 
filename);
     int id_length = in.get();
     int color_map_type = in.get();
     if ( color_map_type != 0 )
-      throw InternalError( "Color map TGA files currently unsupported", 
__FILE__, __LINE__  );
+      throw InternalError( "Color map TGA files currently unsupported");
     int image_type = in.get();
     if ( image_type != 2 )
-      throw InternalError( "Only uncompressed true-color TGA files currently 
supported", __FILE__, __LINE__  );
+      throw InternalError( "Only uncompressed true-color TGA files currently 
supported");
 #if 0
     int color_map_first_entry_index = read16bit( in );
     int color_map_length = read16bit( in );
@@ -283,7 +278,7 @@
     if (image_descriptor & (192)) {
       // Bits 6-7 are for strange interleaving formats.  If they are
       // set, we should blow up.
-      throw InternalError( "Only non interleaved TGA files currently 
supported", __FILE__, __LINE__  );
+      throw InternalError( "Only non interleaved TGA files currently 
supported");
     }
     in.ignore( id_length );
     bool flip_image = !!(image_descriptor & 32); // bit 5 says flip in y
@@ -311,6 +306,6 @@
         }
       return si;
     }
-    throw InternalError( "Unhandled pixel depth and alpha for TGA files", 
__FILE__, __LINE__  );
+    throw InternalError( "Unhandled pixel depth and alpha for TGA files");
   }
 

Modified: trunk/Interface/AmbientLight.h
==============================================================================
--- trunk/Interface/AmbientLight.h      (original)
+++ trunk/Interface/AmbientLight.h      Mon Nov 26 21:56:50 2007
@@ -3,9 +3,7 @@
 #define Manta_Interface_AmbientLight_h
 
 #include <MantaTypes.h>
-#include <sgi_stl_warnings_off.h>
 #include <string>
-#include <sgi_stl_warnings_on.h>
 #include <Interface/RayPacket.h>
 
 namespace Manta {

Modified: trunk/Interface/CMakeLists.txt
==============================================================================
--- trunk/Interface/CMakeLists.txt      (original)
+++ trunk/Interface/CMakeLists.txt      Mon Nov 26 21:56:50 2007
@@ -74,4 +74,4 @@
         XWindow.h
         )
 
-TARGET_LINK_LIBRARIES(Manta_Interface Manta_Core SCIRun_Core)
+TARGET_LINK_LIBRARIES(Manta_Interface Manta_Core)

Modified: trunk/Interface/Camera.h
==============================================================================
--- trunk/Interface/Camera.h    (original)
+++ trunk/Interface/Camera.h    Mon Nov 26 21:56:50 2007
@@ -6,10 +6,7 @@
 #include <Core/Geometry/BBox.h>
 #include <Core/Geometry/AffineTransform.h>
 #include <Interface/Interpolable.h>
-
-#include <sgi_stl_warnings_off.h>
 #include <iosfwd>
-#include <sgi_stl_warnings_on.h>
 
 namespace Manta {
   class PreprocessContext;

Modified: trunk/Interface/Context.cc
==============================================================================
--- trunk/Interface/Context.cc  (original)
+++ trunk/Interface/Context.cc  Mon Nov 26 21:56:50 2007
@@ -35,9 +35,9 @@
   if (barrier) barrier->wait(numProcs);
 }
 
-SCIRun::Barrier* PreprocessContext::setBarrier(SCIRun::Barrier* new_barrier)
+Barrier* PreprocessContext::setBarrier(Barrier* new_barrier)
 {
-  SCIRun::Barrier* old = barrier;
+  Barrier* old = barrier;
   barrier = new_barrier;
   return old;
 }

Modified: trunk/Interface/Context.h
==============================================================================
--- trunk/Interface/Context.h   (original)
+++ trunk/Interface/Context.h   Mon Nov 26 21:56:50 2007
@@ -2,11 +2,8 @@
 #ifndef Manta_Interface_Context_h
 #define Manta_Interface_Context_h
 
-namespace SCIRun {
-  class Barrier;
-};
-
 namespace Manta {
+  class Barrier;
   class Camera;
   class FrameState;
   class LightSet;
@@ -213,7 +210,7 @@
     // Set the barrier.  You shouldn't need to call this if you used
     // the constructor that takes a manta_interface.  It returns the
     // old barrier.
-    SCIRun::Barrier* setBarrier(SCIRun::Barrier* barrier);
+    Barrier* setBarrier(Barrier* barrier);
 
     // Call this when you're done changing your state values during a
     // preprocess call.  It ensures that all the threads finish
@@ -225,7 +222,7 @@
     int numProcs;
     LightSet* globalLights;
   private:
-    mutable SCIRun::Barrier* barrier;
+    mutable Barrier* barrier;
 
     PreprocessContext(const PreprocessContext&);
     PreprocessContext& operator=(const PreprocessContext&);

Modified: trunk/Interface/LightSet.cc
==============================================================================
--- trunk/Interface/LightSet.cc (original)
+++ trunk/Interface/LightSet.cc Mon Nov 26 21:56:50 2007
@@ -7,10 +7,8 @@
 #include <Core/Persistent/stdRTTI.h>
 #include <Core/Util/Assert.h>
 
-#include <sgi_stl_warnings_off.h>
 #include <iostream>
 #include <sstream>
-#include <sgi_stl_warnings_on.h>
 
 using namespace Manta;
 using namespace std;

Modified: trunk/Interface/LightSet.h
==============================================================================
--- trunk/Interface/LightSet.h  (original)
+++ trunk/Interface/LightSet.h  Mon Nov 26 21:56:50 2007
@@ -3,11 +3,8 @@
 #define Manta_Interface_LightSet_h
 
 #include <Interface/RayPacket.h>
-
-#include <sgi_stl_warnings_off.h>
 #include <vector>
 #include <string>
-#include <sgi_stl_warnings_on.h>
 
 namespace Manta {
   class AmbientLight;

Modified: trunk/Interface/MantaInterface.h
==============================================================================
--- trunk/Interface/MantaInterface.h    (original)
+++ trunk/Interface/MantaInterface.h    Mon Nov 26 21:56:50 2007
@@ -32,22 +32,16 @@
 
 #include <Interface/Callback.h>
 #include <Interface/Transaction.h>
-#include <SCIRun/Core/Exceptions/Exception.h>
+#include <Core/Exceptions/Exception.h>
 #include <MantaTypes.h>
-
-#include <sgi_stl_warnings_off.h>
 #include <string>
 #include <vector>
-#include <sgi_stl_warnings_on.h>
-
-namespace SCIRun {
-  class Barrier;
-}
 
 namespace Manta {
 
   using namespace std;
 
+  class Barrier;
   class Camera;
   class CameraPath;
   class Group;
@@ -171,7 +165,7 @@
     virtual TValue<int>& numWorkers() = 0;
 
     // Control
-    virtual void beginRendering(bool blockUntilFinished) throw 
(SCIRun::Exception&) = 0;
+    virtual void beginRendering(bool blockUntilFinished) throw (Exception&) 
= 0;
     virtual void blockUntilFinished() = 0;
 
     // Control
@@ -228,7 +222,7 @@
     virtual void unregisterCallback(CallbackHandle*) = 0;
 
     //
-    virtual SCIRun::Barrier* getPreprocessBarrier() = 0;
+    virtual Barrier* getPreprocessBarrier() = 0;
 
     
///////////////////////////////////////////////////////////////////////////
     
///////////////////////////////////////////////////////////////////////////

Modified: trunk/Interface/Material.cc
==============================================================================
--- trunk/Interface/Material.cc (original)
+++ trunk/Interface/Material.cc Mon Nov 26 21:56:50 2007
@@ -15,6 +15,6 @@
 void Material::sampleBSDF(const RenderContext& context,
                           RayPacket& rays, Packet<Color>& reflectance) const
 {
-  throw SCIRun::InternalError("computeBSDF not implemented for this 
material", __FILE__, __LINE__);
+  throw InternalError("computeBSDF not implemented for this material");
 }
 

Modified: trunk/Interface/MeshTriangle.h
==============================================================================
--- trunk/Interface/MeshTriangle.h      (original)
+++ trunk/Interface/MeshTriangle.h      Mon Nov 26 21:56:50 2007
@@ -3,7 +3,7 @@
 
 #include <Interface/Primitive.h>
 #include <Model/Groups/Mesh.h>
-#include <SCIRun/Core/Util/Assert.h>
+#include <Core/Util/Assert.h>
 
 namespace Manta {
 

Modified: trunk/Interface/Primitive.cc
==============================================================================
--- trunk/Interface/Primitive.cc        (original)
+++ trunk/Interface/Primitive.cc        Mon Nov 26 21:56:50 2007
@@ -18,8 +18,7 @@
                                 Packet<Real>& pdfs,
                                 const RenderContext& context,
                                 RayPacket& rays) const {
-  throw SCIRun::InternalError("Unimplemented getRandomPoint for Primitive",
-                              __FILE__, __LINE__);
+  throw InternalError("Unimplemented getRandomPoint for Primitive");
 }
 
 void Primitive::computeSurfaceDerivatives(const RenderContext& context,

Modified: trunk/Interface/RayPacket.cc
==============================================================================
--- trunk/Interface/RayPacket.cc        (original)
+++ trunk/Interface/RayPacket.cc        Mon Nov 26 21:56:50 2007
@@ -1,10 +1,7 @@
 
 #include <Interface/RayPacket.h>
 #include <MantaSSE.h>
-
-#include <sgi_stl_warnings_off.h>
 #include <iostream>
-#include <sgi_stl_warnings_on.h>
 
 using namespace Manta;
 
@@ -18,7 +15,7 @@
       Real sum = 0;
       for(int j=0;j<3;j++)
         sum += data->direction[j][i] * data->direction[j][i];
-      Real length = SCIRun::Sqrt(sum);
+      Real length = Sqrt(sum);
       data->minT[i] *= length;
       Real scale = 1/length;
       for(int j=0;j<3;j++)
@@ -30,7 +27,7 @@
       Real sum = 0;
       for(int j=0;j<3;j++)
         sum += data->direction[j][i] * data->direction[j][i];
-      Real length = SCIRun::Sqrt(sum);
+      Real length = Sqrt(sum);
       data->minT[i] *= length;
       Real scale = 1/length;
       for(int j=0;j<3;j++)
@@ -54,7 +51,7 @@
       Real sum = 0;
       for(int j=0;j<3;j++)
         sum += data->direction[j][i] * data->direction[j][i];
-      Real length = SCIRun::Sqrt(sum);
+      Real length = Sqrt(sum);
       data->minT[i] *= length;
       Real scale = 1/length;
       for(int j=0;j<3;j++)
@@ -66,7 +63,7 @@
     Real sum = 0;
     for(int j=0;j<3;j++)
       sum += data->direction[j][i] * data->direction[j][i];
-    Real length = SCIRun::Sqrt(sum);
+    Real length = Sqrt(sum);
     data->minT[i] *= length;
     Real scale = 1/length;
     for(int j=0;j<3;j++)
@@ -167,7 +164,7 @@
         Real sum = 0;
         for(int j=0;j<3;++j)
           sum += data->normal[j][s] * data->normal[j][s];
-        Real scale = 1/SCIRun::Sqrt(sum);
+        Real scale = 1/Sqrt(sum);
         for(int j=0;j<3;++j)
           data->normal[j][s] *= scale;
       }
@@ -209,7 +206,7 @@
         Real sum = 0;
         for(int j=0;j<3;++j)
           sum += data->normal[j][s] * data->normal[j][s];
-        Real scale = 1/SCIRun::Sqrt(sum);
+        Real scale = 1/Sqrt(sum);
         for(int j=0;j<3;++j)
           data->normal[j][s] *= scale;
       }

Modified: trunk/Interface/RayPacket.h
==============================================================================
--- trunk/Interface/RayPacket.h (original)
+++ trunk/Interface/RayPacket.h Mon Nov 26 21:56:50 2007
@@ -47,10 +47,7 @@
 #ifdef MANTA_SSE
 #include <Core/Math/SSEDefs.h>
 #endif
-
-#include <sgi_stl_warnings_off.h>
 #include <iosfwd>
-#include <sgi_stl_warnings_on.h>
 
 namespace Manta {
   class Material;

Modified: trunk/Interface/ShadowAlgorithm.h
==============================================================================
--- trunk/Interface/ShadowAlgorithm.h   (original)
+++ trunk/Interface/ShadowAlgorithm.h   Mon Nov 26 21:56:50 2007
@@ -4,9 +4,7 @@
 #define Manta_Interface_ShadowAlgorithm_h
 
 #include <Interface/RayPacket.h>
-#include <sgi_stl_warnings_off.h>
 #include <string>
-#include <sgi_stl_warnings_on.h>
 
 namespace Manta {
   class LightSet;

Modified: trunk/Interface/Task.h
==============================================================================
--- trunk/Interface/Task.h      (original)
+++ trunk/Interface/Task.h      Mon Nov 26 21:56:50 2007
@@ -45,9 +45,9 @@
     CallbackBase_0Data* reduction_function;
 
     std::vector<Task*> tasks;
-    SCIRun::AtomicCounter num_assigned;
+    AtomicCounter num_assigned;
     // Need to keep track of how many tasks are left unfinished
-    SCIRun::AtomicCounter num_remaining;
+    AtomicCounter num_remaining;
   };
 } // end namespace Manta
 

Modified: trunk/Model/AmbientLights/ArcAmbient.cc
==============================================================================
--- trunk/Model/AmbientLights/ArcAmbient.cc     (original)
+++ trunk/Model/AmbientLights/ArcAmbient.cc     Mon Nov 26 21:56:50 2007
@@ -3,16 +3,12 @@
 #include <Interface/RayPacket.h>
 #include <Interface/InterfaceRTTI.h>
 #include <Core/Persistent/ArchiveElement.h>
-
-#include <sgi_stl_warnings_off.h>
+#include <Core/Math/Trig.h>
 #include <sstream>
-#include <sgi_stl_warnings_on.h>
 
-#include <Core/Math/Trig.h>
 
 using namespace Manta;
 using namespace std;
-using namespace SCIRun;
 
 ArcAmbient::ArcAmbient()
 {
@@ -43,7 +39,7 @@
     // This makes this safe from cases where your normal is too "long"
     // and cosine is greater than 1.  In that case you end up with
     // sine being NaN, which really sucks.
-    sine = (sine > 0) ? SCIRun::Sqrt(sine): 0;
+    sine = (sine > 0) ? Sqrt(sine): 0;
     // So we want to do the computation for w0 and w1 as type Real,
     // because that is what all the other computation will be done,
     // but we would like to cast that to type ColorComponent, because

Modified: trunk/Model/AmbientLights/ArcAmbient.h
==============================================================================
--- trunk/Model/AmbientLights/ArcAmbient.h      (original)
+++ trunk/Model/AmbientLights/ArcAmbient.h      Mon Nov 26 21:56:50 2007
@@ -5,10 +5,7 @@
 #include <Interface/AmbientLight.h>
 #include <Core/Color/Color.h>
 #include <Core/Geometry/Vector.h>
-
-#include <sgi_stl_warnings_off.h>
 #include <string>
-#include <sgi_stl_warnings_on.h>
 
 namespace Manta {
 

Modified: trunk/Model/AmbientLights/ConstantAmbient.cc
==============================================================================
--- trunk/Model/AmbientLights/ConstantAmbient.cc        (original)
+++ trunk/Model/AmbientLights/ConstantAmbient.cc        Mon Nov 26 21:56:50 
2007
@@ -4,10 +4,7 @@
 #include <Interface/InterfaceRTTI.h>
 #include <Core/Persistent/ArchiveElement.h>
 #include <MantaSSE.h>
-
-#include <sgi_stl_warnings_off.h>
 #include <sstream>
-#include <sgi_stl_warnings_on.h>
 
 using namespace Manta;
 using namespace std;

Modified: trunk/Model/AmbientLights/ConstantAmbient.h
==============================================================================
--- trunk/Model/AmbientLights/ConstantAmbient.h (original)
+++ trunk/Model/AmbientLights/ConstantAmbient.h Mon Nov 26 21:56:50 2007
@@ -4,10 +4,7 @@
 
 #include <Interface/AmbientLight.h>
 #include <Core/Color/Color.h>
-
-#include <sgi_stl_warnings_off.h>
 #include <string>
-#include <sgi_stl_warnings_on.h>
 
 namespace Manta{
   class ConstantAmbient : public AmbientLight {

Modified: trunk/Model/Backgrounds/EnvMapBackground.cc
==============================================================================
--- trunk/Model/Backgrounds/EnvMapBackground.cc (original)
+++ trunk/Model/Backgrounds/EnvMapBackground.cc Mon Nov 26 21:56:50 2007
@@ -1,13 +1,11 @@
 
 #include <Interface/RayPacket.h>
 #include <Model/Backgrounds/EnvMapBackground.h>
-#include <SCIRun/Core/Math/Trig.h>
-#include <SCIRun/Core/Math/Expon.h>
-#include <SCIRun/Core/Exceptions/InternalError.h>
+#include <Core/Math/Trig.h>
+#include <Core/Math/Expon.h>
+#include <Core/Exceptions/InternalError.h>
 
 using namespace Manta;
-using SCIRun::InternalError;
-using SCIRun::Sqrt;
 
 static Real OneOverPi=static_cast<Real>(1/M_PI);
 static Real OneOverTwoPi=static_cast<Real>(1/(2*M_PI));
@@ -52,7 +50,7 @@
     OldBehaviorMapping(context, rays);
     break;
   default:
-    throw InternalError("Unknown map_type", __FILE__, __LINE__);
+    throw InternalError("Unknown map_type");
     break;
   }
 

Modified: trunk/Model/Backgrounds/TextureBackground.cc
==============================================================================
--- trunk/Model/Backgrounds/TextureBackground.cc        (original)
+++ trunk/Model/Backgrounds/TextureBackground.cc        Mon Nov 26 21:56:50 
2007
@@ -34,7 +34,6 @@
 #include <Core/Geometry/Vector.h>
 
 using namespace Manta;
-using namespace SCIRun;
 
 TextureBackground::TextureBackground(const Texture<Color>* colortex,
                                      const TexCoordMapper* mapper_in)

Modified: trunk/Model/Cameras/EnvironmentCamera.cc
==============================================================================
--- trunk/Model/Cameras/EnvironmentCamera.cc    (original)
+++ trunk/Model/Cameras/EnvironmentCamera.cc    Mon Nov 26 21:56:50 2007
@@ -17,7 +17,6 @@
 
 using namespace Manta;
 using namespace std;
-using SCIRun::Clamp;
 
 EnvironmentCamera::EnvironmentCamera(const Vector& eye_,
                                      const Vector& lookat_,

Modified: trunk/Model/Cameras/EnvironmentCamera.h
==============================================================================
--- trunk/Model/Cameras/EnvironmentCamera.h     (original)
+++ trunk/Model/Cameras/EnvironmentCamera.h     Mon Nov 26 21:56:50 2007
@@ -4,10 +4,8 @@
 
 #include <Interface/Camera.h>
 #include <Core/Geometry/Vector.h>
-#include <sgi_stl_warnings_off.h>
 #include <string>
 #include <vector>
-#include <sgi_stl_warnings_on.h>
 
 namespace Manta {
   using namespace std;

Modified: trunk/Model/Cameras/FisheyeCamera.cc
==============================================================================
--- trunk/Model/Cameras/FisheyeCamera.cc        (original)
+++ trunk/Model/Cameras/FisheyeCamera.cc        Mon Nov 26 21:56:50 2007
@@ -13,13 +13,9 @@
 #include <Core/Math/Trig.h>
 #include <Core/Math/Expon.h>
 #include <Core/Util/Assert.h>
-
-#include <sgi_stl_warnings_off.h>
 #include <iostream>
-#include <sgi_stl_warnings_on.h>
 
 using namespace Manta;
-using namespace SCIRun;
 using namespace std;
 
 FisheyeCamera::FisheyeCamera(const Vector& eye_, const Vector& lookat_,

Modified: trunk/Model/Cameras/FisheyeCamera.h
==============================================================================
--- trunk/Model/Cameras/FisheyeCamera.h (original)
+++ trunk/Model/Cameras/FisheyeCamera.h Mon Nov 26 21:56:50 2007
@@ -4,10 +4,8 @@
 
 #include <Interface/Camera.h>
 #include <Core/Geometry/Vector.h>
-#include <sgi_stl_warnings_off.h>
 #include <string>
 #include <vector>
-#include <sgi_stl_warnings_on.h>
 
 namespace Manta {
   using namespace std;

Modified: trunk/Model/Cameras/OrthogonalCamera.cc
==============================================================================
--- trunk/Model/Cameras/OrthogonalCamera.cc     (original)
+++ trunk/Model/Cameras/OrthogonalCamera.cc     Mon Nov 26 21:56:50 2007
@@ -14,7 +14,6 @@
 
 using namespace Manta;
 using namespace std;
-using namespace SCIRun;
 
 OrthogonalCamera::OrthogonalCamera(const Vector& eye_, const Vector& lookat_,
                                    const Vector& up_, Real hscale_, Real 
vscale_ )

Modified: trunk/Model/Cameras/OrthogonalCamera.h
==============================================================================
--- trunk/Model/Cameras/OrthogonalCamera.h      (original)
+++ trunk/Model/Cameras/OrthogonalCamera.h      Mon Nov 26 21:56:50 2007
@@ -4,10 +4,8 @@
 
 #include <Interface/Camera.h>
 #include <Core/Geometry/Vector.h>
-#include <sgi_stl_warnings_off.h>
 #include <string>
 #include <vector>
-#include <sgi_stl_warnings_on.h>
 
 namespace Manta {
   using namespace std;

Modified: trunk/Model/Cameras/PinholeCamera.cc
==============================================================================
--- trunk/Model/Cameras/PinholeCamera.cc        (original)
+++ trunk/Model/Cameras/PinholeCamera.cc        Mon Nov 26 21:56:50 2007
@@ -19,8 +19,6 @@
 
 using namespace Manta;
 using namespace std;
-using SCIRun::Clamp;
-using SCIRun::Abs;
 
 PinholeCamera::PinholeCamera( const Vector& eye_, const Vector& lookat_,
                               const Vector &up_, Real hfov_, Real vfov_ )
@@ -254,10 +252,10 @@
           //find max ray extents.
           //TODO: double check that calling getImageCoordinates again
           //won't return different values and isn't slow.
-          min_v = SCIRun::Min(min_v, rays.getImageCoordinates(i, 0));
-          max_v = SCIRun::Max(max_v, rays.getImageCoordinates(i, 0));
-          min_u = SCIRun::Min(min_u, rays.getImageCoordinates(i, 1));
-          max_u = SCIRun::Max(max_u, rays.getImageCoordinates(i, 1));
+          min_v = Min(min_v, rays.getImageCoordinates(i, 0));
+          max_v = Max(max_v, rays.getImageCoordinates(i, 0));
+          min_u = Min(min_u, rays.getImageCoordinates(i, 1));
+          max_u = Max(max_u, rays.getImageCoordinates(i, 1));
         }
       }
     } else {
@@ -270,10 +268,10 @@
 
         if (CREATE_CORNER_RAYS) {
           //find max ray extents
-          min_v = SCIRun::Min(min_v, rays.getImageCoordinates(i, 0));
-          max_v = SCIRun::Max(max_v, rays.getImageCoordinates(i, 0));
-          min_u = SCIRun::Min(min_u, rays.getImageCoordinates(i, 1));
-          max_u = SCIRun::Max(max_u, rays.getImageCoordinates(i, 1));
+          min_v = Min(min_v, rays.getImageCoordinates(i, 0));
+          max_v = Max(max_v, rays.getImageCoordinates(i, 0));
+          min_u = Min(min_u, rays.getImageCoordinates(i, 1));
+          max_u = Max(max_u, rays.getImageCoordinates(i, 1));
         }
       }
       for(i=e;i<rays.rayEnd;i++){
@@ -284,10 +282,10 @@
 
         if (CREATE_CORNER_RAYS) {
           //find max ray extents
-          min_v = SCIRun::Min(min_v, rays.getImageCoordinates(i, 0));
-          max_v = SCIRun::Max(max_v, rays.getImageCoordinates(i, 0));
-          min_u = SCIRun::Min(min_u, rays.getImageCoordinates(i, 1));
-          max_u = SCIRun::Max(max_u, rays.getImageCoordinates(i, 1));
+          min_v = Min(min_v, rays.getImageCoordinates(i, 0));
+          max_v = Max(max_v, rays.getImageCoordinates(i, 0));
+          min_u = Min(min_u, rays.getImageCoordinates(i, 1));
+          max_u = Max(max_u, rays.getImageCoordinates(i, 1));
         }
       }
 
@@ -377,10 +375,10 @@
         raydir.normalize();
       rays.setRay(i, eye, raydir);
       if (CREATE_CORNER_RAYS) {
-          min_v = SCIRun::Min(min_v, v_imageCoord);
-          max_v = SCIRun::Max(max_v, v_imageCoord);
-          min_u = SCIRun::Min(min_u, u_imageCoord);
-          max_u = SCIRun::Max(max_u, u_imageCoord);
+          min_v = Min(min_v, v_imageCoord);
+          max_v = Max(max_v, v_imageCoord);
+          min_u = Min(min_u, u_imageCoord);
+          max_u = Max(max_u, u_imageCoord);
       }
     }
 

Modified: trunk/Model/Cameras/PinholeCamera.h
==============================================================================
--- trunk/Model/Cameras/PinholeCamera.h (original)
+++ trunk/Model/Cameras/PinholeCamera.h Mon Nov 26 21:56:50 2007
@@ -5,10 +5,8 @@
 
 #include <Interface/Camera.h>
 #include <Core/Geometry/Vector.h>
-#include <sgi_stl_warnings_off.h>
 #include <string>
 #include <vector>
-#include <sgi_stl_warnings_on.h>
 
 namespace Manta {
   using namespace std;

Modified: trunk/Model/Cameras/ThinLensCamera.cc
==============================================================================
--- trunk/Model/Cameras/ThinLensCamera.cc       (original)
+++ trunk/Model/Cameras/ThinLensCamera.cc       Mon Nov 26 21:56:50 2007
@@ -20,8 +20,6 @@
 
 using namespace Manta;
 using namespace std;
-using SCIRun::Clamp;
-using SCIRun::Abs;
 
 ThinLensCamera::ThinLensCamera( const Vector& eye_, const Vector& lookat_,
                                 const Vector &up_, Real hfov_, Real vfov_,
@@ -172,7 +170,7 @@
       Real imageY = rays.getImageCoordinates(i, 1);
 
       Real theta = 2.0 * M_PI * lens_coord_x.get(i);
-      Real r = radius * SCIRun::Sqrt( lens_coord_y.get(i) );
+      Real r = radius * Sqrt( lens_coord_y.get(i) );
 
       Vector origin = r*Cos(theta)*u + r*Sin(theta)*v;
       Vector on_film = imageX*v+imageY*u+direction*focal_length;
@@ -186,7 +184,7 @@
       Real imageY = rays.getImageCoordinates(i, 1);
 
       Real theta = 2.0 * M_PI * lens_coord_x.get(i);
-      Real r = radius * SCIRun::Sqrt( lens_coord_y.get(i) );
+      Real r = radius * Sqrt( lens_coord_y.get(i) );
 
       Vector origin = r*Cos(theta)*u + r*Sin(theta)*v;
       Vector on_film = imageX*v+imageY*u+direction*focal_length;
@@ -198,7 +196,7 @@
       Real imageY = rays.getImageCoordinates(i, 1);
 
       Real theta = 2.0 * M_PI * lens_coord_x.get(i);
-      Real r = radius * SCIRun::Sqrt( lens_coord_y.get(i) );
+      Real r = radius * Sqrt( lens_coord_y.get(i) );
 
       Vector origin = r*Cos(theta)*u + r*Sin(theta)*v;
       Vector on_film = imageX*v+imageY*u+direction*focal_length;
@@ -278,7 +276,7 @@
     Real imageY = rays.getImageCoordinates(i, 1);
 
     Real theta = 2.0 * M_PI * lens_coord_x.get(i);
-    Real r = radius * SCIRun::Sqrt( lens_coord_y.get(i) );
+    Real r = radius * Sqrt( lens_coord_y.get(i) );
 
     Vector origin = r*Cos(theta)*u + r*Sin(theta)*v;
     Vector on_film = imageX*v+imageY*u+direction*focal_length;

Modified: trunk/Model/Cameras/ThinLensCamera.h
==============================================================================
--- trunk/Model/Cameras/ThinLensCamera.h        (original)
+++ trunk/Model/Cameras/ThinLensCamera.h        Mon Nov 26 21:56:50 2007
@@ -5,10 +5,8 @@
 
 #include <Interface/Camera.h>
 #include <Core/Geometry/Vector.h>
-#include <sgi_stl_warnings_off.h>
 #include <string>
 #include <vector>
-#include <sgi_stl_warnings_on.h>
 
 namespace Manta {
   using namespace std;

Modified: trunk/Model/Groups/DynBVH.cc
==============================================================================
--- trunk/Model/Groups/DynBVH.cc        (original)
+++ trunk/Model/Groups/DynBVH.cc        Mon Nov 26 21:56:50 2007
@@ -7,7 +7,7 @@
 #include <float.h>
 #include <limits>
 #include <iostream>
-#include <SCIRun/Core/Thread/Time.h>
+#include <Core/Thread/Time.h>
 #include <Interface/Context.h>
 #include <Interface/Task.h>
 
@@ -669,7 +669,7 @@
   if (proc > 0) return;
 
   cerr << "\nDynBVH::preprocess START (" << currGroup->size() << " 
objects)\n";
-  double start = SCIRun::Time::currentSeconds();
+  double start = Time::currentSeconds();
 
   if(currGroup->size() > object_ids.size()) {
     nodes.resize(2*currGroup->size());
@@ -688,11 +688,11 @@
 
   num_nodes = 1; // root node
   int nextFree = 1;
-  double build_start = SCIRun::Time::currentSeconds();
+  double build_start = Time::currentSeconds();
   build(context, 0, 0, currGroup->size(), nextFree);
-  double updateBound_start = SCIRun::Time::currentSeconds();
+  double updateBound_start = Time::currentSeconds();
   updateBounds(context, 0);
-  double end = SCIRun::Time::currentSeconds();
+  double end = Time::currentSeconds();
   cerr << "\nDynBVH build time: Total ("<<end-start<<")\n"
        << "object_ids initialization ("<<build_start-start<<")\n"
        << "build ("<<updateBound_start-build_start<<")\n"

Modified: trunk/Model/Groups/DynBVH.h
==============================================================================
--- trunk/Model/Groups/DynBVH.h (original)
+++ trunk/Model/Groups/DynBVH.h Mon Nov 26 21:56:50 2007
@@ -63,7 +63,7 @@
     unsigned int num_nodes;
     Group* currGroup;
     bool group_changed;
-    SCIRun::Barrier barrier;
+    Barrier barrier;
     SpinLock taskpool_mutex;
 
     vector<BBox> obj_bounds;

Modified: trunk/Model/Groups/GriddedGroup.cc
==============================================================================
--- trunk/Model/Groups/GriddedGroup.cc  (original)
+++ trunk/Model/Groups/GriddedGroup.cc  Mon Nov 26 21:56:50 2007
@@ -7,13 +7,12 @@
 #include <Core/Geometry/BBox.h>
 #include <Core/Math/MinMax.h>
 #include <Core/Util/Args.h>
-#include <SCIRun/Core/Thread/Time.h>
-#include <SCIRun/Core/Math/MinMax.h>
+#include <Core/Thread/Time.h>
+#include <Core/Math/MinMax.h>
 #include <iostream>
 
 using namespace std;
 using namespace Manta;
-using namespace SCIRun;
 
 Group *GriddedGroup::create( const vector< string > &args )
 {
@@ -86,7 +85,7 @@
   int nx = static_cast<int>(diag.x()/vol3 * avgside + 0.8);
   int ny = static_cast<int>(diag.y()/vol3 * avgside + 0.8);
   int nz = static_cast<int>(diag.z()/vol3 * avgside + 0.8);
-  nx = SCIRun::Max(1, nx); ny = SCIRun::Max(1, ny); nz = SCIRun::Max(1, nz);
+  nx = Max(1, nx); ny = Max(1, ny); nz = Max(1, nz);
   int totalcells = nx*ny*nz;
   cellsize = diag/Vector(nx, ny, nz);
   inv_cellsize = cellsize.inverse();

Modified: trunk/Model/Groups/Group.cc
==============================================================================
--- trunk/Model/Groups/Group.cc (original)
+++ trunk/Model/Groups/Group.cc Mon Nov 26 21:56:50 2007
@@ -6,7 +6,7 @@
 #include <Interface/InterfaceRTTI.h>
 #include <Core/Persistent/stdRTTI.h>
 #include <Core/Persistent/ArchiveElement.h>
-#include <SCIRun/Core/Util/Assert.h>
+#include <Core/Util/Assert.h>
 #include <algorithm>
 #include <iostream>
 using std::cerr;

Modified: trunk/Model/Groups/Group.h
==============================================================================
--- trunk/Model/Groups/Group.h  (original)
+++ trunk/Model/Groups/Group.h  Mon Nov 26 21:56:50 2007
@@ -33,13 +33,11 @@
 
 #include <Interface/Object.h>
 #include <Core/Thread/Barrier.h>
-#include <SCIRun/Core/Thread/Mutex.h>
+#include <Core/Thread/Mutex.h>
 #include <Core/Geometry/BBox.h>
 #include <Core/Persistent/MantaRTTI.h>
-#include <sgi_stl_warnings_off.h>
 #include <vector>
 #include <string>
-#include <sgi_stl_warnings_on.h>
 
 namespace Manta {
   using namespace std;
@@ -94,8 +92,8 @@
     vector<Object*>::iterator  parallelSplit; //point to the start of the 
parallel objects
     mutable BBox bbox;
     mutable bool dirtybbox;
-    mutable SCIRun::Barrier barrier;
-    mutable SCIRun::Mutex mutex;
+    mutable Barrier barrier;
+    mutable Mutex mutex;
 
   };
 }

Modified: trunk/Model/Groups/KDTree.cc
==============================================================================
--- trunk/Model/Groups/KDTree.cc        (original)
+++ trunk/Model/Groups/KDTree.cc        Mon Nov 26 21:56:50 2007
@@ -3,7 +3,7 @@
 #include <Core/Geometry/Vector.h>
 #include <Core/Math/MinMax.h>
 #include <Interface/Context.h>
-#include <SCIRun/Core/Thread/Time.h>
+#include <Core/Thread/Time.h>
 #include <Interface/MantaInterface.h>
 
 #include <fstream>
@@ -58,7 +58,7 @@
   if (proc != 0)
     return;
 
-  double startTime = SCIRun::Time::currentSeconds();
+  double startTime = Time::currentSeconds();
 
   bounds.reset();
 
@@ -88,7 +88,7 @@
   build(0, primitives, bounds);
   
   cout << "done building" << endl << flush;
-  float buildTime = SCIRun::Time::currentSeconds() - startTime;
+  float buildTime = Time::currentSeconds() - startTime;
   printf("KDTree tree built in %f seconds\n", buildTime);
   printStats();
 }
@@ -697,7 +697,7 @@
             } 
             else {
               new_valid[ray] = true;
-              new_t_out[ray] = SCIRun::Min(t_out[ray], t_plane[ray]);
+              new_t_out[ray] = Min(t_out[ray], t_plane[ray]);
             }
           }
         }
@@ -732,7 +732,7 @@
           } 
           else {
             new_valid[ray] = true;
-            new_t_out[ray] = SCIRun::Min(t_out[ray], t_plane[ray]);
+            new_t_out[ray] = Min(t_out[ray], t_plane[ray]);
           }
         }
       }
@@ -765,13 +765,13 @@
             if (t_in[ray] > t_plane[ray]) {
               new_t_in[ray] = t_in[ray];
               // might may have changed in prev isec step:
-              new_t_out[ray] = SCIRun::Min(t_out[ray],rays.getMinT(ray)); 
+              new_t_out[ray] = Min(t_out[ray],rays.getMinT(ray)); 
               new_valid[ray] = (new_t_in[ray]<=new_t_out[ray]);
             } else if (t_out[ray] < t_plane[ray]) {
               new_valid[ray] = false;
             } else {
               new_t_in[ray] = t_plane[ray]; //t_in[ray];
-              new_t_out[ray] = SCIRun::Min(t_out[ray],rays.getMinT(ray)); 
+              new_t_out[ray] = Min(t_out[ray],rays.getMinT(ray)); 
               new_valid[ray] = (new_t_in[ray]<=new_t_out[ray]);
             }
             back += new_valid[ray];
@@ -808,13 +808,13 @@
           if (t_in[ray] > t_plane[ray]) {
             new_t_in[ray] = t_in[ray];
             // might may have changed in prev isec step:
-            new_t_out[ray] = 
SCIRun::Min(t_out[ray],static_cast<float>(rays.getMinT(ray))); 
+            new_t_out[ray] = 
Min(t_out[ray],static_cast<float>(rays.getMinT(ray))); 
             new_valid[ray] = (new_t_in[ray]<=new_t_out[ray]);
           } else if (t_out[ray] < t_plane[ray]) {
             new_valid[ray] = false;
           } else {
             new_t_in[ray] = t_plane[ray]; //t_in[ray];
-            new_t_out[ray] = 
SCIRun::Min(t_out[ray],static_cast<float>(rays.getMinT(ray))); 
+            new_t_out[ray] = 
Min(t_out[ray],static_cast<float>(rays.getMinT(ray))); 
             new_valid[ray] = (new_t_in[ray]<=new_t_out[ray]);
           }
           back += new_valid[ray];
@@ -846,14 +846,14 @@
  */
 bool KDTree::intersectBounds(const RenderContext& context, RayPacket& rays) 
const
 {
-  throw SCIRun::InternalError("hopefully done need this function", __FILE__, 
__LINE__);
+  throw InternalError("hopefully done need this function");
   return false;
 }
 
 
 bool KDTree::buildFromFile(const string &file)
 {
-  double startTime = SCIRun::Time::currentSeconds();
+  double startTime = Time::currentSeconds();
 
   bounds.reset();
 
@@ -920,7 +920,7 @@
   in.close();
 
   cout << "done building" << endl << flush;
-  float buildTime = SCIRun::Time::currentSeconds() - startTime;
+  float buildTime = Time::currentSeconds() - startTime;
   printf("KDTree tree built in %f seconds\n", buildTime);
   printStats();
 
@@ -972,9 +972,9 @@
 {
   const Node &node = this->node[nodeID];
   if (node.isLeaf) {
-    stats.maxDepth = SCIRun::Max(stats.maxDepth, depth);
-    stats.maxObjectsInLeaf = SCIRun::Max(stats.maxObjectsInLeaf,
-                                         node.numPrimitives);
+    stats.maxDepth = Max(stats.maxDepth, depth);
+    stats.maxObjectsInLeaf = Max(stats.maxObjectsInLeaf,
+                                 node.numPrimitives);
     stats.childrenLeafHist[std::min(node.numPrimitives,1023)]++;
   }
   else {

Modified: trunk/Model/Groups/Mesh.cc
==============================================================================
--- trunk/Model/Groups/Mesh.cc  (original)
+++ trunk/Model/Groups/Mesh.cc  Mon Nov 26 21:56:50 2007
@@ -1,7 +1,7 @@
 #include <Model/Groups/Mesh.h>
 #include <Core/Util/Preprocessor.h>
 #include <Core/Util/UpdateGraph.h>
-#include <SCIRun/Core/Exceptions/InternalError.h>
+#include <Core/Exceptions/InternalError.h>
 #include <Interface/MeshTriangle.h>
 
 using namespace Manta;
@@ -131,13 +131,13 @@
 void Mesh::add(Object* obj)
 {
   //I don't think this should be allowed.
-  throw SCIRun::InternalError(string("Illegal call to ") + __func__, 
__FILE__, __LINE__);
+  throw InternalError(string("Illegal call to ") + __func__);
 }
 
 void Mesh::set( int i, Object *obj )
 {
   //I don't think this should be allowed.
-  throw SCIRun::InternalError(string("Illegal call to ") + __func__, 
__FILE__, __LINE__);
+  throw InternalError(string("Illegal call to ") + __func__);
 }
 
 MeshTriangle* Mesh::get( size_t i ) {

Modified: trunk/Model/Groups/Mesh.h
==============================================================================
--- trunk/Model/Groups/Mesh.h   (original)
+++ trunk/Model/Groups/Mesh.h   Mon Nov 26 21:56:50 2007
@@ -3,7 +3,7 @@
 
 #include <Core/Geometry/Vector.h>
 #include <Core/Thread/Barrier.h>
-#include <SCIRun/Core/Thread/Mutex.h>
+#include <Core/Thread/Mutex.h>
 #include <Core/Geometry/BBox.h>
 #include <Interface/Material.h>
 #include <Interface/RayPacket.h>

Modified: trunk/Model/Groups/MovingMesh.cc
==============================================================================
--- trunk/Model/Groups/MovingMesh.cc    (original)
+++ trunk/Model/Groups/MovingMesh.cc    Mon Nov 26 21:56:50 2007
@@ -1,7 +1,7 @@
 #include <Model/Groups/MovingMesh.h>
 #include <Core/Util/Preprocessor.h>
 #include <Core/Util/UpdateGraph.h>
-#include <SCIRun/Core/Exceptions/InternalError.h>
+#include <Core/Exceptions/InternalError.h>
 #include <Interface/MeshTriangle.h>
 
 using namespace Manta;

Modified: trunk/Model/Groups/MovingMesh.h
==============================================================================
--- trunk/Model/Groups/MovingMesh.h     (original)
+++ trunk/Model/Groups/MovingMesh.h     Mon Nov 26 21:56:50 2007
@@ -3,7 +3,7 @@
 
 #include <Core/Geometry/Vector.h>
 #include <Core/Thread/Barrier.h>
-#include <SCIRun/Core/Thread/Mutex.h>
+#include <Core/Thread/Mutex.h>
 #include <Core/Geometry/BBox.h>
 #include <Interface/Material.h>
 #include <Interface/RayPacket.h>

Modified: trunk/Model/Groups/ObjGroup.cc
==============================================================================
--- trunk/Model/Groups/ObjGroup.cc      (original)
+++ trunk/Model/Groups/ObjGroup.cc      Mon Nov 26 21:56:50 2007
@@ -3,7 +3,7 @@
 #include <Interface/Texture.h>
 #include <Core/Color/Color.h>
 #include <Core/Color/ColorSpace.h>
-#include <SCIRun/Core/Exceptions/InternalError.h>
+#include <Core/Exceptions/InternalError.h>
 #include <Model/Groups/ObjGroup.h>
 #include <Model/Textures/Constant.h>
 #include <Model/Textures/ImageTexture.h>
@@ -51,7 +51,7 @@
           texture = it;
           texture_cache[tex_name] = texture;
         }
-        catch (SCIRun::Exception &e) {
+        catch (Exception &e) {
             std::cerr << "Could not load diffuse map: "
                       << file_name
                       << ": " << e.message() << std::endl;
@@ -219,7 +219,7 @@
     MovingKS_triangles = new MovingKSTriangle[model->numtriangles];
     break;
   default:
-    throw SCIRun::InternalError("Invalid triangle type", __FILE__, __LINE__);
+    throw InternalError("Invalid triangle type");
     break;
   }
 

Modified: trunk/Model/Groups/TimeSteppedParticles.h
==============================================================================
--- trunk/Model/Groups/TimeSteppedParticles.h   (original)
+++ trunk/Model/Groups/TimeSteppedParticles.h   Mon Nov 26 21:56:50 2007
@@ -4,7 +4,7 @@
 
 #include <MantaTypes.h>
 #include <Model/Groups/Group.h>
-#include <SCIRun/Core/Thread/Mailbox.h>
+#include <Core/Thread/Mailbox.h>
 
 #include <string>
 using std::string;

Modified: trunk/Model/Instances/Instance.cc
==============================================================================
--- trunk/Model/Instances/Instance.cc   (original)
+++ trunk/Model/Instances/Instance.cc   Mon Nov 26 21:56:50 2007
@@ -38,9 +38,7 @@
 #include <Core/Util/UpdateGraph.h>
 
 #include <iostream>
-#include <sgi_stl_warnings_off.h>
 #include <sstream>
-#include <sgi_stl_warnings_on.h>
 using namespace Manta;
 using namespace std;
 
@@ -263,7 +261,7 @@
 void Instance::setTexCoordMapper(const TexCoordMapper* new_tex)
 {
   string me(MANTA_FUNC);
-  throw SCIRun::InternalError(me + " shouldn't be called", __FILE__, 
__LINE__);
+  throw InternalError(me + " shouldn't be called");
 }
 
 void Instance::computeTexCoords2(const RenderContext& context,

Modified: trunk/Model/Instances/InstanceRST.cc
==============================================================================
--- trunk/Model/Instances/InstanceRST.cc        (original)
+++ trunk/Model/Instances/InstanceRST.cc        Mon Nov 26 21:56:50 2007
@@ -33,9 +33,7 @@
 #include <Core/Math/MiscMath.h>
 #include <Model/Instances/MPT.h>
 
-#include <sgi_stl_warnings_off.h>
 #include <sstream>
-#include <sgi_stl_warnings_on.h>
 
 using namespace Manta;
 using namespace std;
@@ -58,8 +56,8 @@
   
   scale = l1;
   inv_scale = 1/l1;
-  if(SCIRun::Abs(l1-l2)/SCIRun::Abs(l1) > (Real)1.e-10 ||
-     SCIRun::Abs(l1-l3)/SCIRun::Abs(l1) > (Real)1.e-10) {
+  if(Abs(l1-l2)/Abs(l1) > (Real)1.e-10 ||
+     Abs(l1-l3)/Abs(l1) > (Real)1.e-10) {
     ostringstream msg;
     msg << "Nonuniform scale for InstanceRST, scalefactor=[" << l1 << ' '
                  << l2 << ' ' << l3 << ']';

Modified: trunk/Model/Instances/InstanceRT.cc
==============================================================================
--- trunk/Model/Instances/InstanceRT.cc (original)
+++ trunk/Model/Instances/InstanceRT.cc Mon Nov 26 21:56:50 2007
@@ -32,10 +32,7 @@
 #include <Core/Exceptions/BadPrimitive.h>
 #include <Core/Geometry/BBox.h>
 #include <Core/Math/MiscMath.h>
-
-#include <sgi_stl_warnings_off.h>
 #include <sstream>
-#include <sgi_stl_warnings_on.h>
 
 using namespace Manta;
 using namespace std;
@@ -56,9 +53,9 @@
   Vector v3 = transform.multiply_vector(Vector(0,0,1));
   Real   l3 = v3.normalize();
 
-  if(SCIRun::Abs(l1-1) > (Real)1.e-7 ||
-     SCIRun::Abs(l2-1) > (Real)1.e-7 ||
-     SCIRun::Abs(l3-1) > (Real)1.e-7)
+  if(Abs(l1-1) > (Real)1.e-7 ||
+     Abs(l2-1) > (Real)1.e-7 ||
+     Abs(l3-1) > (Real)1.e-7)
     {
       ostringstream msg;
       msg << "Nonuniform scale for InstanceRT, scalefactor=[" << l1 << ' '

Modified: trunk/Model/Materials/AmbientOcclusion.cc
==============================================================================
--- trunk/Model/Materials/AmbientOcclusion.cc   (original)
+++ trunk/Model/Materials/AmbientOcclusion.cc   Mon Nov 26 21:56:50 2007
@@ -6,10 +6,9 @@
 #include <Interface/ShadowAlgorithm.h>
 #include <Model/Textures/Constant.h>
 #include <Core/Math/MT_RNG.h>
-#include <SCIRun/Core/Math/Trig.h>
+#include <Core/Math/Trig.h>
 
 using namespace Manta;
-using SCIRun::Sqrt;
 
 // TODO: sort the rays generated in generateDirections to make them more
 // coherent for ray packets.

Modified: trunk/Model/Materials/AmbientOcclusion.h
==============================================================================
--- trunk/Model/Materials/AmbientOcclusion.h    (original)
+++ trunk/Model/Materials/AmbientOcclusion.h    Mon Nov 26 21:56:50 2007
@@ -5,10 +5,7 @@
 #include <Core/Color/Color.h>
 #include <Interface/Texture.h>
 #include <Core/Geometry/Vector.h>
-
-#include <sgi_stl_warnings_off.h>
 #include <vector>
-#include <sgi_stl_warnings_on.h>
 
 namespace Manta
 {

Modified: trunk/Model/Materials/Dielectric.cc
==============================================================================
--- trunk/Model/Materials/Dielectric.cc (original)
+++ trunk/Model/Materials/Dielectric.cc Mon Nov 26 21:56:50 2007
@@ -43,7 +43,6 @@
 
 #include <iostream>
 using namespace Manta;
-using namespace SCIRun;
 using std::cerr;
 
 Dielectric::Dielectric(const Texture<Real>* n, const Texture<Real>* nt,

Modified: trunk/Model/Materials/Lambertian.cc
==============================================================================
--- trunk/Model/Materials/Lambertian.cc (original)
+++ trunk/Model/Materials/Lambertian.cc Mon Nov 26 21:56:50 2007
@@ -43,7 +43,6 @@
 #include <Model/Textures/Constant.h>
 #include <iostream>
 using namespace Manta;
-using namespace SCIRun;
 using std::cerr;
 
 Lambertian::Lambertian(const Color& color)
@@ -65,7 +64,7 @@
   int debugFlag = rays.getAllFlags() & RayPacket::DebugPacket;
   if (debugFlag) {
     cerr << "Lambertian::shade called (rays["<<rays.begin()<<", 
"<<rays.end()<<"])\n";
-    //    cerr << SCIRun::getStackTrace();
+    //    cerr << getStackTrace();
   }
   // Shade a bunch of rays.  We know that they all have the same intersected
   // object and are all of the same material

Modified: trunk/Model/Materials/OrenNayar.cc
==============================================================================
--- trunk/Model/Materials/OrenNayar.cc  (original)
+++ trunk/Model/Materials/OrenNayar.cc  Mon Nov 26 21:56:50 2007
@@ -37,7 +37,7 @@
 #include <Model/Textures/Constant.h>
 #include <iostream>
 #include <math.h>
-#include <SCIRun/Core/Math/MinMax.h>
+#include <Core/Math/MinMax.h>
 using namespace Manta;
 using std::cerr;
 
@@ -63,7 +63,7 @@
   int debugFlag = rays.getAllFlags() & RayPacket::DebugPacket;
   if (debugFlag) {
     cerr << "OrenNayar::shade called (rays["<<rays.begin()<<", 
"<<rays.end()<<"])\n";
-    //    cerr << SCIRun::getStackTrace();
+    //    cerr << getStackTrace();
   }
   // Shade a bunch of rays.  We know that they all have the same intersected
   // object and are all of the same material

Modified: trunk/Model/Materials/Phong.cc
==============================================================================
--- trunk/Model/Materials/Phong.cc      (original)
+++ trunk/Model/Materials/Phong.cc      Mon Nov 26 21:56:50 2007
@@ -87,7 +87,7 @@
   speculartex = new Constant<Color>(specular);
   refltex = new Constant<ColorComponent>(refl);
   do_refl = (refl != 0);
-  highlight_threshold = SCIRun::Pow(COLOR_EPSILON, 1./specpow);
+  highlight_threshold = Pow(COLOR_EPSILON, 1.f/specpow);
   highlight_threshold = 0;
 }
 
@@ -106,7 +106,7 @@
   } else {
     do_refl = false;
   }
-  highlight_threshold = SCIRun::Pow(COLOR_EPSILON, 1./specpow);
+  highlight_threshold = Pow(COLOR_EPSILON, 1.f/specpow);
   highlight_threshold = 0;
 }
 
@@ -119,7 +119,7 @@
   int debugFlag = rays.getAllFlags() & RayPacket::DebugPacket;
   if (debugFlag) {
     cerr << "Phong::shade called\n";
-    //    cerr << SCIRun::getStackTrace();
+    //    cerr << getStackTrace();
   }
   // Shade a bunch of rays.  We know that they all have the same intersected
   // object and are all of the same material

Modified: trunk/Model/Materials/ThinDielectric.cc
==============================================================================
--- trunk/Model/Materials/ThinDielectric.cc     (original)
+++ trunk/Model/Materials/ThinDielectric.cc     Mon Nov 26 21:56:50 2007
@@ -43,7 +43,6 @@
 
 #include <iostream>
 using namespace Manta;
-using namespace SCIRun;
 using std::cerr;
 
 ThinDielectric::ThinDielectric(Real eta, const Color& sigma_a,

Modified: trunk/Model/MiscObjects/CuttingPlane.cc
==============================================================================
--- trunk/Model/MiscObjects/CuttingPlane.cc     (original)
+++ trunk/Model/MiscObjects/CuttingPlane.cc     Mon Nov 26 21:56:50 2007
@@ -3,10 +3,7 @@
 #include <Model/MiscObjects/CuttingPlane.h>
 #include <Model/Intersections/AxisAlignedBox.h>
 #include <Model/Intersections/Plane.h>
-
-#include <sgi_stl_warnings_off.h>
 #include <iostream>
-#include <sgi_stl_warnings_on.h>
 
 
 using namespace Manta;

Modified: trunk/Model/MiscObjects/Difference.cc
==============================================================================
--- trunk/Model/MiscObjects/Difference.cc       (original)
+++ trunk/Model/MiscObjects/Difference.cc       Mon Nov 26 21:56:50 2007
@@ -4,12 +4,11 @@
 #include <Core/Exceptions/InternalError.h>
 
 using namespace Manta;
-using SCIRun::InternalError;
 
 Difference::Difference(Object* object1, Object* object2)
   : object1(object1), object2(object2)
 {
-  throw InternalError("Difference not yet implemented", __FILE__, __LINE__ );
+  throw InternalError("Difference not yet implemented");
 }
 
 Difference::~Difference()

Modified: trunk/Model/MiscObjects/KeyFrameAnimation.cc
==============================================================================
--- trunk/Model/MiscObjects/KeyFrameAnimation.cc        (original)
+++ trunk/Model/MiscObjects/KeyFrameAnimation.cc        Mon Nov 26 21:56:50 
2007
@@ -1,7 +1,7 @@
 #include <Model/MiscObjects/KeyFrameAnimation.h>
 #include <Interface/Context.h>
 #include <Interface/MantaInterface.h>
-#include <SCIRun/Core/Thread/Time.h>
+#include <Core/Thread/Time.h>
 #include <Core/Util/UpdateGraph.h>
 
 #include <assert.h>
@@ -47,7 +47,7 @@
 
 void KeyFrameAnimation::startAnimation()
 {
-  startTime = SCIRun::Time::currentSeconds();
+  startTime = Time::currentSeconds();
   paused = false;
 
   if (spareGroup == NULL && interpolation != truncate && !frames.empty()) {
@@ -63,14 +63,14 @@
 void KeyFrameAnimation::pauseAnimation()
 {
   if (!paused)
-    pauseTime = SCIRun::Time::currentSeconds();
+    pauseTime = Time::currentSeconds();
   paused = true;
 }
 
 void KeyFrameAnimation::resumeAnimation()
 {
   if (paused)
-    startTime += SCIRun::Time::currentSeconds() - pauseTime;
+    startTime += Time::currentSeconds() - pauseTime;
   paused = false;
 }
 
@@ -200,7 +200,7 @@
   Temp_Callback context;
   context.proc = proc;
   context.numProcs = numProcs;
-  context.time = SCIRun::Time::currentSeconds();
+  context.time = Time::currentSeconds();
   update(context);
   changed = differentFrame;
 }

Modified: trunk/Model/MiscObjects/KeyFrameAnimation.h
==============================================================================
--- trunk/Model/MiscObjects/KeyFrameAnimation.h (original)
+++ trunk/Model/MiscObjects/KeyFrameAnimation.h Mon Nov 26 21:56:50 2007
@@ -3,7 +3,7 @@
 
 #include <Interface/AccelerationStructure.h>
 #include <Model/Groups/Group.h>
-#include <SCIRun/Core/Thread/Barrier.h>
+#include <Core/Thread/Barrier.h>
 
 namespace Manta {
   struct Temp_Callback {int proc, numProcs;
@@ -79,7 +79,7 @@
 
     bool paused;
 
-    SCIRun::Barrier barrier;
+    Barrier barrier;
     bool differentFrame; //used by setTime()
 
     vector<Group*> frames;

Modified: trunk/Model/Primitives/BumpPrimitive.cc
==============================================================================
--- trunk/Model/Primitives/BumpPrimitive.cc     (original)
+++ trunk/Model/Primitives/BumpPrimitive.cc     Mon Nov 26 21:56:50 2007
@@ -6,7 +6,6 @@
 #include <Core/Math/MiscMath.h>
 #include <Core/Math/Trig.h>
 
-using namespace SCIRun;
 using namespace Manta;
 using namespace std;
 

Modified: trunk/Model/Primitives/Cone.cc
==============================================================================
--- trunk/Model/Primitives/Cone.cc      (original)
+++ trunk/Model/Primitives/Cone.cc      Mon Nov 26 21:56:50 2007
@@ -5,7 +5,6 @@
 #include <Core/Math/Expon.h>
 
 using namespace Manta;
-using namespace SCIRun;
 using namespace std;
 
 Cone::Cone(Material* mat, Real radius, Real height)

Modified: trunk/Model/Primitives/Cube.cc
==============================================================================
--- trunk/Model/Primitives/Cube.cc      (original)
+++ trunk/Model/Primitives/Cube.cc      Mon Nov 26 21:56:50 2007
@@ -8,7 +8,6 @@
 
 using namespace Manta;
 using namespace std;
-using SCIRun::Abs;
 
 Cube::Cube(Material* mat, const Vector& p0, const Vector& p1)
   : PrimitiveCommon(mat)

Modified: trunk/Model/Primitives/Cylinder.cc
==============================================================================
--- trunk/Model/Primitives/Cylinder.cc  (original)
+++ trunk/Model/Primitives/Cylinder.cc  Mon Nov 26 21:56:50 2007
@@ -6,7 +6,6 @@
 #include <Core/Math/Expon.h>
 
 using namespace Manta;
-using namespace SCIRun;
 using namespace std;
 
 Cylinder::Cylinder(Material* mat, const Vector& bottom, const Vector& top,

Modified: trunk/Model/Primitives/GridSpheres.cc
==============================================================================
--- trunk/Model/Primitives/GridSpheres.cc       (original)
+++ trunk/Model/Primitives/GridSpheres.cc       Mon Nov 26 21:56:50 2007
@@ -13,9 +13,9 @@
 #include <Interface/ShadowAlgorithm.h>
 #include <Model/Primitives/GridSpheres.h>
 #include <Model/Textures/Constant.h>
-#include <SCIRun/Core/Containers/Array1.h>
-#include <SCIRun/Core/Math/MinMax.h>
-#include <SCIRun/Core/Util/Timer.h>
+#include <Core/Containers/Array1.h>
+#include <Core/Math/MinMax.h>
+#include <Core/Util/Timer.h>
 
 #include <iostream>
 using std::cerr;
@@ -23,7 +23,6 @@
 #include <float.h>
 
 using namespace Manta;
-using namespace SCIRun;
 
 GridSpheres::GridSpheres(float* spheres, int nspheres, int nvars, int ncells,
                          int depth, Real radius, int ridx, RegularColorMap* 
cmap,
@@ -59,8 +58,8 @@
   float* data=spheres;
   for (int i=0; i<nspheres; ++i) {
     for (int j=0; j<nvars; ++j) {
-      min[j]=SCIRun::Min(min[j], data[j]);
-      max[j]=SCIRun::Max(max[j], data[j]);
+      min[j]=Min(min[j], data[j]);
+      max[j]=Max(max[j], data[j]);
     }
 
     data += nvars;
@@ -985,7 +984,7 @@
     float minimum=min[cidx];
     float normalized=(value - minimum)/(max[cidx] - minimum);
     int ncolors=cmap->blended.size() - 1;
-    int idx=SCIRun::Clamp(static_cast<int>(ncolors*normalized), 0, ncolors);
+    int idx=Clamp(static_cast<int>(ncolors*normalized), 0, ncolors);
     diffuse.set(i, cmap->blended[idx]);
   }
 }

Modified: trunk/Model/Primitives/Heightfield.cc
==============================================================================
--- trunk/Model/Primitives/Heightfield.cc       (original)
+++ trunk/Model/Primitives/Heightfield.cc       Mon Nov 26 21:56:50 2007
@@ -4,14 +4,11 @@
 #include <Core/Exceptions/InternalError.h>
 #include <Core/Geometry/BBox.h>
 #include <Core/Geometry/Vector.h>
-
+#include <Core/Util/Assert.h>
 
 #include <limits>
-#include <sgi_stl_warnings_off.h>
 #include <fstream>
 #include <iostream>
-#include <sgi_stl_warnings_on.h>
-#include <assert.h>
 
 using namespace Manta;
 using namespace std;
@@ -27,14 +24,12 @@
   cout << "\n\nbounds are: " << minBound << " " <<maxBound<<endl;
   ifstream in(filename.c_str());
   if(!in){
-    throw SCIRun::InternalError("Error opening " + filename, 
-                                __FILE__, __LINE__); 
+    throw InternalError("Error opening " + filename);
   }
   Real minz, maxz;
   in >> nx >> ny >> minz >> maxz;
   if(!in){
-    throw SCIRun::InternalError("Error reading header from " + filename,
-                                __FILE__, __LINE__); 
+    throw InternalError("Error reading header from " + filename);
   }
   in.get();
   data = new float*[nx+1];
@@ -43,8 +38,7 @@
     data[i] = p+i*(ny+1);
   in.read(reinterpret_cast<char*>(data[0]), sizeof(float)*(nx+1)*(ny+1));
   if(!in){
-    throw SCIRun::InternalError("Error reading data from " + filename,
-                                __FILE__, __LINE__); 
+    throw InternalError("Error reading data from " + filename);
   }
   Real dz = maxz-minz;
   if(dz < 1.e-3)
@@ -103,7 +97,7 @@
                                  int proc, int numProc)
 {
   //TODO: Parallelize this
-  assert(!keyframes.empty());
+  ASSERT(!keyframes.empty());
 
   Heightfield *heightfields[keyframes.size()];
 
@@ -114,8 +108,8 @@
     heightfields[frame] = h;
 
     if (frame>0) {
-      assert(h->nx == heightfields[0]->nx);
-      assert(h->ny == heightfields[0]->ny);
+      ASSERT(h->nx == heightfields[0]->nx);
+      ASSERT(h->ny == heightfields[0]->ny);
     }
   }
 
@@ -232,8 +226,8 @@
     int stopy = signy>0?ny:-1;
 
     // Step 5
-    Real dtdx = SCIRun::Abs(cellsize.x()/ray.direction().x());
-    Real dtdy = SCIRun::Abs(cellsize.y()/ray.direction().y());
+    Real dtdx = Abs(cellsize.x()/ray.direction().x());
+    Real dtdy = Abs(cellsize.y()/ray.direction().y());
 
     // Step 6
     Real far_x;
@@ -253,18 +247,18 @@
 
     // Step 8
     Real zenter = ray.origin().z() + tnear * ray.direction().z();
-    tfar = SCIRun::Min((Real)tfar, rays.getMinT(rayIndex));
+    tfar = Min((Real)tfar, rays.getMinT(rayIndex));
     while(tnear < tfar) {
-      Real texit = SCIRun::Min(tnext_x, tnext_y);
+      Real texit = Min(tnext_x, tnext_y);
       Real zexit = ray.origin().z() + texit * ray.direction().z();
 
       // Step 9
-      float datamin = SCIRun::Min(SCIRun::Min(data[Lx][Ly], data[Lx+1][Ly]), 
-                                  SCIRun::Min(data[Lx][Ly+1], 
data[Lx+1][Ly+1]));
-      float datamax = SCIRun::Max(SCIRun::Max(data[Lx][Ly], data[Lx+1][Ly]),
-                                  SCIRun::Max(data[Lx][Ly+1], 
data[Lx+1][Ly+1]));
-      float zmin = SCIRun::Min(zenter, zexit);
-      float zmax = SCIRun::Max(zenter, zexit);
+      float datamin = Min(Min(data[Lx][Ly], data[Lx+1][Ly]), 
+                                  Min(data[Lx][Ly+1], data[Lx+1][Ly+1]));
+      float datamax = Max(Max(data[Lx][Ly], data[Lx+1][Ly]),
+                                  Max(data[Lx][Ly+1], data[Lx+1][Ly+1]));
+      float zmin = Min(zenter, zexit);
+      float zmax = Max(zenter, zexit);
       if(zmin < datamax && zmax > datamin){
         // Step 10
         Vector C = m_Box.getMin() + Vector(Lx, Ly, 0)*cellsize;
@@ -282,7 +276,7 @@
         Real a = Vx*Vy*zd;
         Real b = -Vz + Vx*zb + Vy*zc + (Ex*Vy + Ey*Vx)*zd;
         Real c = -Ez + za + Ex*zb + Ey*zc + Ex*Ey*zd;
-        if(SCIRun::Abs(a) < 1.e-6){
+        if(Abs(a) < 1.e-6){
           // Linear
           Real tcell = -c/b;
           if(tcell > 0 && tnear+tcell < texit){
@@ -372,8 +366,8 @@
 // // 
--------------------------------------------------------------------------------------
 // void Heightfield::rescaleDataHeight(Real scale)
 // {
-//   using SCIRun::Min;
-//   using SCIRun::Max;
+//   using Min;
+//   using Max;
 
 //   unsigned int i, j;
 //   Real min, max, factor, margin;

Modified: trunk/Model/Primitives/Heightfield.h
==============================================================================
--- trunk/Model/Primitives/Heightfield.h        (original)
+++ trunk/Model/Primitives/Heightfield.h        Mon Nov 26 21:56:50 2007
@@ -8,7 +8,7 @@
 #include <Interface/Clonable.h>
 #include <Model/MiscObjects/KeyFrameAnimation.h>
 #include <Model/Primitives/PrimitiveCommon.h>
-#include <SCIRun/Core/Thread/Mutex.h>
+#include <Core/Thread/Mutex.h>
 
 namespace Manta {
 
@@ -43,8 +43,8 @@
     Vector cellsize;
     Vector inv_cellsize;
 
-    SCIRun::Barrier barrier;
-    SCIRun::Mutex mutex;
+    Barrier barrier;
+    Mutex mutex;
 
     Heightfield() : barrier("heightfield barrier"), mutex("heightfield 
mutex"){ };
 

Modified: trunk/Model/Primitives/Hemisphere.cc
==============================================================================
--- trunk/Model/Primitives/Hemisphere.cc        (original)
+++ trunk/Model/Primitives/Hemisphere.cc        Mon Nov 26 21:56:50 2007
@@ -9,7 +9,6 @@
 // TODO: tighter bounds
 
 using namespace Manta;
-using namespace SCIRun;
 using namespace std;
 
 Hemisphere::Hemisphere(Material* material, const Vector& center,

Modified: trunk/Model/Primitives/IsosurfaceGridVolume.cc
==============================================================================
--- trunk/Model/Primitives/IsosurfaceGridVolume.cc      (original)
+++ trunk/Model/Primitives/IsosurfaceGridVolume.cc      Mon Nov 26 21:56:50 
2007
@@ -7,7 +7,6 @@
 
 using namespace std;
 using namespace Manta;
-using namespace SCIRun;
 
 IsosurfaceGridVolume::IsosurfaceGridVolume(char* filebase, int _mc_depth, 
double isovalue, Material* _matl)
 : PrimitiveCommon(_matl), isoval((ST)isovalue)

Modified: trunk/Model/Primitives/IsosurfaceGridVolume.h
==============================================================================
--- trunk/Model/Primitives/IsosurfaceGridVolume.h       (original)
+++ trunk/Model/Primitives/IsosurfaceGridVolume.h       Mon Nov 26 21:56:50 
2007
@@ -3,7 +3,7 @@
 #define _MANTA_ISOSURFACEGRIDVOLUME_H_
 
 #include <Model/Primitives/PrimitiveCommon.h>
-#include <SCIRun/Core/Containers/Array3.h>
+#include <Core/Containers/Array3.h>
 #include <Model/MiscObjects/BrickArray3.h>
 #include <Core/Geometry/Vector.h>
 #include <Core/Geometry/BBox.h>

Modified: trunk/Model/Primitives/KenslerShirleyTriangle.cc
==============================================================================
--- trunk/Model/Primitives/KenslerShirleyTriangle.cc    (original)
+++ trunk/Model/Primitives/KenslerShirleyTriangle.cc    Mon Nov 26 21:56:50 
2007
@@ -3,10 +3,8 @@
 #include <Interface/RayPacket.h>
 #include <Core/Geometry/BBox.h>
 #include <Core/Util/Preprocessor.h>
-#include <SCIRun/Core/Util/Assert.h>
-#include <sgi_stl_warnings_off.h>
+#include <Core/Util/Assert.h>
 #include <iostream>
-#include <sgi_stl_warnings_on.h>
 
 using namespace Manta;
 using namespace std;

Modified: trunk/Model/Primitives/MovingKSTriangle.cc
==============================================================================
--- trunk/Model/Primitives/MovingKSTriangle.cc  (original)
+++ trunk/Model/Primitives/MovingKSTriangle.cc  Mon Nov 26 21:56:50 2007
@@ -3,10 +3,8 @@
 #include <Interface/RayPacket.h>
 #include <Core/Geometry/BBox.h>
 #include <Core/Util/Preprocessor.h>
-#include <SCIRun/Core/Util/Assert.h>
-#include <sgi_stl_warnings_off.h>
+#include <Core/Util/Assert.h>
 #include <iostream>
-#include <sgi_stl_warnings_on.h>
 
 using namespace Manta;
 using namespace std;

Modified: trunk/Model/Primitives/OctreeVolume.cc
==============================================================================
--- trunk/Model/Primitives/OctreeVolume.cc      (original)
+++ trunk/Model/Primitives/OctreeVolume.cc      Mon Nov 26 21:56:50 2007
@@ -15,7 +15,6 @@
 #include <Core/Util/LargeFile.h>
 
 using namespace Manta;
-using namespace SCIRun;
 
 #define START_ISOVAL 20
 

Modified: trunk/Model/Primitives/OctreeVolume.h
==============================================================================
--- trunk/Model/Primitives/OctreeVolume.h       (original)
+++ trunk/Model/Primitives/OctreeVolume.h       Mon Nov 26 21:56:50 2007
@@ -39,7 +39,7 @@
 //#define OCTVOL_DYNAMIC_MULTIRES
 
 #include <Core/Geometry/BBox.h>
-#include <SCIRun/Core/Containers/Array3.h>
+#include <Core/Containers/Array3.h>
 #include <Core/Geometry/vecdefs.h>
 #include <Core/Geometry/Vector.h>
 #include <stdlib.h>
@@ -453,7 +453,7 @@
             the build process could be made faster by just unrolling loops. 
Parallelizing it would also be
             desirable.
         */
-        void make_from_single_res_data(SCIRun::Array3<ST>& originalData, 
+        void make_from_single_res_data(Array3<ST>& originalData, 
                                         int ts, 
                                         double variance_threshold, 
                                         int kernelWidth, 

Modified: trunk/Model/Primitives/Parallelogram.cc
==============================================================================
--- trunk/Model/Primitives/Parallelogram.cc     (original)
+++ trunk/Model/Primitives/Parallelogram.cc     Mon Nov 26 21:56:50 2007
@@ -11,7 +11,6 @@
 #include <Interface/SampleGenerator.h>
 
 using namespace Manta;
-using SCIRun::Abs;
 
 #define USE_SCRATCHPAD 0
 

Modified: trunk/Model/Primitives/Plane.cc
==============================================================================
--- trunk/Model/Primitives/Plane.cc     (original)
+++ trunk/Model/Primitives/Plane.cc     Mon Nov 26 21:56:50 2007
@@ -34,7 +34,6 @@
 
 using namespace Manta;
 using namespace std;
-//using SCIRun::Clamp;
 
 Plane::Plane(Material* material, const Vector& normal, const Vector& center):
   PrimitiveCommon(material), normal(normal), center(center)

Modified: trunk/Model/Primitives/Ring.cc
==============================================================================
--- trunk/Model/Primitives/Ring.cc      (original)
+++ trunk/Model/Primitives/Ring.cc      Mon Nov 26 21:56:50 2007
@@ -29,7 +29,7 @@
 #include <Model/Primitives/Ring.h>
 #include <Interface/RayPacket.h>
 #include <Core/Geometry/BBox.h>
-#include <SCIRun/Core/Math/Expon.h>
+#include <Core/Math/Expon.h>
 
 using namespace Manta;
 using namespace std;
@@ -51,7 +51,7 @@
 
 void Ring::computeBounds(const PreprocessContext&, BBox& bbox) const
 {
-  bbox.extendByDisc(center, normal, SCIRun::Sqrt(outer_radius2));
+  bbox.extendByDisc(center, normal, Sqrt(outer_radius2));
 }
 
 void Ring::intersect(const RenderContext&, RayPacket& rays) const

Modified: trunk/Model/Primitives/Sphere.cc
==============================================================================
--- trunk/Model/Primitives/Sphere.cc    (original)
+++ trunk/Model/Primitives/Sphere.cc    Mon Nov 26 21:56:50 2007
@@ -12,7 +12,6 @@
 #include <MantaSSE.h>
 
 using namespace Manta;
-using namespace SCIRun;
 using namespace std;
 
 Sphere::Sphere()

Modified: trunk/Model/Primitives/SuperEllipsoid.cc
==============================================================================
--- trunk/Model/Primitives/SuperEllipsoid.cc    (original)
+++ trunk/Model/Primitives/SuperEllipsoid.cc    Mon Nov 26 21:56:50 2007
@@ -4,13 +4,9 @@
 #include <Core/Math/MinMax.h>
 #include <Core/Math/MiscMath.h>
 #include <Core/Math/Trig.h>
-
-#include <sgi_stl_warnings_off.h>
 #include <iostream>
-#include <sgi_stl_warnings_on.h>
 
 using namespace std;
-using namespace SCIRun;
 using namespace Manta;
 
 static const Real golden_mean = static_cast< Real >( 0.61803398874989484820 
);
@@ -40,20 +36,20 @@
 inline Real SuperEllipsoid::functionValue(
   Vector const &location ) const
 {
-  Real x_power = SCIRun::Pow( SCIRun::Abs( location.x() ), two_over_alpha );
-  Real y_power = SCIRun::Pow( SCIRun::Abs( location.y() ), two_over_alpha );
-  Real z_power = SCIRun::Pow( SCIRun::Abs( location.z() ), two_over_beta );
-  return SCIRun::Pow( x_power + y_power, alpha_over_beta ) + z_power - 1;
+  Real x_power = Pow( Abs( location.x() ), two_over_alpha );
+  Real y_power = Pow( Abs( location.y() ), two_over_alpha );
+  Real z_power = Pow( Abs( location.z() ), two_over_beta );
+  return Pow( x_power + y_power, alpha_over_beta ) + z_power - 1;
 }
 
 inline Vector SuperEllipsoid::functionGradient(
   Vector const &location,
   Real &value ) const
 {
-  Real x_power = SCIRun::Pow( SCIRun::Abs(location.x() ), two_over_alpha );
-  Real y_power = SCIRun::Pow( SCIRun::Abs(location.y() ), two_over_alpha );
-  Real z_power = SCIRun::Pow( SCIRun::Abs(location.z() ), two_over_beta );
-  Real x_and_y_power = SCIRun::Pow( x_power + y_power, alpha_over_beta - 1 );
+  Real x_power = Pow( Abs(location.x() ), two_over_alpha );
+  Real y_power = Pow( Abs(location.y() ), two_over_alpha );
+  Real z_power = Pow( Abs(location.z() ), two_over_beta );
+  Real x_and_y_power = Pow( x_power + y_power, alpha_over_beta - 1 );
   value = x_and_y_power * ( x_power + y_power ) + z_power - 1;
   return Vector( two_over_beta * x_and_y_power * x_power / location.x(),
                  two_over_beta * x_and_y_power * y_power / location.y(),
@@ -64,14 +60,14 @@
   Vector const &location,
   Real &value ) const
 {
-  Real x_power = SCIRun::Pow( SCIRun::Abs(location.x() ), two_over_alpha );
-  Real y_power = SCIRun::Pow( SCIRun::Abs(location.y() ), two_over_alpha );
-  Real z_power = SCIRun::Pow( SCIRun::Abs(location.z() ), two_over_beta );
-  Real x_and_y_power = ( SCIRun::Pow( x_power + y_power, 1 - alpha_over_beta 
) * z_power + x_power + y_power );
-  value = log( SCIRun::Pow( x_power + y_power, alpha_over_beta ) + z_power );
+  Real x_power = Pow( Abs(location.x() ), two_over_alpha );
+  Real y_power = Pow( Abs(location.y() ), two_over_alpha );
+  Real z_power = Pow( Abs(location.z() ), two_over_beta );
+  Real x_and_y_power = ( Pow( x_power + y_power, 1 - alpha_over_beta ) * 
z_power + x_power + y_power );
+  value = log( Pow( x_power + y_power, alpha_over_beta ) + z_power );
   return Vector( two_over_beta * x_power / ( location.x() * x_and_y_power ),
                  two_over_beta * y_power / ( location.y() * x_and_y_power ),
-                 two_over_beta / ( location.z() * ( 1 + SCIRun::Pow( x_power 
+ y_power, alpha_over_beta ) / z_power ) ) );
+                 two_over_beta / ( location.z() * ( 1 + Pow( x_power + 
y_power, alpha_over_beta ) / z_power ) ) );
 }
 
 void SuperEllipsoid::computeBounds(
@@ -110,8 +106,6 @@
       t1 = t2;
       t2 = temp;
     }
-    using SCIRun::Max;
-    using SCIRun::Min;
     tnear = Max( t1, tnear );
     tfar = Min( t2, tfar );
     t1 = ( -radius - offset_center.z() ) * inverseDirection.z();
@@ -151,7 +145,7 @@
       Real right = ( 1 - golden_mean ) * a_bracket + golden_mean * b_bracket;
       Real right_value = functionValue( ( offset_center + right * rayD )
                                         * inv_radius );
-      while( SCIRun::Abs( b_bracket - a_bracket ) > bracket_width ) {
+      while( Abs( b_bracket - a_bracket ) > bracket_width ) {
         if ( left_value < right_value ) {
           b_bracket = right;
           right = left;
@@ -198,8 +192,8 @@
                                       * inv_radius, root_value ),
            rayD );
     int iterations = 0;
-    while ( SCIRun::Abs( tfar - tnear ) >= (Real)T_EPSILON &&
-            SCIRun::Abs( root_value ) >= (Real)T_EPSILON &&
+    while ( Abs( tfar - tnear ) >= (Real)T_EPSILON &&
+            Abs( root_value ) >= (Real)T_EPSILON &&
             ++iterations < max_newton_iter ) {
       if ( root_value * near_value < 0 ) {
         tfar = troot;

Modified: trunk/Model/Primitives/Torus.cc
==============================================================================
--- trunk/Model/Primitives/Torus.cc     (original)
+++ trunk/Model/Primitives/Torus.cc     Mon Nov 26 21:56:50 2007
@@ -4,7 +4,6 @@
 #include <Core/Math/Expon.h>
 
 using namespace Manta;
-using namespace SCIRun;
 using namespace std;
 
 

Modified: trunk/Model/Primitives/WaldTriangle.cc
==============================================================================
--- trunk/Model/Primitives/WaldTriangle.cc      (original)
+++ trunk/Model/Primitives/WaldTriangle.cc      Mon Nov 26 21:56:50 2007
@@ -3,9 +3,7 @@
 #include <Interface/RayPacket.h>
 #include <Core/Geometry/BBox.h>
 #include <Core/Util/Preprocessor.h>
-#include <sgi_stl_warnings_off.h>
 #include <iostream>
-#include <sgi_stl_warnings_on.h>
 
 using namespace Manta;
 using namespace std;

Modified: trunk/Model/Readers/ParticleNRRD.cc
==============================================================================
--- trunk/Model/Readers/ParticleNRRD.cc (original)
+++ trunk/Model/Readers/ParticleNRRD.cc Mon Nov 26 21:56:50 2007
@@ -4,9 +4,7 @@
 
 #include <teem/nrrd.h>
 
-#include <sgi_stl_warnings_off.h>
 #include <iostream>
-#include <sgi_stl_warnings_on.h>
 
 using namespace Manta;
 using namespace std;

Modified: trunk/Model/Readers/PlyReader.cc
==============================================================================
--- trunk/Model/Readers/PlyReader.cc    (original)
+++ trunk/Model/Readers/PlyReader.cc    Mon Nov 26 21:56:50 2007
@@ -7,12 +7,9 @@
 #include <Core/Geometry/Vector.h>
 #include <Core/Color/Color.h>
 #include <Core/Color/RGBColor.h>
-#include <SCIRun/Core/Exceptions/FileNotFound.h>
+#include <Core/Exceptions/FileNotFound.h>
 #include <Model/Readers/rply/rply.h>
-
-#include <sgi_stl_warnings_off.h>
 #include <sstream>
-#include <sgi_stl_warnings_on.h>
 
 #include <stdlib.h>
 
@@ -153,7 +150,7 @@
      {
          ostringstream msg;
          msg << "An error occured while trying to load the following ply 
file: " << fileName;
-         throw SCIRun::FileNotFound(msg.str(), __FILE__, __LINE__);
+         throw FileNotFound(msg.str());
      }
 
      

Modified: trunk/Model/Readers/PlyReader.h
==============================================================================
--- trunk/Model/Readers/PlyReader.h     (original)
+++ trunk/Model/Readers/PlyReader.h     Mon Nov 26 21:56:50 2007
@@ -5,10 +5,7 @@
 #include <Core/Geometry/AffineTransform.h>
 #include <Model/Groups/Mesh.h>
 #include <Interface/MeshTriangle.h>
-
-#include <sgi_stl_warnings_off.h>
 #include <string>
-#include <sgi_stl_warnings_on.h>
 
 namespace Manta {
 

Modified: trunk/Model/Readers/V3C1.cc
==============================================================================
--- trunk/Model/Readers/V3C1.cc (original)
+++ trunk/Model/Readers/V3C1.cc Mon Nov 26 21:56:50 2007
@@ -31,13 +31,12 @@
 #include <Core/Util/Endian.h>
 #include <Core/Exceptions/InputError.h>
 
-#include <SCIRun/Core/Containers/Array1.h>
-#include <SCIRun/Core/Exceptions/ErrnoException.h>
+#include <Core/Containers/Array1.h>
+#include <Core/Exceptions/ErrnoException.h>
 
 #include <string>
 #include <errno.h>
 
-using namespace SCIRun;
 using namespace std;
 
 using namespace Manta;
@@ -71,8 +70,7 @@
   // Attempt to open the input file.
   FILE *file;
   if ((file = fopen( prefix.c_str(), "rb" )) == 0) {
-    throw ErrnoException( "Error opening .v3c1 file.", errno,
-                          __FILE__, __LINE__ );
+    throw ErrnoException( "Error opening .v3c1 file.", errno, __FILE__, 
__LINE__);
   }
   
   // Determine input file size.

Modified: trunk/Model/Readers/V3C1.h
==============================================================================
--- trunk/Model/Readers/V3C1.h  (original)
+++ trunk/Model/Readers/V3C1.h  Mon Nov 26 21:56:50 2007
@@ -36,8 +36,8 @@
 #include <Core/Color/Color.h>
 #include <Core/Geometry/VectorT.h>
 
-#include <SCIRun/Core/Util/Assert.h>
-#include <SCIRun/Core/Containers/Array1.h>
+#include <Core/Util/Assert.h>
+#include <Core/Containers/Array1.h>
 
 #include <string>
 
@@ -81,8 +81,8 @@
   // Load data into arrays of corresponding type and correct endianness if
   // necessary.
   
-  extern "C" void v3c1_load_triangles( SCIRun::Array1<V3C1Triangle> &array, 
const std::string &prefix );
-  extern "C" void v3c1_load_normals  ( SCIRun::Array1<V3C1Normal>   &array, 
const std::string &prefix );
+  extern "C" void v3c1_load_triangles( Array1<V3C1Triangle> &array, const 
std::string &prefix );
+  extern "C" void v3c1_load_normals  ( Array1<V3C1Normal>   &array, const 
std::string &prefix );
     
 };
 

Modified: trunk/Model/TexCoordMappers/SphericalMapper.cc
==============================================================================
--- trunk/Model/TexCoordMappers/SphericalMapper.cc      (original)
+++ trunk/Model/TexCoordMappers/SphericalMapper.cc      Mon Nov 26 21:56:50 
2007
@@ -5,7 +5,6 @@
 #include <Core/Math/Trig.h>
 
 using namespace Manta;
-using SCIRun::Clamp;
 
 SphericalMapper::SphericalMapper(const Vector& center, Real radius)
   : center(center), radius(radius)

Modified: trunk/Model/Textures/CloudTexture.h
==============================================================================
--- trunk/Model/Textures/CloudTexture.h (original)
+++ trunk/Model/Textures/CloudTexture.h Mon Nov 26 21:56:50 2007
@@ -103,7 +103,7 @@
       value=value*(Real)0.5+(Real)0.5;
       value=value*density;
       value=value*(Real)0.5+(Real)0.5;
-      results.set(i, (SCIRun::Interpolate( skycolor, Color::white(), 
value))+Color::white());
+      results.set(i, (Interpolate( skycolor, Color::white(), 
value))+Color::white());
     
     }
   }

Modified: trunk/Model/Textures/ColorMap.cc
==============================================================================
--- trunk/Model/Textures/ColorMap.cc    (original)
+++ trunk/Model/Textures/ColorMap.cc    Mon Nov 26 21:56:50 2007
@@ -47,7 +47,7 @@
 //     if (!(normalized >= 0.0 && normalized <= 1.0))
     //  cout << normalized << endl;
     //assert(normalized >= 0.0 && normalized <= 1.0);
-    const int idx = SCIRun::Clamp(static_cast<int>(ncolors*normalized), 0, 
ncolors);
+    const int idx = Clamp(static_cast<int>(ncolors*normalized), 0, ncolors);
     if (baseMaterial)
       results.set(i, rays.getColor(i)*cmap.blended[idx]);
     else

Modified: trunk/Model/Textures/ImageTexture.h
==============================================================================
--- trunk/Model/Textures/ImageTexture.h (original)
+++ trunk/Model/Textures/ImageTexture.h Mon Nov 26 21:56:50 2007
@@ -190,7 +190,7 @@
         break;
       case Clamp:
       default:
-        result = SCIRun::Clamp(val, 0, size-1);
+        result = Manta::Clamp(val, 0, size-1);
         break;
       }
       return result;
@@ -200,7 +200,7 @@
 
   private:
     // We make a copy of the data
-    SCIRun::Array2<ValueType> texture;
+    Array2<ValueType> texture;
     // You can scale the normal [(0,0)..(1,1)] texture coordinates,
     VectorT< ScalarType, 2 > scale;
     // Linear, nearest neighbor?
@@ -219,7 +219,7 @@
     int xres, yres;
     image->getResolution(stereo, xres, yres);
     if (stereo) {
-      throw SCIRun::InternalError( "ImageTexture doesn't support stereo 
currently", __FILE__, __LINE__);
+      throw InternalError( "ImageTexture doesn't support stereo currently");
     }
     texture.resize(xres, yres);
 
@@ -302,7 +302,7 @@
       edge = new_behavior;
       break;
     default:
-      throw SCIRun::InternalError( "ImageTexture::setEdgeBehavior doesn't 
support this edge behavior", __FILE__, __LINE__);
+      throw InternalError( "ImageTexture::setEdgeBehavior doesn't support 
this edge behavior");
       break;
     }
   }
@@ -315,7 +315,7 @@
       interpolation_method = new_method;
       break;
     default:
-      throw SCIRun::InternalError( "ImageTexture::setInterpolationMethod 
doesn't support this interpolation method", __FILE__, __LINE__);
+      throw InternalError( "ImageTexture::setInterpolationMethod doesn't 
support this interpolation method");
       break;
     }
   }

Modified: trunk/Model/Textures/MarbleTexture.h
==============================================================================
--- trunk/Model/Textures/MarbleTexture.h        (original)
+++ trunk/Model/Textures/MarbleTexture.h        Mon Nov 26 21:56:50 2007
@@ -82,7 +82,7 @@
       ColorComponent value = (Real)0.25 *
         Cos( rays.getTexCoords(i).x() * scale + tscale *
              (Real)Turbulence( T, octaves, lacunarity, gain ) );
-      results.set(i, SCIRun::Interpolate( value1, value2, value ));
+      results.set(i, Interpolate( value1, value2, value ));
     }
   }
 }

Modified: trunk/Model/Textures/OakTexture.h
==============================================================================
--- trunk/Model/Textures/OakTexture.h   (original)
+++ trunk/Model/Textures/OakTexture.h   Mon Nov 26 21:56:50 2007
@@ -93,7 +93,6 @@
                                           const RenderContext& context,
                                           RayPacket& rays) const
   {
-    using SCIRun::SmoothStep;
     rays.computeTextureCoordinates3( context );
     for( int i = rays.begin(); i < rays.end(); i++ ) {
       Vector tc = rays.getTexCoords(i);
@@ -105,12 +104,12 @@
       Pring += Vector( trunkwobble * vsnoise.x(),
                        trunkwobble * vsnoise.y(),
                        0 );
-      Real r = SCIRun::Sqrt( Pring.x() * Pring.x() + Pring.y() * Pring.y() ) 
* ringfreq;
+      Real r = Sqrt( Pring.x() * Pring.x() + Pring.y() * Pring.y() ) * 
ringfreq;
       r += angularwobble * SmoothStep( r, 0, 5 ) * ScalarNoise( Vector( 
angularwobble * Pring.x(),
                                                                         
angularwobble * Pring.y(),
                                                                         
angularwobble * Pring.z() * 0.1 ) );
       r += (Real)0.5 * ScalarNoise( Vector( (Real)0.5, (Real)0.5, r ) );
-      Real rfrac = r - SCIRun::Floor( r );
+      Real rfrac = r - Floor( r );
       Real inring = (SmoothStep( rfrac, (Real)0.1, (Real)0.55 ) -
                      SmoothStep( rfrac, (Real)0.7, (Real)0.95 ));
       Vector Pgrain( tc * Vector(grainfreq, grainfreq, 
grainfreq*(Real)0.05));
@@ -120,16 +119,16 @@
       {
           Real g = (Real)0.8 * ScalarNoise( Pgrain );
           g *= ( (Real)0.3 + (Real)0.7 * inring );
-          g = SCIRun::Clamp( (Real)0.8 - g, (Real)0, (Real)1 );
+          g = Clamp( (Real)0.8 - g, (Real)0, (Real)1 );
           g = grainy * SmoothStep( g * g, (Real)0.5, 1 );
           if ( it == 0 )
               inring *= (Real)0.7;
-          grain = SCIRun::Max( grain, g );
+          grain = Max( grain, g );
           Pgrain *= 2;
           amp *= (Real)0.5;
       }
-      Real value = SCIRun::Interpolate( (Real)1, grain, inring * ringy );
-      results.set(i, SCIRun::Interpolate( value2, value1, value ) );
+      Real value = Interpolate( (Real)1, grain, inring * ringy );
+      results.set(i, Interpolate( value2, value1, value ) );
     }
   }
 }

Modified: trunk/Model/Textures/WoodTexture.h
==============================================================================
--- trunk/Model/Textures/WoodTexture.h  (original)
+++ trunk/Model/Textures/WoodTexture.h  Mon Nov 26 21:56:50 2007
@@ -79,11 +79,11 @@
     rays.computeTextureCoordinates3( context );
     for( int i = rays.begin(); i < rays.end(); i++ ) {
       Vector T = rays.getTexCoords(i) * scale;
-      Real distance = SCIRun::Sqrt( T.x() * T.x() + T.y() * T.y() ) * rscale;
+      Real distance = Sqrt( T.x() * T.x() + T.y() * T.y() ) * rscale;
       Real fbm = tscale * ScalarFBM( T, octaves, lacunarity, gain );
       Real value = (Real)0.5 * Cos( distance + fbm ) + (Real)0.5;
-      results.set(i, SCIRun::Interpolate( value2, value1,
-                                          SCIRun::Pow( value, sharpness ) ));
+      results.set(i, Interpolate( value2, value1,
+                                  Pow( value, sharpness ) ));
     }
   }
 

Modified: trunk/StandAlone/CMakeLists.txt
==============================================================================
--- trunk/StandAlone/CMakeLists.txt     (original)
+++ trunk/StandAlone/CMakeLists.txt     Mon Nov 26 21:56:50 2007
@@ -17,7 +17,7 @@
 SET (BUILD_OCTVOL_BUILD 0 CACHE BOOL "Include .v3c1 tools")
 IF (BUILD_OCTVOL_BUILD) 
   ADD_EXECUTABLE(octvol_build octvol_build.cc)
-  TARGET_LINK_LIBRARIES(octvol_build SCIRun_Core Manta_Model Manta_Engine
+  TARGET_LINK_LIBRARIES(octvol_build Manta_Model Manta_Engine
                                      ${CMAKE_THREAD_LIBS_INIT} -lm)
 ENDIF(BUILD_OCTVOL_BUILD) 
                                   
@@ -36,7 +36,6 @@
     INCLUDE_DIRECTORIES(${GLUT_INCLUDE_DIR})
     ADD_EXECUTABLE(displaytest displaytest.cc)
     TARGET_LINK_LIBRARIES(displaytest ${MANTA_TARGET_LINK_LIBRARIES}
-                                      SCIRun_Core
                                       ${CMAKE_THREAD_LIBS_INIT}
                                       ${GLUT_LIBRARIES}
                                       -lm)

Modified: trunk/StandAlone/displaytest.cc
==============================================================================
--- trunk/StandAlone/displaytest.cc     (original)
+++ trunk/StandAlone/displaytest.cc     Mon Nov 26 21:56:50 2007
@@ -11,8 +11,8 @@
 #include <MantaSSE.h>
 #include <Interface/Image.h>
 #include <Interface/Fragment.h>
-#include <SCIRun/Core/Thread/Time.h>
-#include <SCIRun/Core/Math/MinMax.h>
+#include <Core/Thread/Time.h>
+#include <Core/Math/MinMax.h>
 // #include <Interface/ImageTraverser.h>
 // #include <Interface/PixelSampler.h>
 // #include <Interface/LoadBalancer.h>
@@ -25,7 +25,6 @@
 
 using namespace std;
 using namespace Manta;
-using namespace SCIRun;
 
 PureOpenGLDisplay* ogl = NULL;
 Image* images[2] = { NULL, NULL };
@@ -222,7 +221,7 @@
     for(int x = 0; x < xres; x+= Fragment::MaxSize) {
       int xstart = x;
       int xend = xstart + Fragment::MaxSize;
-      int fsize = SCIRun::Min(Fragment::MaxSize, xend-xstart);
+      int fsize = Min(Fragment::MaxSize, xend-xstart);
       Fragment fragment(Fragment::LineShape,
                         Fragment::ConsecutiveX|Fragment::ConstantEye);
 

Modified: trunk/StandAlone/frust-test.cc
==============================================================================
--- trunk/StandAlone/frust-test.cc      (original)
+++ trunk/StandAlone/frust-test.cc      Mon Nov 26 21:56:50 2007
@@ -10,9 +10,7 @@
 #include <Model/Groups/FrustumKDTree.h>
 #include <Interface/Context.h>
 
-#include <sgi_stl_warnings_off.h>
 #include <iostream>
-#include <sgi_stl_warnings_on.h>
 
 using namespace Manta;
 using namespace Kdtree;

Modified: trunk/StandAlone/manta.cc
==============================================================================
--- trunk/StandAlone/manta.cc   (original)
+++ trunk/StandAlone/manta.cc   Mon Nov 26 21:56:50 2007
@@ -64,19 +64,12 @@
 #include <Model/Primitives/Parallelogram.h>
 #include <Model/Primitives/Sphere.h>
 #include <Model/TexCoordMappers/UniformMapper.h>
-#include <SCIRun/Core/Thread/Thread.h>
-
+#include <Core/Thread/Thread.h>
 #include <strings.h>
-
-#include <sgi_stl_warnings_off.h>
 #include <iostream>
-#include <sgi_stl_warnings_on.h>
 
 using namespace std;
 using namespace Manta;
-using SCIRun::InternalError;
-using SCIRun::Time;
-using SCIRun::Thread;
 
 #if HAVE_IEEEFP_H
 #include <ieeefp.h>
@@ -230,15 +223,15 @@
 
     // Default options.
     if(!factory->selectImageType("argb8"))
-      throw InternalError("default image not found", __FILE__, __LINE__);
+      throw InternalError("default image not found");
 
     if(!factory->selectShadowAlgorithm("hard"))
-      throw InternalError("default shadow algorithm not found", __FILE__, 
__LINE__ );
+      throw InternalError("default shadow algorithm not found" );
 
     // Set camera for the default scene.
     Camera* currentCamera = factory->createCamera("pinhole(-normalizeRays)");
     if(!currentCamera)
-      throw InternalError("cannot create default camera", __FILE__, __LINE__ 
);
+      throw InternalError("cannot create default camera");
 
     // Defaults for command line args.
     int xres = 512, yres = 512;
@@ -430,8 +423,8 @@
         }
       }
     }
-    catch (SCIRun::Exception& e) {
-      cerr << "manta.cc (argument parsing): Caught SCIRun exception: " << 
e.message() << '\n';
+    catch (Exception& e) {
+      cerr << "manta.cc (argument parsing): Caught exception: " << 
e.message() << '\n';
       Thread::exitAll( 1 );
 
     } catch (std::exception e){
@@ -508,8 +501,8 @@
     
///////////////////////////////////////////////////////////////////////////
     
///////////////////////////////////////////////////////////////////////////
 
-  } catch (SCIRun::Exception& e) {
-    cerr << "manta.cc (top level): Caught SCIRun exception: " << e.message() 
<< '\n';
+  } catch (Exception& e) {
+    cerr << "manta.cc (top level): Caught exception: " << e.message() << 
'\n';
     Thread::exitAll( 1 );
 
   } catch (std::exception e){
@@ -536,16 +529,16 @@
   // Defaults.
 
   if(!factory->selectLoadBalancer("workqueue"))
-    throw InternalError("default load balancer not found", __FILE__, 
__LINE__);
+    throw InternalError("default load balancer not found");
 
   if(!factory->selectImageTraverser("tiled"))
-    throw InternalError("default image traverser not found", __FILE__, 
__LINE__ );
+    throw InternalError("default image traverser not found");
 
   if(!factory->selectPixelSampler("singlesample"))
-    throw InternalError("default pixel sampler not found", __FILE__, 
__LINE__ );
+    throw InternalError("default pixel sampler not found");
 
   if(!factory->selectRenderer("raytracer"))
-    throw InternalError("default renderer not found", __FILE__, __LINE__ );
+    throw InternalError("default renderer not found");
 
   // Parse command line args.
   for (size_t i=0; i < args.size(); ++i) {

Modified: trunk/StandAlone/octvol_build.cc
==============================================================================
--- trunk/StandAlone/octvol_build.cc    (original)
+++ trunk/StandAlone/octvol_build.cc    Mon Nov 26 21:56:50 2007
@@ -9,10 +9,9 @@
 #include <Core/Exceptions/InputError.h>
 #include <Core/Util/Args.h>
 #include <iostream>
-#include <SCIRun/Core/Thread/Time.h>
+#include <Core/Thread/Time.h>
 
 using namespace Manta;
-using namespace SCIRun;
 using namespace std;
 
 static void printUsage()

Modified: trunk/StandAlone/savescene.cc
==============================================================================
--- trunk/StandAlone/savescene.cc       (original)
+++ trunk/StandAlone/savescene.cc       Mon Nov 26 21:56:50 2007
@@ -36,7 +36,7 @@
 #include <Interface/MantaInterface.h>
 #include <Interface/InterfaceRTTI.h>
 #include <Interface/Scene.h>
-#include <SCIRun/Core/Thread/Thread.h>
+#include <Core/Thread/Thread.h>
 #include <Model/Textures/CheckerTexture.h>
 
 #include <iostream>
@@ -44,7 +44,6 @@
 
 using namespace std;
 using namespace Manta;
-using namespace SCIRun;
 
 void usage()
 {
@@ -98,8 +97,8 @@
     delete archive;
     delete rtrt;
 
-  } catch (SCIRun::Exception& e) {
-    cerr << "savescene.cc (top level): Caught SCIRun exception: " << 
e.message() << '\n';
+  } catch (Exception& e) {
+    cerr << "savescene.cc (top level): Caught exception: " << e.message() << 
'\n';
     Thread::exitAll( 1 );
                
   } catch (std::exception e){

Modified: trunk/SwigInterface/CMakeLists.txt
==============================================================================
--- trunk/SwigInterface/CMakeLists.txt  (original)
+++ trunk/SwigInterface/CMakeLists.txt  Mon Nov 26 21:56:50 2007
@@ -49,8 +49,7 @@
 
 # -Wall : Turn on all the warnings.
 # -w512 : Turn off warning 512.  Overloaded declaration const ignored. 
Non-const method at file:line used.
-# -DSCI_NOPERSISTENT : Flag for SCIRun headers.
-SET(MANTA_SWIG_FLAGS ${warning_extra} -w512 -DSCI_NOPERSISTENT) # Don't put 
quotes around it.  It needs to be a list.
+SET(MANTA_SWIG_FLAGS ${warning_extra} -w512) # Don't put quotes around it.  
It needs to be a list.
 
 ############################################################
 # Manta Interface.

Modified: trunk/SwigInterface/python.cc
==============================================================================
--- trunk/SwigInterface/python.cc       (original)
+++ trunk/SwigInterface/python.cc       Mon Nov 26 21:56:50 2007
@@ -29,7 +29,7 @@
 
 
 #include <Interface/Context.h>
-#include <SCIRun/Core/Exceptions/InternalError.h>
+#include <Core/Exceptions/InternalError.h>
 
 #include <Core/Exceptions/IllegalArgument.h>
 #include <Core/Util/Args.h>
@@ -37,7 +37,6 @@
 #include <string>
 #include <iostream>
 
-using namespace SCIRun;
 using namespace Manta;
 
 #include <Python.h>

Modified: trunk/UserInterface/AutomatorUI.cc
==============================================================================
--- trunk/UserInterface/AutomatorUI.cc  (original)
+++ trunk/UserInterface/AutomatorUI.cc  Mon Nov 26 21:56:50 2007
@@ -27,13 +27,10 @@
 */
 
 #include <UserInterface/AutomatorUI.h>
-
-#include <SCIRun/Core/Thread/Thread.h>
-
+#include <Core/Thread/Thread.h>
 #include <Interface/Callback.h>
 
 using namespace Manta;
-using namespace SCIRun;
 
 AutomatorUI::AutomatorUI( MantaInterface *manta_interface_,
                           int warmup_frames_, bool is_detached_ ) :

Modified: trunk/UserInterface/AutomatorUI.h
==============================================================================
--- trunk/UserInterface/AutomatorUI.h   (original)
+++ trunk/UserInterface/AutomatorUI.h   Mon Nov 26 21:56:50 2007
@@ -32,17 +32,12 @@
 #include <Interface/MantaInterface.h>
 #include <Interface/UserInterface.h>
 
-#include <SCIRun/Core/Thread/Thread.h>
-#include <SCIRun/Core/Thread/Runnable.h>
-#include <SCIRun/Core/Thread/Semaphore.h>
+#include <Core/Thread/Thread.h>
+#include <Core/Thread/Runnable.h>
+#include <Core/Thread/Semaphore.h>
 
 namespace Manta {
 
-  using SCIRun::Thread;
-  using SCIRun::Runnable;
-  using SCIRun::Semaphore;
-
-  
   
/////////////////////////////////////////////////////////////////////////////
   // An Automator is an automated user interface. Classes which implement the
   // run method may send transactions to Manta or interact with

Modified: trunk/UserInterface/CameraPathAutomator.cc
==============================================================================
--- trunk/UserInterface/CameraPathAutomator.cc  (original)
+++ trunk/UserInterface/CameraPathAutomator.cc  Mon Nov 26 21:56:50 2007
@@ -28,11 +28,11 @@
 
 #include <UserInterface/CameraPathAutomator.h>
 
-#include <SCIRun/Core/Thread/Thread.h>
-#include <SCIRun/Core/Thread/Time.h>
-#include <SCIRun/Core/Exceptions/ErrnoException.h>
-#include <SCIRun/Core/Exceptions/InternalError.h>
-#include <SCIRun/Core/Math/MinMax.h>
+#include <Core/Thread/Thread.h>
+#include <Core/Thread/Time.h>
+#include <Core/Exceptions/ErrnoException.h>
+#include <Core/Exceptions/InternalError.h>
+#include <Core/Math/MinMax.h>
 
 #include <Interface/Camera.h>
 #include <Interface/Callback.h>
@@ -47,7 +47,6 @@
 #include <fstream>
 
 using namespace Manta;
-using namespace SCIRun;
 
 
///////////////////////////////////////////////////////////////////////////////
 
///////////////////////////////////////////////////////////////////////////////
@@ -170,8 +169,7 @@
 
   // Check to make sure we got enough control points
   if (total_points < 4) {
-    throw  InternalError( "Didn't find at least 4 control points in the 
file: " + file_name,
-                             __FILE__, __LINE__ );
+    throw  InternalError( "Didn't find at least 4 control points in the 
file: " + file_name );
   }
 
   // Clear the EOF bit and rewind the input file.
@@ -374,11 +372,11 @@
   
   int current_point = 0;
 
-  int last_point  = SCIRun::Min(total_points-2,interval_last);
-  int first_point = SCIRun::Max(1,SCIRun::Min(interval_start,last_point));
+  int last_point  = Min(total_points-2,interval_last);
+  int first_point = Max(1,Min(interval_start,last_point));
   
   int start_frame = getMantaInterface()->getCurrentFrame();
-  start_seconds = SCIRun::Time::currentSeconds();
+  start_seconds = Time::currentSeconds();
   
   std::cerr << "Beginning camera path " << total_points 
             << " control points. Using interval " << first_point << ":" << 
last_point << std::endl;
@@ -410,7 +408,7 @@
         catmull_rom_interpolate( &up[current_point],     t, current_up );
 
         // Record the time of this transaction before a potential sync
-        double start_time = SCIRun::Time::currentSeconds();
+        double start_time = Time::currentSeconds();
         
         // Send the transaction to manta.
         getMantaInterface()->addTransaction
@@ -436,13 +434,13 @@
 
         
//////////////////////////////////////////////////////////////////////
         // Wait for delta_time seconds.
-        while ((SCIRun::Time::currentSeconds()-start_time) < delta_time);
+        while ((Time::currentSeconds()-start_time) < delta_time);
       }
     }
 
     // Compute the average fps for this run.
     int total_frames = getMantaInterface()->getCurrentFrame() - start_frame;
-    average_fps = 
(Real)total_frames/(SCIRun::Time::currentSeconds()-start_seconds);
+    average_fps = (Real)total_frames/(Time::currentSeconds()-start_seconds);
 
     std::cerr << "Path complete. "    << total_frames
               << " frames. Avg fps: " << average_fps << std::endl;
@@ -478,7 +476,7 @@
   // Wait for either the renderer thread or the camera path thread.
   synchronize_barrier.wait( 2 );
 
-  double current_sync_seconds = SCIRun::Time::currentSeconds();
+  double current_sync_seconds = Time::currentSeconds();
   int  current_sync_frame   = getMantaInterface()->getCurrentFrame();
 
   double total_elapse_seconds = current_sync_seconds - start_seconds;

Modified: trunk/UserInterface/CameraPathAutomator.h
==============================================================================
--- trunk/UserInterface/CameraPathAutomator.h   (original)
+++ trunk/UserInterface/CameraPathAutomator.h   Mon Nov 26 21:56:50 2007
@@ -35,7 +35,7 @@
 #include <MantaTypes.h>
 #include <Core/Geometry/Vector.h>
 
-#include <SCIRun/Core/Thread/Barrier.h>
+#include <Core/Thread/Barrier.h>
 
 #include <string>
 #include <vector>
@@ -49,9 +49,6 @@
 
   using std::string;
   using std::vector;
-#ifndef SWIG
-  using SCIRun::Barrier;
-#endif
 
   // std::vector wrapper class for swig.
   class CameraPathDataVector : public std::vector<BasicCameraData> {

Modified: trunk/UserInterface/NullUI.h
==============================================================================
--- trunk/UserInterface/NullUI.h        (original)
+++ trunk/UserInterface/NullUI.h        Mon Nov 26 21:56:50 2007
@@ -6,11 +6,8 @@
 
 #include <Interface/UserInterface.h>
 #include <Core/Thread/Runnable.h>
-
-#include <sgi_stl_warnings_off.h>
 #include <vector>
 #include <string>
-#include <sgi_stl_warnings_on.h>
 
 namespace Manta {
 

Modified: trunk/UserInterface/PromptUI.cc
==============================================================================
--- trunk/UserInterface/PromptUI.cc     (original)
+++ trunk/UserInterface/PromptUI.cc     Mon Nov 26 21:56:50 2007
@@ -39,16 +39,12 @@
 
 #include <Engine/Factory/RegisterKnownComponents.h>
 
-#include <sgi_stl_warnings_off.h>
 #include <vector>
 #include <string>
 #include <iostream>
-#include <sgi_stl_warnings_on.h>
 
 using namespace Manta;
 using namespace std;
-using SCIRun::Exception;
-using SCIRun::Thread;
 
 
///////////////////////////////////////////////////////////////////////////////
 
///////////////////////////////////////////////////////////////////////////////
@@ -96,10 +92,10 @@
       // Process the command.
       processCommand( buffer );
     }
-    catch (SCIRun::Exception &e) {
+    catch (Exception &e) {
       cerr << e.message() << std::endl;
     }
-    catch (SCIRun::Exception *e) {
+    catch (Exception *e) {
       cerr << e->message() << std::endl;
     }
   }
@@ -229,9 +225,9 @@
       Thread::exitAll( 0 );
     }
 
-  } catch (SCIRun::Exception *e) {
+  } catch (Exception *e) {
     cerr << "Caught exception: " << e->message() << std::endl << std::endl;
-  } catch (SCIRun::Exception& e) {
+  } catch (Exception& e) {
     cerr << "Caught exception: " << e.message() << '\n';
     if(e.stackTrace())
       cerr << "Stack trace: " << e.stackTrace() << '\n';

Modified: trunk/UserInterface/SyncFrameAutomator.cc
==============================================================================
--- trunk/UserInterface/SyncFrameAutomator.cc   (original)
+++ trunk/UserInterface/SyncFrameAutomator.cc   Mon Nov 26 21:56:50 2007
@@ -27,18 +27,14 @@
 */
 
 #include <UserInterface/SyncFrameAutomator.h>
-
-#include <sgi_stl_warnings_off.h>
 #include <iostream>
-#include <sgi_stl_warnings_on.h>
-
 #include <unistd.h>
-
 #include <Core/Thread/Mutex.h>
-extern SCIRun::Mutex sync_lock;
 
 using namespace Manta;
 using namespace std;
+
+extern Mutex sync_lock;
 
 SyncFrameAutomator::SyncFrameAutomator( MantaInterface* manta_interface_,
                                         SyncDisplay* syncd)

Modified: trunk/UserInterface/SyncFrameAutomator.h
==============================================================================
--- trunk/UserInterface/SyncFrameAutomator.h    (original)
+++ trunk/UserInterface/SyncFrameAutomator.h    Mon Nov 26 21:56:50 2007
@@ -32,10 +32,8 @@
 #include <UserInterface/AutomatorUI.h>
 #include <Engine/Display/SyncDisplay.h>
 
-#include <sgi_stl_warnings_off.h>
 #include <string>
 #include <vector>
-#include <sgi_stl_warnings_on.h>
 
 namespace Manta {
 

Modified: trunk/UserInterface/XWindowUI.cc
==============================================================================
--- trunk/UserInterface/XWindowUI.cc    (original)
+++ trunk/UserInterface/XWindowUI.cc    Mon Nov 26 21:56:50 2007
@@ -27,12 +27,10 @@
 #include <unistd.h>
 #include <sys/select.h>
 
-#include <sgi_stl_warnings_off.h>
 #include <iostream>
 #include <sstream>
 #include <functional>
 #include <algorithm>
-#include <sgi_stl_warnings_on.h>
 
 // TODO:
 // 1. Specify UI for only particular channels
@@ -47,7 +45,6 @@
 #define TOKEN_SHUTDOWN 3
 
 using namespace Manta;
-using namespace SCIRun;
 using namespace std;
 
 UserInterface* XWindowUI::create(const vector<string>& args,
@@ -137,9 +134,9 @@
   }
   dpy = XOpenDisplay(NULL);
   if(!dpy)
-    throw InternalError("XOpenDisplay failed", __FILE__, __LINE__ );
+    throw InternalError("XOpenDisplay failed");
   if(XAddConnectionWatch(dpy, connection_watch, 
reinterpret_cast<XPointer>(this)) == 0)
-    throw InternalError("XAddConnectionWatch failed", __FILE__, __LINE__ );
+    throw InternalError("XAddConnectionWatch failed");
 
   if(xfds.size() == 0){
     // XAddConnectionWatch must be broken.  To fix it, we look at the
@@ -267,8 +264,7 @@
         return;
         break;
       default:
-        throw InternalError("XWindowUI::Unknown token in pipe",
-                            __FILE__, __LINE__ );
+        throw InternalError("XWindowUI::Unknown token in pipe");
       }
     }
     bool have_some = false;
@@ -378,12 +374,12 @@
 {
   // cerr << description << ": " << (void*)key << '\n';
   if(key == 0)
-    throw InternalError("tried to register invalid key: "+description, 
__FILE__, __LINE__ );
+    throw InternalError("tried to register invalid key: "+description);
 
   for(vector<KeyTab>::iterator iter = keys.begin();
       iter != keys.end(); iter++){
     if(key == iter->key && state == iter->state)
-      throw InternalError("Two functions mapped to the same key: 
"+description+" and "+iter->description, __FILE__, __LINE__ );
+      throw InternalError("Two functions mapped to the same key: 
"+description+" and "+iter->description);
   }
   KeyTab entry;
   entry.key = key;
@@ -402,7 +398,7 @@
   for(vector<MouseTab>::iterator iter = mouse.begin();
       iter != mouse.end(); iter++){
     if(button == iter->button && state == iter->state)
-      throw InternalError("Two functions mapped to the same mouse button: 
"+description+" and "+iter->description, __FILE__, __LINE__ );
+      throw InternalError("Two functions mapped to the same mouse button: 
"+description+" and "+iter->description);
   }
   MouseTab entry;
   entry.state = state;

Modified: trunk/UserInterface/XWindowUI.h
==============================================================================
--- trunk/UserInterface/XWindowUI.h     (original)
+++ trunk/UserInterface/XWindowUI.h     Mon Nov 26 21:56:50 2007
@@ -11,11 +11,9 @@
 #include <Core/Thread/Semaphore.h>
 #include <X11/Xlib.h>
 
-#include <sgi_stl_warnings_off.h>
 #include <vector>
 #include <string>
 #include <iosfwd>
-#include <sgi_stl_warnings_on.h>
 
 namespace Manta {
   using namespace std;
@@ -26,7 +24,7 @@
   class CameraPath;
   class TimeViewSampler;
   
-  class XWindowUI: public UserInterface, public SetupCallback, public 
SCIRun::Runnable {
+  class XWindowUI: public UserInterface, public SetupCallback, public 
Runnable {
   public:
     XWindowUI(const vector<string>& args, MantaInterface *rtrt_interface);
     virtual ~XWindowUI();
@@ -131,8 +129,8 @@
     void toggleTimeView();
     TimeViewSampler* timeView;
     
-    SCIRun::Mutex xlock;
-    SCIRun::Semaphore xsema;
+    Mutex xlock;
+    Semaphore xsema;
 
     struct KeyTab {
       unsigned int state;

Modified: trunk/scenes/0.cc
==============================================================================
--- trunk/scenes/0.cc   (original)
+++ trunk/scenes/0.cc   Mon Nov 26 21:56:50 2007
@@ -18,13 +18,8 @@
 #include <Model/Textures/CheckerTexture.h>
 #include <Core/Geometry/AffineTransform.h>
 #include <Core/Util/NotFinished.h>
-
 #include <Engine/Factory/Factory.h>
-
-#include <sgi_stl_warnings_off.h>
 #include <iostream>
-#include <sgi_stl_warnings_on.h>
-
 #include <math.h>
 #include <string.h>
 

Modified: trunk/scenes/complexitytest.cc
==============================================================================
--- trunk/scenes/complexitytest.cc      (original)
+++ trunk/scenes/complexitytest.cc      Mon Nov 26 21:56:50 2007
@@ -80,11 +80,9 @@
 #include <Model/Textures/WoodTexture.h>
 #include <Model/Textures/OakTexture.h>
 #include <Core/Math/MinMax.h>
-#include <sgi_stl_warnings_off.h>
 #include <string>
 #include <vector>
 #include <iostream>
-#include <sgi_stl_warnings_on.h>
 
 #include "UsePrivateCode.h"
 #ifdef USE_PRIVATE_CODE
@@ -229,7 +227,7 @@
     } else if(object_type == "box") {
       object = new Cube(matl, Vector(-.5, -.5, -.5), Vector(.5, .5, .5));
     } else {
-      throw SCIRun::InternalError("unknown primitive type: " + object_type, 
__FILE__, __LINE__);
+      throw InternalError("unknown primitive type: " + object_type);
     }
   }
 

Modified: trunk/scenes/dynlt.cc
==============================================================================
--- trunk/scenes/dynlt.cc       (original)
+++ trunk/scenes/dynlt.cc       Mon Nov 26 21:56:50 2007
@@ -22,18 +22,15 @@
 #include <Model/Lights/PointLight.h>
 #include <Model/Primitives/Sphere.h>
 #include <Model/Readers/ParticleNRRD.h>
-#include <SCIRun/Core/Thread/Thread.h>
+#include <Core/Thread/Thread.h>
 
-#include <sgi_stl_warnings_off.h>
 #include <iostream>
-#include <sgi_stl_warnings_on.h>
 
 #include <float.h>
 
 #define WORKER_THREAD_STACKSIZE 8*1024*1024
 
 using namespace Manta;
-using namespace SCIRun;
 using namespace std;
 
 extern "C"

Modified: trunk/scenes/galileo/galileo.cc
==============================================================================
--- trunk/scenes/galileo/galileo.cc     (original)
+++ trunk/scenes/galileo/galileo.cc     Mon Nov 26 21:56:50 2007
@@ -21,9 +21,7 @@
 
 #include <Engine/Factory/Factory.h>
 
-#include <sgi_stl_warnings_off.h>
 #include <iostream>
-#include <sgi_stl_warnings_on.h>
 
 #include <math.h>
 #include <string.h>

Modified: trunk/scenes/gridisovol.cc
==============================================================================
--- trunk/scenes/gridisovol.cc  (original)
+++ trunk/scenes/gridisovol.cc  Mon Nov 26 21:56:50 2007
@@ -27,12 +27,10 @@
 #include <Core/Geometry/AffineTransform.h>
 #include <Model/AmbientLights/ConstantAmbient.h>
 #include <Model/MiscObjects/CuttingPlane.h>
-#include <SCIRun/Core/Containers/Array3.h>
-
-#include <SCIRun/Core/Thread/Time.h>
+#include <Core/Containers/Array3.h>
+#include <Core/Thread/Time.h>
 
 using namespace Manta;
-using namespace SCIRun;
 
 enum CuttingPlaneType { CUTTING_NONE, CUTTING_DEFAULT, CUTTING_SPECIFIED };
 

Modified: trunk/scenes/octisovol.cc
==============================================================================
--- trunk/scenes/octisovol.cc   (original)
+++ trunk/scenes/octisovol.cc   Mon Nov 26 21:56:50 2007
@@ -27,12 +27,10 @@
 #include <Core/Geometry/AffineTransform.h>
 #include <Model/AmbientLights/ConstantAmbient.h>
 #include <Model/MiscObjects/CuttingPlane.h>
-#include <SCIRun/Core/Containers/Array3.h>
-
-#include <SCIRun/Core/Thread/Time.h>
+#include <Core/Containers/Array3.h>
+#include <Core/Thread/Time.h>
 
 using namespace Manta;
-using namespace SCIRun;
 
 ///////////////////////////////////////////////////////////////////////////
 extern "C"

Modified: trunk/scenes/primtest.cc
==============================================================================
--- trunk/scenes/primtest.cc    (original)
+++ trunk/scenes/primtest.cc    Mon Nov 26 21:56:50 2007
@@ -52,11 +52,9 @@
 #include <Model/Textures/WoodTexture.h>
 #include <Model/Textures/OakTexture.h>
 #include <Core/Math/MinMax.h>
-#include <sgi_stl_warnings_off.h>
 #include <string>
 #include <vector>
 #include <iostream>
-#include <sgi_stl_warnings_on.h>
 
 #include "UsePrivateCode.h"
 #ifdef USE_PRIVATE_CODE
@@ -130,7 +128,7 @@
   }
 
   Group* group = new Group();
-  int max = SCIRun::Max(numx, numy);
+  int max = Max(numx, numy);
 
 
   if(bgpoly && bgpoly_first){
@@ -373,7 +371,7 @@
     if  (!strncmp(modelName.c_str()+modelName.length()-4, ".obj", 4)) {
       mesh = new ObjGroup(modelName.c_str());
     } else {
-      throw SCIRun::InternalError("No OBJ model found", __FILE__, __LINE__);
+      throw InternalError("No OBJ model found");
     }
     as->setGroup(mesh);
     spinprim = as;

Modified: trunk/scenes/volumeTest.cc
==============================================================================
--- trunk/scenes/volumeTest.cc  (original)
+++ trunk/scenes/volumeTest.cc  Mon Nov 26 21:56:50 2007
@@ -62,9 +62,7 @@
 
 #include <Model/MiscObjects/CuttingPlane.h>
 
-#include <sgi_stl_warnings_off.h>
 #include <iostream>
-#include <sgi_stl_warnings_on.h>
 
 #include <math.h>
 #include <string>

Modified: trunk/scenes/vorpal.cc
==============================================================================
--- trunk/scenes/vorpal.cc      (original)
+++ trunk/scenes/vorpal.cc      Mon Nov 26 21:56:50 2007
@@ -17,11 +17,9 @@
 #include <Model/Primitives/Heightfield.h>
 #include <Model/Readers/PlyReader.h>
 #include <Core/Math/MinMax.h>
-#include <sgi_stl_warnings_off.h>
 #include <string>
 #include <iostream>
 #include <fstream>
-#include <sgi_stl_warnings_on.h>
 
 using namespace Manta;
 using namespace std;

Modified: trunk/tests/atomic_counter.cc
==============================================================================
--- trunk/tests/atomic_counter.cc       (original)
+++ trunk/tests/atomic_counter.cc       Mon Nov 26 21:56:50 2007
@@ -44,8 +44,7 @@
 #include <unistd.h>
 #endif
 
-
-using namespace SCIRun;
+using namespace Manta;
 
 class AtomicCountTest : public Runnable {
     AtomicCounter* counter;





Archive powered by MHonArc 2.6.16.

Top of page