Changeset 2003 for GTP/trunk/Lib/Vis/Preprocessing/src/BvHierarchy.cpp
- Timestamp:
- 01/21/07 00:40:56 (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/Lib/Vis/Preprocessing/src/BvHierarchy.cpp
r1999 r2003 26 26 #define USE_FIXEDPOINT_T 0 27 27 #define USE_VOLUMES_FOR_HEURISTICS 1 28 29 //int BvhNode::sMailId = 10000; //2147483647; 30 //int BvhNode::sReservedMailboxes = 1; 28 #define TEST_POWERPLANT 0 29 30 //int BvhNode::sMailId = 10000; 31 //int BvhNode::sReservedMailboxes = 1; 31 32 32 33 BvHierarchy *BvHierarchy::BvhSubdivisionCandidate::sBvHierarchy = NULL; … … 382 383 BvhTraversalData &frontData, 383 384 BvhTraversalData &backData) 384 { 385 { 385 386 const BvhTraversalData &tData = sc.mParentData; 386 387 BvhLeaf *leaf = tData.mNode; … … 427 428 ++ mBvhStats.splits; 428 429 429 430 430 431 //////////////////////////////////////// 431 432 //-- fill front and back traversal data with the new values … … 446 447 AssociateObjectsWithLeaf(back); 447 448 AssociateObjectsWithLeaf(front); 448 449 450 //////////// 449 451 //-- compute pvs correction to cope with undersampling 452 450 453 frontData.mPvs = (float)CountViewCells(front->mObjects); 451 454 backData.mPvs = (float)CountViewCells(back->mObjects); … … 453 456 frontData.mCorrectedPvs = sc.mCorrectedFrontPvs; 454 457 backData.mCorrectedPvs = sc.mCorrectedBackPvs; 458 455 459 456 460 // compute probability of this node being visible, … … 462 466 backData.mCorrectedVolume = sc.mCorrectedBackVolume; 463 467 468 464 469 // how often was max cost ratio missed in this branch? 465 470 frontData.mMaxCostMisses = sc.GetMaxCostMisses(); … … 468 473 // set the time stamp so the order of traversal can be reconstructed 469 474 node->SetTimeStamp(mHierarchyManager->mTimeStamp ++); 470 475 471 476 // assign the objects in sorted order 472 if ( mUseGlobalSorting)477 if (!TEST_POWERPLANT && mUseGlobalSorting) 473 478 { 474 479 AssignSortedObjects(sc, frontData, backData); … … 497 502 BvhTraversalData tFrontData; 498 503 BvhTraversalData tBackData; 499 504 500 505 // create new interior node and two leaf node 501 506 currentNode = SubdivideNode(*sc, tFrontData, tBackData); … … 628 633 } 629 634 635 630 636 const BvhTraversalData &tData = splitCandidate.mParentData; 631 637 BvhLeaf *leaf = tData.mNode; … … 671 677 672 678 if (0) 673 cout << "bvh volume cost" 679 { 680 cout << "bvh volume cost" 674 681 << " avg ray contri: " << avgRayContri << " ratio: " << oldRatio 675 682 << " parent: " << parentVol << " old vol: " << oldVolume 676 683 << " frontvol: " << frontVol << " corr. " << splitCandidate.mCorrectedFrontVolume 677 684 << " backvol: " << backVol << " corr. " << splitCandidate.mCorrectedBackVolume << endl; 685 } 678 686 679 687 #ifdef GTP_DEBUG … … 849 857 850 858 851 #if 0859 #if 1 852 860 853 861 /// compute object boundaries using spatial mid split … … 857 865 ObjectContainer &objectsBack) 858 866 { 859 const float maxBox = tData.mBoundingBox.Max(axis); 860 const float minBox = tData.mBoundingBox.Min(axis); 867 AxisAlignedBox3 parentBox = tData.mNode->GetBoundingBox(); 868 869 const float maxBox = parentBox.Max(axis); 870 const float minBox = parentBox.Min(axis); 861 871 862 872 float midPoint = (maxBox + minBox) * 0.5f; … … 882 892 } 883 893 884 const float oldRenderCost = EvalRenderCost(tData.mNode->mObjects); 885 const float newRenderCost = EvalRenderCost(objectsFront) * EvalRenderCost(objectsBack); 894 AxisAlignedBox3 fbox = EvalBoundingBox(objectsFront, &parentBox); 895 AxisAlignedBox3 bbox = EvalBoundingBox(objectsBack, &parentBox); 896 897 const float oldRenderCost = (float)tData.mNode->mObjects.size() * parentBox.SurfaceArea(); 898 const float newRenderCost = (float)objectsFront.size() * fbox.SurfaceArea() + (float)objectsBack.size() * bbox.SurfaceArea(); 886 899 887 900 const float ratio = newRenderCost / oldRenderCost; … … 920 933 921 934 #if 1 935 // hack: always take driving axis 922 936 const float cost = (tData.mNode->GetBoundingBox().Size().DrivingAxis() == axis) ? -1.0f : 0.0f; 923 937 #else 924 938 const float oldRenderCost = EvalRenderCost(tData.mNode->mObjects); 925 const float newRenderCost = EvalRenderCost(objectsFront) *EvalRenderCost(objectsBack);939 const float newRenderCost = EvalRenderCost(objectsFront) + EvalRenderCost(objectsBack); 926 940 927 941 const float cost = newRenderCost / oldRenderCost; … … 986 1000 } 987 1001 988 // temporary surface areas1002 // record surface areas during the sweep 989 1003 float al = 0; 990 1004 float ar = boxArea; … … 1394 1408 void BvHierarchy::CreateLocalSubdivisionCandidates(const ObjectContainer &objects, 1395 1409 SortableEntryContainer **subdivisionCandidates, 1396 const bool sort ,1410 const bool sortEntries, 1397 1411 const int axis) 1398 1412 { … … 1400 1414 1401 1415 // compute requested size and look if subdivision candidate has to be recomputed 1402 const int requestedSize = (int)objects.size() * 2;1416 const int requestedSize = (int)objects.size(); 1403 1417 1404 1418 // creates a sorted split candidates array … … 1423 1437 } 1424 1438 1425 if (sort )1439 if (sortEntries) 1426 1440 { // no presorted candidate list 1427 stable_sort((*subdivisionCandidates)->begin(), (*subdivisionCandidates)->end()); 1441 //stable_sort((*subdivisionCandidates)->begin(), (*subdivisionCandidates)->end()); 1442 sort((*subdivisionCandidates)->begin(), (*subdivisionCandidates)->end()); 1428 1443 } 1429 1444 } … … 2201 2216 // root and bounding box was already constructed 2202 2217 BvhLeaf *bvhLeaf = dynamic_cast<BvhLeaf *>(mRoot); 2203 2218 2204 2219 // only rays intersecting objects in node are interesting 2205 2220 const int nRays = AssociateObjectsWithRays(sampleRays); 2206 2221 //cout << "using " << nRays << " of " << (int)sampleRays.size() << " rays" << endl; 2207 2222 2208 2223 // probability that volume is "seen" from the view cells 2209 2224 const float prop = EvalViewCellsVolume(objects) / GetViewSpaceVolume(); … … 2213 2228 2214 2229 // create sorted object lists for the first data 2215 if ( mUseGlobalSorting)2230 if (!TEST_POWERPLANT && mUseGlobalSorting) 2216 2231 { 2217 2232 AssignInitialSortedObjectList(oData, objects); … … 2257 2272 tQueue.Push(sCandidate); 2258 2273 } 2274 2275 cout << "size of initial bv subdivision: " << GetStatistics().Leaves() << endl; 2259 2276 } 2260 2277 else 2261 { 2278 { 2262 2279 // evaluate priority 2263 2280 EvalSubdivisionCandidate(*oSubdivisionCandidate); … … 2265 2282 2266 2283 tQueue.Push(oSubdivisionCandidate); 2267 } 2268 2269 cout << "size of initial bv subdivision: " << GetStatistics().Leaves() << endl; 2284 cout << "size of initial bv subdivision: " << GetStatistics().Leaves() << endl; 2285 } 2270 2286 } 2271 2287 … … 2304 2320 2305 2321 *(tData.mSortedObjects[3]) = objects; 2306 stable_sort(tData.mSortedObjects[3]->begin(), tData.mSortedObjects[3]->end(), smallerSize); 2322 //stable_sort(tData.mSortedObjects[3]->begin(), tData.mSortedObjects[3]->end(), smallerSize); 2323 sort(tData.mSortedObjects[3]->begin(), tData.mSortedObjects[3]->end(), smallerSize); 2307 2324 } 2308 2325 … … 2375 2392 BvhTraversalData oData(bvhLeaf, 0, prop, nRays); 2376 2393 2377 AssignInitialSortedObjectList(oData, objects); 2394 if (!TEST_POWERPLANT && mUseGlobalSorting) 2395 AssignInitialSortedObjectList(oData, objects); 2378 2396 2379 2397 … … 2657 2675 delete bsc; 2658 2676 } 2659 else // initial preprocessing finished for this candidate 2660 { 2677 else 2678 { 2679 // initial preprocessing finished for this candidate 2661 2680 // add to candidate container 2662 2681 candidateContainer.push_back(bsc);
Note: See TracChangeset
for help on using the changeset viewer.