- Timestamp:
- 09/19/05 03:07:07 (19 years ago)
- Location:
- trunk/VUT/GtpVisibilityPreprocessor
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/VUT/GtpVisibilityPreprocessor/scripts/default.env
r286 r289 14 14 # filename ../data/soda/soda5.dat 15 15 # viewcells ../data/atlanta/atlanta_viewcells_large.x3d 16 # viewcells ../data/atlanta/atlanta_viewcells_large2.x3d17 viewcells ../data/vienna/viewcells-25-sel.x3d18 #viewcells ../data/vienna/viewcells-25.x3d16 # viewcells ../data/atlanta/atlanta_viewcells_large2.x3d 17 # viewcells ../data/vienna/viewcells-25-sel.x3d 18 viewcells ../data/vienna/viewcells-25.x3d 19 19 # viewcells ../data/vienna/viewcells-large-sel.x3d 20 20 } … … 70 70 splitPlaneStrategy combined 71 71 # constructionMethod rays 72 #constructionMethod viewCells73 constructionMethod sceneGeometry72 constructionMethod viewCells 73 # constructionMethod sceneGeometry 74 74 maxCandidates 25 75 75 maxViewCells 999999 76 76 Termination { 77 maxPolygons 378 maxDepth 3077 maxPolygons 0 78 maxDepth 100 79 79 } 80 80 } -
trunk/VUT/GtpVisibilityPreprocessor/src/Plane3.h
r270 r289 44 44 { 45 45 const Vector3 v = b - a; // line from A to B 46 float dv = DotProd( mNormal, v);46 float dv = DotProd(v, mNormal); 47 47 48 48 if (signum(dv) == 0) … … 50 50 if (coplanar) 51 51 (*coplanar) = true; 52 Debug << "signum is zero" << endl;52 53 53 return a; 54 54 } … … 63 63 64 64 //return a - Distance(a) * b / dv + Distance(a) * a / dv; // NOTE: gives better precision than calclulating a + u * v 65 return a + (u * v);65 return a + u * v; 66 66 } 67 67 -
trunk/VUT/GtpVisibilityPreprocessor/src/Polygon3.cpp
r286 r289 6 6 // tolerance value for side relation 7 7 #define SIDE_TOLERANCE 0.002f // TODO: Test different values 8 #define SIDE_TOLERANCE_SQRD 0.000004f 8 9 9 10 Polygon3::Polygon3(): mMaterial(NULL), mParent(NULL) … … 38 39 } 39 40 40 void Polygon3::Split(Plane3 *partition, Polygon3 *front, Polygon3 *back, int &splits) 41 { 42 splits = 0; 43 Vector3 ptA = mVertices[mVertices.size() - 1]; 41 void Polygon3::Split(Plane3 *partition, Polygon3 *front, Polygon3 *back) 42 { 43 Vector3 ptA = mVertices.back(); 44 44 45 45 int sideA = partition->Side(ptA, SIDE_TOLERANCE); 46 46 47 47 VertexContainer::const_iterator it; 48 bool foundSplit = false; 49 50 Vector3 prevSplitPt(ptA); 48 51 49 52 // find line - plane intersections 50 53 for (it = mVertices.begin(); it != mVertices.end(); ++ it) 51 54 { 52 Vector3 ptB = (*it);55 Vector3 ptB = *it; 53 56 int sideB = partition->Side(ptB, SIDE_TOLERANCE); 54 57 … … 60 63 //-- plane - line intersection 61 64 Vector3 splitPt = partition->FindIntersection(ptA, ptB); 62 63 // add vertex to both polygons 64 front->mVertices.push_back(splitPt); 65 back->mVertices.push_back(splitPt); 66 67 ++ splits; 65 Debug << "front split pt " << splitPt << " ptA " << ptA << " ptB " << ptB << " side " << sideB << endl; 66 if (!foundSplit || (SqrDistance(splitPt, prevSplitPt) > SIDE_TOLERANCE_SQRD)) 67 { 68 // add vertex to both polygons 69 front->mVertices.push_back(splitPt); 70 back->mVertices.push_back(splitPt); 71 72 foundSplit = true; 73 prevSplitPt = splitPt; 74 } 68 75 } 69 76 front->mVertices.push_back(ptB); … … 75 82 //-- plane - line intersection 76 83 Vector3 splitPt = partition->FindIntersection(ptA, ptB); 77 78 // add vertex to both polygons 79 front->mVertices.push_back(splitPt); 80 back->mVertices.push_back(splitPt); 81 82 ++ splits; 84 // if (foundSplit) Debug << "back split pt " << splitPt << " prev " << prevSplitPt << endl; 85 if (!foundSplit || (SqrDistance(splitPt, prevSplitPt) > SIDE_TOLERANCE_SQRD)) 86 { 87 //Debug << "add back split vertex " << splitPt << endl; 88 // add vertex to both polygons 89 front->mVertices.push_back(splitPt); 90 back->mVertices.push_back(splitPt); 91 92 foundSplit = true; 93 prevSplitPt = splitPt; 94 }//else Debug << "reject back split vertex " << splitPt << endl; 83 95 } 84 96 back->mVertices.push_back(ptB); … … 120 132 { 121 133 int side = plane.Side(*it, SIDE_TOLERANCE); 122 if (BspTree::displayDebug)Debug << "side: " << side << " " << plane.Distance(*it) << endl;134 //Debug << "side: " << side << " " << plane.Distance(*it) << endl; 123 135 124 136 if (side > 0) … … 134 146 // 3 vertices enough to decide coincident 135 147 else if (((++ count) >= 3) && !onFrontSide && !onBackSide) 136 return COINCIDENT; 148 { 149 // Decide if plane and surface normal are same 150 if (DotProd(plane.mNormal, GetSupportingPlane().mNormal) > 0) 151 return COINCIDENT; 152 else 153 return FRONT_SIDE; 154 } 137 155 } 138 156 … … 159 177 sum += mVertices[i]; 160 178 161 return sum/ i;179 return sum/(float)i; 162 180 } 163 181 … … 172 190 } 173 191 } 192 193 bool Polygon3::CheckValid() const 194 { 195 if (mVertices.size() < 3) 196 return false; 197 198 Vector3 vtx = mVertices.back(); 199 VertexContainer::const_iterator it, it_end = mVertices.end(); 200 201 for (it = mVertices.begin(); it != it_end; ++it) 202 { 203 if (!(SqrDistance(vtx, *it) > SIDE_TOLERANCE_SQRD)) 204 { 205 Debug << "Malformed vertices:\n" << *this << endl; 206 return false; 207 } 208 vtx = *it; 209 } 210 211 return true; 212 } -
trunk/VUT/GtpVisibilityPreprocessor/src/Polygon3.h
r286 r289 15 15 class Intersectable; 16 16 17 /** Class representing a general planar polygon in 3d. 17 //typedef Vertex3 Vector3; 18 19 /** Class representing a planar convex polygon in 3d. 18 20 */ 19 21 class Polygon3 … … 36 38 @param front the front polygon 37 39 @param back the back polygon 38 @param splits number of splits39 40 */ 40 void Split(Plane3 *partition, Polygon3 *front, Polygon3 *back , int &splits);41 void Split(Plane3 *partition, Polygon3 *front, Polygon3 *back); 41 42 42 43 enum {BACK_SIDE, FRONT_SIDE, SPLIT, COINCIDENT}; … … 59 60 */ 60 61 Vector3 Center() const; 62 /** Checks if the polygon is valid, i.e., not degenerated. 63 @returns true if polygon is valid. 64 */ 65 bool CheckValid() const; 61 66 62 63 67 /// vertices are connected in counterclockwise order. 64 68 VertexContainer mVertices; … … 77 81 VertexContainer::const_iterator it; 78 82 79 s << setprecision(6) << "Polygon:\n"; 80 83 //s << setprecision(6) << "Polygon:\n"; 81 84 for (it = A.mVertices.begin(); it != A.mVertices.end(); ++it) 82 85 s << *it << endl; -
trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.cpp
r286 r289 33 33 const int FACTOR_LEAST_SPLITS = 1; 34 34 35 int counter = 0;36 bool BspTree::displayDebug = false;35 //int counter = 0; 36 //bool BspTree::displayDebug = false; 37 37 /****************************************************************/ 38 38 /* class BspNode implementation */ … … 88 88 } 89 89 else CLEAR_CONTAINER(*polys); 90 91 delete polys;92 90 } 93 91 … … 136 134 } 137 135 138 void BspInterior::ProcessPolygon(Polygon3 * poly, const bool storePolys)136 void BspInterior::ProcessPolygon(Polygon3 **poly, const bool storePolys) 139 137 { 140 138 if (storePolys) 141 GetPolygons()->push_back( poly);139 GetPolygons()->push_back(*poly); 142 140 else 143 delete poly; 144 } 145 146 Polygon3 *BspInterior::SplitPolygons(PolygonContainer *polys, 147 PolygonContainer *frontPolys, 148 PolygonContainer *backPolys, 149 int &splits, bool storePolys) 141 DEL_PTR(*poly); 142 } 143 144 void BspInterior::SplitPolygons(PolygonContainer *polys, 145 PolygonContainer *frontPolys, 146 PolygonContainer *backPolys, 147 PolygonContainer *coincident, 148 int &splits, 149 bool storePolys) 150 150 { 151 151 Polygon3 *splitPoly = NULL; 152 152 #ifdef _Debug 153 if (BspTree::displayDebug)Debug << "Splitting polygons of node " << this << " with plane " << mPlane << endl;153 Debug << "Splitting polygons of node " << this << " with plane " << mPlane << endl; 154 154 #endif 155 155 while (!polys->empty()) … … 158 158 polys->pop_back(); 159 159 160 // if (BspTree::displayDebug)Debug << "New polygon with plane: " << poly->GetSupportingPlane() << "\n";160 //Debug << "New polygon with plane: " << poly->GetSupportingPlane() << "\n"; 161 161 162 162 // test if split is neccessary … … 170 170 case Polygon3::COINCIDENT: 171 171 //Debug << "coincident" << endl; 172 // same surface normal 173 if (DotProd(mPlane.mNormal, poly->GetSupportingPlane().mNormal) > 0) 174 { 175 if (!splitPoly) // store the split polygon if there is none 176 splitPoly = poly; 177 else // discard it otherwise 178 ProcessPolygon(poly, storePolys); 179 180 break; 181 } 182 172 coincident->push_back(poly); 173 break; 183 174 case Polygon3::FRONT_SIDE: 184 175 //Debug << "front" << endl; … … 192 183 front_piece = new Polygon3(poly->mParent); 193 184 back_piece = new Polygon3(poly->mParent); 194 185 Debug << "*************\n"; 186 Debug << "initial poly\n" << *poly << endl; 195 187 //-- split polygon 196 poly->Split(&mPlane, front_piece, back_piece, splits); 197 198 frontPolys->push_back(front_piece); 199 backPolys->push_back(back_piece); 200 188 poly->Split(&mPlane, front_piece, back_piece); 189 ++ splits; 190 191 //Debug << "poly\n" << *poly << "split front piece not valid\n" << *front_piece << endl; 192 //Debug << "poly\n" << *poly << "split back piece not valid\n" << *back_piece << endl; 193 194 if (front_piece->CheckValid()) 195 frontPolys->push_back(front_piece); 196 else 197 DEL_PTR(front_piece); 198 199 //if (back_piece->CheckValid()) 200 backPolys->push_back(back_piece); 201 //else 202 // DEL_PTR(back_piece); 203 Debug << "*************\n"; 201 204 #ifdef _DEBUG 202 205 Debug << "split " << *poly << endl << *front_piece << endl << *back_piece << endl; 203 206 #endif 204 ProcessPolygon( poly, storePolys);207 ProcessPolygon(&poly, storePolys); 205 208 206 209 break; … … 210 213 } 211 214 } 212 //if (BspTree::displayDebug) Debug << "inside: " << inside << endl; 213 214 delete polys; // contains nothing 215 return splitPoly; 215 //Debug << "inside: " << inside << endl; 216 216 } 217 217 … … 357 357 } 358 358 359 360 /*void BspTree::InsertViewCell(ViewCell *viewCell) 361 { 362 std::stack<BspTraversalData> tStack; 363 359 void BspTree::InsertViewCell(ViewCell *viewCell) 360 { 364 361 PolygonContainer *polys = new PolygonContainer(); 365 362 … … 368 365 mBox.Include(viewCell->GetBox()); // add to BSP aabb 369 366 370 // traverse tree or create new one 367 InsertPolygons(polys); 368 } 369 370 void BspTree::InsertPolygons(PolygonContainer *polys, ViewCellContainer *viewCells) 371 { 372 std::stack<BspTraversalData> tStack; 373 374 // traverse tree or create new one 371 375 BspNode *firstNode = mRoot ? mRoot : new BspLeaf(); 372 376 373 tStack.push(BspTraversalData(firstNode, polys, 0, true));377 tStack.push(BspTraversalData(firstNode, polys, 0, NULL)); 374 378 375 379 while (!tStack.empty()) … … 388 392 PolygonContainer *frontPolys = new PolygonContainer(); 389 393 PolygonContainer *backPolys = new PolygonContainer(); 390 Polygon 3 *coincident = NULL;394 PolygonContainer coincident; 391 395 392 396 int splits = 0; 393 397 394 398 // split viecell polygons with respect to split plane 395 bool inside =interior->SplitPolygons(tData.mPolygons,396 397 398 399 400 399 interior->SplitPolygons(tData.mPolygons, 400 frontPolys, 401 backPolys, 402 &coincident, 403 splits, 404 mStorePolys); 401 405 406 // get view cell associated with the split polygon 407 ViewCell *viewCell = (coincident.size() > 0) ? 408 dynamic_cast<ViewCell *>(coincident.front()->mParent) : NULL; 409 interior->ProcessPolygons(&coincident, mStorePolys); 410 402 411 //Debug << "split node on level " << tData.mDepth << " bk: " << backPolys->size() << " frnt: " << frontPolys->size() << endl; 403 412 mStat.splits += splits; … … 405 414 // push the children on the stack 406 415 tStack.push(BspTraversalData(interior->GetFront(), frontPolys, tData.mDepth + 1, NULL)); 407 tStack.push(BspTraversalData(interior->GetBack(), backPolys, tData.mDepth + 1, coincident)); 408 416 tStack.push(BspTraversalData(interior->GetBack(), backPolys, tData.mDepth + 1, viewCell)); 409 417 } 410 else // stop traversal 411 { 412 DEL_PTR(tData.mPolygons); 413 } 418 419 // cleanup 420 DEL_PTR(tData.mPolygons); 414 421 } 415 422 else // reached leaf => subdivide current viewcell 416 423 { 417 424 if (tData.mPolygons->size() > 0) 418 Debug << " WARNING (should not come here): polygon size: " << (int)tData.mPolygons->size() << " inside: " << tData.mIsInside<< endl;419 420 BspNode *root = Subdivide(tStack, tData, viewCell );425 Debug << "Subdividing further: polygon size: " << (int)tData.mPolygons->size() << ", view cell: " << tData.mViewCell << endl; 426 427 BspNode *root = Subdivide(tStack, tData, viewCells); 421 428 422 429 if (!mRoot) // tree empty => new root … … 424 431 } 425 432 } 426 } */433 } 427 434 428 435 void BspTree::InitTree(int maxPolygons, int maxDepth) … … 448 455 poly->mParent = parent; // set parent intersectable 449 456 polys.push_back(poly); 450 //if (displayDebug)Debug << *poly << endl; 457 458 if (!poly->CheckValid()) 459 Debug << "Input polygon not valid: " << *poly << endl; 460 451 461 ++ polysNum; 452 462 } … … 504 514 void BspTree::Construct(const ViewCellContainer &viewCells) 505 515 { 506 //-- Construct tree using the given viewcells507 508 /* for this type of construction we filter all viewcells down the509 * tree. If there is no polygon left, the last split plane510 * decides inside or outside of the viewcell.511 */512 516 InitTree(sTermMaxPolygons, sTermMaxDepth); 513 517 … … 592 596 } 593 597 //-- add viewcell stored in split polygon 594 else if (tData.m SplitPoly && tData.mSplitPoly->mParent)598 else if (tData.mViewCell) 595 599 { 596 600 if (leaf->GetViewCell()) 597 601 Debug << "ERROR: leaf already has view cell " << endl;//leaf->mViewCellIdx << endl; 598 602 599 //leaf->mViewCellIdx = counter;Debug << "insert view cell" << endl; 600 601 leaf->SetViewCell(dynamic_cast<ViewCell *>(tData.mSplitPoly->mParent)); 602 603 // discard split polygon 604 tData.mNode->GetParent()->ProcessPolygon(tData.mSplitPoly, mStorePolys); 605 } 606 607 // add or delete remaining polygons 603 //leaf->mViewCellIdx = counter; 604 Debug << "insert view cell" << endl; 605 606 leaf->SetViewCell(dynamic_cast<ViewCell *>(tData.mViewCell)); 607 } 608 609 // remaining polygons are discarded or added to node 608 610 tData.mNode->ProcessPolygons(tData.mPolygons, mStorePolys); 609 611 DEL_PTR(tData.mPolygons); 612 610 613 return tData.mNode; 611 614 } 612 615 613 // discard the split polygon (not needed if traversal continues) 614 if (tData.mSplitPoly) 615 tData.mNode->GetParent()->ProcessPolygon(tData.mSplitPoly, mStorePolys); 616 617 //-- create new subdivided node 616 //-- continue subdivision 618 617 PolygonContainer *backPolys = new PolygonContainer(); 619 618 PolygonContainer *frontPolys = new PolygonContainer(); 620 Polygon3 *splitPoly = NULL; 621 619 PolygonContainer coincident; 620 621 // create new interior node and two leaf nodes 622 622 BspInterior *interior = SubdivideNode(dynamic_cast<BspLeaf *>(tData.mNode), 623 623 tData.mPolygons, 624 624 frontPolys, 625 625 backPolys, 626 &splitPoly); 626 &coincident); 627 628 if (coincident.size() == 0) 629 { 630 Debug << "size is zero at depth " << tData.mDepth << ", #back polys: " << (int)backPolys->size() << ", #front polys: " << (int)frontPolys->size() << endl; 631 if (frontPolys) Debug << "front poly: " << *frontPolys->back() << endl; 632 } 633 //Debug << "coincident size: " << coincident.size() << endl; 634 635 // get view cell associated with the first split polygon 636 ViewCell *viewCell = (coincident.size() > 0) ? 637 dynamic_cast<ViewCell *>(coincident.front()->mParent) : NULL; 638 interior->ProcessPolygons(&coincident, mStorePolys); 627 639 628 640 // push the children on the stack 629 // inside information is only propagated withthe back leaf641 // split polygon is only needed in the back leaf 630 642 tStack.push(BspTraversalData(interior->GetFront(), frontPolys, tData.mDepth + 1, NULL)); 631 tStack.push(BspTraversalData(interior->GetBack(), backPolys, tData.mDepth + 1, splitPoly)); 643 tStack.push(BspTraversalData(interior->GetBack(), backPolys, tData.mDepth + 1, viewCell)); 644 645 // cleanup 646 DEL_PTR(tData.mNode); 647 DEL_PTR(tData.mPolygons); 632 648 633 649 return interior; … … 638 654 PolygonContainer *polys, 639 655 PolygonContainer *frontPolys, 640 PolygonContainer *backPolys, Polygon3 **splitPoly) 656 PolygonContainer *backPolys, 657 PolygonContainer *coincident) 641 658 { 642 659 mStat.nodes += 2; … … 651 668 // split polygon according to current plane 652 669 int splits = 0; 653 654 *splitPoly = interior->SplitPolygons(polys, frontPolys, backPolys, splits, mStorePolys);670 671 interior->SplitPolygons(polys, frontPolys, backPolys, coincident, splits, mStorePolys); 655 672 656 673 mStat.splits += splits; … … 666 683 667 684 // and setup child links 668 //interior->SetupChildLinks(new BspLeaf(interior), new BspLeaf(interior, leaf->mViewCell));669 685 interior->SetupChildLinks(new BspLeaf(interior), new BspLeaf(interior)); 670 686 671 delete leaf; // leaf not member of tree anymore672 673 687 return interior; 674 688 } … … 1038 1052 { 1039 1053 exporter->ExportBspTree(*this); 1040 delete exporter;1041 1042 1054 return true; 1043 1055 } -
trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.h
r286 r289 182 182 @param frontPolys returns the polygons in the front of the split plane 183 183 @param backPolys returns the polygons in the back of the split plane 184 @param splits number of splits 185 @returns split polygon if there is a polygon coincident to the split plane, NULL otherwise 186 */ 187 Polygon3 *SplitPolygons(PolygonContainer *polys, 188 PolygonContainer *frontPolys, 189 PolygonContainer *backPolys, 190 int &splits, 191 bool storePolys = false); 184 @param coincident returns the polygons coincident to the split plane 185 @param splits returns the splits number of splits 186 @param storePolys if the polygons should be stored in the node 187 */ 188 void SplitPolygons(PolygonContainer *polys, 189 PolygonContainer *frontPolys, 190 PolygonContainer *backPolys, 191 PolygonContainer *coincident, 192 int &splits, 193 bool storePolys = false); 192 194 193 195 /** Stores polygon in node or discards them according to storePolys. … … 195 197 @param storePolys if the polygons should be stored or discarded 196 198 */ 197 void ProcessPolygon(Polygon3 * poly, const bool storePolys);199 void ProcessPolygon(Polygon3 **poly, const bool storePolys); 198 200 199 201 friend ostream &operator<<(ostream &s, const BspInterior &A) … … 204 206 protected: 205 207 206 207 208 /// Splitting plane corresponding to this node 208 209 Plane3 mPlane; … … 258 259 /// current depth 259 260 int mDepth; 260 /// the polygon that drove the split plane computation261 Polygon3 *mSplitPoly;261 /// the view cell associated with this subdivsion 262 ViewCell *mViewCell; 262 263 /// if the node is an inside or outside node with respect to the parent plane 263 264 //bool mIsInside; 264 265 BspTraversalData() {} 265 266 266 BspTraversalData(BspNode *node, PolygonContainer *polys, const int depth, Polygon3 *splitPoly):267 mNode(node), mPolygons(polys), mDepth(depth), m SplitPoly(splitPoly) {}267 BspTraversalData(BspNode *node, PolygonContainer *polys, const int depth, ViewCell *viewCell): 268 mNode(node), mPolygons(polys), mDepth(depth), mViewCell(viewCell) {} 268 269 }; 269 270 … … 282 283 283 284 /** Constructs tree using the given list of view cells. 284 A pointer to the appropriate view cell is stored within each leaf. 285 For this type of construction we filter all view cells down the 286 tree. If there is no polygon left, the last split plane 287 decides inside or outside of the viewcell. A pointer to the 288 appropriate view cell is stored within each leaf. 285 289 Many leafs can point to the same viewcell. 286 290 */ … … 322 326 bool Export(const string filename); 323 327 324 static bool displayDebug;328 //static bool displayDebug; 325 329 protected: 326 330 … … 360 364 Plane3 SelectPlane(PolygonContainer *polys) const; 361 365 362 /** Filters next view cell down the tree and inserts it into the appropriate leaves366 /** Filters next view cell down the tree and inserts it into the appropriate leaves 363 367 (i.e., possibly more than one leaf). 364 368 */ 365 //void InsertViewCell(ViewCell *viewCell); 366 369 void InsertViewCell(ViewCell *viewCell); 370 /** Inserts polygons down the tree. The polygons are filtered until a leaf is reached, 371 then further subdivided. 372 @param viewCellContainer if not null, a new viewcell is created and stored in the container 373 */ 374 void InsertPolygons(PolygonContainer *polys, ViewCellContainer *viewCells = NULL); 375 367 376 /** Subdivide leaf. 368 377 @param leaf the leaf to be subdivided 369 378 @param polys the input polygons 370 @param frontPolys the polygons of the front child node as a result from splitting371 @param backPolys the polygons of the back child node as a result from splitting372 @param splitPoly polygon that is coincident to the split plane, NULL if no such polygon379 @param frontPolys returns the polygons in the front of the split plane 380 @param backPolys returns the polygons in the back of the split plane 381 @param coincident returns the polygons coincident to the split plane 373 382 @returns the root of the subdivision 374 383 */ … … 376 385 PolygonContainer *polys, 377 386 PolygonContainer *frontPolys, 378 PolygonContainer *backPolys, Polygon3 **splitPoly); 387 PolygonContainer *backPolys, 388 PolygonContainer *coincident); 379 389 380 390 /** Filters polygons down the tree. -
trunk/VUT/GtpVisibilityPreprocessor/src/X3dExporter.cpp
r265 r289 352 352 Mesh *mesh = new Mesh; 353 353 // add 6 vertices of the box 354 int index = mesh->mVertices.size();354 int index = (int)mesh->mVertices.size(); 355 355 for (int i=0; i < 8; i++) { 356 356 Vector3 v; … … 397 397 ViewCellContainer mFoundViewCells; 398 398 399 while (!tStack.empty()) 400 { 401 BspNode *node = tStack.top(); 399 if (tree.StorePolys()) 400 { 401 while (!tStack.empty()) 402 { 403 BspNode *node = tStack.top(); 402 404 403 tStack.pop(); 404 405 if (tree.StorePolys()) // extract the polygons 405 tStack.pop(); 406 407 if (tree.StorePolys()) // extract the polygons 408 { 409 PolygonContainer::const_iterator it; 410 PolygonContainer::const_iterator it_end = node->GetPolygons()->end(); 411 412 for (it = node->GetPolygons()->begin(); it != it_end; ++ it) 413 ExportPolygon(*it); 414 } 415 416 if (!node->IsLeaf()) 417 { 418 BspInterior *interior = dynamic_cast<BspInterior *>(node); 419 420 tStack.push(interior->GetFront()); 421 tStack.push(interior->GetBack()); 422 423 } 424 } 425 } 426 else // export view cells 427 { 428 while (!tStack.empty()) 406 429 { 407 PolygonContainer::const_iterator it; 408 PolygonContainer::const_iterator it_end = node->GetPolygons()->end(); 409 410 for (it = node->GetPolygons()->begin(); it != it_end; ++ it) 411 ExportPolygon(*it); 430 BspNode *node = tStack.top(); 431 432 tStack.pop(); 433 434 if (node->IsLeaf()) 435 { 436 ViewCell *viewCell = dynamic_cast<BspLeaf *>(node)->GetViewCell(); 437 if (viewCell) 438 mFoundViewCells.push_back(viewCell); 439 } 440 else 441 { 442 BspInterior *interior = dynamic_cast<BspInterior *>(node); 443 444 tStack.push(interior->GetFront()); 445 tStack.push(interior->GetBack()); 446 } 412 447 } 413 448 414 if (!node->IsLeaf()) 415 { 416 BspInterior *interior = dynamic_cast<BspInterior *>(node); 417 418 tStack.push(interior->GetFront()); 419 tStack.push(interior->GetBack()); 420 421 } 422 else if (!tree.StorePolys()) 423 { 424 ViewCell *viewCell = dynamic_cast<BspLeaf *>(node)->GetViewCell(); 425 426 if (viewCell) 427 mFoundViewCells.push_back(viewCell); 428 } 429 } 430 431 if (!tree.StorePolys()) 432 { 433 //move consecutive duplicates past the end; store new end 449 Debug << "Number of view cells with dublicates: " << (int)mFoundViewCells.size() << endl; 450 451 //-- erase dublicates 452 sort(mFoundViewCells.begin(), mFoundViewCells.end()); 434 453 ViewCellContainer::iterator new_end = unique(mFoundViewCells.begin(), mFoundViewCells.end()); 435 // delete all elements past new_end436 454 mFoundViewCells.erase(new_end, mFoundViewCells.end()); 437 455 ExportViewCells(&mFoundViewCells); 456 457 Debug << "Number of view cells after erasing dublicates: " << (int)mFoundViewCells.size() << endl; 438 458 } 439 459 … … 458 478 AxisAlignedBox3 box = tree.GetBox(node); 459 479 // add 6 vertices of the box 460 int index = mesh->mVertices.size();480 int index = (int)mesh->mVertices.size(); 461 481 for (int i=0; i < 8; i++) { 462 482 Vector3 v; … … 513 533 514 534 // add 6 vertices of the box 515 int index = mesh->mVertices.size();535 int index = (int)mesh->mVertices.size(); 516 536 for (int i=0; i < 8; i++) { 517 537 Vector3 v; -
trunk/VUT/GtpVisibilityPreprocessor/src/main.cpp
r286 r289 42 42 { 43 43 if (vcFilename != "") 44 {45 44 p->LoadViewCells(vcFilename); 46 47 Exporter *exporter = Exporter::GetExporter("viewcells.x3d");48 if (exporter)49 { exporter->ExportViewCells(&p->mViewCells);50 delete exporter;51 }52 }53 45 else 54 46 p->GenerateViewCells(); 47 48 Exporter *exporter = Exporter::GetExporter("viewcells.x3d"); 49 if (exporter) 50 { 51 exporter->ExportViewCells(&p->mViewCells); // export view cells 52 delete exporter; 53 } 54 Debug << "Viewcells loaded / generated. Number of view cells: " << p->mViewCells.size() << endl; 55 55 } 56 56 57 57 p->BuildBspTree(); 58 58 p->BspTreeStatistics(Debug); 59 Debug << "Number of view cells: " << p->mViewCells.size() << endl; 60 p->Export(filename + "-bsptree.x3d", false, false, true); 59 p->Export("vc_bsptree.x3d", false, false, true); 61 60 62 61 #endif
Note: See TracChangeset
for help on using the changeset viewer.