OSG  3.4.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
DelaunayTriangulator.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_DELAUNAYTRIANGULATOR_
15 #define OSGUTIL_DELAUNAYTRIANGULATOR_
16 
17 #include <list>
18 
19 #include <osg/ref_ptr>
20 #include <osg/Array>
21 #include <osg/Referenced>
22 #include <osg/CopyOp>
23 #include <osg/PrimitiveSet>
24 #include <osg/Geometry>
25 
26 #include <osgUtil/Export>
27 
28 namespace osgUtil
29 {
30 
39  // controls the edges in a Delaunay triangulation.
40  // constraints can be linear (with width), areal (contains an area)
41  // uses: to replace part of a terrain with an alternative textured model (roads, lakes).
42  // the primitive sets in this are either LINE_LOOP or LINE_STRIP
43 public:
45 
55  void addtriangle(int i1, int i2, int i3);
56 
63  inline const osg::DrawElementsUInt *getTriangles() const { return prim_tris_.get(); }
64 
65  inline osg::DrawElementsUInt *getTriangles() { return prim_tris_.get(); }
66 
69  osg::Vec3Array *getPoints(const osg::Vec3Array *points);
70 
73  osg::DrawElementsUInt *makeDrawable();
74 
79  void merge(DelaunayConstraint *dco);
80 
83  void removeVerticesInside(const DelaunayConstraint *dco);
84 
87  float windingNumber(const osg::Vec3 &testpoint) const ;
88 
90  virtual bool contains(const osg::Vec3 &testpoint) const;
91  virtual bool outside(const osg::Vec3 &testpoint) const;
92 
95  void handleOverlaps(void);
96 
97 protected:
98  virtual ~DelaunayConstraint();
99 
100  typedef std::vector< int* > trilist; // array of indices in points array defining triangles
101 
102  trilist _interiorTris; // list of triangles that fits the area.
103 
104  osg::ref_ptr<osg::DrawElementsUInt> prim_tris_; // returns a PrimitiveSet to draw the interior of this DC
105 };
106 
107 
109 public:
110 
112  explicit DelaunayTriangulator(osg::Vec3Array *points, osg::Vec3Array *normals = 0);
114 
115  typedef std::vector< osg::ref_ptr<DelaunayConstraint> > linelist;
116 
118  inline void setInputPointArray(osg::Vec3Array* points) { points_ = points; }
119 
121  inline const osg::Vec3Array* getInputPointArray() const { return points_.get(); }
122 
124  inline osg::Vec3Array* getInputPointArray() { return points_.get(); }
125 
126 
128  inline void setOutputNormalArray(osg::Vec3Array* normals) { normals_ = normals; }
129 
131  inline const osg::Vec3Array *getOutputNormalArray() const { return normals_.get(); }
132 
134  inline osg::Vec3Array *getOutputNormalArray() { return normals_.get(); }
135 
136 
142  void addInputConstraint(DelaunayConstraint *dc) { constraint_lines.push_back(dc); }
143 
144 
146  bool triangulate();
147 
149  inline const osg::DrawElementsUInt *getTriangles() const { return prim_tris_.get(); }
150 
152  inline osg::DrawElementsUInt *getTriangles() { return prim_tris_.get(); }
153 
156  void removeInternalTriangles(DelaunayConstraint *constraint);
157 
158 
159 protected:
160  virtual ~DelaunayTriangulator();
162  int getindex(const osg::Vec3 &pt,const osg::Vec3Array *points);
163 
164 private:
168 
169  // GWM these lines provide required edges in the triangulated shape.
170  linelist constraint_lines;
171 
172  void _uniqueifyPoints();
173 };
174 
175 // INLINE METHODS
176 
177 
178 
179 }
180 
181 #endif
182 
std::vector< osg::ref_ptr< DelaunayConstraint > > linelist
const osg::Vec3Array * getInputPointArray() const
DelaunayTriangulator & operator=(const DelaunayTriangulator &)
osg::DrawElementsUInt * getTriangles()
void addInputConstraint(DelaunayConstraint *dc)
osg::ref_ptr< osg::DrawElementsUInt > prim_tris_
const osg::DrawElementsUInt * getTriangles() const
const osg::Vec3Array * getOutputNormalArray() const
void setOutputNormalArray(osg::Vec3Array *normals)
osg::DrawElementsUInt * getTriangles()
void setInputPointArray(osg::Vec3Array *points)
#define OSGUTIL_EXPORT
Definition: Export.h:40
const osg::DrawElementsUInt * getTriangles() const
Shader generator framework.
Definition: RenderInfo.h:20