From Paul Martz and Robert Osfield, renamed include/osgUtil/Tesselator and associated classes/references to Tessellator etc.

This commit is contained in:
Robert Osfield
2007-01-08 11:23:52 +00:00
parent dfb21cb81a
commit 02bda82b55
26 changed files with 316 additions and 318 deletions

View File

@@ -23,7 +23,7 @@
#include <osg/Texture2D>
#include <osg/Projection>
#include <osg/MatrixTransform>
#include <osgUtil/Tesselator> // tesselator triangulates the constrained triangles
#include <osgUtil/Tessellator> // tessellator triangulates the constrained triangles
#include <osgText/Text>
@@ -273,7 +273,7 @@ osg::Vec3d getpt(const int np)
return osg::Vec3d(x,y,z);
}
osg::Node* createHUD(const int ndcs,std::string what)
{ // add a string reporting the type of winding rule tesselation applied
{ // add a string reporting the type of winding rule tessellation applied
osg::Geode* geode = new osg::Geode();
std::string timesFont("fonts/arial.ttf");
@@ -988,14 +988,14 @@ osg::Geometry *ArealConstraint::makeWallGeometry( osg::Vec3Array *pt)
osg::DrawElementsUInt *trgeom=getTriangles();
edges->addPrimitiveSet(trgeom);
osg::ref_ptr<osgUtil::Tesselator> tscx=new osgUtil::Tesselator; // this assembles all the constraints
tscx->setTesselationType(osgUtil::Tesselator::TESS_TYPE_GEOMETRY);
osg::ref_ptr<osgUtil::Tessellator> tscx=new osgUtil::Tessellator; // this assembles all the constraints
tscx->setTessellationType(osgUtil::Tessellator::TESS_TYPE_GEOMETRY);
tscx->setBoundaryOnly(true);
tscx->setWindingType( osgUtil::Tesselator::TESS_WINDING_NONZERO);
tscx->setWindingType( osgUtil::Tessellator::TESS_WINDING_NONZERO);
// find all edges.
const osg::Vec3Array *points=dynamic_cast<osg::Vec3Array*>(getVertexArray());
tscx->retesselatePolygons(*(edges)); // find all edges
tscx->retessellatePolygons(*(edges)); // find all edges
if (walltexture!="") {
osg::Image* image = osgDB::readImageFile(walltexture.c_str());

View File

@@ -294,7 +294,7 @@ osg::Node* createScene()
// note, anticlockwsie ordering.
// note II, OpenGL polygons must be convex plan polygons, otherwise
// undefined results will occur. If you have concave polygons or ones
// that cross over themselves then use the osgUtil::Tesselator to fix
// that cross over themselves then use the osgUtil::Tessellator to fix
// the polygons into a set of valid polygons.
osg::Vec3 myCoords[] =
{

View File

@@ -19,7 +19,6 @@
#include <osg/Projection>
#include <osg/io_utils>
#include <osgUtil/Tesselator>
#include <osgUtil/CullVisitor>
#include <osgUtil/Optimizer>

View File

@@ -8,7 +8,7 @@
#include <osg/BlendFunc>
#include <osg/ClearNode>
#include <osgUtil/Tesselator>
#include <osgUtil/Tessellator>
#include <osgUtil/CullVisitor>
#include <osgText/Text>
@@ -115,8 +115,8 @@ osg::Geometry* createWing(const osg::Vec3& left, const osg::Vec3& nose, const os
geom->addPrimitiveSet(new osg::DrawArrays(GL_POLYGON,0,vertices->getNumElements()));
osgUtil::Tesselator tesselator;
tesselator.retesselatePolygons(*geom);
osgUtil::Tessellator tessellator;
tessellator.retessellatePolygons(*geom);
return geom;

View File

@@ -8,7 +8,6 @@
#include <osg/ClearNode>
#include <osg/Projection>
#include <osgUtil/Tesselator>
#include <osgUtil/CullVisitor>

View File

@@ -2,7 +2,7 @@ TOPDIR = ../..
include $(TOPDIR)/Make/makedefs
CXXFILES =\
osgtesselate.cpp\
osgtessellate.cpp\
LIBS += -losgProducer -lProducer -losgText -losgGA -losgDB -losgUtil -losg $(GL_LIBS) $(X_LIBS) $(OTHER_LIBS)
@@ -10,7 +10,7 @@ INSTFILES = \
$(CXXFILES)\
GNUmakefile.inst=GNUmakefile
EXEC = osgtesselate
EXEC = osgtessellate
INC += $(X_INC)

View File

@@ -2,11 +2,11 @@ TOPDIR = ../..
include $(TOPDIR)/Make/makedefs
CXXFILES =\
osgtesselate.cpp\
osgtessellate.cpp\
LIBS += -losgProducer -lProducer -losgDB -losgText -losgUtil -losg $(GL_LIBS) $(X_LIBS) $(OTHER_LIBS)
EXEC = osgtesselate
EXEC = osgtessellate
INC += $(X_INC)

View File

@@ -9,14 +9,14 @@
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*/
/* osgtesselator
* - this tesselator is an extension of the basic one - rather than tesselating
/* osgTessellator
* - this Tessellator is an extension of the basic one - rather than tesselating
* individual polygons, we tesselate the entire geode with multiple contours.
* allows for overlapping contours etc.
* the tesselator has new member fuinctions
setTesselationType(osgUtil::Tesselator::TESS_TYPE_xxx);
* the Tessellator has new member fuinctions
setTessellationType(osgUtil::Tessellator::TESS_TYPE_xxx);
tscx->setBoundaryOnly(bool);
tscx->setWindingType( osgUtil::Tesselator::TESS_WINDING_xxx);
tscx->setWindingType( osgUtil::Tessellator::TESS_WINDING_xxx);
* for winding rules: See the red book chap 13.
*/
@@ -28,12 +28,12 @@
#include <osgText/Text>
#include <osgUtil/Tesselator> // to tesselate multiple contours
#include <osgUtil/Tessellator> // to tesselate multiple contours
class tesselateDemoGeometry : public osg::Geometry, public osgUtil::Tesselator {
// We add the Tesselator to the geometry because we want to access the
// tesselatable contours again; you can apply a tesselator to a Geometry
class tesselateDemoGeometry : public osg::Geometry, public osgUtil::Tessellator {
// We add the Tessellator to the geometry because we want to access the
// tesselatable contours again; you can apply a Tessellator to a Geometry
// to produce exactly a required tesselation once only, and then
// the contours could be discarded since the geometry does not need to be retesselated.
public:
@@ -89,7 +89,7 @@ osg::Geometry *makePolsTwo (void)
gtess->setNormalBinding(osg::Geometry::BIND_PER_VERTEX);
gtess->setTexCoordArray(0,tcs);
// demonstrate that the tesselator makes textured tesselations
// demonstrate that the Tessellator makes textured tesselations
osg::StateSet* stateset = new osg::StateSet();
osg::Image* image = osgDB::readImageFile("Cubemap_snow/posy.jpg");
@@ -108,9 +108,9 @@ osg::Geometry *makePolsTwo (void)
gtess->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::TRIANGLE_STRIP,nstart,8));nstart+=8;
gtess->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::TRIANGLE_STRIP,nstart,8));nstart+=8;
gtess->setTesselationType(osgUtil::Tesselator::TESS_TYPE_GEOMETRY);
gtess->setTessellationType(osgUtil::Tessellator::TESS_TYPE_GEOMETRY);
gtess->setBoundaryOnly(true);
gtess->setWindingType( osgUtil::Tesselator::TESS_WINDING_ABS_GEQ_TWO); // so that first change in wind type makes the commonest tesselation - ODD.
gtess->setWindingType( osgUtil::Tessellator::TESS_WINDING_ABS_GEQ_TWO); // so that first change in wind type makes the commonest tesselation - ODD.
return gtess;
}
@@ -161,7 +161,7 @@ osg::Geometry *makeSideWall (const float xpos)
}
gtess->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::POLYGON,nstart,5));nstart+=5;
// demonstrate that the tesselator makes textured tesselations
// demonstrate that the Tessellator makes textured tesselations
osg::StateSet* stateset = new osg::StateSet();
osg::Image* image = osgDB::readImageFile("Cubemap_snow/posx.jpg");
@@ -176,14 +176,14 @@ osg::Geometry *makeSideWall (const float xpos)
gtess->setStateSet( stateset );
osg::ref_ptr<osgUtil::Tesselator> tscx=new osgUtil::Tesselator; // the v1.2 multi-contour tesselator.
osg::ref_ptr<osgUtil::Tessellator> tscx=new osgUtil::Tessellator; // the v1.2 multi-contour Tessellator.
// we use the geometry primitives to describe the contours which are tesselated.
// Winding odd means leave hole in surface where there are 2,4,6... contours circling the point.
tscx->setTesselationType(osgUtil::Tesselator::TESS_TYPE_GEOMETRY);
tscx->setTessellationType(osgUtil::Tessellator::TESS_TYPE_GEOMETRY);
tscx->setBoundaryOnly(false);
tscx->setWindingType( osgUtil::Tesselator::TESS_WINDING_ODD); // so that first change in wind type makes the commonest tesselation - ODD.
tscx->setWindingType( osgUtil::Tessellator::TESS_WINDING_ODD); // so that first change in wind type makes the commonest tesselation - ODD.
tscx->retesselatePolygons(*gtess);
tscx->retessellatePolygons(*gtess);
return gtess;
}
@@ -258,7 +258,7 @@ osg::Geometry *makeFrontWall (const float zpos) {
}
gtess->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::QUADS,nstart,20));nstart+=20;
// demonstrate that the tesselator makes textured tesselations
// demonstrate that the Tessellator makes textured tesselations
osg::StateSet* stateset = new osg::StateSet();
osg::Image* image = osgDB::readImageFile("Cubemap_snow/posy.jpg");
@@ -272,14 +272,14 @@ osg::Geometry *makeFrontWall (const float zpos) {
}
gtess->setStateSet( stateset );
// We use a Tesselator to produce the tesselation required once only
// We use a Tessellator to produce the tesselation required once only
// and the contours are discarded.
osg::ref_ptr<osgUtil::Tesselator> tscx=new osgUtil::Tesselator; // the v1.2 multi-contour tesselator.
tscx->setTesselationType(osgUtil::Tesselator::TESS_TYPE_GEOMETRY);
osg::ref_ptr<osgUtil::Tessellator> tscx=new osgUtil::Tessellator; // the v1.2 multi-contour Tessellator.
tscx->setTessellationType(osgUtil::Tessellator::TESS_TYPE_GEOMETRY);
tscx->setBoundaryOnly(false);
tscx->setWindingType( osgUtil::Tesselator::TESS_WINDING_ODD); // so that first change in wind type makes the commonest tesselation - ODD.
tscx->setWindingType( osgUtil::Tessellator::TESS_WINDING_ODD); // so that first change in wind type makes the commonest tesselation - ODD.
tscx->retesselatePolygons(*gtess);
tscx->retessellatePolygons(*gtess);
return gtess;
}
@@ -298,7 +298,7 @@ osg::Geometry *makePols (void) {
osg::Vec3Array *nrms = new osg::Vec3Array;
osg::Vec2Array *tcs = new osg::Vec2Array;
osg::Vec3 nrm(0,-1,0);
// coordinates from red book code but shifted by 1000 & 2000 for alternate tesselatory things.
// coordinates from red book code but shifted by 1000 & 2000 for alternate Tessellatory things.
static GLdouble rects[12][3] =
{ { 50.0, 50.0, 0.0 },
{ 300.0, 50.0, 0.0 },
@@ -452,7 +452,7 @@ osg::Geometry *makePols (void) {
gtess->setNormalBinding(osg::Geometry::BIND_PER_VERTEX);
gtess->setTexCoordArray(0,tcs);
// demonstrate that the tesselator makes textured tesselations
// demonstrate that the Tessellator makes textured tesselations
osg::StateSet* stateset = new osg::StateSet();
osg::Image* image = osgDB::readImageFile("Cubemap_snow/posz.jpg");
@@ -483,12 +483,12 @@ osg::Geometry *makePols (void) {
gtess->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::TRIANGLE_STRIP,nstart,8));nstart+=8;
// We need to access the tesselatable contours again to demonstrate all types of tesselation.
// I could add the Tesselator to the geometry as userdata, but here
// I could add the Tessellator to the geometry as userdata, but here
// I use the derived tesselateDemoGeometry to hold both the drawable geode and the original contours.
gtess->setTesselationType(osgUtil::Tesselator::TESS_TYPE_GEOMETRY);
gtess->setTessellationType(osgUtil::Tessellator::TESS_TYPE_GEOMETRY);
gtess->setBoundaryOnly(true);
gtess->setWindingType( osgUtil::Tesselator::TESS_WINDING_ABS_GEQ_TWO); // so that first change in wind type makes the commonest tesselation - ODD.
gtess->setWindingType( osgUtil::Tessellator::TESS_WINDING_ABS_GEQ_TWO); // so that first change in wind type makes the commonest tesselation - ODD.
return gtess;
}
@@ -575,50 +575,50 @@ public:
{
osg::Geometry* geom = dynamic_cast<osg::Geometry*>(geode.getDrawable(i));
if (geom) {
osg::ref_ptr<osgUtil::Tesselator> tscx=new osgUtil::Tesselator();
osg::ref_ptr<osgUtil::Tessellator> tscx=new osgUtil::Tessellator();
if (tscx.valid()) {
tscx->setTesselationType(osgUtil::Tesselator::TESS_TYPE_GEOMETRY);
tscx->setTessellationType(osgUtil::Tessellator::TESS_TYPE_GEOMETRY);
if (geode.getName()== "tesselate") {
// add a tesselator so that this geom is retesselated when N is pressed
// add a Tessellator so that this geom is retesselated when N is pressed
tscx->setBoundaryOnly(true);
tscx->setWindingType( osgUtil::Tesselator::TESS_WINDING_ABS_GEQ_TWO); // so that first change in wind type makes the commonest tesselation - ODD.
tscx->setWindingType( osgUtil::Tessellator::TESS_WINDING_ABS_GEQ_TWO); // so that first change in wind type makes the commonest tesselation - ODD.
geom->setUserData(tscx.get());
} else if (geode.getName()== "tesselate odd") {
// OR you can just apply the tesselator once only, using these different types
tscx->setWindingType( osgUtil::Tesselator::TESS_WINDING_ODD); // commonest tesselation - ODD.
tscx->retesselatePolygons(*geom);
// OR you can just apply the Tessellator once only, using these different types
tscx->setWindingType( osgUtil::Tessellator::TESS_WINDING_ODD); // commonest tesselation - ODD.
tscx->retessellatePolygons(*geom);
} else if (geode.getName()== "tesselate odd bound") {
tscx->setBoundaryOnly(true);
tscx->setWindingType( osgUtil::Tesselator::TESS_WINDING_ODD); // tesselation - ODD, only show boundary.
tscx->retesselatePolygons(*geom);
tscx->setWindingType( osgUtil::Tessellator::TESS_WINDING_ODD); // tesselation - ODD, only show boundary.
tscx->retessellatePolygons(*geom);
} else if (geode.getName()== "tesselate positive") {
tscx->setWindingType( osgUtil::Tesselator::TESS_WINDING_POSITIVE); // tesselation - pos.
tscx->retesselatePolygons(*geom);
tscx->setWindingType( osgUtil::Tessellator::TESS_WINDING_POSITIVE); // tesselation - pos.
tscx->retessellatePolygons(*geom);
} else if (geode.getName()== "tesselate positive bound") {
tscx->setBoundaryOnly(true);
tscx->setWindingType( osgUtil::Tesselator::TESS_WINDING_POSITIVE);
tscx->retesselatePolygons(*geom);
tscx->setWindingType( osgUtil::Tessellator::TESS_WINDING_POSITIVE);
tscx->retessellatePolygons(*geom);
} else if (geode.getName()== "tesselate negative") {
tscx->setWindingType( osgUtil::Tesselator::TESS_WINDING_NEGATIVE);
tscx->retesselatePolygons(*geom);
tscx->setWindingType( osgUtil::Tessellator::TESS_WINDING_NEGATIVE);
tscx->retessellatePolygons(*geom);
} else if (geode.getName()== "tesselate negative bound") {
tscx->setBoundaryOnly(true);
tscx->setWindingType( osgUtil::Tesselator::TESS_WINDING_NEGATIVE);
tscx->retesselatePolygons(*geom);
tscx->setWindingType( osgUtil::Tessellator::TESS_WINDING_NEGATIVE);
tscx->retessellatePolygons(*geom);
} else if (geode.getName()== "tesselate nonzero") {
tscx->setWindingType( osgUtil::Tesselator::TESS_WINDING_NONZERO);
tscx->retesselatePolygons(*geom);
tscx->setWindingType( osgUtil::Tessellator::TESS_WINDING_NONZERO);
tscx->retessellatePolygons(*geom);
} else if (geode.getName()== "tesselate nonzero bound") {
tscx->setBoundaryOnly(true);
tscx->setWindingType( osgUtil::Tesselator::TESS_WINDING_NONZERO);
tscx->retesselatePolygons(*geom);
tscx->setWindingType( osgUtil::Tessellator::TESS_WINDING_NONZERO);
tscx->retessellatePolygons(*geom);
} else if (geode.getName()== "tesselate geq2") {
tscx->setWindingType( osgUtil::Tesselator::TESS_WINDING_ABS_GEQ_TWO);
tscx->retesselatePolygons(*geom);
tscx->setWindingType( osgUtil::Tessellator::TESS_WINDING_ABS_GEQ_TWO);
tscx->retessellatePolygons(*geom);
} else if (geode.getName()== "tesselate geq2 bound") {
tscx->setBoundaryOnly(true);
tscx->setWindingType( osgUtil::Tesselator::TESS_WINDING_ABS_GEQ_TWO);
tscx->retesselatePolygons(*geom);
tscx->setWindingType( osgUtil::Tessellator::TESS_WINDING_ABS_GEQ_TWO);
tscx->retessellatePolygons(*geom);
}
}
}
@@ -630,8 +630,8 @@ public:
class cxTesselateVisitor : public osg::NodeVisitor
{ // special to this demo, traverses SG and finds nodes which have been tesselated
// for test/demo purposes these nodes are of type tesselateDemoGeometry
// but you could store the Tesselator as UserData or however you like.
// the tesselator holds copies of the original contours used in the tesselation
// but you could store the Tessellator as UserData or however you like.
// the Tessellator holds copies of the original contours used in the tesselation
// In this visitor, I reuse the contours to make a different type of tesselation.
public:
@@ -650,44 +650,44 @@ public:
} else { // change to next type of tesselation...
geom->setBoundaryOnly(false);
switch (geom->getWindingType()) {
case osgUtil::Tesselator::TESS_WINDING_ODD:
geom->setWindingType(osgUtil::Tesselator::TESS_WINDING_NONZERO);
case osgUtil::Tessellator::TESS_WINDING_ODD:
geom->setWindingType(osgUtil::Tessellator::TESS_WINDING_NONZERO);
break;
case osgUtil::Tesselator::TESS_WINDING_NONZERO:
geom->setWindingType( osgUtil::Tesselator::TESS_WINDING_POSITIVE);
case osgUtil::Tessellator::TESS_WINDING_NONZERO:
geom->setWindingType( osgUtil::Tessellator::TESS_WINDING_POSITIVE);
break;
case osgUtil::Tesselator::TESS_WINDING_POSITIVE:
geom->setWindingType( osgUtil::Tesselator::TESS_WINDING_NEGATIVE);
case osgUtil::Tessellator::TESS_WINDING_POSITIVE:
geom->setWindingType( osgUtil::Tessellator::TESS_WINDING_NEGATIVE);
break;
case osgUtil::Tesselator::TESS_WINDING_NEGATIVE:
geom->setWindingType( osgUtil::Tesselator::TESS_WINDING_ABS_GEQ_TWO);
case osgUtil::Tessellator::TESS_WINDING_NEGATIVE:
geom->setWindingType( osgUtil::Tessellator::TESS_WINDING_ABS_GEQ_TWO);
break;
case osgUtil::Tesselator::TESS_WINDING_ABS_GEQ_TWO:
geom->setWindingType( osgUtil::Tesselator::TESS_WINDING_ODD);
case osgUtil::Tessellator::TESS_WINDING_ABS_GEQ_TWO:
geom->setWindingType( osgUtil::Tessellator::TESS_WINDING_ODD);
break;
}
}
switch (geom->getWindingType()) { // a text to be added to the scene.
case osgUtil::Tesselator::TESS_WINDING_ODD:
case osgUtil::Tessellator::TESS_WINDING_ODD:
str="TESS_WINDING_ODD";
break;
case osgUtil::Tesselator::TESS_WINDING_NONZERO:
case osgUtil::Tessellator::TESS_WINDING_NONZERO:
str="TESS_WINDING_NONZERO";
break;
case osgUtil::Tesselator::TESS_WINDING_POSITIVE:
case osgUtil::Tessellator::TESS_WINDING_POSITIVE:
str="TESS_WINDING_POSITIVE";
break;
case osgUtil::Tesselator::TESS_WINDING_NEGATIVE:
case osgUtil::Tessellator::TESS_WINDING_NEGATIVE:
str="TESS_WINDING_NEGATIVE";
break;
case osgUtil::Tesselator::TESS_WINDING_ABS_GEQ_TWO:
case osgUtil::Tessellator::TESS_WINDING_ABS_GEQ_TWO:
str="TESS_WINDING_ABS_GEQ_TWO";
break;
}
if (geom->getBoundaryOnly()) str += " Boundary";
geom->retesselatePolygons(*geom);
geom->retessellatePolygons(*geom);
}
osgText::Text* txt = dynamic_cast<osgText::Text*>(geode.getDrawable(i));
if (txt) {