Changeset 1563 for GTP/trunk/Lib/Vis/Preprocessing/src
- Timestamp:
- 10/03/06 22:03:58 (18 years ago)
- Location:
- GTP/trunk/Lib/Vis/Preprocessing/src
- Files:
-
- 20 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/Lib/Vis/Preprocessing/src/BvHierarchy.cpp
r1551 r1563 892 892 int nObjectsLeft = 0; 893 893 const int nTotalObjects = (int)tData.mNode->mObjects.size(); 894 const float viewSpaceVol = m HierarchyManager->GetViewSpaceBox().GetVolume();894 const float viewSpaceVol = mViewCellsManager->GetViewSpaceBox().GetVolume(); 895 895 896 896 SortableEntryContainer::const_iterator backObjectsStart = mSubdivisionCandidates->begin(); … … 1294 1294 const float area = box.SurfaceArea(); 1295 1295 1296 return (float)objects.size() * area / m HierarchyManager->GetViewSpaceBox().SurfaceArea();1296 return (float)objects.size() * area / mViewCellsManager->GetViewSpaceBox().SurfaceArea(); 1297 1297 } 1298 1298 else … … 1300 1300 //-- render cost heuristics 1301 1301 1302 const float viewSpaceVol = m HierarchyManager->GetViewSpaceBox().GetVolume();1302 const float viewSpaceVol = mViewCellsManager->GetViewSpaceBox().GetVolume(); 1303 1303 // probability that view point lies in a view cell which sees this node 1304 1304 const float p = EvalViewCellsVolume(objects) / viewSpaceVol; … … 1712 1712 bvhLeaf->SetSubdivisionCandidate(oSubdivisionCandidate); 1713 1713 1714 const float viewSpaceVol = m HierarchyManager->GetViewSpaceBox().GetVolume();1714 const float viewSpaceVol = mViewCellsManager->GetViewSpaceBox().GetVolume(); 1715 1715 mTotalCost = (float)objects.size() * prop / viewSpaceVol; 1716 1716 … … 1822 1822 bvhLeaf->SetSubdivisionCandidate(oSubdivisionCandidate); 1823 1823 1824 const float viewSpaceVol = m HierarchyManager->GetViewSpaceBox().GetVolume();1824 const float viewSpaceVol = mViewCellsManager->GetViewSpaceBox().GetVolume(); 1825 1825 mTotalCost = (float)objects.size() * prop / viewSpaceVol; 1826 1826 -
GTP/trunk/Lib/Vis/Preprocessing/src/GvsPreprocessor.cpp
r1551 r1563 184 184 SimpleRay sray(oldRay.mOrigin, p - oldRay.mOrigin); 185 185 186 VssRay *newRay = mRayCaster->CastRay(sray, mView SpaceBox, false);186 VssRay *newRay = mRayCaster->CastRay(sray, mViewCellsManager->GetViewSpaceBox(), false); 187 187 //cout << "\np1: " << p1 << "\np : " << p << "\np2: " << p2 << endl; 188 188 if (!newRay) return 0; … … 293 293 const VssRay &oldRay) 294 294 { 295 cout << "r";296 295 ++ mReverseSamples; 297 296 … … 393 392 const long startTime = GetTime(); 394 393 395 mViewSpaceBox = mKdTree->GetBox();396 394 Randomize(0); 397 395 … … 406 404 407 405 if (!mLoadViewCells) 408 { /// construct the view cells from the scratch 409 ConstructViewCells(mViewSpaceBox); 410 cout << "view cells loaded" << endl; 406 { 407 /// construct the view cells from the scratch 408 ConstructViewCells(); 409 cout << "finished view cell construction" << endl; 411 410 } 412 411 else if (1) 413 { cout << "here2255566" << endl;412 { 414 413 //-- load view cells from file 415 414 //-- test successful view cells loading by exporting them again 416 415 VssRayContainer dummies; 417 416 mViewCellsManager->Visualize(mObjects, dummies); 418 mViewCellsManager->ExportViewCells("test.xml. zip", mViewCellsManager->GetExportPvs(), mObjects);417 mViewCellsManager->ExportViewCells("test.xml.gz", mViewCellsManager->GetExportPvs(), mObjects); 419 418 } 420 419 -
GTP/trunk/Lib/Vis/Preprocessing/src/GvsPreprocessor.h
r1545 r1563 128 128 int mSamplingType; 129 129 130 AxisAlignedBox3 mViewSpaceBox;130 //AxisAlignedBox3 mViewSpaceBox; 131 131 float mEps; 132 132 float mThreshold; -
GTP/trunk/Lib/Vis/Preprocessing/src/GzBinFileInputStream.h
r1294 r1563 134 134 inline bool GzBinFileInputStream::getIsOpen() const 135 135 { 136 return bool (mStream.is_open());//(fSource != 0);136 return mStream.is_open() != 0;//(fSource != 0); 137 137 } 138 138 -
GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.cpp
r1557 r1563 163 163 } 164 164 165 165 /* 166 166 AxisAlignedBox3 HierarchyManager::GetViewSpaceBox() const 167 167 { 168 168 return mVspTree->mBoundingBox; 169 } 169 }*/ 170 170 171 171 … … 312 312 cout << "\nfinished in " << TimeDiff(startTime, GetTime()) * 1e-3 << " secs" << endl; 313 313 314 #if _DEBUG314 /*#if _DEBUG 315 315 cout << "view space: " << GetViewSpaceBox() << endl; 316 316 cout << "object space: " << GetObjectSpaceBox() << endl; 317 #endif 317 #endif*/ 318 318 319 319 mObjectSpaceSubdivisionType = mSavedObjectSpaceSubdivisionType; … … 709 709 cout << "\nfinished in " << TimeDiff(startTime, GetTime()) * 1e-3 << " secs" << endl; 710 710 711 #if _DEBUG711 /*#if _DEBUG 712 712 cout << "view space: " << GetViewSpaceBox() << endl; 713 713 cout << "object space: " << GetObjectSpaceBox() << endl; 714 #endif 714 #endif*/ 715 715 716 716 mHierarchyStats.Stop(); -
GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.h
r1557 r1563 195 195 /** Returns view space bounding box. 196 196 */ 197 AxisAlignedBox3 GetViewSpaceBox() const;197 //AxisAlignedBox3 GetViewSpaceBox() const; 198 198 /** Returns object space bounding box. 199 199 */ -
GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.cpp
r1545 r1563 422 422 /////// 423 423 //-- parse view cells construction method 424 424 425 Environment::GetSingleton()->GetBoolValue("ViewCells.loadFromFile", mLoadViewCells); 425 426 char buf[100]; … … 429 430 Environment::GetSingleton()->GetStringValue("ViewCells.filename", buf); 430 431 cout << "loading view cells from " << buf << endl; 432 431 433 mViewCellsManager = ViewCellsManager::LoadViewCells(buf, &mObjects, true); 434 432 435 if (!mViewCellsManager) 433 436 return false; … … 440 443 441 444 // default view space is the extent of the scene 442 mViewCellsManager->SetViewSpaceBox(mSceneGraph->GetBox()); 443 445 AxisAlignedBox3 box = mSceneGraph->GetBox(); 446 447 if (0) 448 { 449 // use a small box outside of the scene 450 box.Scale(Vector3(0.1f,0.5f,0.5f)); 451 box.Translate(Vector3(Magnitude(mSceneGraph->GetBox().Size())*0.5f, 0, 0)); 452 } 453 454 mViewCellsManager->SetViewSpaceBox(box); 455 444 456 bool loadVcGeometry; 445 457 Environment::GetSingleton()->GetBoolValue("ViewCells.loadGeometry", loadVcGeometry); … … 492 504 493 505 494 bool Preprocessor::ConstructViewCells(const AxisAlignedBox3 &viewSpaceBox) 495 { 496 mViewCellsManager->SetViewSpaceBox(viewSpaceBox); 497 506 bool Preprocessor::ConstructViewCells() 507 { 498 508 // construct view cells using it's own set of samples 499 509 mViewCellsManager->Construct(this); -
GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.h
r1545 r1563 92 92 /** Construct viewcells from the scratch 93 93 */ 94 bool ConstructViewCells( const AxisAlignedBox3 &viewSpaceBox);94 bool ConstructViewCells(); 95 95 96 96 /** Returns the specified sample strategy, NULL if no valid strategy. -
GTP/trunk/Lib/Vis/Preprocessing/src/RssPreprocessor.cpp
r1520 r1563 283 283 exporter->SetWireframe(); 284 284 285 if (1 || mViewSpaceBox) {285 if (1) { 286 286 exporter->SetForcedMaterial(RgbColor(1,0,1)); 287 287 exporter->ExportBox(mViewCellsManager->GetViewSpaceBox()); … … 321 321 exporter->SetWireframe(); 322 322 323 if (1 || mViewSpaceBox) {323 if (1) { 324 324 exporter->SetForcedMaterial(RgbColor(1,0,1)); 325 325 exporter->ExportBox(mViewCellsManager->GetViewSpaceBox()); … … 361 361 exporter->SetWireframe(); 362 362 exporter->ExportKdTree(*mKdTree); 363 364 if (mViewSpaceBox) {365 exporter->SetForcedMaterial(RgbColor(1,0,0));366 exporter->ExportBox(*mViewSpaceBox);367 exporter->ResetForcedMaterial();368 }369 363 370 364 exporter->SetForcedMaterial(RgbColor(0,0,1)); … … 510 504 int totalSamples = 0; 511 505 512 mViewSpaceBox = NULL;513 514 506 // if not already loaded, construct view cells from file 515 507 if (!mLoadViewCells) 516 508 { 517 if (1) 518 mViewCellsManager->SetViewSpaceBox(mKdTree->GetBox()); 519 else { 520 AxisAlignedBox3 box = mKdTree->GetBox(); 521 522 if (1) { 523 // use a small box outside of the scene 524 box.Scale(Vector3(0.1f,0.5f,0.5f)); 525 box.Translate(Vector3(Magnitude(mKdTree->GetBox().Size())*0.5f, 0, 0)); 526 } else { 527 float s = box.Size(0); 528 box.Scale(0.1f); 529 box.SetMin(0, box.Min(0) + s); 530 box.SetMax(0, box.Max(0) + s); 531 } 532 533 mViewCellsManager->SetViewSpaceBox(box); 534 } 535 536 // construct view cells using it's own set of samples 537 mViewCellsManager->Construct(this); 538 539 //-- several visualizations and statistics 540 Debug << "view cells construction finished: " << endl; 541 mViewCellsManager->PrintStatistics(Debug); 542 } 543 509 // construct view cells using it's own set of samples 510 mViewCellsManager->Construct(this); 511 512 //-- several visualizations and statistics 513 Debug << "view cells construction finished: " << endl; 514 mViewCellsManager->PrintStatistics(Debug); 515 } 516 544 517 545 518 int rssPass = 0; -
GTP/trunk/Lib/Vis/Preprocessing/src/RssPreprocessor.h
r1281 r1563 38 38 bool mDirectionalSampling; 39 39 40 AxisAlignedBox3 *mViewSpaceBox;40 //AxisAlignedBox3 *mViewSpaceBox; 41 41 42 42 ofstream mStats; -
GTP/trunk/Lib/Vis/Preprocessing/src/RssTree.cpp
r1548 r1563 348 348 } else { 349 349 mRoots.resize(1); 350 RssTreeLeaf *leaf = new RssTreeLeaf(NULL, rays.size());350 RssTreeLeaf *leaf = new RssTreeLeaf(NULL, (int)rays.size()); 351 351 leaf->bbox.Initialize(); 352 352 leaf->dirBBox.Initialize(); … … 1897 1897 } 1898 1898 1899 return rays.size();1899 return (int)rays.size(); 1900 1900 } 1901 1901 -
GTP/trunk/Lib/Vis/Preprocessing/src/SamplingPreprocessor.cpp
r1520 r1563 118 118 119 119 Randomize(0); 120 121 long startTime = GetTime(); 122 120 const long startTime = GetTime(); 123 121 int totalSamples = 0; 124 122 … … 126 124 if (!mLoadViewCells) 127 125 { 128 ConstructViewCells(mKdTree->GetBox()); 129 } 130 131 132 126 ConstructViewCells(); 127 } 128 133 129 int samples = 0; 134 130 int i=0; -
GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellBsp.cpp
r1558 r1563 171 171 mTimeStamp(1), 172 172 mViewCellsTree(NULL), 173 mOutOfBoundsCellPartOfTree(false) 173 mOutOfBoundsCellPartOfTree(false), 174 mOutOfBoundsCell(NULL) 174 175 { 175 176 Randomize(); // initialise random generator for heuristics … … 956 957 { 957 958 tData = tStack.top(); 958 959 959 tStack.pop(); 960 960 … … 1010 1010 if (!mUsePredefinedViewCells) 1011 1011 { // generate new view cell for each leaf 1012 viewCell = new BspViewCell(); 1012 viewCell = new BspViewCell();cout << "g"; 1013 1013 } 1014 1014 else 1015 { 1015 { 1016 1016 // add predefined view cell to leaf 1017 1017 viewCell = dynamic_cast<BspViewCell *>(tData.mViewCell); 1018 1019 1018 // from now on out of bounds cell can be handled as any other cell, 1020 1019 // responsibility for deleting has been shifted 1021 if ( viewCell == mOutOfBoundsCell)1020 if (IsOutOfBounds(viewCell)) 1022 1021 { 1023 1022 mOutOfBoundsCellPartOfTree = true; 1024 1023 } 1024 1025 1025 } 1026 1026 … … 1035 1035 else 1036 1036 viewCell->SetVolume(probability); 1037 1038 1037 1039 1038 /////////// … … 1049 1048 } 1050 1049 1051 if (1)EvaluateLeafStats(tData); 1052 1053 1050 if (1) EvaluateLeafStats(tData); 1051 1054 1052 //////// 1055 1053 //-- clean up … … 2399 2397 { 2400 2398 // per definition out of bounds cell has zero volume 2401 if ( (*it) == mOutOfBoundsCell)2399 if (IsOutOfBounds(*it)) 2402 2400 continue; 2403 2401 … … 3325 3323 ViewCell *BspTree::GetViewCell(const Vector3 &point) 3326 3324 { 3327 if (mRoot == NULL) 3328 return NULL; 3329 3330 3331 stack<BspNode *> nodeStack; 3332 nodeStack.push(mRoot); 3333 3334 ViewCellLeaf *viewcell = NULL; 3335 3336 while (!nodeStack.empty()) { 3337 BspNode *node = nodeStack.top(); 3338 nodeStack.pop(); 3339 3340 if (node->IsLeaf()) { 3341 viewcell = dynamic_cast<BspLeaf *>(node)->mViewCell; 3342 break; 3343 } else { 3344 3345 BspInterior *interior = dynamic_cast<BspInterior *>(node); 3346 3347 // random decision 3348 if (interior->GetPlane().Side(point) < 0) 3349 nodeStack.push(interior->GetBack()); 3350 else 3351 nodeStack.push(interior->GetFront()); 3352 } 3353 } 3354 3355 return viewcell; 3325 if (mRoot == NULL) 3326 return NULL; 3327 3328 stack<BspNode *> nodeStack; 3329 nodeStack.push(mRoot); 3330 3331 ViewCellLeaf *viewcell = NULL; 3332 3333 while (!nodeStack.empty()) { 3334 BspNode *node = nodeStack.top(); 3335 nodeStack.pop(); 3336 3337 if (node->IsLeaf()) 3338 { 3339 viewcell = dynamic_cast<BspLeaf *>(node)->mViewCell; 3340 break; 3341 } 3342 else 3343 { 3344 3345 BspInterior *interior = dynamic_cast<BspInterior *>(node); 3346 3347 // random decision 3348 if (interior->GetPlane().Side(point) < 0) 3349 { 3350 nodeStack.push(interior->GetBack()); 3351 } 3352 else 3353 { 3354 nodeStack.push(interior->GetFront()); 3355 } 3356 } 3357 } 3358 3359 return viewcell; 3356 3360 } 3357 3361 -
GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellBsp.h
r1558 r1563 625 625 int _CastRay(Ray &ray); 626 626 627 /** Casts line segment between origin and termination and returns 628 view cells which are touched by the line. 629 */ 627 630 int CastLineSegment(const Vector3 &origin, 628 631 const Vector3 &termination, … … 630 633 ); 631 634 635 /** Returns view cell this point is located in. 636 */ 632 637 ViewCell *GetViewCell(const Vector3 &point); 633 638 … … 665 670 */ 666 671 BspLeaf *GetRandomLeaf(const bool onlyUnmailed = false); 667 668 672 669 673 /** Returns epsilon of this tree. -
GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp
r1557 r1563 233 233 Mesh *m = vc->GetMesh(); 234 234 235 if (m) { 236 m->ComputeBoundingBox(); 237 return m->mBox; 235 if (m) 236 { 237 m->ComputeBoundingBox(); 238 return m->mBox; 238 239 } 239 240 240 241 AxisAlignedBox3 box; 241 242 242 box.Initialize(); 243 243 … … 289 289 { 290 290 VssRayContainer::const_iterator it, it_end = rays.end(); 291 292 291 for (it = rays.begin(); it != it_end; ++ it) 293 292 { … … 298 297 { 299 298 VssRayContainer::const_iterator it, it_end = rays.end(); 300 301 299 for (it = rays.begin(); it != it_end; ++ it) 302 300 { 303 //(*it)->Unref();304 301 if (!(*it)->IsActive()) 305 302 delete (*it); … … 322 319 mPreprocessor = preprocessor; 323 320 324 321 325 322 /////////////////////////////////////////////////////// 326 323 //-- Initial sampling for the construction of the view cell hierarchy. … … 361 358 { 362 359 //-- export initial view cell partition 363 Debug << "\nView cells after initial sampling:\n" 364 << mCurrentViewCellsStats << endl; 360 Debug << "\nView cells after initial sampling:\n" << mCurrentViewCellsStats << endl; 365 361 366 362 const string filename("viewcells.wrl"); … … 428 424 429 425 430 #if 0 431 ///////////////432 //-- Get stats after the additional sampling step433 //-- and before the bottom-up mergestep434 435 EvaluateViewCellsStats(); 436 Debug << "\noriginal view cell partition before post process:\n"437 << mCurrentViewCellsStats << endl;438 439 mRenderer->RenderScene();440 SimulationStatistics ss;441 dynamic_cast<RenderSimulator *>(mRenderer)->GetStatistics(ss);442 443 Debug << ss << endl; 444 #endif 445 426 if (0) 427 { 428 /////////////// 429 //-- Get stats after the additional sampling step 430 //-- and before the bottom-up merge step 431 432 EvaluateViewCellsStats(); 433 Debug << "\noriginal view cell partition before post process:\n" 434 << mCurrentViewCellsStats << endl; 435 436 mRenderer->RenderScene(); 437 SimulationStatistics ss; 438 dynamic_cast<RenderSimulator *>(mRenderer)->GetStatistics(ss); 439 440 Debug << ss << endl; 441 } 446 442 447 443 //////////////////// … … 612 608 { 613 609 ViewCellsParser parser; 614 615 610 ViewCellsManager *vm = NULL; 616 611 617 612 if (parser.ParseViewCellsFile(filename, &vm, objects, bconverter)) 618 613 { 619 long startTime = GetTime();614 const long startTime = GetTime(); 620 615 621 616 vm->ResetViewCells(); … … 671 666 for (oit = objects.begin(); oit != oit_end; ++ oit) 672 667 { 673 MeshInstance *mi = dynamic_cast<MeshInstance *>(*oit); 674 const AxisAlignedBox3 box = mi->GetBox(); 668 const AxisAlignedBox3 box = (*oit)->GetBox(); 675 669 676 670 //////////// 677 671 //-- the bounding boxes 678 stream << "<BoundingBox" << " id=\"" << mi->GetId() << "\""672 stream << "<BoundingBox" << " id=\"" << (*oit)->GetId() << "\"" 679 673 << " min=\"" << box.Min().x << " " << box.Min().y << " " << box.Min().z << "\"" 680 674 << " max=\"" << box.Max().x << " " << box.Max().y << " " << box.Max().z << "\" />" << endl; … … 1262 1256 const bool extrudeBaseTriangles) 1263 1257 { 1264 bool success;1265 1266 1258 /// we use predefined view cells from now on 1267 1259 mUsePredefinedViewCells = true; … … 1271 1263 { 1272 1264 Environment::GetSingleton()->GetFloatValue("ViewCells.height", parser.mViewCellHeight); 1273 success = parser.ParseFile(filename, *this); 1265 const bool success = parser.ParseFile(filename, *this); 1266 1267 if (!success) 1268 return false; 1274 1269 } 1275 1270 else … … 1277 1272 // hack: use standard mesh loading 1278 1273 // create temporary scene graph for loading the view cells geometry 1274 // note: delete the meshes as they are created two times for transformed mesh instances. 1279 1275 SceneGraphNode *root = new SceneGraphNode(); 1280 success = parser.ParseFile(filename, root, true); 1281 1282 if (success) 1283 { 1284 ObjectContainer::const_iterator oit, oit_end = root->mGeometry.end(); 1285 for (oit = root->mGeometry.begin(); oit != oit_end; ++ oit) 1276 const bool success = parser.ParseFile(filename, root, true); 1277 1278 if (!success) 1279 { 1280 DEL_PTR(root); 1281 return false; 1282 } 1283 1284 ObjectContainer::const_iterator oit, oit_end = root->mGeometry.end(); 1285 1286 for (oit = root->mGeometry.begin(); oit != oit_end; ++ oit) 1287 { 1288 Mesh *mesh; 1289 if ((*oit)->Type() == Intersectable::TRANSFORMED_MESH_INSTANCE) 1286 1290 { 1287 if ((*oit)->Type() == Intersectable::TRANSFORMED_MESH_INSTANCE) 1288 { 1289 TransformedMeshInstance *mit = dynamic_cast<TransformedMeshInstance *>(*oit); 1290 Mesh *mesh = MeshManager::GetSingleton()->CreateResource(); 1291 mit->GetTransformedMesh(*mesh); 1292 mesh->ComputeBoundingBox(); 1293 mViewCells.push_back(GenerateViewCell(mesh)); 1294 } 1295 else if ((*oit)->Type() == Intersectable::MESH_INSTANCE) 1296 { 1297 MeshInstance *mit = dynamic_cast<MeshInstance *>(*oit); 1298 mViewCells.push_back(GenerateViewCell(mit->GetMesh())); 1299 } 1291 TransformedMeshInstance *mit = dynamic_cast<TransformedMeshInstance *>(*oit); 1292 mesh = MeshManager::GetSingleton()->CreateResource(); 1293 mit->GetTransformedMesh(*mesh); 1300 1294 } 1301 } 1295 else if ((*oit)->Type() == Intersectable::MESH_INSTANCE) 1296 { 1297 MeshInstance *mit = dynamic_cast<MeshInstance *>(*oit); 1298 mesh = mit->GetMesh(); 1299 } 1300 mesh->ComputeBoundingBox(); 1301 mViewCells.push_back(GenerateViewCell(mesh)); 1302 } 1303 1302 1304 DEL_PTR(root); 1303 1305 } 1304 1306 1305 if (success) 1306 { 1307 // set view space box to bounding box of the view cells 1308 AxisAlignedBox3 bbox; 1309 bbox.Initialize(); 1310 ViewCellContainer::iterator it = mViewCells.begin(), it_end = mViewCells.end(); 1311 for (; it != it_end; ++ it) 1312 { 1313 bbox.Include(GetViewCellBox(*it)); 1314 } 1315 SetViewSpaceBox(bbox); 1316 1317 cout << "generated " << (int)mViewCells.size() << " view cells using the geometry from file " << filename << endl; 1318 } 1319 1320 return success; 1307 // set view space box to bounding box of the view cells 1308 AxisAlignedBox3 bbox; 1309 bbox.Initialize(); 1310 ViewCellContainer::iterator it = mViewCells.begin(), it_end = mViewCells.end(); 1311 1312 for (; it != it_end; ++ it) 1313 { 1314 bbox.Include((*it)->GetMesh()->mBox); 1315 } 1316 1317 SetViewSpaceBox(bbox); 1318 cout << "view space box: " << bbox << endl; 1319 cout << "generated " << (int)mViewCells.size() << " view cells using the geometry " << filename << endl; 1320 1321 return true; 1321 1322 } 1322 1323 … … 2539 2540 VssRayContainer savedRays; 2540 2541 2542 // choose a a number of rays based on the ratio of cast rays / requested rays 2541 2543 const int limit = min(mInitialSamples, (int)rays.size()); 2542 2543 2544 VssRayContainer::const_iterator it, it_end = rays.end(); 2544 2545 2545 2546 const float prop = (float)limit / ((float)rays.size() + Limits::Small); 2546 2547 2547 for (it = rays.begin(); it != it_end; ++ it) 2548 2548 { … … 2785 2785 return; 2786 2786 2787 int savedColorCode = mColorCode;2787 const int savedColorCode = mColorCode; 2788 2788 2789 2789 if (1) // export final view cells … … 2989 2989 const AxisAlignedBox3 *sceneBox, 2990 2990 const AxisAlignedPlane *clipPlane 2991 ) const 2992 { 2993 // out of bounds cell 2994 //if (vc->GetId() == OUT_OF_BOUNDS_ID) return; 2995 2996 // export mesh if available 2997 if (vc->GetMesh()) 2998 { 2999 exporter->ExportMesh(vc->GetMesh()); 3000 return; 3001 } 3002 3003 // otherwise construct from leaves 2991 ) const 2992 { 3004 2993 if (clipPlane) 3005 2994 { … … 3018 3007 mBspTree->ConstructGeometry(*it, geom); 3019 3008 3020 const float eps = 0.000 00001f;3009 const float eps = 0.0001f; 3021 3010 const int cf = geom.Side(plane, eps); 3022 3011 … … 3032 3021 mViewSpaceBox, 3033 3022 eps); 3034 3023 3035 3024 if (back.Valid()) 3036 { 3025 { 3037 3026 exporter->ExportPolygons(back.GetPolys()); 3038 3027 } … … 3042 3031 else 3043 3032 { 3044 BspNodeGeometry geom; 3045 mBspTree->ConstructGeometry(vc, geom); 3046 exporter->ExportPolygons(geom.GetPolys()); 3033 // export mesh if available 3034 // TODO: some bug here? 3035 if (1 && vc->GetMesh()) 3036 { 3037 exporter->ExportMesh(vc->GetMesh()); 3038 } 3039 else 3040 { 3041 BspNodeGeometry geom; 3042 mBspTree->ConstructGeometry(vc, geom); 3043 exporter->ExportPolygons(geom.GetPolys()); 3044 } 3047 3045 } 3048 3046 } … … 3158 3156 for (oit = objects.begin(); oit != oit_end; ++ oit) 3159 3157 { 3160 MeshInstance *mi = dynamic_cast<MeshInstance *>(*oit); 3161 const AxisAlignedBox3 box = mi->GetBox(); 3158 const AxisAlignedBox3 box = (*oit)->GetBox(); 3162 3159 3163 stream << "<BoundingBox" << " id=\"" << mi->GetId() << "\""3160 stream << "<BoundingBox" << " id=\"" << (*oit)->GetId() << "\"" 3164 3161 << " min=\"" << box.Min().x << " " << box.Min().y << " " << box.Min().z << "\"" 3165 3162 << " max=\"" << box.Max().x << " " << box.Max().y << " " << box.Max().z << "\" />" << endl; … … 4123 4120 { 4124 4121 cout << "exporting view cells after post process ... "; 4125 4126 4122 if (0) 4127 { 4128 // export view space box 4123 { // export view space box 4129 4124 exporter->SetWireframe(); 4130 4125 exporter->ExportBox(mViewSpaceBox); … … 4133 4128 4134 4129 Material m; 4135 4136 4130 m.mDiffuseColor.r = 0.0f; 4137 4131 m.mDiffuseColor.g = 0.5f; … … 4140 4134 exporter->SetForcedMaterial(m); 4141 4135 4142 if ( 0&& mExportGeometry)4136 if (1 && mExportGeometry) 4143 4137 { 4144 4138 exporter->ExportGeometry(objects); 4145 4139 } 4146 4140 4147 // export rays4148 4141 if (0 && mExportRays) 4149 4142 { 4150 4143 exporter->ExportRays(visRays, RgbColor(1, 0, 0)); 4151 4144 } 4152 4153 4145 ExportViewCellsForViz(exporter, NULL, GetClipPlane()); 4154 4146 … … 4500 4492 ) const 4501 4493 { 4502 // out of bounds cell4503 //if (vc->GetId() == OUT_OF_BOUNDS_ID) return;4504 4494 if (clipPlane) 4505 4495 { … … 4513 4503 { 4514 4504 BspNodeGeometry geom; 4515 4516 4505 BspNodeGeometry front; 4517 4506 BspNodeGeometry back; … … 4545 4534 // export mesh if available 4546 4535 // TODO: some bug here? 4547 if ( 0&& vc->GetMesh())4536 if (1 && vc->GetMesh()) 4548 4537 { 4549 4538 exporter->ExportMesh(vc->GetMesh()); … … 5070 5059 5071 5060 // matt: hack for clamping scene 5072 AxisAlignedBox3 bbox = m HierarchyManager->GetViewSpaceBox();5061 AxisAlignedBox3 bbox = mViewSpaceBox; 5073 5062 bbox.Scale(Vector3(0.5, 1, 0.5)); 5074 5063 if (CLAMP_TO_BOX) -
GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsParser.cpp
r1558 r1563 850 850 851 851 // set view space box 852 mVspBspTree->mBo x = mViewSpaceBox;852 mVspBspTree->mBoundingBox = mViewSpaceBox; 853 853 854 854 ViewCellsMap::iterator vit, vit_end = mViewCells.end(); -
GTP/trunk/Lib/Vis/Preprocessing/src/VspBspTree.cpp
r1558 r1563 277 277 if (mesh) 278 278 { // // copy the mesh into polygons and add to BSP tree aabb 279 mBo x.Include(viewCells[i]->GetBox());279 mBoundingBox.Include(viewCells[i]->GetBox()); 280 280 polysSize += AddMeshToPolygons(mesh, 281 281 polys, … … 326 326 if (mesh) // copy the mesh data to polygons 327 327 { 328 mBo x.Include(object->GetBox()); // add to BSP tree aabb328 mBoundingBox.Include(object->GetBox()); // add to BSP tree aabb 329 329 AddMeshToPolygons(mesh, polys, NULL); 330 330 … … 344 344 if (forcedBoundingBox) 345 345 { 346 mBo x = *forcedBoundingBox;346 mBoundingBox = *forcedBoundingBox; 347 347 } 348 348 else // compute vsp tree bounding box 349 349 { 350 mBo x.Initialize();350 mBoundingBox.Initialize(); 351 351 352 352 VssRayContainer::const_iterator rit, rit_end = sampleRays.end(); … … 358 358 359 359 // compute bounding box of view space 360 mBo x.Include(ray->GetTermination());361 mBo x.Include(ray->GetOrigin());360 mBoundingBox.Include(ray->GetTermination()); 361 mBoundingBox.Include(ray->GetOrigin()); 362 362 } 363 363 } … … 393 393 Intersectable *obj = ray->mTerminationObject; 394 394 395 if ((mBo x.IsInside(ray->mTermination) || !forcedBoundingBox) &&395 if ((mBoundingBox.IsInside(ray->mTermination) || !forcedBoundingBox) && 396 396 obj && !obj->Mailed()) 397 397 { … … 419 419 //-- compute bounding box 420 420 if (!forcedBoundingBox) 421 mBo x.Include(ray->mTermination);422 } 423 424 if ((mBo x.IsInside(ray->mOrigin) || !forcedBoundingBox) &&421 mBoundingBox.Include(ray->mTermination); 422 } 423 424 if ((mBoundingBox.IsInside(ray->mOrigin) || !forcedBoundingBox) && 425 425 ray->mOriginObject && 426 426 !ray->mOriginObject->Mailed()) … … 460 460 461 461 // TODO: not very efficient to implictly cast between rays types 462 if (mBo x.GetRaySegment(hray, minT, maxT))462 if (mBoundingBox.GetRaySegment(hray, minT, maxT)) 463 463 { 464 464 float len = ray->Length(); … … 473 473 // normalize 474 474 if (mUseAreaForPvs) 475 mTermMinProbability *= mBo x.SurfaceArea();475 mTermMinProbability *= mBoundingBox.SurfaceArea(); 476 476 else 477 mTermMinProbability *= mBo x.GetVolume();477 mTermMinProbability *= mBoundingBox.GetVolume(); 478 478 479 479 … … 547 547 548 548 549 mTotalCost = tData.mPvs * tData.mProbability / mBo x.GetVolume();549 mTotalCost = tData.mPvs * tData.mProbability / mBoundingBox.GetVolume(); 550 550 mTotalPvsSize = tData.mPvs; 551 551 … … 652 652 tQueue.push(splitCandidate); 653 653 654 mTotalCost = tData.mPvs * tData.mProbability / mBo x.GetVolume();654 mTotalCost = tData.mPvs * tData.mProbability / mBoundingBox.GetVolume(); 655 655 mTotalPvsSize = tData.mPvs; 656 656 … … 948 948 949 949 float costDecr = 950 (cFront + cBack - cData) / mBo x.GetVolume();950 (cFront + cBack - cData) / mBoundingBox.GetVolume(); 951 951 952 952 mTotalCost += costDecr; … … 1109 1109 1110 1110 const float costDecr = 1111 (cFront + cBack - cData) / mBo x.GetVolume();1111 (cFront + cBack - cData) / mBoundingBox.GetVolume(); 1112 1112 1113 1113 mTotalCost += costDecr; … … 1162 1162 *backData.mGeometry, 1163 1163 splitPlane, 1164 mBo x,1164 mBoundingBox, 1165 1165 //0.0f); 1166 1166 mEpsilon); … … 2003 2003 geomBack, 2004 2004 candidatePlane, 2005 mBo x,2005 mBoundingBox, 2006 2006 //0.0f); 2007 2007 mEpsilon); … … 2041 2041 const float newRenderCost = penaltyFront * pFront + penaltyBack * pBack; 2042 2042 2043 const float renderCostDecrease = (oldRenderCost - newRenderCost) / mBo x.GetVolume();2043 const float renderCostDecrease = (oldRenderCost - newRenderCost) / mBoundingBox.GetVolume(); 2044 2044 2045 2045 // take render cost of node into account to avoid being stuck in a local minimum 2046 normalizedOldRenderCost = oldRenderCost / mBo x.GetVolume();2046 normalizedOldRenderCost = oldRenderCost / mBoundingBox.GetVolume(); 2047 2047 2048 2048 return renderCostDecrease; … … 2108 2108 geomBack, 2109 2109 candidatePlane, 2110 mBo x,2110 mBoundingBox, 2111 2111 //0.0f); 2112 2112 mEpsilon); … … 2236 2236 *secondGeom, 2237 2237 interior->GetPlane(), 2238 mBo x,2238 mBoundingBox, 2239 2239 //0.0000001f); 2240 2240 mEpsilon); … … 2427 2427 AxisAlignedBox3 VspBspTree::GetBoundingBox() const 2428 2428 { 2429 return mBo x;2429 return mBoundingBox; 2430 2430 } 2431 2431 … … 2500 2500 float maxt, mint; 2501 2501 2502 if (!mBo x.GetRaySegment(ray, mint, maxt))2502 if (!mBoundingBox.GetRaySegment(ray, mint, maxt)) 2503 2503 return 0; 2504 2504 … … 2761 2761 PolygonContainer boxPolys; 2762 2762 2763 mBo x.ExtractPolys(boxPolys);2763 mBoundingBox.ExtractPolys(boxPolys); 2764 2764 vector<Plane3> boxPlanes; 2765 2765 … … 2930 2930 2931 2931 for (int j = 0; j < 4; ++ j) 2932 vertices.push_back(mBox.GetFace(i).mVertices[j]); 2932 { 2933 vertices.push_back(mBoundingBox.GetFace(i).mVertices[j]); 2934 } 2933 2935 2934 2936 Polygon3 *poly = new Polygon3(vertices); … … 2967 2969 2968 2970 if (backPoly->Valid(mEpsilon)) 2971 { 2969 2972 candidatePolys[i] = backPoly; 2973 } 2970 2974 else 2975 { 2971 2976 DEL_PTR(backPoly); 2977 } 2972 2978 2973 2979 // outside, don't need this 2974 2980 DEL_PTR(frontPoly); 2975 2981 break; 2982 2976 2983 // polygon outside of halfspace 2977 2984 case Polygon3::FRONT_SIDE: 2978 2985 DEL_PTR(candidatePolys[i]); 2979 2986 break; 2987 2980 2988 // just take polygon as it is 2981 2989 case Polygon3::BACK_SIDE: … … 2989 2997 { 2990 2998 geom.Add(candidatePolys[i], candidatePlanes[i]); 2991 // geom.mPolys.push_back(candidates[i]); 2992 } 2993 } 2999 } 3000 } 3001 } 3002 3003 3004 bool VspBspTree::IsOutOfBounds(ViewCell *vc) const 3005 { 3006 return vc->GetId() == OUT_OF_BOUNDS_ID; 3007 } 3008 3009 3010 void VspBspTree::SetViewCellsTree(ViewCellsTree *viewCellsTree) 3011 { 3012 mViewCellsTree = viewCellsTree; 2994 3013 } 2995 3014 … … 3009 3028 for (it = leaves.begin(); it != it_end; ++ it) 3010 3029 { 3011 if ( (*it) == mOutOfBoundsCell)3030 if (IsOutOfBounds(*it)) 3012 3031 continue; 3013 3032 … … 3120 3139 *bGeom, 3121 3140 interior->GetPlane(), 3122 mBo x,3141 mBoundingBox, 3123 3142 //0.0000001f); 3124 3143 eps); … … 3214 3233 *bGeom, 3215 3234 interior->GetPlane(), 3216 mBo x,3235 mBoundingBox, 3217 3236 //0.0000001f); 3218 3237 eps); … … 3709 3728 *secondGeom, 3710 3729 interior->GetPlane(), 3711 mBo x,3730 mBoundingBox, 3712 3731 //0.0000001f); 3713 3732 mEpsilon); -
GTP/trunk/Lib/Vis/Preprocessing/src/VspBspTree.h
r1545 r1563 356 356 int ComputeBoxIntersections(const AxisAlignedBox3 &box, ViewCellContainer &viewCells) const; 357 357 358 /// pointer to the hierarchy of view cells 359 ViewCellsTree *mViewCellsTree; 360 358 /** Pointer to the view cells tree. 359 */ 360 void SetViewCellsTree(ViewCellsTree *vct); 361 362 /** Returns true if this view cell prepresents 363 invalid view space. 364 */ 365 bool IsOutOfBounds(ViewCell *vc) const; 366 367 361 368 362 369 protected: … … 736 743 737 744 /// box around the whole view domain 738 AxisAlignedBox3 mBox; 739 740 745 AxisAlignedBox3 mBoundingBox; 746 747 /// pointer to the hierarchy of view cells 748 ViewCellsTree *mViewCellsTree; 749 750 741 751 //-- termination critera 742 752 -
GTP/trunk/Lib/Vis/Preprocessing/src/VssPreprocessor.cpp
r1528 r1563 40 40 41 41 useViewspacePlane = mUseViewSpaceBox; //hack 42 43 mViewSpaceBox.Initialize();44 42 45 43 Debug << "*********** vss preprocessor options **************" << endl; … … 158 156 159 157 exporter->SetForcedMaterial(RgbColor(1,0,1)); 160 exporter->ExportBox(mView SpaceBox);158 exporter->ExportBox(mViewCellsManager->GetViewSpaceBox()); 161 159 exporter->ResetForcedMaterial(); 162 160 … … 201 199 202 200 exporter->SetForcedMaterial(RgbColor(1,0,0)); 203 exporter->ExportBox(mView SpaceBox);201 exporter->ExportBox(mViewCellsManager->GetViewSpaceBox()); 204 202 exporter->ResetForcedMaterial(); 205 203 … … 373 371 Debug << "type: vss" << endl; 374 372 375 long startTime = GetTime(); 376 377 int totalSamples = 0; 378 379 380 AxisAlignedBox3 box(mKdTree->GetBox()); 381 382 if (!useViewspacePlane) { 383 float size = 0.05f; 384 float s = 0.5f - size; 385 float olds = Magnitude(box.Size()); 386 box.Enlarge(box.Size()*Vector3(-s)); 387 Vector3 translation = Vector3(-olds*0.1f, 0, 0); 388 box.SetMin(box.Min() + translation); 389 box.SetMax(box.Max() + translation); 390 } else { 391 392 // sample city like heights 393 box.SetMin(1, box.Min(1) + box.Size(1)*0.2f); 394 box.SetMax(1, box.Min(1) + box.Size(1)*0.3f); 395 } 396 397 if (use2dSampling) 398 box.SetMax(1, box.Min(1)); 399 400 cout << "use view space box=" << mUseViewSpaceBox << endl; 401 402 403 if (mUseViewSpaceBox) 404 { 405 if (!mEnlargeViewSpace) 406 { 407 mViewSpaceBox = AxisAlignedBox3(box); 408 } 409 else 410 { 411 mViewSpaceBox = AxisAlignedBox3(mKdTree->GetBox()); 412 413 if (0) 414 { 415 // HACK: enlarge in y directon 416 Vector3 size = mViewSpaceBox.Size(); 417 418 size[1] *= 1.25; 419 Vector3 enlarge(size[0] * 0.25f, size[1] * 0.0f, size[2] * 0.25f); 420 //Vector3 enlarge(size[0] * 4.0f, 0.0f, 0.0f); 421 422 mViewSpaceBox.Enlarge(enlarge); 423 mViewSpaceBox.SetMax(mViewSpaceBox.Max() + enlarge); 424 } 425 else 426 { 427 AxisAlignedBox3 tbox(mViewSpaceBox); 428 429 Vector3 size = mViewSpaceBox.Size(); 430 tbox.SetMax(0, mViewSpaceBox.Max(0) + size[0] * 0.5f); 431 tbox.SetMin(0, mViewSpaceBox.Min(0) + size[0]); 432 mViewSpaceBox = tbox; 433 } 434 } 435 } 436 else 437 { 438 mViewSpaceBox = AxisAlignedBox3(mKdTree->GetBox()); 439 } 440 441 mSceneGraph->CollectObjects(&mObjects); 442 443 if (!mLoadViewCells) 444 { 445 //-- generate new view cells from the scratch 446 //-- for construction the manager uses it's own set of samples 447 ConstructViewCells(mViewSpaceBox); 448 } 373 const long startTime = GetTime(); 374 int totalSamples = 0; 375 376 if (mUseViewSpaceBox) 377 { 378 AxisAlignedBox3 viewSpaceBox; 379 viewSpaceBox.Initialize(); 380 381 viewSpaceBox = AxisAlignedBox3(mKdTree->GetBox()); 382 AxisAlignedBox3 tbox(mViewCellsManager->GetViewSpaceBox()); 383 384 const Vector3 size = tbox.Size(); 385 viewSpaceBox.SetMax(0, tbox.Max(0) + size[0] * 0.5f); 386 viewSpaceBox.SetMin(0, tbox.Min(0) + size[0]); 387 388 // change the view space of the view cells manager 389 mViewCellsManager->SetViewSpaceBox(viewSpaceBox); 390 } 391 392 393 mSceneGraph->CollectObjects(&mObjects); 394 395 if (!mLoadViewCells) 396 { 397 //-- generate new view cells from the scratch 398 //-- for construction the manager uses it's own set of samples 399 ConstructViewCells(); 400 } 449 401 #if 0 450 451 452 453 454 455 456 457 402 else 403 { 404 //-- load view cells from file 405 //-- test successful view cells loading by exporting them again 406 VssRayContainer dummies; 407 mViewCellsManager->Visualize(mObjects, dummies); 408 mViewCellsManager->ExportViewCells("test.xml.zip", mViewCellsManager->GetExportPvs(), mObjects); 409 } 458 410 #endif 459 411 460 VssTree *vssTree = NULL; 461 const long initialTime = GetTime(); 462 463 if (mLoadInitialSamples) 464 { 465 cout << "Loading samples from file ... "; 466 LoadSamples(mVssRays, mObjects); 467 cout << "finished\n" << endl; 468 totalSamples = (int)mVssRays.size(); 469 } 470 else 471 { 472 while (totalSamples < mInitialSamples) { 473 int passContributingSamples = 0; 474 int passSampleContributions = 0; 475 int passSamples = 0; 476 477 int index = 0; 478 479 int sampleContributions; 480 481 int s = Min(mSamplesPerPass, mInitialSamples); 482 for (int k=0; k < s; k++) 412 VssTree *vssTree = NULL; 413 const long initialTime = GetTime(); 414 415 if (mLoadInitialSamples) 416 { 417 cout << "Loading samples from file ... "; 418 LoadSamples(mVssRays, mObjects); 419 cout << "finished\n" << endl; 420 totalSamples = (int)mVssRays.size(); 421 } 422 else 423 { 424 while (totalSamples < mInitialSamples) { 425 int passContributingSamples = 0; 426 int passSampleContributions = 0; 427 int passSamples = 0; 428 429 int index = 0; 430 431 int sampleContributions; 432 433 int s = Min(mSamplesPerPass, mInitialSamples); 434 for (int k=0; k < s; k++) 435 { 436 Vector3 viewpoint; 437 438 mViewCellsManager->GetViewPoint(viewpoint); 439 const Vector3 direction = GetDirection(viewpoint, &mViewCellsManager->GetViewSpaceBox()); 440 441 const SimpleRay sray(viewpoint, direction); 442 sampleContributions = mRayCaster->CastRay(sray, mVssRays, mViewCellsManager->GetViewSpaceBox(), true); 443 444 if (sampleContributions) { 445 passContributingSamples ++; 446 passSampleContributions += sampleContributions; 447 } 448 passSamples++; 449 totalSamples++; 450 } 451 452 mPass++; 453 int pvsSize = 0; 454 float avgRayContrib = (passContributingSamples > 0) ? 455 passSampleContributions/(float)passContributingSamples : 0; 456 457 cout << "#Pass " << mPass << " : t = " << TimeDiff(startTime, GetTime())*1e-3 << "s" << endl; 458 cout << "#TotalSamples=" << totalSamples/1000 459 << "#SampleContributions=" << passSampleContributions << " (" 460 << 100*passContributingSamples/(float)passSamples<<"%)" << " avgPVS=" 461 << pvsSize/(float)mObjects.size() << endl 462 << "avg ray contrib=" << avgRayContrib << endl; 463 464 mStats << 465 "#Pass\n" <<mPass<<endl<< 466 "#Time\n" << TimeDiff(startTime, GetTime())*1e-3 << endl<< 467 "#TotalSamples\n" << totalSamples<< endl<< 468 "#SampleContributions\n" << passSampleContributions << endl << 469 "#PContributingSamples\n"<<100*passContributingSamples/(float)passSamples<<endl << 470 "#AvgPVS\n"<< pvsSize/(float)mObjects.size() << endl << 471 "#AvgRayContrib\n" << avgRayContrib << endl; 472 } 473 474 cout << "#totalPvsSize=" << mKdTree->CollectLeafPvs() << endl; 475 476 477 478 } 479 480 481 cout << "#totalRayStackSize=" << (int)mVssRays.size() << endl << flush; 482 Debug << (int)mVssRays.size() << " rays generated in " 483 << TimeDiff(initialTime, GetTime()) * 1e-3 << " seconds" << endl; 484 485 if (mStoreInitialSamples) 486 { 487 cout << "Writing " << (int)mVssRays.size() << " samples to file ... "; 488 ExportSamples(mVssRays); 489 cout << "finished\n" << endl; 490 491 /*VssRayContainer dummyRays; 492 LoadSamples(dummyRays, mObjects); 493 Debug << "rays " << (int)mVssRays.size() << " " << dummyRays.size() << endl; 494 495 for (int i = 0; i < (int)mVssRays.size(); ++ i) 483 496 { 484 Vector3 viewpoint; 485 486 mViewCellsManager->GetViewPoint(viewpoint); 487 const Vector3 direction = GetDirection(viewpoint, &mViewSpaceBox); 488 489 const SimpleRay sray(viewpoint, direction); 490 sampleContributions = mRayCaster->CastRay(sray, mVssRays, mViewSpaceBox, true); 491 492 if (sampleContributions) { 493 passContributingSamples ++; 494 passSampleContributions += sampleContributions; 497 Debug << mVssRays[i]->GetOrigin() << " " << mVssRays[i]->GetTermination() << " " << mVssRays[i]->mOriginObject << " " << mVssRays[i]->mTerminationObject << endl; 498 Debug << dummyRays[i]->GetOrigin() << " " << dummyRays[i]->GetTermination() << " " << dummyRays[i]->mOriginObject << " " << dummyRays[i]->mTerminationObject << endl << endl; 499 }*/ 500 } 501 502 503 //int numExportRays = 2000; 504 int numExportRays = 0; 505 506 if (numExportRays) { 507 char filename[64]; 508 sprintf(filename, "vss-rays-initial.x3d"); 509 ExportRays(filename, mVssRays, numExportRays); 510 } 511 512 vssTree = new VssTree; 513 // viewcells = Construct(mVssRays); 514 515 vssTree->Construct(mVssRays, NULL); 516 cout<<"VssTree root PVS size = "<<vssTree->GetRootPvsSize()<<endl; 517 518 if (0) ExportRays("kdtree.x3d", mVssRays, 10); 519 520 if (0) 521 { 522 ExportVssTree("vss-tree-100.x3d", vssTree, Vector3(1,0,0)); 523 ExportVssTree("vss-tree-001.x3d", vssTree, Vector3(0,0,1)); 524 ExportVssTree("vss-tree-101.x3d", vssTree, Vector3(1,0,1)); 525 ExportVssTree("vss-tree-101m.x3d", vssTree, Vector3(-1,0,-1)); 526 ExportVssTreeLeaves(vssTree, 10); 527 } 528 529 // viewcells->UpdatePVS(newVssRays); 530 // get viewcells as kd tree boxes 531 vector<AxisAlignedBox3> kdViewcells; 532 if (0) { 533 vector<KdLeaf *> leaves; 534 mKdTree->CollectLeaves(leaves); 535 vector<KdLeaf *>::const_iterator it; 536 int targetLeaves = 50; 537 float prob = targetLeaves/(float)leaves.size(); 538 for (it = leaves.begin(); it != leaves.end(); ++it) 539 if (RandomValue(0.0f,1.0f) < prob) 540 kdViewcells.push_back(mKdTree->GetBox(*it)); 541 542 float avgPvs = GetAvgPvsSize(vssTree, kdViewcells); 543 cout<<"Initial average PVS size = "<<avgPvs<<endl; 544 } 545 546 547 int samples = 0; 548 int pass = 0; 549 550 551 // cast view cell samples 552 while (samples < mVssSamples) 553 { 554 555 int num = mVssSamplesPerPass; 556 SimpleRayContainer rays; 557 VssRayContainer vssRays; 558 559 if (!mUseImportanceSampling) { 560 for (int j=0; j < num; j++) { 561 Vector3 viewpoint; 562 mViewCellsManager->GetViewPoint(viewpoint); 563 Vector3 direction = GetDirection(viewpoint, NULL); 564 rays.push_back(SimpleRay(viewpoint, direction)); 495 565 } 496 passSamples++;497 totalSamples++;566 } else { 567 num = GenerateImportanceRays(vssTree, num, rays); 498 568 } 499 569 500 mPass++; 501 int pvsSize = 0; 502 float avgRayContrib = (passContributingSamples > 0) ? 503 passSampleContributions/(float)passContributingSamples : 0; 504 505 cout << "#Pass " << mPass << " : t = " << TimeDiff(startTime, GetTime())*1e-3 << "s" << endl; 506 cout << "#TotalSamples=" << totalSamples/1000 507 << "#SampleContributions=" << passSampleContributions << " (" 508 << 100*passContributingSamples/(float)passSamples<<"%)" << " avgPVS=" 509 << pvsSize/(float)mObjects.size() << endl 510 << "avg ray contrib=" << avgRayContrib << endl; 511 512 mStats << 513 "#Pass\n" <<mPass<<endl<< 514 "#Time\n" << TimeDiff(startTime, GetTime())*1e-3 << endl<< 515 "#TotalSamples\n" << totalSamples<< endl<< 516 "#SampleContributions\n" << passSampleContributions << endl << 517 "#PContributingSamples\n"<<100*passContributingSamples/(float)passSamples<<endl << 518 "#AvgPVS\n"<< pvsSize/(float)mObjects.size() << endl << 519 "#AvgRayContrib\n" << avgRayContrib << endl; 520 } 521 522 cout << "#totalPvsSize=" << mKdTree->CollectLeafPvs() << endl; 523 524 525 526 } 527 528 529 cout << "#totalRayStackSize=" << (int)mVssRays.size() << endl << flush; 530 Debug << (int)mVssRays.size() << " rays generated in " 531 << TimeDiff(initialTime, GetTime()) * 1e-3 << " seconds" << endl; 532 533 if (mStoreInitialSamples) 534 { 535 cout << "Writing " << (int)mVssRays.size() << " samples to file ... "; 536 ExportSamples(mVssRays); 537 cout << "finished\n" << endl; 538 539 /*VssRayContainer dummyRays; 540 LoadSamples(dummyRays, mObjects); 541 Debug << "rays " << (int)mVssRays.size() << " " << dummyRays.size() << endl; 542 543 for (int i = 0; i < (int)mVssRays.size(); ++ i) 544 { 545 Debug << mVssRays[i]->GetOrigin() << " " << mVssRays[i]->GetTermination() << " " << mVssRays[i]->mOriginObject << " " << mVssRays[i]->mTerminationObject << endl; 546 Debug << dummyRays[i]->GetOrigin() << " " << dummyRays[i]->GetTermination() << " " << dummyRays[i]->mOriginObject << " " << dummyRays[i]->mTerminationObject << endl << endl; 547 }*/ 548 } 549 550 551 //int numExportRays = 2000; 552 int numExportRays = 0; 553 554 if (numExportRays) { 555 char filename[64]; 556 sprintf(filename, "vss-rays-initial.x3d"); 557 ExportRays(filename, mVssRays, numExportRays); 558 } 559 560 vssTree = new VssTree; 561 // viewcells = Construct(mVssRays); 562 563 vssTree->Construct(mVssRays, NULL); 564 cout<<"VssTree root PVS size = "<<vssTree->GetRootPvsSize()<<endl; 565 566 if (0) ExportRays("kdtree.x3d", mVssRays, 10); 567 568 if (0) 569 { 570 ExportVssTree("vss-tree-100.x3d", vssTree, Vector3(1,0,0)); 571 ExportVssTree("vss-tree-001.x3d", vssTree, Vector3(0,0,1)); 572 ExportVssTree("vss-tree-101.x3d", vssTree, Vector3(1,0,1)); 573 ExportVssTree("vss-tree-101m.x3d", vssTree, Vector3(-1,0,-1)); 574 ExportVssTreeLeaves(vssTree, 10); 575 } 576 577 // viewcells->UpdatePVS(newVssRays); 578 // get viewcells as kd tree boxes 579 vector<AxisAlignedBox3> kdViewcells; 580 if (0) { 581 vector<KdLeaf *> leaves; 582 mKdTree->CollectLeaves(leaves); 583 vector<KdLeaf *>::const_iterator it; 584 int targetLeaves = 50; 585 float prob = targetLeaves/(float)leaves.size(); 586 for (it = leaves.begin(); it != leaves.end(); ++it) 587 if (RandomValue(0.0f,1.0f) < prob) 588 kdViewcells.push_back(mKdTree->GetBox(*it)); 589 590 float avgPvs = GetAvgPvsSize(vssTree, kdViewcells); 591 cout<<"Initial average PVS size = "<<avgPvs<<endl; 592 } 593 594 595 int samples = 0; 596 int pass = 0; 597 598 599 // cast view cell samples 600 while (samples < mVssSamples) 601 { 602 603 int num = mVssSamplesPerPass; 604 SimpleRayContainer rays; 605 VssRayContainer vssRays; 606 607 if (!mUseImportanceSampling) { 608 for (int j=0; j < num; j++) { 609 Vector3 viewpoint; 610 mViewCellsManager->GetViewPoint(viewpoint); 611 Vector3 direction = GetDirection(viewpoint, NULL); 612 rays.push_back(SimpleRay(viewpoint, direction)); 613 } 614 } else { 615 num = GenerateImportanceRays(vssTree, num, rays); 616 } 617 618 CastRays(rays, vssRays, true); 619 vssTree->AddRays(vssRays); 620 621 if (0) { 622 int subdivided = vssTree->UpdateSubdivision(); 623 cout<<"subdivided leafs = "<<subdivided<<endl; 624 } 625 626 float avgPvs = GetAvgPvsSize(vssTree, kdViewcells); 627 cout<<"Average PVS size = "<<avgPvs<<endl; 628 629 /// compute view cell contribution of rays 630 mViewCellsManager->ComputeSampleContributions(vssRays, true, false); 631 632 if (numExportRays) { 633 char filename[64]; 634 if (mUseImportanceSampling) 635 sprintf(filename, "vss-rays-i%04d.x3d", pass); 636 else 637 sprintf(filename, "vss-rays-%04d.x3d", pass); 638 639 ExportRays(filename, vssRays, numExportRays); 640 } 641 642 samples+=num; 643 float pvs = vssTree->GetAvgPvsSize(); 644 cout<<"*****************************\n"; 645 cout<<samples<<" avgPVS ="<<pvs<<endl; 646 cout<<"VssTree root PVS size = "<<vssTree->GetRootPvsSize()<<endl; 647 cout<<"*****************************\n"; 648 // if (samples >= mVssSamples) break; 649 pass ++; 650 } 651 652 if (mTestBeamSampling && mUseGlRenderer) 653 { 654 TestBeamCasting(vssTree, mViewCellsManager, mObjects); 655 } 656 657 if (0) Debug << vssTree->stat << endl; 658 659 if (0) 660 { 661 VssRayContainer viewCellRays; 662 // compute rays used for view cells construction 663 const int numRays = mViewCellsManager->GetVisualizationSamples(); 664 vssTree->CollectRays(viewCellRays, numRays); 665 } 666 667 668 //////////////////// 669 //-- render simulation after construction 670 671 mRenderSimulator->RenderScene(); 672 SimulationStatistics ss; 673 mRenderSimulator->GetStatistics(ss); 674 Debug << "\nFinal view cells partition render time\n" << ss << endl; 675 cout << "\nFinal view cells partition render time\n" << ss << endl; 676 677 delete vssTree; 678 679 return true; 680 } 681 682 } 570 CastRays(rays, vssRays, true); 571 vssTree->AddRays(vssRays); 572 573 if (0) { 574 int subdivided = vssTree->UpdateSubdivision(); 575 cout<<"subdivided leafs = "<<subdivided<<endl; 576 } 577 578 float avgPvs = GetAvgPvsSize(vssTree, kdViewcells); 579 cout<<"Average PVS size = "<<avgPvs<<endl; 580 581 /// compute view cell contribution of rays 582 mViewCellsManager->ComputeSampleContributions(vssRays, true, false); 583 584 if (numExportRays) { 585 char filename[64]; 586 if (mUseImportanceSampling) 587 sprintf(filename, "vss-rays-i%04d.x3d", pass); 588 else 589 sprintf(filename, "vss-rays-%04d.x3d", pass); 590 591 ExportRays(filename, vssRays, numExportRays); 592 } 593 594 samples+=num; 595 float pvs = vssTree->GetAvgPvsSize(); 596 cout<<"*****************************\n"; 597 cout<<samples<<" avgPVS ="<<pvs<<endl; 598 cout<<"VssTree root PVS size = "<<vssTree->GetRootPvsSize()<<endl; 599 cout<<"*****************************\n"; 600 // if (samples >= mVssSamples) break; 601 pass ++; 602 } 603 604 if (mTestBeamSampling && mUseGlRenderer) 605 { 606 TestBeamCasting(vssTree, mViewCellsManager, mObjects); 607 } 608 609 if (0) Debug << vssTree->stat << endl; 610 611 if (0) 612 { 613 VssRayContainer viewCellRays; 614 // compute rays used for view cells construction 615 const int numRays = mViewCellsManager->GetVisualizationSamples(); 616 vssTree->CollectRays(viewCellRays, numRays); 617 } 618 619 620 //////////////////// 621 //-- render simulation after construction 622 623 mRenderSimulator->RenderScene(); 624 SimulationStatistics ss; 625 mRenderSimulator->GetStatistics(ss); 626 Debug << "\nFinal view cells partition render time\n" << ss << endl; 627 cout << "\nFinal view cells partition render time\n" << ss << endl; 628 629 delete vssTree; 630 631 return true; 632 } 633 634 } -
GTP/trunk/Lib/Vis/Preprocessing/src/VssPreprocessor.h
r1486 r1563 26 26 bool mUseImportanceSampling; 27 27 bool mEnlargeViewSpace; 28 AxisAlignedBox3 mViewSpaceBox;28 //AxisAlignedBox3 mViewSpaceBox; 29 29 30 30 ofstream mStats;
Note: See TracChangeset
for help on using the changeset viewer.