OSG  3.4.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
EdgeCollector.h
Go to the documentation of this file.
1 /* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
2  *
3  * This library is open source and may be redistributed and/or modified under
4  * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
5  * (at your option) any later version. The full license is in LICENSE file
6  * included with this distribution, and on the openscenegraph.org website.
7  *
8  * This library is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * OpenSceneGraph Public License for more details.
12 */
13 
14 #ifndef OSGUTIL_EDGECOLLECTOR
15 #define OSGUTIL_EDGECOLLECTOR 1
16 
17 
18 #include <set>
19 #include <map>
20 #include <list>
21 #include <vector>
22 #include <algorithm>
23 
24 #include <osg/Array>
25 #include <osg/Geometry>
26 #include <osg/ref_ptr>
27 
28 #include <osgUtil/Export>
29 
30 
31 namespace osgUtil {
32 
34  {
35  template<class T, class U>
36  inline bool operator() (const T& lhs,const U& rhs) const
37  {
38  return *lhs < *rhs;
39  }
40  };
41 
42  template<class T>
43  bool dereference_check_less(const T& lhs,const T& rhs)
44  {
45  if (lhs==rhs) return false;
46  if (!lhs) return true;
47  if (!rhs) return false;
48  return *lhs < *rhs;
49  }
50 
52  {
53  template<class T>
54  inline void operator() (const T& t)
55  {
56  T& non_const_t = const_cast<T&>(t);
57  non_const_t->clear();
58  }
59  };
60 
61 
63 {
64 public:
65 
66  struct Triangle;
67  struct Edge;
68  struct Edgeloop;
69  struct Point;
70 
71  typedef std::list<osg::ref_ptr<osg::UIntArray> > IndexArrayList;
72 
73  ~EdgeCollector();
74 
75  void setGeometry(osg::Geometry* geometry);
76  osg::Geometry* getGeometry() { return _geometry; }
77 
78  unsigned int getNumOfTriangles() { return _triangleSet.size(); }
79 
80  typedef std::set<osg::ref_ptr<Edge>,dereference_less > EdgeSet;
81  typedef std::vector<osg::ref_ptr<Edge> > EdgeList;
82  typedef std::list< osg::ref_ptr<Edgeloop> > EdgeloopList;
83  typedef std::set< osg::ref_ptr<Point>,dereference_less > PointSet;
84  typedef std::vector< osg::ref_ptr<Point> > PointList;
85  typedef std::list< osg::ref_ptr<Triangle> > TriangleList;
86  typedef std::set< osg::ref_ptr<Triangle> > TriangleSet;
87  typedef std::map< osg::ref_ptr<Triangle>, unsigned int, dereference_less > TriangleMap;
88 
90  {
91  Point(): _protected(false), _index(0) {}
92 
93  bool _protected;
94 
95  unsigned int _index;
96 
98  TriangleSet _triangles;
99 
100  void clear() { _triangles.clear(); }
101 
102  bool operator < ( const Point& rhs) const { return _vertex < rhs._vertex; }
103 
104  bool isBoundaryPoint() const;
105  };
106 
108  {
109  void clear();
110 
113 
116 
117  TriangleSet _triangles;
118 
119 
120  bool operator < ( const Edge& rhs) const;
121 
122  bool operator == ( const Edge& rhs) const;
123 
124  bool operator != ( const Edge& rhs) const;
125 
126  void setOrderedPoints(Point* p1, Point* p2);
127 
128  void addTriangle(Triangle* triangle) { _triangles.insert(triangle); }
129 
130  bool isBoundaryEdge() const { return _triangles.size()<=1; }
131 
132  bool isAdjacentToBoundary() const { return isBoundaryEdge() || _p1->isBoundaryPoint() || _p2->isBoundaryPoint(); }
133 
134  bool endConnected(const Edge& rhs) const { return (_op2 == rhs._op1); }
135 
136  bool beginConnected(const Edge& rhs) const { return (_op1 == rhs._op2); }
137  };
138 
140  {
141  Triangle() {}
142 
143  void clear();
144 
145  bool operator < (const Triangle& rhs) const;
146 
147  void setOrderedPoints(Point* p1, Point* p2, Point* p3);
148 
149  float distance(const osg::Vec3& vertex) const { return _plane.distance(vertex); }
150 
151  bool isBoundaryTriangle() const
152  { return (_e1->isBoundaryEdge() || _e2->isBoundaryEdge() || _e3->isBoundaryEdge()); }
153 
154 
158 
162 
166 
168  };
169 
171  {
172  typedef std::vector<osg::ref_ptr<Edge> > EdgeList;
173 
174  bool isClosed() { return (_edgeList.back()->endConnected(*_edgeList.front().get())); }
175 
176  osg::UIntArray * toIndexArray() const;
177 
178  EdgeList _edgeList;
179  };
180 
181 
182 
183  Triangle* addTriangle(unsigned int p1, unsigned int p2, unsigned int p3);
184  Triangle* addTriangle(Point* p1, Point* p2, Point* p3);
185 
186  Edge* addEdge(Triangle* triangle, Point* p1, Point* p2);
187 
188  Point* addPoint(Triangle* triangle, unsigned int p1) { return addPoint(triangle,_originalPointList[p1].get()); }
189  Point* addPoint(Triangle* triangle, Point* point);
190 
191  void getBoundaryEdgeList(EdgeList & el);
192  bool extractBoundaryEdgeloop(EdgeList & el, Edgeloop & edgeloop);
193  bool extractBoundaryEdgeloopList(EdgeList & el, EdgeloopList & edgeloopList);
194 
195  void getEdgeloopIndexList(IndexArrayList & ial);
196 
197 //protected:
198 
200 
201  EdgeSet _edgeSet;
202  TriangleSet _triangleSet;
203  PointSet _pointSet;
205 
206 };
207 
208 } // end of osgUtil namespace
209 
210 #endif // ** OSGUTIL_EDGECOLLECTOR ** //
std::map< osg::ref_ptr< Triangle >, unsigned int, dereference_less > TriangleMap
Definition: EdgeCollector.h:87
bool endConnected(const Edge &rhs) const
float distance(const osg::Vec3 &vertex) const
osg::ref_ptr< Point > _op2
bool dereference_check_less(const T &lhs, const T &rhs)
Definition: EdgeCollector.h:43
unsigned int getNumOfTriangles()
Definition: EdgeCollector.h:78
osg::ref_ptr< Point > _op3
std::vector< osg::ref_ptr< Point > > PointList
Definition: EdgeCollector.h:84
bool isAdjacentToBoundary() const
osg::ref_ptr< Point > _op1
std::vector< osg::ref_ptr< Edge > > EdgeList
bool beginConnected(const Edge &rhs) const
std::list< osg::ref_ptr< Triangle > > TriangleList
Definition: EdgeCollector.h:85
osg::Geometry * getGeometry()
Definition: EdgeCollector.h:76
std::set< osg::ref_ptr< Edge >, dereference_less > EdgeSet
Definition: EdgeCollector.h:80
osg::ref_ptr< Point > _op1
std::list< osg::ref_ptr< Edgeloop > > EdgeloopList
Definition: EdgeCollector.h:82
PointArray::value_type Point
Definition: Types.h:29
A plane class. It can be used to represent an infinite plane.
Definition: Plane.h:33
std::vector< osg::ref_ptr< Edge > > EdgeList
Definition: EdgeCollector.h:81
std::list< osg::ref_ptr< osg::UIntArray > > IndexArrayList
Definition: EdgeCollector.h:69
osg::ref_ptr< Point > _p2
void operator()(const T &t)
Definition: EdgeCollector.h:54
osg::ref_ptr< Point > _p1
osg::Geometry * _geometry
Point * addPoint(Triangle *triangle, unsigned int p1)
#define OSGUTIL_EXPORT
Definition: Export.h:40
bool operator()(const T &lhs, const U &rhs) const
Definition: EdgeCollector.h:36
void addTriangle(Triangle *triangle)
std::set< osg::ref_ptr< Point >, dereference_less > PointSet
Definition: EdgeCollector.h:83
std::set< osg::ref_ptr< Triangle > > TriangleSet
Definition: EdgeCollector.h:86
Shader generator framework.
Definition: RenderInfo.h:20
osg::ref_ptr< Point > _op2