openscenegraph
DelaunayTriangulator
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
28namespace 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
43public:
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
70
74
80
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
97protected:
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
109public:
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
147
149 inline const osg::DrawElementsUInt *getTriangles() const { return prim_tris_.get(); }
150
152 inline osg::DrawElementsUInt *getTriangles() { return prim_tris_.get(); }
153
157
158
159protected:
162 int getindex(const osg::Vec3 &pt,const osg::Vec3Array *points);
163
164private:
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
Definition DelaunayTriangulator:38
osg::DrawElementsUInt * getTriangles()
Definition DelaunayTriangulator:65
void addtriangle(int i1, int i2, int i3)
std::vector< int * > trilist
Definition DelaunayTriangulator:100
float windingNumber(const osg::Vec3 &testpoint) const
osg::ref_ptr< osg::DrawElementsUInt > prim_tris_
Definition DelaunayTriangulator:104
virtual bool contains(const osg::Vec3 &testpoint) const
const osg::DrawElementsUInt * getTriangles() const
Definition DelaunayTriangulator:63
osg::Vec3Array * getPoints(const osg::Vec3Array *points)
DelaunayConstraint()
Definition DelaunayTriangulator:44
void merge(DelaunayConstraint *dco)
void removeVerticesInside(const DelaunayConstraint *dco)
virtual bool outside(const osg::Vec3 &testpoint) const
trilist _interiorTris
Definition DelaunayTriangulator:102
osg::DrawElementsUInt * makeDrawable()
Definition DelaunayTriangulator:108
void setInputPointArray(osg::Vec3Array *points)
Definition DelaunayTriangulator:118
osg::Vec3Array * getInputPointArray()
Definition DelaunayTriangulator:124
void addInputConstraint(DelaunayConstraint *dc)
Definition DelaunayTriangulator:142
DelaunayTriangulator & operator=(const DelaunayTriangulator &)
Definition DelaunayTriangulator:161
osg::Vec3Array * getOutputNormalArray()
Definition DelaunayTriangulator:134
std::vector< osg::ref_ptr< DelaunayConstraint > > linelist
Definition DelaunayTriangulator:115
void removeInternalTriangles(DelaunayConstraint *constraint)
void setOutputNormalArray(osg::Vec3Array *normals)
Definition DelaunayTriangulator:128
const osg::DrawElementsUInt * getTriangles() const
Definition DelaunayTriangulator:149
DelaunayTriangulator(osg::Vec3Array *points, osg::Vec3Array *normals=0)
DelaunayTriangulator(const DelaunayTriangulator &copy, const osg::CopyOp &copyop=osg::CopyOp::SHALLOW_COPY)
osg::DrawElementsUInt * getTriangles()
Definition DelaunayTriangulator:152
int getindex(const osg::Vec3 &pt, const osg::Vec3Array *points)
const osg::Vec3Array * getInputPointArray() const
Definition DelaunayTriangulator:121
const osg::Vec3Array * getOutputNormalArray() const
Definition DelaunayTriangulator:131
Definition CopyOp:41
@ SHALLOW_COPY
Definition CopyOp:47
Definition PrimitiveSet:502
Definition Geometry:31
Definition Referenced:44
A concrete array holding elements of type T.
Definition Array:243
Definition Vec3f:29
Definition ref_ptr:32
Shader generator framework.
Definition NodeVisitor:25
#define OSGUTIL_EXPORT
Definition osgUtil/Export:40