Changeset 1027 for GTP/trunk/Lib/Vis/Preprocessing
- Timestamp:
- 06/21/06 09:44:39 (19 years ago)
- Location:
- GTP/trunk/Lib/Vis/Preprocessing/src
- Files:
-
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/Lib/Vis/Preprocessing/src/Environment.cpp
r1023 r1027 2089 2089 2090 2090 2091 /*************************************************************************** *********/2092 /* View space partition tree related options 2093 /*************************************************************************** *********/2091 /***************************************************************************/ 2092 /* View space partition tree related options */ 2093 /***************************************************************************/ 2094 2094 2095 2095 2096 RegisterOption("VspTree.Construction.samples", 2097 optInt, 2098 "vsp_construction_samples=", 2099 "10000"); 2100 2096 2101 RegisterOption("VspTree.Termination.maxDepth", 2097 2102 optInt, -
GTP/trunk/Lib/Vis/Preprocessing/src/RssPreprocessor.cpp
r1004 r1027 490 490 box.SetMin(0, box.Min(0) + s); 491 491 box.SetMax(0, box.Max(0) + s); 492 492 493 mViewCellsManager->SetViewSpaceBox(box); 493 494 } -
GTP/trunk/Lib/Vis/Preprocessing/src/ViewCell.cpp
r1010 r1027 381 381 Debug << "max memory: " << mMaxMemory << endl; 382 382 Debug << "refining view cells: " << mRefineViewCells << endl; 383 Debug << "=========== == view cell tree options ================\n";383 Debug << "=========== end view cell tree options ===============\n"; 384 384 385 385 MergeCandidate::sRenderCostWeight = mRenderCostWeight; -
GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellBsp.cpp
r1016 r1027 60 60 61 61 62 bool BspNode::IsRoot() const63 {64 return mParent == NULL;65 }66 67 68 BspInterior *BspNode::GetParent()69 {70 return mParent;71 }72 73 74 void BspNode::SetParent(BspInterior *parent)75 {76 mParent = parent;77 }78 79 80 62 bool BspNode::IsSibling(BspNode *n) const 81 63 { … … 127 109 } 128 110 129 bool BspInterior::IsLeaf() const130 {131 return false;132 }133 134 BspNode *BspInterior::GetBack()135 {136 return mBack;137 }138 139 BspNode *BspInterior::GetFront()140 {141 return mFront;142 }143 144 Plane3 BspInterior::GetPlane() const145 {146 return mPlane;147 }148 149 void BspInterior::ReplaceChildLink(BspNode *oldChild, BspNode *newChild)150 {151 if (mBack == oldChild)152 mBack = newChild;153 else154 mFront = newChild;155 }156 111 157 112 void BspInterior::SetupChildLinks(BspNode *b, BspNode *f) … … 193 148 BspNode(parent), mViewCell(viewCell), mPvs(NULL) 194 149 { 195 }196 197 ViewCellLeaf *BspLeaf::GetViewCell() const198 {199 return mViewCell;200 }201 202 void BspLeaf::SetViewCell(ViewCellLeaf *viewCell)203 {204 mViewCell = viewCell;205 }206 207 208 bool BspLeaf::IsLeaf() const209 {210 return true;211 150 } 212 151 … … 1010 949 // generate new view cell for each leaf 1011 950 if (mGenerateViewCells) 951 { 1012 952 viewCell = new BspViewCell(); 953 } 1013 954 else 955 { 1014 956 // add view cell to leaf 1015 957 viewCell = dynamic_cast<BspViewCell *>(tData.mViewCell); 1016 958 } 959 1017 960 leaf->SetViewCell(viewCell); 1018 961 viewCell->mLeaf = leaf; … … 1036 979 } 1037 980 1038 EvaluateLeafStats(tData); 981 if (1) 982 EvaluateLeafStats(tData); 1039 983 1040 984 //-- clean up … … 1045 989 CLEAR_CONTAINER(*tData.mRays); 1046 990 1047 DEL_PTR(tData.mPolygons);1048 DEL_PTR(tData.mRays);1049 DEL_PTR(tData.mGeometry);991 delete tData.mPolygons; 992 delete tData.mRays; 993 delete tData.mGeometry; 1050 994 1051 995 return leaf; -
GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellBsp.h
r1012 r1027 278 278 279 279 /** Determines whether this node is a root 280 @return true if root 281 */ 282 virtual bool IsRoot() const; 280 @return true if root 281 */ 282 virtual bool IsRoot() const 283 { 284 return mParent == NULL; 285 } 283 286 284 287 /** Returns parent node. 285 288 */ 286 BspInterior *GetParent(); 289 inline BspInterior *GetParent() 290 { 291 return mParent; 292 } 287 293 288 294 /** Sets parent node. 289 295 */ 290 void SetParent(BspInterior *parent); 296 inline void BspNode::SetParent(BspInterior *parent) 297 { 298 mParent = parent; 299 } 300 291 301 292 302 /** Returns true if this node is a sibling of node n. … … 334 344 BspInterior(const Plane3 &plane); 335 345 ~BspInterior(); 346 336 347 /** @return false since it is an interior node 337 348 */ 338 bool IsLeaf() const; 339 340 BspNode *GetBack(); 341 BspNode *GetFront(); 342 349 bool IsLeaf() const 350 { 351 return false; 352 } 353 BspNode *GetBack() 354 { 355 return mBack; 356 } 357 358 BspNode *GetFront() 359 { 360 return mFront; 361 } 362 343 363 /** Returns split plane. 344 364 */ 345 Plane3 GetPlane() const; 365 Plane3 BspInterior::GetPlane() const 366 { 367 return mPlane; 368 } 346 369 347 370 /** Replace front or back child with new child. 348 371 */ 349 void ReplaceChildLink(BspNode *oldChild, BspNode *newChild); 372 inline void ReplaceChildLink(BspNode *oldChild, BspNode *newChild) 373 { 374 if (mBack == oldChild) 375 mBack = newChild; 376 else 377 mFront = newChild; 378 } 379 350 380 /** Replace front and back child. 351 381 */ … … 383 413 ~BspLeaf(); 384 414 415 /** Returns pointer of view cell. 416 */ 417 inline ViewCellLeaf *GetViewCell() const 418 { 419 return mViewCell; 420 } 421 422 /** Sets pointer to view cell. 423 */ 424 inline void SetViewCell(ViewCellLeaf *viewCell) 425 { 426 mViewCell = viewCell; 427 } 428 385 429 /** @return true since it is an interior node 386 430 */ 387 bool IsLeaf() const; 388 389 /** Returns pointer of view cell. 390 */ 391 ViewCellLeaf *GetViewCell() const; 392 393 /** Sets pointer to view cell. 394 */ 395 void SetViewCell(ViewCellLeaf *viewCell); 431 bool BspLeaf::IsLeaf() const 432 { 433 return true; 434 } 435 396 436 397 437 /// Rays piercing this leaf. … … 403 443 /// Probability that the view point lies in this leaf 404 444 float mProbability; 445 405 446 406 447 protected: -
GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp
r1022 r1027 181 181 182 182 183 Debug << "*********** View Cells options ****************" << endl;183 Debug << "************ View Cells options ***************" << endl; 184 184 Debug << "color code: " << mColorCode << endl; 185 185 … … 417 417 << TimeDiff(startTime, GetTime()) * 1e-3 << " secs" << endl; 418 418 419 //return 0; 419 420 420 // take post processing time 421 421 startTime = GetTime(); … … 1727 1727 { 1728 1728 mViewSpaceBox = box; 1729 1729 Debug << "here111 " << mViewSpaceBox << endl; 1730 // hack: create clip plane relative to new view space box 1730 1731 CreateClipPlane(); 1731 1732 // the total area of the view space has changed 1732 1733 mTotalAreaValid = false; 1733 1734 } … … 2928 2929 const Plane3 *clipPlane) const 2929 2930 { 2931 // export mesh if available 2930 2932 if (vc->GetMesh()) 2931 2933 { 2932 2934 exporter->ExportMesh(vc->GetMesh()); 2933 2934 2935 return; 2935 2936 } 2936 2937 2937 // otherwise construct from leaves 2938 2938 if (clipPlane) 2939 2939 { … … 4787 4787 ViewCellsManager(), mVspTree(vspTree), mOspTree(ospTree) 4788 4788 { 4789 Environment::GetSingleton()->GetIntValue("VspBspTree.Construction.samples", mInitialSamples); 4789 mHierarchyManager = new HierarchyManager(*vspTree, *ospTree); 4790 Environment::GetSingleton()->GetIntValue("VspTree.Construction.samples", mInitialSamples); 4790 4791 mVspTree->SetViewCellsManager(this); 4791 4792 mVspTree->mViewCellsTree = mViewCellsTree; … … 4795 4796 VspOspViewCellsManager::~VspOspViewCellsManager() 4796 4797 { 4798 DEL_PTR(mHierarchyManager); 4797 4799 } 4798 4800 … … 4835 4837 mMaxPvsSize = (int)(mMaxPvsRatio * (float)objects.size()); 4836 4838 4839 Debug << "here125 view space box " << mViewSpaceBox << endl; 4840 4837 4841 // if view cells were already constructed 4838 4842 if (ViewCellsConstructed()) … … 4858 4862 long startTime; 4859 4863 4860 #if TODO 4861 if (1) 4862 mVspTree->Construct(constructionRays, &mViewSpaceBox); 4863 else 4864 mVspTree->Construct(rays, &mViewSpaceBox); 4865 #endif 4866 // collapse invalid regions 4867 cout << "collapsing invalid tree regions ... "; 4868 startTime = GetTime(); 4869 const int collapsedLeaves = mVspTree->CollapseTree(); 4870 Debug << "collapsed in " << TimeDiff(startTime, GetTime()) * 1e-3 4871 << " seconds" << endl; 4872 4873 cout << "finished" << endl; 4874 4864 mHierarchyManager->Construct(constructionRays, objects, &mViewSpaceBox); 4865 4866 4875 4867 //-- stats 4876 4868 Debug << mVspTree->GetStatistics() << endl; … … 4917 4909 4918 4910 4919 // view cells already finished before post processing step 4920 // (i.e. because they were loaded) 4911 // take this step only if 4912 // view cells already constructed before post processing step 4913 // (e.g., because they were loaded) 4921 4914 if (mViewCellsFinished) 4922 4915 { … … 5154 5147 5155 5148 5149 void VspOspViewCellsManager::ExportViewCellGeometry(Exporter *exporter, 5150 ViewCell *vc, 5151 const Plane3 *clipPlane) const 5152 { 5153 ViewCellContainer leaves; 5154 5155 mViewCellsTree->CollectLeaves(vc, leaves); 5156 ViewCellContainer::const_iterator it, it_end = leaves.end(); 5157 5158 for (it = leaves.begin(); it != it_end; ++ it) 5159 { 5160 VspViewCell *vspVc = dynamic_cast<VspViewCell *>(*it); 5161 VspLeaf *l = vspVc->mLeaf; 5162 5163 const AxisAlignedBox3 box = mVspTree->GetBBox(vspVc->mLeaf); 5164 5165 if (!clipPlane || !box.Side(*clipPlane)) 5166 exporter->ExportBox(box); 5167 } 5168 } 5169 5170 5156 5171 bool VspOspViewCellsManager::ViewPointValid(const Vector3 &viewPoint) const 5157 5172 { … … 5161 5176 5162 5177 // return mViewSpaceBox.IsInside(viewPoint) && 5163 // mVsp BspTree->ViewPointValid(viewPoint);5178 // mVspTree->ViewPointValid(viewPoint); 5164 5179 } 5165 5180 … … 5170 5185 if (!ViewCellsConstructed()) 5171 5186 return; 5172 #if TODO 5187 5173 5188 VssRayContainer visRays; 5174 5189 GetRaySets(sampleRays, mVisualizationSamples, visRays); … … 5208 5223 5209 5224 // HACK: export without clip plane 5210 const bool b = mUseClipPlaneForViz;5211 mUseClipPlaneForViz = false;5225 //const bool b = mUseClipPlaneForViz; 5226 //mUseClipPlaneForViz = false; 5212 5227 5213 5228 ExportViewCellsForViz(exporter); 5214 5229 5215 mUseClipPlaneForViz = b;5230 //mUseClipPlaneForViz = b; 5216 5231 delete exporter; 5217 5232 … … 5220 5235 5221 5236 mColorCode = savedColorCode; 5222 }5223 5224 5225 if (0)5226 {5227 cout << "exporting depth map ... ";5228 5229 Exporter *exporter = Exporter::GetExporter("depth_map.x3d");5230 if (exporter)5231 {5232 if (1)5233 {5234 exporter->SetWireframe();5235 exporter->ExportBox(mViewSpaceBox);5236 exporter->SetFilled();5237 }5238 5239 if (mExportGeometry)5240 {5241 exporter->ExportGeometry(objects);5242 }5243 5244 const int maxDepth = mVspBspTree->mBspStats.maxDepth;5245 5246 ViewCellContainer::const_iterator vit, vit_end = mViewCells.end();5247 5248 for (vit = mViewCells.begin(); vit != mViewCells.end(); ++ vit)5249 {5250 ViewCell *vc = *vit;5251 5252 ViewCellContainer leaves;5253 mViewCellsTree->CollectLeaves(vc, leaves);5254 5255 ViewCellContainer::const_iterator lit, lit_end = leaves.end();5256 5257 for (lit = leaves.begin(); lit != lit_end; ++ lit)5258 {5259 BspLeaf *leaf = dynamic_cast<BspViewCell *>(*lit)->mLeaf;5260 5261 Material m;5262 5263 float relDepth = (float)leaf->GetDepth() / (float)maxDepth;5264 m.mDiffuseColor.r = relDepth;5265 m.mDiffuseColor.g = 0.0f;5266 m.mDiffuseColor.b = 1.0f - relDepth;5267 5268 exporter->SetForcedMaterial(m);5269 5270 5271 BspNodeGeometry geom;5272 mVspBspTree->ConstructGeometry(leaf, geom);5273 exporter->ExportPolygons(geom.GetPolys());5274 }5275 }5276 5277 delete exporter;5278 }5279 5280 5281 cout << "finished" << endl;5282 }5283 5284 //-- visualization of the BSP splits5285 5286 bool exportSplits = false;5287 Environment::GetSingleton()->GetBoolValue("VspBspTree.Visualization.exportSplits", exportSplits);5288 5289 if (exportSplits)5290 {5291 cout << "exporting splits ... ";5292 ExportSplits(objects, visRays);5293 cout << "finished" << endl;5294 5237 } 5295 5238 5296 5239 //-- export single view cells 5297 5240 ExportBspPvs(objects, visRays); 5298 #endif5299 5241 } 5300 5242 … … 5482 5424 5483 5425 5484 void VspOspViewCellsManager::ExportViewCellGeometry(Exporter *exporter,5485 ViewCell *vc,5486 const Plane3 *clipPlane) const5487 {5488 // matt: TODO5489 }5490 5491 5492 5426 bool VspOspViewCellsManager::ExportViewCells(const string filename, 5493 5427 const bool exportPvs, … … 5537 5471 5538 5472 //-- export the view cells and the pvs 5539 stream << "<HierarchyType name=\"vsp BspTree\" />" << endl;5473 stream << "<HierarchyType name=\"vspTree\" />" << endl; 5540 5474 5541 5475 const int numViewCells = mCurrentViewCellsStats.viewCells; … … 5566 5500 5567 5501 5568 ViewCell *VspOspViewCellsManager::GetViewCell(const Vector3 &point, const bool active) const 5502 ViewCell *VspOspViewCellsManager::GetViewCell(const Vector3 &point, 5503 const bool active) const 5569 5504 { 5570 5505 if (!ViewCellsConstructed()) … … 5582 5517 // matt: TODO 5583 5518 Mesh *mesh = MeshManager::GetSingleton()->CreateResource(); 5519 5520 ViewCellContainer leaves; 5521 mViewCellsTree->CollectLeaves(vc, leaves); 5522 5523 ViewCellContainer::const_iterator it, it_end = leaves.end(); 5524 5525 for (it = leaves.begin(); it != it_end; ++ it) 5526 { 5527 VspLeaf *leaf = dynamic_cast<VspViewCell *>(*it)->mLeaf; 5528 const AxisAlignedBox3 box = mVspTree->GetBBox(leaf); 5529 5530 IncludeBoxInMesh(box, *mesh); 5531 } 5532 5584 5533 vc->SetMesh(mesh); 5585 5534 } … … 5596 5545 const bool createMesh) 5597 5546 { 5598 #if TODO5599 5547 float area = 0; 5600 5548 float volume = 0; … … 5607 5555 for (it = leaves.begin(); it != it_end; ++ it) 5608 5556 { 5609 BspNodeGeometry geom;5610 BspLeaf *leaf = dynamic_cast<BspViewCell *>(*it)->mLeaf;5611 mVspBspTree->ConstructGeometry(leaf, geom);5612 5613 const float lVol = geom.GetVolume();5614 const float lArea = geom.GetArea();5557 VspLeaf *leaf = dynamic_cast<VspViewCell *>(*it)->mLeaf; 5558 5559 const AxisAlignedBox3 box = mVspTree->GetBBox(leaf); 5560 5561 const float lVol = box.GetVolume(); 5562 const float lArea = box.SurfaceArea(); 5615 5563 5616 5564 //(*it)->SetVolume(vol); … … 5625 5573 viewCell->SetVolume(volume); 5626 5574 viewCell->SetArea(area); 5627 #endif5628 5575 } 5629 5576 -
GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.h
r1022 r1027 35 35 class OspTree; 36 36 class VspNode; 37 37 class HierarchyManager; 38 38 39 39 struct BspRay; … … 298 298 /** Writes view cells to disc. 299 299 */ 300 virtual bool ExportViewCells(const string filename, const bool exportPvs, const ObjectContainer &objects); 300 virtual bool ExportViewCells(const string filename, 301 const bool exportPvs, 302 const ObjectContainer &objects); 301 303 302 304 /** Casts beam to collect view cells. … … 983 985 void CreateMesh(ViewCell *vc); 984 986 985 bool ExportViewCells(const string filename, const bool exportPvs, const ObjectContainer &objects); 987 bool ExportViewCells(const string filename, 988 const bool exportPvs, 989 const ObjectContainer &objects); 986 990 987 991 int CastBeam(Beam &beam); 988 992 993 void Finalize(ViewCell *viewCell, const bool createMesh); 994 995 996 protected: 997 998 999 /** Exports view cell geometry. 1000 */ 989 1001 void ExportViewCellGeometry(Exporter *exporter, 990 1002 ViewCell *vc, 991 1003 const Plane3 *clipPlane = NULL) const; 992 1004 993 void Finalize(ViewCell *viewCell, const bool createMesh);994 995 996 protected:997 998 1005 int ComputeBoxIntersections(const AxisAlignedBox3 &box, ViewCellContainer &viewCells) const; 999 1006 … … 1020 1027 VspTree *mVspTree; 1021 1028 OspTree *mOspTree; 1029 1030 HierarchyManager *mHierarchyManager; 1022 1031 }; 1023 1032 -
GTP/trunk/Lib/Vis/Preprocessing/src/VspBspTree.cpp
r1023 r1027 197 197 Debug << endl; 198 198 } 199 /* 200 VspBspTree::VspBspTree(): 201 mRoot(NULL), 202 mUseAreaForPvs(false), 203 mCostNormalizer(Limits::Small), 204 mViewCellsManager(NULL), 205 mOutOfBoundsCell(NULL), 206 mStoreRays(false), 207 mRenderCostWeight(0.5), 208 mUseRandomAxis(false), 209 mTimeStamp(1), 210 mEpsilon(1e-6f) 211 { 212 }*/ 199 213 200 214 201 BspViewCell *VspBspTree::GetOutOfBoundsCell() … … 343 330 344 331 332 void VspBspTree::ComputeBoundingBox(const VssRayContainer &sampleRays, 333 AxisAlignedBox3 *forcedBoundingBox) 334 { 335 if (forcedBoundingBox) 336 { 337 mBox = *forcedBoundingBox; 338 } 339 else // compute vsp tree bounding box 340 { 341 mBox.Initialize(); 342 343 VssRayContainer::const_iterator rit, rit_end = sampleRays.end(); 344 345 //-- compute bounding box 346 for (rit = sampleRays.begin(); rit != rit_end; ++ rit) 347 { 348 VssRay *ray = *rit; 349 350 // compute bounding box of view space 351 mBox.Include(ray->GetTermination()); 352 mBox.Include(ray->GetOrigin()); 353 } 354 } 355 } 356 357 345 358 void VspBspTree::Construct(const VssRayContainer &sampleRays, 346 359 AxisAlignedBox3 *forcedBoundingBox) 347 360 { 348 mBspStats.nodes = 1; 349 mBox.Initialize(); // initialise BSP tree bounding box 350 351 if (forcedBoundingBox) 352 mBox = *forcedBoundingBox; 361 // Compute the bounding box from the rays 362 ComputeBoundingBox(sampleRays, forcedBoundingBox); 353 363 354 364 PolygonContainer polys; 355 365 RayInfoContainer *rays = new RayInfoContainer(); 356 366 367 //-- extract polygons from rays if there are polygon candidates 368 if (mMaxPolyCandidates) 369 { 370 int numObj = 0; 371 372 Intersectable::NewMail(); 373 374 cout << "Extracting polygons from rays ... "; 375 376 long startTime = GetTime(); 377 378 VssRayContainer::const_iterator rit, rit_end = sampleRays.end(); 379 380 //-- extract polygons intersected by the rays 381 for (rit = sampleRays.begin(); rit != rit_end; ++ rit) 382 { 383 VssRay *ray = *rit; 384 Intersectable *obj = ray->mTerminationObject; 385 386 if ((mBox.IsInside(ray->mTermination) || !forcedBoundingBox) && 387 obj && !obj->Mailed()) 388 { 389 obj->Mail(); 390 391 // transformed mesh instance and mesh instance handle mesh differently 392 if (obj->Type() == Intersectable::TRANSFORMED_MESH_INSTANCE) 393 { 394 Mesh mesh; 395 396 TransformedMeshInstance *tmobj = 397 dynamic_cast<TransformedMeshInstance *>(obj); 398 399 tmobj->GetTransformedMesh(mesh); 400 AddMeshToPolygons(&mesh, polys, tmobj); 401 } 402 else // MeshInstance 403 { 404 MeshInstance *mobj = dynamic_cast<MeshInstance *>(obj); 405 AddMeshToPolygons(mobj->GetMesh(), polys, mobj); 406 } 407 408 ++ numObj; 409 410 //-- compute bounding box 411 if (!forcedBoundingBox) 412 mBox.Include(ray->mTermination); 413 } 414 415 if ((mBox.IsInside(ray->mOrigin) || !forcedBoundingBox) && 416 ray->mOriginObject && 417 !ray->mOriginObject->Mailed()) 418 { 419 ray->mOriginObject->Mail(); 420 MeshInstance *obj = dynamic_cast<MeshInstance *>(ray->mOriginObject); 421 AddMeshToPolygons(obj->GetMesh(), polys, obj); 422 423 ++ numObj; 424 } 425 } 426 427 // throw out unnecessary polygons 428 PreprocessPolygons(polys); 429 430 cout << "finished" << endl; 431 432 Debug << "\n" << (int)polys.size() << " polys extracted from " 433 << (int)sampleRays.size() << " rays in " 434 << TimeDiff(startTime, GetTime())*1e-3 << " secs" << endl << endl; 435 } 436 437 Debug << "maximal pvs (i.e., pvs still considered as valid): " 438 << mViewCellsManager->GetMaxPvsSize() << endl; 439 357 440 VssRayContainer::const_iterator rit, rit_end = sampleRays.end(); 358 359 long startTime = GetTime();360 361 cout << "Extracting polygons from rays ... ";362 363 Intersectable::NewMail();364 365 int numObj = 0;366 367 //-- extract polygons intersected by the rays368 for (rit = sampleRays.begin(); rit != rit_end; ++ rit)369 {370 VssRay *ray = *rit;371 Intersectable *obj = ray->mTerminationObject;372 373 if ((mBox.IsInside(ray->mTermination) || !forcedBoundingBox) &&374 obj && !obj->Mailed())375 {376 obj->Mail();377 378 // transformed mesh instance and mesh instance handle mesh differently379 if (obj->Type() == Intersectable::TRANSFORMED_MESH_INSTANCE)380 {381 Mesh mesh;382 383 TransformedMeshInstance *tmobj =384 dynamic_cast<TransformedMeshInstance *>(obj);385 386 tmobj->GetTransformedMesh(mesh);387 AddMeshToPolygons(&mesh, polys, tmobj);388 }389 else // MeshInstance390 {391 MeshInstance *mobj = dynamic_cast<MeshInstance *>(obj);392 AddMeshToPolygons(mobj->GetMesh(), polys, mobj);393 }394 395 ++ numObj;396 397 //-- compute bounding box398 if (!forcedBoundingBox)399 mBox.Include(ray->mTermination);400 }401 402 if ((mBox.IsInside(ray->mOrigin) || !forcedBoundingBox) &&403 ray->mOriginObject &&404 !ray->mOriginObject->Mailed())405 {406 ray->mOriginObject->Mail();407 MeshInstance *obj = dynamic_cast<MeshInstance *>(ray->mOriginObject);408 AddMeshToPolygons(obj->GetMesh(), polys, obj);409 ++ numObj;410 411 //-- compute bounding box412 if (!forcedBoundingBox)413 mBox.Include(ray->mOrigin);414 }415 }416 417 Debug << "maximal pvs (i.e., pvs still considered as valid) : "418 << mViewCellsManager->GetMaxPvsSize() << endl;419 441 420 442 //-- store rays … … 446 468 mTermMinProbability *= mBox.GetVolume(); 447 469 448 // throw out unnecessary polygons 449 PreprocessPolygons(polys); 450 470 471 mBspStats.nodes = 1; 451 472 mBspStats.polys = (int)polys.size(); 452 473 mGlobalCostMisses = 0; 453 474 454 cout << "finished" << endl;455 456 Debug << "\nPolygon extraction: " << (int)polys.size() << " polys extracted from "457 << (int)sampleRays.size() << " rays in "458 << TimeDiff(startTime, GetTime())*1e-3 << " secs" << endl << endl;459 475 460 476 // use split cost priority queue … … 684 700 { 685 701 nViewCells += 500; 686 687 702 cout << "generated " << mCreatedViewCells << " viewcells" << endl; 688 703 } … … 847 862 848 863 // should I check here? 849 if (0 && !mViewCellsManager->CheckValidity(viewCell, 0, mViewCellsManager->GetMaxPvsSize())) 864 if (0 && !mViewCellsManager->CheckValidity(viewCell, 0, 865 mViewCellsManager->GetMaxPvsSize())) 850 866 { 851 867 viewCell->SetValid(false); … … 866 882 867 883 // finally evaluate stats until this leaf 868 EvaluateLeafStats(tData); 884 if (0) 885 EvaluateLeafStats(tData); 869 886 } 870 887 … … 875 892 } 876 893 877 // subdivide using a split plane queue 894 895 // subdivide node using a split plane queue 878 896 BspNode *VspBspTree::Subdivide(VspBspSplitQueue &tQueue, 879 897 VspBspSplitCandidate &splitCandidate) … … 990 1008 991 1009 // finally evaluate stats until this leaf 992 EvaluateLeafStats(tData); 1010 if (0) 1011 EvaluateLeafStats(tData); 993 1012 } 994 1013 … … 1031 1050 1032 1051 // TODO: reuse 1033 DEL_PTR(frontData.mGeometry);1034 DEL_PTR(backData.mGeometry);1052 delete frontData.mGeometry; 1053 delete backData.mGeometry; 1035 1054 1036 1055 // compute global decrease in render cost … … 1910 1929 1911 1930 // something is wrong with the volume 1912 if ( (pFront < 0.0) || (pBack < 0.0))1931 if (0 && ((pFront < 0.0) || (pBack < 0.0))) 1913 1932 { 1914 1933 Debug << "ERROR in volume:\n" … … 2025 2044 { 2026 2045 //Debug << "error f: " << pFront << " b: " << pBack << endl; 2027 // high penalty for this split 2046 2047 // high penalty for degenerated / wrong split 2028 2048 return 99999.9f; 2029 2049 } … … 2382 2402 << "Depth: " << data.mDepth << " (max: " << mTermMaxDepth << "), " 2383 2403 << "PVS: " << data.mPvs << " (min: " << mTermMinPvs << "), " 2384 // << "Area: " << data.mProbability << " (min: " << mTermMinProbability << "), " 2385 << "#rays: " << (int)data.mRays->size() << " (max: " << mTermMinRays << "), " 2386 << "#pvs: " << leaf->GetViewCell()->GetPvs().GetSize() << "=, " 2404 << "#rays: " << (int)data.mRays->size() << " (max: " << mTermMinRays << "), " 2405 << "#pvs: " << leaf->GetViewCell()->GetPvs().GetSize() << "), " 2387 2406 << "#avg ray contrib (pvs): " << (float)data.mPvs / (float)data.mRays->size() << endl; 2388 2407 #endif … … 2660 2679 // preprocess: throw out polygons coincident to the view space box (not needed) 2661 2680 PolygonContainer boxPolys; 2662 /*mBox.ExtractPolys(boxPolys); 2681 2682 mBox.ExtractPolys(boxPolys); 2663 2683 vector<Plane3> boxPlanes; 2664 2684 … … 2699 2719 polys.pop_back(); 2700 2720 } 2701 } */2721 } 2702 2722 } 2703 2723 -
GTP/trunk/Lib/Vis/Preprocessing/src/VspBspTree.h
r1020 r1027 227 227 /** Returns box which bounds the whole tree. 228 228 */ 229 AxisAlignedBox3 GetBoundingBox() const;229 AxisAlignedBox3 GetBoundingBox() const; 230 230 231 231 /** Returns root of BSP tree. … … 389 389 } 390 390 }; 391 392 void ComputeBoundingBox(const VssRayContainer &sampleRays, 393 AxisAlignedBox3 *forcedBoundingBox); 391 394 392 395 /** faster evaluation of split plane cost for kd axis aligned cells. -
GTP/trunk/Lib/Vis/Preprocessing/src/VspOspTree.cpp
r1023 r1027 53 53 void VspTreeStatistics::Print(ostream &app) const 54 54 { 55 #if TODO 56 app << "===== BspTree statistics ===============\n"; 55 app << "===== VspTree statistics ===============\n"; 57 56 58 57 app << setprecision(4); … … 65 64 66 65 app << "#N_LEAVES ( Number of leaves )\n" << Leaves() << "\n"; 67 68 app << "#N_POLYSPLITS ( Number of polygon splits )\n" << polySplits << "\n";69 66 70 67 app << "#AXIS_ALIGNED_SPLITS (number of axis aligned splits)\n" << splits[0] + splits[1] + splits[2] << endl; … … 100 97 app << "#AVGDEPTH ( average depth )\n" << AvgDepth() << endl; 101 98 102 app << "#N_INPUTPOLYGONS (number of input polygons )\n" << polys << endl;103 104 99 app << "#N_INVALIDLEAVES (number of invalid leaves )\n" << invalidLeaves << endl; 105 100 … … 107 102 //app << "#N_PVS: " << pvs << endl; 108 103 109 app << "#N_ROUTPUT_INPUT_POLYGONS ( ratio polygons after subdivision / input polygons )\n" << 110 (polys + polySplits) / (double)polys << endl; 111 112 app << "===== END OF BspTree statistics ==========\n"; 113 #endif 104 app << "===== END OF VspTree statistics ==========\n"; 114 105 } 115 106 … … 267 258 return Interior; 268 259 } 260 261 269 262 270 263 /****************************************************************/ … … 449 442 { 450 443 mVspStats.nodes = 1; 451 mBoundingBox.Initialize(); // initialise vsp tree bounding box 452 444 453 445 if (forcedBoundingBox) 446 { 454 447 mBoundingBox = *forcedBoundingBox; 455 456 VssRayContainer::const_iterator rit, rit_end = sampleRays.end();457 458 Intersectable::NewMail();459 460 //-- compute bounding box461 for (rit = sampleRays.begin(); rit != rit_end; ++ rit) 462 {463 VssRay *ray = *rit; 464 465 // compute bounding box of view space466 if (!forcedBoundingBox) 467 {448 } 449 else // compute vsp tree bounding box 450 { 451 mBoundingBox.Initialize(); 452 453 VssRayContainer::const_iterator rit, rit_end = sampleRays.end(); 454 455 //-- compute bounding box 456 for (rit = sampleRays.begin(); rit != rit_end; ++ rit) 457 { 458 VssRay *ray = *rit; 459 460 // compute bounding box of view space 468 461 mBoundingBox.Include(ray->GetTermination()); 469 462 mBoundingBox.Include(ray->GetOrigin()); 470 463 } 471 } 472 473 mTermMinProbability *= mBoundingBox.GetVolume();474 mGlobalCostMisses = 0;464 465 mTermMinProbability *= mBoundingBox.GetVolume(); 466 mGlobalCostMisses = 0; 467 } 475 468 } 476 469 … … 480 473 const float splitCandidateCost, 481 474 const float totalRenderCost, 482 475 const float avgRenderCost) 483 476 { 484 477 mSubdivisionStats … … 507 500 { 508 501 return 502 #if TODO 509 503 (((int)data.mRays->size() <= mTermMinRays) || 510 504 (data.mPvs <= mTermMinPvs) || … … 512 506 (data.GetAvgRayContribution() > mTermMaxRayContribution) || 513 507 (data.mDepth >= mTermMaxDepth)); 508 #else 509 false; 510 #endif 514 511 } 515 512 … … 518 515 { 519 516 return 517 #if TODO 520 518 (mOutOfMemory || 521 519 (mVspStats.Leaves() >= mMaxViewCells) || 522 520 (mGlobalCostMisses >= mTermGlobalCostMissTolerance)); 521 #else 522 (mVspStats.Leaves() >= mMaxViewCells) ; 523 #endif 523 524 } 524 525 … … 633 634 634 635 void VspTree::EvalSplitCandidate(VspTraversalData &tData, 635 VspSplitCandidate &split Data)636 VspSplitCandidate &splitCandidate) 636 637 { 637 638 float frontProb; 638 float back tProb;639 float backProb; 639 640 640 641 VspLeaf *leaf = dynamic_cast<VspLeaf *>(tData.mNode); … … 642 643 // compute locally best split plane 643 644 const bool success = 644 SelectPlane(tData, splitData.mSplitPlane, 645 frontProb, backtProb); 646 647 //TODO 645 SelectSplitPlane(tData, splitCandidate.mSplitPlane, frontProb, backProb); 646 648 647 // compute global decrease in render cost 649 splitData.mPriority = EvalRenderCostDecrease(splitData.mSplitPlane, tData); 650 splitData.mParentData = tData; 651 splitData.mMaxCostMisses = success ? tData.mMaxCostMisses : tData.mMaxCostMisses + 1; 648 splitCandidate.mPriority = EvalRenderCostDecrease(splitCandidate.mSplitPlane, tData); 649 splitCandidate.mParentData = tData; 650 splitCandidate.mMaxCostMisses = success ? tData.mMaxCostMisses : tData.mMaxCostMisses + 1; 651 652 Debug << "p: " << tData.mNode << " depth: " << tData.mDepth << endl; 652 653 } 653 654 … … 673 674 *backData.mRays); 674 675 676 Debug << "f: " << frontData.mRays->size() << " b: " << backData.mRays->size() << "d: " << tData.mRays->size() << endl; 675 677 //-- compute pvs 676 678 frontData.mPvs = ComputePvsSize(*frontData.mRays); … … 831 833 832 834 833 float VspTree:: BestCostRatioHeuristics(const RayInfoContainer &rays,834 835 836 837 835 float VspTree::EvalLocalCostHeuristics(const RayInfoContainer &rays, 836 const AxisAlignedBox3 &box, 837 const int pvsSize, 838 const int axis, 839 float &position) 838 840 { 839 841 const float minBox = box.Min(axis); … … 1003 1005 1004 1006 1005 float VspTree::Select Plane(const VspTraversalData &tData,1006 1007 1008 1007 float VspTree::SelectSplitPlane(const VspTraversalData &tData, 1008 AxisAlignedPlane &plane, 1009 float &pFront, 1010 float &pBack) 1009 1011 { 1010 1012 float nPosition[3]; … … 1019 1021 int bestAxis = -1; 1020 1022 1021 1022 1023 // if we use some kind of specialised fixed axis 1023 1024 const bool useSpecialAxis = 1024 1025 mOnlyDrivingAxis || mCirculatingAxis; 1025 1026 1027 int parentAxis = 0; 1028 VspNode *parent = tData.mNode->GetParent(); 1029 1030 if (parent) 1031 parentAxis = dynamic_cast<VspInterior *>(parent)->GetAxis(); 1032 1026 1033 if (mCirculatingAxis) 1027 sAxis = ( tData.mAxis + 1) % 3;1034 sAxis = (parentAxis + 1) % 3; 1028 1035 else if (mOnlyDrivingAxis) 1029 1036 sAxis = box.Size().DrivingAxis(); … … 1039 1046 { 1040 1047 nCostRatio[axis] = 1041 BestCostRatioHeuristics(*tData.mRays,1042 1048 EvalLocalCostHeuristics(*tData.mRays, 1049 box, 1043 1050 tData.mPvs, 1044 1051 axis, … … 1049 1056 nPosition[axis] = (box.Min()[axis] + box.Max()[axis]) * 0.5f; 1050 1057 1051 nCostRatio[axis] = Eval SplitCost(tData,1052 box,1053 axis,1054 nPosition[axis],1055 nProbFront[axis],1056 nProbBack[axis]);1058 nCostRatio[axis] = EvalLocalSplitCost(tData, 1059 box, 1060 axis, 1061 nPosition[axis], 1062 nProbFront[axis], 1063 nProbBack[axis]); 1057 1064 } 1058 1065 … … 1091 1098 const VspTraversalData &data) const 1092 1099 { 1100 #if 1 1101 return -data.mDepth; 1102 #endif 1093 1103 float pvsFront = 0; 1094 1104 float pvsBack = 0; … … 1112 1122 float t; 1113 1123 VssRay *ray = rayInf.mRay; 1124 1114 1125 const int cf = 1115 1126 rayInf.ComputeRayIntersection(candidatePlane.mAxis, … … 1120 1131 AddObjToPvs(ray->mOriginObject, cf, pvsFront, pvsBack, totalPvs); 1121 1132 } 1133 1122 1134 1123 1135 AxisAlignedBox3 frontBox; … … 1145 1157 const float renderCostDecrease = (oldRenderCost - newRenderCost) / mBoundingBox.GetVolume(); 1146 1158 1147 1148 #if 11149 1159 // take render cost of node into account 1150 1160 // otherwise danger of being stuck in a local minimum!! 1161 const float factor = 0.99f; 1162 1151 1163 const float normalizedOldRenderCost = oldRenderCost / mBoundingBox.GetVolume(); 1152 return 0.99f * renderCostDecrease + 0.01f * normalizedOldRenderCost; 1153 #else 1154 return renderCostDecrease; 1155 #endif 1156 } 1157 1158 1159 float VspTree::EvalSplitCost(const VspTraversalData &data, 1160 const AxisAlignedBox3 &box, 1161 const int axis, 1162 const float &position, 1163 float &pFront, 1164 float &pBack) const 1164 return factor * renderCostDecrease + (1.0f - factor) * normalizedOldRenderCost; 1165 } 1166 1167 1168 float VspTree::EvalLocalSplitCost(const VspTraversalData &data, 1169 const AxisAlignedBox3 &box, 1170 const int axis, 1171 const float &position, 1172 float &pFront, 1173 float &pBack) const 1165 1174 { 1166 1175 float pvsTotal = 0; … … 1190 1199 1191 1200 //-- compute heurstics 1192 //-- we take simplified computation for mid split 1193 1201 1194 1202 pOverall = data.mProbability; 1203 // we take simplified computation for mid split 1195 1204 pBack = pFront = pOverall * 0.5f; 1196 1205 … … 1210 1219 1211 1220 void VspTree::AddObjToPvs(Intersectable *obj, 1212 1213 1214 1215 1221 const int cf, 1222 float &frontPvs, 1223 float &backPvs, 1224 float &totalPvs) const 1216 1225 { 1217 1226 if (!obj) … … 1352 1361 ++ mCreatedViewCells; 1353 1362 1354 #ifdef _DEBUG1363 //#ifdef _DEBUG 1355 1364 Debug << "BSP stats: " 1356 1365 << "Depth: " << data.mDepth << " (max: " << mTermMaxDepth << "), " 1357 1366 << "PVS: " << data.mPvs << " (min: " << mTermMinPvs << "), " 1358 // << "Area: " << data.mProbability << " (min: " << mTermMinProbability << "), "1359 1367 << "#rays: " << (int)data.mRays->size() << " (max: " << mTermMinRays << "), " 1360 << "#pvs: " << leaf->GetViewCell()->GetPvs().GetSize() << " =, "1368 << "#pvs: " << leaf->GetViewCell()->GetPvs().GetSize() << "), " 1361 1369 << "#avg ray contrib (pvs): " << (float)data.mPvs / (float)data.mRays->size() << endl; 1362 #endif1370 //#endif 1363 1371 } 1364 1372 … … 1605 1613 1606 1614 if (GetBBox(interior->GetBack()).Side(plane) < 0) 1615 { 1607 1616 next = interior->GetFront(); 1617 } 1608 1618 else 1619 { 1609 1620 if (GetBBox(interior->GetFront()).Side(plane) < 0) 1621 { 1610 1622 next = interior->GetBack(); 1623 } 1611 1624 else 1612 1625 { … … 1618 1631 mask = mask >> 1; 1619 1632 } 1620 1621 nodeStack.push(next); 1633 } 1634 1635 nodeStack.push(next); 1622 1636 } 1623 1637 } … … 1704 1718 1705 1719 int VspTree::CastLineSegment(const Vector3 &origin, 1706 1707 1720 const Vector3 &termination, 1721 ViewCellContainer &viewcells) 1708 1722 { 1709 1723 int hits = 0; … … 1722 1736 VspNode *node = mRoot; 1723 1737 VspNode *farChild; 1738 1739 float position; 1740 int axis; 1741 1742 while (1) 1743 { 1744 if (!node->IsLeaf()) 1745 { 1746 VspInterior *in = dynamic_cast<VspInterior *>(node); 1747 position = in->GetPosition(); 1748 axis = in->GetAxis(); 1749 1750 if (entp[axis] <= position) 1751 { 1752 if (extp[axis] <= position) 1753 { 1754 node = in->GetFront(); 1755 // cases N1,N2,N3,P5,Z2,Z3 1756 continue; 1757 } else 1758 { 1759 // case N4 1760 node = in->GetFront(); 1761 farChild = in->GetBack(); 1762 } 1763 } 1764 else 1765 { 1766 if (position <= extp[axis]) 1767 { 1768 node = in->GetBack(); 1769 // cases P1,P2,P3,N5,Z1 1770 continue; 1771 } 1772 else 1773 { 1774 node = in->GetBack(); 1775 farChild = in->GetFront(); 1776 // case P4 1777 } 1778 } 1779 1780 // $$ modification 3.5.2004 - hints from Kamil Ghais 1781 // case N4 or P4 1782 const float tdist = (position - origin[axis]) / dir[axis]; 1783 tStack.push(LineTraversalData(farChild, extp, maxt)); //TODO 1784 1785 extp = origin + dir * tdist; 1786 maxt = tdist; 1787 } 1788 else 1789 { 1790 // compute intersection with all objects in this leaf 1791 VspLeaf *leaf = dynamic_cast<VspLeaf *>(node); 1792 ViewCell *vc = leaf->GetViewCell(); 1793 1794 if (!vc->Mailed()) 1795 { 1796 vc->Mail(); 1797 viewcells.push_back(vc); 1798 ++ hits; 1799 } 1800 #if 0 1801 leaf->mRays.push_back(RayInfo(new VssRay(origin, termination, NULL, NULL, 0))); 1802 #endif 1803 // get the next node from the stack 1804 if (tStack.empty()) 1805 break; 1806 1807 entp = extp; 1808 mint = maxt; 1809 1810 LineTraversalData &s = tStack.top(); 1811 node = s.mNode; 1812 extp = s.mExitPoint; 1813 maxt = s.mMaxT; 1814 tStack.pop(); 1815 } 1816 } 1817 1818 return hits; 1819 } 1820 1821 1822 int VspTree::CastRay(Ray &ray) 1823 { 1824 int hits = 0; 1825 1826 stack<LineTraversalData> tStack; 1827 const Vector3 dir = ray.GetDir(); 1828 1829 float maxt, mint; 1830 1831 if (!mBoundingBox.GetRaySegment(ray, mint, maxt)) 1832 return 0; 1833 1834 Intersectable::NewMail(); 1835 ViewCell::NewMail(); 1836 1837 Vector3 entp = ray.Extrap(mint); 1838 Vector3 extp = ray.Extrap(maxt); 1839 1840 const Vector3 origin = entp; 1841 1842 VspNode *node = mRoot; 1843 VspNode *farChild = NULL; 1724 1844 1725 1845 float position; … … 1741 1861 // cases N1,N2,N3,P5,Z2,Z3 1742 1862 continue; 1743 } else 1863 } 1864 else 1744 1865 { 1745 1866 // case N4 … … 1768 1889 const float tdist = (position - origin[axis]) / dir[axis]; 1769 1890 tStack.push(LineTraversalData(farChild, extp, maxt)); //TODO 1770 1771 1891 extp = origin + dir * tdist; 1772 1892 maxt = tdist; … … 1781 1901 { 1782 1902 vc->Mail(); 1783 viewcells.push_back(vc);1903 // todo: add view cells to ray 1784 1904 ++ hits; 1785 1905 } … … 1804 1924 return hits; 1805 1925 } 1806 1807 1808 int VspTree::CastRay(Ray &ray)1809 {1810 int hits = 0;1811 1812 stack<LineTraversalData> tStack;1813 const Vector3 dir = ray.GetDir();1814 1815 float maxt, mint;1816 1817 if (!mBoundingBox.GetRaySegment(ray, mint, maxt))1818 return 0;1819 1820 Intersectable::NewMail();1821 ViewCell::NewMail();1822 1823 Vector3 entp = ray.Extrap(mint);1824 Vector3 extp = ray.Extrap(maxt);1825 1826 const Vector3 origin = entp;1827 1828 VspNode *node = mRoot;1829 VspNode *farChild = NULL;1830 1831 float position;1832 int axis;1833 1834 while (1)1835 {1836 if (!node->IsLeaf())1837 {1838 VspInterior *in = dynamic_cast<VspInterior *>(node);1839 position = in->GetPosition();1840 axis = in->GetAxis();1841 1842 if (entp[axis] <= position)1843 {1844 if (extp[axis] <= position)1845 {1846 node = in->GetBack();1847 // cases N1,N2,N3,P5,Z2,Z31848 continue;1849 }1850 else1851 {1852 // case N41853 node = in->GetBack();1854 farChild = in->GetFront();1855 }1856 }1857 else1858 {1859 if (position <= extp[axis])1860 {1861 node = in->GetFront();1862 // cases P1,P2,P3,N5,Z11863 continue;1864 }1865 else1866 {1867 node = in->GetFront();1868 farChild = in->GetBack();1869 // case P41870 }1871 }1872 1873 // $$ modification 3.5.2004 - hints from Kamil Ghais1874 // case N4 or P41875 const float tdist = (position - origin[axis]) / dir[axis];1876 tStack.push(LineTraversalData(farChild, extp, maxt)); //TODO1877 extp = origin + dir * tdist;1878 maxt = tdist;1879 }1880 else1881 {1882 // compute intersection with all objects in this leaf1883 VspLeaf *leaf = dynamic_cast<VspLeaf *>(node);1884 ViewCell *vc = leaf->GetViewCell();1885 1886 if (!vc->Mailed())1887 {1888 vc->Mail();1889 // todo: add view cells to ray1890 ++ hits;1891 }1892 #if 01893 leaf->mRays.push_back(RayInfo(new VssRay(origin, termination, NULL, NULL, 0)));1894 #endif1895 // get the next node from the stack1896 if (tStack.empty())1897 break;1898 1899 entp = extp;1900 mint = maxt;1901 1902 LineTraversalData &s = tStack.top();1903 node = s.mNode;1904 extp = s.mExitPoint;1905 maxt = s.mMaxT;1906 tStack.pop();1907 }1908 }1909 1910 return hits;1911 }1912 1913 1914 VspNode *VspTree::CollapseTree(VspNode *node, int &collapsed)1915 {1916 // TODO1917 #if HAS_TO_BE_REDONE1918 if (node->IsLeaf())1919 return node;1920 1921 VspInterior *interior = dynamic_cast<VspInterior *>(node);1922 1923 VspNode *front = CollapseTree(interior->GetFront(), collapsed);1924 VspNode *back = CollapseTree(interior->GetBack(), collapsed);1925 1926 if (front->IsLeaf() && back->IsLeaf())1927 {1928 VspLeaf *frontLeaf = dynamic_cast<VspLeaf *>(front);1929 VspLeaf *backLeaf = dynamic_cast<VspLeaf *>(back);1930 1931 //-- collapse tree1932 if (frontLeaf->GetViewCell() == backLeaf->GetViewCell())1933 {1934 BspViewCell *vc = frontLeaf->GetViewCell();1935 1936 VspLeaf *leaf = new VspLeaf(interior->GetParent(), vc);1937 leaf->SetTreeValid(frontLeaf->TreeValid());1938 1939 // replace a link from node's parent1940 if (leaf->GetParent())1941 leaf->GetParent()->ReplaceChildLink(node, leaf);1942 else1943 mRoot = leaf;1944 1945 ++ collapsed;1946 delete interior;1947 1948 return leaf;1949 }1950 }1951 #endif1952 return node;1953 }1954 1955 1956 int VspTree::CollapseTree()1957 {1958 int collapsed = 0;1959 1960 (void)CollapseTree(mRoot, collapsed);1961 // revalidate leaves1962 RepairViewCellsLeafLists();1963 1964 return collapsed;1965 }1966 1967 1968 void VspTree::RepairViewCellsLeafLists()1969 {1970 // TODO1971 #if HAS_TO_BE_REDONE1972 // list not valid anymore => clear1973 stack<VspNode *> nodeStack;1974 nodeStack.push(mRoot);1975 1976 ViewCell::NewMail();1977 1978 while (!nodeStack.empty())1979 {1980 VspNode *node = nodeStack.top();1981 nodeStack.pop();1982 1983 if (node->IsLeaf())1984 {1985 VspLeaf *leaf = dynamic_cast<VspLeaf *>(node);1986 1987 BspViewCell *viewCell = leaf->GetViewCell();1988 1989 if (!viewCell->Mailed())1990 {1991 viewCell->mLeaves.clear();1992 viewCell->Mail();1993 }1994 1995 viewCell->mLeaves.push_back(leaf);1996 1997 }1998 else1999 {2000 VspInterior *interior = dynamic_cast<VspInterior *>(node);2001 2002 nodeStack.push(interior->GetFront());2003 nodeStack.push(interior->GetBack());2004 }2005 }2006 // TODO2007 #endif2008 }2009 2010 1926 2011 1927 … … 2171 2087 //-- test if start point behind or in front of plane 2172 2088 const int side = plane.ComputeRayIntersection(bRay, t); 2173 2089 #if 1 2174 2090 if (side == 0) 2175 2091 { … … 2195 2111 backRays.push_back(bRay); 2196 2112 } 2197 2113 #else 2114 if (side == 0) 2115 { 2116 ++ splits; 2117 2118 if (ray->HasPosDir(plane.mAxis)) 2119 { 2120 backRays.push_back(RayInfo(ray, bRay.GetMaxT(), t)); 2121 frontRays.push_back(RayInfo(ray, t, bRay.GetMinT())); 2122 } 2123 else 2124 { 2125 frontRays.push_back(RayInfo(ray, bRay.GetMaxT(), t)); 2126 backRays.push_back(RayInfo(ray, t, bRay.GetMinT())); 2127 } 2128 } 2129 else if (side == 1) 2130 { 2131 backRays.push_back(bRay); 2132 } 2133 else 2134 { 2135 frontRays.push_back(bRay); 2136 2137 } 2138 #endif 2198 2139 } 2199 2140 … … 2216 2157 AxisAlignedBox3 box(parent->GetBoundingBox()); 2217 2158 2218 if (parent->Get Front() == node)2159 if (parent->GetBack() == node) 2219 2160 box.SetMin(parent->GetAxis(), parent->GetPosition()); 2220 2161 else … … 2230 2171 ViewCellContainer &viewCells) const 2231 2172 { 2232 #if TODO 2233 stack<bspNodePair> nodeStack; 2234 BspNodeGeometry *rgeom = new BspNodeGeometry(); 2235 2236 ConstructGeometry(mRoot, *rgeom); 2237 2238 nodeStack.push(bspNodePair(mRoot, rgeom)); 2239 2173 stack<VspNode *> nodeStack; 2174 2240 2175 ViewCell::NewMail(); 2241 2176 2242 2177 while (!nodeStack.empty()) 2243 2178 { 2244 BspNode *node = nodeStack.top().first; 2245 BspNodeGeometry *geom = nodeStack.top().second; 2179 VspNode *node = nodeStack.top(); 2246 2180 nodeStack.pop(); 2247 2181 2248 const int side = geom->ComputeIntersection(box); 2249 2250 switch (side) 2251 { 2252 case -1: 2182 const AxisAlignedBox3 bbox = GetBBox(node); 2183 2184 if (bbox.Includes(box)) 2185 { 2253 2186 // node geometry is contained in box 2254 2187 CollectViewCells(node, true, viewCells, true); 2255 break;2256 2257 case 0:2188 } 2189 else if (Overlap(bbox, box)) 2190 { 2258 2191 if (node->IsLeaf()) 2259 2192 { … … 2268 2201 else 2269 2202 { 2270 BspInterior *interior = dynamic_cast<BspInterior *>(node);2203 VspInterior *interior = dynamic_cast<VspInterior *>(node); 2271 2204 2272 BspNode *first = interior->GetFront();2273 BspNode *second = interior->GetBack();2205 VspNode *first = interior->GetFront(); 2206 VspNode *second = interior->GetBack(); 2274 2207 2275 BspNodeGeometry *firstGeom = new BspNodeGeometry(); 2276 BspNodeGeometry *secondGeom = new BspNodeGeometry(); 2277 2278 geom->SplitGeometry(*firstGeom, 2279 *secondGeom, 2280 interior->GetPlane(), 2281 mBox, 2282 //0.0000001f); 2283 mEpsilon); 2284 2285 nodeStack.push(bspNodePair(first, firstGeom)); 2286 nodeStack.push(bspNodePair(second, secondGeom)); 2287 } 2288 2289 break; 2290 default: 2291 // default: cull 2292 break; 2293 } 2294 DEL_PTR(geom); 2295 } 2296 2297 #endif 2208 nodeStack.push(first); 2209 nodeStack.push(second); 2210 } 2211 } 2212 // default: cull 2213 } 2214 2298 2215 return (int)viewCells.size(); 2299 2216 } … … 2304 2221 /* class OspTree implementation */ 2305 2222 /*****************************************************************/ 2223 2306 2224 2307 2225 OspTree::OspTree(): … … 2499 2417 // create new interior node and two leaf node 2500 2418 const AxisAlignedPlane splitPlane = splitCandidate.mSplitPlane; 2419 2501 2420 newNode = SubdivideNode(dynamic_cast<KdLeaf *>(newNode), 2502 2421 splitPlane, … … 2635 2554 // << "Area: " << data.mProbability << " (min: " << mTermMinProbability << "), " 2636 2555 << "#rays: " << (int)data.mRays->size() << " (max: " << mTermMinRays << "), " 2637 << "#pvs: " << leaf->GetViewCell()->GetPvs().GetSize() << " =, "2556 << "#pvs: " << leaf->GetViewCell()->GetPvs().GetSize() << "), " 2638 2557 << "#avg ray contrib (pvs): " << (float)data.mPvs / (float)data.mRays->size() << endl; 2639 2558 #endif … … 2647 2566 /*********************************************************************/ 2648 2567 2649 HierarchyManager::HierarchyManager() 2568 HierarchyManager::HierarchyManager(VspTree &vspTree, OspTree &ospTree): 2569 mVspTree(vspTree), mOspTree(ospTree) 2650 2570 { 2651 2571 } … … 2655 2575 { 2656 2576 SplitCandidate *splitCandidate = mTQueue.top(); 2577 Debug << "priority: " << splitCandidate->GetPriority() << endl; 2657 2578 mTQueue.pop(); 2658 2579 … … 2662 2583 2663 2584 void HierarchyManager::PrepareConstruction(const VssRayContainer &sampleRays, 2585 const ObjectContainer &objects, 2664 2586 AxisAlignedBox3 *forcedViewSpace, 2665 2587 RayInfoContainer &rays) 2666 2588 { 2589 mVspTree.PrepareConstruction(sampleRays, forcedViewSpace); 2590 2591 long startTime = GetTime(); 2592 2593 cout << "storing rays ... "; 2594 2595 Intersectable::NewMail(); 2596 2667 2597 VssRayContainer::const_iterator rit, rit_end = sampleRays.end(); 2668 2669 long startTime = GetTime();2670 2671 cout << "storing rays ... ";2672 2673 Intersectable::NewMail();2674 2675 mVspTree->PrepareConstruction(sampleRays, forcedViewSpace);2676 2598 2677 2599 //-- store rays … … 2684 2606 static Ray hray; 2685 2607 hray.Init(*ray); 2686 2608 2687 2609 // TODO: not very efficient to implictly cast between rays types 2688 if (m BoundingBox.GetRaySegment(hray, minT, maxT))2610 if (mVspTree.GetBoundingBox().GetRaySegment(hray, minT, maxT)) 2689 2611 { 2690 2612 float len = ray->Length(); … … 2697 2619 } 2698 2620 2699 cout << "finished" << endl; 2621 cout << "finished in " << TimeDiff(startTime, GetTime()) * 1e-3 << " secs" << endl; 2622 2623 /// add first candidate for view space partition 2624 mVspTree.mRoot = new VspLeaf(); 2625 const float prop = mVspTree.mBoundingBox.GetVolume(); 2626 2627 /// first traversal data 2628 VspTree::VspTraversalData tData(mVspTree.mRoot, 2629 0, 2630 &rays, 2631 (int)objects.size(), 2632 //mVspTree.ComputePvsSize(rays), 2633 prop, 2634 mVspTree.mBoundingBox); 2635 2636 // compute first split candidate 2637 VspTree::VspSplitCandidate *splitCandidate = new VspTree::VspSplitCandidate(); 2638 mVspTree.EvalSplitCandidate(tData, *splitCandidate); 2639 2640 mTQueue.push(splitCandidate); 2700 2641 2701 2642 //mOspTree->PrepareConstruction(sampleRays, forcedViewSpace, rays); … … 2710 2651 dynamic_cast<VspTree::VspSplitCandidate *>(candidate); 2711 2652 2712 return mVspTree ->GlobalTerminationCriteriaMet(sc->mParentData);2653 return mVspTree.GlobalTerminationCriteriaMet(sc->mParentData); 2713 2654 } 2714 2655 … … 2724 2665 2725 2666 // prepare vsp and osp trees for traversal 2726 PrepareConstruction(sampleRays, forcedViewSpace, *rays); 2727 2728 mVspTree->mVspStats.Start(); 2667 PrepareConstruction(sampleRays, objects, forcedViewSpace, *rays); 2668 2669 mVspTree.mVspStats.Reset(); 2670 mVspTree.mVspStats.Start(); 2729 2671 2730 2672 cout << "Constructing view space / object space tree ... \n"; … … 2738 2680 GlobalTerminationCriteriaMet(splitCandidate); 2739 2681 2682 Debug << "cost: " << splitCandidate->GetPriority(); 2683 2740 2684 // cost ratio of cost decrease / totalCost 2741 2685 const float costRatio = splitCandidate->GetPriority() / mTotalCost; … … 2744 2688 if (costRatio < mTermMinGlobalCostRatio) 2745 2689 ++ mGlobalCostMisses; 2746 2690 2747 2691 //-- subdivide leaf node 2748 2692 //-- either a object space or view space split … … 2752 2696 dynamic_cast<VspTree::VspSplitCandidate *>(splitCandidate); 2753 2697 2754 VspNode *r = mVspTree ->Subdivide(mTQueue, *sc, globalTerminationCriteriaMet);2698 VspNode *r = mVspTree.Subdivide(mTQueue, *sc, globalTerminationCriteriaMet); 2755 2699 } 2756 2700 else // object space split 2757 2701 { 2758 2702 #if TODO 2759 KdNode *r = mKdtree ->Subdivide(tOspQueue, dynamic_cast<OspSplitCandidate<(splitCandidate));2703 KdNode *r = mKdtree.Subdivide(tOspQueue, dynamic_cast<OspSplitCandidate<(splitCandidate)); 2760 2704 #endif 2761 2705 } … … 2766 2710 cout << "finished in " << TimeDiff(startTime, GetTime())*1e-3 << "secs" << endl; 2767 2711 2768 mVspTree ->mVspStats.Stop();2712 mVspTree.mVspStats.Stop(); 2769 2713 } 2770 2714 -
GTP/trunk/Lib/Vis/Preprocessing/src/VspOspTree.h
r1023 r1027 34 34 class KdTreeStatistics; 35 35 36 template <typename T> class GtPriority 37 { 38 public: 39 bool operator() (const T c1, const T c2) const 40 { 41 //return false; 42 return c1->GetPriority() < c2->GetPriority(); 43 } 44 }; 45 36 46 /** A definition for an axis aligned plane. 37 47 */ … … 84 94 float GetPriority() const 85 95 { 86 #if 187 96 return mPriority; 88 #else89 return (float) (-mDepth); // for kd tree90 #endif91 97 } 92 98 93 friend bool operator<(const SplitCandidate &a, const SplitCandidate &b)99 /*friend bool operator<(const SplitCandidate &a, const SplitCandidate &b) 94 100 { 95 101 return a.GetPriority() < b.GetPriority(); 96 } 102 }*/ 97 103 }; 98 104 … … 461 467 462 468 463 typedef std::priority_queue<SplitCandidate *> SplitQueue; 464 469 typedef std::priority_queue<SplitCandidate *, 470 std::vector<SplitCandidate *>, 471 GtPriority<std::vector<SplitCandidate *>::value_type> > SplitQueue; 465 472 466 473 #if TODO … … 511 518 /// how often this branch has missed the max-cost ratio 512 519 int mMaxCostMisses; 513 // current axis514 int mAxis;515 520 // current priority 516 521 float mPriority; … … 532 537 mProbability(0.0), 533 538 mMaxCostMisses(0), 534 mPriority(0), 535 mAxis(0) 539 mPriority(0) 536 540 {} 537 541 … … 549 553 mBoundingBox(box), 550 554 mMaxCostMisses(0), 551 mPriority(0), 552 mAxis(0) 555 mPriority(0) 553 556 {} 554 557 … … 562 565 mProbability(0), 563 566 mMaxCostMisses(0), 564 mAxis(0),565 567 mBoundingBox(box) 566 568 {} … … 698 700 */ 699 701 void SetViewCellsManager(ViewCellsManager *vcm); 700 701 702 /** Collapses the tree with respect to the view cell partition.703 @returns number of collapsed nodes704 */705 int CollapseTree();706 702 707 703 /** Returns view cell the current point is located in. … … 785 781 } 786 782 787 friend bool operator<(const SortableEntry &a, const SortableEntry &b) 783 friend bool operator<(const SortableEntry &a, const SortableEntry &b) 788 784 { 789 785 return a.value < b.value; … … 793 789 /** faster evaluation of split plane cost for kd axis aligned cells. 794 790 */ 795 float Eval SplitCost(const VspTraversalData &data,796 const AxisAlignedBox3 &box,797 const int axis,798 const float &position,799 float &pFront,800 float &pBack) const;791 float EvalLocalSplitCost(const VspTraversalData &data, 792 const AxisAlignedBox3 &box, 793 const int axis, 794 const float &position, 795 float &pFront, 796 float &pBack) const; 801 797 802 798 void PrepareConstruction(const VssRayContainer &sampleRays, … … 806 802 */ 807 803 void EvalSplitCandidate(VspTraversalData &tData, VspSplitCandidate &splitData); 808 809 /** Computes priority of the traversal data and stores it in tData.810 */811 void EvalPriority(VspTraversalData &tData) const;812 804 813 805 /** Evaluates render cost decrease of next split. … … 882 874 @returns cost for this split 883 875 */ 884 float Select Plane(const VspTraversalData &tData,885 AxisAlignedPlane &plane,886 float &pFront,887 float &pBack);876 float SelectSplitPlane(const VspTraversalData &tData, 877 AxisAlignedPlane &plane, 878 float &pFront, 879 float &pBack); 888 880 889 881 /** Sorts split candidates for surface area heuristics for axis aligned splits. … … 899 891 /** Computes best cost for axis aligned planes. 900 892 */ 901 float BestCostRatioHeuristics(const RayInfoContainer &rays,893 float EvalLocalCostHeuristics(const RayInfoContainer &rays, 902 894 const AxisAlignedBox3 &box, 903 895 const int pvsSize, … … 1339 1331 /** faster evaluation of split plane cost for kd axis aligned cells. 1340 1332 */ 1341 float Eval SplitCost(const OspTraversalData &data,1342 const AxisAlignedBox3 &box,1343 const int axis,1344 const float &position,1345 float &pFront,1346 float &pBack) const;1333 float EvalLocalSplitCost(const OspTraversalData &data, 1334 const AxisAlignedBox3 &box, 1335 const int axis, 1336 const float &position, 1337 float &pFront, 1338 float &pBack) const; 1347 1339 1348 1340 /** Evaluates candidate for splitting. … … 1429 1421 /** Computes best cost for axis aligned planes. 1430 1422 */ 1431 float BestCostRatioHeuristics(const RayInfoContainer &rays,1423 float EvalLocalCostHeuristics(const RayInfoContainer &rays, 1432 1424 const AxisAlignedBox3 &box, 1433 1425 const int pvsSize, … … 1622 1614 class HierarchyManager 1623 1615 { 1624 /** Default constructor. 1625 */ 1626 HierarchyManager(); 1616 public: 1617 /** Constructor taking an object space partition and a view space partition tree. 1618 */ 1619 HierarchyManager(VspTree &vspTree, OspTree &ospTree); 1627 1620 1628 1621 /** Constructs the view space and object space subdivision from a given set of rays … … 1636 1629 1637 1630 public: 1638 VspTree *mVspTree;1639 OspTree *mOspTree;1631 VspTree &mVspTree; 1632 OspTree &mOspTree; 1640 1633 1641 1634 protected: … … 1644 1637 1645 1638 void PrepareConstruction(const VssRayContainer &sampleRays, 1639 const ObjectContainer &objects, 1646 1640 AxisAlignedBox3 *forcedViewSpace, 1647 1641 RayInfoContainer &rays); -
GTP/trunk/Lib/Vis/Preprocessing/src/VssPreprocessor.cpp
r1004 r1027 616 616 if (!mLoadViewCells) 617 617 { 618 Debug << "here923 " << vbox << endl; 618 619 mViewCellsManager->SetViewSpaceBox(vbox); 619 620 // construct view cells using it's own set of samples
Note: See TracChangeset
for help on using the changeset viewer.