osgEarth 2.1.1
Classes | Typedefs | Functions

/home/cube/sources/osgearth/src/applications/osgearth_symbology/osgearth_symbology.cpp File Reference

#include <sstream>
#include <osg/Notify>
#include <osgGA/StateSetManipulator>
#include <osgGA/GUIEventHandler>
#include <osgGA/TrackballManipulator>
#include <osgDB/FileNameUtils>
#include <osgViewer/Viewer>
#include <osgViewer/ViewerEventHandlers>
#include <osgDB/ReadFile>
#include <osgEarthSymbology/GeometryExtrudeSymbolizer>
#include <osgEarthSymbology/GeometrySymbolizer>
#include <osgEarthSymbology/Style>
#include <osgEarthSymbology/SymbolicNode>
#include <osgEarthSymbology/MarkerSymbol>
#include <osgEarthSymbology/MarkerSymbolizer>
#include <osgEarthSymbology/ExtrudedSymbol>
#include <osgEarthSymbology/ModelSymbolizer>
#include <osgEarthUtil/Popups>
#include <osg/MatrixTransform>
#include <osg/Geometry>
#include <osgUtil/Tessellator>
#include <osg/LineWidth>
#include <osg/Point>
#include <osg/Material>
Include dependency graph for osgearth_symbology.cpp:

Go to the source code of this file.

Classes

struct  SampleGeometryInput
struct  PopUpSymbolizerContext
struct  PopUpSymbolizer
struct  PolygonPointSizeSymbol
struct  GeometryPointSymbolizer
class  StyleEditor

Typedefs

typedef SymbolicNode< State
< GeometryContent > > 
GeometrySymbolicNode

Functions

static double getRandomValueInOne ()
GeometrycreateLineGeometry (const osg::Vec3d &start)
GeometrycreateRingGeometry (const osg::Vec3d &start)
GeometrycreatePolygonGeometry (const osg::Vec3d &start)
GeometrycreatePointsGeometry (const osg::Vec3d &start)
osg::Group * createSymbologyScene (PopupManager *wm)
int main (int argc, char **argv)

Typedef Documentation

typedef SymbolicNode< State<GeometryContent> > GeometrySymbolicNode

Definition at line 469 of file osgearth_symbology.cpp.


Function Documentation

Geometry* createLineGeometry ( const osg::Vec3d &  start)

Definition at line 59 of file osgearth_symbology.cpp.

{
    osg::ref_ptr<osg::Vec3dArray> array = new osg::Vec3dArray;
    array->push_back(start + osg::Vec3d(-100,-100,0));
    array->push_back(start + osg::Vec3d(100,-100,0));
    array->push_back(start + osg::Vec3d(100,100,0));
    array->push_back(start + osg::Vec3d(-100,100,0));
    return Geometry::create(Geometry::TYPE_LINESTRING, array);
}

Here is the call graph for this function:

Here is the caller graph for this function:

Geometry* createPointsGeometry ( const osg::Vec3d &  start)

Definition at line 92 of file osgearth_symbology.cpp.

{
    osg::ref_ptr<osg::Vec3dArray> array = new osg::Vec3dArray;
    array->push_back(start + osg::Vec3d(-100,-100,0));
    array->push_back(start + osg::Vec3d(100,-100,0));
    array->push_back(start + osg::Vec3d(100,100,0));
    array->push_back(start + osg::Vec3d(-100,100,0));
    return Geometry::create(Geometry::TYPE_POINTSET, array);
}

Here is the call graph for this function:

Here is the caller graph for this function:

Geometry* createPolygonGeometry ( const osg::Vec3d &  start)

Definition at line 80 of file osgearth_symbology.cpp.

{
    osg::ref_ptr<osg::Vec3dArray> array = new osg::Vec3dArray;
    array->push_back(start + osg::Vec3d(-100,-100,0));
    array->push_back(start + osg::Vec3d(-10,-10,0));
    array->push_back(start + osg::Vec3d(100,-100,0));
    array->push_back(start + osg::Vec3d(100,100,0));
    array->push_back(start + osg::Vec3d(-100,100,0));
    return Geometry::create(Geometry::TYPE_POLYGON, array);
}

Here is the call graph for this function:

Here is the caller graph for this function:

Geometry* createRingGeometry ( const osg::Vec3d &  start)

Definition at line 69 of file osgearth_symbology.cpp.

{
    osg::ref_ptr<osg::Vec3dArray> array = new osg::Vec3dArray;
    array->push_back(start + osg::Vec3d(-100,-100,0));
    array->push_back(start + osg::Vec3d(100,-100,0));
    array->push_back(start + osg::Vec3d(100,100,0));
    array->push_back(start + osg::Vec3d(-100,100,0));
    return Geometry::create(Geometry::TYPE_RING, array);
}

Here is the call graph for this function:

Here is the caller graph for this function:

osg::Group* createSymbologyScene ( PopupManager *  wm)

associate the style / symbolizer to the symbolic node

Definition at line 472 of file osgearth_symbology.cpp.

{
    osg::Group* grp = new osg::Group;

    osg::ref_ptr<SampleGeometryInput> dataset = new SampleGeometryInput;
    StyleList styles;

    {
        osg::ref_ptr<Style> style = new Style;
        style->setName("PolygonSymbol-color");
        osg::ref_ptr<PolygonSymbol> polySymbol = new PolygonSymbol;
        polySymbol->fill()->color() = osg::Vec4(0,1,1,1);
        style->addSymbol(polySymbol.get());
        styles.push_back(style.get());
    }

    {
        osg::ref_ptr<Style> style = new Style;
        style->setName("Custom-PolygonPointSizeSymbol-size&color");
        osg::ref_ptr<PolygonPointSizeSymbol> polySymbol = new PolygonPointSizeSymbol;
        polySymbol->fill()->color() = osg::Vec4(1,0,0,1);
        polySymbol->size() = 2.0;
        style->addSymbol(polySymbol.get());
        styles.push_back(style.get());
    }


    // style for extruded
    {
        osg::ref_ptr<Style> style = new Style;
        style->setName("Extrude-Polygon&Line-height&color");
        osg::ref_ptr<ExtrudedPolygonSymbol> polySymbol = new ExtrudedPolygonSymbol;
        polySymbol->fill()->color() = osg::Vec4(1,0,0,1);
        polySymbol->extrude()->height() = 100;
        polySymbol->extrude()->offset() = 10;
        style->addSymbol(polySymbol.get());

        osg::ref_ptr<ExtrudedLineSymbol> lineSymbol = new ExtrudedLineSymbol;
        lineSymbol->stroke()->color() = osg::Vec4(0,0,1,1);
        lineSymbol->extrude()->height() = 150;
        lineSymbol->extrude()->offset() = 10;
        style->addSymbol(lineSymbol.get());
        styles.push_back(style.get());
    }


    // style for marker
    {
        osg::ref_ptr<Style> style = new Style;
        style->setName("Marker");
        osg::ref_ptr<MarkerSymbol> pointSymbol = new MarkerSymbol;
        pointSymbol->marker() = "../data/tree.ive";
        style->addSymbol(pointSymbol.get());

        osg::ref_ptr<MarkerLineSymbol> lineSymbol = new MarkerLineSymbol;
        lineSymbol->marker() = "../data/tree.ive";
        lineSymbol->interval() = 5;
        style->addSymbol(lineSymbol.get());

        osg::ref_ptr<MarkerPolygonSymbol> polySymbol = new MarkerPolygonSymbol;
        polySymbol->marker() = "../data/tree.ive";
        polySymbol->interval() = 20;
        polySymbol->randomRatio() = 1.0;
        style->addSymbol(polySymbol.get());

        styles.push_back(style.get());
    }


    // style for popup
    {
        osg::ref_ptr<Style> style = new Style;
        style->setName("Popup");
        osg::ref_ptr<TextSymbol> symbol = new TextSymbol;
        //symbol->theme() = "../data/popup-theme.png";
        symbol->font() = "arial.ttf";
        symbol->size() = 14;
        symbol->fill()->color() = osg::Vec4(getRandomValueInOne(), getRandomValueInOne() , getRandomValueInOne(), 0.7);
        style->addSymbol(symbol.get());
        styles.push_back(style.get());
    }


    {
        GeometrySymbolicNode* node = new GeometrySymbolicNode();
        node->setSymbolizer( new GeometrySymbolizer() );

        node->getState()->setStyle( styles[0].get() );
        node->getState()->setContent( dataset.get() );

        osg::MatrixTransform* tr = new osg::MatrixTransform;
        tr->setMatrix(osg::Matrix::translate(0, -250 , 0));
        tr->addChild(node);
        grp->addChild(tr);
    }


    {
        GeometrySymbolicNode* node = new GeometrySymbolicNode();
        node->setSymbolizer( new GeometryPointSymbolizer() );
        node->getState()->setStyle(styles[1].get());
        node->getState()->setContent(dataset.get());
        osg::MatrixTransform* tr = new osg::MatrixTransform;
        tr->addChild(node);
        tr->setMatrix(osg::Matrix::translate(0, 0 , 0));
        grp->addChild(tr);
    }


    {
        GeometrySymbolicNode* node = new GeometrySymbolicNode();
        node->setSymbolizer( new GeometryExtrudeSymbolizer() );
        node->getState()->setStyle(styles[2].get());
        node->getState()->setContent(dataset.get());
        osg::MatrixTransform* tr = new osg::MatrixTransform;
        tr->addChild(node);
        tr->setMatrix(osg::Matrix::translate(0, 250 , 0));
        grp->addChild(tr);
    }


    {
        GeometrySymbolicNode* node = new GeometrySymbolicNode();
        node->setSymbolizer( new MarkerSymbolizer() );
        node->getState()->setStyle(styles[3].get());
        node->getState()->setContent(dataset.get());
        osg::MatrixTransform* tr = new osg::MatrixTransform;
        tr->addChild(node);
        tr->setMatrix(osg::Matrix::translate(0, 500 , 0));
        grp->addChild(tr);
    }



    //{
    //    osg::ref_ptr<ModelSymbolizer> symbolizer = new ModelSymbolizer();
    //    osg::ref_ptr<SymbolicNode> node = new SymbolicNode;
    //    node->setSymbolizer(symbolizer.get());
    //    Style* style = new Style;
    //    std::string real = osgDB::getRealPath("../data/tree.ive");
    //    MarkerSymbol* marker = new MarkerSymbol;
    //    marker->marker() = real;
    //    node->setDataSet(dataset.get());
    //    style->addSymbol(marker);
    //    node->setStyle(style);
    //    osg::MatrixTransform* tr = new osg::MatrixTransform;
    //    tr->addChild(node);
    //    tr->setMatrix(osg::Matrix::scale(10,10,10) * osg::Matrix::translate(0, 750 , 0));
    //    grp->addChild(tr);
    //}

    StyleEditor* styleEditor = new StyleEditor(styles);
    {
        PopUpSymbolizerContext* ctx = new PopUpSymbolizerContext(wm);
        styleEditor->setPopupContext(ctx);

        SymbolicNode< State<GeometryContent> >* node = new SymbolicNode< State<GeometryContent> >();
        node->setSymbolizer( new PopUpSymbolizer() );
        node->getState()->setStyle(styles[4]);
        node->getState()->setContent(dataset.get());
        node->getState()->setContext(ctx);
        osg::MatrixTransform* tr = new osg::MatrixTransform;
        tr->addChild(node);
        tr->setMatrix(osg::Matrix::translate(0, 1000 , 0));
        grp->addChild(tr);
    }
    
    grp->addEventCallback(styleEditor);
    return grp;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static double getRandomValueInOne ( ) [static]

Definition at line 53 of file osgearth_symbology.cpp.

{
    return ((rand() * 1.0)/(RAND_MAX-1));
}

Here is the caller graph for this function:

int main ( int  argc,
char **  argv 
)

Definition at line 647 of file osgearth_symbology.cpp.

{
    osg::ArgumentParser arguments(&argc,argv);

    osgViewer::Viewer viewer(arguments);

    // add some stock OSG handlers:
    viewer.setCameraManipulator(new osgGA::TrackballManipulator());
    viewer.addEventHandler(new osgViewer::StatsHandler());
    viewer.addEventHandler(new osgViewer::WindowSizeHandler());
    viewer.addEventHandler(new osgGA::StateSetManipulator(viewer.getCamera()->getOrCreateStateSet()));
    
    osg::Group* root = new osg::Group;
    viewer.setSceneData(root);
    viewer.realize();

    PopupManager* wm = new PopupManager(&viewer);
    osg::Node* node = createSymbologyScene(wm);
    root->addChild(node);
    return viewer.run();
}

Here is the call graph for this function:

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines