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

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