This commit is contained in:
Robert Osfield
2017-06-19 08:26:24 +01:00
6 changed files with 67 additions and 39 deletions

View File

@@ -86,6 +86,7 @@ struct PrimitiveIndicesCollector
if (v0==v1)
{
//OSG_NOTICE<<"Disgarding degenerate triangle"<<std::endl;
_buildKdTree->_kdTree._degenerateCount++;
return;
}
@@ -111,6 +112,7 @@ struct PrimitiveIndicesCollector
if (v0==v1 || v1==v2 || v2==v0)
{
//OSG_NOTICE<<"Disgarding degenerate triangle"<<std::endl;
_buildKdTree->_kdTree._degenerateCount++;
return;
}
@@ -138,6 +140,7 @@ struct PrimitiveIndicesCollector
if (v0==v1 || v1==v2 || v2==v0 || v3==v0 || v3==v1 || v3==v2)
{
//OSG_NOTICE<<"Disgarding degenerate quad"<<std::endl;
_buildKdTree->_kdTree._degenerateCount++;
return;
}
@@ -287,6 +290,7 @@ int BuildKdTree::divide(KdTree::BuildOptions& options, osg::BoundingBox& bb, int
for(int i=istart; i<=iend; ++i)
{
unsigned int primitiveIndex = _kdTree.getPrimitiveIndices()[_primitiveIndices[i]];
primitiveIndex++; //skip original Primitive index
unsigned int numPoints = _kdTree.getVertexIndices()[primitiveIndex++];
for(; numPoints>0; --numPoints)
@@ -361,8 +365,6 @@ int BuildKdTree::divide(KdTree::BuildOptions& options, osg::BoundingBox& bb, int
while(left<right && (_centers[_primitiveIndices[right]][axis]>mid)) { --right; }
while(left<right && (_centers[_primitiveIndices[right]][axis]>mid)) { --right; }
if (left<right)
{
std::swap(_primitiveIndices[left], _primitiveIndices[right]);
@@ -482,12 +484,13 @@ KdTree::BuildOptions::BuildOptions():
//
// KdTree
KdTree::KdTree()
KdTree::KdTree() : _degenerateCount(0)
{
}
KdTree::KdTree(const KdTree& rhs, const osg::CopyOp& copyop):
Shape(rhs, copyop),
_degenerateCount(rhs._degenerateCount),
_vertices(rhs._vertices),
_kdNodes(rhs._kdNodes)
{

View File

@@ -141,7 +141,7 @@ struct IntersectFunctor
}
}
// compate s and e against the yMin to yMax range of bb.
// compare s and e against the yMin to yMax range of bb.
if (s.y()<=e.y())
{
@@ -179,7 +179,7 @@ struct IntersectFunctor
}
}
// compate s and e against the zMin to zMax range of bb.
// compare s and e against the zMin to zMax range of bb.
if (s.z()<=e.z())
{
@@ -247,8 +247,8 @@ struct IntersectFunctor
value_type r,r0,r1,r2;
const value_type esplison = 1e-10;
if (det>esplison)
const value_type epsilon = 1e-10;
if (det>epsilon)
{
value_type u = (P*T);
if (u<0.0 || u>det) return;
@@ -271,7 +271,7 @@ struct IntersectFunctor
r2 = v;
r = t * _inverse_length;
}
else if (det<-esplison)
else if (det<-epsilon)
{
value_type u = (P*T);
if (u>0.0 || u<det) return;
@@ -357,15 +357,15 @@ struct IntersectFunctor
// handle triangles
void operator()(const osg::Vec3& v0, const osg::Vec3& v1, const osg::Vec3& v2, bool /*treatVertexDataAsTemporary*/)
{
++_primitiveIndex;
intersect(v0,v1,v2);
++_primitiveIndex;
}
void operator()(const osg::Vec3& v0, const osg::Vec3& v1, const osg::Vec3& v2, const osg::Vec3& v3, bool /*treatVertexDataAsTemporary*/)
{
++_primitiveIndex;
intersect(v0,v1,v3);
intersect(v1,v2,v3);
++_primitiveIndex;
}
void intersect(const osg::Vec3Array*, int , unsigned int)
@@ -595,7 +595,7 @@ bool LineSegmentIntersector::intersectAndClip(osg::Vec3d& s, osg::Vec3d& e,const
double epsilon = 1e-5;
// compate s and e against the xMin to xMax range of bb.
// compare s and e against the xMin to xMax range of bb.
if (s.x()<=e.x())
{
// trivial reject of segment wholely outside.
@@ -636,7 +636,7 @@ bool LineSegmentIntersector::intersectAndClip(osg::Vec3d& s, osg::Vec3d& e,const
}
}
// compate s and e against the yMin to yMax range of bb.
// compare s and e against the yMin to yMax range of bb.
if (s.y()<=e.y())
{
// trivial reject of segment wholely outside.
@@ -677,7 +677,7 @@ bool LineSegmentIntersector::intersectAndClip(osg::Vec3d& s, osg::Vec3d& e,const
}
}
// compate s and e against the zMin to zMax range of bb.
// compare s and e against the zMin to zMax range of bb.
if (s.z()<=e.z())
{
// trivial reject of segment wholely outside.

View File

@@ -256,9 +256,11 @@ struct IntersectFunctor
{
if (_settings->_limitOneIntersection && _hit) return;
++_primitiveIndex;
if ((_settings->_primitiveMask&PolytopeIntersector::POINT_PRIMITIVES)==0) return;
if ((_settings->_primitiveMask&PolytopeIntersector::POINT_PRIMITIVES)==0)
{
++_primitiveIndex;
return;
}
// initialize the set of vertices to test.
src.clear();
@@ -278,7 +280,11 @@ struct IntersectFunctor
{
const osg::Plane& plane=*pitr;
double d1=plane.distance(v0);
if (d1<0.0) return; // point outside
if (d1<0.0) // point outside
{
++_primitiveIndex;
return;
}
}
}
}
@@ -286,6 +292,8 @@ struct IntersectFunctor
src.push_back(v0);
addIntersection();
++_primitiveIndex;
}
// handle lines
@@ -293,9 +301,11 @@ struct IntersectFunctor
{
if (_settings->_limitOneIntersection && _hit) return;
++_primitiveIndex;
if ((_settings->_primitiveMask&PolytopeIntersector::LINE_PRIMITIVES)==0) return;
if ((_settings->_primitiveMask&PolytopeIntersector::LINE_PRIMITIVES)==0)
{
++_primitiveIndex;
return;
}
src.clear();
src.push_back(v0);
@@ -305,6 +315,7 @@ struct IntersectFunctor
{
addIntersection();
}
++_primitiveIndex;
}
// handle triangles
@@ -312,9 +323,11 @@ struct IntersectFunctor
{
if (_settings->_limitOneIntersection && _hit) return;
++_primitiveIndex;
if ((_settings->_primitiveMask&PolytopeIntersector::TRIANGLE_PRIMITIVES)==0) return;
if ((_settings->_primitiveMask&PolytopeIntersector::TRIANGLE_PRIMITIVES)==0)
{
++_primitiveIndex;
return;
}
src.clear();
src.push_back(v0);
@@ -326,15 +339,18 @@ struct IntersectFunctor
{
addIntersection();
}
++_primitiveIndex;
}
void operator()(const osg::Vec3& v0, const osg::Vec3& v1, const osg::Vec3& v2, const osg::Vec3& v3, bool /*treatVertexDataAsTemporary*/)
{
if (_settings->_limitOneIntersection && _hit) return;
++_primitiveIndex;
if ((_settings->_primitiveMask&PolytopeIntersector::TRIANGLE_PRIMITIVES)==0) return;
if ((_settings->_primitiveMask&PolytopeIntersector::TRIANGLE_PRIMITIVES)==0)
{
++_primitiveIndex;
return;
}
src.clear();
@@ -348,6 +364,7 @@ struct IntersectFunctor
{
addIntersection();
}
++_primitiveIndex;
}
void intersect(const osg::Vec3Array* vertices, int primitiveIndex, unsigned int p0)