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

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