Changeset 263 for trunk/VUT/GtpVisibilityPreprocessor/src
- Timestamp:
- 09/12/05 02:07:02 (19 years ago)
- Location:
- trunk/VUT/GtpVisibilityPreprocessor/src
- Files:
-
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/VUT/GtpVisibilityPreprocessor/src/Camera.cpp
r242 r263 97 97 exporter->SetWireframe(); 98 98 exporter->ExportKdTree(*tree); 99 // exporter->ExportBspTree(*tree);99 //exporter->ExportBspTree(*bsptree); 100 100 exporter->ExportRays(rays, 10000); 101 101 exporter->SetFilled(); -
trunk/VUT/GtpVisibilityPreprocessor/src/Containers.h
r236 r263 11 11 class SceneGraphNode; 12 12 class Intersectable; 13 class Polygon3; 13 14 15 /** Container storing polygons used during BSP tree construction 16 */ 17 typedef vector<Polygon3 *> PolygonContainer; 14 18 15 19 /** Container for Mesh pointers primarily for the use within the kDTree and -
trunk/VUT/GtpVisibilityPreprocessor/src/Polygon3.h
r262 r263 13 13 class Face; 14 14 15 /** Container storing polygons used during BSP tree construction16 */17 typedef vector<Polygon3 *> PolygonContainer;18 15 19 16 /** Class representing a general planar polygon in 3d. … … 67 64 /// we can also store materials with polygons 68 65 Material *mMaterial; 66 67 static int mLeastSplitTable[4]; 68 static int mBalancedTreeTable[4]; 69 69 }; 70 70 -
trunk/VUT/GtpVisibilityPreprocessor/src/Preprocessor.cpp
r262 r263 23 23 Preprocessor::LoadViewCells(const string filename) 24 24 { 25 X3dParser *parser = new X3dParser; 26 27 bool result = parser->ParseFile(filename, mViewCells); 28 29 if (result) 30 { 31 Exporter *exporter = Exporter::GetExporter("viewcells.x3d"); 32 33 if (exporter) 34 { 35 exporter->ExportViewCells(&mViewCells); 36 delete exporter; 37 } 38 39 Debug << "Generating view cells" << endl; 40 GenerateViewCells(); 41 Debug << "Generated view cells" << endl; 42 } 43 44 DEL_PTR(parser); 45 46 47 return result; 25 return X3dParser().ParseFile(filename, mViewCells); 48 26 } 49 27 … … 51 29 Preprocessor::GenerateViewCells() 52 30 { 53 return BuildBspTree(); 31 // TODO 32 // HACK: derive view cells from the scene objects 33 ObjectContainer objects; 34 35 int maxViewCells = 0; 36 environment->GetIntValue("BspTree.maxViewCells", maxViewCells); 37 38 mSceneGraph->CollectObjects(&objects); 39 ViewCell::DeriveViewCells(objects, mViewCells, maxViewCells); 40 41 return true; 54 42 } 55 43 … … 94 82 } 95 83 84 96 85 bool 97 86 Preprocessor::BuildBspTree() … … 100 89 mBspTree = new BspTree(); 101 90 102 char constructionMethodStr[64];103 int maxViewCells = 0;104 105 environment->GetIntValue("BspTree.maxViewCells", maxViewCells);106 environment->GetStringValue("BspTree.constructionMethod", constructionMethodStr);107 108 int constructionMethod = BspTree::VIEWCELLS;109 110 if (strcmp(constructionMethodStr, "viewCells") == 0)111 constructionMethod = BspTree::VIEWCELLS;112 else if (strcmp(constructionMethodStr, "sceneGeometry") == 0)113 constructionMethod = BspTree::SCENE_GEOMETRY;114 else if (strcmp(constructionMethodStr, "rays") == 0)115 constructionMethod = BspTree::RAYS;116 else117 {118 cerr << "Wrong bsp construction method " << constructionMethodStr << endl;119 exit(1);120 }121 122 91 ObjectContainer objects; 123 92 RayContainer rays; 124 93 125 switch ( constructionMethod)94 switch (BspTree::sConstructionMethod) 126 95 { 127 case BspTree::VIEW CELLS:96 case BspTree::VIEW_CELLS: 128 97 Debug << "Construction method: view cells\n"; 129 130 // derive view cells from the scene objects 131 if (mViewCells.empty()) 132 { 133 Debug << "View cells empty => generating new ones\n"; Debug.flush(); 134 mSceneGraph->CollectObjects(&objects); 135 ViewCell::DeriveViewCells(objects, mViewCells, maxViewCells); 136 } 137 98 138 99 mBspTree->Construct(mViewCells); 139 100 break; … … 142 103 143 104 CLEAR_CONTAINER(mViewCells); // we generate new view cells 105 144 106 mSceneGraph->CollectObjects(&objects); 145 146 107 mBspTree->Construct(objects, &mViewCells); 147 108 break; … … 149 110 Debug << "Construction method: rays\n"; 150 111 151 CLEAR_CONTAINER(mViewCells); // we generate new view cells 152 112 CLEAR_CONTAINER(mViewCells); // we generate new view cells 153 113 mBspTree->Construct(rays, &mViewCells); 154 114 break; -
trunk/VUT/GtpVisibilityPreprocessor/src/Preprocessor.h
r262 r263 67 67 68 68 /** Build the BSP tree of currently loaded occluders/occludees/viewcells. The construction 69 is driven by the environment settings, which also sa is which of the three types of69 is driven by the environment settings, which also says which of the three types of 70 70 entities should be used to drive the heuristical construction (only occluders by default) 71 71 */ -
trunk/VUT/GtpVisibilityPreprocessor/src/ViewCell.cpp
r262 r263 116 116 mesh->mVertices.push_back(topTri.mVertices[i]); 117 117 118 mesh->Preprocess(); 119 118 120 return new ViewCell(mesh); 119 121 } -
trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.cpp
r262 r263 19 19 int BspTree::sSplitPlaneStrategy = NEXT_POLYGON; 20 20 int BspTree::sMaxCandidates = 10; 21 int BspTree::sConstructionMethod = VIEW_CELLS; 22 23 /** Evaluates split plane classification with respect to the plane's 24 contribution for a balanced tree. 25 */ 26 int BspTree::sLeastSplitsTable[4] = {0, 0, 1, 0}; 27 /** Evaluates split plane classification with respect to the plane's 28 contribution for a minimum number splits in the tree. 29 */ 30 int BspTree::sBalancedTreeTable[4] = {-1, 1, 0, 0}; 21 31 22 32 /****************************************************************/ … … 51 61 } 52 62 63 void BspNode::AddPolygons(PolygonContainer *polys) 64 { 65 while (!polys->empty()) 66 { 67 mPolygons.push_back(polys->back()); 68 polys->pop_back(); 69 } 70 } 71 72 53 73 /****************************************************************/ 54 74 /* class BspInterior implementation */ … … 56 76 57 77 58 BspInterior::BspInterior(Plane3 plane): mPlane(plane) 78 BspInterior::BspInterior(const Plane3 &plane): 79 mPlane(plane), mFront(NULL), mBack(NULL) 59 80 {} 60 81 … … 95 116 mBack = b; 96 117 mFront = f; 118 } 119 120 void BspInterior::ProcessPolygon(Polygon3 *poly, bool storePolys) 121 { 122 if (storePolys) 123 mPolygons.push_back(poly); 124 else 125 delete poly; 97 126 } 98 127 … … 116 145 { 117 146 case Polygon3::COINCIDENT: 118 // same sides => discard 119 if (DotProd(poly->GetSupportingPlane().mNormal, mPlane.mNormal) > 0) 120 { 121 if (storePolys) 122 mPolygons.push_back(poly); 123 else 124 DEL_PTR(poly); 125 } 126 else 127 backPolys->push_back(poly); 128 break; // TODO: compare normals 147 // discard polygons or saves them in node 148 ProcessPolygon(poly, storePolys); 149 break; 129 150 case Polygon3::FRONT_SIDE: 130 151 frontPolys->push_back(poly); … … 142 163 frontPolys->push_back(front_piece); 143 164 backPolys->push_back(back_piece); 165 166 #ifdef _DEBUG 167 Debug << "split " << *poly << endl << *front_piece << endl << *back_piece << endl; 168 #endif 169 // save or discard polygons 170 ProcessPolygon(poly, storePolys); 144 171 145 if (storePolys)146 mPolygons.push_back(poly);147 else148 DEL_PTR(poly);149 #ifdef _DEBUG150 Debug << "split " << poly << endl << front << endl << back << endl;151 #endif152 172 break; 153 173 default: … … 164 184 /* class BspLeaf implementation */ 165 185 /****************************************************************/ 186 BspLeaf::BspLeaf(): mViewCell(NULL) 187 { 188 } 166 189 167 190 BspLeaf::BspLeaf(ViewCell *viewCell): mViewCell(viewCell) 168 191 { 169 192 } 193 194 BspLeaf::BspLeaf(BspInterior *parent): BspNode(parent), mViewCell(NULL) 195 {} 170 196 171 197 ViewCell *BspLeaf::GetViewCell() … … 184 210 } 185 211 186 void BspLeaf::AddPolygons(PolygonContainer *polys)187 {188 while (!polys->empty())189 {190 mPolygons.push_back(polys->back());191 polys->pop_back();192 }193 }194 212 /****************************************************************/ 195 213 /* class BspTree implementation */ … … 218 236 219 237 app << "#N_RAYS Number of rays )\n" 220 << rays << endl;238 << rays << endl; 221 239 app << "#N_DOMAINS ( Number of query domains )\n" 222 240 << queryDomains <<endl; … … 247 265 248 266 app << "#N_PEMPTYLEAVES ( Percentage of leaves with zero query domains )\n"<< 249 zeroQueryNodes*100/(double)Leaves() <<endl;267 zeroQueryNodes*100/(double)Leaves() << endl; 250 268 251 269 app << "#N_PMAXDEPTHLEAVES ( Percentage of leaves at maxdepth )\n"<< … … 300 318 { 301 319 std::stack<BspTraversalData> tStack; 302 303 PolygonContainer polys;304 305 // copy polygon information toguide the split process306 AddMesh2Polygons(viewCell->GetMesh(), polys);320 Debug << "getting polygons" << endl; Debug.flush(); 321 PolygonContainer *polys = new PolygonContainer(); 322 323 // extract polygons that guide the split process 324 AddMesh2Polygons(viewCell->GetMesh(), *polys); 307 325 mBox.Include(viewCell->GetBox()); // add to BSP aabb 308 326 309 BspNode *firstNode = mRoot ? mRoot : new BspLeaf(); // traverse tree or create new one 310 311 tStack.push(BspTraversalData(firstNode, NULL, &polys, 0)); 312 327 // traverse tree or create new one 328 BspNode *firstNode = mRoot ? mRoot : new BspLeaf(); 329 330 tStack.push(BspTraversalData(firstNode, NULL, polys, 0)); 331 332 Debug << "starting traversal" << endl; Debug.flush(); 313 333 while (!tStack.empty()) 314 334 { 335 Debug << "new traversal step" << endl; Debug.flush(); 336 315 337 // filter polygons donw the tree 316 338 BspTraversalData tData = tStack.top(); 317 318 339 tStack.pop(); 319 320 if (!tData.mNode->IsLeaf()) 321 { 340 341 Debug << "popped stack" << endl; Debug.flush(); 342 if (!tData.mNode) 343 Debug << "ERROR NO NODE\n"; Debug.flush(); 344 if (!tData.mNode->IsLeaf()) 345 { 346 Debug << "no leaf" << endl; Debug.flush(); 322 347 BspInterior *interior = dynamic_cast<BspInterior *>(tData.mNode); 323 348 … … 327 352 328 353 int splits = 0; 329 // split viecell polygons with respect to split plane 330 interior->SplitPolygons(tData.mPolygons, frontPolys, backPolys, splits); 331 332 mStat.splits += splits; 333 334 // push the children on the stack 335 if (frontPolys->size() > 0) // if polygons on front side of bsp tree 354 355 if ((int)tData.mPolygons->size() > 0) 336 356 { 357 Debug << "traversing down tree" << endl; Debug.flush(); 358 // split viecell polygons with respect to split plane 359 interior->SplitPolygons(tData.mPolygons, frontPolys, backPolys, splits, mStorePolys); 360 Debug << "polygon splitted" << endl; Debug.flush(); 361 //Debug << "Reached level " << tData.mDepth << " bk: " << backPolys->size() << " frnt: " << frontPolys->size() << endl; 362 mStat.splits += splits; 363 364 // push the children on the stack 337 365 tStack.push(BspTraversalData(interior->GetFront(), interior->GetParent(), 338 366 frontPolys, tData.mDepth + 1)); 339 } 340 else // front side polygons empty 341 delete frontPolys; 342 343 if (backPolys->size() > 0) // if polygons on backc side of bsp tree 344 { 367 345 368 tStack.push(BspTraversalData(interior->GetBack(), interior->GetParent(), 346 369 backPolys, tData.mDepth + 1)); 370 347 371 } 348 else // back side polygons empty 349 delete backPolys; 372 else 373 { 374 Debug << "deleting data" << endl; Debug.flush(); 375 DEL_PTR(tData.mPolygons); 376 Debug << "deleted data" << endl; Debug.flush(); 377 } 350 378 } 351 379 else // reached leaf => subdivide current viewcell 352 380 { 353 BspNode *root = Subdivide(tStack, tData, viewCell); 381 Debug << "reached leaf" << endl; Debug.flush(); 382 BspNode *root = Subdivide(tStack, tData, viewCell); 354 383 355 384 // tree empty => new root 356 385 if (!mRoot) 357 mRoot = root; 358 } 359 } 386 mRoot = root; 387 Debug << "subdivision done" << endl; Debug.flush(); 388 } 389 Debug << "ended one traversal step" << endl; Debug.flush(); 390 } 391 Debug << "ended traversal" << endl; Debug.flush(); 360 392 } 361 393 … … 434 466 435 467 /* for this type of construction we filter all viewcells down the 436 * tree until there is no polygon left. The split of the last polygon468 * tree. If there is no polygon left, the last split plane 437 469 * decides inside or outside of the viewcell. 438 470 */ 439 const int maxPolygons = 0; 440 const int maxDepth = 99999; 441 442 InitTree(maxPolygons, maxDepth); 443 471 InitTree(sTermMaxPolygons, sTermMaxDepth); 472 473 bool savedStorePolys = mStorePolys; 474 444 475 // tree is completely constructed once before 445 476 // view cells are inserted one after another => … … 447 478 if (!mIsIncremential) 448 479 { 449 Debug << "Not incremential => constructing tree in advance\n";450 480 // copy view cell meshes into one big polygon soup 451 481 PolygonContainer *polys = new PolygonContainer(); 452 482 Copy2PolygonSoup(viewCells, *polys, sMaxCandidates); 453 483 484 // polygons are stored only during view cell insertion 485 mStorePolys = false; 486 454 487 // construct tree from viewcell polygons 455 488 Construct(polys); 456 457 Export("bsp.x3d"); 489 //Export("bsp.x3d"); 458 490 } 459 491 … … 461 493 ViewCellContainer::const_iterator it; 462 494 495 mStorePolys = savedStorePolys; 496 463 497 int counter = 0; 464 498 465 Debug << " View cells insertion...\n"; Debug.flush();499 Debug << "\n**** Started view cells insertion ****\n\n"; 466 500 for (it = viewCells.begin(); it != viewCells.end(); ++ it) 467 501 { 468 Debug << " Inserting view cell " << ++counter;502 Debug << "*** Inserting view cell " << counter << " ***" << endl; 469 503 InsertViewCell(*it); 470 } 471 Debug << "finished view cells insertion"; 504 Debug << "*** view cell " << ++ counter << " inserted ***" << endl; 505 } 506 Debug << "**** finished view cells insertion ****" << endl; Debug.flush(); 472 507 } 473 508 … … 476 511 { 477 512 // take termination criteria from globals 478 InitTree( mTermMaxPolygons, mTermMaxDepth);479 Debug << "HAHAHAHHA";Debug.flush();513 InitTree(sTermMaxPolygons, sTermMaxDepth); 514 480 515 PolygonContainer *polys = new PolygonContainer(); 481 516 … … 497 532 { 498 533 std::stack<BspTraversalData> tStack; 499 Debug << "HDDHDH"; Debug.flush(); 500 534 501 535 BspTraversalData tData(new BspLeaf(), NULL, polys, 0); 502 536 503 537 tStack.push(tData); 504 538 505 Debug << " Contructing tree using objects..."; Debug.flush();539 Debug << "**** Contructing tree using objects ****\n"; 506 540 while (!tStack.empty()) 507 541 { 508 542 tData = tStack.top(); 509 543 tStack.pop(); 510 511 544 512 545 // subdivide leaf node 513 546 BspNode *root = Subdivide(tStack, tData); 514 547 515 // empty tree => //new root corresponding to unbounded space548 // empty tree => new root corresponding to unbounded space 516 549 if (!mRoot) 517 550 mRoot = root; 518 551 } 519 552 520 Debug << " finished\n";553 Debug << "**** tree construction finished ****\n"; 521 554 } 522 555 … … 526 559 ViewCell *viewCell) 527 560 { 561 Debug << "subdividing" << endl; Debug.flush(); 528 562 PolygonContainer *backPolys = new PolygonContainer(); 529 563 PolygonContainer *frontPolys = new PolygonContainer(); … … 538 572 if (!node->IsLeaf()) // node was subdivided 539 573 { 574 Debug << "node was subdivided" << endl; Debug.flush(); 540 575 BspInterior *interior = dynamic_cast<BspInterior *>(node); 541 576 … … 544 579 tStack.push(BspTraversalData(interior->GetFront(), interior, frontPolys, tData.mDepth + 1)); 545 580 } 546 else // tree terminates here 547 { 581 else // traversal terminates 582 { 583 Debug << "eval stats" << endl; Debug.flush(); 548 584 EvaluateLeafStats(tData); 549 585 550 // add view cell if in positive halfspace 551 if (!tData.mParent || (node == tData.mParent->GetFront())) 552 dynamic_cast<BspLeaf *>(node)->SetViewCell(viewCell); 586 BspLeaf *leaf = dynamic_cast<BspLeaf *>(node); 587 588 // add view cell if in negative halfspace (== inside object) 589 // or if there is still geometry left 590 if (viewCell && 591 (!node->GetParent() || (node == node->GetParent()->GetBack()) || 592 (tData.mPolygons->size() > 0))) 593 { 594 Debug << "** view cell inserted **\n"; 595 leaf->SetViewCell(viewCell); 596 } 597 598 Debug << "storing or deleting polygons: " << mStorePolys << endl; Debug.flush(); 599 // add or delete remaining polygons 600 if (mStorePolys) 601 leaf->AddPolygons(tData.mPolygons); 602 else 603 CLEAR_CONTAINER(*tData.mPolygons); 604 605 DEL_PTR(tData.mPolygons); 606 Debug << "deleted polygon container" << endl; Debug.flush(); 553 607 } 554 608 … … 556 610 } 557 611 558 bool BspTree::ProcessPolygons(PolygonContainer *polys, BspLeaf *leaf)559 {560 bool result = false;561 562 if (mStorePolys)563 {564 leaf->AddPolygons(polys);565 result = true;566 }567 else568 CLEAR_CONTAINER(*polys);569 570 delete polys;571 return result;572 }573 612 574 613 BspNode *BspTree::SubdivideNode(BspLeaf *leaf, … … 579 618 PolygonContainer *backPolys) 580 619 { 581 // terminate traversal 582 if ((polys->size() <= mTermMaxPolygons) || (depth >= mTermMaxDepth)) 583 { 584 // add or delete remaining polygons 585 ProcessPolygons(polys, leaf); 586 620 if (leaf->GetViewCell() && (polys->size() == 0)) 621 Debug << "error: no distinct view cells!!!!!!!!!!!\n"; 622 623 // terminate traversal 624 if (//!leaf->GetViewCell() && 625 ((polys->size() <= mTermMaxPolygons) || (depth >= mTermMaxDepth))) 626 {Debug << "subdividing node termination" << endl; Debug.flush(); 587 627 return leaf; 588 628 } … … 600 640 int splits = 0; 601 641 642 Debug << "splipoly" << endl; Debug.flush(); 602 643 node->SplitPolygons(polys, frontPolys, backPolys, splits, mStorePolys); 603 644 … … 605 646 606 647 // two new leaves 607 BspLeaf *back = new BspLeaf( );608 BspLeaf *front = new BspLeaf( );648 BspLeaf *back = new BspLeaf(node); 649 BspLeaf *front = new BspLeaf(node); 609 650 610 651 // replace a link from node's parent 611 652 if (parent) 612 {613 653 parent->ReplaceChildLink(leaf, node); 614 } 615 654 616 655 // and setup child links 617 656 node->SetupChildLinks(back, front); 618 619 delete leaf; // leaf not member of tree anymore657 658 DEL_PTR(leaf); // leaf not member of tree anymore 620 659 621 660 return node; 622 661 } 623 662 624 Plane3 BspTree::SelectPlane(PolygonContainer *polygons) const 625 { 663 Plane3 BspTree::SelectPlane(PolygonContainer *polys) const 664 { 665 if (polys->size() == 0) 666 { 667 Debug << "Warning: No split candidate available\n"; 668 return Plane3(); 669 } 670 626 671 // simple strategy: just take next polygon 627 672 if (sSplitPlaneStrategy == NEXT_POLYGON) 628 673 { 629 return poly gons->front()->GetSupportingPlane();674 return polys->front()->GetSupportingPlane(); 630 675 } 631 676 632 677 // use heuristics to find appropriate plane 633 return SelectPlaneHeuristics(poly gons, sMaxCandidates);678 return SelectPlaneHeuristics(polys, sMaxCandidates); 634 679 } 635 680 … … 672 717 if ((sSplitPlaneStrategy == BALANCED_TREE) || (sSplitPlaneStrategy == COMBINED)) 673 718 { 674 sum += EvalForBalancedTree(classification);719 sum += sBalancedTreeTable[classification]; 675 720 } 676 721 677 722 if ((sSplitPlaneStrategy == LEAST_SPLITS) || (sSplitPlaneStrategy == COMBINED)) 678 723 { 679 sum2 += EvalForLeastSplits(classification);724 sum2 += sLeastSplitsTable[classification]; 680 725 } 681 726 } … … 684 729 return abs(sum) + abs(sum2); 685 730 } 686 687 int BspTree::EvalForBalancedTree(const int classification)688 {689 // there should be roughly the same number of front and back polygons690 if (classification == Polygon3::FRONT_SIDE)691 return 1;692 else if (classification == Polygon3::BACK_SIDE)693 return -1;694 695 return 0;696 }697 698 int BspTree::EvalForLeastSplits(const int classification)699 {700 if (classification == Polygon3::SPLIT)701 return 1;702 703 return 0;704 }705 706 731 707 732 void BspTree::ParseEnvironment() … … 729 754 exit(1); 730 755 } 756 757 //-- parse BSP tree construction method 758 char constructionMethodStr[64]; 759 760 environment->GetStringValue("BspTree.constructionMethod", constructionMethodStr); 761 762 sConstructionMethod = BspTree::VIEW_CELLS; 763 764 if (strcmp(constructionMethodStr, "viewCells") == 0) 765 sConstructionMethod = BspTree::VIEW_CELLS; 766 else if (strcmp(constructionMethodStr, "sceneGeometry") == 0) 767 sConstructionMethod = BspTree::SCENE_GEOMETRY; 768 else if (strcmp(constructionMethodStr, "rays") == 0) 769 sConstructionMethod = BspTree::RAYS; 770 else 771 { 772 cerr << "Wrong bsp construction method " << constructionMethodStr << endl; 773 exit(1); 774 } 775 731 776 } 732 777 … … 919 964 BspLeaf *leaf = dynamic_cast<BspLeaf *>(node); 920 965 //ray.leaves.push_back(leaf); 921 966 // TODO 922 967 /*ObjectContainer::const_iterator mi; 923 968 for (mi = leaf->mObjects.begin(); mi != leaf->mObjects.end(); ++mi) -
trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.h
r262 r263 72 72 73 73 int Nodes() const {return nodes;} 74 int Interior() const { return nodes /2; }75 int Leaves() const { return (nodes /2) + 1; }74 int Interior() const { return nodes / 2; } 75 int Leaves() const { return (nodes / 2) + 1; } 76 76 77 77 void Reset() … … 128 128 PolygonContainer *GetPolygons(); 129 129 130 /** Adds polygons to node. 131 */ 132 void AddPolygons(PolygonContainer *polys); 133 130 134 protected: 131 135 … … 143 147 /** Standard contructor taking split plane as argument. 144 148 */ 145 BspInterior( Plane3plane);149 BspInterior(const Plane3 &plane); 146 150 /** @return false since it is an interior node 147 151 */ … … 173 177 protected: 174 178 179 /** Discards or stores polygon in node. 180 @param polys the polygons 181 @param storePolys if the polygons should be stored or discarded 182 */ 183 void ProcessPolygon(Polygon3 *poly, bool storePolys); 184 175 185 /// Splitting plane corresponding to this node 176 186 Plane3 mPlane; … … 188 198 189 199 public: 190 BspLeaf(ViewCell *viewCell = NULL); 200 BspLeaf(); 201 BspLeaf(ViewCell *viewCell); 202 BspLeaf(BspInterior *parent); 191 203 192 204 /** @return true since it is an interior node … … 201 213 202 214 protected: 203 204 /** Helper function used to add remaining polygons to leaf.205 */206 void AddPolygons(PolygonContainer *polys);207 215 208 216 /// polygonal representation of this viewcell … … 239 247 240 248 /// BSP tree construction type 241 enum {VIEW CELLS, SCENE_GEOMETRY, RAYS};249 enum {VIEW_CELLS, SCENE_GEOMETRY, RAYS}; 242 250 243 251 /** Default constructor creating an empty tree. … … 305 313 void Construct(PolygonContainer *polys); 306 314 307 /** Evaluates plane classification with respect to the plane's308 contribution for a balanced tree.309 */310 static inline int EvalForBalancedTree(const int classficiation);311 /** Evaluates plane classification with respect to the plane's312 contribution for a minimum number splits in the tree.313 */314 static inline int EvalForLeastSplits(const int classification);315 316 315 /** Evaluates the contribution of the candidate split plane. 317 316 */ … … 331 330 332 331 /** Selects a splitting plane. 333 @param poly gons the polygon dataon which the split decition is based334 */ 335 Plane3 SelectPlane(PolygonContainer *poly gons) const;332 @param polys the polygon list on which the split decition is based 333 */ 334 Plane3 SelectPlane(PolygonContainer *polys) const; 336 335 337 336 /** Filters next viewcell down the tree and inserts it into the appropriate leaves … … 391 390 int CastRay(Ray &ray); 392 391 393 /** Discards or stores polygons in leaf and deletes the container. 394 @param polys the polygons 395 @param leaf the leaf where polygons are stored 396 */ 397 bool ProcessPolygons(PolygonContainer *polys, BspLeaf *node); 392 398 393 399 394 /// Pointer to the root of the tree … … 433 428 /// number of candidates evaluated for the next split plane 434 429 static int sMaxCandidates; 430 /// BSP tree construction method 431 static int sConstructionMethod; 432 433 private: 434 /** Evaluates split plane classification with respect to the plane's 435 contribution for a balanced tree. 436 */ 437 static int sLeastSplitsTable[4]; 438 /** Evaluates split plane classification with respect to the plane's 439 contribution for a minimum number splits in the tree. 440 */ 441 static int sBalancedTreeTable[4]; 435 442 }; 436 443 -
trunk/VUT/GtpVisibilityPreprocessor/src/X3dExporter.cpp
r262 r263 274 274 } 275 275 276 void X3dExporter::ExportPolygons(PolygonContainer *polys) 277 { 278 stream << "<Shape>" << endl; 279 stream << "<Appearance>" << endl; 280 281 // $$ tmp -> random material 282 283 float r, g, b; 284 285 if (mUseForcedMaterial) 286 { 287 r = mForcedMaterial.mDiffuseColor.r; 288 g = mForcedMaterial.mDiffuseColor.g; 289 b = mForcedMaterial.mDiffuseColor.b; 290 } 291 else 292 { 293 r = RandomValue(0.5, 1.0); 294 g = RandomValue(0.5, 1.0); 295 b = RandomValue(0.5, 1.0); 296 } 297 298 stream << "<Material diffuseColor=\"" << r << " " << g << " " << b 299 << "\" specularColor=\"0.0 0.0 0.0\"/>" << endl; 300 301 stream << "</Appearance>" << endl; 302 303 304 //-- create and write indices 305 if (mWireframe) 306 stream << "<IndexedLineSet ccw=\"TRUE\" coordIndex=\"" << endl; 307 else 308 stream << "<IndexedFaceSet ccw=\"TRUE\" coordIndex=\"" << endl; 309 310 int index = 0; 311 312 PolygonContainer::const_iterator pit; 313 314 VertexContainer::const_iterator vi; 315 316 for (pit = polys->begin(); pit != polys->end(); ++pit) 317 { 318 Polygon3 *poly = *pit; 319 for (vi = poly->mVertices.begin(); vi != poly->mVertices.end(); ++vi) 320 { 321 stream << index ++ << " "; 322 } 323 stream << "-1" << endl; 324 } 325 326 stream << "\" >" << endl; 327 328 stream << "<Coordinate point=\"" << endl; 329 for (pit = polys->begin(); pit != polys->end(); ++pit) 330 { 331 Polygon3 *poly = *pit; 332 for (vi = poly->mVertices.begin(); vi != poly->mVertices.end(); ++vi) 333 { 334 stream << (*vi).x << " " << (*vi).y << " " << (*vi).z; 335 stream << "," << endl; 336 } 337 } 338 stream << "\" >" << endl; 339 stream << "</Coordinate>" << endl; 340 341 if (mWireframe) 342 stream << "</IndexedLineSet>" << endl; 343 else 344 stream << "</IndexedFaceSet>" << endl; 345 346 stream << "</Shape>" << endl; 347 } 276 348 277 349 bool … … 305 377 if (mExportRayDensity) 306 378 { 307 return false;//ExportKdTreeRayDensity(tree);379 return ExportBspTreeRayDensity(tree); 308 380 } 309 381 … … 340 412 341 413 } 342 else 414 else if (!tree.StorePolys()) 343 415 { 344 BspLeaf *leaf = dynamic_cast<BspLeaf *>(node);416 ViewCell *viewCell = dynamic_cast<BspLeaf *>(node)->GetViewCell(); 345 417 346 // export view cell geometry 347 348 if (!tree.StorePolys() && leaf->GetViewCell()) 349 { 350 ExportViewCell(leaf->GetViewCell()); 351 } 352 418 if (viewCell) // export view cell geometry 419 ExportViewCell(viewCell); 353 420 } 354 355 356 421 } 422 423 return true; 357 424 } 358 425 … … 402 469 } 403 470 471 472 bool 473 X3dExporter::ExportBspTreeRayDensity(const BspTree &tree) 474 { 475 // TODO 476 return true; 477 } 404 478 405 479 bool -
trunk/VUT/GtpVisibilityPreprocessor/src/X3dExporter.h
r261 r263 50 50 ExportPolygon(Polygon3 *poly); 51 51 52 virtual void ExportPolygons(PolygonContainer *polys); 53 52 54 virtual bool 53 55 ExportBox(const AxisAlignedBox3 &box); … … 75 77 ExportKdTreeRayDensity(const KdTree &tree); 76 78 77 79 bool 80 ExportBspTreeRayDensity(const BspTree &tree); 78 81 }; 79 82 -
trunk/VUT/GtpVisibilityPreprocessor/src/main.cpp
r261 r263 35 35 environment->GetStringValue("Scene.viewcells", buff); 36 36 37 string viewCellsFile(buff); 38 p->LoadViewCells(viewCellsFile); 37 string vcFileName(buff); 39 38 39 // if BSP tree construction method needs predefined view cells 40 if (BspTree::sConstructionMethod == BspTree::VIEW_CELLS) 41 { 42 if (vcFileName != "") 43 p->LoadViewCells(vcFileName); 44 else 45 p->GenerateViewCells(); 46 } 47 48 p->BuildBspTree(); 40 49 p->BspTreeStatistics(Debug); 50 p->Export(filename + "-bsptree.x3d", false, false, true); 51 41 52 #endif 42 53 … … 44 55 if (0) { 45 56 p->Export(filename + "-out.x3d", true, false, false); 46 p->Export(filename + "-kdtree.x3d", false, true, false); 57 p->Export(filename + "-kdtree.x3d", false, true, false); 47 58 } 48 59
Note: See TracChangeset
for help on using the changeset viewer.