Index: GTP/trunk/Lib/Geom/shared/GTGeometry/include/GeoLodTreeLibrary.h
===================================================================
--- GTP/trunk/Lib/Geom/shared/GTGeometry/include/GeoLodTreeLibrary.h	(revision 831)
+++ GTP/trunk/Lib/Geom/shared/GTGeometry/include/GeoLodTreeLibrary.h	(revision 895)
@@ -16,4 +16,5 @@
 {	
 	class IndexData;
+	class VertexData;
 	class LodTreeLibrary
 	{
@@ -22,6 +23,8 @@
 		LodTreeLibrary(LodTreeLibrary*);*/
 		LodTreeLibrary(	std::string trunkSimpSeqFile,
+						std::string leafSimpSeqFile,
 						Geometry::Mesh *treeGeoMesh,
-						std::string foliage_verts,
+						uint32 leafSubMeshID
+						/*std::string foliage_verts,
 						std::string foliage_leafs,
 						std::string foliage_simpl/*,
@@ -54,6 +57,6 @@
 		uint32 CurrentLOD_Foliage_IndexCount(void) const;
 		const IndexData* CurrentLOD_Foliage_Indices(void) const;
-/*		const VertexData* Get_Foliage_VertexData(void) const;
-*/
+		const VertexData* Get_Foliage_VertexData(void) const;
+
 //		Geometry::IndexData *trunk_all_indices;
 //		unsigned int *indices_offsets;
Index: GTP/trunk/Lib/Geom/shared/GTGeometry/src/libs/leaves/Arbol.cpp
===================================================================
--- GTP/trunk/Lib/Geom/shared/GTGeometry/src/libs/leaves/Arbol.cpp	(revision 834)
+++ GTP/trunk/Lib/Geom/shared/GTGeometry/src/libs/leaves/Arbol.cpp	(revision 895)
@@ -4,8 +4,13 @@
 #include "Arbol.h"
 
+
 //--------------------------------------------------------------------------------------------------------------------------------
 // Constructor with the name of a file cotaining the data
 //--------------------------------------------------------------------------------------------------------------------------------
-Arbol::Arbol (const char * arbol, const char* hojas, const char* simplifi, Geometry::CREATEVERTEXDATAFUNC vdfun, Geometry::CREATEINDEXDATAFUNC idfun): 
+/*Arbol::Arbol (const char * arbol, const char* hojas, const char* simplifi, Geometry::CREATEVERTEXDATAFUNC vdfun, Geometry::CREATEINDEXDATAFUNC idfun): 
+create_vertex_data_func(vdfun==NULL?Geometry::DefaultVertexDataCreator:vdfun),
+create_index_data_func(idfun==NULL?Geometry::DefaultIndexDataCreator:idfun),
+vertexdata(NULL), Hojas(NULL), MinDet(NULL)*/
+Arbol::Arbol (const Geometry::SubMesh *leafsSubMesh, const char *simpSeq, Geometry::CREATEVERTEXDATAFUNC vdfun, Geometry::CREATEINDEXDATAFUNC idfun):
 create_vertex_data_func(vdfun==NULL?Geometry::DefaultVertexDataCreator:vdfun),
 create_index_data_func(idfun==NULL?Geometry::DefaultIndexDataCreator:idfun),
@@ -13,5 +18,22 @@
 {	
 	cx = cy= cz= 0;
-	ReadFromFile (arbol, hojas, simplifi);
+
+	//VERTICES
+/*	if ((TotVerts=LeeVertices(arbol))==0){ printf("File not found '%s'\n",arbol); exit(1); }//ThrowFileNotFoundError((const char*)arbol);
+	if ((nHojas = LeoHojas (hojas))==0) { printf("File not found '%s'\n",hojas); exit(1); }//ThrowFileNotFoundError((const char*)hojas);
+//	TotTronco = LeoTronco (tronco);
+//	CalculaNormalesVertice();	
+	if ((TotHojas = LeoHojasSimpl(simpli))==0){ printf("File not found '%s'\n",simpli); exit(1); }// ThrowFileNotFoundError((const char*)simpli);	
+	RellenoRaiz();
+
+	CalculaTexCoordsYNorms();*/
+
+
+	ReadVertices(leafsSubMesh);
+	ReadLeafs(leafsSubMesh);
+	if (!ReadSimpSeq(simpSeq)) exit(1);
+	RellenoRaiz();
+	CalculaTexCoordsYNorms();
+
 
 	// esto no sé si devería haber akí
@@ -37,5 +59,5 @@
 // leer informacion desde el fichero
 //--------------------------------------------------------------------------------------------------------------------------------
-void Arbol::ReadFromFile ( const char * arbol, const char* hojas, const char* simpli/*, char* tronco*/) // Reads a obj-model from a file
+/*void Arbol::ReadFromFile ( const char * arbol, const char* hojas, const char* simpli) // Reads a obj-model from a file
 {
 	    
@@ -49,9 +71,30 @@
 
 	CalculaTexCoordsYNorms();
-}
-
-
-#include "TMatrix.h"
-
+}*/
+
+
+//#include "TMatrix.h"
+
+
+void Arbol::ReadVertices(const Geometry::SubMesh *submesh)
+{
+	int countv=submesh->mVertexBuffer->mVertexCount;
+	vertexdata = create_vertex_data_func(2*countv);
+	Hojas = new Hoja[countv*2];
+	indexdata = create_index_data_func(countv*2*3); // 3 indices x 2 triangulos x hoja
+	
+	vertexdata->Begin();
+	for (int i=0; i<countv; i++)
+	{
+		vertexdata->SetVertexCoord( i,	submesh->mVertexBuffer->mPosition[i].x, 
+										submesh->mVertexBuffer->mPosition[i].y, 
+										submesh->mVertexBuffer->mPosition[i].z );
+	}
+	vertexdata->End();
+
+	TotVerts = countv;
+}
+
+/*
 //--------------------------------------------------------------------------------------------------------------------------------
 // Procesar línea para extraer los VERTICES DE VERTICES.OBJ
@@ -66,7 +109,4 @@
 		bool fin_vertices = false;
 
-/*		TMatrix rot90mat;
-		rot90mat.RotateX(-90);
-*/		
 		//cuento todos los vertices, y relleno la estructura
 		if ((fp_origen = fopen (arbol, "r")) == NULL)
@@ -152,5 +192,5 @@
 
 		
-}
+}*/
 
 //--------------------------------------------------------------------------------------------------------------------------------
@@ -319,8 +359,24 @@
 }*/
 
+void Arbol::ReadLeafs(const Geometry::SubMesh *submesh)
+{
+	int numtris = submesh->mIndexCount / 3;
+	nHojas =  numtris / 2;
+	for (int h=0; h<nHojas; h++)
+	{
+		Hojas[h].Vert_Hoja[0] = submesh->mIndex[h*6+0];
+		Hojas[h].Vert_Hoja[1] = submesh->mIndex[h*6+1];
+		Hojas[h].Vert_Hoja[2] = submesh->mIndex[h*6+2];
+		Hojas[h].Vert_Hoja[3] = submesh->mIndex[h*6+5];
+		Hojas[h].visible = 0;
+
+		GetNormalH ( Hojas[h]);
+	}
+}
+
 //--------------------------------------------------------------------------------------------------------------------------------
 // Procesar línea para extraer las HOJAS DE HOJAS.OBJ
 //--------------------------------------------------------------------------------------------------------------------------------
-
+/*
   int Arbol::LeoHojas (const char* hojas)
 {
@@ -376,5 +432,5 @@
 	return (h);	
 }
-
+*/
 
 //--------------------------------------------------------------------------------------------------------------------------------
@@ -415,8 +471,70 @@
 }
 */
+
+
+ /// returns the number of total leafs
+bool Arbol::ReadSimpSeq(const char *simpSeqFile)
+{
+	FILE* fp_simpli;
+	char linea[256], str[10];
+	int v0, v1, v2, v3, tn, tv1,tv2, e=0;
+
+	if ((fp_simpli = fopen (simpSeqFile, "r")) == NULL)
+	{
+		printf ("No he podido abrir el fichero %s\n", simpSeqFile);
+		return false;
+	}
+	else
+	{
+		tn = nHojas;
+		while (fgets (linea, 255, fp_simpli) != NULL)
+		{
+			if (linea[0]<'0' || linea[0]>'9')
+				continue;
+		
+			//N 446 Ver 10176 10178 10169 10171  Tv 156 154 E 2
+
+//			sscanf(linea, "%s %lu %s %lu %lu  %lu %lu %s %lu %lu %s %i", 
+//				&str, &tn, &str, &v0, &v1, &v2, &v3, &str, &tv1, &tv2, &str, &e );
+			long int triviej00=-1, triviej01=-1;
+			long int triviej10=-1, triviej11=-1;
+			sscanf(linea, "%lu %lu %lu %lu & %lu %lu %lu %lu", &triviej00,&triviej01,&triviej10,&triviej11, &v0,&v1,&v2,&v3);
+
+			Hojas[tn].Vert_Hoja[0] = v0;
+			Hojas[tn].Vert_Hoja[1] = v1;
+			Hojas[tn].Vert_Hoja[2] = v2;
+			Hojas[tn].Vert_Hoja[3] = v3;
+
+			Hojas[tn].visible = 0;
+
+			GetNormalH  (Hojas[tn]);
+
+			tv1 = triviej00/2;
+			tv2 = triviej10/2;
+
+			Hojas[tn].hijoi= tv1;
+			Hojas[tn].hijod= tv2;
+
+			Hojas[tv1].padre = tn;
+			Hojas[tv2].padre = tn;		
+
+			tn++;
+		}
+
+	}
+
+	fclose(fp_simpli);
+
+	TotHojas=tn;
+		
+	return true;
+}
+
+
+
 //---------------------------------------------------------------------------------------------------------------------
 // Procesar línea para extraer las HOJAS DE SIMPLIFICA.OBJ
 //---------------------------------------------------------------------------------------------------------------------
-
+/*
   int Arbol::LeoHojasSimpl (const char* simplifica)
 {
@@ -501,5 +619,5 @@
 	return (tn);
 }
-
+*/
  
 //--------------------------------------------------------------------------------------------------------------------------------
Index: GTP/trunk/Lib/Geom/shared/GTGeometry/src/libs/leaves/Hoja.cpp
===================================================================
--- GTP/trunk/Lib/Geom/shared/GTGeometry/src/libs/leaves/Hoja.cpp	(revision 834)
+++ GTP/trunk/Lib/Geom/shared/GTGeometry/src/libs/leaves/Hoja.cpp	(revision 895)
@@ -14,5 +14,5 @@
 	Cuantas_hojas = 1;
 	dist = coplanar = criterio = hoja_cop = hoja_crit =-1;
-	existe = true;
+	existe = false;
 	padre=-1;
 	hijoi = hijod = -1;
Index: GTP/trunk/Lib/Geom/shared/GTGeometry/src/libs/leaves/arbol.h
===================================================================
--- GTP/trunk/Lib/Geom/shared/GTGeometry/src/libs/leaves/arbol.h	(revision 830)
+++ GTP/trunk/Lib/Geom/shared/GTGeometry/src/libs/leaves/arbol.h	(revision 895)
@@ -7,6 +7,5 @@
 #include "Point3D.h"
 #include "Activas.h"
-
-
+#include "GeoSubMesh.h"
 
 class Arbol
@@ -37,14 +36,18 @@
 
 	public :
-		Arbol (const char *, const char *, const char*, Geometry::CREATEVERTEXDATAFUNC vdfun=NULL, Geometry::CREATEINDEXDATAFUNC idfun=NULL); // Constructor with the name of a file cotaining the data
+//		Arbol (const char *, const char *, const char*, Geometry::CREATEVERTEXDATAFUNC vdfun=NULL, Geometry::CREATEINDEXDATAFUNC idfun=NULL); // Constructor with the name of a file cotaining the data
+		Arbol (const Geometry::SubMesh *, const char *simpSeq, Geometry::CREATEVERTEXDATAFUNC vdfun=NULL, Geometry::CREATEINDEXDATAFUNC idfun=NULL); // Constructor with the name of a file cotaining the data
 		Arbol (Arbol *a);
 		virtual ~Arbol (void); // Destructor
 		
 		// Montan la estructura
-		void ReadFromFile (const char *, const char*, const char*/*, char**/); // Reads a obj-model from a file
-		int LeeVertices ( const char * );
+//		void ReadFromFile (const char *, const char*, const char*/*, char**/); // Reads a obj-model from a file
+/*		int LeeVertices ( const char * );
 		int LeoHojas( const char *);
 //		int LeoTronco( char *);
-		int LeoHojasSimpl( const char*);
+		int LeoHojasSimpl( const char*);*/
+		void ReadLeafs(const Geometry::SubMesh *);
+		void ReadVertices(const Geometry::SubMesh *);
+		bool ReadSimpSeq(const char*); /// returns true when successful
 		void RellenoRaiz (void);
 
Index: GTP/trunk/Lib/Geom/shared/GTGeometry/src/libs/leaves/foliage.cpp
===================================================================
--- GTP/trunk/Lib/Geom/shared/GTGeometry/src/libs/leaves/foliage.cpp	(revision 830)
+++ GTP/trunk/Lib/Geom/shared/GTGeometry/src/libs/leaves/foliage.cpp	(revision 895)
@@ -992,42 +992,2 @@
 
  }
-
-/******************************************   IMPOSTORES **************************************************/
-	
-//--------------------------------------------------------------------------------------------------------------------------------
-// Dibuja la caja envolvente. DibujaCaja la dibuja realmente, y la 
-//--------------------------------------------------------------------------------------------------------------------------------
-			/*	
-void Foliage::DibujaCaja (float alfa, float d)
-{
-
-	glPushMatrix();
-
-	glColor3f(1.0, 0.0, 0.0);
-
-//	glLineWidth(2.0);
-//	glTranslated (0.0,cy, 0.0);
-//	glScalef (width,heigth,depth);
-//	glutWireCube ( 1.0);
-	glRotatef(-alfa,0,1,0);
-
-	glPolygonMode (GL_FRONT_AND_BACK, GL_LINE);
-	glBegin (GL_POLYGON); 
-
-		glVertex3f (MiArbol->cx + MiArbol->rad, MiArbol->cy - MiArbol->rad, d); 
-		glVertex3f (MiArbol->cx - MiArbol->rad, MiArbol->cy - MiArbol->rad, d);
-		glVertex3f (MiArbol->cx - MiArbol->rad, MiArbol->cy + MiArbol->rad, d);
-		glVertex3f (MiArbol->cx + MiArbol->rad, MiArbol->cy + MiArbol->rad, d);
-
-
-	glEnd();
-
-
-	glColor3f(1.0, 1.0, 1.0);
-
-	glPopMatrix();
-	
-
-}
-
-*/
Index: GTP/trunk/Lib/Geom/shared/GTGeometry/src/SimplificationMethod.cpp
===================================================================
--- GTP/trunk/Lib/Geom/shared/GTGeometry/src/SimplificationMethod.cpp	(revision 891)
+++ GTP/trunk/Lib/Geom/shared/GTGeometry/src/SimplificationMethod.cpp	(revision 895)
@@ -663,5 +663,5 @@
 //Unify the model to work with it
 //The vertices that have the same space coordinates are stored as an unique vertex
-//in order to not produce holes in the simplification
+//in order to avoid holes in the simplification
 //The necessary information to store correctly the decimation data is stored
 void SimplificationMethod::geomesh2simplifModel(void)
@@ -679,5 +679,5 @@
 		{
 			//If the model has texture information
-			if (objmesh->mSubMesh[i].mVertexBuffer->mVertexInfo & VERTEX_TEXCOORDS) 
+/*			if (objmesh->mSubMesh[i].mVertexBuffer->mVertexInfo & VERTEX_TEXCOORDS) 
 			{
 				//For all the vertices of each submesh
@@ -727,5 +727,5 @@
 			}
 			else //the model has not texture information
-			{ 
+			{ */
 				//For all the vertices of each submesh
 				for (size_t j=0; j<objmesh->mSubMesh[i].mVertexBuffer->mVertexCount; j++) 
@@ -764,10 +764,10 @@
 					}	
 				}
-			}
-		}
-		if (objmesh->mSubMesh[i].mSharedVertexBuffer)
-		{
-			printf("Shared break\n");
-			break;
+		/*	}*/
+			if (objmesh->mSubMesh[i].mSharedVertexBuffer)
+			{
+				printf("Shared break");
+				break;
+			}
 		}
 	}
Index: GTP/trunk/Lib/Geom/shared/GTGeometry/src/GeoLodTreeLibrary.cpp
===================================================================
--- GTP/trunk/Lib/Geom/shared/GTGeometry/src/GeoLodTreeLibrary.cpp	(revision 831)
+++ GTP/trunk/Lib/Geom/shared/GTGeometry/src/GeoLodTreeLibrary.cpp	(revision 895)
@@ -10,8 +10,10 @@
 
 Geometry::LodTreeLibrary::LodTreeLibrary(std::string trunkSimpSeqFile,
-							   Geometry::Mesh *treeGeoMesh,
-							   std::string foliage_verts, 
-							   std::string foliage_leafs, 
-							   std::string foliage_simpl/*,
+										 std::string leafSimpSeqFile,
+										 Geometry::Mesh *treeGeoMesh,
+										 uint32 leafSubMeshID/*
+								std::string foliage_verts, 
+								std::string foliage_leafs, 
+								std::string foliage_simpl,
 							   uint32 leafSubMeshID,
 							   CREATEVERTEXDATAFUNC vdfun,
@@ -25,5 +27,7 @@
 
 	// Cargar la copa del árbol
-	arbol = new Arbol(foliage_verts.c_str(),foliage_leafs.c_str(),foliage_simpl.c_str(),NULL/*vdfun*/,NULL/*idfun*/);
+//	arbol = new Arbol(foliage_verts.c_str(),foliage_leafs.c_str(),foliage_simpl.c_str(),NULL/*vdfun*/,NULL/*idfun*/);
+	Geometry::SubMesh * leafsSubMesh = &(treeGeoMesh->mSubMesh[leafSubMeshID]);
+	arbol = new Arbol(leafsSubMesh,leafSimpSeqFile.c_str());
 	foliage = new Foliage(arbol);
 }
@@ -151,10 +155,12 @@
 uint32 LodTreeLibrary::MinFoliageLod(void) const
 {
-	return arbol->minHojas; // una hoja: preguntar a francisco
+//	return arbol->minHojas;
+	return arbol->nHojas;
 }
 uint32 LodTreeLibrary::MaxFoliageLod(void) const
 {
-//	return arbol->TotHojas;
-	return arbol->nHojas;
+	//	return arbol->TotHojas;
+	//return arbol->nHojas;
+	return arbol->minHojas;
 }
 
@@ -170,10 +176,10 @@
 }*/
 
-/*
+
 const VertexData* LodTreeLibrary::Get_Foliage_VertexData(void) const
 {
 	return arbol->vertexdata;
 }
-*/
+
 const IndexData* LodTreeLibrary::CurrentLOD_Foliage_Indices(void) const
 {
Index: GTP/trunk/Lib/Geom/shared/GTGeometry/src/GeoTreeSimplifier.cpp
===================================================================
--- GTP/trunk/Lib/Geom/shared/GTGeometry/src/GeoTreeSimplifier.cpp	(revision 834)
+++ GTP/trunk/Lib/Geom/shared/GTGeometry/src/GeoTreeSimplifier.cpp	(revision 895)
@@ -179,12 +179,13 @@
 		Hojasa[pos].Vert_Hoja[1]=v2;
 		Hojasa[pos].Vert_Hoja[2]=v3;
+		Hojasa[pos].id_triangulo[0]=num_triangulo;
+		Hojasa[pos].existe=true;
 		num_triangulo++;
-		Hojasa[pos].id_triangulo[0]=num_triangulo;
 
 		// Segundo triángulo
 		v3=mesh->mSubMesh[meshLeaves].mIndex[j+5];
 		Hojasa[pos].Vert_Hoja[3]=v3;
+		Hojasa[pos].id_triangulo[1]=num_triangulo;
 		num_triangulo++;
-		Hojasa[pos].id_triangulo[1]=num_triangulo;
 
 		Centroh(Hojasa[pos]);
@@ -1025,4 +1026,6 @@
      	Hojasa[counth].existe = true;
 		Hojasa[counth].criterio = 1000;
+		Hojasa[counth].id_triangulo[0] = counth*2;
+		Hojasa[counth].id_triangulo[1] = counth*2+1;
 
  		//coplanaridad
Index: GTP/trunk/Lib/Geom/shared/GeoTool/include/GeoMeshViewUI.h
===================================================================
--- GTP/trunk/Lib/Geom/shared/GeoTool/include/GeoMeshViewUI.h	(revision 841)
+++ GTP/trunk/Lib/Geom/shared/GeoTool/include/GeoMeshViewUI.h	(revision 895)
@@ -42,4 +42,5 @@
 #include	"GeoTreeSimpSequence.h"
 #include	"GeoLodStripsConstructor.h"
+#include	"GeoLodTreeConstructor.h"
 #include	"GeoLodTreeLibrary.h"
 
@@ -58,4 +59,5 @@
 	LODSTRIPS_AUTO,
 	LODTREES,
+	LODTREES_AUTO,
 	SELECT_LEAVES,
 	VISUALIZE_LODSTRIPS,
@@ -174,4 +176,6 @@
 	inline void cb_menuLodTreesOpenLeavesSimplification_i(fltk::Item*, void*);
 	static void cb_menuLodTreesOpenLeavesSimplification(fltk::Item*, void*);
+	inline void cb_menuLodTreesGenerate_i(fltk::Item*, void*);
+	static void cb_menuLodTreesGenerate(fltk::Item*, void*);
 	inline void cb_menuLodTreesVisualize_i(fltk::Item*, void*);
 	static void cb_menuLodTreesVisualize(fltk::Item*, void*);
@@ -187,6 +191,8 @@
 	inline void cb_mMeshInfo_i(fltk::Browser*, void*);
 	static void cb_mMeshInfo(fltk::Browser*, void*);
-	inline void cb_mLodSlider_i(fltk::Slider*, void*);
-	static void cb_mLodSlider(fltk::Slider*, void*);
+	inline void cb_mLodStripSlider_i(fltk::Slider*, void*);
+	static void cb_mLodStripSlider(fltk::Slider*, void*);
+	inline void cb_mLodTreeSlider_i(fltk::Slider*, void*);
+	static void cb_mLodTreeSlider(fltk::Slider*, void*);
 
 	//	Logo's callback.
@@ -204,4 +210,5 @@
 	void	showOpenMeshSimplification();
 	void	showAutoGenerateLodStrips();
+	void	showAutoGenerateLodTrees();
 
 	//	Shows the LodTrees panel.
@@ -212,5 +219,6 @@
 	
 	//	Show the LodStrips visulization panel.
-	void	showSlider();
+	void	showLodStripSlider();
+	void	showLodTreeSlider();
 
 	void	hideStripify();
@@ -224,5 +232,6 @@
 
 	//	Hide the LodStrips visualization panel.
-	void	hideSlider();
+	void	hideLodStripSlider();
+	void	hideLodTreeSlider();
 	
 	//	Get the number of vertices.
@@ -247,5 +256,5 @@
 
 	//	Create a siplification sequence of the leaves.
-	void	createLeavesSequence();
+	void	createLeavesSequence(const std::string &);
 
 	//	Stripify the mesh object.
@@ -301,4 +310,5 @@
 	fltk::Item					*menuLodStripsVisualize;
 	fltk::ItemGroup			*menuLodTrees;
+	fltk::Item					*menuLodTreesGenerate;
 	fltk::Item					*menuLodTreesVisualize;
 
@@ -321,5 +331,6 @@
 	fltk::Button				*mButtonBuild;
 	fltk::ProgressBar		*mBuildBar;
-	fltk::Slider				*mLodSlider;
+	fltk::Slider				*mLodStripSlider;
+	fltk::Slider				*mLodTreeSlider;
 	fltk::CheckButton		*mGeometryBased;
 	fltk::CheckButton		*mImageBased;
@@ -344,5 +355,5 @@
 	void	setLodStripsLibrary(std::string lodfile, Mesh	*geomesh);
 	//	Initialize the lodtreelibrary for visualization.
-	void	setLodTreesLibrary(std::string lodfile, Mesh	*geomesh);
+	void	setLodTreesLibrary(std::string lodfile, std::string leafseqfile, Mesh	*geomesh, uint32 ileafSubMesh);
 
 	// 26-12-2005
Index: GTP/trunk/Lib/Geom/shared/GeoTool/include/GeoMeshView.h
===================================================================
--- GTP/trunk/Lib/Geom/shared/GeoTool/include/GeoMeshView.h	(revision 829)
+++ GTP/trunk/Lib/Geom/shared/GeoTool/include/GeoMeshView.h	(revision 895)
@@ -169,5 +169,6 @@
 
 	//	Change de Level of detail of the object.
-	void	GoToLod(unsigned int lod);
+	void	GoToLod_LodStrip(unsigned int lod);
+	void	GoToLod_LodTree(unsigned int lod);
 
 	private:
Index: GTP/trunk/Lib/Geom/shared/GeoTool/src/GeoMeshViewUI.cpp
===================================================================
--- GTP/trunk/Lib/Geom/shared/GeoTool/src/GeoMeshViewUI.cpp	(revision 891)
+++ GTP/trunk/Lib/Geom/shared/GeoTool/src/GeoMeshViewUI.cpp	(revision 895)
@@ -3,4 +3,5 @@
 #include "GeoMeshViewUI.h"
 #include "resource.h"
+#include "GeoLodTreeConstructor.h"
 
 using	namespace	Geometry;
@@ -65,6 +66,5 @@
 
 		//	Save the file mesh.
-		mesh_saver->save(	mGeoMesh,
-				mFileName);
+		mesh_saver->save(mGeoMesh, mFileName);
 
 		//	Free memory.
@@ -100,8 +100,5 @@
 		{
 			mesh_saver	=	new	GeoMeshSaver(mMeshBounds);
-
-			mesh_saver->save(	mGeoMesh,
-					filename_name(fcho->value()));
-
+			mesh_saver->save(mGeoMesh,filename_name(fcho->value()));
 			delete	mesh_saver;
 		}
@@ -151,7 +148,5 @@
   
 	//	Open file chooser dialog.
-	p	=	fltk::file_chooser(	"Export to OBJ",
-													"*.obj",
-													"");
+	p	=	fltk::file_chooser("Export to OBJ","*.obj","");
 	if (p && mGeoMesh)
 	{
@@ -667,4 +662,35 @@
 
 //---------------------------------------------------------------------------
+//	Auto Generate LodStrips Callback
+//---------------------------------------------------------------------------
+inline void GeoMeshViewUI::cb_menuLodTreesGenerate_i(fltk::Item*, void*)
+{
+	//	Show title.
+	mProcessTitle->label("Generate LodTree");
+	mProcessBar->position(0);
+	mBuildBar->position(0);
+
+	//	Hide the right panel.
+	hideRightPanel();
+
+	//	Show the LodStrips panel.
+	showAutoGenerateLodTrees();
+	
+	//	Sets menus application state to LODSTRIPS_AUTO.
+	mApplicationState	=	LODTREES_AUTO;
+
+	//	Repaint the window.
+	mMainWindow->redraw();
+}
+
+void GeoMeshViewUI::cb_menuLodTreesGenerate(fltk::Item* o, void* v)
+{
+  ((GeoMeshViewUI*)	(o->parent()->parent()->parent()->user_data()))
+										->
+										cb_menuLodTreesGenerate_i(o,v);
+}
+
+
+//---------------------------------------------------------------------------
 //	Visualize LodStrips Callback
 //---------------------------------------------------------------------------
@@ -715,5 +741,5 @@
 
 	//	Show the Visulize LodStrips panel.
-	showSlider();
+	showLodStripSlider();
 	
 	//	Repaint the window.
@@ -739,4 +765,21 @@
 	//	Show title.
 	mProcessTitle->label("Visualize LodTrees");
+
+	/*if (geoMeshView->getLeavesSubmesh()==-1)
+	{
+		fltk::alert("No se ha seleccionado el submesh de hojas!");
+		return;
+	}*/
+
+	// POR AHORA SE SELECCIONA EL PRIMER SUBMESH QUE NO ES STRIPS COMO HOJAS
+	int leafsSubMeshID = -1;
+	for (int i=0; i<mGeoMesh->mSubMeshCount; i++)
+		if (mGeoMesh->mSubMesh[i].mType==GEO_TRIANGLE_LIST)
+		{
+			leafsSubMeshID=i;
+			break;
+		}
+
+
 
 	//	If an object is loaded.
@@ -754,8 +797,23 @@
 		{
 			//	Build lod strips library.
-			setLodTreesLibrary(string(fcho->value()), mGeoMesh);
-
-			//	Sets the aplication mode.
-			mApplicationState	=	VISUALIZE_LODTREES;
+
+			std::string lodstripFile(fcho->value());
+			delete fcho;
+			fcho	=	new fltk::FileChooser("",
+					"*.leafseq",
+					fltk::FileChooser::CREATE,
+					"Open LeafSeq file");
+
+			fcho->exec();
+
+			if (fcho->value())
+			{
+				std::string leafseqFile(fcho->value());
+
+				setLodTreesLibrary(lodstripFile, leafseqFile, mGeoMesh, leafsSubMeshID);
+
+				//	Sets the aplication mode.
+				mApplicationState	=	VISUALIZE_LODTREES;
+			}
 		}
 
@@ -768,5 +826,6 @@
 
 	//	Show the Visulize LodTree panel.
-	showSlider();
+	showLodStripSlider();
+	showLodTreeSlider();
 	
 	//	Repaint the window.
@@ -904,9 +963,51 @@
 
 				//	Create the leaves simplification sequence.
-				createLeavesSequence();
+				createLeavesSequence("leavesSimplification.txt");
 				
 				break;
 
 				//	Simplify and generate simplification sequence.
+			case	LODTREES_AUTO:
+				if (idMeshLeaves==(unsigned short)-1)
+				{
+					fltk::alert("Leaves submesh not selected!");
+				}
+				else
+				{
+					std::cout << "Simplificando hojas...";
+					simplifyLeavesCollapse();
+					std::cout << "OK!" << std::endl;
+
+//					std::cout << "Creando secuencia de simplificacion de hojas...";
+//					createLeavesSequence("leavesSimplification.txt");
+//					std::cout << "OK!" << std::endl;
+
+					undo();
+
+
+					std::cout << "Simplificando tronco...";
+					std::cout << "OK!" << std::endl;
+
+					//	Transform NoSV Mesh to a SV Mesh.
+					mesh_aux	=	mGeoMesh->toSharedVertex();
+
+					//	Deletes the mesh No Shared Vertex.
+					delete	mGeoMesh;
+
+					//	Gets the mesh Shared Vertex.
+					mGeoMesh	=	mesh_aux;
+
+					geoMeshView->setMesh(mGeoMesh);
+
+					//	Simplify the mesh object.
+					simplifyEdgeCollapse();
+
+					//	Create the qslim simplification sequence.
+					createQslimSequence();
+
+				}
+				
+				break; 
+
 			case	LODSTRIPS_AUTO:
 
@@ -994,5 +1095,5 @@
 inline void GeoMeshViewUI::cb_mButtonBuild_i(fltk::Button*, void*)
 {
-	char					*file_name;
+	char			*file_name=NULL;
 	GeoMeshSaver	*mesh_saver;
 	Serializer		*oSerializer;
@@ -1011,12 +1112,38 @@
 		{
 			//	Build the LOD file.
+			case	LODTREES_AUTO:			
+				
+				//	Open file chooser dialog.
+				file_name	=	fltk::file_chooser("Build LOD","*","");
+				if (!file_name)
+					break;
+
+				std::cout << "Creando secuencia de simplificacion de hojas...";
+				createLeavesSequence(file_name+std::string(".leafseq"));
+				std::cout << "OK!" << std::endl;
+
+/*				TreeSimplificationSequence * auxTreeSimpSequence = new TreeSimplificationSequence();
+				auxTreeSimpSequence->Load(Serializer("leavesSimplification.txt",Serializer::READ));
+
+				if (auxTreeSimpSequence && mGeoMesh)
+				{
+					LodTreeConstructor * auxLodTreeConstructor = new LodTreeConstructor(mGeoMesh,auxTreeSimpSequence);
+					delete auxLodTreeConstructor;
+				}
+				else
+				{
+					fltk::alert("There is no leaf simplification sequence.");
+					break;
+				}
+
+
+				delete auxTreeSimpSequence;*/
+				
+
 			case	LODSTRIPS_AUTO:
 
-				// Builder
-				//	Open file chooser dialog.
-				file_name	=	fltk::file_chooser(	"Build LOD",
-						"*",
-						"");
-
+				// Builder					
+				if (!file_name)
+					file_name	=	fltk::file_chooser("Build LOD","*","");
 				//	If a file was selected.
 				if (file_name)
@@ -1035,6 +1162,5 @@
 
 					//	Loads a simplification sequence file.
-					oMeshSimpSequence->Load(Serializer(	"mqslimSequence.txt",
-								Serializer::READ));
+					oMeshSimpSequence->Load(Serializer("mqslimSequence.txt",Serializer::READ));
 
 					//	If the simplification sequence and the mesh exist.
@@ -1046,6 +1172,5 @@
 								progress_function);
 
-						oSerializer	=	new Serializer(	strcat(file_name,".lod"),
-								Serializer::Mode::WRITE);
+						oSerializer	=	new Serializer(strcat(file_name,".lod"),Serializer::Mode::WRITE);
 
 						oLodStrip->Save(*oSerializer);
@@ -1070,6 +1195,5 @@
 						mesh_saver	=	new	GeoMeshSaver(mMeshBounds);
 						file_name[strlen(file_name) - 4]	=	'\0';
-						mesh_saver->save(	mGeoMesh,
-								strcat(file_name,".mesh"));
+						mesh_saver->save(mGeoMesh, strcat(file_name,".mesh"));
 						delete	mesh_saver;
 
@@ -1101,8 +1225,8 @@
 //	Lod Slider Callback
 //---------------------------------------------------------------------------
-inline void GeoMeshViewUI::cb_mLodSlider_i(fltk::Slider	*o, void	*)
+inline void GeoMeshViewUI::cb_mLodStripSlider_i(fltk::Slider	*o, void	*)
 {
 	//	Change the lod.
-	geoMeshView->GoToLod((unsigned int)o->value());
+	geoMeshView->GoToLod_LodStrip((unsigned int)o->value());
 
 	//	Refresh data aplication.
@@ -1112,10 +1236,34 @@
 }
 
-void GeoMeshViewUI::cb_mLodSlider(fltk::Slider	*o, void	*v)
-{
-  ((GeoMeshViewUI*)	(o->parent()->parent()->parent()->user_data()))
-										->
-										cb_mLodSlider_i(o,v);
-}
+void GeoMeshViewUI::cb_mLodStripSlider(fltk::Slider	*o, void	*v)
+{
+  ((GeoMeshViewUI*)	(o->parent()->parent()->parent()->user_data()))
+										->
+										cb_mLodStripSlider_i(o,v);
+}
+
+
+//---------------------------------------------------------------------------
+//	Lod Slider Callback for the foliage
+//---------------------------------------------------------------------------
+inline void GeoMeshViewUI::cb_mLodTreeSlider_i(fltk::Slider	*o, void	*)
+{
+	//	Change the lod.
+	geoMeshView->GoToLod_LodTree((unsigned int)o->value());
+
+	//	Refresh data aplication.
+	refreshApplicationBar();
+		
+	mMainWindow->flush();
+}
+
+void GeoMeshViewUI::cb_mLodTreeSlider(fltk::Slider	*o, void	*v)
+{
+  ((GeoMeshViewUI*)	(o->parent()->parent()->parent()->user_data()))
+										->
+										cb_mLodTreeSlider_i(o,v);
+}
+
+
 
 //---------------------------------------------------------------------------
@@ -1418,12 +1566,26 @@
 	mBuildBar->activate();
 }
+//---------------------------------------------------------------------------
+//	Shows the auto generate LodStrips panel
+//---------------------------------------------------------------------------
+void	GeoMeshViewUI::showAutoGenerateLodTrees()
+{
+	//	Shows the simplify panel.
+	showEdgeCollapse();
+
+	mButtonBuild->set_visible();
+	mButtonBuild->activate();
+
+	mBuildBar->set_visible();
+	mBuildBar->activate();
+}
 
 //---------------------------------------------------------------------------
 //	Show the LodStrips visulization panel
 //---------------------------------------------------------------------------
-void	GeoMeshViewUI::showSlider()
-{
-	mLodSlider->set_visible();
-	mLodSlider->activate();
+void	GeoMeshViewUI::showLodStripSlider()
+{
+	mLodStripSlider->set_visible();
+	mLodStripSlider->activate();
 }
 
@@ -1431,8 +1593,26 @@
 //	Hide the LodStrips visualization panel
 //---------------------------------------------------------------------------
-void	GeoMeshViewUI::hideSlider()
-{
-	mLodSlider->hide();
-	mLodSlider->deactivate();
+void	GeoMeshViewUI::hideLodStripSlider()
+{
+	mLodStripSlider->hide();
+	mLodStripSlider->deactivate();
+}
+
+//---------------------------------------------------------------------------
+//	Show the LodTree visulization panel
+//---------------------------------------------------------------------------
+void	GeoMeshViewUI::showLodTreeSlider()
+{
+	mLodTreeSlider->set_visible();
+	mLodTreeSlider->activate();
+}
+
+//---------------------------------------------------------------------------
+//	Hide the LodTree visualization panel
+//---------------------------------------------------------------------------
+void	GeoMeshViewUI::hideLodTreeSlider()
+{
+	mLodTreeSlider->hide();
+	mLodTreeSlider->deactivate();
 }
 
@@ -1580,5 +1760,6 @@
 	hideOpenMeshSimplification();
 	hideOpenLeavesSimplification();
-	hideSlider();
+	hideLodStripSlider();
+	hideLodTreeSlider();
 	hideMeshInfo();
 }
@@ -1858,5 +2039,5 @@
 //	Create a simplification sequence of the leaves.
 //---------------------------------------------------------------------------
-void	GeoMeshViewUI::createLeavesSequence()
+void	GeoMeshViewUI::createLeavesSequence(const std::string &filename)
 {
 	TreeSimplificationSequence	*tree_sequencer;
@@ -1865,5 +2046,5 @@
 	
 	tree_sequencer->putMeshName(nombremesh); 
-	tree_sequencer->Save(Serializer("leavesSequence.txt",Serializer::WRITE));
+	tree_sequencer->Save(Serializer(filename,Serializer::WRITE));
 
 	delete	tree_sequencer;
@@ -2032,5 +2213,5 @@
 
 	//	Sets the slider range.
-	mLodSlider->range(lodStripsLib->MaxLod(),
+	mLodStripSlider->range(lodStripsLib->MaxLod(),
 										lodStripsLib->MinLod());
 
@@ -2039,5 +2220,5 @@
 	
 	//	Puts the slider in the max position.
-	mLodSlider->value(lodStripsLib->MinLod());
+	mLodStripSlider->value(lodStripsLib->MinLod());
 }
 
@@ -2045,5 +2226,7 @@
 //	Initialize the lodTreelibrary for visualization.
 //---------------------------------------------------------------------------
-void	GeoMeshViewUI::setLodTreesLibrary(std::string lodfile, Mesh	*geomesh)
+//void	GeoMeshViewUI::setLodTreesLibrary(std::string lodfile, Mesh	*geomesh)
+void	GeoMeshViewUI::setLodTreesLibrary(std::string lodfile, std::string leafseqfile, Mesh *geomesh, uint32 ileafSubMesh)
+
 {
 	//	If there is no lod strips object.
@@ -2054,10 +2237,13 @@
 
 	//	New lod strips object.
-	lodTreeLib	=	new	Geometry::LodTreeLibrary(lodfile, geomesh,"\\\\quake\\home\\\Modelos\\betula_populifolia\\vertices.obj",
+/*	lodTreeLib	=	new	Geometry::LodTreeLibrary(lodfile, geomesh,"\\\\quake\\home\\\Modelos\\betula_populifolia\\vertices.obj",
 										"\\\\quake\\home\\\Modelos\\betula_populifolia\\hojas.obj",
-										"\\\\quake\\home\\\Modelos\\betula_populifolia\\simplifica.obj");
+										"\\\\quake\\home\\\Modelos\\betula_populifolia\\simplifica.obj");*/
+
+	lodTreeLib = new Geometry::LodTreeLibrary(lodfile,leafseqfile,geomesh,ileafSubMesh);
 
 	//	Sets the slider range.
-	mLodSlider->range(lodTreeLib->MaxTrunkLod(), lodTreeLib->MinTrunkLod());
+	mLodStripSlider->range(lodTreeLib->MaxTrunkLod(), lodTreeLib->MinTrunkLod());
+	mLodTreeSlider->range(lodTreeLib->MaxFoliageLod(), lodTreeLib->MinFoliageLod());
 
 	//	Pass to geomeshview the lod strips object.
@@ -2065,5 +2251,6 @@
 	
 	//	Puts the slider in the max position.
-	mLodSlider->value(lodTreeLib->MinTrunkLod());
+	mLodStripSlider->value(lodTreeLib->MinTrunkLod());
+	mLodTreeSlider->value(lodTreeLib->MinFoliageLod());
 }
 
@@ -2289,8 +2476,17 @@
 				{
 					fltk::Slider* o;
-					o = mLodSlider = new fltk::Slider(16, 50, 30, 450);
+					o = mLodStripSlider = new fltk::Slider(16, 50, 30, 450);
 					o->type(fltk::Slider::TICK_BELOW);
 					o->set_vertical();
-					o->callback((fltk::Callback*)cb_mLodSlider);
+					o->callback((fltk::Callback*)cb_mLodStripSlider);
+					o->hide();
+					o->deactivate();
+				}
+				{
+					fltk::Slider* o;
+					o = mLodTreeSlider = new fltk::Slider(46, 50, 30, 450);
+					o->type(fltk::Slider::TICK_BELOW);
+					o->set_vertical();
+					o->callback((fltk::Callback*)cb_mLodTreeSlider);
 					o->hide();
 					o->deactivate();
@@ -2609,5 +2805,10 @@
 				{
 					fltk::Item* o;
-					o = menuLodTreesVisualize = new fltk::Item("Visualize Trunk");
+					o = menuLodTreesGenerate = new fltk::Item("Generate");
+					o->callback((fltk::Callback*)cb_menuLodTreesGenerate);
+				}
+				{
+					fltk::Item* o;
+					o = menuLodTreesVisualize = new fltk::Item("Visualize");
 					o->callback((fltk::Callback*)cb_menuLodTreesVisualize);
 				}
Index: GTP/trunk/Lib/Geom/shared/GeoTool/src/GeoMeshView.cpp
===================================================================
--- GTP/trunk/Lib/Geom/shared/GeoTool/src/GeoMeshView.cpp	(revision 842)
+++ GTP/trunk/Lib/Geom/shared/GeoTool/src/GeoMeshView.cpp	(revision 895)
@@ -1,3 +1,4 @@
 #include "GeoMeshView.h"
+#include <VertexData.h>
 
 using	namespace	Geometry;
@@ -413,4 +414,5 @@
 		mPan							=	false;
 		mLodStrip					=	false;
+		mLodTree					=	false;
 		mIdVisualList			=	0;
 		mSubMeshCount			=	0;
@@ -913,4 +915,7 @@
 	current_strip	=	0;
 
+
+	// DRAW THE TRUNK AS A LODSTRIP OBJECT
+
 	//	For each submesh.
 	for (int submesh = 0; submesh < geoMesh->mSubMeshCount; submesh++)
@@ -976,4 +981,21 @@
 		}
 	}
+
+	// DRAW THE LEAVES AS A TRIANGLE SOUP
+	glColor3f(0,1,1);
+	glDisable(GL_LIGHTING);
+	glBegin(GL_TRIANGLES);
+	const Geometry::VertexData *foliage_verts = lodTreeLib->Get_Foliage_VertexData();
+	const Geometry::IndexData *foliage_inds = lodTreeLib->CurrentLOD_Foliage_Indices();
+	for (int j=0; j<lodTreeLib->CurrentLOD_Foliage_IndexCount(); j++)
+	{
+		float vx,vy,vz;
+		foliage_verts->GetVertexCoord(foliage_inds->GetIndex(j),vx,vy,vz);
+		glVertex3f(vx,vy,vz);
+	}
+	glEnd();
+
+	glEnable(GL_LIGHTING);
+	glColor3f(1,1,1);
 	
 }//End drawTriangleStrip.
@@ -1002,5 +1024,5 @@
 //	Change de Level of detail of the object.
 //---------------------------------------------------------------------------
-void	GeoMeshView::GoToLod(unsigned int	lod)
+void	GeoMeshView::GoToLod_LodStrip(unsigned int	lod)
 {
 	if (mLodStrip)
@@ -1010,4 +1032,15 @@
 	draw();
 }
+
+//---------------------------------------------------------------------------
+//	Change de Level of detail of the object.
+//---------------------------------------------------------------------------
+void	GeoMeshView::GoToLod_LodTree(unsigned int	lod)
+{
+	if (mLodTree)
+		lodTreeLib->GoToFoliageLod(lod);
+	draw();
+}
+
 
 //---------------------------------------------------------------------------
