Changeset 1658


Ignore:
Timestamp:
10/20/06 13:21:15 (18 years ago)
Author:
mattausch
Message:

implemented obj dump for fast loading

Location:
GTP/trunk/Lib/Vis/Preprocessing
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • GTP/trunk/Lib/Vis/Preprocessing/scripts/vsposp_typical.sh

    r1654 r1658  
    1313#SCENE=vsposp_typical 
    1414#SCENE=soda5_vsposp 
    15 SCENE=soda_vsposp 
    16 #SCENE=vsposp_vienna 
     15#SCENE=soda_vsposp 
     16#SCENE=vienna_vsposp 
     17SCENE=vsposp_citymodel 
    1718#SCENE=soda5 
    1819#SCENE=cube 
     
    6263 echo "$SCENE $METHOD" 
    6364 
    64  $PROGRAM $ENVIRONMENT \ 
    65  -view_cells_evaluation_stats_prefix=$LOG_PREFIX-$METHOD \ 
    66  -view_cells_merge_stats=$LOG_PREFIX-$METHOD-mergeStats.log \ 
    67  -vsp_subdivision_stats=$LOG_PREFIX-$METHOD-vsp-subdivisionStats.log \ 
    68  -bvh_subdivision_stats=$LOG_PREFIX-$METHOD-bvh-subdivisionStats.log \ 
    69  -hierarchy_subdivision_stats=$LOG_PREFIX-$METHOD-hierarchy-subdivisionStats.log \ 
    70  -hierarchy_construction_type=2 \ 
    71  -hierarchy_construction_recompute_split_on_repair=true 
     65# $PROGRAM $ENVIRONMENT \ 
     66# -view_cells_evaluation_stats_prefix=$LOG_PREFIX-$METHOD \ 
     67# -view_cells_merge_stats=$LOG_PREFIX-$METHOD-mergeStats.log \ 
     68# -vsp_subdivision_stats=$LOG_PREFIX-$METHOD-vsp-subdivisionStats.log \ 
     69# -bvh_subdivision_stats=$LOG_PREFIX-$METHOD-bvh-subdivisionStats.log \ 
     70# -hierarchy_subdivision_stats=$LOG_PREFIX-$METHOD-hierarchy-subdivisionStats.log \ 
     71# -hierarchy_construction_type=2 \ 
     72# -hierarchy_construction_recompute_split_on_repair=true 
    7273 
    7374sh movefiles.sh $LOG_PREFIX-$METHOD 
     
    8081  echo "$SCENE $METHOD" 
    8182 
    82  $PROGRAM $ENVIRONMENT \ 
    83   -view_cells_evaluation_stats_prefix=$LOG_PREFIX-$METHOD \ 
    84   -view_cells_merge_stats=$LOG_PREFIX-$METHOD-mergeStats.log \ 
    85   -vsp_subdivision_stats=$LOG_PREFIX-$METHOD-vsp-subdivisionStats.log \ 
    86   -bvh_subdivision_stats=$LOG_PREFIX-$METHOD-bvh-subdivisionStats.log \ 
    87   -hierarchy_subdivision_stats=$LOG_PREFIX-$METHOD-hierarchy-subdivisionStats.log \ 
    88   -hierarchy_construction_type=0 \ 
    89   -bvh_term_max_leaves=$NODES 
     83# $PROGRAM $ENVIRONMENT \ 
     84#  -view_cells_evaluation_stats_prefix=$LOG_PREFIX-$METHOD \ 
     85#  -view_cells_merge_stats=$LOG_PREFIX-$METHOD-mergeStats.log \ 
     86#  -vsp_subdivision_stats=$LOG_PREFIX-$METHOD-vsp-subdivisionStats.log \ 
     87#  -bvh_subdivision_stats=$LOG_PREFIX-$METHOD-bvh-subdivisionStats.log \ 
     88#  -hierarchy_subdivision_stats=$LOG_PREFIX-$METHOD-hierarchy-subdivisionStats.log \ 
     89#  -hierarchy_construction_type=0 \ 
     90#  -bvh_term_max_leaves=$NODES 
    9091 
    9192sh movefiles.sh $LOG_PREFIX-$METHOD 
     
    9495 
    9596NODES=10000 
     97 
     98  METHOD=sequential-$NODES 
     99  echo "$SCENE $METHOD" 
     100 
     101# $PROGRAM $ENVIRONMENT \ 
     102#  -view_cells_evaluation_stats_prefix=$LOG_PREFIX-$METHOD \ 
     103#  -view_cells_merge_stats=$LOG_PREFIX-$METHOD-mergeStats.log \ 
     104#  -vsp_subdivision_stats=$LOG_PREFIX-$METHOD-vsp-subdivisionStats.log \ 
     105 # -bvh_subdivision_stats=$LOG_PREFIX-$METHOD-bvh-subdivisionStats.log \ 
     106 # -hierarchy_subdivision_stats=$LOG_PREFIX-$METHOD-hierarchy-subdivisionStats.log \ 
     107 # -hierarchy_construction_type=0 \ 
     108#  -bvh_term_max_leaves=$NODES 
     109 
     110sh movefiles.sh $LOG_PREFIX-$METHOD 
     111 
     112 
     113############################################################################ 
     114 
     115NODES=30000 
    96116 
    97117  METHOD=sequential-$NODES 
  • GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.cpp

    r1655 r1658  
    226226bool Preprocessor::LoadBinaryObj(const string filename, 
    227227                                                                 SceneGraphNode *root, 
    228                                                                  const bool loadMeshes, 
    229228                                                                 vector<FaceParentInfo> *parents) 
    230229{ 
    231         ifstream samplesIn(fileName, ios::binary); 
     230        //ifstream samplesIn(filename, ios::binary); 
     231        igzstream samplesIn(filename.c_str()); 
     232         
    232233        if (!samplesIn.is_open()) 
    233234                return false; 
    234235 
    235  
     236        cout << "binary obj dump available, loading " << filename.c_str() << endl; 
    236237        // table associating indices with vectors 
    237238        map<int, Vector3> hashTable; 
     239 
    238240        // table for vertices 
    239241        VertexContainer vertices;  
    240242        FaceContainer faces; 
    241243 
    242         char str[100]; 
    243         int meshGrouping; 
    244         Environment::GetSingleton()->GetIntValue("ObjParser.meshGrouping", meshGrouping); 
    245  
    246         int nMaxFaces = meshGrouping; 
    247  
    248244        while (1) 
    249245        { 
     
    271267         
    272268        return true; 
     269} 
     270 
     271 
     272bool Preprocessor::ExportBinaryObj(const string filename, SceneGraphNode *root) 
     273{ 
     274        //ifstream samplesIn(filename, ios::binary); 
     275        ogzstream samplesOut(filename.c_str()); 
     276        if (!samplesOut.is_open()) 
     277                return false; 
     278 
     279        ObjectContainer::const_iterator oit, oit_end = root->mGeometry.end(); 
     280 
     281        for (oit = root->mGeometry.begin(); oit != oit_end; ++ oit) 
     282        { 
     283                Intersectable *obj = *oit; 
     284 
     285                if (obj->Type() == Intersectable::TRIANGLE_INTERSECTABLE) 
     286                { 
     287                        Triangle3 tri = dynamic_cast<TriangleIntersectable *>(obj)->GetItem(); 
     288 
     289                        samplesOut.write(reinterpret_cast<char *>(tri.mVertices + 0), sizeof(Vector3)); 
     290                        samplesOut.write(reinterpret_cast<char *>(tri.mVertices + 1), sizeof(Vector3)); 
     291                        samplesOut.write(reinterpret_cast<char *>(tri.mVertices + 2), sizeof(Vector3)); 
     292                } 
     293                else 
     294                { 
     295                        cout << "not implemented intersectable type " << obj->Type() << endl; 
     296                } 
     297        } 
     298 
     299        return true; 
     300} 
     301 
     302static string ReplaceSuffix(string filename, string a, string b) 
     303{ 
     304        string result = filename; 
     305 
     306        int pos = (int)filename.rfind(a, (int)filename.size() - 1); 
     307        if (pos == filename.size() - a.size()) { 
     308                result.replace(pos, a.size(), b); 
     309        } 
     310        return result; 
    273311} 
    274312 
     
    295333                &mFaceParents : NULL; 
    296334 
    297         if (files == 1) { 
    298                  
     335        if (files == 1)  
     336        { 
    299337                if (strstr(filename.c_str(), ".x3d")) 
    300338                { 
    301339                        parser = new X3dParser; 
    302                 } 
    303                 else 
    304                 { 
    305                   if (strstr(filename.c_str(), ".ply") || strstr(filename.c_str(), ".plb")) 
    306                   { 
    307                           parser = new PlyParser; 
    308                   } 
    309                   else if (strstr(filename.c_str(), ".obj")) 
    310                   { 
    311                           // hack: load binary dump 
    312                           string binFile = ReplaceSuffix(filename, ".obj", ".bin"); 
    313340                         
    314                           const bool loaded =  
    315                                   LoadBinaryObj(binFile, mSceneGraph->GetRoot(), mLoadMeshes, fi); 
    316                                  
    317                           if (loaded) 
    318                                 return true; 
    319  
    320               parser = new ObjParser; 
    321                   } 
    322                   else  
    323                   { 
    324                           parser = new UnigraphicsParser; 
    325                   } 
    326                 } 
    327  
    328                 cout << filename << endl; 
    329                  
    330                 result = parser->ParseFile(filename,  
     341                        result = parser->ParseFile(filename,  
     342                                                                           mSceneGraph->GetRoot(), 
     343                                                                           mLoadMeshes, 
     344                                                                           fi); 
     345                        delete parser; 
     346                } 
     347                else if (strstr(filename.c_str(), ".ply") || strstr(filename.c_str(), ".plb")) 
     348                { 
     349                        parser = new PlyParser; 
     350 
     351                        result = parser->ParseFile(filename,  
     352                                                                           mSceneGraph->GetRoot(), 
     353                                                                           mLoadMeshes, 
     354                                                                           fi); 
     355                        delete parser; 
     356                } 
     357                else if (strstr(filename.c_str(), ".obj")) 
     358                { 
     359                        // hack: load binary dump 
     360                        string binFile = ReplaceSuffix(filename, ".obj", ".bin"); 
     361 
     362                        if (!mLoadMeshes) 
     363                        { 
     364                                result = LoadBinaryObj(binFile, mSceneGraph->GetRoot(), fi); 
     365                        } 
     366 
     367                        if (!result) 
     368                        { 
     369                                cout << "no binary dump available or loading full meshes, parsing file" << endl; 
     370                                parser = new ObjParser; 
     371                 
     372                                result = parser->ParseFile(filename,  
    331373                                                                   mSceneGraph->GetRoot(), 
    332374                                                                   mLoadMeshes, 
    333375                                                                   fi); 
    334  
    335                 // only works for triangles 
    336                 ExportBinaryObj(binFile): 
    337  
    338                 delete parser; 
    339  
     376                                                 
     377                                // only works for triangles 
     378                                if (!mLoadMeshes) 
     379                                { 
     380                                        cout << "exporting binary obj to " << binFile << "... " << endl; 
     381                                        ExportBinaryObj(binFile, mSceneGraph->GetRoot()); 
     382                                        cout << "finished" << endl; 
     383                                } 
     384 
     385                                delete parser; 
     386                        } 
     387                        else if (1) 
     388                        { 
     389                                ExportBinaryObj("../data/test.bin", mSceneGraph->GetRoot()); 
     390                                //Exporter *exporter = Exporter::GetExporter("dummy.wrl"); 
     391                                //exporter->ExportGeometry(mSceneGraph->GetRoot()->mGeometry); 
     392                        } 
     393                } 
     394                else  
     395                { 
     396                        parser = new UnigraphicsParser; 
     397                        result = parser->ParseFile(filename,  
     398                                                                           mSceneGraph->GetRoot(), 
     399                                                                           mLoadMeshes,                                                            
     400                                                                           fi); 
     401                        delete parser; 
     402                } 
     403                 
     404                cout << filename << endl; 
    340405        }  
    341         else { 
     406        else  
     407        { 
    342408                vector<string>::const_iterator fit, fit_end = filenames.end(); 
    343409                 
  • GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.h

    r1613 r1658  
    208208protected: 
    209209 
     210        bool LoadBinaryObj(const string filename, 
     211                                           SceneGraphNode *root, 
     212                                           vector<FaceParentInfo> *parents); 
     213 
     214        bool ExportBinaryObj(const string filename, SceneGraphNode *root); 
     215 
     216 
    210217        void SetupRay(Ray &ray, const Vector3 &point, const Vector3 &direction) const; 
    211218 
    212         // matt: previously was a signal 
    213219        void EvalPvsStat(); 
    214220 
  • GTP/trunk/Lib/Vis/Preprocessing/src/main.cpp

    r1640 r1658  
    4646// DLL function signature 
    4747typedef GlRendererWidget *(*importFunction)(Preprocessor *); 
    48  
    4948 
    5049 
     
    142141                else if (strstr(strippedFilename.c_str(), ".obj")) 
    143142                { 
    144                         kdFilename += ReplaceSuffix(strippedFilename, ".dat", suffix); 
     143                        kdFilename += ReplaceSuffix(strippedFilename, ".obj", suffix); 
    145144                } 
    146145                else 
Note: See TracChangeset for help on using the changeset viewer.