Changeset 2390 for GTP/trunk/Lib/Vis
- Timestamp:
- 05/21/07 14:51:38 (18 years ago)
- Location:
- GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/include/OgreBiHierarchy.h
r2384 r2390 423 423 { 424 424 // cse 425 //showBoxes=true;425 showBoxes=true; 426 426 if (showBoxes) 427 427 { … … 430 430 queue->addRenderable(getWireBoundingBox()); 431 431 */ 432 /*432 433 433 if (mLevel == mOwner->getHiLiteLevel() || mOwner->getShowAllBoxes()) 434 434 queue->addRenderable(getWireBoundingBox()); 435 */435 436 436 } 437 437 -
GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/include/OgreBihRenderable.h
r2385 r2390 71 71 }; 72 72 73 inline void setActualSide(int d,BihPlaneEvent::Side s) 74 { 75 mActualSide[d] = s; 76 }; 77 78 inline void FinalizeSide(int d) 79 { 80 mFinalSide[d]=mActualSide[d]; 81 }; 82 83 inline BihPlaneEvent::Side GetFinalSide(int d) 84 { 85 return mFinalSide[d]; 86 }; 87 73 88 // funcions for attachment/detachment of renderables to/from the kd-tree 74 89 inline bool isAttached() … … 132 147 // Flag for the SAH determining the "cheaper" side of the split plane 133 148 BihPlaneEvent::Side mSide; 149 BihPlaneEvent::Side mFinalSide[3]; 150 BihPlaneEvent::Side mActualSide[3]; 134 151 // Flag for the SAH which marks if this renderable was already placed in the list after a split 135 152 bool mClassified; -
GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreBiHierarchy.cpp
r2383 r2390 364 364 Vector3 bmin = parent.getMinimum(); 365 365 Vector3 bmax = parent.getMaximum(); 366 Real mu= lookupPenalty(366 Real mu=/*lookupPenalty( 367 367 (mPosition[mDimension] - bmin[mDimension]) / 368 (bmax[mDimension] - bmin[mDimension])); 368 (bmax[mDimension] - bmin[mDimension]));*/ 1; 369 369 Real sav = surfaceArea(parent); 370 370 Real pl = surfaceArea(split.bleft) / sav; … … 1115 1115 BiHierarchy::Node * BiHierarchy::recBuild(BihPlaneEventList& events, int nObjects, AxisAlignedBox& aabb, BiHierarchy::Branch * parent) 1116 1116 { 1117 #define OLD_METHOD 1118 // 859 1117 #undef OLD_METHOD 1118 #undef DEBUG_BUILD_TREE 1119 1119 1120 // determine the depth we are on 1120 1121 int level = 0; … … 1131 1132 // initialize 1132 1133 const int dim = 3; 1133 int pStart, pOn, pEnd;1134 // int pStart, pOn, pEnd; 1134 1135 int nLeft[dim], nPlane[dim], nRight[dim]; 1135 1136 int nObjectCount[dim]; … … 1150 1151 BihPlaneEventList::iterator it_a = begin; // iterator for adjusting the bounding box 1151 1152 1153 // hold the minimum left and right bounding box 1152 1154 AxisAlignedBox minLefts[dim]; 1153 1155 AxisAlignedBox minRights[dim]; 1154 1156 1155 Vector3 MaxBoundingLeft=aabb.getMaximum(); 1156 Vector3 MinBoundingRight=aabb.getMinimum(); 1157 1158 Vector3 LastPosition=MinBoundingRight; 1159 1160 1161 1162 1163 1164 bool LeftMod[dim]; 1165 bool RightMod[dim]; 1166 1157 1158 1159 Vector3 LastPosition=aabb.getMinimum(); // needed to remember the last split plane position 1160 1161 // needed for the final sort before splitting 1167 1162 AxisAlignedBox minLeft; 1168 1163 AxisAlignedBox minRight; 1164 1165 // the border which seperates finished and unfinished events 1169 1166 BihPlaneEventList::iterator LeftBorder[dim]; 1170 1167 1171 1168 for (int i=0; i<dim; i++) 1172 1169 { 1173 minLefts[i].setNull(); 1174 minRights[i]=aabb; 1175 nRight[i]=nObjects; 1176 nLeft[i]=0; 1177 LeftBorder[i]=it; 1170 minLefts[i].setNull(); // left aabb starts with null 1171 minRights[i]=aabb; // right aabb contains all objects 1172 nRight[i]=nObjects; // all objects are on the right side 1173 nLeft[i]=0; 1174 LeftBorder[i]=it; // set the left border to the first event 1178 1175 } 1179 1176 // try all planes to find the best one for the given set of objects … … 1184 1181 { 1185 1182 1183 // slow implementation. for every event the left and right bounding boxes are calculated. 1186 1184 #ifdef OLD_METHOD 1187 1185 it = begin; … … 1276 1274 while (it != end) 1277 1275 { 1278 it->getRenderable()->setDecided(0,false); 1279 it->getRenderable()->setDecided(1,false); 1280 it->getRenderable()->setDecided(2,false); 1276 for (int i=0; i<dim; i++) 1277 { 1278 it->getRenderable()->setDecided(i,false); 1279 it->getRenderable()->setActualSide(i,BihPlaneEvent::PES_RIGHT); 1280 } 1281 1281 it->ClearGrowBB(); 1282 1282 it++; … … 1284 1284 it = end; 1285 1285 AxisAlignedBox tempBB[3]; 1286 for (int i=0; i<3; i++) tempBB[i].setNull(); 1286 for (int i=0; i<dim; i++) tempBB[i].setNull(); 1287 1287 1288 while (it != begin) 1288 1289 { 1289 1290 it--; 1290 if ((it->getRenderable()) 1291 if ((it->getRenderable())) //&& (it->equalsType(*it, BihPlaneEvent::PET_START))) 1291 1292 { 1292 1293 tempBB[it->getDimension()].merge(it->getRenderable()->getBoundingBox()); 1293 1294 it->GrowBB(tempBB[it->getDimension()]); 1294 1295 } 1296 1295 1297 1296 1298 … … 1334 1336 1335 1337 minRights[d]=it_a->GetGrowBB(); 1336 //mBuildLog->logMessage("Found Right side: d" + StringConverter::toString(d)+ " " + StringConverter::toString(pos[d]) ); 1338 #ifdef DEBUG_BUILD_TREE 1339 mBuildLog->logMessage("Found Right side: d" + StringConverter::toString(d)+ " " + StringConverter::toString(pos[d]) ); 1340 #endif 1337 1341 break; 1338 1342 } … … 1346 1350 if (it_a->getRenderable()) 1347 1351 { 1348 /* 1349 if (it_a->getDimension()==0 && d==0) 1350 { 1351 mBuildLog->logMessage("--------Enter Loop: d" ); 1352 if (it_a->GetType() == BihPlaneEvent::PET_START) 1353 mBuildLog->logMessage("--------START" ); 1354 if (it_a->GetType() == BihPlaneEvent::PET_END) 1355 mBuildLog->logMessage("--------END" ); 1356 if (it_a->GetType() == BihPlaneEvent::PET_ON) 1357 mBuildLog->logMessage("--------ON" ); 1358 1359 } 1360 */ 1361 if ((it_a->getDimension()==d) /*&& (it_a->GetType() == BihPlaneEvent::PET_START) */&& (!it_a->getRenderable()->isDecided(d))) 1352 1353 if ((it_a->getDimension()==d) && (!it_a->getRenderable()->isDecided(d))) 1362 1354 { 1363 1355 it_a->classify(*it, split.side,true); … … 1366 1358 // right side 1367 1359 1368 1369 minRights[d].merge(it_a->GetGrowBB()); 1370 //if (d==0) 1371 //mBuildLog->logMessage("Move to Right side: d" + StringConverter::toString(d)+ " " + StringConverter::toString(pos[d]) ); 1372 1360 minRights[d].merge(it_a->getRenderable()->getBoundingBox()); 1361 #ifdef DEBUG_BUILD_TREE 1362 mBuildLog->logMessage("Move to Right side: d" + StringConverter::toString(d)+ " " + StringConverter::toString(pos[d]) ); 1363 #endif 1373 1364 1374 1365 } else … … 1376 1367 minLefts[d].merge(it_a->getRenderable()->getBoundingBox()); 1377 1368 it_a->getRenderable()->setDecided(d,true); 1369 it_a->getRenderable()->setActualSide(d,BihPlaneEvent::PES_LEFT); 1370 1371 1378 1372 Vector3 pos=minLefts[d].getMaximum(); 1379 1373 nLeft[d]++; nRight[d]--; 1380 //if (d==0) 1381 //mBuildLog->logMessage("Move to Left side: d" + StringConverter::toString(d)+ " " + StringConverter::toString(pos[d]) );1382 1374 #ifdef DEBUG_BUILD_TREE 1375 mBuildLog->logMessage("Move to Left side: d" + StringConverter::toString(d)+ " " + StringConverter::toString(pos[d]) ); 1376 #endif 1383 1377 if ((it_a->getPosition()[d]>LeftBorder[d]->getPosition()[d]) && (!foundLeft[d])) 1384 1378 { 1385 1379 LeftBorder[d]=it_a; 1386 //if (d==0) 1387 //mBuildLog->logMessage("Adjust left to d" + StringConverter::toString(d)+ " " + StringConverter::toString(it_a->getPosition()[d]) ); 1380 #ifdef DEBUG_BUILD_TREE 1381 mBuildLog->logMessage("Adjust left to d" + StringConverter::toString(d)+ " " + StringConverter::toString(it_a->getPosition()[d]) ); 1382 #endif 1388 1383 } else 1389 1384 { 1390 //if (d==0) 1391 //mBuildLog->logMessage("Found left d" + StringConverter::toString(d)+ " " + StringConverter::toString(it_a->getPosition()[d]) ); 1385 #ifdef DEBUG_BUILD_TREE 1386 mBuildLog->logMessage("Found left d" + StringConverter::toString(d)+ " " + StringConverter::toString(it_a->getPosition()[d]) ); 1387 #endif 1392 1388 foundLeft[d]=true; 1393 1389 } … … 1400 1396 else 1401 1397 { 1402 //if (d==0) 1403 //mBuildLog->logMessage("------No renderable " + StringConverter::toString(d)+ " " + StringConverter::toString(it_a->getPosition()[d]) ); 1398 #ifdef DEBUG_BUILD_TREE 1399 mBuildLog->logMessage("------No renderable " + StringConverter::toString(d)+ " " + StringConverter::toString(it_a->getPosition()[d]) ); 1400 #endif 1404 1401 } 1405 1402 it_a++; 1406 1403 } 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1404 1417 1405 #endif 1418 1406 if (it!=end) it++; … … 1421 1409 if (split.cost < best.cost) 1422 1410 { 1411 if ((nLeft[d]!=0) && (nRight[d]!=0)) 1423 1412 best = split; 1424 1413 } 1425 #endif 1426 /* 1427 if (d==0) 1414 #ifdef DEBUG_BUILD_TREE 1428 1415 mBuildLog->logMessage("SAH " + StringConverter::toString(best.cost)+ " " + StringConverter::toString(split.cost) + 1429 1416 "dim: " + StringConverter::toString(d)+ "Elements: " + StringConverter::toString(nLeft[d]) + … … 1431 1418 " " + StringConverter::toString(it->getPosition()[d]) +" " + StringConverter::toString(minRights[d].getMinimum()[d]) 1432 1419 +" " + StringConverter::toString(LeftBorder[d]->getPosition()[d])); 1433 */ 1420 1421 mBuildLog->logMessage(" BOXES " + StringConverter::toString(minLefts[d].getMaximum()[d]-minLefts[d].getMinimum()[d]) + 1422 " " + StringConverter::toString(minRights[d].getMaximum()[d]-minRights[d].getMinimum()[d])); 1423 #endif // DEBUG_BUILD_TREE 1424 1425 #endif // OLD_METHOD 1426 1427 1428 1434 1429 #ifndef OLD_METHOD 1435 1430 if (it!=end) … … 1441 1436 if (split.cost < best.cost) 1442 1437 { 1443 best = split; 1438 if ((nLeft[d]!=0) && (nRight[d]!=0)) 1439 { 1440 best = split; 1441 1442 it_a=begin; 1443 while (it_a!=end) 1444 { 1445 if (it_a->getRenderable()) it_a->getRenderable()->FinalizeSide(d); 1446 it_a++; 1447 } 1448 #ifdef DEBUG_BUILD_TREE 1449 mBuildLog->logMessage("SAH " + StringConverter::toString(best.cost)+ " " + StringConverter::toString(split.cost) + 1450 "dim: " + StringConverter::toString(d)+ "Elements: " + StringConverter::toString(nLeft[d]) + 1451 " " + StringConverter::toString(nRight[d])+ "Planes: "+ StringConverter::toString(minLefts[d].getMaximum()[d]) + 1452 " " + StringConverter::toString(it->getPosition()[d]) +" " + StringConverter::toString(minRights[d].getMinimum()[d]) 1453 +" " + StringConverter::toString(LeftBorder[d]->getPosition()[d])+ " " + StringConverter::toString(it->getPosition()[it->getDimension()])); 1454 1455 mBuildLog->logMessage("BOXES Left " + StringConverter::toString(minLefts[d].getMaximum()[d]-minLefts[d].getMinimum()[d]) + 1456 " " + StringConverter::toString(minRights[d].getMaximum()[d]-minRights[d].getMinimum()[d])); 1457 #endif 1458 } 1459 1444 1460 } 1461 1462 1463 1464 1465 } else 1466 { 1467 #ifdef DEBUG_BUILD_TREE 1468 mBuildLog->logMessage("Cancel " + StringConverter::toString(it->getPosition()[it->getDimension()])); 1469 #endif 1445 1470 } 1471 1446 1472 } else 1447 1473 { … … 1449 1475 if (split.cost < best.cost) 1450 1476 { 1451 best = split; 1477 if ((nLeft[d]!=0) && (nRight[d]!=0)) 1478 { 1479 best = split; 1480 it_a=begin; 1481 while (it_a!=end) 1482 { 1483 if (it_a->getRenderable()) it_a->getRenderable()->FinalizeSide(d); 1484 it_a++; 1485 } 1486 } 1452 1487 } 1488 #ifdef DEBUG_BUILD_TREE 1489 mBuildLog->logMessage("SAH " + StringConverter::toString(best.cost)+ " " + StringConverter::toString(split.cost) + 1490 "dim: " + StringConverter::toString(d)+ "Elements: " + StringConverter::toString(nLeft[d]) + 1491 " " + StringConverter::toString(nRight[d])+ "Planes: "+ StringConverter::toString(minLefts[d].getMaximum()[d]) + 1492 " " + StringConverter::toString(it->getPosition()[d]) +" " + StringConverter::toString(minRights[d].getMinimum()[d]) 1493 +" " + StringConverter::toString(LeftBorder[d]->getPosition()[d])+ " " + StringConverter::toString(it->getPosition()[it->getDimension()])); 1494 #endif 1453 1495 } 1454 1496 … … 1515 1557 /************************************************/ 1516 1558 // check terminating condition 1517 if (best.cost > BihPlaneEvent::KI*nObjects || level >= mMaxDepth || nObjects<4 )1518 //if (best.cost > 2*nObjects || level >= mMaxDepth )//|| nObjects<4)1559 1560 if (best.cost > BihPlaneEvent::KI*nObjects || level >= mMaxDepth || nObjects<2 ) 1519 1561 { 1520 1562 // Terminating condition reached, create leaf and add renderables to list 1563 #ifdef DEBUG_BUILD_TREE 1521 1564 mBuildLog->logMessage("Terminate " + StringConverter::toString(best.cost)+ " o:" + StringConverter::toString(nObjects) + 1522 1565 " ki: " + StringConverter::toString(BihPlaneEvent::KI*nObjects)+ " dim: " + StringConverter::toString(best.event.getDimension())); 1566 #endif 1523 1567 BiHierarchy::Leaf * leaf = new BiHierarchy::Leaf(this, level, aabb, parent); 1524 1568 if (parent->GetSide()==1) leaf->SetToLeft(); else leaf->SetToRight(); … … 1579 1623 { 1580 1624 // right-only nodes go in right list 1581 if (it->getRenderable() ->getSide() == BihPlaneEvent::PES_RIGHT)1582 { 1583 if ( !it->getRenderable()->isClassified())1625 if (it->getRenderable()) 1626 { 1627 if (it->getRenderable()->GetFinalSide(best.event.getDimension()) == BihPlaneEvent::PES_RIGHT) 1584 1628 { 1585 it->getRenderable()->setClassified(true); 1586 nRightS++; 1629 if (!it->getRenderable()->isClassified()) 1630 { 1631 it->getRenderable()->setClassified(true); 1632 nRightS++; 1633 } 1634 minRight.merge(it->getRenderable()->getBoundingBox()); 1635 eventsRight.push_back(*it); 1587 1636 } 1588 minRight.merge(it->getRenderable()->getBoundingBox()); 1589 //mBuildLog->logMessage("merge right " + StringConverter::toString(minRight.volume())); 1590 eventsRight.push_back(*it); 1591 } 1592 // left-only nodes go in left list 1593 else if (it->getRenderable()->getSide() == BihPlaneEvent::PES_LEFT) 1594 { 1595 if (!it->getRenderable()->isClassified()) 1637 // left-only nodes go in left list 1638 else if (it->getRenderable()->GetFinalSide(best.event.getDimension()) == BihPlaneEvent::PES_LEFT) 1596 1639 { 1597 it->getRenderable()->setClassified(true); 1598 nLeftS++; 1640 if (!it->getRenderable()->isClassified()) 1641 { 1642 it->getRenderable()->setClassified(true); 1643 nLeftS++; 1644 } 1645 minLeft.merge(it->getRenderable()->getBoundingBox()); 1646 eventsLeft.push_back(*it); 1599 1647 } 1600 minLeft.merge(it->getRenderable()->getBoundingBox()); 1601 //mBuildLog->logMessage("merge left " + StringConverter::toString(minLeft.volume())); 1602 eventsLeft.push_back(*it); 1603 } 1604 // remaining nodes go in both lists, bust must be clipped to prevent 1605 // events from lying outside the new nodes aabb 1606 else 1607 { 1608 if (!it->getRenderable()->isClassified()) 1609 { 1610 it->getRenderable()->setClassified(true); 1611 nBothS++; 1612 } 1613 1614 // calculate the intersecting box for the right side 1615 1616 1617 minRight.merge(best.bright.intersection(it->getRenderable()->getBoundingBox())); 1618 1619 1620 //mBuildLog->logMessage("merge Right Overlap " + StringConverter::toString(minRight.volume())); 1621 eventsRight.push_back(it->clip(best.bright, best.event.getDimension())); 1622 1623 minLeft.merge(best.bleft.intersection(it->getRenderable()->getBoundingBox())); 1624 1625 //mBuildLog->logMessage("merge Left Overlap " + StringConverter::toString(minLeft.volume())); 1626 eventsLeft.push_back(it->clip(best.bleft, best.event.getDimension())); 1627 } 1648 } 1649 1628 1650 it++; 1629 1651 } 1630 1631 mBuildLog->logMessage("Split R:" + StringConverter::toString(nRightS)+ " L:" + StringConverter::toString(nLeftS) + 1632 " O: " + StringConverter::toString(nObjects)); 1633 1652 #ifdef DEBUG_BUILD_TREE 1653 mBuildLog->logMessage("Split " + StringConverter::toString(best.cost)+ " o:" + StringConverter::toString(nObjects) + 1654 " ki: " + StringConverter::toString(BihPlaneEvent::KI*nObjects)+ " dim: " + StringConverter::toString(best.event.getDimension())); 1655 #endif 1656 1634 1657 1635 1658 1636 1659 1637 // calculate minimum of the left bounding box 1638 /* 1639 AxisAlignedBox minimum; 1640 minimum.setNull(); 1641 it=eventsLeft.begin(); 1642 while (it!=eventsLeft.end()) 1643 { 1644 minimum.merge(it->getRenderable()->getBoundingBox()); 1645 it++; 1646 } 1647 */ 1660 1648 1661 1649 1662 … … 1654 1667 1655 1668 // now create the child nodes and continue recursion 1656 1657 //if (best.bleft.volume()>minLeft.volume())1658 {1659 mBuildLog->logMessage("Volume Smaller Left " + StringConverter::toString(minLeft.volume()) + " " + StringConverter::toString(best.bleft.volume(),3,3));1660 if (best.bleft.volume()!=minLeft.volume())1661 {1662 mBuildLog->logMessage("Error Volume Left " + StringConverter::toString(best.bleft.getMinimum())+ " " + StringConverter::toString(best.bleft.getMaximum()));1663 mBuildLog->logMessage("Error Volume Left " + StringConverter::toString(minLeft.getMinimum()) + " " + StringConverter::toString(minLeft.getMaximum()) );1664 }1665 1666 }1667 1668 //if (best.bright.volume()>minRight.volume())1669 {1670 mBuildLog->logMessage("Volume Smaller Right " + StringConverter::toString(minRight.volume()) + " " + StringConverter::toString(best.bright.volume(),3,3));1671 if (best.bright.volume()!=minRight.volume())1672 {1673 mBuildLog->logMessage("Error Volume Right " + StringConverter::toString(best.bright.getMinimum())+ " " + StringConverter::toString(best.bright.getMaximum()));1674 mBuildLog->logMessage("Error Volume Right " + StringConverter::toString(minRight.getMinimum()) + " " + StringConverter::toString(minRight.getMaximum()) );1675 }1676 }1677 1678 1669 1679 1670 if (eventsLeft.size() > 0) 1680 1671 { 1681 1672 1682 branch->mLeft = recBuild(eventsLeft, nLeftS + nBothS, /*best.bleft*/minLeft, branch);1673 branch->mLeft = recBuild(eventsLeft, nLeftS + nBothS, minLeft, branch); 1683 1674 branch->mLeft->SetToLeft(); 1684 //mBuildLog->logMessage("SetToLeft"); 1685 //branch->mLeft = recBuild(eventsLeft, nLeftS + nBothS, best.bleft, branch); 1675 1686 1676 } 1687 1677 if (eventsRight.size() > 0) … … 1690 1680 branch->mRight = recBuild(eventsRight, nBothS + nRightS, /*best.bright*/ minRight, branch); 1691 1681 branch->mRight->SetToRight(); 1692 //mBuildLog->logMessage("SetToRight"); 1693 1694 1695 //branch->mRight = recBuild(eventsRight, nBothS + nRightS, best.bright, branch); 1682 1696 1683 } 1697 1684 … … 2277 2264 queue->addRenderable(getWireBoundingBox()); 2278 2265 */ 2279 /*2266 2280 2267 if (mLevel == mOwner->getHiLiteLevel() || mOwner->getShowAllBoxes()) 2281 2268 queue->addRenderable(getWireBoundingBox()); 2282 */2269 2283 2270 } 2284 2271
Note: See TracChangeset
for help on using the changeset viewer.