Changeset 895


Ignore:
Timestamp:
05/04/06 13:18:08 (18 years ago)
Author:
gumbau
Message:

Working LODTree constructor and visualizer

Location:
GTP/trunk/Lib/Geom/shared
Files:
12 edited

Legend:

Unmodified
Added
Removed
  • GTP/trunk/Lib/Geom/shared/GTGeometry/include/GeoLodTreeLibrary.h

    r831 r895  
    1616{        
    1717        class IndexData; 
     18        class VertexData; 
    1819        class LodTreeLibrary 
    1920        { 
     
    2223                LodTreeLibrary(LodTreeLibrary*);*/ 
    2324                LodTreeLibrary( std::string trunkSimpSeqFile, 
     25                                                std::string leafSimpSeqFile, 
    2426                                                Geometry::Mesh *treeGeoMesh, 
    25                                                 std::string foliage_verts, 
     27                                                uint32 leafSubMeshID 
     28                                                /*std::string foliage_verts, 
    2629                                                std::string foliage_leafs, 
    2730                                                std::string foliage_simpl/*, 
     
    5457                uint32 CurrentLOD_Foliage_IndexCount(void) const; 
    5558                const IndexData* CurrentLOD_Foliage_Indices(void) const; 
    56 /*              const VertexData* Get_Foliage_VertexData(void) const; 
    57 */ 
     59                const VertexData* Get_Foliage_VertexData(void) const; 
     60 
    5861//              Geometry::IndexData *trunk_all_indices; 
    5962//              unsigned int *indices_offsets; 
  • GTP/trunk/Lib/Geom/shared/GTGeometry/src/GeoLodTreeLibrary.cpp

    r831 r895  
    1010 
    1111Geometry::LodTreeLibrary::LodTreeLibrary(std::string trunkSimpSeqFile, 
    12                                                            Geometry::Mesh *treeGeoMesh, 
    13                                                            std::string foliage_verts,  
    14                                                            std::string foliage_leafs,  
    15                                                            std::string foliage_simpl/*, 
     12                                                                                 std::string leafSimpSeqFile, 
     13                                                                                 Geometry::Mesh *treeGeoMesh, 
     14                                                                                 uint32 leafSubMeshID/* 
     15                                                                std::string foliage_verts,  
     16                                                                std::string foliage_leafs,  
     17                                                                std::string foliage_simpl, 
    1618                                                           uint32 leafSubMeshID, 
    1719                                                           CREATEVERTEXDATAFUNC vdfun, 
     
    2527 
    2628        // Cargar la copa del árbol 
    27         arbol = new Arbol(foliage_verts.c_str(),foliage_leafs.c_str(),foliage_simpl.c_str(),NULL/*vdfun*/,NULL/*idfun*/); 
     29//      arbol = new Arbol(foliage_verts.c_str(),foliage_leafs.c_str(),foliage_simpl.c_str(),NULL/*vdfun*/,NULL/*idfun*/); 
     30        Geometry::SubMesh * leafsSubMesh = &(treeGeoMesh->mSubMesh[leafSubMeshID]); 
     31        arbol = new Arbol(leafsSubMesh,leafSimpSeqFile.c_str()); 
    2832        foliage = new Foliage(arbol); 
    2933} 
     
    151155uint32 LodTreeLibrary::MinFoliageLod(void) const 
    152156{ 
    153         return arbol->minHojas; // una hoja: preguntar a francisco 
     157//      return arbol->minHojas; 
     158        return arbol->nHojas; 
    154159} 
    155160uint32 LodTreeLibrary::MaxFoliageLod(void) const 
    156161{ 
    157 //      return arbol->TotHojas; 
    158         return arbol->nHojas; 
     162        //      return arbol->TotHojas; 
     163        //return arbol->nHojas; 
     164        return arbol->minHojas; 
    159165} 
    160166 
     
    170176}*/ 
    171177 
    172 /* 
     178 
    173179const VertexData* LodTreeLibrary::Get_Foliage_VertexData(void) const 
    174180{ 
    175181        return arbol->vertexdata; 
    176182} 
    177 */ 
     183 
    178184const IndexData* LodTreeLibrary::CurrentLOD_Foliage_Indices(void) const 
    179185{ 
  • GTP/trunk/Lib/Geom/shared/GTGeometry/src/GeoTreeSimplifier.cpp

    r834 r895  
    179179                Hojasa[pos].Vert_Hoja[1]=v2; 
    180180                Hojasa[pos].Vert_Hoja[2]=v3; 
     181                Hojasa[pos].id_triangulo[0]=num_triangulo; 
     182                Hojasa[pos].existe=true; 
    181183                num_triangulo++; 
    182                 Hojasa[pos].id_triangulo[0]=num_triangulo; 
    183184 
    184185                // Segundo triángulo 
    185186                v3=mesh->mSubMesh[meshLeaves].mIndex[j+5]; 
    186187                Hojasa[pos].Vert_Hoja[3]=v3; 
     188                Hojasa[pos].id_triangulo[1]=num_triangulo; 
    187189                num_triangulo++; 
    188                 Hojasa[pos].id_triangulo[1]=num_triangulo; 
    189190 
    190191                Centroh(Hojasa[pos]); 
     
    10251026        Hojasa[counth].existe = true; 
    10261027                Hojasa[counth].criterio = 1000; 
     1028                Hojasa[counth].id_triangulo[0] = counth*2; 
     1029                Hojasa[counth].id_triangulo[1] = counth*2+1; 
    10271030 
    10281031                //coplanaridad 
  • GTP/trunk/Lib/Geom/shared/GTGeometry/src/SimplificationMethod.cpp

    r891 r895  
    663663//Unify the model to work with it 
    664664//The vertices that have the same space coordinates are stored as an unique vertex 
    665 //in order to not produce holes in the simplification 
     665//in order to avoid holes in the simplification 
    666666//The necessary information to store correctly the decimation data is stored 
    667667void SimplificationMethod::geomesh2simplifModel(void) 
     
    679679                { 
    680680                        //If the model has texture information 
    681                         if (objmesh->mSubMesh[i].mVertexBuffer->mVertexInfo & VERTEX_TEXCOORDS)  
     681/*                      if (objmesh->mSubMesh[i].mVertexBuffer->mVertexInfo & VERTEX_TEXCOORDS)  
    682682                        { 
    683683                                //For all the vertices of each submesh 
     
    727727                        } 
    728728                        else //the model has not texture information 
    729                         {  
     729                        { */ 
    730730                                //For all the vertices of each submesh 
    731731                                for (size_t j=0; j<objmesh->mSubMesh[i].mVertexBuffer->mVertexCount; j++)  
     
    764764                                        }        
    765765                                } 
    766                         } 
    767                 } 
    768                 if (objmesh->mSubMesh[i].mSharedVertexBuffer) 
    769                 { 
    770                         printf("Shared break\n"); 
    771                         break; 
     766                /*      }*/ 
     767                        if (objmesh->mSubMesh[i].mSharedVertexBuffer) 
     768                        { 
     769                                printf("Shared break"); 
     770                                break; 
     771                        } 
    772772                } 
    773773        } 
  • GTP/trunk/Lib/Geom/shared/GTGeometry/src/libs/leaves/Arbol.cpp

    r834 r895  
    44#include "Arbol.h" 
    55 
     6 
    67//-------------------------------------------------------------------------------------------------------------------------------- 
    78// Constructor with the name of a file cotaining the data 
    89//-------------------------------------------------------------------------------------------------------------------------------- 
    9 Arbol::Arbol (const char * arbol, const char* hojas, const char* simplifi, Geometry::CREATEVERTEXDATAFUNC vdfun, Geometry::CREATEINDEXDATAFUNC idfun):  
     10/*Arbol::Arbol (const char * arbol, const char* hojas, const char* simplifi, Geometry::CREATEVERTEXDATAFUNC vdfun, Geometry::CREATEINDEXDATAFUNC idfun):  
     11create_vertex_data_func(vdfun==NULL?Geometry::DefaultVertexDataCreator:vdfun), 
     12create_index_data_func(idfun==NULL?Geometry::DefaultIndexDataCreator:idfun), 
     13vertexdata(NULL), Hojas(NULL), MinDet(NULL)*/ 
     14Arbol::Arbol (const Geometry::SubMesh *leafsSubMesh, const char *simpSeq, Geometry::CREATEVERTEXDATAFUNC vdfun, Geometry::CREATEINDEXDATAFUNC idfun): 
    1015create_vertex_data_func(vdfun==NULL?Geometry::DefaultVertexDataCreator:vdfun), 
    1116create_index_data_func(idfun==NULL?Geometry::DefaultIndexDataCreator:idfun), 
     
    1318{        
    1419        cx = cy= cz= 0; 
    15         ReadFromFile (arbol, hojas, simplifi); 
     20 
     21        //VERTICES 
     22/*      if ((TotVerts=LeeVertices(arbol))==0){ printf("File not found '%s'\n",arbol); exit(1); }//ThrowFileNotFoundError((const char*)arbol); 
     23        if ((nHojas = LeoHojas (hojas))==0) { printf("File not found '%s'\n",hojas); exit(1); }//ThrowFileNotFoundError((const char*)hojas); 
     24//      TotTronco = LeoTronco (tronco); 
     25//      CalculaNormalesVertice();        
     26        if ((TotHojas = LeoHojasSimpl(simpli))==0){ printf("File not found '%s'\n",simpli); exit(1); }// ThrowFileNotFoundError((const char*)simpli);    
     27        RellenoRaiz(); 
     28 
     29        CalculaTexCoordsYNorms();*/ 
     30 
     31 
     32        ReadVertices(leafsSubMesh); 
     33        ReadLeafs(leafsSubMesh); 
     34        if (!ReadSimpSeq(simpSeq)) exit(1); 
     35        RellenoRaiz(); 
     36        CalculaTexCoordsYNorms(); 
     37 
    1638 
    1739        // esto no sé si devería haber akí 
     
    3759// leer informacion desde el fichero 
    3860//-------------------------------------------------------------------------------------------------------------------------------- 
    39 void Arbol::ReadFromFile ( const char * arbol, const char* hojas, const char* simpli/*, char* tronco*/) // Reads a obj-model from a file 
     61/*void Arbol::ReadFromFile ( const char * arbol, const char* hojas, const char* simpli) // Reads a obj-model from a file 
    4062{ 
    4163             
     
    4971 
    5072        CalculaTexCoordsYNorms(); 
    51 } 
    52  
    53  
    54 #include "TMatrix.h" 
    55  
     73}*/ 
     74 
     75 
     76//#include "TMatrix.h" 
     77 
     78 
     79void Arbol::ReadVertices(const Geometry::SubMesh *submesh) 
     80{ 
     81        int countv=submesh->mVertexBuffer->mVertexCount; 
     82        vertexdata = create_vertex_data_func(2*countv); 
     83        Hojas = new Hoja[countv*2]; 
     84        indexdata = create_index_data_func(countv*2*3); // 3 indices x 2 triangulos x hoja 
     85         
     86        vertexdata->Begin(); 
     87        for (int i=0; i<countv; i++) 
     88        { 
     89                vertexdata->SetVertexCoord( i,  submesh->mVertexBuffer->mPosition[i].x,  
     90                                                                                submesh->mVertexBuffer->mPosition[i].y,  
     91                                                                                submesh->mVertexBuffer->mPosition[i].z ); 
     92        } 
     93        vertexdata->End(); 
     94 
     95        TotVerts = countv; 
     96} 
     97 
     98/* 
    5699//-------------------------------------------------------------------------------------------------------------------------------- 
    57100// Procesar línea para extraer los VERTICES DE VERTICES.OBJ 
     
    66109                bool fin_vertices = false; 
    67110 
    68 /*              TMatrix rot90mat; 
    69                 rot90mat.RotateX(-90); 
    70 */               
    71111                //cuento todos los vertices, y relleno la estructura 
    72112                if ((fp_origen = fopen (arbol, "r")) == NULL) 
     
    152192 
    153193                 
    154 } 
     194}*/ 
    155195 
    156196//-------------------------------------------------------------------------------------------------------------------------------- 
     
    319359}*/ 
    320360 
     361void Arbol::ReadLeafs(const Geometry::SubMesh *submesh) 
     362{ 
     363        int numtris = submesh->mIndexCount / 3; 
     364        nHojas =  numtris / 2; 
     365        for (int h=0; h<nHojas; h++) 
     366        { 
     367                Hojas[h].Vert_Hoja[0] = submesh->mIndex[h*6+0]; 
     368                Hojas[h].Vert_Hoja[1] = submesh->mIndex[h*6+1]; 
     369                Hojas[h].Vert_Hoja[2] = submesh->mIndex[h*6+2]; 
     370                Hojas[h].Vert_Hoja[3] = submesh->mIndex[h*6+5]; 
     371                Hojas[h].visible = 0; 
     372 
     373                GetNormalH ( Hojas[h]); 
     374        } 
     375} 
     376 
    321377//-------------------------------------------------------------------------------------------------------------------------------- 
    322378// Procesar línea para extraer las HOJAS DE HOJAS.OBJ 
    323379//-------------------------------------------------------------------------------------------------------------------------------- 
    324  
     380/* 
    325381  int Arbol::LeoHojas (const char* hojas) 
    326382{ 
     
    376432        return (h);      
    377433} 
    378  
     434*/ 
    379435 
    380436//-------------------------------------------------------------------------------------------------------------------------------- 
     
    415471} 
    416472*/ 
     473 
     474 
     475 /// returns the number of total leafs 
     476bool Arbol::ReadSimpSeq(const char *simpSeqFile) 
     477{ 
     478        FILE* fp_simpli; 
     479        char linea[256], str[10]; 
     480        int v0, v1, v2, v3, tn, tv1,tv2, e=0; 
     481 
     482        if ((fp_simpli = fopen (simpSeqFile, "r")) == NULL) 
     483        { 
     484                printf ("No he podido abrir el fichero %s\n", simpSeqFile); 
     485                return false; 
     486        } 
     487        else 
     488        { 
     489                tn = nHojas; 
     490                while (fgets (linea, 255, fp_simpli) != NULL) 
     491                { 
     492                        if (linea[0]<'0' || linea[0]>'9') 
     493                                continue; 
     494                 
     495                        //N 446 Ver 10176 10178 10169 10171  Tv 156 154 E 2 
     496 
     497//                      sscanf(linea, "%s %lu %s %lu %lu  %lu %lu %s %lu %lu %s %i",  
     498//                              &str, &tn, &str, &v0, &v1, &v2, &v3, &str, &tv1, &tv2, &str, &e ); 
     499                        long int triviej00=-1, triviej01=-1; 
     500                        long int triviej10=-1, triviej11=-1; 
     501                        sscanf(linea, "%lu %lu %lu %lu & %lu %lu %lu %lu", &triviej00,&triviej01,&triviej10,&triviej11, &v0,&v1,&v2,&v3); 
     502 
     503                        Hojas[tn].Vert_Hoja[0] = v0; 
     504                        Hojas[tn].Vert_Hoja[1] = v1; 
     505                        Hojas[tn].Vert_Hoja[2] = v2; 
     506                        Hojas[tn].Vert_Hoja[3] = v3; 
     507 
     508                        Hojas[tn].visible = 0; 
     509 
     510                        GetNormalH  (Hojas[tn]); 
     511 
     512                        tv1 = triviej00/2; 
     513                        tv2 = triviej10/2; 
     514 
     515                        Hojas[tn].hijoi= tv1; 
     516                        Hojas[tn].hijod= tv2; 
     517 
     518                        Hojas[tv1].padre = tn; 
     519                        Hojas[tv2].padre = tn;           
     520 
     521                        tn++; 
     522                } 
     523 
     524        } 
     525 
     526        fclose(fp_simpli); 
     527 
     528        TotHojas=tn; 
     529                 
     530        return true; 
     531} 
     532 
     533 
     534 
    417535//--------------------------------------------------------------------------------------------------------------------- 
    418536// Procesar línea para extraer las HOJAS DE SIMPLIFICA.OBJ 
    419537//--------------------------------------------------------------------------------------------------------------------- 
    420  
     538/* 
    421539  int Arbol::LeoHojasSimpl (const char* simplifica) 
    422540{ 
     
    501619        return (tn); 
    502620} 
    503  
     621*/ 
    504622  
    505623//-------------------------------------------------------------------------------------------------------------------------------- 
  • GTP/trunk/Lib/Geom/shared/GTGeometry/src/libs/leaves/Hoja.cpp

    r834 r895  
    1414        Cuantas_hojas = 1; 
    1515        dist = coplanar = criterio = hoja_cop = hoja_crit =-1; 
    16         existe = true; 
     16        existe = false; 
    1717        padre=-1; 
    1818        hijoi = hijod = -1; 
  • GTP/trunk/Lib/Geom/shared/GTGeometry/src/libs/leaves/arbol.h

    r830 r895  
    77#include "Point3D.h" 
    88#include "Activas.h" 
    9  
    10  
     9#include "GeoSubMesh.h" 
    1110 
    1211class Arbol 
     
    3736 
    3837        public : 
    39                 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 
     38//              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 
     39                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 
    4040                Arbol (Arbol *a); 
    4141                virtual ~Arbol (void); // Destructor 
    4242                 
    4343                // Montan la estructura 
    44                 void ReadFromFile (const char *, const char*, const char*/*, char**/); // Reads a obj-model from a file 
    45                 int LeeVertices ( const char * ); 
     44//              void ReadFromFile (const char *, const char*, const char*/*, char**/); // Reads a obj-model from a file 
     45/*              int LeeVertices ( const char * ); 
    4646                int LeoHojas( const char *); 
    4747//              int LeoTronco( char *); 
    48                 int LeoHojasSimpl( const char*); 
     48                int LeoHojasSimpl( const char*);*/ 
     49                void ReadLeafs(const Geometry::SubMesh *); 
     50                void ReadVertices(const Geometry::SubMesh *); 
     51                bool ReadSimpSeq(const char*); /// returns true when successful 
    4952                void RellenoRaiz (void); 
    5053 
  • GTP/trunk/Lib/Geom/shared/GTGeometry/src/libs/leaves/foliage.cpp

    r830 r895  
    992992 
    993993 } 
    994  
    995 /******************************************   IMPOSTORES **************************************************/ 
    996          
    997 //-------------------------------------------------------------------------------------------------------------------------------- 
    998 // Dibuja la caja envolvente. DibujaCaja la dibuja realmente, y la  
    999 //-------------------------------------------------------------------------------------------------------------------------------- 
    1000                         /*       
    1001 void Foliage::DibujaCaja (float alfa, float d) 
    1002 { 
    1003  
    1004         glPushMatrix(); 
    1005  
    1006         glColor3f(1.0, 0.0, 0.0); 
    1007  
    1008 //      glLineWidth(2.0); 
    1009 //      glTranslated (0.0,cy, 0.0); 
    1010 //      glScalef (width,heigth,depth); 
    1011 //      glutWireCube ( 1.0); 
    1012         glRotatef(-alfa,0,1,0); 
    1013  
    1014         glPolygonMode (GL_FRONT_AND_BACK, GL_LINE); 
    1015         glBegin (GL_POLYGON);  
    1016  
    1017                 glVertex3f (MiArbol->cx + MiArbol->rad, MiArbol->cy - MiArbol->rad, d);  
    1018                 glVertex3f (MiArbol->cx - MiArbol->rad, MiArbol->cy - MiArbol->rad, d); 
    1019                 glVertex3f (MiArbol->cx - MiArbol->rad, MiArbol->cy + MiArbol->rad, d); 
    1020                 glVertex3f (MiArbol->cx + MiArbol->rad, MiArbol->cy + MiArbol->rad, d); 
    1021  
    1022  
    1023         glEnd(); 
    1024  
    1025  
    1026         glColor3f(1.0, 1.0, 1.0); 
    1027  
    1028         glPopMatrix(); 
    1029          
    1030  
    1031 } 
    1032  
    1033 */ 
  • GTP/trunk/Lib/Geom/shared/GeoTool/include/GeoMeshView.h

    r829 r895  
    169169 
    170170        //      Change de Level of detail of the object. 
    171         void    GoToLod(unsigned int lod); 
     171        void    GoToLod_LodStrip(unsigned int lod); 
     172        void    GoToLod_LodTree(unsigned int lod); 
    172173 
    173174        private: 
  • GTP/trunk/Lib/Geom/shared/GeoTool/include/GeoMeshViewUI.h

    r841 r895  
    4242#include        "GeoTreeSimpSequence.h" 
    4343#include        "GeoLodStripsConstructor.h" 
     44#include        "GeoLodTreeConstructor.h" 
    4445#include        "GeoLodTreeLibrary.h" 
    4546 
     
    5859        LODSTRIPS_AUTO, 
    5960        LODTREES, 
     61        LODTREES_AUTO, 
    6062        SELECT_LEAVES, 
    6163        VISUALIZE_LODSTRIPS, 
     
    174176        inline void cb_menuLodTreesOpenLeavesSimplification_i(fltk::Item*, void*); 
    175177        static void cb_menuLodTreesOpenLeavesSimplification(fltk::Item*, void*); 
     178        inline void cb_menuLodTreesGenerate_i(fltk::Item*, void*); 
     179        static void cb_menuLodTreesGenerate(fltk::Item*, void*); 
    176180        inline void cb_menuLodTreesVisualize_i(fltk::Item*, void*); 
    177181        static void cb_menuLodTreesVisualize(fltk::Item*, void*); 
     
    187191        inline void cb_mMeshInfo_i(fltk::Browser*, void*); 
    188192        static void cb_mMeshInfo(fltk::Browser*, void*); 
    189         inline void cb_mLodSlider_i(fltk::Slider*, void*); 
    190         static void cb_mLodSlider(fltk::Slider*, void*); 
     193        inline void cb_mLodStripSlider_i(fltk::Slider*, void*); 
     194        static void cb_mLodStripSlider(fltk::Slider*, void*); 
     195        inline void cb_mLodTreeSlider_i(fltk::Slider*, void*); 
     196        static void cb_mLodTreeSlider(fltk::Slider*, void*); 
    191197 
    192198        //      Logo's callback. 
     
    204210        void    showOpenMeshSimplification(); 
    205211        void    showAutoGenerateLodStrips(); 
     212        void    showAutoGenerateLodTrees(); 
    206213 
    207214        //      Shows the LodTrees panel. 
     
    212219         
    213220        //      Show the LodStrips visulization panel. 
    214         void    showSlider(); 
     221        void    showLodStripSlider(); 
     222        void    showLodTreeSlider(); 
    215223 
    216224        void    hideStripify(); 
     
    224232 
    225233        //      Hide the LodStrips visualization panel. 
    226         void    hideSlider(); 
     234        void    hideLodStripSlider(); 
     235        void    hideLodTreeSlider(); 
    227236         
    228237        //      Get the number of vertices. 
     
    247256 
    248257        //      Create a siplification sequence of the leaves. 
    249         void    createLeavesSequence(); 
     258        void    createLeavesSequence(const std::string &); 
    250259 
    251260        //      Stripify the mesh object. 
     
    301310        fltk::Item                                      *menuLodStripsVisualize; 
    302311        fltk::ItemGroup                 *menuLodTrees; 
     312        fltk::Item                                      *menuLodTreesGenerate; 
    303313        fltk::Item                                      *menuLodTreesVisualize; 
    304314 
     
    321331        fltk::Button                            *mButtonBuild; 
    322332        fltk::ProgressBar               *mBuildBar; 
    323         fltk::Slider                            *mLodSlider; 
     333        fltk::Slider                            *mLodStripSlider; 
     334        fltk::Slider                            *mLodTreeSlider; 
    324335        fltk::CheckButton               *mGeometryBased; 
    325336        fltk::CheckButton               *mImageBased; 
     
    344355        void    setLodStripsLibrary(std::string lodfile, Mesh   *geomesh); 
    345356        //      Initialize the lodtreelibrary for visualization. 
    346         void    setLodTreesLibrary(std::string lodfile, Mesh    *geomesh); 
     357        void    setLodTreesLibrary(std::string lodfile, std::string leafseqfile, Mesh   *geomesh, uint32 ileafSubMesh); 
    347358 
    348359        // 26-12-2005 
  • GTP/trunk/Lib/Geom/shared/GeoTool/src/GeoMeshView.cpp

    r842 r895  
    11#include "GeoMeshView.h" 
     2#include <VertexData.h> 
    23 
    34using   namespace       Geometry; 
     
    413414                mPan                                                    =       false; 
    414415                mLodStrip                                       =       false; 
     416                mLodTree                                        =       false; 
    415417                mIdVisualList                   =       0; 
    416418                mSubMeshCount                   =       0; 
     
    913915        current_strip   =       0; 
    914916 
     917 
     918        // DRAW THE TRUNK AS A LODSTRIP OBJECT 
     919 
    915920        //      For each submesh. 
    916921        for (int submesh = 0; submesh < geoMesh->mSubMeshCount; submesh++) 
     
    976981                } 
    977982        } 
     983 
     984        // DRAW THE LEAVES AS A TRIANGLE SOUP 
     985        glColor3f(0,1,1); 
     986        glDisable(GL_LIGHTING); 
     987        glBegin(GL_TRIANGLES); 
     988        const Geometry::VertexData *foliage_verts = lodTreeLib->Get_Foliage_VertexData(); 
     989        const Geometry::IndexData *foliage_inds = lodTreeLib->CurrentLOD_Foliage_Indices(); 
     990        for (int j=0; j<lodTreeLib->CurrentLOD_Foliage_IndexCount(); j++) 
     991        { 
     992                float vx,vy,vz; 
     993                foliage_verts->GetVertexCoord(foliage_inds->GetIndex(j),vx,vy,vz); 
     994                glVertex3f(vx,vy,vz); 
     995        } 
     996        glEnd(); 
     997 
     998        glEnable(GL_LIGHTING); 
     999        glColor3f(1,1,1); 
    9781000         
    9791001}//End drawTriangleStrip. 
     
    10021024//      Change de Level of detail of the object. 
    10031025//--------------------------------------------------------------------------- 
    1004 void    GeoMeshView::GoToLod(unsigned int       lod) 
     1026void    GeoMeshView::GoToLod_LodStrip(unsigned int      lod) 
    10051027{ 
    10061028        if (mLodStrip) 
     
    10101032        draw(); 
    10111033} 
     1034 
     1035//--------------------------------------------------------------------------- 
     1036//      Change de Level of detail of the object. 
     1037//--------------------------------------------------------------------------- 
     1038void    GeoMeshView::GoToLod_LodTree(unsigned int       lod) 
     1039{ 
     1040        if (mLodTree) 
     1041                lodTreeLib->GoToFoliageLod(lod); 
     1042        draw(); 
     1043} 
     1044 
    10121045 
    10131046//--------------------------------------------------------------------------- 
  • GTP/trunk/Lib/Geom/shared/GeoTool/src/GeoMeshViewUI.cpp

    r891 r895  
    33#include "GeoMeshViewUI.h" 
    44#include "resource.h" 
     5#include "GeoLodTreeConstructor.h" 
    56 
    67using   namespace       Geometry; 
     
    6566 
    6667                //      Save the file mesh. 
    67                 mesh_saver->save(       mGeoMesh, 
    68                                 mFileName); 
     68                mesh_saver->save(mGeoMesh, mFileName); 
    6969 
    7070                //      Free memory. 
     
    100100                { 
    101101                        mesh_saver      =       new     GeoMeshSaver(mMeshBounds); 
    102  
    103                         mesh_saver->save(       mGeoMesh, 
    104                                         filename_name(fcho->value())); 
    105  
     102                        mesh_saver->save(mGeoMesh,filename_name(fcho->value())); 
    106103                        delete  mesh_saver; 
    107104                } 
     
    151148   
    152149        //      Open file chooser dialog. 
    153         p       =       fltk::file_chooser(     "Export to OBJ", 
    154                                                                                                         "*.obj", 
    155                                                                                                         ""); 
     150        p       =       fltk::file_chooser("Export to OBJ","*.obj",""); 
    156151        if (p && mGeoMesh) 
    157152        { 
     
    667662 
    668663//--------------------------------------------------------------------------- 
     664//      Auto Generate LodStrips Callback 
     665//--------------------------------------------------------------------------- 
     666inline void GeoMeshViewUI::cb_menuLodTreesGenerate_i(fltk::Item*, void*) 
     667{ 
     668        //      Show title. 
     669        mProcessTitle->label("Generate LodTree"); 
     670        mProcessBar->position(0); 
     671        mBuildBar->position(0); 
     672 
     673        //      Hide the right panel. 
     674        hideRightPanel(); 
     675 
     676        //      Show the LodStrips panel. 
     677        showAutoGenerateLodTrees(); 
     678         
     679        //      Sets menus application state to LODSTRIPS_AUTO. 
     680        mApplicationState       =       LODTREES_AUTO; 
     681 
     682        //      Repaint the window. 
     683        mMainWindow->redraw(); 
     684} 
     685 
     686void GeoMeshViewUI::cb_menuLodTreesGenerate(fltk::Item* o, void* v) 
     687{ 
     688  ((GeoMeshViewUI*)     (o->parent()->parent()->parent()->user_data())) 
     689                                                                                -> 
     690                                                                                cb_menuLodTreesGenerate_i(o,v); 
     691} 
     692 
     693 
     694//--------------------------------------------------------------------------- 
    669695//      Visualize LodStrips Callback 
    670696//--------------------------------------------------------------------------- 
     
    715741 
    716742        //      Show the Visulize LodStrips panel. 
    717         showSlider(); 
     743        showLodStripSlider(); 
    718744         
    719745        //      Repaint the window. 
     
    739765        //      Show title. 
    740766        mProcessTitle->label("Visualize LodTrees"); 
     767 
     768        /*if (geoMeshView->getLeavesSubmesh()==-1) 
     769        { 
     770                fltk::alert("No se ha seleccionado el submesh de hojas!"); 
     771                return; 
     772        }*/ 
     773 
     774        // POR AHORA SE SELECCIONA EL PRIMER SUBMESH QUE NO ES STRIPS COMO HOJAS 
     775        int leafsSubMeshID = -1; 
     776        for (int i=0; i<mGeoMesh->mSubMeshCount; i++) 
     777                if (mGeoMesh->mSubMesh[i].mType==GEO_TRIANGLE_LIST) 
     778                { 
     779                        leafsSubMeshID=i; 
     780                        break; 
     781                } 
     782 
     783 
    741784 
    742785        //      If an object is loaded. 
     
    754797                { 
    755798                        //      Build lod strips library. 
    756                         setLodTreesLibrary(string(fcho->value()), mGeoMesh); 
    757  
    758                         //      Sets the aplication mode. 
    759                         mApplicationState       =       VISUALIZE_LODTREES; 
     799 
     800                        std::string lodstripFile(fcho->value()); 
     801                        delete fcho; 
     802                        fcho    =       new fltk::FileChooser("", 
     803                                        "*.leafseq", 
     804                                        fltk::FileChooser::CREATE, 
     805                                        "Open LeafSeq file"); 
     806 
     807                        fcho->exec(); 
     808 
     809                        if (fcho->value()) 
     810                        { 
     811                                std::string leafseqFile(fcho->value()); 
     812 
     813                                setLodTreesLibrary(lodstripFile, leafseqFile, mGeoMesh, leafsSubMeshID); 
     814 
     815                                //      Sets the aplication mode. 
     816                                mApplicationState       =       VISUALIZE_LODTREES; 
     817                        } 
    760818                } 
    761819 
     
    768826 
    769827        //      Show the Visulize LodTree panel. 
    770         showSlider(); 
     828        showLodStripSlider(); 
     829        showLodTreeSlider(); 
    771830         
    772831        //      Repaint the window. 
     
    904963 
    905964                                //      Create the leaves simplification sequence. 
    906                                 createLeavesSequence(); 
     965                                createLeavesSequence("leavesSimplification.txt"); 
    907966                                 
    908967                                break; 
    909968 
    910969                                //      Simplify and generate simplification sequence. 
     970                        case    LODTREES_AUTO: 
     971                                if (idMeshLeaves==(unsigned short)-1) 
     972                                { 
     973                                        fltk::alert("Leaves submesh not selected!"); 
     974                                } 
     975                                else 
     976                                { 
     977                                        std::cout << "Simplificando hojas..."; 
     978                                        simplifyLeavesCollapse(); 
     979                                        std::cout << "OK!" << std::endl; 
     980 
     981//                                      std::cout << "Creando secuencia de simplificacion de hojas..."; 
     982//                                      createLeavesSequence("leavesSimplification.txt"); 
     983//                                      std::cout << "OK!" << std::endl; 
     984 
     985                                        undo(); 
     986 
     987 
     988                                        std::cout << "Simplificando tronco..."; 
     989                                        std::cout << "OK!" << std::endl; 
     990 
     991                                        //      Transform NoSV Mesh to a SV Mesh. 
     992                                        mesh_aux        =       mGeoMesh->toSharedVertex(); 
     993 
     994                                        //      Deletes the mesh No Shared Vertex. 
     995                                        delete  mGeoMesh; 
     996 
     997                                        //      Gets the mesh Shared Vertex. 
     998                                        mGeoMesh        =       mesh_aux; 
     999 
     1000                                        geoMeshView->setMesh(mGeoMesh); 
     1001 
     1002                                        //      Simplify the mesh object. 
     1003                                        simplifyEdgeCollapse(); 
     1004 
     1005                                        //      Create the qslim simplification sequence. 
     1006                                        createQslimSequence(); 
     1007 
     1008                                } 
     1009                                 
     1010                                break;  
     1011 
    9111012                        case    LODSTRIPS_AUTO: 
    9121013 
     
    9941095inline void GeoMeshViewUI::cb_mButtonBuild_i(fltk::Button*, void*) 
    9951096{ 
    996         char                                    *file_name; 
     1097        char                    *file_name=NULL; 
    9971098        GeoMeshSaver    *mesh_saver; 
    9981099        Serializer              *oSerializer; 
     
    10111112                { 
    10121113                        //      Build the LOD file. 
     1114                        case    LODTREES_AUTO:                   
     1115                                 
     1116                                //      Open file chooser dialog. 
     1117                                file_name       =       fltk::file_chooser("Build LOD","*",""); 
     1118                                if (!file_name) 
     1119                                        break; 
     1120 
     1121                                std::cout << "Creando secuencia de simplificacion de hojas..."; 
     1122                                createLeavesSequence(file_name+std::string(".leafseq")); 
     1123                                std::cout << "OK!" << std::endl; 
     1124 
     1125/*                              TreeSimplificationSequence * auxTreeSimpSequence = new TreeSimplificationSequence(); 
     1126                                auxTreeSimpSequence->Load(Serializer("leavesSimplification.txt",Serializer::READ)); 
     1127 
     1128                                if (auxTreeSimpSequence && mGeoMesh) 
     1129                                { 
     1130                                        LodTreeConstructor * auxLodTreeConstructor = new LodTreeConstructor(mGeoMesh,auxTreeSimpSequence); 
     1131                                        delete auxLodTreeConstructor; 
     1132                                } 
     1133                                else 
     1134                                { 
     1135                                        fltk::alert("There is no leaf simplification sequence."); 
     1136                                        break; 
     1137                                } 
     1138 
     1139 
     1140                                delete auxTreeSimpSequence;*/ 
     1141                                 
     1142 
    10131143                        case    LODSTRIPS_AUTO: 
    10141144 
    1015                                 // Builder 
    1016                                 //      Open file chooser dialog. 
    1017                                 file_name       =       fltk::file_chooser(     "Build LOD", 
    1018                                                 "*", 
    1019                                                 ""); 
    1020  
     1145                                // Builder                                       
     1146                                if (!file_name) 
     1147                                        file_name       =       fltk::file_chooser("Build LOD","*",""); 
    10211148                                //      If a file was selected. 
    10221149                                if (file_name) 
     
    10351162 
    10361163                                        //      Loads a simplification sequence file. 
    1037                                         oMeshSimpSequence->Load(Serializer(     "mqslimSequence.txt", 
    1038                                                                 Serializer::READ)); 
     1164                                        oMeshSimpSequence->Load(Serializer("mqslimSequence.txt",Serializer::READ)); 
    10391165 
    10401166                                        //      If the simplification sequence and the mesh exist. 
     
    10461172                                                                progress_function); 
    10471173 
    1048                                                 oSerializer     =       new Serializer( strcat(file_name,".lod"), 
    1049                                                                 Serializer::Mode::WRITE); 
     1174                                                oSerializer     =       new Serializer(strcat(file_name,".lod"),Serializer::Mode::WRITE); 
    10501175 
    10511176                                                oLodStrip->Save(*oSerializer); 
     
    10701195                                                mesh_saver      =       new     GeoMeshSaver(mMeshBounds); 
    10711196                                                file_name[strlen(file_name) - 4]        =       '\0'; 
    1072                                                 mesh_saver->save(       mGeoMesh, 
    1073                                                                 strcat(file_name,".mesh")); 
     1197                                                mesh_saver->save(mGeoMesh, strcat(file_name,".mesh")); 
    10741198                                                delete  mesh_saver; 
    10751199 
     
    11011225//      Lod Slider Callback 
    11021226//--------------------------------------------------------------------------- 
    1103 inline void GeoMeshViewUI::cb_mLodSlider_i(fltk::Slider *o, void        *) 
     1227inline void GeoMeshViewUI::cb_mLodStripSlider_i(fltk::Slider    *o, void        *) 
    11041228{ 
    11051229        //      Change the lod. 
    1106         geoMeshView->GoToLod((unsigned int)o->value()); 
     1230        geoMeshView->GoToLod_LodStrip((unsigned int)o->value()); 
    11071231 
    11081232        //      Refresh data aplication. 
     
    11121236} 
    11131237 
    1114 void GeoMeshViewUI::cb_mLodSlider(fltk::Slider  *o, void        *v) 
    1115 { 
    1116   ((GeoMeshViewUI*)     (o->parent()->parent()->parent()->user_data())) 
    1117                                                                                 -> 
    1118                                                                                 cb_mLodSlider_i(o,v); 
    1119 } 
     1238void GeoMeshViewUI::cb_mLodStripSlider(fltk::Slider     *o, void        *v) 
     1239{ 
     1240  ((GeoMeshViewUI*)     (o->parent()->parent()->parent()->user_data())) 
     1241                                                                                -> 
     1242                                                                                cb_mLodStripSlider_i(o,v); 
     1243} 
     1244 
     1245 
     1246//--------------------------------------------------------------------------- 
     1247//      Lod Slider Callback for the foliage 
     1248//--------------------------------------------------------------------------- 
     1249inline void GeoMeshViewUI::cb_mLodTreeSlider_i(fltk::Slider     *o, void        *) 
     1250{ 
     1251        //      Change the lod. 
     1252        geoMeshView->GoToLod_LodTree((unsigned int)o->value()); 
     1253 
     1254        //      Refresh data aplication. 
     1255        refreshApplicationBar(); 
     1256                 
     1257        mMainWindow->flush(); 
     1258} 
     1259 
     1260void GeoMeshViewUI::cb_mLodTreeSlider(fltk::Slider      *o, void        *v) 
     1261{ 
     1262  ((GeoMeshViewUI*)     (o->parent()->parent()->parent()->user_data())) 
     1263                                                                                -> 
     1264                                                                                cb_mLodTreeSlider_i(o,v); 
     1265} 
     1266 
     1267 
    11201268 
    11211269//--------------------------------------------------------------------------- 
     
    14181566        mBuildBar->activate(); 
    14191567} 
     1568//--------------------------------------------------------------------------- 
     1569//      Shows the auto generate LodStrips panel 
     1570//--------------------------------------------------------------------------- 
     1571void    GeoMeshViewUI::showAutoGenerateLodTrees() 
     1572{ 
     1573        //      Shows the simplify panel. 
     1574        showEdgeCollapse(); 
     1575 
     1576        mButtonBuild->set_visible(); 
     1577        mButtonBuild->activate(); 
     1578 
     1579        mBuildBar->set_visible(); 
     1580        mBuildBar->activate(); 
     1581} 
    14201582 
    14211583//--------------------------------------------------------------------------- 
    14221584//      Show the LodStrips visulization panel 
    14231585//--------------------------------------------------------------------------- 
    1424 void    GeoMeshViewUI::showSlider() 
    1425 { 
    1426         mLodSlider->set_visible(); 
    1427         mLodSlider->activate(); 
     1586void    GeoMeshViewUI::showLodStripSlider() 
     1587{ 
     1588        mLodStripSlider->set_visible(); 
     1589        mLodStripSlider->activate(); 
    14281590} 
    14291591 
     
    14311593//      Hide the LodStrips visualization panel 
    14321594//--------------------------------------------------------------------------- 
    1433 void    GeoMeshViewUI::hideSlider() 
    1434 { 
    1435         mLodSlider->hide(); 
    1436         mLodSlider->deactivate(); 
     1595void    GeoMeshViewUI::hideLodStripSlider() 
     1596{ 
     1597        mLodStripSlider->hide(); 
     1598        mLodStripSlider->deactivate(); 
     1599} 
     1600 
     1601//--------------------------------------------------------------------------- 
     1602//      Show the LodTree visulization panel 
     1603//--------------------------------------------------------------------------- 
     1604void    GeoMeshViewUI::showLodTreeSlider() 
     1605{ 
     1606        mLodTreeSlider->set_visible(); 
     1607        mLodTreeSlider->activate(); 
     1608} 
     1609 
     1610//--------------------------------------------------------------------------- 
     1611//      Hide the LodTree visualization panel 
     1612//--------------------------------------------------------------------------- 
     1613void    GeoMeshViewUI::hideLodTreeSlider() 
     1614{ 
     1615        mLodTreeSlider->hide(); 
     1616        mLodTreeSlider->deactivate(); 
    14371617} 
    14381618 
     
    15801760        hideOpenMeshSimplification(); 
    15811761        hideOpenLeavesSimplification(); 
    1582         hideSlider(); 
     1762        hideLodStripSlider(); 
     1763        hideLodTreeSlider(); 
    15831764        hideMeshInfo(); 
    15841765} 
     
    18582039//      Create a simplification sequence of the leaves. 
    18592040//--------------------------------------------------------------------------- 
    1860 void    GeoMeshViewUI::createLeavesSequence() 
     2041void    GeoMeshViewUI::createLeavesSequence(const std::string &filename) 
    18612042{ 
    18622043        TreeSimplificationSequence      *tree_sequencer; 
     
    18652046         
    18662047        tree_sequencer->putMeshName(nombremesh);  
    1867         tree_sequencer->Save(Serializer("leavesSequence.txt",Serializer::WRITE)); 
     2048        tree_sequencer->Save(Serializer(filename,Serializer::WRITE)); 
    18682049 
    18692050        delete  tree_sequencer; 
     
    20322213 
    20332214        //      Sets the slider range. 
    2034         mLodSlider->range(lodStripsLib->MaxLod(), 
     2215        mLodStripSlider->range(lodStripsLib->MaxLod(), 
    20352216                                                                                lodStripsLib->MinLod()); 
    20362217 
     
    20392220         
    20402221        //      Puts the slider in the max position. 
    2041         mLodSlider->value(lodStripsLib->MinLod()); 
     2222        mLodStripSlider->value(lodStripsLib->MinLod()); 
    20422223} 
    20432224 
     
    20452226//      Initialize the lodTreelibrary for visualization. 
    20462227//--------------------------------------------------------------------------- 
    2047 void    GeoMeshViewUI::setLodTreesLibrary(std::string lodfile, Mesh     *geomesh) 
     2228//void  GeoMeshViewUI::setLodTreesLibrary(std::string lodfile, Mesh     *geomesh) 
     2229void    GeoMeshViewUI::setLodTreesLibrary(std::string lodfile, std::string leafseqfile, Mesh *geomesh, uint32 ileafSubMesh) 
     2230 
    20482231{ 
    20492232        //      If there is no lod strips object. 
     
    20542237 
    20552238        //      New lod strips object. 
    2056         lodTreeLib      =       new     Geometry::LodTreeLibrary(lodfile, geomesh,"\\\\quake\\home\\\Modelos\\betula_populifolia\\vertices.obj", 
     2239/*      lodTreeLib      =       new     Geometry::LodTreeLibrary(lodfile, geomesh,"\\\\quake\\home\\\Modelos\\betula_populifolia\\vertices.obj", 
    20572240                                                                                "\\\\quake\\home\\\Modelos\\betula_populifolia\\hojas.obj", 
    2058                                                                                 "\\\\quake\\home\\\Modelos\\betula_populifolia\\simplifica.obj"); 
     2241                                                                                "\\\\quake\\home\\\Modelos\\betula_populifolia\\simplifica.obj");*/ 
     2242 
     2243        lodTreeLib = new Geometry::LodTreeLibrary(lodfile,leafseqfile,geomesh,ileafSubMesh); 
    20592244 
    20602245        //      Sets the slider range. 
    2061         mLodSlider->range(lodTreeLib->MaxTrunkLod(), lodTreeLib->MinTrunkLod()); 
     2246        mLodStripSlider->range(lodTreeLib->MaxTrunkLod(), lodTreeLib->MinTrunkLod()); 
     2247        mLodTreeSlider->range(lodTreeLib->MaxFoliageLod(), lodTreeLib->MinFoliageLod()); 
    20622248 
    20632249        //      Pass to geomeshview the lod strips object. 
     
    20652251         
    20662252        //      Puts the slider in the max position. 
    2067         mLodSlider->value(lodTreeLib->MinTrunkLod()); 
     2253        mLodStripSlider->value(lodTreeLib->MinTrunkLod()); 
     2254        mLodTreeSlider->value(lodTreeLib->MinFoliageLod()); 
    20682255} 
    20692256 
     
    22892476                                { 
    22902477                                        fltk::Slider* o; 
    2291                                         o = mLodSlider = new fltk::Slider(16, 50, 30, 450); 
     2478                                        o = mLodStripSlider = new fltk::Slider(16, 50, 30, 450); 
    22922479                                        o->type(fltk::Slider::TICK_BELOW); 
    22932480                                        o->set_vertical(); 
    2294                                         o->callback((fltk::Callback*)cb_mLodSlider); 
     2481                                        o->callback((fltk::Callback*)cb_mLodStripSlider); 
     2482                                        o->hide(); 
     2483                                        o->deactivate(); 
     2484                                } 
     2485                                { 
     2486                                        fltk::Slider* o; 
     2487                                        o = mLodTreeSlider = new fltk::Slider(46, 50, 30, 450); 
     2488                                        o->type(fltk::Slider::TICK_BELOW); 
     2489                                        o->set_vertical(); 
     2490                                        o->callback((fltk::Callback*)cb_mLodTreeSlider); 
    22952491                                        o->hide(); 
    22962492                                        o->deactivate(); 
     
    26092805                                { 
    26102806                                        fltk::Item* o; 
    2611                                         o = menuLodTreesVisualize = new fltk::Item("Visualize Trunk"); 
     2807                                        o = menuLodTreesGenerate = new fltk::Item("Generate"); 
     2808                                        o->callback((fltk::Callback*)cb_menuLodTreesGenerate); 
     2809                                } 
     2810                                { 
     2811                                        fltk::Item* o; 
     2812                                        o = menuLodTreesVisualize = new fltk::Item("Visualize"); 
    26122813                                        o->callback((fltk::Callback*)cb_menuLodTreesVisualize); 
    26132814                                } 
Note: See TracChangeset for help on using the changeset viewer.