Ignore:
Timestamp:
01/19/08 05:28:24 (16 years ago)
Author:
mattausch
Message:

did some stuff for the visualization

File:
1 edited

Legend:

Unmodified
Added
Removed
  • GTP/trunk/Lib/Vis/Preprocessing/src/KdTree.cpp

    r2606 r2615  
    13721372bool KdTree::ImportBinTree(const string &filename, ObjectContainer &objects) 
    13731373{ 
    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; 
     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; 
    14521452} 
    14531453 
     
    14561456KdTree::GetOrCreateKdIntersectable(KdNode *node) 
    14571457{ 
    1458   if (node == NULL) 
    1459     return NULL; 
     1458        if (node == NULL) 
     1459                return NULL; 
    14601460 
    14611461        if (node->mIntersectable == NULL)  
     
    14651465                KdIntersectable *kdObj = new KdIntersectable(node, GetBox(node)); 
    14661466                node->mIntersectable = kdObj; 
    1467                  
     1467 
    14681468                mKdIntersectables.push_back(kdObj); 
    14691469                kdObj->SetId(id); 
    14701470#ifdef USE_BIT_PVS 
    1471     // hack: for kd pvs the kd intersecables are the pvs objects 
    1472     ObjectPvsIterator::sObjects.push_back(kdObj); 
     1471                // hack: for kd pvs the kd intersecables are the pvs objects 
     1472                ObjectPvsIterator::sObjects.push_back(kdObj); 
    14731473#endif 
    1474   } 
    1475  
    1476   return node->mIntersectable; 
     1474        } 
     1475 
     1476        return node->mIntersectable; 
    14771477} 
    14781478 
     
    15191519} 
    15201520 
     1521 
     1522/*KdNode * 
     1523KdTree::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 
    15211541KdNode * 
    15221542KdTree::GetPvsNode(const Vector3 &point) const 
     
    15611581   
    15621582  while (!tStack.empty()) 
    1563     { 
    1564       KdNode *node = tStack.top(); 
    1565       tStack.pop(); 
    1566        
    1567       if (node->IsLeaf()) 
    1568         { 
    1569           leaves.push_back(static_cast<KdLeaf *>(node)); 
    1570         } 
    1571       else // interior 
    1572         { 
    1573           KdInterior *interior = static_cast<KdInterior *>(node); 
    1574            
    1575           if (box.Max(interior->mAxis) >= interior->mPosition) 
    1576             { 
    1577               tStack.push(interior->mFront); 
    1578             } 
    1579            
    1580           if (box.Min(interior->mAxis) < interior->mPosition) 
    1581             { 
    1582               tStack.push(interior->mBack); 
    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.