EdgeCollector
Go to the documentation of this file.
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
*
* This library is open source and may be redistributed and/or modified under
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
* (at your option) any later version. The full license is in LICENSE file
* included with this distribution, and on the openscenegraph.org website.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* OpenSceneGraph Public License for more details.
*/
#ifndef OSGUTIL_EDGECOLLECTOR
#define OSGUTIL_EDGECOLLECTOR 1
#include <set>
#include <map>
#include <list>
#include <vector>
#include <algorithm>
#include <osg/Array>
#include <osg/Geometry>
#include <osg/ref_ptr>
#include <osgUtil/Export>
namespace osgUtil {
struct dereference_less
{
template<class T, class U>
inline bool operator() (const T& lhs,const U& rhs) const
{
return *lhs < *rhs;
}
};
template<class T>
bool dereference_check_less(const T& lhs,const T& rhs)
{
if (lhs==rhs) return false;
if (!lhs) return true;
if (!rhs) return false;
return *lhs < *rhs;
}
struct dereference_clear
{
template<class T>
inline void operator() (const T& t)
{
T& non_const_t = const_cast<T&>(t);
non_const_t->clear();
}
};
class OSGUTIL_EXPORT EdgeCollector
{
public:
struct Triangle;
struct Edge;
struct Edgeloop;
struct Point;
typedef std::list<osg::ref_ptr<osg::UIntArray> > IndexArrayList;
~EdgeCollector();
void setGeometry(osg::Geometry* geometry);
osg::Geometry* getGeometry() { return _geometry; }
unsigned int getNumOfTriangles() { return _triangleSet.size(); }
typedef std::set<osg::ref_ptr<Edge>,dereference_less > EdgeSet;
typedef std::vector<osg::ref_ptr<Edge> > EdgeList;
typedef std::list< osg::ref_ptr<Edgeloop> > EdgeloopList;
typedef std::set< osg::ref_ptr<Point>,dereference_less > PointSet;
typedef std::vector< osg::ref_ptr<Point> > PointList;
typedef std::list< osg::ref_ptr<Triangle> > TriangleList;
typedef std::set< osg::ref_ptr<Triangle> > TriangleSet;
typedef std::map< osg::ref_ptr<Triangle>, unsigned int, dereference_less > TriangleMap;
struct OSGUTIL_EXPORT Point : public osg::Referenced
{
Point(): _protected(false), _index(0) {}
bool _protected;
unsigned int _index;
osg::Vec3d _vertex;
TriangleSet _triangles;
void clear() { _triangles.clear(); }
bool operator < ( const Point& rhs) const { return _vertex < rhs._vertex; }
bool isBoundaryPoint() const;
};
struct OSGUTIL_EXPORT Edge : public osg::Referenced
{
void clear();
osg::ref_ptr<Point> _p1;
osg::ref_ptr<Point> _p2;
osg::ref_ptr<Point> _op1;
osg::ref_ptr<Point> _op2;
TriangleSet _triangles;
bool operator < ( const Edge& rhs) const;
bool operator == ( const Edge& rhs) const;
bool operator != ( const Edge& rhs) const;
void setOrderedPoints(Point* p1, Point* p2);
void addTriangle(Triangle* triangle) { _triangles.insert(triangle); }
bool isBoundaryEdge() const { return _triangles.size()<=1; }
bool isAdjacentToBoundary() const { return isBoundaryEdge() || _p1->isBoundaryPoint() || _p2->isBoundaryPoint(); }
bool endConnected(const Edge& rhs) const { return (_op2 == rhs._op1); }
bool beginConnected(const Edge& rhs) const { return (_op1 == rhs._op2); }
};
struct OSGUTIL_EXPORT Triangle : public osg::Referenced
{
Triangle() {}
void clear();
bool operator < (const Triangle& rhs) const;
void setOrderedPoints(Point* p1, Point* p2, Point* p3);
float distance(const osg::Vec3& vertex) const { return _plane.distance(vertex); }
bool isBoundaryTriangle() const
{ return (_e1->isBoundaryEdge() || _e2->isBoundaryEdge() || _e3->isBoundaryEdge()); }
osg::ref_ptr<Point> _p1;
osg::ref_ptr<Point> _p2;
osg::ref_ptr<Point> _p3;
osg::ref_ptr<Point> _op1;
osg::ref_ptr<Point> _op2;
osg::ref_ptr<Point> _op3;
osg::ref_ptr<Edge> _e1;
osg::ref_ptr<Edge> _e2;
osg::ref_ptr<Edge> _e3;
osg::Plane _plane;
};
struct OSGUTIL_EXPORT Edgeloop : public osg::Referenced
{
typedef std::vector<osg::ref_ptr<Edge> > EdgeList;
bool isClosed() { return (_edgeList.back()->endConnected(*_edgeList.front().get())); }
osg::UIntArray * toIndexArray() const;
EdgeList _edgeList;
};
Triangle* addTriangle(unsigned int p1, unsigned int p2, unsigned int p3);
Triangle* addTriangle(Point* p1, Point* p2, Point* p3);
Edge* addEdge(Triangle* triangle, Point* p1, Point* p2);
Point* addPoint(Triangle* triangle, unsigned int p1) { return addPoint(triangle,_originalPointList[p1].get()); }
Point* addPoint(Triangle* triangle, Point* point);
void getBoundaryEdgeList(EdgeList & el);
bool extractBoundaryEdgeloop(EdgeList & el, Edgeloop & edgeloop);
bool extractBoundaryEdgeloopList(EdgeList & el, EdgeloopList & edgeloopList);
void getEdgeloopIndexList(IndexArrayList & ial);
//protected:
osg::Geometry* _geometry;
EdgeSet _edgeSet;
TriangleSet _triangleSet;
PointSet _pointSet;
PointList _originalPointList;
};
} // end of osgUtil namespace
#endif // ** OSGUTIL_EDGECOLLECTOR ** //
Array
Geometry
osgUtil::EdgeCollector
Definition EdgeCollector:63
osgUtil::EdgeCollector::EdgeloopList
std::list< osg::ref_ptr< Edgeloop > > EdgeloopList
Definition EdgeCollector:82
osgUtil::EdgeCollector::PointSet
std::set< osg::ref_ptr< Point >, dereference_less > PointSet
Definition EdgeCollector:83
osgUtil::EdgeCollector::getGeometry
osg::Geometry * getGeometry()
Definition EdgeCollector:76
osgUtil::EdgeCollector::IndexArrayList
std::list< osg::ref_ptr< osg::UIntArray > > IndexArrayList
Definition EdgeCollector:71
osgUtil::EdgeCollector::TriangleMap
std::map< osg::ref_ptr< Triangle >, unsigned int, dereference_less > TriangleMap
Definition EdgeCollector:87
osgUtil::EdgeCollector::_geometry
osg::Geometry * _geometry
Definition EdgeCollector:199
osgUtil::EdgeCollector::extractBoundaryEdgeloop
bool extractBoundaryEdgeloop(EdgeList &el, Edgeloop &edgeloop)
osgUtil::EdgeCollector::EdgeList
std::vector< osg::ref_ptr< Edge > > EdgeList
Definition EdgeCollector:81
osgUtil::EdgeCollector::_pointSet
PointSet _pointSet
Definition EdgeCollector:203
osgUtil::EdgeCollector::addTriangle
Triangle * addTriangle(Point *p1, Point *p2, Point *p3)
osgUtil::EdgeCollector::TriangleSet
std::set< osg::ref_ptr< Triangle > > TriangleSet
Definition EdgeCollector:86
osgUtil::EdgeCollector::EdgeSet
std::set< osg::ref_ptr< Edge >, dereference_less > EdgeSet
Definition EdgeCollector:80
osgUtil::EdgeCollector::setGeometry
void setGeometry(osg::Geometry *geometry)
osgUtil::EdgeCollector::addPoint
Point * addPoint(Triangle *triangle, unsigned int p1)
Definition EdgeCollector:188
osgUtil::EdgeCollector::getBoundaryEdgeList
void getBoundaryEdgeList(EdgeList &el)
osgUtil::EdgeCollector::getNumOfTriangles
unsigned int getNumOfTriangles()
Definition EdgeCollector:78
osgUtil::EdgeCollector::addPoint
Point * addPoint(Triangle *triangle, Point *point)
osgUtil::EdgeCollector::_edgeSet
EdgeSet _edgeSet
Definition EdgeCollector:201
osgUtil::EdgeCollector::extractBoundaryEdgeloopList
bool extractBoundaryEdgeloopList(EdgeList &el, EdgeloopList &edgeloopList)
osgUtil::EdgeCollector::addTriangle
Triangle * addTriangle(unsigned int p1, unsigned int p2, unsigned int p3)
osgUtil::EdgeCollector::_originalPointList
PointList _originalPointList
Definition EdgeCollector:204
osgUtil::EdgeCollector::TriangleList
std::list< osg::ref_ptr< Triangle > > TriangleList
Definition EdgeCollector:85
osgUtil::EdgeCollector::~EdgeCollector
~EdgeCollector()
osgUtil::EdgeCollector::getEdgeloopIndexList
void getEdgeloopIndexList(IndexArrayList &ial)
osgUtil::EdgeCollector::PointList
std::vector< osg::ref_ptr< Point > > PointList
Definition EdgeCollector:84
osgUtil::EdgeCollector::_triangleSet
TriangleSet _triangleSet
Definition EdgeCollector:202
osgUtil::EdgeCollector::addEdge
Edge * addEdge(Triangle *triangle, Point *p1, Point *p2)
osg::Geometry
Definition Geometry:31
osg::Plane
A plane class. It can be used to represent an infinite plane.
Definition Plane:34
osg::Referenced
Definition Referenced:44
osg::Vec3d
Definition Vec3d:30
osg::ref_ptr
Definition ref_ptr:32
osgUtil
Definition NodeVisitor:25
osgUtil::dereference_check_less
bool dereference_check_less(const T &lhs, const T &rhs)
Definition EdgeCollector:43
osg::UIntArray
TemplateIndexArray< GLuint, Array::UIntArrayType, 1, GL_UNSIGNED_INT > UIntArray
Definition Array:419
osg::Vec3
Vec3f Vec3
Definition Vec3:21
Export
OSGUTIL_EXPORT
#define OSGUTIL_EXPORT
Definition osgUtil/Export:40
ref_ptr
osgUtil::EdgeCollector::Edge
Definition EdgeCollector:108
osgUtil::EdgeCollector::Edge::_op1
osg::ref_ptr< Point > _op1
Definition EdgeCollector:114
osgUtil::EdgeCollector::Edge::_op2
osg::ref_ptr< Point > _op2
Definition EdgeCollector:115
osgUtil::EdgeCollector::Edge::isBoundaryEdge
bool isBoundaryEdge() const
Definition EdgeCollector:130
osgUtil::EdgeCollector::Edge::_p2
osg::ref_ptr< Point > _p2
Definition EdgeCollector:112
osgUtil::EdgeCollector::Edge::setOrderedPoints
void setOrderedPoints(Point *p1, Point *p2)
osgUtil::EdgeCollector::Edge::_triangles
TriangleSet _triangles
Definition EdgeCollector:117
osgUtil::EdgeCollector::Edge::addTriangle
void addTriangle(Triangle *triangle)
Definition EdgeCollector:128
osgUtil::EdgeCollector::Edge::beginConnected
bool beginConnected(const Edge &rhs) const
Definition EdgeCollector:136
osgUtil::EdgeCollector::Edge::_p1
osg::ref_ptr< Point > _p1
Definition EdgeCollector:111
osgUtil::EdgeCollector::Edge::endConnected
bool endConnected(const Edge &rhs) const
Definition EdgeCollector:134
osgUtil::EdgeCollector::Edge::isAdjacentToBoundary
bool isAdjacentToBoundary() const
Definition EdgeCollector:132
osgUtil::EdgeCollector::Edge::clear
void clear()
osgUtil::EdgeCollector::Edgeloop
Definition EdgeCollector:171
osgUtil::EdgeCollector::Edgeloop::toIndexArray
osg::UIntArray * toIndexArray() const
osgUtil::EdgeCollector::Edgeloop::_edgeList
EdgeList _edgeList
Definition EdgeCollector:178
osgUtil::EdgeCollector::Edgeloop::EdgeList
std::vector< osg::ref_ptr< Edge > > EdgeList
Definition EdgeCollector:172
osgUtil::EdgeCollector::Edgeloop::isClosed
bool isClosed()
Definition EdgeCollector:174
osgUtil::EdgeCollector::Point
Definition EdgeCollector:90
osgUtil::EdgeCollector::Point::Point
Point()
Definition EdgeCollector:91
osgUtil::EdgeCollector::Point::_triangles
TriangleSet _triangles
Definition EdgeCollector:98
osgUtil::EdgeCollector::Point::clear
void clear()
Definition EdgeCollector:100
osgUtil::EdgeCollector::Point::isBoundaryPoint
bool isBoundaryPoint() const
osgUtil::EdgeCollector::Point::_index
unsigned int _index
Definition EdgeCollector:95
osgUtil::EdgeCollector::Point::_vertex
osg::Vec3d _vertex
Definition EdgeCollector:97
osgUtil::EdgeCollector::Point::_protected
bool _protected
Definition EdgeCollector:93
osgUtil::EdgeCollector::Triangle
Definition EdgeCollector:140
osgUtil::EdgeCollector::Triangle::setOrderedPoints
void setOrderedPoints(Point *p1, Point *p2, Point *p3)
osgUtil::EdgeCollector::Triangle::_op2
osg::ref_ptr< Point > _op2
Definition EdgeCollector:160
osgUtil::EdgeCollector::Triangle::_op1
osg::ref_ptr< Point > _op1
Definition EdgeCollector:159
osgUtil::EdgeCollector::Triangle::_p2
osg::ref_ptr< Point > _p2
Definition EdgeCollector:156
osgUtil::EdgeCollector::Triangle::_e1
osg::ref_ptr< Edge > _e1
Definition EdgeCollector:163
osgUtil::EdgeCollector::Triangle::distance
float distance(const osg::Vec3 &vertex) const
Definition EdgeCollector:149
osgUtil::EdgeCollector::Triangle::_e2
osg::ref_ptr< Edge > _e2
Definition EdgeCollector:164
osgUtil::EdgeCollector::Triangle::Triangle
Triangle()
Definition EdgeCollector:141
osgUtil::EdgeCollector::Triangle::isBoundaryTriangle
bool isBoundaryTriangle() const
Definition EdgeCollector:151
osgUtil::EdgeCollector::Triangle::_p3
osg::ref_ptr< Point > _p3
Definition EdgeCollector:157
osgUtil::EdgeCollector::Triangle::_plane
osg::Plane _plane
Definition EdgeCollector:167
osgUtil::EdgeCollector::Triangle::_e3
osg::ref_ptr< Edge > _e3
Definition EdgeCollector:165
osgUtil::EdgeCollector::Triangle::_p1
osg::ref_ptr< Point > _p1
Definition EdgeCollector:155
osgUtil::EdgeCollector::Triangle::_op3
osg::ref_ptr< Point > _op3
Definition EdgeCollector:161
osgUtil::EdgeCollector::Triangle::clear
void clear()
osgUtil::dereference_clear
Definition EdgeCollector:52
osgUtil::dereference_clear::operator()
void operator()(const T &t)
Definition EdgeCollector:54
osgUtil::dereference_less
Definition EdgeCollector:34
osgUtil::dereference_less::operator()
bool operator()(const T &lhs, const U &rhs) const
Definition EdgeCollector:36