osgEarth 2.1.1
|
Public Member Functions | |
GeometryFactory (const SpatialReference *srs=0L) | |
Geometry * | createCircle (const osg::Vec3d ¢er, const Linear &radius, unsigned numSegments=0) |
Geometry * | createArc (const osg::Vec3d ¢er, const Linear &radius, const Angular &startAngle, const Angular &endAngle, unsigned numSegments=0) |
Geometry * | createEllipse (const osg::Vec3d ¢er, const Linear &radiusMajor, const Linear &radiusMinor, const Angular &rotationAngle, unsigned numSegments=0) |
Protected Attributes | |
osg::ref_ptr< const SpatialReference > | _srs |
Convenience class for building simple tessellated Geometry shapes.
Definition at line 36 of file GeometryFactory.
GeometryFactory::GeometryFactory | ( | const SpatialReference * | srs = 0L | ) |
Constructs the factory.
srs | The 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 }
Geometry * GeometryFactory::createArc | ( | const osg::Vec3d & | center, |
const Linear & | radius, | ||
const Angular & | startAngle, | ||
const Angular & | endAngle, | ||
unsigned | numSegments = 0 |
||
) |
Creates an arc geometry.
center | Center point (must be in map SRS if a map was provided in ctor) |
radius | Arc radius |
start | Starting angle of the arc |
end | Ending angle of the arc |
numSegments | Number 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; }
Geometry * GeometryFactory::createCircle | ( | const osg::Vec3d & | center, |
const Linear & | radius, | ||
unsigned | numSegments = 0 |
||
) |
Creates a circle geometry.
center | Center point (must be in map SRS if a map was provided in ctor) |
radius | Circle radius |
numSegments | Number 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; }
Geometry * GeometryFactory::createEllipse | ( | const osg::Vec3d & | center, |
const Linear & | radiusMajor, | ||
const Linear & | radiusMinor, | ||
const Angular & | rotationAngle, | ||
unsigned | numSegments = 0 |
||
) |
Creates a ellipse geometry.
center | Center point (must be in map SRS if a map was provided in ctor) |
radiusMajor | Major radius (X-axis) length |
radiusMinor | Minor radius (Y-axis) length |
rotationAngle | with respect to the X-axis |
numSegments | Number 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; }
osg::ref_ptr<const SpatialReference> osgEarth::Symbology::GeometryFactory::_srs [protected] |
Definition at line 89 of file GeometryFactory.