OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
ossimVrect.h
Go to the documentation of this file.
1 //*******************************************************************
2 //
3 // Copyright (C) 2000 ImageLinks Inc.
4 //
5 // License: MIT
6 //
7 // See LICENSE.txt file in the top level directory for more details.
8 //
9 // Author: Garrett Potts
10 //
11 // Description:
12 //
13 // Contains class declaration for vrect.
14 // Container class for four double points representing a rectangle
15 // where y is up
16 //
17 //*******************************************************************
18 // $Id: ossimVrect.h 11955 2007-10-31 16:10:22Z gpotts $
19 #ifndef ossimVrect_HEADER
20 #define ossimVrect_HEADER
21 #include <iostream>
22 
23 #include <ossim/base/ossimDpt.h>
24 
26 {
27 public:
29  :theUlCorner(0.0, 0.0),
30  theLlCorner(0.0, 0.0),
31  theLrCorner(0.0, 0.0),
32  theUrCorner(0.0, 0.0)
33  {}
34  ossimVrect(const ossimDpt &ul,
35  const ossimDpt &lr)
36  :theUlCorner(ul),
37  theLlCorner(ul.x, lr.y),
38  theLrCorner(lr),
39  theUrCorner(lr.x, ul.y)
40  {}
41  ossimVrect(double ul_corner_x,
42  double ul_corner_y,
43  double lr_corner_x,
44  double lr_corner_y)
45  :
46  theUlCorner(ul_corner_x, ul_corner_y),
47  theLlCorner(ul_corner_x, lr_corner_y),
48  theLrCorner(lr_corner_x, lr_corner_y),
49  theUrCorner(lr_corner_x, ul_corner_y)
50  {}
51  ossimVrect(const ossimVrect& rect)
52  :
53  theUlCorner(rect.ul()),
54  theLlCorner(rect.ll()),
55  theLrCorner(rect.lr()),
56  theUrCorner(rect.ur())
57  {}
58 
59  ~ossimVrect();
60 
61  const ossimVrect& operator= (const ossimVrect& rect);
62  bool operator!= (const ossimVrect& rect) const;
63  bool operator== (const ossimVrect& rect) const;
64 
65  const ossimDpt &ul() const { return theUlCorner; }
66  const ossimDpt &ur() const { return theUrCorner; }
67  const ossimDpt &lr() const { return theLrCorner; }
68  const ossimDpt &ll() const { return theLlCorner; }
73  { return fabs(theLlCorner.y - theUlCorner.y) + 1.0; }
74 
79  { return fabs(theLrCorner.x - theLlCorner.x) + 1.0; }
80 
81  inline ossimDpt midPoint()const;
82  void print(std::ostream& os) const;
83 
84  ossimVrect combine(const ossimVrect& rect)const;
85  inline ossimVrect clipToRect(const ossimVrect& rect)const;
86 
87  friend std::ostream& operator<<(std::ostream& os, const ossimVrect& rect);
88 
89 private:
94 };
95 
96 inline const ossimVrect& ossimVrect::operator=(const ossimVrect& rect)
97 {
98  if (this != &rect)
99  {
100  theUlCorner = rect.ul();
101  theUrCorner = rect.ur();
102  theLrCorner = rect.lr();
103  theLlCorner = rect.ll();
104  }
105 
106  return *this;
107 }
108 
109 inline bool ossimVrect::operator!=(const ossimVrect& rect) const
110 {
111  return ( (theUlCorner != rect.ul()) ||
112  (theUrCorner != rect.ur()) ||
113  (theLrCorner != rect.lr()) ||
114  (theLlCorner != rect.ll()) );
115 }
116 
117 inline bool ossimVrect::operator==(const ossimVrect& rect) const
118 {
119  return ( (theUlCorner == rect.ul()) &&
120  (theUrCorner == rect.ur()) &&
121  (theLrCorner == rect.lr()) &&
122  (theLlCorner == rect.ll()) );
123 }
124 
125 
127 {
128  ossim_float64 ulx, uly, lrx, lry;
129 
130  // XXX not replaced with std::max or ossim::max since the test is backward
131  // here and will give a different answer in the case of nan.
132  #define d_MAX(a,b) (((a)>(b)) ? a : b)
133 
134  ulx = d_MAX(rect.ul().x,ul().x);
135  uly = d_MAX(rect.ul().y,ul().y);
136 
137  #undef d_MAX
138 
139  lrx = std::min(rect.lr().x,lr().x);
140  lry = std::min(rect.lr().y,lr().y);
141 
142  if( lrx <= ulx || lry <= uly )
143  return ossimVrect(ossimDpt(0,0),ossimDpt(0,0));
144  else
145  return ossimVrect(ulx,uly,lrx,lry);
146 }
147 
149 {
150  return ossimDpt( (ul().x + ur().x + ll().x + lr().x)*.25,
151  (ul().y + ur().y + ll().y + lr().y)*.25);
152 }
153 
154 inline ossimVrect ossimVrect::combine(const ossimVrect& rect)const
155 {
156  ossimDpt ulCombine;
157  ossimDpt lrCombine;
158 
159  ulCombine.x = ((ul().x <= rect.ul().x)?ul().x:rect.ul().x);
160  ulCombine.y = ((ul().y >= rect.ul().y)?ul().y:rect.ul().y);
161  lrCombine.x = ((lr().x >= rect.lr().x)?lr().x:rect.lr().x);
162  lrCombine.y = ((lr().y <= rect.lr().y)?lr().y:rect.lr().y);
163 
164  return ossimVrect(ulCombine, lrCombine);
165 }
166 
167 #endif
ossimVrect clipToRect(const ossimVrect &rect) const
Definition: ossimVrect.h:126
ossim_uint32 x
ossimDpt theLrCorner
Definition: ossimVrect.h:92
ossimDpt theUlCorner
Definition: ossimVrect.h:90
ossim_float64 height() const
Definition: ossimVrect.h:72
#define OSSIMDLLEXPORT
bool operator!=(const ossimRefPtr< _Tp1 > &__a, const ossimRefPtr< _Tp2 > &__b) noexcept
Definition: ossimRefPtr.h:111
const ossimDpt & ur() const
Definition: ossimVrect.h:66
ossim_uint32 y
void combine(const std::string &left, const std::string &right, char separator, std::string &result)
double y
Definition: ossimDpt.h:165
std::ostream & print(H5::H5File *file, std::ostream &out)
Print method.
Definition: ossimH5Util.cpp:41
ossimVrect(const ossimVrect &rect)
Definition: ossimVrect.h:51
bool operator==(const ossimVrect &rect) const
Definition: ossimVrect.h:117
ossimVrect(double ul_corner_x, double ul_corner_y, double lr_corner_x, double lr_corner_y)
Definition: ossimVrect.h:41
#define d_MAX(a, b)
double ossim_float64
ostream & operator<<(ostream &out, const ossimAxes &axes)
Definition: ossimAxes.h:88
ossimVrect combine(const ossimVrect &rect) const
Definition: ossimVrect.h:154
const ossimDpt & ul() const
Definition: ossimVrect.h:65
const ossimDpt & ll() const
Definition: ossimVrect.h:68
bool operator==(const ossimRefPtr< _Tp1 > &__a, const ossimRefPtr< _Tp2 > &__b) noexcept
Definition: ossimRefPtr.h:101
const ossimDpt & lr() const
Definition: ossimVrect.h:67
ossimDpt midPoint() const
Definition: ossimVrect.h:148
ossimDpt theLlCorner
Definition: ossimVrect.h:91
ossim_float64 width() const
Definition: ossimVrect.h:78
double x
Definition: ossimDpt.h:164
ossimDpt theUrCorner
Definition: ossimVrect.h:93
const ossimVrect & operator=(const ossimVrect &rect)
Definition: ossimVrect.h:96
bool operator!=(const ossimVrect &rect) const
Definition: ossimVrect.h:109
ossimVrect(const ossimDpt &ul, const ossimDpt &lr)
Definition: ossimVrect.h:34
std::basic_ostream< char > ostream
Base class for char output streams.
Definition: ossimIosFwd.h:23
#define min(a, b)
Definition: auxiliary.h:75