Changeset 418 for trunk/VUT/GtpVisibilityPreprocessor
- Timestamp:
- 11/16/05 18:33:18 (19 years ago)
- Location:
- trunk/VUT/GtpVisibilityPreprocessor
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/VUT/GtpVisibilityPreprocessor/scripts/default.env
r416 r418 68 68 ViewCells { 69 69 #hierarchy kdTree 70 hierarchy vspTree70 #hierarchy vspTree 71 71 hierarchy bspTree 72 72 # hierarchy sceneDependent … … 133 133 #splitPlaneStrategy 130 134 134 135 splitPlaneStrategy 1 2135 splitPlaneStrategy 1024 136 136 137 137 maxPolyCandidates 50 -
trunk/VUT/GtpVisibilityPreprocessor/src/Exporter.h
r396 r418 12 12 class KdTree; 13 13 class BspTree; 14 class VspKdTree; 14 15 class SceneGraphNode; 15 16 class Ray; … … 46 47 virtual bool 47 48 ExportKdTree(const KdTree &tree) = 0; 49 50 virtual bool 51 ExportVspKdTree(const VspKdTree &tree) = 0; 48 52 49 53 virtual bool -
trunk/VUT/GtpVisibilityPreprocessor/src/RenderSimulator.cpp
r416 r418 54 54 // probability that view point lies in a view cell 55 55 float pInVcTotal = 0; 56 56 57 // total probability that a view cell border is crossed 57 float pCrossVcTotal = 0;58 const float pCrossVcTotal = mBspTree->GetBoundingBox().SurfaceArea(); 58 59 59 60 // collect all view cells … … 78 79 // compute render time of PVS times probability that view point is in view cell 79 80 float vcCost = pInVc * RenderPvs(*(*it), mObjRenderCost); 80 Debug << "p: " << pInVc << " rendercost: " << RenderPvs(*(*it), mObjRenderCost) << endl;81 //Debug << "p: " << pInVc << " rendercost: " << RenderPvs(*(*it), mObjRenderCost) << endl; 81 82 renderTime += vcCost; 82 83 … … 87 88 88 89 // probability that a view cell border is crossed 89 float pCrossVc = area ;90 float pCrossVc = area * mMoveSpeed; 90 91 91 92 // crossing the border of a view cell is also depending on the move speed 92 loadPvsOverhead += pCrossVc * mVcOverhead * mMoveSpeed;93 loadPvsOverhead += pCrossVc * mVcOverhead; 93 94 94 95 pInVcTotal += pInVc; 95 pCrossVcTotal += pCrossVc;96 96 } 97 97 … … 99 99 renderTime /= pInVcTotal; 100 100 loadPvsOverhead /= pCrossVcTotal; 101 102 Debug << "bsp RT: " << renderTime << endl;103 Debug << "bsp pvsOverhead: " << loadPvsOverhead << endl;104 101 105 102 mStat.avgRtWithoutOverhead = renderTime; … … 144 141 145 142 // total probability that a view cell border is crossed 146 float pCrossVcTotal = 0;143 const float pCrossVcTotal = mKdTree->GetBox().SurfaceArea(); 147 144 148 145 vector<KdLeaf *> leaves; … … 165 162 pInVc = box.SurfaceArea(); 166 163 167 // probability that a view cell border is crossed168 const float pCrossVc = box.SurfaceArea();169 170 164 float vcCost = pInVc * RenderPvs(*it, mObjRenderCost); 171 165 renderTime += vcCost; … … 176 170 mStat.minCost = vcCost; 177 171 178 loadPvsOverhead += pCrossVc * mVcOverhead * mMoveSpeed; 172 // probability that a view cell border is crossed 173 const float pCrossVc = box.SurfaceArea() * mMoveSpeed; 174 175 loadPvsOverhead += pCrossVc * mVcOverhead; 179 176 180 177 pInVcTotal += pInVc; 181 pCrossVcTotal += pCrossVc;182 178 } 183 184 Debug << "RT: " << renderTime << endl;185 Debug << "pvsOverhead: " << loadPvsOverhead << endl;186 187 179 188 180 renderTime /= pInVcTotal; -
trunk/VUT/GtpVisibilityPreprocessor/src/SamplingPreprocessor.cpp
r416 r418 167 167 168 168 int 169 SamplingPreprocessor::CastRay(Intersectable *object, 170 Ray &ray 171 ) 169 SamplingPreprocessor::CastRay(Intersectable *object, Ray &ray) 172 170 { 173 171 int sampleContributions = 0; … … 520 518 } 521 519 else 522 {523 Debug << "contr: " << passSampleContributions << " pvs: " << pvsSize << " objects: " << objects.size() << endl;524 520 pvsSize += passSampleContributions; 525 }521 526 522 float avgRayContrib = (passContributingSamples > 0) ? 527 523 passSampleContributions/(float)passContributingSamples : 0; … … 641 637 exporter->ExportKdTree(*mKdTree); 642 638 643 if (mBspTree && (ViewCell::sHierarchy == ViewCell:: BSP))644 exporter->Export BspTree(*mBspTree);639 if (mBspTree && (ViewCell::sHierarchy == ViewCell::VSP)) 640 exporter->ExportVspKdTree(*mVspKdTree); 645 641 646 642 delete exporter; -
trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.cpp
r414 r418 1487 1487 1488 1488 // give penalty to unbalanced split 1489 if (0) 1489 1490 if (((pFront * 0.2 + Limits::Small) > pBack) || (pFront < (pBack * 0.2 + Limits::Small))) 1490 1491 val += 0.5; 1491 1492 } 1492 1493 1493 if (0) 1494 #ifdef _DEBUG 1494 1495 Debug << "totalpvs: " << pvs << " ptotal: " << pOverall 1495 1496 << " frontpvs: " << frontPvs << " pFront: " << pFront 1496 << " backpvs: " << backPvs << " pBack: " << pBack 1497 << " val " << val << " new size: " << ComputePvsSize(rays)<< endl << endl; 1498 1497 << " backpvs: " << backPvs << " pBack: " << pBack << endl << endl; 1498 #endif 1499 1499 return val; 1500 1500 } -
trunk/VUT/GtpVisibilityPreprocessor/src/VspKdTree.cpp
r414 r418 25 25 #include "Ray.h" 26 26 27 28 #define DEBUG_DIR_SPLIT 029 30 31 32 27 // Static variables 33 int 34 VspKdTreeLeaf::mailID = 0; 28 int VspKdTreeLeaf::mailID = 0; 29 int VspKdTree::sTermMaxDepth = 10; 30 float VspKdTree::sTermMinSize = 0.1; 31 int VspKdTree::sTermMinPvs = 10; 32 int VspKdTree::sTermMinRays = 20; 33 float VspKdTree::sTermMaxCostRatio = 0.1; 34 float VspKdTree::sTermMaxRayContribution = 0.1; 35 36 35 37 36 38 inline void AddObject2Pvs(Intersectable *object, … … 68 70 } 69 71 72 /**************************************************************/ 73 * VspKdTreeInterior implementation * 74 /**************************************************************/ 75 76 VspKdTreeInterior::VspKdTreeInterior(VspKdTreeInterior *p): 77 VspKdTreeNode(p), mBack(NULL), mFront(NULL), mAccesses(0), mLastAccessTime(-1) 78 { 79 } 80 81 int VspKdTreeInterior::GetAccessTime() 82 { 83 return lastAccessTime; 84 } 85 86 void VspKdTreeInterior::SetupChildLinks(VspKdTreeNode *b, VspKdTreeNode *f) 87 { 88 mBack = b; 89 mFront = f; 90 b->mParent = f->mParent = this; 91 } 92 93 void VspKdTreeInterior::ReplaceChildLink(VspKdTreeNode *oldChild, VspKdTreeNode *newChild) 94 { 95 if (mBack == oldChild) 96 mBack = newChild; 97 else 98 mFront = newChild; 99 } 100 101 int VspKdTreeInterior::Type() const 102 { 103 return VspKdInterior; 104 } 105 106 VspKdTreeInterior::~VspKdTreeInterior() 107 { 108 DEL_PTR(mBack); 109 DEL_PTR(mFront); 110 } 111 112 void VspKdTreeInterior::Print(ostream &s) const 113 { 114 if (axis == 0) 115 s << "x "; 116 else 117 if (axis == 1) 118 s << "y "; 119 else 120 s << "z "; 121 s << position << " "; 122 123 mBack->Print(s); 124 mFront->Print(s); 125 } 126 127 int VspKdTreeInterior::ComputeRayIntersection(const RayInfo &rayData, float &t) 128 { 129 return rayData.ComputeRayIntersection(axis, position, t); 130 } 131 70 132 71 133 // Constructor 72 134 VspKdTree::VspKdTree() 73 135 { 74 environment->GetIntValue("VspKdTree.maxDepth", termMaxDepth);75 environment->GetIntValue("VspKdTree.minPvs", termMinPvs);76 environment->GetIntValue("VspKdTree.minRays", termMinRays);77 environment->GetFloatValue("VspKdTree.maxRayContribution", termMaxRayContribution);78 environment->GetFloatValue("VspKdTree.maxCostRatio", termMaxCostRatio);79 80 environment->GetFloatValue("VspKdTree.minSize", termMinSize);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); 81 143 termMinSize = sqr(termMinSize); 82 83 environment->GetFloatValue("VspKdTree.refDirBoxMaxSize", refDirBoxMaxSize); 84 refDirBoxMaxSize = sqr(refDirBoxMaxSize); 85 144 86 145 environment->GetFloatValue("VspKdTree.epsilon", epsilon); 87 146 environment->GetFloatValue("VspKdTree.ct_div_ci", ct_div_ci); … … 92 151 93 152 float refDirAngle; 94 environment->GetFloatValue("VspKdTree.refDirAngle", refDirAngle);95 96 153 environment->GetIntValue("VspKdTree.accessTimeThreshold", accessTimeThreshold); 97 154 //= 1000; … … 119 176 environment->GetBoolValue("VspKdTree.randomize", randomize); 120 177 121 root = NULL;178 mRoot = NULL; 122 179 123 180 splitCandidates = new vector<SortableEntry>; … … 127 184 VspKdTree::~VspKdTree() 128 185 { 129 if (root) 130 delete root; 131 } 132 133 134 135 136 void 137 VspKdStatistics::Print(ostream &app) const 186 if (mRoot) 187 delete mRoot; 188 } 189 190 void VspKdStatistics::Print(ostream &app) const 138 191 { 139 192 app << "===== VspKdTree statistics ===============\n"; … … 1493 1546 return sumPvs / (float)leaves; 1494 1547 } 1548 1549 VspKdTreeNode *VspKdTree::GetRoot() const 1550 { 1551 return mRoot; 1552 } 1553 1554 AxisAlignedBox3 VspKdTree::GetBBox(const VspKdTreeNode *node) 1555 { 1556 if (node->parent == NULL) 1557 return mBbox; 1558 1559 if (!node->IsLeaf()) 1560 return ((VspKdTreeInterior *)node)->mBbox; 1561 1562 if (node->parent->axis >= 3) 1563 return node->parent->mBbox; 1564 1565 AxisAlignedBox3 box(node->parent->mBbox); 1566 if (node->parent->front == node) 1567 box.SetMin(node->parent->axis, node->parent->position); 1568 else 1569 box.SetMax(node->parent->axis, node->parent->position); 1570 return mBbox; 1571 } 1572 1573 int VspKdTree::GetRootPvsSize() const 1574 { 1575 return GetPvsSize(mRoot, mBox); 1576 } -
trunk/VUT/GtpVisibilityPreprocessor/src/VspKdTree.h
r414 r418 272 272 { 273 273 public: 274 // plane in local modelling coordinates 275 float position; 276 277 // pointers to children 278 VspKdTreeNode *back, *front; 279 280 // the bbox of the node 281 AxisAlignedBox3 bbox; 282 283 // the bbox of the node 284 AxisAlignedBox3 dirBBox; 285 286 // data for caching 287 long accesses; 288 long lastAccessTime; 289 290 VspKdTreeInterior(VspKdTreeInterior *p):VspKdTreeNode(p), 291 back(NULL), 292 front(NULL), 293 accesses(0), 294 lastAccessTime(-1) 295 { } 296 297 virtual int GetAccessTime() { 298 return lastAccessTime; 299 } 300 301 void SetupChildLinks(VspKdTreeNode *b, VspKdTreeNode *f) { 302 back = b; 303 front = f; 304 b->parent = f->parent = this; 305 } 306 307 void ReplaceChildLink(VspKdTreeNode *oldChild, VspKdTreeNode *newChild) { 308 if (back == oldChild) 309 back = newChild; 310 else 311 front = newChild; 312 } 313 314 virtual int Type() const { return EInterior; } 315 316 virtual ~VspKdTreeInterior() 317 { 318 DEL_PTR(back); 319 DEL_PTR(front); 320 } 321 322 virtual void Print(ostream &s) const 323 { 324 if (axis == 0) 325 s << "x "; 326 else 327 if (axis == 1) 328 s << "y "; 329 else 330 s << "z "; 331 s << position << " "; 332 back->Print(s); 333 front->Print(s); 334 } 335 336 int ComputeRayIntersection(const RayInfo &rayData, float &t) 337 { 338 return rayData.ComputeRayIntersection(axis, position, t); 339 } 340 274 275 VspKdTreeInterior(VspKdTreeInterior *p); 276 277 virtual int GetAccessTime(); 278 279 virtual int Type(); 280 281 virtual ~VspKdTreeInterior(); 282 283 virtual void Print(ostream &s) const; 284 285 protected: 286 287 void SetupChildLinks(VspKdTreeNode *b, VspKdTreeNode *f); 288 289 void ReplaceChildLink(VspKdTreeNode *oldChild, VspKdTreeNode *newChild); 290 291 int ComputeRayIntersection(const RayInfo &rayData, float &t); 292 293 // plane in local modelling coordinates 294 float mPosition; 295 296 // pointers to children 297 VspKdTreeNode *mBack; 298 VspKdTreeNode *mFront; 299 300 // the bbox of the node 301 AxisAlignedBox3 mBbox; 302 303 // data for caching 304 long mAccesses; 305 long mLastAccessTime; 341 306 }; 342 307 … … 543 508 544 509 public: 545 546 ///////////////////////////// 547 // The core pointer 548 VspKdTreeNode *root; 549 550 ///////////////////////////// 551 // Basic properties 552 553 // total number of nodes of the tree 554 int nodes; 555 556 // axis aligned bounding box of the scene 557 AxisAlignedBox3 bbox; 558 559 // axis aligned bounding box of directions 560 AxisAlignedBox3 dirBBox; 561 562 const VspKdStatistics &GetStatistics() const { 563 return mStat; 564 } 565 ///////////////////////////// 566 // Construction parameters 567 568 // epsilon used for the construction 569 float epsilon; 570 571 // ratio between traversal and intersection costs 572 float ct_div_ci; 573 574 // max depth of the tree 575 int termMaxDepth; 576 // minimal ratio of the volume of the cell and the query volume 577 float termMinSize; 578 579 // minimal pvs per node to still get subdivided 580 int termMinPvs; 581 582 // minimal ray number per node to still get subdivided 583 int termMinRays; 584 585 // maximal cost ration to subdivide a node 586 float termMaxCostRatio; 587 588 // maximal contribution per ray to subdivide the node 589 float termMaxRayContribution; 590 591 // randomized construction 592 bool randomize; 593 594 // type of the splitting to use for the tree construction 595 enum {ESplitRegular, ESplitHeuristic }; 596 int splitType; 597 598 // maximal size of the box on which the refdir splitting can be performed 599 // (relative to the scene bbox 600 float refDirBoxMaxSize; 601 602 // maximum alovable memory in MB 603 float maxTotalMemory; 604 605 // maximum alovable memory for static kd tree in MB 606 float maxStaticMemory; 607 608 // this is used during the construction depending 609 // on the type of the tree and queries... 610 float maxMemory; 611 612 // minimal acess time for collapse 613 int accessTimeThreshold; 614 615 // minimal depth at which to perform collapse 616 int minCollapseDepth; 617 618 // reusable array of split candidates 619 vector<SortableEntry> *splitCandidates; 620 621 ///////////////////////////// 622 VspKdStatistics mStat; 623 510 624 511 VspKdTree(); 625 512 virtual ~VspKdTree(); … … 697 584 int &pvsFront); 698 585 699 AxisAlignedBox3 GetBBox(const VspKdTreeNode *node) 700 { 701 if (node->parent == NULL) 702 return bbox; 703 704 if (!node->IsLeaf()) 705 return ((VspKdTreeInterior *)node)->bbox; 706 707 if (node->parent->axis >= 3) 708 return node->parent->bbox; 709 710 AxisAlignedBox3 box(node->parent->bbox); 711 if (node->parent->front == node) 712 box.SetMin(node->parent->axis, node->parent->position); 713 else 714 box.SetMax(node->parent->axis, node->parent->position); 715 return box; 716 } 717 718 AxisAlignedBox3 GetDirBBox(const VspKdTreeNode *node) 719 { 720 if (node->parent == NULL) 721 return dirBBox; 722 if (!node->IsLeaf()) 723 return ((VspKdTreeInterior *)node)->dirBBox; 724 if (node->parent->axis < 3) 725 return node->parent->dirBBox; 726 727 AxisAlignedBox3 dBBox(node->parent->dirBBox); 728 729 if (node->parent->front == node) 730 dBBox.SetMin(node->parent->axis - 3, node->parent->position); 731 else 732 dBBox.SetMax(node->parent->axis - 3, node->parent->position); 733 return dBBox; 734 } 735 736 int ReleaseMemory(const int time); 737 738 int CollapseSubtree(VspKdTreeNode *node, const int time); 739 740 void CountAccess(VspKdTreeInterior *node, const long time) 741 { 742 ++ node->accesses; 743 node->lastAccessTime = time; 744 } 586 AxisAlignedBox3 GetBBox(const VspKdTreeNode *node); 745 587 746 588 VspKdTreeNode * SubdivideLeaf(VspKdTreeLeaf *leaf, … … 759 601 760 602 761 int GetRootPvsSize() const 762 { 763 return GetPvsSize(root, bbox); 764 } 603 int GetRootPvsSize() const; 765 604 766 605 int GetPvsSize(VspKdTreeNode *node, const AxisAlignedBox3 &box) const; … … 774 613 775 614 float GetAvgPvsSize(); 615 616 /** Get the root of the tree. 617 */ 618 VspKdTreeNode *GetRoot() const; 619 620 int CollapseSubtree(VspKdTreeNode *sroot, const int time); 621 622 const VspKdStatistics &GetStatistics() const { 623 return mStat; 624 } 625 626 627 ///////////////////////////// 628 // Construction parameters 629 630 // max depth of the tree 631 int sTermMaxDepth; 632 633 // minimal ratio of the volume of the cell and the query volume 634 float sTermMinSize; 635 636 // minimal pvs per node to still get subdivided 637 int sTermMinPvs; 638 639 // minimal ray number per node to still get subdivided 640 int sTermMinRays; 641 642 // maximal cost ration to subdivide a node 643 float sTermMaxCostRatio; 644 645 // maximal contribution per ray to subdivide the node 646 float sTermMaxRayContribution; 647 648 protected: 649 ///////////////////////////// 650 // The core pointer 651 VspKdTreeNode *mRoot; 652 653 ///////////////////////////// 654 // Basic properties 655 656 // total number of nodes of the tree 657 int nodes; 658 659 // axis aligned bounding box of the scene 660 AxisAlignedBox3 mBox; 661 662 // epsilon used for the construction 663 float epsilon; 664 665 // ratio between traversal and intersection costs 666 float ct_div_ci; 667 668 // type of the splitting to use for the tree construction 669 enum {ESplitRegular, ESplitHeuristic }; 670 int splitType; 671 672 // maximum alovable memory in MB 673 float maxTotalMemory; 674 675 // maximum alovable memory for static kd tree in MB 676 float maxStaticMemory; 677 678 // this is used during the construction depending 679 // on the type of the tree and queries... 680 float maxMemory; 681 682 // minimal acess time for collapse 683 int accessTimeThreshold; 684 685 // minimal depth at which to perform collapse 686 int minCollapseDepth; 687 688 // reusable array of split candidates 689 vector<SortableEntry> *splitCandidates; 690 691 ///////////////////////////// 692 VspKdStatistics mStat; 776 693 }; 777 694 -
trunk/VUT/GtpVisibilityPreprocessor/src/X3dExporter.cpp
r396 r418 9 9 #include "Polygon3.h" 10 10 #include "VssRay.h" 11 #include "VspKdTree.h" 11 12 12 13 X3dExporter::X3dExporter(const string filename):Exporter(filename) … … 580 581 581 582 return true; 583 } 584 585 bool X3dExporter::ExportVspKdTree(const VspKdTree &tree) 586 { 587 if (mExportRayDensity) 588 { 589 return ExportKdTreeRayDensity(tree); 590 } 591 592 stack<VspKdTreeNode *> tStack; 593 594 tStack.push(tree.GetRoot()); 595 596 Mesh *mesh = new Mesh; 597 598 while (!tStack.empty()) 599 { 600 VspKdTreeNode *node = tStack.top(); 601 602 tStack.pop(); 603 AxisAlignedBox3 box = tree.GetBBox(node); 604 605 // add 6 vertices of the box 606 607 int index = (int)mesh->mVertices.size(); 608 609 for (int i=0; i < 8; ++ i) 610 { 611 Vector3 v; 612 box.GetVertex(i, v); 613 mesh->mVertices.push_back(v); 614 } 615 616 mesh->AddFace(new Face(index + 0, index + 1, index + 3, index + 2) ); 617 mesh->AddFace(new Face(index + 0, index + 2, index + 6, index + 4) ); 618 mesh->AddFace(new Face(index + 4, index + 6, index + 7, index + 5) ); 619 620 621 mesh->AddFace(new Face(index + 3, index + 1, index + 5, index + 7) ); 622 mesh->AddFace(new Face(index + 0, index + 4, index + 5, index + 1) ); 623 mesh->AddFace(new Face(index + 2, index + 3, index + 7, index + 6) ); 624 625 if (!node->IsLeaf()) 626 { 627 VspKdTreeInterior *interior = dynamic_cast<VspKdTreeInterior *>(node); 628 tStack.push(interior->mFront); 629 tStack.push(interior->mBack); 630 } 631 } 632 633 ExportMesh(mesh); 634 DEL_PTR(mesh); 635 636 return true; 582 637 } 583 638 -
trunk/VUT/GtpVisibilityPreprocessor/src/X3dExporter.h
r396 r418 39 39 ExportKdTree(const KdTree &tree); 40 40 41 bool 42 ExportVspKdTree(const VspKdTree &tree); 43 41 44 bool ExportBspTree(const BspTree &tree); 42 45
Note: See TracChangeset
for help on using the changeset viewer.