osgEarth 2.1.1
Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes

osgEarth::Symbology::Geometry Class Reference

Inheritance diagram for osgEarth::Symbology::Geometry:
Collaboration diagram for osgEarth::Symbology::Geometry:

List of all members.

Public Types

enum  Type {
  TYPE_UNKNOWN, TYPE_POINTSET, TYPE_LINESTRING, TYPE_RING,
  TYPE_POLYGON, TYPE_MULTI
}

Public Member Functions

 Geometry (const Vec3dVector *toCopy)
virtual int getTotalPointCount () const
virtual unsigned getNumComponents () const
virtual unsigned getNumGeometries () const
virtual GeometrycloneAs (const Geometry::Type &newType) const
osg::Vec3Array * toVec3Array () const
osg::Vec3dArray * toVec3dArray () const
virtual Bounds getBounds () const
bool isLinear () const
bool buffer (double distance, osg::ref_ptr< Geometry > &output, const BufferParameters &bp=BufferParameters()) const
bool crop (const class Polygon *cropPolygon, osg::ref_ptr< Geometry > &output) const
bool difference (const class Polygon *diffPolygon, osg::ref_ptr< Geometry > &output) const
osg::Vec3d localize ()
void delocalize (const osg::Vec3d &offset)
virtual Type getType () const =0
virtual Type getComponentType () const
virtual bool isValid () const
virtual Geometryclone () const

Static Public Member Functions

static std::string toString (Type t)
static Geometrycreate (Type type, const Vec3dVector *toCopy)
static bool hasBufferOperation ()

Protected Member Functions

 Geometry (int capacity=0)
 Geometry (const Geometry &rhs)

Protected Attributes

Vec3dVector _data

Detailed Description

Baseline geometry class. All Geometry objects derive from this class, even MultiGeometry.

Definition at line 53 of file Geometry.


Member Enumeration Documentation

Enumerator:
TYPE_UNKNOWN 
TYPE_POINTSET 
TYPE_LINESTRING 
TYPE_RING 
TYPE_POLYGON 
TYPE_MULTI 

Definition at line 59 of file Geometry.


Constructor & Destructor Documentation

Geometry::Geometry ( const Vec3dVector toCopy)

Definition at line 52 of file Geometry.cpp.

{
    reserve( data->size() );
    insert( begin(), data->begin(), data->end() );
}

Here is the call graph for this function:

Geometry::Geometry ( int  capacity = 0) [protected]

Definition at line 46 of file Geometry.cpp.

{
    if ( capacity > 0 )
        reserve( capacity );
}

Here is the call graph for this function:

Geometry::Geometry ( const Geometry rhs) [protected]

Definition at line 40 of file Geometry.cpp.


Member Function Documentation

bool Geometry::buffer ( double  distance,
osg::ref_ptr< Geometry > &  output,
const BufferParameters bp = BufferParameters() 
) const

Runs a buffer (dialate/erode) operation on this geometry and returns the result in the output parameter. Returns true if the op succeeded.

Definition at line 144 of file Geometry.cpp.

{
#ifdef OSGEARTH_HAVE_GEOS   

    geom::Geometry* inGeom = GEOSUtils::importGeometry( this );
    if ( inGeom )
    {
        buffer::BufferParameters::EndCapStyle geosEndCap =
            params._capStyle == BufferParameters::CAP_ROUND  ? buffer::BufferParameters::CAP_ROUND :
            params._capStyle == BufferParameters::CAP_SQUARE ? buffer::BufferParameters::CAP_SQUARE :
            params._capStyle == BufferParameters::CAP_FLAT   ? buffer::BufferParameters::CAP_FLAT :
            buffer::BufferParameters::CAP_SQUARE;

        buffer::BufferParameters::JoinStyle geosJoinStyle =
            params._joinStyle == BufferParameters::JOIN_ROUND ? buffer::BufferParameters::JOIN_ROUND :
            params._joinStyle == BufferParameters::JOIN_MITRE ? buffer::BufferParameters::JOIN_MITRE :
            params._joinStyle == BufferParameters::JOIN_BEVEL ? buffer::BufferParameters::JOIN_BEVEL :
            buffer::BufferParameters::JOIN_ROUND;

        //JB:  Referencing buffer::BufferParameters::DEFAULT_QUADRANT_SEGMENTS causes link errors b/c it is defined as a static in the header of BufferParameters.h and not defined in the cpp anywhere.
        //     This seems to only effect the Linux build, Windows works fine
        int geosQuadSegs = params._cornerSegs > 0 
            ? params._cornerSegs
            : 8;//buffer::BufferParameters::DEFAULT_QUADRANT_SEGMENTS;

        geom::Geometry* outGeom = NULL;

        buffer::BufferParameters geosBufferParams;
        geosBufferParams.setQuadrantSegments( geosQuadSegs );
        geosBufferParams.setEndCapStyle( geosEndCap );
        geosBufferParams.setJoinStyle( geosJoinStyle );
        buffer::BufferBuilder bufBuilder( geosBufferParams );

        if (params._singleSided)
        {
            outGeom = bufBuilder.bufferLineSingleSided(inGeom, distance, params._leftSide );
        }
        else
        {
            outGeom = bufBuilder.buffer(inGeom, distance );
        }

        if ( outGeom )
        {
            output = GEOSUtils::exportGeometry( outGeom );
            outGeom->getFactory()->destroyGeometry( outGeom );
        }
        else
        {
            OE_INFO << LC << "Buffer: no output geometry" << std::endl;
        }

        inGeom->getFactory()->destroyGeometry( inGeom );
    }
    return output.valid();

#else // OSGEARTH_HAVE_GEOS

    OE_WARN << LC << "Buffer failed - GEOS not available" << std::endl;
    return false;

#endif // OSGEARTH_HAVE_GEOS
}

Here is the caller graph for this function:

virtual Geometry* osgEarth::Symbology::Geometry::clone ( ) const [inline, virtual]

Definition at line 170 of file Geometry.

{ return cloneAs(getType()); }

Here is the caller graph for this function:

Geometry * Geometry::cloneAs ( const Geometry::Type newType) const [virtual]

Converts this geometry to another type. This function will return "this" if the type is the same, and will return NULL if the conversion is impossible.

Reimplemented in osgEarth::Symbology::Ring, and osgEarth::Symbology::MultiGeometry.

Definition at line 74 of file Geometry.cpp.

{
    //if ( newType == getType() )        
    //    return static_cast<Geometry*>( clone() );
    
    switch( newType )
    {
    case TYPE_POINTSET:
        return new PointSet( &this->asVector() );
    case TYPE_LINESTRING:
        return new LineString( &this->asVector() );
    case TYPE_RING:
        return new Ring( &this->asVector() );
    case TYPE_POLYGON:
        if ( dynamic_cast<const Polygon*>(this) )
            return new Polygon( *static_cast<const Polygon*>(this) );
        else
            return new Polygon( &this->asVector() );
    default:
        break;
    }
    return 0L;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Geometry * Geometry::create ( Type  type,
const Vec3dVector toCopy 
) [static]

Definition at line 115 of file Geometry.cpp.

{
    Geometry* output = 0L;
    switch( type ) {
        case TYPE_POINTSET:
            output = new PointSet( toCopy ); break;
        case TYPE_LINESTRING:
            output = new LineString( toCopy ); break;
        case TYPE_RING:
            output = new Ring( toCopy ); break;
        case TYPE_POLYGON:
            output = new Polygon( toCopy ); break;
        default:
            break;
    }
    return output;
}

Here is the caller graph for this function:

bool Geometry::crop ( const class Polygon cropPolygon,
osg::ref_ptr< Geometry > &  output 
) const

Crops this geometry to the region represented by the crop polygon, returning the result in the output parameter. Returns true if the op succeeded.

Definition at line 211 of file Geometry.cpp.

{
#ifdef OSGEARTH_HAVE_GEOS

    geom::GeometryFactory* f = new geom::GeometryFactory();

    //Create the GEOS Geometries
    geom::Geometry* inGeom = GEOSUtils::importGeometry( this );
    geom::Geometry* cropGeom = GEOSUtils::importGeometry( cropPoly );

    if ( inGeom )
    {    
        geom::Geometry* outGeom = 0L;
        try {
            outGeom = overlay::OverlayOp::overlayOp(
                inGeom, cropGeom,
                overlay::OverlayOp::opINTERSECTION );
        }
        catch( ... ) {
            outGeom = 0L;
            OE_NOTICE << LC << "::crop, GEOS overlay op exception, skipping feature" << std::endl;
        }

        if ( outGeom )
        {
            output = GEOSUtils::exportGeometry( outGeom );
            f->destroyGeometry( outGeom );
            if ( output.valid() && !output->isValid() )
            {
                output = 0L;
            }
        }
    }

    //Destroy the geometry
    f->destroyGeometry( cropGeom );
    f->destroyGeometry( inGeom );

    delete f;
    return output.valid();

#else // OSGEARTH_HAVE_GEOS

    OE_WARN << LC << "Crop failed - GEOS not available" << std::endl;
    return false;

#endif // OSGEARTH_HAVE_GEOS
}

Here is the caller graph for this function:

void Geometry::delocalize ( const osg::Vec3d &  offset)

Reverses a call the localize(), given the same offset returned by that method.

Definition at line 336 of file Geometry.cpp.

{
    GeometryIterator i( this );
    while( i.hasMore() )
    {
        Geometry* part = i.next();
        for( Geometry::iterator j = part->begin(); j != part->end(); ++j )
        {
            *j = *j + offset;
        }
    }
}

Here is the call graph for this function:

bool Geometry::difference ( const class Polygon diffPolygon,
osg::ref_ptr< Geometry > &  output 
) const

Boolean difference - subtracts diffPolygon from this geometry, and put the result in output.

Definition at line 261 of file Geometry.cpp.

{
#ifdef OSGEARTH_HAVE_GEOS

    geom::GeometryFactory* f = new geom::GeometryFactory();

    //Create the GEOS Geometries
    geom::Geometry* inGeom = GEOSUtils::importGeometry( this );
    geom::Geometry* diffGeom = GEOSUtils::importGeometry( diffPolygon );

    if ( inGeom )
    {    
        geom::Geometry* outGeom = 0L;
        try {
            outGeom = overlay::OverlayOp::overlayOp(
                inGeom, diffGeom,
                overlay::OverlayOp::opDIFFERENCE );
        }
        catch( ... ) {
            outGeom = 0L;
            OE_NOTICE << LC << "::difference, GEOS overlay op exception, skipping feature" << std::endl;
        }

        if ( outGeom )
        {
            output = GEOSUtils::exportGeometry( outGeom );
            f->destroyGeometry( outGeom );
            if ( output.valid() && !output->isValid() )
            {
                output = 0L;
            }
        }
    }

    //Destroy the geometry
    f->destroyGeometry( diffGeom );
    f->destroyGeometry( inGeom );

    delete f;
    return output.valid();

#else // OSGEARTH_HAVE_GEOS

    OE_WARN << LC << "Difference failed - GEOS not available" << std::endl;
    return false;

#endif // OSGEARTH_HAVE_GEOS
}
Bounds Geometry::getBounds ( ) const [virtual]

Gets the bounds of this geometry

Reimplemented in osgEarth::Symbology::MultiGeometry.

Definition at line 65 of file Geometry.cpp.

{
    Bounds bounds;
    for( const_iterator i = begin(); i != end(); ++i )
        bounds.expandBy( i->x(), i->y(), i->z() );
    return bounds;
}

Here is the call graph for this function:

Here is the caller graph for this function:

virtual Type osgEarth::Symbology::Geometry::getComponentType ( ) const [inline, virtual]

Reimplemented in osgEarth::Symbology::MultiGeometry.

Definition at line 167 of file Geometry.

{ return getType(); }

Here is the caller graph for this function:

virtual unsigned osgEarth::Symbology::Geometry::getNumComponents ( ) const [inline, virtual]

Gets the total number of geometry components

Reimplemented in osgEarth::Symbology::MultiGeometry.

Definition at line 92 of file Geometry.

{ return 1; }
virtual unsigned osgEarth::Symbology::Geometry::getNumGeometries ( ) const [inline, virtual]

Gets the total number of geometries; it is the total of all parts of all components. Also can be seen as the number of Geometry objects that would be returned by a full GeometryIterator.

Reimplemented in osgEarth::Symbology::Polygon, and osgEarth::Symbology::MultiGeometry.

Definition at line 99 of file Geometry.

{ return 1; }

Here is the caller graph for this function:

int Geometry::getTotalPointCount ( ) const [virtual]

Gets the total number of points in this geometry.

Reimplemented in osgEarth::Symbology::Polygon, and osgEarth::Symbology::MultiGeometry.

Definition at line 59 of file Geometry.cpp.

{
    return size();
}

Here is the call graph for this function:

Here is the caller graph for this function:

virtual Type osgEarth::Symbology::Geometry::getType ( ) const [pure virtual]
bool Geometry::hasBufferOperation ( ) [static]

Definition at line 134 of file Geometry.cpp.

{
#ifdef OSGEARTH_HAVE_GEOS
    return true;
#else
    return false;
#endif
}

Here is the caller graph for this function:

bool osgEarth::Symbology::Geometry::isLinear ( ) const [inline]

Whether the geometry is lines

Definition at line 127 of file Geometry.

virtual bool osgEarth::Symbology::Geometry::isValid ( ) const [inline, virtual]

Reimplemented in osgEarth::Symbology::LineString, osgEarth::Symbology::Ring, and osgEarth::Symbology::MultiGeometry.

Definition at line 168 of file Geometry.

{ return size() >= 1; }

Here is the caller graph for this function:

osg::Vec3d Geometry::localize ( )

Localizes this geometry relative to its centroid, and returns the localization offset.

Definition at line 311 of file Geometry.cpp.

{
    osg::Vec3d offset;

    Bounds bounds = getBounds();
    if ( bounds.isValid() )
    {      
        osg::Vec2d center = bounds.center2d();
        offset.set( center.x(), center.y(), 0 );

        GeometryIterator i( this );
        while( i.hasMore() )
        {
            Geometry* part = i.next();
            for( Geometry::iterator j = part->begin(); j != part->end(); ++j )
            {
                *j = *j - offset;
            }
        }
    }

    return offset;
}

Here is the call graph for this function:

static std::string osgEarth::Symbology::Geometry::toString ( Type  t) [inline, static]

Definition at line 68 of file Geometry.

                                            {
            return 
                t == TYPE_POINTSET ?   "pointset" :
                t == TYPE_LINESTRING ? "linestring" :
                t == TYPE_RING ?       "ring" :
                t == TYPE_POLYGON ?    "polygon" :
                t == TYPE_MULTI ?      "multi" :
                "unknown";
        }

Here is the caller graph for this function:

osg::Vec3Array * Geometry::toVec3Array ( ) const

Creates a new Vec3Array (single-precision), copies the part into it, and returns the new object.

Definition at line 99 of file Geometry.cpp.

{
    osg::Vec3Array* result = new osg::Vec3Array( this->size() );
    std::copy( begin(), end(), result->begin() );
    return result;
}

Here is the call graph for this function:

Here is the caller graph for this function:

osg::Vec3dArray * Geometry::toVec3dArray ( ) const

Creates a new Vec3dArray (double-precision), copies the part into it, and returns the new object.

Definition at line 107 of file Geometry.cpp.

{
    osg::Vec3dArray* result = new osg::Vec3dArray( this->size() );
    std::copy( begin(), end(), result->begin() );
    return result;
}

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Definition at line 176 of file Geometry.


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