- Timestamp:
- 08/08/05 18:03:08 (19 years ago)
- Location:
- trunk/VUT/GtpVisibilityPreprocessor/src
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.cpp
r221 r222 19 19 /****************************************************************/ 20 20 21 22 BspInterior::BspInterior(Plane3 plane): mPlane(plane) 23 {} 24 21 25 bool BspInterior::IsLeaf() const 22 26 { 23 27 return false; 28 } 29 30 BspNode *BspInterior::GetBack() 31 { 32 return mBack; 33 } 34 35 BspNode *BspInterior::GetFront() 36 { 37 return mFront; 38 } 39 40 Plane3 *BspInterior::GetPlane() 41 { 42 return &mPlane; 24 43 } 25 44 … … 42 61 } 43 62 63 44 64 /****************************************************************/ 45 65 /* class BspLeaf implementation */ … … 48 68 BspLeaf::BspLeaf(ViewCell *viewCell): mViewCell(viewCell) 49 69 { 70 } 71 72 ViewCell *BspLeaf::GetViewCell() 73 { 74 return mViewCell; 50 75 } 51 76 … … 83 108 Mesh frontPolys; 84 109 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); 91 118 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); 95 122 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 } 101 127 } 102 128 } 103 129 } 104 130 105 Plane3 *BspTree::SelectPlane(Mesh *viewcell)131 Plane3 BspTree::SelectPlane(Mesh *polys) 106 132 { 107 return &viewcell->GetFacePlane(0); 133 // TODO: more sophisticated criteria 134 return polys->GetFacePlane(0); 108 135 } 109 136 … … 112 139 Mesh &frontPolys, Mesh &backPolys) 113 140 { 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 { 117 146 return leaf; 118 147 } 119 148 // 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)); 123 150 124 151 FaceContainer::const_iterator fi; 125 152 126 for ( 153 for (fi = viewCell->mFaces.begin(); fi != viewCell->mFaces.end(); ++ fi) 127 154 { 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 } 128 174 } 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); 132 178 133 179 // replace a link from node's parent -
trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.h
r221 r222 45 45 BspNode *GetFront() {return mFront;} 46 46 47 Plane3 *GetPlane(); 48 47 49 void ReplaceChildLink(BspNode *oldChild, BspNode *newChild); 48 50 void SetupChildLinks(BspNode *b, BspNode *f); … … 67 69 /** @return true since it is an interior node */ 68 70 bool IsLeaf() const; 71 ViewCell *GetViewCell(); 69 72 70 73 protected: … … 97 100 98 101 protected: 102 /** Selects a splitting plane from the given polygons. */ 103 Plane3 SelectPlane(Mesh *polys); 99 104 100 Plane3 *SelectPlane(Mesh *viewcell);101 105 void Subdivide(); 102 106
Note: See TracChangeset
for help on using the changeset viewer.