Ignore:
Timestamp:
08/08/05 18:03:08 (19 years ago)
Author:
mattausch
Message:
 
Location:
trunk/VUT/GtpVisibilityPreprocessor/src
Files:
2 edited

Legend:

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

    r221 r222  
    1919/****************************************************************/ 
    2020 
     21 
     22BspInterior::BspInterior(Plane3 plane): mPlane(plane)  
     23{} 
     24 
    2125bool BspInterior::IsLeaf() const 
    2226{  
    2327        return false;  
     28} 
     29 
     30BspNode *BspInterior::GetBack()  
     31{ 
     32        return mBack; 
     33} 
     34 
     35BspNode *BspInterior::GetFront()  
     36{ 
     37        return mFront; 
     38} 
     39 
     40Plane3 *BspInterior::GetPlane() 
     41{ 
     42        return &mPlane; 
    2443} 
    2544 
     
    4261} 
    4362 
     63 
    4464/****************************************************************/ 
    4565/*                  class BspLeaf implementation                */ 
     
    4868BspLeaf::BspLeaf(ViewCell *viewCell): mViewCell(viewCell)  
    4969{ 
     70} 
     71 
     72ViewCell *BspLeaf::GetViewCell() 
     73{ 
     74        return mViewCell; 
    5075} 
    5176 
     
    83108                Mesh frontPolys; 
    84109 
    85                 BspNode *node = SubdivideNode(dynamic_cast<BspLeaf *>(data.mNode), 
    86                                                                           data.mParent, 
    87                                                                           &data.mViewCell, 
    88                                                                       data.mDepth, 
    89                                                                           backPolys, 
    90                                                                           frontPolys); 
     110                if (data.mNode->IsLeaf()) // if we have a leaf => subdivide 
     111                { 
     112                        BspNode *node = SubdivideNode(dynamic_cast<BspLeaf *>(data.mNode), 
     113                                                                                  data.mParent, 
     114                                                                                  &data.mViewCell, 
     115                                                                              data.mDepth, 
     116                                                                                  backPolys, 
     117                                                                                  frontPolys); 
    91118         
    92                 if (!node->IsLeaf()) 
    93                 { 
    94                         BspInterior *interior = dynamic_cast<BspInterior *>(node); 
     119                        if (!node->IsLeaf()) // node was subdivided 
     120                        { 
     121                                BspInterior *interior = dynamic_cast<BspInterior *>(node); 
    95122 
    96                         // push the children on the stack 
    97                         if (interior->GetBack()) 
    98                                 tStack.push(BspTraversalData(interior->GetBack(), interior, backPolys, data.mDepth+1)); 
    99                         if (interior->GetFront()) 
    100                                 tStack.push(BspTraversalData(interior->GetFront(), interior, frontPolys, data.mDepth+1)); 
     123                                // push the children on the stack (there are always two children) 
     124                                tStack.push(BspTraversalData(interior->GetBack(), interior, backPolys, data.mDepth + 1)); 
     125                                tStack.push(BspTraversalData(interior->GetFront(), interior, frontPolys, data.mDepth + 1)); 
     126                        } 
    101127                } 
    102128        } 
    103129} 
    104130 
    105 Plane3 *BspTree::SelectPlane(Mesh *viewcell) 
     131Plane3 BspTree::SelectPlane(Mesh *polys) 
    106132{ 
    107         return &viewcell->GetFacePlane(0); 
     133        // TODO: more sophisticated criteria 
     134        return polys->GetFacePlane(0); 
    108135} 
    109136 
     
    112139                                                                Mesh &frontPolys, Mesh &backPolys) 
    113140{ 
    114 static int sMaxDepth = 5; // HACK 
    115         // terminate traversal if no more faces in mesh 
    116         if ((viewCell->mFaces.size() == 0) && depth > sMaxDepth) 
     141        ViewCell *viewCell = leaf->GetViewCell(); 
     142 
     143        // terminate traversal if no more faces in mesh or outside 
     144        if (!viewCell || (viewCell->mFaces.size() == 0)) 
     145        { 
    117146                return leaf; 
    118   
     147        } 
    119148        // add the new nodes to the tree + select subdivision plane 
    120         Plane3 *plane = SelectPlane(viewCell); 
    121         BspInterior *node = new BspInterior(*plane); // ERROR!! 
    122    
     149        BspInterior *node = new BspInterior(SelectPlane(viewCell));  
    123150 
    124151        FaceContainer::const_iterator fi; 
    125152 
    126         for ( fi = viewCell->mFaces.begin(); fi != viewCell->mFaces.end(); ++ fi) 
     153        for (fi = viewCell->mFaces.begin(); fi != viewCell->mFaces.end(); ++ fi) 
    127154        { 
     155                int  result = node->GetPlane()->Side(); 
     156                Mesh *front_piece, *back_piece; 
     157 
     158                switch (result) 
     159                { 
     160                        case 1: 
     161                                frontPolys.AddFace(poly); 
     162                                break; 
     163                        case -1: 
     164                                backPolys.AddFace(poly); 
     165                                break; 
     166                        case 0: 
     167                                //Split_Polygon (poly, tree->partition, front_piece, back_piece); 
     168                                backPolys.AddFace(back_piece); 
     169                                frontPolys.AddFace(front_piece); 
     170                                break; 
     171                        default; 
     172                                brak; 
     173                } 
    128174        } 
    129    
    130         BspLeaf *back = new BspLeaf(mRootCell); 
    131         BspLeaf *front = new BspLeaf(mRootCell); 
     175        // backside of convex view cell polygon => outside 
     176        BspLeaf *back = new BspLeaf(NULL); 
     177        BspLeaf *front = new BspLeaf(viewCell); 
    132178 
    133179        // replace a link from node's parent 
  • trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.h

    r221 r222  
    4545          BspNode *GetFront() {return mFront;} 
    4646 
     47          Plane3 *GetPlane(); 
     48 
    4749          void ReplaceChildLink(BspNode *oldChild, BspNode *newChild); 
    4850          void SetupChildLinks(BspNode *b, BspNode *f); 
     
    6769          /** @return true since it is an interior node */ 
    6870          bool IsLeaf() const; 
     71          ViewCell *GetViewCell(); 
    6972 
    7073  protected: 
     
    97100         
    98101  protected: 
     102          /** Selects a splitting plane from the given polygons. */ 
     103          Plane3 SelectPlane(Mesh *polys); 
    99104 
    100           Plane3 *SelectPlane(Mesh *viewcell); 
    101105          void Subdivide(); 
    102106            
Note: See TracChangeset for help on using the changeset viewer.