OpendTect-6_4  6.4
array2dresample.h
Go to the documentation of this file.
1 #ifndef array2dresample_h
2 #define array2dresample_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: 26/07/2000
10  RCS: $Id$
11 ________________________________________________________________________
12 
13 -*/
14 
15 #include "arraynd.h"
16 #include "array2dfunc.h"
17 #include "task.h"
18 #include "geometry.h"
19 #include "interpol2d.h"
20 
29 template <class T, class TT>
32 public:
33 
34  inline Array2DReSampler(const Array2D<T>& from,
35  Array2D<TT>& to, bool fromhasudfs,
36  const Geom::PosRectangle<float>* rectinfrom=0 );
40  inline Array2DReSampler(const Array2D<T>& from,
41  TT* to, int sz0, int sz1, bool fromhasudfs,
42  const Geom::PosRectangle<float>* rectinfrom=0 );
46  inline Array2DReSampler(const Array2D<T>& from,
47  ValueSeries<TT>& to,int sz0,int sz1,
48  bool fromhasudfs,
49  const Geom::PosRectangle<float>* rectinfrom=0 );
54  inline void set(const Array2D<T>& from, Array2D<TT>& to,
55  bool fromhasudfs,
56  const Geom::PosRectangle<float>* rectinfrom=0 );
60  inline void set(const Array2D<T>& from, TT* to, int sz0, int sz1,
61  bool fromhasudfs,
62  const Geom::PosRectangle<float>* rectinfrom=0 );
66  inline void set(const Array2D<T>& from,ValueSeries<TT>& to,
67  int sz0, int sz1,bool fromhasudfs,
68  const Geom::PosRectangle<float>* rectinfrom=0 );
73  inline od_int64 nrIterations() const;
74  void setInterpolate(bool yn) { interpolate_ = yn; }
75 
76 private:
77  inline void updateScale(const Geom::PosRectangle<float>*);
78  inline bool doWork(od_int64,od_int64, int );
80  { return tr("Data columns resampled"); }
81 
82  const Array2D<T>* from_;
85  TT* toptr_;
91 };
92 
93 #define mXDim 0
94 #define mYDim 1
95 
96 
97 template <class T, class TT> inline
99  Array2D<TT>& to, bool fromhasudfs,
100  const Geom::PosRectangle<float>* rectinfrom )
101  : ParallelTask("Re-sampling data")
102 { set( from, to, fromhasudfs, rectinfrom ); }
103 
104 
105 template <class T, class TT> inline
107  TT* to, int sz0, int sz1, bool fromhasudfs,
108  const Geom::PosRectangle<float>* rectinfrom )
109  : ParallelTask("Re-sampling data")
110 { set( from, to, sz0, sz1, fromhasudfs, rectinfrom ); }
111 
112 
113 template <class T, class TT> inline
115  ValueSeries<TT>& to, int sz0, int sz1, bool fromhasudfs,
116  const Geom::PosRectangle<float>* rectinfrom )
117  : ParallelTask("Re-sampling data")
118 { set( from, to, sz0, sz1, fromhasudfs, rectinfrom ); }
119 
120 
121 #define mUpdateResampler \
122  from_ = &from; \
123  func_.set( from, fromhasudfs ); \
124  updateScale( rectinfromptr )
125 
126 template <class T, class TT> inline
128  bool fromhasudfs,
129  const Geom::PosRectangle<float>* rectinfromptr)
130 {
131  if ( to.getData() )
132  {
133  toptr_ = to.getData();
134  to_ = 0;
135  tovs_ = 0;
136  }
137  else if ( to.getStorage() )
138  {
139  to_ = 0;
140  toptr_ = 0;
141  tovs_ = to.getStorage();
142  }
143  else
144  {
145  to_ = &to;
146  toptr_ = 0;
147  tovs_ = 0;
148  }
149 
150  toinfo_ = to.info();
151 
153 }
154 
155 
156 template <class T, class TT> inline
158  int sz0, int sz1, bool fromhasudfs,
159  const Geom::PosRectangle<float>* rectinfromptr)
160 {
161  toptr_ = to;
162  to_ = 0;
163  tovs_ = 0;
164 
165  toinfo_.setSize( mXDim, sz0 );
166  toinfo_.setSize( mYDim, sz1 );
167 
169 }
170 
171 
172 template <class T, class TT> inline
174  int sz0, int sz1, bool fromhasudfs,
175  const Geom::PosRectangle<float>* rectinfromptr)
176 {
177  if ( to.arr() )
178  {
179  toptr_ = to.arr();
180  tovs_ = 0;
181  to_ = 0;
182  }
183  else
184  {
185  toptr_ = 0;
186  tovs_ = &to;
187  to_ = 0;
188  }
189 
190  toinfo_.setSize( mXDim, sz0 );
191  toinfo_.setSize( mYDim, sz1 );
193 }
194 
195 
196 template <class T, class TT> inline
198  const Geom::PosRectangle<float>* rectinfromptr )
199 {
200  const int xsize = toinfo_.getSize( mXDim );
201  const int ysize = toinfo_.getSize( mYDim );
202 
203  Geom::PosRectangle<float> rectinfrom( 0, 0,
204  mCast(float,from_->info().getSize(mXDim)-1),
205  mCast(float,from_->info().getSize(mYDim)-1) );
206 
207  if ( rectinfromptr )
208  {
209  Geom::PosRectangle<float> nrect( *rectinfromptr );
210  nrect.sortCorners( true, true );
211  if ( rectinfrom.contains( nrect, 1e-3 ) )
212  rectinfrom = nrect;
213  }
214 
215  xsampling_.start = rectinfrom.left();
216  xsampling_.step = rectinfrom.width()/(xsize-1);
217 
218  ysampling_.start = rectinfrom.left();
219  ysampling_.step = rectinfrom.height()/(ysize-1);
220 }
221 
222 
223 template <class T, class TT> inline
225 {
226  return toinfo_.getSize( mXDim );
227 }
228 
229 
230 
231 template <class T, class TT> inline
233 {
234  const int ysize = toinfo_.getSize( mYDim );
235  int localnrdone = 0;
236  od_int64 offset = start*ysize;
237  TT* toptr = toptr_ ? toptr_+offset : 0;
238  for ( int idx=mCast(int,start); idx<=stop; idx++ )
239  {
240  const float sourcex = xsampling_.atIndex( idx );
241  for ( int idy=0; idy<ysize; idy++ )
242  {
243  const float sourcey = ysampling_.atIndex( idy );
244 
245  const TT val = interpolate_
246  ? func_.getValue( sourcex, sourcey )
247  : from_->get( mNINT32(sourcex), mNINT32( sourcey ) );
248  if ( toptr )
249  {
250  *toptr = val;
251  toptr++;
252  }
253  else if ( tovs_ )
254  tovs_->setValue( offset++, val );
255  else
256  to_->set( idx, idy , val );
257  }
258 
259  localnrdone++;
260 
261  if ( localnrdone>100 )
262  {
263  addToNrDone( localnrdone );
264  localnrdone = 0;
265  }
266  }
267 
268  addToNrDone( localnrdone );
269 
270  return true;
271 }
272 
273 #undef mXDim
274 #undef mYDim
275 #undef mUpdateResampler
276 
277 
278 #endif
T step
Definition: samplingdata.h:50
bool interpolate_
Definition: array2dresample.h:90
T width() const
Definition: geometry.h:554
T left() const
Definition: geometry.h:564
T to(const F &fr)
Definition: convert.h:33
RT getValue(PT, PT) const
Definition: array2dfunc.h:50
SamplingData< float > ysampling_
Definition: array2dresample.h:89
#define mODTextTranslationClass(clss)
Definition: uistring.h:38
uiString uiNrDoneText() const
will be nrDoneText() in 7.x
Definition: array2dresample.h:79
const ValueSeries< T > * getStorage() const
Definition: arraynd.h:46
#define mCast(tp, v)
Definition: commondefs.h:124
mODTextTranslationClass(Array2DReSampler) public Array2DReSampler(const Array2D< T > &from, TT *to, int sz0, int sz1, bool fromhasudfs, const Geom::PosRectangle< float > *rectinfrom=0)
Definition: array2dresample.h:106
void sortCorners(bool leftislow=true, bool topislow=true)
Definition: geometry.h:614
#define od_int64
Definition: plftypes.h:36
#define mUpdateResampler
Definition: array2dresample.h:121
void updateScale(const Geom::PosRectangle< float > *)
Definition: array2dresample.h:197
Definition: uistring.h:89
virtual void set(int, int, T)=0
Generalization of a task that can be run in parallel.
Definition: paralleltask.h:66
bool contains(const Point2D< T > &p, T eps) const
Definition: geometry.h:238
T atIndex(IT) const
Definition: samplingdata.h:158
T height() const
Definition: geometry.h:559
#define mNINT32(x)
Definition: commondefs.h:45
const T * getData() const
Definition: arraynd.h:55
#define mYDim
Definition: array2dresample.h:94
Array2D ( Subclass of ArrayND ) is a two dimensional array.
Definition: arraynd.h:131
void set(const Array2D< T > &from, Array2D< TT > &to, bool fromhasudfs, const Geom::PosRectangle< float > *rectinfrom=0)
Definition: array2dresample.h:127
T start
Definition: samplingdata.h:49
Fills an Array2D from another Array2D of another size. Usage:
Definition: array2dresample.h:30
void setInterpolate(bool yn)
Definition: array2dresample.h:74
#define mXDim
Definition: array2dresample.h:93
virtual void setValue(int64_t, T)
Definition: valseries.h:45
Array2D< TT > * to_
Definition: array2dresample.h:83
TT * toptr_
Definition: array2dresample.h:85
virtual bool setSize(int dim, int nsz)
Implementation of Array2DInfo.
Definition: arrayndinfo.h:166
bool doWork(od_int64, od_int64, int)
Definition: array2dresample.h:232
virtual int getSize(int dim) const
Definition: arrayndinfo.h:252
Array2DFunc< TT, float, T > func_
Definition: array2dresample.h:87
#define mClass(module)
Definition: commondefs.h:164
virtual const Array2DInfo & info() const =0
void addToNrDone(int64_t increment)
virtual T * arr()
Definition: valseries.h:55
od_int64 nrIterations() const
Definition: array2dresample.h:224
ValueSeries< TT > * tovs_
Definition: array2dresample.h:86
Floating-point rectangle class.
Definition: geometry.h:225
const Array2D< T > * from_
Definition: array2dresample.h:82
SamplingData< float > xsampling_
Definition: array2dresample.h:88
Array2DInfoImpl toinfo_
Definition: array2dresample.h:84

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