Ignore:
Timestamp:
08/12/05 18:42:20 (19 years ago)
Author:
mattausch
Message:

added bsp stuff

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.cpp

    r236 r237  
    9696                polys->pop(); 
    9797 
     98                Debug << (*poly); 
     99 
    98100                int result = poly->Side(&mPlane); 
    99101 
     
    104106                { 
    105107                        case Polygon3::COINCIDENT: 
    106                                 break; 
     108                                //break; //TODO: comment in 
    107109                        case Polygon3::FRONT_SIDE: 
    108110                                frontPolys->push(poly); 
     
    118120                                poly->Split(&mPlane, front_piece, back_piece, splits); 
    119121                         
     122                                Debug << "SPLIT, plane: " << mPlane << "\norginal: " << (*poly) << "\nback: " << (*back_piece) << "\nfront: " << (*front_piece) << endl; 
    120123                                backPolys->push(back_piece); 
    121124                                frontPolys->push(front_piece); 
     
    123126                                // don't need polygon anymore 
    124127                                DEL_PTR(poly); 
     128 
    125129                                break; 
    126130                        default: 
     
    128132                } 
    129133        } 
    130         // delete old polygons 
    131 //      Polygon3::DeletePolygons(polys); 
    132134} 
    133135 
     
    204206 
    205207        app << "#N_PMAXDEPTHLEAVES ( Percentage of leaves at maxdepth )\n"<< 
    206         maxDepthNodes*100/(double)Leaves()<<endl; 
    207  
    208         app << "#N_PMAXDEPTH ( Maximal reached depth )\n"<< 
    209         maxDepth*100/(double)Leaves()<<endl; 
     208        maxDepthNodes * 100 / (double)Leaves() << endl; 
     209 
     210        app << "#N_PMAXDEPTH ( Maximal reached depth )\n" << maxDepth <<endl; 
    210211 
    211212        app << "#N_ADDED_RAYREFS  (Number of dynamically added ray references )\n"<< 
     
    334335        ObjectContainer::const_iterator it, it_end = objects.end(); 
    335336 
    336         for (it = objects.begin(); it != it_end; ++ it) 
    337         { 
    338                 Intersectable *object = *it; 
     337        int limit = min((int)objects.size(), 1); 
     338 
     339        //for (it = objects.begin(); it != it_end; ++ it) 
     340        for (int i = 0; i < limit; ++i) 
     341        { 
     342                Intersectable *object = objects[i];//*it; 
    339343                Mesh *mesh = NULL; 
    340344 
     
    343347                { 
    344348                case Intersectable::MESH_INSTANCE: 
    345                          
    346349                        mesh = dynamic_cast<MeshInstance *>(object)->GetMesh(); 
    347                          
     350                        break; 
    348351                case Intersectable::VIEWCELL: 
    349352                        mesh = dynamic_cast<ViewCell *>(object)->GetMesh(); 
    350                         // copy the mesh data to polygons 
    351                         CopyMesh2Polygons(mesh, polys); 
    352353                        break; 
    353354                default: 
    354355                        break; 
    355356                } 
    356         } 
     357                 
     358                if (mesh) // copy the mesh data to polygons 
     359                { 
     360                        CopyMesh2Polygons(mesh, polys); 
     361                } 
     362        } 
     363 
    357364        Debug << "number of polygons: " << polys.size() << endl; 
    358365} 
     
    360367void BspTree::Construct(const ObjectContainer &objects) 
    361368{ 
     369        Debug << "Constructing tree using object container\n"; 
     370 
    362371        mTermMaxPolygons = sTermMaxPolygons; 
    363372        mTermMaxDepth = sTermMaxDepth; 
     
    376385        while (!tStack.empty())  
    377386        { 
    378             tData = tStack.top(); 
     387                tData = tStack.top(); 
    379388            tStack.pop(); 
    380      
     389                 
    381390                Subdivide(tStack, tData); 
    382391        } 
     
    385394void BspTree::Subdivide(BspTraversalStack &tStack, BspTraversalData &tData, ViewCell *viewCell) 
    386395{ 
     396        //Debug << "Subdividing node\n"; 
     397 
    387398        PolygonQueue *backPolys = new PolygonQueue(); 
    388399        PolygonQueue *frontPolys = new PolygonQueue(); 
     
    404415                tStack.push(BspTraversalData(interior->GetFront(), interior, frontPolys, tData.mDepth + 1)); 
    405416        } 
    406         else 
     417        else // tree terminates here 
     418        { 
    407419                EvaluateLeafStats(tData); 
     420                // don't need to store polygon information => delete polygons 
     421                Polygon3::DeletePolygons(tData.mPolygons); 
     422        } 
    408423} 
    409424 
     
    434449        if ((polys->size() <= mTermMaxPolygons) || (depth >= mTermMaxDepth)) 
    435450        { 
    436                 // don't need to store polygon information => delete polygons 
    437                 Polygon3::DeletePolygons(polys); 
    438451                // Debug << polys->size() << ", " << depth << endl;              
    439452                return leaf; 
     
    444457        // add the new nodes to the tree + select subdivision plane 
    445458        BspInterior *node = new BspInterior(SelectPlane(polys));  
    446  
     459        Debug << "new bspinterior: " << (*node) << endl; 
    447460        // split polygon according to current plane 
    448461        int splits = 0; 
     
    463476        node->SetupChildLinks(back, front); 
    464477 
    465         DEL_PTR(leaf); 
     478        DEL_PTR(leaf); // leaf not member of tree anymore 
    466479 
    467480        return node; 
     
    473486        environment->GetIntValue("BspTree.Termination.maxPolygons", sTermMaxPolygons); 
    474487 
     488        //-- extract strategy to choose the next split plane 
    475489        char splitPlaneStrategyStr[60]; 
    476490 
    477491        environment->GetStringValue("BspTree.splitPlaneStrategy", splitPlaneStrategyStr); 
    478         // TODO: Extract nodes 
     492         
     493        sSplitPlaneStrategy = BspTree::NEXT_POLYGON; 
     494         
     495        if (strcmp(splitPlaneStrategyStr, "nextPolygon") == 0) 
     496                sSplitPlaneStrategy = BspTree::NEXT_POLYGON; 
     497        else if (strcmp(splitPlaneStrategyStr, "leastSplits") == 0) 
     498                sSplitPlaneStrategy = BspTree::LEAST_SPLITS; 
     499        else  
     500        { 
     501                cerr << "Wrong BSP split plane strategy " << splitPlaneStrategyStr << endl; 
     502                exit(1); 
     503    } 
    479504} 
    480505 
    481506void BspTree::EvaluateLeafStats(const BspTraversalData &data) 
    482507{ 
    483  
    484508  // the node became a leaf -> evaluate stats for leafs 
    485509  BspLeaf *leaf = dynamic_cast<BspLeaf *>(data.mNode); 
    486510 
    487   if (data.mDepth > mTermMaxDepth) 
    488     ++ mStat.maxDepthNodes;  
     511  if (data.mDepth >= mTermMaxDepth) 
     512  { 
     513          ++ mStat.maxDepthNodes;  
     514  } 
    489515 
    490516  // record maximal depth 
    491517  if (data.mDepth > mStat.maxDepth) 
    492518          mStat.maxDepth = data.mDepth; 
     519 
     520  Debug << "BSP Traversal data. Depth: " << data.mDepth << " (max: " << mTermMaxDepth<< "), #polygons: " <<  
     521          data.mPolygons->size() << " (max: " << mTermMaxPolygons << ")" << endl; 
    493522} 
    494523//} // GtpVisibilityPreprocessor 
Note: See TracChangeset for help on using the changeset viewer.