diff --git a/src/osgUtil/Simplifier.cpp b/src/osgUtil/Simplifier.cpp index 4692ced62..da29a1d03 100644 --- a/src/osgUtil/Simplifier.cpp +++ b/src/osgUtil/Simplifier.cpp @@ -16,6 +16,7 @@ #include #include +#include #include using namespace osgUtil; @@ -43,12 +44,16 @@ public: class Triangle; class Edge; + typedef std::vector FloatList; struct Point : public osg::Referenced { Point() {} unsigned int _index; + + osg::Vec3 _vertex; + FloatList _attributes; }; struct Edge : public osg::Referenced @@ -81,7 +86,9 @@ public: }; - struct LessPtr + + + struct LessErrorMetricFunctor { inline bool operator() (const osg::ref_ptr& lhs,const osg::ref_ptr& rhs) const { @@ -89,12 +96,78 @@ public: } }; - typedef std::set,LessPtr> EdgeSet; + struct LessTriangleFunctor + { + inline bool operator() (const osg::ref_ptr& lhs,const osg::ref_ptr& rhs) const + { + if (lhs->_p1 < rhs->_p1) return true; + if (lhs->_p1 > rhs->_p1) return false; + if (lhs->_p2 < rhs->_p2) return true; + if (lhs->_p2 > rhs->_p2) return false; - void addTriangle(unsigned int p1, unsigned int p2, unsigned int p3) + if (lhs->_p1 < rhs->_p3) return true; + return false; + } + }; + + struct LessPointFunctor + { + inline bool operator() (const osg::ref_ptr& lhs,const osg::ref_ptr& rhs) const + { + return lhs->_index_index; + } + }; + + typedef std::set,LessErrorMetricFunctor> EdgeSet; + typedef std::set< osg::ref_ptr, LessPointFunctor> PointSet; + typedef std::list< osg::ref_ptr > TriangleList; + + Triangle* addTriangle(unsigned int p1, unsigned int p2, unsigned int p3) { std::cout<<"addTriangle("<_p1 = points[lowest]; + triangle->_p2 = points[(lowest+1)%3]; + triangle->_p3 = points[(lowest+2)%3]; + + triangle->_e1 = addEdge(triangle, triangle->_p1, triangle->_p2); + triangle->_e2 = addEdge(triangle, triangle->_p2, triangle->_p3); + triangle->_e3 = addEdge(triangle, triangle->_p3, triangle->_p1); + + _triangleList.insert(triangle); + + return triangle; +#endif + } + + Edge* addEdge(Triangle* triangle, Point* p1, Point* p2) + { + std::cout<<"addEdge("< MyTriangleIndexFunctor; +typedef osg::TriangleIndexFunctor CollectTriangleIndexFunctor; void EdgeCollapse::setGeometry(osg::Geometry* geometry) { _geometry = geometry; - MyTriangleIndexFunctor collectTriangles; + CollectTriangleIndexFunctor collectTriangles; collectTriangles.setEdgeCollapse(this); + + _geometry->accept(collectTriangles); } Simplifier::Simplifier() @@ -138,6 +215,8 @@ Simplifier::Simplifier() void Simplifier::simplify(osg::Geometry& geometry, float sampleRatio) { + std::cout<<"++++++++++++++simplifier************"<