#include <Iguana/Inventor/interface/IgBSPTriangle.h>
Public Types | |
enum | { POINT_A = 1, POINT_B = 2, POINT_C = 4, ALL_POINTS = 7 } |
typedef std::list < IgBSPTriangle * > | List |
Public Member Functions | |
float | area (void) |
SbVec3f | barycenter (void) const |
int | evaluateCoplanarMask (const SbPlane &plane) |
int | evaluateInHalfPlaneMask (const SbPlane &plane) |
bool | good (void) const |
IgBSPTriangle (const IgBSPTriangle &t) | |
IgBSPTriangle (const SbVec3f &a, const SbVec3f &b, const SbVec3f &c) | |
void | ref (void) |
void | split (const SbPlane &plane, IgBSPTriangle::List &result, int coplanarMask, int inFrontMask) |
void | unref (void) |
const SbVec3f & | v (int n) const |
Static Public Member Functions | |
static bool | areCoplanar (int coplanarMask) |
static bool | areIntersecting (int coplanarMask, int inHalfPlaneMask) |
static bool | isInBack (int coplanarMask, int inHalfPlaneMask) |
static bool | isInFront (int coplanarMask, int inHalfPlaneMask) |
static void | largestOnTop (List &triangleList) |
static void | unrefAndDeleteTriangle (IgBSPTriangle *triangle) |
static void | unrefAndDeleteTriangles (IgBSPTriangle::List &triangles) |
Protected Member Functions | |
~IgBSPTriangle (void) | |
Private Attributes | |
unsigned int | m_refCounter |
SbVec3f | m_vertex [3] |
Classes | |
struct | LessArea |
struct | MoreArea |
Definition at line 17 of file IgBSPTriangle.h.
typedef std::list<IgBSPTriangle *> IgBSPTriangle::List |
Definition at line 39 of file IgBSPTriangle.h.
anonymous enum |
Definition at line 31 of file IgBSPTriangle.h.
00032 { 00033 POINT_A = 1, 00034 POINT_B = 2, 00035 POINT_C = 4, 00036 ALL_POINTS = 7 00037 };
IgBSPTriangle::IgBSPTriangle | ( | const SbVec3f & | a, | |
const SbVec3f & | b, | |||
const SbVec3f & | c | |||
) |
IgBSPTriangle::IgBSPTriangle | ( | const IgBSPTriangle & | t | ) |
IgBSPTriangle::~IgBSPTriangle | ( | void | ) | [protected] |
float IgBSPTriangle::area | ( | void | ) |
Definition at line 275 of file IgBSPTriangle.cc.
References v().
Referenced by IgBSPTriangle::LessArea::operator()(), and IgBSPTriangle::MoreArea::operator()().
00276 { 00277 SbVec3f side1 = v (0) - v (1); 00278 SbVec3f side2 = v (0) - v (2); 00279 return fabs (side1.cross (side2).length ()); 00280 }
Definition at line 125 of file IgBSPTriangle.cc.
References ALL_POINTS.
Referenced by IgBSPNode::add(), and evaluatePlane().
00126 { 00127 return coplanarMask == IgBSPTriangle::ALL_POINTS; 00128 }
Definition at line 154 of file IgBSPTriangle.cc.
References isInBack(), and isInFront().
Referenced by IgBSPNode::add(), and addBestPlane().
00155 { 00156 return !isInFront (coplanarMask, inHalfPlaneMask) 00157 && !isInBack (coplanarMask, inHalfPlaneMask); 00158 }
SbVec3f IgBSPTriangle::barycenter | ( | void | ) | const |
int IgBSPTriangle::evaluateCoplanarMask | ( | const SbPlane & | plane | ) |
Definition at line 104 of file IgBSPTriangle.cc.
References int, isOnPlane(), and v().
Referenced by IgBSPNode::add().
00105 { 00106 // This returns a mask which has bit n set to 1 if point n is 00107 // on the plane. 00108 return ((int) isOnPlane (plane, v (0))) 00109 | (((int) isOnPlane (plane, v (1))) << 1) 00110 | (((int) isOnPlane (plane, v (2))) << 2); 00111 }
int IgBSPTriangle::evaluateInHalfPlaneMask | ( | const SbPlane & | plane | ) |
Definition at line 114 of file IgBSPTriangle.cc.
Referenced by IgBSPNode::add().
00115 { 00116 // This returns a mask which has bit n set to 1 if point n is in 00117 // front of the plane. 00118 return ((int) plane.isInHalfSpace (v (0))) 00119 | (((int) plane.isInHalfSpace (v (1))) << 1) 00120 | (((int) plane.isInHalfSpace (v (2))) << 2); 00121 }
Definition at line 59 of file IgBSPTriangle.cc.
Referenced by split().
00060 { 00061 SbVec3f side1 = v (1) - v (0); 00062 SbVec3f side2 = v (2) - v (0); 00063 side1.normalize (); 00064 side2.normalize (); 00065 00066 SbVec3f norm = side1.cross (side2); 00067 00068 return norm.length () > 0.000001; 00069 }
Definition at line 137 of file IgBSPTriangle.cc.
References ALL_POINTS.
Referenced by addBestPlane(), areIntersecting(), and evaluatePlane().
00138 { 00139 // Check if all the points of a triangle are in the back of the 00140 // plane (or at most they touch it). 00141 // 00142 // First create a mask with bit n set to 1 for point n being in 00143 // the back. This is done by doing a not operation on the 00144 // isInFrontMask, and then masking out the 3 significant bit. 00145 // Than mask out coplanar points by doing an or of the mask of 00146 // coplanar points with the mask of points in the back. If all 00147 // the points are in the back, the result should be all the bits 00148 // set to 1. 00149 int isInBackMask = inHalfPlaneMask ^ IgBSPTriangle::ALL_POINTS; 00150 return (coplanarMask | isInBackMask) == IgBSPTriangle::ALL_POINTS; 00151 }
Definition at line 131 of file IgBSPTriangle.cc.
References ALL_POINTS.
Referenced by IgBSPNode::add(), addBestPlane(), areIntersecting(), and evaluatePlane().
00132 { 00133 return (coplanarMask | inHalfPlaneMask) == IgBSPTriangle::ALL_POINTS; 00134 }
Definition at line 284 of file IgBSPTriangle.cc.
00285 { 00286 List::iterator biggest; 00287 float maxArea; 00288 List::iterator end (triangleList.end ()); 00289 00290 for (List::iterator i = triangleList.begin (); 00291 i != end; 00292 i++) 00293 { 00294 float currentArea = (*i)->area (); 00295 00296 if ( maxArea < currentArea) 00297 { 00298 maxArea = currentArea; 00299 biggest = i; 00300 } 00301 } 00302 00303 triangleList.splice (triangleList.begin (), 00304 triangleList, 00305 biggest); 00306 }
Definition at line 313 of file IgBSPTriangle.cc.
References m_refCounter.
Referenced by addTriangleInBack(), addTriangleInFront(), and IgBSPNode::IgBSPNode().
00314 { 00315 m_refCounter++; 00316 }
void IgBSPTriangle::split | ( | const SbPlane & | plane, | |
IgBSPTriangle::List & | result, | |||
int | coplanarMask, | |||
int | inFrontMask | |||
) |
Definition at line 164 of file IgBSPTriangle.cc.
References ALL_POINTS, good(), IgBSPTriangle(), NEXT_VERTEX, POINT_A, POINT_B, POINT_C, PREV_VERTEX, and v().
Referenced by IgBSPNode::add().
00168 { 00169 // This splits a triangle which is intersecting the plane passed. 00170 00171 // First of all we handle the special case in which one of the 00172 // points is actually on the plane. 00173 // Two triangles results in this case. 00174 int cv; // index of the vertex which is coplanar to the cutting plane. 00175 if (coplanarMask == IgBSPTriangle::POINT_A) cv = 0; 00176 else if (coplanarMask == IgBSPTriangle::POINT_B) cv = 1; 00177 else if (coplanarMask == IgBSPTriangle::POINT_C) cv = 2; 00178 else cv = -1; 00179 00180 if (cv >= 0) 00181 { 00182 int cvn = NEXT_VERTEX(cv); // index of the point which is after the 00183 // coplanar point in counterclockwise ordering. 00184 int cvp = PREV_VERTEX(cv); // index of the point which is before the 00185 // coplanar point in counterclockwise ordering. 00186 00187 SbVec3f intersectionPoint; 00188 plane.intersect (SbLine (v (cvn), v (cvp)), 00189 intersectionPoint); 00190 00191 IgBSPTriangle *t1 = new IgBSPTriangle (v (cv), 00192 v (cvn), 00193 intersectionPoint); 00194 IgBSPTriangle *t2 = new IgBSPTriangle (v (cv), 00195 intersectionPoint, 00196 v (cvp)); 00197 00198 if (t1->good ()) 00199 result.push_back (t1); 00200 else 00201 delete t1; 00202 00203 if (t2->good ()) 00204 result.push_back (t2); 00205 else 00206 delete t2; 00207 00208 return; 00209 } 00210 00211 // Now we handle the case in which none of the vertices are 00212 // coplanar with the plane. 00213 00214 // index of the vertex which is alone on one side of the plane. 00215 int av = 0; 00216 // mask with bit n set to 1 if point n is behind the plane. 00217 int inBackMask = (inFrontMask ^ IgBSPTriangle::ALL_POINTS); 00218 00219 assert (inFrontMask != IgBSPTriangle::ALL_POINTS); 00220 assert (inBackMask != IgBSPTriangle::ALL_POINTS); 00221 00222 if ((inFrontMask == IgBSPTriangle::POINT_A) 00223 || (inBackMask == IgBSPTriangle::POINT_A)) av = 0; 00224 else if ((inFrontMask == IgBSPTriangle::POINT_B) 00225 || (inBackMask == IgBSPTriangle::POINT_B)) av = 1; 00226 else if ((inFrontMask == IgBSPTriangle::POINT_C) 00227 || (inBackMask == IgBSPTriangle::POINT_C)) av = 2; 00228 else 00229 assert ("split: This should never be reached!" == 0); 00230 00231 // index of the vertex which is after the one 00232 // alone on one side of the plane in 00233 // counterclockwise ordering. 00234 int avn = NEXT_VERTEX(av); 00235 // index of the vertex which is before the one 00236 // alone on one side of the plane in 00237 // counterclockwise ordering. 00238 int avp = PREV_VERTEX(av); 00239 00240 SbVec3f intersectionWithNext; 00241 SbVec3f intersectionWithPrev; 00242 00243 plane.intersect (SbLine (v (av), v (avn)), 00244 intersectionWithNext); 00245 plane.intersect (SbLine (v (avp), v (av)), 00246 intersectionWithPrev); 00247 00248 IgBSPTriangle *t1 = new IgBSPTriangle (v (av), 00249 intersectionWithNext, 00250 intersectionWithPrev); 00251 IgBSPTriangle *t2 = new IgBSPTriangle (intersectionWithNext, 00252 v (avn), 00253 v (avp)); 00254 IgBSPTriangle *t3 = new IgBSPTriangle (v (avp), 00255 intersectionWithPrev, 00256 intersectionWithNext); 00257 00258 if (t1->good ()) 00259 result.push_back (t1); 00260 else 00261 delete t1; 00262 00263 if (t2->good ()) 00264 result.push_back (t2); 00265 else 00266 delete t2; 00267 00268 if (t3->good ()) 00269 result.push_back (t3); 00270 else 00271 delete t3; 00272 }
Definition at line 319 of file IgBSPTriangle.cc.
References m_refCounter.
Referenced by unrefAndDeleteTriangle().
00320 { 00321 assert (m_refCounter >= 1); 00322 m_refCounter--; 00323 }
void IgBSPTriangle::unrefAndDeleteTriangle | ( | IgBSPTriangle * | triangle | ) | [static] |
Definition at line 364 of file IgBSPTriangle.cc.
References m_refCounter, and unref().
00365 { 00366 triangle->unref (); 00367 if (triangle->m_refCounter == 0) 00368 delete triangle; 00369 }
void IgBSPTriangle::unrefAndDeleteTriangles | ( | IgBSPTriangle::List & | triangles | ) | [static] |
Definition at line 344 of file IgBSPTriangle.cc.
Referenced by IgBSPNode::add(), IgBSPTree::add(), addBestPlane(), IgSurfaceOperation::apply(), IgBSPTree::intersect(), and IgBSPNode::~IgBSPNode().
00345 { 00346 List::iterator i = triangles.begin (); 00347 List::iterator end (triangles.begin ()); 00348 while ( i != end) 00349 { 00350 (*i)->unref (); 00351 if ((*i)->m_refCounter == 0) 00352 { 00353 delete (*i); 00354 List::iterator j = i; 00355 i++; 00356 triangles.erase (j); 00357 } 00358 else 00359 i++; 00360 } 00361 }
const SbVec3f & IgBSPTriangle::v | ( | int | n | ) | const |
Definition at line 53 of file IgBSPTriangle.cc.
References m_vertex.
Referenced by addBestPlane(), area(), barycenter(), evaluateCoplanarMask(), evaluateInHalfPlaneMask(), getFaceNormal(), good(), IgBSPTriangle(), operator<<(), and split().
unsigned int IgBSPTriangle::m_refCounter [private] |
Definition at line 69 of file IgBSPTriangle.h.
Referenced by ref(), unref(), and unrefAndDeleteTriangle().
SbVec3f IgBSPTriangle::m_vertex[3] [private] |