OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
ossimGrect.h
Go to the documentation of this file.
1 //*******************************************************************
2 // Copyright (C) 2000 ImageLinks Inc.
3 //
4 // License: MIT
5 //
6 // See LICENSE.txt file in the top level directory for more details.
7 //
8 // Author: Garrett Potts
9 //
10 //*************************************************************************
11 // $Id: ossimGrect.h 23461 2015-08-05 20:20:20Z okramer $
12 #ifndef ossimGrect_HEADER
13 #define ossimGrect_HEADER 1
14 
17 #include <ossim/base/ossimGpt.h>
18 #include <ossim/base/ossimCommon.h>
19 
20 #include <vector>
21 #include <iostream>
22 
24 {
25 public:
26  friend OSSIM_DLL std::ostream& operator<<(std::ostream& os, const ossimGrect& rect);
27 
32  :
33  theUlCorner(0.0, 0.0, 0.0),
34  theLrCorner(0.0, 0.0, 0.0)
35  {}
36 
41  ossimGrect(const ossimGrect& rect)
42  :
43  theUlCorner(rect.ul()),
44  theLrCorner(rect.lr())
45  {}
46 
51  ossimGrect(const ossimGpt& p1, const ossimGpt& p2);
52 
57  ossimGrect(double ulLat,
58  double ulLon,
59  double lrLat,
60  double lrLon,
61  const ossimDatum* aDatum=ossimDatumFactory::instance()->wgs84())
62  :
63  theUlCorner(ulLat, ulLon,0, aDatum),
64  theLrCorner(lrLat, lrLon, 0, aDatum)
65  {}
66  ossimGrect(const ossimGpt& point,
67  double latSpacingInDegrees,
68  double lonSpacingInDegrees)
69  :
70  theUlCorner(point),
71  theLrCorner(point)
72  {
73  std::vector<ossimGrect> v;
74  computeEvenTiles(v, latSpacingInDegrees, lonSpacingInDegrees);
75  if(v.size())
76  *this = v[0];
77  }
78  ossimGrect(std::vector<ossimGpt>& points);
79  ossimGrect(const ossimGpt& p1,
80  const ossimGpt& p2,
81  const ossimGpt& p3,
82  const ossimGpt& p4);
83 
84 
85  const ossimGrect& operator=(const ossimGrect& rect)
86  {
87  theUlCorner = rect.ul();
88  theLrCorner = rect.lr();
89  return *this;
90  }
91 
92  inline ossimGpt midPoint()const;
93 
95  inline ossim_float64 height() const;
96 
98  inline ossim_float64 width() const;
99 
101  ossim_float64 heightMeters() const;
102 
104  ossim_float64 widthMeters() const;
105 
106  inline const ossimGpt& ul()const;
107  inline const ossimGpt& lr()const;
108  inline ossimGpt ur() const;
109  inline ossimGpt ll() const;
110 
111  inline ossimGpt& ul();
112  inline ossimGpt& lr();
113 
114  inline void makeNan();
115 
116  inline bool isLonLatNan()const;
117 
118  inline bool hasNans()const;
119 
120  inline bool isNan()const;
121 
126  bool completely_within(const ossimGrect& rect) const;
127 
132  bool intersects(const ossimGrect& rect) const;
133 
134  inline ossimGrect clipToRect(const ossimGrect& rect)const;
135 
136  inline ossimGrect combine(const ossimGrect& rect)const;
137 
145  void expandToInclude(const ossimGpt& gpt);
146  void expandToInclude(const ossimGrect& rect);
147 
158  inline bool pointWithin(const ossimGpt& gpt, bool considerHgt=false) const; //inline below
159 
160  ossimGrect stretchToEvenBoundary(double latSpacingInDegrees,
161  double lonSpacingInDegrees)const;
162 
163  void computeEvenTiles(std::vector<ossimGrect>& result,
164  double latSpacingInDegrees,
165  double lonSpacingInDegrees,
166  bool clipToGeographicBounds = true)const;
167 private:
168  ossimGpt theUlCorner; // Contains max height as well
169  ossimGpt theLrCorner; // Contains min height as well
170 
171 };
172 
173 //==================== BEGIN INLINE DEFINITIONS ===============================
174 
175 //*****************************************************************************
176 // INLINE METHOD: ossimGrect::midPoint()
177 //*****************************************************************************
179 {
180  return ossimGpt((ul().latd() + ur().latd() + ll().latd() + lr().latd())*.25,
181  (ul().lond() + ur().lond() + ll().lond() + lr().lond())*.25,
182  (ul().height()+ur().height()+ll().height()+
183  lr().height())*.25,
184  ul().datum() );
185 }
186 
187 //*****************************************************************************
188 // INLINE METHOD: ossimGrect::clipToRect()
189 //*****************************************************************************
191 {
192  double ulx, uly, lrx, lry;
193 
194  ulx = ossim::max<ossim_float64>(rect.ul().lond(),ul().lond());
195  uly = ossim::min<ossim_float64>(rect.ul().latd(),ul().latd());
196  lrx = ossim::min<ossim_float64>(rect.lr().lond(),lr().lond());
197  lry = ossim::max<ossim_float64>(rect.lr().latd(),lr().latd());
198 
199  if( lrx < ulx || lry > uly )
200  {
201  return ossimGrect(ossimGpt(0,0,0),ossimGpt(0,0,0));
202  }
203  else
204  {
205  return ossimGrect(ossimGpt(uly, ulx, 0, rect.ul().datum()),
206  ossimGpt(lry, lrx, 0, rect.ul().datum()));
207  }
208 }
209 
210 //*******************************************************************
211 // Inline Method: ossimDrect::combine(const ossimDrect& rect)
212 //*******************************************************************
213 inline ossimGrect ossimGrect::combine(const ossimGrect& rect)const
214 {
215  if (isLonLatNan())
216  return rect;
217 
218  ossimGpt ulCombine;
219  ossimGpt lrCombine;
220 
221  ulCombine.lon = ((ul().lon <= rect.ul().lon)?ul().lon:rect.ul().lon);
222  ulCombine.lat = ((ul().lat >= rect.ul().lat)?ul().lat:rect.ul().lat);
223  lrCombine.lon = ((lr().lon >= rect.lr().lon)?lr().lon:rect.lr().lon);
224  lrCombine.lat = ((lr().lat <= rect.lr().lat)?lr().lat:rect.lr().lat);
225 
226  return ossimGrect(ulCombine, lrCombine);
227 }
228 
229 //*****************************************************************************
230 // INLINE METHOD: ossimGrect::pointWithin()
231 //*****************************************************************************
232 inline bool ossimGrect::pointWithin(const ossimGpt& gpt, bool considerHgt) const
233 {
234  bool within = (gpt.lat <= theUlCorner.lat) && (gpt.lat >= theLrCorner.lat) &&
235  (gpt.lon >= theUlCorner.lon) && (gpt.lon <= theLrCorner.lon);
236  if (considerHgt)
237  within &= (gpt.hgt <= theUlCorner.hgt) && (gpt.hgt >= theLrCorner.hgt);
238 
239  return within;
240 }
241 
243 {
244  return (theUlCorner.latd() - theLrCorner.latd());
245 }
246 
248 {
249  return (theLrCorner.lond() - theUlCorner.lond());
250 }
251 
252 inline const ossimGpt& ossimGrect::ul() const
253 {
254  return theUlCorner;
255 }
256 
257 inline ossimGpt ossimGrect::ur() const
258 {
260  return gpt;
261 }
262 
263 inline ossimGpt ossimGrect::ll() const
264 {
266  return gpt;
267 }
268 
269 inline const ossimGpt& ossimGrect::lr() const
270 {
271  return theLrCorner;
272 }
273 
275 {
276  return theUlCorner;
277 }
278 
280 {
281  return theLrCorner;
282 }
283 
284 inline void ossimGrect::makeNan()
285 {
288 }
289 
290 inline bool ossimGrect::isLonLatNan() const
291 {
292  return ( ossim::isnan(theUlCorner.lat) ||
296 }
297 
298 inline bool ossimGrect::hasNans() const
299 {
300  return ( theUlCorner.hasNans() ||
301  theLrCorner.hasNans() );
302 }
303 
304 inline bool ossimGrect::isNan()const
305 {
306  return ( theUlCorner.hasNans() &&
307  theLrCorner.hasNans() );
308 }
309 
310 #endif /* End of "#ifndef ossimGrect_HEADER" */
ossim_float64 max< ossim_float64 >(ossim_float64 a, ossim_float64 b)
Definition: ossimCommon.h:250
double lond() const
Will convert the radian measure to degrees.
Definition: ossimGpt.h:97
void makeNan()
Definition: ossimGrect.h:284
void combine(const std::string &left, const std::string &right, char separator, std::string &result)
ossim_float64 width() const
Returns the width of a rectangle in deg.
Definition: ossimGrect.h:247
void makeNan()
Definition: ossimGpt.h:130
ossimGrect()
Will default to 0,0,0,0.
Definition: ossimGrect.h:31
ossim_float64 hgt
Height in meters above the ellipsiod.
Definition: ossimGpt.h:274
double latd() const
Will convert the radian measure to degrees.
Definition: ossimGpt.h:87
bool hasNans() const
Definition: ossimGrect.h:298
const ossimDatum * datum() const
datum().
Definition: ossimGpt.h:196
const ossimGrect & operator=(const ossimGrect &rect)
Definition: ossimGrect.h:85
ossimGrect(const ossimGpt &point, double latSpacingInDegrees, double lonSpacingInDegrees)
Definition: ossimGrect.h:66
double ossim_float64
ostream & operator<<(ostream &out, const ossimAxes &axes)
Definition: ossimAxes.h:88
bool pointWithin(const ossimGpt &gpt, bool considerHgt=false) const
METHOD: pointWithin(ossimGpt)
Definition: ossimGrect.h:232
bool isNan() const
Definition: ossimGrect.h:304
ossim_float64 lon
Definition: ossimGpt.h:266
ossimGrect clipToRect(const ossimGrect &rect) const
Definition: ossimGrect.h:190
static ossimDatumFactory * instance()
const ossimGpt & ul() const
Definition: ossimGrect.h:252
ossimGpt ur() const
Definition: ossimGrect.h:257
ossimGpt midPoint() const
Definition: ossimGrect.h:178
ossimGrect combine(const ossimGrect &rect) const
Definition: ossimGrect.h:213
ossimGrect(double ulLat, double ulLon, double lrLat, double lrLon, const ossimDatum *aDatum=ossimDatumFactory::instance() ->wgs84())
Takes the upper left and lower right ground points.
Definition: ossimGrect.h:57
bool hasNans() const
Definition: ossimGpt.h:135
#define OSSIM_DLL
ossimGpt theLrCorner
Definition: ossimGrect.h:169
ossimGrect(const ossimGrect &rect)
Copies the passed in rectangle to this object.
Definition: ossimGrect.h:41
ossim_float64 lat
Definition: ossimGpt.h:265
ossimGpt theUlCorner
Definition: ossimGrect.h:168
bool isLonLatNan() const
Definition: ossimGrect.h:290
ossim_float64 height() const
Returns the height of a rectangle in deg.
Definition: ossimGrect.h:242
const ossimGpt & lr() const
Definition: ossimGrect.h:269
int completely_within(extent_type extent1, extent_type extent2)
ossimGpt ll() const
Definition: ossimGrect.h:263
std::basic_ostream< char > ostream
Base class for char output streams.
Definition: ossimIosFwd.h:23
bool isnan(const float &v)
isnan Test for floating point Not A Number (NAN) value.
Definition: ossimCommon.h:91
ossim_float64 min< ossim_float64 >(ossim_float64 a, ossim_float64 b)
Definition: ossimCommon.h:223