Changeset 238 for trunk/VUT/GtpVisibilityPreprocessor/src/Polygon3.cpp
- Timestamp:
- 08/15/05 20:50:00 (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/VUT/GtpVisibilityPreprocessor/src/Polygon3.cpp
r237 r238 1 1 #include "Polygon3.h" 2 2 #include "Mesh.h" 3 4 #define SIDE_TOLERANCE 0.002 3 5 4 6 Polygon3::Polygon3() … … 21 23 } 22 24 23 Plane3 Polygon3::GetSupportingPlane() 25 Plane3 Polygon3::GetSupportingPlane() const 24 26 { 27 Debug << "creating plane using vertices: " << mVertices[0] << mVertices[1] << mVertices[2] << endl; 28 Vector3 v1 = mVertices[0] - mVertices[1]; 29 Vector3 v2 = mVertices[2] - mVertices[1]; 30 Debug << "plane has vectors " << v1 << v2 << endl; 25 31 return Plane3(mVertices[0], mVertices[1], mVertices[2]); 26 32 } 27 33 28 void Polygon3::DeletePolygons(Polygon Queue*polys)34 void Polygon3::DeletePolygons(PolygonContainer *polys) 29 35 { 30 // don't need to store polygon information = delete polygons36 // don't need to store polygon information => delete polygons 31 37 while(!polys->empty()) 32 38 { 33 Polygon3 *poly = polys-> front();34 polys->pop ();39 Polygon3 *poly = polys->back(); 40 polys->pop_back(); 35 41 DEL_PTR(poly); 36 42 } … … 42 48 Vector3 ptA = mVertices[mVertices.size() - 1]; 43 49 44 int sideA = partition->Side(ptA );50 int sideA = partition->Side(ptA, SIDE_TOLERANCE); 45 51 46 52 VertexContainer::const_iterator it; 53 54 Debug << "\n\nvertex A: " << ptA << ", side A: " << sideA << " (" << partition->Distance(ptA) << ")"; 47 55 48 56 // find line - plane intersections … … 50 58 { 51 59 Vector3 ptB = (*it); 52 int sideB = partition->Side(ptB); 60 int sideB = partition->Side(ptB, SIDE_TOLERANCE); 61 Debug << " <=> vertex B: " << ptB << ", side B: " << sideB << " (" << partition->Distance(ptB) << ")\n\n"; 53 62 54 63 // vertices on different sides => split … … 62 71 // add vertex to both polygons 63 72 front->mVertices.push_back(splitPt); 64 back->mVertices.push_back(splitPt); 73 back->mVertices.push_back(splitPt); Debug << "front and back polygon + " << splitPt << endl; 65 74 66 75 ++ splits; 67 76 } 68 front->mVertices.push_back(ptB); 77 front->mVertices.push_back(ptB); Debug << "front polygon + " << ptB << endl; 69 78 } 70 79 else if (sideB < 0) … … 77 86 // add vertex to both polygons 78 87 front->mVertices.push_back(splitPt); 79 back->mVertices.push_back(splitPt); 88 back->mVertices.push_back(splitPt); Debug << "front and back polygon + " << splitPt << endl; 80 89 81 90 ++ splits; 82 91 } 83 back->mVertices.push_back(ptB); 92 back->mVertices.push_back(ptB); Debug << "back polygon + " << ptB << endl; 84 93 } 85 94 else … … 87 96 // vertex on plane => add vertex to both polygons 88 97 front->mVertices.push_back(ptB); 89 back->mVertices.push_back(ptB); 98 back->mVertices.push_back(ptB); Debug << "front and back polygon + " << ptB << endl; 90 99 } 91 100 92 101 ptA = ptB; 93 102 sideA = sideB; 103 Debug << "vertex A: " << ptA << ", side A: " << sideA << " (" << partition->Distance(ptA) << ")"; 94 104 } 105 Debug << "\n*********************\n"; 95 106 } 96 107 97 int Polygon3::Side(Plane3 *plane) 108 int Polygon3::Side(const Plane3 &plane) const 109 { 110 int classification = ClassifyPlane(plane); 111 112 if (classification == BACK_SIDE) 113 return -1; 114 else if (classification == FRONT_SIDE) 115 return 1; 116 117 return 0; 118 } 119 120 int Polygon3::ClassifyPlane(const Plane3 &plane) const 98 121 { 99 122 VertexContainer::const_iterator it; … … 102 125 bool onBackSide = false; 103 126 104 // find line -plane intersections127 // find possible line-plane intersections 105 128 for (it = mVertices.begin(); it != mVertices.end(); ++ it) 106 129 { 107 int side = plane ->Side(*it);130 int side = plane.Side(*it, SIDE_TOLERANCE); 108 131 109 132 if (side > 0) … … 116 139 } 117 140 118 if (onFrontSide && onBackSide) // split 141 if (onFrontSide && onBackSide) // split //TODO: check if through vvertex 119 142 { 120 143 return SPLIT; … … 131 154 } 132 155 156 // plane and polygon are coincident 133 157 return COINCIDENT; 134 158 }
Note: See TracChangeset
for help on using the changeset viewer.