Changeset 428 for trunk/VUT/GtpVisibilityPreprocessor
- Timestamp:
- 11/23/05 18:29:41 (19 years ago)
- Location:
- trunk/VUT/GtpVisibilityPreprocessor
- Files:
-
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/VUT/GtpVisibilityPreprocessor/scripts/default.env
r426 r428 62 62 63 63 Sampling { 64 totalSamples 100000064 totalSamples 600000 65 65 samplesPerPass 3 66 66 } … … 219 219 220 220 Construction { 221 samples 1000000221 samples 500000 222 222 } 223 223 224 224 Termination { 225 225 maxDepth 30 226 minPvs 50227 minRays 1 0226 minPvs 60 227 minRays 1 228 228 minSize 0.1 229 maxCostRatio 0.95229 maxCostRatio 999.0 230 230 maxRayContribution 0.2 231 231 } -
trunk/VUT/GtpVisibilityPreprocessor/src/Exporter.h
r425 r428 110 110 GetExporter(const string filename); 111 111 112 113 112 }; 114 113 -
trunk/VUT/GtpVisibilityPreprocessor/src/Ray.cpp
r426 r428 171 171 } 172 172 173 int 174 Ray::ClassifyPlane(const Plane3 &plane, 175 const float minT, 176 const float maxT, 177 Vector3 &entP, 178 Vector3 &extP) const 173 int Ray::ClassifyPlane(const Plane3 &plane, 174 const float minT, 175 const float maxT, 176 Vector3 &entP, 177 Vector3 &extP) const 179 178 { 180 179 entP = Extrap(minT); -
trunk/VUT/GtpVisibilityPreprocessor/src/Ray.h
r426 r428 45 45 const int face):mT(t), mObject(object), mFace(face) {} 46 46 47 Intersection() {}47 Intersection(): mT(0), mObject(NULL), mFace(0) {} 48 48 49 49 bool operator<( -
trunk/VUT/GtpVisibilityPreprocessor/src/SamplingPreprocessor.cpp
r426 r428 450 450 direction = point - pointToSample; 451 451 point = pointToSample; 452 Debug << "point: " << pointToSample << endl; 452 453 } 453 454 } … … 667 668 if (mVspKdTree) 668 669 { 669 Exporter *exporter = Exporter::GetExporter("vspkdtree.x3d"); 670 //exporter->SetWireframe(); 671 exporter->ExportVspKdTree(*mVspKdTree, mVspKdTree->GetStatistics().maxPvsSize); 672 673 Debug << "average PVS size: " << mVspKdTree->GetAvgPvsSize() << endl; 674 675 if (1) ExportSceneGeometry(exporter, objects); 676 677 bool exportRays = false; 678 679 if (exportRays) 680 { 681 int raysSize = 500; 682 float prob = raysSize / (float)mVspSampleRays.size(); 683 684 exporter->SetWireframe(); 685 686 VssRayContainer rays; 687 for (int i = 0; i < mVspSampleRays.size(); ++ i) 688 { 689 if (RandomValue(0,1) < prob) 690 rays.push_back(mVspSampleRays[i]); 691 } 692 693 exporter->ExportRays(rays, RgbColor(1, 0, 0)); 694 } 695 696 delete exporter; 670 if (1) 671 { 672 Exporter *exporter = Exporter::GetExporter("vspkdtree.x3d"); 673 //exporter->SetWireframe(); 674 exporter->ExportVspKdTree(*mVspKdTree, mVspKdTree->GetStatistics().maxPvsSize); 675 676 Debug << "average PVS size: " << mVspKdTree->GetAvgPvsSize() << endl; 677 678 if (0) ExportSceneGeometry(exporter, objects); 679 680 bool exportRays = true; 681 682 if (exportRays) 683 { 684 int raysSize = 2000; 685 float prob = raysSize / (float)mVspSampleRays.size(); 686 687 exporter->SetWireframe(); 688 689 VssRayContainer rays; 690 for (int i = 0; i < mVspSampleRays.size(); ++ i) 691 { 692 if (RandomValue(0,1) < prob) 693 rays.push_back(mVspSampleRays[i]); 694 } 695 696 exporter->ExportRays(rays, RgbColor(1, 0, 0)); 697 } 698 699 delete exporter; 700 } 701 702 if (1) 703 { 704 vector<VspKdTreeLeaf *> leafContainer; 705 706 mVspKdTree->CollectLeaves(leafContainer); 707 708 for (int i = 0; i < 10; ++ i) 709 { 710 char s[64]; 711 sprintf(s, "vsp_leaves%04d.x3d", i); 712 Exporter *exporter = Exporter::GetExporter(s); 713 714 // export geometry 715 VspKdTreeLeaf *leaf = leafContainer[Random((int)leafContainer.size())]; 716 AxisAlignedBox3 box = mVspKdTree->GetBBox(leaf); 717 718 Material m; 719 m.mDiffuseColor = RgbColor(0, 1, 1); 720 exporter->SetForcedMaterial(m); 721 exporter->SetWireframe(); 722 exporter->ExportBox(box); 723 724 //-- export stored rays 725 VssRayContainer vssRays; 726 leaf->GetRays(vssRays); 727 728 VssRayContainer rays; 729 730 VssRayContainer::const_iterator it, it_end = vssRays.end(); 731 732 for (it = vssRays.begin(); it != it_end; ++ it) 733 if (!(*it)->mOriginObject) 734 rays.push_back(*it); 735 736 exporter->ExportRays(rays, RgbColor(1, 0, 0)); 737 738 //-- export stored PVS 739 ObjectContainer pvsObj; 740 leaf->ExtractPvs(pvsObj); 741 742 ExportSceneGeometry(exporter, pvsObj); 743 744 delete exporter; 745 } 746 } 697 747 } 698 748 … … 757 807 758 808 759 void SamplingPreprocessor::ProcessVspViewCells( constRay &ray,809 void SamplingPreprocessor::ProcessVspViewCells(Ray &ray, 760 810 Intersectable *object, 761 811 const int faceIndex, … … 768 818 if ((int)mVspSampleRays.size() < mVspConstructionSamples) 769 819 { 820 ray.sourceObject = Ray::Intersection(0.0, object, faceIndex); 770 821 VssRay *sRay = new VssRay(ray); 771 772 mVspSampleRays.push_back(sRay); 773 774 // also add origin to sample 775 sRay->mOriginObject = object; 776 sRay->mOrigin = ray.GetLoc(); 822 mVspSampleRays.push_back(sRay); 777 823 } 778 824 else -
trunk/VUT/GtpVisibilityPreprocessor/src/SamplingPreprocessor.h
r426 r428 71 71 int &sampleContributions); 72 72 73 void ProcessVspViewCells( constRay &ray,73 void ProcessVspViewCells(Ray &ray, 74 74 Intersectable *object, 75 75 const int faceIndex, … … 100 100 101 101 protected: 102 103 102 104 int mPass; 103 105 int mSamplesPerPass; -
trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.cpp
r426 r428 38 38 int BspTree::sConstructionMethod = FROM_INPUT_VIEW_CELLS; 39 39 40 int BspTree::sFrontId = 0; 41 int BspTree::sBackId = 0; 42 int BspTree::sFrontAndBackId = 0; 40 43 41 44 /****************************************************************/ … … 1420 1423 } 1421 1424 1425 inline void BspTree::GenerateUniqueIdsForPvs() 1426 { 1427 Intersectable::NewMail(); sBackId = ViewCell::sMailId; 1428 Intersectable::NewMail(); sFrontId = ViewCell::sMailId; 1429 Intersectable::NewMail(); sFrontAndBackId = ViewCell::sMailId; 1430 } 1431 1422 1432 float BspTree::SplitPlaneCost(const Plane3 &candidatePlane, 1423 1433 const BoundedRayContainer &rays, … … 1445 1455 if (mSplitPlaneStrategy & PVS) 1446 1456 { 1447 // create three unique ids for pvs heuristics 1448 Intersectable::NewMail(); backId = ViewCell::sMailId; 1449 Intersectable::NewMail(); frontId = ViewCell::sMailId; 1450 Intersectable::NewMail(); frontAndBackId = ViewCell::sMailId; 1457 // create unique ids for pvs heuristics 1458 GenerateUniqueIdsForPvs(); 1451 1459 1452 1460 if (mPvsUseArea) // use front and back cell areas to approximate volume … … 1490 1498 if (mSplitPlaneStrategy & PVS) 1491 1499 { 1492 if (!ray->intersections.empty()) 1493 { 1494 // in case the ray intersects an objcrs 1495 // assure that we only count a object 1496 // once for the front and once for the back side of the plane 1497 IncPvs(*ray->intersections[0].mObject, frontPvs, backPvs, 1498 cf, frontId, backId, frontAndBackId); 1499 } 1500 1501 // the source object in the origin of the ray 1502 if (ray->sourceObject.mObject) 1503 { 1504 IncPvs(*ray->sourceObject.mObject, frontPvs, backPvs, 1505 cf, frontId, backId, frontAndBackId); 1506 } 1507 1500 // in case the ray intersects an object 1501 // assure that we only count the object 1502 // once for the front and once for the back side of the plane 1503 1504 // add the termination object 1505 AddObjToPvs(ray->intersections[0].mObject, cf, frontPvs, backPvs); 1506 1507 // add the source object 1508 AddObjToPvs(ray->sourceObject.mObject, cf, frontPvs, backPvs); 1509 1508 1510 if (!mPvsUseArea) // use front and back cell areas to approximate volume 1509 1511 { … … 1584 1586 } 1585 1587 1586 void BspTree::IncPvs(Intersectable &obj, 1587 int &frontPvs, 1588 int &backPvs, 1589 const int cf, 1590 const int frontId, 1591 const int backId, 1592 const int frontAndBackId) const 1593 { 1588 void BspTree::AddObjToPvs(Intersectable *obj, 1589 const int cf, 1590 int &frontPvs, 1591 int &backPvs) const 1592 { 1593 if (!obj) 1594 return; 1594 1595 // TODO: does this really belong to no pvs? 1595 1596 //if (cf == Ray::COINCIDENT) return; 1596 1597 1597 if (cf == Ray::FRONT) 1598 { 1599 if ((obj.mMailbox != frontId) && 1600 (obj.mMailbox != frontAndBackId)) 1598 // object belongs to both PVS 1599 const bool bothSides = (cf == Ray::FRONT_BACK) || 1600 (cf == Ray::BACK_FRONT) || 1601 (cf == Ray::COINCIDENT); 1602 1603 if ((cf == Ray::FRONT) || bothSides) 1604 { 1605 if ((obj->mMailbox != sFrontId) && 1606 (obj->mMailbox != sFrontAndBackId)) 1601 1607 { 1602 1608 ++ frontPvs; 1603 1609 1604 if (obj .mMailbox != backId)1605 obj .mMailbox = frontId;1610 if (obj->mMailbox == sBackId) 1611 obj->mMailbox = sFrontAndBackId; 1606 1612 else 1607 obj.mMailbox = frontAndBackId; 1608 } 1609 } 1610 else if (cf == Ray::BACK) 1611 { 1612 if ((obj.mMailbox != backId) && 1613 (obj.mMailbox != frontAndBackId)) 1613 obj->mMailbox = sFrontId; 1614 } 1615 } 1616 1617 if ((cf == Ray::BACK) || bothSides) 1618 { 1619 if ((obj->mMailbox != sBackId) && 1620 (obj->mMailbox != sFrontAndBackId)) 1614 1621 { 1615 1622 ++ backPvs; 1616 1623 1617 if (obj .mMailbox != frontId)1618 obj .mMailbox = backId;1624 if (obj->mMailbox == sFrontId) 1625 obj->mMailbox = sFrontAndBackId; 1619 1626 else 1620 obj.mMailbox = frontAndBackId; 1621 } 1622 } 1623 // object belongs to both PVS 1624 else if ((cf == Ray::FRONT_BACK) || (cf == Ray::BACK_FRONT) ||(cf == Ray::COINCIDENT)) 1625 { 1626 if (obj.mMailbox != frontAndBackId) 1627 { 1628 if (obj.mMailbox != frontId) 1629 ++ frontPvs; 1630 if (obj.mMailbox != backId) 1631 ++ backPvs; 1632 1633 obj.mMailbox = frontAndBackId; 1627 obj->mMailbox = sBackId; 1634 1628 } 1635 1629 } -
trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.h
r426 r428 328 328 void SetViewCell(BspViewCell *viewCell); 329 329 330 /** Adds ray s to the PVS.331 @param sampleContributions the number contributions of the samp els330 /** Adds ray sample contributions to the PVS. 331 @param sampleContributions the number contributions of the samples 332 332 @param contributingSampels the number of contributing rays 333 333 … … 755 755 void ExtractHalfSpaces(BspNode *n, vector<Plane3> &halfSpaces) const; 756 756 757 /** Computesthe pvs of the front and back leaf with a given classification.758 */ 759 void IncPvs(Intersectable &obj,760 int &frontPvs,761 int &backPvs,762 const int cf,763 const int frontId,764 const int backId,765 const int frontAndBackId) const;757 /** Adds the object to the pvs of the front and back leaf with a given classification. 758 759 @param obj the object to be added 760 @param cf the ray classification regarding the split plane 761 @param frontPvs returns the PVS of the front partition 762 @param backPvs returns the PVS of the back partition 763 764 */ 765 void AddObjToPvs(Intersectable *obj, const int cf, int &frontPvs, int &backPvs) const; 766 766 767 767 int ComputePvsSize(const BoundedRayContainer &rays) const; … … 859 859 860 860 private: 861 861 862 /** Evaluates split plane classification with respect to the plane's 862 863 contribution for a balanced tree. … … 876 877 static const float sBalancedRaysTable[5]; 877 878 879 /// Generates unique ids for PVS criterium 880 static void GenerateUniqueIdsForPvs(); 881 882 //-- unique ids for PVS criterium 883 static int sFrontId; 884 static int sBackId; 885 static int sFrontAndBackId; 878 886 }; 879 887 -
trunk/VUT/GtpVisibilityPreprocessor/src/VspKdTree.cpp
r426 r428 26 26 #include "RayInfo.h" 27 27 28 28 29 // Static variables 29 30 int VspKdTreeLeaf::mailID = 0; 31 32 #define USE_FIXEDPOINT_T 0 30 33 31 34 /// Adds object to the pvs of the front and back node … … 51 54 } 52 55 53 if (side >= 0) 56 if (side >= 0) 54 57 { 55 58 if (!object->Mailed(1) && !object->Mailed(2)) 56 59 { 57 60 ++ pvsFront; 61 58 62 if (object->Mailed()) 59 63 object->Mail(2); … … 245 249 return mRays; 246 250 } 251 252 void VspKdTreeLeaf::ExtractPvs(ObjectContainer &objects) const 253 { 254 RayInfoContainer::const_iterator it, it_end = mRays.end(); 255 256 for (it = mRays.begin(); it != it_end; ++ it) 257 { 258 if ((*it).mRay->mTerminationObject) 259 objects.push_back((*it).mRay->mTerminationObject); 260 if ((*it).mRay->mOriginObject) 261 objects.push_back((*it).mRay->mOriginObject); 262 } 263 } 264 265 void VspKdTreeLeaf::GetRays(VssRayContainer &rays) 266 { 267 RayInfoContainer::const_iterator it, it_end = mRays.end(); 268 269 for (it = mRays.begin(); it != mRays.end(); ++ it) 270 rays.push_back((*it).mRay); 271 } 272 247 273 /*********************************************************/ 248 274 /* class VspKdTree implementation */ … … 250 276 251 277 252 // Constructor 253 VspKdTree::VspKdTree(): 254 mOnlyDrivingAxis(true) 278 VspKdTree::VspKdTree(): mOnlyDrivingAxis(true) 255 279 { 256 280 environment->GetIntValue("VspKdTree.Termination.maxDepth", mTermMaxDepth); … … 546 570 { 547 571 int minDirDepth = 6; 548 int axis ;549 float costRatio ;572 int axis = 0; 573 float costRatio = 0; 550 574 551 575 if (splitType == ESplitRegular) … … 575 599 } 576 600 577 if ( 0 &&costRatio > mTermMaxCostRatio)601 if (costRatio > mTermMaxCostRatio) 578 602 { 579 603 Debug << "Too big cost ratio " << costRatio << endl; … … 581 605 } 582 606 583 #if 1 584 Debug << 585 "pvs=" << leaf->mPvsSize << 586 " rays=" << (int)leaf->mRays.size() << 587 " rc=" << leaf->GetAvgRayContribution() << 588 " axis=" << axis << endl; 589 #endif 607 if (0) 608 Debug << "pvs=" << leaf->mPvsSize 609 << " rays=" << (int)leaf->mRays.size() 610 << " rc=" << leaf->GetAvgRayContribution() 611 << " axis=" << axis << endl; 590 612 591 613 return axis; … … 638 660 float ratio = 0; 639 661 640 if ( 1)641 { 642 const float sum = pvsBack + pvsFront;662 if (0) 663 { 664 const float sum = float(pvsBack + pvsFront); 643 665 const float oldCost = (float)pvsSize * 2; 644 666 645 667 return sum / oldCost; 646 668 } 647 else { 669 else 670 { 648 671 AxisAlignedBox3 box = GetBBox(leaf); 649 672 … … 653 676 654 677 // float sum = raysBack*(position - minBox) + raysFront*(maxBox - position); 655 float sum = pvsBack * (position - minBox) + pvsFront * (maxBox - position);678 const float sum = pvsBack * (position - minBox) + pvsFront * (maxBox - position); 656 679 657 680 newCost = mCtDivCi + sum / sizeBox; … … 659 682 //Debug << axis << " " << pvsSize << " " << pvsBack << " " << pvsFront << endl; 660 683 // float oldCost = leaf->mRays.size(); 661 float oldCost = (float)pvsSize;684 const float oldCost = (float)pvsSize; 662 685 663 686 float ratio = newCost / oldCost; 664 665 687 } 666 688 … … 685 707 AxisAlignedBox3 sBox = GetBBox(leaf); 686 708 687 // int sAxis = box.Size().DrivingAxis(); 688 int sAxis = sBox.Size().DrivingAxis(); 709 const int sAxis = sBox.Size().DrivingAxis(); 689 710 690 711 for (axis = 0; axis < 3; ++ axis) … … 706 727 else 707 728 if (nCostRatio[axis] < nCostRatio[bestAxis]) 729 { 730 Debug << "pvs front " << nPvsBack[axis] 731 << " pvs back " << nPvsFront[axis] 732 << " overall pvs " << leaf->GetPvsSize() << endl; 708 733 bestAxis = axis; 709 } 710 } 711 734 } 735 } 736 } 737 738 //-- assign best axis 712 739 axis = bestAxis; 713 740 position = nPosition[bestAxis]; … … 924 951 if (TerminationCriteriaMet(leaf, box)) 925 952 { 926 if (1) 927 { 928 if (leaf->mDepth >= mTermMaxDepth) 929 { 930 Debug << "Warning: max depth reached depth=" << (int)leaf->mDepth<<" rays=" << (int)leaf->mRays.size() << endl; 931 Debug << "Bbox: " << GetBBox(leaf) << endl; 932 } 933 //Debug << "depth: " << (int)leaf->mDepth << " pvs: " << leaf->GetPvsSize() << " rays: " << leaf->mRays.size() << endl; 934 } 953 if (1 && leaf->mDepth >= mTermMaxDepth) 954 { 955 Debug << "Warning: max depth reached depth=" << (int)leaf->mDepth<<" rays=" << (int)leaf->mRays.size() << endl; 956 Debug << "Bbox: " << GetBBox(leaf) << endl; 957 } 958 //Debug << "depth: " << (int)leaf->mDepth << " pvs: " << leaf->GetPvsSize() << " rays: " << leaf->mRays.size() << endl; 959 935 960 return leaf; 936 961 } … … 1351 1376 #if DEBUG_COLLAPSE 1352 1377 cout << "Collapsing subtree" << endl; 1353 cout << "ac essTime=" << sroot->GetAccessTime() << endl;1378 cout << "accessTime=" << sroot->GetAccessTime() << endl; 1354 1379 cout << "depth=" << (int)sroot->depth << endl; 1355 1380 #endif … … 1717 1742 return pvsSize; 1718 1743 } 1744 1745 void VspKdTree::CollectLeaves(vector<VspKdTreeLeaf *> &leaves) const 1746 { 1747 stack<VspKdTreeNode *> nodeStack; 1748 nodeStack.push(mRoot); 1749 1750 while (!nodeStack.empty()) 1751 { 1752 VspKdTreeNode *node = nodeStack.top(); 1753 1754 nodeStack.pop(); 1755 1756 if (node->IsLeaf()) 1757 { 1758 VspKdTreeLeaf *leaf = dynamic_cast<VspKdTreeLeaf *>(node); 1759 leaves.push_back(leaf); 1760 } 1761 else 1762 { 1763 VspKdTreeInterior *interior = dynamic_cast<VspKdTreeInterior *>(node); 1764 1765 nodeStack.push(interior->mBack); 1766 nodeStack.push(interior->mFront); 1767 } 1768 } 1769 } -
trunk/VUT/GtpVisibilityPreprocessor/src/VspKdTree.h
r426 r428 32 32 33 33 #include "RayInfo.h" 34 34 #include "Containers.h" 35 35 36 36 /** … … 123 123 124 124 friend class VspKdTree; 125 #define USE_FIXEDPOINT_T 1126 125 127 126 enum {EInterior, ELeaf}; … … 266 265 void UpdatePvsSize(); 267 266 267 /** Returns stored rays. 268 */ 268 269 RayInfoContainer &GetRays(); 269 270 271 /** Returns rays into this ray container. 272 */ 273 void GetRays(VssRayContainer &rays); 270 274 /** Returns average contribution of a ray to the PVS 271 275 */ … … 275 279 inline float GetSqrRayContribution() const; 276 280 281 /** Extracts PVS from ray set. 282 */ 283 void ExtractPvs(ObjectContainer &objects) const; 284 277 285 //-- mailing options 278 279 286 void Mail(); 280 287 … … 286 293 287 294 static int mailID; 295 288 296 289 297 protected: … … 441 449 float GetRayMemUsage() const; 442 450 451 /** Collects leaves of this tree. 452 */ 453 void CollectLeaves(vector<VspKdTreeLeaf *> &leaves) const; 454 443 455 protected: 456 444 457 // incremental construction 445 458 virtual void UpdateRays(VssRayContainer &remove, VssRayContainer &add); -
trunk/VUT/GtpVisibilityPreprocessor/src/VssRay.h
r427 r428 72 72 mOrigin = ray.GetLoc(); 73 73 74 Debug << "origin: " << mOrigin << endl; 75 74 76 if (!ray.intersections.empty()) 75 77 { … … 79 81 else 80 82 { 81 mTermination = 1e6; 83 //mTermination = 1e6; 84 mTermination = mOrigin + ray.GetDir() * 1e6; 82 85 mTerminationObject = NULL; 83 86 }
Note: See TracChangeset
for help on using the changeset viewer.