OpendTect-6_4  6.4
uigeom.h
Go to the documentation of this file.
1 #ifndef uigeom_h
2 #define uigeom_h
3 
4 /*+
5 ________________________________________________________________________
6 
7  (C) dGB Beheer B.V.; (LICENSE) http://opendtect.org/OpendTect_license.txt
8  Author: A.H. Lammertink
9  Date: 01/02/2000
10  RCS: $Id$
11 ________________________________________________________________________
12 
13 -*/
14 
15 #include "uibasemod.h"
16 #include "oduicommon.h"
17 #include "geometry.h"
18 #include "enums.h"
19 
23 
24 
25 mExpClass(uiBase) uiSize : public Geom::Size2D<int>
26 {
27 public:
29  : Geom::Size2D<int>( a ) {}
30  uiSize( int wdt=0 , int hgt=0 )
31  : Geom::Size2D<int>(wdt,hgt) {}
32 
33  inline int hNrPics() const { return width_; }
34  inline int vNrPics() const { return height_; }
36  inline void setHNrPics( int np ) { width_ = mMAX(np,1); }
38  inline void setVNrPics( int np ) { height_ = mMAX(np,1); }
39 };
40 
41 
42 mExpClass(uiBase) uiRect : public Geom::PixRectangle<int>
43 {
44 public:
45 
46  enum Side { Left, Right, Top, Bottom };
48  static inline bool isHor( Side s ) { return s > Right; }
49  static uiRect::Side across(uiRect::Side);
50  static uiRect::Side clockWise(uiRect::Side);
51 
52  inline uiRect( int l = 0 , int t = 0, int r = 0 , int b = 0 );
53  inline uiRect( const uiPoint& tl, const uiPoint& br );
54  inline uiRect( const uiPoint& tl, const uiSize& sz );
55  inline uiRect( const Geom::PixRectangle<int>& );
56  inline uiSize getPixelSize() const;
57 
58  inline uiRect selectArea( const uiRect& other ) const;
59  inline bool topToAtLeast( int ref );
60  inline void topTo( int ref );
61  inline bool bottomToAtLeast( int ref );
62  inline void bottomTo( int ref );
63  inline bool leftToAtLeast( int ref );
64  inline void leftTo( int ref );
65  inline void rightTo( int ref );
66  inline bool rightToAtLeast( int ref );
67  inline void expandTo( const uiRect& oth );
68  inline int hNrPics() const;
69  inline int vNrPics() const;
70  inline void setHNrPics( int np );
71  inline void setVNrPics( int np );
72 
73  int get(Side) const;
74  void set(Side,int);
75 };
76 
77 
79 {
80 public:
81  uiBorder( int i=0 ) : lt_(i,i), rb_(i,i) {}
82  uiBorder( int l, int t, int r, int b )
83  : lt_(l,t), rb_(r,b) {}
84  bool operator ==( const uiBorder& b ) const
85  { return lt_ == b.lt_ && rb_ == b.rb_; }
86  bool operator !=( const uiBorder& b ) const
87  { return !(*this == b); }
88 
89  int left() const { return lt_.width(); }
90  int right() const { return rb_.width(); }
91  int top() const { return lt_.height(); }
92  int bottom() const { return rb_.height(); }
93  void setLeft( int i ) { lt_.setWidth(i); }
94  void setRight( int i ) { rb_.setWidth(i); }
95  void setTop( int i ) { lt_.setHeight(i); }
96  void setBottom( int i ) { rb_.setHeight(i); }
97  int get(uiRect::Side) const;
98  void set(uiRect::Side,int);
99 
102 
103  inline uiPoint drawPt(const uiPoint& relpt) const;
104  inline uiPoint relPt(const uiPoint& drawpt) const;
105  inline uiRect getRect(const uiSize&,int extrapix=0) const;
106  inline uiRect getRect(const uiRect&,int extrapix=0) const;
107  uiBorder& operator +=( const uiBorder& b )
108  { lt_ += b.lt_; rb_ += b.rb_; return *this; }
109 };
110 
111 
112 inline uiRect::uiRect( int l, int t, int r, int b )
113  : Geom::PixRectangle<int>( l, t, r, b )
114 {}
115 
116 
117 inline uiRect::uiRect( const uiPoint& tl, const uiPoint& br )
118  : Geom::PixRectangle<int>( tl, br )
119 {}
120 
121 
122 inline uiRect::uiRect( const uiPoint& tl, const uiSize& sz )
123  : Geom::PixRectangle<int>( tl, sz )
124 {}
125 
126 
128  : Geom::PixRectangle<int>( pr )
129 {}
130 
131 
133 { return uiSize( hNrPics(),vNrPics() ); }
134 
135 
136 inline uiRect uiRect::selectArea( const uiRect& other ) const
137 {
138  int hOffset = other.left() - left();
139  int vOffset = other.top() - top();
140  return uiRect( hOffset, vOffset,
141  other.width(), other.height() );
142 }
143 
144 
145 inline bool uiRect::topToAtLeast( int ref )
146 {
147  int shift = ref - top();
148  if ( shift > 0 )
149  {
150  setTop( top() + shift );
151  setBottom( bottom() + shift);
152  return true;
153  }
154  return false;
155 }
156 
157 
158 inline void uiRect::topTo( int ref )
159 {
160  int shift = ref - top();
161  setTop( top() + shift );
162  setBottom( bottom() + shift);
163 }
164 
165 
166 inline bool uiRect::bottomToAtLeast( int ref )
167 {
168  int shift = ref - bottom();
169  if ( shift > 0 )
170  {
171  setTop( top() + shift );
172  setBottom( bottom() + shift);
173  }
174  return false;
175 }
176 
177 
178 inline void uiRect::bottomTo( int ref )
179 {
180  int shift = ref - bottom();
181  setTop( top() + shift );
182  setBottom( bottom() + shift);
183 }
184 
185 
186 inline bool uiRect::leftToAtLeast( int ref )
187 {
188  int shift = ref - left();
189  if ( shift > 0 )
190  {
191  setLeft( left() + shift );
192  setRight( right() + shift );
193  return true;
194  }
195  return false;
196 }
197 
198 inline void uiRect::leftTo( int ref )
199 {
200  int shift = ref - left();
201  setLeft( left() + shift );
202  setRight( right() + shift );
203 }
204 
205 
206 inline void uiRect::rightTo( int ref )
207 {
208  int shift = ref - right();
209  setLeft( left() + shift );
210  setRight( right() + shift );
211 }
212 
213 
214 inline bool uiRect::rightToAtLeast( int ref )
215 {
216  int shift = ref - right();
217  if ( shift > 0 )
218  {
219  setLeft( left() + shift );
220  setRight( right() + shift );
221  return true;
222  }
223  return false;
224 }
225 
226 
227 inline void uiRect::expandTo( const uiRect& oth )
228 {
229  sortCorners();
230  topleft_.x = mMIN( topleft_.x, oth.topleft_.x );
231  topleft_.y = mMIN( topleft_.y, oth.topleft_.y );
233  oth.bottomright_.x );
235  oth.bottomright_.y );
236 }
237 
238 
239 inline int uiRect::hNrPics() const { return width() + 1; }
240 
241 
242 inline int uiRect::vNrPics() const { return height()+ 1; }
243 
244 
246 inline void uiRect::setHNrPics( int np )
247 { setRight( left() + mMAX( 1, np ) - 1 ); }
248 
249 
251 inline void uiRect::setVNrPics( int np )
252 { setBottom( top() + mMAX( 1, np ) - 1 ); }
253 
254 
256 { return uiRect::isHor(s) ? (s == uiRect::Top ? uiRect::Bottom :uiRect::Top)
257  : (s == uiRect::Left ? uiRect::Right : uiRect::Left); }
259 { return uiRect::isHor(s) ? (s == uiRect::Top ? uiRect::Left :uiRect::Right)
261 
262 #define mUIGeomImplSideFns(clss) \
263 inline int clss::get( uiRect::Side s ) const \
264 { return uiRect::isHor(s) ? (s == uiRect::Top ? top() : bottom()) \
265  : (s == uiRect::Left ? left() : right() ); } \
266 inline void clss::set( uiRect::Side s, int i ) \
267 { uiRect::isHor(s) ? (s == uiRect::Top ? setTop(i) : setBottom(i)) \
268  : (s == uiRect::Left ? setLeft(i) : setRight(i)); }
269 
272 
273 
274 inline uiPoint uiBorder::drawPt( const uiPoint& relpt ) const
275 {
276  return uiPoint( relpt.x+lt_.width(), relpt.y+lt_.height());
277 }
278 
279 
280 inline uiPoint uiBorder::relPt( const uiPoint& dpt ) const
281 {
282  return uiPoint( dpt.x-lt_.width(), dpt.y-lt_.height() );
283 }
284 
285 
286 inline uiRect uiBorder::getRect( const uiSize& sz, int extr ) const
287 {
288  return uiRect( lt_.width()+extr, lt_.height()+extr,
289  sz.width()-rb_.width()-2*extr,
290  sz.height()-rb_.height()-2*extr );
291 }
292 
293 
294 inline uiRect uiBorder::getRect( const uiRect& rect, int extr ) const
295 {
296  return uiRect( rect.left()+lt_.width()+extr,rect.top()+lt_.height()+extr,
297  rect.right()-rb_.width()-2*extr,
298  rect.bottom()-rb_.height()-2*extr );
299 }
300 
301 #define mGoldenRatio 1.618034f
302 
303 inline int GetGoldenMajor( int inp )
304 {
305  const float val = inp * mGoldenRatio;
306  return inp > 0 ? (int)(val+.5f) : (int)(val - .5f);
307 }
308 
309 static const float cGoldenRatio = 1.618034f;
310 inline int GetGoldenMinor( int inp )
311 {
312  const float val = inp / mGoldenRatio;
313  return inp > 0 ? (int)(val+.5f) : (int)(val - .5f);
314 }
315 
316 
317 #endif
#define mExpClass(module)
Definition: commondefs.h:160
void bottomTo(int ref)
Definition: uigeom.h:178
Definition: uigeom.h:46
T width() const
Definition: geometry.h:554
uiBorder(int l, int t, int r, int b)
Definition: uigeom.h:82
Definition: uigeom.h:42
Definition: uilayout.h:22
T left() const
Definition: geometry.h:564
int right() const
Definition: uigeom.h:90
bool operator==(const ArrayNDInfo &a1, const ArrayNDInfo &a2)
Definition: arrayndinfo.h:53
uiSize getPixelSize() const
Definition: uigeom.h:132
uiRect selectArea(const uiRect &other) const
Definition: uigeom.h:136
void setTop(int val)
uiRect(int l=0, int t=0, int r=0, int b=0)
Definition: uigeom.h:112
void sortCorners(bool leftislow=true, bool topislow=true)
bool leftToAtLeast(int ref)
Definition: uigeom.h:186
PixRectangle(int l=0, int t=0, int r=0, int b=0)
void leftTo(int ref)
Definition: uigeom.h:198
bool bottomToAtLeast(int ref)
Definition: uigeom.h:166
void setVNrPics(int np)
nr of pics should be > 0
Definition: uigeom.h:251
void rightTo(int ref)
Definition: uigeom.h:206
Point2D< int > bottomright_
Definition: geometry.h:178
uiSize lt_
Definition: uigeom.h:100
T width() const
Definition: geometry.h:403
mDeclareEnumUtils(Side) static inline bool isHor(Side s)
Definition: uigeom.h:47
void setHNrPics(int np)
nr of pics should be > 0
Definition: uigeom.h:246
Definition: uigeom.h:46
void setBottom(int val)
#define mMIN(x, y)
Definition: commondefs.h:49
Definition: uigeom.h:25
void setHNrPics(int np)
nr of pics should be > 0
Definition: uigeom.h:36
bool rightToAtLeast(int ref)
Definition: uigeom.h:214
int left() const
Definition: uigeom.h:89
T height() const
Definition: geometry.h:559
int top() const
Definition: uigeom.h:91
int GetGoldenMajor(int inp)
Definition: uigeom.h:303
uiPoint relPt(const uiPoint &drawpt) const
Definition: uigeom.h:280
bool topToAtLeast(int ref)
Definition: uigeom.h:145
Definition: uigeom.h:46
#define mUIGeomImplSideFns(clss)
Definition: uigeom.h:262
static const float cGoldenRatio
Definition: uigeom.h:309
int vNrPics() const
Definition: uigeom.h:34
void setRight(int i)
Definition: uigeom.h:94
T y
Definition: geometry.h:67
#define mGoldenRatio
Definition: uigeom.h:301
void setRight(int val)
int bottom() const
Definition: uigeom.h:92
void setBottom(int i)
Definition: uigeom.h:96
void setLeft(int val)
uiSize rb_
Definition: uigeom.h:101
T top() const
Definition: geometry.h:569
bool operator!=(const ArrayNDInfo &a1, const ArrayNDInfo &a2)
Definition: arrayndinfo.h:62
void expandTo(const uiRect &oth)
Definition: uigeom.h:227
Definition: uigeom.h:78
uiRect getRect(const uiSize &, int extrapix=0) const
Definition: uigeom.h:286
uiSize(const Geom::Size2D< int > &a)
Definition: uigeom.h:28
Geom::PosRectangle< double > uiWorldRect
Definition: uigeom.h:22
void setTop(int i)
Definition: uigeom.h:95
T x
Definition: geometry.h:66
Point2D< int > topleft_
Definition: geometry.h:177
void setLeft(int i)
Definition: uigeom.h:93
Definition: uigeom.h:46
Geom::Point2D< double > uiWorldPoint
Definition: uigeom.h:21
Geom::Point2D< int > uiPoint
Definition: uigeom.h:20
int vNrPics() const
Definition: uigeom.h:242
int hNrPics() const
Definition: uigeom.h:239
Definition: geometry.h:19
uiSize(int wdt=0, int hgt=0)
Definition: uigeom.h:30
int hNrPics() const
Definition: uigeom.h:33
uiBorder(int i=0)
Definition: uigeom.h:81
LeftTo/RightTo allow extra horizonal distance.
Definition: uilayout.h:22
int GetGoldenMinor(int inp)
Definition: uigeom.h:310
void setVNrPics(int np)
nr of pics should be > 0
Definition: uigeom.h:38
T height() const
Definition: geometry.h:408
static uiRect::Side across(uiRect::Side)
Definition: uigeom.h:255
void topTo(int ref)
Definition: uigeom.h:158
static uiRect::Side clockWise(uiRect::Side)
Definition: uigeom.h:258
Side
Definition: uigeom.h:46
#define mMAX(x, y)
Definition: commondefs.h:48

Generated at for the OpendTect seismic interpretation project. Copyright (C): dGB Beheer B. V. 2019