// rasterizes a geometry.
    void rasterize(const Geometry* geometry, const osg::Vec4& color, RenderFrame& frame, 
                   agg::rasterizer& ras, agg::renderer<agg::span_abgr32>& ren)
    {
        osg::Vec4 c = color;
        unsigned int a = (unsigned int)(127+(c.a()*255)/2); // scale alpha up
        agg::rgba8 fgColor( (unsigned int)(c.r()*255), (unsigned int)(c.g()*255), (unsigned int)(c.b()*255), a );

        ras.filling_rule( agg::fill_even_odd );

        ConstGeometryIterator gi( geometry );
        while( gi.hasMore() )
        {
            c = color;
            const Geometry* g = gi.next();

            for( Geometry::const_iterator p = g->begin(); p != g->end(); p++ )
            {
                const osg::Vec3d& p0 = *p;
                double x0 = frame.xf*(p0.x()-frame.xmin);
                double y0 = frame.yf*(p0.y()-frame.ymin);

                if ( p == g->begin() )
                    ras.move_to_d( x0, y0 );
                else
                    ras.line_to_d( x0, y0 );
            }
        }
        ras.render(ren, fgColor);
        ras.reset();
    }
    void rasterizeCoverage(const Geometry* geometry, float value, RenderFrame& frame, 
                           agg::rasterizer& ras, agg::rendering_buffer& buffer)
    {
        ConstGeometryIterator gi( geometry );
        while( gi.hasMore() )
        {
            const Geometry* g = gi.next();

            for( Geometry::const_iterator p = g->begin(); p != g->end(); p++ )
            {
                const osg::Vec3d& p0 = *p;
                double x0 = frame.xf*(p0.x()-frame.xmin);
                double y0 = frame.yf*(p0.y()-frame.ymin);

                if ( p == g->begin() )
                    ras.move_to_d( x0, y0 );
                else
                    ras.line_to_d( x0, y0 );
            }
        }
        
        agg::renderer<span_coverage32, float32> ren(buffer);
        ras.render(ren, value);
        ras.reset();
    }
    // rasterizes a geometry to color
    void rasterize(const Geometry* geometry, const osg::Vec4& color, RenderFrame& frame, 
                   agg::rasterizer& ras, agg::rendering_buffer& buffer)
    {
        unsigned a = (unsigned)(127.0f+(color.a()*255.0f)/2.0f); // scale alpha up
        agg::rgba8 fgColor = agg::rgba8( (unsigned)(color.r()*255.0f), (unsigned)(color.g()*255.0f), (unsigned)(color.b()*255.0f), a );
        
        ConstGeometryIterator gi( geometry );
        while( gi.hasMore() )
        {
            const Geometry* g = gi.next();

            for( Geometry::const_iterator p = g->begin(); p != g->end(); p++ )
            {
                const osg::Vec3d& p0 = *p;
                double x0 = frame.xf*(p0.x()-frame.xmin);
                double y0 = frame.yf*(p0.y()-frame.ymin);

                if ( p == g->begin() )
                    ras.move_to_d( x0, y0 );
                else
                    ras.line_to_d( x0, y0 );
            }
        }
        agg::renderer<agg::span_abgr32, agg::rgba8> ren(buffer);
        ras.render(ren, fgColor);

        ras.reset();
    }
Пример #4
0
void draw_ellipse(agg::rasterizer& ras,
                  double x,  double y,
                  double rx, double ry)
{
	int i;
	ras.move_to_d(x + rx, y);

	// Here we have a fixed number of approximation steps, namely 360
	// while in reality it's supposed to be smarter.
	for(i = 1; i < 360; i++) {
		double a = double(i) * 3.1415926 / 180.0;
		ras.line_to_d(x + cos(a) * rx, y + sin(a) * ry);
	}
}
Пример #5
0
void draw_line(agg::rasterizer& ras,
               double x1, double y1,
               double x2, double y2,
               double width)
{

	double dx = x2 - x1;
	double dy = y2 - y1;
	double d = sqrt(dx*dx + dy*dy);

	dx = width * (y2 - y1) / d;
	dy = width * (x2 - x1) / d;

	ras.move_to_d(x1 - dx,  y1 + dy);
	ras.line_to_d(x2 - dx,  y2 + dy);
	ras.line_to_d(x2 + dx,  y2 - dy);
	ras.line_to_d(x1 + dx,  y1 - dy);
}