#include <OSGPlane.h>
Public Member Functions | |
Constructor | |
| * | Plane (void) |
| Plane (const Plane &obj) | |
| Plane (const Pnt3f &p0, const Pnt3f &p1, const Pnt3f &p2) | |
| Plane (const Vec3f &n, Real32 d) | |
| Plane (const Vec3f &n, const Pnt3f &p) | |
Destructor | |
| * | ~Plane (void) |
Offset | |
| *void | offset (Real32 d) |
Intersection | |
| *bool | intersect (const Plane &pl, Line &intersection) const |
| bool | intersect (const Line &l, Pnt3f &intersection) const |
| bool | intersect (const Line &l, Real32 &t) const |
| bool | intersectInfinite (const Line &l, Real32 &t) const |
| bool | intersectInfinite (const Line &l, Pnt3f &intersection) const |
| void | transform (const Matrix &matrix) |
| int | clip (Pnt3f *polyIn, Pnt3f *polyOut, int count) const |
| bool | isOnPlane (const Pnt3f &point) const |
| bool | isInHalfSpace (const Pnt3f &point) const |
| Real32 | distance (const Pnt3f &point) const |
| bool | isInHalfSpace (const Pnt3f &min, const Pnt3f &max) const |
| bool | isOutHalfSpace (const Pnt3f &min, const Pnt3f &max) const |
Set Values | |
| *void | set (const Vec3f &normal, Real32 distance) |
| void | set (Real32 x, Real32 y, Real32 z, Real32 distance) |
| void | set (const Vec4f &plane) |
Access | |
| *const Vec3f & | getNormal (void) const |
| Real32 | getDistanceFromOrigin (void) const |
| void | setDirectionIndexPoint (const Pnt3f &min, const Pnt3f &max, const UInt8 index, Pnt3f &pnt) const |
Private Member Functions | |
| void | updateDirectionIndex (void) |
Private Attributes | |
| Vec3f | _normalVec |
| Real32 | _distance |
| UInt8 | _directionIndex |
Friends | |
Comparison | |
| *friend bool | operator== (const Plane &p1, const Plane &p2) |
| bool | operator!= (const Plane &p1, const Plane &p2) |
The plane is defined by a plane normal and a distance from the origin along that normal. Planes may be used to represent either planes or half-spaces. In the latter case (as for the isInHalfSpace() method), the half-space is defined to be all points on the plane or on the side of the plane in the direction of the plane normal.
The 4 coefficients of the plane equation of an Plane can be obtained easily as the 3 coordinates of the plane normal and the distance, in that order. The normal is normalized.
Note: Plane is all p such that normalVec . p - distance = 0
Dev:
Internally the plane keeps an additional osg::Plane::_index, which is used to speed up volume checks.
Definition at line 55 of file OSGPlane.h.
|
|
Definition at line 81 of file OSGPlane.cpp. 00081 : 00082 _normalVec (0.f, 0.f, 0.f), 00083 _distance (0.f ), 00084 _directionIndex (0) 00085 { 00086 }
|
|
|
Definition at line 89 of file OSGPlane.cpp. References updateDirectionIndex(). 00089 : 00090 _normalVec (obj._normalVec ), 00091 _distance (obj._distance ), 00092 _directionIndex (obj._directionIndex) 00093 { 00094 updateDirectionIndex(); 00095 }
|
|
||||||||||||||||
|
Construct a plane given 3 points. Orientation is computed by taking (p1 - p0) x (p2 - p0) and pointing the normal in that direction. Definition at line 103 of file OSGPlane.cpp. References _distance, _normalVec, osg::VectorInterface< ValueTypeT, StorageInterfaceT >::crossThis(), osg::VectorInterface< ValueTypeT, StorageInterfaceT >::dot(), osg::VectorInterface< ValueTypeT, StorageInterfaceT >::normalize(), and updateDirectionIndex(). 00104 { 00105 Vec3f vec2(p2 - p0); 00106 00107 _normalVec = p1 - p0; 00108 00109 _normalVec.crossThis(vec2); 00110 _normalVec.normalize(); 00111 00112 _distance = _normalVec.dot(p0); 00113 00114 updateDirectionIndex(); 00115 }
|
|
||||||||||||
|
Definition at line 118 of file OSGPlane.cpp. References _normalVec, osg::VectorInterface< ValueTypeT, StorageInterfaceT >::normalize(), and updateDirectionIndex(). 00118 : 00119 _normalVec(normal ), 00120 _distance (distance) 00121 { 00122 _normalVec.normalize(); 00123 00124 updateDirectionIndex(); 00125 }
|
|
||||||||||||
|
Definition at line 128 of file OSGPlane.cpp. References _distance, _normalVec, osg::VectorInterface< ValueTypeT, StorageInterfaceT >::dot(), osg::VectorInterface< ValueTypeT, StorageInterfaceT >::normalize(), and updateDirectionIndex(). 00128 : 00129 _normalVec(normal) 00130 { 00131 _normalVec.normalize(); 00132 00133 _distance = _normalVec.dot(point); 00134 00135 updateDirectionIndex(); 00136 }
|
|
|
Definition at line 140 of file OSGPlane.cpp.
|
|
|
Add offset to distance. Definition at line 148 of file OSGPlane.cpp. References _distance. Referenced by osg::Brick::render3DSlices(). 00149 { 00150 _distance += d; 00151 }
|
|
||||||||||||
|
Intersect plane and plane, returning true if there is an intersection false if planes are parallel taken from Steve Baker's SG library, used with permission. Algorithm explanation can be found at http://geometryalgorithms.com/Archive/algorithm_0104/algorithm_0104.htm Definition at line 161 of file OSGPlane.cpp. References _distance, _normalVec, osg::VectorInterface< ValueTypeT, StorageInterfaceT >::cross(), osg::Eps, getDistanceFromOrigin(), getNormal(), osg::VectorInterface< ValueTypeT, StorageInterfaceT >::length(), osg::osgabs(), osg::Line::setValue(), and osg::VecStorage3< ValueTypeT >::setValues(). Referenced by osg::drawVolume(), osg::FrustumVolume::getCenter(), osg::FrustumVolume::getScalarVolume(), intersect(), osg::Line::intersect(), and osg::Brick::render3DSlices(). 00162 { 00163 Vec3f dir = _normalVec.cross(pl.getNormal()); 00164 Pnt3f pnt; 00165 00166 Real32 len = dir.length(); 00167 00168 if(len < Eps) 00169 return false; 00170 00171 /* Determine intersection point with the best suited coordinate plane. */ 00172 00173 Real32 abs; 00174 Real32 maxabs = osgabs(dir[0]); 00175 UInt16 index = 0; 00176 00177 if((abs = osgabs(dir[1])) > maxabs) 00178 { 00179 maxabs = abs; 00180 index = 1; 00181 } 00182 00183 if((abs = osgabs(dir[2])) > maxabs) 00184 { 00185 maxabs = abs; 00186 index = 2; 00187 } 00188 00189 switch(index) 00190 { 00191 case 0: 00192 pnt.setValues( 00193 0.f, 00194 (pl.getNormal ()[2] * _distance - 00195 pl.getDistanceFromOrigin() * _normalVec[2]) / dir[0], 00196 (pl.getDistanceFromOrigin() * _normalVec[1] - 00197 pl.getNormal ()[1] * _distance ) / dir[0]); 00198 break; 00199 00200 case 1: 00201 pnt.setValues( 00202 (pl.getDistanceFromOrigin() * _normalVec[2] - 00203 pl.getNormal ()[2] * _distance ) / dir[1], 00204 0.f, 00205 (pl.getNormal ()[0] * _distance - 00206 pl.getDistanceFromOrigin() * _normalVec[0]) / dir[1]); 00207 break; 00208 00209 case 2: 00210 pnt.setValues( 00211 (pl.getNormal ()[1] * _distance - 00212 pl.getDistanceFromOrigin() * _normalVec[1]) / dir[2], 00213 (pl.getDistanceFromOrigin() * _normalVec[0] - 00214 pl.getNormal ()[0] * _distance) / dir[2], 00215 0.f); 00216 break; 00217 00218 default: 00219 return false; /* Impossible */ 00220 } 00221 00222 /* Normalize the direction */ 00223 00224 dir *= 1.f / len; 00225 00226 is.setValue(pnt, dir); 00227 00228 return true; 00229 }
|
|
||||||||||||
|
Intersect line and plane, returning true if there is an intersection in the positive part of the line false if line is parallel to plane Definition at line 235 of file OSGPlane.cpp. References osg::Line::getDirection(), osg::Line::getPosition(), and intersect(). 00236 { 00237 Real32 t; 00238 00239 if(intersect(line, t) == true) 00240 { 00241 point = line.getPosition() + t * line.getDirection(); 00242 00243 return true; 00244 } 00245 else 00246 { 00247 return false; 00248 } 00249 }
|
|
||||||||||||
|
Intersect line and plane, returning true if there is an intersection false if line is parallel to plane. t is the distance along the line. Definition at line 255 of file OSGPlane.cpp. References intersectInfinite(). 00256 { 00257 if(intersectInfinite(line, t) == false || t < 0.f) 00258 { 00259 return false; 00260 } 00261 00262 return true; 00263 }
|
|
||||||||||||
|
Intersect line and plane, returning true if there is an intersection false if line is parallel to plane. t is the distance along the line, which may be negative, i.e. the check is against a double infinite line. Definition at line 271 of file OSGPlane.cpp. References _distance, _normalVec, osg::VectorInterface< ValueTypeT, StorageInterfaceT >::dot(), osg::Line::getDirection(), and osg::Line::getPosition(). Referenced by clip(), osg::drawVolume(), osg::FrustumVolume::getCenter(), osg::FrustumVolume::getScalarVolume(), intersect(), osg::Line::intersect(), and intersectInfinite(). 00272 { 00273 Real32 a; 00274 00275 a = _normalVec.dot(line.getDirection()); 00276 00277 if(a != 0.0f) 00278 { 00279 t = _normalVec.dot( 00280 Pnt3f(_normalVec * _distance) - line.getPosition()) / a; 00281 00282 return true; 00283 } 00284 else 00285 { 00286 if(_normalVec.dot(line.getPosition()) - _distance == 0.f) 00287 { 00288 t = 0.f; 00289 00290 return true; 00291 } 00292 } 00293 00294 return false; 00295 }
|
|
||||||||||||
|
Intersect line and plane, returning true if there is an intersection false if line is parallel to plane Definition at line 301 of file OSGPlane.cpp. References osg::Line::getDirection(), osg::Line::getPosition(), and intersectInfinite(). 00302 { 00303 Real32 t; 00304 00305 if(intersectInfinite(line, t) == true) 00306 { 00307 point = line.getPosition() + t * line.getDirection(); 00308 00309 return true; 00310 } 00311 else 00312 { 00313 return false; 00314 } 00315 }
|
|
|
Intersect plane and plane, returning true if there is an intersection false if planes are parallel taken from Steve Baker's SG library, used with permission. Algorithm explanation can be found at http://geometryalgorithms.com/Archive/algorithm_0104/algorithm_0104.htm Definition at line 356 of file OSGPlane.cpp. References _distance, _normalVec, osg::Eps, osg::getMaxIndexAbs3(), osg::VectorInterface< ValueTypeT, StorageInterfaceT >::length(), osg::TransformationMatrix< ValueTypeT >::mult(), osg::VectorInterface< ValueTypeT, StorageInterfaceT >::normalize(), osg::VectorInterface< ValueTypeT, StorageInterfaceT >::projectTo(), and updateDirectionIndex(). Referenced by osg::FrustumVolume::transform(). 00357 { 00358 matrix.mult(_normalVec); 00359 00360 _normalVec.normalize(); 00361 00362 Vec3f trans; 00363 00364 trans[0] = matrix[3][0]; 00365 trans[1] = matrix[3][1]; 00366 trans[2] = matrix[3][2]; 00367 00368 trans.projectTo(_normalVec); 00369 00370 UInt32 uiValNorm = getMaxIndexAbs3(_normalVec); 00371 UInt32 uiValPoint = getMaxIndexAbs3( trans); 00372 00373 if(trans[uiValPoint] > Eps || trans[uiValPoint] < -Eps) 00374 { 00375 if((_normalVec[uiValNorm ] < 0.f && 00376 trans [uiValPoint] < 0.f ) || 00377 (_normalVec[uiValNorm ] > 0.f && 00378 trans [uiValPoint] > 0.f )) 00379 { 00380 _distance -= trans.length(); 00381 } 00382 else 00383 { 00384 _distance += trans.length(); 00385 } 00386 } 00387 00388 updateDirectionIndex(); 00389 }
|
|
||||||||||||||||
|
Clip Polygon, defined by count points through polyIn, at plane, output is copied into polyOut; returns number of output points. Definition at line 321 of file OSGPlane.cpp. References intersectInfinite(), isInHalfSpace(), and p. 00322 { 00323 Pnt3f i, s, p; 00324 int j, n; 00325 00326 n = 0; 00327 s = polyIn[count-1]; 00328 00329 for (j = 0; j < count; j++) { 00330 p = polyIn[j]; 00331 00332 if (isInHalfSpace(p)) { 00333 if (isInHalfSpace(s)) 00334 polyOut[n++] = p; 00335 else { 00336 Line lp(s, p); 00337 if (intersectInfinite(lp, i)) { 00338 polyOut[n++] = i; 00339 polyOut[n++] = p; 00340 } 00341 } 00342 } 00343 else if (isInHalfSpace(s)) { 00344 Line ls(s, p); 00345 if (intersectInfinite(ls, i)) 00346 polyOut[n++] = i; 00347 } 00348 00349 s = p; 00350 } 00351 00352 return n; 00353 }
|
|
|
Check if the point is on the plane. Definition at line 47 of file OSGPlane.inl. References _distance, _normalVec, osg::VectorInterface< ValueTypeT, StorageInterfaceT >::dot(), osg::Eps, and osg::osgabs(). Referenced by osg::CylinderVolume::isOnSurface(). 00048 { 00049 Real32 scalar = _normalVec.dot(point) - _distance; 00050 00051 return osgabs(scalar) < Eps ? true : false; 00052 }
|
|
|
Check if the point is in the Plane's halfspace. Definition at line 58 of file OSGPlane.inl. References _distance, _normalVec, and osg::VectorInterface< ValueTypeT, StorageInterfaceT >::dot(). Referenced by clip(), osg::PolytopeVolume::intersect(), osg::Line::intersect(), osg::intersect(), osg::CylinderVolume::intersect(), isInHalfSpace(), and isOutHalfSpace(). 00059 { 00060 Real32 scalar = _normalVec.dot(point) - _distance; 00061 00062 return scalar >= 0 ? true : false; 00063 }
|
|
|
Calc the distance from the point to the Plane. Definition at line 39 of file OSGPlane.inl. References _distance, _normalVec, and osg::VectorInterface< ValueTypeT, StorageInterfaceT >::dot(). Referenced by osg::DVRVertex::calculatePlaneDistance(), osg::DVRVertex::calculatePlaneDistanceTransformed(), osg::ProjectionCameraDecorator::getProjection(), osg::Brick::render2DSliceXY(), osg::Brick::render2DSliceXZ(), and osg::Brick::render2DSliceYZ(). 00040 { 00041 return _normalVec.dot(pnt) - _distance; 00042 }
|
|
||||||||||||
|
Check if the box formed by min/max is fully in the Plane's halfspace. Definition at line 68 of file OSGPlane.inl. References _directionIndex, isInHalfSpace(), p, and setDirectionIndexPoint(). 00069 { 00070 Pnt3f p; 00071 00072 setDirectionIndexPoint(min, max, _directionIndex, p); 00073 00074 return isInHalfSpace(p); 00075 }
|
|
||||||||||||
|
Check if the box formed by min/max is fully outside the Plane's halfspace. Definition at line 80 of file OSGPlane.inl. References _directionIndex, isInHalfSpace(), p, and setDirectionIndexPoint(). Referenced by osg::intersect(). 00081 { 00082 Pnt3f p; 00083 00084 setDirectionIndexPoint(min, max, _directionIndex ^ 7, p); 00085 00086 return !isInHalfSpace(p); 00087 }
|
|
||||||||||||
|
Set the plane given the normal and distance. The normal needs to be normalized! Definition at line 94 of file OSGPlane.inl. References _distance, _normalVec, and updateDirectionIndex(). Referenced by osg::FieldDataTraits< Plane >::copyFromBin(), osg::Slices::drawSlices(), osg::FrustumVolume::setPlanes(), and osg::DVRClipper::setReferencePlane(). 00095 { 00096 _normalVec = normal; 00097 _distance = distance; 00098 00099 updateDirectionIndex(); 00100 }
|
|
||||||||||||||||||||
|
Set the plane given the (x,y,z) normal and distance The normal needs to be normalized! Definition at line 108 of file OSGPlane.inl. References _distance, _normalVec, osg::VecStorage3< ValueTypeT >::setValues(), and updateDirectionIndex(). 00109 { 00110 _normalVec.setValues(x, y, z); 00111 00112 _distance = distance; 00113 00114 updateDirectionIndex(); 00115 }
|
|
|
Set the plane given the (x,y,z) normal and distance in a Vec4f The normal needs to be normalized! Definition at line 123 of file OSGPlane.inl. References _distance, _normalVec, osg::VecStorage3< ValueTypeT >::setValues(), and updateDirectionIndex(). 00124 { 00125 _normalVec.setValues(plane[0], plane[1], plane[2]); 00126 00127 _distance = plane[3]; 00128 00129 updateDirectionIndex(); 00130 }
|
|
|
Definition at line 134 of file OSGPlane.inl. References _normalVec. Referenced by osg::calcVertexNormals(), osg::FieldDataTraits< Plane >::copyToBin(), osg::FrustumVolume::dump(), osg::FrustumVolume::getScalarVolume(), intersect(), osg::Line::intersect(), osg::FrustumVolume::intersect(), osg::operator<<(), osg::FieldDataTraits< Plane >::putToString(), and osg::DVRClipper::setReferencePlane(). 00135 { 00136 return _normalVec; 00137 }
|
|
|
Definition at line 141 of file OSGPlane.inl. References _distance. Referenced by osg::FieldDataTraits< Plane >::copyToBin(), osg::FrustumVolume::dump(), osg::FrustumVolume::getScalarVolume(), intersect(), osg::FrustumVolume::intersect(), osg::operator<<(), osg::FieldDataTraits< Plane >::putToString(), and osg::DVRClipper::setReferencePlane(). 00142 { 00143 return _distance; 00144 }
|
|
||||||||||||||||||||
|
Definition at line 154 of file OSGPlane.inl. Referenced by isInHalfSpace(), and isOutHalfSpace(). 00156 { 00157 if(index & 0x1) 00158 { 00159 pnt[0] = min[0]; 00160 } 00161 else 00162 { 00163 pnt[0] = max[0]; 00164 } 00165 00166 if(index & 0x2) 00167 { 00168 pnt[1] = min[1]; 00169 } 00170 else 00171 { 00172 pnt[1] = max[1]; 00173 } 00174 00175 if(index & 0x4) 00176 { 00177 pnt[2] = min[2]; 00178 } 00179 else 00180 { 00181 pnt[2] = max[2]; 00182 } 00183 }
|
|
|
Definition at line 391 of file OSGPlane.cpp. References _directionIndex, and _normalVec. Referenced by Plane(), set(), and transform(). 00392 { 00393 UInt8 ind = 0; 00394 00395 if(_normalVec[0] > 0) 00396 ind |= 0x1; 00397 if(_normalVec[1] > 0) 00398 ind |= 0x2; 00399 if(_normalVec[2] > 0) 00400 ind |= 0x4; 00401 00402 _directionIndex = ind; 00403 }
|
|
||||||||||||
|
Definition at line 410 of file OSGPlane.cpp. 00411 { 00412 return ((p1._distance == p2._distance ) && 00413 (p1._normalVec == p2._normalVec) ); 00414 }
|
|
||||||||||||
|
Definition at line 148 of file OSGPlane.inl.
|
|
|
Definition at line 152 of file OSGPlane.h. Referenced by distance(), getNormal(), intersect(), intersectInfinite(), isInHalfSpace(), isOnPlane(), osg::operator==(), Plane(), set(), transform(), and updateDirectionIndex(). |
|
|
Definition at line 153 of file OSGPlane.h. Referenced by distance(), getDistanceFromOrigin(), intersect(), intersectInfinite(), isInHalfSpace(), isOnPlane(), offset(), osg::operator==(), Plane(), set(), and transform(). |
|
|
Definition at line 154 of file OSGPlane.h. Referenced by isInHalfSpace(), isOutHalfSpace(), and updateDirectionIndex(). |
1.4.3