Ignore:
Timestamp:
09/13/05 18:31:48 (19 years ago)
Author:
mattausch
Message:

did bsp stuff

Location:
trunk/VUT/GtpVisibilityPreprocessor
Files:
13 edited

Legend:

Unmodified
Added
Removed
  • trunk/VUT/GtpVisibilityPreprocessor/scripts/default.env

    r264 r265  
    1313#       viewcells ../data/atlanta/atlanta_viewcells_large.x3d 
    1414#viewcells ../data/atlanta/atlanta_viewcells_large2.x3d 
    15 #       viewcells ../data/vienna/viewcells-25-sel.x3d 
    16         viewcells ../data/vienna/viewcells-25.x3d 
     15        viewcells ../data/vienna/viewcells-25-sel.x3d 
     16#       viewcells ../data/vienna/viewcells-25.x3d 
    1717#       viewcells ../data/vienna/viewcells-large-sel.x3d 
    1818} 
     
    6363 
    6464BspTree { 
    65         splitPlaneStrategy leastSplits 
    66 #       splitPlaneStrategy balancedTree 
     65#       splitPlaneStrategy leastSplits 
     66        splitPlaneStrategy balancedTree 
    6767#       splitPlaneStrategy nextPolygon 
    6868#       splitPlaneStrategy combined 
  • trunk/VUT/GtpVisibilityPreprocessor/src/AxisAlignedBox3.h

    r191 r265  
    4545 
    4646  float Center(const int axis) const { 
    47     return  0.5 * (mMin[axis] + mMax[axis]); 
     47    return  0.5f * (mMin[axis] + mMax[axis]); 
    4848  } 
    4949 
  • trunk/VUT/GtpVisibilityPreprocessor/src/Mesh.h

    r209 r265  
    167167  virtual bool IsConvex() { return mMesh->mIsConvex; } 
    168168  virtual bool IsWatertight() { return mMesh->mIsWatertight; } 
    169   virtual float IntersectionComplexity() {  return mMesh->mFaces.size(); } 
     169  virtual float IntersectionComplexity() {  return (int)mMesh->mFaces.size(); } 
    170170 
    171171  virtual int Type() const { return MESH_INSTANCE; } 
  • trunk/VUT/GtpVisibilityPreprocessor/src/Plane3.h

    r245 r265  
    4747     
    4848    if (signum(dv) == 0) 
    49       { 
    50         if (coplanar)  
    51           (*coplanar) = true;    
     49        { 
     50                if (coplanar)  
     51                        (*coplanar) = true;      
    5252         
    53         return a; 
    54       } 
     53                return a; 
     54        } 
    5555     
    5656    float u = - Distance(a) / dv; // TODO: could be done more efficiently 
  • trunk/VUT/GtpVisibilityPreprocessor/src/Polygon3.cpp

    r264 r265  
    109109        bool onBackSide = false; 
    110110 
     111        int count = 0; 
    111112        // find possible line-plane intersections 
    112113        for (it = mVertices.begin(); it != mVertices.end(); ++ it) 
    113114        { 
    114115                int side = plane.Side(*it, SIDE_TOLERANCE); 
     116                //Debug << "side: " << side << " " << plane.Distance(*it) << endl; 
     117 
     118                if (side > 0) 
     119                        onFrontSide = true; 
     120                else if (side < 0) 
     121                        onBackSide = true; 
    115122                 
    116                 if (side > 0) 
    117                 { 
    118                         onFrontSide = true; 
    119                 } 
    120                 else if (side < 0) 
    121                 { 
    122                         onBackSide = true; 
    123                 } 
    124123                //TODO: check if split goes through vertex 
    125124                if (onFrontSide && onBackSide) // split  
     
    127126                        return SPLIT; 
    128127                } 
     128                // 3 vertices enough to decide coincident 
     129                else if (((++ count) >= 3) && !onFrontSide && !onBackSide)  
     130                        return COINCIDENT; 
    129131        } 
    130132 
  • trunk/VUT/GtpVisibilityPreprocessor/src/Preprocessor.cpp

    r264 r265  
    9595        { 
    9696        case BspTree::VIEW_CELLS: 
    97                 Debug << "Construction method: view cells\n"; 
    98                  
    9997                mBspTree->Construct(mViewCells); 
    10098                break; 
    10199        case BspTree::SCENE_GEOMETRY: 
    102                 Debug << "Construction method: geometry\n"; 
    103  
    104         CLEAR_CONTAINER(mViewCells); // we generate new view cells 
     100                CLEAR_CONTAINER(mViewCells); // we generate new view cells 
    105101 
    106102                mSceneGraph->CollectObjects(&objects); 
     
    108104                break; 
    109105        case BspTree::RAYS: 
    110                 Debug << "Construction method: rays\n"; 
    111  
    112106                CLEAR_CONTAINER(mViewCells); // we generate new view cells       
    113107                mBspTree->Construct(rays, &mViewCells); 
  • trunk/VUT/GtpVisibilityPreprocessor/src/Pvs.h

    r260 r265  
    4848  int AddNodeSample(KdNode *node); 
    4949  int Compress() {return 0;} 
    50   int GetSize() { return mEntries.size(); } 
     50  int GetSize() { return (int)mEntries.size(); } 
    5151  void GetData(const int index, 
    5252               KdNode *&node, 
  • trunk/VUT/GtpVisibilityPreprocessor/src/ViewCell.cpp

    r264 r265  
    44#include "Triangle3.h" 
    55 
     6ViewCell::ViewCell(): mMesh(NULL) 
     7{ 
     8} 
    69 
    710ViewCell::ViewCell(Mesh *mesh): mMesh(mesh), mPvs(NULL)  
  • trunk/VUT/GtpVisibilityPreprocessor/src/ViewCell.h

    r262 r265  
    1818{ 
    1919public: 
     20        ViewCell(); 
    2021        /** Default constructor taking a mesh which represents the shape of 
    2122                the viewcell. 
  • trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.cpp

    r264 r265  
    1717int BspTree::sTermMaxPolygons = 10; 
    1818int BspTree::sTermMaxDepth = 20; 
     19int BspTree::sMaxCandidates = 10; 
    1920int BspTree::sSplitPlaneStrategy = NEXT_POLYGON;  
    20 int BspTree::sMaxCandidates = 10; 
    2121int BspTree::sConstructionMethod = VIEW_CELLS; 
    2222 
     
    3030int BspTree::sBalancedTreeTable[4] = {-1, 1, 0, 0}; 
    3131 
    32 int counter = 0; 
    3332/****************************************************************/ 
    3433/*                  class BspNode implementation                */ 
     
    3635 
    3736BspNode::BspNode(): mParent(NULL), mPolygons(NULL) 
    38 { 
    39 } 
     37{} 
    4038 
    4139BspNode::BspNode(BspInterior *parent): mParent(parent), mPolygons(NULL) 
     
    5048        } 
    5149} 
     50 
    5251bool BspNode::IsRoot() const  
    5352{ 
     
    145144                                                                int &splits, bool storePolys) 
    146145{ 
    147 #ifdef _Debug 
     146//#ifdef _Debug 
    148147        Debug << "Splitting polygons of node " << this << " with plane " << mPlane << endl; 
    149 #endif 
     148//#endif 
    150149        bool inside = false; 
    151150 
     
    156155 
    157156                // test if split is neccessary 
    158                 int result = poly->ClassifyPlane(mPlane); 
    159  
     157                int classification = poly->ClassifyPlane(mPlane); 
     158 
     159                //Debug << "polygon plane: " << poly->GetSupportingPlane() << endl; 
    160160                Polygon3 *front_piece = NULL; 
    161161                Polygon3 *back_piece = NULL; 
    162162                 
    163                 switch (result) 
     163                switch (classification) 
    164164                { 
    165165                        case Polygon3::COINCIDENT: 
     
    169169                                        inside = (DotProd(mPlane.mNormal, poly->GetSupportingPlane().mNormal) > 0); 
    170170                                         
    171                                 //Debug << "coincident" << endl; 
     171                                Debug << "coincident" << endl; 
    172172                                // discard polygons or saves them in node 
    173173                                ProcessPolygon(poly, storePolys); 
    174174                                break; 
    175175                        case Polygon3::FRONT_SIDE: 
    176                                 //Debug << "front" << endl; 
     176                                Debug << "front" << endl; 
    177177                                frontPolys->push_back(poly); 
    178178                                break; 
    179179                        case Polygon3::BACK_SIDE: 
    180180                                inside = true; 
    181                                 //Debug << "back" << endl; 
     181                                Debug << "back" << endl; 
    182182                                backPolys->push_back(poly); 
    183183                                break; 
    184184                        case Polygon3::SPLIT: 
    185185                                inside = true; 
    186                                 //Debug << "split" << endl; 
     186                                Debug << "split " << poly << endl; 
    187187 
    188188                                front_piece = new Polygon3(); 
     
    279279        app << "#N_NODES ( Number of nodes )\n" << nodes << "\n"; 
    280280 
     281        app << "#N_LEAVES ( Number of interior nodes )\n" << Interior() << "\n"; 
     282 
    281283        app << "#N_LEAVES ( Number of leaves )\n" << Leaves() << "\n"; 
    282284 
    283         app << "#N_SPLITS ( Number of splits)\n" << splits << "\n"; 
     285        app << "#N_SPLITS ( Number of splits )\n" << splits << "\n"; 
    284286 
    285287        app << "#N_RAYREFS ( Number of rayRefs )\n" << 
     
    307309        maxDepthNodes * 100 / (double)Leaves() << endl; 
    308310 
    309         app << "#N_PMAXDEPTH ( Maximal reached depth )\n" << maxDepth <<endl; 
    310  
    311         app << "#N_ADDED_RAYREFS  (Number of dynamically added ray references )\n"<< 
    312         addedRayRefs<<endl; 
    313  
    314         app << "#N_REMOVED_RAYREFS  (Number of dynamically removed ray references )\n"<< 
    315         removedRayRefs<<endl; 
    316  
    317         //  app << setprecision(4); 
    318  
    319         //  app << "#N_CTIME  ( Construction time [s] )\n" 
    320         //      << Time() << " \n"; 
    321  
     311        app << "#N_PMAXDEPTH ( Maximal reached depth )\n" << maxDepth << endl; 
     312 
     313        app << "#N_PMINDEPTH ( Minimal reached depth )\n" << minDepth << endl; 
     314 
     315        app << "#AVGEPTH ( average depth )\n" << AvgDepth() << endl; 
     316 
     317        app << "#N_ADDED_RAYREFS  ( Number of dynamically added ray references )\n"<< 
     318        addedRayRefs << endl; 
     319 
     320        app << "#N_REMOVED_RAYREFS  ( Number of dynamically removed ray references )\n" << 
     321        removedRayRefs << endl; 
     322 
     323        app << "#N_INPUT_POLYGONS (number of input polygons )\n" << 
     324                polys << endl; 
     325 
     326        app << "#N_ROUTPUT_INPUT_POLYGONS ( ratio polygons after subdivision / input polygons )\n" << 
     327                 (polys + splits) / (double)polys << endl; 
     328         
    322329        app << "===== END OF BspTree statistics ==========\n"; 
    323330} 
     
    356363 
    357364        // extract polygons that guide the split process 
    358         AddMesh2Polygons(viewCell->GetMesh(), *polys); 
     365        mStat.polys += AddMesh2Polygons(viewCell->GetMesh(), *polys); 
    359366        mBox.Include(viewCell->GetBox()); // add to BSP aabb 
    360367 
     
    382389                                int splits = 0; 
    383390                 
     391                                Debug << "Splitting poly, YEAHH\n"; 
    384392                                // split viecell polygons with respect to split plane 
    385393                                bool inside = interior->SplitPolygons(tData.mPolygons, frontPolys, backPolys, splits, mStorePolys); 
     
    399407                else // reached leaf => subdivide current viewcell 
    400408                { 
     409                        if (tData.mPolygons->size() > 0) 
     410                                Debug << "WARNING (should not come here): polygon size: " << tData.mPolygons->size() << " inside: " << tData.mIsInside  << endl; 
     411 
    401412                        BspNode *root = Subdivide(tStack, tData, viewCell);              
    402413 
    403             // tree empty => new root 
    404                         if (!mRoot) 
     414                        //if (!root->IsLeaf()) 
     415                        //      Debug << "WARNING should NOT have subdivided further\n"; 
     416          
     417                        if (!mRoot) // tree empty => new root 
    405418                                mRoot = root; 
    406419                } 
    407420        } 
    408         Debug << "ended traversal" << endl; Debug.flush(); 
    409421} 
    410422 
     
    420432 
    421433 
    422 void BspTree::AddMesh2Polygons(Mesh *mesh, PolygonContainer &polys) 
     434int BspTree::AddMesh2Polygons(Mesh *mesh, PolygonContainer &polys) 
    423435{ 
    424436        FaceContainer::const_iterator fi; 
    425          
     437        int polysNum = 0; 
     438 
    426439        // copy the face data to polygons 
    427440        for (fi = mesh->mFaces.begin(); fi != mesh->mFaces.end(); ++ fi) 
     
    429442                Polygon3 *poly = new Polygon3((*fi), mesh); 
    430443                polys.push_back(poly); 
    431         } 
    432 } 
    433  
    434 void BspTree::Copy2PolygonSoup(const ViewCellContainer &viewCells, PolygonContainer &polys, int maxObjects) 
     444                polysNum ++; 
     445        } 
     446        return polysNum; 
     447} 
     448 
     449int BspTree::Copy2PolygonSoup(const ViewCellContainer &viewCells, PolygonContainer &polys, int maxObjects) 
    435450{ 
    436451        int limit = (maxObjects > 0) ? Min((int)viewCells.size(), maxObjects) : (int)viewCells.size(); 
     
    444459                } 
    445460        } 
    446 } 
    447  
    448 void BspTree::Copy2PolygonSoup(const ObjectContainer &objects, PolygonContainer &polys, int maxObjects) 
     461 
     462        return (int)polys.size(); 
     463} 
     464 
     465int BspTree::Copy2PolygonSoup(const ObjectContainer &objects, PolygonContainer &polys, int maxObjects) 
    449466{ 
    450467        int limit = (maxObjects > 0) ? Min((int)objects.size(), maxObjects) : (int)objects.size(); 
     
    475492        } 
    476493 
    477         Debug << "Number of polygons: " << (int)polys.size() << ", BSP root box: " << mBox << endl; 
     494        return (int)polys.size(); 
    478495} 
    479496 
     
    511528 
    512529        mStorePolys = savedStorePolys; 
    513  
    514         counter = 0; 
    515  
    516         Debug << "\n**** Started view cells insertion ****\n\n"; 
     530        mStat.polys = 0; 
     531        mStat.splits = 0; 
     532        //int counter = 0; 
     533         
     534        long startTime = GetTime(); 
     535        Debug << "**** Starting view cell insertion ****" << endl; 
    517536        for (it = viewCells.begin(); it != viewCells.end(); ++ it) 
    518537        { 
    519                 Debug << "*** Inserting view cell " << counter << " ***" << endl; 
     538                //Debug << "*** Inserting view cell " << counter ++ << " ***" << endl; 
    520539                InsertViewCell(*it); 
    521                 counter ++; 
    522         } 
    523         Debug << "**** finished view cells insertion ****" << endl; Debug.flush(); 
     540        } 
     541        Debug << "**** Finished view cell insertion ****" << endl; 
     542        Debug << "insertion time: "<< TimeDiff(startTime, GetTime())*1e-3 << "s" << endl; 
    524543} 
    525544 
     
    533552         
    534553        // copy mesh instance polygons into one big polygon soup 
    535         Copy2PolygonSoup(objects, *polys, sMaxCandidates); 
     554        mStat.polys = Copy2PolygonSoup(objects, *polys, sMaxCandidates); 
    536555 
    537556        // construct tree from polygon soup 
     
    546565} 
    547566 
    548 void BspTree::Construct(PolygonContainer *polys) 
     567void BspTree::Construct(PolygonContainer *polys, ViewCellContainer *viewCells) 
    549568{ 
    550569        std::stack<BspTraversalData> tStack; 
     
    554573        tStack.push(tData); 
    555574 
     575        long startTime = GetTime(); 
    556576        Debug << "**** Contructing tree using objects ****\n"; 
    557577        while (!tStack.empty())  
     
    559579                tData = tStack.top(); 
    560580            tStack.pop(); 
    561          
     581 
     582                ViewCell *viewCell = NULL; 
     583 
     584        if (viewCells) // generate new view cell in leaf 
     585                { 
     586                        viewCell = new ViewCell(); 
     587                        viewCells->push_back(viewCell); 
     588                } 
     589 
    562590                // subdivide leaf node 
    563                 BspNode *root = Subdivide(tStack, tData); 
     591                BspNode *root = Subdivide(tStack, tData, viewCell); 
    564592 
    565593                // empty tree => new root corresponding to unbounded space 
     
    568596        } 
    569597 
    570         Debug << "**** tree construction finished ****\n"; 
     598        Debug << "**** Finished tree construction ****\n"; 
     599        Debug << "BSP tree contruction time: "<< TimeDiff(startTime, GetTime())*1e-3 << "s" << endl; 
    571600} 
    572601 
     
    576605{ 
    577606        //-- terminate traversal   
    578         if (((tData.mPolygons->size() <= mTermMaxPolygons) || (tData.mDepth >= mTermMaxDepth)) 
     607        if ((tData.mPolygons->size() <= mTermMaxPolygons) || (tData.mDepth >= mTermMaxDepth)) 
    579608                // if there is another view cell associated with this leaf => subdivide further 
    580                 && !(viewCell && tData.mIsInside && dynamic_cast<BspLeaf *>(tData.mNode)->GetViewCell())) 
     609                //&& !(viewCell && tData.mIsInside && dynamic_cast<BspLeaf *>(tData.mNode)->GetViewCell()))   
    581610        { 
    582611#ifdef _DEBUG 
    583         Debug << "terminate subdivision, size " << (int)tData.mPolygons->size() << ", depth " << tData.mDepth << endl; 
     612                Debug << "subdivision terminated at depth " << tData.mDepth << ", #polys: " << (int)tData.mPolygons->size() << endl; 
    584613#endif 
    585614 
     
    587616 
    588617            // add view cell if inside object)  
    589                 if (viewCell && tData.mIsInside)  
    590                         // || (tData.mGeometry->size() > 0) // or if there is still geometry left  
     618                if (viewCell && tData.mIsInside) // || (tData.mGeometry->size() > 0) // or if there is still geometry left  
    591619                { 
    592620                        BspLeaf *leaf = dynamic_cast<BspLeaf *>(tData.mNode); 
    593621 
    594 #ifdef _DEBUG 
    595622                        if (leaf->GetViewCell()) 
    596623                                Debug << "ERROR: leaf already has view cell" << endl; 
    597624 
    598                         Debug << "**** Inserted view cell ****" << endl; 
    599 #endif 
    600625                        leaf->SetViewCell(viewCell); 
    601626                } 
     
    613638        bool inside = false; 
    614639 
     640        Debug << "Subdividing node at depth " << tData.mDepth << endl; 
    615641        BspInterior *interior = SubdivideNode(dynamic_cast<BspLeaf *>(tData.mNode), 
    616642                                                                                  tData.mPolygons, 
     
    618644                                                                                  backPolys, inside); 
    619645 
    620         // push the children on the stack (there are always two children) 
     646        // push the children on the stack 
     647        // inside information is only propagated with the back leaf 
    621648        tStack.push(BspTraversalData(interior->GetBack(), backPolys, tData.mDepth + 1, inside)); 
    622649        tStack.push(BspTraversalData(interior->GetFront(), frontPolys, tData.mDepth + 1, false)); 
     
    657684 
    658685        // and setup child links 
    659         interior->SetupChildLinks(new BspLeaf(interior, leaf->mViewCell), new BspLeaf(interior)); 
     686        //interior->SetupChildLinks(new BspLeaf(interior), new BspLeaf(interior, leaf->mViewCell)); 
     687        interior->SetupChildLinks(new BspLeaf(interior), new BspLeaf(interior)); 
    660688         
    661689        delete leaf; // leaf not member of tree anymore 
     
    685713{ 
    686714        int lowestCost = INITIAL_COST; 
    687         Plane3 *bestPlane = NULL; 
     715        int bestPlaneIdx = 0; 
    688716         
    689717        int limit = Min((int)polygons->size(), maxTests); 
    690718 
    691         for (int i = 0; i < limit; ++i) 
    692         { 
    693                 int candidateIdx = Random((int)polygons->size()); 
     719        for (int i = 0; i < limit; ++ i) 
     720        { 
     721                int candidateIdx = Random((int)polygons->size()); // TODO:  avoid testing same plane 2 times 
    694722                Plane3 candidatePlane = (*polygons)[candidateIdx]->GetSupportingPlane(); 
    695723                 
     
    699727                if (candidateCost < lowestCost) 
    700728                { 
    701                         bestPlane = &candidatePlane; 
     729                        bestPlaneIdx = candidateIdx; 
    702730                        lowestCost = candidateCost; 
    703731                        //Debug << "new plane cost " << lowestCost << endl; 
    704732                } 
    705733        } 
    706                  
    707         return *bestPlane; 
     734         
     735        if (lowestCost > 0) 
     736                Debug << "Split plane cost: " << lowestCost << " plane: " << (*polygons)[bestPlaneIdx]->GetSupportingPlane() << endl; 
     737        else 
     738                Debug << "no splits for plane: " << (*polygons)[bestPlaneIdx]->GetSupportingPlane() << endl; 
     739        return (*polygons)[bestPlaneIdx]->GetSupportingPlane(); 
    708740} 
    709741 
     
    712744        PolygonContainer::const_iterator it; 
    713745 
    714         int sum = 0, sum2 = 0; 
    715  
    716         for (it = polygons->begin(); it < polygons->end(); ++ it) 
     746        int sumBalanced = 0, sumLeastSplits = 0; 
     747 
     748        for (it = polygons->begin(); it != polygons->end(); ++ it) 
    717749        { 
    718750                int classification = (*it)->ClassifyPlane(candidatePlane); 
     
    720752                if ((sSplitPlaneStrategy == COMBINED) || (sSplitPlaneStrategy == BALANCED_TREE)) 
    721753                { 
    722                         sum += sBalancedTreeTable[classification]; 
     754                        sumBalanced += sBalancedTreeTable[classification]; 
    723755                } 
    724756                 
    725                 if ((sSplitPlaneStrategy == COMBINED) ||(sSplitPlaneStrategy == LEAST_SPLITS)) 
    726                 { 
    727                         sum2 += sLeastSplitsTable[classification]; 
    728                 } 
    729         } 
     757                if ((sSplitPlaneStrategy == COMBINED) || (sSplitPlaneStrategy == LEAST_SPLITS)) 
     758                { 
     759                        sumLeastSplits += sLeastSplitsTable[classification]; 
     760                        Debug << "Adding " <<  sLeastSplitsTable[classification] << " for poly " << *it << "!"; 
     761                } 
     762        } 
     763 
     764        Debug << "\n" << candidatePlane << " evaluation: " << abs(sumBalanced) + abs(sumLeastSplits) << endl; 
    730765 
    731766        // return linear combination of both sums 
    732         return abs(sum) + abs(sum2); 
     767        return abs(sumBalanced) + abs(sumLeastSplits); 
    733768} 
    734769 
     
    738773        environment->GetIntValue("BspTree.Termination.maxPolygons", sTermMaxPolygons); 
    739774        environment->GetIntValue("BspTree.maxCandidates", sMaxCandidates); 
     775 
     776        Debug << "BSP max depth: " << sTermMaxDepth << endl; 
     777        Debug << "BSP max polys: " << sTermMaxPolygons << endl; 
     778        Debug << "BSP max candidates: " << sMaxCandidates << endl; 
    740779 
    741780        //-- extract strategy to choose the next split plane 
     
    758797    } 
    759798 
     799        Debug << "Split plane heuristic: " << splitPlaneStrategyStr << endl; 
     800 
    760801        //-- parse BSP tree construction method 
    761         char constructionMethodStr[64]; 
     802        char constructionMethodStr[60]; 
    762803         
    763804        environment->GetStringValue("BspTree.constructionMethod", constructionMethodStr); 
     
    777818    } 
    778819 
     820        Debug << "Construction method: " << constructionMethodStr << endl; 
    779821} 
    780822 
     
    879921        } 
    880922 
    881         // store maximal depth 
     923        // store maximal and minimal depth 
    882924        if (data.mDepth > mStat.maxDepth) 
    883925                mStat.maxDepth = data.mDepth; 
     926        if (data.mDepth < mStat.minDepth) 
     927                mStat.minDepth = data.mDepth; 
     928 
     929        mStat.accumDepth += data.mDepth; 
     930 
     931        if (leaf->mViewCell) 
     932                ++ mStat.viewCellLeaves; 
    884933 
    885934#ifdef _DEBUG 
    886         Debug << "BSP Traversal data. Depth: " << data.mDepth << " (max: " << mTermMaxDepth<< "), #polygons: " <<  
     935        Debug << "BSP Traversal data. Depth: " << data.mDepth << " (max: " << mTermMaxDepth << "), #polygons: " <<  
    887936          data.mPolygons->size() << " (max: " << mTermMaxPolygons << ")" << endl; 
    888937#endif 
  • trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.h

    r264 r265  
    4646  // maximal reached depth 
    4747  int maxDepth; 
     48  // minimal depth 
     49  int minDepth; 
    4850  // total number of query domains 
    4951  int queryDomains; 
     
    6466  // number of dynamically removed ray refs 
    6567  int removedRayRefs; 
    66    
     68  // accumulated depth (used to compute average) 
     69  int accumDepth; 
     70  // number of initial polygons 
     71  int polys; 
     72  /// number of view cells in leaf 
     73  int viewCellLeaves; 
     74 
    6775  // Constructor 
    6876  BspTreeStatistics()  
     
    7482  int Interior() const { return nodes / 2; } 
    7583  int Leaves() const { return (nodes / 2) + 1; } 
    76  
     84  int AvgDepth() const { return accumDepth / Leaves();}; 
     85   
    7786  void Reset()  
    7887  { 
     
    8392          zeroQueryNodes = 0; 
    8493      maxDepthNodes = 0; 
    85       //minCostNodes = 0; 
     94 
    8695          maxObjectRefs = 0; 
    8796          addedRayRefs = removedRayRefs = 0; 
     97          maxDepth = 0; 
     98          minDepth = 99999; 
     99          polys = 0; 
     100          accumDepth = 0; 
     101          viewCellLeaves = 0; 
    88102  } 
    89103 
     
    316330 
    317331        /** Constructs the tree from the given list of polygons. 
    318         */ 
    319         void Construct(PolygonContainer *polys); 
     332                @param viewCells if not NULL, new view cells are  
     333                created in the leafs and stored in the conatainer 
     334        */ 
     335        void Construct(PolygonContainer *polys, ViewCellContainer *viewCells = NULL); 
    320336 
    321337        /** Evaluates the contribution of the candidate split plane. 
     
    376392                Adds object aabb to the aabb of the tree. 
    377393                @param maxPolys the maximal number of objects to be stored as polygons 
    378         */ 
    379         void Copy2PolygonSoup(const ObjectContainer &objects, PolygonContainer &polys, int maxObjects); 
     394                @returns the number of polygons 
     395        */ 
     396        int Copy2PolygonSoup(const ObjectContainer &objects, PolygonContainer &polys, int maxObjects); 
    380397        /** Extracts the meshes of the view cells and copies them into the mesh.  
    381398                Adds view cell aabb to the aabb of the tree. 
    382399                @param maxPolys the maximal number of objects to be stored as polygons 
    383         */ 
    384         void Copy2PolygonSoup(const ViewCellContainer &viewCells, PolygonContainer &polys, int maxObjects); 
    385  
    386         /** Add this mesh as polygons to polygon container. 
    387         */ 
    388         void AddMesh2Polygons(Mesh *mesh, PolygonContainer &polys); 
     400                @returns the number of polygons 
     401        */ 
     402        int Copy2PolygonSoup(const ViewCellContainer &viewCells, PolygonContainer &polys, int maxObjects); 
     403 
     404        /** Extract polygons of this mesh and add to polygon container. 
     405                @returns number of polygons 
     406        */ 
     407        int AddMesh2Polygons(Mesh *mesh, PolygonContainer &polys); 
    389408 
    390409        /** A ray is cast possible intersecting the tree. 
     
    393412        */ 
    394413        int CastRay(Ray &ray); 
    395  
    396  
    397414 
    398415        /// Pointer to the root of the tree 
  • trunk/VUT/GtpVisibilityPreprocessor/src/X3dExporter.cpp

    r264 r265  
    395395                SetFilled(); 
    396396 
     397        ViewCellContainer mFoundViewCells; 
     398 
    397399        while (!tStack.empty())  
    398400        { 
     
    422424                        ViewCell *viewCell = dynamic_cast<BspLeaf *>(node)->GetViewCell(); 
    423425                         
    424                         if (viewCell) // export view cell geometry 
    425                                 ExportViewCell(viewCell);        
     426                        if (viewCell) 
     427                                mFoundViewCells.push_back(viewCell); 
    426428                } 
    427429        } 
    428430         
     431        if (!tree.StorePolys()) 
     432        { 
     433                //move consecutive duplicates past the end; store new end 
     434                ViewCellContainer::iterator new_end = unique(mFoundViewCells.begin(), mFoundViewCells.end()); 
     435                // delete all elements past new_end  
     436                mFoundViewCells.erase(new_end, mFoundViewCells.end()); 
     437                ExportViewCells(&mFoundViewCells); 
     438        } 
     439 
    429440        return true; 
    430441} 
  • trunk/VUT/GtpVisibilityPreprocessor/src/main.cpp

    r264 r265  
    4444          { 
    4545          p->LoadViewCells(vcFilename); 
    46                   Exporter *exporter = Exporter::GetExporter("viewcells.x3d"); 
     46                   
     47                  /*Exporter *exporter = Exporter::GetExporter("viewcells.x3d"); 
    4748                  if (exporter)  
    48                   { 
    49                           exporter->ExportViewCells(&p->mViewCells); 
    50                           delete exporter; 
    51                   } 
     49                  {       exporter->ExportViewCells(&p->mViewCells); 
     50                          delete exporter;   
     51                  }*/ 
    5252          } 
    5353          else 
    5454                  p->GenerateViewCells(); 
     55 
     56          Debug << "Number of view cells: " << p->mViewCells.size() << endl; 
    5557  } 
    5658 
Note: See TracChangeset for help on using the changeset viewer.