OpendTect  6.6
arrayndinfo.h
Go to the documentation of this file.
1 #pragma once
2 /*
3 ________________________________________________________________________
4 
5  (C) dGB Beheer B.V.; (LICENSE) http://opendtect.org/OpendTect_license.txt
6  Author: K. Tingdahl
7  Date: 9-3-1999
8  RCS: $Id$
9 ________________________________________________________________________
10 
11 
12 */
13 
14 #include "basicmod.h"
15 
16 #include "gendefs.h"
17 #include "typeset.h"
18 
25 {
26 public:
27 
28  typedef od_int16 nr_dims_type; // number of dimensions, rank
30  typedef od_int32 size_type; // size of a singe dimension
32  typedef od_int64 offset_type; // offset/total size in/of the array
34  typedef const size_type* NDSize; // arr with sizes for each dimension
35  typedef const idx_type* NDPos;
36  typedef TypeSet<idx_type> NDPosBuf; // to put your own ND-indexes
37 
38  virtual ArrayNDInfo* clone() const = 0;
39  virtual ~ArrayNDInfo() {}
40 
41  int nrDims() const { return getNDim(); }
42  virtual int getNDim() const = 0;
43  virtual int getSize(int dim) const = 0;
44  virtual bool setSize(int dim,int sz);
45 
46  virtual bool isOK() const;
47 
48  virtual od_uint64 getTotalSz() const;
49  virtual od_uint64 getOffset(const int*) const;
51  virtual bool validPos(const int*) const;
53  bool validDimPos(int dim,int pos) const;
55  virtual bool getArrayPos(od_uint64, int*) const;
58 protected:
59 
61 
62 };
63 
64 
65 #define mTypeDefArrNDTypes \
66  mUseType( ArrayNDInfo, dim_idx_type ); \
67  mUseType( ArrayNDInfo, nr_dims_type ); \
68  mUseType( ArrayNDInfo, idx_type ); \
69  mUseType( ArrayNDInfo, size_type ); \
70  mUseType( ArrayNDInfo, offset_type ); \
71  mUseType( ArrayNDInfo, total_size_type ); \
72  mUseType( ArrayNDInfo, NDSize ); \
73  mUseType( ArrayNDInfo, NDPos ); \
74  mUseType( ArrayNDInfo, NDPosBuf ); \
75 
76 #define mDefNDPosBuf(nm,nrdims) ArrayNDInfo::NDPosBuf nm( nrdims, 0 )
77 #define mNDPosFromPosBuf(bufnm) bufnm.arr()
78 #define mNDPosBufFromPos(pos,nrdims) ArrayNDInfo::NDPosBuf( pos, nrdims )
79 
80 
81 inline bool operator ==( const ArrayNDInfo& a1, const ArrayNDInfo& a2 )
82 {
83  int nd = a1.getNDim();
84  if ( nd != a2.getNDim() ) return false;
85  for ( int idx=0; idx<nd; idx++ )
86  if ( a1.getSize(idx) != a2.getSize(idx) ) return false;
87  return true;
88 }
89 
90 inline bool operator !=( const ArrayNDInfo& a1, const ArrayNDInfo& a2 )
91 { return !(a1 == a2); }
92 
93 
100 {
101 public:
102 
103  virtual int getNDim() const { return 1; }
104 
105  virtual od_uint64 getOffset( int pos ) const
106  { return pos; }
107  virtual bool validPos( int pos ) const
108  { return ArrayNDInfo::validPos( &pos ); }
109 
110  virtual od_uint64 getOffset( const int* iarr ) const
111  { return getOffset( *iarr ); }
112  virtual bool validPos( const int* iarr ) const
113  { return ArrayNDInfo::validPos( iarr ); }
114 
115 };
116 
117 
124 {
125 public:
126 
127  virtual int getNDim() const { return 2; }
128 
129  virtual od_uint64 getOffset(int,int) const;
131  virtual bool validPos(int,int) const;
132 
133  virtual od_uint64 getOffset( const int* iarr ) const
134  { return ArrayNDInfo::getOffset( iarr ); }
135  virtual bool validPos( const int* iarr ) const
136  { return ArrayNDInfo::validPos( iarr ); }
137 
138 };
139 
140 
147 {
148 public:
149  virtual int getNDim() const { return 3; }
150 
151  virtual od_uint64 getOffset(int, int, int) const;
153  virtual bool validPos(int,int,int) const;
154 
155  virtual od_uint64 getOffset( const int* iarr ) const
156  { return ArrayNDInfo::getOffset( iarr ); }
157  virtual bool validPos( const int* iarr ) const
158  { return ArrayNDInfo::validPos( iarr ); }
159 };
160 
161 
166 {
167 public:
168  virtual int getNDim() const { return 4; }
169 
170  virtual od_uint64 getOffset(int,int,int,int) const;
172  virtual bool validPos(int,int,int,int) const;
173 
174  virtual od_uint64 getOffset( const int* pos ) const
175  { return ArrayNDInfo::getOffset( pos ); }
176  virtual bool validPos( const int* pos ) const
177  { return ArrayNDInfo::validPos( pos ); }
178 };
179 
180 
186 {
187 public:
188 
189  virtual Array1DInfo* clone() const
190  { return new Array1DInfoImpl(*this); }
191 
192  Array1DInfoImpl(int nsz=0);
194 
195  virtual int getSize(int dim) const;
196  virtual bool setSize(int dim,int nsz);
197  virtual bool isOK() const { return dimsz_>=0; }
198  virtual od_uint64 getTotalSz() const { return dimsz_; }
199 
200 protected:
201 
202  int dimsz_;
203 
204 };
205 
206 
212 {
213 public:
214 
215  virtual Array2DInfo* clone() const { return new Array2DInfoImpl(*this); }
216 
217  Array2DInfoImpl(int sz0=0, int sz1=0);
219 
220  virtual int getSize(int dim) const;
221  virtual bool setSize(int dim,int nsz);
222  virtual bool isOK() const { return cachedtotalsz_ > 0; }
223 
224  virtual od_uint64 getTotalSz() const { return cachedtotalsz_; }
225 
226 protected:
227 
228  int dimsz_[2];
230 
231 };
232 
233 
239 {
240 public:
241 
242  virtual Array3DInfo* clone() const { return new Array3DInfoImpl(*this); }
243 
244  Array3DInfoImpl(int sz0=0, int sz1=0, int sz2=0);
246 
247  virtual int getSize(int dim) const;
248  virtual bool setSize(int dim,int nsz);
249  virtual bool isOK() const { return cachedtotalsz_ > 0; }
250  virtual od_uint64 getTotalSz() const { return cachedtotalsz_; }
251 
252 protected:
253 
254  int dimsz_[3];
256 
257 };
258 
259 
263 {
264 public:
265  virtual Array4DInfo* clone() const { return new Array4DInfoImpl(*this); }
266 
267  Array4DInfoImpl(int sz0=0,int sz1=0,
268  int sz2=0,int sz3=0);
270 
271  virtual int getSize(int dim) const;
272  virtual bool setSize(int dim,int nsz);
273  virtual bool isOK() const { return cachedtotalsz_ > 0; }
274  virtual od_uint64 totalSize() const { return cachedtotalsz_; }
275 
276 protected:
277 
278  int dimsz_[4];
280 
281 };
282 
288 {
289 public:
290 
291  virtual ArrayNDInfo* clone() const;
292  static ArrayNDInfo* create(int ndim);
293  template <class T> static ArrayNDInfo* create(const T*,int sz);
294 
295  ArrayNDInfoImpl(int ndim);
299  virtual bool isOK() const { return cachedtotalsz_ > 0; }
300 
301  virtual od_uint64 getTotalSz() const { return cachedtotalsz_; }
302  virtual int getNDim() const;
303  virtual int getSize(int dim) const;
304  virtual bool setSize(int dim,int nsz);
305 
306 protected:
307 
308  int ndim_;
309  int* dimsz_;
310 
312 };
313 
314 
315 inline int Array1DInfoImpl::getSize( int dim ) const
316 {
317  return dim ? 0 : dimsz_;
318 }
319 
320 
321 inline int Array2DInfoImpl::getSize( int dim ) const
322 {
323  return dim>1 || dim<0 ? 0 : dimsz_[dim];
324 }
325 
326 
327 inline int Array3DInfoImpl::getSize( int dim ) const
328 {
329  return dim>2 || dim<0 ? 0 : dimsz_[dim];
330 }
331 
332 
333 inline int Array4DInfoImpl::getSize( int dim ) const
334 {
335  return dim>3 || dim<0 ? 0 : dimsz_[dim];
336 }
337 
338 
339 template <class T> inline
340 ArrayNDInfo* ArrayNDInfoImpl::create( const T* sizes, int sz )
341 {
342  TypeSet<int> dimszs;
343  for ( int idx=0; idx<sz; idx++ )
344  {
345  const int dimsz = mNINT32(sizes[idx]);
346  if ( dimsz > 1 )
347  dimszs += dimsz;
348  }
349  ArrayNDInfo* ret = create( dimszs.size() );
350  if ( !ret )
351  return nullptr;
352 
353  for ( int idx=0; idx<ret->getNDim(); idx++ )
354  ret->setSize( idx, dimszs[idx] );
355 
356  return ret;
357 }
358 
359 
od_uint64
#define od_uint64
Definition: plftypes.h:36
Array1DInfo::getOffset
virtual uint64_t getOffset(int pos) const
Definition: arrayndinfo.h:105
ArrayNDInfoImpl::getTotalSz
virtual uint64_t getTotalSz() const
Definition: arrayndinfo.h:301
ArrayNDInfo::validDimPos
bool validDimPos(int dim, int pos) const
Array3DInfo::getNDim
virtual int getNDim() const
Definition: arrayndinfo.h:149
Array2DInfo
Contains the information about the size of Array2D, and in what order the data is stored (if accessab...
Definition: arrayndinfo.h:124
ArrayNDInfo::validPos
virtual bool validPos(const int *) const
ArrayNDInfoImpl::cachedtotalsz_
uint64_t cachedtotalsz_
Definition: arrayndinfo.h:311
ArrayNDInfo::setSize
virtual bool setSize(int dim, int sz)
ArrayNDInfo
Contains the information about the size of ArrayND, and in what order the data is stored (if accessab...
Definition: arrayndinfo.h:25
ArrayNDInfo::isOK
virtual bool isOK() const
Array2DInfoImpl::dimsz_
int dimsz_[2]
Definition: arrayndinfo.h:228
Array3DInfo::getOffset
virtual uint64_t getOffset(int, int, int) const
ArrayNDInfo::getTotalSz
virtual uint64_t getTotalSz() const
Array1DInfo::getNDim
virtual int getNDim() const
Definition: arrayndinfo.h:103
Array2DInfo::validPos
virtual bool validPos(const int *iarr) const
Definition: arrayndinfo.h:135
Array4DInfo::getNDim
virtual int getNDim() const
Definition: arrayndinfo.h:168
Array4DInfoImpl::dimsz_
int dimsz_[4]
Definition: arrayndinfo.h:278
Array3DInfoImpl::setSize
virtual bool setSize(int dim, int nsz)
ArrayNDInfoImpl::~ArrayNDInfoImpl
~ArrayNDInfoImpl()
od_int64
#define od_int64
Definition: plftypes.h:35
Array2DInfo::getOffset
virtual uint64_t getOffset(const int *iarr) const
Definition: arrayndinfo.h:133
mExpClass
#define mExpClass(module)
Definition: commondefs.h:177
ArrayNDInfoImpl::ArrayNDInfoImpl
ArrayNDInfoImpl(const ArrayNDInfoImpl &)
ArrayNDInfo::getOffset
virtual uint64_t getOffset(const int *) const
Array2DInfoImpl::isOK
virtual bool isOK() const
Definition: arrayndinfo.h:222
ArrayNDInfo::getSize
virtual int getSize(int dim) const =0
typeset.h
operator==
bool operator==(const ArrayNDInfo &a1, const ArrayNDInfo &a2)
Definition: arrayndinfo.h:81
Array3DInfoImpl::getTotalSz
virtual uint64_t getTotalSz() const
Definition: arrayndinfo.h:250
Array4DInfo::getOffset
virtual uint64_t getOffset(int, int, int, int) const
Array4DInfo::validPos
virtual bool validPos(const int *pos) const
Definition: arrayndinfo.h:176
Array2DInfoImpl::Array2DInfoImpl
Array2DInfoImpl(const Array2DInfo &)
Array3DInfo::validPos
virtual bool validPos(const int *iarr) const
Definition: arrayndinfo.h:157
Array1DInfoImpl::clone
virtual Array1DInfo * clone() const
Definition: arrayndinfo.h:189
ArrayNDInfoImpl
Implementation of ArrayNDInfo.
Definition: arrayndinfo.h:288
Array3DInfoImpl::cachedtotalsz_
uint64_t cachedtotalsz_
Definition: arrayndinfo.h:255
ArrayNDInfoImpl::ndim_
int ndim_
Definition: arrayndinfo.h:308
ArrayNDInfoImpl::setSize
virtual bool setSize(int dim, int nsz)
Array2DInfo::getNDim
virtual int getNDim() const
Definition: arrayndinfo.h:127
Array3DInfoImpl::isOK
virtual bool isOK() const
Definition: arrayndinfo.h:249
Array2DInfo::validPos
virtual bool validPos(int, int) const
Array3DInfo::validPos
virtual bool validPos(int, int, int) const
Array2DInfoImpl::setSize
virtual bool setSize(int dim, int nsz)
ArrayNDInfoImpl::clone
virtual ArrayNDInfo * clone() const
Array3DInfoImpl::getSize
virtual int getSize(int dim) const
Definition: arrayndinfo.h:327
Array2DInfoImpl::cachedtotalsz_
uint64_t cachedtotalsz_
Definition: arrayndinfo.h:229
Array1DInfoImpl::Array1DInfoImpl
Array1DInfoImpl(const Array1DInfo &)
Array4DInfoImpl::getSize
virtual int getSize(int dim) const
Definition: arrayndinfo.h:333
ArrayNDInfo::dim_idx_type
nr_dims_type dim_idx_type
Definition: arrayndinfo.h:29
Array1DInfo::validPos
virtual bool validPos(int pos) const
Definition: arrayndinfo.h:107
ArrayNDInfo::size_type
int size_type
Definition: arrayndinfo.h:30
operator!=
bool operator!=(const ArrayNDInfo &a1, const ArrayNDInfo &a2)
Definition: arrayndinfo.h:90
ArrayNDInfoImpl::create
static ArrayNDInfo * create(int ndim)
Array1DInfoImpl::isOK
virtual bool isOK() const
Definition: arrayndinfo.h:197
Array1DInfo
Contains the information about the size of Array1D, and in what order the data is stored (if accessab...
Definition: arrayndinfo.h:100
od_int16
#define od_int16
Definition: plftypes.h:26
ArrayNDInfo::nrDims
int nrDims() const
Definition: arrayndinfo.h:41
ArrayNDInfoImpl::dimsz_
int * dimsz_
Definition: arrayndinfo.h:309
gendefs.h
Array4DInfoImpl::Array4DInfoImpl
Array4DInfoImpl(int sz0=0, int sz1=0, int sz2=0, int sz3=0)
Array4DInfo
Contains the information about the size of Array4D, and in what order the data is stored (if accessab...
Definition: arrayndinfo.h:166
Array1DInfoImpl::dimsz_
int dimsz_
Definition: arrayndinfo.h:202
Array4DInfoImpl::setSize
virtual bool setSize(int dim, int nsz)
Array3DInfo::getOffset
virtual uint64_t getOffset(const int *iarr) const
Definition: arrayndinfo.h:155
Array3DInfo
Contains the information about the size of Array3D, and in what order the data is stored (if accessab...
Definition: arrayndinfo.h:147
Array2DInfoImpl::getSize
virtual int getSize(int dim) const
Definition: arrayndinfo.h:321
Array3DInfoImpl
Implementation of Array3DInfo.
Definition: arrayndinfo.h:239
Array4DInfoImpl::isOK
virtual bool isOK() const
Definition: arrayndinfo.h:273
Array4DInfoImpl::Array4DInfoImpl
Array4DInfoImpl(const Array4DInfo &)
ArrayNDInfo::getArrayPos
virtual bool getArrayPos(uint64_t, int *) const
ArrayNDInfo::idx_type
size_type idx_type
Definition: arrayndinfo.h:31
Array1DInfoImpl::getSize
virtual int getSize(int dim) const
Definition: arrayndinfo.h:315
Array1DInfoImpl::Array1DInfoImpl
Array1DInfoImpl(int nsz=0)
Array2DInfoImpl::Array2DInfoImpl
Array2DInfoImpl(int sz0=0, int sz1=0)
Array2DInfoImpl::clone
virtual Array2DInfo * clone() const
Definition: arrayndinfo.h:215
Array2DInfo::getOffset
virtual uint64_t getOffset(int, int) const
Array2DInfoImpl
Implementation of Array2DInfo.
Definition: arrayndinfo.h:212
ArrayNDInfoImpl::getSize
virtual int getSize(int dim) const
ArrayNDInfo::NDPosBuf
TypeSet< idx_type > NDPosBuf
Definition: arrayndinfo.h:36
Array1DInfoImpl::setSize
virtual bool setSize(int dim, int nsz)
Array2DInfoImpl::getTotalSz
virtual uint64_t getTotalSz() const
Definition: arrayndinfo.h:224
ArrayNDInfo::NDPos
const idx_type * NDPos
Definition: arrayndinfo.h:35
Array4DInfo::validPos
virtual bool validPos(int, int, int, int) const
od_int32
#define od_int32
Definition: plftypes.h:30
Array4DInfoImpl::cachedtotalsz_
uint64_t cachedtotalsz_
Definition: arrayndinfo.h:279
ArrayNDInfo::clone
virtual ArrayNDInfo * clone() const =0
ArrayNDInfoImpl::getNDim
virtual int getNDim() const
Array3DInfoImpl::Array3DInfoImpl
Array3DInfoImpl(int sz0=0, int sz1=0, int sz2=0)
ArrayNDInfo::total_size_type
offset_type total_size_type
Definition: arrayndinfo.h:33
Array1DInfoImpl
Implementation of Array1DInfo.
Definition: arrayndinfo.h:186
Array1DInfoImpl::getTotalSz
virtual uint64_t getTotalSz() const
Definition: arrayndinfo.h:198
ArrayNDInfo::getNDim
virtual int getNDim() const =0
ArrayNDInfoImpl::isOK
virtual bool isOK() const
Definition: arrayndinfo.h:299
ArrayNDInfo::calcTotalSz
uint64_t calcTotalSz() const
Array4DInfo::getOffset
virtual uint64_t getOffset(const int *pos) const
Definition: arrayndinfo.h:174
ArrayNDInfo::~ArrayNDInfo
virtual ~ArrayNDInfo()
Definition: arrayndinfo.h:39
create
static uiHor3DInterpol * create(uiParent *)
Array1DInfo::getOffset
virtual uint64_t getOffset(const int *iarr) const
Definition: arrayndinfo.h:110
ArrayNDInfo::nr_dims_type
short nr_dims_type
Definition: arrayndinfo.h:28
ArrayNDInfo::NDSize
const size_type * NDSize
Definition: arrayndinfo.h:34
Array3DInfoImpl::dimsz_
int dimsz_[3]
Definition: arrayndinfo.h:254
ArrayNDInfoImpl::ArrayNDInfoImpl
ArrayNDInfoImpl(const ArrayNDInfo &)
Array1DInfo::validPos
virtual bool validPos(const int *iarr) const
Definition: arrayndinfo.h:112
mNINT32
#define mNINT32(x)
Definition: commondefs.h:58
ArrayNDInfo::offset_type
int64_t offset_type
Definition: arrayndinfo.h:32
ArrayNDInfoImpl::ArrayNDInfoImpl
ArrayNDInfoImpl(int ndim)
Array4DInfoImpl
Implementation of Array4DInfo.
Definition: arrayndinfo.h:263
Array3DInfoImpl::clone
virtual Array3DInfo * clone() const
Definition: arrayndinfo.h:242
Array3DInfoImpl::Array3DInfoImpl
Array3DInfoImpl(const Array3DInfo &)
TypeSet< idx_type >
Array4DInfoImpl::totalSize
virtual uint64_t totalSize() const
Definition: arrayndinfo.h:274
Array4DInfoImpl::clone
virtual Array4DInfo * clone() const
Definition: arrayndinfo.h:265

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