Ignore:
Timestamp:
08/08/07 15:50:33 (17 years ago)
Author:
mattausch
Message:

fixed obj loading error

File:
1 edited

Legend:

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

    r2538 r2539  
    10211021                                                                                                  
    10221022{ 
     1023        // give just an empty container as parameter: 
     1024        // this loading function is used in the engine, thus it 
     1025        // does not need to load the entities the preprocessor works on 
    10231026        ObjectContainer preprocessorObjects; 
    10241027 
     
    10581061        } 
    10591062         
    1060         if (0) 
     1063        if (0) //hack: should work with reset function, but something is wrong .. 
    10611064        { 
    10621065                vm->ResetViewCells(); 
     
    10641067        else 
    10651068        { 
    1066                 //hack: should work with reset function 
    10671069                ViewCellContainer leaves; 
    10681070 
     
    11111113        OUT_STREAM stream(filename.c_str()); 
    11121114 
    1113         // for output we need unique ids for each view cell 
     1115        // we need unique ids for each view cell 
    11141116        CreateUniqueViewCellIds(); 
    11151117 
     
    12871289 
    12881290        ViewCellContainer viewCells; 
     1291 
    12891292#ifdef USE_BIT_PVS 
    12901293        cout << "objects size: " << (int)ObjectPvsIterator::sObjects.size() << endl; 
    12911294        cout << "pvs size: " <<  ObjectPvs::sPvsSize << endl; 
    12921295#endif 
     1296 
    12931297        // $$ JB hack - the collect best viewcells does not work? 
    12941298#if 0 
     
    12971301        viewCells = mViewCells; 
    12981302#endif 
     1303 
    12991304        ViewCellContainer::iterator it = viewCells.begin(), it_end = viewCells.end();            
     1305         
    13001306        for (; it != it_end; ++it)  
    13011307        { 
    1302                 if (1) 
    1303                         (*it)->UpdatePvsCost(); 
    1304                 else 
    1305                         (*it)->SetTrianglesInPvs((float)(*it)->GetFilteredPvsSize()); 
     1308                (*it)->UpdatePvsCost(); 
    13061309        } 
    13071310 
     
    13641367                        ++ smallerSum; 
    13651368                } 
    1366                  
    1367                 //              if (0 && (i < (int)viewCells.size())) 
    1368                 //                Debug << "new pvs cost increase: " << mViewCellsTree->GetTrianglesInPvs(viewCells[i])  
    1369                 //                              << " " << currentPvs << endl; 
    13701369                 
    13711370                const float volRatioDif = volDif / totalVol; 
     
    18431842                                                           const float filterWidth) 
    18441843{ 
    1845   ViewCell *currentViewCell = GetViewCell(viewPoint); 
    1846  
    1847   if (mMaxFilterSize < 1) { 
    1848         prvs.mViewCell = currentViewCell; 
    1849         return; 
    1850   } 
    1851    
    1852   const AxisAlignedBox3 box = GetFilterBBox(viewPoint, filterWidth); 
    1853    
    1854   if (currentViewCell)  
    1855         { 
    1856           ViewCellContainer viewCells; 
    1857           ComputeBoxIntersections(box, viewCells); 
    1858            
    1859           ViewCell *root = ConstructLocalMergeTree2(currentViewCell, viewCells); 
    1860           prvs.mViewCell = root; 
    1861            
     1844        ViewCell *currentViewCell = GetViewCell(viewPoint); 
     1845 
     1846        if (mMaxFilterSize < 1) { 
     1847                prvs.mViewCell = currentViewCell; 
     1848                return; 
     1849        } 
     1850 
     1851        const AxisAlignedBox3 box = GetFilterBBox(viewPoint, filterWidth); 
     1852 
     1853        if (currentViewCell)  
     1854        { 
     1855                ViewCellContainer viewCells; 
     1856                ComputeBoxIntersections(box, viewCells); 
     1857 
     1858                ViewCell *root = ConstructLocalMergeTree2(currentViewCell, viewCells); 
     1859                prvs.mViewCell = root; 
     1860 
    18621861        }  
    1863   else 
    1864         { 
    1865           prvs.mViewCell = NULL; 
    1866           //prvs.mPvs = root->GetPvs(); 
     1862        else 
     1863        { 
     1864                prvs.mViewCell = NULL; 
     1865                //prvs.mPvs = root->GetPvs(); 
    18671866        } 
    18681867} 
     
    40774076 
    40784077        ////////// 
    4079         //-- some view cells for output 
     4078        //-- export visualizations of some view cells 
    40804079 
    40814080        ViewCell::NewMail(); 
     
    41164115                for (vit = leaves.begin(); vit != vit_end; ++ vit) 
    41174116                        {        
    4118                                 // prepare some rays for output 
     4117                                // prepare some rays for visualization 
    41194118                                VssRayContainer::const_iterator rit, rit_end = (*vit)->GetOrCreateRays()->end(); 
    41204119                                for (rit = (*vit)->GetOrCreateRays()->begin(); rit != rit_end; ++ rit) 
     
    41264125                        const int raysOut = min((int)collectRays.size(), maxRays); 
    41274126 
    4128                         // prepare some rays for output 
     4127                        // prepare some rays for visualization 
    41294128                        VssRayContainer::const_iterator rit, rit_end = collectRays.end(); 
    41304129                        for (rit = collectRays.begin(); rit != rit_end; ++ rit) 
     
    43814380        OUT_STREAM stream(filename.c_str()); 
    43824381 
    4383         // for output we need unique ids for each view cell 
     4382        // we need unique ids for each view cell 
    43844383        CreateUniqueViewCellIds(); 
    43854384 
     
    46114610                ViewCell::NewMail(); 
    46124611 
    4613                 //-- some rays for output 
     4612                //-- some rays for visualization 
    46144613                const int raysOut = min((int)sampleRays.size(), mVisualizationSamples); 
    46154614                Debug << "visualization using " << raysOut << " samples" << endl; 
    46164615 
    4617                 //-- some random view cells and rays for output 
     4616                //-- some random view cells and rays for visualization 
    46184617                vector<KdLeaf *> kdLeaves; 
    46194618 
     
    54005399 
    54015400        ////////// 
    5402         //-- some view cells for output 
     5401        //-- export some view cells for visualization 
    54035402 
    54045403        ViewCell::NewMail(); 
     
    54535452                        const int raysOut = min((int)collectRays.size(), maxRays); 
    54545453                 
    5455                         // prepare some rays for output 
     5454                        // prepare some rays for visualization 
    54565455                        VssRayContainer::const_iterator rit, rit_end = collectRays.end(); 
    54575456                        for (rit = collectRays.begin(); rit != rit_end; ++ rit) 
     
    54835482                { 
    54845483                        Intersectable::NewMail(); 
    5485  
    54865484                        ObjectPvsIterator pit = pvs.GetIterator(); 
    54875485 
     
    65856583        OUT_STREAM stream(filename.c_str()); 
    65866584 
    6587         // for output we need unique ids for each view cell 
     6585        // we need unique ids for each view cell 
    65886586        CreateUniqueViewCellIds(); 
    65896587 
     
    66006598                { 
    66016599                        stream << "<BoundingBoxes>" << endl; 
     6600 
     6601                        int id = 0; 
     6602 
    66026603                        vector<KdIntersectable *>::const_iterator kit, kit_end = mPreprocessor->mKdTree->mKdIntersectables.end(); 
    6603  
    6604                         int id = 0; 
    6605  
     6604                         
    66066605                        for (kit = mPreprocessor->mKdTree->mKdIntersectables.begin(); kit != kit_end; ++ kit, ++ id) 
    66076606                        { 
     
    66576656} 
    66586657 
     6658 
     6659bool VspOspViewCellsManager::ExportBinaryViewCells(const string filename,  
     6660                                                                                                   const bool exportPvs,  
     6661                                                                                                   const ObjectContainer &objects) 
     6662{ 
     6663        if (!ViewCellsConstructed() || !ViewCellsTreeConstructed()) 
     6664                return false; 
     6665 
     6666        const long starttime = GetTime(); 
     6667        cout << "exporting view cells to binary format ... "; 
     6668         
     6669        OUT_STREAM stream(filename.c_str()); 
     6670 
     6671        // we need unique ids for each view cell 
     6672        CreateUniqueViewCellIds(); 
     6673 
     6674        int numBoundingBoxes = mPreprocessor->mKdTree->mKdIntersectables.size(); 
     6675        stream.write(reinterpret_cast<char *>(&numBoundingBoxes), sizeof(int)); 
     6676 
     6677 
     6678    /////////////// 
     6679        //-- export bounding boxes 
     6680        //-- we need the boxes to identify objects in the target engine 
     6681 
     6682        vector<KdIntersectable *>::const_iterator kit, kit_end = mPreprocessor->mKdTree->mKdIntersectables.end(); 
     6683 
     6684        int id = 0; 
     6685 
     6686        for (kit = mPreprocessor->mKdTree->mKdIntersectables.begin(); kit != kit_end; ++ kit, ++ id) 
     6687        { 
     6688                Intersectable *obj = (*kit); 
     6689                const AxisAlignedBox3 &box = obj->GetBox(); 
     6690 
     6691                // set kd node id 
     6692                obj->SetId(id); 
     6693                Vector3 bmin = box.Min(); 
     6694                Vector3 bmax = box.Max(); 
     6695 
     6696                stream.write(reinterpret_cast<char *>(&bmin), sizeof(Vector3)); 
     6697                stream.write(reinterpret_cast<char *>(&bmax), sizeof(Vector3)); 
     6698                stream.write(reinterpret_cast<char *>(&id), sizeof(int)); 
     6699        } 
     6700 
     6701 
     6702        /////////////// 
     6703        //-- export the view cells and the pvs 
     6704 
     6705 
     6706        int numViewCells = mCurrentViewCellsStats.viewCells; 
     6707        stream.write(reinterpret_cast<char *>(&numViewCells), sizeof(int)); 
     6708 
     6709        Vector3 vmin = mViewSpaceBox.Min(); 
     6710        Vector3 vmax = mViewSpaceBox.Max(); 
     6711 
     6712        stream.write(reinterpret_cast<char *>(&vmin), sizeof(Vector3)); 
     6713        stream.write(reinterpret_cast<char *>(&vmax), sizeof(Vector3)); 
     6714 
     6715 
     6716        ////////////////////// 
     6717        //-- export the view space hierarchy 
     6718         
     6719        mHierarchyManager->GetVspTree()->ExportBinary(stream); 
     6720         
     6721        stream.close(); 
     6722         
     6723        cout << "finished in " << TimeDiff(starttime, GetTime()) * 1e-3 << " secs" << endl; 
     6724        return true; 
     6725} 
    66596726 
    66606727 
     
    69667033                                ////////// 
    69677034                                // compare results 
    6968  
    69697035                                cout << "ray " << i << ": " << (int)tmpRays[i]->mViewCells.size() << " " << (int)packet.mViewCells[i].size() << endl; 
    69707036                        } 
    6971  
    6972                          
    69737037                         
    69747038                        CLEAR_CONTAINER(tmpRays); 
    69757039                } 
    69767040        } 
    6977 cout << "=================\nhere6"<<endl; 
     7041         
    69787042        CLEAR_CONTAINER(tmpRays); 
    69797043 
     
    69907054 
    69917055 
    6992 } 
     7056 
     7057ViewCellsManager *LoadViewCellsBinary(const string &filename,  
     7058                                                                          ObjectContainer &pvsObjects, 
     7059                                                                          bool finalizeViewCells, 
     7060                                                                          BoundingBoxConverter *bconverter)                                                                                               
     7061{ 
     7062        ViewCellsParser parser; 
     7063        ViewCellsManager *vm = NULL; 
     7064 
     7065        const long startTime = GetTime(); 
     7066        const bool success = false; 
     7067 
     7068        if (!success) 
     7069        { 
     7070                Debug << "Error: loading view cells failed!" << endl; 
     7071                DEL_PTR(vm); 
     7072 
     7073                return NULL; 
     7074        } 
     7075         
     7076        ViewCellContainer leaves; 
     7077 
     7078        vm->mViewCells.clear(); 
     7079        vm->mViewCellsTree->CollectLeaves(vm->mViewCellsTree->GetRoot(), leaves); 
     7080 
     7081        ViewCellContainer::const_iterator it, it_end = leaves.end(); 
     7082 
     7083        for (it = leaves.begin(); it != it_end; ++ it) 
     7084        { 
     7085                vm->mViewCells.push_back(*it); 
     7086        } 
     7087 
     7088        vm->mViewCellsFinished = true; 
     7089        vm->mMaxPvsSize = (int)pvsObjects.size(); 
     7090 
     7091        if (finalizeViewCells) 
     7092        { 
     7093                // create the meshes and compute view cell volumes 
     7094                const bool createMeshes = true; 
     7095                vm->FinalizeViewCells(createMeshes); 
     7096        } 
     7097 
     7098        cout << (int)vm->mViewCells.size() << " view cells loaded in " 
     7099                 << TimeDiff(startTime, GetTime()) * 1e-3f << " secs" << endl; 
     7100 
     7101        Debug << (int)vm->mViewCells.size() << " view cells loaded in " 
     7102                  << TimeDiff(startTime, GetTime()) * 1e-3f << " secs" << endl; 
     7103         
     7104        return vm; 
     7105} 
     7106 
     7107} 
Note: See TracChangeset for help on using the changeset viewer.