Changeset 2539 for GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp
- Timestamp:
- 08/08/07 15:50:33 (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp
r2538 r2539 1021 1021 1022 1022 { 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 1023 1026 ObjectContainer preprocessorObjects; 1024 1027 … … 1058 1061 } 1059 1062 1060 if (0) 1063 if (0) //hack: should work with reset function, but something is wrong .. 1061 1064 { 1062 1065 vm->ResetViewCells(); … … 1064 1067 else 1065 1068 { 1066 //hack: should work with reset function1067 1069 ViewCellContainer leaves; 1068 1070 … … 1111 1113 OUT_STREAM stream(filename.c_str()); 1112 1114 1113 // for outputwe need unique ids for each view cell1115 // we need unique ids for each view cell 1114 1116 CreateUniqueViewCellIds(); 1115 1117 … … 1287 1289 1288 1290 ViewCellContainer viewCells; 1291 1289 1292 #ifdef USE_BIT_PVS 1290 1293 cout << "objects size: " << (int)ObjectPvsIterator::sObjects.size() << endl; 1291 1294 cout << "pvs size: " << ObjectPvs::sPvsSize << endl; 1292 1295 #endif 1296 1293 1297 // $$ JB hack - the collect best viewcells does not work? 1294 1298 #if 0 … … 1297 1301 viewCells = mViewCells; 1298 1302 #endif 1303 1299 1304 ViewCellContainer::iterator it = viewCells.begin(), it_end = viewCells.end(); 1305 1300 1306 for (; it != it_end; ++it) 1301 1307 { 1302 if (1) 1303 (*it)->UpdatePvsCost(); 1304 else 1305 (*it)->SetTrianglesInPvs((float)(*it)->GetFilteredPvsSize()); 1308 (*it)->UpdatePvsCost(); 1306 1309 } 1307 1310 … … 1364 1367 ++ smallerSum; 1365 1368 } 1366 1367 // if (0 && (i < (int)viewCells.size()))1368 // Debug << "new pvs cost increase: " << mViewCellsTree->GetTrianglesInPvs(viewCells[i])1369 // << " " << currentPvs << endl;1370 1369 1371 1370 const float volRatioDif = volDif / totalVol; … … 1843 1842 const float filterWidth) 1844 1843 { 1845 1846 1847 1848 prvs.mViewCell = currentViewCell;1849 return;1850 1851 1852 1853 1854 1855 { 1856 1857 1858 1859 1860 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 1862 1861 } 1863 1864 { 1865 1866 1862 else 1863 { 1864 prvs.mViewCell = NULL; 1865 //prvs.mPvs = root->GetPvs(); 1867 1866 } 1868 1867 } … … 4077 4076 4078 4077 ////////// 4079 //-- some view cells for output4078 //-- export visualizations of some view cells 4080 4079 4081 4080 ViewCell::NewMail(); … … 4116 4115 for (vit = leaves.begin(); vit != vit_end; ++ vit) 4117 4116 { 4118 // prepare some rays for output4117 // prepare some rays for visualization 4119 4118 VssRayContainer::const_iterator rit, rit_end = (*vit)->GetOrCreateRays()->end(); 4120 4119 for (rit = (*vit)->GetOrCreateRays()->begin(); rit != rit_end; ++ rit) … … 4126 4125 const int raysOut = min((int)collectRays.size(), maxRays); 4127 4126 4128 // prepare some rays for output4127 // prepare some rays for visualization 4129 4128 VssRayContainer::const_iterator rit, rit_end = collectRays.end(); 4130 4129 for (rit = collectRays.begin(); rit != rit_end; ++ rit) … … 4381 4380 OUT_STREAM stream(filename.c_str()); 4382 4381 4383 // for outputwe need unique ids for each view cell4382 // we need unique ids for each view cell 4384 4383 CreateUniqueViewCellIds(); 4385 4384 … … 4611 4610 ViewCell::NewMail(); 4612 4611 4613 //-- some rays for output4612 //-- some rays for visualization 4614 4613 const int raysOut = min((int)sampleRays.size(), mVisualizationSamples); 4615 4614 Debug << "visualization using " << raysOut << " samples" << endl; 4616 4615 4617 //-- some random view cells and rays for output4616 //-- some random view cells and rays for visualization 4618 4617 vector<KdLeaf *> kdLeaves; 4619 4618 … … 5400 5399 5401 5400 ////////// 5402 //-- some view cells for output5401 //-- export some view cells for visualization 5403 5402 5404 5403 ViewCell::NewMail(); … … 5453 5452 const int raysOut = min((int)collectRays.size(), maxRays); 5454 5453 5455 // prepare some rays for output5454 // prepare some rays for visualization 5456 5455 VssRayContainer::const_iterator rit, rit_end = collectRays.end(); 5457 5456 for (rit = collectRays.begin(); rit != rit_end; ++ rit) … … 5483 5482 { 5484 5483 Intersectable::NewMail(); 5485 5486 5484 ObjectPvsIterator pit = pvs.GetIterator(); 5487 5485 … … 6585 6583 OUT_STREAM stream(filename.c_str()); 6586 6584 6587 // for outputwe need unique ids for each view cell6585 // we need unique ids for each view cell 6588 6586 CreateUniqueViewCellIds(); 6589 6587 … … 6600 6598 { 6601 6599 stream << "<BoundingBoxes>" << endl; 6600 6601 int id = 0; 6602 6602 6603 vector<KdIntersectable *>::const_iterator kit, kit_end = mPreprocessor->mKdTree->mKdIntersectables.end(); 6603 6604 int id = 0; 6605 6604 6606 6605 for (kit = mPreprocessor->mKdTree->mKdIntersectables.begin(); kit != kit_end; ++ kit, ++ id) 6607 6606 { … … 6657 6656 } 6658 6657 6658 6659 bool 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 } 6659 6726 6660 6727 … … 6966 7033 ////////// 6967 7034 // compare results 6968 6969 7035 cout << "ray " << i << ": " << (int)tmpRays[i]->mViewCells.size() << " " << (int)packet.mViewCells[i].size() << endl; 6970 7036 } 6971 6972 6973 7037 6974 7038 CLEAR_CONTAINER(tmpRays); 6975 7039 } 6976 7040 } 6977 cout << "=================\nhere6"<<endl; 7041 6978 7042 CLEAR_CONTAINER(tmpRays); 6979 7043 … … 6990 7054 6991 7055 6992 } 7056 7057 ViewCellsManager *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.