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

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