Changeset 327 for trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.cpp
- Timestamp:
- 10/13/05 17:58:37 (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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 }
Note: See TracChangeset
for help on using the changeset viewer.