- Timestamp:
- 08/16/05 00:08:53 (19 years ago)
- Location:
- trunk/VUT/GtpVisibilityPreprocessor
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/VUT/GtpVisibilityPreprocessor/scripts/default.env
r238 r239 62 62 splitPlaneStrategy balancedTree 63 63 # splitPlaneStrategy nextPolygon 64 #constructionMethod viewCells65 constructionMethod sceneGeometry64 constructionMethod viewCells 65 # constructionMethod sceneGeometry 66 66 maxCandidates 20 67 maxViewCells 10 067 maxViewCells 10 68 68 Termination { 69 69 maxPolygons 4 -
trunk/VUT/GtpVisibilityPreprocessor/src/Plane3.h
r238 r239 49 49 if (signum(dv) != 0) 50 50 { 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; 54 55 } 55 else { 56 if (coplanar) (*coplanar) = true; 56 else if (coplanar) 57 { 58 (*coplanar) = true; 57 59 } 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 61 64 return a + u * b - u * a; // NOTE: gives better precision than calclulating a + u * v 62 65 //return a + (u * v); -
trunk/VUT/GtpVisibilityPreprocessor/src/Polygon3.cpp
r238 r239 14 14 VertexIndexContainer::const_iterator it; 15 15 16 Debug << "Creating polygon:\n";17 18 16 for (it = face->mVertexIndices.begin(); it != face->mVertexIndices.end(); ++ it) 19 17 { … … 25 23 Plane3 Polygon3::GetSupportingPlane() const 26 24 { 27 Debug << "creating plane using vertices: " << mVertices[0] << mVertices[1] << mVertices[2] << endl;28 25 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 31 30 return Plane3(mVertices[0], mVertices[1], mVertices[2]); 32 31 } … … 52 51 VertexContainer::const_iterator it; 53 52 54 Debug << "\n\nvertex A: " << ptA << ", side A: " << sideA << " (" << partition->Distance(ptA) << ")";55 56 53 // find line - plane intersections 57 54 for (it = mVertices.begin(); it != mVertices.end(); ++ it) … … 59 56 Vector3 ptB = (*it); 60 57 int sideB = partition->Side(ptB, SIDE_TOLERANCE); 61 Debug << " <=> vertex B: " << ptB << ", side B: " << sideB << " (" << partition->Distance(ptB) << ")\n\n"; 62 58 63 59 // vertices on different sides => split 64 60 if (sideB > 0) … … 71 67 // add vertex to both polygons 72 68 front->mVertices.push_back(splitPt); 73 back->mVertices.push_back(splitPt); Debug << "front and back polygon + " << splitPt << endl;69 back->mVertices.push_back(splitPt); 74 70 75 71 ++ splits; 76 72 } 77 front->mVertices.push_back(ptB); Debug << "front polygon + " << ptB << endl;73 front->mVertices.push_back(ptB); 78 74 } 79 75 else if (sideB < 0) … … 86 82 // add vertex to both polygons 87 83 front->mVertices.push_back(splitPt); 88 back->mVertices.push_back(splitPt); Debug << "front and back polygon + " << splitPt << endl;84 back->mVertices.push_back(splitPt); 89 85 90 86 ++ splits; 91 87 } 92 back->mVertices.push_back(ptB); Debug << "back polygon + " << ptB << endl;88 back->mVertices.push_back(ptB); 93 89 } 94 90 else … … 96 92 // vertex on plane => add vertex to both polygons 97 93 front->mVertices.push_back(ptB); 98 back->mVertices.push_back(ptB); Debug << "front and back polygon + " << ptB << endl;94 back->mVertices.push_back(ptB); 99 95 } 100 96 101 97 ptA = ptB; 102 98 sideA = sideB; 103 Debug << "vertex A: " << ptA << ", side A: " << sideA << " (" << partition->Distance(ptA) << ")";104 99 } 105 Debug << "\n*********************\n";106 100 } 107 101 -
trunk/VUT/GtpVisibilityPreprocessor/src/ViewCell.cpp
r237 r239 41 41 float ViewCell::IntersectionComplexity() 42 42 { 43 return mMesh->mFaces.size();43 return (float)mMesh->mFaces.size(); 44 44 } 45 45 … … 56 56 void ViewCell::DeriveViewCells(const ObjectContainer &objects, 57 57 ViewCellContainer &viewCells, 58 const int max )58 const int maxViewCells) 59 59 { 60 60 // 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(); 62 62 63 for (int i = 0; i < n; ++i)63 for (int i = 0; i < limit; ++i) 64 64 { 65 65 Intersectable *object = objects[i]; -
trunk/VUT/GtpVisibilityPreprocessor/src/ViewCell.h
r235 r239 46 46 @param objects the intersectables the viewcells are derived from 47 47 @param viewCells the viewcells are returned in this container 48 @param if >0, indicates the maximim number of viewcells that will be created48 @param maxViewCells if > 0, indicates the maximim number of viewcells that will be created 49 49 */ 50 50 static void DeriveViewCells(const ObjectContainer &objects, 51 51 ViewCellContainer &viewCells, 52 const int max );52 const int maxViewCells); 53 53 protected: 54 54 -
trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.cpp
r238 r239 11 11 #include <iomanip> 12 12 13 #define INITIAL_TEST_VAL 999999// unreachable high initial value for heuristic evaluation 14 13 15 int BspTree::sTermMaxPolygons = 10; 14 16 int BspTree::sTermMaxDepth = 20; … … 96 98 { 97 99 Polygon3 *poly = polys->back(); 98 99 100 polys->pop_back(); 100 101 101 Debug << (*poly); 102 102 // test if split is neccessary 103 103 int result = poly->ClassifyPlane(mPlane); 104 104 … … 109 109 { 110 110 case Polygon3::COINCIDENT: 111 Debug << "coincident\n";112 111 break; // do nothing 113 112 case Polygon3::FRONT_SIDE: 114 Debug << "front\n";115 113 frontPolys->push_back(poly); 116 114 break; 117 115 case Polygon3::BACK_SIDE: 118 Debug << "back\n";119 116 backPolys->push_back(poly); 120 117 break; … … 123 120 back_piece = new Polygon3(); 124 121 125 Debug << "\n\n**************SPLIT***************\n";126 Debug << "Split plane: " << mPlane << "\noriginal " << (*poly) << endl;127 128 122 //-- split polygon 129 123 poly->Split(&mPlane, front_piece, back_piece, splits); 130 131 Debug << "new front " << (*front_piece) << endl;132 Debug << "new back " << (*back_piece) << endl;133 124 134 125 frontPolys->push_back(front_piece); 135 126 backPolys->push_back(back_piece); 136 127 128 #ifdef _DEBUG 129 Debug << "split " << poly << endl << front << endl << back << endl; 130 #endif 137 131 // don't need polygon anymore 138 132 DEL_PTR(poly); … … 169 163 /****************************************************************/ 170 164 171 BspTree::BspTree(): mTermMaxPolygons(0), mTermMaxDepth(0) 172 { 173 mRoot = new BspLeaf(); 165 BspTree::BspTree(): mTermMaxPolygons(0), mTermMaxDepth(0), mRoot(NULL) 166 { 174 167 Randomize(); // initialise random generator for heuristics 175 168 } … … 267 260 268 261 void BspTree::InsertViewCell(ViewCell *viewCell) 269 { 270 Debug << "Inserting view cells\n"; 262 { 271 263 std::stack<BspTraversalData> tStack; 272 264 … … 275 267 CopyMesh2Polygons(viewCell->GetMesh(), polys); 276 268 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)); 278 272 279 273 while (!tStack.empty()) … … 283 277 284 278 tStack.pop(); 285 279 286 280 if (!tData.mNode->IsLeaf()) 287 281 { 288 282 BspInterior *interior = dynamic_cast<BspInterior *>(tData.mNode); 289 283 290 // filter polygons down the tree.284 //-- filter view cell polygons down the tree until a leaf is reached 291 285 PolygonContainer *frontPolys = new PolygonContainer(); 292 286 PolygonContainer *backPolys = new PolygonContainer(); 293 287 294 288 int splits = 0; 289 // split viecell polygons with respect to split plane 295 290 interior->SplitPolygons(tData.mPolygons, frontPolys, backPolys, splits); 296 291 mStat.splits += splits; … … 309 304 delete backPolys; 310 305 } 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; 314 312 } 315 313 } … … 349 347 ObjectContainer::const_iterator it, it_end = objects.end(); 350 348 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 354 351 for (int i = 0; i < limit; ++i) 355 352 { … … 376 373 } 377 374 378 Debug << " number of polygons: " << polys.size() << endl;375 Debug << "Number of polygons: " << polys.size() << endl; 379 376 } 380 377 … … 394 391 Copy2PolygonSoup(objects, *polys, 100); 395 392 396 BspTraversalData tData(mRoot, mRoot->GetParent(), polys, 0); 393 BspTraversalData tData(new BspLeaf(), mRoot->GetParent(), polys, 0); 394 397 395 tStack.push(tData); 398 396 … … 401 399 tData = tStack.top(); 402 400 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 410 BspNode * BspTree::Subdivide(BspTraversalStack &tStack, BspTraversalData &tData, ViewCell *viewCell) 411 { 411 412 PolygonContainer *backPolys = new PolygonContainer(); 412 413 PolygonContainer *frontPolys = new PolygonContainer(); 413 int polySize = tData.mPolygons->size(); 414 414 415 BspNode *node = SubdivideNode(dynamic_cast<BspLeaf *>(tData.mNode), 415 416 tData.mParent, … … 419 420 frontPolys, 420 421 backPolys); 421 Debug << "Level " << tData.mDepth << ", all: " << polySize << ", front: " << frontPolys->size() << ", back: " << backPolys->size() << endl; 422 422 423 if (!node->IsLeaf()) // node was subdivided 423 424 { … … 434 435 Polygon3::DeletePolygons(tData.mPolygons); 435 436 } 437 438 return node; 436 439 } 437 440 438 441 Plane3 BspTree::SelectPlane(PolygonContainer *polygons) const 439 442 { 440 // mostsimple strategy: just take next polygon443 // simple strategy: just take next polygon 441 444 if (sSplitPlaneStrategy == NEXT_POLYGON) 442 445 { 443 Debug << "simple plane selection\n";444 446 return polygons->front()->GetSupportingPlane(); 445 447 } … … 450 452 Plane3 BspTree::SelectPlaneHeuristics(PolygonContainer *polygons, int maxTests) const 451 453 { 452 Debug << "selecting plane heuristics\n"; 453 454 int bestValue = 999999; 455 454 int bestValue = INITIAL_TEST_VAL; 456 455 Plane3 *bestPlane = NULL; 457 456 … … 462 461 int candidateIdx = Random((int)polygons->size()); 463 462 Plane3 candidatePlane = (*polygons)[candidateIdx]->GetSupportingPlane(); 464 Debug << "choosing new candidate: " << limit << endl;463 465 464 // evaluate current candidate 466 465 int candidateValue = EvalSplitPlane(polygons, candidatePlane); … … 470 469 bestPlane = &candidatePlane; 471 470 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 } 476 474 477 475 return *bestPlane; … … 532 530 if ((polys->size() <= mTermMaxPolygons) || (depth >= mTermMaxDepth)) 533 531 { 534 // Debug << polys->size() << ", " << depth << endl;535 532 return leaf; 536 533 } … … 540 537 // add the new nodes to the tree + select subdivision plane 541 538 BspInterior *node = new BspInterior(SelectPlane(polys)); 542 Debug << "new bspinterior: " << (*node) << endl; 539 540 #ifdef _DEBUG 541 Debug << node << endl; 542 #endif 543 543 // split polygon according to current plane 544 544 int splits = 0; … … 546 546 547 547 node->SplitPolygons(polys, frontPolys, backPolys, splits); 548 Debug << "$$ " << polySize << " " << frontPolys->size() << " " << backPolys->size() << endl;548 549 549 mStat.splits += splits; 550 550 … … 595 595 void BspTree::EvaluateLeafStats(const BspTraversalData &data) 596 596 { 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: " << 612 611 data.mPolygons->size() << " (max: " << mTermMaxPolygons << ")" << endl; 612 #endif 613 613 } 614 614 //} // GtpVisibilityPreprocessor -
trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.h
r238 r239 254 254 @param tData traversal data also holding node to be subdivided 255 255 @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); 258 259 259 260 /** Selects a splitting plane.
Note: See TracChangeset
for help on using the changeset viewer.