Ignore:
Timestamp:
10/20/06 08:32:45 (18 years ago)
Author:
mattausch
Message:
 
File:
1 edited

Legend:

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

    r1634 r1655  
    224224 
    225225 
     226bool Preprocessor::LoadBinaryObj(const string filename, 
     227                                                                 SceneGraphNode *root, 
     228                                                                 const bool loadMeshes, 
     229                                                                 vector<FaceParentInfo> *parents) 
     230{ 
     231        ifstream samplesIn(fileName, ios::binary); 
     232        if (!samplesIn.is_open()) 
     233                return false; 
     234 
     235 
     236        // table associating indices with vectors 
     237        map<int, Vector3> hashTable; 
     238        // table for vertices 
     239        VertexContainer vertices;  
     240        FaceContainer faces; 
     241 
     242        char str[100]; 
     243        int meshGrouping; 
     244        Environment::GetSingleton()->GetIntValue("ObjParser.meshGrouping", meshGrouping); 
     245 
     246        int nMaxFaces = meshGrouping; 
     247 
     248        while (1) 
     249        { 
     250                Triangle3 tri; 
     251                 
     252                samplesIn.read(reinterpret_cast<char *>(tri.mVertices + 0), sizeof(Vector3)); 
     253                samplesIn.read(reinterpret_cast<char *>(tri.mVertices + 1), sizeof(Vector3)); 
     254                samplesIn.read(reinterpret_cast<char *>(tri.mVertices + 2), sizeof(Vector3)); 
     255                 
     256                // end of file reached 
     257                if (samplesIn.eof()) 
     258                        break; 
     259 
     260                TriangleIntersectable *obj = new TriangleIntersectable(tri); 
     261                root->mGeometry.push_back(obj); 
     262 
     263                // matt: we don't really need to keep an additional data structure 
     264                // if working with triangles => remove this 
     265                if (parents)  
     266                { 
     267                        FaceParentInfo info(obj, 0); 
     268                        parents->push_back(info); 
     269                }        
     270        } 
     271         
     272        return true; 
     273} 
     274 
     275 
    226276bool 
    227277Preprocessor::LoadScene(const string filename) 
    228278{ 
    229         // use leaf nodes of the original spatial hierarchy as occludees 
     279    // use leaf nodes of the original spatial hierarchy as occludees 
    230280        mSceneGraph = new SceneGraph; 
    231281   
     
    248298                 
    249299                if (strstr(filename.c_str(), ".x3d")) 
    250                   parser = new X3dParser; 
     300                { 
     301                        parser = new X3dParser; 
     302                } 
    251303                else 
     304                { 
    252305                  if (strstr(filename.c_str(), ".ply") || strstr(filename.c_str(), ".plb")) 
    253                         parser = new PlyParser; 
     306                  { 
     307                          parser = new PlyParser; 
     308                  } 
    254309                  else if (strstr(filename.c_str(), ".obj")) 
    255                           parser = new ObjParser; 
     310                  { 
     311                          // hack: load binary dump 
     312                          string binFile = ReplaceSuffix(filename, ".obj", ".bin"); 
     313                         
     314                          const bool loaded =  
     315                                  LoadBinaryObj(binFile, mSceneGraph->GetRoot(), mLoadMeshes, fi); 
     316                                 
     317                          if (loaded) 
     318                                return true; 
     319 
     320              parser = new ObjParser; 
     321                  } 
    256322                  else  
     323                  { 
    257324                          parser = new UnigraphicsParser; 
     325                  } 
     326                } 
    258327 
    259328                cout << filename << endl; 
    260329                 
    261                 result = parser->ParseFile( 
    262                                 filename,  
    263                                 mSceneGraph->GetRoot(), 
    264                                 mLoadMeshes, 
    265                                 fi); 
    266                          
     330                result = parser->ParseFile(filename,  
     331                                                                   mSceneGraph->GetRoot(), 
     332                                                                   mLoadMeshes, 
     333                                                                   fi); 
     334 
     335                // only works for triangles 
     336                ExportBinaryObj(binFile): 
     337 
    267338                delete parser; 
    268339 
Note: See TracChangeset for help on using the changeset viewer.