Changeset 260 for trunk/VUT/GtpVisibilityPreprocessor/src
- Timestamp:
- 09/08/05 01:52:52 (19 years ago)
- Location:
- trunk/VUT/GtpVisibilityPreprocessor/src
- Files:
-
- 2 added
- 15 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/VUT/GtpVisibilityPreprocessor/src/Environment.cpp
r238 r260 1066 1066 optString, 1067 1067 "-scene_filename=", 1068 "soda.x3d"); 1068 "atlanta2.x3d"); 1069 1070 RegisterOption("Scene.viewcells", 1071 optString, 1072 "-viewcells_filename=", 1073 "atlanta_viewcells_large.x3d"); 1069 1074 1070 1075 RegisterOption("Unigraphics.meshGrouping", … … 1179 1184 optInt, 1180 1185 "-bsp_max_viewcells=", 1181 " 100");1186 "9999"); 1182 1187 } 1183 1188 -
trunk/VUT/GtpVisibilityPreprocessor/src/Polygon3.cpp
r256 r260 35 35 void Polygon3::DeletePolygons(PolygonContainer *polys) 36 36 { 37 // don't need to store polygon information => delete polygons38 37 while(!polys->empty()) 39 38 { 40 Polygon3 *poly = polys->back();39 DEL_PTR(polys->back()); 41 40 polys->pop_back(); 42 DEL_PTR(poly);43 41 } 44 42 } -
trunk/VUT/GtpVisibilityPreprocessor/src/Preprocessor.cpp
r242 r260 79 79 else if (strcmp(constructionMethodStr, "sceneGeometry") == 0) 80 80 constructionMethod = BspTree::SCENE_GEOMETRY; 81 else if (strcmp(constructionMethodStr, "rays") == 0) 82 constructionMethod = BspTree::RAYS; 81 83 else 82 84 { -
trunk/VUT/GtpVisibilityPreprocessor/src/Pvs.h
r240 r260 85 85 int Compress() {return 0;} 86 86 87 int GetSize() {return mEntries.size();}87 int GetSize() {return (int)mEntries.size();} 88 88 89 89 void GetData(const int index, -
trunk/VUT/GtpVisibilityPreprocessor/src/SceneGraph.cpp
r176 r260 50 50 return number; 51 51 } 52 53 -
trunk/VUT/GtpVisibilityPreprocessor/src/ViewCell.cpp
r256 r260 76 76 } 77 77 } 78 79 ViewCell *ViewCell::Convert2ViewCell(Face *face, float scale) 80 { 81 // TODO: delete mesh 82 Mesh *mesh = new Mesh(); 83 mesh->mFaces.push_back(face); 84 85 86 return new ViewCell(mesh); 87 } -
trunk/VUT/GtpVisibilityPreprocessor/src/ViewCell.h
r239 r260 51 51 ViewCellContainer &viewCells, 52 52 const int maxViewCells); 53 54 static ViewCell *Convert2ViewCell(Face *face); 53 55 protected: 54 56 -
trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.cpp
r258 r260 45 45 } 46 46 47 PolygonContainer *BspNode::GetPolygons() 48 { 49 return &mPolygons; 50 } 51 47 52 /****************************************************************/ 48 53 /* class BspInterior implementation */ … … 94 99 PolygonContainer *frontPolys, 95 100 PolygonContainer *backPolys, 96 int &splits )101 int &splits, bool storePolys) 97 102 { 98 103 while (!polys->empty()) … … 110 115 { 111 116 case Polygon3::COINCIDENT: 117 // same sides => discard 118 if (DotProd(poly->GetSupportingPlane().mNormal, mPlane.mNormal) > 0) 119 { 120 if (storePolys) 121 mPolygons.push_back(poly); 122 else 123 DEL_PTR(poly); 124 } 125 else 126 backPolys->push_back(poly); 112 127 break; // TODO: compare normals 113 128 case Polygon3::FRONT_SIDE: … … 127 142 backPolys->push_back(back_piece); 128 143 144 if (storePolys) 145 mPolygons.push_back(poly); 146 else 147 DEL_PTR(poly); 129 148 #ifdef _DEBUG 130 //Debug << "split " << poly << endl << front << endl << back << endl;149 Debug << "split " << poly << endl << front << endl << back << endl; 131 150 #endif 132 // don't need polygon anymore133 DEL_PTR(poly);134 135 151 break; 136 152 default: 137 153 Debug << "SHOULD NEVER COME HERE\n"; 138 154 break; 139 155 } 140 156 } 157 158 // contains nothing 159 delete polys; 141 160 } 142 161 … … 154 173 } 155 174 175 void BspLeaf::SetViewCell(ViewCell *viewCell) 176 { 177 mViewCell = viewCell; 178 } 179 156 180 bool BspLeaf::IsLeaf() const 157 181 { … … 159 183 } 160 184 161 185 void BspLeaf::AddPolygons(PolygonContainer *polys) 186 { 187 while (!polys->empty()) 188 { 189 mPolygons.push_back(polys->back()); 190 polys->pop_back(); 191 } 192 } 162 193 /****************************************************************/ 163 194 /* class BspTree implementation */ 164 195 /****************************************************************/ 165 196 166 BspTree::BspTree(): mTermMaxPolygons(0), mTermMaxDepth(0), mRoot(NULL) 197 BspTree::BspTree(): 198 mTermMaxPolygons(0), 199 mTermMaxDepth(0), 200 mRoot(NULL), 201 mIsIncremential(false), 202 mStorePolys(false) 167 203 { 168 204 Randomize(); // initialise random generator for heuristics … … 243 279 tStack.pop(); 244 280 281 /// if we store 282 if (mStorePolys) 283 Polygon3::DeletePolygons(&node->mPolygons); 284 245 285 if (!node->IsLeaf()) 246 286 { … … 248 288 249 289 // push the children on the stack (there are always two children) 250 interior->GetBack()->mParent = NULL;251 interior->GetFront()->mParent = NULL;252 253 290 tStack.push(interior->GetBack()); 254 291 tStack.push(interior->GetFront()); … … 268 305 // copy polygon information to guide the split process 269 306 AddMesh2Polygons(viewCell->GetMesh(), polys); 270 mBox.Include(viewCell->GetBox()); // a lso add to BSP root box307 mBox.Include(viewCell->GetBox()); // add to BSP aabb 271 308 272 309 BspNode *firstNode = mRoot ? mRoot : new BspLeaf(); // traverse tree or create new one … … 292 329 // split viecell polygons with respect to split plane 293 330 interior->SplitPolygons(tData.mPolygons, frontPolys, backPolys, splits); 331 294 332 mStat.splits += splits; 295 333 296 334 // push the children on the stack 297 if (frontPolys->size() > 0) // if polygons on this side of bsp tree 335 if (frontPolys->size() > 0) // if polygons on front side of bsp tree 336 { 298 337 tStack.push(BspTraversalData(interior->GetFront(), interior->GetParent(), 299 338 frontPolys, tData.mDepth + 1)); 300 else 339 } 340 else // front side polygons empty 301 341 delete frontPolys; 302 342 303 if (backPolys->size() > 0) // if polygons on this side of bsp tree 343 if (backPolys->size() > 0) // if polygons on backc side of bsp tree 344 { 304 345 tStack.push(BspTraversalData(interior->GetBack(), interior->GetParent(), 305 346 backPolys, tData.mDepth + 1)); 306 else 347 } 348 else // back side polygons empty 307 349 delete backPolys; 308 350 } 309 351 else // reached leaf => subdivide current viewcell 310 352 { 311 BspNode *root = Subdivide(tStack, tData, NULL); 312 313 if (!mRoot) // take as root if there is none yet 353 BspNode *root = Subdivide(tStack, tData, viewCell); 354 355 // tree empty => new root 356 if (!mRoot) 314 357 mRoot = root; 315 358 } … … 317 360 } 318 361 319 void BspTree::Construct(const ViewCellContainer &viewCells) 320 { 321 // for this type of construction we split until no polygons is left 322 mTermMaxPolygons = 0; 323 mTermMaxDepth = sTermMaxDepth; 324 362 void BspTree::InitTree(int maxPolygons, int maxDepth) 363 { 364 mTermMaxPolygons = maxPolygons; 365 mTermMaxDepth = maxDepth; 325 366 mStat.nodes = 1; 326 327 // insert all viewcells 328 ViewCellContainer::const_iterator it; 329 330 for (it = viewCells.begin(); it != viewCells.end(); ++ it) 331 { 332 InsertViewCell(*it); 333 } 334 } 367 mBox.Initialize(); // initialise bsp tree bounding box 368 } 369 370 335 371 336 372 void BspTree::AddMesh2Polygons(Mesh *mesh, PolygonContainer &polys) … … 346 382 } 347 383 348 void BspTree::Copy2PolygonSoup(const ObjectContainer &objects, PolygonContainer &polys, int maxObjects) 349 { 350 ObjectContainer::const_iterator it, it_end = objects.end(); 351 352 int limit = (maxObjects > 0) ? Min((int)objects.size(), maxObjects) : (int)objects.size(); 353 354 // initialise bounding box 355 mBox.Initialize(); 384 void BspTree::Copy2PolygonSoup(const ViewCellContainer &viewCells, PolygonContainer &polys, int maxObjects) 385 { 386 int limit = (maxObjects > 0) ? Min((int)viewCells.size(), maxObjects) : (int)viewCells.size(); 356 387 357 388 for (int i = 0; i < limit; ++i) 358 389 { 390 if (viewCells[i]->GetMesh()) // copy the mesh data to polygons 391 { 392 mBox.Include(viewCells[i]->GetBox()); // add to BSP tree aabb 393 AddMesh2Polygons(viewCells[i]->GetMesh(), polys); 394 } 395 } 396 } 397 398 void BspTree::Copy2PolygonSoup(const ObjectContainer &objects, PolygonContainer &polys, int maxObjects) 399 { 400 int limit = (maxObjects > 0) ? Min((int)objects.size(), maxObjects) : (int)objects.size(); 401 402 for (int i = 0; i < limit; ++i) 403 { 359 404 Intersectable *object = objects[i];//*it; 360 405 Mesh *mesh = NULL; 361 406 362 // extract the meshes 363 switch (object->Type()) 407 switch (object->Type()) // extract the meshes 364 408 { 365 409 case Intersectable::MESH_INSTANCE: … … 376 420 if (mesh) // copy the mesh data to polygons 377 421 { 378 mBox.Include(object->GetBox()); // a lso add to BSP root box422 mBox.Include(object->GetBox()); // add to BSP tree aabb 379 423 AddMesh2Polygons(mesh, polys); 380 424 } 381 425 } 382 426 383 Debug << "Number of polygons: " << polys.size() << ", BSP root box: " << mBox << endl; 384 } 385 386 void BspTree::Construct(const ObjectContainer &objects) 387 { 427 Debug << "Number of polygons: " << (int)polys.size() << ", BSP root box: " << mBox << endl; 428 } 429 430 void BspTree::Construct(const ViewCellContainer &viewCells) 431 { 432 //-- Construct tree using the given viewcells 433 434 /* for this type of construction we filter all viewcells down the 435 * tree until there is no polygon left. The split of the last polygon 436 * decides inside or outside of the viewcell. 437 */ 438 const int maxPolygons = 0; 439 const int maxDepth = 99999; 440 InitTree(maxPolygons, maxDepth); 441 442 443 // tree is completely constructed before 444 // view cells are not inserted one after another => better tree behaviour 445 if (!mIsIncremential) 446 { 447 // copy view cell meshes into one big polygon soup 448 PolygonContainer *polys = new PolygonContainer(); 449 Copy2PolygonSoup(viewCells, *polys, sMaxCandidates); 450 451 // construct tree from viewcell polygons 452 Construct(polys); 453 } 454 455 // insert all viewcells 456 ViewCellContainer::const_iterator it; 457 458 for (it = viewCells.begin(); it != viewCells.end(); ++ it) 459 { 460 InsertViewCell(*it); 461 } 462 } 463 464 465 ViewCellContainer *BspTree::Construct(const ObjectContainer &objects) 466 { 467 #ifdef _DEBUG 388 468 Debug << "Constructing tree using object container\n"; 389 390 mTermMaxPolygons = sTermMaxPolygons; 391 mTermMaxDepth = sTermMaxDepth; 392 393 mStat.nodes = 1; 394 469 #endif 470 // take termination criteria from globals 471 InitTree(mTermMaxPolygons, mTermMaxDepth); 472 473 PolygonContainer *polys = new PolygonContainer(); 474 475 // copy mesh instance polygons into one big polygon soup 476 Copy2PolygonSoup(objects, *polys, sMaxCandidates); 477 478 // construct tree from polygon soup 479 Construct(polys); 480 481 return NULL;// TODO 482 } 483 484 ViewCellContainer *BspTree::Construct(const RayContainer &rays) 485 { 486 // TODO 487 return NULL; 488 } 489 490 void BspTree::Construct(PolygonContainer *polys) 491 { 395 492 std::stack<BspTraversalData> tStack; 396 PolygonContainer *polys = new PolygonContainer(); 397 398 // copy mesh instance polygons into one big polygon soup 399 Copy2PolygonSoup(objects, *polys, 100); 400 401 BspTraversalData tData(new BspLeaf(), mRoot->GetParent(), polys, 0); // new root corresponding to unbounded space 493 // new root corresponding to unbounded space 494 BspTraversalData tData(new BspLeaf(), mRoot->GetParent(), polys, 0); 402 495 403 496 tStack.push(tData); … … 411 504 BspNode *root = Subdivide(tStack, tData); 412 505 413 if (!mRoot) 506 if (!mRoot) // empty tree => new root 414 507 mRoot = root; 415 508 } 416 509 } 417 510 418 BspNode * BspTree::Subdivide(BspTraversalStack &tStack, BspTraversalData &tData, ViewCell *viewCell) 511 512 BspNode * BspTree::Subdivide(BspTraversalStack &tStack, 513 BspTraversalData &tData, 514 ViewCell *viewCell) 419 515 { 420 516 PolygonContainer *backPolys = new PolygonContainer(); … … 425 521 tData.mPolygons, 426 522 tData.mDepth, 427 viewCell,428 523 frontPolys, 429 524 backPolys); … … 440 535 { 441 536 EvaluateLeafStats(tData); 442 // don't need to store polygon information => delete polygons 443 Polygon3::DeletePolygons(tData.mPolygons); 444 } 445 537 538 // add view cell if in positive halfspace 539 if (!tData.mParent || (node == tData.mParent->GetFront())) 540 dynamic_cast<BspLeaf *>(node)->SetViewCell(viewCell); 541 } 542 543 return node; 544 } 545 546 BspNode *BspTree::SubdivideNode(BspLeaf *leaf, 547 BspInterior *parent, 548 PolygonContainer *polys, 549 const int depth, 550 PolygonContainer *frontPolys, 551 PolygonContainer *backPolys) 552 { 553 // terminate traversal 554 if ((polys->size() <= mTermMaxPolygons) || (depth >= mTermMaxDepth)) 555 { 556 // add or delete remaining polygons 557 if (mStorePolys) 558 leaf->AddPolygons(polys); 559 else 560 Polygon3::DeletePolygons(polys); 561 562 delete polys; 563 564 return leaf; 565 } 566 567 mStat.nodes += 2; 568 569 // add the new nodes to the tree + select subdivision plane 570 BspInterior *node = new BspInterior(SelectPlane(polys)); 571 572 #ifdef _DEBUG 573 Debug << node << endl; 574 #endif 575 // split polygon according to current plane 576 int splits = 0; 577 578 node->SplitPolygons(polys, frontPolys, backPolys, splits, mStorePolys); 579 580 mStat.splits += splits; 581 582 // two new leaves 583 BspLeaf *back = new BspLeaf(); 584 BspLeaf *front = new BspLeaf(); 585 586 // replace a link from node's parent 587 if (parent) 588 { 589 parent->ReplaceChildLink(leaf, node); 590 } 591 592 // and setup child links 593 node->SetupChildLinks(back, front); 594 595 delete leaf; // leaf not member of tree anymore 596 446 597 return node; 447 598 } … … 455 606 } 456 607 608 // use heuristics to find appropriate plane 457 609 return SelectPlaneHeuristics(polygons, sMaxCandidates); 458 610 } … … 511 663 int BspTree::EvalForBalancedTree(const int classification) 512 664 { 665 // there should be roughly the same number of front and back polygons 513 666 if (classification == Polygon3::FRONT_SIDE) 514 667 return 1; … … 527 680 } 528 681 529 BspNode *BspTree::SubdivideNode(BspLeaf *leaf,530 BspInterior *parent,531 PolygonContainer *polys,532 const int depth,533 ViewCell *viewCell,534 PolygonContainer *frontPolys,535 PolygonContainer *backPolys)536 {537 // terminate traversal538 if ((polys->size() <= mTermMaxPolygons) || (depth >= mTermMaxDepth))539 {540 return leaf;541 }542 543 mStat.nodes += 2;544 545 // add the new nodes to the tree + select subdivision plane546 BspInterior *node = new BspInterior(SelectPlane(polys));547 548 #ifdef _DEBUG549 Debug << node << endl;550 #endif551 // split polygon according to current plane552 int splits = 0;553 int polySize = polys->size();554 555 node->SplitPolygons(polys, frontPolys, backPolys, splits);556 557 mStat.splits += splits;558 559 // two new leaves560 BspLeaf *back = new BspLeaf();561 BspLeaf *front = new BspLeaf(viewCell);562 563 // replace a link from node's parent564 if (parent)565 {566 parent->ReplaceChildLink(leaf, node);567 }568 569 // and setup child links570 node->SetupChildLinks(back, front);571 572 DEL_PTR(leaf); // leaf not member of tree anymore573 574 return node;575 }576 682 577 683 void BspTree::ParseEnvironment() … … 648 754 if (!viewcell->Mailed()) 649 755 { 650 viewcell->Mail(); 756 viewcell->Mail(); // what does mail mean? 651 757 652 758 // add this node to pvs of all nodes it can see … … 686 792 } 687 793 794 bool BspTree::StorePolys() const 795 { 796 return mStorePolys; 797 } 688 798 void BspTree::EvaluateLeafStats(const BspTraversalData &data) 689 799 { … … 696 806 } 697 807 698 // recordmaximal depth808 // store maximal depth 699 809 if (data.mDepth > mStat.maxDepth) 700 810 mStat.maxDepth = data.mDepth; … … 732 842 BspNode *farChild; 733 843 734 float position; 735 736 while (1) // endless loop 844 while (1) 737 845 { 738 846 if (!node->IsLeaf()) … … 781 889 // find intersection with plane between ray origin and exit point 782 890 extp = splitPlane->FindIntersection(ray.GetLoc(), extp, &maxt); 891 783 892 } else // compute intersections with objects in leaf 784 893 { … … 816 925 tStack.pop(); 817 926 } 818 819 return hits; 820 }927 } 928 929 return hits; 821 930 } 822 931 -
trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.h
r242 r260 13 13 class Polygon3; 14 14 class AxisAlignedBox3; 15 15 class Ray; 16 16 17 17 //namespace GtpVisibilityPreprocessor { … … 19 19 /** Container storing a soup of polygons used during BSP tree construction 20 20 */ 21 typedef std::vector<Polygon3 *> PolygonContainer; 21 typedef vector<Polygon3 *> PolygonContainer; 22 typedef vector<Ray *> RayContainer; 22 23 23 24 struct BspRayTraversalData … … 125 126 void SetParent(BspInterior *parent); 126 127 128 PolygonContainer *GetPolygons(); 129 127 130 protected: 128 131 129 132 /// parent of this node 130 133 BspInterior *mParent; 134 135 PolygonContainer mPolygons; 131 136 }; 132 137 … … 158 163 */ 159 164 void SplitPolygons(PolygonContainer *polys, PolygonContainer *frontPolys, 160 PolygonContainer *backPolys, int &splits );165 PolygonContainer *backPolys, int &splits, bool storePolys = false); 161 166 162 167 friend ostream &operator<<(ostream &s, const BspInterior &A) … … 180 185 class BspLeaf : public BspNode 181 186 { 187 friend BspTree; 188 182 189 public: 183 190 BspLeaf(ViewCell *viewCell = NULL); 184 191 185 /** @return true since it is an interior node */ 192 /** @return true since it is an interior node 193 */ 186 194 bool IsLeaf() const; 195 /** Returns pointer from view cell. 196 */ 187 197 ViewCell *GetViewCell(); 198 /** Sets pointer to view cell. 199 */ 200 void SetViewCell(ViewCell *viewCell); 188 201 189 202 protected: 203 204 /** Helper function used to add remaining polygons to leaf. 205 */ 206 void AddPolygons(PolygonContainer *polys); 190 207 191 208 /// polygonal representation of this viewcell … … 222 239 223 240 /// BSP tree construction type 224 enum {VIEWCELLS, SCENE_GEOMETRY };241 enum {VIEWCELLS, SCENE_GEOMETRY, RAYS}; 225 242 226 243 /** Default constructor creating an empty tree. … … 232 249 const BspTreeStatistics &GetStatistics() const; 233 250 234 /** Constructs tree using the given list of view cells.235 A pointer to the appropriate view cell is stored within each leaf.251 /** Constructs tree using the given list of view cells. 252 A pointer to the appropriate view cell is stored within each leaf. 236 253 Many leafs can point to the same viewcell. 237 254 */ 238 255 void Construct(const ViewCellContainer &viewCells); 239 /** Constructs tree using the given list of objects. Each leaf is taken as viewcell. 240 No objects are treated as viewcells explicitly. 256 257 /** Constructs tree using the given list of objects. 258 Note that the objects are not taken as view cells, but the view cells are 259 constructed from the subdivision: Each leaf is taken as one viewcell; 241 260 242 261 @param objects list of objects 243 */ 244 void Construct(const ObjectContainer &objects); 262 @returns list of view cells. 263 */ 264 ViewCellContainer *Construct(const ObjectContainer &objects); 265 266 /** Constructs tree using the given number of rays 267 @param objects list of objects 268 @returns list of view cells. 269 */ 270 ViewCellContainer *Construct(const RayContainer &rays); 245 271 246 272 int CollectLeafPvs(); … … 255 281 */ 256 282 BspNode *GetRoot() const; 283 284 /** If the view cell polygons are stored in the nodes. 285 */ 286 bool StorePolys() const; 257 287 258 288 protected: 259 289 290 /** Initialises BSP tree. 291 @param maxPolygons the maximal polygon count before termination of 292 subdivision 293 @param maxDepth the maximal depth before termination of 294 subdivision 295 */ 296 void InitTree(int maxPolygons, int maxDepth); 297 298 /** Constructs the tree from the given list of polygons. 299 */ 300 void Construct(PolygonContainer *polys); 301 260 302 /** Evaluates plane classification with respect to the plane's 261 303 contribution for a balanced tree. … … 301 343 @param backPolys the polygons of the back child node as a result from splitting 302 344 */ 303 BspNode *SubdivideNode(BspLeaf *leaf, BspInterior *parent, 304 PolygonContainer *polys, const int depth, 305 ViewCell *viewCell, 306 PolygonContainer *frontPolys, PolygonContainer *backPolys); 345 BspNode *SubdivideNode(BspLeaf *leaf, 346 BspInterior *parent, 347 PolygonContainer *polys, 348 const int depth, 349 PolygonContainer *frontPolys, 350 PolygonContainer *backPolys); 307 351 308 352 /** Filters polygons down the tree. … … 321 365 Plane3 SelectPlaneHeuristics(PolygonContainer *polygons, int maxTests) const; 322 366 323 /** Extracts the meshes of the objects and copies them into the mesh. Also calculcates the bounding box of the tree. 367 /** Extracts the meshes of the objects and copies them into the mesh. 368 Adds object aabb to the aabb of the tree. 324 369 @param maxPolys the maximal number of objects to be stored as polygons 325 370 */ 326 371 void Copy2PolygonSoup(const ObjectContainer &objects, PolygonContainer &polys, int maxObjects); 372 /** Extracts the meshes of the view cells and copies them into the mesh. 373 Adds view cell aabb to the aabb of the tree. 374 @param maxPolys the maximal number of objects to be stored as polygons 375 */ 376 void Copy2PolygonSoup(const ViewCellContainer &viewCells, PolygonContainer &polys, int maxObjects); 327 377 328 378 /** Add this mesh as polygons to polygon container. … … 353 403 /// box around the whole view domain 354 404 AxisAlignedBox3 mBox; 405 406 /// if view cell calculation is incremential 407 bool mIsIncremential; 408 409 /// if polygons should be stored in the tree 410 bool mStorePolys; 355 411 356 412 public: -
trunk/VUT/GtpVisibilityPreprocessor/src/X3dExporter.cpp
r242 r260 7 7 #include "ViewCellBsp.h" 8 8 #include "ViewCell.h" 9 #include "Polygon3.h" ;9 #include "Polygon3.h" 10 10 11 11 … … 296 296 Mesh *mesh = new Mesh; 297 297 298 AxisAlignedBox3 box = tree.GetBoundingBox();299 ExportBox(box);300 301 298 //AxisAlignedBox3 box = tree.GetBoundingBox(); 299 //ExportBox(box); 300 301 while (!tStack.empty()) 302 302 { 303 303 BspNode *node = tStack.top(); … … 305 305 tStack.pop(); 306 306 307 if (tree.StorePolys()) // extract the polygons 308 { 309 PolygonContainer::const_iterator it; 310 PolygonContainer::const_iterator it_end = node->GetPolygons()->end(); 311 312 for (it = node->GetPolygons()->begin(); it != it_end; ++ it) 313 ExportPolygon(*it); 314 } 315 307 316 if (!node->IsLeaf()) 308 317 { … … 311 320 tStack.push(interior->GetFront()); 312 321 tStack.push(interior->GetBack()); 322 313 323 } 314 324 else 315 325 { 316 326 BspLeaf *leaf = dynamic_cast<BspLeaf *>(node); 317 // NOTE: could also export polygons to see if splits work318 if ( leaf->GetViewCell())327 // export view cell geometry 328 if (!tree.StorePolys() && leaf->GetViewCell()) 319 329 ExportViewCell(leaf->GetViewCell()); 320 330 } 321 331 } 322 332 323 ExportMesh(mesh);324 delete mesh;325 333 return true; 326 334 } -
trunk/VUT/GtpVisibilityPreprocessor/src/X3dExporter.h
r242 r260 47 47 48 48 virtual void 49 49 ExportPolygon(Polygon3 *poly); 50 50 51 51 virtual bool … … 61 61 ExportMesh(Mesh *mesh); 62 62 63 virtual void ExportViewCell(ViewCell *viewCell); 63 virtual void 64 ExportViewCell(ViewCell *viewCell); 64 65 65 66 protected: -
trunk/VUT/GtpVisibilityPreprocessor/src/X3dParser.cpp
r182 r260 374 374 375 375 376 377 /*********************************************************** 378 * class X3dViewCellsParser implemenation * 379 ***********************************************************/ 380 381 382 // --------------------------------------------------------------------------- 383 // StdInParseHandlers: Constructors and Destructor 384 // --------------------------------------------------------------------------- 385 X3dViewCellsParser::X3dViewCellsParser(ViewCellContainer *viewCells) : 386 mElementCount(0) 387 , mAttrCount(0) 388 , mCharacterCount(0) 389 , mSpaceCount(0) 390 , mViewCells(viewCells) 391 { 392 } 393 394 X3dViewCellsParser::~X3dViewCellsParser() 395 { 396 } 397 398 399 // --------------------------------------------------------------------------- 400 // StdInParseHandlers: Implementation of the SAX DocumentHandler interface 401 // --------------------------------------------------------------------------- 402 void X3dViewCellsParser::endElement(const XMLCh* const name) 403 { 404 StrX lname(name); 405 string element(lname.LocalForm()); 406 if (element == "Shape") 407 EndShape(); 408 } 409 410 void 411 X3dViewCellsParser::EndShape() 412 { 413 } 414 415 void 416 X3dViewCellsParser::StartIndexedFaceSet( 417 AttributeList& attributes) 418 { 419 int len = attributes.getLength(); 420 int i; 421 VertexIndexContainer vertices; 422 423 for (i=0; i < len; i++) 424 { 425 string attrName(StrX(attributes.getName(i)).LocalForm()); 426 427 if (attrName == "coordIndex") 428 { 429 StrX attrValue(attributes.getValue(i)); 430 431 // handle coordIndex 432 vertices.clear(); 433 const char *ptr = attrValue.LocalForm(); 434 char *endptr; 435 436 while(1) 437 { 438 int index = strtol(ptr, &endptr, 10); 439 440 if (ptr == endptr || index == -1) 441 { 442 if (vertices.size() > 2) 443 { 444 // the base of all view cells is a triangle. 445 Face *face = new Face(vertices); 446 447 mViewCells->push_back(ViewCell::Convert2ViewCell(face)); 448 } 449 vertices.clear(); 450 451 if (ptr == endptr) 452 break; 453 } 454 else 455 { 456 vertices.push_back(index); 457 } 458 459 ptr = endptr; 460 } 461 } 462 } 463 } 464 465 466 void 467 X3dViewCellsParser::StartCoordinate( 468 AttributeList& attributes) 469 { 470 int len = attributes.getLength(); 471 472 VertexContainer vertices; 473 474 for (int i=0; i < len; i++) 475 { 476 string attrName(StrX(attributes.getName(i)).LocalForm()); 477 478 if (attrName == "point") 479 { 480 StrX attrValue(attributes.getValue(i)); 481 482 const char *ptr = attrValue.LocalForm(); 483 484 char *endptr; 485 486 while (1) 487 { 488 float x = strtod(ptr, &endptr); 489 490 if (ptr == endptr) 491 break; 492 ptr = endptr; 493 494 float y = strtod(ptr, &endptr); 495 496 497 if (ptr == endptr) 498 break; 499 ptr = endptr; 500 501 float z = strtod(ptr, &endptr); 502 503 if (ptr == endptr) 504 break; 505 506 ptr = endptr; 507 if (*ptr == ',') 508 ptr++; 509 510 Vector3 v(x, y, z); 511 vertices.push_back(v); 512 } 513 mCurrentMesh->mVertices = vertices; 514 } 515 } 516 } 517 518 519 void 520 X3dViewCellsParser::startElement(const XMLCh* const name, 521 AttributeList& attributes) 522 { 523 StrX lname(name); 524 string element(lname.LocalForm()); 525 526 if (element == "IndexedFaceSet") { 527 // create a new mesh node in the scene graph 528 StartIndexedFaceSet(attributes); 529 } 530 531 if (element == "Shape") { 532 cout<<"+"; 533 mCurrentMesh = new Mesh; 534 } 535 536 if (element == "Coordinate") { 537 if (mCurrentMesh) 538 StartCoordinate(attributes); 539 } 540 541 if (element == "Material") { 542 StartMaterial(attributes); 543 } 544 545 mElementCount++; 546 mAttrCount += attributes.getLength(); 547 } 548 549 void 550 X3dViewCellsParser::characters(const XMLCh* const chars, 551 const unsigned int length) 552 { 553 mCharacterCount += length; 554 } 555 556 void 557 X3dViewCellsParser::ignorableWhitespace(const XMLCh* const chars, 558 const unsigned int length) 559 { 560 mSpaceCount += length; 561 } 562 563 void 564 X3dViewCellsParser::resetDocument() 565 { 566 mAttrCount = 0; 567 mCharacterCount = 0; 568 mElementCount = 0; 569 mSpaceCount = 0; 570 } 571 572 573 574 // --------------------------------------------------------------------------- 575 // StdInParseHandlers: Overrides of the SAX ErrorHandler interface 576 // --------------------------------------------------------------------------- 577 void 578 X3dViewCellsParser::error(const SAXParseException& e) 579 { 580 XERCES_STD_QUALIFIER cerr << "\nError at (file " << StrX(e.getSystemId()) 581 << ", line " << e.getLineNumber() 582 << ", char " << e.getColumnNumber() 583 << "): " << StrX(e.getMessage()) << XERCES_STD_QUALIFIER endl; 584 } 585 586 void 587 X3dViewCellsParser::fatalError(const SAXParseException& e) 588 { 589 XERCES_STD_QUALIFIER cerr << "\nFatal Error at (file " << StrX(e.getSystemId()) 590 << ", line " << e.getLineNumber() 591 << ", char " << e.getColumnNumber() 592 << "): " << StrX(e.getMessage()) << XERCES_STD_QUALIFIER endl; 593 } 594 595 void 596 X3dViewCellsParser::warning(const SAXParseException& e) 597 { 598 XERCES_STD_QUALIFIER cerr << "\nWarning at (file " << StrX(e.getSystemId()) 599 << ", line " << e.getLineNumber() 600 << ", char " << e.getColumnNumber() 601 << "): " << StrX(e.getMessage()) << XERCES_STD_QUALIFIER endl; 602 } 603 604 605 bool 606 X3dParser::ParseFile(const string filename, 607 SceneGraphNode **root) 608 { 609 // Initialize the XML4C system 610 try { 611 XMLPlatformUtils::Initialize(); 612 } 613 614 catch (const XMLException& toCatch) 615 { 616 XERCES_STD_QUALIFIER cerr << "Error during initialization! Message:\n" 617 << StrX(toCatch.getMessage()) << XERCES_STD_QUALIFIER endl; 618 return false; 619 } 620 621 622 // 623 // Create a SAX parser object. Then, according to what we were told on 624 // the command line, set the options. 625 // 626 SAXParser* parser = new SAXParser; 627 parser->setValidationScheme(valScheme); 628 parser->setDoNamespaces(doNamespaces); 629 parser->setDoSchema(doSchema); 630 parser->setValidationSchemaFullChecking(schemaFullChecking); 631 632 633 // 634 // Create our SAX handler object and install it on the parser, as the 635 // document and error handler. We are responsible for cleaning them 636 // up, but since its just stack based here, there's nothing special 637 // to do. 638 // 639 *root = new SceneGraphNode; 640 X3dViewCellsParser handler(*root); 641 parser->setDocumentHandler(&handler); 642 parser->setErrorHandler(&handler); 643 644 unsigned long duration; 645 int errorCount = 0; 646 // create a faux scope so that 'src' destructor is called before 647 // XMLPlatformUtils::Terminate 648 { 649 // 650 // Kick off the parse and catch any exceptions. Create a standard 651 // input input source and tell the parser to parse from that. 652 // 653 // StdInInputSource src; 654 try 655 { 656 const unsigned long startMillis = XMLPlatformUtils::getCurrentMillis(); 657 parser->parse(filename.c_str()); 658 const unsigned long endMillis = XMLPlatformUtils::getCurrentMillis(); 659 duration = endMillis - startMillis; 660 errorCount = parser->getErrorCount(); 661 } 662 catch (const OutOfMemoryException&) 663 { 664 XERCES_STD_QUALIFIER cerr << "OutOfMemoryException" << XERCES_STD_QUALIFIER endl; 665 errorCount = 2; 666 return false; 667 } 668 catch (const XMLException& e) 669 { 670 XERCES_STD_QUALIFIER cerr << "\nError during parsing: \n" 671 << StrX(e.getMessage()) 672 << "\n" << XERCES_STD_QUALIFIER endl; 673 errorCount = 1; 674 return false; 675 } 676 677 678 // Print out the stats that we collected and time taken 679 if (!errorCount) { 680 XERCES_STD_QUALIFIER cout << filename << ": " << duration << " ms (" 681 << handler.GetElementCount() << " elems, " 682 << handler.GetAttrCount() << " attrs, " 683 << handler.GetSpaceCount() << " spaces, " 684 << handler.GetCharacterCount() << " chars)" << XERCES_STD_QUALIFIER endl; 685 } 686 } 687 688 // 689 // Delete the parser itself. Must be done prior to calling Terminate, below. 690 // 691 delete parser; 692 693 XMLPlatformUtils::Terminate(); 694 695 if (errorCount > 0) 696 return false; 697 else 698 return true; 699 } -
trunk/VUT/GtpVisibilityPreprocessor/src/X3dParser.h
r170 r260 3 3 4 4 #include "Parser.h" 5 5 #include "ViewCells.h" 6 6 7 7 class X3dParser : public Parser … … 11 11 12 12 bool ParseFile(const string filename, SceneGraphNode **root); 13 13 bool ParseViewCells(const string filename, ViewCellContainer *viewCells); 14 14 }; 15 15 -
trunk/VUT/GtpVisibilityPreprocessor/src/X3dParserXerces.h
r180 r260 105 105 }; 106 106 107 /** Parser handlers for view cell x3d files. 108 */ 109 class X3dViewCellsParseHandlers : public HandlerBase 110 { 111 public: 112 // ----------------------------------------------------------------------- 113 // Constructors and Destructor 114 // ----------------------------------------------------------------------- 115 X3dViewCellsParseHandlers(ViewCellContainer *mViewCells;); 116 ~X3dViewCellsParseHandlers(); 117 118 119 // ----------------------------------------------------------------------- 120 // Getter methods 121 // ----------------------------------------------------------------------- 122 unsigned int GetElementCount() 123 { 124 return mElementCount; 125 } 126 127 unsigned int GetAttrCount() 128 { 129 return mAttrCount; 130 } 131 132 unsigned int GetCharacterCount() 133 { 134 return mCharacterCount; 135 } 136 137 unsigned int GetSpaceCount() 138 { 139 return mSpaceCount; 140 } 141 142 143 // ----------------------------------------------------------------------- 144 // Handlers for the SAX DocumentHandler interface 145 // ----------------------------------------------------------------------- 146 void endElement(const XMLCh* const name); 147 void startElement(const XMLCh* const name, AttributeList& attributes); 148 void characters(const XMLCh* const chars, const unsigned int length); 149 void ignorableWhitespace(const XMLCh* const chars, const unsigned int length); 150 void resetDocument(); 151 152 ViewCellContainer *mViewCells; 153 154 // Handlers for X3D 155 void 156 StartIndexedFaceSet( 157 AttributeList& attributes); 158 159 void 160 EndShape(); 161 162 void 163 StartCoordinate( 164 AttributeList& attributes); 165 166 void 167 StartMaterial( 168 AttributeList& attributes); 169 170 171 // ----------------------------------------------------------------------- 172 // Handlers for the SAX ErrorHandler interface 173 // ----------------------------------------------------------------------- 174 void warning(const SAXParseException& exc); 175 void error(const SAXParseException& exc); 176 void fatalError(const SAXParseException& exc); 177 178 179 private: 180 // ----------------------------------------------------------------------- 181 // Private data members 182 // 183 // fAttrCount 184 // fCharacterCount 185 // fElementCount 186 // fSpaceCount 187 // These are just counters that are run upwards based on the input 188 // from the document handlers. 189 // ----------------------------------------------------------------------- 190 unsigned int mAttrCount; 191 unsigned int mCharacterCount; 192 unsigned int mElementCount; 193 unsigned int mSpaceCount; 194 }; 195 107 196 108 197 // --------------------------------------------------------------------------- -
trunk/VUT/GtpVisibilityPreprocessor/src/main.cpp
r242 r260 31 31 p->BuildKdTree(); 32 32 p->KdTreeStatistics(cout); 33 33 34 #ifdef TEST_BSP_VIEWCELLS 35 environment->GetStringValue("Scene.viewcells", buff); 36 34 37 p->GenerateViewcells(); 35 38 p->BspTreeStatistics(Debug);
Note: See TracChangeset
for help on using the changeset viewer.