OpendTect-6_4  6.4
axislayout.h
Go to the documentation of this file.
1 #ifndef axislayout_h
2 #define axislayout_h
3 
4 /*+
5 ________________________________________________________________________
6 
7  (C) dGB Beheer B.V.; (LICENSE) http://opendtect.org/OpendTect_license.txt
8  Author: A.H.Bril
9  Date: Jan 2005 / Dec 2009
10  RCS: $Id$
11 ________________________________________________________________________
12 
13 -*/
14 
15 #include "algomod.h"
16 #include "ranges.h"
17 #include "samplingdata.h"
18 
19 #include <math.h>
20 
21 
26 template <class T>
28 {
29 public:
30  // Have layout calculated
31  AxisLayout( const Interval<T>& dr, bool asint=false,
32  bool inside=false )
33  : annotinint_(asint)
34  , annotinsiderg_(inside)
35  { setDataRange( dr ); }
36 
37  void setDataRange(const Interval<T>&);
38  StepInterval<T> getSampling() const;
39 
41  T stop_;
44 
45  // Init with explicit layout
46  AxisLayout( T start=0, T st_op=1,
47  T step=1 )
48  : sd_(start,step), stop_(st_op)
49  , annotinsiderg_(false)
50  , annotinint_(false) {}
51 
53  : sd_(rg.start,rg.step)
54  , stop_(rg.stop)
55  , annotinsiderg_(false)
56  , annotinint_(false) {}
57 
58  // Returns 'modulo' end with this sd_ and stop_
59  T findEnd(T datastop) const;
60 };
61 
62 
63 template <class T> inline
65 { return StepInterval<T>( sd_.start, stop_, sd_.step ); }
66 
67 
68 template <class T> inline
70 {
71  Interval<T> intv = dr;
72  sd_.start = intv.start;
73  const bool rev = intv.start > intv.stop;
74  if ( rev ) Swap( intv.start, intv.stop );
75  T wdth = intv.width();
76 
77 
78  // guard against zero interval
79  T indic = intv.start + wdth;
80  T indic_start = intv.start;
81  if ( mIsZero(indic,mDefEps) ) { indic_start += 1; indic += 1; }
82  indic = 1 - indic_start / indic;
83  if ( mIsZero(indic,mDefEps) )
84  {
85  sd_.start = intv.start - 1;
86  sd_.step = 1;
87  stop_ = intv.start + 1;
88  return;
89  }
90 
91  double scwdth = wdth < 1e-30 ? -30 : log10( (double)wdth );
92  int tenpow = 1 - (int)scwdth; if ( scwdth < 0 ) tenpow++;
93  double stepfac = Math::IntPowerOf( ((double)10), tenpow );
94  scwdth = wdth * stepfac;
95 
96  double scstep;
97  if ( scwdth < 15 ) scstep = annotinint_ ? 2. : 2.5;
98  else if ( scwdth < 30 ) scstep = 5;
99  else if ( scwdth < 50 ) scstep = 10;
100  else scstep = 20;
101 
102  sd_.step = (T) ( scstep / stepfac );
103  if ( annotinint_ )
104  {
105  int istep = mNINT32( sd_.step );
106  if ( istep == 0 )
107  istep = 1;
108  sd_.step = (T)istep;
109  }
110 
111  if ( mIsZero(sd_.step,mDefEps) )
112  sd_.step = 1;
113 
114  if ( wdth > 1e-30 )
115  {
116  double idx0 = 0;
117  if ( annotinsiderg_ )
118  {
119  idx0 = rev ? Math::Floor(intv.stop / sd_.step + 1e-6)
120  : Math::Ceil(intv.start / sd_.step + 1e-6);
121  }
122  else
123  {
124  idx0 = rev ? Math::Ceil(intv.stop / sd_.step + 1e-6)
125  : Math::Floor(intv.start / sd_.step + 1e-6);
126  }
127 
128  sd_.start = mNINT32( idx0 ) * sd_.step;
129  }
130  if ( rev ) sd_.step = -sd_.step;
131 
132  stop_ = findEnd( rev ? intv.start : intv.stop );
133 }
134 
135 
136 template <class T> inline
137 T AxisLayout<T>::findEnd( T datastop ) const
138 {
139  SamplingData<T> worksd = sd_;
140  const bool rev = worksd.step < 0;
141  if ( rev )
142  {
143  worksd.start = -worksd.start;
144  worksd.step = -worksd.step;
145  datastop = -datastop;
146  }
147 
148  if ( worksd.start + 10000 * worksd.step < datastop )
149  return datastop;
150 
151  const double dnrsteps = double(datastop-worksd.start)/worksd.step - 1e-6;
152  int nrsteps =
153  mNINT32( (annotinsiderg_ ? Math::Floor(dnrsteps)
154  : Math::Ceil(dnrsteps)) );
155  if ( nrsteps < 1 ) nrsteps = 1;
156  T wdth = nrsteps * worksd.step;
157  return sd_.start + (rev ? -wdth : wdth);
158 }
159 
160 #endif
T step
Definition: samplingdata.h:50
SamplingData< T > sd_
Definition: axislayout.h:40
float Ceil(float)
#define mIsZero(x, eps)
Definition: commondefs.h:53
if(!noudf_ &&(mIsUdf(inpval)))
Definition: arrayndalgo.h:1662
AxisLayout(T start=0, T st_op=1, T step=1)
Definition: axislayout.h:46
void setDataRange(const Interval< T > &)
Definition: axislayout.h:69
Interval of values.
Definition: commontypes.h:31
T findEnd(T datastop) const
Definition: axislayout.h:137
float Floor(float)
#define mNINT32(x)
Definition: commondefs.h:45
Helps making nice axes for graphs.
Definition: axislayout.h:27
T width(bool allowrev=true) const
Definition: ranges.h:451
T start
Definition: samplingdata.h:49
Interval with step.
Definition: commontypes.h:33
void Swap(T &a, T &b)
Definition: commondefs.h:36
T stop_
Definition: axislayout.h:41
#define mDefEps
Definition: commondefs.h:58
bool annotinsiderg_
Definition: axislayout.h:43
StepInterval< T > getSampling() const
Definition: axislayout.h:64
T stop
Definition: ranges.h:93
AxisLayout(const Interval< T > &dr, bool asint=false, bool inside=false)
Definition: axislayout.h:31
AxisLayout(const StepInterval< T > &rg)
Definition: axislayout.h:52
T start
Definition: ranges.h:92
Holds the fundamental sampling info: start and interval.
Definition: samplingdata.h:22
#define mClass(module)
Definition: commondefs.h:164
iT IntPowerOf(iT i, iPOW p)
Definition: math2.h:122
bool annotinint_
Definition: axislayout.h:42

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