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

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