OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
Public Types | Public Member Functions | Protected Member Functions | Protected Attributes | Friends | List of all members
ossimPolygon Class Reference

#include <ossimPolygon.h>

Public Types

typedef std::vector< ossimPolygonVector
 

Public Member Functions

 ossimPolygon ()
 
 ossimPolygon (const vector< ossimIpt > &polygon)
 
 ossimPolygon (const vector< ossimDpt > &polygon)
 
 ossimPolygon (const vector< ossimGpt > &polygon)
 
 ossimPolygon (int numVertices, const ossimDpt *vertex_array)
 
 ossimPolygon (const ossimPolygon &copy_this)
 
 ossimPolygon (ossimDpt v1, ossimDpt v2, ossimDpt v3, ossimDpt v4)
 CONSTRUCTOR: Provided for convenience. More...
 
 ossimPolygon (const ossimIrect &rect)
 
 ossimPolygon (const ossimDrect &rect)
 
 ~ossimPolygon ()
 
ossimDptoperator[] (int index)
 
const ossimDptoperator[] (int index) const
 
ossim_uint32 getVertexCount () const
 
ossim_uint32 getNumberOfVertices () const
 
double area () const
 Returns polygon area. Negative indicates CW ordering of vertices (in right-handed coordinates) More...
 
void getIntegerBounds (ossim_int32 &minX, ossim_int32 &minY, ossim_int32 &maxX, ossim_int32 &maxY) const
 
void getFloatBounds (ossim_float64 &minX, ossim_float64 &minY, ossim_float64 &maxX, ossim_float64 &maxY) const
 
void getBoundingRect (ossimIrect &rect) const
 
void getBoundingRect (ossimDrect &rect) const
 
void getMinimumBoundingRect (ossimPolygon &minRect) const
 Initializes minRect with the minimum area rect (not-necessarily aligned with axes) that bounds this polygon. More...
 
void roundToIntegerBounds (bool compress=false)
 
void clear ()
 
void addPoint (const ossimDpt &pt)
 
void addPoint (double x, double y)
 
ossimDpt midPoint () const
 
bool hasNans () const
 will sequence through the polygon and check to see if any values are NAN More...
 
const vector< ossimDpt > & getVertexList () const
 
bool clipToRect (vector< ossimPolygon > &result, const ossimDrect &rect) const
 Uses the ossimPolyArea2d class for the intersection. More...
 
bool clipLineSegment (ossimDpt &p1, ossimDpt &p2) const
 METHOD: clipLineSegment(p1, p2) Implements Cyrus-Beck clipping algorithm as described in: http://www.daimi.au.dk/~mbl/cgcourse/wiki/cyrus-beck_line-clipping_.html Clips the line segment defined by thw two endpoints provided. More...
 
bool pointWithin (const ossimDpt &point) const
 METHOD: pointWithin(ossimDpt) Returns TRUE if point is inside polygon. More...
 
bool isPointWithin (const ossimDpt &point) const
 
bool isRectWithin (const ossimIrect &rect) const
 METHOD: isRectWithin() Returns true if all the corner points of the given rect fit within. More...
 
bool rectIntersects (const ossimIrect &rect) const
 METHOD: rectIntersects() Returns true if at least one corner points of the given rect is within. More...
 
bool isPolyWithin (const ossimPolygon &poly) const
 METHOD: isPolyWithin() Returns true if all the vertices of the given polygon fit within. More...
 
bool vertex (int index, ossimDpt &tbd_vertex) const
 METHOD: vertex(index) Returns the ossimDpt vertex given the index. More...
 
bool nextVertex (ossimDpt &tbd_vertex) const
 METHOD: nextVertex() Assigns the ossimDpt tbd_vertex following the current vertex. More...
 
void reverseOrder ()
 
const ossimPolygonoperator= (const ossimPolygon &copy_this)
 OPERATORS: (Some are inlined at bottom) More...
 
const ossimPolygonoperator= (const vector< ossimDpt > &vertexList)
 
const ossimPolygonoperator= (const vector< ossimGpt > &vertexList)
 
const ossimPolygonoperator= (const vector< ossimIpt > &vertexList)
 
const ossimPolygonoperator= (const ossimIrect &rect)
 
const ossimPolygonoperator= (const ossimDrect &rect)
 
bool operator== (const ossimPolygon &compare_this) const
 
bool operator!= (const ossimPolygon &compare_this) const
 
const ossimPolygonoperator*= (const ossimDpt &scale)
 
const ossimPolygonoperator*= (double scale)
 
ossimPolygon operator* (const ossimDpt &scale) const
 
ossimPolygon operator* (double scale) const
 
void resize (ossim_uint32 newSize)
 
void removeVertex (int vertex)
 METHOD: remove() Removes the vertex from the polygon. More...
 
void print (ostream &os) const
 METHOD: print() More...
 
bool saveState (ossimKeywordlist &kwl, const char *prefix=0) const
 
bool loadState (const ossimKeywordlist &kwl, const char *prefix=0)
 
ossimVertexOrdering checkOrdering () const
 
ossimVertexOrdering getOrdering () const
 

Protected Member Functions

void getCentroid (ossimDpt &centroid) const
 METHOD: getCentroid() Assigns the ossimDpt centroid the polygon. More...
 
bool shrink (ossimPolygon &dest, double inset) const
 METHOD: shrink() Shrinks the current polygon by inset, return true if success. More...
 
void removeSmallestContributingVertex ()
 METHOD: removeSmallestContributingVertex() Removes the vertex that contributes the smallest area to the polygon. More...
 
void intersectEdge (ossimDpt &result, const ossimLine &segment, const ossimDrect &rect, int edge)
 
bool isInsideEdge (const ossimDpt &pt, const ossimDrect &rect, int edge) const
 
void fitCircleInsideVertex (ossimDpt &destPt, unsigned int vertex, double radius) const
 Assigns destPt the point that fits a circle of given radius inside the polygon vertex. More...
 

Protected Attributes

ossimVertexOrdering theOrderingType
 
vector< ossimDpttheVertexList
 
ossim_int32 theCurrentVertex
 

Friends

ostream & operator<< (ostream &, const ossimPolygon &)
 

Detailed Description

Definition at line 38 of file ossimPolygon.h.

Member Typedef Documentation

◆ Vector

typedef std::vector<ossimPolygon> ossimPolygon::Vector

Definition at line 41 of file ossimPolygon.h.

Constructor & Destructor Documentation

◆ ossimPolygon() [1/9]

ossimPolygon::ossimPolygon ( )

Definition at line 35 of file ossimPolygon.cpp.

Referenced by shrink().

37  theVertexList(),
39 
40 {}
ossim_int32 theCurrentVertex
Definition: ossimPolygon.h:251
vector< ossimDpt > theVertexList
Definition: ossimPolygon.h:250
ossimVertexOrdering theOrderingType
Definition: ossimPolygon.h:249

◆ ossimPolygon() [2/9]

ossimPolygon::ossimPolygon ( const vector< ossimIpt > &  polygon)

Definition at line 42 of file ossimPolygon.cpp.

References theVertexList.

44  theVertexList(polygon.size()),
46 
47 {
48  // Assign std::vector<ossimIpt> list to std::vector<ossimDpt> theVertexList.
49  for (std::vector<ossimIpt>::size_type i = 0; i < polygon.size(); ++i)
50  {
51  theVertexList[i] = polygon[i];
52  }
53 }
ossim_int32 theCurrentVertex
Definition: ossimPolygon.h:251
vector< ossimDpt > theVertexList
Definition: ossimPolygon.h:250
ossimVertexOrdering theOrderingType
Definition: ossimPolygon.h:249

◆ ossimPolygon() [3/9]

ossimPolygon::ossimPolygon ( const vector< ossimDpt > &  polygon)

Definition at line 69 of file ossimPolygon.cpp.

71  theVertexList(polygon),
73 {
74 }
ossim_int32 theCurrentVertex
Definition: ossimPolygon.h:251
vector< ossimDpt > theVertexList
Definition: ossimPolygon.h:250
ossimVertexOrdering theOrderingType
Definition: ossimPolygon.h:249

◆ ossimPolygon() [4/9]

ossimPolygon::ossimPolygon ( const vector< ossimGpt > &  polygon)

Definition at line 55 of file ossimPolygon.cpp.

References theVertexList.

57  theVertexList(polygon.size()),
59 
60 {
61  // Assign std::vector<ossimIpt> list to std::vector<ossimDpt> theVertexList.
62  for (std::vector<ossimGpt>::size_type i = 0; i < polygon.size(); ++i)
63  {
64  theVertexList[i] = polygon[i];
65  }
66 }
ossim_int32 theCurrentVertex
Definition: ossimPolygon.h:251
vector< ossimDpt > theVertexList
Definition: ossimPolygon.h:250
ossimVertexOrdering theOrderingType
Definition: ossimPolygon.h:249

◆ ossimPolygon() [5/9]

ossimPolygon::ossimPolygon ( int  numVertices,
const ossimDpt vertex_array 
)

Definition at line 80 of file ossimPolygon.cpp.

References theVertexList.

83 
84 {
85  theVertexList.insert(theVertexList.begin(),
86  v, v+numVertices);
87 }
ossim_int32 theCurrentVertex
Definition: ossimPolygon.h:251
vector< ossimDpt > theVertexList
Definition: ossimPolygon.h:250
ossimVertexOrdering theOrderingType
Definition: ossimPolygon.h:249

◆ ossimPolygon() [6/9]

ossimPolygon::ossimPolygon ( const ossimPolygon copy_this)

Definition at line 93 of file ossimPolygon.cpp.

95 {
96  *this = polygon;
97 }
ossim_int32 theCurrentVertex
Definition: ossimPolygon.h:251

◆ ossimPolygon() [7/9]

ossimPolygon::ossimPolygon ( ossimDpt  v1,
ossimDpt  v2,
ossimDpt  v3,
ossimDpt  v4 
)

CONSTRUCTOR: Provided for convenience.

Does not imply the polygon is limited to four vertices:

Definition at line 106 of file ossimPolygon.cpp.

References theVertexList.

111  theVertexList(4),
113 
114 {
115  theVertexList[0] = v1;
116  theVertexList[1] = v2;
117  theVertexList[2] = v3;
118  theVertexList[3] = v4;
119 }
ossim_int32 theCurrentVertex
Definition: ossimPolygon.h:251
vector< ossimDpt > theVertexList
Definition: ossimPolygon.h:250
ossimVertexOrdering theOrderingType
Definition: ossimPolygon.h:249

◆ ossimPolygon() [8/9]

ossimPolygon::ossimPolygon ( const ossimIrect rect)

Definition at line 121 of file ossimPolygon.cpp.

References ossimIrect::ll(), ossimIrect::lr(), theVertexList, ossimIrect::ul(), and ossimIrect::ur().

123  theVertexList(4),
125 {
126  theVertexList[0] = rect.ul();
127  theVertexList[1] = rect.ur();
128  theVertexList[2] = rect.lr();
129  theVertexList[3] = rect.ll();
130 }
const ossimIpt & ul() const
Definition: ossimIrect.h:274
const ossimIpt & ll() const
Definition: ossimIrect.h:277
const ossimIpt & lr() const
Definition: ossimIrect.h:276
const ossimIpt & ur() const
Definition: ossimIrect.h:275
ossim_int32 theCurrentVertex
Definition: ossimPolygon.h:251
vector< ossimDpt > theVertexList
Definition: ossimPolygon.h:250
ossimVertexOrdering theOrderingType
Definition: ossimPolygon.h:249

◆ ossimPolygon() [9/9]

ossimPolygon::ossimPolygon ( const ossimDrect rect)

Definition at line 132 of file ossimPolygon.cpp.

References ossimDrect::ll(), ossimDrect::lr(), theVertexList, ossimDrect::ul(), and ossimDrect::ur().

134 theVertexList(4),
136 {
137  theVertexList[0] = rect.ul();
138  theVertexList[1] = rect.ur();
139  theVertexList[2] = rect.lr();
140  theVertexList[3] = rect.ll();
141 }
const ossimDpt & ul() const
Definition: ossimDrect.h:339
const ossimDpt & ur() const
Definition: ossimDrect.h:340
ossim_int32 theCurrentVertex
Definition: ossimPolygon.h:251
const ossimDpt & ll() const
Definition: ossimDrect.h:342
vector< ossimDpt > theVertexList
Definition: ossimPolygon.h:250
ossimVertexOrdering theOrderingType
Definition: ossimPolygon.h:249
const ossimDpt & lr() const
Definition: ossimDrect.h:341

◆ ~ossimPolygon()

ossimPolygon::~ossimPolygon ( )

Definition at line 148 of file ossimPolygon.cpp.

149 {
150 }

Member Function Documentation

◆ addPoint() [1/2]

void ossimPolygon::addPoint ( const ossimDpt pt)

◆ addPoint() [2/2]

void ossimPolygon::addPoint ( double  x,
double  y 
)

Definition at line 1140 of file ossimPolygon.cpp.

References OSSIM_VERTEX_ORDER_UNKNOWN, theOrderingType, theVertexList, x, and y.

1141 {
1142  theVertexList.push_back(ossimDpt(x, y));
1144 }
ossim_uint32 x
ossim_uint32 y
vector< ossimDpt > theVertexList
Definition: ossimPolygon.h:250
ossimVertexOrdering theOrderingType
Definition: ossimPolygon.h:249

◆ area()

double ossimPolygon::area ( ) const

Returns polygon area. Negative indicates CW ordering of vertices (in right-handed coordinates)

Returns polygon area. Negative indicates CW ordering of vertices (in right-handed coordinates.

Definition at line 156 of file ossimPolygon.cpp.

References size, and theVertexList.

Referenced by checkOrdering(), getCentroid(), getMinimumBoundingRect(), ATP::AtpGenerator::layoutSearchTileRects(), and removeSmallestContributingVertex().

157 {
158  double area = 0;
159  ossim_uint32 i=0;
160  ossim_uint32 j=0;
162 
163  for (i=0;i<size;i++)
164  {
165  j = (i + 1) % (int)size;
166  area += theVertexList[i].x * theVertexList[j].y;
167  area -= theVertexList[i].y * theVertexList[j].x;
168  }
169 
170  area /= 2;
171 
172  return area;
173 }
yy_size_t size
unsigned int ossim_uint32
double area() const
Returns polygon area. Negative indicates CW ordering of vertices (in right-handed coordinates) ...
vector< ossimDpt > theVertexList
Definition: ossimPolygon.h:250

◆ checkOrdering()

ossimVertexOrdering ossimPolygon::checkOrdering ( ) const

Definition at line 701 of file ossimPolygon.cpp.

References area(), OSSIM_CLOCKWISE_ORDER, OSSIM_COUNTERCLOCKWISE_ORDER, OSSIM_VERTEX_ORDER_UNKNOWN, and theOrderingType.

Referenced by clipLineSegment(), fitCircleInsideVertex(), getMinimumBoundingRect(), and ossimImageHandler::writeValidImageVertices().

702 {
704  {
705  double areaValue = area();
706  if(areaValue > 0)
707  {
709  }
710  else if(areaValue <= 0)
711  {
713  }
714  }
715 
716  return theOrderingType;
717 }
double area() const
Returns polygon area. Negative indicates CW ordering of vertices (in right-handed coordinates) ...
ossimVertexOrdering theOrderingType
Definition: ossimPolygon.h:249

◆ clear()

void ossimPolygon::clear ( )

◆ clipLineSegment()

bool ossimPolygon::clipLineSegment ( ossimDpt p1,
ossimDpt p2 
) const

METHOD: clipLineSegment(p1, p2) Implements Cyrus-Beck clipping algorithm as described in: http://www.daimi.au.dk/~mbl/cgcourse/wiki/cyrus-beck_line-clipping_.html Clips the line segment defined by thw two endpoints provided.

The endpoints are modified as needed to represent the clipped line. Returnes true if intersection present.

Definition at line 344 of file ossimPolygon.cpp.

References checkOrdering(), ossimLine::normal(), OSSIM_COUNTERCLOCKWISE_ORDER, theOrderingType, ossimLine::theP1, theVertexList, ossimDpt::x, and ossimDpt::y.

345 {
346  ossimDpt PQ (Q - P);
347  double tE = 0.0;
348  double tL = 1.0;
349  ossimLine edge, edgeE, edgeL;
350  bool intersected=false;
351  double num, denom, t;
352  ossim_uint32 npol = (ossim_uint32)theVertexList.size();
353 
354  checkOrdering();
355  //***
356  // clip the segment against each edge of the polygon
357  //***
358  ossim_uint32 i = 0;
359  ossim_uint32 j = 0;
360  for(i = 0, j = 1; i < npol;)
361  {
362  edge = ossimLine(theVertexList[i],
363  theVertexList[j]);
364 
365  ossimDpt normal = edge.normal();
366 
367  // Fix from CChuah@observera.com for counter clockwise polygons. (drb)
369  {
370  normal.x = -normal.x;
371  normal.y = -normal.y;
372  }
373 
374  denom = normal.x*PQ.x + normal.y*PQ.y;
375 
376  num = normal.x*(edge.theP1.x - P.x) + normal.y*(edge.theP1.y - P.y);
377 
378  if (denom < 0)
379  {
380  //***
381  // Appears to be entering:
382  //***
383  t = num / denom;
384  if (t > tE)
385  {
386  tE = t; //+ FLT_EPSILON;
387  edgeE = edge;
388  }
389  }
390  else if (denom > 0)
391  {
392  //***
393  // Appears to be leaving:
394  //***
395  t = num / denom;
396  if (t < tL)
397  {
398  tL = t;// - FLT_EPSILON;
399  edgeL = edge;
400  }
401  }
402 
403  ++i;
404  ++j;
405  j%=npol;
406  }
407 
408  //***
409  // Compute clipped end points:
410  //***
411  if(tL >= tE)
412  {
413  Q.x = P.x + tL*PQ.x;
414  Q.y = P.y + tL*PQ.y;
415  P.x += tE*PQ.x;
416  P.y += tE*PQ.y;
417  intersected = true;
418  }
419 
420  return intersected;
421 }
ossimDpt theP1
Definition: ossimLine.h:77
double y
Definition: ossimDpt.h:165
ossimVertexOrdering checkOrdering() const
ossimDpt normal() const
Definition: ossimLine.cpp:135
unsigned int ossim_uint32
double x
Definition: ossimDpt.h:164
vector< ossimDpt > theVertexList
Definition: ossimPolygon.h:250
ossimVertexOrdering theOrderingType
Definition: ossimPolygon.h:249

◆ clipToRect()

bool ossimPolygon::clipToRect ( vector< ossimPolygon > &  result,
const ossimDrect rect 
) const

Uses the ossimPolyArea2d class for the intersection.

Definition at line 319 of file ossimPolygon.cpp.

References ossimPolyArea2d::getVisiblePolygons(), ossimDrect::ll(), ossimDrect::lr(), ossimDrect::ul(), and ossimDrect::ur().

Referenced by ossimImageGeometry::calculatePolyBounds(), ossimAnnotationMultiPolyObject::draw(), ossimAnnotationPolyObject::draw(), ossimAnnotationPolyObject::getNewClippedObject(), ossimImageViewProjectionTransform::getViewSegments(), and ossimAnnotationPolyObject::intersects().

321 {
322  result.clear();
323  ossimPolyArea2d p1(*this);
324  ossimPolyArea2d p2(rect.ul(), rect.ur(), rect.lr(), rect.ll());
325 
326  p1&=p2;
327 
328  p1.getVisiblePolygons(result);
329 
330  return (result.size() > 0);
331 }
const ossimDpt & ul() const
Definition: ossimDrect.h:339
const ossimDpt & ur() const
Definition: ossimDrect.h:340
const ossimDpt & ll() const
Definition: ossimDrect.h:342
const ossimDpt & lr() const
Definition: ossimDrect.h:341
bool getVisiblePolygons(vector< ossimPolygon > &polyList) const

◆ fitCircleInsideVertex()

void ossimPolygon::fitCircleInsideVertex ( ossimDpt destPt,
unsigned int  vertex,
double  radius 
) const
protected

Assigns destPt the point that fits a circle of given radius inside the polygon vertex.

METHOD: fitCircleInsideVertex() Assigns destPt the point that fits a circle of given radius inside the polygon vertex.

Warning: destPt is not guaranteed to be inside the polygon! (you may not be able to fit a circle of the given radius inside the polygon)

Definition at line 1222 of file ossimPolygon.cpp.

References checkOrdering(), getOrdering(), ossimDpt::length(), OSSIM_COUNTERCLOCKWISE_ORDER, theVertexList, vertex(), ossimDpt::x, and ossimDpt::y.

Referenced by shrink().

1223 {
1224  ossim_uint32 num_vertices=(int)theVertexList.size(),n1,n2;
1225  ossimDpt side1,side2,bisection,currpt;
1226  double length_out,side1_side2_cross;
1227  bool concave=true;
1228 
1229  // don't be doing that dude.
1230  if(num_vertices<3 || vertex>=num_vertices) {
1231  destPt=ossimDpt(0,0);
1232  return;
1233  }
1234 
1235  if(vertex==0) {
1236  n1=num_vertices-1;
1237  n2=vertex+1;
1238  } else if(vertex==num_vertices-1) {
1239  n1=num_vertices-2;
1240  n2=0;
1241  } else {
1242  n1=vertex-1;
1243  n2=vertex+1;
1244  }
1245 
1246  currpt=theVertexList[vertex];
1247  // get the side vectors
1248  side1=theVertexList[n1]-currpt;
1249  side2=theVertexList[n2]-currpt;
1250 
1251  // normalize the sides
1252  side1 = side1/side1.length();
1253  side2 = side2/side2.length();
1254 
1255  side1_side2_cross=side1.x*side2.y-side2.x*side1.y;
1256 
1257  checkOrdering();
1259  if(side1_side2_cross<0)
1260  concave=false;
1261  } else { //clockwise
1262  if(side1_side2_cross>0)
1263  concave=false;
1264  }
1265 
1266  bisection = side1+side2;
1267  bisection = bisection/bisection.length();
1268 
1269  if(concave) {
1270  bisection=bisection*-1.0;
1271  length_out=radius;
1272  } else {
1273  double cos_theta=(side1.x*bisection.x+side1.y*bisection.y);
1274  length_out=radius/sqrt(1-cos_theta*cos_theta);
1275  }
1276  destPt=ossimDpt(currpt+bisection*length_out);
1277  return;
1278 }
double y
Definition: ossimDpt.h:165
ossimVertexOrdering checkOrdering() const
ossimVertexOrdering getOrdering() const
bool vertex(int index, ossimDpt &tbd_vertex) const
METHOD: vertex(index) Returns the ossimDpt vertex given the index.
double length() const
Definition: ossimDpt.h:81
unsigned int ossim_uint32
double x
Definition: ossimDpt.h:164
vector< ossimDpt > theVertexList
Definition: ossimPolygon.h:250

◆ getBoundingRect() [1/2]

void ossimPolygon::getBoundingRect ( ossimIrect rect) const

Definition at line 1108 of file ossimPolygon.cpp.

References getIntegerBounds().

Referenced by ossimActiveEdgeTable::createTable(), and ATP::AtpGenerator::layoutSearchTileRects().

1109 {
1110  ossim_int32 minX;
1111  ossim_int32 minY;
1112  ossim_int32 maxX;
1113  ossim_int32 maxY;
1114  getIntegerBounds(minX, minY, maxX, maxY);
1115  rect = ossimIrect(minX, minY, maxX, maxY);
1116 }
void getIntegerBounds(ossim_int32 &minX, ossim_int32 &minY, ossim_int32 &maxX, ossim_int32 &maxY) const
int ossim_int32

◆ getBoundingRect() [2/2]

void ossimPolygon::getBoundingRect ( ossimDrect rect) const

Definition at line 1118 of file ossimPolygon.cpp.

References getFloatBounds().

1119 {
1120  ossim_float64 minX;
1121  ossim_float64 minY;
1122  ossim_float64 maxX;
1123  ossim_float64 maxY;
1124  getFloatBounds(minX, minY, maxX, maxY);
1125  rect = ossimDrect(minX, minY, maxX, maxY);
1126 }
void getFloatBounds(ossim_float64 &minX, ossim_float64 &minY, ossim_float64 &maxX, ossim_float64 &maxY) const
double ossim_float64

◆ getCentroid()

void ossimPolygon::getCentroid ( ossimDpt centroid) const
protected

METHOD: getCentroid() Assigns the ossimDpt centroid the polygon.

Warning: centroid is not guaranteed to be inside the polygon!

Definition at line 1194 of file ossimPolygon.cpp.

References area(), theVertexList, ossimDpt::x, and ossimDpt::y.

1195 {
1196  int numpts = (int)theVertexList.size();
1197  unsigned int next;
1198  double area=0,parea;
1199 
1200  centroid=ossimDpt(0,0);
1201  for(int i=0;i<numpts;i++) {
1202  if(i<numpts-1) {
1203  next=i+1;
1204  } else {
1205  next=0;
1206  }
1207  parea=theVertexList[i].x*theVertexList[next].y-theVertexList[next].x*theVertexList[i].y;
1208  area+=parea;
1209  centroid.x+=(theVertexList[i].x+theVertexList[next].x)*parea;
1210  centroid.y+=(theVertexList[i].y+theVertexList[next].y)*parea;
1211  }
1212  area=area/2.0;
1213  centroid=centroid/(area*6.0);
1214 }
double y
Definition: ossimDpt.h:165
double area() const
Returns polygon area. Negative indicates CW ordering of vertices (in right-handed coordinates) ...
double x
Definition: ossimDpt.h:164
vector< ossimDpt > theVertexList
Definition: ossimPolygon.h:250

◆ getFloatBounds()

void ossimPolygon::getFloatBounds ( ossim_float64 minX,
ossim_float64 minY,
ossim_float64 maxX,
ossim_float64 maxY 
) const

Definition at line 287 of file ossimPolygon.cpp.

References ossim::nan(), theVertexList, x, and y.

Referenced by getBoundingRect().

291 {
292  ossim_int32 npoly = (ossim_int32)theVertexList.size();
293  int i = 0;
294 
295  if(npoly)
296  {
297  minX = floor(theVertexList[0].x);
298  maxX = ceil(theVertexList[0].x);
299  minY = floor(theVertexList[0].y);
300  maxY = ceil(theVertexList[0].y);
301 
302  for(i =1; i < npoly; ++i)
303  {
304  minX = std::min<double>(floor(theVertexList[i].x), minX);
305  maxX = std::max<double>(ceil(theVertexList[i].x), maxX);
306  minY = std::min<double>(floor(theVertexList[i].y), minY);
307  maxY = std::max<double>(ceil(theVertexList[i].y), maxY);
308  }
309  }
310  else
311  {
312  minX = ossim::nan();
313  minY = ossim::nan();
314  maxX = ossim::nan();
315  maxY = ossim::nan();
316  }
317 }
ossim_uint32 x
ossim_uint32 y
double nan()
Method to return ieee floating point double precision NAN.
Definition: ossimCommon.h:135
vector< ossimDpt > theVertexList
Definition: ossimPolygon.h:250
int ossim_int32

◆ getIntegerBounds()

void ossimPolygon::getIntegerBounds ( ossim_int32 minX,
ossim_int32 minY,
ossim_int32 maxX,
ossim_int32 maxY 
) const

Definition at line 251 of file ossimPolygon.cpp.

References max, min, OSSIM_INT_NAN, theVertexList, x, and y.

Referenced by ossimImageDataHelper::copyInputToThis(), ossimImageDataHelper::fill(), and getBoundingRect().

255 {
256  ossim_int32 npoly = (ossim_int32)theVertexList.size();
257  int i = 0;
258 
259  if(npoly)
260  {
261  minX = (ossim_int32)floor(theVertexList[0].x);
262  maxX = (ossim_int32)ceil(theVertexList[0].x);
263  minY = (ossim_int32)floor(theVertexList[0].y);
264  maxY = (ossim_int32)ceil(theVertexList[0].y);
265 
266  for(i =1; i < npoly; ++i)
267  {
268  minX = std::min((ossim_int32)floor(theVertexList[i].x),
269  (ossim_int32)minX);
270  maxX = std::max((ossim_int32)ceil(theVertexList[i].x),
271  (ossim_int32)maxX);
272  minY = std::min((ossim_int32)floor(theVertexList[i].y),
273  (ossim_int32)minY);
274  maxY = std::max((ossim_int32)ceil(theVertexList[i].y),
275  (ossim_int32)maxY);
276  }
277  }
278  else
279  {
280  minX = OSSIM_INT_NAN;
281  minY = OSSIM_INT_NAN;
282  maxX = OSSIM_INT_NAN;
283  maxY = OSSIM_INT_NAN;
284  }
285 }
ossim_uint32 x
ossim_uint32 y
#define OSSIM_INT_NAN
#define max(a, b)
Definition: auxiliary.h:76
vector< ossimDpt > theVertexList
Definition: ossimPolygon.h:250
#define min(a, b)
Definition: auxiliary.h:75
int ossim_int32

◆ getMinimumBoundingRect()

void ossimPolygon::getMinimumBoundingRect ( ossimPolygon minRect) const

Initializes minRect with the minimum area rect (not-necessarily aligned with axes) that bounds this polygon.

Parameters
minRectPolygon to initialize with the minimum rect.

Definition at line 887 of file ossimPolygon.cpp.

References addPoint(), area(), checkOrdering(), clear(), DBL_EPSILON, getOrdering(), ossimDrect::ll(), ossimDrect::lr(), M_PI, OSSIM_COUNTERCLOCKWISE_ORDER, OSSIM_RIGHT_HANDED, reverseOrder(), theVertexList, ossimDrect::ul(), ossimDrect::ur(), vertex(), ossimDpt::x, x, ossimDpt::y, and y.

888 {
889  static const double MIN_STEP = (0.5)*M_PI/180.0;
890  double angle_step = M_PI/8.0; // initial rotation step size for min area search = 22.5 deg
891  double theta;
892  double best_theta = M_PI/4.0; // Initial guess is 45 deg orientation
893  double center_theta;
894  double cos_theta, sin_theta;
895  ossimPolygon rotatedPolygon(*this);
896  ossimDpt xlatedVertex;
897  ossimDpt rotatedVertex(0.0, 0.0);
898  double min_x, min_y, max_x, max_y;
899  double area;
900  double min_area = 1.0/DBL_EPSILON;
901  rotatedPolygon.theVertexList[0] = ossimDpt(0, 0); // first vertex always at origin
902  bool first_time = true;
903  ossimDrect best_rect;
904  static const bool TESTING = false;
905 
906  //***
907  // Loop to converge on best orientation angle for bounding polygon:
908  //***
909  while (angle_step > MIN_STEP)
910  {
911  //***
912  // Try four different rotations evenly centered about the current best guess:
913  //***
914  center_theta = best_theta;
915  for (int i=0; i<5; i++)
916  {
917  //***
918  // Check for i=2 (center angle) since already computed quantities for this in last iteration
919  // unless this is first time through:
920  //***
921  if ((i != 2) || (first_time))
922  {
923  theta = center_theta + (i - 2.0)*angle_step;
924  cos_theta = cos(theta);
925  sin_theta = sin(theta);
926  min_x = rotatedPolygon.theVertexList[0].x;
927  min_y = rotatedPolygon.theVertexList[0].y;
928  max_x = min_x;
929  max_y = min_y;
930 
931  //***
932  // Translate polygon to origin and rotate all vertices by current theta:
933  //***
934  for (unsigned int vertex=1; vertex < theVertexList.size(); vertex++)
935  {
936  xlatedVertex.x = theVertexList[vertex].x - theVertexList[0].x;
937  xlatedVertex.y = theVertexList[vertex].y - theVertexList[0].y;
938  rotatedVertex.x = cos_theta*xlatedVertex.x + sin_theta*xlatedVertex.y;
939  rotatedVertex.y = cos_theta*xlatedVertex.y - sin_theta*xlatedVertex.x;
940  rotatedPolygon.theVertexList[vertex] = rotatedVertex;
941 
942  //***
943  // Latch max and mins of bounding rect:
944  //***
945  if (min_x > rotatedVertex.x) min_x = rotatedVertex.x;
946  if (min_y > rotatedVertex.y) min_y = rotatedVertex.y;
947  if (max_x < rotatedVertex.x) max_x = rotatedVertex.x;
948  if (max_y < rotatedVertex.y) max_y = rotatedVertex.y;
949  }
950 
951  if (TESTING)
952  {
953  ossimDpt v1 (cos_theta*min_x - sin_theta*max_y + theVertexList[0].x,
954  cos_theta*max_y + sin_theta*min_x + theVertexList[0].y);
955  ossimDpt v2 (cos_theta*max_x - sin_theta*max_y + theVertexList[0].x,
956  cos_theta*max_y + sin_theta*max_x + theVertexList[0].y);
957  ossimDpt v3 (cos_theta*max_x - sin_theta*min_y + theVertexList[0].x,
958  cos_theta*min_y + sin_theta*max_x + theVertexList[0].y);
959  ossimDpt v4 (cos_theta*min_x - sin_theta*min_y + theVertexList[0].x,
960  cos_theta*min_y + sin_theta*min_x + theVertexList[0].y);
961  cout << v1.x << "\t" << v1.y << endl;
962  cout << v2.x << "\t" << v2.y << endl;
963  cout << v3.x << "\t" << v3.y << endl;
964  cout << v4.x << "\t" << v4.y << endl << endl;
965  }
966 
967  //***
968  // Establish bounding rect and area about rotated polygon:
969  //***
970  area = (max_x - min_x) * (max_y - min_y);
971  if (area < min_area)
972  {
973  best_theta = theta;
974  min_area = area;
975  best_rect = ossimDrect(min_x, max_y, max_x, min_y, OSSIM_RIGHT_HANDED);
976  }
977  } // end if (i != 2 || first_time)
978  } // end for-loop over surrounding rotations
979 
980  //***
981  // Adjust step size by half to repeat process:
982  //***
983  angle_step /= 2.0;
984  first_time = false;
985 
986  } // end while loop for convergence
987 
988  //***
989  // best_theta now contains optimum rotation of bounding rect. Need to apply reverse
990  // rotation and translation of best_rect:
991  //***
992  cos_theta = cos(best_theta);
993  sin_theta = sin(best_theta);
994  ossimDpt v1 (cos_theta*best_rect.ul().x - sin_theta*best_rect.ul().y + theVertexList[0].x,
995  cos_theta*best_rect.ul().y + sin_theta*best_rect.ul().x + theVertexList[0].y);
996  ossimDpt v2 (cos_theta*best_rect.ur().x - sin_theta*best_rect.ur().y + theVertexList[0].x,
997  cos_theta*best_rect.ur().y + sin_theta*best_rect.ur().x + theVertexList[0].y);
998  ossimDpt v3 (cos_theta*best_rect.lr().x - sin_theta*best_rect.lr().y + theVertexList[0].x,
999  cos_theta*best_rect.lr().y + sin_theta*best_rect.lr().x + theVertexList[0].y);
1000  ossimDpt v4 (cos_theta*best_rect.ll().x - sin_theta*best_rect.ll().y + theVertexList[0].x,
1001  cos_theta*best_rect.ll().y + sin_theta*best_rect.ll().x + theVertexList[0].y);
1002 
1003  if (TESTING)
1004  {
1005  cout << v1.x << "\t" << v1.y << endl;
1006  cout << v2.x << "\t" << v2.y << endl;
1007  cout << v3.x << "\t" << v3.y << endl;
1008  cout << v4.x << "\t" << v4.y << endl << endl;
1009  }
1010 
1011  //***
1012  // Assign return value rect:
1013  //***
1014  minRect.clear();
1015  minRect.addPoint(v1);
1016  minRect.addPoint(v2);
1017  minRect.addPoint(v3);
1018  minRect.addPoint(v4);
1019 
1020  // Make sure we are always returning a positive clockwise area.
1021  minRect.checkOrdering();
1023  minRect.reverseOrder();
1024  return;
1025 }
ossim_uint32 x
ossim_uint32 y
const ossimDpt & ul() const
Definition: ossimDrect.h:339
void addPoint(const ossimDpt &pt)
double y
Definition: ossimDpt.h:165
ossimVertexOrdering checkOrdering() const
ossimVertexOrdering getOrdering() const
bool vertex(int index, ossimDpt &tbd_vertex) const
METHOD: vertex(index) Returns the ossimDpt vertex given the index.
#define M_PI
#define DBL_EPSILON
void reverseOrder()
const ossimDpt & ur() const
Definition: ossimDrect.h:340
double area() const
Returns polygon area. Negative indicates CW ordering of vertices (in right-handed coordinates) ...
double x
Definition: ossimDpt.h:164
const ossimDpt & ll() const
Definition: ossimDrect.h:342
vector< ossimDpt > theVertexList
Definition: ossimPolygon.h:250
const ossimDpt & lr() const
Definition: ossimDrect.h:341

◆ getNumberOfVertices()

ossim_uint32 ossimPolygon::getNumberOfVertices ( ) const

◆ getOrdering()

ossimVertexOrdering ossimPolygon::getOrdering ( ) const

Definition at line 1173 of file ossimPolygon.cpp.

References theOrderingType.

Referenced by fitCircleInsideVertex(), getMinimumBoundingRect(), and ossimImageHandler::writeValidImageVertices().

1174 {
1175  return theOrderingType;
1176 }
ossimVertexOrdering theOrderingType
Definition: ossimPolygon.h:249

◆ getVertexCount()

ossim_uint32 ossimPolygon::getVertexCount ( ) const

◆ getVertexList()

const vector< ossimDpt > & ossimPolygon::getVertexList ( ) const

Definition at line 1146 of file ossimPolygon.cpp.

References theVertexList.

Referenced by ATP::AtpAnnotatedImage::annotateOverlap(), and OssimPolyArea2dPrivate::setGeometry().

1147 {
1148  return theVertexList;
1149 }
vector< ossimDpt > theVertexList
Definition: ossimPolygon.h:250

◆ hasNans()

bool ossimPolygon::hasNans ( ) const

will sequence through the polygon and check to see if any values are NAN

Definition at line 235 of file ossimPolygon.cpp.

References theVertexList.

Referenced by ossimApplanixUtmModel::worldToLineSample(), ossimSpectraboticsRedEdgeModel::worldToLineSample(), ossimApplanixEcefModel::worldToLineSample(), ossimH5GridModel::worldToLineSample(), and ossimSensorModel::worldToLineSample().

236 {
237  int upper = (int)theVertexList.size();
238  int i = 0;
239 
240  for(i = 0; i < upper; ++i)
241  {
242  if(theVertexList[i].hasNans())
243  {
244  return true;
245  }
246  }
247 
248  return false;
249 }
bool hasNans() const
will sequence through the polygon and check to see if any values are NAN
vector< ossimDpt > theVertexList
Definition: ossimPolygon.h:250

◆ intersectEdge()

void ossimPolygon::intersectEdge ( ossimDpt result,
const ossimLine segment,
const ossimDrect rect,
int  edge 
)
protected

Definition at line 719 of file ossimPolygon.cpp.

723 {
724  ossimLine edgeLine;
725  switch(edge)
726  {
727  case RECT_LEFT_EDGE:
728  {
729  edgeLine.theP1 = rect.ll();
730  edgeLine.theP2 = rect.ul();
731  break;
732  }
733  case RECT_TOP_EDGE:
734  {
735  edgeLine.theP1 = rect.ul();
736  edgeLine.theP2 = rect.ur();
737  break;
738  }
739  case RECT_RIGHT_EDGE:
740  {
741  edgeLine.theP1 = rect.ur();
742  edgeLine.theP2 = rect.lr();
743  break;
744  }
745  case RECT_BOTTOM_EDGE:
746  {
747  edgeLine.theP1 = rect.lr();
748  edgeLine.theP2 = rect.ll();
749  break;
750  }
751  }
752 
753  result = segment.intersectInfinite(edgeLine);
754 }
ossimDpt theP1
Definition: ossimLine.h:77
const ossimDpt & ul() const
Definition: ossimDrect.h:339
ossimDpt intersectInfinite(const ossimLine &line) const
Definition: ossimLine.cpp:20
ossimDpt theP2
Definition: ossimLine.h:78
const ossimDpt & ur() const
Definition: ossimDrect.h:340
const ossimDpt & ll() const
Definition: ossimDrect.h:342
const ossimDpt & lr() const
Definition: ossimDrect.h:341

◆ isInsideEdge()

bool ossimPolygon::isInsideEdge ( const ossimDpt pt,
const ossimDrect rect,
int  edge 
) const
protected

Definition at line 756 of file ossimPolygon.cpp.

759 {
760  switch(edge)
761  {
762  case RECT_LEFT_EDGE:
763  {
764  return (pt.x>rect.ul().x);
765  break;
766  }
767  case RECT_TOP_EDGE:
768  {
769  if(rect.orientMode() == OSSIM_LEFT_HANDED)
770  {
771  return (pt.y > rect.ul().y);
772  }
773  else
774  {
775  return (pt.y < rect.ul().y);
776  }
777  break;
778  }
779  case RECT_RIGHT_EDGE:
780  {
781  return (pt.x<rect.lr().x);
782 
783  break;
784  }
785  case RECT_BOTTOM_EDGE:
786  {
787  if(rect.orientMode() == OSSIM_LEFT_HANDED)
788  {
789  return (pt.y < rect.lr().y);
790  }
791  else
792  {
793  return (pt.y > rect.lr().y);
794  }
795  break;
796  }
797  }
798  return false;
799 }
const ossimDpt & ul() const
Definition: ossimDrect.h:339
double y
Definition: ossimDpt.h:165
ossimCoordSysOrientMode orientMode() const
Definition: ossimDrect.h:414
double x
Definition: ossimDpt.h:164
const ossimDpt & lr() const
Definition: ossimDrect.h:341

◆ isPointWithin()

bool ossimPolygon::isPointWithin ( const ossimDpt point) const

Definition at line 476 of file ossimPolygon.cpp.

References theVertexList, ossimDpt::x, ossimDpt::y, and y.

Referenced by ossimPixelFlipper::clipTile(), ossimDilationFilter::doDilation(), ossimErosionFilter::doErosion(), isPolyWithin(), isRectWithin(), pointWithin(), and rectIntersects().

477 {
478 
479  int i, j, c = 0;
480  int npol = (int)theVertexList.size();
481 
482  for (i = 0, j = npol-1; i < npol; j = i++)
483  {
484  if ((((theVertexList[i].y <= point.y) && (point.y < theVertexList[j].y)) ||
485  ((theVertexList[j].y <= point.y) && (point.y < theVertexList[i].y))) &&
486  (point.x < (theVertexList[j].x - theVertexList[i].x) * (point.y - theVertexList[i].y) /
487  (theVertexList[j].y - theVertexList[i].y) + theVertexList[i].x))
488  {
489  c = !c;
490  }
491  }
492 
493  if(!c) // check if on if not within
494  {
495  for (i = 0, j = npol-1; i < npol; j = i++)
496  {
498  {
499  return true;
500  }
501  }
502  }
503 
504  return (c!=0);
505 }
ossim_uint32 y
double y
Definition: ossimDpt.h:165
bool isPointWithin(const ossimDpt &point) const
double x
Definition: ossimDpt.h:164
vector< ossimDpt > theVertexList
Definition: ossimPolygon.h:250

◆ isPolyWithin()

bool ossimPolygon::isPolyWithin ( const ossimPolygon poly) const

METHOD: isPolyWithin() Returns true if all the vertices of the given polygon fit within.

Definition at line 454 of file ossimPolygon.cpp.

References getNumberOfVertices(), and isPointWithin().

Referenced by shrink().

455 {
456  bool ret=false;
457  int numvertex=poly.getNumberOfVertices();
458  if(getNumberOfVertices()>1 && numvertex) {
459  ret=true;
460  for(int v=0;v<numvertex;v++) {
461  if(!isPointWithin(poly[v])) {
462  ret=false;
463  break;
464  }
465  }
466  }
467  return ret;
468 }
ossim_uint32 getNumberOfVertices() const
bool isPointWithin(const ossimDpt &point) const

◆ isRectWithin()

bool ossimPolygon::isRectWithin ( const ossimIrect rect) const

METHOD: isRectWithin() Returns true if all the corner points of the given rect fit within.

Definition at line 427 of file ossimPolygon.cpp.

References isPointWithin(), ossimIrect::ll(), ossimIrect::lr(), ossimIrect::ul(), and ossimIrect::ur().

Referenced by ATP::AtpGenerator::layoutSearchTileRects().

428 {
429  if(isPointWithin(rect.ul()) &&
430  isPointWithin(rect.ur()) &&
431  isPointWithin(rect.ll()) &&
432  isPointWithin(rect.lr())) {
433  return true;
434  }
435  return false;
436 }
const ossimIpt & ul() const
Definition: ossimIrect.h:274
const ossimIpt & ll() const
Definition: ossimIrect.h:277
const ossimIpt & lr() const
Definition: ossimIrect.h:276
const ossimIpt & ur() const
Definition: ossimIrect.h:275
bool isPointWithin(const ossimDpt &point) const

◆ loadState()

bool ossimPolygon::loadState ( const ossimKeywordlist kwl,
const char *  prefix = 0 
)

Definition at line 852 of file ossimPolygon.cpp.

References ossimKeywordlist::find().

854 {
855  ossimString order = kwl.find(prefix, VERTEX_ORDER_KW);
856  const char* number_vertices = kwl.find(prefix, NUMBER_VERTICES_KW);
857  ossimString x,y;
858  if(order=="unknown")
859  {
861  }
862  else if(order =="clockwise")
863  {
865  }
866  else if(order =="counter_clockwise")
867  {
869  }
870 
871  theVertexList.clear();
872  int vertexCount = ossimString(number_vertices).toLong();
873  int i = 0;
874  for(i = 0; i < vertexCount; ++i)
875  {
876  ossimString v = kwl.find(prefix, (ossimString("v")+ossimString::toString(i)).c_str());
877  v = v.trim();
878 
879  istringstream vStream(v.string());
880  vStream >> x.string() >> y.string();
881  theVertexList.push_back(ossimDpt(x.toDouble(),y.toDouble()));
882  }
883 
884  return true;
885 }
ossim_uint32 x
ossim_uint32 y
const char * find(const char *key) const
static ossimString toString(bool aValue)
Numeric to string methods.
ossimString trim(const ossimString &valueToTrim=ossimString(" \\)) const
this will strip lead and trailing character passed in.
long toLong() const
toLong&#39;s deprecated, please use the toInts...
vector< ossimDpt > theVertexList
Definition: ossimPolygon.h:250
std::basic_istringstream< char > istringstream
Class for char input memory streams.
Definition: ossimIosFwd.h:32
ossimVertexOrdering theOrderingType
Definition: ossimPolygon.h:249
const std::string & string() const
Definition: ossimString.h:414

◆ midPoint()

ossimDpt ossimPolygon::midPoint ( ) const

Definition at line 211 of file ossimPolygon.cpp.

References ossimDpt::makeNan(), theVertexList, ossimDpt::x, and ossimDpt::y.

212 {
213  int upper = (int)theVertexList.size();
214  ossimDpt result(0.0, 0.0);
215  int i = 0;
216 
217  if(!upper)
218  {
219  result.makeNan();
220  }
221  else
222  {
223  for(i = 0; i < upper; ++i)
224  {
225  result.x+=theVertexList[i].x;
226  result.y+=theVertexList[i].y;
227  }
228  result.x/=(double)upper;
229  result.y/=(double)upper;
230  }
231 
232  return result;
233 }
vector< ossimDpt > theVertexList
Definition: ossimPolygon.h:250

◆ nextVertex()

bool ossimPolygon::nextVertex ( ossimDpt tbd_vertex) const

METHOD: nextVertex() Assigns the ossimDpt tbd_vertex following the current vertex.

The current vertex is initialized with a call to vertex(int), or after the last vertex is reached. Returns false if no vertex defined. Intended to be when cycling through all vertices.

Definition at line 537 of file ossimPolygon.cpp.

References theCurrentVertex, and theVertexList.

538 {
541  {
542  return false;
543  }
544  tbd_vertex = theVertexList[theCurrentVertex];
545 
546  return true;
547 }
ossim_int32 theCurrentVertex
Definition: ossimPolygon.h:251
vector< ossimDpt > theVertexList
Definition: ossimPolygon.h:250
int ossim_int32

◆ operator!=()

bool ossimPolygon::operator!= ( const ossimPolygon compare_this) const

Definition at line 1178 of file ossimPolygon.cpp.

1179 {
1180  return !(*this == compare_this);
1181 }

◆ operator*() [1/2]

ossimPolygon ossimPolygon::operator* ( const ossimDpt scale) const

Definition at line 658 of file ossimPolygon.cpp.

References theVertexList, ossimDpt::x, and ossimDpt::y.

659 {
660  ossimPolygon result(*this);
661 
662  ossim_uint32 upper = (ossim_uint32)theVertexList.size();
663  ossim_uint32 i = 0;
664  for(i = 0; i < upper; ++i)
665  {
666  result.theVertexList[i].x*=scale.x;
667  result.theVertexList[i].y*=scale.y;
668  }
669 
670  return result;
671 }
double y
Definition: ossimDpt.h:165
unsigned int ossim_uint32
double x
Definition: ossimDpt.h:164
vector< ossimDpt > theVertexList
Definition: ossimPolygon.h:250

◆ operator*() [2/2]

ossimPolygon ossimPolygon::operator* ( double  scale) const

Definition at line 1161 of file ossimPolygon.cpp.

1162 {
1163  return ((*this)*ossimDpt(scale, scale));
1164 }

◆ operator*=() [1/2]

const ossimPolygon & ossimPolygon::operator*= ( const ossimDpt scale)

Definition at line 645 of file ossimPolygon.cpp.

References theVertexList, ossimDpt::x, and ossimDpt::y.

646 {
647  ossim_uint32 upper = (ossim_uint32)theVertexList.size();
648  ossim_uint32 i = 0;
649  for(i = 0; i < upper; ++i)
650  {
651  theVertexList[i].x*=scale.x;
652  theVertexList[i].y*=scale.y;
653  }
654 
655  return *this;
656 }
double y
Definition: ossimDpt.h:165
unsigned int ossim_uint32
double x
Definition: ossimDpt.h:164
vector< ossimDpt > theVertexList
Definition: ossimPolygon.h:250

◆ operator*=() [2/2]

const ossimPolygon & ossimPolygon::operator*= ( double  scale)

Definition at line 1156 of file ossimPolygon.cpp.

1157 {
1158  return ((*this)*=ossimDpt(scale, scale));
1159 }

◆ operator=() [1/6]

const ossimPolygon & ossimPolygon::operator= ( const ossimPolygon copy_this)

OPERATORS: (Some are inlined at bottom)

Definition at line 577 of file ossimPolygon.cpp.

References theCurrentVertex, theOrderingType, and theVertexList.

578 {
579  theVertexList = polygon.theVertexList;
580  theCurrentVertex = polygon.theCurrentVertex;
581  theOrderingType = polygon.theOrderingType;
582 
583  return *this;
584 }
ossim_int32 theCurrentVertex
Definition: ossimPolygon.h:251
vector< ossimDpt > theVertexList
Definition: ossimPolygon.h:250
ossimVertexOrdering theOrderingType
Definition: ossimPolygon.h:249

◆ operator=() [2/6]

const ossimPolygon & ossimPolygon::operator= ( const vector< ossimDpt > &  vertexList)

Definition at line 586 of file ossimPolygon.cpp.

References OSSIM_VERTEX_ORDER_UNKNOWN, theCurrentVertex, theOrderingType, and theVertexList.

587 {
588  theVertexList = vertexList;
589  theCurrentVertex = 0;
591 
592  return *this;
593 }
ossim_int32 theCurrentVertex
Definition: ossimPolygon.h:251
vector< ossimDpt > theVertexList
Definition: ossimPolygon.h:250
ossimVertexOrdering theOrderingType
Definition: ossimPolygon.h:249

◆ operator=() [3/6]

const ossimPolygon & ossimPolygon::operator= ( const vector< ossimGpt > &  vertexList)

Definition at line 611 of file ossimPolygon.cpp.

References OSSIM_VERTEX_ORDER_UNKNOWN, theCurrentVertex, theOrderingType, and theVertexList.

612 {
613  theVertexList.resize(vertexList.size());
614 
615  // Assign std::vector<ossimIpt> list to std::vector<ossimDpt> theVertexList.
616  for (std::vector<ossimIpt>::size_type i = 0; i < vertexList.size(); ++i)
617  {
618  theVertexList[i] = vertexList[i];
619  }
620 
621  theCurrentVertex = 0;
623 
624  return *this;
625 }
ossim_int32 theCurrentVertex
Definition: ossimPolygon.h:251
vector< ossimDpt > theVertexList
Definition: ossimPolygon.h:250
ossimVertexOrdering theOrderingType
Definition: ossimPolygon.h:249

◆ operator=() [4/6]

const ossimPolygon & ossimPolygon::operator= ( const vector< ossimIpt > &  vertexList)

Definition at line 595 of file ossimPolygon.cpp.

References OSSIM_VERTEX_ORDER_UNKNOWN, theCurrentVertex, theOrderingType, and theVertexList.

596 {
597  theVertexList.resize(vertexList.size());
598 
599  // Assign std::vector<ossimIpt> list to std::vector<ossimDpt> theVertexList.
600  for (std::vector<ossimIpt>::size_type i = 0; i < vertexList.size(); ++i)
601  {
602  theVertexList[i] = vertexList[i];
603  }
604 
605  theCurrentVertex = 0;
607 
608  return *this;
609 }
ossim_int32 theCurrentVertex
Definition: ossimPolygon.h:251
vector< ossimDpt > theVertexList
Definition: ossimPolygon.h:250
ossimVertexOrdering theOrderingType
Definition: ossimPolygon.h:249

◆ operator=() [5/6]

const ossimPolygon & ossimPolygon::operator= ( const ossimIrect rect)

Definition at line 553 of file ossimPolygon.cpp.

References ossimIrect::ll(), ossimIrect::lr(), theCurrentVertex, theVertexList, ossimIrect::ul(), and ossimIrect::ur().

554 {
555  theCurrentVertex = 0;
556  theVertexList.resize(4);
557  theVertexList[0] = rect.ul();
558  theVertexList[1] = rect.ur();
559  theVertexList[2] = rect.lr();
560  theVertexList[3] = rect.ll();
561 
562  return *this;
563 }
const ossimIpt & ul() const
Definition: ossimIrect.h:274
const ossimIpt & ll() const
Definition: ossimIrect.h:277
const ossimIpt & lr() const
Definition: ossimIrect.h:276
const ossimIpt & ur() const
Definition: ossimIrect.h:275
ossim_int32 theCurrentVertex
Definition: ossimPolygon.h:251
vector< ossimDpt > theVertexList
Definition: ossimPolygon.h:250

◆ operator=() [6/6]

const ossimPolygon & ossimPolygon::operator= ( const ossimDrect rect)

Definition at line 565 of file ossimPolygon.cpp.

References ossimDrect::ll(), ossimDrect::lr(), theCurrentVertex, theVertexList, ossimDrect::ul(), and ossimDrect::ur().

566 {
567  theCurrentVertex = 0;
568  theVertexList.resize(4);
569  theVertexList[0] = rect.ul();
570  theVertexList[1] = rect.ur();
571  theVertexList[2] = rect.lr();
572  theVertexList[3] = rect.ll();
573 
574  return *this;
575 }
const ossimDpt & ul() const
Definition: ossimDrect.h:339
const ossimDpt & ur() const
Definition: ossimDrect.h:340
ossim_int32 theCurrentVertex
Definition: ossimPolygon.h:251
const ossimDpt & ll() const
Definition: ossimDrect.h:342
vector< ossimDpt > theVertexList
Definition: ossimPolygon.h:250
const ossimDpt & lr() const
Definition: ossimDrect.h:341

◆ operator==()

bool ossimPolygon::operator== ( const ossimPolygon compare_this) const

Definition at line 631 of file ossimPolygon.cpp.

References theVertexList.

632 {
633  if( (theVertexList.size() != polygon.theVertexList.size()))
634  {
635  return false;
636  }
637  if(!theVertexList.size() && polygon.theVertexList.size())
638  {
639  return true;
640  }
641 
642  return (theVertexList == polygon.theVertexList);
643 }
vector< ossimDpt > theVertexList
Definition: ossimPolygon.h:250

◆ operator[]() [1/2]

ossimDpt & ossimPolygon::operator[] ( int  index)

Definition at line 1088 of file ossimPolygon.cpp.

References theVertexList.

1089 {
1090  return theVertexList[index];
1091 }
vector< ossimDpt > theVertexList
Definition: ossimPolygon.h:250

◆ operator[]() [2/2]

const ossimDpt & ossimPolygon::operator[] ( int  index) const

Definition at line 1093 of file ossimPolygon.cpp.

References theVertexList.

1094 {
1095  return theVertexList[index];
1096 }
vector< ossimDpt > theVertexList
Definition: ossimPolygon.h:250

◆ pointWithin()

bool ossimPolygon::pointWithin ( const ossimDpt point) const

METHOD: pointWithin(ossimDpt) Returns TRUE if point is inside polygon.

Definition at line 1151 of file ossimPolygon.cpp.

References isPointWithin().

Referenced by ossimApplanixUtmModel::worldToLineSample(), ossimSpectraboticsRedEdgeModel::worldToLineSample(), ossimApplanixEcefModel::worldToLineSample(), ossimH5GridModel::worldToLineSample(), and ossimSensorModel::worldToLineSample().

1152 {
1153  return isPointWithin(point);
1154 }
bool isPointWithin(const ossimDpt &point) const

◆ print()

void ossimPolygon::print ( ostream &  os) const

METHOD: print()

Definition at line 693 of file ossimPolygon.cpp.

References theVertexList.

Referenced by operator<<().

694 {
695  copy(theVertexList.begin(),
696  theVertexList.end(),
697  ostream_iterator<ossimDpt>(os, "\n"));
698 }
vector< ossimDpt > theVertexList
Definition: ossimPolygon.h:250

◆ rectIntersects()

bool ossimPolygon::rectIntersects ( const ossimIrect rect) const

METHOD: rectIntersects() Returns true if at least one corner points of the given rect is within.

Definition at line 438 of file ossimPolygon.cpp.

References isPointWithin(), ossimIrect::ll(), ossimIrect::lr(), ossimIrect::ul(), and ossimIrect::ur().

439 {
440  if ( isPointWithin(rect.ul()) ||
441  isPointWithin(rect.ur()) ||
442  isPointWithin(rect.ll()) ||
443  isPointWithin(rect.lr()))
444  {
445  return true;
446  }
447  return false;
448 }
const ossimIpt & ul() const
Definition: ossimIrect.h:274
const ossimIpt & ll() const
Definition: ossimIrect.h:277
const ossimIpt & lr() const
Definition: ossimIrect.h:276
const ossimIpt & ur() const
Definition: ossimIrect.h:275
bool isPointWithin(const ossimDpt &point) const

◆ removeSmallestContributingVertex()

void ossimPolygon::removeSmallestContributingVertex ( )
protected

METHOD: removeSmallestContributingVertex() Removes the vertex that contributes the smallest area to the polygon.

Definition at line 1052 of file ossimPolygon.cpp.

References addPoint(), area(), clear(), DBL_EPSILON, getNumberOfVertices(), removeVertex(), and theVertexList.

1053 {
1054  unsigned int numvertices=getNumberOfVertices();
1055  if (!numvertices)
1056  return;
1057 
1058  int smallest_vertex=-1,n1,n2;
1059  double smallest_area=1.0/DBL_EPSILON;
1060  ossimPolygon tmp;
1061 
1062  for(unsigned int v=0;v<numvertices;v++) {
1063  tmp.clear();
1064  if(v==0) {
1065  n1=numvertices-1;
1066  n2=1;
1067  } else if(v==numvertices-1) {
1068  n1=numvertices-2;
1069  n2=0;
1070  } else {
1071  n1=v-1;
1072  n2=v+1;
1073  }
1074 
1075  tmp.addPoint(theVertexList[n1]);
1076  tmp.addPoint(theVertexList[v]);
1077  tmp.addPoint(theVertexList[n2]);
1078 
1079  if(fabs(tmp.area())<smallest_area) {
1080  smallest_area=fabs(tmp.area());
1081  smallest_vertex=v;
1082  }
1083  }
1084  removeVertex(smallest_vertex);
1085 }
void addPoint(const ossimDpt &pt)
void removeVertex(int vertex)
METHOD: remove() Removes the vertex from the polygon.
#define DBL_EPSILON
ossim_uint32 getNumberOfVertices() const
double area() const
Returns polygon area. Negative indicates CW ordering of vertices (in right-handed coordinates) ...
vector< ossimDpt > theVertexList
Definition: ossimPolygon.h:250

◆ removeVertex()

void ossimPolygon::removeVertex ( int  vertex)

METHOD: remove() Removes the vertex from the polygon.

Definition at line 1031 of file ossimPolygon.cpp.

References getNumberOfVertices(), theVertexList, and vertex().

Referenced by ATP::AtpGenerator::layoutSearchTileRects(), and removeSmallestContributingVertex().

1032 {
1033  int numvertices=getNumberOfVertices();
1034  if(vertex>numvertices) {
1035  return;
1036  } else {
1037  vector<ossimDpt>::iterator it;
1038  int v=0;
1039  for(it=theVertexList.begin();it!=theVertexList.end();it++) {
1040  if(v++==vertex) {
1041  theVertexList.erase(it);
1042  break;
1043  }
1044  }
1045  }
1046 }
bool vertex(int index, ossimDpt &tbd_vertex) const
METHOD: vertex(index) Returns the ossimDpt vertex given the index.
ossim_uint32 getNumberOfVertices() const
vector< ossimDpt > theVertexList
Definition: ossimPolygon.h:250

◆ resize()

void ossimPolygon::resize ( ossim_uint32  newSize)

◆ reverseOrder()

void ossimPolygon::reverseOrder ( )

Definition at line 674 of file ossimPolygon.cpp.

References OSSIM_CLOCKWISE_ORDER, OSSIM_COUNTERCLOCKWISE_ORDER, theOrderingType, and theVertexList.

Referenced by getMinimumBoundingRect().

675 {
676  std::reverse(theVertexList.begin(), theVertexList.end());
677 
679  {
681  }
683  {
685  }
686 
687 }
vector< ossimDpt > theVertexList
Definition: ossimPolygon.h:250
ossimVertexOrdering theOrderingType
Definition: ossimPolygon.h:249

◆ roundToIntegerBounds()

void ossimPolygon::roundToIntegerBounds ( bool  compress = false)

Definition at line 175 of file ossimPolygon.cpp.

References theCurrentVertex, and theVertexList.

176 {
177  int i = 0;
178  for(i = 0; i < (int)theVertexList.size(); ++i)
179  {
181  }
182 
183  if(compress&&theVertexList.size())
184  {
185  vector<ossimDpt> polyLine;
186 
187  polyLine.push_back(theVertexList[0]);
188  ossimDpt testPt = theVertexList[0];
189  for(i=1; i < (int)theVertexList.size(); ++i)
190  {
191  if(testPt!=theVertexList[i])
192  {
193  testPt = theVertexList[i];
194  polyLine.push_back(testPt);
195  }
196  }
197  if(polyLine.size() == 1)
198  {
199  polyLine.push_back(polyLine[0]);
200  }
201 
202  if(theVertexList.size() == 1)
203  {
204  polyLine.push_back(testPt);
205  }
206  theVertexList = polyLine;
207  theCurrentVertex = 0;
208  }
209 }
ossim_int32 theCurrentVertex
Definition: ossimPolygon.h:251
vector< ossimDpt > theVertexList
Definition: ossimPolygon.h:250

◆ saveState()

bool ossimPolygon::saveState ( ossimKeywordlist kwl,
const char *  prefix = 0 
) const

Definition at line 802 of file ossimPolygon.cpp.

References ossimKeywordlist::add(), and ossimKeywordNames::TYPE_KW.

804 {
805  kwl.add(prefix,
807  "ossimPolygon",
808  true);
809  kwl.add(prefix,
810  NUMBER_VERTICES_KW,
811  static_cast<ossim_uint32>(theVertexList.size()),
812  true);
813  int i = 0;
814  for(i = 0; i < (int)theVertexList.size();++i)
815  {
816  ossimString vert = "v"+ossimString::toString(i);;
817  ossimString value = (ossimString::toString(theVertexList[i].x) + " " +
819  kwl.add(prefix,
820  vert.c_str(),
821  value.c_str(),
822  true);
823  }
824  ossimString order = "";
825 
826  switch(theOrderingType)
827  {
829  {
830  order = "unknown";
831  break;
832  }
834  {
835  order = "clockwise";
836  break;
837  }
839  {
840  order = "counter_clockwise";
841  break;
842  }
843  }
844  kwl.add(prefix,
845  VERTEX_ORDER_KW,
846  order,
847  true);
848 
849  return true;
850 }
ossim_uint32 x
ossim_uint32 y
static ossimString toString(bool aValue)
Numeric to string methods.
static const char * TYPE_KW
void add(const char *prefix, const ossimKeywordlist &kwl, bool overwrite=true)
const char * c_str() const
Returns a pointer to a null-terminated array of characters representing the string&#39;s contents...
Definition: ossimString.h:396
vector< ossimDpt > theVertexList
Definition: ossimPolygon.h:250
ossimVertexOrdering theOrderingType
Definition: ossimPolygon.h:249

◆ shrink()

bool ossimPolygon::shrink ( ossimPolygon dest,
double  inset 
) const
protected

METHOD: shrink() Shrinks the current polygon by inset, return true if success.


! Shrinks this polygon by radius.

Effectively, circles of given radius are placed inside ! the vertices just tangent to the polygon edges (via fitCircleInsideVertex()). The new ! polygon's vertices will be the center of these circles. Return true if success.

Definition at line 1286 of file ossimPolygon.cpp.

References addPoint(), clear(), fitCircleInsideVertex(), isPolyWithin(), ossimPolygon(), and theVertexList.

1287 {
1288  int numpts = (int) theVertexList.size();
1289  ossimDpt pt;
1290 
1291  //don't let people shrink themselves, that isn't going to work
1292  if (&dest==this)
1293  return false;
1294 
1295  dest.clear();
1296  for(int i=0;i<numpts;i++)
1297  {
1298  fitCircleInsideVertex(pt,i,inset);
1299  dest.addPoint(pt);
1300  }
1301  if(isPolyWithin(dest))
1302  {
1303  return true;
1304  } else
1305  {
1306  //return an empty polygon
1307  dest=ossimPolygon();
1308  return false;
1309  }
1310 }
void addPoint(const ossimDpt &pt)
bool isPolyWithin(const ossimPolygon &poly) const
METHOD: isPolyWithin() Returns true if all the vertices of the given polygon fit within.
void fitCircleInsideVertex(ossimDpt &destPt, unsigned int vertex, double radius) const
Assigns destPt the point that fits a circle of given radius inside the polygon vertex.
vector< ossimDpt > theVertexList
Definition: ossimPolygon.h:250

◆ vertex()

bool ossimPolygon::vertex ( int  index,
ossimDpt tbd_vertex 
) const

METHOD: vertex(index) Returns the ossimDpt vertex given the index.

Returns false if no vertex defined.

Definition at line 514 of file ossimPolygon.cpp.

References theCurrentVertex, and theVertexList.

Referenced by fitCircleInsideVertex(), getMinimumBoundingRect(), ossimDrect::ossimDrect(), and removeVertex().

515 {
516  if((index >= (int)theVertexList.size()) ||
517  (index < 0))
518  {
519  return false;
520  }
521 
522  tbd_vertex = theVertexList[index];
523  theCurrentVertex = index;
524 
525  return true;
526 }
ossim_int32 theCurrentVertex
Definition: ossimPolygon.h:251
vector< ossimDpt > theVertexList
Definition: ossimPolygon.h:250

Friends And Related Function Documentation

◆ operator<<

ostream& operator<< ( ostream &  os,
const ossimPolygon polygon 
)
friend

Definition at line 1183 of file ossimPolygon.cpp.

1184 {
1185  polygon.print(os);
1186  return os;
1187 }
void print(ostream &os) const
METHOD: print()

Member Data Documentation

◆ theCurrentVertex

ossim_int32 ossimPolygon::theCurrentVertex
mutableprotected

Definition at line 251 of file ossimPolygon.h.

Referenced by nextVertex(), operator=(), resize(), roundToIntegerBounds(), and vertex().

◆ theOrderingType

ossimVertexOrdering ossimPolygon::theOrderingType
mutableprotected

◆ theVertexList

vector<ossimDpt> ossimPolygon::theVertexList
protected

The documentation for this class was generated from the following files: