Index: GTP/trunk/App/Demos/Vis/CHC_revisited/Geometry.h
===================================================================
--- GTP/trunk/App/Demos/Vis/CHC_revisited/Geometry.h	(revision 2746)
+++ GTP/trunk/App/Demos/Vis/CHC_revisited/Geometry.h	(revision 2751)
@@ -2,132 +2,66 @@
 #define GEOMETRY_H
 
-extern "C"
+
+namespace CHCDemo 
 {
-	#include "MathStuff.h"
-}
 
-/** Represents a drawable geometry. It can draw simple objects (teapot,
-	torus, shere. It also contains the object transformation and 
-	the material .An AAB is used as bouning volume.
+/** Represents drawable geometry consisting of triangles
 */
 class Geometry
 {
 public:
-	Geometry();
-	Geometry(Vector3 translation, float xRot, float yRot, float zRot, float scale, int objectType);
-	//! Renders this geometry
-	void Render();
-	//! sets rotations in degree : executed in the order x, y, and z rotation
-	void SetRotations(float xRot, float yRot, float zRot);
-	//! sets the rotation matrix
-	void SetTranslation(Vector3 translation);
-	//! a uniform scale
-	void SetScale(float scale);
-	//! returns current scale
-	float GetScale();
-
-	//! returns translation
-	void GetTranslation(Vector3 translation);
-	//! returns rotation
-	void GetRotations(float &xRot, float &yRot, float &zRot);
-
-	//! Set pointer to the material
-	void SetMaterial(Material *mat);
-	//! Returns the bounding box
-	const AABox& GetBoundingVolume();
-	//! last visited flag, important for rendering each geometry only once
-	void SetLastVisited(int lastVisited);
-	//! returns lastvisited flag
-	int GetLastVisited();
-	// --- sets the object type to one of teapot, torus, sphere
-	void SetObjectType(int type);
-
-	
-	
-	static int sDisplayList[NUM_OBJECTS];
-	
-	//! cleans static members
-	static void CleanUp();
-	//! returns the triangle count of the specified object type
-	static int CountTriangles(int objectType);
-	//! initialises display lists
-	static void ResetLists(); 
+	/** Constructor taking a triangle container.
+	*/
+	Geometry(const TriangleContainer &triangles);
 
 protected:
 
-	//! generates the display list this a object
-	void GenerateList();
+	AxisAlignedBox3 mBoundingBox;
+	TriangleContainer mTriangles;
+}
 
-	//! calculates accumulated transformation matrix
-	void CalcTransform();
-	//! applies tranformations
-	void Transform();
 
-	// --- statistics
-	static int CountTorusTriangles();
-	static int CountSphereTriangles();
-	static int CountTeapotTriangles();
+/** Class representing a scene entity.
+    A scene entity basicly consists of geometry, transformation, and a material
+*/
+class SceneEntity
+{
+	/** Create scene entity.
+	*/
+	SceneEntity(Geometry *geometry, Matrix4x4 *trafo, Material *mat);
+	/** Renders this geometry.
+	*/
+	void Render();	
+	/** Set pointer to the geometry
+	*/
+	void SetGeometry(Geometry *geom);
+	/** Set pointer to the geometry
+	*/
+	void SetTransformation(const Matrix4x4 *trafo);
+	/** Set pointer to the material
+	*/
+	void SetMaterial(Material *mat);
+	/** Returns the transformed bounding box.
+	*/
+	const AxisAlignedBox3& GetBoundingVolume();
+	/** set frame where we last visitied this node
+	*/
+	void SetLastVisited(int lastVisited);
+	/** returns frame where we last visited this node
+	*/
+	int GetLastVisited() const;
 
-	//!
-	static void CreateTorus(float innerRadius, float outerRadius, int precision);
+protected:
 
-	//! calculates the bounding volume of this geometry
-	void CalcBoundingVolume();
-	// the size of the bounging box is calculated using the radius of the sphere
-	void CalcSphereBoundingVolume();
-	// the standard bounding volume calculation having an array of vertices
-	void CalcBoundingVolume(float *vertices, const int num_vertices);
+	/// transform matrix 
+	Matrix4x4 *mTransform;
+	Geometry *mGeometry;
+	Material *mMaterial;
 
-	// initialises static members
-	static bool Init();
-
-	// --- drawing routines
-	static void RenderTeapot();
-	static void RenderSphere();
-	static void RenderTorus();
-
-	// --- transformations
-	float mXRotation;
-	float mYRotation;
-	float mZRotation;
-	
-	float mScale;
-
-	Vector3 mTranslation;
-	
-	//! accumulated transform matrix 
-	Matrix4x4 mTransform;
-
-	// --- material
-	float mAmbientColor[3];
-	float mDiffuseColor[3];
-	float mSpecularColor[3];
-
-	AABox mBoundingBox;
-	//! type of the rendered object (teapot, sphere ...)
-	int mObjectType;
+	AxisAlignedBox3 mBoundingBox;
 	
 	int mLastVisited;
-
-	// --- static members
-
-	static bool sIsInitialised;
-
-	static float const sphere_radius;
-	
-	static int num_torus_indices;
-	static int num_torus_vertices;
-	static int num_torus_normals;
-
-	static float *torus_vertices;
-	static float *torus_normals;
-	static int *torus_indices;
-
-	static const int torus_precision;
-	static const int sphere_precision;
-	static const float torus_inner_radius;
-	static const float torus_outer_radius;
 };
 
-
+}
 #endif // GEOMETRY_H
Index: GTP/trunk/App/Demos/Vis/CHC_revisited/Timers.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/CHC_revisited/Timers.cpp	(revision 2642)
+++ GTP/trunk/App/Demos/Vis/CHC_revisited/Timers.cpp	(revision 2751)
@@ -107,16 +107,17 @@
   
 #else
-  
-  if (hasHRTimer == 1) {
-    LARGE_INTEGER counter;
-    QueryPerformanceCounter(&counter);
-    // return in usec
-    return (long) (1000000*counter.QuadPart/(hrFreq.QuadPart));
-  } else {
-    static struct _timeb mtime;
-    _ftime(&mtime);
-    
-    return 1000*(1000*mtime.time + mtime.millitm);
-  }
+
+	if (hasHRTimer == 1) 
+	{
+		LARGE_INTEGER counter;
+		QueryPerformanceCounter(&counter);
+		// return in usec
+		return (long) (1000000*counter.QuadPart/(hrFreq.QuadPart));
+	} else {
+		static struct _timeb mtime;
+		_ftime(&mtime);
+
+		return 1000 * (1000 * mtime.time + mtime.millitm);
+	}
 #endif
 }
@@ -138,4 +139,5 @@
   time_t t;
   time(&t);
+
   return ctime(&t);
 }
Index: GTP/trunk/App/Demos/Vis/CHC_revisited/Material.h
===================================================================
--- GTP/trunk/App/Demos/Vis/CHC_revisited/Material.h	(revision 2747)
+++ GTP/trunk/App/Demos/Vis/CHC_revisited/Material.h	(revision 2751)
@@ -2,7 +2,7 @@
 #define __MATERIAL_H
 
-//namespace CHCDemo 
-//{
 
+namespace CHCDemo 
+{
 
 class RgbColor 
@@ -80,5 +80,5 @@
 extern Material RandomMaterial();
 
-//}
+}
 
 #endif
Index: GTP/trunk/App/Demos/Vis/CHC_revisited/Matrix4x4.h
===================================================================
--- GTP/trunk/App/Demos/Vis/CHC_revisited/Matrix4x4.h	(revision 2746)
+++ GTP/trunk/App/Demos/Vis/CHC_revisited/Matrix4x4.h	(revision 2751)
@@ -5,5 +5,7 @@
 
 
-//namespace GtpVisibilityPreprocessor {
+namespace CHCDemo 
+{
+
 
 class Vector3;
@@ -14,18 +16,21 @@
 {
 public:
-	float x[4][4]; // first index is column [x], the second is row [y]
-
-	Matrix4x4() { }
-
-	// here xXY - 'X' is row, and 'Y' is column - classical mathematical notation
+	/** Default constructor initialising nothig.
+	*/
+	Matrix4x4();
+	/** here xXY - 'X' is row, and 'Y' is column - classical mathematical notation
+	*/
 	Matrix4x4(float x11, float x12, float x13, float x14,
-		float x21, float x22, float x23, float x24,
-		float x31, float x32, float x33, float x34,
-		float x41, float x42, float x43, float x44);
-
+  		      float x21, float x22, float x23, float x24,
+			  float x31, float x32, float x33, float x34,
+			  float x41, float x42, float x43, float x44);
+	/** Constructor setting the columns of the 3x3 part of the matrix.
+	*/
 	Matrix4x4(const Vector3 &a, const Vector3 &b, const Vector3 &c);
 
 
-	// Assignment operators
+	////////////////
+	//-- Assignment operators
+
 	Matrix4x4& operator+= (const Matrix4x4 &A); 	// add-to
 	Matrix4x4& operator-= (const Matrix4x4 &A); 	// subtract-from
@@ -33,27 +38,38 @@
 	Matrix4x4& operator*= (float A); 		// scale by scalar
 
-	// Fundamental operations
-	/// Invert the matrix .. returns 0 = regular
+
+	////////////////
+	//-- Fundamental operations
+
+	/** Invert the matrix .. returns 0 = regular
+	*/
 	int Invert();		
-	/// Transpose the matrix
+	/** Transpose the matrix
+	*/
 	void Transpose();	
+	/** Sets the columns of the 3x3 part of the matrix.
+	*/
+	void SetColumns(const Vector3 &a, const Vector3 &b, const Vector3 &c);
 
-	void
-		SetColumns(const Vector3 &a, const Vector3 &b, const Vector3 &c);
-
-	float Det3x3() const {
-		return (x[0][0]*x[1][1]*x[2][2] + \
-			x[1][0]*x[2][1]*x[0][2] + \
-			x[2][0]*x[0][1]*x[1][2] - \
-			x[2][0]*x[1][1]*x[0][2] - \
-			x[0][0]*x[2][1]*x[1][2] - \
-			x[1][0]*x[0][1]*x[2][2]);
-	}
+	float Det3x3() const;
 
 
-	friend Matrix4x4 Invert(const Matrix4x4 &M);	// Invert a given matrix
-	friend Matrix4x4 Transpose(const Matrix4x4 &M);	// Transpose a given matrix
+	////////////
+	//-- members
 
-	// Create various types of matrix.
+	float x[4][4]; // first index is column [x], the second is row [y]
+
+
+	////////////////////
+
+	// Invert a given matrix
+	friend Matrix4x4 Invert(const Matrix4x4 &M);
+	// Transpose a given matrix
+	friend Matrix4x4 Transpose(const Matrix4x4 &M);	
+
+
+	///////////
+	//-- Create various types of matrix.
+
 	friend Matrix4x4 IdentityMatrix();
 	friend Matrix4x4 ZeroMatrix();
@@ -94,19 +110,16 @@
 	friend Vector3 GetTranslation(const Matrix4x4 &M);
 
-	// Construct rotation description according VRML'97 specification
-	//  const CVector4D SFRotation(void) const;
-
-
-
 	// Overloaded output operator.
 	friend std::ostream& operator<< (std::ostream &s, const Matrix4x4 &M);
 };
 
-// forward declaration
+
+/////////
+//-- forward declaration
+
+
 Matrix4x4 IdentityMatrix();
-Matrix4x4 Invert(const Matrix4x4 &M);	// Invert a given matrix
-Matrix4x4 Transpose(const Matrix4x4 &M);	// Transpose a given matrix
-
-// Create various types of matrix.
+Matrix4x4 Invert(const Matrix4x4 &M);	
+Matrix4x4 Transpose(const Matrix4x4 &M);	
 Matrix4x4 IdentityMatrix();
 Matrix4x4 ZeroMatrix();
@@ -116,10 +129,7 @@
 Matrix4x4 RotationZMatrix(float Angle);
 Matrix4x4 RotationYPRMatrix(float Yaw, float Pitch, float Roll);
-// about axis 'axis' by angle 'Angle'
 Matrix4x4 RotationAxisMatrix(const Vector3 &axis, float Angle);
-// create the rotation matrix that rotates 'vecFrom' to 'vecTo'
 Matrix4x4 RotationVectorsMatrix(const Vector3 &vecFrom,
 								const Vector3 &vecTo);
-
 Matrix4x4 ScaleMatrix(float X, float Y, float Z);
 Matrix4x4 GenRotation(const Vector3 &x, const Vector3 &y,
@@ -127,19 +137,13 @@
 Matrix4x4 QuadricMatrix(float a, float b, float c, float d, float e,
 						float f, float g, float h, float j, float k);
-// returns matrix for transforming normal
 Matrix4x4 NormalTransformMatrix(const Matrix4x4 &M);
-
 Matrix4x4 MirrorX();
 Matrix4x4 MirrorY();
 Matrix4x4 MirrorZ();
 Matrix4x4 RotationOnly(const Matrix4x4 &x);
-
-// Binary operators
 Matrix4x4 operator+ (const Matrix4x4 &A, const Matrix4x4 &B);
 Matrix4x4 operator- (const Matrix4x4 &A, const Matrix4x4 &B);
 Matrix4x4 operator* (const Matrix4x4 &A, float B);
 Matrix4x4 operator* (const Matrix4x4 &A, const Matrix4x4 &B);
-
-// friends returning Vector3
 Vector3 operator*(const Matrix4x4 &M, const Vector3 &v);
 Vector3 RotateOnly(const Matrix4x4 &M, const Vector3 &v);
@@ -148,6 +152,5 @@
 
 
-//}
-
+}
 
 
Index: GTP/trunk/App/Demos/Vis/CHC_revisited/Bvh.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/CHC_revisited/Bvh.cpp	(revision 2746)
+++ GTP/trunk/App/Demos/Vis/CHC_revisited/Bvh.cpp	(revision 2751)
@@ -13,11 +13,14 @@
 #include "Viewer.h"
 
-
 #include <fstream>
 #include <iostream>
 #include <iomanip>
 
+
+
+namespace CHCDemo
+{
+
 #define INVALID_TEST ((unsigned int)-1)
-#define MAX_FLOAT 1e20f
 
 #define TYPE_INTERIOR -2
@@ -324,5 +327,5 @@
 float Bvh::SelectPlaneSah(BvhLeaf *leaf, int &axis, float &minCost)
 {
-	minCost = MAX_FLOAT;
+	minCost = MAXFLOAT;
 	float bestPos = minCost;
 	int bestAxis = 0;
@@ -584,10 +587,10 @@
 			pos = SelectPlaneSah(leaf, axis, cost);
 
-			if (pos != MAX_FLOAT)
+			if (pos != MAXFLOAT)
 			{
 				split = SortTriangles(leaf, axis, pos);
 			}
 
-			if ((pos == MAX_FLOAT) || (split == leaf->mLast))
+			if ((pos == MAXFLOAT) || (split == leaf->mLast))
 			{
 				split = -1;
@@ -608,5 +611,5 @@
 				pos = SelectPlaneSah(leaf, axis, cost);
 
-				if (pos != MAX_FLOAT)
+				if (pos != MAXFLOAT)
 					split = SortTriangles(leaf, axis, pos);
 				else
@@ -2590,3 +2593,5 @@
 } 
 
+}
+
 #endif
Index: GTP/trunk/App/Demos/Vis/CHC_revisited/Plane3.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/CHC_revisited/Plane3.cpp	(revision 2751)
+++ GTP/trunk/App/Demos/Vis/CHC_revisited/Plane3.cpp	(revision 2751)
@@ -0,0 +1,109 @@
+#include "Plane3.h"
+#include "Matrix4x4.h"
+
+
+namespace CHCDemo 
+{
+
+Plane3::Plane3(const Vector3 &a, const Vector3 &b, const Vector3 &c) 
+{
+    Vector3 v1=a-b, v2=c-b;
+    mNormal = Normalize(CrossProd(v2,v1));
+    mD = -DotProd(b, mNormal);
+}
+
+
+Plane3::Plane3(const Vector3 &normal, const Vector3 &point):
+mNormal(normal)
+{
+    mD = -DotProd(normal, point);
+}
+
+
+bool PlaneIntersection(const Plane3 &a, 
+					   const Plane3 &b, 
+					   const Plane3 &c, 
+					   Vector3 &result)
+{
+	Vector3 sx(a.mNormal.x, b.mNormal.x, c.mNormal.x),
+		    sy(a.mNormal.y, b.mNormal.y, c.mNormal.y),
+			sz(a.mNormal.z, b.mNormal.z, c.mNormal.z),
+			sd(a.mD, b.mD, c.mD);
+
+  Matrix4x4 md(a.mNormal, b.mNormal, c.mNormal), mx, my, mz;
+
+  mx.SetColumns(sd, sy, sz);
+  my.SetColumns(sx, sd, sz);
+  mz.SetColumns(sx, sy, sd);
+  
+  const float det = md.Det3x3();
+
+  if (fabs(det) < TRASH)
+    return false;
+
+  result.SetValue(mx.Det3x3()/det,
+				  my.Det3x3()/det,
+				  mz.Det3x3()/det);
+  
+  return true;
+}
+
+
+ bool PlaneIntersection(const Plane3 &p1, const Plane3 &p2)
+ {
+	 return 
+		 p1.mNormal.x != p2.mNormal.x ||
+		 p1.mNormal.y != p2.mNormal.y ||
+		 p1.mNormal.z != p2.mNormal.z ||
+		 p1.mD == p2.mD;
+ }
+
+
+Vector3 Plane3::FindIntersection(const Vector3 &a,						   
+								 const Vector3 &b,
+								 float *t,
+								 bool *coplanar) const 
+{
+	// line from A to B
+	const Vector3 v = b - a; 
+	float dv = DotProd(v, mNormal);
+    
+    if (signum(dv) == 0)
+	{
+		if (coplanar) (*coplanar) = true;	
+
+		if (t) (*t) = 0;
+
+		return a;
+	}
+	
+	if (coplanar) (*coplanar) = false;
+
+    float u = - Distance(a) / dv;
+
+	if (t) (*t) = u;
+
+    return a + u * v;
+}
+
+
+int Plane3::Side(const Vector3 &v, const float threshold) const 
+{
+    return signum(Distance(v), threshold);
+}
+
+
+float Plane3::FindT(const Vector3 &a, const Vector3 &b) const 
+{	  
+	const Vector3 v = b - a; // line from A to B
+	const float dv = DotProd(v, mNormal);
+    
+	// does not intersect or coincident
+	if (signum(dv) == 0)
+		return 0;
+	
+	return - Distance(a) / dv; 
+}
+
+
+}
Index: GTP/trunk/App/Demos/Vis/CHC_revisited/common.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/CHC_revisited/common.cpp	(revision 2746)
+++ GTP/trunk/App/Demos/Vis/CHC_revisited/common.cpp	(revision 2751)
@@ -25,5 +25,7 @@
 using namespace std;
 
-//namespace CHCDemo {
+
+namespace CHCDemo 
+{
 
 
@@ -337,3 +339,3 @@
 #endif
 
-//}
+}
Index: GTP/trunk/App/Demos/Vis/CHC_revisited/AxisAlignedBox3.h
===================================================================
--- GTP/trunk/App/Demos/Vis/CHC_revisited/AxisAlignedBox3.h	(revision 2749)
+++ GTP/trunk/App/Demos/Vis/CHC_revisited/AxisAlignedBox3.h	(revision 2751)
@@ -10,13 +10,12 @@
 
 
-//namespace CHCDemo
-//{
+namespace CHCDemo
+{
 
 struct Triangle3;
 
 /** Axis alignedd box class.
-This is a box in 3-space, defined by min and max
-corner vectors.  Many useful operations are defined
-on this
+    This is a box in 3-space, defined by min and max
+	corner vectors.  Many useful operations are defined.
 */
 class AxisAlignedBox3
@@ -25,12 +24,10 @@
 public:
 
-	// Constructors.
-	AxisAlignedBox3() { }
-
-	AxisAlignedBox3(const Vector3 &nMin, const Vector3 &nMax)
-	{
-		mMin = nMin; mMax = nMax;
-	}
-
+	///////////
+	//-- Constructors.
+
+	AxisAlignedBox3();
+
+	AxisAlignedBox3(const Vector3 &nMin, const Vector3 &nMax);
 	/** initialization to the non existing bounding box
 	*/
@@ -131,53 +128,19 @@
 	*/
 	void Translate(const Vector3 &shift);
-
 	/** Returns the square of the minimal and maximal distance to 
-	a point on the box.
-	*/
-	void
-		GetSqrDistances(const Vector3 &point,
-		float &minDistance,
-		float &maxDistance
-		) const;
-
-
-
-	Vector3 GetRandomPoint(const Vector3 &r) const;
+	    a point on the box.
+	*/
+	void GetSqrDistances(const Vector3 &point, 
+		                 float &minDistance,
+						 float &maxDistance) const;
+	/** return random point in box.
+	*/
 	Vector3 GetRandomPoint() const;
-
-	Vector3 GetPoint(const Vector3 &p) const 
-	{
-		return mMin + p*Size(); 
-	}
-
-
-protected:
-	Vector3 mMin, mMax;
-
-public:
-
-	// Returns the smallest axis-aligned box that includes all points
-	// inside the two given boxes.
-	friend inline AxisAlignedBox3 Union(const AxisAlignedBox3 &x,
-		const AxisAlignedBox3 &y);
-
-	// Returns the intersection of two axis-aligned boxes.
-	friend inline AxisAlignedBox3 Intersect(const AxisAlignedBox3 &x,
-		const AxisAlignedBox3 &y);
-
-	// Given 4x4 matrix, transform the current box to new one.
-	friend inline AxisAlignedBox3 Transform(const AxisAlignedBox3 &box,
-		const Matrix4x4 &tform);
-
-
-	// returns true when two boxes are completely equal
-	friend inline int operator== (const AxisAlignedBox3 &A, 
-		const AxisAlignedBox3 &B);
-
-	virtual float SurfaceArea() const;
-	virtual float GetVolume() const 
-	{
-		return (mMax.x - mMin.x) * (mMax.y - mMin.y) * (mMax.z - mMin.z);
-	}
+	/** Returns surface area of the box.
+	*/
+	float SurfaceArea() const;
+	/** Returns volume of the box.
+	*/
+	float GetVolume() const;
 
 	// Six faces are distuinguished by their name.
@@ -194,5 +157,5 @@
 
 	// For edge .. number <0..11> returns two incident vertices
-	void GetEdge(const int edge, Vector3 *a, Vector3 *b) const;
+	void GetEdge(int edge, Vector3 *a, Vector3 *b) const;
 
 	// Compute the coordinates of one vertex of the box for 0/1 in each axis
@@ -203,15 +166,13 @@
 	// x,y,z are either 0 or 1; (0 .. lower coordinate, 1 .. large coordinate)
 	// (xmin,ymin, zmin) .. N = 0, (xmax, ymax, zmax) .. N= 7
-	void GetVertex(const int N, Vector3 &vertex) const;
-
-	Vector3 GetVertex(const int N) const {
-		Vector3 v;
-		GetVertex(N, v);
-		return v;
-	}
-
-	// Returns 1, if the box includes on arbitrary face a given box
+	void GetVertex(int N, Vector3 &vertex) const;
+
+	Vector3 GetVertex(int N) const;
+	/** get the extent of face.
+	*/
+	float GetExtent(int face) const; 
+	/** Returns 1, if the box includes on arbitrary face a given box
+	*/
 	int IsPiercedByBox(const AxisAlignedBox3 &box, int &axis) const;
-
 
 	int GetFaceVisibilityMask(const Vector3 &position) const;
@@ -219,6 +180,4 @@
 	*/
 	//Plane3 GetPlane(const int face) const;
-
-
 	/** Returns vertex indices of edge.
 	*/
@@ -226,12 +185,31 @@
 
 
-	// get the extent of face
-	float GetExtent(const int &face) const 
-	{
-		if (face < 3)
-			return mMin[face];
-		else
-			return mMax[face - 3];
-	}
+
+	////////////
+	//-- friend functions
+
+	// Returns the smallest axis-aligned box that includes all points
+	// inside the two given boxes.
+	friend inline AxisAlignedBox3 Union(const AxisAlignedBox3 &x,
+		                                const AxisAlignedBox3 &y);
+
+	// Returns the intersection of two axis-aligned boxes.
+	friend inline AxisAlignedBox3 Intersect(const AxisAlignedBox3 &x,
+		                                    const AxisAlignedBox3 &y);
+
+	// Given 4x4 matrix, transform the current box to new one.
+	friend inline AxisAlignedBox3 Transform(const AxisAlignedBox3 &box,
+		                                    const Matrix4x4 &tform);
+
+
+	// returns true when two boxes are completely equal
+	friend inline int operator== (const AxisAlignedBox3 &A, 
+		                          const AxisAlignedBox3 &B);
+
+	// input and output operator with stream
+	friend std::ostream& operator<<(std::ostream &s, const AxisAlignedBox3 &A);
+	friend std::istream& operator>>(std::istream &s, AxisAlignedBox3 &A);
+
+
 
 	// The vertices that form boundaries of the projected bounding box
@@ -272,7 +250,8 @@
 	static const int fsvertices[27][9];
 
-	// input and output operator with stream
-	friend std::ostream& operator<<(std::ostream &s, const AxisAlignedBox3 &A);
-	friend std::istream& operator>>(std::istream &s, AxisAlignedBox3 &A);
+protected:
+
+	Vector3 mMin, mMax;
+
 };
 
@@ -385,5 +364,5 @@
 
 
-//}
+}
 
 
Index: GTP/trunk/App/Demos/Vis/CHC_revisited/Vector3.h
===================================================================
--- GTP/trunk/App/Demos/Vis/CHC_revisited/Vector3.h	(revision 2746)
+++ GTP/trunk/App/Demos/Vis/CHC_revisited/Vector3.h	(revision 2751)
@@ -11,4 +11,6 @@
 
 
+namespace CHCDemo
+{
 
 /** Vector class.
@@ -358,5 +360,5 @@
 
 	if (signedAngle < 0)
-		return 2 * PI + signedAngle;
+		return 2 * M_PI + signedAngle;
 
 	return signedAngle;
@@ -530,6 +532,5 @@
 
 
-
-//}
+}
 
 #endif
Index: GTP/trunk/App/Demos/Vis/CHC_revisited/Geometry.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/CHC_revisited/Geometry.cpp	(revision 2746)
+++ GTP/trunk/App/Demos/Vis/CHC_revisited/Geometry.cpp	(revision 2751)
@@ -1,2 +1,5 @@
+#if 0
+
+
 #include "Geometry.h"
 #include "glInterface.h"
@@ -5,4 +8,8 @@
 
 #include <math.h>
+
+
+namespace CHCDemo 
+{
 
 #define NO_LIST    -1
@@ -547,2 +554,6 @@
 	glFrontFace(GL_CCW);
 }
+
+}
+
+#endif
Index: GTP/trunk/App/Demos/Vis/CHC_revisited/chc_revisited.vcproj
===================================================================
--- GTP/trunk/App/Demos/Vis/CHC_revisited/chc_revisited.vcproj	(revision 2746)
+++ GTP/trunk/App/Demos/Vis/CHC_revisited/chc_revisited.vcproj	(revision 2751)
@@ -46,4 +46,5 @@
 				BasicRuntimeChecks="3"
 				RuntimeLibrary="3"
+				RuntimeTypeInfo="false"
 				UsePrecompiledHeader="0"
 				WarningLevel="3"
@@ -119,7 +120,13 @@
 			<Tool
 				Name="VCCLCompilerTool"
+				InlineFunctionExpansion="2"
+				EnableIntrinsicFunctions="true"
+				FavorSizeOrSpeed="1"
+				OmitFramePointers="true"
+				EnableFiberSafeOptimizations="true"
 				AdditionalIncludeDirectories="GL"
 				PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE"
 				RuntimeLibrary="2"
+				RuntimeTypeInfo="false"
 				UsePrecompiledHeader="0"
 				WarningLevel="3"
@@ -182,33 +189,13 @@
 			>
 			<File
-				RelativePath=".\AxisAlignedBox3.cpp"
-				>
-			</File>
-			<File
-				RelativePath=".\common.cpp"
-				>
-			</File>
-			<File
-				RelativePath=".\HierarchyNode.cpp"
-				>
-			</File>
-			<File
-				RelativePath=".\Material.cpp"
-				>
-			</File>
-			<File
-				RelativePath=".\Matrix4x4.cpp"
+				RelativePath=".\Bvh.cpp"
+				>
+			</File>
+			<File
+				RelativePath=".\Geometry.cpp"
 				>
 			</File>
 			<File
 				RelativePath=".\occquery.cpp"
-				>
-			</File>
-			<File
-				RelativePath=".\RenderTraverser.cpp"
-				>
-			</File>
-			<File
-				RelativePath=".\Timers.cpp"
 				>
 			</File>
@@ -220,13 +207,29 @@
 			>
 			<File
+				RelativePath=".\Bvh.h"
+				>
+			</File>
+			<File
+				RelativePath=".\Geometry.h"
+				>
+			</File>
+			<File
+				RelativePath=".\Material.h"
+				>
+			</File>
+		</Filter>
+		<Filter
+			Name="utils"
+			>
+			<File
+				RelativePath=".\AxisAlignedBox3.cpp"
+				>
+			</File>
+			<File
 				RelativePath=".\AxisAlignedBox3.h"
 				>
 			</File>
 			<File
-				RelativePath=".\Bvh.cpp"
-				>
-			</File>
-			<File
-				RelativePath=".\Bvh.h"
+				RelativePath=".\common.cpp"
 				>
 			</File>
@@ -240,5 +243,9 @@
 			</File>
 			<File
-				RelativePath=".\Material.h"
+				RelativePath=".\Material.cpp"
+				>
+			</File>
+			<File
+				RelativePath=".\Matrix4x4.cpp"
 				>
 			</File>
@@ -248,17 +255,45 @@
 			</File>
 			<File
+				RelativePath=".\Plane3.cpp"
+				>
+			</File>
+			<File
+				RelativePath=".\Plane3.h"
+				>
+			</File>
+			<File
+				RelativePath=".\Timers.cpp"
+				>
+			</File>
+			<File
+				RelativePath=".\Timers.h"
+				>
+			</File>
+			<File
+				RelativePath=".\Triangle3.cpp"
+				>
+			</File>
+			<File
+				RelativePath=".\Triangle3.h"
+				>
+			</File>
+			<File
+				RelativePath=".\Vector3.cpp"
+				>
+			</File>
+			<File
+				RelativePath=".\Vector3.h"
+				>
+			</File>
+		</Filter>
+		<Filter
+			Name="traversal"
+			>
+			<File
+				RelativePath=".\RenderTraverser.cpp"
+				>
+			</File>
+			<File
 				RelativePath=".\RenderTraverser.h"
-				>
-			</File>
-			<File
-				RelativePath=".\Timers.h"
-				>
-			</File>
-			<File
-				RelativePath=".\Vector3.cpp"
-				>
-			</File>
-			<File
-				RelativePath=".\Vector3.h"
 				>
 			</File>
Index: GTP/trunk/App/Demos/Vis/CHC_revisited/Triangle3.h
===================================================================
--- GTP/trunk/App/Demos/Vis/CHC_revisited/Triangle3.h	(revision 2750)
+++ GTP/trunk/App/Demos/Vis/CHC_revisited/Triangle3.h	(revision 2751)
@@ -5,10 +5,10 @@
 
 
-namespace GtpVisibilityPreprocessor {
+namespace CHCDemo 
+{
 
 class AxisAlignedBox3;
-class Ray;
-struct SimpleRay;
 class Plane3;
+
 
 struct Triangle3 
@@ -26,20 +26,10 @@
 
 	float GetArea() const;
-
-	/// returns bounding box around this triangle
+	/** returns bounding box around this triangle
+	*/
 	AxisAlignedBox3 GetBoundingBox() const;
-
-	/// Casts ray into this triangle. Returns hit
-	int CastRay(const Ray &ray, float &t, const float nearestT, Vector3 &normal) const;
-
-	int CastSimpleRay(const SimpleRay &ray, float &t, const float nearestT) const;
-  
-	friend std::ostream& operator<< (std::ostream &s, const Triangle3 &A);
-	friend std::istream& operator>> (std::istream &s, Triangle3 &A);
-
 	/** Checks if this triangle is ill-defined.
 	*/
 	bool CheckValidity() const;
-
 	/** Intersects triangle with plane, returns intersection points
 		if intersection is happening.
@@ -50,4 +40,9 @@
 							  Vector3 &intersectA, 
 							  Vector3 &intersectB) const;
+
+	  
+	friend std::ostream& operator<< (std::ostream &s, const Triangle3 &A);
+	friend std::istream& operator>> (std::istream &s, Triangle3 &A);
+
 
 	///////////////////
Index: GTP/trunk/App/Demos/Vis/CHC_revisited/Material.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/CHC_revisited/Material.cpp	(revision 2747)
+++ GTP/trunk/App/Demos/Vis/CHC_revisited/Material.cpp	(revision 2751)
@@ -2,6 +2,6 @@
 #include "Material.h"
 
-//namespace CHCDemo
-//{
+namespace CHCDemo
+{
 
 RgbColor RandomColor(const float a, const float b)
@@ -22,5 +22,3 @@
 }
 
-
-
-//}
+}
Index: GTP/trunk/App/Demos/Vis/CHC_revisited/Matrix4x4.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/CHC_revisited/Matrix4x4.cpp	(revision 2746)
+++ GTP/trunk/App/Demos/Vis/CHC_revisited/Matrix4x4.cpp	(revision 2751)
@@ -6,5 +6,9 @@
 using namespace std;
 
-//namespace GtpVisibilityPreprocessor {
+namespace CHCDemo 
+{
+
+Matrix4x4::Matrix4x4()
+{}
 
 
@@ -85,4 +89,16 @@
 	x[3][3] = x44;
 }
+
+
+float Matrix4x4::Det3x3() const 
+{
+	return (x[0][0]*x[1][1]*x[2][2] + \
+		x[1][0]*x[2][1]*x[0][2] + \
+		x[2][0]*x[0][1]*x[1][2] - \
+		x[2][0]*x[1][1]*x[0][2] - \
+		x[0][0]*x[2][1]*x[1][2] - \
+		x[1][0]*x[0][1]*x[2][2]);
+}
+
 
 
@@ -167,7 +183,7 @@
 }
 
+
 // Invert the given matrix using the above inversion routine.
-Matrix4x4
-Invert(const Matrix4x4& M)
+Matrix4x4 Invert(const Matrix4x4& M)
 {
 	Matrix4x4 InvertMe = M;
@@ -178,6 +194,5 @@
 
 // Transpose the matrix.
-void
-Matrix4x4::Transpose()
+void Matrix4x4::Transpose()
 {
 	for (int i = 0; i < 4; i++)
@@ -190,7 +205,7 @@
 }
 
+
 // Transpose the given matrix using the transpose routine above.
-Matrix4x4
-Transpose(const Matrix4x4& M)
+Matrix4x4 Transpose(const Matrix4x4& M)
 {
 	Matrix4x4 TransposeMe = M;
@@ -199,7 +214,7 @@
 }
 
+
 // Construct an identity matrix.
-Matrix4x4
-IdentityMatrix()
+Matrix4x4 IdentityMatrix()
 {
 	Matrix4x4 M;
@@ -211,7 +226,7 @@
 }
 
+
 // Construct a zero matrix.
-Matrix4x4
-ZeroMatrix()
+Matrix4x4 ZeroMatrix()
 {
 	Matrix4x4 M;
@@ -635,3 +650,3 @@
 }
 
-//}
+}
Index: GTP/trunk/App/Demos/Vis/CHC_revisited/Timers.h
===================================================================
--- GTP/trunk/App/Demos/Vis/CHC_revisited/Timers.h	(revision 2746)
+++ GTP/trunk/App/Demos/Vis/CHC_revisited/Timers.h	(revision 2751)
@@ -18,5 +18,5 @@
 
 /** Example of usage:
-see timers.h for diffirent possibilities of what is really measured..
+see timers.h for diffirent possibilities of what is really measured.
 
 
Index: GTP/trunk/App/Demos/Vis/CHC_revisited/RenderTraverser.h
===================================================================
--- GTP/trunk/App/Demos/Vis/CHC_revisited/RenderTraverser.h	(revision 2746)
+++ GTP/trunk/App/Demos/Vis/CHC_revisited/RenderTraverser.h	(revision 2751)
@@ -1,4 +1,6 @@
 #ifndef RENDERTRAVERSER_H
 #define RENDERTRAVERSER_H
+
+
 
 #if TOIMPLEMENT
@@ -10,5 +12,6 @@
 #include <stack>
 
-
+namespace CHCDemo
+{
 
 typedef stack<HierarchyNode *> TraversalStack;
@@ -131,4 +134,9 @@
 	bool mUseOptimization;
 };
+
+}
+
 #endif
+
+
 #endif // RENDERTRAVERSER_H
Index: GTP/trunk/App/Demos/Vis/CHC_revisited/Bvh.h
===================================================================
--- GTP/trunk/App/Demos/Vis/CHC_revisited/Bvh.h	(revision 2746)
+++ GTP/trunk/App/Demos/Vis/CHC_revisited/Bvh.h	(revision 2751)
@@ -3,4 +3,5 @@
 #ifndef __BVH_H
 #define __BVH_H
+
 
 #if TOIMPLEMENT
@@ -12,4 +13,9 @@
 #include "HierarchyNode.h"
 #include "FlexibleHeap.h"
+
+
+
+namespace CHCDemo
+{
 
 
@@ -894,4 +900,6 @@
 };
 
+}
+
 #endif
 #endif // __BVH_H
Index: GTP/trunk/App/Demos/Vis/CHC_revisited/AxisAlignedBox3.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/CHC_revisited/AxisAlignedBox3.cpp	(revision 2747)
+++ GTP/trunk/App/Demos/Vis/CHC_revisited/AxisAlignedBox3.cpp	(revision 2751)
@@ -6,8 +6,6 @@
 using namespace std;
 
-//namespace CHCDemo
-//{
-
-// AxisAlignedBox3 implementations
+namespace CHCDemo
+{
 
 // Overload << operator for C++-style output
@@ -27,4 +25,14 @@
 		>> A.mMax.x >> a >> A.mMax.y >> a >> A.mMax.z >> a;
 }
+
+
+AxisAlignedBox3::AxisAlignedBox3() 
+{ }
+
+
+AxisAlignedBox3::AxisAlignedBox3(const Vector3 &nMin, const Vector3 &nMax)
+: mMin(nMin), mMax(nMax)
+{}
+
 
 
@@ -246,4 +254,10 @@
 		ext.x * ext.z +
 		ext.y * ext.z);
+}
+
+
+float AxisAlignedBox3::GetVolume() const 
+{
+	return (mMax.x - mMin.x) * (mMax.y - mMin.y) * (mMax.z - mMin.z);
 }
 
@@ -947,13 +961,7 @@
 	Vector3 size = Size();
 
-	return GetRandomPoint(Vector3(RandomValue(0.0f, 1.0f),
-                                  RandomValue(0.0f, 1.0f),
-								  RandomValue(0.0f, 1.0f)));
-}
-
-
-Vector3 AxisAlignedBox3::GetRandomPoint(const Vector3 &r) const
-{
-	return mMin + Size()*r;
+	return mMin + Vector3(RandomValue(0.0f, 1.0f),
+		                  RandomValue(0.0f, 1.0f),
+						  RandomValue(0.0f, 1.0f)) * Size();
 }
 
@@ -1004,4 +1012,23 @@
 }
 
-//}
-
+
+Vector3 AxisAlignedBox3::GetVertex(const int N) const 
+{
+	Vector3 v;
+	GetVertex(N, v);
+
+	return v;
+}
+
+
+float AxisAlignedBox3::GetExtent(int face) const 
+{
+	if (face < 3)
+		return mMin[face];
+	else
+			return mMax[face - 3];
+}
+
+
+}
+
Index: GTP/trunk/App/Demos/Vis/CHC_revisited/Vector3.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/CHC_revisited/Vector3.cpp	(revision 2746)
+++ GTP/trunk/App/Demos/Vis/CHC_revisited/Vector3.cpp	(revision 2751)
@@ -5,6 +5,6 @@
 
 
-//namespace CHCDemo
-//{
+namespace CHCDemo
+{
 
 // Given min a vector to minimize and a candidate vector, replace
@@ -263,11 +263,8 @@
 		sinTheta*cos(fi));
 
-	Matrix4x4 m = RotationVectorsMatrix(
-		normal,
-		Vector3(0,1,0));
+	Matrix4x4 m = RotationVectorsMatrix(normal, Vector3(0,1,0));
 	Matrix4x4 mi = Invert(m);
-	m = m*RotationVectorsMatrix(
-		Vector3(0,1,0),
-		Normalize(dir))*mi;
+
+	m = m*RotationVectorsMatrix(Vector3(0, 1, 0), Normalize(dir)) * mi;
 
 	return TransformNormal(m, normal);
@@ -282,6 +279,5 @@
 	return !(isnan(x) || isnan(y) || isnan(z));
 #endif  
-	//return ((x != x) || (y != y) || (z != z));
-}
-
-//}
+}
+
+}
Index: GTP/trunk/App/Demos/Vis/CHC_revisited/Plane3.h
===================================================================
--- GTP/trunk/App/Demos/Vis/CHC_revisited/Plane3.h	(revision 2751)
+++ GTP/trunk/App/Demos/Vis/CHC_revisited/Plane3.h	(revision 2751)
@@ -0,0 +1,78 @@
+#ifndef _Plane3_H__
+#define _Plane3_H__
+
+#include "Vector3.h"
+
+namespace CHCDemo 
+{
+
+/** 3D Plane.
+*/
+class Plane3 
+{
+public:
+
+	Plane3() {}
+
+	Plane3(const Vector3 &a, const Vector3 &b, const Vector3 &c);
+
+	Plane3(const Vector3 &normal, const Vector3 &point);
+
+	void ReverseOrientation()
+	{
+		mNormal *= -1;
+		mD *= -1;
+	}
+
+	float Distance(const Vector3 &v) const 
+	{
+		return DotProd(v, mNormal) + mD;
+	}
+
+	enum {BACK_SIDE = -1, INTERSECTS = 0, FRONT_SIDE = 1};
+
+	/** Returns 1 if v is on front side, -1 if on back side, 0 if on plane.
+	*/
+	int Side(const Vector3 &v, const float threshold = 1e-6) const;
+	/** Finds intersection of line segment between points a and b with plane.
+	    @param a start point
+		@param b end point
+		@param t if not NULL, returns parameter value of intersections
+		@param coplanar if not NULL, returns true if plane and line segments are coplanar.
+	*/
+	Vector3 FindIntersection(const Vector3 &a,
+ 		                     const Vector3 &b,
+							 float *t = NULL,
+							 bool *coplanar = NULL) const;
+
+	/** Finds value of intersection parameter t on line segment from a to b.
+	    @returns 0 if coplanar, else parameter t
+	*/
+	float FindT(const Vector3 &a, const Vector3 &b) const;
+
+
+	//////////////////
+	//-- friends
+
+	friend bool	PlaneIntersection(const Plane3 &a, const Plane3 &b, const Plane3 &c, Vector3 &result);
+
+	friend bool PlaneIntersection(const Plane3 &p1, const Plane3 &p2);
+
+	friend std::ostream &operator<<(std::ostream &s, const Plane3 &p) 
+	{	
+		s<<p.mNormal<<" "<<p.mD;
+		return s;
+	}
+
+
+	///////////////
+
+	Vector3 mNormal;
+	float mD;
+
+	//////////////////
+
+};
+
+}
+#endif
Index: GTP/trunk/App/Demos/Vis/CHC_revisited/Triangle3.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/CHC_revisited/Triangle3.cpp	(revision 2750)
+++ GTP/trunk/App/Demos/Vis/CHC_revisited/Triangle3.cpp	(revision 2751)
@@ -1,13 +1,12 @@
 #include "Triangle3.h"
-#include "Ray.h"
-#include "SimpleRay.h"
 #include "AxisAlignedBox3.h"
-#include "Containers.h"
-#include "Polygon3.h"
+#include "common.h"
+#include "Plane3.h"
 
 
 using namespace std;
 
-namespace GtpVisibilityPreprocessor {
+
+namespace CHCDemo {
 
 	
@@ -25,205 +24,4 @@
 }
 
-
-float Triangle3::GetSpatialAngle(const Vector3 &point) const
-{
-	return 0.0f;
-}
-
-
-int
-Triangle3::CastRay(const Ray &ray,
-		   float &t,
-		   const float nearestT,
-		   Vector3 &normal) const
-{
-  //////////////
-  // specialised triangle ray casting version
-  // using ray-plane intersection
-  
-  // get triangle edge vectors and plane normal
-  const Vector3 u = mVertices[0] - mVertices[1];
-  const Vector3 v = mVertices[2] - mVertices[1];
-  
-  // cross product
-  normal = Normalize(CrossProd(v, u));
-  
-  // ray direction vector
-  const Vector3 dir = ray.GetDir();
-  const Vector3 w0 = ray.GetLoc() - mVertices[1];
-  
-  // params to calc ray-plane intersect
-  const float a = -DotProd(normal, w0);
-  const float b = DotProd(normal, dir);
-  
-  // check for division by zero
-  if (fabs(b) < Limits::Small) 
-    {   
-      // ray is parallel to triangle plane
-      if (a == 0)
-	{
-	  // ray lies in triangle plane
-	  return Ray::INTERSECTION_OUT_OF_LIMITS;
-	}
-      else
-	{
-	  // ray disjoint from plane
-	  return Ray::NO_INTERSECTION;
-	}
-    }
-
-  // distance from origin of ray to plane
-  t = a / b;
-  
-  if (t <= Limits::Small) // ray goes away from triangle
-    {
-      return Ray::INTERSECTION_OUT_OF_LIMITS;
-    }
-  // already found nearer intersection
-  else if ((ray.GetType() == Ray::LOCAL_RAY) && (t >= nearestT))
-    {
-      return Ray::NO_INTERSECTION;
-    }
-  
-  /////////////////
-    //-- found intersection point
-  //-- check if it is inside triangle
-  
-  const Vector3 pt = ray.GetLoc() + t * dir; 
-#if GTP_DEBUG
-  if (!pt.CheckValidity())
-    {
-      cout << "tr: " << *this << endl;
-      cout << "v: " << pt << " t: " << t << " a: " << a << " b: " << b << " n: " << normal << endl;
-    }
-#endif
-  const Vector3 w = pt - mVertices[1];
-  
-  const float uu = DotProd(u, u);
-  const float uv = DotProd(u, v);
-  const float vv = DotProd(v, v);
-  
-  const float wu = DotProd(w, u);
-  const float wv = DotProd(w, v);
-  
-  
-  const float D = uv * uv - uu * vv;
-  
-  // get and test parametric coords
-  const float s = (uv * wv - vv * wu) / D;
-  
-  if ((s < -Limits::Small) || (s > 1.0f + Limits::Small)) // pt is outside triangle
-    {	
-      return Ray::NO_INTERSECTION;
-    }
-  
-  const float s2 = (uv * wu - uu * wv) / D;
-  
-  if ((s2 < -Limits::Small) || ((s + s2) > 1.0f + Limits::Small)) // pt is outside triangle
-    {	
-      return Ray::NO_INTERSECTION;
-    }
-  
-  return Ray::INTERSECTION; // I is in T
-}
-
-
-int
-Triangle3::CastSimpleRay(const SimpleRay &ray,
-			 float &t,
-			 const float nearestT) const
-{
-  //////////////
-  // specialised triangle ray casting version
-  // using ray-plane intersection
-  
-  // get triangle edge vectors and plane normal
-  const Vector3 u = mVertices[0] - mVertices[1];
-  const Vector3 v = mVertices[2] - mVertices[1];
-
-  // cross product
-  const Vector3 normal = Normalize(CrossProd(v, u));
-
-  // ray direction vector
-  const Vector3 dir = ray.mDirection;
-  const Vector3 w0 = ray.mOrigin - mVertices[1];
-
-  // params to calc ray-plane intersect
-  const float a = -DotProd(normal, w0);
-  const float b = DotProd(normal, dir);
-
-  // check for division by zero
-  if (fabs(b) < Limits::Small) 
-  {   
-    // ray is parallel to triangle plane
-    if (a == 0)
-    {
-      // ray lies in triangle plane
-      return Ray::INTERSECTION_OUT_OF_LIMITS;
-    }
-    else {
-      // ray disjoint from plane
-      return Ray::NO_INTERSECTION;
-    }
-  }
-
-  // distance from origin of ray to plane
-  t = a / b;
-
-  if (t <= Limits::Small) // ray goes away from triangle
-  {
-    return Ray::INTERSECTION_OUT_OF_LIMITS;
-  }
-
-  // already found nearer intersection
-  if (t > nearestT + 1e-5)
-  {
-    return Ray::NO_INTERSECTION;
-  }
-
-  /////////////////
-  //-- found intersection point
-  //-- check if it is inside triangle
-  
-  const Vector3 pt = ray.mOrigin + t * dir; 
-#if GTP_DEBUG
-  if (!pt.CheckValidity())
-  {
-    cout << "tr: " << *this << endl;
-    cout << "v: " << pt << " t: " << t << " a: " << a << " b: " << b << " n: " << normal << endl;
-  }
-#endif
-  const Vector3 w = pt - mVertices[1];
-
-  const float uu = DotProd(u, u);
-  const float uv = DotProd(u, v);
-  const float vv = DotProd(v, v);
-    
-  const float wu = DotProd(w, u);
-  const float wv = DotProd(w, v);
-  
-  
-  const float D = uv * uv - uu * vv;
-  
-  // get and test parametric coords
-  const float s = (uv * wv - vv * wu) / D;
-  
-  if ((s < -Limits::Small) ||
-      (s > 1.0f + Limits::Small)) // pt is outside triangle
-  {	
-    return Ray::NO_INTERSECTION;
-  }
-
-  const float s2 = (uv * wu - uu * wv) / D;
-  
-  if ((s2 < -Limits::Small) ||
-      ((s + s2) > 1.0f + Limits::Small)) // pt is outside triangle
-  {	
-    return Ray::NO_INTERSECTION;
-  }
-  
-  return Ray::INTERSECTION; // I is in T
-}
-  
 
 AxisAlignedBox3 Triangle3::GetBoundingBox() const
@@ -282,7 +80,5 @@
 	// compute distance from plane
 	for (int i = 0; i < 3; ++ i)
-	{
 		side[i] = plane.Side(mVertices[i], Limits::Small);
-	}
 
 	/////
@@ -324,5 +120,4 @@
 			{
 				intersectA = mVertices[i] + t * (mVertices[i_2] - mVertices[i]);
-			
 				foundA = true;
 			}
@@ -330,5 +125,4 @@
 			{
 				intersectB = mVertices[i] + t * (mVertices[i_2] - mVertices[i]);
-			
 				return true;
 			}
Index: GTP/trunk/App/Demos/Vis/CHC_revisited/common.h
===================================================================
--- GTP/trunk/App/Demos/Vis/CHC_revisited/common.h	(revision 2746)
+++ GTP/trunk/App/Demos/Vis/CHC_revisited/common.h	(revision 2751)
@@ -1,7 +1,4 @@
-/**
-
-This file contains various macros, templates and constants for the ERS system.
-
-@author Jiri Bittner
+/** This file contains various macros, templates and constants for the ERS system.
+    @author Jiri Bittner
 */
 
@@ -19,6 +16,8 @@
 
 
-//namespace GtpVisibilityPreprocessor {
-
+namespace CHCDemo 
+{
+
+struct Triangle3;
   
 #if defined(_MSC_VER)
@@ -54,5 +53,5 @@
 #include <values.h>
 #else // __WATCOMC__
-#define M_PI        3.14159265358979323846
+#define M_PI        3.14159265358979323846F
 #define MAXFLOAT    3.40282347e+37F
 #endif // __WATCOMC__
@@ -119,17 +118,7 @@
 #endif // NULL
 
-//ostream& operator<<(ostream &s,const BaseC &c);
-
 typedef float Real;
 typedef unsigned char byte;
 
-//#ifndef FALSE
-//#define FALSE 0
-//#define TRUE !0
-//#endif
-
-#ifndef __GNUG__
-// typedef int bool;
-#endif
 
 #ifndef getch
@@ -137,18 +126,7 @@
 #endif
 
-
 #define TRASH 1.0e-5
 
-#ifndef PI
-#define PI    3.14159265358979323846f
-#endif
-
-#define MIN_FLOAT -1e30f
-#define MAX_FLOAT  1e30f
-
-
-// tolerance value for polygon area
-#define AREA_LIMIT 0.0001f
-
+// delete a pointer and set to NULL
 #ifndef DEL_PTR
 #define DEL_PTR(ptr) do {if (ptr) {        \
@@ -157,17 +135,9 @@
                      while (0)
 #endif
+
+
 // Clears a container (i.e., a vector of pointers) and deletes the pointers
-#if 0
 #ifndef CLEAR_CONTAINER
-#define CLEAR_CONTAINER(co) do { while (!(co).empty()) {   \
-						           DEL_PTR((co).back());     \
-								   (co).pop_back();}}      \
-							while (0)
-#endif
-
-#else
-
-#ifndef CLEAR_CONTAINER
-#define CLEAR_CONTAINER(co) do { for (int _i = 0; _i < (int)(co).size(); ++ _i) { \
+#define CLEAR_CONTAINER(co) do { for (size_t _i = 0; _i < (int)(co).size(); ++ _i) { \
 	DEL_PTR((co)[_i]);} \
 	(co).clear(); } \
@@ -175,9 +145,6 @@
 #endif
 
-#endif
-
-
-inline
-int signum(const Real a, const Real thresh = TRASH)
+
+inline int signum(const Real a, const Real thresh = TRASH)
 {
   if (a>thresh)
@@ -320,9 +287,9 @@
 inline Real Deg2Rad(const Real a)
 {
-   return a * (PI / 180.0f);
+   return a * (M_PI / 180.0f);
 }
 
 inline Real Rad2Deg(const Real a) {
-  return a*(180.0f/PI);
+  return a * (180.0f/M_PI);
 }
   
@@ -335,26 +302,25 @@
 
 
-// -------------------------------------------------------------------
-// Limits.
-//  This class encapsulates all the concessions to Realing-point
-//  error made by ray tracers.
-// -------------------------------------------------------------------
-
-class Limits {
+/** Limits.
+    This class encapsulates all the concessions to Realing-point
+	error made by ray tracers.
+*/
+class Limits 
+{
 public:
-  // This is the number used to reject too-close intersections.
-  // The default value is 1.0.
-  static Real Threshold;
-
-  // This is a "small" number.  Less than this number is assumed to
-  // be 0, when such things matter.
-  // The default value is 0.1.
-  static Real Small;
-
-  // This is an impractically "large" number, used for intersection
-  // parameters out to infinity (e.g. the span resulting from an
-  // FindAllIntersections operation on a plane).
-  // The default value is 100000.
-  static Real Infinity;
+	// This is the number used to reject too-close intersections.
+	// The default value is 1.0.
+	static Real Threshold;
+
+	// This is a "small" number.  Less than this number is assumed to
+	// be 0, when such things matter.
+	// The default value is 0.1.
+	static Real Small;
+
+	// This is an impractically "large" number, used for intersection
+	// parameters out to infinity (e.g. the span resulting from an
+	// FindAllIntersections operation on a plane).
+	// The default value is 100000.
+	static Real Infinity;
 };
 
@@ -488,13 +454,15 @@
 
 
-//}
-
-#endif
-
-
-
-
-
-
-
-
+typedef std::vector<Triangle3> TriangleContainer;
+
+}
+
+#endif
+
+
+
+
+
+
+
+
