Ignore:
Timestamp:
08/21/07 19:37:28 (17 years ago)
Author:
mattausch
Message:
 
File:
1 edited

Legend:

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

    r2542 r2543  
    528528                                                                                 SimpleRay &ray) 
    529529{ 
    530         // do not use this function since it could return different viewpoints for 
    531         // different executions of the algorithm 
     530        // do not use this function since it could return different  
     531        // viewpoints for different executions of the algorithm 
     532 
    532533        int tries = 0; 
    533534        Vector3 viewPoint, direction; 
     
    542543        Mesh *mesh = viewCell->GetMesh(); 
    543544                AxisAlignedBox3 box = mesh->mBox; 
    544                 //cout <<"box: " << box << endl; 
    545                 /*Vector3 pVector = Vector3(halton.GetNumber(1), 
    546                                                                   halton.GetNumber(2), 
    547                                                                   halton.GetNumber(3));*/ 
    548  
     545                 
    549546                Vector3 pVector = Vector3(Random(1.0f), 
    550547                                                                  Random(1.0f), 
     
    553550                viewPoint =  box.GetPoint(pVector); 
    554551         
    555                 //const Vector3 dVector = Vector3(2 * M_PI * halton.GetNumber(4), M_PI*halton.GetNumber(5),0.0f); 
    556552                const Vector3 dVector = Vector3(2 * M_PI * Random(1.0f), M_PI * Random(1.0f), 0.0f); 
    557553                direction = Normalize(Vector3(sin(dVector.x), 0.0f, cos(dVector.x))); 
    558                 //halton.GenerateNext(); 
    559554 
    560555                ViewCell *v = GetViewCell(viewPoint); 
     
    564559                        mPreprocessor->GetRenderer()->mViewPoint = viewPoint; 
    565560                        mPreprocessor->GetRenderer()->mViewDirection = direction; 
    566                         //mPreprocessor->GetRenderer()->EvalPvsStat(); 
    567  
     561                 
    568562                        if (mPreprocessor->GetRenderer()->ValidViewPoint()) 
    569563                        { 
     
    574568                } 
    575569 
    576                 // generate a new vector 
    577                 //halton.GenerateNext(); 
    578  
    579                 //if (!box.IsInside(viewPoint)) 
    580                 //      cout << "error!" << endl; 
    581570                if (++ tries > maxTries) 
    582571                { 
     
    672661 
    673662        DEL_PTR(mMixtureDistribution); 
    674          
    675663        CLEAR_CONTAINER(mViewCellPoints); 
    676664} 
     
    829817         
    830818        // mix of sampling strategies 
     819#if 0 
    831820        vector<int>dummy; 
    832         //dummy.push_back(SamplingStrategy::OBJECT_BASED_DISTRIBUTION); 
    833         //dummy.push_back(SamplingStrategy::SPATIAL_BOX_BASED_DISTRIBUTION); 
    834         //dummy.push_back(SamplingStrategy::REVERSE_OBJECT_BASED_DISTRIBUTION); 
    835  
     821        dummy.push_back(SamplingStrategy::OBJECT_BASED_DISTRIBUTION); 
     822        dummy.push_back(SamplingStrategy::SPATIAL_BOX_BASED_DISTRIBUTION); 
     823        dummy.push_back(SamplingStrategy::REVERSE_OBJECT_BASED_DISTRIBUTION); 
     824#endif 
    836825        CastPassSamples(mInitialSamples, mStrategies, initialSamples); 
    837826 
     
    10321021        if (!Debug.is_open()) Debug.open("debug.log"); 
    10331022 
     1023        Debug << "here23" << endl; 
    10341024        // give just an empty container as parameter: 
    10351025        // this loading function is used in the engine, thus it 
     
    10451035 
    10461036 
    1047 void ViewCellsManager::LoadIndexedBoundingBoxes(IN_STREAM &stream, IndexedBoundingBoxContainer &iboxes) 
    1048 { 
    1049         Vector3 bmin; 
    1050         Vector3 bmax; 
    1051         int id; 
    1052  
    1053         stream.read(reinterpret_cast<char *>(&bmin), sizeof(Vector3)); 
    1054         stream.read(reinterpret_cast<char *>(&bmax), sizeof(Vector3)); 
    1055         stream.read(reinterpret_cast<char *>(&id), sizeof(int)); 
    1056  
    1057         AxisAlignedBox3 box(bmin, bmax); 
    1058  
    1059         iboxes.push_back(IndexedBoundingBox(id, box)); 
    1060         //Debug << "bbox: " << box << endl; 
    1061 } 
    1062  
    1063  
    1064 ViewCellsManager *ViewCellsManager::LoadViewCellsBin(const string &filename,  
    1065                                                                                                          ObjectContainer &pvsObjects, 
    1066                                                                                                          ObjectContainer &preprocessorObjects, 
    1067                                                                                                          bool finalizeViewCells, 
    1068                                                                                                          BoundingBoxConverter *bconverter) 
    1069 { 
    1070         IN_STREAM stream(filename.c_str()); 
    1071          
    1072         IndexedBoundingBoxContainer iboxes; 
    1073         LoadIndexedBoundingBoxes(stream, iboxes); 
    1074  
    1075         if (bconverter) 
    1076         { 
    1077                 // all bounding boxes gathered in this step =>  
    1078                 // associate object ids with bounding boxes 
    1079                 bconverter->IdentifyObjects(iboxes, pvsObjects); 
    1080         } 
    1081  
    1082         // sort objects by id 
    1083         sort(pvsObjects.begin(), pvsObjects.end(), ilt); 
    1084  
    1085         ViewCellsTree *vcTree = new ViewCellsTree(); 
    1086         VspTree *vspTree = new VspTree(); 
    1087  
    1088         HierarchyManager *hm = new HierarchyManager(0); 
    1089  
    1090         vspTree->ImportBinary(stream, pvsObjects); 
    1091          
    1092         VspOspViewCellsManager *vcm = new VspOspViewCellsManager(vcTree, hm); 
    1093  
    1094         return vcm; 
     1037void ViewCellsManager::LoadIndexedBoundingBoxesBinary(IN_STREAM &stream, IndexedBoundingBoxContainer &iboxes) 
     1038{ 
     1039        int numBoxes; 
     1040        stream.read(reinterpret_cast<char *>(&numBoxes), sizeof(int)); 
     1041 
     1042        for (int i = 0; i < numBoxes; ++ i) 
     1043        { 
     1044                Vector3 bmin; 
     1045                Vector3 bmax; 
     1046                int id; 
     1047 
     1048                stream.read(reinterpret_cast<char *>(&bmin), sizeof(Vector3)); 
     1049                stream.read(reinterpret_cast<char *>(&bmax), sizeof(Vector3)); 
     1050                stream.read(reinterpret_cast<char *>(&id), sizeof(int)); 
     1051 
     1052                AxisAlignedBox3 box(bmin, bmax); 
     1053                iboxes.push_back(IndexedBoundingBox(id, box)); 
     1054        } 
    10951055} 
    10961056 
     
    11001060                                                                                                  ObjectContainer &preprocessorObjects, 
    11011061                                                                                                  bool finalizeViewCells, 
    1102                                                                                                   BoundingBoxConverter *bconverter) 
    1103                                                                                                   
     1062                                                                                                  BoundingBoxConverter *bconverter)                                                                                               
    11041063{ 
    11051064        ViewCellsParser parser; 
     
    11451104        if (finalizeViewCells) 
    11461105        { 
     1106                // do some final computations, e.g., 
    11471107                // create the meshes and compute view cell volumes 
    11481108                const bool createMeshes = true; 
     
    12501210} 
    12511211 
     1212 
    12521213void ViewCellsManager::EvalViewCellHistogram(const string filename,  
    12531214                                                                                         const int nViewCells) 
     
    12571218 
    12581219        ViewCellContainer viewCells; 
    1259         // $$ JB hack - the collect best viewcells does not work? 
    1260 #if 1 
     1220         
     1221        // the collect best viewcells does not work? 
    12611222        mViewCellsTree->CollectBestViewCellSet(viewCells, nViewCells); 
    1262 #else 
    1263         viewCells = mViewCells; 
    1264 #endif 
    12651223 
    12661224        float maxRenderCost, minRenderCost; 
     
    31923150                        if (boxesIn.eof()) 
    31933151                                break; 
    3194  
    31953152                         
    31963153                        AxisAlignedBox3 box(bmin, bmax); 
    31973154                        MeshInstance *mi = new MeshInstance(NULL); 
    31983155 
    3199                         // HACK: set bounding box to new box 
    3200                         //mi->mBox = box; 
    3201                         //boxes.push_back(mi); 
    32023156                        boxes.push_back(IndexedBoundingBox(id, box)); 
    32033157                } 
     
    32563210                return; 
    32573211 
    3258         if (viewSpaceFilterSize >= 0.0f) { 
    3259  
     3212        if (viewSpaceFilterSize >= 0.0f)  
     3213        { 
    32603214                const bool usePrVS = false; 
    32613215 
    3262                 if (!usePrVS) { 
     3216                if (!usePrVS) 
     3217                { 
    32633218                        AxisAlignedBox3 box = GetViewCellBox(viewCell); 
    32643219                        box.Enlarge(Vector3(viewSpaceFilterSize/2)); 
     
    32783233                                pvs = interPvs; 
    32793234                        } 
    3280                 } else  
     3235                }  
     3236                else  
    32813237                { 
    32823238                        PrVs prvs; 
     
    33493305                                                                         ) 
    33503306{ 
    3351   // now compute a new Pvs by including also objects intersecting the  
    3352   // extended boxes of visible objects 
    3353   Intersectable::NewMail(); 
    3354  
    3355   ObjectPvsIterator pit = pvs.GetIterator(); 
    3356  
    3357   while (pit.HasMoreEntries()) 
    3358       pit.Next()->Mail(); 
    3359  
    3360   ObjectPvs nPvs; 
    3361   int nPvsSize = 0; 
    3362    
    3363   ObjectPvsIterator pit2 = pvs.GetIterator(); 
    3364  
    3365   while (pit2.HasMoreEntries()) 
    3366   {              
    3367           // now go through the pvs again 
    3368           Intersectable *object = pit2.Next(); 
    3369  
    3370           //    Vector3 center = object->GetBox().Center(); 
    3371           //    AxisAlignedBox3 box(center - Vector3(spatialFilterSize/2), 
    3372           //                                            center + Vector3(spatialFilterSize/2)); 
    3373  
    3374           AxisAlignedBox3 box = object->GetBox(); 
    3375           box.Enlarge(Vector3(spatialFilterSize/2)); 
    3376  
    3377           ObjectContainer objects; 
    3378  
    3379           // $$ warning collect objects takes only unmailed ones! 
    3380           kdTree->CollectObjects(box, objects); 
    3381           //    cout<<"collected objects="<<objects.size()<<endl; 
    3382           ObjectContainer::const_iterator noi = objects.begin(); 
    3383           for (; noi != objects.end(); ++ noi)  
    3384           { 
    3385                   Intersectable *o = *noi; 
    3386                   cout<<"w"; 
    3387                   // $$ JB warning: pdfs are not correct at this point!    
    3388                   nPvs.AddSample(o, Limits::Small); 
    3389                   nPvsSize ++; 
    3390           } 
    3391   } 
    3392  
    3393   // cout<<"nPvs size = "<<nPvsSize<<endl; 
    3394   pvs.MergeInPlace(nPvs); 
     3307        // now compute a new Pvs by including also objects intersecting the  
     3308        // extended boxes of visible objects 
     3309        Intersectable::NewMail(); 
     3310 
     3311        ObjectPvsIterator pit = pvs.GetIterator(); 
     3312 
     3313        while (pit.HasMoreEntries()) 
     3314                pit.Next()->Mail(); 
     3315 
     3316        ObjectPvs nPvs; 
     3317        int nPvsSize = 0; 
     3318 
     3319        ObjectPvsIterator pit2 = pvs.GetIterator(); 
     3320 
     3321        while (pit2.HasMoreEntries()) 
     3322        {                
     3323                // now go through the pvs again 
     3324                Intersectable *object = pit2.Next(); 
     3325 
     3326                //      Vector3 center = object->GetBox().Center(); 
     3327                //      AxisAlignedBox3 box(center - Vector3(spatialFilterSize/2), 
     3328                //                                              center + Vector3(spatialFilterSize/2)); 
     3329 
     3330                AxisAlignedBox3 box = object->GetBox(); 
     3331                box.Enlarge(Vector3(spatialFilterSize/2)); 
     3332 
     3333                ObjectContainer objects; 
     3334 
     3335                // $$ warning collect objects takes only unmailed ones! 
     3336                kdTree->CollectObjects(box, objects); 
     3337                //      cout<<"collected objects="<<objects.size()<<endl; 
     3338                ObjectContainer::const_iterator noi = objects.begin(); 
     3339                for (; noi != objects.end(); ++ noi)  
     3340                { 
     3341                        Intersectable *o = *noi; 
     3342                        cout<<"w"; 
     3343                        // $$ JB warning: pdfs are not correct at this point!      
     3344                        nPvs.AddSample(o, Limits::Small); 
     3345                        nPvsSize ++; 
     3346                } 
     3347        } 
     3348 
     3349        // cout<<"nPvs size = "<<nPvsSize<<endl; 
     3350        pvs.MergeInPlace(nPvs); 
    33953351} 
    33963352 
     
    34333389                                                           ) 
    34343390{ 
     3391        pvs.Reserve(viewCell->GetFilteredPvsSize()); 
     3392 
    34353393        PvsFilterStatistics stats; 
    34363394 
    34373395        AxisAlignedBox3 vbox = GetViewCellBox(viewCell); 
    3438         Vector3 center = vbox.Center(); 
     3396        const Vector3 center = vbox.Center(); 
     3397         
    34393398        // copy the PVS 
    3440         Intersectable::NewMail(); 
     3399        if (!mUseKdPvs) 
     3400                Intersectable::NewMail(); 
     3401        else 
     3402                KdNode::NewMail(); 
     3403 
    34413404        ObjectPvs basePvs = viewCell->GetPvs(); 
    34423405        ObjectPvsIterator pit = basePvs.GetIterator(); 
    34433406 
    3444         pvs.Reserve(viewCell->GetFilteredPvsSize()); 
    3445  
    34463407        if (!mUseKdPvs) 
    3447         { 
    3448                 // first mark all objects from this pvs 
     3408        {       // first mark all objects from this pvs 
    34493409                while (pit.HasMoreEntries())     
    34503410                        pit.Next()->Mail(); 
     
    34533413        int pvsSize = 0; 
    34543414        int nPvsSize = 0; 
    3455         float samples = (float)basePvs.GetSamples(); 
    3456  
    3457         Debug<<"f #s="<<samples<<"  pvs size = "<<basePvs.GetSize(); 
     3415         
     3416        //Debug<<"f #s="<<samples<<"  pvs size = "<<basePvs.GetSize(); 
    34583417        //  cout<<"Filter size = "<<filterSize<<endl; 
    34593418        //  cout<<"vbox = "<<vbox<<endl; 
     
    34683427        // and gobal estimate for the view cell 
    34693428        // (total #rays intersecting the viewcell) 
    3470         int minLocalSamples = 2; 
    3471  
    3472         float viewCellRadius = 0.5f*Magnitude(vbox.Diagonal()); 
    3473  
    3474         // now compute the filter box around the current viewCell 
     3429        const int minLocalSamples = 2; 
     3430        const float viewCellRadius = 0.5f * Magnitude(vbox.Diagonal()); 
     3431 
     3432        float samples = (float)basePvs.GetSamples(); 
     3433 
     3434        ////////// 
     3435        //-- now compute the filter box around the current viewCell 
    34753436 
    34763437        if (useViewSpaceFilter)  
    34773438        { 
    3478                 //      float radius = Max(viewCellRadius/100.0f, avgRadius - viewCellRadius); 
    3479                 float radius = viewCellRadius/100.0f; 
     3439                // float radius = Max(viewCellRadius/100.0f, avgRadius - viewCellRadius); 
     3440                float radius = viewCellRadius / 100.0f; 
    34803441                vbox.Enlarge(radius); 
    34813442                cout<<"vbox = "<<vbox<<endl; 
     3443 
    34823444                ViewCellContainer viewCells; 
    34833445                ComputeBoxIntersections(vbox, viewCells); 
     
    34873449                for (int i = 0; it != it_end; ++ it, ++ i) 
    34883450                { 
    3489                          
    34903451                        if ((*it) != viewCell)  
    34913452                        { 
     
    35923553                        } 
    35933554                } 
     3555                 
    35943556                stats.mAvgFilterRadius /= (stats.mLocalFilterCount + stats.mGlobalFilterCount); 
    35953557        } 
     
    36133575        viewCell->SetFilteredPvsSize(pvs.GetSize()); 
    36143576 
    3615         Intersectable::NewMail(); 
     3577        //cout << "pvssize: " << pvs.GetSize() << endl; 
     3578        // warning: not thread-safe! 
     3579        if (!mUseKdPvs) 
     3580                Intersectable::NewMail(); 
     3581 
    36163582        return stats; 
    36173583} 
     
    37353701        Intersectable::NewMail(); 
    37363702 
     3703 
    37373704        /////////// 
    37383705        //-- merge pvss 
    37393706 
     3707        PvsData pvsData; 
     3708 
    37403709        vector<ObjectPvs>::iterator oit = pvsList.begin(); 
    3741  
    3742         PvsData pvsData; 
    37433710 
    37443711        for (vit = interior->mChildren.begin(); vit != vit_end; ++ vit, ++ oit) 
     
    47864753                        exporter->SetWireframe(); 
    47874754 
    4788                         // matt: we don't have no kd pvs 
     4755                        // matt: we do not use kd pvs 
    47894756#if 0 
    47904757                        KdPvsMap::iterator kit = object->mKdPvs.mEntries.begin(); 
     
    59195886{ 
    59205887        Environment::GetSingleton()->GetIntValue("Hierarchy.Construction.samples", mInitialSamples); 
    5921  
    59225888        Environment::GetSingleton()->GetBoolValue("ViewCells.compressObjects", mCompressObjects); 
    59235889 
     
    59265892 
    59275893        mHierarchyManager = CreateHierarchyManager(hierarchyType); 
     5894 
    59285895        mHierarchyManager->SetViewCellsManager(this); 
    59295896        mHierarchyManager->SetViewCellsTree(mViewCellsTree); 
     
    62476214                                                                                                        ) const 
    62486215{ 
     6216        Plane3 plane; 
     6217        if (clipPlane) 
     6218        { 
     6219                // arbitrary plane definition 
     6220                plane = clipPlane->GetPlane(); 
     6221        } 
     6222 
    62496223        ViewCellContainer leaves; 
    62506224        mViewCellsTree->CollectLeaves(vc, leaves); 
     6225 
    62516226        ViewCellContainer::const_iterator it, it_end = leaves.end(); 
    6252  
    6253         Plane3 plane; 
    6254         if (clipPlane) 
    6255         { 
    6256                 // arbitrary plane definition 
    6257                 plane = clipPlane->GetPlane(); 
    6258         } 
    62596227 
    62606228        for (it = leaves.begin(); it != it_end; ++ it) 
     
    65226490                { 
    65236491                        Material m; 
    6524  
    65256492                        Intersectable::NewMail(); 
    65266493                         
     
    66366603                return false; 
    66376604 
    6638         cout << "exporting binary" << endl; 
    6639         string fname("test.vc"); 
    6640         return ExportBinaryViewCells(fname, exportPvs, objects); 
     6605        /*if (strstr(filename.c_str(), ".bn")) 
     6606        { 
     6607                cout << "exporting view cells to binary format" << endl; 
     6608                return ExportViewCellsBinary(filename, exportPvs, objects); 
     6609        }*/ 
     6610 
     6611        cout << "exporting binary" << endl; string fname("test.vc"); return ExportViewCellsBinary(fname, exportPvs, objects); 
    66416612 
    66426613        const long starttime = GetTime(); 
     
    66626633 
    66636634                        int id = 0; 
    6664  
    66656635                        vector<KdIntersectable *>::const_iterator kit, kit_end = mPreprocessor->mKdTree->mKdIntersectables.end(); 
    66666636                         
     
    66976667 
    66986668 
    6699         ////////////////////// 
     6669        ///////////////// 
    67006670        //-- export the view space hierarchy 
    67016671         
     
    67076677        stream << "</ViewSpaceHierarchy>" << endl; 
    67086678 
    6709         //////////////////////   
    6710         //-- export the object space partition 
     6679        ///////////////// 
     6680        //-- export the object space hierarchy 
    67116681         
    67126682        mHierarchyManager->ExportObjectSpaceHierarchy(stream); 
     
    67206690 
    67216691 
    6722 bool VspOspViewCellsManager::ExportBinaryViewCells(const string filename,  
     6692bool VspOspViewCellsManager::ExportViewCellsBinary(const string filename,  
    67236693                                                                                                   const bool exportPvs,  
    67246694                                                                                                   const ObjectContainer &objects) 
     
    67366706        CreateUniqueViewCellIds(); 
    67376707 
    6738         int numBoundingBoxes = mPreprocessor->mKdTree->mKdIntersectables.size(); 
    6739         stream.write(reinterpret_cast<char *>(&numBoundingBoxes), sizeof(int)); 
     6708        int numBoxes = mPreprocessor->mKdTree->mKdIntersectables.size(); 
     6709        stream.write(reinterpret_cast<char *>(&numBoxes), sizeof(int)); 
    67406710 
    67416711 
     
    67516721        { 
    67526722                Intersectable *obj = (*kit); 
     6723                // set the kd node id to identify the kd node as a pvs entry 
     6724                obj->SetId(id); 
     6725 
    67536726                const AxisAlignedBox3 &box = obj->GetBox(); 
    6754  
    6755                 // setting the kd node id important to identify the kd node as pvs entry 
    6756                 obj->SetId(id); 
    6757  
    67586727                Vector3 bmin = box.Min(); 
    67596728                Vector3 bmax = box.Max(); 
     
    67646733        } 
    67656734 
     6735        cout << "written " << numBoxes << " kd nodes" << endl; 
    67666736 
    67676737        /////////////// 
    67686738        //-- export the view cells and the pvs 
    67696739 
    6770         int numViewCells = mCurrentViewCellsStats.viewCells; 
     6740        int numViewCells = mViewCells.size(); 
    67716741        stream.write(reinterpret_cast<char *>(&numViewCells), sizeof(int)); 
    67726742 
     
    67776747        stream.write(reinterpret_cast<char *>(&vmax), sizeof(Vector3)); 
    67786748 
    6779         // todo 
     6749 
     6750        ////////// 
     6751        //-- export binary view cells 
     6752 
    67806753        mViewCellsTree->ExportBinary(stream); 
    67816754 
    67826755 
    6783         ////////////////////// 
     6756        ///////// 
    67846757        //-- export the view space hierarchy 
    67856758         
    67866759        mHierarchyManager->GetVspTree()->ExportBinary(stream); 
    67876760         
     6761 
     6762        //////// 
     6763        //-- export the object space hierarchy 
     6764 
     6765        //mHierarchyManager->ExportObjectSpaceHierarchyBinary(); 
     6766     
    67886767        stream.close(); 
    67896768         
     6769        mHierarchyManager->GetVspTree()->TestOutput("output.txt"); 
     6770 
    67906771        cout << "finished in " << TimeDiff(starttime, GetTime()) * 1e-3 << " secs" << endl; 
    67916772        return true; 
     
    68886869        if (!(ViewCellsTreeConstructed() && mCompressViewCells)) 
    68896870                return; 
     6871 
    68906872 
    68916873        //////////// 
     
    70427024                cout << "computing histogram for " << pass << " view cells" << endl; 
    70437025 
    7044                 ///////////////////////////// 
     7026                /////////////////// 
    70457027                //-- evaluate histogram for pvs size 
    70467028 
     
    70607042 
    70617043        if (mHierarchyManager->mUseTraversalTree) 
    7062         { 
    7063                 // create a traversal tree for optimal view cell casting 
     7044        {       // create a traversal tree for optimal view cell casting 
    70647045                mHierarchyManager->CreateTraversalTree(); 
    70657046        } 
     
    70977078                        { 
    70987079                                ComputeSampleContribution(*tmpRays[i], addContributions, true, useHitObjects); 
    7099  
    7100                                 ////////// 
    71017080                                // compare results 
    7102                                 cout << "ray " << i << ": " << (int)tmpRays[i]->mViewCells.size() << " " << (int)packet.mViewCells[i].size() << endl; 
     7081                                cout << "ray " << i << ": " << (int)tmpRays[i]->mViewCells.size() << " "  
     7082                                         << (int)packet.mViewCells[i].size() << endl; 
    71037083                        } 
    71047084                         
     
    71277107                                                                          BoundingBoxConverter *bconverter)                                                                                               
    71287108{ 
    7129         ViewCellsParser parser; 
    7130         ViewCellsManager *vm = NULL; 
     7109        if (!Debug.is_open()) Debug.open("debug.log"); 
     7110 
     7111        IN_STREAM stream(filename.c_str()); 
     7112 
     7113        if (!stream.is_open()) 
     7114        { 
     7115                Debug << "View cells loading failed: could not open file" << endl; 
     7116                return NULL; 
     7117        } 
     7118 
     7119        Debug << "loading boxes" << endl; 
    71317120 
    71327121        const long startTime = GetTime(); 
    7133         const bool success = false; 
    7134  
    7135         if (!success) 
    7136         { 
    7137                 Debug << "Error: loading view cells failed!" << endl; 
    7138                 DEL_PTR(vm); 
    7139  
     7122 
     7123        IndexedBoundingBoxContainer iboxes; 
     7124        ViewCellsManager::LoadIndexedBoundingBoxesBinary(stream, iboxes); 
     7125 
     7126        Debug << (int)iboxes.size() << " boxes loaded" << endl; 
     7127 
     7128        /*IndexedBoundingBoxContainer::const_iterator bit, bit_end = iboxes.end(); 
     7129        for (bit = iboxes.begin(); bit != bit_end; ++ bit) 
     7130        { 
     7131                IndexedBoundingBox ibox = *bit; 
     7132                cerr << "box: " << ibox.first << " " << ibox.second << endl; 
     7133        }*/ 
     7134 
     7135 
     7136        if (bconverter) 
     7137        { 
     7138                // all bounding boxes gathered in this step =>  
     7139                // associate object ids with bounding boxes 
     7140                bconverter->IdentifyObjects(iboxes, pvsObjects); 
     7141        } 
     7142 
     7143        // sort objects by id 
     7144        sort(pvsObjects.begin(), pvsObjects.end(), ilt); 
     7145         
     7146 
     7147        ///////////// 
     7148        //-- load the view cells 
     7149         
     7150        int numViewCells; 
     7151        stream.read(reinterpret_cast<char *>(&numViewCells), sizeof(int)); 
     7152 
     7153        Debug << "loading " << numViewCells << " view cells " << endl; 
     7154 
     7155        Vector3 vmin, vmax; 
     7156 
     7157        stream.read(reinterpret_cast<char *>(&vmin), sizeof(Vector3)); 
     7158        stream.read(reinterpret_cast<char *>(&vmax), sizeof(Vector3)); 
     7159 
     7160        AxisAlignedBox3 viewSpaceBox(vmin, vmax); 
     7161 
     7162        Debug << "view space box: " << viewSpaceBox << endl; 
     7163 
     7164    ViewCellsTree *vcTree = new ViewCellsTree(); 
     7165 
     7166        if (!vcTree->ImportBinary(stream, pvsObjects)) 
     7167        { 
     7168                Debug << "Error: loading view cells tree failed!" << endl; 
     7169                delete vcTree; 
     7170         
    71407171                return NULL; 
    71417172        } 
    7142          
    7143         ViewCellContainer leaves; 
     7173 
     7174        Debug << "loading the view space partition tree" << endl; 
     7175        VspTree *vspTree = new VspTree(); 
     7176 
     7177        vspTree->mBoundingBox = viewSpaceBox; 
     7178 
     7179        if (!vspTree->ImportBinary(stream, pvsObjects)) 
     7180        { 
     7181                Debug << "Error: loading vsp tree failed!" << endl; 
     7182                delete vcTree; delete vspTree; 
     7183 
     7184                return NULL; 
     7185        } 
     7186 
     7187 
     7188        HierarchyManager * hm =  
     7189                new HierarchyManager(HierarchyManager::BV_BASED_OBJ_SUBDIV); 
     7190 
     7191        hm->SetVspTree(vspTree); 
     7192 
     7193 
     7194        ///////// 
     7195        //-- create view cells manager 
     7196         
     7197        VspOspViewCellsManager *vm = new VspOspViewCellsManager(vcTree, hm); 
     7198 
     7199 
     7200 
     7201        ////////////// 
     7202        //-- do some more preparation 
    71447203 
    71457204        vm->mViewCells.clear(); 
    7146         vm->mViewCellsTree->CollectLeaves(vm->mViewCellsTree->GetRoot(), leaves); 
    7147  
    7148         ViewCellContainer::const_iterator it, it_end = leaves.end(); 
    7149  
    7150         for (it = leaves.begin(); it != it_end; ++ it) 
    7151         { 
    7152                 vm->mViewCells.push_back(*it); 
    7153         } 
     7205 
     7206        ViewCellContainer viewCells; 
     7207        vcTree->CollectLeaves(vcTree->GetRoot(), viewCells); 
     7208 
     7209        ViewCellContainer::const_iterator cit, cit_end = viewCells.end(); 
     7210 
     7211        for (cit = viewCells.begin(); cit != cit_end; ++ cit) 
     7212        { 
     7213                vm->mViewCells.push_back(*cit); 
     7214        } 
     7215 
     7216 
     7217        ////////////// 
     7218        //-- associate view cells with vsp leaves 
     7219 
     7220        vector<VspLeaf *> vspLeaves; 
     7221        vspTree->CollectLeaves(vspLeaves); 
     7222 
     7223        vector<VspLeaf *>::const_iterator vit, vit_end = vspLeaves.end(); 
     7224        cit = viewCells.begin(); 
     7225 
     7226        for (vit = vspLeaves.begin(); vit != vit_end; ++ vit, ++ cit) 
     7227        { 
     7228                VspLeaf *leaf = *vit; 
     7229                VspViewCell *vc = static_cast<VspViewCell *>(*cit); 
     7230 
     7231                leaf->SetViewCell(vc); 
     7232                vc->mLeaves.push_back(leaf); 
     7233        } 
     7234 
    71547235 
    71557236        vm->mViewCellsFinished = true; 
     
    71637244        } 
    71647245 
    7165         cout << (int)vm->mViewCells.size() << " view cells loaded in " 
    7166                  << TimeDiff(startTime, GetTime()) * 1e-3f << " secs" << endl; 
    7167  
    71687246        Debug << (int)vm->mViewCells.size() << " view cells loaded in " 
    7169                   << TimeDiff(startTime, GetTime()) * 1e-3f << " secs" << endl; 
    7170          
     7247                  << TimeDiff(startTime, GetTime()) * 1e-6f << " secs" << endl; 
     7248 
     7249        vspTree->TestOutput("input.txt"); 
     7250 
    71717251        return vm; 
    71727252} 
Note: See TracChangeset for help on using the changeset viewer.