Ignore:
Timestamp:
08/20/07 12:51:12 (17 years ago)
Author:
mattausch
Message:
 
File:
1 edited

Legend:

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

    r2539 r2542  
    3434#define PVS_ADD_DIRTY 1 
    3535 
     36 
     37 
    3638namespace GtpVisibilityPreprocessor { 
    3739 
     
    4648const static bool CLAMP_TO_BOX = true; 
    4749 
     50 
     51 
     52inline static bool ilt(Intersectable *obj1, Intersectable *obj2) 
     53{ 
     54        return obj1->mId < obj2->mId; 
     55} 
    4856 
    4957 
     
    9941002        EvaluateViewCellsStats(); 
    9951003 
    996         if (1) CompressViewCells(); 
     1004        // compress the final solution 
     1005        if (0) CompressViewCells(); 
    9971006 
    9981007        // write view cells to disc 
     
    10211030                                                                                                  
    10221031{ 
     1032        if (!Debug.is_open()) Debug.open("debug.log"); 
     1033 
    10231034        // give just an empty container as parameter: 
    10241035        // this loading function is used in the engine, thus it 
    10251036        // does not need to load the entities the preprocessor works on 
    10261037        ObjectContainer preprocessorObjects; 
    1027  
    1028         if (!Debug.is_open()) Debug.open("debug.log"); 
    10291038 
    10301039        return LoadViewCells(filename,  
     
    10331042                                                 finalizeViewCells, 
    10341043                                                 bconverter); 
     1044} 
     1045 
     1046 
     1047void 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 
     1064ViewCellsManager *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; 
    10351095} 
    10361096 
     
    10611121        } 
    10621122         
    1063         if (0) //hack: should work with reset function, but something is wrong .. 
     1123        if (0) //hack: reset function should work, but something is wrong .. 
    10641124        { 
    10651125                vm->ResetViewCells(); 
     
    11041164                                                                                         const ObjectContainer &objects) 
    11051165{ 
     1166        // no view cells constructed yet 
    11061167        if (!ViewCellsConstructed() || !ViewCellsTreeConstructed()) 
    1107         { 
    11081168                return false; 
    1109         } 
    11101169 
    11111170        cout << "exporting view cells to xml ... "; 
     
    24242483 
    24252484 
    2426  
    2427                   if (evaluateFilter) { 
     2485                  if (evaluateFilter)  
     2486                  { 
    24282487                          ObjectPvs filteredPvs; 
    24292488 
    2430                           PvsFilterStatistics fstat = ApplyFilter2(viewcell, 
    2431                                   false, 
    2432                                   mFilterWidth, 
    2433                                   filteredPvs); 
    2434  
    2435                           float filteredCost = filteredPvs.EvalPvsCost(); 
     2489                          PvsFilterStatistics fstat = ApplyFilter2(viewcell, false, mFilterWidth, filteredPvs); 
     2490 
     2491                          const float filteredCost = filteredPvs.EvalPvsCost(); 
    24362492 
    24372493                          stat.avgFilteredPvs += filteredCost; 
     
    30703126                        MeshInstance *mi = static_cast<MeshInstance *>(*it); 
    30713127                        const AxisAlignedBox3 box = mi->GetBox(); 
     3128                         
    30723129                        Vector3 bmin = box.Min(); 
    30733130                        Vector3 bmax = box.Max(); 
     3131                         
    30743132                        int id = mi->GetId(); 
    30753133 
     
    34443502 
    34453503        // Minimal number of samples so that filtering takes place 
    3446 #define MIN_SAMPLES  50 
     3504        const float MIN_SAMPLES = 50; 
    34473505 
    34483506        if (samples > MIN_SAMPLES)  
     
    35373595        } 
    35383596 
    3539         Debug << " nPvs size = " << pvs.GetSize() << endl; 
     3597        //Debug << " nPvs size = " << pvs.GetSize() << endl; 
    35403598 
    35413599        if (!mUseKdPvs) 
     
    58875945 
    58885946 
    5889 Intersectable * 
    5890 VspOspViewCellsManager::GetIntersectable(const VssRay &ray, const bool isTermination) const 
     5947Intersectable *VspOspViewCellsManager::GetIntersectable(const VssRay &ray,  
     5948                                                                                                                const bool isTermination) const 
    58915949{ 
    58925950        if (mUseKdPvs) 
     
    63876445                        const bool exportBounds = false; 
    63886446 
    6389                         if (1) 
    63906447                        mHierarchyManager->ExportObjectSpaceHierarchy(exporter,  
    63916448                                                                      objects,  
     
    65756632                                                                                         const ObjectContainer &objects) 
    65766633{ 
     6634        // no view cells were computed 
    65776635        if (!ViewCellsConstructed() || !ViewCellsTreeConstructed()) 
    65786636                return false; 
     6637 
     6638        cout << "exporting binary" << endl; 
     6639        string fname("test.vc"); 
     6640        return ExportBinaryViewCells(fname, exportPvs, objects); 
    65796641 
    65806642        const long starttime = GetTime(); 
     
    66126674 
    66136675                                stream << "<BoundingBox" << " id=\"" << id << "\"" 
    6614                                    << " min=\"" << box.Min().x << " " << box.Min().y << " " << box.Min().z << "\"" 
    6615                                    << " max=\"" << box.Max().x << " " << box.Max().y << " " << box.Max().z << "\" />" << endl; 
     6676                                           << " min=\"" << box.Min().x << " " << box.Min().y << " " << box.Min().z << "\"" 
     6677                                       << " max=\"" << box.Max().x << " " << box.Max().y << " " << box.Max().z << "\" />" << endl; 
    66166678                        } 
     6679 
    66176680                        stream << "</BoundingBoxes>" << endl; 
    66186681                } 
     
    66616724                                                                                                   const ObjectContainer &objects) 
    66626725{ 
     6726        // no view cells constructed yet 
    66636727        if (!ViewCellsConstructed() || !ViewCellsTreeConstructed()) 
    66646728                return false; 
     
    66786742    /////////////// 
    66796743        //-- export bounding boxes 
    6680         //-- we need the boxes to identify objects in the target engine 
    6681  
     6744 
     6745        // we use bounding box intersection to identify pvs objects in the target engine 
    66826746        vector<KdIntersectable *>::const_iterator kit, kit_end = mPreprocessor->mKdTree->mKdIntersectables.end(); 
    66836747 
     
    66896753                const AxisAlignedBox3 &box = obj->GetBox(); 
    66906754 
    6691                 // set kd node id 
     6755                // setting the kd node id important to identify the kd node as pvs entry 
    66926756                obj->SetId(id); 
     6757 
    66936758                Vector3 bmin = box.Min(); 
    66946759                Vector3 bmax = box.Max(); 
     
    67036768        //-- export the view cells and the pvs 
    67046769 
    6705  
    67066770        int numViewCells = mCurrentViewCellsStats.viewCells; 
    67076771        stream.write(reinterpret_cast<char *>(&numViewCells), sizeof(int)); 
     
    67126776        stream.write(reinterpret_cast<char *>(&vmin), sizeof(Vector3)); 
    67136777        stream.write(reinterpret_cast<char *>(&vmax), sizeof(Vector3)); 
     6778 
     6779        // todo 
     6780        mViewCellsTree->ExportBinary(stream); 
    67146781 
    67156782 
Note: See TracChangeset for help on using the changeset viewer.