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

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