OpenSceneGraph 3.6.5
EdgeCollector
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
31namespace 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{
64public:
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
74
75 void setGeometry(osg::Geometry* 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
94
95 unsigned int _index;
96
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
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
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 {
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
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
177
179 };
180
181
182
183 Triangle* addTriangle(unsigned int p1, unsigned int p2, unsigned int 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
194
196
197//protected:
198
200
205
206};
207
208} // end of osgUtil namespace
209
210#endif // ** OSGUTIL_EDGECOLLECTOR ** //
TemplateIndexArray< GLuint, Array::UIntArrayType, 1, GL_UNSIGNED_INT > UIntArray
Definition Array:419
Vec3f Vec3
Definition Vec3:21
The osgUtil library provides general purpose utility classes such as update, cull and draw traverses,...
Definition NodeVisitor:25
bool dereference_check_less(const T &lhs, const T &rhs)
Definition EdgeCollector:43
Definition Geometry:31
A plane class.
Definition Plane:34
Smart pointer for handling referenced counted objects.
Definition ref_ptr:32
Base class for providing reference counted objects.
Definition Referenced:44
General purpose double triple for use as vertices, vectors and normals.
Definition Vec3d:30
Definition EdgeCollector:34
bool operator()(const T &lhs, const U &rhs) const
Definition EdgeCollector:36
Definition EdgeCollector:52
void operator()(const T &t)
Definition EdgeCollector:54
Definition EdgeCollector:63
std::list< osg::ref_ptr< Edgeloop > > EdgeloopList
Definition EdgeCollector:82
std::set< osg::ref_ptr< Point >, dereference_less > PointSet
Definition EdgeCollector:83
osg::Geometry * getGeometry()
Definition EdgeCollector:76
std::list< osg::ref_ptr< osg::UIntArray > > IndexArrayList
Definition EdgeCollector:71
std::map< osg::ref_ptr< Triangle >, unsigned int, dereference_less > TriangleMap
Definition EdgeCollector:87
osg::Geometry * _geometry
Definition EdgeCollector:199
bool extractBoundaryEdgeloop(EdgeList &el, Edgeloop &edgeloop)
std::vector< osg::ref_ptr< Edge > > EdgeList
Definition EdgeCollector:81
PointSet _pointSet
Definition EdgeCollector:203
Triangle * addTriangle(Point *p1, Point *p2, Point *p3)
std::set< osg::ref_ptr< Triangle > > TriangleSet
Definition EdgeCollector:86
std::set< osg::ref_ptr< Edge >, dereference_less > EdgeSet
Definition EdgeCollector:80
void setGeometry(osg::Geometry *geometry)
Point * addPoint(Triangle *triangle, unsigned int p1)
Definition EdgeCollector:188
void getBoundaryEdgeList(EdgeList &el)
unsigned int getNumOfTriangles()
Definition EdgeCollector:78
Point * addPoint(Triangle *triangle, Point *point)
EdgeSet _edgeSet
Definition EdgeCollector:201
bool extractBoundaryEdgeloopList(EdgeList &el, EdgeloopList &edgeloopList)
Triangle * addTriangle(unsigned int p1, unsigned int p2, unsigned int p3)
PointList _originalPointList
Definition EdgeCollector:204
std::list< osg::ref_ptr< Triangle > > TriangleList
Definition EdgeCollector:85
void getEdgeloopIndexList(IndexArrayList &ial)
std::vector< osg::ref_ptr< Point > > PointList
Definition EdgeCollector:84
TriangleSet _triangleSet
Definition EdgeCollector:202
Edge * addEdge(Triangle *triangle, Point *p1, Point *p2)
Definition EdgeCollector:90
Point()
Definition EdgeCollector:91
TriangleSet _triangles
Definition EdgeCollector:98
void clear()
Definition EdgeCollector:100
unsigned int _index
Definition EdgeCollector:95
osg::Vec3d _vertex
Definition EdgeCollector:97
bool _protected
Definition EdgeCollector:93
Definition EdgeCollector:108
osg::ref_ptr< Point > _op1
Definition EdgeCollector:114
osg::ref_ptr< Point > _op2
Definition EdgeCollector:115
bool isBoundaryEdge() const
Definition EdgeCollector:130
osg::ref_ptr< Point > _p2
Definition EdgeCollector:112
void setOrderedPoints(Point *p1, Point *p2)
TriangleSet _triangles
Definition EdgeCollector:117
void addTriangle(Triangle *triangle)
Definition EdgeCollector:128
bool beginConnected(const Edge &rhs) const
Definition EdgeCollector:136
osg::ref_ptr< Point > _p1
Definition EdgeCollector:111
bool endConnected(const Edge &rhs) const
Definition EdgeCollector:134
bool isAdjacentToBoundary() const
Definition EdgeCollector:132
Definition EdgeCollector:140
void setOrderedPoints(Point *p1, Point *p2, Point *p3)
osg::ref_ptr< Point > _op2
Definition EdgeCollector:160
osg::ref_ptr< Point > _op1
Definition EdgeCollector:159
osg::ref_ptr< Point > _p2
Definition EdgeCollector:156
osg::ref_ptr< Edge > _e1
Definition EdgeCollector:163
float distance(const osg::Vec3 &vertex) const
Definition EdgeCollector:149
osg::ref_ptr< Edge > _e2
Definition EdgeCollector:164
Triangle()
Definition EdgeCollector:141
bool isBoundaryTriangle() const
Definition EdgeCollector:151
osg::ref_ptr< Point > _p3
Definition EdgeCollector:157
osg::Plane _plane
Definition EdgeCollector:167
osg::ref_ptr< Edge > _e3
Definition EdgeCollector:165
osg::ref_ptr< Point > _p1
Definition EdgeCollector:155
osg::ref_ptr< Point > _op3
Definition EdgeCollector:161
Definition EdgeCollector:171
osg::UIntArray * toIndexArray() const
EdgeList _edgeList
Definition EdgeCollector:178
std::vector< osg::ref_ptr< Edge > > EdgeList
Definition EdgeCollector:172
bool isClosed()
Definition EdgeCollector:174
#define OSGUTIL_EXPORT
Definition Export:40

osg logo
Generated at Wed Jul 23 2025 00:00:00 for the OpenSceneGraph by doxygen 1.14.0.