OpendTect  6.3
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 ________________________________________________________________________
10 
11 @$*/
12 
13 #include "basicmod.h"
14 #include "arraynd.h"
15 #include "varlenarray.h"
16 #include "valseriesimpl.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:
41  ArrayNDSliceBase( ArrayNDInfo*,
42  const ArrayNDInfo& );
43  void getSourcePos(const int* localpos,
44  int* sourcepos) const;
47 
51  bool isinited_;
52 };
53 
54 
59 template <class T>
60 mClass(Basic) Array1DSlice : public Array1D<T>, public ArrayNDSliceBase
61 {
62 public:
64  Array1DSlice(const ArrayND<T>&);
65  ~Array1DSlice();
66 
67  ValueSeries<T>* clone() const;
68 
69  T get( int ) const;
70  void set( int, T );
71  const Array1DInfo& info() const;
72  bool isSettable() const;
73 
74 protected:
75 
76  const ValueSeries<T>* getStorage_() const;
77 
78  bool writable_;
81 
82 };
83 
84 
89 template <class T>
90 mClass(Basic) Array2DSlice : public Array2D<T>, public ArrayNDSliceBase
91 {
92 public:
94  Array2DSlice(const ArrayND<T>&);
95  ~Array2DSlice();
96 
97  T get(int,int) const;
98  void set(int,int, T );
99  const Array2DInfo& info() const;
100  bool isSettable() const;
101 
102 protected:
103 
104  const ValueSeries<T>* getStorage_() const;
105  bool writable_;
106 
109 
110 };
111 
112 
113 //Array1DSlice
114 template <class T> inline
116  : ArrayNDSliceBase( new Array1DInfoImpl, source.info() )
117  , source_( source )
118  , storage_( 0 )
119  , writable_( true )
120 {}
121 
122 
123 template <class T> inline
125  : ArrayNDSliceBase( new Array1DInfoImpl, source.info() )
126  , source_( const_cast<ArrayND<T>& >(source) )
127  , storage_( 0 )
128  , writable_( false )
129 {}
130 
131 
132 template <class T> inline
134 { delete storage_; }
135 
136 
137 template <class T> inline
139 { return writable_ && source_.isSettable(); }
140 
141 
142 template <class T> inline
143 void Array1DSlice<T>::set( int pos, T val )
144 {
145  if ( !isinited_ )
146  { pErrMsg("ArrayNDSlice not inited!"); }
147 
148  if ( !writable_ ) return;
149  mAllocVarLenArr( int, srcpos, position_.size() );
150  getSourcePos( &pos, srcpos );
151  source_.setND( srcpos, val );
152 }
153 
154 
155 template <class T> inline
156 T Array1DSlice<T>::get( int pos ) const
157 {
158  if ( !isinited_ )
159  { pErrMsg("ArrayNDSlice not inited!"); }
160 
161  mAllocVarLenArr( int, srcpos, position_.size() );
162  getSourcePos( &pos, srcpos );
163  return source_.getND( srcpos );
164 }
165 
166 
167 template <class T> inline
169 {
171  res->info_ = info_;
172  res->vardim_ = vardim_;
173  res->position_ = position_;
174  res->offset_ = offset_;
175 
176  return res;
177 }
178 
179 template <class T> inline
181 { return (const Array1DInfo&) info_; }
182 
183 
184 template <class T> inline
186 {
187  if ( !isinited_ )
188  { pErrMsg("ArrayNDSlice not inited!"); }
189 
190  if ( offset_<0 )
191  return 0;
192 
193  if ( !source_.getStorage() )
194  return 0;
195 
196  if ( offset_==0 )
197  {
198  delete storage_;
199  storage_ = 0;
200  return source_.getStorage();
201  }
202 
203  if ( !storage_ || &storage_->source() != source_.getStorage() )
204  {
205  delete storage_;
206  storage_ =
207  new OffsetValueSeries<T>( *source_.getStorage(), offset_ );
208  }
209  else
210  storage_->setOffset( offset_ );
211  return storage_;
212 }
213 
214 
215 //Array2DSlice
216 template <class T> inline
218  : ArrayNDSliceBase( new Array2DInfoImpl, source.info() )
219  , source_( source )
220  , storage_( 0 )
221  , writable_( true )
222 {}
223 
224 
225 template <class T> inline
227  : ArrayNDSliceBase( new Array2DInfoImpl, source.info() )
228  , source_( const_cast<ArrayND<T>&>(source) )
229  , storage_( 0 )
230  , writable_( false )
231 {}
232 
233 
234 template <class T> inline
236 { delete storage_; }
237 
238 
239 template <class T> inline
241 { return writable_ && source_.isSettable(); }
242 
243 
244 template <class T> inline
245 void Array2DSlice<T>::set( int pos0, int pos1, T val )
246 {
247  if ( !isinited_ )
248  { pErrMsg("ArrayNDSlice not inited!"); }
249 
250  if ( !writable_ ) return;
251 
252  const int localpos[] = { pos0, pos1 };
253  mAllocVarLenArr( int, srcpos, position_.size() );
254  getSourcePos( localpos, srcpos );
255  source_.setND( srcpos, val );
256 }
257 
258 
259 template <class T> inline
260 T Array2DSlice<T>::get( int pos0, int pos1 ) const
261 {
262  if ( !isinited_ )
263  { pErrMsg("ArrayNDSlice not inited!"); }
264 
265  const int localpos[] = { pos0, pos1 };
266  mAllocVarLenArr( int, srcpos, position_.size() );
267  getSourcePos( localpos, srcpos );
268  return source_.getND( srcpos );
269 }
270 
271 
272 template <class T> inline
274 { return (const Array2DInfo&) info_; }
275 
276 
277 template <class T> inline
279 {
280  if ( !isinited_ )
281  { pErrMsg("ArrayNDSlice not inited!"); }
282 
283  if ( offset_<0 )
284  return 0;
285 
286  if ( !source_.getStorage() )
287  return 0;
288 
289  if ( offset_==0 )
290  {
291  delete storage_;
292  storage_ = 0;
293  return source_.getStorage();
294  }
295 
296  if ( !storage_ || &storage_->source() != source_.getStorage() )
297  {
298  delete storage_;
299  storage_ =
300  new OffsetValueSeries<T>( *source_.getStorage(), offset_ );
301  }
302  else
303  storage_->setOffset( offset_ );
304 
305  return storage_;
306 }
Array1D ( Subclass of ArrayND ) is a one dimensional array.
Definition: arraynd.h:97
#define mExpClass(module)
Definition: commondefs.h:157
bool writable_
Definition: arrayndslice.h:78
const Array2DInfo & info() const
Definition: arrayndslice.h:273
void getSourcePos(const int *localpos, int *sourcepos) const
Subclass of Array1D and ArrayNDSliceBase.
Definition: arrayndslice.h:60
#define od_int64
Definition: plftypes.h:34
bool init()
Contains the information about the size of ArrayND, and in what order the data is stored (if accessab...
Definition: arrayndinfo.h:21
Contains the information about the size of Array1D, and in what order the data is stored (if accessab...
Definition: arrayndinfo.h:69
Array1DSlice(ArrayND< T > &)
Definition: arrayndslice.h:115
ValueSeries of offsets.
Definition: valseriesimpl.h:22
const ValueSeries< T > * getStorage_() const
Definition: arrayndslice.h:278
int64_t offset_
Definition: arrayndslice.h:50
OffsetValueSeries< T > * storage_
Definition: arrayndslice.h:80
Array2DSlice(ArrayND< T > &)
Definition: arrayndslice.h:217
Array2D ( Subclass of ArrayND ) is a two dimensional array.
Definition: arraynd.h:127
~Array1DSlice()
Definition: arrayndslice.h:133
bool isinited_
Definition: arrayndslice.h:51
Subclass of Array2D and ArrayNDSliceBase.
Definition: arrayndslice.h:90
bool isSettable() const
Definition: arrayndslice.h:138
const ArrayNDInfo & sourceinfo_
Definition: arrayndslice.h:46
Interface to a series of values.
Definition: odmemory.h:15
ArrayND< T > & source_
Definition: arrayndslice.h:79
const ValueSeries< T > * getStorage_() const
Definition: arrayndslice.h:185
Contains the information about the size of Array2D, and in what order the data is stored (if accessab...
Definition: arrayndinfo.h:93
T get(int, int) const
Definition: arrayndslice.h:260
void set(int, int, T)
Definition: arrayndslice.h:245
#define mAllocVarLenArr(type, varnm, __size)
Definition: varlenarray.h:52
bool writable_
Definition: arrayndslice.h:105
ArrayND< T > & source_
Definition: arrayndslice.h:107
An ArrayND is an array with a given number of dimensions and a size.
Definition: arraynd.h:29
bool isSettable() const
Definition: arrayndslice.h:240
~Array2DSlice()
Definition: arrayndslice.h:235
size_type size() const
Definition: typeset.h:263
ValueSeries< T > * clone() const
Definition: arrayndslice.h:168
const Array1DInfo & info() const
Definition: arrayndslice.h:180
Implementation of Array1DInfo.
Definition: arrayndinfo.h:138
OffsetValueSeries< T > * storage_
Definition: arrayndslice.h:108
ArrayNDInfo & info_
Definition: arrayndslice.h:45
Implementation of Array2DInfo.
Definition: arrayndinfo.h:164
TypeSet< int > position_
Definition: arrayndslice.h:49
T get(int) const
Definition: arrayndslice.h:156
Base class of Array1DSlice and Array2DSlice. Access-tool to another ArrayND with higher dimensionalit...
Definition: arrayndslice.h:31
TypeSet< int > vardim_
Definition: arrayndslice.h:48
#define mClass(module)
Definition: commondefs.h:161
#define pErrMsg(msg)
Usual access point for programmer error messages.
Definition: errmsg.h:34
void set(int, T)
Definition: arrayndslice.h:143

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