Changeset 2615 for GTP/trunk/Lib/Vis/Preprocessing/src/KdTree.cpp
- Timestamp:
- 01/19/08 05:28:24 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/Lib/Vis/Preprocessing/src/KdTree.cpp
r2606 r2615 1372 1372 bool KdTree::ImportBinTree(const string &filename, ObjectContainer &objects) 1373 1373 { 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1374 // export binary version of mesh 1375 queue<TraversalData> tStack; 1376 IN_STREAM stream(filename.c_str(), IN_BIN_MODE); 1377 1378 if (!stream.is_open()) return false; 1379 1380 // sort objects by their id 1381 // if (!is_sorted(objects.begin(), objects.end(), ilt)) 1382 sort(objects.begin(), objects.end(), ilt); 1383 1384 mBox.Initialize(); 1385 ObjectContainer::const_iterator oit, oit_end = objects.end(); 1386 1387 /////////////////////////// 1388 //-- compute bounding box of object space 1389 1390 for (oit = objects.begin(); oit != oit_end; ++ oit) 1391 { 1392 const AxisAlignedBox3 box = (*oit)->GetBox(); 1393 mBox.Include(box); 1394 } 1395 1396 // hack: we make a new root 1397 DEL_PTR(mRoot); 1398 1399 mRoot = ImportNextNode(stream, NULL, objects); 1400 1401 tStack.push(TraversalData(mRoot, mBox, 0)); 1402 mStat.Reset(); 1403 mStat.nodes = 1; 1404 1405 while(!tStack.empty()) 1406 { 1407 TraversalData tData = tStack.front(); 1408 tStack.pop(); 1409 1410 KdNode *node = tData.mNode; 1411 1412 if (!node->IsLeaf()) 1413 { 1414 mStat.nodes += 2; 1415 1416 //Debug << "i" ; 1417 KdInterior *interior = static_cast<KdInterior *>(node); 1418 interior->mBox = tData.mBox; 1419 1420 KdNode *front = ImportNextNode(stream, interior, objects); 1421 KdNode *back = ImportNextNode(stream, interior, objects); 1422 1423 interior->SetupChildLinks(back, front); 1424 1425 ++ mStat.splits[interior->mAxis]; 1426 1427 // compute new bounding box 1428 AxisAlignedBox3 frontBox, backBox; 1429 1430 tData.mBox.Split(interior->mAxis, 1431 interior->mPosition, 1432 frontBox, 1433 backBox); 1434 1435 tStack.push(TraversalData(front, frontBox, tData.mDepth + 1)); 1436 tStack.push(TraversalData(back, backBox, tData.mDepth + 1)); 1437 } 1438 else 1439 { 1440 EvaluateLeafStats(tData); 1441 //cout << "l"; 1442 } 1443 } 1444 1445 float area = GetBox().SurfaceArea()*mKdPvsArea; 1446 1447 SetPvsTerminationNodes(area); 1448 1449 Debug << mStat << endl; 1450 1451 return true; 1452 1452 } 1453 1453 … … 1456 1456 KdTree::GetOrCreateKdIntersectable(KdNode *node) 1457 1457 { 1458 1459 1458 if (node == NULL) 1459 return NULL; 1460 1460 1461 1461 if (node->mIntersectable == NULL) … … 1465 1465 KdIntersectable *kdObj = new KdIntersectable(node, GetBox(node)); 1466 1466 node->mIntersectable = kdObj; 1467 1467 1468 1468 mKdIntersectables.push_back(kdObj); 1469 1469 kdObj->SetId(id); 1470 1470 #ifdef USE_BIT_PVS 1471 1472 1471 // hack: for kd pvs the kd intersecables are the pvs objects 1472 ObjectPvsIterator::sObjects.push_back(kdObj); 1473 1473 #endif 1474 1475 1476 1474 } 1475 1476 return node->mIntersectable; 1477 1477 } 1478 1478 … … 1519 1519 } 1520 1520 1521 1522 /*KdNode * 1523 KdTree::GetPvsNode(const Triangle3 &tri) const 1524 { 1525 KdNode *node = mRoot; 1526 1527 while (node->mPvsTermination == 0 ) 1528 { 1529 KdInterior *inter = (KdInterior *)node; 1530 if (point[inter->mAxis] < inter->mPosition) 1531 node = inter->mBack; 1532 else 1533 node = inter->mFront; 1534 } 1535 1536 return node; 1537 }*/ 1538 1539 1540 1521 1541 KdNode * 1522 1542 KdTree::GetPvsNode(const Vector3 &point) const … … 1561 1581 1562 1582 while (!tStack.empty()) 1563 1564 1565 1566 1567 1568 {1569 leaves.push_back(static_cast<KdLeaf *>(node));1570 }1571 1572 {1573 KdInterior *interior = static_cast<KdInterior *>(node);1574 1575 if (box.Max(interior->mAxis) >= interior->mPosition)1576 1577 1578 1579 1580 if (box.Min(interior->mAxis) < interior->mPosition)1581 1582 1583 1584 }1585 1586 } 1587 1588 1589 1590 } 1583 { 1584 KdNode *node = tStack.top(); 1585 tStack.pop(); 1586 1587 if (node->IsLeaf()) 1588 { 1589 leaves.push_back(static_cast<KdLeaf *>(node)); 1590 } 1591 else // interior 1592 { 1593 KdInterior *interior = static_cast<KdInterior *>(node); 1594 1595 if (box.Max(interior->mAxis) >= interior->mPosition) 1596 { 1597 tStack.push(interior->mFront); 1598 } 1599 1600 if (box.Min(interior->mAxis) < interior->mPosition) 1601 { 1602 tStack.push(interior->mBack); 1603 } 1604 } 1605 } 1606 } 1607 1608 1609 1610 }
Note: See TracChangeset
for help on using the changeset viewer.