DelaunayTriangulator
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_DELAUNAYTRIANGULATOR_
#define OSGUTIL_DELAUNAYTRIANGULATOR_
#include <list>
#include <osg/ref_ptr>
#include <osg/Array>
#include <osg/Referenced>
#include <osg/CopyOp>
#include <osg/PrimitiveSet>
#include <osg/Geometry>
#include <osgUtil/Export>
namespace osgUtil
{
class OSGUTIL_EXPORT DelaunayConstraint: public osg::Geometry {
// controls the edges in a Delaunay triangulation.
// constraints can be linear (with width), areal (contains an area)
// uses: to replace part of a terrain with an alternative textured model (roads, lakes).
// the primitive sets in this are either LINE_LOOP or LINE_STRIP
public:
DelaunayConstraint() { }
void addtriangle(int i1, int i2, int i3);
inline const osg::DrawElementsUInt *getTriangles() const { return prim_tris_.get(); }
inline osg::DrawElementsUInt *getTriangles() { return prim_tris_.get(); }
osg::Vec3Array *getPoints(const osg::Vec3Array *points);
osg::DrawElementsUInt *makeDrawable();
void merge(DelaunayConstraint *dco);
void removeVerticesInside(const DelaunayConstraint *dco);
float windingNumber(const osg::Vec3 &testpoint) const ;
virtual bool contains(const osg::Vec3 &testpoint) const;
virtual bool outside(const osg::Vec3 &testpoint) const;
void handleOverlaps(void);
protected:
virtual ~DelaunayConstraint();
typedef std::vector< int* > trilist; // array of indices in points array defining triangles
trilist _interiorTris; // list of triangles that fits the area.
osg::ref_ptr<osg::DrawElementsUInt> prim_tris_; // returns a PrimitiveSet to draw the interior of this DC
};
class OSGUTIL_EXPORT DelaunayTriangulator: public osg::Referenced {
public:
DelaunayTriangulator();
explicit DelaunayTriangulator(osg::Vec3Array *points, osg::Vec3Array *normals = 0);
DelaunayTriangulator(const DelaunayTriangulator &copy, const osg::CopyOp &copyop = osg::CopyOp::SHALLOW_COPY);
typedef std::vector< osg::ref_ptr<DelaunayConstraint> > linelist;
inline void setInputPointArray(osg::Vec3Array* points) { points_ = points; }
inline const osg::Vec3Array* getInputPointArray() const { return points_.get(); }
inline osg::Vec3Array* getInputPointArray() { return points_.get(); }
inline void setOutputNormalArray(osg::Vec3Array* normals) { normals_ = normals; }
inline const osg::Vec3Array *getOutputNormalArray() const { return normals_.get(); }
inline osg::Vec3Array *getOutputNormalArray() { return normals_.get(); }
void addInputConstraint(DelaunayConstraint *dc) { constraint_lines.push_back(dc); }
bool triangulate();
inline const osg::DrawElementsUInt *getTriangles() const { return prim_tris_.get(); }
inline osg::DrawElementsUInt *getTriangles() { return prim_tris_.get(); }
void removeInternalTriangles(DelaunayConstraint *constraint);
protected:
virtual ~DelaunayTriangulator();
DelaunayTriangulator &operator=(const DelaunayTriangulator &) { return *this; }
int getindex(const osg::Vec3 &pt,const osg::Vec3Array *points);
private:
osg::ref_ptr<osg::Vec3Array> points_;
osg::ref_ptr<osg::Vec3Array> normals_;
osg::ref_ptr<osg::DrawElementsUInt> prim_tris_;
// GWM these lines provide required edges in the triangulated shape.
linelist constraint_lines;
void _uniqueifyPoints();
};
// INLINE METHODS
}
#endif
Array
CopyOp
Geometry
PrimitiveSet
Referenced
osgUtil::DelaunayConstraint
Definition DelaunayTriangulator:38
osgUtil::DelaunayConstraint::getTriangles
osg::DrawElementsUInt * getTriangles()
Definition DelaunayTriangulator:65
osgUtil::DelaunayConstraint::addtriangle
void addtriangle(int i1, int i2, int i3)
osgUtil::DelaunayConstraint::trilist
std::vector< int * > trilist
Definition DelaunayTriangulator:100
osgUtil::DelaunayConstraint::windingNumber
float windingNumber(const osg::Vec3 &testpoint) const
osgUtil::DelaunayConstraint::prim_tris_
osg::ref_ptr< osg::DrawElementsUInt > prim_tris_
Definition DelaunayTriangulator:104
osgUtil::DelaunayConstraint::contains
virtual bool contains(const osg::Vec3 &testpoint) const
osgUtil::DelaunayConstraint::getTriangles
const osg::DrawElementsUInt * getTriangles() const
Definition DelaunayTriangulator:63
osgUtil::DelaunayConstraint::getPoints
osg::Vec3Array * getPoints(const osg::Vec3Array *points)
osgUtil::DelaunayConstraint::~DelaunayConstraint
virtual ~DelaunayConstraint()
osgUtil::DelaunayConstraint::DelaunayConstraint
DelaunayConstraint()
Definition DelaunayTriangulator:44
osgUtil::DelaunayConstraint::merge
void merge(DelaunayConstraint *dco)
osgUtil::DelaunayConstraint::removeVerticesInside
void removeVerticesInside(const DelaunayConstraint *dco)
osgUtil::DelaunayConstraint::outside
virtual bool outside(const osg::Vec3 &testpoint) const
osgUtil::DelaunayConstraint::handleOverlaps
void handleOverlaps(void)
osgUtil::DelaunayConstraint::_interiorTris
trilist _interiorTris
Definition DelaunayTriangulator:102
osgUtil::DelaunayConstraint::makeDrawable
osg::DrawElementsUInt * makeDrawable()
osgUtil::DelaunayTriangulator::setInputPointArray
void setInputPointArray(osg::Vec3Array *points)
Definition DelaunayTriangulator:118
osgUtil::DelaunayTriangulator::getInputPointArray
osg::Vec3Array * getInputPointArray()
Definition DelaunayTriangulator:124
osgUtil::DelaunayTriangulator::addInputConstraint
void addInputConstraint(DelaunayConstraint *dc)
Definition DelaunayTriangulator:142
osgUtil::DelaunayTriangulator::operator=
DelaunayTriangulator & operator=(const DelaunayTriangulator &)
Definition DelaunayTriangulator:161
osgUtil::DelaunayTriangulator::getOutputNormalArray
osg::Vec3Array * getOutputNormalArray()
Definition DelaunayTriangulator:134
osgUtil::DelaunayTriangulator::triangulate
bool triangulate()
osgUtil::DelaunayTriangulator::linelist
std::vector< osg::ref_ptr< DelaunayConstraint > > linelist
Definition DelaunayTriangulator:115
osgUtil::DelaunayTriangulator::removeInternalTriangles
void removeInternalTriangles(DelaunayConstraint *constraint)
osgUtil::DelaunayTriangulator::setOutputNormalArray
void setOutputNormalArray(osg::Vec3Array *normals)
Definition DelaunayTriangulator:128
osgUtil::DelaunayTriangulator::getTriangles
const osg::DrawElementsUInt * getTriangles() const
Definition DelaunayTriangulator:149
osgUtil::DelaunayTriangulator::~DelaunayTriangulator
virtual ~DelaunayTriangulator()
osgUtil::DelaunayTriangulator::DelaunayTriangulator
DelaunayTriangulator(osg::Vec3Array *points, osg::Vec3Array *normals=0)
osgUtil::DelaunayTriangulator::DelaunayTriangulator
DelaunayTriangulator()
osgUtil::DelaunayTriangulator::DelaunayTriangulator
DelaunayTriangulator(const DelaunayTriangulator &copy, const osg::CopyOp &copyop=osg::CopyOp::SHALLOW_COPY)
osgUtil::DelaunayTriangulator::getTriangles
osg::DrawElementsUInt * getTriangles()
Definition DelaunayTriangulator:152
osgUtil::DelaunayTriangulator::getindex
int getindex(const osg::Vec3 &pt, const osg::Vec3Array *points)
osgUtil::DelaunayTriangulator::getInputPointArray
const osg::Vec3Array * getInputPointArray() const
Definition DelaunayTriangulator:121
osgUtil::DelaunayTriangulator::getOutputNormalArray
const osg::Vec3Array * getOutputNormalArray() const
Definition DelaunayTriangulator:131
osg::CopyOp
Definition CopyOp:41
osg::CopyOp::SHALLOW_COPY
@ SHALLOW_COPY
Definition CopyOp:47
osg::DrawElementsUInt
Definition PrimitiveSet:502
osg::Geometry
Definition Geometry:31
osg::Referenced
Definition Referenced:44
osg::ref_ptr
Definition ref_ptr:32
osgUtil
Definition NodeVisitor:25
osg::Vec3Array
TemplateArray< Vec3, Array::Vec3ArrayType, 3, GL_FLOAT > Vec3Array
Definition Array:449
osg::Vec3
Vec3f Vec3
Definition Vec3:21
Export
OSGUTIL_EXPORT
#define OSGUTIL_EXPORT
Definition osgUtil/Export:40
ref_ptr