OpendTect-6_4  6.4
undefarray.h
Go to the documentation of this file.
1 #ifndef undefarray_h
2 #define undefarray_h
3 /*+
4 ________________________________________________________________________
5 
6  (C) dGB Beheer B.V.; (LICENSE) http://opendtect.org/OpendTect_license.txt
7  Author: K. Tingdahl
8  Date: 13/01/2005
9  RCS: $Id$
10 ________________________________________________________________________
11 
12 -*/
13 
14 #include "algomod.h"
15 #include "commondefs.h"
16 #include "plftypes.h"
17 #include "ptrman.h"
18 #include "valseries.h"
19 
20 class BinDataDesc;
21 
27 template <class T>
28 inline bool filterUndef(const T* input,T* output,int sz);
29 
30 template <class T>
31 inline bool filterUndef(const ValueSeries<T>& input,ValueSeries<T>& output,int);
32 
33 
40 {
41 public:
42  UndefArrayHandler(const BinDataDesc& desc);
43  bool set(const BinDataDesc& desc);
44  bool isOK() const;
45 
46  bool isUdf(const void* ptr, od_int64 idx) const;
47  void setUdf(void* ptr, od_int64 idx) const;
48  void unSetUdf(void* ptr, od_int64 idx) const;
52 protected:
53  typedef bool (*IsUdfFunc)(const void*,od_int64 idx);
54  typedef void (*SetUdfFunc)(void*,od_int64 idx);
55  typedef void (*UnsetUdfFunc)(void*,od_int64 idx);
56 
57  IsUdfFunc isudf_;
58  SetUdfFunc setudf_;
59  UnsetUdfFunc limitrange_;
60 
61  static bool isUdfUChar(const void*,od_int64);
62  static void setUdfUChar(void*,od_int64);
63  static void unsetUdfUChar(void*,od_int64);
64 
65  static bool isUdfChar(const void*,od_int64);
66  static void setUdfChar(void*,od_int64);
67  static void unsetUdfChar(void*,od_int64);
68 
69  static bool isUdfUShort(const void*,od_int64);
70  static void setUdfUShort(void*,od_int64);
71  static void unsetUdfUShort(void*,od_int64);
72 
73  static bool isUdfShort(const void*,od_int64);
74  static void setUdfShort(void*,od_int64);
75  static void unsetUdfShort(void*,od_int64);
76 
77  static bool isUdfUInt32(const void*,od_int64);
78  static void setUdfUInt32(void*,od_int64);
79  static void unsetUdfUInt32(void*,od_int64);
80 
81  static bool isUdfInt32(const void*,od_int64);
82  static void setUdfInt32(void*,od_int64);
83  static void unsetUdfInt32(void*,od_int64);
84 
85  static bool isUdfUInt64(const void*,od_int64);
86  static void setUdfUInt64(void*,od_int64);
87  static void unsetUdfUInt64(void*,od_int64);
88 
89  static bool isUdfInt64(const void*,od_int64);
90  static void setUdfInt64(void*,od_int64);
91  static void unsetUdfInt64(void*,od_int64);
92 
93  static bool isUdfFloat(const void*,od_int64);
94  static void setUdfFloat(void*,od_int64);
95  static void unsetUdfFloat(void*,od_int64);
96 
97  static bool isUdfDouble(const void*,od_int64);
98  static void setUdfDouble(void*,od_int64);
99  static void unsetUdfDouble(void*,od_int64);
100 };
101 
102 
103 template <class T> inline
104 bool filterUndef( const ValueSeries<T>& input, T* outptr, int sz )
105 {
106  if ( !sz || !outptr ) return true;
107 
108  const T* inptr = input.arr();
109 
110  ArrPtrMan<T> myinp = 0;
111  if ( !inptr )
112  {
113  myinp = new T[sz];
114  input.getValues( myinp, sz );
115  }
116 
117  return filterUndef( inptr ? inptr : myinp, outptr, sz );
118 }
119 
120 
121 template <class T> inline
122 bool filterUndef( const ValueSeries<T>& input, ValueSeries<T>& output, int sz )
123 {
124  if ( !sz ) return true;
125 
126  T* outptr = output.arr();
127 
128  ArrPtrMan<T> myoutp = 0;
129  if ( !outptr )
130  myoutp = outptr = new T[sz];
131 
132  if ( !filterUndef( input, outptr, sz ) )
133  return false;
134 
135  if ( myoutp )
136  output->setValues( outptr, sz );
137 
138  return true;
139 }
140 
141 
142 template <class T> inline
143 bool filterUndef(const T* input, T* output, int sz )
144 {
145  if ( !sz )
146  return true;
147 
148  int firstdefined = 0;
149  while ( firstdefined<sz && mIsUdf(input[firstdefined]) )
150  firstdefined++;
151 
152  if ( firstdefined==sz )
153  return false;
154 
155  for ( int idx=0; idx<=firstdefined; idx++ )
156  output[idx] = input[firstdefined];
157 
158  if ( firstdefined==sz-1 )
159  return true;
160 
161  int prevdefined = firstdefined;
162  int nextdefined = -1;
163 
164  for ( int idx=firstdefined+1; idx<sz; )
165  {
166  if ( !mIsUdf(input[idx]) )
167  {
168  prevdefined = idx;
169  output[idx] = input[idx];
170  idx++;
171 
172  continue;
173  }
174 
175  nextdefined = idx+1;
176  while ( nextdefined<sz && mIsUdf(input[nextdefined]) )
177  nextdefined++;
178 
179  idx = nextdefined;
180 
181  if ( nextdefined==sz )
182  {
183  for ( int posidx = prevdefined+1; posidx<sz; posidx++ )
184  output[posidx] = input[prevdefined];
185 
186  return true;
187  }
188  else
189  {
190  const T diff = input[nextdefined] - input[prevdefined];
191  const T unit = diff / (float)(nextdefined-prevdefined);
192  for ( int posidx = prevdefined+1; posidx<=nextdefined; posidx++ )
193  output[posidx] = input[prevdefined]+unit*(posidx-prevdefined);
194 
195  prevdefined = nextdefined;
196  nextdefined = -1;
197  }
198  }
199 
200  return true;
201 }
202 
203 #endif
#define mExpClass(module)
Definition: commondefs.h:160
void getValues(ValueSeries< T > &, int64_t nrvals) const
Definition: valseries.h:261
#define mIsUdf(val)
Use mIsUdf to check for undefinedness of simple types.
Definition: undefval.h:287
#define od_int64
Definition: plftypes.h:36
Class that handles undefvalues in arrays that are in a format described by a BinDataDesc.
Definition: undefarray.h:39
IsUdfFunc isudf_
Definition: undefarray.h:57
Interface to a series of values.
Definition: odmemory.h:17
SetUdfFunc setudf_
Definition: undefarray.h:58
Definition: ptrman.h:119
T & setUdf(T &u)
Definition: undefval.h:262
UnsetUdfFunc limitrange_
Definition: undefarray.h:59
bool filterUndef(const T *input, T *output, int sz)
Definition: undefarray.h:143
Description of binary data.
Definition: bindatadesc.h:43
bool isUdf(const T &t)
Definition: undefval.h:243
virtual T * arr()
Definition: valseries.h:55

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