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

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