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

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