38 _maskStack(cv._maskStack),
39 _resultMask(cv._resultMask),
40 _planeList(cv._planeList),
41 _referenceVertexList(cv._referenceVertexList) {}
47 inline void clear() { _planeList.clear(); setupMask(); }
51 if (&cv==
this)
return *
this;
63 _planeList.push_back(
Plane(1.0,0.0,0.0,1.0));
64 _planeList.push_back(
Plane(-1.0,0.0,0.0,1.0));
65 _planeList.push_back(
Plane(0.0,1.0,0.0,1.0));
66 _planeList.push_back(
Plane(0.0,-1.0,0.0,1.0));
67 if (withNear) _planeList.push_back(
Plane(0.0,0.0,1.0,1.0));
68 if (withFar) _planeList.push_back(
Plane(0.0,0.0,-1.0,1.0));
76 _planeList.push_back(
Plane(1.0,0.0,0.0,-bb.
xMin()));
77 _planeList.push_back(
Plane(-1.0,0.0,0.0,bb.
xMax()));
78 _planeList.push_back(
Plane(0.0,1.0,0.0,-bb.
yMin()));
79 _planeList.push_back(
Plane(0.0,-1.0,0.0,bb.
yMax()));
80 _planeList.push_back(
Plane(0.0,0.0,1.0,-bb.
zMin()));
81 _planeList.push_back(
Plane(0.0,0.0,-1.0,bb.
zMax()));
92 _maskStack.back() = 0;
100 unsigned int numActivePlanes = 0;
103 PlaneList::const_iterator itr;
108 if (resultMask&selector_mask) ++numActivePlanes;
112 _planeList.resize(numActivePlanes);
115 unsigned int index = 0;
120 if (resultMask&selector_mask)
122 _planeList[index] = *itr;
123 _planeList[index++].transformProvidingInverse(matrix);
124 _resultMask = (_resultMask<<1) | 1;
129 _maskStack.back() = _resultMask;
135 inline void add(
const osg::Plane& pl) { _planeList.push_back(pl); setupMask(); }
140 for(PlaneList::iterator itr=_planeList.begin();
141 itr!=_planeList.end();
148 inline bool empty()
const {
return _planeList.empty(); }
165 for(
unsigned int i=0;i<_planeList.size();++i)
167 _resultMask = (_resultMask<<1) | 1;
169 _maskStack.push_back(_resultMask);
187 _maskStack.push_back(_resultMask);
192 _maskStack.pop_back();
198 if (!_maskStack.back())
return true;
200 unsigned int selector_mask = 0x1;
201 for(PlaneList::const_iterator itr=_planeList.begin();
202 itr!=_planeList.end();
205 if ((_maskStack.back()&selector_mask) && (itr->distance(v)<0.0f))
return false;
212 inline bool contains(
const std::vector<Vec3>& vertices)
214 if (!_maskStack.back())
return true;
216 _resultMask = _maskStack.back();
218 for(std::vector<Vec3>::const_iterator vitr = vertices.begin();
219 vitr != vertices.end();
223 bool outside =
false;
225 for(PlaneList::const_iterator itr=_planeList.begin();
226 itr!=_planeList.end() && !outside;
229 if ((_maskStack.back()&selector_mask) && (itr->distance(v)<0.0f)) outside =
true;
233 if (!outside)
return true;
245 if (!_maskStack.back())
return true;
247 _resultMask = _maskStack.back();
250 for(PlaneList::const_iterator itr=_planeList.begin();
251 itr!=_planeList.end();
254 if (_resultMask&selector_mask)
256 int res=itr->intersect(bs);
257 if (res<0)
return false;
258 else if (res>0) _resultMask ^= selector_mask;
272 if (!_maskStack.back())
return true;
274 _resultMask = _maskStack.back();
277 for(PlaneList::const_iterator itr=_planeList.begin();
278 itr!=_planeList.end();
281 if (_resultMask&selector_mask)
283 int res=itr->intersect(bb);
284 if (res<0)
return false;
285 else if (res>0) _resultMask ^= selector_mask;
295 if (!_maskStack.back())
return false;
297 _resultMask = _maskStack.back();
300 for(PlaneList::const_iterator itr=_planeList.begin();
301 itr!=_planeList.end();
304 if (_resultMask&selector_mask)
306 int res=itr->intersect(vertices);
307 if (res<1)
return false;
308 _resultMask ^= selector_mask;
318 if (!_maskStack.back())
return false;
320 _resultMask = _maskStack.back();
323 for(PlaneList::const_iterator itr=_planeList.begin();
324 itr!=_planeList.end();
327 if (_resultMask&selector_mask)
329 int res=itr->intersect(bs);
330 if (res<1)
return false;
331 _resultMask ^= selector_mask;
341 if (!_maskStack.back())
return false;
343 _resultMask = _maskStack.back();
346 for(PlaneList::const_iterator itr=_planeList.begin();
347 itr!=_planeList.end();
350 if (_resultMask&selector_mask)
352 int res=itr->intersect(bb);
353 if (res<1)
return false;
354 _resultMask ^= selector_mask;
375 transformProvidingInverse(inverse);
382 if (!_maskStack.back())
return;
384 _resultMask = _maskStack.back();
386 for(PlaneList::iterator itr=_planeList.begin();
387 itr!=_planeList.end();
390 if (_resultMask&selector_mask)
392 itr->transformProvidingInverse(matrix);
Definition BoundingBox:34
value_type & xMax()
Definition BoundingBox:116
value_type & yMin()
Definition BoundingBox:110
value_type & xMin()
Definition BoundingBox:107
value_type & zMin()
Definition BoundingBox:113
value_type & zMax()
Definition BoundingBox:122
value_type & yMax()
Definition BoundingBox:119
Definition BoundingSphere:35
bool invert(const Matrixd &rhs)
Definition Matrixd:233
A plane class. It can be used to represent an infinite plane.
Definition Plane:34
bool containsAllOf(const osg::BoundingSphere &bs)
Definition Polytope:316
ClippingMask _resultMask
Definition Polytope:402
bool contains(const osg::Vec3f &v0, const osg::Vec3f &v1, const osg::Vec3f &v2) const
ClippingMask getResultMask() const
Definition Polytope:178
void setReferenceVertexList(VertexList &vertices)
Definition Polytope:155
const VertexList & getReferenceVertexList() const
Definition Polytope:159
void pushCurrentMask()
Definition Polytope:185
void set(const PlaneList &pl)
Definition Polytope:132
Polytope()
Definition Polytope:35
bool contains(const osg::Vec3 &v) const
Definition Polytope:196
PlaneList & getPlaneList()
Definition Polytope:150
Polytope(const PlaneList &pl)
Definition Polytope:43
MaskStack & getMaskStack()
Definition Polytope:180
~Polytope()
Definition Polytope:45
void setAndTransformProvidingInverse(const Polytope &pt, const osg::Matrix &matrix)
Definition Polytope:85
bool contains(const osg::BoundingSphere &bs)
Definition Polytope:243
bool contains(const std::vector< Vec3 > &vertices)
Definition Polytope:212
unsigned int ClippingMask
Definition Polytope:30
void setupMask()
Definition Polytope:162
void setResultMask(ClippingMask mask)
Definition Polytope:176
void add(const osg::Plane &pl)
Definition Polytope:135
PlaneList _planeList
Definition Polytope:403
MaskStack _maskStack
Definition Polytope:401
ClippingMask getCurrentMask() const
Definition Polytope:174
bool contains(const osg::BoundingBox &bb)
Definition Polytope:270
void popCurrentMask()
Definition Polytope:190
void setToBoundingBox(const BoundingBox &bb)
Definition Polytope:73
void flip()
Definition Polytope:138
bool containsAllOf(const std::vector< Vec3 > &vertices)
Definition Polytope:293
VertexList _referenceVertexList
Definition Polytope:404
void clear()
Definition Polytope:47
void transform(const osg::Matrix &matrix)
Definition Polytope:371
std::vector< Vec3 > VertexList
Definition Polytope:32
Polytope(const Polytope &cv)
Definition Polytope:37
VertexList & getReferenceVertexList()
Definition Polytope:157
void transformProvidingInverse(const osg::Matrix &matrix)
Definition Polytope:380
bool containsAllOf(const osg::BoundingBox &bb)
Definition Polytope:339
std::vector< Plane > PlaneList
Definition Polytope:31
const MaskStack & getMaskStack() const
Definition Polytope:182
fast_back_stack< ClippingMask > MaskStack
Definition Polytope:33
const PlaneList & getPlaneList() const
Definition Polytope:152
ClippingMask & getCurrentMask()
Definition Polytope:172
void setToUnitFrustum(bool withNear=true, bool withFar=true)
Definition Polytope:60
bool empty() const
Definition Polytope:148
Definition fast_back_stack:31
T & back()
Definition fast_back_stack:54
author: Julien Valentin 2017 (mp3butcher@hotmail.com)
Definition AlphaFunc:19
#define OSG_EXPORT
Definition osg/Export:39