|
osgEarth 2.1.1
|
Collaboration diagram for osgEarth::Symbology::GeometryRasterizer:Public Member Functions | |
| GeometryRasterizer (int width, int height, const Style &style=Style()) | |
| void | draw (const Geometry *geom, const osg::Vec4f &color=osg::Vec4f(1, 1, 1, 1)) |
| osg::Image * | finalize () |
Private Attributes | |
| osg::ref_ptr< osg::Image > | _image |
| Style | _style |
| osg::ref_ptr< osg::Referenced > | _state |
Draws geometry onto an Image canvas using software path-rendering.
Definition at line 33 of file GeometryRasterizer.
| void GeometryRasterizer::draw | ( | const Geometry * | geom, |
| const osg::Vec4f & | color = osg::Vec4f(1,1,1,1) |
||
| ) |
draws the geometry to the image.
Definition at line 76 of file GeometryRasterizer.cpp.
{
if ( !_image.valid() ) return;
AggState* state = static_cast<AggState*>( _state.get() );
osg::Vec4f color = c;
osg::ref_ptr<const Geometry> geomToRender = geom;
if ( geom->getType() == Geometry::TYPE_POLYGON )
{
const PolygonSymbol* ps = _style.getSymbol<const PolygonSymbol>();
if ( ps )
color = ps->fill()->color();
}
else
{
const LineSymbol* ls = _style.getSymbol<const LineSymbol>();
float distance = ls ? ls->stroke()->width().value() * 0.5f : 1.0f;
osg::ref_ptr<Geometry> bufferedGeom;
if ( !geom->buffer( distance, bufferedGeom ) )
{
OE_WARN << LC << "Failed to draw line; buffer op not available" << std::endl;
return;
}
geomToRender = bufferedGeom.get();
if ( ls )
color = ls->stroke()->color();
}
float a = 127+(color.a()*255)/2; // scale alpha up
agg::rgba8 fgColor = agg::rgba8( (unsigned int)(color.r()*255), (unsigned int)(color.g()*255), (unsigned int)(color.b()*255), (unsigned int)a );
ConstGeometryIterator gi( geomToRender.get() );
while( gi.hasMore() )
{
const Vec3dVector& g = gi.next()->asVector();
for( Vec3dVector::const_iterator p = g.begin(); p != g.end(); p++ )
{
const osg::Vec3d& p0 = *p;
if ( p == g.begin() )
state->_ras.move_to_d( p0.x(), p0.y() );
else
state->_ras.line_to_d( p0.x(), p0.y() );
}
}
state->_ras.render( state->_ren, fgColor );
state->_ras.reset();
}
Here is the call graph for this function:
Here is the caller graph for this function:| osg::Image * GeometryRasterizer::finalize | ( | ) |
finishes the image and returns it. calls to draw() after this will have no effect.
Definition at line 61 of file GeometryRasterizer.cpp.
{
//convert from ABGR to RGBA
unsigned char* pixel = _image->data();
for(int i=0; i<_image->s()*_image->t()*4; i+=4, pixel+=4)
{
std::swap( pixel[0], pixel[3] );
std::swap( pixel[1], pixel[2] );
}
osg::Image* result = _image.release();
_image = 0L;
return result;
}
Here is the caller graph for this function:osg::ref_ptr<osg::Image> osgEarth::Symbology::GeometryRasterizer::_image [private] |
Definition at line 45 of file GeometryRasterizer.
osg::ref_ptr<osg::Referenced> osgEarth::Symbology::GeometryRasterizer::_state [private] |
Definition at line 47 of file GeometryRasterizer.
Definition at line 46 of file GeometryRasterizer.
1.7.3