Changeset 319 for trunk/VUT/GtpVisibilityPreprocessor
- Timestamp:
- 10/12/05 01:15:22 (19 years ago)
- Location:
- trunk/VUT/GtpVisibilityPreprocessor
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/VUT/GtpVisibilityPreprocessor/scripts/default.env
r318 r319 9 9 # filename vienna.x3d 10 10 # filename ../data/vienna/vienna-simple.x3d 11 #filename ../data/vienna/vienna-buildings.x3d11 filename ../data/vienna/vienna-buildings.x3d 12 12 # filename ../data/vienna/viewcells-25-sel.x3d 13 filename ../data/atlanta/atlanta2.x3d13 # filename ../data/atlanta/atlanta2.x3d 14 14 # filename ../data/soda/soda.dat 15 15 # filename ../data/soda/soda5.dat … … 66 66 #hierarchyType kdTree 67 67 #hierarchyType sceneDependent 68 filename ../data/atlanta/atlanta_viewcells_large.x3d68 # filename ../data/atlanta/atlanta_viewcells_large.x3d 69 69 # filename ../data/vienna/viewcells-25-sel.x3d 70 70 filename ../data/vienna/viewcells-25.x3d … … 84 84 # largest polygon area = 32 85 85 # vertical axis = 64 86 # blocked rays = 128 86 87 87 splitPlaneStrategy 6688 88 # least splits + balanced polygons 89 89 #splitPlaneStrategy 12 … … 101 101 #splitPlaneStrategy 72 102 102 103 splitPlaneStrategy 66 104 103 105 maxCandidates 50 104 106 -
trunk/VUT/GtpVisibilityPreprocessor/src/Polygon3.cpp
r318 r319 6 6 #include "Ray.h" 7 7 8 Polygon3::Polygon3(): mMaterial(NULL), mParent(NULL) 8 Polygon3::Polygon3(): 9 mMaterial(NULL), mParent(NULL), mPiercingRays(NULL) 9 10 {} 10 11 11 Polygon3::Polygon3(const VertexContainer &vertices): mVertices(vertices), mMaterial(NULL), mParent(NULL) 12 Polygon3::Polygon3(const VertexContainer &vertices): 13 mVertices(vertices), mMaterial(NULL), mParent(NULL), mPiercingRays(NULL) 12 14 {} 13 15 14 Polygon3::Polygon3(MeshInstance *parent): mMaterial(NULL), mParent(parent) 16 Polygon3::Polygon3(MeshInstance *parent): 17 mMaterial(NULL), mParent(parent) 15 18 {} 16 17 // creates an "infinite" polygon from this plane18 //Polygon3::Polygon3(Plane3 plane)19 //{}20 19 21 20 Polygon3::Polygon3(Face *face, Mesh *parentMesh) … … 27 26 mMaterial = parentMesh->mMaterial; 28 27 } 28 } 29 30 Polygon3::~Polygon3() 31 { 32 DEL_PTR(mPiercingRays); 29 33 } 30 34 … … 352 356 } 353 357 358 RayContainer *Polygon3::GetPiercingRays() 359 { 360 if (!mPiercingRays) 361 mPiercingRays = new RayContainer(); 362 return mPiercingRays; 363 } 364 365 void Polygon3::AddPiercingRay(Ray *ray) 366 { 367 if (!mPiercingRays) 368 mPiercingRays = new RayContainer(); 369 //if (binary_search(mPiercingRays.begin(), mPiercingRays.end(), ray)) return false; 370 371 mPiercingRays->push_back(ray); 372 } -
trunk/VUT/GtpVisibilityPreprocessor/src/Polygon3.h
r317 r319 87 87 int CastRay(const Ray &ray, float &t, const float nearestT); 88 88 89 /** Returns piercing rays container. 90 */ 91 RayContainer *GetPiercingRays(); 92 93 /** Adds a ray to the ray container. 94 */ 95 void AddPiercingRay(Ray *ray); 96 89 97 /// vertices are connected in counterclockwise order. 90 98 VertexContainer mVertices; … … 95 103 /// pointer to the mesh instance this polygon is derived from 96 104 MeshInstance *mParent; 105 106 /// Rays piercing this polygon 107 RayContainer *mPiercingRays; 97 108 }; 98 109 -
trunk/VUT/GtpVisibilityPreprocessor/src/Preprocessor.cpp
r313 r319 168 168 break; 169 169 case BspTree::FROM_RAYS: 170 DeleteViewCells(); // we generate new view cells 171 mBspTree->Construct(rays, &mViewCells); 170 DeleteViewCells(); // we generate new view cells 171 mSceneGraph->CollectObjects(&objects); 172 mBspTree->Construct(objects, rays, &mViewCells); 172 173 break; 173 174 default: -
trunk/VUT/GtpVisibilityPreprocessor/src/SamplingPreprocessor.cpp
r318 r319 236 236 vector<Ray> vcRays[5]; 237 237 238 const int fromRaysBspThresh = 1000; 239 238 240 while (totalSamples < mTotalSamples) { 239 241 int passContributingSamples = 0; … … 241 243 int passSamples = 0; 242 244 int index = 0; 243 245 246 // construct Bsp tree if not 247 if ((mViewCellsType == Preprocessor::BSP_VIEW_CELLS) && 248 !mBspTree->GetRoot() && (passSamples > fromRaysBspThresh)) 249 { 250 BuildBspTree(); 251 } 252 244 253 for (i = 0; i < objects.size(); i++) { 245 254 KdNode *nodeToSample = NULL; -
trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.cpp
r318 r319 16 16 int BspTree::sTermMaxDepth = 20; 17 17 int BspTree::sMaxCandidates = 10; 18 int BspTree::sSplitPlaneStrategy = NEXT_POLYGON;18 int BspTree::sSplitPlaneStrategy = BALANCED_POLYS; 19 19 int BspTree::sConstructionMethod = FROM_INPUT_VIEW_CELLS; 20 20 int BspTree::sTermMaxPolysForAxisAligned = 50; … … 30 30 float BspTree::sVerticalSplitsFactor = 1.0f; // very important criterium for 2.5d scenes 31 31 float BspTree::sLargestPolyAreaFactor = 1.0f; 32 float BspTree::sBlockedRaysFactor = 1.0f; 32 33 33 34 /** Evaluates split plane classification with respect to the plane's … … 552 553 } 553 554 554 void BspTree::Construct(const RayContainer &rays, ViewCellContainer *viewCells) 555 { 556 // TODO 555 void BspTree::Construct(const ObjectContainer &objects, 556 const RayContainer &rays, 557 ViewCellContainer *viewCells) 558 { 559 PolygonContainer *polys = new PolygonContainer(); 560 561 // copy mesh instance polygons into one big polygon soup 562 mStat.polys = AddToPolygonSoup(objects, *polys); 563 564 RayContainer::const_iterator rit, rit_end = rays.end(); 565 566 long startTime = GetTime(); 567 Debug << "**** Casting rays into polygons ****\n"; 568 569 //-- cast rays into all polygons 570 for (rit = rays.begin(); rit != rays.end(); ++ rit) 571 { 572 Ray *ray = *rit; 573 574 PolygonContainer::const_iterator pit, pit_end = polys->end(); 575 576 for (pit = polys->begin(); pit != pit_end; ++ pit) 577 { 578 Polygon3 *poly = *pit; 579 580 float t = 0; 581 float nearestT = 0; 582 583 if (poly->CastRay(*ray, t, nearestT) > 0) 584 poly->AddPiercingRay(ray); 585 } 586 } 587 588 Debug << "**** Finished ray casting ****\n"; 589 Debug << "ray casting time: " << TimeDiff(startTime, GetTime())*1e-3 << "s" << endl; 590 591 Construct(polys, viewCells); 557 592 } 558 593 … … 565 600 566 601 long startTime = GetTime(); 567 Debug << "**** Contructing tree using objects****\n";602 Debug << "**** Contructing tree using scene geometry ****\n"; 568 603 while (!tStack.empty()) 569 604 { … … 607 642 leaf->SetViewCell(tData.mViewCell); 608 643 609 //-- clean up 610 644 // clean up 611 645 // remaining polygons are discarded or added to node 612 646 leaf->ProcessPolygons(tData.mPolygons, mStoreSplitPolys); 613 647 DEL_PTR(tData.mPolygons); 614 615 CLEAR_CONTAINER(*tData.mRays);616 DEL_PTR(tData.mRays);617 648 618 649 return leaf; … … 629 660 *frontPolys, 630 661 *backPolys, 631 coincident, 632 *tData.mRays); 662 coincident); 633 663 634 664 ViewCell *frontViewCell = mRootCell; … … 644 674 // extract view cells from coincident polygons according to plane normal 645 675 // only if front or back polygons are empty 646 ExtractViewCells(&backViewCell, 647 &frontViewCell, 648 coincident, 649 interior->mPlane, 676 ExtractViewCells(&backViewCell, 677 &frontViewCell, 678 coincident, 679 interior->mPlane, 650 680 backPolys->empty(), 651 681 frontPolys->empty()); … … 653 683 // don't need coincident polygons anymore 654 684 interior->ProcessPolygons(&coincident, mStoreSplitPolys); 655 656 // split rays657 RayContainer *frontRays = NULL;658 RayContainer *backRays = NULL;659 660 if (tData.mRays->size() > 0)661 {662 RayContainer *frontRays = new RayContainer();663 RayContainer *backRays = new RayContainer();664 665 Plane3 plane;666 SplitRays(plane, *tData.mRays, *frontRays, *backRays);667 }668 685 669 686 // push the children on the stack … … 671 688 backPolys, 672 689 tData.mDepth + 1, 673 backViewCell, 674 backRays)); 690 backViewCell)); 675 691 676 692 tStack.push(BspTraversalData(interior->GetFront(), 677 693 frontPolys, 678 694 tData.mDepth + 1, 679 frontViewCell, 680 frontRays)); 695 frontViewCell)); 681 696 682 697 // cleanup 683 698 DEL_PTR(tData.mNode); 684 699 DEL_PTR(tData.mPolygons); 685 DEL_PTR(tData.mRays);686 700 687 701 return interior; … … 720 734 PolygonContainer &frontPolys, 721 735 PolygonContainer &backPolys, 722 PolygonContainer &coincident, 723 const RayContainer &rays) 736 PolygonContainer &coincident) 724 737 { 725 738 mStat.nodes += 2; 726 739 727 740 // add the new nodes to the tree + select subdivision plane 728 BspInterior *interior = new BspInterior(SelectPlane(leaf, polys , rays));741 BspInterior *interior = new BspInterior(SelectPlane(leaf, polys)); 729 742 730 743 #ifdef _DEBUG … … 863 876 864 877 Plane3 BspTree::SelectPlane(BspLeaf *leaf, 865 PolygonContainer &polys, 866 const RayContainer &rays) 878 PolygonContainer &polys) 867 879 { 868 880 if (polys.size() == 0) … … 917 929 918 930 // use heuristics to find appropriate plane 919 return SelectPlaneHeuristics(polys, rays,sMaxCandidates);931 return SelectPlaneHeuristics(polys, sMaxCandidates); 920 932 } 921 933 922 934 Plane3 BspTree::SelectPlaneHeuristics(PolygonContainer &polys, 923 const RayContainer &rays,924 935 const int maxTests) 925 936 { … … 938 949 939 950 // evaluate current candidate 940 float candidateCost = EvalSplitPlane(polys, candidatePlane , rays);951 float candidateCost = EvalSplitPlane(polys, candidatePlane); 941 952 942 953 if (candidateCost < lowestCost) … … 966 977 967 978 float BspTree::EvalSplitPlane(PolygonContainer &polys, 968 const Plane3 &candidatePlane, 969 const RayContainer &rays) 979 const Plane3 &candidatePlane) 970 980 { 971 981 float val = 0; … … 980 990 } 981 991 982 //-- strategies where the effect of the split plane on the polygons is tested 983 if (!((sSplitPlaneStrategy & BALANCED_POLYS) || 984 (sSplitPlaneStrategy & LEAST_SPLITS) || 985 (sSplitPlaneStrategy & LARGEST_POLY_AREA) || 986 (sSplitPlaneStrategy & BALANCED_VIEW_CELLS))) 992 // strategies where the effect of the split plane is tested 993 // on all input polygons 994 if (!((sSplitPlaneStrategy & BALANCED_POLYS) || 995 (sSplitPlaneStrategy & LEAST_SPLITS) || 996 (sSplitPlaneStrategy & LARGEST_POLY_AREA) || 997 (sSplitPlaneStrategy & BALANCED_VIEW_CELLS) || 998 (sSplitPlaneStrategy & BLOCKED_RAYS))) 999 { 987 1000 return val; 988 989 PolygonContainer::const_iterator it, it_end = polys.end(); 1001 } 1002 990 1003 float sumBalancedPolys = 0; 991 1004 float sumSplits = 0; 992 1005 float sumPolyArea = 0; 993 1006 float sumBalancedViewCells = 0; 1007 float sumBlockedRays = 0; 1008 1009 float totalBlockedRays = 0; 994 1010 //float totalArea = 0; 995 1011 996 // container for view cells1012 // container for balanced view cells criterium 997 1013 ObjectContainer frontViewCells; 998 1014 ObjectContainer backViewCells; 1015 1016 PolygonContainer::const_iterator it, it_end = polys.end(); 999 1017 1000 1018 for (it = polys.begin(); it != it_end; ++ it) … … 1019 1037 } 1020 1038 1039 1040 if (sSplitPlaneStrategy & BLOCKED_RAYS) 1041 { 1042 float blockedRays = (float)(*it)->GetPiercingRays()->size(); 1043 if (classification == Polygon3::COINCIDENT) 1044 { 1045 sumBlockedRays += blockedRays; 1046 } 1047 1048 totalBlockedRays += blockedRays; 1049 } 1050 1021 1051 // assign view cells to back or front according to classificaion 1022 1052 if (sSplitPlaneStrategy & BALANCED_VIEW_CELLS) … … 1031 1061 } 1032 1062 1063 // all values should be approx. between 0 and 1 so they can be combined 1064 // and scaled with the factors according to their importance 1033 1065 if (sSplitPlaneStrategy & BALANCED_POLYS) 1034 1066 val += sBalancedPolysFactor * fabs(sumBalancedPolys) / (float)polys.size(); … … 1038 1070 1039 1071 if (sSplitPlaneStrategy & LARGEST_POLY_AREA) 1040 val += sLargestPolyAreaFactor * (float)polys.size() / sumPolyArea; // HACK 1072 // HACK (polys.size should be totalArea) 1073 val += sLargestPolyAreaFactor * (float)polys.size() / sumPolyArea; 1074 1075 if (sSplitPlaneStrategy & BLOCKED_RAYS) 1076 if (totalBlockedRays > 0) 1077 val += sBlockedRaysFactor * sumBlockedRays / totalBlockedRays; 1041 1078 1042 1079 if (sSplitPlaneStrategy & BALANCED_VIEW_CELLS) … … 1133 1170 if (sSplitPlaneStrategy & VERTICAL_AXIS) 1134 1171 Debug << "vertical axis "; 1172 if (sSplitPlaneStrategy & BLOCKED_RAYS) 1173 Debug << "blocked rays "; 1135 1174 1136 1175 Debug << endl; … … 1357 1396 } 1358 1397 } 1359 1360 void BspTree::SplitRays(const Plane3 plane,1361 RayContainer &rays,1362 RayContainer &frontRays,1363 RayContainer &backRays)1364 {1365 while (!rays.empty())1366 {1367 //TODO1368 }1369 }1370 1398 //} // GtpVisibilityPreprocessor -
trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.h
r318 r319 254 254 /// the view cell associated with this subdivsion 255 255 ViewCell *mViewCell; 256 /// rays piercing this node 257 RayContainer *mRays; 258 256 259 257 BspTraversalData(): 260 258 mNode(NULL), 261 259 mPolygons(NULL), 262 260 mDepth(0), 263 mViewCell(NULL), 264 mRays(NULL) 261 mViewCell(NULL) 265 262 {} 266 263 … … 268 265 PolygonContainer *polys, 269 266 const int depth, 270 ViewCell *viewCell, 271 RayContainer *rays = NULL): 267 ViewCell *viewCell): 272 268 mNode(node), 273 269 mPolygons(polys), 274 270 mDepth(depth), 275 mViewCell(viewCell), 276 mRays(rays) 271 mViewCell(viewCell) 277 272 {} 278 273 }; … … 299 294 300 295 /** Constructs tree using the given list of objects. 301 Note thatthe objects are not taken as view cells, but the view cells are302 constructed from the subdivision: Each leaf is taken as one viewcell ;296 @note the objects are not taken as view cells, but the view cells are 297 constructed from the subdivision: Each leaf is taken as one viewcell. 303 298 304 299 @param objects list of objects … … 307 302 void Construct(const ObjectContainer &objects, ViewCellContainer *viewCells); 308 303 309 /** Constructs tree using the given number of rays 310 @param objects list of objects 311 @returns list of view cells. 312 */ 313 void Construct(const RayContainer &rays, ViewCellContainer *viewCells); 314 315 int CollectLeafPvs(); 316 304 /** Constructs the tree from the given list of polygons. 305 @param viewCells if not NULL, new view cells are 306 created in the leafs and stored in the conatainer 307 */ 308 void Construct(PolygonContainer *polys, ViewCellContainer *viewCells = NULL); 309 310 /** Constructs the tree from a list of scene geometry and a 311 given bundle of rays. 312 @param objects list of objects 313 @param rays the bundle of sample rays 314 @param viewCells if not NULL, new view cells are 315 created in the leafs and stored in the conatainer 316 */ 317 void Construct(const ObjectContainer &objects, 318 const RayContainer &rays, 319 ViewCellContainer *viewCells = NULL); 320 321 /** Returns list of BSP leaves. 322 */ 317 323 void CollectLeaves(vector<BspLeaf *> &leaves); 318 324 … … 366 372 }; 367 373 368 /** Constructs the tree from the given list of polygons.369 @param viewCells if not NULL, new view cells are370 created in the leafs and stored in the conatainer371 */372 void Construct(PolygonContainer *polys, ViewCellContainer *viewCells = NULL);373 374 374 /** Evaluates the contribution of the candidate split plane. 375 375 @note the polygons can be reordered in the process. … … 377 377 */ 378 378 float EvalSplitPlane(PolygonContainer &polys, 379 const Plane3 &candidatePlane, 380 const RayContainer &rays); 379 const Plane3 &candidatePlane); 381 380 382 381 /** Evaluates tree stats in the BSP tree leafs. … … 391 390 BspNode *Subdivide(BspTraversalStack &tStack, BspTraversalData &tData); 392 391 393 /** Selects asplitting plane.392 /** Selects the best possible splitting plane. 394 393 @param leaf the leaf to be split 395 394 @param polys the polygon list on which the split decition is based 396 @param rays ray container on which selection may be based 397 Returns the split plane 395 @Returns the split plane 398 396 */ 399 397 Plane3 SelectPlane(BspLeaf *leaf, 400 PolygonContainer &polys, 401 const RayContainer &ray); 398 PolygonContainer &polys); 402 399 403 400 /** Filters next view cell down the tree and inserts it into the appropriate leaves … … 417 414 @param backPolys returns the polygons in the back of the split plane 418 415 @param coincident returns the polygons coincident to the split plane 419 @param rays ray container used to guide the split process420 416 @returns the root of the subdivision 421 417 */ … … 424 420 PolygonContainer &frontPolys, 425 421 PolygonContainer &backPolys, 426 PolygonContainer &coincident, 427 const RayContainer &rays); 422 PolygonContainer &coincident); 428 423 429 424 /** Filters polygons down the tree. … … 433 428 @param backPolys returns the polygons in the back of the split plane 434 429 */ 435 void FilterPolygons(BspInterior *node, PolygonContainer *polys, 436 PolygonContainer *frontPolys, PolygonContainer *backPolys); 430 void FilterPolygons(BspInterior *node, 431 PolygonContainer *polys, 432 PolygonContainer *frontPolys, 433 PolygonContainer *backPolys); 437 434 438 435 /** Selects the split plane in order to construct a tree with … … 440 437 2.5d aligned) 441 438 @param polygons container of polygons 442 @param rays bundle of rays on which the split can be based443 439 @param maxTests the maximal number of candidate tests 444 440 */ 445 441 Plane3 SelectPlaneHeuristics(PolygonContainer &polys, 446 const RayContainer &rays, 447 const int maxTests); 442 const int maxTests); 448 443 449 444 /** Extracts the meshes of the objects and adds them to polygons. … … 519 514 vector<SortableEntry> &splitCandidates) const; 520 515 521 /** Splits the rays into front and back rays according to split plane522 @param rays contains the rays to be split. The rays are523 distributed to front and back rays.524 @param frontRays returns rays on the front side of the plane525 @param backRays returns rays on the back side of the plane526 */527 void BspTree::SplitRays(const Plane3 plane,528 RayContainer &rays,529 RayContainer &frontRays,530 RayContainer &backRays);531 532 516 /// Pointer to the root of the tree 533 517 BspNode *mRoot; … … 546 530 BALANCED_VIEW_CELLS = 16, 547 531 LARGEST_POLY_AREA = 32, 548 VERTICAL_AXIS = 64 532 VERTICAL_AXIS = 64, 533 BLOCKED_RAYS = 128 549 534 }; 550 535 … … 585 570 static float sVerticalSplitsFactor; 586 571 static float sLargestPolyAreaFactor; 587 572 static float sBlockedRaysFactor; 573 588 574 private: 589 575 /** Evaluates split plane classification with respect to the plane's -
trunk/VUT/GtpVisibilityPreprocessor/src/main.cpp
r318 r319 38 38 p->ParseViewCellsOptions(); 39 39 40 if (p->mViewCellsType == Preprocessor::BSP_VIEW_CELLS) 40 if (p->mViewCellsType == Preprocessor::BSP_VIEW_CELLS && 41 !(BspTree::sConstructionMethod == BspTree::FROM_RAYS)) // construct tree later 41 42 { 42 43 if (BspTree::sConstructionMethod == BspTree::FROM_INPUT_VIEW_CELLS)
Note: See TracChangeset
for help on using the changeset viewer.