osgEarth 2.1.1
Public Member Functions | Protected Attributes

osgEarth::Symbology::GeometryFactory Class Reference

List of all members.

Public Member Functions

 GeometryFactory (const SpatialReference *srs=0L)
GeometrycreateCircle (const osg::Vec3d &center, const Linear &radius, unsigned numSegments=0)
GeometrycreateArc (const osg::Vec3d &center, const Linear &radius, const Angular &startAngle, const Angular &endAngle, unsigned numSegments=0)
GeometrycreateEllipse (const osg::Vec3d &center, const Linear &radiusMajor, const Linear &radiusMinor, const Angular &rotationAngle, unsigned numSegments=0)

Protected Attributes

osg::ref_ptr< const
SpatialReference
_srs

Detailed Description

Convenience class for building simple tessellated Geometry shapes.

Definition at line 36 of file GeometryFactory.


Constructor & Destructor Documentation

GeometryFactory::GeometryFactory ( const SpatialReference srs = 0L)

Constructs the factory.

Parameters:
srsThe spatial reference in which to create the geometry, or NULL to create simple localized geometry.

Definition at line 27 of file GeometryFactory.cpp.

                                                              :
_srs( srs )
{
    //nop
}

Member Function Documentation

Geometry * GeometryFactory::createArc ( const osg::Vec3d &  center,
const Linear radius,
const Angular startAngle,
const Angular endAngle,
unsigned  numSegments = 0 
)

Creates an arc geometry.

Parameters:
centerCenter point (must be in map SRS if a map was provided in ctor)
radiusArc radius
startStarting angle of the arc
endEnding angle of the arc
numSegmentsNumber of circumference segments, or zero to automatically calculate it

Definition at line 84 of file GeometryFactory.cpp.

{
    Geometry* geom = new LineString();

    if ( numSegments == 0 )
    {
        // automatically calculate
        double segLen = radius.as(Units::METERS) / 8.0;
        double circumference = 2*osg::PI*radius.as(Units::METERS);
        numSegments = (unsigned)::ceil(circumference / segLen);
    }

    double startRad = std::min( start.as(Units::RADIANS), end.as(Units::RADIANS) );
    double endRad   = std::max( start.as(Units::RADIANS), end.as(Units::RADIANS) );
    double span     = endRad - startRad;    
    double step     = span/(double)numSegments;

    if ( _srs.valid() && _srs->isGeographic() )
    {
        double earthRadius = _srs->getEllipsoid()->getRadiusEquator();
        double lat = osg::DegreesToRadians(center.y());
        double lon = osg::DegreesToRadians(center.x());
        double rM  = radius.as(Units::METERS);

        for( unsigned i=0; i<=numSegments; ++i )
        {
            double angle = startRad + step*(double)i;
            double clat, clon;
            GeoMath::destination( lat, lon, angle, rM, clat, clon, earthRadius );
            geom->push_back( osg::Vec3d(osg::RadiansToDegrees(clon), osg::RadiansToDegrees(clat), center.z()) );
        }
    }

    else
    {
        double rM = radius.as(Units::METERS);

        for( unsigned i=0; i<=numSegments; ++i )
        {
            double angle = startRad + step*(double)i;
            double x, y;
            x = center.x() + sin(angle)*rM;
            y = center.y() + cos(angle)*rM;
            geom->push_back( osg::Vec3d(x, y, center.z()) );
        }
    }

    return geom;
}

Here is the call graph for this function:

Geometry * GeometryFactory::createCircle ( const osg::Vec3d &  center,
const Linear radius,
unsigned  numSegments = 0 
)

Creates a circle geometry.

Parameters:
centerCenter point (must be in map SRS if a map was provided in ctor)
radiusCircle radius
numSegmentsNumber of circumference segments, or zero to automatically calculate it

Definition at line 34 of file GeometryFactory.cpp.

{
    Polygon* geom = new Polygon();

    if ( numSegments == 0 )
    {
        // automatically calculate
        double segLen = radius.as(Units::METERS) / 8.0;
        double circumference = 2*osg::PI*radius.as(Units::METERS);
        numSegments = (unsigned)::ceil(circumference / segLen);
    }
    
    double segAngle = (2.0*osg::PI)/(double)numSegments;

    if ( _srs.valid() && _srs->isGeographic() )
    {
        double earthRadius = _srs->getEllipsoid()->getRadiusEquator();
        double lat = osg::DegreesToRadians(center.y());
        double lon = osg::DegreesToRadians(center.x());
        double rM  = radius.as(Units::METERS);

        for( unsigned i=0; i<numSegments; ++i )
        {
            double angle = segAngle * (double)i;
            double clat, clon;
            GeoMath::destination( lat, lon, angle, rM, clat, clon, earthRadius );
            geom->push_back( osg::Vec3d(osg::RadiansToDegrees(clon), osg::RadiansToDegrees(clat), center.z()) );
        }
    }

    else
    {
        double rM = radius.as(Units::METERS);

        for( unsigned i=0; i<numSegments; ++i )
        {
            double angle = segAngle * (double)i;
            double x, y;
            x = center.x() + sin(angle)*rM;
            y = center.y() + cos(angle)*rM;
            geom->push_back( osg::Vec3d(x, y, center.z()) );
        }
    }

    return geom;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Geometry * GeometryFactory::createEllipse ( const osg::Vec3d &  center,
const Linear radiusMajor,
const Linear radiusMinor,
const Angular rotationAngle,
unsigned  numSegments = 0 
)

Creates a ellipse geometry.

Parameters:
centerCenter point (must be in map SRS if a map was provided in ctor)
radiusMajorMajor radius (X-axis) length
radiusMinorMinor radius (Y-axis) length
rotationAnglewith respect to the X-axis
numSegmentsNumber of circumference segments, or zero to automatically calculate it

Definition at line 139 of file GeometryFactory.cpp.

{
    Polygon* geom = new Polygon();

    if ( numSegments == 0 )
    {
        // automatically calculate
        double ravgM = 0.5*(radiusMajor.as(Units::METERS) + radiusMinor.as(Units::METERS));
        double segLen = ravgM / 8.0;
        double circumference = 2*osg::PI*ravgM;
        numSegments = (unsigned)::ceil(circumference / segLen);
    }
    
    double segAngle = 2.0*osg::PI/(double)numSegments;

    if ( _srs.valid() && _srs->isGeographic() )
    {
        double earthRadius = _srs->getEllipsoid()->getRadiusEquator();
        double lat = osg::DegreesToRadians(center.y());
        double lon = osg::DegreesToRadians(center.x());
        double a = radiusMajor.as(Units::METERS);
        double b = radiusMinor.as(Units::METERS);
        double g = rotationAngle.as(Units::RADIANS) - osg::PI_2;

        for( unsigned i=0; i<numSegments; ++i )
        {
            double angle = segAngle * (double)i;
            double t = angle - osg::PI_2;
            double clat, clon;

            double rA = (b*b-a*a)*cos(2*t - 2*g) + a*a + b*b;
            double q = sqrt(2.0)*a*b*sqrt(rA);
            double r = q/rA;

            GeoMath::destination( lat, lon, angle, r, clat, clon, earthRadius );
            geom->push_back( osg::Vec3d(osg::RadiansToDegrees(clon), osg::RadiansToDegrees(clat), center.z()) );
        }
    }
    else
    {
        double a = radiusMajor.as(Units::METERS);
        double b = radiusMinor.as(Units::METERS);
        double g = rotationAngle.as(Units::RADIANS) - osg::PI_2;
        double sing = sin(g), cosg = cos(g);

        for( unsigned i=0; i<numSegments; ++i )
        {
            double angle = segAngle * (double)i;
            double t = angle - osg::PI_2;
            double cost = cos(t), sint = sin(t);
            double x = center.x() + a*cost*cosg - b*sint*sing;
            double y = center.y() + a*cost*sing + b*sint*cosg;

            geom->push_back( osg::Vec3d(x, y, center.z()) );
        }
    }

    return geom;
}

Here is the call graph for this function:


Member Data Documentation

Definition at line 89 of file GeometryFactory.


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