Index: GTP/trunk/Lib/Geom/shared/GTGeometry/include/GeoTreeSimplifier.h
===================================================================
--- GTP/trunk/Lib/Geom/shared/GTGeometry/include/GeoTreeSimplifier.h	(revision 774)
+++ GTP/trunk/Lib/Geom/shared/GTGeometry/include/GeoTreeSimplifier.h	(revision 1007)
@@ -6,6 +6,8 @@
 #include "Hoja.h"
 
-#define K1		0.8f //distancia
-#define K2		0.2f // coplanar
+#define K1		0.8f //distance factor
+#define K2		0.2f //coplanar factor
+
+class LeafOctree;
 
 namespace Geometry
@@ -34,15 +36,8 @@
 	public:
 		/// Class constructor. Retrieves a pointer to a valid Mesh object to simplify
-		TreeSimplifier(	const Geometry::Mesh 	*,
-										Geometry::TIPOFUNC		upb=0);
+		TreeSimplifier(const Geometry::Mesh *, Geometry::TIPOFUNC upb=0);
 
 		/// Class destructor.
 		~TreeSimplifier(void);
-
-		/// Copy constructor
-		//TreeSimplifier(const TreeSimplifier&);
-
-		/// Assignment operator
-		//TreeSimplifier& operator =(const TreeSimplifier&);
 
 		/// Starts the simplification process. Receives as a parameter the LOD factor in a range of [0,1].
@@ -55,41 +50,52 @@
 		TreeSimplificationSequence *GetSimplificationSequence();
 
-	//private:
-		void Centroh(Hoja	&);
-		void GetNormal(Hoja	&);
-		void DistanciaEntreHojas(void);
-		void CoplanarEntreHojas(FILE*);
-		float DiametroEsferaEnvolvente();
-		void EstableceCriterio(float);
+	private:
+		void CalculateLeafCenter(Hoja &);
+		void CalculateLeafNormal(Hoja &);
+		float CalculateLeafArea(Hoja &) const;
+		void CoplanarBetweenLeaves(void);
+		float BoundingSphereDiameter() const;
+//		void SetCriteria(float);  // to be erased: obsolete!
+		void SetCriteriaOptimized(float);
 
-		float max(float, float);
-		float min(float, float);
+		float max(float, float) const;
+		float min(float, float) const;
 
-		//long int Colapsa (TreeSimplificationSequence *, float);
-		long int Colapsa(float);
-		void DosMayores(float*, int* );
-		void ElijeVertices(Hoja& , Hoja& , long int);
-		float Hausdorff(Hoja &, Hoja&);
-		float distan(float, float, float, float, float, float);
-		long int MinimaDistancia(void);
-		void NormalizaDistancia(float diametro);
-		void EstableceCriterio2(float, long int);
-		long int MinimoCriterio(void);
+		long int Collapse(float);
+		void TwoGreater(float*, int* );
+		void ChooseVertices(Hoja& , Hoja& , long int);
+		float HausdorffOptimized(const Hoja &, const Hoja&) const;
+		float DistanceFromCenters(const Hoja &, const Hoja &) const;
+		float distan(float, float, float, float, float, float) const;
+		long int MinDistance(void);
+		void NormalizeDistance(float diametro);
+//		void SetCriteria2(float, long int); obsolete!
+		void SetCriteria2Optimized(float, long int);
+		long int MinCriteria(void);
 
-		void Mesh2Estructura(	const Geometry::Mesh *,
-													Index);
-		
-		void EscribeMesh(int);
+		void Mesh2Structure(const Geometry::Mesh *,Index);
+		void BuildOutputMesh(int);
+		void CrossProduct(const float *v1, const float *v2, float *res) const;
+		float SquaredModule(const float *v) const;
 
-		Mesh			*mesh; // objeto mesh simplificado (para la salida)
+		Mesh			*mesh; // simplified mesh object (for output)
 		const			Mesh *objmesh;
 		float			(*Vertex)[3];
-		Hoja			*Hojasa;  // las activas
-		long int	activas, counth;
+		Hoja			*Leaves;
+		long int	activeLeaves, countLeaves;
 		TreeSimplificationSequence	*mtreesimpsequence;
 		
-	private:
 		//	Update progress bar.
 		Geometry::TIPOFUNC	mUPB;
+
+		// the octree used to speed up the simplification process
+		LeafOctree *octree;
+		void RecursiveCreateLeafOctree(LeafOctree*, int deep); // this is called from CreateLeafNode
+		void RecursiveFillOctreeWithLeaves(LeafOctree*);
+		LeafOctree* CreateLeafOctree(int deep); // generates a new leaf octree and returns its root node
+		int vertex_count;
+		LeafOctree ** octree_owning_leaf;
+		LeafOctree *GetMinOctreeNodeForLeaf(LeafOctree *start, const Hoja &leaf);
+		bool PruneOctree(LeafOctree *); // erases one octree level and translates its leaves to the parent. Returns true if the node itself was pruned
 	};
 }
