27 static const char* NUMBER_VERTICES_KW =
"number_vertices";
28 static const char* VERTEX_ORDER_KW =
"order";
30 static const int RECT_LEFT_EDGE = 0;
31 static const int RECT_TOP_EDGE = 1;
32 static const int RECT_RIGHT_EDGE = 2;
33 static const int RECT_BOTTOM_EDGE = 3;
44 theVertexList(polygon.
size()),
49 for (std::vector<ossimIpt>::size_type i = 0; i < polygon.size(); ++i)
57 theVertexList(polygon.
size()),
62 for (std::vector<ossimGpt>::size_type i = 0; i < polygon.size(); ++i)
71 theVertexList(polygon),
165 j = (i + 1) % (
int)
size;
185 vector<ossimDpt> polyLine;
194 polyLine.push_back(testPt);
197 if(polyLine.size() == 1)
199 polyLine.push_back(polyLine[0]);
204 polyLine.push_back(testPt);
223 for(i = 0; i < upper; ++i)
228 result.
x/=(double)upper;
229 result.
y/=(double)upper;
240 for(i = 0; i < upper; ++i)
266 for(i =1; i < npoly; ++i)
302 for(i =1; i < npoly; ++i)
330 return (result.size() > 0);
350 bool intersected=
false;
351 double num, denom, t;
360 for(i = 0, j = 1; i < npol;)
370 normal.
x = -normal.
x;
371 normal.
y = -normal.
y;
374 denom = normal.
x*PQ.
x + normal.
y*PQ.
y;
460 for(
int v=0;v<numvertex;v++) {
482 for (i = 0, j = npol-1; i < npol; j = i++)
495 for (i = 0, j = npol-1; i < npol; j = i++)
600 for (std::vector<ossimIpt>::size_type i = 0; i < vertexList.size(); ++i)
616 for (std::vector<ossimIpt>::size_type i = 0; i < vertexList.size(); ++i)
649 for(i = 0; i < upper; ++i)
664 for(i = 0; i < upper; ++i)
697 ostream_iterator<ossimDpt>(os,
"\n"));
705 double areaValue =
area();
710 else if(areaValue <= 0)
739 case RECT_RIGHT_EDGE:
745 case RECT_BOTTOM_EDGE:
764 return (pt.
x>rect.
ul().
x);
771 return (pt.
y > rect.
ul().
y);
775 return (pt.
y < rect.
ul().
y);
779 case RECT_RIGHT_EDGE:
781 return (pt.
x<rect.
lr().
x);
785 case RECT_BOTTOM_EDGE:
789 return (pt.
y < rect.
lr().
y);
793 return (pt.
y > rect.
lr().
y);
803 const char* prefix)
const 840 order =
"counter_clockwise";
856 const char* number_vertices = kwl.
find(prefix, NUMBER_VERTICES_KW);
862 else if(order ==
"clockwise")
866 else if(order ==
"counter_clockwise")
874 for(i = 0; i < vertexCount; ++i)
880 vStream >>
x.string() >>
y.string();
889 static const double MIN_STEP = (0.5)*
M_PI/180.0;
890 double angle_step =
M_PI/8.0;
892 double best_theta =
M_PI/4.0;
894 double cos_theta, sin_theta;
898 double min_x, min_y, max_x, max_y;
902 bool first_time =
true;
904 static const bool TESTING =
false;
909 while (angle_step > MIN_STEP)
914 center_theta = best_theta;
915 for (
int i=0; i<5; i++)
921 if ((i != 2) || (first_time))
923 theta = center_theta + (i - 2.0)*angle_step;
924 cos_theta = cos(theta);
925 sin_theta = sin(theta);
938 rotatedVertex.
x = cos_theta*xlatedVertex.
x + sin_theta*xlatedVertex.
y;
939 rotatedVertex.
y = cos_theta*xlatedVertex.
y - sin_theta*xlatedVertex.
x;
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;
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;
970 area = (max_x - min_x) * (max_y - min_y);
992 cos_theta = cos(best_theta);
993 sin_theta = sin(best_theta);
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;
1037 vector<ossimDpt>::iterator it;
1058 int smallest_vertex=-1,n1,n2;
1062 for(
unsigned int v=0;v<numvertices;v++) {
1067 }
else if(v==numvertices-1) {
1079 if(fabs(tmp.
area())<smallest_area) {
1080 smallest_area=fabs(tmp.
area());
1158 return ((*
this)*=
ossimDpt(scale, scale));
1163 return ((*
this)*
ossimDpt(scale, scale));
1180 return !(*
this == compare_this);
1198 double area=0,parea;
1201 for(
int i=0;i<numpts;i++) {
1213 centroid=centroid/(
area*6.0);
1225 ossimDpt side1,side2,bisection,currpt;
1226 double length_out,side1_side2_cross;
1230 if(num_vertices<3 || vertex>=num_vertices) {
1238 }
else if(
vertex==num_vertices-1) {
1252 side1 = side1/side1.
length();
1253 side2 = side2/side2.
length();
1255 side1_side2_cross=side1.
x*side2.
y-side2.
x*side1.
y;
1259 if(side1_side2_cross<0)
1262 if(side1_side2_cross>0)
1266 bisection = side1+side2;
1267 bisection = bisection/bisection.
length();
1270 bisection=bisection*-1.0;
1273 double cos_theta=(side1.
x*bisection.
x+side1.
y*bisection.
y);
1274 length_out=radius/sqrt(1-cos_theta*cos_theta);
1276 destPt=
ossimDpt(currpt+bisection*length_out);
1296 for(
int i=0;i<numpts;i++)
ossimDpt midPoint() const
ossimDpt & operator[](int index)
Represents serializable keyword/value map.
bool nextVertex(ossimDpt &tbd_vertex) const
METHOD: nextVertex() Assigns the ossimDpt tbd_vertex following the current vertex.
const char * find(const char *key) const
bool operator==(const ossimPolygon &compare_this) const
void removeSmallestContributingVertex()
METHOD: removeSmallestContributingVertex() Removes the vertex that contributes the smallest area to t...
double nan()
Method to return ieee floating point double precision NAN.
const ossimDpt & ul() const
void addPoint(const ossimDpt &pt)
void getFloatBounds(ossim_float64 &minX, ossim_float64 &minY, ossim_float64 &maxX, ossim_float64 &maxY) const
static ossimString toString(bool aValue)
Numeric to string methods.
bool shrink(ossimPolygon &dest, double inset) const
METHOD: shrink() Shrinks the current polygon by inset, return true if success.
const ossimIpt & ul() const
bool isRectWithin(const ossimIrect &rect) const
METHOD: isRectWithin() Returns true if all the corner points of the given rect fit within...
ossimVertexOrdering checkOrdering() const
ossimVertexOrdering getOrdering() const
void removeVertex(int vertex)
METHOD: remove() Removes the vertex from the polygon.
bool clipLineSegment(ossimDpt &p1, ossimDpt &p2) const
METHOD: clipLineSegment(p1, p2) Implements Cyrus-Beck clipping algorithm as described in: http://www...
const ossimIpt & ll() const
bool isPolyWithin(const ossimPolygon &poly) const
METHOD: isPolyWithin() Returns true if all the vertices of the given polygon fit within.
bool vertex(int index, ossimDpt &tbd_vertex) const
METHOD: vertex(index) Returns the ossimDpt vertex given the index.
static const char * TYPE_KW
void getCentroid(ossimDpt ¢roid) const
METHOD: getCentroid() Assigns the ossimDpt centroid the polygon.
ossimCoordSysOrientMode orientMode() const
void add(const char *prefix, const ossimKeywordlist &kwl, bool overwrite=true)
void getIntegerBounds(ossim_int32 &minX, ossim_int32 &minY, ossim_int32 &maxX, ossim_int32 &maxY) const
ossimDpt intersectInfinite(const ossimLine &line) const
ossim_uint32 getVertexCount() const
bool loadState(const ossimKeywordlist &kwl, const char *prefix=0)
bool operator!=(const ossimPolygon &compare_this) const
bool saveState(ossimKeywordlist &kwl, const char *prefix=0) const
unsigned int ossim_uint32
ossimString trim(const ossimString &valueToTrim=ossimString(" \\)) const
this will strip lead and trailing character passed in.
void print(ostream &os) const
METHOD: print()
bool hasNans() const
will sequence through the polygon and check to see if any values are NAN
void intersectEdge(ossimDpt &result, const ossimLine &segment, const ossimDrect &rect, int edge)
const ossimIpt & lr() const
bool rectIntersects(const ossimIrect &rect) const
METHOD: rectIntersects() Returns true if at least one corner points of the given rect is within...
bool pointWithin(const ossimDpt &point) const
METHOD: pointWithin(ossimDpt) Returns TRUE if point is inside polygon.
void roundToIntegerBounds(bool compress=false)
const ossimIpt & ur() const
void getBoundingRect(ossimIrect &rect) const
bool clipToRect(vector< ossimPolygon > &result, const ossimDrect &rect) const
Uses the ossimPolyArea2d class for the intersection.
const vector< ossimDpt > & getVertexList() const
ossim_uint32 getNumberOfVertices() const
long toLong() const
toLong's deprecated, please use the toInts...
bool isPointWithin(const ossimDpt &point) const
const ossimDpt & ur() const
double area() const
Returns polygon area. Negative indicates CW ordering of vertices (in right-handed coordinates) ...
ossim_int32 theCurrentVertex
const char * c_str() const
Returns a pointer to a null-terminated array of characters representing the string's contents...
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.
const ossimDpt & ll() const
vector< ossimDpt > theVertexList
std::basic_istringstream< char > istringstream
Class for char input memory streams.
void getMinimumBoundingRect(ossimPolygon &minRect) const
Initializes minRect with the minimum area rect (not-necessarily aligned with axes) that bounds this p...
const ossimPolygon & operator*=(const ossimDpt &scale)
void resize(ossim_uint32 newSize)
ossimVertexOrdering theOrderingType
const ossimDpt & lr() const
bool isInsideEdge(const ossimDpt &pt, const ossimDrect &rect, int edge) const
bool getVisiblePolygons(vector< ossimPolygon > &polyList) const
std::basic_ostream< char > ostream
Base class for char output streams.
ostream & operator<<(ostream &os, const ossimPolygon &polygon)
ossimPolygon operator*(const ossimDpt &scale) const
const ossimPolygon & operator=(const ossimPolygon ©_this)
OPERATORS: (Some are inlined at bottom)
const std::string & string() const