Added a filter to the Delaunay Triangulator to insure that incoming points

are unique in the X and Y components.
This commit is contained in:
Don BURNS
2006-02-08 23:41:32 +00:00
parent 608a183753
commit 8f7d349f7e
2 changed files with 32 additions and 0 deletions

View File

@@ -167,6 +167,8 @@ private:
// GWM these lines provide required edges in the triangulated shape.
linelist constraint_lines;
void _uniqueifyPoints();
};

View File

@@ -658,6 +658,32 @@ void DelaunayConstraint::merge(DelaunayConstraint *dco)
if (varr) vmerge->insert(vmerge->end(),varr->begin(),varr->end());
}
void DelaunayTriangulator::_uniqueifyPoints()
{
std::sort( points_->begin(), points_->end() );
osg::ref_ptr<osg::Vec3Array> temppts = new osg::Vec3Array;
// This won't work... must write our own unique() that compares only the first
// two terms of a Vec3 for equivalency
//std::insert_iterator< osg::Vec3Array > ti( *(temppts.get()), temppts->begin() );
//std::unique_copy( points_->begin(), points_->end(), ti );
osg::Vec3Array::iterator p = points_->begin();
osg::Vec3 v = *p;
for( ; p != points_->end(); p++ )
{
if( v[0] == (*p)[0] && v[1] == (*p)[1] )
continue;
temppts->push_back( (v = *p));
}
points_->clear();
std::insert_iterator< osg::Vec3Array > ci(*(points_.get()),points_->begin());
std::copy( temppts->begin(), temppts->end(), ci );
}
bool DelaunayTriangulator::triangulate()
{
@@ -676,6 +702,10 @@ bool DelaunayTriangulator::triangulate()
return false;
}
// Eliminate duplicate lat/lon points from input coordinates.
_uniqueifyPoints();
// initialize storage structures
Triangle_list triangles;
Triangle_list discarded_tris;