- Timestamp:
- 10/26/05 19:18:30 (19 years ago)
- Location:
- trunk/VUT/GtpVisibilityPreprocessor
- Files:
-
- 18 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/VUT/GtpVisibilityPreprocessor/scripts/default.env
r344 r349 8 8 # filename glasgow1.x3d 9 9 # filename vienna.x3d 10 filename ../data/vienna/vienna-simple.x3d10 # filename ../data/vienna/vienna-simple.x3d 11 11 # 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 … … 56 56 57 57 Sampling { 58 totalSamples 10059 samplesPerPass 2 058 totalSamples 200000 59 samplesPerPass 2 60 60 } 61 61 … … 76 76 BspTree { 77 77 Construction { 78 #input fromRays79 input fromViewCells78 input fromRays 79 # input fromViewCells 80 80 # input fromSceneGeometry 81 samples 20000081 samples 150000 82 82 sideTolerance 0.005 83 83 } … … 113 113 #splitPlaneStrategy 130 114 114 115 splitPlaneStrategy 66 115 #splitPlaneStrategy 384 116 splitPlaneStrategy 130 116 117 117 maxCandidates 50118 maxCandidates 80 118 119 119 120 Termination { 120 121 # autopartition 121 maxRays -1122 maxRays 10 122 123 maxPolygons 0 123 124 maxDepth 100 124 125 125 126 #axis aligned split 126 maxPolysForAxisAligned 100127 maxPolysForAxisAligned 200 127 128 maxCostRatio 0.9 128 129 ct_div_ci 0.5 -
trunk/VUT/GtpVisibilityPreprocessor/src/Exporter.h
r313 r349 53 53 ) = 0; 54 54 55 virtual bool 56 ExportRays(const RayContainer &rays, 57 const float length=1000, 58 const RgbColor &color = RgbColor(1,1,1) 59 ) = 0; 55 60 56 61 virtual void -
trunk/VUT/GtpVisibilityPreprocessor/src/Intersectable.h
r340 r349 41 41 virtual int Type() const = 0; 42 42 43 virtual voidGetRandomSurfacePoint(Vector3 &point, Vector3 &normal) = 0;43 virtual int GetRandomSurfacePoint(Vector3 &point, Vector3 &normal) = 0; 44 44 45 45 virtual ostream &Describe(ostream &s) = 0; -
trunk/VUT/GtpVisibilityPreprocessor/src/Mesh.cpp
r340 r349 266 266 } 267 267 268 269 void 268 int 270 269 Mesh::GetRandomSurfacePoint(Vector3 &point, Vector3 &normal) 271 270 { … … 285 284 286 285 normal = GetFacePlane(faceIndex).mNormal; 287 } 288 286 287 return faceIndex; 288 } 289 289 290 290 int … … 308 308 309 309 310 void 310 int 311 311 MeshInstance::GetRandomSurfacePoint(Vector3 &point, Vector3 &normal) 312 312 { 313 mMesh->GetRandomSurfacePoint(point, normal);314 } 315 316 void 313 return mMesh->GetRandomSurfacePoint(point, normal); 314 } 315 316 int 317 317 TransformedMeshInstance::GetRandomSurfacePoint(Vector3 &point, Vector3 &normal) 318 318 { 319 mMesh->GetRandomSurfacePoint(point, normal);319 int index = mMesh->GetRandomSurfacePoint(point, normal); 320 320 point = mWorldTransform*point; 321 321 normal = TransformNormal(mWorldTransform, normal); 322 return index; 322 323 } 323 324 -
trunk/VUT/GtpVisibilityPreprocessor/src/Mesh.h
r340 r349 143 143 AxisAlignedBox3 GetFaceBox(const int faceIndex); 144 144 145 voidGetRandomSurfacePoint(Vector3 &point, Vector3 &normal);145 int GetRandomSurfacePoint(Vector3 &point, Vector3 &normal); 146 146 147 147 virtual ostream &Describe(ostream &s) { … … 160 160 } 161 161 162 voidGetRandomSurfacePoint(Vector3 &point, Vector3 &normal);162 int GetRandomSurfacePoint(Vector3 &point, Vector3 &normal); 163 163 164 164 … … 215 215 virtual int Type() const { return TRANSFORMED_MESH_INSTANCE; } 216 216 217 voidGetRandomSurfacePoint(Vector3 &point, Vector3 &normal);217 int GetRandomSurfacePoint(Vector3 &point, Vector3 &normal); 218 218 219 219 private: -
trunk/VUT/GtpVisibilityPreprocessor/src/Plane3.h
r327 r349 30 30 } 31 31 32 // relation of objects with the plane33 enum {BACK_SIDE, FRONT_SIDE, SPLIT, COINCIDENT};34 32 35 33 float Distance(const Vector3 &v) const { -
trunk/VUT/GtpVisibilityPreprocessor/src/Polygon3.cpp
r344 r349 6 6 #include "Ray.h" 7 7 8 float Polygon3::sSideTolerance = 0.002f;9 float Polygon3::sSideToleranceSqrt = 0.000004f;10 11 8 Polygon3::Polygon3(): 12 mMaterial(NULL), mParent(NULL), mPiercingRays( NULL)9 mMaterial(NULL), mParent(NULL), mPiercingRays(0) 13 10 {} 14 11 15 12 Polygon3::Polygon3(const VertexContainer &vertices): 16 mVertices(vertices), mMaterial(NULL), mParent(NULL), mPiercingRays( NULL)13 mVertices(vertices), mMaterial(NULL), mParent(NULL), mPiercingRays(0) 17 14 {} 18 15 19 16 Polygon3::Polygon3(MeshInstance *parent): 20 mMaterial(NULL), mParent(parent), mPiercingRays( NULL)17 mMaterial(NULL), mParent(parent), mPiercingRays(0) 21 18 {} 22 19 23 20 Polygon3::Polygon3(Face *face, Mesh *parentMesh): 24 mMaterial(NULL), mParent(NULL), mPiercingRays( NULL)21 mMaterial(NULL), mParent(NULL), mPiercingRays(0) 25 22 { 26 23 VertexIndexContainer::iterator it = face->mVertexIndices.begin(); … … 30 27 mMaterial = parentMesh->mMaterial; 31 28 } 32 }33 34 Polygon3::~Polygon3()35 {36 DEL_PTR(mPiercingRays);37 29 } 38 30 … … 55 47 Vector3 ptA = mVertices.back(); 56 48 57 int sideA = partition.Side(ptA, sSideTolerance);49 int sideA = partition.Side(ptA, Vector3::sDistTolerance); 58 50 59 51 VertexContainer::const_iterator it; … … 64 56 { 65 57 Vector3 ptB = *it; 66 int sideB = partition.Side(ptB, sSideTolerance);58 int sideB = partition.Side(ptB, Vector3::sDistTolerance); 67 59 68 60 // vertices on different sides => split … … 76 68 // test if split point not too close to previous split point 77 69 if (!foundSplit || 78 (SqrDistance(splitPt, splitPts.back()) > sSideToleranceSqrt))70 (SqrDistance(splitPt, splitPts.back()) > Vector3::sDistToleranceSqrt)) 79 71 { 80 72 // add vertex to both polygons … … 97 89 // test if split point not too close to previous split point 98 90 if (!foundSplit || 99 (SqrDistance(splitPt, splitPts.back()) > sSideToleranceSqrt))91 (SqrDistance(splitPt, splitPts.back()) > Vector3::sDistToleranceSqrt)) 100 92 { 101 93 // add vertex to both polygons … … 136 128 int classification = ClassifyPlane(plane); 137 129 138 if (classification == Plane3::BACK_SIDE)130 if (classification == BACK_SIDE) 139 131 return -1; 140 else if (classification == Plane3::FRONT_SIDE)132 else if (classification == FRONT_SIDE) 141 133 return 1; 142 134 … … 155 147 for (it = mVertices.begin(); it != mVertices.end(); ++ it) 156 148 { 157 int side = plane.Side(*it, sSideTolerance);149 int side = plane.Side(*it, Vector3::sDistTolerance); 158 150 159 151 if (side > 0) … … 165 157 if (onFrontSide && onBackSide) // split 166 158 { 167 return Plane3::SPLIT;159 return SPLIT; 168 160 } 169 161 // 3 vertices enough to decide coincident 170 162 else if (((++ count) >= 3) && !onFrontSide && !onBackSide) 171 { //if (DotProd(plane.mNormal, GetNormal()) > 0)172 return Plane3::COINCIDENT;163 { 164 return COINCIDENT; 173 165 } 174 166 } … … 176 168 if (onBackSide) 177 169 { 178 return Plane3::BACK_SIDE;170 return BACK_SIDE; 179 171 } 180 172 else if (onFrontSide) 181 173 { 182 return Plane3::FRONT_SIDE;183 } 184 //if (DotProd(plane.mNormal, GetNormal()) < 0) return Plane3::FRONT_SIDE;185 return Plane3::COINCIDENT; // plane and polygon are coincident174 return FRONT_SIDE; 175 } 176 177 return COINCIDENT; // plane and polygon are coincident 186 178 } 187 179 … … 227 219 for (it = mVertices.begin(); it != it_end; ++it) 228 220 { 229 if (!(SqrDistance(vtx, *it) > SIDE_TOLERANCE_SQRD))221 if (!(SqrDistance(vtx, *it) > sDistToleranceSqrt)) 230 222 { 231 223 Debug << "Malformed vertices:\n" << *this << endl; … … 356 348 } 357 349 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 GetPiercingRays()->push_back(ray); 368 } 350 void Polygon3::InheritRays(Polygon3 &front_piece, 351 Polygon3 &back_piece) const 352 { 353 RayContainer::const_iterator it, 354 it_end = mPiercingRays.end(); 355 356 for (it = mPiercingRays.begin(); it != it_end; ++ it) 357 { 358 switch((*it)->GetId()) 359 { 360 case Ray::BACK: 361 back_piece.mPiercingRays.push_back(*it); 362 break; 363 case Ray::FRONT: 364 front_piece.mPiercingRays.push_back(*it); 365 break; 366 case Ray::FRONT_BACK: 367 back_piece.mPiercingRays.push_back(*it); 368 break; 369 case Ray::BACK_FRONT: 370 front_piece.mPiercingRays.push_back(*it); 371 break; 372 default: 373 break; 374 } 375 } 376 } -
trunk/VUT/GtpVisibilityPreprocessor/src/Polygon3.h
r333 r349 23 23 { 24 24 public: 25 enum {BACK_SIDE, FRONT_SIDE, SPLIT, COINCIDENT}; 26 27 /** Default constructor creating an empty polygon. 28 */ 25 29 Polygon3(); 26 30 /** Constructor creating a polygon from the vertices. 31 */ 27 32 Polygon3(const VertexContainer &vertices); 33 /** Creates a polygon and stores pointer to parent mesh 34 instance. 35 */ 28 36 Polygon3(MeshInstance *parent); 29 30 ~Polygon3();31 37 32 38 // creates an "infinite" polygon from this plane … … 89 95 int CastRay(const Ray &ray, float &t, const float nearestT); 90 96 91 /** Returns piercing rays container.92 */93 RayContainer *GetPiercingRays();94 95 /** Adds a ray to the ray container.96 */97 void AddPiercingRay(Ray *ray);98 99 97 /// vertices are connected in counterclockwise order. 100 98 VertexContainer mVertices; … … 107 105 108 106 /// Rays piercing this polygon 109 RayContainer *mPiercingRays;107 RayContainer mPiercingRays; 110 108 111 static float sSideTolerance; 112 static float sSideToleranceSqrt; 109 /** The piercing rays of the polygon are inherited by the child fragments 110 @parm front_piece the front fragment inheriting the front rays 111 @param back_piece the back fragment inheriting the back rays 112 */ 113 void InheritRays(Polygon3 &front_piece, 114 Polygon3 &back_piece) const; 113 115 }; 114 116 -
trunk/VUT/GtpVisibilityPreprocessor/src/Ray.cpp
r328 r349 158 158 } 159 159 160 int Ray::ClassifyPlane(const Plane3 &plane, float minT, float maxT) 160 int Ray::ClassifyPlane(const Plane3 &plane, 161 const float minT, 162 const float maxT) const 161 163 { 162 Vector3 entp = Extrap(minT);163 Vector3 extp = Extrap(maxT);164 const Vector3 entp = Extrap(minT); 165 const Vector3 extp = Extrap(maxT); 164 166 165 int entSide = plane.Side(entp);166 int extSide = plane.Side(extp);167 const int entSide = plane.Side(entp); 168 const int extSide = plane.Side(extp); 167 169 168 170 if ((entSide == 0) && (extSide == 0)) 169 170 return Plane3::COINCIDENT;171 { 172 return COINCIDENT; 171 173 } 172 else if ((entSide <= 0) && (e ntSide <= 0))174 else if ((entSide <= 0) && (extSide <= 0)) 173 175 { 174 return Plane3::BACK_SIDE;176 return BACK; 175 177 } 176 else if ((entSide >= 0) && (e ntSide >= 0))178 else if ((entSide >= 0) && (extSide >= 0)) 177 179 { 178 return Plane3::FRONT_SIDE;180 return FRONT; 179 181 } 182 else if ((entSide <= 0) && (extSide >= 0)) 183 return BACK_FRONT; 180 184 181 return Plane3::SPLIT;185 return FRONT_BACK; 182 186 } 183 187 -
trunk/VUT/GtpVisibilityPreprocessor/src/Ray.h
r340 r349 24 24 25 25 enum { NO_INTERSECTION=0, INTERSECTION_OUT_OF_LIMITS, INTERSECTION }; 26 27 /// if ray is on back (front) side of plane, or goes from the front (back) to the back (front) 28 enum {FRONT, BACK, BACK_FRONT, FRONT_BACK, COINCIDENT}; 26 29 27 30 struct Intersection { … … 190 193 /** Classifies ray with respect to the plane. 191 194 */ 192 int ClassifyPlane(const Plane3 &plane, float minT, float maxT);195 int ClassifyPlane(const Plane3 &plane, const float minT, const float maxT) const; 193 196 194 197 private: -
trunk/VUT/GtpVisibilityPreprocessor/src/SamplingPreprocessor.cpp
r344 r349 55 55 DEL_PTR(mBspTree); 56 56 mBspTree = new BspTree(&mUnbounded); 57 58 57 ObjectContainer objects; 59 int prunedCells = 0;58 60 59 switch (BspTree::sConstructionMethod) 61 60 { … … 76 75 mBspTree->SetGenerateViewCells(true); 77 76 mBspTree->Construct(mSampleRays); 78 // prunedCells = mBspTree->MergeViewCells();79 77 80 78 mBspTree->CollectViewCells(mViewCells); 81 82 // Debug << "Collected " << (int)mViewCells.size() << " cells (" << prunedCells << " pruned)" << endl;83 79 break; 84 80 default: … … 169 165 170 166 if (mViewCellsType == BSP_VIEW_CELLS) 167 { 168 // cast ray to BSP tree to get intersection with view cells 169 if (mBspTree) 171 170 { 172 // cast ray to BSP tree to get intersection with view cells 173 if (mBspTree) 174 { 175 mBspTree->CastRay(ray); 171 mBspTree->CastRay(ray); 176 172 177 173 sampleContributions += AddObjectSamples(object, ray); 178 174 179 if (!ray.intersections.empty()) // second intersection found 180 { 181 sampleContributions += 182 AddObjectSamples(ray.intersections[0].mObject, ray); 183 } 184 } 175 if (!ray.intersections.empty()) // second intersection found 176 { 177 sampleContributions += 178 AddObjectSamples(ray.intersections[0].mObject, ray); 179 } 185 180 } 181 } 186 182 else 187 183 { … … 319 315 int maxTimeIdx = 0; 320 316 317 bool collectSamplesForBsp = 318 (mViewCellsType == BSP_VIEW_CELLS) && 319 (BspTree::sConstructionMethod == BspTree::FROM_RAYS) && 320 (totalSamples < mBspConstructionSamples); 321 321 322 cout << "totalSamples: " << totalSamples << endl; 322 323 … … 382 383 } 383 384 384 object->GetRandomSurfacePoint(point, normal);385 int faceIndex = object->GetRandomSurfacePoint(point, normal); 385 386 386 387 long samplesPerObjStart = GetTime(); … … 418 419 419 420 // construct a ray 420 SetupRay(ray, point, direction, Ray::LOCAL_RAY); 421 421 SetupRay(ray, point, direction, 422 collectSamplesForBsp ? Ray::LINE_SEGMENT : Ray::LOCAL_RAY); 423 424 // also add origin to sample in order to extract it as input polygons 425 if (0 && collectSamplesForBsp) 426 { 427 MeshInstance *meshInst = dynamic_cast<MeshInstance *>(object); 428 ray.intersections.push_back(Ray::Intersection(0.0, meshInst, faceIndex)); 429 } 430 422 431 sampleContributions = CastRay(object, ray); 423 432 … … 443 452 if (mViewCellsType == BSP_VIEW_CELLS) 444 453 { 445 // save rays for bsp tree construction 446 if ((BspTree::sConstructionMethod = BspTree::FROM_RAYS) && 447 (totalSamples < mBspConstructionSamples)) 454 // save rays for bsp tree construction 455 if (collectSamplesForBsp) 448 456 { 449 457 mSampleRays.push_back(new Ray(ray)); 450 458 } 451 459 else 452 460 { 453 461 // construct BSP tree using the samples 454 462 if (!mBspTree) 455 463 { … … 463 471 Export("vc_bsptree.x3d", false, false, true); 464 472 } 465 473 466 474 // some random view cells for output 467 475 if (pvsViewCells.empty()) … … 477 485 } 478 486 else 479 { 487 { 480 488 // check whether we can add the current ray to the rays 481 489 for (int k = 0; k < (int)ray.viewCells.size(); ++ k) … … 484 492 vcRays[j].push_back(ray); 485 493 } 486 } 494 } 487 495 } 488 496 … … 549 557 "#AvgRayContrib\n" << avgRayContrib << endl; 550 558 } 551 559 552 560 if (mViewCellsType == KD_VIEW_CELLS) 553 561 cout << "#totalPvsSize=" << mKdTree->CollectLeafPvs() << endl; … … 559 567 exporter->ExportKdTree(*mKdTree); 560 568 561 if (m ViewCellsType == BSP_VIEW_CELLS)569 if (mBspTree && (mViewCellsType == BSP_VIEW_CELLS)) 562 570 exporter->ExportBspTree(*mBspTree); 563 571 … … 579 587 delete exporter; 580 588 } 589 581 590 //-- several visualizations and statistics 582 591 if (1) { 583 if (m ViewCellsType == BSP_VIEW_CELLS)592 if (mBspTree && (mViewCellsType == BSP_VIEW_CELLS)) 584 593 { 585 594 bool exportSplits = false; … … 588 597 // export the bsp splits 589 598 if (exportSplits) 590 { 591 Exporter *exporter = Exporter::GetExporter("bsp_splits.x3d"); 592 593 if (exporter) 594 { 595 Material m; 596 m.mDiffuseColor = RgbColor(1, 0, 0); 597 exporter->SetForcedMaterial(m); 598 exporter->SetWireframe(); 599 exporter->ExportBspSplits(*mBspTree); 600 601 // take forced material, else big scenes cannot be viewed 602 m.mDiffuseColor = RgbColor(0, 1, 0); 603 exporter->SetForcedMaterial(m); 604 exporter->SetFilled(); 605 606 exporter->ResetForcedMaterial(); 607 608 // export scene geometry 609 if (0) 610 { 611 Material m;//= RandomMaterial(); 612 m.mDiffuseColor = RgbColor(0, 0, 1); 613 exporter->SetForcedMaterial(m); 614 615 for (int j = 0; j < objects.size(); ++ j) 616 exporter->ExportIntersectable(objects[j]); 617 618 delete exporter; 619 } 620 } 621 } 622 599 ExportSplits(objects); 600 623 601 for (int j = 0; j < pvsViewCells.size(); ++ j) 624 602 { … … 666 644 } 667 645 668 // output rest of the sobjects646 // output rest of the objects 669 647 if (0) 670 648 { … … 727 705 return true; 728 706 } 707 708 709 void SamplingPreprocessor::ExportSplits(const ObjectContainer &objects) 710 { 711 Exporter *exporter = Exporter::GetExporter("bsp_splits.x3d"); 712 713 if (exporter) 714 { 715 cout << "exporting splits ... "; 716 717 Material m; 718 m.mDiffuseColor = RgbColor(1, 0, 0); 719 exporter->SetForcedMaterial(m); 720 exporter->SetWireframe(); 721 exporter->ExportBspSplits(*mBspTree); 722 723 // take forced material, else big scenes cannot be viewed 724 m.mDiffuseColor = RgbColor(0, 1, 0); 725 exporter->SetForcedMaterial(m); 726 exporter->SetFilled(); 727 728 exporter->ResetForcedMaterial(); 729 730 // export rays 731 if (0) 732 { 733 RayContainer outRays; 734 735 for (int i = 0; i < mSampleRays.size(); ++ i) 736 { 737 // only rays piercing geometry 738 if (!mSampleRays[i]->intersections.empty()) 739 outRays.push_back(mSampleRays[i]); 740 } 741 if (BspTree::sConstructionMethod == BspTree::FROM_RAYS) 742 { 743 // export rays 744 exporter->ExportRays(outRays, 1000, RgbColor(1, 1, 0)); 745 } 746 } 747 748 // export scene geometry 749 if (1) 750 { 751 Material m;//= RandomMaterial(); 752 m.mDiffuseColor = RgbColor(0, 1, 0); 753 exporter->SetForcedMaterial(m); 754 exporter->SetWireframe(); 755 756 for (int j = 0; j < objects.size(); ++ j) 757 exporter->ExportIntersectable(objects[j]); 758 } 759 760 delete exporter; 761 762 cout << "finished" << endl; 763 } 764 } -
trunk/VUT/GtpVisibilityPreprocessor/src/SamplingPreprocessor.h
r335 r349 64 64 65 65 bool BuildBspTree(); 66 67 void ExportSplits(const ObjectContainer &objects); 66 68 }; 67 69 -
trunk/VUT/GtpVisibilityPreprocessor/src/Vector3.cpp
r340 r349 2 2 #include "Vector3.h" 3 3 4 float Vector3::sDistTolerance = 0.002f; 5 float Vector3::sDistToleranceSqrt = 0.000004f; 4 6 5 7 // Given min a vector to minimize and a candidate vector, replace -
trunk/VUT/GtpVisibilityPreprocessor/src/Vector3.h
r318 r349 36 36 Vector3(float X) { x = y = z = X; } 37 37 Vector3(const Vector3 &v) { x = v.x; y = v.y; z = v.z; } 38 39 /// the distance where two points are still considered equal 40 static float sDistTolerance; 41 static float sDistToleranceSqrt; 38 42 39 43 // Functions to get at the vector components -
trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.cpp
r342 r349 43 43 contribution for a minimum number splits in the tree. 44 44 */ 45 float BspTree::sLeast SplitsTable[] = {0, 0, 1, 0};45 float BspTree::sLeastPolySplitsTable[] = {0, 0, 1, 0}; 46 46 /** Evaluates split plane classification with respect to the plane's 47 47 contribution for a balanced tree. 48 48 */ 49 float BspTree::sBalancedTreeTable[] = {-1, 1, 0, 0}; 49 float BspTree::sBalancedPolysTable[] = {1, -1, 0, 0}; 50 51 /** Evaluates split plane classification with respect to the plane's 52 contribution for a minimum number of ray splits. 53 */ 54 float BspTree::sLeastRaySplitsTable[] = {0, 0, 1, 1, 0}; 55 /** Evaluates split plane classification with respect to the plane's 56 contribution for balanced rays. 57 */ 58 float BspTree::sBalancedRaysTable[] = {1, -1, 0, 0, 0}; 50 59 51 60 /****************************************************************/ … … 158 167 } 159 168 160 void BspInterior::SplitRays(RayContainer &rays, 161 RayContainer &frontRays, 162 RayContainer &backRays) 163 { 169 int BspInterior::SplitRays(RayContainer &rays, 170 RayContainer &frontRays, 171 RayContainer &backRays, 172 const AxisAlignedBox3 &box) 173 { 174 int splits = 0; 175 164 176 while (!rays.empty()) 165 177 { … … 172 184 173 185 // test with tree bounding box 174 /* if (!mBox.GetMinMaxT(*ray, &minT, &maxT))186 if (!box.GetMinMaxT(*ray, &minT, &maxT)) 175 187 continue; 188 176 189 if (minT < 0) // start ray from origin 177 190 minT = 0; 178 */ 191 179 192 // bound ray 180 193 if ((ray->GetType() == Ray::LOCAL_RAY) && … … 185 198 } 186 199 187 int classification = ray->ClassifyPlane(mPlane, minT, maxT); 188 200 const int classification = ray->ClassifyPlane(mPlane, minT, maxT); 201 202 ray->SetId(classification); 203 189 204 switch (classification) 190 205 { 191 case Plane3::COINCIDENT:206 case Ray::COINCIDENT: 192 207 break; 193 case Plane3::BACK_SIDE: 194 ray->SetId(BACK_RAY); 208 case Ray::BACK: 195 209 backRays.push_back(ray); 196 210 break; 197 case Plane3::FRONT_SIDE: 198 ray->SetId(FRONT_RAY); 211 case Ray::FRONT: 199 212 frontRays.push_back(ray); 200 213 break; 201 case Plane3::SPLIT: 202 ray->SetId(SPLIT_RAY); 214 case Ray::FRONT_BACK: 215 ray->SetId(Ray::FRONT_BACK); 216 backRays.push_back(ray); 217 ++ splits; 218 break; 219 case Ray::BACK_FRONT: 203 220 frontRays.push_back(ray); 204 backRays.push_back(ray); 205 //extp = splitPlane->FindIntersection(ray.GetLoc(), extp, &maxt); 221 ++ splits; 206 222 break; 207 223 default: 224 Debug << "Should not come here" << endl; 208 225 break; 209 226 } 210 227 } 228 229 return splits; 211 230 } 212 231 … … 215 234 PolygonContainer &backPolys, 216 235 PolygonContainer &coincident, 217 bool storePolys)236 const bool storePolys) 218 237 { 219 238 Polygon3 *splitPoly = NULL; … … 232 251 233 252 // classify polygon 234 int classification = poly->ClassifyPlane(mPlane);253 const int classification = poly->ClassifyPlane(mPlane); 235 254 236 255 Polygon3 *front_piece = NULL; … … 241 260 switch (classification) 242 261 { 243 case P lane3::COINCIDENT:262 case Polygon3::COINCIDENT: 244 263 coincident.push_back(poly); 245 264 break; 246 case P lane3::FRONT_SIDE:265 case Polygon3::FRONT_SIDE: 247 266 frontPolys.push_back(poly); 248 267 break; 249 case P lane3::BACK_SIDE:268 case Polygon3::BACK_SIDE: 250 269 backPolys.push_back(poly); 251 270 break; 252 case P lane3::SPLIT:271 case Polygon3::SPLIT: 253 272 front_piece = new Polygon3(poly->mParent); 254 273 back_piece = new Polygon3(poly->mParent); … … 262 281 ++ splits; // increase number of splits 263 282 264 //-- inherit rays 265 if (poly->mPiercingRays)266 InheritRays(*poly, *front_piece, *back_piece);267 283 //-- inherit rays from parent polygon 284 poly->InheritRays(*front_piece, *back_piece); 285 Debug << "p: " << poly->mPiercingRays.size() << " f: " << front_piece->mPiercingRays.size() << " b: " << back_piece->mPiercingRays.size() << endl; 286 268 287 // check if polygons still valid 269 288 if (front_piece->Valid()) … … 280 299 Debug << "split " << *poly << endl << *front_piece << endl << *back_piece << endl; 281 300 #endif 282 ProcessPolygon(&poly, storePolys); 283 301 ProcessPolygon(&poly, storePolys); 284 302 break; 285 303 default: … … 290 308 291 309 return splits; 292 }293 294 void BspInterior::InheritRays(const Polygon3 &poly,295 Polygon3 &front_piece,296 Polygon3 &back_piece)297 {298 RayContainer *rays = poly.mPiercingRays;299 300 RayContainer::const_iterator it, it_end = rays->end();301 302 for (it = rays->begin(); it != it_end; ++ it)303 {304 switch((*it)->GetId())305 {306 case BACK_RAY:307 back_piece.GetPiercingRays()->push_back(*it);308 break;309 case FRONT_RAY:310 front_piece.GetPiercingRays()->push_back(*it);311 break;312 }313 }314 310 } 315 311 … … 664 660 if (it != facePolyMap.end()) 665 661 { 666 (*it).second-> AddPiercingRay(ray);662 (*it).second->mPiercingRays.push_back(ray); 667 663 } 668 664 else … … 670 666 Polygon3 *poly = new Polygon3(face, obj->GetMesh()); 671 667 polys->push_back(poly); 672 poly-> AddPiercingRay(ray);668 poly->mPiercingRays.push_back(ray); 673 669 674 670 facePolyMap[face] = poly; … … 842 838 PolygonContainer &coincident, 843 839 RayContainer &rays, 844 RayContainer & backRays,845 RayContainer & frontRays)840 RayContainer &frontRays, 841 RayContainer &backRays) 846 842 { 847 843 mStat.nodes += 2; … … 855 851 #endif 856 852 857 // partitionrays858 interior->SplitRays(rays, frontRays, backRays );853 // subdivide rays into front and back rays 854 interior->SplitRays(rays, frontRays, backRays, mBox); 859 855 860 856 // split polygons with split plane … … 987 983 } 988 984 985 bool BspTree::SelectAxisAlignedPlane(Plane3 &plane, 986 const PolygonContainer &polys) const 987 { 988 AxisAlignedBox3 box; 989 box.Initialize(); 990 991 // create bounding box of region 992 Polygon3::IncludeInBox(polys, box); 993 994 int objectsBack = 0, objectsFront = 0; 995 int axis = 0; 996 float costRatio = MAX_FLOAT; 997 Vector3 position; 998 999 //-- area subdivision 1000 for (int i = 0; i < 3; ++ i) 1001 { 1002 float p = 0; 1003 float r = BestCostRatio(polys, box, i, p, objectsBack, objectsFront); 1004 1005 if (r < costRatio) 1006 { 1007 costRatio = r; 1008 axis = i; 1009 position = p; 1010 } 1011 } 1012 1013 if (costRatio >= sMaxCostRatio) 1014 return false; 1015 1016 Vector3 norm(0,0,0); norm[axis] = 1.0f; 1017 plane = Plane3(norm, position); 1018 1019 return true; 1020 } 1021 989 1022 Plane3 BspTree::SelectPlane(BspLeaf *leaf, 990 1023 PolygonContainer &polys, 991 1024 const RayContainer &rays) 992 1025 { 993 if (polys.size() == 0) 994 { 995 Debug << "Warning: No split candidate available\n"; 996 return Plane3(); 1026 if (polys.empty()) 1027 { 1028 Debug << "Warning: No autopartition polygon candidate available\n"; 1029 1030 // return axis aligned split 1031 AxisAlignedBox3 box; 1032 box.Initialize(); 1033 1034 // create bounding box of region 1035 Polygon3::IncludeInBox(polys, box); 1036 1037 const int axis = box.Size().DrivingAxis(); 1038 const Vector3 position = (box.Min()[axis] + box.Max()[axis])*0.5f; 1039 1040 Vector3 norm(0,0,0); norm[axis] = 1.0f; 1041 return Plane3(norm, position); 997 1042 } 998 1043 … … 1000 1045 ((int)polys.size() > sTermMaxPolysForAxisAligned)) 1001 1046 { 1002 AxisAlignedBox3 box; 1003 box.Initialize(); 1004 1005 // todo: area subdivision 1006 Polygon3::IncludeInBox(polys, box); 1007 1008 int objectsBack = 0, objectsFront = 0; 1009 int axis = 0; 1010 float costRatio = MAX_FLOAT; 1011 Vector3 position; 1012 1013 for (int i = 0; i < 3; ++ i) 1014 { 1015 float p = 0; 1016 float r = BestCostRatio(polys, box, i, p, objectsBack, objectsFront); 1017 1018 if (r < costRatio) 1019 { 1020 costRatio = r; 1021 axis = i; 1022 position = p; 1023 } 1024 } 1025 1026 if (costRatio < sMaxCostRatio) 1027 { 1028 Vector3 norm(0,0,0); norm[axis] = 1.0f; 1029 return Plane3(norm, position); 1030 } 1047 Plane3 plane; 1048 if (SelectAxisAlignedPlane(plane, polys)) 1049 return plane; 1031 1050 } 1032 1051 … … 1074 1093 int BspTree::GetNextCandidateIdx(int currentIdx, PolygonContainer &polys) 1075 1094 { 1076 int candidateIdx = Random(currentIdx --);1095 const int candidateIdx = Random(currentIdx --); 1077 1096 1078 1097 // swap candidates to avoid testing same plane 2 times … … 1101 1120 // needed for balanced view cells criterium 1102 1121 ViewCell::NewMail(); 1103 int backId = ViewCell::sMailId;1122 const int backId = ViewCell::sMailId; 1104 1123 ViewCell::NewMail(); 1105 int frontId = ViewCell::sMailId;1124 const int frontId = ViewCell::sMailId; 1106 1125 ViewCell::NewMail(); 1107 int frontAndBackId = ViewCell::sMailId;1126 const int frontAndBackId = ViewCell::sMailId; 1108 1127 1109 1128 PolygonContainer::const_iterator it, it_end = polys.end(); … … 1111 1130 for (it = polys.begin(); it != it_end; ++ it) 1112 1131 { 1113 int classification = (*it)->ClassifyPlane(candidatePlane);1132 const int classification = (*it)->ClassifyPlane(candidatePlane); 1114 1133 1115 1134 if (sSplitPlaneStrategy & BALANCED_POLYS) 1116 sumBalancedPolys += sBalanced TreeTable[classification];1135 sumBalancedPolys += sBalancedPolysTable[classification]; 1117 1136 1118 1137 if (sSplitPlaneStrategy & LEAST_SPLITS) 1119 sumSplits += sLeast SplitsTable[classification];1138 sumSplits += sLeastPolySplitsTable[classification]; 1120 1139 1121 1140 if (sSplitPlaneStrategy & LARGEST_POLY_AREA) 1122 1141 { 1123 if (classification == P lane3::COINCIDENT)1142 if (classification == Polygon3::COINCIDENT) 1124 1143 sumPolyArea += (*it)->GetArea(); 1125 1144 //totalArea += area; … … 1128 1147 if (sSplitPlaneStrategy & BLOCKED_RAYS) 1129 1148 { 1130 float blockedRays = (float)(*it)->GetPiercingRays()->size();1131 1132 if (classification == P lane3::COINCIDENT)1149 const float blockedRays = (float)(*it)->mPiercingRays.size(); 1150 1151 if (classification == Polygon3::COINCIDENT) 1133 1152 sumBlockedRays += blockedRays; 1134 1153 … … 1143 1162 // assure that we only count a view cell 1144 1163 // once for the front and once for the back side of the plane 1145 if (classification == P lane3::FRONT_SIDE)1164 if (classification == Polygon3::FRONT_SIDE) 1146 1165 { 1147 1166 if ((viewCell->mMailbox != frontId) && … … 1158 1177 } 1159 1178 } 1160 else if (classification == P lane3::BACK_SIDE)1179 else if (classification == Polygon3::BACK_SIDE) 1161 1180 { 1162 1181 if ((viewCell->mMailbox != backId) && … … 1190 1209 if (sSplitPlaneStrategy & BLOCKED_RAYS) 1191 1210 if (totalBlockedRays != 0) 1192 val += sBlockedRaysFactor * sumBlockedRays/ totalBlockedRays;1211 val += sBlockedRaysFactor * (totalBlockedRays - sumBlockedRays) / totalBlockedRays; 1193 1212 1194 1213 if (sSplitPlaneStrategy & BALANCED_VIEW_CELLS) … … 1218 1237 1219 1238 // test with tree bounding box 1220 /*if (!mBox.GetMinMaxT(*ray, &minT, &maxT))1239 if (!mBox.GetMinMaxT(*ray, &minT, &maxT)) 1221 1240 continue; 1222 1241 if (minT < 0) // start ray from origin 1223 minT = 0; */1242 minT = 0; 1224 1243 1225 1244 // bound ray … … 1231 1250 } 1232 1251 1233 int classification = ray->ClassifyPlane(candidatePlane, minT, maxT); 1252 const int classification = 1253 ray->ClassifyPlane(candidatePlane, minT, maxT); 1234 1254 1235 1255 if (sSplitPlaneStrategy & LEAST_RAY_SPLITS) 1236 1256 { 1237 sumBalancedRays += sBalanced TreeTable[classification];1257 sumBalancedRays += sBalancedRaysTable[classification]; 1238 1258 } 1239 1259 1240 1260 if (sSplitPlaneStrategy & BALANCED_RAYS) 1241 1261 { 1242 sumRaySplits += sLeast SplitsTable[classification];1262 sumRaySplits += sLeastRaySplitsTable[classification]; 1243 1263 } 1244 1264 } … … 1332 1352 environment->GetBoolValue("BspTree.storeSplitPolys", sStoreSplitPolys); 1333 1353 1334 environment->GetFloatValue("BspTree.Construction.sideTolerance", Polygon3::sSideTolerance);1335 Polygon3::sSideToleranceSqrt = Polygon3::sSideTolerance * Polygon3::sSideTolerance;1354 environment->GetFloatValue("BspTree.Construction.sideTolerance", Vector3::sDistTolerance); 1355 Vector3::sDistToleranceSqrt = Vector3::sDistTolerance * Vector3::sDistTolerance; 1336 1356 1337 1357 Debug << "BSP max depth: " << sTermMaxDepth << endl; … … 1379 1399 { 1380 1400 BspInterior *interior = dynamic_cast<BspInterior *>(node); 1401 1381 1402 nodeStack.push(interior->GetBack()); 1382 1403 nodeStack.push(interior->GetFront()); … … 1417 1438 } 1418 1439 1419 #ifdef _DEBUG1440 //#ifdef _DEBUG 1420 1441 Debug << "BSP stats: " 1421 1442 << "Depth: " << data.mDepth << " (max: " << sTermMaxDepth << "), " 1422 1443 << "#polygons: " << (int)data.mPolygons->size() << " (max: " << sTermMaxPolygons << "), " 1423 1444 << "#rays: " << (int)data.mRays->size() << " (max: " << sTermMaxRays << ")" << endl; 1424 #endif1445 //#endif 1425 1446 } 1426 1447 … … 1520 1541 entp = extp; 1521 1542 mint = maxt; // NOTE: need this? 1543 1544 if (ray.GetType() == Ray::LINE_SEGMENT && mint > 1.0f) 1545 break; 1546 1522 1547 BspRayTraversalData &s = tStack.top(); 1523 1548 -
trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.h
r344 r349 169 169 PolygonContainer &backPolys, 170 170 PolygonContainer &coincident, 171 bool storePolys = false);172 173 /** S plits the rays into front and back rays according to split plane171 const bool storePolys = false); 172 173 /** Subdivides the rays into front and back rays according to the split plane. 174 174 @param rays contains the rays to be split. The rays are 175 distributed to front and back rays.175 distributed into front and back rays. 176 176 @param frontRays returns rays on the front side of the plane 177 177 @param backRays returns rays on the back side of the plane 178 */ 179 void SplitRays(RayContainer &rays, 180 RayContainer &frontRays, 181 RayContainer &backRays); 178 @param box the bounding box of the scene 179 @returns the number of splits 180 */ 181 int SplitRays(RayContainer &rays, 182 RayContainer &frontRays, 183 RayContainer &backRays, 184 const AxisAlignedBox3 &box); 182 185 183 186 /** Stores polygon in node or discards them according to storePolys. … … 192 195 } 193 196 194 protected: 195 196 /** The piercing rays of the polygon are inherited by the child fragments 197 @param poly the parent polygon 198 @parm front_piece the front fragment inheriting the front rays 199 @param back_piece the back fragment inheriting the back rays 200 */ 201 void InheritRays(const Polygon3 &poly, 202 Polygon3 &front_piece, 203 Polygon3 &back_piece); 204 205 enum {BACK_RAY, FRONT_RAY, SPLIT_RAY}; 197 protected: 198 206 199 /// Splitting plane corresponding to this node 207 200 Plane3 mPlane; … … 474 467 PolygonContainer &coincident, 475 468 RayContainer &rays, 476 RayContainer & backRays,477 RayContainer &frontRays);469 RayContainer &frontRays, 470 RayContainer &backRays); 478 471 479 472 /** Filters polygons down the tree. … … 571 564 vector<SortableEntry> &splitCandidates) const; 572 565 566 /** Selects an axis aligned split plane. 567 Returns true if split is valied 568 */ 569 bool SelectAxisAlignedPlane(Plane3 &plane, const PolygonContainer &polys) const; 570 573 571 /// Pointer to the root of the tree 574 572 BspNode *mRoot; … … 642 640 contribution for a balanced tree. 643 641 */ 644 static float sLeast SplitsTable[4];642 static float sLeastPolySplitsTable[4]; 645 643 /** Evaluates split plane classification with respect to the plane's 646 644 contribution for a minimum number splits in the tree. 647 645 */ 648 static float sBalancedTreeTable[4]; 646 static float sBalancedPolysTable[4]; 647 /** Evaluates split plane classification with respect to the plane's 648 contribution for a minimum number of ray splits. 649 */ 650 static float sLeastRaySplitsTable[5]; 651 /** Evaluates split plane classification with respect to the plane's 652 contribution for balanced rays. 653 */ 654 static float sBalancedRaysTable[5]; 655 649 656 }; 650 657 -
trunk/VUT/GtpVisibilityPreprocessor/src/X3dExporter.cpp
r333 r349 72 72 stream<<"</IndexedLineSet>"<<endl; 73 73 stream<<"</Shape>"<<endl; 74 return true; 75 } 76 77 bool 78 X3dExporter::ExportRays(const RayContainer &rays, 79 const float length, 80 const RgbColor &color) 81 { 82 RayContainer::const_iterator ri = rays.begin(); 83 84 stream<<"<Shape>"<<endl; 85 stream<<"<Appearance>"<<endl; 86 stream<<"<Material ambientColor=\""<<color.r<<" "<<color.g<<" "<<color.b<< 87 "\" />"<<endl; 88 stream<<"</Appearance>"<<endl; 89 90 stream<<"<IndexedLineSet coordIndex=\""<<endl; 91 92 int index = 0; 93 for (; ri != rays.end(); ri++) { 94 stream<<index<<" "<<index+1<<" -1\n"; 95 index+=2; 96 } 97 98 stream<<"\" >"<<endl; 99 100 stream<<"<Coordinate point=\""<<endl; 101 102 ri = rays.begin(); 103 for (; ri != rays.end(); ri++) { 104 Vector3 a = (*ri)->GetLoc(); 105 106 Vector3 b; 107 if (length < 0) 108 b = (*ri)->GetLoc() - length*(*ri)->GetDir(); 109 else 110 if ((*ri)->intersections.size()==0) 111 b = (*ri)->GetLoc() + length*(*ri)->GetDir(); 112 else 113 b = (*ri)->Extrap((*ri)->intersections[0].mT); 114 115 stream<<a.x<<" "<<a.y<<" "<<a.z<<" ,"; 116 stream<<b.x<<" "<<b.y<<" "<<b.z<<" ,\n"; 117 } 118 119 stream<<"\" >"<<endl; 120 stream<<"</Coordinate>"<<endl; 121 stream<<"</IndexedLineSet>"<<endl; 122 stream<<"</Shape>"<<endl; 123 74 124 return true; 75 125 } … … 668 718 Polygon3 *backPoly = new Polygon3(); 669 719 670 if (planePoly->ClassifyPlane(*tData.mPlanes[i]) == P lane3::SPLIT)720 if (planePoly->ClassifyPlane(*tData.mPlanes[i]) == Polygon3::SPLIT) 671 721 { 672 722 planePoly->Split(*tData.mPlanes[i], *frontPoly, *backPoly, splitPts); -
trunk/VUT/GtpVisibilityPreprocessor/src/X3dExporter.h
r329 r349 76 76 ExportBspSplits(const BspTree &tree); 77 77 78 bool 79 ExportRays(const RayContainer &rays, 80 const float length=1000, 81 const RgbColor &color = RgbColor(1,1,1)); 82 78 83 static ViewCellContainer foundViewCells; // todo: remove this 79 84 protected:
Note: See TracChangeset
for help on using the changeset viewer.