OpendTect  6.6
arrayndslice.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: Kristofer Tingdahl
8  Date: 10-12-1999
9  RCS: $Id$
10 ________________________________________________________________________
11 
12 @$*/
13 
14 #include "basicmod.h"
15 #include "arraynd.h"
16 #include "varlenarray.h"
17 
32 {
33 public:
34  virtual ~ArrayNDSliceBase();
35  int getDimSize(int dim) const;
36  int getPos(int dim) const;
37  bool setPos(int dim,int pos);
38  bool init();
39  void setDimMap(int localdim, int remotedim );
40 protected:
42  const ArrayNDInfo& );
43  void getSourcePos(const int* localpos,
44  int* sourcepos) const;
47 
51 };
52 
53 
58 template <class T>
60 {
61 public:
63  Array1DSlice(const ArrayND<T>&);
64  ~Array1DSlice();
65 
66  ValueSeries<T>* clone() const;
67 
68  T get( int ) const;
69  void set( int, T );
70  const Array1DInfo& info() const;
71  bool isSettable() const;
72 
73 protected:
74  const ValueSeries<T>* getStorage_() const;
75 
76  bool writable_;
79 };
80 
81 
86 template <class T>
88 {
89 public:
91  Array2DSlice(const ArrayND<T>&);
92  ~Array2DSlice();
93 
94  T get(int,int) const;
95  void set(int,int, T );
96  const Array2DInfo& info() const;
97  bool isSettable() const;
98 
99 protected:
100  const ValueSeries<T>* getStorage_() const;
101  bool writable_;
102 
105 };
106 
107 
112 template <class T>
114 {
115 public:
117 
119  Array3DSlice(const ArrayND<T>&);
120  ~Array3DSlice();
121 
122  T get(idx_type,idx_type,idx_type) const;
123  void set(idx_type,idx_type,idx_type,T);
124  const Array3DInfo& info() const;
125  bool isSettable() const;
126 
127 protected:
128 
129  const ValueSeries<T>* getStorage_() const;
130  bool writable_;
131 
134 
135 };
136 
137 
138 
139 //Array1DSlice
140 template <class T> inline
142  : ArrayNDSliceBase( new Array1DInfoImpl, source.info() )
143  , source_( source )
144  , storage_( 0 )
145  , writable_( true )
146 {}
147 
148 
149 template <class T> inline
151  : ArrayNDSliceBase( new Array1DInfoImpl, source.info() )
152  , source_( const_cast<ArrayND<T>& >(source) )
153  , storage_( 0 )
154  , writable_( false )
155 {}
156 
157 
158 template <class T> inline
160 { delete storage_; }
161 
162 
163 template <class T> inline
165 { return writable_ && source_.isSettable(); }
166 
167 
168 template <class T> inline
169 void Array1DSlice<T>::set( int pos, T val )
170 {
171  if ( !writable_ ) return;
172  mAllocVarLenArr( int, srcpos, position_.size() );
173  getSourcePos( &pos, srcpos );
174  source_.setND( srcpos, val );
175 }
176 
177 
178 template <class T> inline
179 T Array1DSlice<T>::get( int pos ) const
180 {
181  mAllocVarLenArr( int, srcpos, position_.size() );
182  getSourcePos( &pos, srcpos );
183  return source_.getND( srcpos );
184 }
185 
186 
187 template <class T> inline
189 {
190  Array1DSlice<T>* res = new Array1DSlice<T>( source_ );
191  res->info_ = info_;
192  res->vardim_ = vardim_;
193  res->position_ = position_;
194  res->offset_ = offset_;
195 
196  return res;
197 }
198 
199 template <class T> inline
201 { return (const Array1DInfo&) info_; }
202 
203 
204 template <class T> inline
206 {
207  if ( offset_<0 )
208  return 0;
209 
210  if ( !source_.getStorage() )
211  return 0;
212 
213  if ( offset_==0 )
214  {
215  delete storage_;
216  storage_ = 0;
217  return source_.getStorage();
218  }
219 
220  if ( !storage_ || &storage_->source() != source_.getStorage() )
221  {
222  delete storage_;
223  storage_ =
224  new OffsetValueSeries<T>( *source_.getStorage(), offset_ );
225  }
226  else
227  storage_->setOffset( offset_ );
228  return storage_;
229 }
230 
231 
232 //Array2DSlice
233 template <class T> inline
235  : ArrayNDSliceBase( new Array2DInfoImpl, source.info() )
236  , source_( source )
237  , storage_( 0 )
238  , writable_( true )
239 {}
240 
241 
242 template <class T> inline
244  : ArrayNDSliceBase( new Array2DInfoImpl, source.info() )
245  , source_( const_cast<ArrayND<T>&>(source) )
246  , storage_( 0 )
247  , writable_( false )
248 {}
249 
250 
251 template <class T> inline
253 { delete storage_; }
254 
255 
256 template <class T> inline
258 { return writable_ && source_.isSettable(); }
259 
260 
261 template <class T> inline
262 void Array2DSlice<T>::set( int pos0, int pos1, T val )
263 {
264  if ( !writable_ ) return;
265 
266  const int localpos[] = { pos0, pos1 };
267  mAllocVarLenArr( int, srcpos, position_.size() );
268  getSourcePos( localpos, srcpos );
269  source_.setND( srcpos, val );
270 }
271 
272 
273 template <class T> inline
274 T Array2DSlice<T>::get( int pos0, int pos1 ) const
275 {
276  const int localpos[] = { pos0, pos1 };
277  mAllocVarLenArr( int, srcpos, position_.size() );
278  getSourcePos( localpos, srcpos );
279  return source_.getND( srcpos );
280 }
281 
282 
283 template <class T> inline
285 { return (const Array2DInfo&) info_; }
286 
287 
288 template <class T> inline
290 {
291  if ( offset_<0 )
292  return 0;
293 
294  if ( !source_.getStorage() )
295  return 0;
296 
297  if ( offset_==0 )
298  {
299  delete storage_;
300  storage_ = 0;
301  return source_.getStorage();
302  }
303 
304  if ( !storage_ || &storage_->source() != source_.getStorage() )
305  {
306  delete storage_;
307  storage_ =
308  new OffsetValueSeries<T>( *source_.getStorage(), offset_ );
309  }
310  else
311  storage_->setOffset( offset_ );
312 
313  return storage_;
314 }
315 
316 
317 //Array3DSlice
318 template <class T> inline
320  : ArrayNDSliceBase( new Array3DInfoImpl, source.info() )
321  , source_( source )
322  , storage_( 0 )
323  , writable_( true )
324 {
325 }
326 
327 
328 template <class T> inline
330  : ArrayNDSliceBase( new Array3DInfoImpl, source.info() )
331  , source_( const_cast<ArrayND<T>&>(source) )
332  , storage_( 0 )
333  , writable_( false )
334 {
335 }
336 
337 
338 template <class T> inline
340 { delete storage_; }
341 
342 
343 template <class T> inline
345 { return writable_ && source_.isSettable(); }
346 
347 
348 template <class T> inline
349 void Array3DSlice<T>::set( idx_type pos0, idx_type pos1, idx_type pos2, T val )
350 {
351  if ( !writable_ ) return;
352 
353  const idx_type localpos[] = { pos0, pos1, pos2 };
354  mAllocVarLenArr( idx_type, srcpos, position_.size() );
355  getSourcePos( const_cast<NDPos>(localpos), srcpos );
356  source_.setND( srcpos, val );
357 }
358 
359 
360 template <class T> inline
361 T Array3DSlice<T>::get( idx_type pos0, idx_type pos1, idx_type pos2 ) const
362 {
363  const idx_type localpos[] = { pos0, pos1, pos2 };
364  mAllocVarLenArr( idx_type, srcpos, position_.size() );
365  getSourcePos( const_cast<NDPos>(localpos), srcpos );
366  return source_.getND( srcpos );
367 }
368 
369 
370 template <class T> inline
372 {
373  return (const Array3DInfo&)info_;
374 }
375 
376 
377 template <class T> inline
379 {
380  if ( offset_<0 )
381  return 0;
382 
383  if ( !source_.getStorage() )
384  return 0;
385 
386  if ( offset_==0 )
387  {
388  delete storage_;
389  storage_ = 0;
390  return source_.getStorage();
391  }
392 
393  if ( !storage_ || &storage_->source() != source_.getStorage() )
394  {
395  delete storage_;
396  storage_ = new OffsetValueSeries<T>( *source_.getStorage(), offset_ );
397  }
398  else
399  storage_->setOffset( offset_ );
400 
401  storage_->setSize( ArrayND<T>::totalSize() );
402 
403  return storage_;
404 }
405 
ValueSeries
Interface to a series of values.
Definition: odmemory.h:16
Array1DSlice::set
void set(int, T)
Definition: arrayndslice.h:169
Array2DInfo
Contains the information about the size of Array2D, and in what order the data is stored (if accessab...
Definition: arrayndinfo.h:124
ArrayNDSliceBase::ArrayNDSliceBase
ArrayNDSliceBase(ArrayNDInfo *, const ArrayNDInfo &)
Array3DSlice::set
void set(idx_type, idx_type, idx_type, T)
Definition: arrayndslice.h:349
ArrayNDInfo
Contains the information about the size of ArrayND, and in what order the data is stored (if accessab...
Definition: arrayndinfo.h:25
Array3DSlice::Array3DSlice
Array3DSlice(ArrayND< T > &)
Definition: arrayndslice.h:319
Array1DSlice::storage_
OffsetValueSeries< T > * storage_
Definition: arrayndslice.h:78
Array1DSlice::isSettable
bool isSettable() const
Definition: arrayndslice.h:164
Array2DSlice::Array2DSlice
Array2DSlice(ArrayND< T > &)
Definition: arrayndslice.h:234
ArrayNDSliceBase::getSourcePos
void getSourcePos(const int *localpos, int *sourcepos) const
od_int64
#define od_int64
Definition: plftypes.h:35
Array3DSlice::source_
ArrayND< T > & source_
Definition: arrayndslice.h:132
ArrayNDSliceBase::getPos
int getPos(int dim) const
mExpClass
#define mExpClass(module)
Definition: commondefs.h:177
Array2DSlice::getStorage_
const ValueSeries< T > * getStorage_() const
Definition: arrayndslice.h:289
ArrayNDSliceBase::~ArrayNDSliceBase
virtual ~ArrayNDSliceBase()
varlenarray.h
ArrayNDSliceBase::position_
TypeSet< int > position_
Definition: arrayndslice.h:49
ArrayNDSliceBase::info_
ArrayNDInfo & info_
Definition: arrayndslice.h:45
Array1DSlice::source_
ArrayND< T > & source_
Definition: arrayndslice.h:77
Array1D
Array1D ( Subclass of ArrayND ) is a one dimensional array.
Definition: arraynd.h:111
Array1DSlice::get
T get(int) const
Definition: arrayndslice.h:179
Array3DSlice::get
T get(idx_type, idx_type, idx_type) const
Definition: arrayndslice.h:361
ArrayNDSliceBase::getDimSize
int getDimSize(int dim) const
Array1DSlice
Subclass of Array1D and ArrayNDSliceBase.
Definition: arrayndslice.h:60
arraynd.h
Array2DSlice::set
void set(int, int, T)
Definition: arrayndslice.h:262
OffsetValueSeries
ValueSeries of offsets.
Definition: valseries.h:70
Array2DSlice::writable_
bool writable_
Definition: arrayndslice.h:101
Array3D
Array3D ( Subclass of ArrayND ) is a three dimensional array.
Definition: arraynd.h:162
Array3DSlice::isSettable
bool isSettable() const
Definition: arrayndslice.h:344
Array3DSlice::idx_type
ArrayNDInfo ::idx_type idx_type
Definition: arrayndslice.h:116
Array1DSlice::info
const Array1DInfo & info() const
Definition: arrayndslice.h:200
Array3DSlice::storage_
OffsetValueSeries< T > * storage_
Definition: arrayndslice.h:133
ArrayNDSliceBase::vardim_
TypeSet< int > vardim_
Definition: arrayndslice.h:48
mClass
#define mClass(module)
Definition: commondefs.h:181
Array1DInfo
Contains the information about the size of Array1D, and in what order the data is stored (if accessab...
Definition: arrayndinfo.h:100
Array2DSlice::~Array2DSlice
~Array2DSlice()
Definition: arrayndslice.h:252
Array1DSlice::writable_
bool writable_
Definition: arrayndslice.h:76
mTypeDefArrNDTypes
#define mTypeDefArrNDTypes
Definition: arrayndinfo.h:65
Array2DSlice
Subclass of Array2D and ArrayNDSliceBase.
Definition: arrayndslice.h:88
Array1DSlice::clone
ValueSeries< T > * clone() const
Definition: arrayndslice.h:188
Conv::set
void set(T &_to, const F &fr)
template based type conversion
Definition: convert.h:27
Array3DInfo
Contains the information about the size of Array3D, and in what order the data is stored (if accessab...
Definition: arrayndinfo.h:147
ArrayNDSliceBase
Base class of Array1DSlice and Array2DSlice. Access-tool to another ArrayND with higher dimensionalit...
Definition: arrayndslice.h:32
Array2DSlice::get
T get(int, int) const
Definition: arrayndslice.h:274
Array3DInfoImpl
Implementation of Array3DInfo.
Definition: arrayndinfo.h:239
Array2DInfoImpl
Implementation of Array2DInfo.
Definition: arrayndinfo.h:212
ArrayNDSliceBase::init
bool init()
ArrayNDSliceBase::offset_
int64_t offset_
Definition: arrayndslice.h:50
Array3DSlice::getStorage_
const ValueSeries< T > * getStorage_() const
Definition: arrayndslice.h:378
mAllocVarLenArr
#define mAllocVarLenArr(type, varnm, __size)
Definition: varlenarray.h:53
ArrayND
An ArrayND is an array with a given number of dimensions and a size.
Definition: arraynd.h:33
Array1DInfoImpl
Implementation of Array1DInfo.
Definition: arrayndinfo.h:186
Array3DSlice
Subclass of Array3D and ArrayNDSliceBase.
Definition: arrayndslice.h:114
Array3DSlice::~Array3DSlice
~Array3DSlice()
Definition: arrayndslice.h:339
Array3DSlice::NDPos
ArrayNDInfo ::NDPos NDPos
Definition: arrayndslice.h:116
Array1DSlice::Array1DSlice
Array1DSlice(ArrayND< T > &)
Definition: arrayndslice.h:141
ArrayNDSliceBase::setPos
bool setPos(int dim, int pos)
Array2DSlice::source_
ArrayND< T > & source_
Definition: arrayndslice.h:103
Array2DSlice::info
const Array2DInfo & info() const
Definition: arrayndslice.h:284
ArrayNDSliceBase::sourceinfo_
const ArrayNDInfo & sourceinfo_
Definition: arrayndslice.h:46
Array1DSlice::~Array1DSlice
~Array1DSlice()
Definition: arrayndslice.h:159
Array1DSlice::getStorage_
const ValueSeries< T > * getStorage_() const
Definition: arrayndslice.h:205
Array2DSlice::isSettable
bool isSettable() const
Definition: arrayndslice.h:257
ArrayNDSliceBase::setDimMap
void setDimMap(int localdim, int remotedim)
Array2DSlice::storage_
OffsetValueSeries< T > * storage_
Definition: arrayndslice.h:104
Array3DSlice::info
const Array3DInfo & info() const
Definition: arrayndslice.h:371
Array2D
Array2D ( Subclass of ArrayND ) is a two dimensional array.
Definition: arraynd.h:140
TypeSet< int >
Array3DSlice::writable_
bool writable_
Definition: arrayndslice.h:130

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