- Timestamp:
- 11/17/05 02:26:30 (19 years ago)
- Location:
- trunk/VUT/GtpVisibilityPreprocessor
- Files:
-
- 13 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/VUT/GtpVisibilityPreprocessor/scripts/default.env
r418 r419 95 95 # input fromViewCells 96 96 # input fromSceneGeometry 97 samples 1 0000097 samples 150000 98 98 sideTolerance 0.005 99 99 } … … 140 140 Termination { 141 141 # parameters used for autopartition 142 maxRays 200142 maxRays 100 143 143 maxPolygons -1 144 144 maxDepth 40 … … 173 173 Simulation { 174 174 objRenderCost 1.0 175 vcOverhead 1.0176 moveSpeed 1.0175 vcOverhead 7.0 176 moveSpeed 3.0 177 177 } 178 178 -
trunk/VUT/GtpVisibilityPreprocessor/src/Environment.cpp
r414 r419 1315 1315 "20"); 1316 1316 1317 RegisterOption("ViewCells.maxViewCells",1318 optInt,1319 "-view_cells_max_viewcells=",1320 "0");1321 1322 1317 RegisterOption("BspTree.Visualization.samples", 1323 1318 optInt, -
trunk/VUT/GtpVisibilityPreprocessor/src/Preprocessor.cpp
r416 r419 30 30 { 31 31 X3dParser parser; 32 int maxViewCells = 0;32 33 33 environment->GetFloatValue("ViewCells.height", parser.mViewCellHeight); 34 environment->GetIntValue("ViewCells.maxViewCells", maxViewCells); 35 36 bool loaded = parser.ParseFile(filename, mViewCells); 37 38 if (maxViewCells > 0) 39 { 40 while (mViewCells.size() > maxViewCells) 41 { 42 ViewCell *vc = mViewCells.back(); 43 DEL_PTR(vc); 44 mViewCells.pop_back(); 45 } 46 } 47 return loaded; 34 35 return parser.ParseFile(filename, mViewCells); 48 36 } 49 37 … … 121 109 } 122 110 123 bool124 Preprocessor::GenerateViewCells()125 {126 // TODO127 // HACK: derive view cells from the scene objects128 ObjectContainer objects;129 130 int maxViewCells = 0;131 environment->GetIntValue("ViewCells.maxViewCells", maxViewCells);132 133 mSceneGraph->CollectObjects(&objects);134 ViewCell::DeriveViewCells(objects, mViewCells, maxViewCells);135 136 return true;137 }138 139 111 int 140 SplitFilenames(const string str, 141 vector<string> &filenames) 112 SplitFilenames(const string str, vector<string> &filenames) 142 113 { 143 114 int pos = 0; -
trunk/VUT/GtpVisibilityPreprocessor/src/Preprocessor.h
r411 r419 46 46 */ 47 47 virtual bool LoadViewCells(const string filename); 48 49 /** Generate the viewCells automatically. The particular algorithm to be used depends50 on the environment setting. Initially the generated viewcells will cover the whole51 bounding volume of the scene. They can be pruned later depending on the results52 of visibility computations.53 @return true on successful viewcell generation.54 */55 virtual bool GenerateViewCells();56 48 57 49 /** Export all preprocessed data in a XML format understandable by the -
trunk/VUT/GtpVisibilityPreprocessor/src/RenderSimulator.cpp
r418 r419 183 183 mStat.avgRtWithoutOverhead = renderTime; 184 184 mStat.avgRenderTime = renderTime + loadPvsOverhead; 185 185 mStat.maxCost /= pCrossVcTotal; 186 mStat.minCost /= pCrossVcTotal; 187 186 188 mStat.Stop(); 187 189 -
trunk/VUT/GtpVisibilityPreprocessor/src/SamplingPreprocessor.cpp
r418 r419 573 573 if (exporter) 574 574 { 575 exporter->ExportBspLeaves(*mBspTree, 350/*stat.maxPvs*/);575 exporter->ExportBspLeaves(*mBspTree, stat.maxPvs); 576 576 //exporter->ExportBspViewCellPartition(*mBspTree, 0); 577 577 delete exporter; … … 609 609 if (exporter) 610 610 { 611 exporter->ExportBspViewCellPartition(*mBspTree, 350/*stat.maxPvs*/);611 exporter->ExportBspViewCellPartition(*mBspTree, stat.maxPvs); 612 612 //exporter->ExportBspViewCellPartition(*mBspTree, 0); 613 613 delete exporter; -
trunk/VUT/GtpVisibilityPreprocessor/src/ViewCell.cpp
r384 r419 27 27 return NULL; 28 28 } 29 } 30 31 const ViewCellPvs &ViewCell::GetPvs() const 32 { 33 return mPvs; 29 34 } 30 35 -
trunk/VUT/GtpVisibilityPreprocessor/src/ViewCell.h
r411 r419 23 23 */ 24 24 ViewCell(Mesh *mesh); 25 /** Returns Pv S.25 /** Returns Pvs. 26 26 */ 27 const ViewCellPvs &GetPvs() const; 27 28 ViewCellPvs &GetPvs(); 28 29 -
trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.h
r414 r419 770 770 771 771 public: 772 /// Parses the environment and stores the global BSP tree parameters 772 /** Parses the environment and stores the global BSP tree parameters 773 */ 773 774 static void ParseEnvironment(); 774 775 -
trunk/VUT/GtpVisibilityPreprocessor/src/VspKdTree.cpp
r418 r419 28 28 int VspKdTreeLeaf::mailID = 0; 29 29 int VspKdTree::sTermMaxDepth = 10; 30 float VspKdTree::sTermMinSize = 0.1 ;30 float VspKdTree::sTermMinSize = 0.1f; 31 31 int VspKdTree::sTermMinPvs = 10; 32 32 int VspKdTree::sTermMinRays = 20; 33 float VspKdTree::sTermMaxCostRatio = 0.1 ;34 float VspKdTree::sTermMaxRayContribution = 0.1 ;33 float VspKdTree::sTermMaxCostRatio = 0.1f; 34 float VspKdTree::sTermMaxRayContribution = 0.1f; 35 35 36 36 … … 71 71 72 72 /**************************************************************/ 73 * VspKdTreeInterior implementation * 73 /* VspKdTreeInterior implementation */ 74 74 /**************************************************************/ 75 75 … … 81 81 int VspKdTreeInterior::GetAccessTime() 82 82 { 83 return lastAccessTime;83 return mLastAccessTime; 84 84 } 85 85 … … 101 101 int VspKdTreeInterior::Type() const 102 102 { 103 return VspKdInterior;103 return EInterior; 104 104 } 105 105 … … 112 112 void VspKdTreeInterior::Print(ostream &s) const 113 113 { 114 if ( axis == 0)114 if (mAxis == 0) 115 115 s << "x "; 116 116 else 117 if ( axis == 1)117 if (mAxis == 1) 118 118 s << "y "; 119 119 else 120 120 s << "z "; 121 s << position << " ";121 s << mPosition << " "; 122 122 123 123 mBack->Print(s); … … 127 127 int VspKdTreeInterior::ComputeRayIntersection(const RayInfo &rayData, float &t) 128 128 { 129 return rayData.ComputeRayIntersection(axis, position, t); 130 } 131 129 return rayData.ComputeRayIntersection(mAxis, mPosition, t); 130 } 131 132 VspKdTreeNode *VspKdTreeInterior::GetBack() const 133 { 134 return mBack; 135 } 136 137 VspKdTreeNode *VspKdTreeInterior::GetFront() const 138 { 139 return mFront; 140 } 141 142 /**************************************************/ 143 /* class VspKdTree implementation */ 144 /**************************************************/ 145 void VspKdTree::ParseEnvironment() 146 { 147 environment->GetIntValue("VspKdTree.Termination.maxDepth", sTermMaxDepth); 148 environment->GetIntValue("VspKdTree.Termination.minPvs", sTermMinPvs); 149 environment->GetIntValue("VspKdTree.Termination.minRays", sTermMinRays); 150 environment->GetFloatValue("VspKdTree.Termination.maxRayContribution", sTermMaxRayContribution); 151 environment->GetFloatValue("VspKdTree.Termination.maxCostRatio", sTermMaxCostRatio); 152 153 environment->GetFloatValue("VspKdTree.Termination.minSize", sTermMinSize); 154 sTermMinSize = sqr(sTermMinSize); 155 } 132 156 133 157 // Constructor 134 158 VspKdTree::VspKdTree() 135 { 136 environment->GetIntValue("VspKdTree.maxDepth", sTermMaxDepth); 137 environment->GetIntValue("VspKdTree.minPvs", sTermMinPvs); 138 environment->GetIntValue("VspKdTree.minRays", sTermMinRays); 139 environment->GetFloatValue("VspKdTree.maxRayContribution", sTermMaxRayContribution); 140 environment->GetFloatValue("VspKdTree.maxCostRatio", sTermMaxCostRatio); 141 142 environment->GetFloatValue("VspKdTree.minSize", sTermMinSize); 143 termMinSize = sqr(termMinSize); 144 159 { 145 160 environment->GetFloatValue("VspKdTree.epsilon", epsilon); 146 161 environment->GetFloatValue("VspKdTree.ct_div_ci", ct_div_ci); … … 150 165 151 166 152 float refDirAngle;153 167 environment->GetIntValue("VspKdTree.accessTimeThreshold", accessTimeThreshold); 154 168 //= 1000; … … 174 188 } 175 189 176 environment->GetBoolValue("VspKdTree.randomize", randomize);177 178 190 mRoot = NULL; 179 191 … … 184 196 VspKdTree::~VspKdTree() 185 197 { 186 if (mRoot) 187 delete mRoot; 198 DEL_PTR(mRoot); 188 199 } 189 200 … … 298 309 maxMemory = maxStaticMemory; 299 310 300 if (root) 301 delete root; 302 303 root = new VspKdTreeLeaf(NULL, rays.size()); 311 DEL_PTR(mRoot); 312 313 mRoot = new VspKdTreeLeaf(NULL, (int)rays.size()); 304 314 305 315 // first construct a leaf that will get subdivide 306 VspKdTreeLeaf *leaf = (VspKdTreeLeaf *) root;316 VspKdTreeLeaf *leaf = dynamic_cast<VspKdTreeLeaf *>(mRoot); 307 317 308 318 309 319 mStat.nodes = 1; 310 320 311 bbox.Initialize(); 312 dirBBox.Initialize(); 313 321 mBox.Initialize(); 314 322 315 323 for (VssRayContainer::const_iterator ri = rays.begin(); ri != rays.end(); ++ ri) … … 317 325 leaf->AddRay(VspKdTreeNode::RayInfo(*ri)); 318 326 319 bbox.Include((*ri)->GetOrigin()); 320 bbox.Include((*ri)->GetTermination()); 321 322 dirBBox.Include(Vector3((*ri)->GetDirParametrization(0), (*ri)->GetDirParametrization(1), 0)); 327 mBox.Include((*ri)->GetOrigin()); 328 mBox.Include((*ri)->GetTermination()); 323 329 } 324 330 325 331 if (forcedBoundingBox) 326 bbox = *forcedBoundingBox; 327 328 cout<<"Bbox = "<<bbox<<endl; 329 cout<<"Dirr Bbox = "<<dirBBox<<endl; 330 331 mStat.rays = leaf->rays.size(); 332 mBox = *forcedBoundingBox; 333 334 cout << "Bbox = " << mBox << endl; 335 336 mStat.rays = (int)leaf->rays.size(); 332 337 leaf->UpdatePvsSize(); 333 338 … … 335 340 336 341 // Subdivide(); 337 root = Subdivide(TraversalData(leaf, bbox, 0));342 mRoot = Subdivide(TraversalData(leaf, mBox, 0)); 338 343 339 344 if (splitCandidates) … … 390 395 391 396 392 VspKdTreeNode *node = SubdivideNode((VspKdTreeLeaf *) data. node,393 data. bbox, backBox, frontBox);397 VspKdTreeNode *node = SubdivideNode((VspKdTreeLeaf *) data.mNode, 398 data.mBox, backBox, frontBox); 394 399 if (result == NULL) 395 400 result = node; … … 400 405 401 406 // push the children on the stack 402 tStack.push(TraversalData(interior-> back, backBox, data.depth+1));403 tStack.push(TraversalData(interior-> front, frontBox, data.depth+1));407 tStack.push(TraversalData(interior->GetBack(), backBox, data.mDepth + 1)); 408 tStack.push(TraversalData(interior->GetFront(), frontBox, data.mDepth + 1)); 404 409 } 405 410 else … … 453 458 } 454 459 455 if (costRatio > termMaxCostRatio)460 if (costRatio > sTermMaxCostRatio) 456 461 { 457 462 // cout<<"Too big cost ratio "<<costRatio<<endl; … … 496 501 Intersectable::NewMail(3); 497 502 498 if (axis <= VspKdTreeNode::SPLIT_Z) { 499 // this is the main ray classification loop! 503 // this is the main ray classification loop! 500 504 for(VspKdTreeNode::RayInfoContainer::iterator ri = leaf->rays.begin(); 501 505 ri != leaf->rays.end(); ri++) 502 if ((*ri).mRay->IsActive()) 503 { 504 // determine the side of this ray with respect to the plane 505 int side = (*ri).ComputeRayIntersection(axis, position, (*ri).mRay->mT); 506 // (*ri).mRay->mSide = side; 506 { 507 if (!(*ri).mRay->IsActive()) 508 continue; 507 509 508 if (side <= 0) 509 raysBack ++; 510 // determine the side of this ray with respect to the plane 511 int side = (*ri).ComputeRayIntersection(axis, position, (*ri).mRay->mT); 512 // (*ri).mRay->mSide = side; 513 514 if (side <= 0) 515 ++ raysBack; 510 516 511 512 raysFront++;517 if (side >= 0) 518 ++ raysFront; 513 519 514 AddObject2Pvs((*ri).mRay->mTerminationObject, side, pvsBack, pvsFront); 515 } 520 AddObject2Pvs((*ri).mRay->mTerminationObject, side, pvsBack, pvsFront); 521 } 522 523 AxisAlignedBox3 box = GetBBox(leaf); 524 525 float minBox = box.Min(axis); 526 float maxBox = box.Max(axis); 527 float sizeBox = maxBox - minBox; 516 528 517 AxisAlignedBox3 box = GetBBox(leaf); 518 519 float minBox = box.Min(axis); 520 float maxBox = box.Max(axis); 521 float sizeBox = maxBox - minBox; 522 523 // float sum = raysBack*(position - minBox) + raysFront*(maxBox - position); 524 float sum = pvsBack*(position - minBox) + pvsFront*(maxBox - position); 525 526 newCost = ct_div_ci + sum/sizeBox; 527 } 528 else 529 { 530 // directional split 531 for(VspKdTreeNode::RayInfoContainer::iterator ri = leaf->rays.begin(); 532 ri != leaf->rays.end(); ++ ri) 533 if ((*ri).mRay->IsActive()) 534 { 535 // determine the side of this ray with respect to the plane 536 int side; 537 if ((*ri).mRay->GetDirParametrization(axis - 3) > position) 538 side = 1; 539 else 540 side = -1; 541 542 if (side <= 0) 543 raysBack++; 544 545 if (side >= 0) 546 raysFront++; 547 548 // (*ri).mRay->mSide = side; 549 AddObject2Pvs((*ri).mRay->mTerminationObject, side, pvsBack, pvsFront); 550 } 551 552 AxisAlignedBox3 box = GetDirBBox(leaf); 553 554 float minBox = box.Min(axis - 3); 555 float maxBox = box.Max(axis - 3); 556 float sizeBox = maxBox - minBox; 557 558 // float sum = raysBack*(position - minBox) + raysFront*(maxBox - position); 559 float sum = pvsBack*(position - minBox) + pvsFront*(maxBox - position); 560 // float sum = pvsBack + pvsFront; 561 newCost = ct_div_ci + sum/sizeBox; 562 } 563 529 // float sum = raysBack*(position - minBox) + raysFront*(maxBox - position); 530 float sum = pvsBack*(position - minBox) + pvsFront*(maxBox - position); 531 532 newCost = ct_div_ci + sum/sizeBox; 533 564 534 // cout<<axis<<" "<<pvsSize<<" "<<pvsBack<<" "<<pvsFront<<endl; 565 535 // float oldCost = leaf->rays.size(); 566 float oldCost = pvsSize;536 float oldCost = (float)pvsSize; 567 537 568 538 float ratio = newCost / oldCost; … … 587 557 588 558 AxisAlignedBox3 sBox = GetBBox(leaf); 589 AxisAlignedBox3 dBox = GetDirBBox(leaf);590 559 591 560 // int sAxis = box.Size().DrivingAxis(); 592 561 int sAxis = sBox.Size().DrivingAxis(); 593 int dAxis = dBox.Size().DrivingAxis() + 3; 594 562 595 563 bool onlyDrivingAxis = true; 596 564 597 565 for (axis = 0; axis < 6; ++ axis) 598 566 { 599 if (!onlyDrivingAxis || axis == sAxis || axis == dAxis) 600 { 601 if (axis < 3) 602 nPosition[axis] = (sBox.Min()[axis] + sBox.Max()[axis])*0.5f; 603 else 604 nPosition[axis] = (dBox.Min()[axis-3] + dBox.Max()[axis-3])*0.5f; 605 567 if (!onlyDrivingAxis || axis == sAxis) 568 { 569 nPosition[axis] = (sBox.Min()[axis] + sBox.Max()[axis])*0.5f; 570 606 571 nCostRatio[axis] = EvalCostRatio(leaf, 607 572 axis, … … 651 616 // C = ct_div_ci + (ql*rl + qr*rr)/queries 652 617 653 int rl=0, rr = leaf->rays.size();618 int rl=0, rr = (int)leaf->rays.size(); 654 619 int pl=0, pr = leaf->GetPvsSize(); 655 620 float minBox = box.Min(axis); … … 657 622 float sizeBox = maxBox - minBox; 658 623 659 float minBand = minBox + 0.1 *(maxBox - minBox);660 float maxBand = minBox + 0.9 *(maxBox - minBox);624 float minBand = minBox + 0.1f*(maxBox - minBox); 625 float maxBand = minBox + 0.9f*(maxBox - minBox); 661 626 662 627 float sum = rr*sizeBox; … … 743 708 } 744 709 745 float oldCost = leaf->GetPvsSize();710 float oldCost = (float)leaf->GetPvsSize(); 746 711 float newCost = ct_div_ci + minSum / sizeBox; 747 712 float ratio = newCost / oldCost; … … 789 754 { 790 755 // the node became a leaf -> evaluate stats for leafs 791 VspKdTreeLeaf *leaf = (VspKdTreeLeaf *)data.node;792 793 if (data. depth >= termMaxDepth)756 VspKdTreeLeaf *leaf = dynamic_cast<VspKdTreeLeaf *>(data.mNode); 757 758 if (data.mDepth >= sTermMaxDepth) 794 759 ++ mStat.maxDepthNodes; 795 760 796 761 // if ( (int)(leaf->rays.size()) < termMinCost) 797 762 // stat.minCostNodes++; 798 if (leaf->GetPvsSize() < termMinPvs)763 if (leaf->GetPvsSize() < sTermMinPvs) 799 764 ++ mStat.minPvsNodes; 800 765 801 if (leaf->GetPvsSize() < termMinRays)766 if (leaf->GetPvsSize() < sTermMinRays) 802 767 ++ mStat.minRaysNodes; 803 768 804 if (0 && leaf->GetAvgRayContribution() > termMaxRayContribution)769 if (0 && leaf->GetAvgRayContribution() > sTermMaxRayContribution) 805 770 ++ mStat.maxRayContribNodes; 806 771 807 if (SqrMagnitude(data. bbox.Size()) <= termMinSize)772 if (SqrMagnitude(data.mBox.Size()) <= sTermMinSize) 808 773 ++ mStat.minSizeNodes; 809 774 … … 819 784 AxisAlignedBox3 &frontBBox) 820 785 { 821 if ( (leaf->GetPvsSize() < termMinPvs) || (leaf->rays.size() < termMinRays) ||786 if ( (leaf->GetPvsSize() < sTermMinPvs) || (leaf->rays.size() < sTermMinRays) || 822 787 // (leaf->GetAvgRayContribution() > termMaxRayContribution ) || 823 (leaf-> depth >= termMaxDepth) || SqrMagnitude(box.Size()) <= termMinSize )788 (leaf->mDepth >= sTermMaxDepth) || SqrMagnitude(box.Size()) <= sTermMinSize ) 824 789 { 825 790 826 791 #if 0 827 if (leaf-> depth >= termMaxDepth) {828 cout<<"Warning: max depth reached depth="<<(int)leaf-> depth<<" rays="<<leaf->rays.size()<<endl;792 if (leaf->mDepth >= termMaxDepth) { 793 cout<<"Warning: max depth reached depth="<<(int)leaf->mDepth<<" rays="<<leaf->rays.size()<<endl; 829 794 cout<<"Bbox: "<<GetBBox(leaf)<<" dirbbox:"<<GetDirBBox(leaf)<<endl; 830 795 } … … 856 821 857 822 // add the new nodes to the tree 858 VspKdTreeInterior *node = new VspKdTreeInterior(leaf->parent); 859 860 node->axis = axis; 861 node->position = position; 862 node->bbox = box; 863 node->dirBBox = GetDirBBox(leaf); 864 823 VspKdTreeInterior *node = new VspKdTreeInterior(leaf->mParent); 824 825 node->mAxis = axis; 826 node->mPosition = position; 827 node->mBox = box; 828 865 829 backBBox = box; 866 830 frontBBox = box; … … 872 836 873 837 // replace a link from node's parent 874 if (leaf-> parent)875 leaf-> parent->ReplaceChildLink(leaf, node);838 if (leaf->mParent) 839 leaf->mParent->ReplaceChildLink(leaf, node); 876 840 // and setup child links 877 841 node->SetupChildLinks(back, front); … … 967 931 int released; 968 932 969 tstack.push( root);933 tstack.push(mRoot); 970 934 971 935 while (!tstack.empty()) … … 976 940 if (!node->IsLeaf()) 977 941 { 978 VspKdTreeInterior *in = (VspKdTreeInterior *)node;942 VspKdTreeInterior *in = dynamic_cast<VspKdTreeInterior *>(node); 979 943 // cout<<"depth="<<(int)in->depth<<" time="<<in->lastAccessTime<<endl; 980 if (in-> depth >= minCollapseDepth && in->lastAccessTime <= maxAccessTime)944 if (in->mDepth >= minCollapseDepth && in->mLastAccessTime <= maxAccessTime) 981 945 { 982 946 released = CollapseSubtree(node, time); 983 947 break; 984 948 } 985 if (in-> back->GetAccessTime() < in->front->GetAccessTime())949 if (in->GetBack()->GetAccessTime() < in->GetFront()->GetAccessTime()) 986 950 { 987 tstack.push(in-> front);988 tstack.push(in-> back);951 tstack.push(in->GetFront()); 952 tstack.push(in->GetBack()); 989 953 } 990 954 else 991 955 { 992 tstack.push(in-> back);993 tstack.push(in-> front);956 tstack.push(in->GetBack()); 957 tstack.push(in->GetFront()); 994 958 } 995 959 } … … 1021 985 // check if we should perform a dynamic subdivision of the leaf 1022 986 if (// leaf->rays.size() > (unsigned)termMinCost && 1023 (leaf->GetPvsSize() >= termMinPvs) &&987 (leaf->GetPvsSize() >= sTermMinPvs) && 1024 988 (SqrMagnitude(leafBBox.Size()) > sizeThreshold) ) 1025 989 { … … 1078 1042 stack<RayTraversalData> tstack; 1079 1043 1080 tstack.push(RayTraversalData( root, VspKdTreeNode::RayInfo(ray)));1044 tstack.push(RayTraversalData(mRoot, VspKdTreeNode::RayInfo(ray))); 1081 1045 1082 1046 RayTraversalData data; … … 1088 1052 tstack.pop(); 1089 1053 1090 if (!data. node->IsLeaf())1054 if (!data.mNode->IsLeaf()) 1091 1055 { 1092 1056 // split the set of rays in two groups intersecting the … … 1099 1063 // remove the ray from the leaf 1100 1064 // find the ray in the leaf and swap it with the last ray... 1101 VspKdTreeLeaf *leaf = (VspKdTreeLeaf *)data. node;1065 VspKdTreeLeaf *leaf = (VspKdTreeLeaf *)data.mNode; 1102 1066 1103 1067 if (!leaf->Mailed()) … … 1168 1132 stack<RayTraversalData> tstack; 1169 1133 1170 tstack.push(RayTraversalData( root, VspKdTreeNode::RayInfo(ray)));1134 tstack.push(RayTraversalData(mRoot, VspKdTreeNode::RayInfo(ray))); 1171 1135 1172 1136 RayTraversalData data; … … 1177 1141 tstack.pop(); 1178 1142 1179 if (!data. node->IsLeaf())1143 if (!data.mNode->IsLeaf()) 1180 1144 { 1181 1145 TraverseInternalNode(data, tstack); … … 1185 1149 // remove the ray from the leaf 1186 1150 // find the ray in the leaf and swap it with the last ray... 1187 VspKdTreeLeaf *leaf = (VspKdTreeLeaf *)data. node;1188 leaf->AddRay(data. rayData);1151 VspKdTreeLeaf *leaf = (VspKdTreeLeaf *)data.mNode; 1152 leaf->AddRay(data.mRayData); 1189 1153 ++ mStat.addedRayRefs; 1190 1154 } … … 1195 1159 stack<RayTraversalData> &tstack) 1196 1160 { 1197 VspKdTreeInterior *in = (VspKdTreeInterior *) data. node;1198 1199 if (in-> axis <= VspKdTreeNode::SPLIT_Z)1161 VspKdTreeInterior *in = (VspKdTreeInterior *) data.mNode; 1162 1163 if (in->mAxis <= VspKdTreeNode::SPLIT_Z) 1200 1164 { 1201 1165 // determine the side of this ray with respect to the plane 1202 int side = in->ComputeRayIntersection(data. rayData, data.rayData.mRay->mT);1166 int side = in->ComputeRayIntersection(data.mRayData, data.mRayData.mRay->mT); 1203 1167 1204 1168 if (side == 0) 1205 1169 { 1206 if (data. rayData.mRay->HasPosDir(in->axis))1207 { 1208 tstack.push(RayTraversalData(in-> back,1209 VspKdTreeNode::RayInfo(data. rayData.mRay, data.rayData.mMinT,1210 data. rayData.mRay->mT)));1170 if (data.mRayData.mRay->HasPosDir(in->mAxis)) 1171 { 1172 tstack.push(RayTraversalData(in->GetBack(), 1173 VspKdTreeNode::RayInfo(data.mRayData.mRay, data.mRayData.mMinT, 1174 data.mRayData.mRay->mT))); 1211 1175 1212 tstack.push(RayTraversalData(in-> front,1213 VspKdTreeNode::RayInfo(data. rayData.mRay, data.rayData.mRay->mT,1214 data. rayData.mMaxT)));1176 tstack.push(RayTraversalData(in->GetFront(), 1177 VspKdTreeNode::RayInfo(data.mRayData.mRay, data.mRayData.mRay->mT, 1178 data.mRayData.mMaxT))); 1215 1179 1216 1180 } 1217 1181 else 1218 1182 { 1219 tstack.push(RayTraversalData(in-> back,1220 VspKdTreeNode::RayInfo(data. rayData.mRay,1221 data. rayData.mRay->mT,1222 data. rayData.mMaxT)));1223 tstack.push(RayTraversalData(in-> front,1224 VspKdTreeNode::RayInfo(data. rayData.mRay,1225 data. rayData.mMinT,1226 data. rayData.mRay->mT)));1183 tstack.push(RayTraversalData(in->GetBack(), 1184 VspKdTreeNode::RayInfo(data.mRayData.mRay, 1185 data.mRayData.mRay->mT, 1186 data.mRayData.mMaxT))); 1187 tstack.push(RayTraversalData(in->GetFront(), 1188 VspKdTreeNode::RayInfo(data.mRayData.mRay, 1189 data.mRayData.mMinT, 1190 data.mRayData.mRay->mT))); 1227 1191 } 1228 1192 } 1229 1193 else 1230 1194 if (side == 1) 1231 tstack.push(RayTraversalData(in-> front, data.rayData));1195 tstack.push(RayTraversalData(in->GetFront(), data.mRayData)); 1232 1196 else 1233 tstack.push(RayTraversalData(in-> back, data.rayData));1197 tstack.push(RayTraversalData(in->GetBack(), data.mRayData)); 1234 1198 } 1235 1199 else 1236 1200 { 1237 1201 // directional split 1238 if (data. rayData.mRay->GetDirParametrization(in->axis - 3) > in->position)1239 tstack.push(RayTraversalData(in-> front, data.rayData));1202 if (data.mRayData.mRay->GetDirParametrization(in->mAxis - 3) > in->mPosition) 1203 tstack.push(RayTraversalData(in->GetFront(), data.mRayData)); 1240 1204 else 1241 tstack.push(RayTraversalData(in-> back, data.rayData));1205 tstack.push(RayTraversalData(in->GetBack(), data.mRayData)); 1242 1206 } 1243 1207 } … … 1290 1254 else 1291 1255 { 1292 tstack.push(((VspKdTreeInterior *)node)-> back);1293 tstack.push(((VspKdTreeInterior *)node)-> front);1256 tstack.push(((VspKdTreeInterior *)node)->GetFront()); 1257 tstack.push(((VspKdTreeInterior *)node)->GetBack()); 1294 1258 } 1295 1259 } … … 1298 1262 1299 1263 // create a new node that will hold the rays 1300 VspKdTreeLeaf *newLeaf = new VspKdTreeLeaf(sroot-> parent, rayCount);1301 1302 if (newLeaf-> parent)1303 newLeaf-> parent->ReplaceChildLink(sroot, newLeaf);1264 VspKdTreeLeaf *newLeaf = new VspKdTreeLeaf(sroot->mParent, rayCount); 1265 1266 if (newLeaf->mParent) 1267 newLeaf->mParent->ReplaceChildLink(sroot, newLeaf); 1304 1268 1305 1269 tstack.push(sroot); … … 1312 1276 if (node->IsLeaf()) 1313 1277 { 1314 VspKdTreeLeaf *leaf = (VspKdTreeLeaf *) node;1278 VspKdTreeLeaf *leaf = dynamic_cast<VspKdTreeLeaf *>(node); 1315 1279 1316 1280 for(VspKdTreeNode::RayInfoContainer::iterator ri = leaf->rays.begin(); … … 1333 1297 else 1334 1298 { 1335 tstack.push(((VspKdTreeInterior *)node)->back); 1336 tstack.push(((VspKdTreeInterior *)node)->front); 1299 VspKdTreeInterior *interior = 1300 dynamic_cast<VspKdTreeInterior *>(node); 1301 tstack.push(interior->GetBack()); 1302 tstack.push(interior->GetFront()); 1337 1303 } 1338 1304 } … … 1368 1334 { 1369 1335 stack<VspKdTreeNode *> tstack; 1370 tstack.push( root);1336 tstack.push(mRoot); 1371 1337 1372 1338 Intersectable::NewMail(); … … 1407 1373 else 1408 1374 { 1409 VspKdTreeInterior *in = (VspKdTreeInterior *)node;1410 1411 if (in-> axis < 3)1375 VspKdTreeInterior *in = dynamic_cast<VspKdTreeInterior *>(node); 1376 1377 if (in->mAxis < 3) 1412 1378 { 1413 if (box.Max(in-> axis) >= in->position)1414 tstack.push(in-> front);1379 if (box.Max(in->mAxis) >= in->mPosition) 1380 tstack.push(in->GetFront()); 1415 1381 1416 if (box.Min(in-> axis) <= in->position)1417 tstack.push(in-> back);1382 if (box.Min(in->mAxis) <= in->mPosition) 1383 tstack.push(in->GetBack()); 1418 1384 } 1419 1385 else 1420 1386 { 1421 1387 // both nodes for directional splits 1422 tstack.push(in-> front);1423 tstack.push(in-> back);1388 tstack.push(in->GetFront()); 1389 tstack.push(in->GetBack()); 1424 1390 } 1425 1391 } … … 1434 1400 { 1435 1401 stack<VspKdTreeNode *> tstack; 1436 tstack.push( root);1402 tstack.push(mRoot); 1437 1403 1438 1404 minRayContribution = 1.0f; … … 1462 1428 VspKdTreeInterior *in = (VspKdTreeInterior *)node; 1463 1429 // both nodes for directional splits 1464 tstack.push(in-> front);1465 tstack.push(in-> back);1466 } 1467 } 1468 1469 cout <<"sum="<<sumRayContribution<<endl;1470 cout <<"leaves="<<leaves<<endl;1430 tstack.push(in->GetFront()); 1431 tstack.push(in->GetBack()); 1432 } 1433 } 1434 1435 cout << "sum=" << sumRayContribution << endl; 1436 cout << "leaves=" << leaves << endl; 1471 1437 avgRayContribution = sumRayContribution/(float)leaves; 1472 1438 } … … 1477 1443 { 1478 1444 stack<VspKdTreeNode *> tstack; 1479 tstack.push( root);1445 tstack.push(mRoot); 1480 1446 1481 1447 while (!tstack.empty()) … … 1494 1460 { 1495 1461 Vector3 origin = GetBBox(leaf).GetRandomPoint(); 1496 Vector3 dirVector = GetDirBBox(leaf).GetRandomPoint();1462 /*Vector3 dirVector = GetDirBBox(leaf).GetRandomPoint(); 1497 1463 Vector3 direction = Vector3(sin(dirVector.x), sin(dirVector.y), cos(dirVector.x)); 1498 1464 //cout<<"dir vector.x="<<dirVector.x<<"direction'.x="<<atan2(direction.x, direction.y)<<endl; 1499 rays.push_back(SimpleRay(origin, direction)); 1465 rays.push_back(SimpleRay(origin, direction));*/ 1500 1466 } 1501 1467 … … 1503 1469 else 1504 1470 { 1505 VspKdTreeInterior *in = (VspKdTreeInterior *)node; 1471 VspKdTreeInterior *in = 1472 dynamic_cast<VspKdTreeInterior *>(node); 1506 1473 // both nodes for directional splits 1507 tstack.push(in-> front);1508 tstack.push(in-> back);1474 tstack.push(in->GetFront()); 1475 tstack.push(in->GetBack()); 1509 1476 } 1510 1477 } … … 1517 1484 { 1518 1485 stack<VspKdTreeNode *> tstack; 1519 tstack.push( root);1486 tstack.push(mRoot); 1520 1487 1521 1488 int sumPvs = 0; … … 1539 1506 VspKdTreeInterior *in = (VspKdTreeInterior *)node; 1540 1507 // both nodes for directional splits 1541 tstack.push(in-> front);1542 tstack.push(in-> back);1508 tstack.push(in->GetFront()); 1509 tstack.push(in->GetBack()); 1543 1510 } 1544 1511 } … … 1552 1519 } 1553 1520 1554 AxisAlignedBox3 VspKdTree::GetBBox( const VspKdTreeNode *node)1555 { 1556 if (node-> parent == NULL)1557 return mB box;1521 AxisAlignedBox3 VspKdTree::GetBBox(VspKdTreeNode *node) const 1522 { 1523 if (node->mParent == NULL) 1524 return mBox; 1558 1525 1559 1526 if (!node->IsLeaf()) 1560 return ( (VspKdTreeInterior *)node)->mBbox;1561 1562 if (node-> parent->axis >= 3)1563 return node-> parent->mBbox;1527 return (dynamic_cast<VspKdTreeInterior *>(node))->mBox; 1528 1529 if (node->mParent->mAxis >= 3) 1530 return node->mParent->mBox; 1564 1531 1565 AxisAlignedBox3 box(node-> parent->mBbox);1566 if (node-> parent->front == node)1567 box.SetMin(node-> parent->axis, node->parent->position);1532 AxisAlignedBox3 box(node->mParent->mBox); 1533 if (node->mParent->mFront == node) 1534 box.SetMin(node->mParent->mAxis, node->mParent->mPosition); 1568 1535 else 1569 box.SetMax(node->parent->axis, node->parent->position); 1570 return mBbox; 1536 box.SetMax(node->mParent->mAxis, node->mParent->mPosition); 1537 1538 return box; 1571 1539 } 1572 1540 … … 1575 1543 return GetPvsSize(mRoot, mBox); 1576 1544 } 1545 1546 const VspKdStatistics &VspKdTree::GetStatistics() const 1547 { 1548 return mStat; 1549 } -
trunk/VUT/GtpVisibilityPreprocessor/src/VspKdTree.h
r418 r419 115 115 public: 116 116 117 friend class VspKdTree; 117 118 #define USE_FIXEDPOINT_T 1 118 119 … … 233 234 234 235 // link to the parent 235 VspKdTreeInterior * parent;236 VspKdTreeInterior *mParent; 236 237 237 238 enum {SPLIT_X=0, SPLIT_Y, SPLIT_Z, SPLIT_DIRX, SPLIT_DIRY, SPLIT_DIRZ}; 238 239 239 240 // splitting axis 240 char axis;241 char mAxis; 241 242 242 243 // depth 243 unsigned char depth;244 unsigned char mDepth; 244 245 245 246 // short depth; … … 251 252 252 253 virtual ~VspKdTreeNode() {}; 253 virtual int Type() const 254 255 256 bool IsLeaf() const { return axis == -1; }254 virtual int Type() const = 0; 255 256 257 bool IsLeaf() const { return mAxis == -1; } 257 258 258 259 virtual void Print(ostream &s) const = 0; 259 260 260 virtual int GetAccessTime() { 261 return 0x7FFFFFF; 261 virtual int GetAccessTime() 262 { 263 return 0x7FFFFFF; 262 264 } 263 265 … … 272 274 { 273 275 public: 274 276 friend class VspKdTree; 277 275 278 VspKdTreeInterior(VspKdTreeInterior *p); 276 279 277 280 virtual int GetAccessTime(); 278 281 279 virtual int Type() ;282 virtual int Type() const; 280 283 281 284 virtual ~VspKdTreeInterior(); 282 285 283 286 virtual void Print(ostream &s) const; 287 288 inline VspKdTreeNode *GetBack() const; 289 inline VspKdTreeNode *GetFront() const; 284 290 285 291 protected: … … 299 305 300 306 // the bbox of the node 301 AxisAlignedBox3 mB box;307 AxisAlignedBox3 mBox; 302 308 303 309 // data for caching … … 310 316 // KD-tree node - leaf node 311 317 // -------------------------------------------------------------- 312 class VspKdTreeLeaf 318 class VspKdTreeLeaf: public VspKdTreeNode 313 319 { 314 private:315 int mPvsSize;316 320 public: 321 friend class VspKdTree; 322 317 323 static int mailID; 318 324 int mailbox; … … 386 392 return sqr(GetPvsSize()/((float)rays.size() + Limits::Small)); 387 393 } 388 394 private: 395 int mPvsSize; 389 396 }; 390 397 391 398 // Inline functions 392 399 inline VspKdTreeNode::VspKdTreeNode(VspKdTreeInterior *p): 393 parent(p), axis(-1), depth(p ? p->depth + 1 : 0)400 mParent(p), mAxis(-1), mDepth(p ? p->mDepth + 1 : 0) 394 401 {} 395 402 … … 430 437 struct TraversalData 431 438 { 432 VspKdTreeNode * node;433 AxisAlignedBox3 bbox;434 int depth;435 float priority;439 VspKdTreeNode *mNode; 440 AxisAlignedBox3 mBox; 441 int mDepth; 442 float mPriority; 436 443 437 444 TraversalData() {} 438 445 439 446 TraversalData(VspKdTreeNode *n, const float p): 440 node(n), priority(p)447 mNode(n), mPriority(p) 441 448 {} 442 449 443 450 TraversalData(VspKdTreeNode *n, const AxisAlignedBox3 &b, const int d): 444 node(n), bbox(b), depth(d) {}451 mNode(n), mBox(b), mDepth(d) {} 445 452 446 453 // comparator for the … … 449 456 bool operator()(const TraversalData a, const TraversalData b) 450 457 { 451 return a. priority < b.priority;458 return a.mPriority < b.mPriority; 452 459 } 453 460 }; … … 459 466 { 460 467 // return a.node->queries.size() < b.node->queries.size(); 461 VspKdTreeLeaf *leafa = (VspKdTreeLeaf *) a. node;462 VspKdTreeLeaf *leafb = (VspKdTreeLeaf *) b. node;468 VspKdTreeLeaf *leafa = (VspKdTreeLeaf *) a.mNode; 469 VspKdTreeLeaf *leafb = (VspKdTreeLeaf *) b.mNode; 463 470 #if 0 464 471 return 465 leafa->rays.size()*a. bbox.GetVolume()472 leafa->rays.size()*a.mBox.GetVolume() 466 473 < 467 leafb->rays.size()*b. bbox.GetVolume();474 leafb->rays.size()*b.mBox.GetVolume(); 468 475 #endif 469 476 #if 1 470 477 return 471 leafa->GetPvsSize()*a. bbox.GetVolume()478 leafa->GetPvsSize()*a.mBox.GetVolume() 472 479 < 473 leafb->GetPvsSize()*b. bbox.GetVolume();480 leafb->GetPvsSize()*b.mBox.GetVolume(); 474 481 #endif 475 482 #if 0 … … 498 505 struct RayTraversalData 499 506 { 500 VspKdTreeNode::RayInfo rayData;501 VspKdTreeNode * node;507 VspKdTreeNode::RayInfo mRayData; 508 VspKdTreeNode *mNode; 502 509 503 510 RayTraversalData() {} 504 511 505 512 RayTraversalData(VspKdTreeNode *n, const VspKdTreeNode::RayInfo &data): 506 rayData(data), node(n) {}513 mRayData(data), mNode(n) {} 507 514 }; 508 515 … … 584 591 int &pvsFront); 585 592 586 AxisAlignedBox3 GetBBox( const VspKdTreeNode *node);593 AxisAlignedBox3 GetBBox(VspKdTreeNode *node) const; 587 594 588 595 VspKdTreeNode * SubdivideLeaf(VspKdTreeLeaf *leaf, … … 620 627 int CollapseSubtree(VspKdTreeNode *sroot, const int time); 621 628 622 const VspKdStatistics &GetStatistics() const { 623 return mStat; 624 } 625 626 629 const VspKdStatistics &GetStatistics() const; 630 631 int ReleaseMemory(const int time); 632 633 /** Parses the environment and stores the global BSP tree parameters 634 */ 635 static void ParseEnvironment(); 636 627 637 ///////////////////////////// 628 638 // Construction parameters 629 639 630 640 // max depth of the tree 631 int sTermMaxDepth;641 static int sTermMaxDepth; 632 642 633 643 // minimal ratio of the volume of the cell and the query volume 634 float sTermMinSize;644 static float sTermMinSize; 635 645 636 646 // minimal pvs per node to still get subdivided 637 int sTermMinPvs;647 static int sTermMinPvs; 638 648 639 649 // minimal ray number per node to still get subdivided 640 int sTermMinRays;650 static int sTermMinRays; 641 651 642 652 // maximal cost ration to subdivide a node 643 float sTermMaxCostRatio;653 static float sTermMaxCostRatio; 644 654 645 655 // maximal contribution per ray to subdivide the node 646 float sTermMaxRayContribution;656 static float sTermMaxRayContribution; 647 657 648 658 protected: -
trunk/VUT/GtpVisibilityPreprocessor/src/X3dExporter.cpp
r418 r419 585 585 bool X3dExporter::ExportVspKdTree(const VspKdTree &tree) 586 586 { 587 if (mExportRayDensity) 588 { 589 return ExportKdTreeRayDensity(tree); 590 } 587 /*if (mExportRayDensity) { 588 return ExportKdTreeRayDensity(tree); }*/ 591 589 592 590 stack<VspKdTreeNode *> tStack; … … 626 624 { 627 625 VspKdTreeInterior *interior = dynamic_cast<VspKdTreeInterior *>(node); 628 tStack.push(interior-> mFront);629 tStack.push(interior-> mBack);626 tStack.push(interior->GetFront()); 627 tStack.push(interior->GetBack()); 630 628 } 631 629 } -
trunk/VUT/GtpVisibilityPreprocessor/src/main.cpp
r409 r419 24 24 MeshKdTree::ParseEnvironment(); 25 25 BspTree::ParseEnvironment(); 26 VspKdTree::ParseEnvironment(); 26 27 27 28 char buff[128]; … … 66 67 if (BspTree::sConstructionMethod == BspTree::FROM_INPUT_VIEW_CELLS) 67 68 { 68 69 // view cells input file name 69 70 environment->GetStringValue("ViewCells.filename", buff); 70 71 string vcFilename(buff); 71 72 if (vcFilename != "") 73 p->LoadViewCells(vcFilename); 74 else 75 p->GenerateViewCells(); 76 77 Debug << "Viewcells loaded / generated. Number of view cells: " << (int)p->mViewCells.size() << endl; 72 p->LoadViewCells(vcFilename); 73 Debug << (int)p->mViewCells.size() << " view cells loaded" << endl; 78 74 } 79 75
Note: See TracChangeset
for help on using the changeset viewer.