OpendTect-6_4  6.4
arrayndsubsel.h
Go to the documentation of this file.
1 #ifndef arrayndsubsel_h
2 #define arrayndsubsel_h
3 
4 /*+
5 ________________________________________________________________________
6 
7  (C) dGB Beheer B.V.; (LICENSE) http://opendtect.org/OpendTect_license.txt
8  Author: K. Tingdahl
9  Date: Nov 2005
10  RCS: $Id$
11 ________________________________________________________________________
12 
13 -*/
14 
15 
16 #include "arraynd.h"
17 
22 template <class T>
23 mClass(General) Array2DSubSelection : public Array2D<T>
24 {
25 public:
26  Array2DSubSelection( int start0, int start1,
27  int sz0, int sz1,
28  Array2D<T>& data );
36  T get( int, int ) const;
37  void set( int, int, T );
38  bool isOK() const;
39 
40  const Array2DInfo& info() const;
41 
42 protected:
43 
44  int start_[2];
47 };
48 
49 
54 template <class T>
55 mClass(General) Array3DSubSelection : public Array3D<T>
56 {
57 public:
58  Array3DSubSelection( int start0, int start1, int start2,
59  int sz0, int sz1, int sz2,
60  Array3D<T>& data );
70  T get( int, int, int ) const;
71  void set( int, int, int, T );
72  bool isOK() const;
73 
74  const Array3DInfo& info() const;
75 
76 protected:
77 
78  int start_[3];
81 };
82 
83 
84 #define mSetupDim( dim ) \
85  start_[dim] = s##dim; \
86  info_.setSize( dim, mMIN( sz##dim, src_.info().getSize(dim)-s##dim) );
87 
88 
89 template <class T>
91  int sz0, int sz1,
92  Array2D<T>& data )
93  : src_( data )
94 {
95  mSetupDim(0); mSetupDim(1);
96 }
97 
98 
99 template <class T>
100 void Array2DSubSelection<T>::set( int s0, int s1, T val )
101 {
102  s0 += start_[0];
103  s1 += start_[1];
104 
105  if ( !src_.info().validPos( s0, s1 ) )
106  pErrMsg("Position is outside of src" );
107  else
108  src_.set( s0, s1, val );
109 }
110 
111 
112 template <class T>
113 T Array2DSubSelection<T>::get( int s0, int s1 ) const
114 {
115  s0 += start_[0];
116  s1 += start_[1];
117 
118  return src_.info().validPos( s0, s1 )
119  ? src_.get( s0, s1 ) : mUdf(T);
120 }
121 
122 
123 template <class T>
125 {
126  if ( !src_.isOK() )
127  return false;
128 
129  for ( int dim=info_.getNDim()-1; dim>=0; dim-- )
130  {
131  if ( start_[dim]<0 || start_[dim]>=src_.info().getSize(dim) ||
132  info_.getSize(dim)<=0 )
133  return false;
134  }
135 
136  return true;
137 }
138 
139 
140 template <class T>
142 { return info_; }
143 
144 
145 template <class T>
147  int sz0, int sz1, int sz2,
148  Array3D<T>& data )
149  : src_( data )
150 {
151  mSetupDim(0);
152  mSetupDim(1);
153  mSetupDim(2);
154 }
155 
156 
157 template <class T>
158 void Array3DSubSelection<T>::set( int s0, int s1, int s2, T val )
159 {
160  s0 += start_[0];
161  s1 += start_[1];
162  s2 += start_[2];
163 
164  if ( !src_.info().validPos( s0, s1, s2 ) )
165  pErrMsg("Position is outside of src" );
166  else
167  src_.set( s0, s1, s2, val );
168 }
169 
170 
171 template <class T>
172 T Array3DSubSelection<T>::get( int s0, int s1, int s2 ) const
173 {
174  s0 += start_[0];
175  s1 += start_[1];
176  s2 += start_[2];
177 
178  return src_.info().validPos( s0, s1, s2 )
179  ? src_.get( s0, s1, s2 ) : mUdf(T);
180 }
181 
182 
183 template <class T>
185 {
186  if ( !src_.isOK() )
187  return false;
188 
189  for ( int dim=info_.getNDim()-1; dim>=0; dim-- )
190  {
191  if ( start_[dim]<0 || start_[dim]>=src_.info().getSize(dim) ||
192  info_.getSize(dim)<=0 )
193  return false;
194  }
195 
196  return true;
197 }
198 
199 
200 template <class T>
202 { return info_; }
203 
204 
205 
206 #endif
Array3DSubSelection(int start0, int start1, int start2, int sz0, int sz1, int sz2, Array3D< T > &data)
Definition: arrayndsubsel.h:146
#define mSetupDim(dim)
Definition: arrayndsubsel.h:84
Contains the information about the size of Array3D, and in what order the data is stored (if accessab...
Definition: arrayndinfo.h:118
bool isOK() const
Definition: arrayndsubsel.h:184
const Array2DInfo & info() const
Definition: arrayndsubsel.h:141
int start_[2]
Definition: arrayndsubsel.h:44
virtual int getSize(int dim) const
Definition: arrayndinfo.h:258
virtual int getNDim() const
Definition: arrayndinfo.h:99
Array3D< T > & src_
Definition: arrayndsubsel.h:80
const Array3DInfo & info() const
Definition: arrayndsubsel.h:201
bool isOK() const
Definition: arrayndsubsel.h:124
void set(int, int, int, T)
Definition: arrayndsubsel.h:158
T get(int, int, int) const
Definition: arrayndsubsel.h:172
Makes a subselection of an Array2D cube.
Definition: arrayndsubsel.h:23
Array2D ( Subclass of ArrayND ) is a two dimensional array.
Definition: arraynd.h:131
Implementation of Array3DInfo.
Definition: arrayndinfo.h:193
#define mUdf(type)
Use this macro to get the undefined for simple types.
Definition: undefval.h:272
void set(int, int, T)
Definition: arrayndsubsel.h:100
Array2D< T > & src_
Definition: arrayndsubsel.h:46
Contains the information about the size of Array2D, and in what order the data is stored (if accessab...
Definition: arrayndinfo.h:95
Array3DInfoImpl info_
Definition: arrayndsubsel.h:79
Definition: arrayndsubsel.h:55
Implementation of Array2DInfo.
Definition: arrayndinfo.h:166
T get(int, int) const
Definition: arrayndsubsel.h:113
Array2DInfoImpl info_
Definition: arrayndsubsel.h:45
virtual int getSize(int dim) const
Definition: arrayndinfo.h:252
#define mClass(module)
Definition: commondefs.h:164
int start_[3]
Definition: arrayndsubsel.h:78
#define pErrMsg(msg)
Definition: errmsg.h:60
Array2DSubSelection(int start0, int start1, int sz0, int sz1, Array2D< T > &data)
Definition: arrayndsubsel.h:90
Array3D ( Subclass of ArrayND ) is a three dimensional array.
Definition: arraynd.h:153
virtual int getNDim() const
Definition: arrayndinfo.h:122

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