Changeset 239


Ignore:
Timestamp:
08/16/05 00:08:53 (19 years ago)
Author:
mattausch
Message:

removed debug stuff. viewcell insertion working

Location:
trunk/VUT/GtpVisibilityPreprocessor
Files:
7 edited

Legend:

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

    r238 r239  
    6262        splitPlaneStrategy balancedTree 
    6363#       splitPlaneStrategy nextPolygon 
    64 #       constructionMethod viewCells 
    65         constructionMethod sceneGeometry 
     64        constructionMethod viewCells 
     65#       constructionMethod sceneGeometry 
    6666        maxCandidates 20 
    67         maxViewCells 100 
     67        maxViewCells 10 
    6868        Termination { 
    6969                maxPolygons 4 
  • trunk/VUT/GtpVisibilityPreprocessor/src/Plane3.h

    r238 r239  
    4949          if (signum(dv) != 0) 
    5050          { 
    51                   u = - Distance(a) / dv; 
    52                   Debug << "t: " << u << ", b - a: " << v << ", norm: " << mNormal << ", dist(a): " << - Distance(a) << ", dv: " << dv << endl; 
    53                   if (coplanar) (*coplanar) = false; 
     51                  u = - Distance(a) / dv; // NOTE: could be done more efficiently 
     52                  //Debug << "t: " << u << ", b - a: " << v << ", norm: " << mNormal << ", dist(a): " << - Distance(a) << ", dv: " << dv << endl; 
     53                  if (coplanar)  
     54                          (*coplanar) = false; 
    5455          } 
    55           else { 
    56                   if (coplanar) (*coplanar) = true;        
     56          else if (coplanar)  
     57          { 
     58                  (*coplanar) = true;      
    5759          } 
    58           if (t) (*t) = u; 
    59           Debug << "result of intersection with A: " << a << ", B: " << b << ":\n" << (a + u * b - u * a) << "\n" << (a + u*v) << "\n\n"; 
    60            
     60 
     61          if (t)  
     62                  (*t) = u; 
     63                   
    6164          return a + u * b - u * a; // NOTE: gives better precision than calclulating a + u * v 
    6265          //return a + (u * v); 
  • trunk/VUT/GtpVisibilityPreprocessor/src/Polygon3.cpp

    r238 r239  
    1414        VertexIndexContainer::const_iterator it; 
    1515 
    16         Debug << "Creating polygon:\n"; 
    17  
    1816        for (it = face->mVertexIndices.begin(); it != face->mVertexIndices.end(); ++ it) 
    1917        { 
     
    2523Plane3 Polygon3::GetSupportingPlane() const 
    2624{ 
    27         Debug << "creating plane using vertices: " << mVertices[0] << mVertices[1] << mVertices[2] << endl; 
    2825        Vector3 v1 = mVertices[0] - mVertices[1]; 
    29                 Vector3 v2 = mVertices[2] - mVertices[1]; 
    30         Debug << "plane has vectors " <<  v1 << v2  << endl; 
     26        Vector3 v2 = mVertices[2] - mVertices[1]; 
     27#ifdef _DEBUG 
     28        Debug << "plane spanned by " <<  v1 << ", " << v2  << endl; 
     29#endif 
    3130        return Plane3(mVertices[0], mVertices[1], mVertices[2]); 
    3231} 
     
    5251        VertexContainer::const_iterator it; 
    5352 
    54         Debug << "\n\nvertex A: " << ptA << ", side A: " << sideA << " (" << partition->Distance(ptA) << ")"; 
    55  
    5653        // find line - plane intersections 
    5754        for (it = mVertices.begin(); it != mVertices.end(); ++ it) 
     
    5956                Vector3 ptB = (*it); 
    6057                int sideB = partition->Side(ptB, SIDE_TOLERANCE); 
    61                 Debug << " <=> vertex B: " << ptB << ", side B: " << sideB << " (" << partition->Distance(ptB) << ")\n\n"; 
    62  
     58         
    6359                // vertices on different sides => split 
    6460            if (sideB > 0) 
     
    7167                                // add vertex to both polygons 
    7268                                front->mVertices.push_back(splitPt); 
    73                                 back->mVertices.push_back(splitPt); Debug << "front and back polygon + " << splitPt << endl; 
     69                                back->mVertices.push_back(splitPt); 
    7470                         
    7571                                ++ splits; 
    7672                        } 
    77                         front->mVertices.push_back(ptB); Debug << "front polygon + " << ptB << endl; 
     73                        front->mVertices.push_back(ptB); 
    7874                } 
    7975                else if (sideB < 0) 
     
    8682                                // add vertex to both polygons 
    8783                                front->mVertices.push_back(splitPt); 
    88                                 back->mVertices.push_back(splitPt); Debug << "front and back polygon + " << splitPt << endl; 
     84                                back->mVertices.push_back(splitPt); 
    8985 
    9086                                ++ splits; 
    9187                        } 
    92                         back->mVertices.push_back(ptB); Debug << "back polygon + " << ptB << endl; 
     88                        back->mVertices.push_back(ptB); 
    9389                } 
    9490                else 
     
    9692                        // vertex on plane => add vertex to both polygons 
    9793                        front->mVertices.push_back(ptB); 
    98                         back->mVertices.push_back(ptB); Debug << "front and back polygon + " << ptB << endl; 
     94                        back->mVertices.push_back(ptB);  
    9995                } 
    10096         
    10197                ptA = ptB; 
    10298                sideA = sideB; 
    103                 Debug << "vertex A: " << ptA << ", side A: " << sideA << " (" << partition->Distance(ptA) << ")"; 
    10499        } 
    105         Debug << "\n*********************\n"; 
    106100} 
    107101 
  • trunk/VUT/GtpVisibilityPreprocessor/src/ViewCell.cpp

    r237 r239  
    4141float ViewCell::IntersectionComplexity()  
    4242{ 
    43         return mMesh->mFaces.size(); 
     43        return (float)mMesh->mFaces.size(); 
    4444} 
    4545 
     
    5656void ViewCell::DeriveViewCells(const ObjectContainer &objects,  
    5757                                                           ViewCellContainer &viewCells,  
    58                                                            const int max) 
     58                                                           const int maxViewCells) 
    5959{ 
    6060        // maximal max viewcells 
    61         int n = max > 0 ? std::min((int)objects.size(), max) : (int)objects.size(); 
     61        int limit = maxViewCells > 0 ? std::min((int)objects.size(), maxViewCells) : (int)objects.size(); 
    6262 
    63         for (int i = 0; i < n; ++i) 
     63        for (int i = 0; i < limit; ++i) 
    6464        { 
    6565                Intersectable *object = objects[i]; 
  • trunk/VUT/GtpVisibilityPreprocessor/src/ViewCell.h

    r235 r239  
    4646                @param objects the intersectables the viewcells are derived from 
    4747                @param viewCells the viewcells are returned in this container 
    48                 @param if >0, indicates the maximim number of viewcells that will be created 
     48                @param maxViewCells if > 0, indicates the maximim number of viewcells that will be created 
    4949        */ 
    5050        static void DeriveViewCells(const ObjectContainer &objects,  
    5151                                                                ViewCellContainer &viewCells,  
    52                                                                 const int max); 
     52                                                                const int maxViewCells); 
    5353protected: 
    5454 
  • trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.cpp

    r238 r239  
    1111#include <iomanip> 
    1212 
     13#define INITIAL_TEST_VAL 999999// unreachable high initial value for heuristic evaluation 
     14 
    1315int BspTree::sTermMaxPolygons = 10; 
    1416int BspTree::sTermMaxDepth = 20; 
     
    9698        { 
    9799                Polygon3 *poly = polys->back(); 
    98  
    99100                polys->pop_back(); 
    100101 
    101                 Debug << (*poly); 
    102  
     102                // test if split is neccessary 
    103103                int result = poly->ClassifyPlane(mPlane); 
    104104 
     
    109109                { 
    110110                        case Polygon3::COINCIDENT: 
    111                                 Debug << "coincident\n"; 
    112111                                break; // do nothing 
    113112                        case Polygon3::FRONT_SIDE: 
    114                                 Debug << "front\n"; 
    115113                                frontPolys->push_back(poly); 
    116114                                break; 
    117115                        case Polygon3::BACK_SIDE: 
    118                                 Debug << "back\n"; 
    119116                                backPolys->push_back(poly); 
    120117                                break; 
     
    123120                                back_piece = new Polygon3(); 
    124121 
    125                                 Debug << "\n\n**************SPLIT***************\n"; 
    126                                 Debug << "Split plane: " << mPlane << "\noriginal " << (*poly) << endl; 
    127  
    128122                                //-- split polygon 
    129123                                poly->Split(&mPlane, front_piece, back_piece, splits); 
    130                          
    131                                 Debug << "new front " << (*front_piece) << endl; 
    132                                 Debug << "new back " << (*back_piece) << endl; 
    133124 
    134125                                frontPolys->push_back(front_piece); 
    135126                                backPolys->push_back(back_piece); 
    136127                                 
     128#ifdef _DEBUG 
     129                                Debug << "split " << poly << endl << front << endl << back << endl; 
     130#endif 
    137131                                // don't need polygon anymore 
    138132                                DEL_PTR(poly); 
     
    169163/****************************************************************/ 
    170164 
    171 BspTree::BspTree(): mTermMaxPolygons(0), mTermMaxDepth(0) 
    172 { 
    173         mRoot = new BspLeaf(); 
     165BspTree::BspTree(): mTermMaxPolygons(0), mTermMaxDepth(0), mRoot(NULL) 
     166{ 
    174167        Randomize(); // initialise random generator for heuristics 
    175168} 
     
    267260 
    268261void BspTree::InsertViewCell(ViewCell *viewCell) 
    269 { 
    270         Debug << "Inserting view cells\n"; 
     262{        
    271263        std::stack<BspTraversalData> tStack; 
    272264         
     
    275267        CopyMesh2Polygons(viewCell->GetMesh(), polys); 
    276268 
    277         tStack.push(BspTraversalData(mRoot, NULL, &polys, 0)); 
     269        BspNode *firstNode = mRoot ? mRoot : new BspLeaf(); // traverse tree or create new one 
     270 
     271        tStack.push(BspTraversalData(firstNode, NULL, &polys, 0)); 
    278272 
    279273        while (!tStack.empty()) 
     
    283277 
    284278            tStack.pop(); 
    285          
     279                                 
    286280        if (!tData.mNode->IsLeaf()) 
    287281                { 
    288282                        BspInterior *interior = dynamic_cast<BspInterior *>(tData.mNode); 
    289283 
    290                         // filter polygons down the tree. 
     284                        //-- filter view cell polygons down the tree until a leaf is reached 
    291285                        PolygonContainer *frontPolys = new PolygonContainer(); 
    292286                        PolygonContainer *backPolys = new PolygonContainer(); 
    293287 
    294288                        int splits = 0; 
     289                        // split viecell polygons with respect to split plane 
    295290                        interior->SplitPolygons(tData.mPolygons, frontPolys, backPolys, splits); 
    296291                        mStat.splits += splits; 
     
    309304                                delete backPolys; 
    310305                } 
    311                 else // reached leaf => subdivide 
    312                 { 
    313                         Subdivide(tStack, tData, NULL); 
     306                else // reached leaf => subdivide current viewcell 
     307                { 
     308                        BspNode *root = Subdivide(tStack, tData, NULL); 
     309 
     310                        if (!mRoot) // take as root if there is none yet 
     311                                mRoot = root;                            
    314312                } 
    315313        } 
     
    349347        ObjectContainer::const_iterator it, it_end = objects.end(); 
    350348 
    351         int limit = maxPolys != 0 ? min((int)objects.size(), maxPolys) : (int)objects.size(); 
    352  
    353         //for (it = objects.begin(); it != it_end; ++ it) 
     349        int limit = (maxPolys > 0) ? min((int)objects.size(), maxPolys) : (int)objects.size(); 
     350 
    354351        for (int i = 0; i < limit; ++i) 
    355352        { 
     
    376373        } 
    377374 
    378         Debug << "number of polygons: " << polys.size() << endl; 
     375        Debug << "Number of polygons: " << polys.size() << endl; 
    379376} 
    380377 
     
    394391        Copy2PolygonSoup(objects, *polys, 100); 
    395392 
    396         BspTraversalData tData(mRoot, mRoot->GetParent(), polys, 0); 
     393        BspTraversalData tData(new BspLeaf(), mRoot->GetParent(), polys, 0); 
     394 
    397395        tStack.push(tData); 
    398396 
     
    401399                tData = tStack.top(); 
    402400            tStack.pop(); 
    403                  
    404                 Subdivide(tStack, tData); 
    405         } 
    406 } 
    407  
    408 void BspTree::Subdivide(BspTraversalStack &tStack, BspTraversalData &tData, ViewCell *viewCell) 
    409 { 
    410         //Debug << "Subdividing node\n"; 
     401 
     402                // subdivide leaf node 
     403                BspNode *root = Subdivide(tStack, tData); 
     404 
     405                if (!mRoot) 
     406                        mRoot = root; 
     407        } 
     408} 
     409 
     410BspNode * BspTree::Subdivide(BspTraversalStack &tStack, BspTraversalData &tData, ViewCell *viewCell) 
     411{ 
    411412        PolygonContainer *backPolys = new PolygonContainer(); 
    412413        PolygonContainer *frontPolys = new PolygonContainer(); 
    413 int polySize = tData.mPolygons->size(); 
     414 
    414415        BspNode *node = SubdivideNode(dynamic_cast<BspLeaf *>(tData.mNode), 
    415416                                                                  tData.mParent, 
     
    419420                                                                  frontPolys, 
    420421                                                                  backPolys); 
    421 Debug << "Level " << tData.mDepth << ", all: " << polySize << ", front: " << frontPolys->size() << ", back: " << backPolys->size() << endl; 
     422 
    422423        if (!node->IsLeaf()) // node was subdivided 
    423424        { 
     
    434435                Polygon3::DeletePolygons(tData.mPolygons); 
    435436        } 
     437 
     438        return node; 
    436439} 
    437440 
    438441Plane3 BspTree::SelectPlane(PolygonContainer *polygons)  const 
    439442{ 
    440         // most simple strategy: just take next polygon 
     443        // simple strategy: just take next polygon 
    441444        if (sSplitPlaneStrategy == NEXT_POLYGON) 
    442445        { 
    443                 Debug << "simple plane selection\n"; 
    444446                return polygons->front()->GetSupportingPlane(); 
    445447        } 
     
    450452Plane3 BspTree::SelectPlaneHeuristics(PolygonContainer *polygons, int maxTests) const 
    451453{ 
    452         Debug << "selecting plane heuristics\n"; 
    453  
    454         int bestValue = 999999; 
    455  
     454        int bestValue = INITIAL_TEST_VAL; 
    456455        Plane3 *bestPlane = NULL; 
    457456         
     
    462461                int candidateIdx = Random((int)polygons->size()); 
    463462                Plane3 candidatePlane = (*polygons)[candidateIdx]->GetSupportingPlane(); 
    464                 Debug << "choosing new candidate: " << limit << endl; 
     463                 
    465464                // evaluate current candidate 
    466465                int candidateValue = EvalSplitPlane(polygons, candidatePlane); 
     
    470469                        bestPlane = &candidatePlane; 
    471470                        bestValue = candidateValue; 
    472                         Debug << "new plane value " << bestValue << endl; 
    473                 } 
    474         } 
    475         Debug << "%%%%%%%%%%found value: " << bestValue << endl; 
     471                        //Debug << "new plane value " << bestValue << endl; 
     472                } 
     473        } 
    476474                 
    477475        return *bestPlane; 
     
    532530        if ((polys->size() <= mTermMaxPolygons) || (depth >= mTermMaxDepth)) 
    533531        { 
    534                 // Debug << polys->size() << ", " << depth << endl;              
    535532                return leaf; 
    536533        } 
     
    540537        // add the new nodes to the tree + select subdivision plane 
    541538        BspInterior *node = new BspInterior(SelectPlane(polys));  
    542         Debug << "new bspinterior: " << (*node) << endl; 
     539 
     540#ifdef _DEBUG 
     541        Debug << node << endl; 
     542#endif 
    543543        // split polygon according to current plane 
    544544        int splits = 0; 
     
    546546         
    547547        node->SplitPolygons(polys, frontPolys, backPolys, splits); 
    548         Debug << "$$ " << polySize << " " << frontPolys->size() << " " << backPolys->size() << endl;  
     548         
    549549        mStat.splits += splits; 
    550550 
     
    595595void BspTree::EvaluateLeafStats(const BspTraversalData &data) 
    596596{ 
    597   // the node became a leaf -> evaluate stats for leafs 
    598   BspLeaf *leaf = dynamic_cast<BspLeaf *>(data.mNode); 
    599  
    600   Debug << "evaluating leaf stats\n"; 
    601  
    602   if (data.mDepth >= mTermMaxDepth) 
    603   { 
    604           ++ mStat.maxDepthNodes;  
    605   } 
    606  
    607   // record maximal depth 
    608   if (data.mDepth > mStat.maxDepth) 
    609           mStat.maxDepth = data.mDepth; 
    610  
    611   Debug << "BSP Traversal data. Depth: " << data.mDepth << " (max: " << mTermMaxDepth<< "), #polygons: " <<  
     597        // the node became a leaf -> evaluate stats for leafs 
     598        BspLeaf *leaf = dynamic_cast<BspLeaf *>(data.mNode); 
     599 
     600        if (data.mDepth >= mTermMaxDepth) 
     601        { 
     602                ++ mStat.maxDepthNodes; 
     603        } 
     604 
     605        // record maximal depth 
     606        if (data.mDepth > mStat.maxDepth) 
     607                mStat.maxDepth = data.mDepth; 
     608 
     609#ifdef _DEBUG 
     610        Debug << "BSP Traversal data. Depth: " << data.mDepth << " (max: " << mTermMaxDepth<< "), #polygons: " <<  
    612611          data.mPolygons->size() << " (max: " << mTermMaxPolygons << ")" << endl; 
     612#endif 
    613613} 
    614614//} // GtpVisibilityPreprocessor 
  • trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.h

    r238 r239  
    254254                @param tData traversal data also holding node to be subdivided 
    255255                @param viewCell the view cell that will be represented with this part of the Bsp tree. 
    256         */ 
    257         void Subdivide(BspTraversalStack &tStack, BspTraversalData &tData, ViewCell *viewCell = NULL); 
     256                @returns new root of the subtree 
     257        */ 
     258        BspNode *Subdivide(BspTraversalStack &tStack, BspTraversalData &tData, ViewCell *viewCell = NULL); 
    258259 
    259260        /** Selects a splitting plane.  
Note: See TracChangeset for help on using the changeset viewer.