- Timestamp:
- 10/13/05 17:58:37 (19 years ago)
- Location:
- trunk/VUT/GtpVisibilityPreprocessor/src
- Files:
-
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/VUT/GtpVisibilityPreprocessor/src/Mesh.h
r308 r327 24 24 class Face { 25 25 public: 26 Face(): mVertexIndices() {}26 Face(): mVertexIndices() {} 27 27 Face(const int a, const int b, const int c):mVertexIndices(3) { 28 28 mVertexIndices[0] = a; … … 31 31 } 32 32 33 Face(const int a, const int b, const int c, const int d):mVertexIndices(4) { 33 Face(const int a, const int b, const int c, const int d): 34 mVertexIndices(4) { 34 35 mVertexIndices[0] = a; 35 36 mVertexIndices[1] = b; … … 41 42 42 43 /// list of vertex pointers 43 VertexIndexContainer mVertexIndices; 44 VertexIndexContainer mVertexIndices; 44 45 }; 45 46 -
trunk/VUT/GtpVisibilityPreprocessor/src/Plane3.h
r290 r327 8 8 class Plane3 { 9 9 public: 10 10 11 Vector3 mNormal; 11 12 float mD; … … 28 29 mD = -DotProd(normal, point); 29 30 } 31 32 // relation of objects with the plane 33 enum {BACK_SIDE, FRONT_SIDE, SPLIT, COINCIDENT}; 30 34 31 35 float Distance(const Vector3 &v) const { -
trunk/VUT/GtpVisibilityPreprocessor/src/Polygon3.cpp
r322 r327 132 132 int classification = ClassifyPlane(plane); 133 133 134 if (classification == BACK_SIDE)134 if (classification == Plane3::BACK_SIDE) 135 135 return -1; 136 else if (classification == FRONT_SIDE)136 else if (classification == Plane3::FRONT_SIDE) 137 137 return 1; 138 138 … … 161 161 if (onFrontSide && onBackSide) // split 162 162 { 163 return SPLIT;163 return Plane3::SPLIT; 164 164 } 165 165 // 3 vertices enough to decide coincident 166 166 else if (((++ count) >= 3) && !onFrontSide && !onBackSide) 167 167 { 168 return COINCIDENT;168 return Plane3::COINCIDENT; 169 169 } 170 170 } … … 172 172 if (onBackSide) 173 173 { 174 return BACK_SIDE;174 return Plane3::BACK_SIDE; 175 175 } 176 176 else if (onFrontSide) 177 177 { 178 return FRONT_SIDE;179 } 180 181 return COINCIDENT; // plane and polygon are coincident178 return Plane3::FRONT_SIDE; 179 } 180 181 return Plane3::COINCIDENT; // plane and polygon are coincident 182 182 } 183 183 -
trunk/VUT/GtpVisibilityPreprocessor/src/Polygon3.h
r321 r327 42 42 @param splitPts returns the split points 43 43 */ 44 void Polygon3::Split(const Plane3 &partition,45 46 47 44 void Split(const Plane3 &partition, 45 Polygon3 &front, 46 Polygon3 &back, 47 VertexContainer &splitPts); 48 48 49 49 /** Returns the area of this polygon. 50 50 */ 51 51 float GetArea() const; 52 53 enum {BACK_SIDE, FRONT_SIDE, SPLIT, COINCIDENT};54 52 55 53 /** Classify polygon with respect to the plane. -
trunk/VUT/GtpVisibilityPreprocessor/src/Preprocessor.cpp
r321 r327 152 152 153 153 ObjectContainer objects; 154 RayContainer rays;154 RayContainer *rays = new RayContainer(); 155 155 156 156 switch (BspTree::sConstructionMethod) … … 167 167 DeleteViewCells(); // we generate new view cells 168 168 mSceneGraph->CollectObjects(&objects); 169 mBspTree->Construct( objects,rays, &mViewCells);169 mBspTree->Construct(rays, &mViewCells); 170 170 break; 171 171 default: -
trunk/VUT/GtpVisibilityPreprocessor/src/Ray.cpp
r191 r327 1 1 #include "Ray.h" 2 2 #include "Plane3.h" 3 3 4 4 // ========================================================= … … 158 158 } 159 159 160 int Ray::ClassifyPlane(const Plane3 &plane, float minT, float maxT) 161 { 162 Vector3 entp = Extrap(minT); 163 Vector3 extp = Extrap(maxT); 164 165 int entSide = plane.Side(entp); 166 int extSide = plane.Side(extp); 167 168 if ((entSide == 0) && (extSide == 0)) 169 { 170 return Plane3::COINCIDENT; 171 } 172 else if ((entSide <= 0) && (entSide <= 0)) 173 { 174 return Plane3::BACK_SIDE; 175 } 176 else if ((entSide >= 0) && (entSide >= 0)) 177 { 178 return Plane3::FRONT_SIDE; 179 } 180 181 return Plane3::SPLIT; 182 } 183 160 184 ostream & 161 185 operator<<(ostream &s, const PassingRaySet &set) -
trunk/VUT/GtpVisibilityPreprocessor/src/Ray.h
r308 r327 60 60 vector<MeshInstance *> meshes; 61 61 vector<ViewCell *> viewCells; 62 62 63 63 // constructors 64 64 Ray(const Vector3 &wherefrom, … … 188 188 void SetDepth(int newDepth) { depth = newDepth;} 189 189 190 /** Classifies ray with respect to the plane. 191 */ 192 int ClassifyPlane(const Plane3 &plane, float minT, float maxT); 193 190 194 private: 191 195 Vector3 loc, dir; // Describes ray origin and vector … … 222 226 223 227 friend class AxisAlignedBox3; 224 friend class Plane ;228 friend class Plane3; 225 229 226 230 // for CKDR GEMS -
trunk/VUT/GtpVisibilityPreprocessor/src/SamplingPreprocessor.cpp
r322 r327 114 114 sampleContributions += AddObjectSamples(object, ray); 115 115 116 if ( ray.intersections.size() > 0) // second intersection found116 if (!ray.intersections.empty()) // second intersection found 117 117 { 118 118 sampleContributions += … … 379 379 rays[i].push_back(ray); 380 380 381 if ( ray.intersections.size()) {381 if (!ray.intersections.empty()) { 382 382 // check whether we can add this to the rays 383 383 for (int j = 0; j < pvsOut; j++) { -
trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.cpp
r326 r327 12 12 #include <iomanip> 13 13 #include "Exporter.h" 14 #include "Plane3.h" 14 15 15 16 int BspTree::sTermMaxPolygons = 10; … … 160 161 { 161 162 Polygon3 *splitPoly = NULL; 163 162 164 #ifdef _Debug 163 165 Debug << "splitting polygons of node " << this << " with plane " << mPlane << endl; … … 170 172 //Debug << "New polygon with plane: " << poly->GetSupportingPlane() << "\n"; 171 173 172 // get polygon classification174 // classify polygon 173 175 int classification = poly->ClassifyPlane(mPlane); 174 176 … … 180 182 switch (classification) 181 183 { 182 case P olygon3::COINCIDENT:184 case Plane3::COINCIDENT: 183 185 coincident.push_back(poly); 184 186 break; 185 case P olygon3::FRONT_SIDE:187 case Plane3::FRONT_SIDE: 186 188 frontPolys.push_back(poly); 187 189 break; 188 case P olygon3::BACK_SIDE:190 case Plane3::BACK_SIDE: 189 191 backPolys.push_back(poly); 190 192 break; 191 case P olygon3::SPLIT:193 case Plane3::SPLIT: 192 194 front_piece = new Polygon3(poly->mParent); 193 195 back_piece = new Polygon3(poly->mParent); … … 505 507 mStat.polys = AddToPolygonSoup(viewCells, *polys); 506 508 507 // construct tree from viewcell polygons508 Construct(polys );509 // construct tree from the view cell polygons 510 Construct(polys, NULL); 509 511 } 510 512 … … 521 523 522 524 // construct tree from polygon soup 523 Construct(polys, viewCells); 524 } 525 526 void BspTree::Construct(const ObjectContainer &objects, 527 const RayContainer &rays, 525 Construct(polys, NULL, viewCells); 526 } 527 528 void BspTree::Construct(RayContainer *rays, 528 529 ViewCellContainer *viewCells) 529 530 { 530 531 PolygonContainer *polys = new PolygonContainer(); 531 532 532 // copy mesh instance polygons into one big polygon soup 533 mStat.polys = AddToPolygonSoup(objects, *polys); 534 535 RayContainer::const_iterator rit, rit_end = rays.end(); 533 RayContainer::const_iterator rit, rit_end = rays->end(); 536 534 537 535 long startTime = GetTime(); 538 Debug << "**** Casting rays into polygons ****\n"; 539 540 //-- cast rays into all polygons 541 for (rit = rays.begin(); rit != rays.end(); ++ rit) 536 Debug << "**** Extracting polygons from rays ****\n"; 537 538 std::map<Face *, Polygon3 *> facePolyMap; 539 540 //-- extract polygons from faces stored in the rays 541 for (rit = rays->begin(); rit != rit_end; ++ rit) 542 542 { 543 543 Ray *ray = *rit; 544 545 PolygonContainer::const_iterator pit, pit_end = polys->end(); 546 547 for (pit = polys->begin(); pit != pit_end; ++ pit) 548 { 549 Polygon3 *poly = *pit; 544 545 for (int i = 0; i < (int)ray->intersections.size(); ++ i) 546 { 547 MeshInstance *obj = dynamic_cast<MeshInstance *>(ray->intersections[i].mObject); 548 Face *face = obj->GetMesh()->mFaces[i]; 550 549 551 float t = 0; 552 float nearestT = 0; 553 554 if (poly->CastRay(*ray, t, nearestT) > 0) 555 poly->AddPiercingRay(ray); 556 } 557 } 558 559 Debug << "**** Finished ray casting ****\n"; 550 std::map<Face *, Polygon3 *>::iterator it= facePolyMap.find(face); 551 552 if (it != facePolyMap.end()) 553 { 554 (*it).second->AddPiercingRay(ray); 555 } 556 else 557 { 558 Polygon3 *poly = new Polygon3(face, obj->GetMesh()); 559 polys->push_back(poly); 560 poly->AddPiercingRay(ray); 561 562 facePolyMap[face] = poly; 563 } 564 } 565 } 566 567 568 mStat.polys = (int)polys->size(); 569 570 Debug << "**** Finished polygon extraction ****\n"; 560 571 Debug << "ray casting time: " << TimeDiff(startTime, GetTime())*1e-3 << "s" << endl; 561 572 562 Construct(polys, viewCells);563 } 564 565 void BspTree::Construct(PolygonContainer *polys, ViewCellContainer *viewCells)573 Construct(polys, rays, viewCells); 574 } 575 576 void BspTree::Construct(PolygonContainer *polys, RayContainer *rays, ViewCellContainer *viewCells) 566 577 { 567 578 std::stack<BspTraversalData> tStack; 568 579 569 BspTraversalData tData(new BspLeaf(), polys, 0, mRootCell );580 BspTraversalData tData(new BspLeaf(), polys, 0, mRootCell, rays); 570 581 tStack.push(tData); 571 582 … … 670 681 RayContainer *backRays = new RayContainer(); 671 682 672 Plane3 plane; 673 SplitRays(plane, *tData.mRays, *frontRays, *backRays); 683 SplitRays(interior->mPlane, *tData.mRays, *frontRays, *backRays); 674 684 } 675 685 … … 1022 1032 if (sSplitPlaneStrategy & LARGEST_POLY_AREA) 1023 1033 { 1024 if (classification == P olygon3::COINCIDENT)1034 if (classification == Plane3::COINCIDENT) 1025 1035 sumPolyArea += (*it)->GetArea(); 1026 1036 //totalArea += area; … … 1031 1041 { 1032 1042 float blockedRays = (float)(*it)->GetPiercingRays()->size(); 1033 if (classification == P olygon3::COINCIDENT)1043 if (classification == Plane3::COINCIDENT) 1034 1044 { 1035 1045 sumBlockedRays += blockedRays; … … 1044 1054 MeshInstance *viewCell = (*it)->mParent; 1045 1055 1046 if (classification == P olygon3::FRONT_SIDE)1056 if (classification == Plane3::FRONT_SIDE) 1047 1057 frontViewCells.push_back(viewCell); 1048 else if (viewCell && (classification == P olygon3::BACK_SIDE))1058 else if (viewCell && (classification == Plane3::BACK_SIDE)) 1049 1059 backViewCells.push_back(viewCell); 1050 1060 } … … 1249 1259 1250 1260 // bound ray 1251 if ((ray.GetType() == Ray::LOCAL_RAY) 1252 ( (int)ray.intersections.size() > 0)&&1261 if ((ray.GetType() == Ray::LOCAL_RAY) && 1262 (!ray.intersections.empty()) && 1253 1263 (ray.intersections[0].mT <= maxt)) 1254 1264 { … … 1383 1393 } 1384 1394 1395 1385 1396 void BspTree::SplitRays(const Plane3 plane, 1386 1387 1388 1397 RayContainer &rays, 1398 RayContainer &frontRays, 1399 RayContainer &backRays) 1389 1400 { 1390 1401 while (!rays.empty()) 1391 1402 { 1392 //TODO 1403 Ray *ray = rays.back(); 1404 rays.pop_back(); 1405 1406 //-- ray-plane intersection 1407 float maxT = 1e6; 1408 float minT = 0; 1409 1410 // test with tree bounding box 1411 if (!mBox.GetMinMaxT(*ray, &minT, &maxT)) 1412 continue; 1413 1414 if (minT < 0) // start ray from origin 1415 minT = 0; 1416 1417 // bound ray 1418 if ((ray->GetType() == Ray::LOCAL_RAY) && 1419 (ray->intersections.empty()) && 1420 (ray->intersections[0].mT <= maxT)) 1421 { 1422 maxT = ray->intersections[0].mT; 1423 } 1424 1425 int classification = ray->ClassifyPlane(plane, minT, maxT); 1426 1427 switch (classification) 1428 { 1429 case Plane3::COINCIDENT: 1430 break; 1431 case Plane3::BACK_SIDE: 1432 backRays.push_back(ray); 1433 break; 1434 case Plane3::FRONT_SIDE: 1435 frontRays.push_back(ray); 1436 break; 1437 case Plane3::SPLIT: 1438 frontRays.push_back(ray); 1439 backRays.push_back(ray); 1440 //extp = splitPlane->FindIntersection(ray.GetLoc(), extp, &maxt); 1441 break; 1442 default: 1443 break; 1444 } 1393 1445 } 1394 1446 } -
trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.h
r325 r327 287 287 void Construct(const ObjectContainer &objects, ViewCellContainer *viewCells); 288 288 289 /** Constructs the tree from the given list of polygons. 290 @param viewCells if not NULL, new view cells are 291 created in the leafs and stored in the conatainer 292 */ 293 void Construct(PolygonContainer *polys, ViewCellContainer *viewCells = NULL); 294 295 /** Constructs the tree from a list of scene geometry and a 296 given bundle of rays. 297 @param objects list of objects 289 /** Constructs the tree from a given bundle of rays. 298 290 @param rays the bundle of sample rays 299 291 @param viewCells if not NULL, new view cells are 300 292 created in the leafs and stored in the conatainer 301 293 */ 302 void Construct(const ObjectContainer &objects, 303 const RayContainer &rays, 294 void Construct(RayContainer *rays, 304 295 ViewCellContainer *viewCells = NULL); 305 296 … … 353 344 }; 354 345 355 /** Evaluates the contribution of the candidate split plane.356 @note the polygons can be reordered in the process.357 @returns the cost of the candidate split plane358 */359 float SplitPlaneCost(PolygonContainer &polys,360 const Plane3 &candidatePlane,361 const RayContainer &rays);362 346 363 347 /** Evaluates tree stats in the BSP tree leafs. … … 371 355 */ 372 356 BspNode *Subdivide(BspTraversalStack &tStack, BspTraversalData &tData); 357 358 /** Constructs the tree from the given list of polygons. 359 @param rayContainer stores bundle of rays on which subdivision may be based 360 @param viewCells if not NULL, new view cells are 361 created in the leafs and stored in the conatainer 362 */ 363 void Construct(PolygonContainer *polys, RayContainer *rays, ViewCellContainer *viewCells = NULL); 373 364 374 365 /** Selects the best possible splitting plane. … … 381 372 PolygonContainer &polys, 382 373 const RayContainer &ray); 374 375 /** Evaluates the contribution of the candidate split plane. 376 @note the polygons can be reordered in the process. 377 @returns the cost of the candidate split plane 378 */ 379 float SplitPlaneCost(PolygonContainer &polys, 380 const Plane3 &candidatePlane, 381 const RayContainer &rays); 383 382 384 383 /** Filters next view cell down the tree and inserts it into the appropriate leaves -
trunk/VUT/GtpVisibilityPreprocessor/src/X3dExporter.cpp
r322 r327 667 667 Polygon3 *backPoly = new Polygon3(); 668 668 669 if (planePoly->ClassifyPlane(*tData.mPlanes[i]) == P olygon3::SPLIT)669 if (planePoly->ClassifyPlane(*tData.mPlanes[i]) == Plane3::SPLIT) 670 670 { 671 671 planePoly->Split(*tData.mPlanes[i], *frontPoly, *backPoly, splitPts);
Note: See TracChangeset
for help on using the changeset viewer.