osg: KdTree: count degenerates to keep original primitive index in sync

This commit is contained in:
blobfish 2017-06-02 15:43:54 -04:00
parent bb804c2045
commit f5bd280b51
2 changed files with 10 additions and 6 deletions

View File

@ -69,7 +69,7 @@ class OSG_EXPORT KdTree : public osg::Shape
inline unsigned int addPoint(unsigned int p0) inline unsigned int addPoint(unsigned int p0)
{ {
unsigned int i = _vertexIndices.size(); unsigned int i = _vertexIndices.size();
_vertexIndices.push_back(_primitiveIndices.size()); _vertexIndices.push_back(_primitiveIndices.size() + _degenerateCount);
_vertexIndices.push_back(1); _vertexIndices.push_back(1);
_vertexIndices.push_back(p0); _vertexIndices.push_back(p0);
_primitiveIndices.push_back(i); _primitiveIndices.push_back(i);
@ -78,7 +78,7 @@ class OSG_EXPORT KdTree : public osg::Shape
inline unsigned int addLine(unsigned int p0, unsigned int p1) inline unsigned int addLine(unsigned int p0, unsigned int p1)
{ {
unsigned int i = _vertexIndices.size(); unsigned int i = _vertexIndices.size();
_vertexIndices.push_back(_primitiveIndices.size()); _vertexIndices.push_back(_primitiveIndices.size() + _degenerateCount);
_vertexIndices.push_back(2); _vertexIndices.push_back(2);
_vertexIndices.push_back(p0); _vertexIndices.push_back(p0);
_vertexIndices.push_back(p1); _vertexIndices.push_back(p1);
@ -89,7 +89,7 @@ class OSG_EXPORT KdTree : public osg::Shape
inline unsigned int addTriangle(unsigned int p0, unsigned int p1, unsigned int p2) inline unsigned int addTriangle(unsigned int p0, unsigned int p1, unsigned int p2)
{ {
unsigned int i = _vertexIndices.size(); unsigned int i = _vertexIndices.size();
_vertexIndices.push_back(_primitiveIndices.size()); _vertexIndices.push_back(_primitiveIndices.size() + _degenerateCount);
_vertexIndices.push_back(3); _vertexIndices.push_back(3);
_vertexIndices.push_back(p0); _vertexIndices.push_back(p0);
_vertexIndices.push_back(p1); _vertexIndices.push_back(p1);
@ -101,7 +101,7 @@ class OSG_EXPORT KdTree : public osg::Shape
inline unsigned int addQuad(unsigned int p0, unsigned int p1, unsigned int p2, unsigned int p3) inline unsigned int addQuad(unsigned int p0, unsigned int p1, unsigned int p2, unsigned int p3)
{ {
unsigned int i = _vertexIndices.size(); unsigned int i = _vertexIndices.size();
_vertexIndices.push_back(_primitiveIndices.size()); _vertexIndices.push_back(_primitiveIndices.size() + _degenerateCount);
_vertexIndices.push_back(4); _vertexIndices.push_back(4);
_vertexIndices.push_back(p0); _vertexIndices.push_back(p0);
_vertexIndices.push_back(p1); _vertexIndices.push_back(p1);
@ -179,7 +179,7 @@ class OSG_EXPORT KdTree : public osg::Shape
} }
} }
unsigned int _degenerateCount;
protected: protected:

View File

@ -86,6 +86,7 @@ struct PrimitiveIndicesCollector
if (v0==v1) if (v0==v1)
{ {
//OSG_NOTICE<<"Disgarding degenerate triangle"<<std::endl; //OSG_NOTICE<<"Disgarding degenerate triangle"<<std::endl;
_buildKdTree->_kdTree._degenerateCount++;
return; return;
} }
@ -111,6 +112,7 @@ struct PrimitiveIndicesCollector
if (v0==v1 || v1==v2 || v2==v0) if (v0==v1 || v1==v2 || v2==v0)
{ {
//OSG_NOTICE<<"Disgarding degenerate triangle"<<std::endl; //OSG_NOTICE<<"Disgarding degenerate triangle"<<std::endl;
_buildKdTree->_kdTree._degenerateCount++;
return; return;
} }
@ -138,6 +140,7 @@ struct PrimitiveIndicesCollector
if (v0==v1 || v1==v2 || v2==v0 || v3==v0 || v3==v1 || v3==v2) if (v0==v1 || v1==v2 || v2==v0 || v3==v0 || v3==v1 || v3==v2)
{ {
//OSG_NOTICE<<"Disgarding degenerate quad"<<std::endl; //OSG_NOTICE<<"Disgarding degenerate quad"<<std::endl;
_buildKdTree->_kdTree._degenerateCount++;
return; return;
} }
@ -481,12 +484,13 @@ KdTree::BuildOptions::BuildOptions():
// //
// KdTree // KdTree
KdTree::KdTree() KdTree::KdTree() : _degenerateCount(0)
{ {
} }
KdTree::KdTree(const KdTree& rhs, const osg::CopyOp& copyop): KdTree::KdTree(const KdTree& rhs, const osg::CopyOp& copyop):
Shape(rhs, copyop), Shape(rhs, copyop),
_degenerateCount(rhs._degenerateCount),
_vertices(rhs._vertices), _vertices(rhs._vertices),
_kdNodes(rhs._kdNodes) _kdNodes(rhs._kdNodes)
{ {