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

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