OpendTect  6.3
posidxpairvalue.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: A.H.Bril
8  Date: 1996/Oct 2013
9 ________________________________________________________________________
10 
11 -*/
12 
13 #include "basicmod.h"
14 #include "posidxpair.h"
15 #include "typeset.h"
16 
17 
18 namespace Pos
19 {
20 
21 template <class IPT,class FT> class IdxPairValues;
22 
23 
26 template <class IPT,class FT>
27 mClass(Basic) ValueIdxPair : public IPT
28 {
29 public:
30 
31  typedef IPT pos_type;
32  typedef FT value_type;
33 
34  inline ValueIdxPair( int f=0, int s=0, FT v=mUdf(FT) )
35  : IPT(f,s), val_(v) {}
36  inline ValueIdxPair( const IPT& b, FT v=mUdf(FT) )
37  : IPT(b), val_(v) {}
38  inline ValueIdxPair( const IdxPairValues<IPT,FT>& ipvs, int idx=0 )
39  { set( ipvs, idx ); }
40 
41  inline bool operator==(const ValueIdxPair&) const;
42  inline bool operator!=( const ValueIdxPair& vip ) const
43  { return !(*this == vip); }
44  inline bool equalPos( const IPT& ip ) const
45  { return IPT::operator==(ip); }
46 
47  FT& val() { return val_; }
48  FT val() const { return val_; }
49  inline operator FT&() { return val_; }
50  inline operator FT() const { return val_; }
51 
52  inline void set( FT f ) { val_ = f; }
53  inline void set( const IPT& ipt ) { IPT::operator=( ipt ); }
54  inline void set( const IPT& ipt, FT f ) { set( ipt ); set( f ); }
55  inline void set(const IdxPairValues<IPT,FT>&,int idx=0);
56 
57  inline bool isUdf() const { return IPT::isUdf()
58  || mIsUdf(val_); }
59 
60 protected:
61 
62  FT val_;
63 
64 };
65 
66 
67 
73 template <class IPT,class FT>
74 mExpClass(Basic) IdxPairValues : public IPT
75 {
76 public:
77 
78  typedef IPT pos_type;
79  typedef FT value_type;
82 
83  IdxPairValues() { setSize(0); }
84  IdxPairValues( int i1, int i2, int nrvals )
85  : IPT(i1,i2) { setSize(nrvals); }
86  IdxPairValues( const IPT& p, int nrvals )
87  : IPT(p) { setSize(nrvals); }
89  : IPT() { *this = oth; }
91  : IPT(vip) { setSize(1); value(0) = vip; }
92 
93  inline bool operator==(const IdxPairValues&) const;
94  inline bool operator!=( const IdxPairValues& ipvs ) const
95  { return !(*this == ipvs); }
96  inline bool equalPos( const IPT& ip ) const
97  { return IPT::operator==(ip); }
98 
99  inline bool validIdx( int i ) const { return vals_.validIdx(i); }
100  inline size_type size() const { return vals_.size(); }
101  inline FT& value( int idx ) { return vals_[idx]; }
102  inline FT value( int idx ) const { return vals_[idx]; }
103  inline FT* values() { return vals_.arr(); }
104  inline const FT* values() const { return vals_.arr(); }
105  inline FT& operator[]( int idx ) { return value( idx ); }
106  inline FT operator[]( int idx ) const { return value( idx ); }
107  inline set_type& valSet() { return vals_; }
108  inline const set_type& valSet() const { return vals_; }
109  inline operator FT*() { return values(); }
110  inline operator const FT*() const { return values(); }
111 
112  inline void setSize(size_type,bool kpvals=false);
113  inline void setVals(const FT*);
114  inline void set(int,FT);
115  inline void set( const IPT& ipt ) { IPT::operator=( ipt ); }
116 
117  inline bool isUdf(bool allvalsudf=true) const;
118 
119 protected:
120 
122 
123 };
124 
125 
126 template <class IPT,class FT> inline
128 {
129  IPT::operator=( ipvs );
130  val_ = ipvs.validIdx( idx ) ? ipvs.value( idx ) : mUdf(FT);
131 }
132 
133 
134 template <class IPT,class FT> inline
136 {
137  if ( !equalPos( oth ) )
138  return false;
139  else if ( mIsUdf(val_) && mIsUdf(oth.val_) )
140  return true;
141 
142  const FT valdiff = val_ - oth.val_;
143  return mIsZero(valdiff,(FT)mDefEps);
144 }
145 
146 
147 template <class IPT,class FT> inline
149  const IdxPairValues<IPT,FT>& oth ) const
150 {
151  const size_type sz = size();
152  if ( sz != size() || !equalPos( oth ) )
153  return false;
154 
155  for ( size_type idx=0; idx<sz; idx++ )
156  {
157  const FT myval = value(idx);
158  const FT othval = oth.value(idx);
159 
160  if ( mIsUdf(myval) && mIsUdf(othval) )
161  continue;
162 
163  const FT valdiff = myval - othval;
164  if ( !mIsZero(valdiff,(FT)mDefEps) )
165  return false;
166  }
167 
168  return true;
169 }
170 
171 
172 template <class IPT,class FT> inline
174  typename IdxPairValues<IPT,FT>::size_type sz, bool kpvals )
175 {
176  if ( sz == size() )
177  {
178  if ( kpvals )
179  return;
180  vals_.erase();
181  }
182 
183  TypeSet<FT> tmp( vals_ );
184  const size_type orgsz = tmp.size();
185  for ( size_type idx=0; idx<sz; idx++ )
186  vals_ += idx<orgsz ? tmp[idx] : mUdf(float);
187 }
188 
189 
190 template <class IPT,class FT> inline
191 void IdxPairValues<IPT,FT>::setVals( const FT* newvals )
192 {
193  const size_type sz = size();
194  for ( size_type idx=0; idx<sz; idx++ )
195  vals_[idx] = newvals ? newvals[idx] : mUdf(float);
196 }
197 
198 
199 template <class IPT,class FT> inline
200 void IdxPairValues<IPT,FT>::set( int idx, FT val )
201 {
202  if ( validIdx(idx) )
203  vals_[idx] = val;
204 }
205 
206 
207 template <class IPT,class FT> inline
208 bool IdxPairValues<IPT,FT>::isUdf( bool anyvaludf ) const
209 {
210  if ( IPT::isUdf() )
211  return true;
212 
213  const size_type sz = size();
214  for ( size_type idx=0; idx<sz; idx++ )
215  {
216  const FT val = vals_[idx];
217  const bool isudf = mIsUdf(val);
218  if ( isudf && anyvaludf )
219  return true; // any val needs to be udf and this one is
220  else if ( !isudf && !anyvaludf )
221  return false; // all vals need to be udf and this one isn't
222  }
223 
224  return !anyvaludf;
225 }
226 
227 
228 } // namespace Pos
#define mExpClass(module)
Definition: commondefs.h:157
#define mIsUdf(val)
Use mIsUdf to check for undefinedness of simple types.
Definition: undefval.h:285
bool operator==(const ArrayNDInfo &a1, const ArrayNDInfo &a2)
Definition: arrayndinfo.h:51
bool operator==(const IdxPairValues &) const
Definition: posidxpairvalue.h:148
TypeSet< FT >::size_type size_type
Definition: posidxpairvalue.h:81
bool equalPos(const IPT &ip) const
Definition: posidxpairvalue.h:96
#define mIsZero(x, eps)
Definition: commondefs.h:55
IdxPair with a value.
Definition: posidxpairvalue.h:27
const set_type & valSet() const
Definition: posidxpairvalue.h:108
IPT pos_type
Definition: posidxpairvalue.h:31
IdxPairValues(int i1, int i2, int nrvals)
Definition: posidxpairvalue.h:84
IdxPair with 0-N values.
Definition: posidxpairvalue.h:21
bool validIdx(int i) const
Definition: posidxpairvalue.h:99
size_type size() const
Definition: posidxpairvalue.h:100
set_type & valSet()
Definition: posidxpairvalue.h:107
FT * values()
Definition: posidxpairvalue.h:103
FT & value(int idx)
Definition: posidxpairvalue.h:101
ValueIdxPair(const IPT &b, FT v=Values::Undef< FT >::val())
Definition: posidxpairvalue.h:36
#define mUdf(type)
Use this macro to get the undefined for simple types.
Definition: undefval.h:270
IdxPairValues()
Definition: posidxpairvalue.h:83
void setSize(size_type, bool kpvals=false)
Definition: posidxpairvalue.h:173
Position.
Definition: commontypes.h:38
bool isUdf() const
Definition: posidxpairvalue.h:57
TypeSet< FT > vals_
Definition: posidxpairvalue.h:121
FT operator[](int idx) const
Definition: posidxpairvalue.h:106
bool operator!=(const IdxPairValues &ipvs) const
Definition: posidxpairvalue.h:94
FT & operator[](int idx)
Definition: posidxpairvalue.h:105
ValueIdxPair(int f=0, int s=0, FT v=Values::Undef< FT >::val())
Definition: posidxpairvalue.h:34
void set(int, FT)
Definition: posidxpairvalue.h:200
#define mDefEps
Definition: commondefs.h:60
IdxPairValues(const IdxPairValues &oth)
Definition: posidxpairvalue.h:88
size_type size() const
Definition: typeset.h:263
FT value_type
Definition: posidxpairvalue.h:79
FT val_
Definition: posidxpairvalue.h:62
FT value(int idx) const
Definition: posidxpairvalue.h:102
bool operator==(const ValueIdxPair &) const
Definition: posidxpairvalue.h:135
bool operator!=(const ValueIdxPair &vip) const
Definition: posidxpairvalue.h:42
FT val() const
Definition: posidxpairvalue.h:48
IPT pos_type
Definition: posidxpairvalue.h:78
TypeSet< FT > set_type
Definition: posidxpairvalue.h:80
void setVals(const FT *)
Definition: posidxpairvalue.h:191
IdxPairValues(const ValueIdxPair< IPT, FT > &vip)
Definition: posidxpairvalue.h:90
bool isUdf(bool allvalsudf=true) const
Definition: posidxpairvalue.h:208
#define mClass(module)
Definition: commondefs.h:161
void set(FT f)
Definition: posidxpairvalue.h:52
bool isUdf(const T &t)
Definition: undefval.h:241
bool equalPos(const IPT &ip) const
Definition: posidxpairvalue.h:44
ValueIdxPair(const IdxPairValues< IPT, FT > &ipvs, int idx=0)
Definition: posidxpairvalue.h:38
FT & val()
Definition: posidxpairvalue.h:47
FT value_type
Definition: posidxpairvalue.h:32
IdxPairValues(const IPT &p, int nrvals)
Definition: posidxpairvalue.h:86
const FT * values() const
Definition: posidxpairvalue.h:104

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