Changeset 2383 for GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE
- Timestamp:
- 05/16/07 14:26:36 (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreBiHierarchy.cpp
r2361 r2383 1115 1115 BiHierarchy::Node * BiHierarchy::recBuild(BihPlaneEventList& events, int nObjects, AxisAlignedBox& aabb, BiHierarchy::Branch * parent) 1116 1116 { 1117 #define OLD_METHOD 1118 // 859 1117 1119 // determine the depth we are on 1118 1120 int level = 0; … … 1151 1153 AxisAlignedBox minRights[dim]; 1152 1154 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 1153 1167 AxisAlignedBox minLeft; 1154 1168 AxisAlignedBox minRight; 1169 BihPlaneEventList::iterator LeftBorder[dim]; 1155 1170 1156 1171 for (int i=0; i<dim; i++) 1172 { 1173 minLefts[i].setNull(); 1174 minRights[i]=aabb; 1175 nRight[i]=nObjects; 1176 nLeft[i]=0; 1177 LeftBorder[i]=it; 1178 } 1157 1179 // try all planes to find the best one for the given set of objects 1158 1180 1159 1181 // Use SAH method 1182 //mBuildLog->logMessage("------------NewRun:" + StringConverter::toString(nObjects)); 1160 1183 if (mAlgorithm==BIHAL_SAH) 1161 1184 { 1185 1186 #ifdef OLD_METHOD 1187 it = begin; 1188 1162 1189 while (it != end) 1163 1190 { 1164 1191 BihPlaneEventList::iterator p = it; 1192 1193 1165 1194 pStart = pOn = pEnd = 0; 1166 1195 1167 1196 while (it != end && p->equalsType(*it, BihPlaneEvent::PET_END)) 1168 1197 { 1169 it++; pEnd++; 1198 it++; pEnd++; 1170 1199 } 1171 1200 while (it != end && p->equalsType(*it, BihPlaneEvent::PET_ON)) … … 1177 1206 it++; pStart++; 1178 1207 } 1179 1208 1180 1209 1181 1210 int d = p->getDimension(); 1211 1182 1212 nPlane[d] = pOn; 1183 //nRight[d] -= pOn; nRight[d] -= pEnd; 1213 nRight[d] -= pOn; nRight[d] -= pEnd; 1214 1184 1215 1185 1216 // find the corrected offsets for the left and right bounding box … … 1187 1218 LeftOffset[d]=0; 1188 1219 RightOffset[d]=0; 1189 minLefts[d].setNull(); 1190 minRights[d].setNull(); 1220 1221 1222 1223 1191 1224 nRight[d]=0; 1192 1225 nLeft[d]=0; 1226 minLefts[d].setNull(); 1227 minRights[d].setNull(); 1228 1229 if (minLefts[d].isNull() && minRights[d].isNull()) 1230 { 1231 while (it_a != end) 1232 { 1233 if ((it_a->getDimension()==d) && (it_a->GetType() == BihPlaneEvent::PET_START)) 1234 { 1235 it_a->getRenderable()->setSide(BihPlaneEvent::PES_BOTH); 1236 it_a->getRenderable()->setClassified(false); 1237 it_a->classify(*p, split.side,true); 1238 if (it_a->getRenderable()->getSide() == BihPlaneEvent::PES_RIGHT) 1239 { 1240 if (!it_a->getRenderable()->isClassified()) 1241 { 1242 it_a->getRenderable()->setClassified(true); 1243 nRight[d]++; 1244 } 1245 minRights[d].merge(it_a->getRenderable()->getBoundingBox()); 1246 1247 } 1248 // left-only nodes go in left list 1249 else if (it_a->getRenderable()->getSide() == BihPlaneEvent::PES_LEFT) 1250 { 1251 1252 if (!it_a->getRenderable()->isClassified()) 1253 { 1254 it_a->getRenderable()->setClassified(true); 1255 nLeft[d]++; 1256 } 1257 minLefts[d].merge(it_a->getRenderable()->getBoundingBox()); 1258 1259 } 1260 } 1261 1262 1263 it_a++; 1264 } 1265 } 1266 1267 1268 1269 1270 #endif 1271 1272 /////////////////////////////////////////////////////////////////////////// 1273 1274 #ifndef OLD_METHOD 1275 it = begin; 1276 while (it != end) 1277 { 1278 it->getRenderable()->setDecided(0,false); 1279 it->getRenderable()->setDecided(1,false); 1280 it->getRenderable()->setDecided(2,false); 1281 it->ClearGrowBB(); 1282 it++; 1283 } 1284 it = end; 1285 AxisAlignedBox tempBB[3]; 1286 for (int i=0; i<3; i++) tempBB[i].setNull(); 1287 while (it != begin) 1288 { 1289 it--; 1290 if ((it->getRenderable()) && (it->equalsType(*it, BihPlaneEvent::PET_START))) 1291 { 1292 tempBB[it->getDimension()].merge(it->getRenderable()->getBoundingBox()); 1293 it->GrowBB(tempBB[it->getDimension()]); 1294 } 1193 1295 1194 1195 while (it_a != end) 1196 { 1197 if (it_a->getDimension()==d) 1198 { 1199 it_a->getRenderable()->setSide(BihPlaneEvent::PES_BOTH); 1200 it_a->getRenderable()->setClassified(false); 1201 it_a->classify(*p, split.side,true); 1202 if (it_a->getRenderable()->getSide() == BihPlaneEvent::PES_RIGHT) 1296 1297 } 1298 1299 it = begin; 1300 1301 1302 while (it != end) 1303 { 1304 1305 1306 BihPlaneEventList::iterator p = it; 1307 1308 int d = p->getDimension(); 1309 1310 1311 // find the corrected offsets for the left and right bounding box 1312 1313 LeftOffset[d]=0; 1314 RightOffset[d]=0; 1315 1316 1317 1318 1319 1320 1321 1322 1323 bool foundLeft[3]; 1324 foundLeft[0]=false; foundLeft[1]=false; foundLeft[2]=false; 1325 1326 1327 // set the right border 1328 it_a=it; 1329 while (it_a!=end) 1203 1330 { 1204 if ( !it_a->getRenderable()->isClassified())1331 if ((it_a->getDimension()==d) && (it_a->GetType() == BihPlaneEvent::PET_START)) 1205 1332 { 1206 it_a->getRenderable()->setClassified(true); 1207 nRight[d]++; 1333 1334 1335 minRights[d]=it_a->GetGrowBB(); 1336 //mBuildLog->logMessage("Found Right side: d" + StringConverter::toString(d)+ " " + StringConverter::toString(pos[d]) ); 1337 break; 1208 1338 } 1209 minRights[d].merge(it_a->getRenderable()->getBoundingBox()); 1210 1339 it_a++; 1211 1340 } 1212 // left-only nodes go in left list 1213 else if (it_a->getRenderable()->getSide() == BihPlaneEvent::PES_LEFT) 1341 1342 1343 it_a=LeftBorder[d]; 1344 while (it_a!=it) 1214 1345 { 1215 if ( !it_a->getRenderable()->isClassified())1346 if (it_a->getRenderable()) 1216 1347 { 1217 it_a->getRenderable()->setClassified(true); 1218 nLeft[d]++; 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))) 1362 { 1363 it_a->classify(*it, split.side,true); 1364 if (it_a->getRenderable()->getSide() == BihPlaneEvent::PES_RIGHT) 1365 { 1366 // right side 1367 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 1373 1374 } else 1375 { 1376 minLefts[d].merge(it_a->getRenderable()->getBoundingBox()); 1377 it_a->getRenderable()->setDecided(d,true); 1378 Vector3 pos=minLefts[d].getMaximum(); 1379 nLeft[d]++; nRight[d]--; 1380 //if (d==0) 1381 //mBuildLog->logMessage("Move to Left side: d" + StringConverter::toString(d)+ " " + StringConverter::toString(pos[d]) ); 1382 1383 if ((it_a->getPosition()[d]>LeftBorder[d]->getPosition()[d]) && (!foundLeft[d])) 1384 { 1385 LeftBorder[d]=it_a; 1386 //if (d==0) 1387 //mBuildLog->logMessage("Adjust left to d" + StringConverter::toString(d)+ " " + StringConverter::toString(it_a->getPosition()[d]) ); 1388 } else 1389 { 1390 //if (d==0) 1391 //mBuildLog->logMessage("Found left d" + StringConverter::toString(d)+ " " + StringConverter::toString(it_a->getPosition()[d]) ); 1392 foundLeft[d]=true; 1393 } 1394 1395 1396 } 1397 } 1398 1219 1399 } 1220 minLefts[d].merge(it_a->getRenderable()->getBoundingBox()); 1221 1400 else 1401 { 1402 //if (d==0) 1403 //mBuildLog->logMessage("------No renderable " + StringConverter::toString(d)+ " " + StringConverter::toString(it_a->getPosition()[d]) ); 1404 } 1405 it_a++; 1222 1406 } 1223 } 1224 1225 1226 it_a++; 1227 } 1228 1229 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 #endif 1418 if (it!=end) it++; 1419 #ifdef OLD_METHOD 1230 1420 p->SAH(aabb, nLeft[d], nPlane[d], nRight[d], split,minLefts[d],minRights[d]); 1231 mBuildLog->logMessage("SAH " + StringConverter::toString(best.cost)+ " " + StringConverter::toString(split.cost) +1232 "dim: " + StringConverter::toString(d));1233 1421 if (split.cost < best.cost) 1234 1422 { 1235 1423 best = split; 1236 1424 } 1425 #endif 1426 /* 1427 if (d==0) 1428 mBuildLog->logMessage("SAH " + StringConverter::toString(best.cost)+ " " + StringConverter::toString(split.cost) + 1429 "dim: " + StringConverter::toString(d)+ "Elements: " + StringConverter::toString(nLeft[d]) + 1430 " " + StringConverter::toString(nRight[d])+ "Planes: "+ StringConverter::toString(minLefts[d].getMaximum()[d]) + 1431 " " + StringConverter::toString(it->getPosition()[d]) +" " + StringConverter::toString(minRights[d].getMinimum()[d]) 1432 +" " + StringConverter::toString(LeftBorder[d]->getPosition()[d])); 1433 */ 1434 #ifndef OLD_METHOD 1435 if (it!=end) 1436 { 1437 if ((it->getPosition()[it->getDimension()]!=LastPosition[it->getDimension()])) 1438 { 1439 LastPosition[it->getDimension()]=it->getPosition()[it->getDimension()]; 1440 p->SAH(aabb, nLeft[d], nPlane[d], nRight[d], split,minLefts[d],minRights[d]); 1441 if (split.cost < best.cost) 1442 { 1443 best = split; 1444 } 1445 } 1446 } else 1447 { 1448 p->SAH(aabb, nLeft[d], nPlane[d], nRight[d], split,minLefts[d],minRights[d]); 1449 if (split.cost < best.cost) 1450 { 1451 best = split; 1452 } 1453 } 1454 1455 #endif 1456 1457 1458 1459 1460 1237 1461 1238 1239 //nLeft[d] += pStart; nLeft[d] += pOn; 1462 #ifdef OLD_METHOD 1463 nLeft[d] += pStart; nLeft[d] += pOn; 1464 #endif 1240 1465 1241 1466 nPlane[d] = 0; … … 1290 1515 /************************************************/ 1291 1516 // check terminating condition 1292 if (/*best.cost > BihPlaneEvent::KI*nObjects ||*/ level >= mMaxDepth || nObjects<20 ) 1517 if (best.cost > BihPlaneEvent::KI*nObjects || level >= mMaxDepth || nObjects<4 ) 1518 //if (best.cost > 2*nObjects || level >= mMaxDepth )//|| nObjects<4 ) 1293 1519 { 1294 1520 // Terminating condition reached, create leaf and add renderables to list … … 1406 1632 " O: " + StringConverter::toString(nObjects)); 1407 1633 1634 1635 1408 1636 1409 1637 // calculate minimum of the left bounding box … … 1419 1647 */ 1420 1648 1421 1649 1422 1650 1423 1651 // create a new branch node and continue recursion … … 1426 1654 1427 1655 // now create the child nodes and continue recursion 1428 /*1429 if (best.bleft.volume()>minLeft.volume())1656 1657 //if (best.bleft.volume()>minLeft.volume()) 1430 1658 { 1431 1659 mBuildLog->logMessage("Volume Smaller Left " + StringConverter::toString(minLeft.volume()) + " " + StringConverter::toString(best.bleft.volume(),3,3)); 1432 } 1433 1434 if (best.bright.volume()>minRight.volume()) 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()) 1435 1669 { 1436 1670 mBuildLog->logMessage("Volume Smaller Right " + StringConverter::toString(minRight.volume()) + " " + StringConverter::toString(best.bright.volume(),3,3)); 1437 } 1438 */ 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 1439 1678 1440 1679 if (eventsLeft.size() > 0) … … 1443 1682 branch->mLeft = recBuild(eventsLeft, nLeftS + nBothS, /*best.bleft*/minLeft, branch); 1444 1683 branch->mLeft->SetToLeft(); 1445 mBuildLog->logMessage("SetToLeft");1684 //mBuildLog->logMessage("SetToLeft"); 1446 1685 //branch->mLeft = recBuild(eventsLeft, nLeftS + nBothS, best.bleft, branch); 1447 1686 } … … 1451 1690 branch->mRight = recBuild(eventsRight, nBothS + nRightS, /*best.bright*/ minRight, branch); 1452 1691 branch->mRight->SetToRight(); 1453 mBuildLog->logMessage("SetToRight");1692 //mBuildLog->logMessage("SetToRight"); 1454 1693 1455 1694 … … 2034 2273 if (showBoxes) 2035 2274 { 2036 if (mLevel == mOwner->getHiLiteLevel()|| (mLevel-1) == mOwner->getHiLiteLevel() || mOwner->getShowAllBoxes()) 2275 /* 2276 if (mLevel == mOwner->getHiLiteLevel()|| (mLevel-1) == mOwner->getHiLiteLevel() || mOwner->getShowAllBoxes()) 2037 2277 queue->addRenderable(getWireBoundingBox()); 2278 */ 2038 2279 /* 2039 2280 if (mLevel == mOwner->getHiLiteLevel() || mOwner->getShowAllBoxes())
Note: See TracChangeset
for help on using the changeset viewer.