Show
Ignore:
Timestamp:
01/08/07 22:19:33 (7 years ago)
Author:
robert
Message:

Tessellator name changes

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • OpenSceneGraph/trunk/examples/osgtessellate/osgtessellate.cpp

    r5928 r5939  
    1111 
    1212/* osgTessellator 
    13  * - this Tessellator is an extension of the basic one - rather than tesselating 
    14  * individual polygons, we tesselate the entire geode with multiple contours. 
     13 * - this Tessellator is an extension of the basic one - rather than tessellating 
     14 * individual polygons, we tessellate the entire geode with multiple contours. 
    1515 * allows for overlapping contours etc. 
    1616 * the Tessellator has new member fuinctions 
     
    2929#include <osgText/Text> 
    3030 
    31 #include <osgUtil/Tessellator> // to tesselate multiple contours 
    32  
    33  
    34 class tesselateDemoGeometry : public osg::Geometry, public osgUtil::Tessellator { 
     31#include <osgUtil/Tessellator> // to tessellate multiple contours 
     32 
     33 
     34class tessellateDemoGeometry : public osg::Geometry, public osgUtil::Tessellator { 
    3535    // We add the Tessellator to the geometry because we want to access the 
    36     // tesselatable contours again;  you can apply a Tessellator to a Geometry  
    37     // to produce exactly a required tesselation once only, and then  
    38     // the contours could be discarded since the geometry does not need to be retesselated. 
     36    // tessellatable contours again;  you can apply a Tessellator to a Geometry  
     37    // to produce exactly a required tessellation once only, and then  
     38    // the contours could be discarded since the geometry does not need to be retessellated. 
    3939public: 
    40     tesselateDemoGeometry() {}; 
     40    tessellateDemoGeometry() {}; 
    4141 
    4242protected: 
    43     virtual ~tesselateDemoGeometry() {}; 
     43    virtual ~tessellateDemoGeometry() {}; 
    4444}; 
    4545 
    4646osg::Geometry *makePolsTwo (void)  
    4747{ 
    48     // an example of using current geometry contours to create next tesselation 
     48    // an example of using current geometry contours to create next tessellation 
    4949    // this polygon disappears once the contour rules make no polygons. 
    50     tesselateDemoGeometry *gtess= new tesselateDemoGeometry; 
     50    tessellateDemoGeometry *gtess= new tessellateDemoGeometry; 
    5151    int i; 
    5252    osg::Vec3Array *coords = new osg::Vec3Array; 
     
    9090    gtess->setTexCoordArray(0,tcs); 
    9191     
    92     // demonstrate that the Tessellator makes textured tesselations 
     92    // demonstrate that the Tessellator makes textured tessellations 
    9393    osg::StateSet* stateset = new osg::StateSet(); 
    9494     
     
    105105     
    106106    int nstart=0; 
    107     // The derived class tesselateDemoGeometry retains the original contours for re-use. 
     107    // The derived class tessellateDemoGeometry retains the original contours for re-use. 
    108108    gtess->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::TRIANGLE_STRIP,nstart,8));nstart+=8; 
    109109    gtess->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::TRIANGLE_STRIP,nstart,8));nstart+=8; 
     
    111111    gtess->setTessellationType(osgUtil::Tessellator::TESS_TYPE_GEOMETRY); 
    112112    gtess->setBoundaryOnly(true); 
    113     gtess->setWindingType( osgUtil::Tessellator::TESS_WINDING_ABS_GEQ_TWO); // so that first change in wind type makes the commonest tesselation - ODD. 
     113    gtess->setWindingType( osgUtil::Tessellator::TESS_WINDING_ABS_GEQ_TWO); // so that first change in wind type makes the commonest tessellation - ODD. 
    114114     
    115115    return gtess; 
     
    162162    gtess->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::POLYGON,nstart,5));nstart+=5; 
    163163     
    164     // demonstrate that the Tessellator makes textured tesselations 
     164    // demonstrate that the Tessellator makes textured tessellations 
    165165    osg::StateSet* stateset = new osg::StateSet(); 
    166166     
     
    178178 
    179179    osg::ref_ptr<osgUtil::Tessellator> tscx=new osgUtil::Tessellator; // the v1.2 multi-contour Tessellator. 
    180     // we use the geometry primitives to describe the contours which are tesselated. 
     180    // we use the geometry primitives to describe the contours which are tessellated. 
    181181    // Winding odd means leave hole in surface where there are 2,4,6... contours circling the point. 
    182182    tscx->setTessellationType(osgUtil::Tessellator::TESS_TYPE_GEOMETRY); 
    183183    tscx->setBoundaryOnly(false); 
    184     tscx->setWindingType( osgUtil::Tessellator::TESS_WINDING_ODD); // so that first change in wind type makes the commonest tesselation - ODD. 
     184    tscx->setWindingType( osgUtil::Tessellator::TESS_WINDING_ODD); // so that first change in wind type makes the commonest tessellation - ODD. 
    185185     
    186186    tscx->retessellatePolygons(*gtess); 
     
    190190 
    191191osg::Geometry *makeFrontWall (const float zpos) { 
    192     // an example of using one tesselation to make a 'house' wall 
     192    // an example of using one tessellation to make a 'house' wall 
    193193    // describe the wall as a pentagon, then door & 4 windows are further contours 
    194     // tesselate the set of contours to make a 'house wall' from the Boolean-like operations. 
     194    // tessellate the set of contours to make a 'house wall' from the Boolean-like operations. 
    195195    int nstart=0; // counts vertices used for the geometry primitives 
    196196 
     
    259259    gtess->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::QUADS,nstart,20));nstart+=20; 
    260260 
    261     // demonstrate that the Tessellator makes textured tesselations 
     261    // demonstrate that the Tessellator makes textured tessellations 
    262262    osg::StateSet* stateset = new osg::StateSet(); 
    263263     
     
    273273    gtess->setStateSet( stateset ); 
    274274     
    275     // We use a Tessellator to produce the tesselation required once only  
     275    // We use a Tessellator to produce the tessellation required once only  
    276276    // and the contours are discarded. 
    277277    osg::ref_ptr<osgUtil::Tessellator> tscx=new osgUtil::Tessellator; // the v1.2 multi-contour Tessellator. 
    278278    tscx->setTessellationType(osgUtil::Tessellator::TESS_TYPE_GEOMETRY); 
    279279    tscx->setBoundaryOnly(false); 
    280     tscx->setWindingType( osgUtil::Tessellator::TESS_WINDING_ODD); // so that first change in wind type makes the commonest tesselation - ODD. 
     280    tscx->setWindingType( osgUtil::Tessellator::TESS_WINDING_ODD); // so that first change in wind type makes the commonest tessellation - ODD. 
    281281     
    282282    tscx->retessellatePolygons(*gtess); 
     
    293293} 
    294294osg::Geometry *makePols (void) { 
    295     tesselateDemoGeometry *gtess= new tesselateDemoGeometry; 
     295    tessellateDemoGeometry *gtess= new tessellateDemoGeometry; 
    296296    int i; 
    297297    osg::Vec3Array *coords = new osg::Vec3Array; 
     
    453453    gtess->setTexCoordArray(0,tcs); 
    454454     
    455     // demonstrate that the Tessellator makes textured tesselations 
     455    // demonstrate that the Tessellator makes textured tessellations 
    456456    osg::StateSet* stateset = new osg::StateSet(); 
    457457     
     
    483483    gtess->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::TRIANGLE_STRIP,nstart,8));nstart+=8; 
    484484     
    485     // We need to access the tesselatable contours again to demonstrate all types of tesselation. 
     485    // We need to access the tessellatable contours again to demonstrate all types of tessellation. 
    486486    // I could add the Tessellator to the geometry as userdata, but here 
    487     // I use the derived tesselateDemoGeometry to hold both the drawable geode and the original contours. 
     487    // I use the derived tessellateDemoGeometry to hold both the drawable geode and the original contours. 
    488488     
    489489    gtess->setTessellationType(osgUtil::Tessellator::TESS_TYPE_GEOMETRY); 
    490490    gtess->setBoundaryOnly(true); 
    491     gtess->setWindingType( osgUtil::Tessellator::TESS_WINDING_ABS_GEQ_TWO); // so that first change in wind type makes the commonest tesselation - ODD. 
     491    gtess->setWindingType( osgUtil::Tessellator::TESS_WINDING_ABS_GEQ_TWO); // so that first change in wind type makes the commonest tessellation - ODD. 
    492492     
    493493    return gtess; 
    494494} 
    495495osg::Node* createHUD() 
    496 { // add a string reporting the type of winding rule tesselation applied 
     496{ // add a string reporting the type of winding rule tessellation applied 
    497497    osg::Geode* geode = new osg::Geode(); 
    498498     
     
    517517        text->setFont(timesFont); 
    518518        text->setPosition(position); 
    519         text->setText("Tesselation example - no tesselation (use 'W' wireframe to visualise)"); 
     519        text->setText("Tessellation example - no tessellation (use 'W' wireframe to visualise)"); 
    520520        text->setColor(osg::Vec4(1.0,1.0,0.8,1.0)); 
    521521        position += delta; 
     
    528528        text->setFont(timesFont); 
    529529        text->setPosition(position); 
    530         text->setText("Press 'n' to use an alternative tesselation."); 
     530        text->setText("Press 'n' to use an alternative tessellation."); 
    531531         
    532532    }     
     
    547547 
    548548 
    549 osg::Group *makeTesselateExample (void) { 
     549osg::Group *makeTessellateExample (void) { 
    550550    osg::Group *grp=new osg::Group; 
    551551    osg::Geode *gd=new osg::Geode; 
     
    559559} 
    560560 
    561 class setTesselateVisitor : public osg::NodeVisitor 
    562 { // searches a loaded model tree for tesselatable geometries. 
    563     // used with any database model which has a renderGroup (Geode) named 'tesselate' 
     561class setTessellateVisitor : public osg::NodeVisitor 
     562{ // searches a loaded model tree for tessellatable geometries. 
     563    // used with any database model which has a renderGroup (Geode) named 'tessellate' 
    564564    // or you can force a type of tess with special names or a sub-class of Geode could have extra information 
    565     // of course you can use any name to detect what is to be tesselated! 
     565    // of course you can use any name to detect what is to be tessellated! 
    566566    // all the polygons within the specific node are deemed to be contours, so 
    567     // any tesselation can be requested. 
     567    // any tessellation can be requested. 
    568568public: 
    569569     
    570     setTesselateVisitor():osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN) { 
     570    setTessellateVisitor():osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN) { 
    571571    } 
    572572    virtual void apply(osg::Geode& geode) { 
    573         if (geode.getName().compare(0,9,"tesselate")==0) { 
     573        if (geode.getName().compare(0,9,"tessellate")==0) { 
    574574            for(unsigned int i=0;i<geode.getNumDrawables();++i) 
    575575            { 
     
    579579                    if (tscx.valid()) { 
    580580                        tscx->setTessellationType(osgUtil::Tessellator::TESS_TYPE_GEOMETRY); 
    581                         if (geode.getName()== "tesselate") { 
    582                             // add a Tessellator so that this geom is retesselated when N is pressed 
     581                        if (geode.getName()== "tessellate") { 
     582                            // add a Tessellator so that this geom is retessellated when N is pressed 
    583583                            tscx->setBoundaryOnly(true); 
    584                             tscx->setWindingType( osgUtil::Tessellator::TESS_WINDING_ABS_GEQ_TWO); // so that first change in wind type makes the commonest tesselation - ODD. 
     584                            tscx->setWindingType( osgUtil::Tessellator::TESS_WINDING_ABS_GEQ_TWO); // so that first change in wind type makes the commonest tessellation - ODD. 
    585585                            geom->setUserData(tscx.get()); 
    586                         } else if (geode.getName()== "tesselate odd") { 
     586                        } else if (geode.getName()== "tessellate odd") { 
    587587                            // OR you can just apply the Tessellator once only, using these different types 
    588                             tscx->setWindingType( osgUtil::Tessellator::TESS_WINDING_ODD); // commonest tesselation - ODD. 
    589                             tscx->retessellatePolygons(*geom); 
    590                         } else if (geode.getName()== "tesselate odd bound") { 
     588                            tscx->setWindingType( osgUtil::Tessellator::TESS_WINDING_ODD); // commonest tessellation - ODD. 
     589                            tscx->retessellatePolygons(*geom); 
     590                        } else if (geode.getName()== "tessellate odd bound") { 
    591591                            tscx->setBoundaryOnly(true); 
    592                             tscx->setWindingType( osgUtil::Tessellator::TESS_WINDING_ODD); // tesselation - ODD, only show boundary. 
    593                             tscx->retessellatePolygons(*geom); 
    594                         } else if (geode.getName()== "tesselate positive") { 
    595                             tscx->setWindingType( osgUtil::Tessellator::TESS_WINDING_POSITIVE); // tesselation - pos. 
    596                             tscx->retessellatePolygons(*geom); 
    597                         } else if (geode.getName()== "tesselate positive bound") { 
     592                            tscx->setWindingType( osgUtil::Tessellator::TESS_WINDING_ODD); // tessellation - ODD, only show boundary. 
     593                            tscx->retessellatePolygons(*geom); 
     594                        } else if (geode.getName()== "tessellate positive") { 
     595                            tscx->setWindingType( osgUtil::Tessellator::TESS_WINDING_POSITIVE); // tessellation - pos. 
     596                            tscx->retessellatePolygons(*geom); 
     597                        } else if (geode.getName()== "tessellate positive bound") { 
    598598                            tscx->setBoundaryOnly(true); 
    599599                            tscx->setWindingType( osgUtil::Tessellator::TESS_WINDING_POSITIVE); 
    600600                            tscx->retessellatePolygons(*geom); 
    601                         } else if (geode.getName()== "tesselate negative") { 
     601                        } else if (geode.getName()== "tessellate negative") { 
    602602                            tscx->setWindingType( osgUtil::Tessellator::TESS_WINDING_NEGATIVE); 
    603603                            tscx->retessellatePolygons(*geom); 
    604                         } else if (geode.getName()== "tesselate negative bound") { 
     604                        } else if (geode.getName()== "tessellate negative bound") { 
    605605                            tscx->setBoundaryOnly(true); 
    606606                            tscx->setWindingType( osgUtil::Tessellator::TESS_WINDING_NEGATIVE); 
    607607                            tscx->retessellatePolygons(*geom); 
    608                         } else if (geode.getName()== "tesselate nonzero") { 
     608                        } else if (geode.getName()== "tessellate nonzero") { 
    609609                            tscx->setWindingType( osgUtil::Tessellator::TESS_WINDING_NONZERO); 
    610610                            tscx->retessellatePolygons(*geom); 
    611                         } else if (geode.getName()== "tesselate nonzero bound") { 
     611                        } else if (geode.getName()== "tessellate nonzero bound") { 
    612612                            tscx->setBoundaryOnly(true); 
    613613                            tscx->setWindingType( osgUtil::Tessellator::TESS_WINDING_NONZERO); 
    614614                            tscx->retessellatePolygons(*geom); 
    615                         } else if (geode.getName()== "tesselate geq2") { 
     615                        } else if (geode.getName()== "tessellate geq2") { 
    616616                            tscx->setWindingType( osgUtil::Tessellator::TESS_WINDING_ABS_GEQ_TWO); 
    617617                            tscx->retessellatePolygons(*geom); 
    618                         } else if (geode.getName()== "tesselate geq2 bound") { 
     618                        } else if (geode.getName()== "tessellate geq2 bound") { 
    619619                            tscx->setBoundaryOnly(true); 
    620620                            tscx->setWindingType( osgUtil::Tessellator::TESS_WINDING_ABS_GEQ_TWO); 
     
    628628}; 
    629629 
    630 class cxTesselateVisitor : public osg::NodeVisitor 
    631 { // special to this demo, traverses SG and finds nodes which have been tesselated 
    632     // for test/demo purposes these nodes are of type tesselateDemoGeometry 
     630class cxTessellateVisitor : public osg::NodeVisitor 
     631{ // special to this demo, traverses SG and finds nodes which have been tessellated 
     632    // for test/demo purposes these nodes are of type tessellateDemoGeometry 
    633633    // but you could store the Tessellator as UserData or however you like. 
    634     // the Tessellator holds copies of the original contours used in the tesselation 
    635     // In this visitor, I reuse the contours to make a different type of tesselation. 
     634    // the Tessellator holds copies of the original contours used in the tessellation 
     635    // In this visitor, I reuse the contours to make a different type of tessellation. 
    636636public: 
    637637     
    638     cxTesselateVisitor():osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN) { 
     638    cxTessellateVisitor():osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN) { 
    639639    } 
    640640    virtual void apply(osg::Geode& geode) { 
     
    642642        for(unsigned int i=0;i<geode.getNumDrawables();++i) 
    643643        { 
    644             tesselateDemoGeometry *geom=dynamic_cast<tesselateDemoGeometry*>(geode.getDrawable(i)); 
     644            tessellateDemoGeometry *geom=dynamic_cast<tessellateDemoGeometry*>(geode.getDrawable(i)); 
    645645            if (geom) { 
    646646                if (!geom->getBoundaryOnly()) { // turn on bounds only 
     
    648648                    geom->setBoundaryOnly(true); 
    649649                     
    650                 } else { // change to next type of tesselation... 
     650                } else { // change to next type of tessellation... 
    651651                    geom->setBoundaryOnly(false); 
    652652                    switch (geom->getWindingType()) { 
     
    705705 
    706706class KeyboardEventHandler : public osgGA::GUIEventHandler 
    707 { // extra event handler traps 'n' key to re-tesselate any tesselated geodes. 
     707{ // extra event handler traps 'n' key to re-tessellate any tessellated geodes. 
    708708public: 
    709709     
     
    719719                    if (_scene && ea.getKey()=='n') 
    720720                    { 
    721                         // re-tesselate the scene graph.  
    722                         // the same contours are re-tesselated using a new method. Old contours  
    723                         // & tesselation type are held internally in the derived Geode class tesselateDemoGeometry. 
    724                         cxTesselateVisitor tsv; 
     721                        // re-tessellate the scene graph.  
     722                        // the same contours are re-tessellated using a new method. Old contours  
     723                        // & tessellation type are held internally in the derived Geode class tessellateDemoGeometry. 
     724                        cxTessellateVisitor tsv; 
    725725                        _scene->accept(tsv); 
    726726                       return true; 
     
    784784    if (!loadedModel)  
    785785    { 
    786         loadedModel=makeTesselateExample(); 
     786        loadedModel=makeTessellateExample(); 
    787787    } else { // if there is a loaded model: 
    788         // tesselate by searching for geode called tesselate & tesselate it 
    789         setTesselateVisitor tsv; 
     788        // tessellate by searching for geode called tessellate & tessellate it 
     789        setTessellateVisitor tsv; 
    790790        loadedModel->accept(tsv); 
    791791    } 
     
    816816    viewer.setSceneData(loadedModel.get()); 
    817817 
    818     // add event handler for keyboard 'n' to retesselate 
     818    // add event handler for keyboard 'n' to retessellate 
    819819    viewer.getEventHandlerList().push_front(new KeyboardEventHandler(loadedModel.get())); 
    820820