Changeset 1106 for GTP/trunk/Lib/Vis/Preprocessing/src/VspOspTree.cpp
- Timestamp:
- 07/10/06 01:57:41 (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/Lib/Vis/Preprocessing/src/VspOspTree.cpp
r1101 r1106 22 22 23 23 #define USE_FIXEDPOINT_T 0 24 24 #define COUNT_OBJECTS 1 25 25 26 26 //-- static members 27 28 int VspTree::sFrontId = 0;29 int VspTree::sBackId = 0;30 int VspTree::sFrontAndBackId = 0;31 27 32 28 VspTree *VspTree::VspSplitCandidate::sVspTree = NULL; … … 379 375 380 376 Debug << "******* VSP options ******** " << endl; 377 381 378 Debug << "max depth: " << mTermMaxDepth << endl; 382 379 Debug << "min PVS: " << mTermMinPvs << endl; … … 399 396 Debug << "minband: " << mMinBand << endl; 400 397 Debug << "maxband: " << mMaxBand << endl; 401 Debug << "pvs count method: " << mPvsCountMethod << endl; 402 398 399 if (mPvsCountMethod == 0) 400 Debug << "pvs count method: per object" << endl; 401 else 402 Debug << "pvs count method: per kd node" << endl; 403 403 404 404 mSplitCandidates = new vector<SortableEntry>; … … 504 504 bool VspTree::LocalTerminationCriteriaMet(const VspTraversalData &data) const 505 505 { 506 return 507 #if TODO 508 (((int)data.mRays->size() <= mTermMinRays) || 509 (data.mPvs <= mTermMinPvs) || 510 (data.mProbability <= mTermMinProbability) || 511 (data.GetAvgRayContribution() > mTermMaxRayContribution) || 512 (data.mDepth >= mTermMaxDepth)); 513 #else 514 false; 515 #endif 506 return( 507 ((int)data.mRays->size() <= mTermMinRays) || 508 (data.mPvs <= mTermMinPvs) || 509 (data.mProbability <= mTermMinProbability) || 510 (data.GetAvgRayContribution() > mTermMaxRayContribution) || 511 (data.mDepth >= mTermMaxDepth) 512 ); 513 516 514 } 517 515 … … 519 517 bool VspTree::GlobalTerminationCriteriaMet(const VspTraversalData &data) const 520 518 { 521 return 522 #if TODO 523 (mOutOfMemory || 519 return ( 520 // mOutOfMemory || 524 521 (mVspStats.Leaves() >= mMaxViewCells) || 525 (mGlobalCostMisses >= mTermGlobalCostMissTolerance)); 526 #else 527 (mVspStats.Leaves() >= mMaxViewCells) ; 528 #endif 522 (mGlobalCostMisses >= mTermGlobalCostMissTolerance) 523 ); 529 524 } 530 525 … … 729 724 // and setup child links 730 725 interior->SetupChildLinks(new VspLeaf(interior), new VspLeaf(interior)); 726 731 727 // add bounding box 732 728 interior->SetBoundingBox(tData.mBoundingBox); 729 730 // set front and back leaf 731 frontData.mNode = interior->GetFront(); 732 backData.mNode = interior->GetBack(); 733 733 734 734 interior->mTimeStamp = mTimeStamp ++; … … 915 915 node->mCounter = 1; 916 916 917 //Debug << "here5 "<<(int)node->mObjects.size() <<" "<< node->mMultipleObjects.size()<< " " <<(int)node->mObjects.size() - node->mMultipleObjects.size()<<endl;918 917 // add objects without the objects which are in several kd leaves 919 918 pvsSize += (int)(node->mObjects.size() - node->mMultipleObjects.size()); … … 933 932 if (!object->Mailed()) 934 933 { 935 //Debug << "here233: " << object->mKdLeaves.size() << endl;936 934 object->Mail(); 937 935 object->mCounter = 1; … … 1322 1320 sAxis = box.Size().DrivingAxis(); 1323 1321 } 1324 //sAxis = 2;1322 1325 1323 for (int axis = 0; axis < 3; ++ axis) 1326 1324 { 1327 1325 if (!useSpecialAxis || (axis == sAxis)) 1328 1326 { 1329 //-- place split plane using heuristics1330 1331 1327 if (mUseCostHeuristics) 1332 1328 { 1329 //-- place split plane using heuristics 1333 1330 nCostRatio[axis] = 1334 1331 EvalLocalCostHeuristics(*tData.mRays, … … 1338 1335 nPosition[axis]); 1339 1336 } 1340 else //-- split plane position is spatial median 1341 { 1337 else 1338 { 1339 //-- split plane position is spatial median 1340 1342 1341 nPosition[axis] = (box.Min()[axis] + box.Max()[axis]) * 0.5f; 1343 1342 … … 2545 2544 mTimeStamp(1) 2546 2545 { 2547 #if TODO 2546 2548 2547 bool randomize = false; 2549 2548 Environment::GetSingleton()->GetBoolValue("VspTree.Construction.randomize", randomize); … … 2552 2551 2553 2552 //-- termination criteria for autopartition 2554 Environment::GetSingleton()->GetIntValue("VspTree.Termination.maxDepth", mTermMaxDepth); 2555 Environment::GetSingleton()->GetIntValue("VspTree.Termination.minPvs", mTermMinPvs); 2556 Environment::GetSingleton()->GetIntValue("VspTree.Termination.minRays", mTermMinRays); 2557 Environment::GetSingleton()->GetFloatValue("VspTree.Termination.minProbability", mTermMinProbability); 2558 Environment::GetSingleton()->GetFloatValue("VspTree.Termination.maxRayContribution", mTermMaxRayContribution); 2559 2560 Environment::GetSingleton()->GetIntValue("VspTree.Termination.missTolerance", mTermMissTolerance); 2561 Environment::GetSingleton()->GetIntValue("VspTree.Termination.maxViewCells", mMaxViewCells); 2562 2553 Environment::GetSingleton()->GetIntValue("OspTree.Termination.maxDepth", mTermMaxDepth); 2554 Environment::GetSingleton()->GetIntValue("OspTree.Termination.maxLeaves", mTermMaxLeaves); 2555 Environment::GetSingleton()->GetIntValue("OspTree.Termination.minObjects", mTermMinObjects); 2556 Environment::GetSingleton()->GetFloatValue("OspTree.Termination.minProbability", mTermMinProbability); 2557 2558 Environment::GetSingleton()->GetIntValue("OspTree.Termination.missTolerance", mTermMissTolerance); 2559 2563 2560 //-- max cost ratio for early tree termination 2564 Environment::GetSingleton()->GetFloatValue("VspTree.Termination.maxCostRatio", mTermMaxCostRatio); 2565 2566 Environment::GetSingleton()->GetFloatValue("VspTree.Termination.minGlobalCostRatio", mTermMinGlobalCostRatio); 2567 Environment::GetSingleton()->GetIntValue("VspTree.Termination.globalCostMissTolerance", mTermGlobalCostMissTolerance); 2568 2569 // HACK//mTermMinPolygons = 25; 2561 Environment::GetSingleton()->GetFloatValue("OspTree.Termination.maxCostRatio", mTermMaxCostRatio); 2562 2563 Environment::GetSingleton()->GetFloatValue("OspTree.Termination.minGlobalCostRatio", mTermMinGlobalCostRatio); 2564 Environment::GetSingleton()->GetIntValue("OspTree.Termination.globalCostMissTolerance", mTermGlobalCostMissTolerance); 2565 2570 2566 2571 2567 //-- factors for bsp tree split plane heuristics 2572 Environment::GetSingleton()->GetFloatValue(" VspTree.Termination.ct_div_ci", mCtDivCi);2568 Environment::GetSingleton()->GetFloatValue("OspTree.Termination.ct_div_ci", mCtDivCi); 2573 2569 2574 2570 //-- partition criteria 2575 Environment::GetSingleton()->GetFloatValue(" VspTree.Construction.epsilon", mEpsilon);2571 Environment::GetSingleton()->GetFloatValue("OspTree.Construction.epsilon", mEpsilon); 2576 2572 2577 2573 // if only the driving axis is used for axis aligned split 2578 Environment::GetSingleton()->GetBoolValue("VspTree.splitUseOnlyDrivingAxis", mOnlyDrivingAxis); 2579 2580 //Environment::GetSingleton()->GetFloatValue("VspTree.maxTotalMemory", mMaxTotalMemory); 2581 Environment::GetSingleton()->GetFloatValue("VspTree.maxStaticMemory", mMaxMemory); 2582 2583 Environment::GetSingleton()->GetBoolValue("VspTree.useCostHeuristics", mUseCostHeuristics); 2584 Environment::GetSingleton()->GetBoolValue("VspTree.simulateOctree", mCirculatingAxis); 2574 Environment::GetSingleton()->GetBoolValue("OspTree.splitUseOnlyDrivingAxis", mOnlyDrivingAxis); 2575 2576 Environment::GetSingleton()->GetFloatValue("OspTree.maxStaticMemory", mMaxMemory); 2577 2578 Environment::GetSingleton()->GetBoolValue("OspTree.useCostHeuristics", mUseCostHeuristics); 2585 2579 2586 2580 2587 2581 char subdivisionStatsLog[100]; 2588 Environment::GetSingleton()->GetStringValue(" VspTree.subdivisionStats", subdivisionStatsLog);2582 Environment::GetSingleton()->GetStringValue("OspTree.subdivisionStats", subdivisionStatsLog); 2589 2583 mSubdivisionStats.open(subdivisionStatsLog); 2590 2584 2591 Environment::GetSingleton()->GetFloatValue("VspTree.Construction.minBand", mMinBand); 2592 Environment::GetSingleton()->GetFloatValue("VspTree.Construction.maxBand", mMaxBand); 2593 2594 mSplitBorder = 0.1f; 2585 Environment::GetSingleton()->GetFloatValue("OspTree.Construction.splitBorder", mSplitBorder); 2586 //mSplitBorder = 0.1f; 2595 2587 2596 2588 … … 2598 2590 2599 2591 Debug << "******* OSP options ******** " << endl; 2592 2600 2593 Debug << "max depth: " << mTermMaxDepth << endl; 2601 Debug << "min PVS: " << mTermMinPvs << endl;2602 2594 Debug << "min probabiliy: " << mTermMinProbability << endl; 2603 Debug << "min rays: " << mTermMinRays << endl; 2604 Debug << "max ray contri: " << mTermMaxRayContribution << endl; 2595 Debug << "min objects: " << mTermMinObjects << endl; 2605 2596 Debug << "max cost ratio: " << mTermMaxCostRatio << endl; 2606 2597 Debug << "miss tolerance: " << mTermMissTolerance << endl; 2607 Debug << "max view cells: " << mMaxViewCells << endl; 2598 Debug << "max leaves: " << mTermMaxLeaves << endl; 2599 2608 2600 Debug << "randomize: " << randomize << endl; 2609 2601 … … 2615 2607 Debug << "subdivision stats log: " << subdivisionStatsLog << endl; 2616 2608 2617 Debug << "circulating axis: " << mCirculatingAxis << endl; 2618 Debug << "minband: " << mMinBand << endl; 2619 Debug << "maxband: " << mMaxBand << endl; 2620 2609 Debug << "split borders: " << mSplitBorder << endl; 2610 2621 2611 2622 2612 mSplitCandidates = new vector<SortableEntry>; 2623 2613 2624 2614 Debug << endl; 2625 #endif2626 2615 } 2627 2616 … … 2630 2619 void OspTree::SplitObjects(const AxisAlignedPlane & splitPlane, 2631 2620 const ObjectContainer &objects, 2632 ObjectContainer & back,2633 ObjectContainer & front)2621 ObjectContainer &front, 2622 ObjectContainer &back) 2634 2623 { 2635 2624 ObjectContainer::const_iterator oit, oit_end = objects.end(); … … 2645 2634 if (box.Min(splitPlane.mAxis) < splitPlane.mPosition) 2646 2635 back.push_back(*oit); 2647 #if TODO 2648 mStat.objectRefs -= (int)objects.size(); 2649 mStat.objectRefs += objectsBack + objectsFront;2650 #endif 2651 2652 } 2653 2654 2655 KdInterior *OspTree::SubdivideNode(KdLeaf *leaf,2636 } 2637 2638 mOspStats.objectRefs -= (int)objects.size(); 2639 mOspStats.objectRefs += (int)back.size() + (int)front.size(); 2640 } 2641 2642 2643 KdInterior *OspTree::SubdivideNode( 2644 KdLeaf *leaf, 2656 2645 const AxisAlignedPlane &splitPlane, 2657 2646 const AxisAlignedBox3 &box, 2658 AxisAlignedBox3 &backBBox, 2659 AxisAlignedBox3 &frontBBox) 2660 { 2661 #if TODO 2662 mSpatialStat.nodes += 2; 2663 mSpatialStat.splits[axis]; 2664 #endif 2647 OspTraversalData &frontData, 2648 OspTraversalData &backData 2649 ) 2650 { 2651 mOspStats.nodes += 2; 2665 2652 2666 2653 // add the new nodes to the tree … … 2674 2661 node->mBox = box; 2675 2662 2676 backBBox = box;2677 front BBox = box;2663 backData.mBoundingBox = box; 2664 frontData.mBoundingBox = box; 2678 2665 2679 2666 // first count ray sides … … 2681 2668 int objectsFront = 0; 2682 2669 2683 back BBox.SetMax(axis, position);2684 front BBox.SetMin(axis, position);2670 backData.mBoundingBox.SetMax(axis, position); 2671 frontData.mBoundingBox.SetMin(axis, position); 2685 2672 2686 2673 ObjectContainer::const_iterator mi, mi_end = leaf->mObjects.end(); … … 2701 2688 KdLeaf *front = new KdLeaf(node, objectsFront); 2702 2689 2690 ///////////// 2691 //-- create front and back leaf 2692 2693 KdInterior *parent = leaf->mParent; 2694 2703 2695 // replace a link from node's parent 2704 if (leaf->mParent) 2705 leaf->mParent->ReplaceChildLink(leaf, node); 2696 if (parent) 2697 { 2698 parent->ReplaceChildLink(leaf, node); 2699 node->mParent = parent; 2700 } 2701 else // new root 2702 { 2703 mRoot = node; 2704 } 2706 2705 2707 2706 // and setup child links 2708 2707 node->SetupChildLinks(back, front); 2709 2708 2710 SplitObjects(splitPlane, leaf->mObjects, back->mObjects, front->mObjects);2709 SplitObjects(splitPlane, leaf->mObjects, front->mObjects, back->mObjects); 2711 2710 2712 2711 ProcessLeafObjects(back, leaf); 2713 2712 ProcessLeafObjects(front, leaf); 2714 2713 2714 backData.mNode = back; 2715 frontData.mNode = front; 2716 2715 2717 //delete leaf; 2716 2718 return node; … … 2721 2723 OspSplitCandidate &splitCandidate, 2722 2724 const bool globalCriteriaMet) 2723 { 2725 {Debug << "here11" << endl; 2724 2726 OspTraversalData &tData = splitCandidate.mParentData; 2725 2727 Debug << "here993" << endl; 2726 2728 KdNode *newNode = tData.mNode; 2727 2729 2730 Debug << "here996" << endl; 2728 2731 if (!LocalTerminationCriteriaMet(tData) && !globalCriteriaMet) 2729 2732 { 2730 2733 OspTraversalData tFrontData; 2731 2734 OspTraversalData tBackData; 2732 2735 Debug << "here3" << endl; 2733 2736 //-- continue subdivision 2734 2737 … … 2739 2742 splitPlane, 2740 2743 tData.mBoundingBox, 2741 tFrontData .mBoundingBox,2742 tBackData .mBoundingBox);2744 tFrontData, 2745 tBackData); 2743 2746 2744 2747 const int maxCostMisses = splitCandidate.mMaxCostMisses; … … 2752 2755 OspSplitCandidate *backCandidate = new OspSplitCandidate(tBackData); 2753 2756 2757 Debug << "here 54 " << tFrontData.mNode << " " << tBackData.mNode << endl; 2758 2754 2759 EvalSplitCandidate(*frontCandidate); 2755 2760 EvalSplitCandidate(*backCandidate); … … 2766 2771 if (newNode->IsLeaf()) 2767 2772 { 2768 //KdLeaf *leaf = dynamic_cast<KdLeaf *>(newNode);2769 2773 EvaluateLeafStats(tData); 2770 2774 } 2771 2775 Debug << "here888 "<< endl; 2772 2776 //-- cleanup 2773 2777 tData.Clear(); 2774 2778 Debug << "here876"<< endl; 2775 2779 return newNode; 2776 2780 } … … 2782 2786 float backProb; 2783 2787 2784 KdLeaf *leaf = dynamic_cast<KdLeaf *>(splitCandidate.mParentData.mNode);2785 2786 2788 // compute locally best split plane 2787 2789 const bool success = 2788 2790 SelectSplitPlane(splitCandidate.mParentData, splitCandidate.mSplitPlane, frontProb, backProb); 2789 2791 2790 //TODO2792 const float priority = EvalRenderCostDecrease(splitCandidate.mSplitPlane, splitCandidate.mParentData); 2791 2793 // compute global decrease in render cost 2792 splitCandidate.SetPriority(EvalRenderCostDecrease(splitCandidate.mSplitPlane, splitCandidate.mParentData)); 2793 splitCandidate.mMaxCostMisses = success ? splitCandidate.mParentData.mMaxCostMisses : splitCandidate.mParentData.mMaxCostMisses + 1; 2794 splitCandidate.SetPriority(priority); 2795 2796 splitCandidate.mMaxCostMisses = 2797 success ? splitCandidate.mParentData.mMaxCostMisses : splitCandidate.mParentData.mMaxCostMisses + 1; 2794 2798 } 2795 2799 … … 2798 2802 { 2799 2803 // matt: TODO 2800 return true; 2801 /* (((int)data.mRays->size() <= mTermMinRays) || 2802 (data.mPvs <= mTermMinPvs) || 2803 (data.mProbability <= mTermMinProbability) || 2804 (data.GetAvgRayContribution() > mTermMaxRayContribution) || 2805 (data.mDepth >= mTermMaxDepth));*/ 2804 return ( 2805 //(data.mNode->mObjects.size() < mTermMinObjects) || 2806 //(data.mProbability <= mTermMinProbability) || 2807 (data.mDepth >= mTermMaxDepth) 2808 ); 2806 2809 } 2807 2810 … … 2810 2813 { 2811 2814 // matt: TODO 2812 return true; 2813 /*(mOutOfMemory || 2814 (mVspStats.Leaves() >= mMaxViewCells) || 2815 (mGlobalCostMisses >= mTermGlobalCostMissTolerance));*/ 2815 Debug << "here888 " << mTermMaxLeaves << " " << mOspStats.Leaves() << endl; 2816 return ( 2817 (mOspStats.Leaves() >= mTermMaxLeaves) 2818 //mOutOfMemory || 2819 //(mGlobalCostMisses >= mTermGlobalCostMissTolerance) 2820 ); 2816 2821 } 2817 2822 … … 2819 2824 void OspTree::EvaluateLeafStats(const OspTraversalData &data) 2820 2825 { 2821 #if TODO2822 2826 // the node became a leaf -> evaluate stats for leafs 2823 VspLeaf *leaf = dynamic_cast<VspLeaf *>(data.mNode);2824 2825 if (data.mPvs > m VspStats.maxPvs)2826 { 2827 m VspStats.maxPvs = data.mPvs;2828 } 2829 2830 m VspStats.pvs += data.mPvs;2831 2832 if (data.mDepth < m VspStats.minDepth)2833 { 2834 m VspStats.minDepth = data.mDepth;2827 KdLeaf *leaf = data.mNode; 2828 2829 if (data.mPvs > mOspStats.maxPvs) 2830 { 2831 mOspStats.maxPvs = data.mPvs; 2832 } 2833 2834 mOspStats.pvs += data.mPvs; 2835 2836 if (data.mDepth < mOspStats.minDepth) 2837 { 2838 mOspStats.minDepth = data.mDepth; 2835 2839 } 2836 2840 2837 2841 if (data.mDepth >= mTermMaxDepth) 2838 2842 { 2839 ++ m VspStats.maxDepthNodes;2843 ++ mOspStats.maxDepthNodes; 2840 2844 //Debug << "new max depth: " << mVspStats.maxDepthNodes << endl; 2841 2845 } 2842 2846 2843 // accumulate rays to compute rays / leaf 2844 mVspStats.accumRays += (int)data.mRays->size(); 2845 2846 if (data.mPvs < mTermMinPvs) 2847 ++ mVspStats.minPvsNodes; 2848 2849 if ((int)data.mRays->size() < mTermMinRays) 2850 ++ mVspStats.minRaysNodes; 2851 2852 if (data.GetAvgRayContribution() > mTermMaxRayContribution) 2853 ++ mVspStats.maxRayContribNodes; 2847 // if (data.mPvs < mTermMinPvs) 2848 // ++ mOspStats.minPvsNodes; 2854 2849 2855 2850 if (data.mProbability <= mTermMinProbability) 2856 ++ m VspStats.minProbabilityNodes;2851 ++ mOspStats.minProbabilityNodes; 2857 2852 2858 2853 // accumulate depth to compute average depth 2859 m VspStats.accumDepth += data.mDepth;2860 2861 ++ mCreated ViewCells;2854 mOspStats.accumDepth += data.mDepth; 2855 2856 ++ mCreatedLeaves; 2862 2857 2863 2858 #ifdef _DEBUG 2864 2859 Debug << "BSP stats: " 2865 2860 << "Depth: " << data.mDepth << " (max: " << mTermMaxDepth << "), " 2866 << "PVS: " << data.mPvs << " (min: " << mTermMinPvs << "), " 2867 << "Area: " << data.mProbability << " (min: " << mTermMinProbability << "), " 2868 << "#rays: " << (int)data.mRays->size() << " (max: " << mTermMinRays << "), " 2869 << "#pvs: " << leaf->GetViewCell()->GetPvs().GetSize() << "), " 2870 << "#avg ray contrib (pvs): " << (float)data.mPvs / (float)data.mRays->size() << endl; 2871 #endif 2872 2861 // << "PVS: " << data.mPvs << " (min: " << mTermMinPvs << "), " 2862 << "Prob: " << data.mProbability << " (min: " << mTermMinProbability << "), " 2863 << "#pvs: " << data.mPvs << ")\n"; 2873 2864 #endif 2874 2865 } … … 2879 2870 const int axis, 2880 2871 float &position, 2881 int &objects Back,2882 int &objects Front)2872 int &objectsFront, 2873 int &objectsBack) 2883 2874 { 2884 2875 … … 2889 2880 // C = ct_div_ci + (ol + or)/queries 2890 2881 2891 int pvsSize = PrepareHeuristics(node->mObjects); ;2882 int pvsSize = PrepareHeuristics(node->mObjects); 2892 2883 int pvsl = 0, pvsr = pvsSize; 2893 2884 … … 3009 3000 int OspTree::PrepareHeuristics(Intersectable *object) 3010 3001 { 3002 #if COUNT_OBJECTS 3003 return 1; 3004 #else 3011 3005 ViewCellPvsMap::const_iterator vit, vit_end = object->mViewCellPvs.mEntries.end(); 3012 3006 … … 3030 3024 3031 3025 return pvsSize; 3026 #endif 3032 3027 } 3033 3028 … … 3073 3068 3074 3069 3070 void OspTree::SetViewCellsManager(ViewCellsManager *vcm) 3071 { 3072 mViewCellsManager = vcm; 3073 } 3074 3075 3076 AxisAlignedBox3 OspTree::GetBoundingBox() const 3077 { 3078 return mBoundingBox; 3079 } 3080 3081 3075 3082 void OspTree::RemoveContriFromPvs(Intersectable *object, int &pvs) const 3076 3083 { 3084 #if COUNT_OBJECTS 3085 -- pvs; 3086 #else 3077 3087 ViewCellPvsMap::const_iterator vit, vit_end = object->mViewCellPvs.mEntries.end(); 3078 3088 … … 3086 3096 } 3087 3097 } 3098 #endif 3088 3099 } 3089 3100 … … 3093 3104 ViewCellPvsMap::const_iterator vit, vit_end = object->mViewCellPvs.mEntries.end(); 3094 3105 3106 #if COUNT_OBJECTS 3107 ++ pvs; 3108 #else 3095 3109 for (vit = object->mViewCellPvs.mEntries.begin(); vit != vit_end; ++ vit) 3096 3110 { … … 3103 3117 } 3104 3118 } 3119 #endif 3105 3120 } 3106 3121 … … 3127 3142 } 3128 3143 3129 /* 3130 //sAxis = 2; 3144 // -- evaluate split cost for all three axis 3131 3145 for (int axis = 0; axis < 3; ++ axis) 3132 3146 { 3133 3147 if (!mOnlyDrivingAxis || (axis == sAxis)) 3134 3148 { 3135 //-- place split plane using heuristics 3136 3137 if (mUseCostHeuristics) 3138 { 3149 if (1 || mUseCostHeuristics) 3150 { 3151 //-- place split plane using heuristics 3152 int objectsFront, objectsBack; 3153 3139 3154 nCostRatio[axis] = 3140 EvalLocalCostHeuristics(*tData.mRays, 3141 box, 3142 tData.mPvs, 3143 axis, 3144 nPosition[axis]); 3145 } 3146 else //-- split plane position is spatial median 3147 { 3155 EvalLocalCostHeuristics(tData.mNode, 3156 tData.mBoundingBox, 3157 axis, 3158 nPosition[axis], 3159 objectsFront, 3160 objectsBack); 3161 } 3162 /* else 3163 { 3164 //-- split plane position is spatial median 3165 3148 3166 nPosition[axis] = (box.Min()[axis] + box.Max()[axis]) * 0.5f; 3149 3167 … … 3154 3172 nProbFront[axis], 3155 3173 nProbBack[axis]); 3156 } 3174 }*/ 3157 3175 3158 3176 if (bestAxis == -1) … … 3167 3185 } 3168 3186 3169 */3170 3187 //-- assign values 3171 3188 3172 3189 plane.mAxis = bestAxis; 3173 3190 // split plane position … … 3184 3201 float OspTree::EvalViewCellPvsIncr(Intersectable *object) const 3185 3202 { 3186 return 0; 3203 // TODO 3204 return 1; 3187 3205 } 3188 3206 … … 3206 3224 3207 3225 Intersectable::NewMail(); 3226 KdLeaf::NewMail(); 3208 3227 ViewCell::NewMail(); 3209 3228 3210 KdLeaf *leaf = d ynamic_cast<KdLeaf *>(data.mNode);3229 KdLeaf *leaf = data.mNode; 3211 3230 ObjectContainer::const_iterator oit, oit_end = leaf->mObjects.end(); 3212 3231 … … 3252 3271 3253 3272 const float normalizedOldRenderCost = oldRenderCost / mBoundingBox.GetVolume(); 3273 3254 3274 return factor * renderCostDecrease + (1.0f - factor) * normalizedOldRenderCost; 3255 3275 } … … 3315 3335 3316 3336 3317 3318 /*********************************************************************/ 3319 /* class HierarchyManager implementation */ 3320 /*********************************************************************/ 3337 void OspTree::CollectLeaves(vector<KdLeaf *> &leaves) const 3338 { 3339 stack<KdNode *> nodeStack; 3340 nodeStack.push(mRoot); 3341 3342 while (!nodeStack.empty()) 3343 { 3344 KdNode *node = nodeStack.top(); 3345 nodeStack.pop(); 3346 if (node->IsLeaf()) 3347 { 3348 KdLeaf *leaf = (KdLeaf *)node; 3349 leaves.push_back(leaf); 3350 } 3351 else 3352 { 3353 KdInterior *interior = (KdInterior *)node; 3354 nodeStack.push(interior->mBack); 3355 nodeStack.push(interior->mFront); 3356 } 3357 } 3358 } 3359 3360 3361 AxisAlignedBox3 OspTree::GetBBox(KdNode *node) const 3362 { 3363 if (!node->mParent) 3364 return mBoundingBox; 3365 3366 if (!node->IsLeaf()) 3367 { 3368 return (dynamic_cast<KdInterior *>(node))->mBox; 3369 } 3370 3371 KdInterior *parent = dynamic_cast<KdInterior *>(node->mParent); 3372 3373 AxisAlignedBox3 box(parent->mBox); 3374 3375 if (parent->mFront == node) 3376 box.SetMin(parent->mAxis, parent->mPosition); 3377 else 3378 box.SetMax(parent->mAxis, parent->mPosition); 3379 3380 return box; 3381 } 3382 3383 3384 /********************************************************************/ 3385 /* class HierarchyManager implementation */ 3386 /********************************************************************/ 3321 3387 3322 3388 … … 3330 3396 SplitCandidate *HierarchyManager::NextSplitCandidate() 3331 3397 { 3332 SplitCandidate *splitCandidate = static_cast<SplitCandidate *>(mTQueue.Top()); 3333 //Debug << "priority: " << splitCandidate->GetPriority() << endl; 3398 SplitCandidate *splitCandidate = mTQueue.Top(); 3399 3400 Debug << "next candidate: " << splitCandidate->Type() 3401 << ", priority: " << splitCandidate->GetPriority() << endl; 3402 3334 3403 mTQueue.Pop(); 3335 3404 … … 3415 3484 3416 3485 // first osp traversal data 3417 OspTree::OspTraversalData oData( mOspTree.mRoot,3486 OspTree::OspTraversalData oData(leaf, 3418 3487 0, 3419 &rays,3420 3488 pvsSize, 3421 3489 prop, … … 3455 3523 3456 3524 void HierarchyManager::Construct2(const VssRayContainer &sampleRays, 3457 const ObjectContainer &objects,3458 AxisAlignedBox3 *forcedViewSpace)3525 const ObjectContainer &objects, 3526 AxisAlignedBox3 *forcedViewSpace) 3459 3527 { 3460 3528 RayInfoContainer *rays = new RayInfoContainer(); … … 3493 3561 3494 3562 cout << "finished in " << TimeDiff(startTime, GetTime()) * 1e-3 << " secs" << endl; 3495 3496 3563 3497 3564 const int pvsSize = mVspTree.ComputePvsSize(*rays); … … 3549 3616 3550 3617 cout << "finished in " << TimeDiff(startTime, GetTime())*1e-3 << " secs" << endl; 3551 3552 3618 mVspTree.mVspStats.Stop(); 3553 3554 3619 3620 Debug << "object space" << endl; 3555 3621 3556 3622 //-- object space partition … … 3566 3632 3567 3633 //-- first osp traversal data 3568 OspTree::OspTraversalData oData( mOspTree.mRoot,3634 OspTree::OspTraversalData oData(leaf, 3569 3635 0, 3570 rays,3571 3636 pvsSize, 3572 3637 prop, … … 3580 3645 mOspTree.EvalSplitCandidate(*oSplitCandidate); 3581 3646 3582 mTQueue.Push( splitCandidate);3647 mTQueue.Push(oSplitCandidate); 3583 3648 3584 3649 i = 0; … … 3590 3655 GlobalTerminationCriteriaMet(splitCandidate); 3591 3656 3592 cout << " view cells: " << i ++ << endl;3657 cout << "kd nodes: " << i ++ << endl; 3593 3658 3594 3659 // cost ratio of cost decrease / totalCost … … 3609 3674 DEL_PTR(splitCandidate); 3610 3675 } 3611 3676 3612 3677 cout << "finished in " << TimeDiff(startTime, GetTime())*1e-3 << " secs" << endl; 3613 3678 }
Note: See TracChangeset
for help on using the changeset viewer.