Changeset 360 for trunk/VUT/GtpVisibilityPreprocessor
- Timestamp:
- 10/28/05 18:13:22 (19 years ago)
- Location:
- trunk/VUT/GtpVisibilityPreprocessor/src
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/VUT/GtpVisibilityPreprocessor/src/Exporter.h
r349 r360 15 15 class AxisAlignedBox3; 16 16 class Intersectable; 17 class BspLeaf; 17 18 18 19 class Exporter … … 70 71 virtual void 71 72 ExportBspSplits(const BspTree &tree) = 0; 73 virtual void 74 ExportLeavesGeometry(const BspTree &tree, const vector<BspLeaf *> &leaves) = 0; 72 75 73 76 void SetExportRayDensity(const bool d) { mExportRayDensity = d; } -
trunk/VUT/GtpVisibilityPreprocessor/src/Polygon3.cpp
r349 r360 375 375 } 376 376 } 377 378 int Polygon3::ClassifyPlane(const PolygonContainer &polys, const Plane3 &plane) 379 { 380 PolygonContainer::const_iterator it; 381 382 bool onFrontSide = false; 383 bool onBackSide = false; 384 385 int count = 0; 386 387 // find possible line-plane intersections 388 for (it = polys.begin(); it != polys.end(); ++ it) 389 { 390 int cf = (*it)->ClassifyPlane(plane); 391 392 if (cf == FRONT_SIDE) 393 onFrontSide = true; 394 else if (cf == BACK_SIDE) 395 onBackSide = true; 396 397 //TODO: check if split goes through vertex 398 if ((cf == SPLIT) || (onFrontSide && onBackSide)) // split 399 { 400 return SPLIT; 401 } 402 } 403 404 if (onBackSide) 405 { 406 return BACK_SIDE; 407 } 408 else if (onFrontSide) 409 { 410 return FRONT_SIDE; 411 } 412 413 return COINCIDENT; // plane and polygon are coincident 414 } -
trunk/VUT/GtpVisibilityPreprocessor/src/Polygon3.h
r349 r360 95 95 int CastRay(const Ray &ray, float &t, const float nearestT); 96 96 97 /** Classify polygons with respect to the plane. 98 @returns one of BACK_SIDE, FRONT_SIDE, SPLIT, COINCIDENT 99 */ 100 static int ClassifyPlane(const PolygonContainer &polys, const Plane3 &plane); 101 97 102 /// vertices are connected in counterclockwise order. 98 103 VertexContainer mVertices; -
trunk/VUT/GtpVisibilityPreprocessor/src/SamplingPreprocessor.cpp
r359 r360 617 617 if (exportSplits) 618 618 ExportSplits(objects); 619 619 620 Exporter *exporter = Exporter::GetExporter("viewCells.x3d"); 621 622 if (exporter) 623 { 624 //exporter->ExportLeavesGeometry(mBspTree, leaves); 625 626 delete exporter; 627 } 628 620 629 for (int j = 0; j < pvsViewCells.size(); ++ j) 621 630 { -
trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.cpp
r353 r360 39 39 40 40 bool BspTree::sStoreSplitPolys = false; 41 42 int BspNode::mailID = 1; 41 43 42 44 /** Evaluates split plane classification with respect to the plane's … … 492 494 { 493 495 Polygon3 *poly = new Polygon3((*fi), mesh); 494 poly->mParent = parent; // set parent intersectable 495 polys.push_back(poly); 496 497 if (poly->Valid()) 498 { 499 poly->mParent = parent; // set parent intersectable 500 polys.push_back(poly); 501 } 502 else 503 DEL_PTR(poly); 496 504 } 497 505 return (int)mesh->mFaces.size(); … … 512 520 { 513 521 mBox.Include(viewCells[i]->GetBox()); // add to BSP tree aabb 514 polysSize += AddMeshToPolygons(viewCells[i]->GetMesh(), 515 polys, viewCells[i]); 522 polysSize += AddMeshToPolygons(viewCells[i]->GetMesh(), polys, viewCells[i]); 516 523 } 517 524 } … … 1678 1685 return splits; 1679 1686 } 1680 /* 1681 void BspTree::ExtractSplitPlanes(BspNode *n, vector<Plane *> planes)1687 1688 void BspTree::ExtractSplitPlanes(BspNode *n, vector<Plane3 *> planes, vector<bool> sides) const 1682 1689 { 1683 1690 while (!n->IsRoot()) 1684 1691 { 1685 1692 if (!n->IsLeaf()) 1686 planes.push_back(dynamic_cast<BspInterior *>(n)->GetPlane(); 1693 planes.push_back(dynamic_cast<BspInterior *>(n)->GetPlane()); 1694 1695 sides.push_back(n->GetParent()->mFront == n); 1687 1696 1688 1697 n = n->GetParent(); … … 1690 1699 } 1691 1700 1692 void BspTree::ExtractGeometry(BspNode *n, PolygonContainer &polys) 1693 { 1694 vector<Plane *> planes; 1695 ExtractSplitPlanes(n, planes); 1696 1697 while (!tStack.empty()) 1698 { 1699 // filter polygons donw the tree 1700 BspSplitData tData = tStack.top(); 1701 tStack.pop(); 1702 1703 if (!tData.mNode->IsLeaf()) 1704 { 1705 BspInterior *interior = dynamic_cast<BspInterior *>(tData.mNode); 1706 if (tData.mNode != tree.GetRoot()) 1707 tData.mSides.push_back(tData.mIsFront); // add current side 1708 1709 // bounded plane is added to the polygons 1710 Polygon3 *planePoly = tree.GetBoundingBox().CrossSection(*interior->GetPlane()); 1711 1712 // do all the splits with the previous planes 1713 for (int i = 0; i < (int)tData.mPlanes.size(); ++i) 1701 void BspTree::ConstructGeometry(BspNode *n, PolygonContainer &cell) const 1702 { 1703 stack<BspNode *> tStack; 1704 1705 vector<Plane3 *> planes; 1706 vector<bool> sides; 1707 1708 ExtractSplitPlanes(n, planes, sides); 1709 1710 PolygonContainer candidatePolys; 1711 1712 // bounded plane is added to the polygons 1713 for (int i = 0; i < (int)planes.size(); ++ i) 1714 { 1715 candidatePolys.push_back(GetBoundingBox().CrossSection(*planes[i])); 1716 } 1717 1718 for (int i = 0; i < 6; ++ i) 1719 { 1720 VertexContainer vertices; 1721 1722 for (int j = 0; j < 4; ++ j) 1723 vertices.push_back(mBox.GetFace(i).mVertices[j]); 1724 1725 candidatePolys.push_back(new Polygon3(vertices)); 1726 } 1727 1728 for (int i = 0; i < (int)candidatePolys.size(); ++ i) 1729 { 1730 bool inside = true; 1731 1732 // polygon is split with all other planes 1733 for (int j = 0; (j < planes.size()) && inside; ++ j) 1734 { 1735 Plane3 *plane = planes[j]; 1736 1737 if (i == j) // same plane 1738 continue; 1739 1740 VertexContainer splitPts; 1741 Polygon3 *frontPoly, *backPoly; 1742 1743 int cf = candidatePolys[i]->ClassifyPlane(*plane); 1744 1745 // split new polygon with all previous planes 1746 switch(cf) 1714 1747 { 1715 VertexContainer splitPts; 1716 Polygon3 *frontPoly = new Polygon3(); 1717 Polygon3 *backPoly = new Polygon3(); 1718 1719 if (planePoly->ClassifyPlane(*tData.mPlanes[i]) == Polygon3::SPLIT) 1720 { 1721 planePoly->Split(*tData.mPlanes[i], *frontPoly, *backPoly, splitPts); 1722 DEL_PTR(planePoly); 1723 1724 if(tData.mSides[i] == true) 1748 case Polygon3::SPLIT: 1749 frontPoly = new Polygon3(); 1750 backPoly = new Polygon3(); 1751 1752 candidatePolys[i]->Split(*plane, *frontPoly, *backPoly, splitPts); 1753 DEL_PTR(candidatePolys[i]); 1754 1755 if(sides[j] == true) 1725 1756 { 1726 planePoly= frontPoly;1757 candidatePolys[i] = frontPoly; 1727 1758 DEL_PTR(backPoly); 1728 1759 } 1729 1760 else 1730 1761 { 1731 planePoly= backPoly;1762 candidatePolys[i] = backPoly; 1732 1763 DEL_PTR(frontPoly); 1733 1764 } 1734 } 1765 break; 1766 1767 case Polygon3::BACK_SIDE: 1768 if (sides[i]) 1769 inside = false; 1770 break; 1771 case Polygon3::FRONT_SIDE: 1772 if (!sides[i]) 1773 inside = false; 1774 break; 1775 default: 1776 break; 1735 1777 } 1736 1737 tData.mPlanes.push_back(interior->GetPlane()); // add plane to split planes 1738 1739 if (planePoly->Valid()) 1740 polys.push_back(planePoly); 1741 else 1742 { 1743 //Debug << "polygon not valid: " << *planePoly << " size: " << (int)planePoly->mVertices.size() << endl; 1744 DEL_PTR(planePoly); 1745 } 1746 // push the children on the stack 1747 tStack.push(BspSplitData(interior->GetFront(), tData.mPlanes, tData.mSides, true)); 1748 tStack.push(BspSplitData(interior->GetBack(), tData.mPlanes, tData.mSides, false)); 1749 } 1750 } 1751 ExportPolygons(polys); 1752 CLEAR_CONTAINER(polys); 1778 } 1779 1780 if (inside) 1781 cell.push_back(candidatePolys[i]); 1782 else 1783 DEL_PTR(candidatePolys[i]); 1784 } 1753 1785 } 1754 1786 1755 1787 int BspTree::FindNeighbors(BspNode *n, vector<BspNode *> &neighbors, bool onlyUnmailed) 1756 1788 { 1789 PolygonContainer cell; 1790 1791 ConstructGeometry(n, cell); 1792 1757 1793 stack<BspNode *> nodeStack; 1758 1794 nodeStack.push(mRoot); 1759 1760 AxisAlignedBox3 box = GetBox(n);1761 1795 1762 1796 while (!nodeStack.empty()) … … 1772 1806 else 1773 1807 { 1774 KdInterior *interior = (KdInterior *)node; 1775 1776 if (interior->mPosition > box.Max(interior->mAxis)) 1808 BspInterior *interior = dynamic_cast<BspInterior *>(node); 1809 1810 const int cf = Polygon3::ClassifyPlane(cell, interior->mPlane); 1811 1812 if (cf == Polygon3::FRONT_SIDE) 1777 1813 nodeStack.push(interior->mBack); 1778 1814 else 1779 if ( interior->mPosition < box.Min(interior->mAxis))1815 if (cf == Polygon3::BACK_SIDE) 1780 1816 nodeStack.push(interior->mFront); 1781 1817 else … … 1788 1824 1789 1825 } 1790 return neighbors.size();1791 } */1826 return (int)neighbors.size(); 1827 } -
trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.h
r359 r360 129 129 void ProcessPolygons(PolygonContainer *polys, const bool storePolys); 130 130 131 static int mailID; 132 int mailbox; 133 134 void Mail() { mailbox = mailID; } 135 static void NewMail() { mailID++; } 136 bool Mailed() const { return mailbox == mailID; } 137 131 138 //int mViewCellIdx; 132 139 protected: … … 356 363 BspTreeStatistics &GetStat(); 357 364 365 /** finds neighbouring leaves of this tree node. 366 */ 367 int FindNeighbors(BspNode *n, vector<BspNode *> &neighbors, bool onlyUnmailed); 368 369 /** Extracts geometry associated with the split plane leading to this node. 370 */ 371 void ConstructGeometry(BspNode *n, PolygonContainer &polys) const; 372 358 373 protected: 359 374 … … 585 600 RayContainer &backRays); 586 601 602 603 /** Extracts the split planes representing the space bounded by node n. 604 */ 605 void ExtractSplitPlanes(BspNode *n, vector<Plane3 *> planes, vector<bool> sides) const; 606 587 607 /// Pointer to the root of the tree 588 608 BspNode *mRoot; -
trunk/VUT/GtpVisibilityPreprocessor/src/X3dExporter.cpp
r349 r360 687 687 }; 688 688 689 void X3dExporter::ExportLeavesGeometry(const BspTree &tree, const vector<BspLeaf *> &leaves) 690 { 691 vector<BspLeaf *>::const_iterator it, it_end = leaves.end(); 692 693 for (it = leaves.begin(); it != it_end; ++ it) 694 { 695 PolygonContainer cell; 696 tree.ConstructGeometry(*it, cell); 697 698 ExportPolygons(cell); 699 700 CLEAR_CONTAINER(cell); 701 } 702 } 703 689 704 void X3dExporter::ExportBspSplits(const BspTree &tree) 690 705 { … … 705 720 { 706 721 BspInterior *interior = dynamic_cast<BspInterior *>(tData.mNode); 722 707 723 if (tData.mNode != tree.GetRoot()) 708 tData.mSides.push_back(tData.mIsFront); // add current side 724 tData.mSides.push_back(tData.mIsFront); // add current side of split plane 709 725 710 726 // bounded plane is added to the polygons … … 712 728 713 729 // do all the splits with the previous planes 714 for (int i = 0; i < (int)tData.mPlanes.size(); ++ i)730 for (int i = 0; i < (int)tData.mPlanes.size(); ++ i) 715 731 { 716 732 VertexContainer splitPts; 717 Polygon3 *frontPoly = new Polygon3(); 718 Polygon3 *backPoly = new Polygon3(); 719 733 720 734 if (planePoly->ClassifyPlane(*tData.mPlanes[i]) == Polygon3::SPLIT) 721 735 { 736 Polygon3 *frontPoly = new Polygon3(); 737 Polygon3 *backPoly = new Polygon3(); 738 722 739 planePoly->Split(*tData.mPlanes[i], *frontPoly, *backPoly, splitPts); 723 740 DEL_PTR(planePoly); … … 741 758 polys.push_back(planePoly); 742 759 else 743 {744 //Debug << "polygon not valid: " << *planePoly << " size: " << (int)planePoly->mVertices.size() << endl;745 760 DEL_PTR(planePoly); 746 }761 747 762 // push the children on the stack 748 763 tStack.push(BspSplitData(interior->GetFront(), tData.mPlanes, tData.mSides, true)); -
trunk/VUT/GtpVisibilityPreprocessor/src/X3dExporter.h
r349 r360 76 76 ExportBspSplits(const BspTree &tree); 77 77 78 virtual void 79 ExportLeavesGeometry(const BspTree &tree, const vector<BspLeaf *> &leaves); 80 78 81 bool 79 82 ExportRays(const RayContainer &rays,
Note: See TracChangeset
for help on using the changeset viewer.