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

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