osgEarth 2.1.1
|
Public Types | |
enum | Orientation { ORIENTATION_CCW, ORIENTATION_CW, ORIENTATION_DEGENERATE } |
Public Member Functions | |
Ring (int capacity=0) | |
Ring (const Ring &ring) | |
Ring (const Vec3dVector *toCopy) | |
virtual Geometry * | cloneAs (const Geometry::Type &newType) const |
Orientation | getOrientation () const |
virtual bool | contains2D (double x, double y) const |
virtual double | getSignedArea2D () const |
virtual void | open () |
void | rewind (Orientation ori) |
virtual Type | getType () const |
virtual bool | isValid () const |
A Ring is a closed region. It is open (the first and last points are not the same). It has an orientation, i.e. it is either wound clockwise or counter-clockwise.
osgEarth::Symbology::Ring::Ring | ( | int | capacity = 0 | ) | [inline] |
Ring::Ring | ( | const Ring & | ring | ) |
Definition at line 405 of file Geometry.cpp.
: Geometry( rhs ) { //nop }
Ring::Ring | ( | const Vec3dVector * | toCopy | ) |
Geometry * Ring::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 from osgEarth::Symbology::Geometry.
Definition at line 418 of file Geometry.cpp.
{ if ( newType == TYPE_LINESTRING ) { LineString* line = new LineString( &this->asVector() ); if ( line->size() > 1 && line->front() != line->back() ) line->push_back( front() ); return line; } else return Geometry::cloneAs( newType ); }
bool Ring::contains2D | ( | double | x, |
double | y | ||
) | const [virtual] |
Reimplemented in osgEarth::Symbology::Polygon.
Definition at line 517 of file Geometry.cpp.
{ bool result = false; const Ring& poly = *this; for( unsigned i=0, j=size()-1; i<size(); j = i++ ) { if ((((poly[i].y() <= y) && (y < poly[j].y())) || ((poly[j].y() <= y) && (y < poly[i].y()))) && (x < (poly[j].x()-poly[i].x()) * (y-poly[i].y())/(poly[j].y()-poly[i].y())+poly[i].x())) { result = !result; } } return result; }
Ring::Orientation Ring::getOrientation | ( | ) | const |
Definition at line 431 of file Geometry.cpp.
{ // adjust for a non-open ring: int n = size(); while( n > 0 && front() == back() ) n--; if ( n < 3 ) return Ring::ORIENTATION_DEGENERATE; // copy the open vec: std::vector<osg::Vec3d> v; v.reserve( n ); std::copy( begin(), begin()+n, std::back_inserter(v) ); int rmin = 0; double xmin = v[0].x(); double ymin = v[0].y(); v[0].z() = 0; for( int i=1; i<n; ++i ) { double x = v[i].x(); double y = v[i].y(); v[i].z() = 0; if ( y > ymin ) continue; if ( y == ymin ) { if (x < xmin ) continue; } rmin = i; xmin = x; ymin = y; } int rmin_less_1 = rmin-1 >= 0 ? rmin-1 : n-1; int rmin_plus_1 = rmin+1 < n ? rmin+1 : 0; osg::Vec3 in = v[rmin] - v[rmin_less_1]; in.normalize(); osg::Vec3 out = v[rmin_plus_1] - v[rmin]; out.normalize(); osg::Vec3 cross = in ^ out; return cross.z() < 0.0 ? Ring::ORIENTATION_CW : cross.z() > 0.0 ? Ring::ORIENTATION_CCW : Ring::ORIENTATION_DEGENERATE; }
double Ring::getSignedArea2D | ( | ) | const [virtual] |
Definition at line 488 of file Geometry.cpp.
{ const_cast<Ring*>(this)->open(); double sum = 0.0; for( unsigned i=0; i<size(); ++i ) { const osg::Vec3d& p0 = (*this)[0]; const osg::Vec3d& p1 = i+1 < size() ? (*this)[i+1] : (*this)[0]; sum += p0.x()*p1.y() - p1.x()*p0.y(); } return .5*sum; }
virtual Type osgEarth::Symbology::Ring::getType | ( | ) | const [inline, virtual] |
Implements osgEarth::Symbology::Geometry.
Reimplemented in osgEarth::Symbology::Polygon.
Definition at line 251 of file Geometry.
{ return Geometry::TYPE_RING; }
virtual bool osgEarth::Symbology::Ring::isValid | ( | ) | const [inline, virtual] |
Reimplemented from osgEarth::Symbology::Geometry.
Definition at line 252 of file Geometry.
{ return size() >= 3; }
void Ring::open | ( | ) | [virtual] |
Reimplemented in osgEarth::Symbology::Polygon.
Definition at line 480 of file Geometry.cpp.
void Ring::rewind | ( | Orientation | ori | ) |
Definition at line 505 of file Geometry.cpp.
{ open(); Orientation current = getOrientation(); if ( current != orientation && current != ORIENTATION_DEGENERATE && orientation != ORIENTATION_DEGENERATE ) { std::reverse( begin(), end() ); } }