OpendTect-6_4  6.4
posidxpairvalset.h
Go to the documentation of this file.
1 #ifndef posidxpairvalset_h
2 #define posidxpairvalset_h
3 
4 /*+
5 ________________________________________________________________________
6 
7  (C) dGB Beheer B.V.; (LICENSE) http://opendtect.org/OpendTect_license.txt
8  Author: A.H.Bril
9  Date: July 2004/Oct 2013
10  RCS: $Id$
11 ________________________________________________________________________
12 
13 -*/
14 
15 #include "generalmod.h"
16 #include "posidxpair.h"
17 #include "sets.h"
18 #include "ranges.h"
19 #include "od_iosfwd.h"
20 namespace PosInfo { class CubeData; }
21 class TrcKeySampling;
22 
23 
24 namespace Pos
25 {
26 template <class IPT,class FT> class ValueIdxPair;
27 template <class IPT,class FT> class IdxPairValues;
28 
29 
69 {
70 public:
71 
75 
76  IdxPairValueSet(int nr_vals,
77  bool allow_duplicate_idxpairs);
78  IdxPairValueSet(const IdxPairValueSet&);
79  virtual ~IdxPairValueSet();
80  IdxPairValueSet& operator =(const IdxPairValueSet&);
81 
82  inline void allowDuplicateIdxPairs( bool yn )
83  { allowdup_ = yn; if ( !yn ) removeDuplicateIdxPairs();}
84  bool allowsDuplicateIdxPairs() const { return allowdup_; }
85  void setEmpty();
86  bool append(const IdxPairValueSet&);
87  void remove(const IdxPairValueSet&);
88  void copyStructureFrom(const IdxPairValueSet&);
90 
96  struct SPos
97  {
98  SPos( int ii=-1, int jj=-1 )
99  : i(ii), j(jj) {}
100  void reset() { i = j = -1; }
101  inline bool operator ==( const SPos& p ) const
102  { return i == p.i && j == p.j; }
103  inline bool operator !=( const SPos& p ) const
104  { return i != p.i || j != p.j; }
105  inline bool operator>( const SPos& p ) const
106  { if ( i>p.i ) return true; return i==p.i && j>p.j; }
107  inline bool operator<( const SPos& p ) const
108  { if ( i<p.i ) return true; return i==p.i && j<p.j; }
109  inline bool isValid() const { return i > -1 && j > -1; }
110 
111  int i, j;
112  };
113 
114  inline SPos find( const IdxPair& ip ) const
115  { return findOccurrence( ip, 0 ); }
116  SPos findOccurrence(const IdxPair&,int occ=0) const;
120  bool next(SPos&,bool skip_duplicate_idxpairs=false) const;
121  bool prev(SPos&,bool skip_duplicate_idxpairs=false) const;
122  bool isValid(const IdxPair&) const;
123 
124  void get(const SPos&,IdxPair&,float* v=0,
125  int mxnrvals=-1) const;
126  IdxPair getIdxPair(const SPos&) const;
127  SPos getPos(od_int64 global_idx) const;
129  SPos add(const IdxPair&,const float* vs=0);
131  SPos add(const DataRow&);
133  void set(SPos,const float* vs=0);
134 
138  // more get, set and add: see below
139 
140  inline int nrVals() const { return nrvals_; }
141  inline int nrFirst() const { return frsts_.size(); }
142  int nrSecond(IdxType firstidx) const;
143  inline bool isEmpty() const { return nrFirst() < 1; }
144  inline bool includes( const IdxPair& ip ) const
145  { return find(ip).j > -1; }
146  bool hasFirst(IdxType) const;
147  bool hasSecond(IdxType) const;
148  IdxPair firstIdxPair() const;
150  od_int64 totalSize() const;
151  Interval<IdxType> firstRange() const;
152  Interval<IdxType> secondRange(IdxType firsidx=-1) const;
153  Interval<float> valRange(int valnr) const;
154 
155  void remove(const SPos&);
157  void remove(const TypeSet<SPos>&);
160  void removeVal(int);
161  bool insertVal(int); //<! Will add a 'column'
162  bool setNrVals(int,bool kp_data=true);
163  int nrDuplicateIdxPairs() const;
164  void sortDuplicateIdxPairs(int value_nr,bool ascending=true);
165  void removeDuplicateIdxPairs();
166  void randomSubselect(od_int64 maxnr);
167 
168  void extend(const IdxPairDelta& stepout,const IdxPairStep&);
170  void removeRange(int valnr,const Interval<float>&,
171  bool inside=true);
174  void remove(const TrcKeySampling& hrg,bool inside);
175 
176  // Convenience stuff
177  SPos add(const PairVal&);
178  SPos add(const IdxPair&,float);
179  SPos add(const IdxPair&,double);
180  SPos add(const IdxPair&,float,float);
181  SPos add(const IdxPair&,const TypeSet<float>&);
182  void add(const PosInfo::CubeData&);
183  void get(const SPos&,DataRow&) const;
184  void get(const SPos&,PairVal&) const;
185  void get(const SPos&,IdxPair&,float&) const;
186  void get(const SPos&,IdxPair&,float&,float&) const;
187  void get(const SPos&,IdxPair&,TypeSet<float>&,
188  int maxnrvals=-1) const;
189  void set(const SPos&,float);
190  void set(const SPos&,float,float);
191  void set(const SPos&,const TypeSet<float>&);
192  void getColumn(int valnr,TypeSet<float>&,bool incudf) const;
193 
194  // Slow! Can still come in handly for small sets
195  void fillPar(IOPar&,const char* key) const;
196  void usePar(const IOPar&,const char* key);
197 
198  // Fast
199  bool getFrom(od_istream&,Pos::GeomID=mUdf(Pos::GeomID));
201  bool putTo(od_ostream&) const;
202 
203  bool includes(const DataRow&) const;
204  int nrPos(int lineidx) const;
205  inline float* getVals( const SPos& pos )
206  { return valsets_[pos.i]->arr() + nrvals_*pos.j; }
208  inline const float* getVals( const SPos& pos ) const
209  { return valsets_[pos.i]->arr() + nrvals_*pos.j; }
211  inline float getVal( const SPos& pos, int valnr ) const
213  { return getVals(pos)[valnr]; }
214  bool hasDuplicateIdxPairs() const;
215  bool haveDataRow(const DataRow&) const;
216 
217  // aliases
218  inline int nrInls() const { return nrFirst(); }
219  inline int nrCrls( IdxType inl ) const { return nrSecond(inl); }
220  inline int nrRows() const { return nrFirst(); }
221  inline int nrCols( IdxType row ) const { return nrSecond(row); }
222  bool hasInl( IdxType inl ) const { return hasFirst(inl); }
223  bool hasCrl( IdxType crl ) const { return hasSecond(crl); }
224  inline bool hasRow( IdxType row ) const { return hasFirst(row); }
225  inline bool hasCol( IdxType col ) const { return hasSecond(col); }
226  Interval<int> inlRange() const { return firstRange(); }
227  Interval<int> rowRange() const { return firstRange(); }
228  Interval<int> crlRange( IdxType inl=-1 ) const
229  { return secondRange(inl); }
230  Interval<int> colRange( IdxType row=-1 ) const
231  { return secondRange(row); }
232 
233 protected:
234 
235  const int nrvals_;
239  bool allowdup_;
240 
241  void addNew(SPos&,IdxType,const float*);
242  void sortPart(TypeSet<IdxType>&,TypeSet<float>&,
243  int,int,int,bool);
244 
245  void removeLine(int idx);
246 
247  inline IdxType getFrst( const SPos& pos ) const
248  { return frsts_[pos.i]; }
249  inline IdxType getScnd( const SPos& pos ) const
250  { return (*scndsets_[pos.i])[pos.j]; }
251  inline TypeSet<IdxType>& getScndSet( const SPos& pos )
252  { return *scndsets_[pos.i]; }
253  inline const TypeSet<IdxType>& getScndSet( const SPos& pos ) const
254  { return *scndsets_[pos.i]; }
255  inline TypeSet<float>& getValSet( const SPos& pos )
256  { return *valsets_[pos.i]; }
257  inline const TypeSet<float>& getValSet( const SPos& pos ) const
258  { return *valsets_[pos.i]; }
259  inline TypeSet<IdxType>& getScndSet( int idx )
260  { return *scndsets_[idx]; }
261  inline const TypeSet<IdxType>& getScndSet( int idx ) const
262  { return *scndsets_[idx]; }
263  inline TypeSet<float>& getValSet( int idx )
264  { return *valsets_[idx]; }
265  inline const TypeSet<float>& getValSet( int idx ) const
266  { return *valsets_[idx]; }
267 
268  friend class DataPointSet;
269  friend class PosVecDataSet;
270 
271 };
272 
273 
274 } // namespace Pos
275 
276 
277 #endif
#define mExpClass(module)
Definition: commondefs.h:160
OD class for stream write common access to the user log file, or std::cout in batch progs...
Definition: od_ostream.h:26
bool operator==(const ArrayNDInfo &a1, const ArrayNDInfo &a2)
Definition: arrayndinfo.h:53
Set of data points with group selection.
Definition: datapointset.h:48
bool isValid() const
Definition: posidxpairvalset.h:109
TypeSet< IdxType > frsts_
Definition: posidxpairvalset.h:236
bool operator<(const SPos &p) const
Definition: posidxpairvalset.h:107
IdxPair with a value.
Definition: posidxpairvalue.h:29
void usePar(const IOPar &iop, ODPolygon< T > &poly, const char *inpkey)
Definition: polygon.h:188
bool hasCol(IdxType col) const
Definition: posidxpairvalset.h:225
#define od_int64
Definition: plftypes.h:36
IdxPair with position indices; base class for BinID et al.
Definition: posidxpair.h:29
const TypeSet< IdxType > & getScndSet(int idx) const
Definition: posidxpairvalset.h:261
bool includes(const IdxPair &ip) const
Definition: posidxpairvalset.h:144
ValueIdxPair< IdxPair, float > PairVal
Definition: posidxpairvalset.h:73
IdxPair::IdxType IdxType
Definition: posidxpairvalset.h:72
bool allowdup_
Definition: posidxpairvalset.h:239
position in IdxPairValueSet; an iterator.
Definition: posidxpairvalset.h:96
TypeSet< IdxType > & getScndSet(const SPos &pos)
Definition: posidxpairvalset.h:251
IdxPair with 0-N values.
Definition: posidxpairvalue.h:23
Interval of values.
Definition: commontypes.h:31
OD class for stream read.
Definition: od_istream.h:24
int nrFirst() const
Definition: posidxpairvalset.h:141
void allowDuplicateIdxPairs(bool yn)
Definition: posidxpairvalset.h:82
bool append(TypeSetBase< T, I > &to, const TypeSetBase< S, J > &from)
append allowing a different type to be merged into set
Definition: typeset.h:198
Set of pointers to objects.
Definition: commontypes.h:32
int j
Definition: posidxpairvalset.h:111
int nrCrls(IdxType inl) const
Definition: posidxpairvalset.h:219
int i
Definition: posidxpairvalset.h:111
Set of (small) copyable elements.
Definition: commontypes.h:30
A sorted set of IdxPairs and associated values.
Definition: posidxpairvalset.h:68
int nrCols(IdxType row) const
Definition: posidxpairvalset.h:221
Generalized set of parameters of the keyword-value type.
Definition: iopar.h:47
Horizontal sampling (inline and crossline range and steps).
Definition: trckeysampling.h:27
bool operator>(const SPos &p) const
Definition: posidxpairvalset.h:105
int nrInls() const
Definition: posidxpairvalset.h:218
Interval< int > crlRange(IdxType inl=-1) const
Definition: posidxpairvalset.h:228
ObjectSet< TypeSet< float > > valsets_
Definition: posidxpairvalset.h:238
#define mUdf(type)
Use this macro to get the undefined for simple types.
Definition: undefval.h:272
ObjectSet< TypeSet< IdxType > > scndsets_
Definition: posidxpairvalset.h:237
const TypeSet< float > & getValSet(const SPos &pos) const
Definition: posidxpairvalset.h:257
Position.
Definition: commontypes.h:42
bool hasInl(IdxType inl) const
Definition: posidxpairvalset.h:222
IdxType getFrst(const SPos &pos) const
Definition: posidxpairvalset.h:247
IdxPairValues< IdxPair, float > DataRow
Definition: posidxpairvalset.h:74
bool allowsDuplicateIdxPairs() const
Definition: posidxpairvalset.h:84
bool operator!=(const ArrayNDInfo &a1, const ArrayNDInfo &a2)
Definition: arrayndinfo.h:62
bool hasRow(IdxType row) const
Definition: posidxpairvalset.h:224
void removeRange(ODSET &inst, size_type start, size_type stop)
Removes a range from the set.
Definition: odset.h:57
void fillPar(IOPar &iop, const ODPolygon< T > &poly, const char *inpkey)
Definition: polygon.h:175
const T * find(const ObjectSet< T > &os, const S &val)
Get const object in set.
Definition: objectset.h:183
Interval< int > inlRange() const
Definition: posidxpairvalset.h:226
IdxType getScnd(const SPos &pos) const
Definition: posidxpairvalset.h:249
TypeSet< IdxType > & getScndSet(int idx)
Definition: posidxpairvalset.h:259
Index_Type GeomID
Definition: commontypes.h:52
int nrRows() const
Definition: posidxpairvalset.h:220
bool hasCrl(IdxType crl) const
Definition: posidxpairvalset.h:223
Position info, often segmented.
Definition: posinfo.h:40
bool isEmpty() const
Definition: posidxpairvalset.h:143
Interval< int > colRange(IdxType row=-1) const
Definition: posidxpairvalset.h:230
Index_Type IdxType
Definition: idxpair.h:34
TypeSet< float > & getValSet(int idx)
Definition: posidxpairvalset.h:263
const float * getVals(const SPos &pos) const
Direct access to value arrays.
Definition: posidxpairvalset.h:208
SPos find(const IdxPair &ip) const
Definition: posidxpairvalset.h:114
const int nrvals_
Definition: posidxpairvalset.h:235
TypeSet< float > & getValSet(const SPos &pos)
Definition: posidxpairvalset.h:255
const TypeSet< float > & getValSet(int idx) const
Definition: posidxpairvalset.h:265
float getVal(const SPos &pos, int valnr) const
< Direct access to value arrays.
Definition: posidxpairvalset.h:211
Interval< int > rowRange() const
Definition: posidxpairvalset.h:227
SPos(int ii=-1, int jj=-1)
Definition: posidxpairvalset.h:98
Position info for an entire 3D cube. The LineData&#39;s are not sorted.
Definition: posinfo.h:95
void reset()
Definition: posidxpairvalset.h:100
Data set consisting of data vectors.
Definition: posvecdataset.h:30
int nrVals() const
Definition: posidxpairvalset.h:140
const TypeSet< IdxType > & getScndSet(const SPos &pos) const
Definition: posidxpairvalset.h:253
float * getVals(const SPos &pos)
Direct access to value arrays.
Definition: posidxpairvalset.h:205

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