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/GTGeometry/src/libs/leaves
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • 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 */ 
Note: See TracChangeset for help on using the changeset viewer.