OpendTect-6_4  6.4
coltabmapper.h
Go to the documentation of this file.
1 #ifndef coltabmapper_h
2 #define coltabmapper_h
3 
4 /*+
5 ________________________________________________________________________
6 
7  (C) dGB Beheer B.V.; (LICENSE) http://opendtect.org/OpendTect_license.txt
8  Author: Bert
9  Date: Sep 2007
10  RCS: $Id$
11 ________________________________________________________________________
12 
13 -*/
14 
15 #include "generalmod.h"
16 #include "enums.h"
17 #include "coltab.h"
18 #include "math2.h"
19 #include "valseries.h"
20 #include "threadlock.h"
21 #include "varlenarray.h"
22 
23 #define mUndefColIdx (nrsteps_)
24 
25 class DataClipper;
26 class TaskRunner;
27 
28 namespace ColTab
29 {
30 
35 mExpClass(General) MapperSetup : public CallBacker
36 {
37 public:
38  MapperSetup();
39  enum Type { Fixed, Auto, HistEq };
41 
44  mDefSetupClssMemb(MapperSetup,bool,autosym0)
45  mDefSetupClssMemb(MapperSetup,float,symmidval)
46  mDefSetupClssMemb(MapperSetup,int,maxpts)
48  mDefSetupClssMemb(MapperSetup,int,nrsegs)
49  mDefSetupClssMemb(MapperSetup,bool,flipseq)
50  mDefSetupClssMemb(MapperSetup,Interval<float>,range)
51 
52  bool operator==(const MapperSetup&) const;
53  bool operator!=(const MapperSetup&) const;
54  MapperSetup& operator=(const MapperSetup&);
55 
56  bool needsReClip(const MapperSetup&) const;
58 
59  void fillPar(IOPar&) const;
60  bool usePar(const IOPar&);
61  static const char* sKeyClipRate() { return "Clip Rate"; }
62  static const char* sKeyAutoSym() { return "Auto Sym"; }
63  static const char* sKeySymMidVal() { return "Sym Mid Value"; }
64  static const char* sKeyStarWidth() { return "Start_Width"; }
65  static const char* sKeyRange() { return "Range"; }
66  static const char* sKeyFlipSeq() { return "Flip seq"; }
67 
68  void triggerRangeChange();
69  void triggerAutoscaleChange();
72 
73  void setAutoScale(bool);
74 };
75 
76 
84 mExpClass(General) Mapper
85 {
86 public:
87 
88  Mapper();
89  ~Mapper();
90 
91  float position(float val) const;
93  static int snappedPosition(const Mapper*,float val,
94  int nrsteps,int udfval);
95  const Interval<float>& range() const;
96  bool isFlipped() const { return setup_.flipseq_; }
97  const ValueSeries<float>* data() const { return vs_; }
98  od_int64 dataSize() const { return vssz_; }
99 
100  void setFlipped(bool yn) { setup_.flipseq_ = yn; }
101 
102  void setRange( const Interval<float>& rg );
103  void setData(const ValueSeries<float>*,od_int64 sz,
104  TaskRunner* = 0);
106 
107  void update(bool full=true, TaskRunner* = 0);
110 
111 protected:
112 
114 
117 
118 };
119 
120 
125 template <class T>
126 mClass(General) MapperTask : public ParallelTask
128 public:
129  MapperTask(const ColTab::Mapper& map,
130  od_int64 sz,T nrsteps,
131  const float* unmapped,
132  T* mappedvals,int mappedvalspacing=1,
133  T* mappedundef=0,int mappedundefspacing=1);
138  MapperTask(const ColTab::Mapper& map,
139  od_int64 sz,T nrsteps,
140  const ValueSeries<float>& unmapped,
141  T* mappedvals, int mappedvalspacing=1,
142  T* mappedundef=0,int mappedundefspacing=1);
147  ~MapperTask();
148  od_int64 nrIterations() const;
149  const unsigned int* getHistogram() const { return histogram_; }
150 
151 private:
152  bool doWork(od_int64 start,od_int64 stop,int);
154  { return tr("Data values mapped"); }
155 
158  const float* unmapped_;
165  unsigned int* histogram_;
167 };
168 
169 
170 template <class T> inline
172  const float* unmapped,
173  T* mappedvals, int mappedvalsspacing,
174  T* mappedudfs, int mappedudfspacing )
175  : ParallelTask( "Color table mapping" )
176  , mapper_( map )
177  , totalsz_( sz )
178  , nrsteps_( nrsteps )
179  , unmapped_( unmapped )
180  , unmappedvs_( 0 )
181  , mappedvals_( mappedvals )
182  , mappedudfs_( mappedudfs )
183  , mappedvalsspacing_( mappedvalsspacing )
184  , mappedudfspacing_( mappedudfspacing )
185  , histogram_( new unsigned int[nrsteps+1] )
186 {
187  OD::memZero( histogram_, (mUndefColIdx+1)*sizeof(unsigned int) );
188 }
189 
190 
191 template <class T> inline
192 MapperTask<T>::MapperTask( const ColTab::Mapper& map, od_int64 sz, T nrsteps,
193  const ValueSeries<float>& unmapped,
194  T* mappedvals, int mappedvalsspacing,
195  T* mappedudfs, int mappedudfspacing )
196  : ParallelTask( "Color table mapping" )
197  , mapper_( map )
198  , totalsz_( sz )
199  , nrsteps_( nrsteps )
200  , unmapped_( unmapped.arr() )
201  , unmappedvs_( unmapped.arr() ? 0 : &unmapped )
202  , mappedvals_( mappedvals )
203  , mappedudfs_( mappedudfs )
204  , mappedvalsspacing_( mappedvalsspacing )
205  , mappedudfspacing_( mappedudfspacing )
206  , histogram_( new unsigned int[nrsteps+1] )
207 {
208  OD::memZero( histogram_, (mUndefColIdx+1)*sizeof(unsigned int) );
209 }
210 
211 
212 template <class T> inline
214 {
215  delete [] histogram_;
216 }
217 
218 
219 template <class T> inline
221 { return totalsz_; }
222 
223 
224 template <class T> inline
225 bool MapperTask<T>::doWork( od_int64 start, od_int64 stop, int )
226 {
227  mAllocVarLenArr( unsigned int, histogram, mUndefColIdx+1);
228 
229  OD::memZero( histogram, (mUndefColIdx+1)*sizeof(unsigned int) );
230 
231  T* valresult = mappedvals_+start*mappedvalsspacing_;
232  T* udfresult = mappedudfs_ ? mappedudfs_+start*mappedudfspacing_ : 0;
233  const float* inp = unmapped_+start;
234 
235  const ValueSeries<float>* unmappedvs = unmappedvs_;
236  const int mappedvalsspacing = mappedvalsspacing_;
237  const int mappedudfspacing = mappedudfspacing_;
238  const int nrsteps = nrsteps_;
239  const int udfcolidx = mUndefColIdx;
240 
241  const int nrsegs = mapper_.setup_.nrsegs_;
242  const bool flipseq = mapper_.setup_.flipseq_;
243  const float rangewidth = mapper_.setup_.range_.width( false );
244  const bool rangehaswidth = !mIsZero(rangewidth,mDefEps);
245  const float rangestart = mapper_.setup_.range_.start;
246 
247  int nrdone = 0;
248  for ( od_int64 idx=start; idx<=stop; idx++ )
249  {
250  const float input = unmappedvs ? unmappedvs->value(idx) : *inp++;
251 
252  float position = 0.0f;
253  bool isudf = true;
254 
255  if ( mFastIsFloatDefined(input) )
256  {
257  isudf = false;
258  if ( rangehaswidth )
259  {
260  position = (input-rangestart) / rangewidth;
261  if ( nrsegs > 0 )
262  position = (0.5f + ((int) (position*nrsegs))) / nrsegs;
263 
264  if ( position > 1.0f )
265  position = 1.0f;
266  else if ( position < 0.0f )
267  position = 0.0f;
268 
269  if ( flipseq )
270  position = 1.0f - position;
271 
272  position *= nrsteps;
273 
274  if ( position > nrsteps-0.9f )
275  position = nrsteps - 0.9f;
276  else if ( position < 0.0f )
277  position = 0.0f;
278  }
279  }
280 
281  const T res = (T) ( isudf ? udfcolidx : (int) position );
282 
283  *valresult = res;
284  valresult += mappedvalsspacing;
285 
286  if ( udfresult )
287  {
288  *udfresult = (T) (isudf ? 0 : udfcolidx);
289  udfresult += mappedudfspacing;
290  }
291 
292  histogram[res]++;
293 
294  if ( nrdone > 100000 )
295  {
296  addToNrDone( nrdone );
297  nrdone = 0;
298  if ( !shouldContinue() )
299  return false;
300  }
301  }
302 
303  if ( nrdone )
304  addToNrDone( nrdone );
305 
306  Threads::Locker lckr( lock_ );
307  for ( int idx=0; idx<=mUndefColIdx; idx++ )
308  histogram_[idx] += histogram[idx];
309 
310  return true;
311 }
312 
313 
314 } // namespace ColTab
315 
316 #endif
#define mExpClass(module)
Definition: commondefs.h:160
virtual T value(int64_t) const =0
To be able to send and/or receive CallBacks, inherit from this class.
Definition: callback.h:272
int mappedudfspacing_
Definition: coltabmapper.h:163
Locks the lock, shutting out access from other threads if needed.
Definition: threadlock.h:85
uiString uiNrDoneText() const
will be nrDoneText() in 7.x
Definition: coltabmapper.h:153
A lock of a type that (hopefully) suits your needs. To use it, you need the Locker class...
Definition: threadlock.h:53
unsigned int * histogram_
Definition: coltabmapper.h:165
const ColTab::Mapper & mapper_
Definition: coltabmapper.h:156
mODTextTranslationClass(MapperTask) public MapperTask(const ColTab::Mapper &map, od_int64 sz, T nrsteps, const ValueSeries< float > &unmapped, T *mappedvals, int mappedvalspacing=1, T *mappedundef=0, int mappedundefspacing=1)
Definition: coltabmapper.h:171
~MapperTask()
Definition: coltabmapper.h:213
#define mODTextTranslationClass(clss)
Definition: uistring.h:38
od_int64 nrIterations() const
Definition: coltabmapper.h:220
#define mIsZero(x, eps)
Definition: commondefs.h:53
#define mUndefColIdx
Definition: coltabmapper.h:23
void usePar(const IOPar &iop, ODPolygon< T > &poly, const char *inpkey)
Definition: polygon.h:188
#define od_int64
Definition: plftypes.h:36
#define mDefSetupClssMemb(clss, typ, memb)
Definition: commondefs.h:133
od_int64 dataSize() const
Definition: coltabmapper.h:98
T nrsteps_
Definition: coltabmapper.h:164
virtual bool shouldContinue()
Definition: uistring.h:89
Maps data values to colortable positions: [0,1].
Definition: coltabmapper.h:84
ParallelTask(const char *nm=0)
#define mDeclareEnumUtils(enm)
Some utilities surrounding the often needed enum <-> string table.
Definition: enums.h:258
Interval of values.
Definition: commontypes.h:31
Generalization of a task that can be run in parallel.
Definition: paralleltask.h:66
static const char * sKeyFlipSeq()
Definition: coltabmapper.h:66
Definition: callback.h:254
Generalized set of parameters of the keyword-value type.
Definition: iopar.h:47
Class that can execute a task.
Definition: task.h:169
const ValueSeries< float > * unmappedvs_
Definition: coltabmapper.h:159
int mappedvalsspacing_
Definition: coltabmapper.h:161
const unsigned int * getHistogram() const
Definition: coltabmapper.h:149
static const char * sKeyRange()
Definition: coltabmapper.h:65
static const char * sKeyStarWidth()
Definition: coltabmapper.h:64
od_int64 vssz_
Definition: coltabmapper.h:116
Notifier< MapperSetup > rangeChange
Definition: coltabmapper.h:70
Setup class for colortable Mapper.
Definition: coltabmapper.h:35
T * mappedvals_
Definition: coltabmapper.h:160
#define mAllocVarLenArr(type, varnm, __size)
Definition: varlenarray.h:54
void fillPar(IOPar &iop, const ODPolygon< T > &poly, const char *inpkey)
Definition: polygon.h:175
#define mDefEps
Definition: commondefs.h:58
Threads::Lock lock_
Definition: coltabmapper.h:166
bool doWork(od_int64 start, od_int64 stop, int)
Definition: coltabmapper.h:225
static const char * sKeyAutoSym()
Definition: coltabmapper.h:62
void setFlipped(bool yn)
Definition: coltabmapper.h:100
T * mappedudfs_
Definition: coltabmapper.h:162
const ValueSeries< float > * vs_
Definition: coltabmapper.h:115
MapperSetup setup_
Definition: coltabmapper.h:109
#define mFastIsFloatDefined(fval)
Definition: undefval.h:295
DataClipper & clipper_
Definition: coltabmapper.h:113
Color Table
Definition: coltab.h:22
Notifier< MapperSetup > autoscaleChange
Definition: coltabmapper.h:71
#define mClass(module)
Definition: commondefs.h:164
static const char * sKeySymMidVal()
Definition: coltabmapper.h:63
void addToNrDone(int64_t increment)
const float * unmapped_
Definition: coltabmapper.h:158
virtual T * arr()
Definition: valseries.h:55
Type
Definition: coltabmapper.h:39
bool isFlipped() const
Definition: coltabmapper.h:96
od_int64 totalsz_
Definition: coltabmapper.h:157
const ValueSeries< float > * data() const
Definition: coltabmapper.h:97
A DataClipper gets a bunch of data and determines at what value to clip if a certain clip percentage ...
Definition: dataclipper.h:73
Takes a Mapper, unmapped data and maps it.
Definition: coltabmapper.h:126

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