Changeset 1294
- Timestamp:
- 08/29/06 17:34:19 (18 years ago)
- Location:
- GTP/trunk/Lib/Vis/Preprocessing/src
- Files:
-
- 13 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/Lib/Vis/Preprocessing/src/BvHierarchy.cpp
r1293 r1294 213 213 Environment::GetSingleton()->GetFloatValue("BvHierarchy.Termination.minGlobalCostRatio", 214 214 mTermMinGlobalCostRatio); 215 Environment::GetSingleton()->GetIntValue("BvHierarchy.Termination.globalCostMissTolerance", mTermGlobalCostMissTolerance); 215 Environment::GetSingleton()->GetIntValue("BvHierarchy.Termination.globalCostMissTolerance", 216 mTermGlobalCostMissTolerance); 216 217 217 218 //-- factors for bsp tree split plane heuristics … … 285 286 // add the new nodes to the tree 286 287 BvhInterior *node = new BvhInterior(tData.mBoundingBox, leaf->GetParent()); 287 //cout << "bbox: " << tData.mBoundingBox << endl; 288 288 289 289 290 290 //-- the front and back traversal data is filled with the new values … … 292 292 frontData.mDepth = backData.mDepth = tData.mDepth + 1; 293 293 294 frontData.mBoundingBox = ComputeBoundingBox(frontObjects, & (tData.mBoundingBox));295 backData.mBoundingBox = ComputeBoundingBox(backObjects, & (tData.mBoundingBox));294 frontData.mBoundingBox = ComputeBoundingBox(frontObjects, &tData.mBoundingBox); 295 backData.mBoundingBox = ComputeBoundingBox(backObjects, &tData.mBoundingBox); 296 296 297 297 ///////////// … … 354 354 if (!LocalTerminationCriteriaMet(tData) && !globalCriteriaMet) 355 355 { 356 //-- continue subdivision 357 356 358 BvhTraversalData tFrontData; 357 359 BvhTraversalData tBackData; 358 359 //-- continue subdivision 360 360 361 361 // create new interior node and two leaf node 362 362 newNode = SubdivideNode(sc->mFrontObjects, … … 392 392 393 393 // delete old leaf node 394 DEL_PTR(tData.mNode);394 //DEL_PTR(tData.mNode); 395 395 } 396 396 … … 409 409 CollectRays(leaf->mObjects, leaf->mVssRays); 410 410 } 411 } 412 413 tData.Clear(); // cleanup 411 412 // detach node so it won't get deleted 413 tData.mNode = NULL; 414 } 414 415 415 416 return newNode; … … 447 448 const float renderCostDecr = oldRenderCost - newRenderCost; 448 449 449 //Debug << "render cost decr: " << renderCostDecr << endl;450 Debug << "\nbvh render cost decr: " << renderCostDecr << endl; 450 451 splitCandidate.SetRenderCostDecrease(renderCostDecr); 451 452 452 #if 0453 const float priority = (float)- data.mDepth;453 #if 1 454 const float priority = (float)-splitCandidate.mParentData.mDepth; 454 455 #else 455 456 // take render cost of node into account … … 469 470 // matt: TODO 470 471 return ( 0 471 || (data.mNode->mObjects.size() < mTermMinObjects)472 || (data.mProbability <= mTermMinProbability)473 || (data.mDepth >= mTermMaxDepth)472 //|| ((int)data.mNode->mObjects.size() < mTermMinObjects) 473 //|| (data.mProbability <= mTermMinProbability) 474 //|| (data.mDepth >= mTermMaxDepth) 474 475 ); 475 476 } … … 536 537 AxisAlignedBox3 box = obj->GetBox(); 537 538 538 const float objMid = (box.Max(axis) + box.Min(axis)) * 0.5 ;539 const float objMid = (box.Max(axis) + box.Min(axis)) * 0.5f; 539 540 540 541 // object mailed => belongs to back objects … … 936 937 937 938 const float viewSpaceVol = mVspTree->GetBoundingBox().GetVolume(); 938 Debug << "\n***** eval render cost *********\n"939 /*Debug << "\nbvh render cost\n" 939 940 << "back p: " << pBack / viewSpaceVol << " front p " << pFront / viewSpaceVol << endl 940 << "new rc: " << newRenderCost / viewSpaceVol << endl; 941 << "new rc: " << newRenderCost / viewSpaceVol << endl;*/ 941 942 942 943 … … 1319 1320 } 1320 1321 1322 void BvHierarchy::CreateRoot(const ObjectContainer &objects) 1323 { 1324 //-- create new root 1325 AxisAlignedBox3 box = ComputeBoundingBox(objects); 1326 BvhLeaf *bvhleaf = new BvhLeaf(box, NULL, (int)objects.size()); 1327 bvhleaf->mObjects = objects; 1328 1329 mRoot = bvhleaf; 1330 1331 // associate root with current objects 1332 AssociateObjectsWithLeaf(bvhleaf); 1333 } 1334 1321 1335 1322 1336 SubdivisionCandidate *BvHierarchy::PrepareConstruction(const VssRayContainer &sampleRays, 1323 const ObjectContainer &objects 1324 //,AxisAlignedBox3 *forcedObjectSpace 1325 ) 1337 const ObjectContainer &objects) 1326 1338 { 1327 1339 // note matt: we assume that we have objects sorted by their id … … 1332 1344 1333 1345 // compute bounding box from objects 1334 mBoundingBox = ComputeBoundingBox(objects); 1346 // we assume that root was already created 1347 mBoundingBox = mRoot->GetBoundingBox(); 1348 BvhLeaf *bvhleaf = dynamic_cast<BvhLeaf *>(mRoot); 1335 1349 1336 1350 mTermMinProbability *= mBoundingBox.GetVolume(); 1337 1351 mGlobalCostMisses = 0; 1338 1352 1339 //-- create new root1340 1341 BvhLeaf *bvhleaf = new BvhLeaf(mBoundingBox, NULL, (int)objects.size());1342 bvhleaf->mObjects = objects;1343 mRoot = bvhleaf;1344 1345 1353 // only rays intersecting objects in node are interesting 1346 1354 AssociateObjectsWithRays(sampleRays); 1347 // associate root with current objects 1348 AssociateObjectsWithLeaf(bvhleaf); 1349 1350 //-- add first candidate for object space partition 1351 1355 1356 1352 1357 // probabilty is voume of all "seen" view cells 1353 1358 #if 1 1354 const float prop = EvalViewCellsVolume( bvhleaf->mObjects);1359 const float prop = EvalViewCellsVolume(objects); 1355 1360 #else 1356 1361 const float prop = GetBoundingBox().GetVolume(); … … 1360 1365 BvhTraversalData oData(bvhleaf, 0, mBoundingBox, prop); 1361 1366 1362 //-- first split candidate1367 //-- add first candidate for object space partition 1363 1368 BvhSubdivisionCandidate *oSubdivisionCandidate = 1364 1369 new BvhSubdivisionCandidate(oData); -
GTP/trunk/Lib/Vis/Preprocessing/src/BvHierarchy.h
r1291 r1294 134 134 virtual bool IsLeaf() const = 0; 135 135 136 //virtual int Type() const = 0;137 138 136 /** Determines whether this node is a root 139 137 @return true if root … … 205 203 */ 206 204 bool IsLeaf() const; 207 //int Type() const; 208 205 209 206 BvhNode *GetBack() { return mBack; } 210 207 BvhNode *GetFront() { return mFront; } … … 249 246 bool IsLeaf() const; 250 247 251 //int Type() const;252 253 248 SubdivisionCandidate *GetSubdivisionCandidate() const 254 249 { … … 292 287 { 293 288 public: 294 /// the current node 295 BvhLeaf *mNode; 296 /// current depth 297 int mDepth; 298 /// the probability that this node is seen 299 float mProbability; 300 /// the bounding box of the node 301 AxisAlignedBox3 mBoundingBox; 302 /// how often this branch has missed the max-cost ratio 303 int mMaxCostMisses; 304 /// current axis 305 int mAxis; 306 /// current priority 307 float mPriority; 308 309 289 310 290 BvhTraversalData(): 311 291 mNode(NULL), … … 335 315 float GetCost() const 336 316 { 337 //cout << mPriority << endl;338 317 return mPriority; 339 318 } … … 342 321 void Clear() 343 322 { 344 //DEL_PTR(mRays);323 DEL_PTR(mNode); 345 324 } 325 326 /// the current node 327 BvhLeaf *mNode; 328 /// current depth 329 int mDepth; 330 /// the probability that this node is seen 331 float mProbability; 332 /// the bounding box of the node 333 AxisAlignedBox3 mBoundingBox; 334 /// how often this branch has missed the max-cost ratio 335 int mMaxCostMisses; 336 /// current axis 337 int mAxis; 338 /// current priority 339 float mPriority; 340 346 341 347 342 friend bool operator<(const BvhTraversalData &a, const BvhTraversalData &b) … … 356 351 { 357 352 public: 358 static BvHierarchy *sBvHierarchy; 359 360 /// parent data 361 BvhTraversalData mParentData; 362 ObjectContainer mFrontObjects; 363 ObjectContainer mBackObjects; 364 365 BvhSubdivisionCandidate(const BvhTraversalData &tData): mParentData(tData) 353 354 BvhSubdivisionCandidate(const BvhTraversalData &tData): mParentData(tData) 366 355 {}; 356 357 ~BvhSubdivisionCandidate() { mParentData.Clear(); } 367 358 368 359 int Type() const { return OBJECT_SPACE; } … … 377 368 return sBvHierarchy->GlobalTerminationCriteriaMet(mParentData); 378 369 } 379 380 370 381 371 BvhSubdivisionCandidate( … … 385 375 mFrontObjects(frontObjects), mBackObjects(backObjects), mParentData(tData) 386 376 {} 377 378 379 static BvHierarchy *sBvHierarchy; 380 381 /// parent data 382 BvhTraversalData mParentData; 383 ObjectContainer mFrontObjects; 384 ObjectContainer mBackObjects; 387 385 }; 388 386 … … 401 399 }; 402 400 403 //typedef std::priority_queue<VspTraversalData> VspOspTraversalQueue;404 401 405 402 /** Default constructor creating an empty tree. … … 616 613 float GetMemUsage() const; 617 614 618 615 /** Creates new root of hierarchy. 616 */ 617 void CreateRoot(const ObjectContainer &objects); 619 618 620 619 ///////////////////////////// -
GTP/trunk/Lib/Vis/Preprocessing/src/Environment.cpp
r1293 r1294 1497 1497 "0"); 1498 1498 1499 RegisterOption("ViewCells.storeKdPvs", 1500 optBool, 1501 "view_cells_store_kd_pvs=", 1502 "false"); 1503 1504 1499 1505 1500 /************************************************************************************/ 1506 1501 /* Render simulation related options */ … … 2220 2215 "vsp_construction_max_band=", 2221 2216 "0.99"); 2222 2223 RegisterOption("VspTree.useKdPvsForHeuristics",2224 optBool,2225 "vsp_use_kd_pvs_for_heuristics=",2226 "true");2227 2228 RegisterOption("VspTree.storeKdPvs",2229 optBool,2230 "vsp_store_kd_pvs=",2231 "true");2232 2217 2233 2218 RegisterOption("VspTree.maxTests", … … 2241 2226 /* Object space partition tree related options */ 2242 2227 /***********************************************************************/ 2228 2243 2229 2244 2230 RegisterOption("OspTree.Construction.randomize", -
GTP/trunk/Lib/Vis/Preprocessing/src/GzBinFileInputStream.h
r1264 r1294 111 111 // Unimplemented constructors and operators 112 112 // ----------------------------------------------------------------------- 113 113 114 GzBinFileInputStream(const GzBinFileInputStream&); 114 115 GzBinFileInputStream& operator=(const GzBinFileInputStream&); … … 121 122 // per platform. 122 123 // ----------------------------------------------------------------------- 124 123 125 FileHandle fSource; 124 126 MemoryManager* const fMemoryManager; … … 129 131 // GzBinFileInputStream: Getter methods 130 132 // --------------------------------------------------------------------------- 133 131 134 inline bool GzBinFileInputStream::getIsOpen() const 132 135 { 133 return (mStream.is_open());//(fSource != 0);136 return bool (mStream.is_open());//(fSource != 0); 134 137 } 135 138 -
GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.cpp
r1293 r1294 97 97 98 98 Environment::GetSingleton()->GetIntValue( 99 "Hierarchy.Termination.maxLeaves", mTermMaxLeaves); 100 101 Environment::GetSingleton()->GetIntValue( 99 102 "Hierarchy.Construction.type", mConstructionType); 100 103 101 //Debug << "max depth: " << mTermMaxDepth << endl; 104 Debug << "******** Hierachy Manager Parameters ***********" << endl; 105 Debug << "max leaves: " << mTermMaxLeaves << endl; 102 106 Debug << "min global cost ratio: " << mTermMinGlobalCostRatio << endl; 103 107 Debug << "global cost miss tolerance: " << mTermGlobalCostMissTolerance << endl; … … 145 149 RayInfoContainer &objectSpaceRays) 146 150 { 147 SubdivisionCandidate *vsc = 148 mVspTree->PrepareConstruction(sampleRays, forcedViewSpace, viewSpaceRays); 149 150 mTQueue.Push(vsc); 151 152 SubdivisionCandidate *osc; 151 mHierarchyStats.Reset(); 152 mHierarchyStats.Start(); 153 153 154 154 switch (mObjectSpaceSubdivisonType) 155 155 { 156 156 case KD_BASED_OBJ_SUBDIV: 157 osc = mOspTree->PrepareConstruction(sampleRays, objects, objectSpaceRays); 158 mTQueue.Push(osc); 159 break; 160 case BV_BASED_OBJ_SUBDIV: 161 osc = mBvHierarchy->PrepareConstruction(sampleRays, objects); 162 mTQueue.Push(osc); 163 break; 164 default: 165 break; 166 } 157 { 158 SubdivisionCandidate *vsc = 159 mVspTree->PrepareConstruction(sampleRays, forcedViewSpace, viewSpaceRays); 160 mTQueue.Push(vsc); 161 162 SubdivisionCandidate *osc; 163 osc = mOspTree->PrepareConstruction(sampleRays, objects, objectSpaceRays); 164 mTQueue.Push(osc); 165 } 166 break; 167 case BV_BASED_OBJ_SUBDIV: 168 { 169 mBvHierarchy->CreateRoot(objects); 170 171 SubdivisionCandidate *vsc = 172 mVspTree->PrepareConstruction(sampleRays, forcedViewSpace, viewSpaceRays); 173 mTQueue.Push(vsc); 174 175 SubdivisionCandidate *osc; 176 osc = mBvHierarchy->PrepareConstruction(sampleRays, objects); 177 mTQueue.Push(osc); 178 } 179 break; 180 default: 181 break; 182 } 183 184 mTotalCost = (float)objects.size(); 185 Debug << " setting total cost to " << mTotalCost << endl; 167 186 } 168 187 … … 211 230 { 212 231 return (0 213 || (mHierarchyStats.Leaves() >= m MaxLeaves)214 || (mGlobalCostMisses >= mTermGlobalCostMissTolerance)215 || candidate->GlobalTerminationCriteriaMet()232 || (mHierarchyStats.Leaves() >= mTermMaxLeaves) 233 //|| (mGlobalCostMisses >= mTermGlobalCostMissTolerance) 234 //|| candidate->GlobalTerminationCriteriaMet() 216 235 ); 217 236 } … … 250 269 *objectSpaceRays); 251 270 252 mHierarchyStats.Reset();253 mHierarchyStats.Start();254 271 255 272 cout << "Constructing view space / object space tree ... \n"; 256 273 const long startTime = GetTime(); 257 274 258 RunConstruction(true); 275 const bool repairQueue = true; 276 277 // process object space candidates 278 RunConstruction(repairQueue); 259 279 260 280 cout << "finished in " << TimeDiff(startTime, GetTime())*1e-3 << " secs" << endl; … … 264 284 265 285 286 void HierarchyManager::ConstructBvHierarchy(const VssRayContainer &sampleRays, 287 const ObjectContainer &objects) 288 289 { 290 Debug << "\n$$$$$$$$$ bv hierarchy construction $$$$$$$$$$\n" << endl; 291 cout << "starting bv hierarchy construction ... " << endl; 292 293 mBvHierarchy->CreateRoot(objects); 294 295 // compute first candidate 296 SubdivisionCandidate *sc = 297 mBvHierarchy->PrepareConstruction(sampleRays, objects); 298 299 mTotalCost = mBvHierarchy->mTotalCost; 300 Debug << "reseting cost, new total cost: " << mTotalCost << endl; 301 302 mTQueue.Push(sc); 303 304 mBvHierarchy->mBvhStats.Reset(); 305 mBvHierarchy->mBvhStats.Start(); 306 307 const long startTime = GetTime(); 308 const bool repairQueue = false; 309 310 cout << "finished in " << TimeDiff(startTime, GetTime()) * 1e-3 << " secs" << endl; 311 312 mBvHierarchy->mBvhStats.Stop(); 313 } 314 315 316 void HierarchyManager::ConstructOspTree(const VssRayContainer &sampleRays, 317 const ObjectContainer &objects) 318 319 { 320 RayInfoContainer *objectSpaceRays = new RayInfoContainer(); 321 322 Debug << "\n$$$$$$$$$ osp tree construction $$$$$$$$$$\n" << endl; 323 cout << "starting osp tree construction ... " << endl; 324 325 // start with one big kd cell - all objects can be seen from everywhere 326 // note: only true for view space = object space 327 328 // compute first candidate 329 SubdivisionCandidate *osc = 330 mOspTree->PrepareConstruction(sampleRays, objects, *objectSpaceRays); 331 332 mTotalCost = mOspTree->mTotalCost; 333 Debug << "reseting cost, new total cost: " << mTotalCost << endl; 334 335 mTQueue.Push(osc); 336 337 mOspTree->mOspStats.Reset(); 338 mOspTree->mOspStats.Start(); 339 340 const long startTime = GetTime(); 341 342 cout << "finished in " << TimeDiff(startTime, GetTime()) * 1e-3 << " secs" << endl; 343 344 mOspTree->mOspStats.Stop(); 345 346 ////////////////////////// 347 // matt: only for debugging purpose 348 349 const float rc = mOspTree->EvalRenderCost(sampleRays); 350 351 Debug << "My render cost evalulation: " << rc << endl; 352 } 353 354 355 266 356 bool HierarchyManager::ApplySubdivisionCandidate(SubdivisionCandidate *sc) 267 357 { 268 358 const bool globalTerminationCriteriaMet = GlobalTerminationCriteriaMet(sc); 269 270 359 const bool vspSplit = (sc->Type() == SubdivisionCandidate::VIEW_SPACE); 271 360 … … 289 378 { 290 379 BvhNode *n = mBvHierarchy->Subdivide(mTQueue, sc, globalTerminationCriteriaMet); 380 291 381 if (n->IsLeaf()) // local or global termination criteria failed 292 382 return false; … … 305 395 while (!FinishedConstruction()) 306 396 { 307 SubdivisionCandidate *splitCandidate = NextSubdivisionCandidate();397 mCurrentCandidate = NextSubdivisionCandidate(); 308 398 309 mTotalCost -= splitCandidate->GetRenderCostDecrease();399 mTotalCost -= mCurrentCandidate->GetRenderCostDecrease(); 310 400 311 401 // cost ratio of cost decrease / totalCost 312 const float costRatio = splitCandidate->GetRenderCostDecrease() / mTotalCost;402 const float costRatio = mCurrentCandidate->GetRenderCostDecrease() / mTotalCost; 313 403 314 404 //Debug << "ratio: " << costRatio << " min ratio: " << mTermMinGlobalCostRatio << endl; … … 318 408 //-- subdivide leaf node 319 409 320 if (ApplySubdivisionCandidate( splitCandidate))410 if (ApplySubdivisionCandidate(mCurrentCandidate)) 321 411 { 322 412 mHierarchyStats.nodes += 2; 323 413 324 414 // subdivision successful 325 EvalSubdivisionStats(* splitCandidate);415 EvalSubdivisionStats(*mCurrentCandidate); 326 416 327 417 // reevaluate candidates affected by the split … … 330 420 if (repair) RepairQueue(); 331 421 332 cout << "candidate: " << splitCandidate->Type() << ", priority: "333 << splitCandidate->GetPriority() << endl;334 } 335 336 DEL_PTR( splitCandidate);422 cout << "candidate: " << mCurrentCandidate->Type() << ", priority: " 423 << mCurrentCandidate->GetPriority() << endl; 424 } 425 426 DEL_PTR(mCurrentCandidate); 337 427 } 338 428 } … … 345 435 346 436 347 void HierarchyManager::CollectObjectSpaceDirtyList( 348 SubdivisionCandidateContainer &dirtyList) 437 void HierarchyManager::CollectObjectSpaceDirtyList(SubdivisionCandidateContainer &dirtyList) 349 438 { 350 439 switch (mObjectSpaceSubdivisonType) … … 383 472 void HierarchyManager::CollectDirtyCandidates(SubdivisionCandidateContainer &dirtyList) 384 473 { 474 Debug << "here65" << endl; 385 475 // we have either a object space or view space split 386 476 if (mCurrentCandidate->Type() == SubdivisionCandidate::VIEW_SPACE) 387 477 { 478 Debug << "collected view space candidate" << endl; 388 479 CollectViewSpaceDirtyList(dirtyList); 389 480 } 390 481 else // object space split 391 482 { 483 Debug << "collecting object space candidate" << endl; 392 484 CollectObjectSpaceDirtyList(dirtyList); 393 485 } … … 423 515 for (sit = dirtyList.begin(); sit != sit_end; ++ sit) 424 516 { 517 Debug << "here4423" << endl; 425 518 SubdivisionCandidate* sc = *sit; 426 519 … … 428 521 429 522 // reevaluate 430 sc->EvalPriority();523 //sc->EvalPriority(); 431 524 432 525 // reinsert … … 553 646 RayInfoContainer *viewSpaceRays = new RayInfoContainer(); 554 647 648 555 649 ///////////////////////////////////////////////////////////// 556 650 // view space space partition 557 651 ///////////////////////////////////////////////////////////// 558 652 653 559 654 // use objects for evaluating vsp tree construction 560 655 const int savedobjectSpaceSubdivisionType = mObjectSpaceSubdivisonType; … … 610 705 break; 611 706 } 612 }613 614 615 void HierarchyManager::ConstructBvHierarchy(const VssRayContainer &sampleRays,616 const ObjectContainer &objects617 //,AxisAlignedBox3 *forcedViewSpace618 )619 620 {621 Debug << "\n$$$$$$$$$ bv hierarchy construction $$$$$$$$$$\n" << endl;622 cout << "starting bv hierarchy construction ... " << endl;623 624 //ObjectContainer obj = objects;625 626 // compute first candidate627 SubdivisionCandidate *sc =628 mBvHierarchy->PrepareConstruction(sampleRays, objects);629 630 mTotalCost = mBvHierarchy->mTotalCost;631 Debug << "reseting cost, new total cost: " << mTotalCost << endl;632 633 mTQueue.Push(sc);634 635 mBvHierarchy->mBvhStats.Reset();636 mBvHierarchy->mBvhStats.Start();637 638 const long startTime = GetTime();639 const bool repairQueue = false;640 707 641 708 // process object space candidates 642 709 RunConstruction(repairQueue); 643 644 cout << "finished in " << TimeDiff(startTime, GetTime()) * 1e-3 << " secs" << endl; 645 646 mBvHierarchy->mBvhStats.Stop(); 647 } 648 649 650 void HierarchyManager::ConstructOspTree(const VssRayContainer &sampleRays, 651 const ObjectContainer &objects) 652 653 { 654 RayInfoContainer *objectSpaceRays = new RayInfoContainer(); 655 656 Debug << "\n$$$$$$$$$ osp tree construction $$$$$$$$$$\n" << endl; 657 cout << "starting osp tree construction ... " << endl; 658 659 // start with one big kd cell - all objects can be seen from everywhere 660 // note: only true for view space = object space 661 662 // compute first candidate 663 SubdivisionCandidate *osc = 664 mOspTree->PrepareConstruction(sampleRays, objects, *objectSpaceRays); 665 666 mTotalCost = mOspTree->mTotalCost; 667 Debug << "reseting cost, new total cost: " << mTotalCost << endl; 668 669 mTQueue.Push(osc); 670 671 mOspTree->mOspStats.Reset(); 672 mOspTree->mOspStats.Start(); 673 674 const long startTime = GetTime(); 675 const bool repairQueue = false; 676 677 // process object space candidates 678 RunConstruction(repairQueue); 679 680 cout << "finished in " << TimeDiff(startTime, GetTime()) * 1e-3 << " secs" << endl; 681 682 mOspTree->mOspStats.Stop(); 683 684 ////////////////////////// 685 // matt: only for debugging purpose 686 687 const float rc = mOspTree->EvalRenderCost(sampleRays); 688 689 Debug << "My render cost evalulation: " << rc << endl; 690 } 691 692 693 694 } 710 } 711 712 713 } -
GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.h
r1293 r1294 290 290 HierarchyStatistics mHierarchyStats; 291 291 292 int m MaxLeaves;292 int mTermMaxLeaves; 293 293 ofstream mSubdivisionStats; 294 294 }; -
GTP/trunk/Lib/Vis/Preprocessing/src/OspTree.cpp
r1291 r1294 895 895 } 896 896 897 Debug << "here32 " << touchedViewCells.size() << endl;897 Debug << "here32 " << (int)touchedViewCells.size() << endl; 898 898 return renderCost; 899 899 } … … 1793 1793 } 1794 1794 } 1795 Debug << "here65 " << touchedObjects.size() << endl;1795 Debug << "here65 " << (int)touchedObjects.size() << endl; 1796 1796 ObjectContainer::const_iterator it, it_end = touchedObjects.end(); 1797 1797 for (it = touchedObjects.begin(); it != it_end; ++ it) -
GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.cpp
r1293 r1294 475 475 } 476 476 477 477 478 HierarchyManager *Preprocessor::CreateHierarchyManager(const char *name) 478 479 { … … 850 851 ) 851 852 { 853 #ifdef GTP_INTERNAL 852 854 VssRay *vssRay = NULL; 853 855 int hits = 0; … … 859 861 860 862 double normal[3]; 861 #ifdef GTP_INTERNAL 863 862 864 hittriangle = mlrtaIntersectAS(&viewPoint.x, 863 865 &direction.x, 864 866 normal, 865 867 dist); 866 #else 867 hittriangle = -1; 868 #endif 868 869 869 if (hittriangle !=-1 ) { 870 870 if (hittriangle >= mFaceParents.size()) … … 881 881 } 882 882 883 883 884 Vector3 dir = -direction; 884 #ifdef GTP_INTERNAL885 885 hittriangle = mlrtaIntersectAS(&viewPoint.x, 886 886 &dir.x, 887 887 normal, 888 888 dist); 889 #else890 hittriangle = -1;891 #endif892 889 893 890 if (hittriangle !=-1 ) { … … 913 910 box 914 911 ); 912 #else 913 return -1; 914 #endif 915 915 } 916 916 … … 929 929 return 0; 930 930 931 #ifdef GTP_INTERNAL 931 932 float pforg[3]; 932 933 float pfdir[3]; … … 936 937 pfdir[0] = direction[0]; pfdir[1] = direction[1]; pfdir[2] = direction[2]; 937 938 938 float dist = 0; 939 #ifdef GTP_INTERNAL 939 float dist; 940 940 const int hittriangle = mlrtaIntersectAS(pforg, pfdir, pfnorm, dist); 941 #else942 const int hittriangle = -1;943 #endif944 941 945 942 if (hittriangle == -1) … … 970 967 } 971 968 } 969 970 #else 971 const int hittriangle = -1; 972 return NULL; 973 #endif 974 975 972 976 973 977 } … … 1330 1334 { 1331 1335 case INTEL_RAYCASTER: { 1332 float dist;1336 1333 1337 int hittriangle; 1338 1339 1340 #ifdef GTP_INTERNAL 1341 float dist; 1334 1342 double n[3]; 1335 1343 1336 #ifdef GTP_INTERNAL1337 1344 hittriangle = mlrtaIntersectAS(&viewPoint.x, 1338 1345 &direction.x, … … 1340 1347 dist); 1341 1348 1342 #else 1343 hittriangle = -1; 1344 #endif 1345 1346 if (hittriangle !=-1 ) { 1349 if (hittriangle !=-1 ) { 1347 1350 if (hittriangle >= mFaceParents.size()) 1348 1351 cerr<<"Warning: traingle index out of range! "<<hittriangle<<endl; … … 1353 1356 } 1354 1357 } 1358 #else 1359 hittriangle = -1; 1360 #endif 1361 1362 1355 1363 break; 1356 1364 } -
GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.h
r1284 r1294 227 227 ) = 0; 228 228 229 /** Returns a stats about the global pvs. 230 */ 229 231 virtual void GetPvsStatistics(PvsStatistics &stat); 230 232 … … 378 380 vector<MergeCandidate> &candidates); 379 381 382 /** Collects n view cells and stores it as the active view cells. 383 */ 380 384 void CollectViewCells(const int n); 381 385 … … 453 457 ////////////////////////////////////////////////////////7 454 458 // visiblity filter options 459 455 460 // TODO: write own visibiltiy filter class 456 461 void ApplyFilter(KdTree *kdTree, … … 472 477 float GetAbsFilterWidth(); 473 478 474 475 479 /** Returns the bounding box of filter width. 476 480 */ 477 481 AxisAlignedBox3 GetFilterBBox(const Vector3 &viewPoint, const float width) const; 478 482 483 ////////////////////////////////////////////////////////////////// 479 484 480 485 /** Returns true if the view cell is equivalent to a … … 482 487 view cell. 483 488 e.g. to see if the spatial tree can be reduced on this location 489 note: not implemented 484 490 */ 485 491 virtual bool EqualToSpatialNode(ViewCell *viewCell) const; … … 502 508 protected: 503 509 504 /** Exports bounding boxes as xml stream505 */506 //bool ExportBoundingBoxes(ofstream &xmlstream, const ObjectContainer &objects) const;507 508 510 /** Intersects box with the tree and returns the number of intersected boxes. 509 511 @returns number of view cells found … … 520 522 bool ViewCellsTreeConstructed() const; 521 523 524 /** Requests preprocessor to cast samplesPerPass samples of a specific type. 525 */ 522 526 int CastPassSamples(const int samplesPerPass, 523 527 const int sampleType, … … 717 721 ViewCellContainer &viewcells); 718 722 723 /** Returns the probability that the view point lies 724 in this view cells. 725 */ 719 726 float GetProbability(ViewCell *viewCell); 720 721 722 /** Get a viewcell containing the specified point 727 728 /** Get a viewcell containing the specified point. 723 729 */ 724 730 ViewCell *GetViewCell(const Vector3 &point, const bool active = false) const; 725 731 732 /** Creates mesh for this view cell. 733 */ 726 734 void CreateMesh(ViewCell *vc); 727 735 -
GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsParser.cpp
r1287 r1294 1243 1243 1244 1244 if (attrName == "min") 1245 { cout << "here6" << endl;1245 { 1246 1246 sscanf(ptr, "%f %f %f", &minBox.x, &minBox.y, &minBox.z); 1247 1247 } 1248 1248 if (attrName == "max") 1249 { cout << "here7" << endl;1249 { 1250 1250 sscanf(ptr, "%f %f %f", &maxBox.x, &maxBox.y, &maxBox.z); 1251 1251 } … … 1262 1262 } 1263 1263 else 1264 { cout << "here18" << endl;1264 { 1265 1265 mHierarchyManager->mBvHierarchy->mRoot = interior; 1266 1266 } 1267 cout << "here28" << endl; 1267 1268 1268 mCurrentBvhNode = interior; 1269 1269 } -
GTP/trunk/Lib/Vis/Preprocessing/src/VspTree.cpp
r1293 r1294 527 527 inline bool VspTree::LocalTerminationCriteriaMet(const VspTraversalData &data) const 528 528 { 529 const bool localTerminationCriteriaMet = ( 530 ((int)data.mRays->size() <= mTermMinRays) ||531 (data.mPvs <= mTermMinPvs) ||532 (data.mProbability <= mTermMinProbability) ||533 (data.GetAvgRayContribution() > mTermMaxRayContribution) ||534 (data.mDepth >= mTermMaxDepth)529 const bool localTerminationCriteriaMet = (0 530 //|| ((int)data.mRays->size() <= mTermMinRays) 531 //|| (data.mPvs <= mTermMinPvs) 532 //|| (data.mProbability <= mTermMinProbability) 533 //|| (data.GetAvgRayContribution() > mTermMaxRayContribution) 534 //|| (data.mDepth >= mTermMaxDepth) 535 535 ); 536 536 … … 545 545 } 546 546 547 return localTerminationCriteriaMet; 548 547 return localTerminationCriteriaMet; 549 548 } 550 549 … … 552 551 inline bool VspTree::GlobalTerminationCriteriaMet(const VspTraversalData &data) const 553 552 { 554 const bool terminationCriteriaMet = ( 555 // mOutOfMemory ||556 (mVspStats.Leaves() >= mMaxViewCells) ||557 (mGlobalCostMisses >= mTermGlobalCostMissTolerance)553 const bool terminationCriteriaMet = (0 554 // || mOutOfMemory 555 || (mVspStats.Leaves() >= mMaxViewCells) 556 || (mGlobalCostMisses >= mTermGlobalCostMissTolerance) 558 557 ); 559 558 … … 674 673 675 674 // delete old leaf node 676 DEL_PTR(tData.mNode);675 //DEL_PTR(tData.mNode); 677 676 } 678 677 … … 713 712 // finally evaluate statistics for this leaf 714 713 EvaluateLeafStats(tData); 715 } 716 717 //-- cleanup718 tData.Clear();719 714 715 // detach node so it won't get deleted 716 tData.mNode = NULL; 717 } 718 720 719 return newNode; 721 720 } … … 750 749 splitCandidate.SetRenderCostDecrease(renderCostDecr); 751 750 752 #if 0753 const float priority = (float)- data.mDepth;751 #if 1 752 const float priority = (float)-splitCandidate.mParentData.mDepth; 754 753 #else 755 754 … … 1426 1425 const float renderCostDecrease = (oldRenderCost - newRenderCost) / viewSpaceVol; 1427 1426 1428 Debug << "\n ==== eval render cost decrease ===" << endl1427 Debug << "\neval vsp render cost decrease" << endl 1429 1428 << "back pvs: " << pvsBack << " front pvs " << pvsFront << " total pvs: " << totalPvs << endl 1430 1429 << "back p: " << pBack / viewSpaceVol << " front p " << pFront / viewSpaceVol << " p: " << pOverall / viewSpaceVol << endl … … 2630 2629 2631 2630 //-- prepare view space partition 2632 2633 // add first candidate for view space partition 2631 const float prop = mBoundingBox.GetVolume(); 2632 2633 // we assume that leaf was already created 2634 2634 VspLeaf *leaf = new VspLeaf(); 2635 2635 mRoot = leaf; 2636 2637 const float prop = mBoundingBox.GetVolume();2638 2636 2639 2637 // first vsp traversal data … … 2649 2647 oit_end = leaf->GetViewCell()->GetPvs().mEntries.end(); 2650 2648 2651 2652 2649 for (oit = leaf->GetViewCell()->GetPvs().mEntries.begin(); oit != oit_end; ++ oit) 2653 2650 { … … 2658 2655 2659 2656 //-- compute first split candidate 2660 2661 2657 VspSubdivisionCandidate *splitCandidate = new VspSubdivisionCandidate(vData); 2662 2658 EvalSubdivisionCandidate(*splitCandidate); … … 2669 2665 2670 2666 2671 void VspTree::CollectDirtyCandidates(VspSubdivisionCandidate *sc, 2672 vector<SubdivisionCandidate *> &dirtyList) 2673 { 2674 VspTraversalData &tData = sc->mParentData; 2675 VspLeaf *node = tData.mNode; 2676 2677 KdLeaf::NewMail(); 2678 2679 RayInfoContainer::const_iterator rit, rit_end = tData.mRays->end(); 2680 2681 // add all kd nodes seen by the rays 2682 for (rit = tData.mRays->begin(); rit != rit_end; ++ rit) 2683 { 2684 VssRay *ray = (*rit).mRay; 2685 2686 KdLeaf *leaf = mHierarchyManager->mOspTree->GetLeaf(ray->mOrigin, ray->mOriginNode); 2687 2688 if (!leaf->Mailed()) 2689 { 2690 leaf->Mail(); 2691 dirtyList.push_back(leaf->mSubdivisionCandidate); 2692 } 2693 2694 leaf = mHierarchyManager->mOspTree->GetLeaf(ray->mTermination, ray->mTerminationNode); 2695 2696 if (!leaf->Mailed()) 2697 { 2698 leaf->Mail(); 2699 dirtyList.push_back(leaf->mSubdivisionCandidate); 2700 } 2701 } 2702 } 2703 2704 2705 int VspTree::EvalMaxEventContribution(const VssRay &ray, 2706 const bool isTermination) const 2667 void VspTree::CollectDirtyCandidate(const VssRay &ray, 2668 const bool isTermination, 2669 vector<SubdivisionCandidate *> &dirtyList) const 2707 2670 { 2708 2671 Intersectable *obj; … … 2712 2675 ray.GetSampleData(isTermination, pt, &obj, &node); 2713 2676 2677 if (!obj) return; 2678 2679 switch (mHierarchyManager->GetObjectSpaceSubdivisonType()) 2680 { 2681 case HierarchyManager::KD_BASED_OBJ_SUBDIV: 2682 { 2683 KdLeaf *leaf = mHierarchyManager->mOspTree->GetLeaf(pt, node); 2684 2685 if (!leaf->Mailed()) 2686 { 2687 leaf->Mail(); 2688 dirtyList.push_back(leaf->mSubdivisionCandidate); 2689 } 2690 2691 break; 2692 } 2693 case HierarchyManager::BV_BASED_OBJ_SUBDIV: 2694 { 2695 } 2696 break; 2697 default: 2698 break; 2699 } 2700 } 2701 2702 2703 void VspTree::CollectDirtyCandidates(VspSubdivisionCandidate *sc, 2704 vector<SubdivisionCandidate *> &dirtyList) 2705 { 2706 VspTraversalData &tData = sc->mParentData; 2707 VspLeaf *node = tData.mNode; 2708 2709 KdLeaf::NewMail(); 2710 BvhLeaf::NewMail(); 2711 2712 RayInfoContainer::const_iterator rit, rit_end = tData.mRays->end(); 2713 2714 // add all kd nodes seen by the rays 2715 for (rit = tData.mRays->begin(); rit != rit_end; ++ rit) 2716 { 2717 VssRay *ray = (*rit).mRay; 2718 2719 CollectDirtyCandidate(*ray, true, dirtyList); 2720 CollectDirtyCandidate(*ray, false, dirtyList); 2721 } 2722 } 2723 2724 2725 int VspTree::EvalMaxEventContribution(const VssRay &ray, 2726 const bool isTermination) const 2727 { 2728 Intersectable *obj; 2729 Vector3 pt; 2730 KdNode *node; 2731 2732 ray.GetSampleData(isTermination, pt, &obj, &node); 2733 2714 2734 if (!obj) 2715 2735 return 0; … … 2717 2737 int pvs = 0; 2718 2738 2719 switch ( 2739 switch (mHierarchyManager->GetObjectSpaceSubdivisonType()) 2720 2740 { 2721 2741 case HierarchyManager::NO_OBJ_SUBDIV: -
GTP/trunk/Lib/Vis/Preprocessing/src/VspTree.h
r1292 r1294 342 342 { 343 343 public: 344 345 /** Returns average ray contribution. 346 */ 347 float GetAvgRayContribution() const 348 { 349 return (float)mPvs / ((float)mRays->size() + Limits::Small); 350 } 351 352 353 VspTraversalData(): 354 mNode(NULL), 355 mDepth(0), 356 mRays(NULL), 357 mPvs(0), 358 mProbability(0.0), 359 mMaxCostMisses(0), 360 mPriority(0) 361 {} 362 363 VspTraversalData(VspLeaf *node, 364 const int depth, 365 RayInfoContainer *rays, 366 const int pvs, 367 const float p, 368 const AxisAlignedBox3 &box): 369 mNode(node), 370 mDepth(depth), 371 mRays(rays), 372 mPvs(pvs), 373 mProbability(p), 374 mBoundingBox(box), 375 mMaxCostMisses(0), 376 mPriority(0) 377 {} 378 379 VspTraversalData(const int depth, 380 RayInfoContainer *rays, 381 const AxisAlignedBox3 &box): 382 mNode(NULL), 383 mDepth(depth), 384 mRays(rays), 385 mPvs(0), 386 mProbability(0), 387 mMaxCostMisses(0), 388 mBoundingBox(box) 389 {} 390 391 /** Returns cost of the traversal data. 392 */ 393 float GetCost() const 394 { 395 return mPriority; 396 } 397 398 /// deletes contents and sets them to NULL 399 void Clear() 400 { 401 DEL_PTR(mRays); 402 DEL_PTR(mNode); 403 } 404 344 405 /// the current node 345 406 VspLeaf *mNode; … … 360 421 361 422 362 /** Returns average ray contribution.363 */364 float GetAvgRayContribution() const365 {366 return (float)mPvs / ((float)mRays->size() + Limits::Small);367 }368 369 370 VspTraversalData():371 mNode(NULL),372 mDepth(0),373 mRays(NULL),374 mPvs(0),375 mProbability(0.0),376 mMaxCostMisses(0),377 mPriority(0)378 {}379 380 VspTraversalData(VspLeaf *node,381 const int depth,382 RayInfoContainer *rays,383 const int pvs,384 const float p,385 const AxisAlignedBox3 &box):386 mNode(node),387 mDepth(depth),388 mRays(rays),389 mPvs(pvs),390 mProbability(p),391 mBoundingBox(box),392 mMaxCostMisses(0),393 mPriority(0)394 {}395 396 VspTraversalData(const int depth,397 RayInfoContainer *rays,398 const AxisAlignedBox3 &box):399 mNode(NULL),400 mDepth(depth),401 mRays(rays),402 mPvs(0),403 mProbability(0),404 mMaxCostMisses(0),405 mBoundingBox(box)406 {}407 408 /** Returns cost of the traversal data.409 */410 float GetCost() const411 {412 //cout << mPriority << endl;413 return mPriority;414 }415 416 /// deletes contents and sets them to NULL417 void Clear()418 {419 DEL_PTR(mRays);420 }421 422 423 friend bool operator<(const VspTraversalData &a, const VspTraversalData &b) 423 424 { … … 441 442 VspSubdivisionCandidate(const VspTraversalData &tData): mParentData(tData) 442 443 {}; 444 445 ~VspSubdivisionCandidate() { mParentData.Clear(); } 443 446 444 447 int Type() const { return VIEW_SPACE; } … … 922 925 */ 923 926 void CollectDirtyCandidates(VspSubdivisionCandidate *sc, vector<SubdivisionCandidate *> &dirtyList); 927 928 void CollectDirtyCandidate( 929 const VssRay &ray, 930 const bool isTermination, 931 vector<SubdivisionCandidate *> &dirtyList) const; 924 932 925 933 /** Rays will be clipped to the bounding box. -
GTP/trunk/Lib/Vis/Preprocessing/src/main.cpp
r1292 r1294 112 112 string result = filename; 113 113 114 int pos = filename.rfind(a, filename.size()-1);114 int pos = filename.rfind(a, (int)filename.size() - 1); 115 115 if (pos == filename.size() - a.size()) { 116 116 result.replace(pos, a.size(), b);
Note: See TracChangeset
for help on using the changeset viewer.