Changeset 1108 for GTP/trunk/Lib/Vis/Preprocessing
- Timestamp:
- 07/10/06 15:57:11 (18 years ago)
- Location:
- GTP/trunk/Lib/Vis/Preprocessing/src
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/Lib/Vis/Preprocessing/src/KdTree.cpp
r1089 r1108 163 163 // cerr<<"\n OBJECTS="<<leaf->mObjects.size()<<endl; 164 164 return 165 ( leaf->mObjects.size() <= mTermMinCost) ||165 ((int)leaf->mObjects.size() <= mTermMinCost) || 166 166 (leaf->mDepth >= mTermMaxDepth); 167 167 -
GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp
r1107 r1108 5039 5039 } 5040 5040 5041 5042 5041 VspInterior *interior = dynamic_cast<VspInterior *>(root); 5043 5042 ViewCellInterior *viewCellInterior = new ViewCellInterior(); … … 5445 5444 if (1) 5446 5445 { //-- export pvs 5446 5447 5447 ObjectPvsMap::const_iterator oit, 5448 5448 oit_end = pvs.mEntries.end(); … … 5460 5460 for (oit = pvs.mEntries.begin(); oit != oit_end; ++ oit) 5461 5461 { 5462 // "original" pvs5462 // exportŽ"original" pvs 5463 5463 Intersectable *obj = (*oit).first; 5464 5464 … … 5487 5487 exporter->SetForcedMaterial(m); 5488 5488 5489 // export kd node pvs5489 //-- export kd node pvs 5490 5490 Intersectable::NewMail(); 5491 5491 -
GTP/trunk/Lib/Vis/Preprocessing/src/VrmlExporter.cpp
r1107 r1108 659 659 vector<KdLeaf *>::const_iterator it, it_end = leaves.end(); 660 660 661 Material white; 662 white.mDiffuseColor.r = 1; 663 white.mDiffuseColor.g = 1; 664 white.mDiffuseColor.b = 1; 665 661 666 for (it = leaves.begin(); it != it_end; ++ it) 662 667 { 663 668 SetWireframe(); 669 SetForcedMaterial(white); 664 670 ExportBox(ospTree.GetBBox(*it)); 665 671 672 SetFilled(); 666 673 SetForcedMaterial(RandomMaterial()); 667 668 674 ExportGeometry((*it)->mObjects); 669 675 } -
GTP/trunk/Lib/Vis/Preprocessing/src/VspOspTree.cpp
r1106 r1108 467 467 mBoundingBox.Include(ray->GetOrigin()); 468 468 } 469 470 mTermMinProbability *= mBoundingBox.GetVolume(); 471 mGlobalCostMisses = 0;472 }469 } 470 471 mTermMinProbability *= mBoundingBox.GetVolume(); 472 mGlobalCostMisses = 0; 473 473 } 474 474 … … 517 517 bool VspTree::GlobalTerminationCriteriaMet(const VspTraversalData &data) const 518 518 { 519 Debug << "cost misses " << mGlobalCostMisses << " " << mTermGlobalCostMissTolerance << endl; 520 Debug << "leaves " << mVspStats.Leaves() << " " << mMaxViewCells << endl; 521 519 522 return ( 520 523 // mOutOfMemory || … … 525 528 526 529 530 void VspTree::CreateViewCell(VspTraversalData &tData) 531 { 532 //-- create new view cell 533 VspLeaf *leaf = dynamic_cast<VspLeaf *>(tData.mNode); 534 535 VspViewCell *viewCell = new VspViewCell(); 536 leaf->SetViewCell(viewCell); 537 538 //-- update pvs 539 int conSamp = 0; 540 float sampCon = 0.0f; 541 AddToPvs(leaf, *tData.mRays, sampCon, conSamp); 542 543 // update scalar pvs size value 544 mViewCellsManager->SetScalarPvsSize(viewCell, viewCell->GetPvs().GetSize()); 545 546 mVspStats.contributingSamples += conSamp; 547 mVspStats.sampleContributions +=(int) sampCon; 548 549 //-- store additional info 550 if (mStoreRays) 551 { 552 RayInfoContainer::const_iterator it, it_end = tData.mRays->end(); 553 for (it = tData.mRays->begin(); it != it_end; ++ it) 554 { 555 (*it).mRay->Ref(); 556 leaf->mVssRays.push_back((*it).mRay); 557 } 558 } 559 560 viewCell->mLeaf = leaf; 561 562 viewCell->SetVolume(tData.mProbability); 563 leaf->mProbability = tData.mProbability; 564 565 mVspStats.contributingSamples += conSamp; 566 mVspStats.sampleContributions +=(int) sampCon; 567 568 // finally evaluate statistics for this leaf 569 EvaluateLeafStats(tData); 570 } 571 572 527 573 VspNode *VspTree::Subdivide(SplitQueue &tQueue, 528 574 VspSplitCandidate &splitCandidate, … … 551 597 tBackData.mMaxCostMisses = maxCostMisses; 552 598 553 //-- statistics599 554 600 if (1) 555 601 { 602 //-- subdivision statistics 603 556 604 const float cFront = (float)tFrontData.mPvs * tFrontData.mProbability; 557 605 const float cBack = (float)tBackData.mPvs * tBackData.mProbability; … … 572 620 573 621 574 //-- push the new split candidates on the queue622 //-- evaluate new split candidates for global greedy cost heuristics 575 623 VspSplitCandidate *frontCandidate = new VspSplitCandidate(tFrontData); 576 624 VspSplitCandidate *backCandidate = new VspSplitCandidate(tBackData); … … 586 634 } 587 635 588 589 //-- terminate traversal and create new view cell 636 // subdivision terminated 590 637 if (newNode->IsLeaf()) 591 638 { 592 VspLeaf *leaf = dynamic_cast<VspLeaf *>(newNode); 593 594 VspViewCell *viewCell = new VspViewCell(); 595 leaf->SetViewCell(viewCell); 596 597 //-- update pvs 598 int conSamp = 0; 599 float sampCon = 0.0f; 600 AddToPvs(leaf, *tData.mRays, sampCon, conSamp); 601 602 // update scalar pvs size value 603 mViewCellsManager->SetScalarPvsSize(viewCell, viewCell->GetPvs().GetSize()); 604 605 mVspStats.contributingSamples += conSamp; 606 mVspStats.sampleContributions +=(int) sampCon; 607 639 //-- create new view cell 640 CreateViewCell(tData); 641 608 642 //-- store additional info 609 643 if (mStoreRays) … … 613 647 { 614 648 (*it).mRay->Ref(); 615 leaf->mVssRays.push_back((*it).mRay); 616 } 617 } 618 619 viewCell->mLeaf = leaf; 620 621 viewCell->SetVolume(tData.mProbability); 622 leaf->mProbability = tData.mProbability; 623 624 // finally evaluate stats until this leaf 649 dynamic_cast<VspLeaf *>(newNode)->mVssRays.push_back((*it).mRay); 650 } 651 } 652 653 // finally evaluate statistics for this leaf 625 654 EvaluateLeafStats(tData); 626 655 } … … 661 690 662 691 //-- the front and back traversal data is filled with the new values 692 663 693 frontData.mDepth = tData.mDepth + 1; 664 694 frontData.mRays = new RayInfoContainer(); … … 672 702 *frontData.mRays, 673 703 *backData.mRays); 704 705 // TODO: 706 // create front and back view cell 707 // remove "parent" view cell from pvs of all objects (traverse trough rays) 708 // add front and back view cell to "Potentially Visbilie View Cells" 709 // of the objects in front and back pvs 674 710 675 711 //Debug << "f: " << frontData.mRays->size() << " b: " << backData.mRays->size() << "d: " << tData.mRays->size() << endl; … … 1012 1048 1013 1049 1014 int VspTree::GetPvsIncr(Intersectable *object, const KdPvsMap &activeNodes)1015 {1016 // TODO:1017 // use kd info table to apply set theory in order to1018 // sort out dublicate pvs entries due to objects which1019 // belong to more than one kd leaves.1020 #if TODO1021 KdPvsMap::const_iterator kit, kit_end = obj->mKdPvs.mEntries.end();1022 1023 // Search kd leaves this object is attached to1024 for (kit = obj->mKdPvs.mEntries.begin(); kit != kit_end; ++ kit)1025 {1026 KdNode *l = (*kit).first;1027 1028 // new object found during sweep1029 // => increase pvs contribution of this kd node1030 if (!l->Mailed())1031 {1032 l->Mail();1033 ++ pvsContr;1034 }1035 }1036 #endif1037 return 0;1038 }1039 1040 1041 1050 void VspTree::RemoveContriFromPvs(KdLeaf *leaf, int &pvs) const 1042 1051 { … … 1200 1209 pvsSize = PrepareHeuristics(rays); 1201 1210 1202 Debug << "here45 pvs: " << pvsSize << endl;1203 1204 1211 // go through the lists, count the number of objects left and right 1205 1212 // and evaluate the following cost funcion: … … 1229 1236 vector<SortableEntry>::const_iterator ci, ci_end = mSplitCandidates->end(); 1230 1237 1231 Debug << "****************" << endl;1232 1238 //-- traverse through visibility events 1233 1239 … … 1338 1344 { 1339 1345 //-- split plane position is spatial median 1340 1341 1346 nPosition[axis] = (box.Min()[axis] + box.Max()[axis]) * 0.5f; 1342 1343 1347 nCostRatio[axis] = EvalLocalSplitCost(tData, 1344 1348 box, … … 1361 1365 1362 1366 1363 //-- assign values 1367 //-- assign values of best split 1364 1368 1365 1369 plane.mAxis = bestAxis; 1366 // split plane position 1367 plane.mPosition = nPosition[bestAxis]; 1370 plane.mPosition = nPosition[bestAxis]; // split plane position 1368 1371 1369 1372 pFront = nProbFront[bestAxis]; … … 1475 1478 } 1476 1479 1477 //-- pvsheuristics1480 //-- cost heuristics 1478 1481 float pOverall; 1479 1480 //-- compute heurstics1481 1482 1482 1483 pOverall = data.mProbability; 1483 // we take simplified computation for mid split 1484 1485 // we take simplified computation for spatial mid split 1484 1486 pBack = pFront = pOverall * 0.5f; 1485 1487 1488 const float newCost = pvsBack * pBack + pvsFront * pFront; 1489 const float oldCost = (float)pvsSize * pOverall + Limits::Small; 1486 1490 1487 1491 #ifdef _DEBUG … … 1489 1493 Debug << pFront << " " << pBack << " " << pOverall << endl; 1490 1494 #endif 1491 1492 1493 const float newCost = pvsBack * pBack + pvsFront * pFront;1494 const float oldCost = (float)pvsSize * pOverall + Limits::Small;1495 1495 1496 1496 return (mCtDivCi + newCost) / oldCost; … … 2642 2642 2643 2643 KdInterior *OspTree::SubdivideNode( 2644 KdLeaf *leaf,2645 2644 const AxisAlignedPlane &splitPlane, 2646 const AxisAlignedBox3 &box,2645 const OspTraversalData &tData, 2647 2646 OspTraversalData &frontData, 2648 2647 OspTraversalData &backData 2649 2648 ) 2650 2649 { 2650 KdLeaf *leaf = tData.mNode; 2651 2652 // two new leaves 2651 2653 mOspStats.nodes += 2; 2652 2654 … … 2659 2661 node->mAxis = axis; 2660 2662 node->mPosition = position; 2661 node->mBox = box; 2662 2663 backData.mBoundingBox = box; 2664 frontData.mBoundingBox = box; 2665 2666 // first count ray sides 2663 node->mBox = tData.mBoundingBox; 2664 2665 2666 //-- the front and back traversal data is filled with the new values 2667 2668 // bounding boxes: split front and back node geometry 2669 tData.mBoundingBox.Split(splitPlane.mAxis, splitPlane.mPosition, 2670 frontData.mBoundingBox, backData.mBoundingBox); 2671 2672 frontData.mDepth = backData.mDepth = tData.mDepth + 1; 2673 2674 // TODO matt: compute pvs 2675 frontData.mPvs = 999; // ComputePvsSize(*frontData.mRays); 2676 backData.mPvs = -999; //ComputePvsSize(*backData.mRays); 2677 2678 frontData.mProbability = frontData.mBoundingBox.GetVolume(); 2679 2680 2681 // classify objects 2667 2682 int objectsBack = 0; 2668 2683 int objectsFront = 0; 2669 2670 backData.mBoundingBox.SetMax(axis, position);2671 frontData.mBoundingBox.SetMin(axis, position);2672 2684 2673 2685 ObjectContainer::const_iterator mi, mi_end = leaf->mObjects.end(); … … 2723 2735 OspSplitCandidate &splitCandidate, 2724 2736 const bool globalCriteriaMet) 2725 { Debug << "here11" << endl;2737 { 2726 2738 OspTraversalData &tData = splitCandidate.mParentData; 2727 Debug << "here993" << endl;2728 2739 KdNode *newNode = tData.mNode; 2729 2740 2730 Debug << "here996" << endl;2731 2741 if (!LocalTerminationCriteriaMet(tData) && !globalCriteriaMet) 2732 2742 { 2733 2743 OspTraversalData tFrontData; 2734 2744 OspTraversalData tBackData; 2735 Debug << "here3" << endl; 2745 2736 2746 //-- continue subdivision 2737 2747 … … 2739 2749 const AxisAlignedPlane splitPlane = splitCandidate.mSplitPlane; 2740 2750 2741 newNode = SubdivideNode(dynamic_cast<KdLeaf *>(newNode), 2742 splitPlane, 2743 tData.mBoundingBox, 2751 newNode = SubdivideNode(splitPlane, 2752 tData, 2744 2753 tFrontData, 2745 2754 tBackData); … … 2755 2764 OspSplitCandidate *backCandidate = new OspSplitCandidate(tBackData); 2756 2765 2757 Debug << "here 54 " << tFrontData.mNode << " " << tBackData.mNode << endl;2758 2759 2766 EvalSplitCandidate(*frontCandidate); 2760 2767 EvalSplitCandidate(*backCandidate); … … 2773 2780 EvaluateLeafStats(tData); 2774 2781 } 2775 Debug << "here888 "<< endl;2782 2776 2783 //-- cleanup 2777 2784 tData.Clear(); 2778 Debug << "here876"<< endl;2785 2779 2786 return newNode; 2780 2787 } … … 3003 3010 return 1; 3004 3011 #else 3005 ViewCellPvsMap::const_iterator vit, vit_end = object->mViewCellPvs.mEntries.end(); 3006 3007 int pvsSize = 0; 3008 3009 for (vit = object->mViewCellPvs.mEntries.begin(); vit != vit_end; ++ vit) 3010 { 3011 ViewCell *vc = (*vit).first; 3012 3013 if (!vc->Mailed()) 3014 { 3015 vc->Mail(); 3016 vc->mCounter = 1; 3017 ++ pvsSize; 3018 } 3019 else 3020 { 3021 ++ vc->mCounter; 3022 } 3023 } 3024 3025 return pvsSize; 3012 // the priotity of the object is the number of view cell pvs entries of the object 3013 return object->mViewCellPvs.GetSize(); 3026 3014 #endif 3027 3015 } … … 3041 3029 { 3042 3030 Intersectable *obj = *oit; 3043 3044 3031 pvsSize += PrepareHeuristics(obj); 3045 3032 } … … 3085 3072 -- pvs; 3086 3073 #else 3087 ViewCellPvsMap::const_iterator vit, vit_end = object->mViewCellPvs.mEntries.end(); 3088 3089 for (vit = object->mViewCellPvs.mEntries.begin(); vit != vit_end; ++ vit) 3090 { 3091 ViewCell *vc = (*vit).first; 3092 3093 if (-- vc->mCounter == 0) 3094 { 3095 -- pvs; 3096 } 3097 } 3074 // the cost of an object is the number of view cells it is part of 3075 pvs -= object->mViewCellPvs.GetSize(); 3098 3076 #endif 3099 3077 } … … 3102 3080 void OspTree::AddContriToPvs(Intersectable *object, int &pvs) const 3103 3081 { 3104 ViewCellPvsMap::const_iterator vit, vit_end = object->mViewCellPvs.mEntries.end();3105 3106 3082 #if COUNT_OBJECTS 3107 3083 ++ pvs; 3108 3084 #else 3109 for (vit = object->mViewCellPvs.mEntries.begin(); vit != vit_end; ++ vit) 3110 { 3111 ViewCell *vc = (*vit).first; 3112 3113 if (!vc->Mailed()) 3114 { 3115 vc->Mail(); 3116 ++ pvs; 3117 } 3118 } 3085 // the cost of an object is the number of view cells it is part of 3086 pvs += object->mViewCellPvs.GetSize(); 3119 3087 #endif 3120 3088 } … … 3218 3186 3219 3187 // probability that view point lies in back / front node 3220 float pOverall = data.m Probability;3188 float pOverall = data.mBoundingBox.GetVolume();//data.mProbability; 3221 3189 float pFront = 0; 3222 3190 float pBack = 0; 3223 3224 3191 3225 3192 Intersectable::NewMail(); … … 3234 3201 Intersectable *obj = *oit; 3235 3202 const AxisAlignedBox3 box = obj->GetBox(); 3203 3204 const float pvsIncr = EvalViewCellPvsIncr(obj); 3205 totalPvs += pvsIncr; 3236 3206 3237 3207 if (box.Max(candidatePlane.mAxis) > candidatePlane.mPosition) 3238 pvsFront += EvalViewCellPvsIncr(obj); 3208 { 3209 pvsFront += pvsIncr; 3210 } 3239 3211 if (box.Min(candidatePlane.mAxis) > candidatePlane.mPosition) 3240 pvsBack += EvalViewCellPvsIncr(obj); 3212 { 3213 pvsBack += pvsIncr; 3214 } 3241 3215 } 3242 3216 … … 3256 3230 3257 3231 //-- only render cost heuristics or combined with standard deviation 3258 const float penaltyOld = EvalPvsPenalty((int)totalPvs, lowerPvsLimit, upperPvsLimit);3259 const float penaltyFront = EvalPvsPenalty((int)pvsFront, lowerPvsLimit, upperPvsLimit);3260 const float penaltyBack = EvalPvsPenalty((int)pvsBack, lowerPvsLimit, upperPvsLimit);3232 const float penaltyOld = totalPvs;//EvalPvsPenalty((int)totalPvs, lowerPvsLimit, upperPvsLimit); 3233 const float penaltyFront = pvsFront;//EvalPvsPenalty((int)pvsFront, lowerPvsLimit, upperPvsLimit); 3234 const float penaltyBack = pvsBack;//EvalPvsPenalty((int)pvsBack, lowerPvsLimit, upperPvsLimit); 3261 3235 3236 Debug << "total pvs: " << totalPvs << " p " << pOverall << endl; 3262 3237 const float oldRenderCost = pOverall * penaltyOld; 3263 3238 const float newRenderCost = penaltyFront * pFront + penaltyBack * pBack; 3264 3239 3265 //Debug << "decrease: " << oldRenderCost - newRenderCost << endl;3240 Debug << "old: " << oldRenderCost << " new: " << newRenderCost << " decrease: " << oldRenderCost - newRenderCost << endl; 3266 3241 const float renderCostDecrease = (oldRenderCost - newRenderCost) / mBoundingBox.GetVolume(); 3267 3242 … … 3303 3278 mBoundingBox.Include(obj->GetBox()); 3304 3279 } 3305 3306 mTermMinProbability *= mBoundingBox.GetVolume(); 3307 mGlobalCostMisses = 0;3308 }3280 } 3281 3282 mTermMinProbability *= mBoundingBox.GetVolume(); 3283 mGlobalCostMisses = 0; 3309 3284 } 3310 3285 … … 3503 3478 bool HierarchyManager::GlobalTerminationCriteriaMet(SplitCandidate *candidate) const 3504 3479 { 3505 if (candidate->Type() == SplitCandidate::VIEW_SPACE) 3506 { 3507 VspTree::VspSplitCandidate *sc = 3508 dynamic_cast<VspTree::VspSplitCandidate *>(candidate); 3509 3510 return mVspTree.GlobalTerminationCriteriaMet(sc->mParentData); 3511 } 3512 else 3513 { 3514 OspTree::OspSplitCandidate *sc = 3515 dynamic_cast<OspTree::OspSplitCandidate *>(candidate); 3516 3517 return mOspTree.GlobalTerminationCriteriaMet(sc->mParentData); 3518 } 3519 3520 return true; 3480 // TODO matt: make virtual by creating superclasss for traveral data 3481 return candidate->GlobalTerminationCriteriaMet(); 3521 3482 } 3522 3483 … … 3595 3556 GlobalTerminationCriteriaMet(splitCandidate); 3596 3557 3597 cout << "view cells: " << i ++ << endl;3558 //cout << "vsp nodes: " << i ++ << endl; 3598 3559 3599 3560 // cost ratio of cost decrease / totalCost … … 3655 3616 GlobalTerminationCriteriaMet(splitCandidate); 3656 3617 3657 cout << "kd nodes: " << i ++ << endl;3658 3659 3618 // cost ratio of cost decrease / totalCost 3660 3619 const float costRatio = splitCandidate->GetPriority() / mTotalCost; 3620 3661 3621 //Debug << "cost ratio: " << costRatio << endl; 3622 //cout << "kd nodes: " << i ++ << endl; 3662 3623 3663 3624 if (costRatio < mTermMinGlobalCostRatio) -
GTP/trunk/Lib/Vis/Preprocessing/src/VspOspTree.h
r1106 r1108 72 72 virtual void EvalPriority() = 0; 73 73 virtual int Type() const = 0; 74 virtual bool GlobalTerminationCriteriaMet() const = 0; 74 75 }; 75 76 … … 554 555 { 555 556 public: 557 556 558 static VspTree* sVspTree; 559 557 560 /// parent node traversal data 558 561 VspTraversalData mParentData; … … 566 569 { 567 570 sVspTree->EvalSplitCandidate(*this); 571 } 572 573 bool GlobalTerminationCriteriaMet() const 574 { 575 return sVspTree->GlobalTerminationCriteriaMet(mParentData); 568 576 } 569 577 … … 969 977 970 978 void ProcessViewCellObjects(ViewCell *parent, ViewCell *front, ViewCell *back) const; 979 980 void CreateViewCell(VspTraversalData &tData); 971 981 972 982 protected: … … 1169 1179 } 1170 1180 1181 bool GlobalTerminationCriteriaMet() const 1182 { 1183 return sOspTree->GlobalTerminationCriteriaMet(mParentData); 1184 } 1185 1186 1171 1187 OspSplitCandidate(const AxisAlignedPlane &plane, const OspTraversalData &tData): 1172 1188 SplitCandidate(plane), mParentData(tData) … … 1379 1395 @returns the root of the subdivision 1380 1396 */ 1381 KdInterior *SubdivideNode( KdLeaf *leaf,1397 KdInterior *SubdivideNode( 1382 1398 const AxisAlignedPlane &splitPlane, 1383 const AxisAlignedBox3 &box,1399 const OspTraversalData &tData, 1384 1400 OspTraversalData &frontData, 1385 1401 OspTraversalData &backData);
Note: See TracChangeset
for help on using the changeset viewer.