Tessellator
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_Tessellator
#define OSGUTIL_Tessellator
#include <osg/Geometry>
#include <osgUtil/Export>
#include <osg/GLU>
#include <vector>
#ifndef CALLBACK
/* Win32 calling conventions. (or a least that's what the GLUT example tess.c uses.)*/
#define CALLBACK
#endif
namespace osgUtil {
class OSGUTIL_EXPORT Tessellator : public osg::Referenced
{
public:
Tessellator();
~Tessellator();
enum WindingType{
TESS_WINDING_ODD = GLU_TESS_WINDING_ODD,
TESS_WINDING_NONZERO = GLU_TESS_WINDING_NONZERO,
TESS_WINDING_POSITIVE = GLU_TESS_WINDING_POSITIVE,
TESS_WINDING_NEGATIVE = GLU_TESS_WINDING_NEGATIVE,
TESS_WINDING_ABS_GEQ_TWO = GLU_TESS_WINDING_ABS_GEQ_TWO
} ;
enum TessellationType {
TESS_TYPE_GEOMETRY, // tessellate everything in the geometry object
TESS_TYPE_DRAWABLE, // tessellate each polygon, triangles & quads drawables in geometry separately
TESS_TYPE_POLYGONS // tessellate ONLY polygon drawables in geometry separately
};
void setBoundaryOnly (const bool tt) { _boundaryOnly=tt;}
inline bool getBoundaryOnly ( ) { return _boundaryOnly;}
void setWindingType (const WindingType wt) { _wtype=wt;}
inline WindingType getWindingType ( ) { return _wtype;}
void setTessellationType (const TessellationType tt) { _ttype=tt;}
inline TessellationType getTessellationType ( ) { return _ttype;}
void retessellatePolygons(osg::Geometry &cxgeom);
void setTessellationNormal(const osg::Vec3 norm) { tessNormal=norm;}
osg::Geometry::PrimitiveSetList getContours() { return _Contours;}
struct Prim : public osg::Referenced
{
Prim(GLenum mode):_mode(mode) {}
typedef std::vector<osg::Vec3*> VecList;
GLenum _mode;
VecList _vertices;
};
virtual void beginTessellation();
void beginContour();
void addVertex(osg::Vec3* vertex);
void endContour();
void endTessellation();
typedef std::vector< osg::ref_ptr<Prim> > PrimList;
PrimList& getPrimList() { return _primList; }
void reset();
protected:
void reduceArray(osg::Array * cold, const unsigned int nnu);
void collectTessellation(osg::Geometry &cxgeom, unsigned int originalIndex);
typedef std::map<osg::Vec3*,unsigned int> VertexPtrToIndexMap;
void addContour(GLenum mode, unsigned int first, unsigned int last, osg::Vec3Array* vertices);
void addContour(osg::PrimitiveSet* primitive, osg::Vec3Array* vertices);
void handleNewVertices(osg::Geometry& geom,VertexPtrToIndexMap &vertexPtrToIndexMap);
void begin(GLenum mode);
void vertex(osg::Vec3* vertex);
void combine(osg::Vec3* vertex,void* vertex_data[4],GLfloat weight[4]);
void end();
void error(GLenum errorCode);
static void CALLBACK beginCallback(GLenum which, void* userData);
static void CALLBACK vertexCallback(GLvoid *data, void* userData);
static void CALLBACK combineCallback(GLdouble coords[3], void* vertex_data[4],
GLfloat weight[4], void** outData,
void* useData);
static void CALLBACK endCallback(void* userData);
static void CALLBACK errorCallback(GLenum errorCode, void* userData);
struct Vec3d
{
double _v[3];
};
struct NewVertex
{
NewVertex():
_vpos(0),
_f1(0),
_v1(0),
_f2(0),
_v2(0),
_f3(0),
_v3(0),
_f4(0),
_v4(0) {}
NewVertex(const NewVertex& nv):
_vpos(nv._vpos),
_f1(nv._f1),
_v1(nv._v1),
_f2(nv._f2),
_v2(nv._v2),
_f3(nv._f3),
_v3(nv._v3),
_f4(nv._f4),
_v4(nv._v4) {}
NewVertex(osg::Vec3* vx,
float f1,osg::Vec3* v1,
float f2,osg::Vec3* v2,
float f3,osg::Vec3* v3,
float f4,osg::Vec3* v4):
_vpos(vx),
_f1(f1),
_v1(v1),
_f2(f2),
_v2(v2),
_f3(f3),
_v3(v3),
_f4(f4),
_v4(v4) {}
osg::Vec3 *_vpos; // added gwm Jan 2004 the vertex coords s.t. NewVertex can be used in a std::vector
float _f1;
osg::Vec3* _v1;
float _f2;
osg::Vec3* _v2;
float _f3;
osg::Vec3* _v3;
float _f4;
osg::Vec3* _v4;
};
//change NewVertexList from std::map<osg::Vec3*,NewVertex> NewVertexList;
// because this has undefined order of insertion for new vertices.
// which occasionally corrupted the texture mapping.
typedef std::vector<NewVertex> NewVertexList;
typedef std::vector<Vec3d*> Vec3dList;
osg::GLUtesselator* _tobj;
PrimList _primList;
Vec3dList _coordData;
NewVertexList _newVertexList;
GLenum _errorCode;
WindingType _wtype;
TessellationType _ttype;
bool _boundaryOnly; // see gluTessProperty - if true: make the boundary edges only.
unsigned int _numberVerts;
osg::Geometry::PrimitiveSetList _Contours;
unsigned int _index;
osg::Vec3 tessNormal;
unsigned int _extraPrimitives;
};
}
#endif
GLU
GLU_TESS_WINDING_NONZERO
#define GLU_TESS_WINDING_NONZERO
Definition GLU:156
GLU_TESS_WINDING_POSITIVE
#define GLU_TESS_WINDING_POSITIVE
Definition GLU:157
GLU_TESS_WINDING_NEGATIVE
#define GLU_TESS_WINDING_NEGATIVE
Definition GLU:158
GLU_TESS_WINDING_ODD
#define GLU_TESS_WINDING_ODD
Definition GLU:155
GLU_TESS_WINDING_ABS_GEQ_TWO
#define GLU_TESS_WINDING_ABS_GEQ_TWO
Definition GLU:159
Geometry
CALLBACK
#define CALLBACK
Definition Tessellator:27
osgUtil::Tessellator::_ttype
TessellationType _ttype
Definition Tessellator:229
osgUtil::Tessellator::Vec3dList
std::vector< Vec3d * > Vec3dList
Definition Tessellator:216
osgUtil::Tessellator::tessNormal
osg::Vec3 tessNormal
Definition Tessellator:243
osgUtil::Tessellator::reset
void reset()
osgUtil::Tessellator::_Contours
osg::Geometry::PrimitiveSetList _Contours
Definition Tessellator:237
osgUtil::Tessellator::getTessellationType
TessellationType getTessellationType()
Definition Tessellator:70
osgUtil::Tessellator::getBoundaryOnly
bool getBoundaryOnly()
Definition Tessellator:62
osgUtil::Tessellator::error
void error(GLenum errorCode)
osgUtil::Tessellator::getWindingType
WindingType getWindingType()
Definition Tessellator:66
osgUtil::Tessellator::~Tessellator
~Tessellator()
osgUtil::Tessellator::setTessellationNormal
void setTessellationNormal(const osg::Vec3 norm)
Definition Tessellator:85
osgUtil::Tessellator::getContours
osg::Geometry::PrimitiveSetList getContours()
Definition Tessellator:87
osgUtil::Tessellator::_numberVerts
unsigned int _numberVerts
Definition Tessellator:234
osgUtil::Tessellator::beginContour
void beginContour()
osgUtil::Tessellator::beginTessellation
virtual void beginTessellation()
osgUtil::Tessellator::_coordData
Vec3dList _coordData
Definition Tessellator:221
osgUtil::Tessellator::combine
void combine(osg::Vec3 *vertex, void *vertex_data[4], GLfloat weight[4])
osgUtil::Tessellator::endTessellation
void endTessellation()
osgUtil::Tessellator::reduceArray
void reduceArray(osg::Array *cold, const unsigned int nnu)
osgUtil::Tessellator::setWindingType
void setWindingType(const WindingType wt)
Definition Tessellator:65
osgUtil::Tessellator::_extraPrimitives
unsigned int _extraPrimitives
Definition Tessellator:246
osgUtil::Tessellator::endCallback
static void CALLBACK endCallback(void *userData)
osgUtil::Tessellator::begin
void begin(GLenum mode)
osgUtil::Tessellator::handleNewVertices
void handleNewVertices(osg::Geometry &geom, VertexPtrToIndexMap &vertexPtrToIndexMap)
osgUtil::Tessellator::end
void end()
osgUtil::Tessellator::errorCallback
static void CALLBACK errorCallback(GLenum errorCode, void *userData)
osgUtil::Tessellator::TessellationType
TessellationType
Definition Tessellator:54
osgUtil::Tessellator::TESS_TYPE_GEOMETRY
@ TESS_TYPE_GEOMETRY
Definition Tessellator:55
osgUtil::Tessellator::TESS_TYPE_DRAWABLE
@ TESS_TYPE_DRAWABLE
Definition Tessellator:56
osgUtil::Tessellator::TESS_TYPE_POLYGONS
@ TESS_TYPE_POLYGONS
Definition Tessellator:57
osgUtil::Tessellator::addVertex
void addVertex(osg::Vec3 *vertex)
osgUtil::Tessellator::_primList
PrimList _primList
Definition Tessellator:220
osgUtil::Tessellator::vertex
void vertex(osg::Vec3 *vertex)
osgUtil::Tessellator::beginCallback
static void CALLBACK beginCallback(GLenum which, void *userData)
osgUtil::Tessellator::combineCallback
static void CALLBACK combineCallback(GLdouble coords[3], void *vertex_data[4], GLfloat weight[4], void **outData, void *useData)
osgUtil::Tessellator::setTessellationType
void setTessellationType(const TessellationType tt)
Definition Tessellator:69
osgUtil::Tessellator::collectTessellation
void collectTessellation(osg::Geometry &cxgeom, unsigned int originalIndex)
osgUtil::Tessellator::_newVertexList
NewVertexList _newVertexList
Definition Tessellator:222
osgUtil::Tessellator::retessellatePolygons
void retessellatePolygons(osg::Geometry &cxgeom)
osgUtil::Tessellator::_index
unsigned int _index
Definition Tessellator:240
osgUtil::Tessellator::_errorCode
GLenum _errorCode
Definition Tessellator:223
osgUtil::Tessellator::Tessellator
Tessellator()
osgUtil::Tessellator::addContour
void addContour(osg::PrimitiveSet *primitive, osg::Vec3Array *vertices)
osgUtil::Tessellator::vertexCallback
static void CALLBACK vertexCallback(GLvoid *data, void *userData)
osgUtil::Tessellator::getPrimList
PrimList & getPrimList()
Definition Tessellator:116
osgUtil::Tessellator::PrimList
std::vector< osg::ref_ptr< Prim > > PrimList
Definition Tessellator:114
osgUtil::Tessellator::VertexPtrToIndexMap
std::map< osg::Vec3 *, unsigned int > VertexPtrToIndexMap
Definition Tessellator:129
osgUtil::Tessellator::NewVertexList
std::vector< NewVertex > NewVertexList
Definition Tessellator:215
osgUtil::Tessellator::_boundaryOnly
bool _boundaryOnly
Definition Tessellator:231
osgUtil::Tessellator::_tobj
osg::GLUtesselator * _tobj
Definition Tessellator:218
osgUtil::Tessellator::WindingType
WindingType
Definition Tessellator:44
osgUtil::Tessellator::TESS_WINDING_NONZERO
@ TESS_WINDING_NONZERO
Definition Tessellator:46
osgUtil::Tessellator::TESS_WINDING_ABS_GEQ_TWO
@ TESS_WINDING_ABS_GEQ_TWO
Definition Tessellator:49
osgUtil::Tessellator::TESS_WINDING_POSITIVE
@ TESS_WINDING_POSITIVE
Definition Tessellator:47
osgUtil::Tessellator::TESS_WINDING_ODD
@ TESS_WINDING_ODD
Definition Tessellator:45
osgUtil::Tessellator::TESS_WINDING_NEGATIVE
@ TESS_WINDING_NEGATIVE
Definition Tessellator:48
osgUtil::Tessellator::addContour
void addContour(GLenum mode, unsigned int first, unsigned int last, osg::Vec3Array *vertices)
osgUtil::Tessellator::endContour
void endContour()
osgUtil::Tessellator::setBoundaryOnly
void setBoundaryOnly(const bool tt)
Definition Tessellator:61
osgUtil::Tessellator::_wtype
WindingType _wtype
Definition Tessellator:226
osg::Array
Definition Array:61
osg::Geometry
Definition Geometry:31
osg::Geometry::PrimitiveSetList
std::vector< ref_ptr< PrimitiveSet > > PrimitiveSetList
Definition Geometry:102
osg::PrimitiveSet
Definition PrimitiveSet:125
osg::Referenced
Definition Referenced:44
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
osgUtil::Tessellator::NewVertex::_f1
float _f1
Definition Tessellator:198
osgUtil::Tessellator::NewVertex::_vpos
osg::Vec3 * _vpos
Definition Tessellator:196
osgUtil::Tessellator::NewVertex::_f2
float _f2
Definition Tessellator:201
osgUtil::Tessellator::NewVertex::NewVertex
NewVertex(const NewVertex &nv)
Definition Tessellator:170
osgUtil::Tessellator::NewVertex::_v1
osg::Vec3 * _v1
Definition Tessellator:199
osgUtil::Tessellator::NewVertex::_v2
osg::Vec3 * _v2
Definition Tessellator:202
osgUtil::Tessellator::NewVertex::NewVertex
NewVertex(osg::Vec3 *vx, float f1, osg::Vec3 *v1, float f2, osg::Vec3 *v2, float f3, osg::Vec3 *v3, float f4, osg::Vec3 *v4)
Definition Tessellator:181
osgUtil::Tessellator::NewVertex::_v3
osg::Vec3 * _v3
Definition Tessellator:205
osgUtil::Tessellator::NewVertex::_f4
float _f4
Definition Tessellator:207
osgUtil::Tessellator::NewVertex::_v4
osg::Vec3 * _v4
Definition Tessellator:208
osgUtil::Tessellator::NewVertex::_f3
float _f3
Definition Tessellator:204
osgUtil::Tessellator::NewVertex::NewVertex
NewVertex()
Definition Tessellator:159
osgUtil::Tessellator::Prim::VecList
std::vector< osg::Vec3 * > VecList
Definition Tessellator:93
osgUtil::Tessellator::Prim::_vertices
VecList _vertices
Definition Tessellator:96
osgUtil::Tessellator::Prim::Prim
Prim(GLenum mode)
Definition Tessellator:91
osgUtil::Tessellator::Prim::_mode
GLenum _mode
Definition Tessellator:95
osgUtil::Tessellator::Vec3d
Definition Tessellator:151
osgUtil::Tessellator::Vec3d::_v
double _v[3]
Definition Tessellator:152