osgEarth 2.1.1
Classes | Functions | Variables

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

#include <osg/Notify>
#include <osgGA/StateSetManipulator>
#include <osgViewer/Viewer>
#include <osgViewer/ViewerEventHandlers>
#include <osgGA/GUIEventHandler>
#include <osgEarth/Map>
#include <osgEarth/MapNode>
#include <osgEarthUtil/EarthManipulator>
#include <osgEarthUtil/AutoClipPlaneHandler>
#include <osgEarth/Utils>
#include <osgEarthSymbology/Style>
#include <osgEarthFeatures/FeatureModelGraph>
#include <osgEarthFeatures/FeatureListSource>
#include <osgEarthFeatures/GeometryCompiler>
#include <osgEarthDrivers/gdal/GDALOptions>
#include <osgEarthDrivers/feature_ogr/OGRFeatureOptions>
#include <osgEarthDrivers/agglite/AGGLiteOptions>
#include <osgEarthDrivers/model_feature_geom/FeatureGeomModelOptions>
#include <osgEarthDrivers/model_feature_stencil/FeatureStencilModelOptions>
#include <osgEarthUtil/Controls>
#include <osgEarthUtil/FeatureEditing>
Include dependency graph for osgearth_featureeditor.cpp:

Go to the source code of this file.

Classes

struct  AddVertsModeHandler
struct  EditModeHandler
struct  ChangeStyleHandler

Functions

osg::Vec4 randomColor ()
GridcreateToolBar ()
StyleSheetbuildStyleSheet (const osg::Vec4 &color, float width)
int main (int argc, char **argv)

Variables

static int s_fid = 0
static osg::ref_ptr
< AddPointHandler
s_addPointHandler
static osg::ref_ptr< osg::Node > s_editor
static osg::ref_ptr< Features_activeFeature
static osgViewer::Viewer * s_viewer
static osg::ref_ptr< osg::Group > s_root
static osg::ref_ptr
< FeatureListSource
s_source
static osg::ref_ptr< MapNodes_mapNode

Function Documentation

StyleSheet* buildStyleSheet ( const osg::Vec4 &  color,
float  width 
)

Definition at line 169 of file osgearth_featureeditor.cpp.

{
    // Define a style for the feature data. Since we are going to render the
    // vectors as lines, configure the line symbolizer:
    Style style;

    LineSymbol* ls = style.getOrCreateSymbol<LineSymbol>();
    ls->stroke()->color() = color;
    ls->stroke()->width() = width;

    //AltitudeSymbol* as = style.getOrCreate<AltitudeSymbol>();
    //as->clamping() = AltitudeSymbol::CLAMP_TO_TERRAIN;

    StyleSheet* styleSheet = new StyleSheet();
    styleSheet->addStyle( style );
    return styleSheet;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Grid* createToolBar ( )

Definition at line 73 of file osgearth_featureeditor.cpp.

{    
    Grid* toolbar = new Grid();
    toolbar->setBackColor(0,0,0,0.5);
    toolbar->setMargin( 10 );
    toolbar->setPadding( 10 );
    toolbar->setChildSpacing( 10 );
    toolbar->setChildVertAlign( Control::ALIGN_CENTER );
    toolbar->setAbsorbEvents( true );
    toolbar->setVertAlign( Control::ALIGN_TOP );    
    return toolbar;    
}

Here is the call graph for this function:

Here is the caller graph for this function:

int main ( int  argc,
char **  argv 
)

Definition at line 191 of file osgearth_featureeditor.cpp.

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

    osgViewer::Viewer viewer(arguments);
    s_viewer = &viewer;

    // Start by creating the map:
    s_mapNode = MapNode::load(arguments);
    if ( !s_mapNode )
    {
        Map* map = new Map();

        // Start with a basemap imagery layer; we'll be using the GDAL driver
        // to load a local GeoTIFF file:
        GDALOptions basemapOpt;
        basemapOpt.url() = "../data/world.tif";
        map->addImageLayer( new ImageLayer( ImageLayerOptions("basemap", basemapOpt) ) );

        // That's it, the map is ready; now create a MapNode to render the Map:
        MapNodeOptions mapNodeOptions;
        mapNodeOptions.enableLighting() = false;

        s_mapNode = new MapNode( map, mapNodeOptions );
    }
    s_mapNode->setNodeMask( 0x01 );

        
    // Define a style for the feature data. Since we are going to render the
    // vectors as lines, configure the line symbolizer:
    StyleSheet* styleSheet = buildStyleSheet( Color::Yellow, 2.0f );

    s_source = new FeatureListSource();

    LineString* line = new LineString();
    line->push_back( osg::Vec3d(-60, 20, 0) );
    line->push_back( osg::Vec3d(-120, 20, 0) );
    line->push_back( osg::Vec3d(-120, 60, 0) );
    line->push_back( osg::Vec3d(-60, 60, 0) );
    Feature *feature = new Feature(s_fid++);
    feature->setGeometry( line );
    s_source->insertFeature( feature );
    s_activeFeature = feature;
  
    s_root = new osg::Group;
    s_root->addChild( s_mapNode.get() );

    Session* session = new Session(s_mapNode->getMap(), styleSheet);

    FeatureModelGraph* graph = new FeatureModelGraph( 
        s_source.get(), 
        FeatureModelSourceOptions(), 
        new GeomFeatureNodeFactory(),
        session );

    graph->getOrCreateStateSet()->setMode(GL_LIGHTING, osg::StateAttribute::OFF);
    graph->getOrCreateStateSet()->setMode(GL_DEPTH_TEST, osg::StateAttribute::OFF);

    s_root->addChild( graph );

    //Setup the controls
    ControlCanvas* canvas = ControlCanvas::get( &viewer );
    s_root->addChild( canvas );
    Grid *toolbar = createToolBar( );
    canvas->addControl( toolbar );
    canvas->setNodeMask( 0x1 << 1 );



    int col = 0;
    LabelControl* addVerts = new LabelControl("Add Verts");
    toolbar->setControl(col++, 0, addVerts );    
    addVerts->addEventHandler( new AddVertsModeHandler( graph ));
    
    LabelControl* edit = new LabelControl("Edit");
    toolbar->setControl(col++, 0, edit );    
    edit->addEventHandler(new EditModeHandler( graph ));

    unsigned int row = 0;
    Grid *styleBar = createToolBar( );
    styleBar->setPosition(0, 50);
    canvas->addControl( styleBar );
    
    //Make a list of styles
    styleBar->setControl(0, row++, new LabelControl("Styles") );    

    unsigned int numStyles = 8;
    for (unsigned int i = 0; i < numStyles; ++i)
    {
        float w = 50;
        osg::Vec4 color = randomColor();

        float widths[3] = {2, 4, 8};

        unsigned int r = row++;
        for (unsigned int j = 0; j < 3; j++) 
        {
            Control* l = new Control();            
            l->setBackColor( color );
            l->addEventHandler(new ChangeStyleHandler(graph, buildStyleSheet( color, widths[j] ) ));
            l->setSize(w,5 * widths[j]);
            styleBar->setControl(j, r, l);
        }
    }
   
    
    viewer.setSceneData( s_root.get() );
    viewer.setCameraManipulator( new EarthManipulator() );
    viewer.addEventHandler( new osgEarth::Util::AutoClipPlaneHandler );

    // add some stock OSG handlers:
    viewer.addEventHandler(new osgViewer::StatsHandler());
    viewer.addEventHandler(new osgViewer::WindowSizeHandler());
    viewer.addEventHandler(new osgGA::StateSetManipulator(viewer.getCamera()->getOrCreateStateSet()));

    return viewer.run();
}

Here is the call graph for this function:

osg::Vec4 randomColor ( )

Definition at line 54 of file osgearth_featureeditor.cpp.

{
    float r = (float)rand() / (float)RAND_MAX;
    float g = (float)rand() / (float)RAND_MAX;
    float b = (float)rand() / (float)RAND_MAX;
    return osg::Vec4(r,g,b,1.0f);
}

Here is the caller graph for this function:


Variable Documentation

osg::ref_ptr< Feature > s_activeFeature [static]

Definition at line 67 of file osgearth_featureeditor.cpp.

osg::ref_ptr< AddPointHandler > s_addPointHandler [static]

Definition at line 65 of file osgearth_featureeditor.cpp.

osg::ref_ptr< osg::Node > s_editor [static]

Definition at line 66 of file osgearth_featureeditor.cpp.

int s_fid = 0 [static]

Definition at line 63 of file osgearth_featureeditor.cpp.

osg::ref_ptr< MapNode > s_mapNode [static]

Definition at line 71 of file osgearth_featureeditor.cpp.

osg::ref_ptr< osg::Group > s_root [static]

Definition at line 69 of file osgearth_featureeditor.cpp.

osg::ref_ptr< FeatureListSource > s_source [static]

Definition at line 70 of file osgearth_featureeditor.cpp.

osgViewer::Viewer* s_viewer [static]

Definition at line 68 of file osgearth_featureeditor.cpp.

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines