Changeset 1655


Ignore:
Timestamp:
10/20/06 08:32:45 (18 years ago)
Author:
mattausch
Message:
 
Location:
GTP/trunk/Lib/Vis/Preprocessing/src
Files:
2 edited

Legend:

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

    r1454 r1655  
    8181        { 
    8282                const int index = (int)strtol(pch, NULL, 10) - 1; 
    83                 //Debug << index << " x "; 
    84                  
     83                                 
    8584                // store vertex in hash table 
    8685                hashTable[index] = vertices[index]; 
     
    8988                pch = strtok(NULL, " "); 
    9089        } 
    91         //if (indices.size() > 4) return NULL; 
    92  
     90         
    9391    return Triangle3(vertices[indices[0]], vertices[indices[1]], vertices[indices[2]]);  
    9492} 
     
    144142        Mesh *mesh = mi->GetMesh(); 
    145143 
     144        int i = 0; 
    146145        FaceContainer::const_iterator fit, fit_end = mesh->mFaces.end(); 
    147         int i = 0; 
     146 
    148147        for (fit = mesh->mFaces.begin(); fit != fit_end; ++ fit, i++) 
    149148        { 
     
    210209                case 'f':  
    211210                        { 
    212                           //                            cout << "f"; 
    213  
     211                                //      cout << "f"; 
    214212                                if (loadMeshes) 
    215213                                { 
  • 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.