osgEarth 2.1.1
Public Member Functions

GeometryPointSymbolizer Struct Reference

Inheritance diagram for GeometryPointSymbolizer:
Collaboration diagram for GeometryPointSymbolizer:

List of all members.

Public Member Functions

bool update (State< GeometryContent > *state, osg::Group *attachPoint, SymbolizerContext *context)

Detailed Description

Definition at line 242 of file osgearth_symbology.cpp.


Member Function Documentation

bool GeometryPointSymbolizer::update ( State< GeometryContent > *  state,
osg::Group *  attachPoint,
SymbolizerContext *  context 
) [inline]

Definition at line 244 of file osgearth_symbology.cpp.

    {
        if ( !state || !attachPoint || !state->getContent() || !state->getStyle() )
            return false;

        osg::ref_ptr<osg::Group> newSymbolized = new osg::Group;
        osg::ref_ptr<osg::Geode> geode = new osg::Geode;
        newSymbolized->addChild(geode.get());

        const GeometryList& geometryList = state->getContent()->getGeometryList();
        for (GeometryList::const_iterator it = geometryList.begin(); it != geometryList.end(); ++it)
        {
            Geometry* geometry = *it;
            if (!geometry)
                continue;

            osg::ref_ptr<osg::Geometry> osgGeom = new osg::Geometry;
            osg::PrimitiveSet::Mode primMode = osg::PrimitiveSet::POINTS;

            osg::Vec4 color = osg::Vec4(1.0, 0.0, 1.0, 1.);

            switch( geometry->getType())
            {
            case Geometry::TYPE_POINTSET:
            {
                primMode = osg::PrimitiveSet::POINTS;
                const PointSymbol* point = state->getStyle()->getSymbol<PointSymbol>();
                if (point)
                {
                    color = point->fill()->color();

                    float size = point->size().value();
                    osgGeom->getOrCreateStateSet()->setAttributeAndModes( new osg::Point(size) );
                }
            }
            break;

            case Geometry::TYPE_LINESTRING:
            {
                primMode = osg::PrimitiveSet::LINE_STRIP;
                const LineSymbol* line = state->getStyle()->getSymbol<LineSymbol>();
                if (line) 
                {
                    color = line->stroke()->color();
                    float size = line->stroke()->width().value();
                    osgGeom->getOrCreateStateSet()->setAttributeAndModes( new osg::LineWidth(size));
                }
            }
            break;

            case Geometry::TYPE_RING:
            {
                primMode = osg::PrimitiveSet::LINE_LOOP;
                const LineSymbol* line = state->getStyle()->getSymbol<LineSymbol>();
                if (line)
                {
                    color = line->stroke()->color();
                    float size = line->stroke()->width().value();
                    osgGeom->getOrCreateStateSet()->setAttributeAndModes( new osg::LineWidth(size));
                }
            }
            break;

            case Geometry::TYPE_POLYGON:
            {
                // use polygon as point for this specific symbolizer
                // it would be simpler to use the symbol style->getPoint but here
                // we want to dmonstrate how to customize Symbol and Symbolizer
                primMode = osg::PrimitiveSet::POINTS;
                const PolygonPointSizeSymbol* poly = state->getStyle()->getSymbol<PolygonPointSizeSymbol>();
                if (poly)
                {
                    color = poly->fill()->color();

                    float size = poly->size();
                    osgGeom->getOrCreateStateSet()->setAttributeAndModes( new osg::Point(size) );
                }
            }
            break;
            }

            osg::Material* material = new osg::Material;
            material->setDiffuse(osg::Material::FRONT_AND_BACK, color);

            osgGeom->setVertexArray( geometry->toVec3Array() );
            osgGeom->addPrimitiveSet( new osg::DrawArrays( primMode, 0, geometry->size() ) );

            osgGeom->getOrCreateStateSet()->setAttributeAndModes(material);
            osgGeom->getOrCreateStateSet()->setMode(GL_LIGHTING, false);
            geode->addDrawable(osgGeom);

        }

        if (geode->getNumDrawables()) 
        {
            attachPoint->removeChildren(0, attachPoint->getNumChildren());
            attachPoint->addChild(newSymbolized.get());
            return true;
        }

        return false;
    }

Here is the call graph for this function:


The documentation for this struct was generated from the following file:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines