- Timestamp:
- 08/09/05 18:39:28 (19 years ago)
- Location:
- trunk/VUT/GtpVisibilityPreprocessor/src
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/VUT/GtpVisibilityPreprocessor/src/Intersectable.h
r176 r224 13 13 KdPvs mKdPvs; 14 14 15 enum { MESH_INSTANCE, TRANSFORMED_MESH_INSTANCE, SPHERE };15 enum { MESH_INSTANCE, TRANSFORMED_MESH_INSTANCE, SPHERE, VIEWCELL }; 16 16 17 17 Intersectable():mailbox(0) {} -
trunk/VUT/GtpVisibilityPreprocessor/src/ViewCell.h
r221 r224 1 1 #ifndef _ViewCell_H__ 2 2 #define _ViewCell_H__ 3 4 #include "Intersectable.h" 3 5 4 6 class Mesh; … … 11 13 View cell represented as a mesh 12 14 */ 13 class ViewCell 15 class ViewCell: public Intersectable 14 16 { 15 17 public: … … 28 30 BspPvs *GetPVS() {return mPvs;} 29 31 32 AxisAlignedBox3 GetBox() {return mMesh->mBox;} 33 34 int CastRay(Ray &ray) {return 0;} 35 36 bool IsConvex() {return mMesh->mIsConvex;} 37 bool IsWatertight() {return mMesh->mIsWatertight;} 38 float IntersectionComplexity() {return mMesh->mFaces.size();} 39 40 int Type() const { return VIEWCELL; } 41 42 void GetRandomSurfacePoint(Vector3 &point, Vector3 &normal) {point = Vector3(0,0,0);}; 43 30 44 protected: 31 45 -
trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.cpp
r222 r224 6 6 #include <stack> 7 7 8 #define DEL_PTR(ptr) while (0) {if (ptr) {delete (ptr); (ptr) = NULL;}} 9 8 10 //namespace GtpVisibilityPreprocessor { 9 11 /****************************************************************/ … … 15 17 } 16 18 19 BspInterior *BspNode::GetParent() 20 { 21 return mParent; 22 } 17 23 /****************************************************************/ 18 24 /* class BspInterior implementation */ … … 61 67 } 62 68 63 64 69 /****************************************************************/ 65 70 /* class BspLeaf implementation */ … … 84 89 /****************************************************************/ 85 90 86 BspTree::BspTree(ViewCell *cell) 87 { 88 mRootCell = cell; 89 mRoot = new BspLeaf(mRootCell); 90 } 91 92 93 void BspTree::Subdivide() 91 BspTree::BspTree(const ViewCellContainer &viewCells): 92 mMaxPolys(0), mMaxDepth(0), mRoot(NULL) 93 { 94 //mRootCell = cell; 95 Subdivide(viewCells); 96 } 97 98 BspTree::BspTree(const ObjectContainer &objects, int maxPolys, int maxDepth): 99 mMaxPolys(maxPolys), mMaxDepth(maxDepth) 100 { 101 mRoot = new BspLeaf(); 102 103 Subdivide(objects); 104 } 105 106 BspTree::~BspTree() 107 { 108 std::stack<BspNode *> tStack; 109 110 tStack.push(mRoot); 111 112 while (!tStack.empty()) 113 { 114 BspNode *node = tStack.top(); 115 116 tStack.pop(); 117 118 if (!node->IsLeaf()) 119 { 120 BspInterior *interior = dynamic_cast<BspInterior *>(node); 121 122 // push the children on the stack (there are always two children) 123 interior->GetBack()->mParent = NULL; 124 interior->GetFront()->mParent = NULL; 125 126 tStack.push(interior->GetBack()); 127 tStack.push(interior->GetFront()); 128 } 129 130 delete node; 131 node = NULL; 132 } 133 } 134 135 136 void BspTree::InsertViewCell(ViewCell *viewCell) 94 137 { 95 138 BspNode *currentNode = mRoot; … … 103 146 { 104 147 BspTraversalData data = tStack.top(); 148 105 149 tStack.pop(); 106 150 … … 112 156 BspNode *node = SubdivideNode(dynamic_cast<BspLeaf *>(data.mNode), 113 157 data.mParent, 114 &data.mViewCell,158 data.mPolys, 115 159 data.mDepth, 116 160 backPolys, … … 122 166 123 167 // 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));168 //tStack.push(BspTraversalData(interior->GetBack(), interior, backPolys, data.mDepth + 1)); 169 //tStack.push(BspTraversalData(interior->GetFront(), interior, frontPolys, data.mDepth + 1)); 126 170 } 127 171 } … … 129 173 } 130 174 131 Plane3 BspTree::SelectPlane(Mesh *polys) 175 void BspTree::Subdivide(const ViewCellContainer &viewCells) 176 { 177 } 178 179 void BspTree::Copy2PolygonSoup(const ObjectContainer &objects, Mesh &mesh) 180 { 181 ObjectContainer::const_iterator it, it_end = objects.end(); 182 183 for (it = objects.begin(); it != it_end; ++ it) 184 { 185 FaceContainer::const_iterator fi; 186 Intersectable *object = *it; 187 188 // extract the mesh instances 189 if (object->Type() == Intersectable::MESH_INSTANCE) 190 { 191 MeshInstance *inst = dynamic_cast<MeshInstance *>(object); 192 193 Mesh *polys = inst->GetMesh(); 194 195 // copy the face data 196 for (fi = polys->mFaces.begin(); fi != polys->mFaces.end(); ++ fi) 197 { 198 Face *face = new Face((*fi)->mVertexIndices); 199 mesh.AddFace(face); 200 } 201 } 202 } 203 } 204 205 void BspTree::Subdivide(const ObjectContainer &objects) 206 { 207 std::stack<BspTraversalData> tStack; 208 Mesh polys; 209 210 // copy mesh instance polygons into one big polygon soup 211 Copy2PolygonSoup(objects, polys); 212 213 BspTraversalData tdata(mRoot, mRoot->GetParent(), &polys, 0); 214 tStack.push(tdata); 215 216 while (!tStack.empty()) 217 { 218 BspTraversalData data = tStack.top(); 219 220 tStack.pop(); 221 222 Mesh backPolys; 223 Mesh frontPolys; 224 225 BspNode *node = SubdivideNode(dynamic_cast<BspLeaf *>(data.mNode), 226 data.mParent, 227 data.mPolys, 228 data.mDepth, 229 backPolys, 230 frontPolys); 231 232 if (!node->IsLeaf()) // node was subdivided 233 { 234 BspInterior *interior = dynamic_cast<BspInterior *>(node); 235 236 // push the children on the stack (there are always two children) 237 tStack.push(BspTraversalData(interior->GetBack(), interior, &backPolys, data.mDepth + 1)); 238 tStack.push(BspTraversalData(interior->GetFront(), interior, &frontPolys, data.mDepth + 1)); 239 } 240 } 241 } 242 243 Plane3 BspTree::SelectPlane(Mesh *polys) 132 244 { 133 245 // TODO: more sophisticated criteria … … 136 248 137 249 BspNode *BspTree::SubdivideNode(BspLeaf *leaf, BspInterior *parent, 138 Mesh * viewCell, const int depth,250 Mesh *polys, const int depth, 139 251 Mesh &frontPolys, Mesh &backPolys) 140 252 { 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 { 253 // terminate traversal if no more faces in mesh 254 if ((polys->mFaces.size() <= mMaxPolys) || (depth >= mMaxDepth)) 255 { 256 // don't need to store polygon information 257 polys->mFaces->clear(); // HACK: faces were deleted before 258 DEL_PTR(polys); // we can savely delete mesh 259 146 260 return leaf; 147 261 } 262 148 263 // add the new nodes to the tree + select subdivision plane 149 BspInterior *node = new BspInterior(SelectPlane( viewCell));264 BspInterior *node = new BspInterior(SelectPlane(polys)); 150 265 151 266 FaceContainer::const_iterator fi; 152 267 153 for (fi = viewCell->mFaces.begin(); fi != viewCell->mFaces.end(); ++ fi) 154 { 155 int result = node->GetPlane()->Side(); 156 Mesh *front_piece, *back_piece; 268 for (fi = polys->mFaces.begin(); fi != polys->mFaces.end(); ++ fi) 269 { 270 Face *face = (*fi); 271 272 int result = 0;// = node->GetPlane()->Side(node->GetPlane()); 273 274 Face *front_piece, *back_piece; 157 275 158 276 switch (result) 159 277 { 160 278 case 1: 161 frontPolys.AddFace( poly);279 frontPolys.AddFace(face); 162 280 break; 163 281 case -1: 164 backPolys.AddFace( poly);282 backPolys.AddFace(face); 165 283 break; 166 284 case 0: 167 //Split_Polygon ( poly, tree->partition, front_piece, back_piece);285 //Split_Polygon (face, tree->partition, front_piece, back_piece); 168 286 backPolys.AddFace(back_piece); 169 287 frontPolys.AddFace(front_piece); 288 289 // face not needed anymore 290 DEL_PTR(face); 291 170 292 break; 171 default; 172 brak; 173 } 174 } 293 default: 294 break; 295 } 296 } 297 175 298 // backside of convex view cell polygon => outside 176 BspLeaf *back = new BspLeaf( NULL);177 BspLeaf *front = new BspLeaf( viewCell);299 BspLeaf *back = new BspLeaf(); 300 BspLeaf *front = new BspLeaf(); 178 301 179 302 // replace a link from node's parent … … 185 308 // and setup child links 186 309 node->SetupChildLinks(back, front); 187 188 delete leaf; 310 311 // don't need to store polygon information 312 polys->mFaces->clear(); // HACK: faces were deleted before 313 DEL_PTR(polys); // we can savely delete mesh 314 315 DEL_PTR(leaf); 316 189 317 return node; 190 318 } -
trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.h
r222 r224 3 3 4 4 #include "Mesh.h" 5 #include "Containers.h" 6 7 5 8 class ViewCell; 6 9 class Plane3; … … 8 11 9 12 //namespace GtpVisibilityPreprocessor { 10 13 class BspTree; 11 14 class BspInterior; 12 15 … … 17 20 class BspNode 18 21 { 22 friend BspTree; 23 19 24 public: 20 25 /** Determines whether this node is a leaf or not … … 28 33 virtual bool IsRoot() const; 29 34 35 /** Returns parent node. 36 */ 37 BspInterior *GetParent(); 38 30 39 protected: 31 40 … … 34 43 }; 35 44 36 /** BSP interior node implementation */ 45 /** BSP interior node implementation 46 */ 37 47 class BspInterior : public BspNode 38 { 48 { 39 49 public: 40 BspInterior(Plane3 plane): mPlane(plane) {} 41 /** @return false since it is an interior node */ 50 /** Standard contructor taking split plane as argument. 51 */ 52 BspInterior(Plane3 plane); 53 /** @return false since it is an interior node 54 */ 42 55 bool IsLeaf() const; 43 56 44 BspNode *GetBack() {return mBack;}45 BspNode *GetFront() {return mFront;}57 BspNode *GetBack(); 58 BspNode *GetFront(); 46 59 47 60 Plane3 *GetPlane(); … … 78 91 }; 79 92 80 /** Implementation of the ViewCell BSP tree */93 /** Implementation of the ViewCell BSP tree. */ 81 94 class BspTree 82 95 { … … 84 97 struct BspTraversalData 85 98 { 99 /// the current node 86 100 BspNode *mNode; 101 /// parent of current node 87 102 BspInterior *mParent; 88 89 Mesh mViewCell; 103 /// polygonal data for splitting 104 Mesh *mPolys; 105 /// current depth 90 106 int mDepth; 91 107 92 108 BspTraversalData() {} 93 BspTraversalData(BspNode *n, BspInterior *p, const Mesh &m, const int d): 94 mNode(n), mParent(p), mViewCell(m), mDepth(d) {} 109 110 BspTraversalData(BspNode *node, BspInterior *parent, Mesh *polys, const int depth): 111 mNode(node), mParent(parent), mPolys(polys), mDepth(depth) {} 95 112 }; 96 113 97 /** Constructor takes a pointer to the cell corresponding to the whole 98 viewspace */ 99 BspTree(ViewCell *cell); 100 114 /** Constructs BSP tree from list of view cells. 115 */ 116 BspTree(const ViewCellContainer &viewCells); 117 /** Constructs BSP tree from list of objects. 118 @param object list of intersectables 119 @param maxPolys maximal allowed number of polygons 120 @param maxDepth maximal allowed BSP tree depth 121 */ 122 BspTree(const ObjectContainer &objects, int maxPolys, int maxDepth); 123 124 ~BspTree(); 125 101 126 protected: 102 /** Selects a splitting plane from the given polygons. */ 127 /** Selects a splitting plane from the given polygons. 128 */ 103 129 Plane3 SelectPlane(Mesh *polys); 104 130 105 void Subdivide(); 131 /** Filters next viewcell down the tree and inserts it into the appropriate leaves 132 (i.e., possibly more than one leaf). 133 */ 134 void InsertViewCell(ViewCell *viewCell); 135 136 /** Subdivides tree according to the given list of viewcells. 137 */ 138 void Subdivide(const ViewCellContainer &viewCells); 139 /** Subdivides tree according to the given list of objects. 140 */ 141 void Subdivide(const ObjectContainer &objects); 106 142 143 /** Subdivides leaf. 144 @param leaf the leaf to be subdivided 145 @param parent the parent node of this leaf 146 @param polys the input polygons 147 @param depth the current tree depth 148 @param frontPolys the polygons of the front child node as a result from splitting 149 @param backPolys the polygons of the back child node as a result from splitting 150 */ 107 151 BspNode *SubdivideNode(BspLeaf *leaf, BspInterior *parent, 108 Mesh * viewCell, const int depth,152 Mesh *polys, const int depth, 109 153 Mesh &frontPolys, Mesh &backPolys); 154 155 /** Extracts the mesh instances of the objects and copies them into the mesh. 156 */ 157 static void Copy2PolygonSoup(const ObjectContainer &objects, Mesh &mesh); 158 110 159 111 160 /// Pointer to the root of the tree 112 161 BspNode *mRoot; 113 162 /// Pointer to the root cell of the viewspace 114 ViewCell *mRootCell; 163 // ViewCell *mRootCell; 164 /// maximal number of polygons allowed in leaf 165 int mMaxPolys; 166 /// maximal depth 167 int mMaxDepth; 115 168 }; 116 169
Note: See TracChangeset
for help on using the changeset viewer.