- Timestamp:
- 10/14/05 02:05:13 (19 years ago)
- Location:
- trunk/VUT/GtpVisibilityPreprocessor/src
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/VUT/GtpVisibilityPreprocessor/src/Ray.cpp
r327 r328 35 35 invDir.SetValue(0.0); 36 36 37 SetI D();37 SetId(); 38 38 } 39 39 -
trunk/VUT/GtpVisibilityPreprocessor/src/Ray.h
r327 r328 140 140 141 141 // returns ID of this ray (use for mailboxes) 142 int GetI D() const { return ID; }142 int GetId() const { return ID; } 143 143 144 144 // returns the transfrom ID of the ray (use for ray transformations) … … 149 149 150 150 // set unique ID for a given ray - always avoid setting to zero 151 void SetI D() {151 void SetId() { 152 152 if ((ID = ++genID) == 0) 153 153 ID = ++genID; … … 156 156 // set ID to explicit value - it can be even 0 for rays transformed 157 157 // to the canonical object space to supress the mailbox failure. 158 void SetI D(int newID) {158 void SetId(int newID) { 159 159 ID = newID; 160 160 // note that transfID is not changed! -
trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.cpp
r327 r328 153 153 } 154 154 155 void BspInterior::SplitPolygons(PolygonContainer &polys, 156 PolygonContainer &frontPolys, 157 PolygonContainer &backPolys, 158 PolygonContainer &coincident, 159 int &splits, 160 bool storePolys) 155 void BspInterior::SplitRays(RayContainer &rays, 156 RayContainer &frontRays, 157 RayContainer &backRays) 158 { 159 while (!rays.empty()) 160 { 161 Ray *ray = rays.back(); 162 rays.pop_back(); 163 164 //-- ray-plane intersection 165 float maxT = 1e6; 166 float minT = 0; 167 168 // test with tree bounding box 169 /* if (!mBox.GetMinMaxT(*ray, &minT, &maxT)) 170 continue; 171 if (minT < 0) // start ray from origin 172 minT = 0; 173 */ 174 // bound ray 175 if ((ray->GetType() == Ray::LOCAL_RAY) && 176 (ray->intersections.empty()) && 177 (ray->intersections[0].mT <= maxT)) 178 { 179 maxT = ray->intersections[0].mT; 180 } 181 182 int classification = ray->ClassifyPlane(mPlane, minT, maxT); 183 184 switch (classification) 185 { 186 case Plane3::COINCIDENT: 187 break; 188 case Plane3::BACK_SIDE: 189 ray->SetId(BACK_RAY); 190 backRays.push_back(ray); 191 break; 192 case Plane3::FRONT_SIDE: 193 ray->SetId(FRONT_RAY); 194 frontRays.push_back(ray); 195 break; 196 case Plane3::SPLIT: 197 ray->SetId(SPLIT_RAY); 198 frontRays.push_back(ray); 199 backRays.push_back(ray); 200 //extp = splitPlane->FindIntersection(ray.GetLoc(), extp, &maxt); 201 break; 202 default: 203 break; 204 } 205 } 206 } 207 208 int BspInterior::SplitPolygons(PolygonContainer &polys, 209 PolygonContainer &frontPolys, 210 PolygonContainer &backPolys, 211 PolygonContainer &coincident, 212 bool storePolys) 161 213 { 162 214 Polygon3 *splitPoly = NULL; 215 216 int splits = 0; 163 217 164 218 #ifdef _Debug … … 196 250 197 251 //-- split polygon into front and back part 198 poly->Split(mPlane, *front_piece, *back_piece, splitVertices); 199 252 poly->Split(mPlane, 253 *front_piece, 254 *back_piece, 255 splitVertices); 256 200 257 ++ splits; // increase number of splits 258 259 //-- inherit rays 260 if (poly->mPiercingRays) 261 InheritRays(*poly, *front_piece, *back_piece); 201 262 202 263 // check if polygons still valid … … 222 283 } 223 284 } 285 286 return splits; 287 } 288 void BspInterior::InheritRays(const Polygon3 &poly, 289 Polygon3 &front_piece, 290 Polygon3 &back_piece) 291 { 292 RayContainer *rays = poly.mPiercingRays; 293 294 RayContainer::const_iterator it, it_end = rays->end(); 295 296 for (it = rays->begin(); it != it_end; ++ it) 297 { 298 switch((*it)->GetId()) 299 { 300 case BACK_RAY: 301 back_piece.GetPiercingRays()->push_back(*it); 302 break; 303 case FRONT_RAY: 304 front_piece.GetPiercingRays()->push_back(*it); 305 break; 306 } 307 } 224 308 } 225 309 … … 347 431 BspNode *firstNode = mRoot ? mRoot : new BspLeaf(); 348 432 349 tStack.push(BspTraversalData(firstNode, polys, 0, mRootCell ));433 tStack.push(BspTraversalData(firstNode, polys, 0, mRootCell, new RayContainer())); 350 434 351 435 while (!tStack.empty()) … … 369 453 370 454 // split viewcell polygons with respect to split plane 371 interior->SplitPolygons(*tData.mPolygons, 372 *frontPolys, 373 *backPolys, 374 coincident, 375 splits, 376 sStoreSplitPolys); 455 splits += interior->SplitPolygons(*tData.mPolygons, 456 *frontPolys, 457 *backPolys, 458 coincident, 459 sStoreSplitPolys); 377 460 378 461 // extract view cells associated with the split polygons … … 399 482 frontPolys, 400 483 tData.mDepth + 1, 401 frontViewCell)); 484 frontViewCell, 485 tData.mRays)); 402 486 403 487 tStack.push(BspTraversalData(interior->GetBack(), 404 488 backPolys, 405 489 tData.mDepth + 1, 406 backViewCell)); 490 backViewCell, 491 new RayContainer())); 407 492 } 408 493 … … 543 628 Ray *ray = *rit; 544 629 630 ray->SetId(-1); // reset id 631 545 632 for (int i = 0; i < (int)ray->intersections.size(); ++ i) 546 633 { … … 637 724 } 638 725 726 639 727 //-- continue subdivision 640 PolygonContainer *backPolys = new PolygonContainer();641 PolygonContainer *frontPolys = new PolygonContainer();642 728 PolygonContainer coincident; 643 729 730 BspSplitData splitData; 731 732 splitData.mPolys = tData.mPolygons; 733 splitData.mFrontPolys = new PolygonContainer(), 734 splitData.mBackPolys = new PolygonContainer(); 735 splitData.mCoincident = &coincident; 736 737 splitData.mRays = tData.mRays; 738 splitData.mFrontRays = new RayContainer(); 739 splitData.mBackRays = new RayContainer(); 740 644 741 // create new interior node and two leaf nodes 645 BspInterior *interior = SubdivideNode(dynamic_cast<BspLeaf *>(tData.mNode), 646 *tData.mPolygons, 647 *frontPolys, 648 *backPolys, 649 coincident, 650 *tData.mRays); 742 BspInterior *interior = 743 SubdivideNode(dynamic_cast<BspLeaf *>(tData.mNode), splitData); 651 744 652 745 ViewCell *frontViewCell = mRootCell; … … 664 757 ExtractViewCells(&backViewCell, 665 758 &frontViewCell, 666 coincident,759 *splitData.mCoincident, 667 760 interior->mPlane, 668 backPolys->empty(),669 frontPolys->empty());761 splitData.mBackPolys->empty(), 762 splitData.mFrontPolys->empty()); 670 763 671 764 // don't need coincident polygons anymore 672 765 interior->ProcessPolygons(&coincident, sStoreSplitPolys); 673 766 674 // split rays675 RayContainer *frontRays = NULL;676 RayContainer *backRays = NULL;677 678 if (tData.mRays)679 {680 RayContainer *frontRays = new RayContainer();681 RayContainer *backRays = new RayContainer();682 683 SplitRays(interior->mPlane, *tData.mRays, *frontRays, *backRays);684 }685 686 767 // push the children on the stack 687 768 tStack.push(BspTraversalData(interior->GetBack(), 688 backPolys,769 splitData.mBackPolys, 689 770 tData.mDepth + 1, 690 771 backViewCell, 691 backRays));772 splitData.mBackRays)); 692 773 693 774 tStack.push(BspTraversalData(interior->GetFront(), 694 frontPolys,775 splitData.mFrontPolys, 695 776 tData.mDepth + 1, 696 777 frontViewCell, 697 frontRays));778 splitData.mFrontRays)); 698 779 699 780 // cleanup … … 736 817 737 818 BspInterior *BspTree::SubdivideNode(BspLeaf *leaf, 738 PolygonContainer &polys, 739 PolygonContainer &frontPolys, 740 PolygonContainer &backPolys, 741 PolygonContainer &coincident, 742 const RayContainer &rays) 819 BspSplitData &splitData) 743 820 { 744 821 mStat.nodes += 2; 745 822 746 // add the new nodes to the tree + select subdivision plane 747 BspInterior *interior = new BspInterior(SelectPlane(leaf, polys, rays)); 823 // select subdivision plane 824 BspInterior *interior = 825 new BspInterior(SelectPlane(leaf, *splitData.mPolys, *splitData.mRays)); 748 826 749 827 #ifdef _DEBUG … … 751 829 #endif 752 830 753 // split polygon according to current plane754 int splits = 0;755 756 interior->SplitPolygons(polys,757 frontPolys,758 backPolys,759 coincident,760 splits,761 sStoreSplitPolys);762 763 mStat.splits += splits;831 // partition rays 832 interior->SplitRays(*splitData.mRays, 833 *splitData.mFrontRays, 834 *splitData.mBackRays); 835 836 // split polygons with split plane 837 mStat.splits +=interior->SplitPolygons(*splitData.mPolys, 838 *splitData.mFrontPolys, 839 *splitData.mBackPolys, 840 *splitData.mCoincident, 841 sStoreSplitPolys); 764 842 765 843 BspInterior *parent = leaf->GetParent(); … … 1393 1471 } 1394 1472 1395 1396 void BspTree::SplitRays(const Plane3 plane,1397 RayContainer &rays,1398 RayContainer &frontRays,1399 RayContainer &backRays)1400 {1401 while (!rays.empty())1402 {1403 Ray *ray = rays.back();1404 rays.pop_back();1405 1406 //-- ray-plane intersection1407 float maxT = 1e6;1408 float minT = 0;1409 1410 // test with tree bounding box1411 if (!mBox.GetMinMaxT(*ray, &minT, &maxT))1412 continue;1413 1414 if (minT < 0) // start ray from origin1415 minT = 0;1416 1417 // bound ray1418 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 }1445 }1446 }1447 1473 //} // GtpVisibilityPreprocessor -
trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.h
r327 r328 157 157 @param backPolys returns the polygons in the back of the split plane 158 158 @param coincident returns the polygons coincident to the split plane 159 @param splits returns the splits number of splits160 159 @param storePolys if the polygons should be stored in the node 161 */ 162 void SplitPolygons(PolygonContainer &polys, 163 PolygonContainer &frontPolys, 164 PolygonContainer &backPolys, 165 PolygonContainer &coincident, 166 int &splits, 167 bool storePolys = false); 160 @returns the number of splits 161 */ 162 int SplitPolygons(PolygonContainer &polys, 163 PolygonContainer &frontPolys, 164 PolygonContainer &backPolys, 165 PolygonContainer &coincident, 166 bool storePolys = false); 167 168 /** Splits the rays into front and back rays according to split plane 169 @param rays contains the rays to be split. The rays are 170 distributed to front and back rays. 171 @param frontRays returns rays on the front side of the plane 172 @param backRays returns rays on the back side of the plane 173 */ 174 void SplitRays(RayContainer &rays, 175 RayContainer &frontRays, 176 RayContainer &backRays); 168 177 169 178 /** Stores polygon in node or discards them according to storePolys. … … 179 188 180 189 protected: 181 190 191 /** The piercing rays of the polygon are inherited by the child fragments 192 @param poly the parent polygon 193 @parm front_piece the front fragment inheriting the front rays 194 @param back_piece the back fragment inheriting the back rays 195 */ 196 void InheritRays(const Polygon3 &poly, 197 Polygon3 &front_piece, 198 Polygon3 &back_piece); 199 200 enum {BACK_RAY, FRONT_RAY, SPLIT_RAY}; 182 201 /// Splitting plane corresponding to this node 183 202 Plane3 mPlane; … … 249 268 const int depth, 250 269 ViewCell *viewCell, 251 RayContainer *rays = NULL):270 RayContainer *rays): 252 271 mNode(node), 253 272 mPolygons(polys), … … 257 276 {} 258 277 }; 278 279 /** given as argument for a node subdivision. 280 Stores the polyons and rays and the returned 281 front and back fragments. 282 */ 283 struct BspSplitData 284 { 285 PolygonContainer *mPolys; 286 PolygonContainer *mFrontPolys; 287 PolygonContainer *mBackPolys; 288 PolygonContainer *mCoincident; 289 RayContainer *mRays; 290 RayContainer *mBackRays; 291 RayContainer *mFrontRays; 292 }; 259 293 260 294 typedef std::stack<BspTraversalData> BspTraversalStack; … … 393 427 /** Subdivide leaf. 394 428 @param leaf the leaf to be subdivided 395 @param polys the input polygons 396 @param frontPolys returns the polygons in the front of the split plane 397 @param backPolys returns the polygons in the back of the split plane 398 @param coincident returns the polygons coincident to the split plane 399 @param rays ray container used to guide the split process 429 @param splitData data relevant for the splti 400 430 @returns the root of the subdivision 401 431 */ 402 432 BspInterior *SubdivideNode(BspLeaf *leaf, 403 PolygonContainer &polys, 404 PolygonContainer &frontPolys, 405 PolygonContainer &backPolys, 406 PolygonContainer &coincident, 407 const RayContainer &rays); 433 BspSplitData &splitData); 408 434 409 435 /** Filters polygons down the tree. … … 501 527 vector<SortableEntry> &splitCandidates) const; 502 528 503 /** Splits the rays into front and back rays according to split plane504 @param rays contains the rays to be split. The rays are505 distributed to front and back rays.506 @param frontRays returns rays on the front side of the plane507 @param backRays returns rays on the back side of the plane508 */509 void BspTree::SplitRays(const Plane3 plane,510 RayContainer &rays,511 RayContainer &frontRays,512 RayContainer &backRays);513 529 514 530 /// Pointer to the root of the tree
Note: See TracChangeset
for help on using the changeset viewer.