Ignore:
Timestamp:
04/20/06 13:25:41 (18 years ago)
Author:
mattausch
Message:

after rendering workshop submissioin
x3dparser can use def - use constructs
implemented improved evaluation (samples are only stored in leaves, only propagate pvs size)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • GTP/trunk/Lib/Vis/Preprocessing/src/PlyParser.cpp

    r749 r752  
    22using namespace std; 
    33#include <ply.h> 
     4#include <stdio.h> 
    45 
    56#include "PlyParser.h" 
     
    910 
    1011 
    11  
    12  
     12// int facesPerMesh = 100000000; 
     13int facesPerMesh = 30; 
     14bool useRandomMaterial = false; 
     15bool indexVertices = true; 
    1316 
    1417/* user's vertex and face definitions for a polygonal object */ 
     
    3336}; 
    3437 
     38 
    3539PlyProperty vert_props[] = { /* list of property information for a vertex */ 
    3640  {"x", PLY_FLOAT, PLY_FLOAT, offsetof(Vertex,x), 0, 0, 0, 0}, 
     
    4751static PlyFace **flist; 
    4852 
     53 
    4954bool 
    50 PlyParser::ParseFile(const string filename, 
    51                                          SceneGraphNode **root, 
    52                                          const bool loadPolygonsAsMeshes) 
     55PlyParser::ParseSingleFile(const string filename, 
     56                                                   SceneGraphNode *root) 
    5357{ 
    54  
    55   /* user's vertex and face definitions for a polygonal object */ 
     58  /*** the PLY object ***/ 
     59  int nverts; 
     60  Vertex **vlist; 
     61  PlyOtherElems *other_elements = NULL; 
     62  PlyOtherProp *vert_other; 
     63  int nelems; 
     64  char **elist; 
     65  int num_comments; 
     66  char **comments; 
     67  int num_obj_info; 
     68  char **obj_info; 
     69  int file_type; 
    5670   
    57  
    58  
    59 typedef double Matrix[4][4]; 
    60  
    61 /*** the PLY object ***/ 
    62  
    63  int nverts; 
    64  Vertex **vlist; 
    65  PlyOtherElems *other_elements = NULL; 
    66  PlyOtherProp *vert_other; 
    67  int nelems; 
    68  char **elist; 
    69  int num_comments; 
    70  char **comments; 
    71  int num_obj_info; 
    72  char **obj_info; 
    73  int file_type; 
    74   
    75  int i,j; 
    76  PlyFile *ply; 
    77  int nprops; 
    78  int num_elems; 
    79  PlyProperty **plist; 
    80  char *elem_name; 
    81  float version; 
    82   
     71  int i,j; 
     72  PlyFile *ply; 
     73  int nprops; 
     74  int num_elems; 
     75  PlyProperty **plist; 
     76  char *elem_name; 
     77  float version; 
     78   
    8379  
    8480  /*** Read in the original PLY object ***/ 
     
    169165 ply_close (ply); 
    170166 
    171  
    172  
    173  
    174  *root = new SceneGraphNode; 
    175  SceneGraphNode *currentNode = *root; 
    176  
    177  
    178  cerr<<"Baking faces into eshes"<<endl; 
     167 SceneGraphNode *currentNode = root; 
     168 
     169 cerr<<"Baking faces into meshes"<<endl; 
     170 
    179171 // bake the faces into meshes 
    180  Mesh *mesh = NULL; 
    181  int facesPerMesh = 100; 
     172 Mesh meshProxy; 
     173 // only one face per mesh 
     174 VertexContainer vertices; 
     175 
    182176 for (i = 0; i < nfaces; i++) { 
    183177   if (i % facesPerMesh == 0) { 
    184          if (mesh) { 
    185                  mesh->Preprocess; 
    186                  // make an instance of this mesh 
    187                  MeshInstance *mi = new MeshInstance(mesh); 
    188                  currentNode->mGeometry.push_back(mi); 
    189            } 
    190            mesh = new Mesh(); 
     178         if (meshProxy.mFaces.size()) { 
     179 
     180           if (indexVertices) 
     181                 meshProxy.IndexVertices(); 
     182            
     183           Mesh *mesh = new Mesh(meshProxy.mVertices.size(), 
     184                                                         meshProxy.mFaces.size()); 
     185            
     186            
     187           //      cout<<"C="<<mesh->mVertices.capacity(); 
     188           mesh->mVertices = meshProxy.mVertices; 
     189           //      cout<<" NC="<<mesh->mVertices.capacity()<<" S="<<mesh->mVertices.size()<<endl; 
     190            
     191           mesh->mFaces = meshProxy.mFaces; 
     192            
     193           if (useRandomMaterial) 
     194                 mesh->AssignRandomMaterial(); 
     195 
     196           mesh->Preprocess(); 
     197           // make an instance of this mesh 
     198           MeshInstance *mi = new MeshInstance(mesh); 
     199           currentNode->mGeometry.push_back(mi); 
    191200         } 
     201 
     202         meshProxy.Clear(); 
     203   } 
    192204                  
    193         // only one face per mesh 
    194         VertexIndexContainer vc; 
    195          
    196         // add vertices 
    197         for (int k  = 0; k < flist[i]->nverts; k++) { 
    198            Vertex *v = vlist[flist[i]->verts[k]]; 
    199            vc.push_back(mesh->mVertices.size()); 
    200            mesh->mVertices.push_back(Vector3(v->x, v->y, v->z)); 
    201         } 
    202          
    203          mesh->mFaces.push_back(new Face(vc)); 
     205  // only one face per mesh 
     206  VertexIndexContainer vc; 
     207   
     208  // add vertices 
     209  for (int k  = 0; k < flist[i]->nverts; k++) { 
     210         Vertex *v = vlist[flist[i]->verts[k]]; 
     211         vc.push_back(meshProxy.mVertices.size()); 
     212         meshProxy.mVertices.push_back(Vector3(v->x, v->y, v->z)); 
     213  } 
     214   
     215   meshProxy.mFaces.push_back(new Face(vc)); 
    204216 } 
    205217  
     218 if (meshProxy.mFaces.size()) { 
     219 
     220   if (indexVertices) 
     221         meshProxy.IndexVertices(); 
     222 
     223   Mesh *mesh = new Mesh(meshProxy.mVertices.size(), 
     224                                                 meshProxy.mFaces.size()); 
     225 
     226   mesh->mVertices = meshProxy.mVertices; 
     227    
     228   mesh->mFaces = meshProxy.mFaces; 
     229    
     230   if (useRandomMaterial) 
     231         mesh->AssignRandomMaterial(); 
     232    
     233   mesh->Preprocess(); 
     234   // make an instance of this mesh 
     235   MeshInstance *mi = new MeshInstance(mesh); 
     236   currentNode->mGeometry.push_back(mi); 
     237 } 
     238 
     239 // make sure that no face gets deleted by the destructor! 
     240 meshProxy.Clear(); 
     241 
    206242 for (i=0; i < nverts; i++) 
    207243   free(vlist[i]); 
     244 
    208245 free(vlist); 
    209246 
    210247 for (i=0; i < nfaces; i++) 
    211248   free(flist[i]); 
     249 
    212250 free(flist); 
    213  
     251  
    214252  
    215253 return true; 
     254 
     255 
    216256} 
     257 
     258bool 
     259PlyParser::ParseFile(const string filename, 
     260                                         SceneGraphNode **root, 
     261                                         const bool loadPolygonsAsMeshes) 
     262{ 
     263  vector<string> filelist; 
     264   
     265  if (strstr(filename.c_str(), ".plb")) { 
     266        // parse the filelist 
     267        FILE *f = fopen(filename.c_str(), "rt"); 
     268        char s[64]; 
     269        if (!f) { 
     270          cerr<<"Cannot open .plb file"<<endl; 
     271          exit(1); 
     272        } 
     273        while (fgets(s,64,f)) { 
     274          // remove nl 
     275          s[strlen(s)-1] = 0; 
     276          filelist.push_back(s); 
     277        } 
     278        fclose(f); 
     279 
     280  } else 
     281        filelist.push_back(filename); 
     282 
     283  *root = new SceneGraphNode; 
     284 
     285  for (int i=0; i < filelist.size(); i++) { 
     286        if (!ParseSingleFile(filelist[i], *root)) { 
     287          cerr<<"Ply parse error. Quiting ...\n"; 
     288          exit(1); 
     289        } 
     290  } 
     291  return true; 
     292} 
Note: See TracChangeset for help on using the changeset viewer.