OpendTect  6.3
posidxpairdataset.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: Bert
8  Date: July 2004/Oct 2013/Mar 2016
9 ________________________________________________________________________
10 
11 -*/
12 
13 #include "generalmod.h"
14 #include "posidxpair.h"
15 #include "sets.h"
16 #include "ranges.h"
17 #include "od_iosfwd.h"
18 namespace PosInfo { class CubeData; }
19 class TrcKeySampling;
20 
21 
22 namespace Pos
23 {
24 
25 class IdxPairDataSet;
26 typedef void (*EntryCreatedFn)(IdxPairDataSet&,int spos_i,int spos_j);
27 
60 mExpClass(General) IdxPairDataSet
61 {
62 public:
63 
68 
69 
75  struct SPos
76  {
77  SPos( ArrIdxType ii=-1, ArrIdxType jj=-1 )
78  : i(ii), j(jj) {}
79  void reset() { i = j = -1; }
80  inline bool operator ==( const SPos& oth ) const
81  { return i == oth.i && j == oth.j; }
82  inline bool operator !=( const SPos& oth ) const
83  { return i != oth.i || j != oth.j; }
84  inline bool operator>(const SPos&) const;
85  inline bool operator<(const SPos&) const;
86  inline bool isValid() const { return i > -1 && j > -1; }
87 
88  ArrIdxType i, j;
89  };
90 
91 
92  IdxPairDataSet(ObjSzType,bool allow_duplicate_idxs,
93  bool manage_data=true);
94  IdxPairDataSet(const IdxPairDataSet&);
95  virtual ~IdxPairDataSet();
96  IdxPairDataSet& operator =(const IdxPairDataSet&);
97 
98  inline bool isEmpty() const { return frsts_.isEmpty(); }
99  void setEmpty();
100  void copyStructureFrom(const IdxPairDataSet&);
102 
103  ObjSzType objSize() const { return objsz_; }
104  bool managesData() const { return mandata_; };
105  bool allowsDuplicateIdxPairs() const { return allowdup_; }
106  void allowDuplicateIdxPairs(bool);
107  bool append(const IdxPairDataSet&);
108  void remove(const IdxPairDataSet&);
109  void remove(const TrcKeySampling& hrg,bool inside);
110  void remove(SPos);
111  void remove(const TypeSet<SPos>&);
114 
115  inline SPos find( const IdxPair& ip ) const
116  { return findFirst(ip); }
117  inline SPos findFirst( const IdxPair& ip ) const
118  { return findOccurrence(ip,0); }
119  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(SPos) const;
123  bool isValid(const IdxPair&) const;
124 
125  IdxPair getIdxPair(SPos) const;
126  const void* getObj(SPos) const;
127  const void* get(SPos,IdxPair&) const;
128  SPos getPos(GlobIdxType) const;
129  SPos add(const IdxPair&,const void* obj=0);
131  void set(SPos,const void* obj=0);
135  void set( const IdxPair& ip, const void* obj=0 )
136  { set( findFirst(ip), obj ); }
138  SPos update(const IdxPair&,const void* obj=0);
142 
143  inline ArrIdxType nrFirst() const { return frsts_.size(); }
144  ArrIdxType nrSecond(IdxType firstidx) const;
145  inline bool includes( const IdxPair& ip ) const
146  { return find(ip).j > -1; }
147  bool hasFirst(IdxType) const;
148  bool hasSecond(IdxType) const;
149  IdxPair firstIdxPair() const;
150  GlobIdxType totalSize() const;
151  Interval<IdxType> firstRange() const;
152  Interval<IdxType> secondRange(IdxType firsidx=-1) const;
153 
154  bool hasDuplicateIdxPairs() const;
155  ArrIdxType nrDuplicateIdxPairs() const;
156  void removeDuplicateIdxPairs();
157  ArrIdxType nrPos(ArrIdxType lineidx) const;
158 
159  void extend(const IdxPairDelta& stepout,const IdxPairStep&,
160  bool avoiddups=true);
161  void add(const PosInfo::CubeData&,EntryCreatedFn fn=0);
163  void randomSubselect(GlobIdxType maxsz);
164 
165  // I/O
166  bool dump(od_ostream&,bool binary) const;
167  bool slurp(od_istream&,bool binary);
168 
169  // aliases
170  inline ArrIdxType nrInls() const { return nrFirst(); }
171  inline ArrIdxType nrCrls( IdxType inl ) const { return nrSecond(inl); }
172  inline ArrIdxType nrRows() const { return nrFirst(); }
173  inline ArrIdxType nrCols( IdxType row ) const { return nrSecond(row); }
174  bool hasInl( IdxType inl ) const { return hasFirst(inl); }
175  bool hasCrl( IdxType crl ) const { return hasSecond(crl); }
176  inline bool hasRow( IdxType row ) const { return hasFirst(row); }
177  inline bool hasCol( IdxType col ) const { return hasSecond(col); }
178  Interval<IdxType> inlRange() const { return firstRange(); }
179  Interval<IdxType> rowRange() const { return firstRange(); }
180  Interval<IdxType> crlRange( IdxType inl=-1 ) const
181  { return secondRange(inl); }
182  Interval<IdxType> colRange( IdxType row=-1 ) const
183  { return secondRange(row); }
184 
185  // Maybe messing with managed objects in buf.
186  bool setObjSize(ObjSzType sz,ObjSzType offs_in_objs=-1,
187  const void* initwith=0);
188  // offs_in_objs < 0: operate at end
189  void decrObjSize(ObjSzType,ObjSzType offs);
190  bool incrObjSize(ObjSzType,ObjSzType offs,const void* =0);
191 
192 protected:
193 
196 
197  class ObjData
198  {
199  public:
200 
201  typedef unsigned char BufType;
202 
203  ObjData() : buf_(0), bufsz_(0)
204  { objs_.allowNull(true); }
205  ObjData(const ObjData&);
206  ~ObjData() { delete [] buf_; }
207 
208  const void* getObj(bool,ArrIdxType,ObjSzType) const;
209  void putObj(bool,ArrIdxType,ObjSzType,const void*);
210  bool addObjSpace(bool,ArrIdxType,ObjSzType);
211  void removeObj(bool,ArrIdxType,ObjSzType);
212  void decrObjSize(ObjSzType orgsz,ObjSzType newsz,
213  ObjSzType at_offs);
214  bool incrObjSize(ObjSzType,ObjSzType,ObjSzType,
215  const void*);
216 
217  private:
218 
219  ObjectSet<const void> objs_; // contains const bool* when mandata
220 
221  BufType* buf_;
222  BufSzType bufsz_;
223  bool manageBufCapacity(ObjSzType);
224 
225  };
226 
227  const ObjSzType objsz_;
228  const bool mandata_;
229  bool allowdup_;
230 
231  IdxSet frsts_;
234 
235  static ArrIdxType findIndexFor(const IdxSet&,IdxType,bool* found=0);
236  const void* gtObj(const SPos&) const;
237  bool addObj(SPos&,IdxType,const void*);
238  void putObj(const SPos&,const void*);
239  void addEntry(const Pos::IdxPair&,const void*,SPos&);
240 
241  // All 'gt' functions return unchecked
242  inline IdxType gtFrst( const SPos& pos ) const
243  { return frsts_[pos.i]; }
244  inline IdxType gtScnd( const SPos& pos ) const
245  { return gtScndSet(pos)[pos.j]; }
246  inline IdxPair gtIdxPair( const SPos& pos ) const
247  { return IdxPair( gtFrst(pos), gtScnd(pos) ); }
248  inline IdxSet& gtScndSet( const SPos& pos )
249  { return *scndsets_[pos.i]; }
250  inline const IdxSet& gtScndSet( const SPos& pos ) const
251  { return *scndsets_[pos.i]; }
252  inline ObjData& gtObjData( const SPos& pos )
253  { return *objdatas_[pos.i]; }
254  inline const ObjData& gtObjData( const SPos& pos ) const
255  { return *objdatas_[pos.i]; }
256  inline IdxSet& gtScndSet( ArrIdxType idx )
257  { return *scndsets_[idx]; }
258  inline const IdxSet& gtScndSet( ArrIdxType idx ) const
259  { return *scndsets_[idx]; }
260  inline ObjData& gtObjData( ArrIdxType idx )
261  { return *objdatas_[idx]; }
262  inline const ObjData& gtObjData( ArrIdxType idx ) const
263  { return *objdatas_[idx]; }
264 
265 };
266 
267 
268 inline bool IdxPairDataSet::SPos::operator >( const SPos& oth ) const
269 {
270  if ( i > oth.i )
271  return true;
272  return i == oth.i && j > oth.j;
273 }
274 
275 
276 inline bool IdxPairDataSet::SPos::operator <( const SPos& oth ) const
277 {
278  if ( i < oth.i )
279  return true;
280  return i == oth.i && j < oth.j;
281 }
282 
283 
284 } // namespace Pos
Interval< IdxType > crlRange(IdxType inl=-1) const
Definition: posidxpairdataset.h:180
#define mExpClass(module)
Definition: commondefs.h:157
ArrIdxType nrCrls(IdxType inl) const
Definition: posidxpairdataset.h:171
const ObjSzType objsz_
Definition: posidxpairdataset.h:227
ObjData()
Definition: posidxpairdataset.h:203
bool operator>(const NamedObject &obj1, const NamedObject &obj2)
Definition: namedobj.h:75
OD class for stream write common access to the user log file, or std::cout in batch progs...
Definition: od_ostream.h:25
const IdxSet & gtScndSet(const SPos &pos) const
Definition: posidxpairdataset.h:250
bool operator==(const ArrayNDInfo &a1, const ArrayNDInfo &a2)
Definition: arrayndinfo.h:51
bool hasCrl(IdxType crl) const
Definition: posidxpairdataset.h:175
IdxSet & gtScndSet(ArrIdxType idx)
Definition: posidxpairdataset.h:256
bool managesData() const
Definition: posidxpairdataset.h:104
bool hasRow(IdxType row) const
Definition: posidxpairdataset.h:176
ArrIdxType nrFirst() const
Definition: posidxpairdataset.h:143
ObjectSet< ObjData > objdatas_
Definition: posidxpairdataset.h:233
#define od_int64
Definition: plftypes.h:34
od_int64 BufSzType
Definition: posidxpairdataset.h:195
Interval< IdxType > rowRange() const
Definition: posidxpairdataset.h:179
IdxPair with position indices; base class for BinID et al.
Definition: posidxpair.h:27
const bool mandata_
Definition: posidxpairdataset.h:228
bool hasCol(IdxType col) const
Definition: posidxpairdataset.h:177
TypeSet< IdxType >::size_type ArrIdxType
Definition: posidxpairdataset.h:65
IdxPair gtIdxPair(const SPos &pos) const
Definition: posidxpairdataset.h:246
BufType * buf_
Definition: posidxpairdataset.h:221
const IdxSet & gtScndSet(ArrIdxType idx) const
Definition: posidxpairdataset.h:258
OD class for stream read.
Definition: od_istream.h:23
ArrIdxType j
Definition: posidxpairdataset.h:88
Definition: posidxpairdataset.h:197
Interval< IdxType > inlRange() const
Definition: posidxpairdataset.h:178
ArrIdxType i
Definition: posidxpairdataset.h:88
IdxSet frsts_
Definition: posidxpairdataset.h:231
bool append(TypeSetBase< T, I > &to, const TypeSetBase< S, J > &from)
append allowing a different type to be merged into set
Definition: typeset.h:205
A sorted set of IdxPairs and associated data buffer.
Definition: posidxpairdataset.h:60
ObjectSet< const void > objs_
Definition: posidxpairdataset.h:219
Set of (small) copyable elements.
Definition: commontypes.h:26
Horizontal sampling (inline and crossline range and steps).
Definition: trckeysampling.h:25
const ObjData & gtObjData(const SPos &pos) const
Definition: posidxpairdataset.h:254
ObjectSet< IdxSet > scndsets_
Definition: posidxpairdataset.h:232
SPos findFirst(const IdxPair &ip) const
Definition: posidxpairdataset.h:117
ArrIdxType nrRows() const
Definition: posidxpairdataset.h:172
IdxPair::IdxType IdxType
Definition: posidxpairdataset.h:64
Position.
Definition: commontypes.h:38
bool allowdup_
Definition: posidxpairdataset.h:229
od_int64 GlobIdxType
Definition: posidxpairdataset.h:67
ObjData & gtObjData(ArrIdxType idx)
Definition: posidxpairdataset.h:260
bool operator!=(const ArrayNDInfo &a1, const ArrayNDInfo &a2)
Definition: arrayndinfo.h:60
void reset()
Definition: posidxpairdataset.h:79
const T * find(const ObjectSet< T > &os, const S &val)
Get const object in set.
Definition: objectset.h:187
ArrIdxType nrInls() const
Definition: posidxpairdataset.h:170
bool includes(const IdxPair &ip) const
Definition: posidxpairdataset.h:145
Position info, often segmented.
Definition: posinfo.h:38
bool isValid() const
Definition: posidxpairdataset.h:86
TypeSet< IdxType > IdxSet
Definition: posidxpairdataset.h:194
IdxType gtScnd(const SPos &pos) const
Definition: posidxpairdataset.h:244
bool isEmpty() const
Definition: posidxpairdataset.h:98
Index_Type IdxType
Definition: idxpair.h:32
BufSzType bufsz_
Definition: posidxpairdataset.h:222
ObjData & gtObjData(const SPos &pos)
Definition: posidxpairdataset.h:252
bool hasInl(IdxType inl) const
Definition: posidxpairdataset.h:174
od_int64 ObjSzType
Definition: posidxpairdataset.h:66
IdxSet & gtScndSet(const SPos &pos)
Definition: posidxpairdataset.h:248
SPos(ArrIdxType ii=-1, ArrIdxType jj=-1)
Definition: posidxpairdataset.h:77
unsigned char BufType
Definition: posidxpairdataset.h:201
void(* EntryCreatedFn)(IdxPairDataSet &, int spos_i, int spos_j)
Definition: posidxpairdataset.h:26
const ObjData & gtObjData(ArrIdxType idx) const
Definition: posidxpairdataset.h:262
IdxType gtFrst(const SPos &pos) const
Definition: posidxpairdataset.h:242
Set Position: position in IdxPairDataSet.
Definition: posidxpairdataset.h:75
Position info for an entire 3D cube. The LineData&#39;s are not sorted.
Definition: posinfo.h:96
bool allowsDuplicateIdxPairs() const
Definition: posidxpairdataset.h:105
Interval< IdxType > colRange(IdxType row=-1) const
Definition: posidxpairdataset.h:182
ObjSzType objSize() const
Definition: posidxpairdataset.h:103
~ObjData()
Definition: posidxpairdataset.h:206
ArrIdxType nrCols(IdxType row) const
Definition: posidxpairdataset.h:173
SPos find(const IdxPair &ip) const
Definition: posidxpairdataset.h:115

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