OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
ossimPolyLine.h
Go to the documentation of this file.
1 //*******************************************************************
2 //
3 // License: See top level LICENSE.txt file.
4 //
5 // AUTHOR: Oscar Kramer (okramer@imagelinks.com)
6 //
7 // DESCRIPTION: Contains declaration of class ossimPolygon.
8 // This class provides utilities associated with N-vertex, convex
9 // (i.e., only two intersections for any line passing through the polygon).
10 //
11 // LIMITATIONS: None.
12 //
13 //*****************************************************************************
14 // $Id: ossimPolyLine.h 15833 2009-10-29 01:41:53Z eshirschorn $
15 
16 #ifndef ossimPolyLine_HEADER
17 #define ossimPolyLine_HEADER
18 #include <iostream>
19 #include <vector>
20 using namespace std;
21 
22 #include <ossim/base/ossimDpt.h>
23 #include <ossim/base/ossimDrect.h>
24 #include <ossim/base/ossimIrect.h>
25 #include <ossim/base/ossimString.h>
26 class ossimLine;
27 class ossimPolygon;
28 
29 /*!****************************************************************************
30  *
31  * CLASS: ossimPolyLine
32  *
33  *****************************************************************************/
35 {
36 public:
38  :theCurrentVertex(0)
39  {}
40  ossimPolyLine(const vector<ossimIpt>& polygon);
41  ossimPolyLine(const vector<ossimDpt>& polygon);
42  ossimPolyLine(int numVertices, const ossimDpt* vertex_array);
43 
44  ossimPolyLine(const ossimPolyLine& copy_this);
45  ossimPolyLine(const ossimPolygon& polygon);
46 
52  ossimDpt v2,
53  ossimDpt v3,
54  ossimDpt v4);
55 
56  ossimPolyLine(const ossimIrect& rect);
57  ossimPolyLine(const ossimDrect& rect);
58 
59  ~ossimPolyLine();
60 
61  ossimDpt& operator[](int index)
62  {
63  return theVertexList[index];
64  }
65  const ossimDpt& operator[](int index)const
66  {
67  return theVertexList[index];
68  }
69 
71  {
72  return (ossim_uint32)theVertexList.size();
73  }
74 
75  void getIntegerBounds(ossim_int32& minX,
76  ossim_int32& minY,
77  ossim_int32& maxX,
78  ossim_int32& maxY)const;
79  void getBounds(double& minX,
80  double& minY,
81  double& maxX,
82  double& maxY)const;
83  void getBoundingRect(ossimDrect& rect)const
84  {
85  ossim_int32 minX;
86  ossim_int32 minY;
87  ossim_int32 maxX;
88  ossim_int32 maxY;
89  getIntegerBounds(minX, minY, maxX, maxY);
90  rect = ossimDrect(minX, minY, maxX, maxY);
91 
92  }
94  {
95  ossimDrect result;
96 
97  getBoundingRect(result);
98 
99  return result;
100  }
101 
102  void roundToIntegerBounds(bool compress=true);
103  void clear()
104  {
105  theVertexList.clear();
106  }
107  void addPoint(const ossimDpt& pt)
108  {
109  theVertexList.push_back(pt);
110  }
111  void addPoint(double x, double y)
112  {
113  theVertexList.push_back(ossimDpt(x, y));
114  }
115  void addAttribute( const ossimString& attribute )
116  {
117  theAttributeList.push_back( attribute );
118  }
119 
120  ossimDpt midPoint()const;
121 
125  bool hasNans()const;
126 
128  {
129  return getNumberOfVertices();
130  }
131  void resize(ossim_uint32 newSize)
132  {
133  theVertexList.resize(newSize);
134  }
135  const vector<ossimDpt>& getVertexList()const
136  {
137  return theVertexList;
138  }
139 
140  vector<ossimDpt>& getVertexList()
141  {
142  return theVertexList;
143  }
144  vector<ossimString>& getAttributeList()
145  {
146  return theAttributeList;
147  }
148 
149  bool clipToRect(vector<ossimPolyLine>& result,
150  const ossimDrect& rect)const;
151 
157  bool isWithin(const ossimDrect& rect)const;
158 
159 
164  bool pointWithin(const ossimDpt& point) const
165  {
166  return isPointWithin(point);
167  }
168  bool isPointWithin(const ossimDpt& point) const;
169 
175  bool vertex(int index, ossimDpt& tbd_vertex) const;
176 
184  bool nextVertex(ossimDpt& tbd_vertex) const;
185 
186  void reverseOrder();
190  const ossimPolyLine& operator= (const ossimPolyLine& copy_this);
191  const ossimPolyLine& operator= (const vector<ossimDpt>& vertexList);
192  const ossimPolyLine& operator= (const vector<ossimIpt>& vertexList);
193  const ossimPolyLine& operator= (const ossimIrect& rect);
194  const ossimPolyLine& operator= (const ossimPolygon& polygon);
195  const ossimPolyLine& operator= (const ossimDrect& rect);
196  bool operator==(const ossimPolyLine& compare_this) const;
197  bool operator!=(const ossimPolyLine& compare_this) const;
198 
199  const ossimPolyLine& operator *=(const ossimDpt& scale);
200  const ossimPolyLine& operator *=(double scale)
201  {
202  return ((*this)*=ossimDpt(scale, scale));
203  }
204 
205  ossimPolyLine operator *(const ossimDpt& scale)const;
206  ossimPolyLine operator *(double scale)const
207  {
208  return ((*this)*ossimDpt(scale, scale));
209  }
210 
214  void print(ostream& os) const;
215  friend ostream& operator<<(ostream&, const ossimPolyLine&);
216 
217 
218  bool saveState(ossimKeywordlist& kwl,
219  const char* prefix=0)const;
220 
221  bool loadState(const ossimKeywordlist& kwl,
222  const char* prefix=0);
223 protected:
224  vector<ossimDpt> theVertexList;
225  vector<ossimString> theAttributeList;
226 
228 };
229 
230 inline bool ossimPolyLine::operator!=(const ossimPolyLine& compare_this) const
231 {
232  return !(*this == compare_this);
233 }
234 
235 inline ostream& operator<<(ostream& os, const ossimPolyLine& polyLine)
236 {
237  polyLine.print(os);
238  return os;
239 }
240 
241 #endif
const vector< ossimDpt > & getVertexList() const
ossim_uint32 x
#define OSSIMDLLEXPORT
bool operator!=(const ossimRefPtr< _Tp1 > &__a, const ossimRefPtr< _Tp2 > &__b) noexcept
Definition: ossimRefPtr.h:111
void getBoundingRect(ossimDrect &rect) const
Definition: ossimPolyLine.h:83
Represents serializable keyword/value map.
ossim_uint32 y
vector< ossimString > & getAttributeList()
std::ostream & print(H5::H5File *file, std::ostream &out)
Print method.
Definition: ossimH5Util.cpp:41
ossim_int32 theCurrentVertex
ossimRationalNumber operator*(ossim_int32 i, ossimRationalNumber &r)
ossim_uint32 getNumberOfVertices() const
Definition: ossimPolyLine.h:70
const ossimDpt & operator[](int index) const
Definition: ossimPolyLine.h:65
ossim_uint32 size()
vector< ossimDpt > & getVertexList()
unsigned int ossim_uint32
bool pointWithin(const ossimDpt &point) const
vector< ossimDpt > theVertexList
bool operator==(const ossimRefPtr< _Tp1 > &__a, const ossimRefPtr< _Tp2 > &__b) noexcept
Definition: ossimRefPtr.h:101
bool operator!=(const ossimPolyLine &compare_this) const
vector< ossimString > theAttributeList
ossimDpt & operator[](int index)
Definition: ossimPolyLine.h:61
void addPoint(const ossimDpt &pt)
ostream & operator<<(ostream &os, const ossimPolyLine &polyLine)
void addPoint(double x, double y)
void print(ostream &os) const
void resize(ossim_uint32 newSize)
ossimDrect getBoundingRect() const
Definition: ossimPolyLine.h:93
std::basic_ostream< char > ostream
Base class for char output streams.
Definition: ossimIosFwd.h:23
void addAttribute(const ossimString &attribute)
int ossim_int32