Changeset 1758 for GTP/trunk/Lib
- Timestamp:
- 11/15/06 16:07:29 (18 years ago)
- Location:
- GTP/trunk/Lib/Vis/Preprocessing/src
- Files:
-
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/Lib/Vis/Preprocessing/src/BvHierarchy.cpp
r1757 r1758 46 46 BvhNode::BvhNode(): 47 47 mParent(NULL), 48 mMailbox(0),49 //mRenderCostDecr(0),50 //mMemoryIncr(0),51 //mPvsEntriesIncr(0),52 48 mTimeStamp(0) 53 49 { … … 58 54 mParent(NULL), 59 55 mBoundingBox(bbox), 60 mMailbox(0),61 //mMemoryIncr(0),62 //mRenderCostDecr(0),63 //mPvsEntriesIncr(0),64 56 mTimeStamp(0) 65 57 { … … 70 62 mBoundingBox(bbox), 71 63 mParent(parent), 72 mMailbox(0),73 //mMemoryIncr(0),74 //mRenderCostDecr(0),75 //mPvsEntriesIncr(0),76 64 mTimeStamp(0) 77 65 { … … 219 207 BvHierarchy::~BvHierarchy() 220 208 { 221 // delete bvh intersectables222 BvhIntersectableMap::iterator it, it_end = mBvhIntersectables.end();223 224 for (it = mBvhIntersectables.begin(); it != mBvhIntersectables.end(); ++ it)225 {226 DEL_PTR((*it).second);227 }228 229 209 // delete the local subdivision candidates 230 210 DEL_PTR(mSubdivisionCandidates); … … 1402 1382 const bool useMailboxing = false; 1403 1383 1404 CollectViewCells(obj, viewCells, useMailboxing, true, true);1384 CollectViewCells(obj, viewCells, useMailboxing, false, true); 1405 1385 1406 1386 // classify view cells and compute volume contri accordingly … … 1836 1816 ViewCellContainer viewCells; 1837 1817 ViewCell::NewMail(); 1838 int numRays = CollectViewCells(node->mObjects, viewCells, true, false);1818 int numRays = CollectViewCells(node->mObjects, viewCells, false, false); 1839 1819 1840 1820 //cout << "here6 " << numRays << endl; … … 1943 1923 1944 1924 1945 BvhIntersectable *BvHierarchy::GetOrCreateBvhIntersectable(BvhLeaf *node)1946 {1947 // search nodes1948 std::map<BvhLeaf *, BvhIntersectable *>::const_iterator1949 it = mBvhIntersectables.find(node);1950 1951 if (it != mBvhIntersectables.end())1952 {1953 return (*it).second;1954 }1955 1956 // not in map => create new entry1957 BvhIntersectable *bvhObj = new BvhIntersectable(node);1958 mBvhIntersectables[node] = bvhObj;1959 1960 return bvhObj;1961 }1962 1963 1964 1925 bool BvHierarchy::Export(OUT_STREAM &stream) 1965 1926 { … … 2424 2385 2425 2386 2426 void BvHierarchy::CollectObjects(const AxisAlignedBox3 &box, 2427 ObjectContainer &objects) 2387 void BvHierarchy::CollectObjects(const AxisAlignedBox3 &box, ObjectContainer &objects) 2428 2388 { 2429 2389 stack<BvhNode *> nodeStack; … … 2431 2391 nodeStack.push(mRoot); 2432 2392 2433 while (!nodeStack.empty()) { 2393 while (!nodeStack.empty()) 2394 { 2434 2395 BvhNode *node = nodeStack.top(); 2435 2396 2436 2397 nodeStack.pop(); 2437 2398 2438 if (node->IsLeaf()) { 2399 if (node->IsLeaf()) 2400 { 2439 2401 BvhLeaf *leaf = (BvhLeaf *)node; 2440 2402 if (Overlap(box, leaf->GetBoundingBox())) { 2441 Intersectable *object = GetOrCreateBvhIntersectable(leaf);2403 Intersectable *object = leaf; 2442 2404 if (!object->Mailed()) { 2443 2405 object->Mail(); … … 2446 2408 } 2447 2409 } 2448 else { 2410 else 2411 { 2449 2412 BvhInterior *interior = (BvhInterior *)node; 2450 2413 -
GTP/trunk/Lib/Vis/Preprocessing/src/BvHierarchy.h
r1744 r1758 32 32 class BvhLeaf; 33 33 class BvhNode; 34 class BvhIntersectable;35 34 class BvhTree; 36 35 class VspTree; … … 151 150 VspNode abstract class serving for interior and leaf node implementation 152 151 */ 153 class BvhNode 152 class BvhNode: public Intersectable 154 153 { 155 154 public: … … 204 203 int mTimeStamp; 205 204 206 //int mPvsEntriesIncr;207 //float mMemoryIncr;208 //float mRenderCostDecr;209 210 205 ///////////////////////////////////// 211 206 //-- mailing options … … 225 220 226 221 static int sMailId; 227 int mMailbox;222 //int mMailbox; 228 223 static int sReservedMailboxes; 224 225 226 227 ///////////////////////////////////////////// 228 //-- inherited functions from Intersectable 229 230 AxisAlignedBox3 GetBox() const { return mBoundingBox; } 231 232 int CastRay(Ray &ray) { return 0; } 233 234 bool IsConvex() const { return true; } 235 bool IsWatertight() const { return true; } 236 float IntersectionComplexity() { return 1; } 237 238 int NumberOfFaces() const { return 6; }; 239 240 int GetRandomSurfacePoint(GtpVisibilityPreprocessor::Vector3 &point, 241 GtpVisibilityPreprocessor::Vector3 &normal) 242 { 243 // TODO 244 return 0; 245 } 246 247 int GetRandomVisibleSurfacePoint(GtpVisibilityPreprocessor::Vector3 &point, 248 GtpVisibilityPreprocessor::Vector3 &normal, 249 const GtpVisibilityPreprocessor::Vector3 &viewpoint, 250 const int maxTries) 251 { 252 // TODO 253 return 0; 254 } 255 256 int Type() const 257 { 258 return Intersectable::BVH_INTERSECTABLE; 259 } 260 261 ostream &Describe(ostream &s) { return s; } 229 262 230 263 /////////////////////////////////// … … 341 374 BvhNode *mActiveNode; 342 375 }; 343 344 345 typedef map<BvhLeaf *, BvhIntersectable *> BvhIntersectableMap;346 376 347 377 … … 568 598 bool Export(OUT_STREAM &stream); 569 599 570 /** Returns or creates a new intersectable for use in a bv based pvs.571 The hierarchy is responsible for destruction of the intersectable.572 */573 BvhIntersectable *GetOrCreateBvhIntersectable(BvhLeaf *node);574 575 600 /** Collects rays associated with the objects. 576 601 */ … … 943 968 /// weight between render cost decrease and node render cost 944 969 float mRenderCostDecreaseWeight; 945 /// stores the kd node intersectables used for pvs 946 BvhIntersectableMap mBvhIntersectables; 970 947 971 /// if the objects should be sorted in one global step 948 972 bool mUseGlobalSorting; -
GTP/trunk/Lib/Vis/Preprocessing/src/Exporter.cpp
r1723 r1758 184 184 case Intersectable::BVH_INTERSECTABLE: 185 185 { 186 BvhNode *node = dynamic_cast<Bvh Intersectable *>(object)->GetItem();186 BvhNode *node = dynamic_cast<BvhNode *>(object); 187 187 if (node->IsLeaf()) 188 188 ExportGeometry(dynamic_cast<BvhLeaf *>(node)->mObjects, true); -
GTP/trunk/Lib/Vis/Preprocessing/src/GlRenderer.cpp
r1737 r1758 133 133 case Intersectable::BVH_INTERSECTABLE: { 134 134 135 136 BvhNode *node = (dynamic_cast<BvhIntersectable *>(object))->GetItem(); 135 BvhNode *node = dynamic_cast<BvhNode *>(object); 137 136 138 137 if (mRenderBoxes) -
GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.cpp
r1750 r1758 1451 1451 { 1452 1452 BvhLeaf *leaf = mBvHierarchy->GetLeaf(obj); 1453 BvhIntersectable *bvhObj = mBvHierarchy->GetOrCreateBvhIntersectable(leaf);1454 1453 1455 return vc->AddPvsSample( bvhObj, pdf, contribution);1454 return vc->AddPvsSample(leaf, pdf, contribution); 1456 1455 } 1457 1456 default: … … 1522 1521 const Vector3 &point) const 1523 1522 { 1524 1525 1526 return NULL;1527 1528 1523 1524 if (!obj) 1525 return NULL; 1526 1527 switch (mObjectSpaceSubdivisionType) 1529 1528 { 1530 1529 case HierarchyManager::KD_BASED_OBJ_SUBDIV: 1531 1532 KdLeaf *leaf = mOspTree->GetLeaf(point, NULL);1533 return mOspTree->GetOrCreateKdIntersectable(leaf);1534 1530 { 1531 KdLeaf *leaf = mOspTree->GetLeaf(point, NULL); 1532 return mOspTree->GetOrCreateKdIntersectable(leaf); 1533 } 1535 1534 case HierarchyManager::BV_BASED_OBJ_SUBDIV: 1536 1537 BvhLeaf *leaf = mBvHierarchy->GetLeaf(obj);1538 return mBvHierarchy->GetOrCreateBvhIntersectable(leaf);1539 1535 { 1536 BvhLeaf *leaf = mBvHierarchy->GetLeaf(obj); 1537 return leaf; 1538 } 1540 1539 default: 1541 1540 return obj; 1542 1541 } 1543 1542 } … … 1546 1545 const bool isTermination) const 1547 1546 { 1548 1547 Intersectable *obj = NULL; 1549 1548 Vector3 pt; 1550 1549 KdNode *node; 1551 1550 1552 1551 ray.GetSampleData(isTermination, pt, &obj, &node); 1553 1552 1554 1553 if (!obj) 1555 1554 return NULL; 1556 1555 1557 1556 switch (mObjectSpaceSubdivisionType) … … 1559 1558 case HierarchyManager::KD_BASED_OBJ_SUBDIV: 1560 1559 { 1561 1560 KdLeaf *leaf = mOspTree->GetLeaf(pt, node); 1562 1561 return mOspTree->GetOrCreateKdIntersectable(leaf); 1563 1562 } … … 1565 1564 { 1566 1565 BvhLeaf *leaf = mBvHierarchy->GetLeaf(obj); 1567 return mBvHierarchy->GetOrCreateBvhIntersectable(leaf);1566 return leaf; 1568 1567 } 1569 1568 default: 1570 1569 break; 1571 1570 } 1572 1571 return obj; … … 1839 1838 ObjectPvsEntry entry = pit.Next(); 1840 1839 1841 BvhIntersectable *intersect = dynamic_cast<BvhIntersectable *>(entry.mObject); 1842 1843 BvhLeaf *leaf = intersect->GetItem(); 1844 BvhNode *activeNode = leaf->GetActiveNode(); 1840 BvhNode *activeNode; 1841 BvhNode *intersect = dynamic_cast<BvhNode *>(entry.mObject); 1842 1843 // hack for choosing which node to account for 1844 if (intersect->IsLeaf()) 1845 activeNode = dynamic_cast<BvhLeaf *>(intersect)->GetActiveNode(); 1846 else 1847 activeNode = intersect; 1845 1848 1846 1849 if (!activeNode->Mailed()) -
GTP/trunk/Lib/Vis/Preprocessing/src/IntersectableWrapper.cpp
r1737 r1758 97 97 mBox = box; 98 98 } 99 100 AxisAlignedBox3 BvhIntersectable::GetBox() const101 {102 return mItem->GetBoundingBox();103 99 } 104 105 } -
GTP/trunk/Lib/Vis/Preprocessing/src/IntersectableWrapper.h
r1737 r1758 169 169 typedef map<KdNode *, KdIntersectable *> KdIntersectableMap; 170 170 171 class BvhIntersectable: public IntersectableWrapper<BvhLeaf *>172 {173 public:174 BvhIntersectable(BvhLeaf *item):175 IntersectableWrapper<BvhLeaf *>(item) {}176 177 int Type() const178 {179 return Intersectable::BVH_INTERSECTABLE;180 }181 182 AxisAlignedBox3 GetBox() const;183 184 };185 186 171 187 172 class TriangleIntersectable: public IntersectableWrapper<Triangle3> -
GTP/trunk/Lib/Vis/Preprocessing/src/OspTree.h
r1695 r1758 280 280 float GetPriority() const 281 281 { 282 HierarchyManager *hm = sOspTree->mHierarchyManager; 283 if (hm->ConsiderMemory()) 284 { 285 const float rc = hm->GetHierarchyStats().mTotalCost - mRenderCostDecrease; 286 const float mc = hm->GetHierarchyStats().mMemory + 287 (float)mPvsEntriesIncr * ObjectPvs::GetEntrySizeByte(); 288 289 return - (rc * mc); 290 } 291 else 292 { 293 return mPriority; 294 } 282 return mPriority; 295 283 } 296 284 -
GTP/trunk/Lib/Vis/Preprocessing/src/Pvs.cpp
r1740 r1758 79 79 We eliminate already accounted bvh nodes and objects using mailboxing. 80 80 */ 81 static float EvalBvhNodeContribution(Bvh Intersectable *bvhobj)81 static float EvalBvhNodeContribution(BvhNode *bvhObj) 82 82 { 83 BvhLeaf *leaf = bvhobj->GetItem(); 84 BvhNode *node = leaf->GetActiveNode(); 83 BvhNode *node; 84 85 // hack for choosing which node to account for 86 if (bvhObj->IsLeaf()) 87 node = dynamic_cast<BvhLeaf *>(bvhObj)->GetActiveNode(); 88 else 89 node = bvhObj; 85 90 86 91 // early exit 87 if (node == leaf) 88 { 92 if (node->IsLeaf()) 93 { 94 BvhLeaf *leaf = dynamic_cast<BvhLeaf *>(node); 89 95 // objects already accounted for 90 96 if (leaf->Mailed()) … … 112 118 if (node->IsLeaf()) 113 119 { 114 leaf = dynamic_cast<BvhLeaf *>(node);120 BvhLeaf *leaf = dynamic_cast<BvhLeaf *>(node); 115 121 116 122 // add #objects exclusivly in this node … … 156 162 case Intersectable::BVH_INTERSECTABLE: 157 163 { 158 Bvh Intersectable *bvhObj = dynamic_cast<BvhIntersectable *>(obj);164 BvhNode *bvhObj = dynamic_cast<BvhNode *>(obj); 159 165 pvs += EvalBvhNodeContribution(bvhObj); 160 166 break; -
GTP/trunk/Lib/Vis/Preprocessing/src/ViewCell.cpp
r1750 r1758 2371 2371 { 2372 2372 ObjectContainer objects; 2373 BvhNode *node = dynamic_cast<Bvh Intersectable *>(obj)->GetItem();2373 BvhNode *node = dynamic_cast<BvhNode *>(obj); 2374 2374 node->CollectObjects(objects); 2375 2375 -
GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp
r1757 r1758 6029 6029 Debug << "finished in " << timeDiff * 1e-3 << " secs" << endl; 6030 6030 6031 if ((castSamples >= samplesForStats + oldSamples) || (castSamples >= numSamples)) 6031 if ((castSamples >= samplesForStats + oldSamples) || 6032 (castSamples >= numSamples)) 6032 6033 { 6033 6034 oldSamples += samplesForStats;
Note: See TracChangeset
for help on using the changeset viewer.