OpendTect-6_4  6.4
posidxpairdataset.h
Go to the documentation of this file.
1 #ifndef posidxpairdataset_h
2 #define posidxpairdataset_h
3 
4 /*+
5 ________________________________________________________________________
6 
7  (C) dGB Beheer B.V.; (LICENSE) http://opendtect.org/OpendTect_license.txt
8  Author: Bert
9  Date: July 2004/Oct 2013/Mar 2016
10 ________________________________________________________________________
11 
12 -*/
13 
14 #include "generalmod.h"
15 #include "posidxpair.h"
16 #include "sets.h"
17 #include "ranges.h"
18 #include "od_iosfwd.h"
19 namespace PosInfo { class CubeData; }
20 class TrcKeySampling;
21 
22 
23 namespace Pos
24 {
25 
26 class IdxPairDataSet;
27 typedef void (*EntryCreatedFn)(IdxPairDataSet&,int spos_i,int spos_j);
28 
61 mExpClass(General) IdxPairDataSet
62 {
63 public:
64 
69 
70 
76  struct SPos
77  {
78  SPos( ArrIdxType ii=-1, ArrIdxType jj=-1 )
79  : i(ii), j(jj) {}
80  void reset() { i = j = -1; }
81  inline bool operator ==( const SPos& oth ) const
82  { return i == oth.i && j == oth.j; }
83  inline bool operator !=( const SPos& oth ) const
84  { return i != oth.i || j != oth.j; }
85  inline bool operator>(const SPos&) const;
86  inline bool operator<(const SPos&) const;
87  inline bool isValid() const { return i > -1 && j > -1; }
88 
89  ArrIdxType i, j;
90  };
91 
92 
93  IdxPairDataSet(ObjSzType,bool allow_duplicate_idxs,
94  bool manage_data=true);
95  IdxPairDataSet(const IdxPairDataSet&);
96  virtual ~IdxPairDataSet();
97  IdxPairDataSet& operator =(const IdxPairDataSet&);
98 
99  inline bool isEmpty() const { return frsts_.isEmpty(); }
100  void setEmpty();
101  void copyStructureFrom(const IdxPairDataSet&);
103 
104  ObjSzType objSize() const { return objsz_; }
105  bool managesData() const { return mandata_; };
106  bool allowsDuplicateIdxPairs() const { return allowdup_; }
107  void allowDuplicateIdxPairs(bool);
108  bool append(const IdxPairDataSet&);
109  void remove(const IdxPairDataSet&);
110  void remove(const TrcKeySampling& hrg,bool inside);
111  void remove(SPos);
112  void remove(const TypeSet<SPos>&);
115 
116  inline SPos find( const IdxPair& ip ) const
117  { return findFirst(ip); }
118  inline SPos findFirst( const IdxPair& ip ) const
119  { return findOccurrence(ip,0); }
120  SPos findOccurrence(const IdxPair&,int occ=0) const;
121  bool next(SPos&,bool skip_duplicate_idxpairs=false) const;
122  bool prev(SPos&,bool skip_duplicate_idxpairs=false) 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  EntryCreatedFn fn=0);
162  void add(const PosInfo::CubeData&,EntryCreatedFn fn=0);
164  void randomSubselect(GlobIdxType maxsz);
165 
166  // I/O
167  bool dump(od_ostream&,bool binary) const;
168  bool slurp(od_istream&,bool binary);
169 
170  // aliases
171  inline ArrIdxType nrInls() const { return nrFirst(); }
172  inline ArrIdxType nrCrls( IdxType inl ) const { return nrSecond(inl); }
173  inline ArrIdxType nrRows() const { return nrFirst(); }
174  inline ArrIdxType nrCols( IdxType row ) const { return nrSecond(row); }
175  bool hasInl( IdxType inl ) const { return hasFirst(inl); }
176  bool hasCrl( IdxType crl ) const { return hasSecond(crl); }
177  inline bool hasRow( IdxType row ) const { return hasFirst(row); }
178  inline bool hasCol( IdxType col ) const { return hasSecond(col); }
179  Interval<IdxType> inlRange() const { return firstRange(); }
180  Interval<IdxType> rowRange() const { return firstRange(); }
181  Interval<IdxType> crlRange( IdxType inl=-1 ) const
182  { return secondRange(inl); }
183  Interval<IdxType> colRange( IdxType row=-1 ) const
184  { return secondRange(row); }
185 
186  // Maybe messing with managed objects in buf.
187  bool setObjSize(ObjSzType sz,ObjSzType offs_in_objs=-1,
188  const void* initwith=0);
189  // offs_in_objs < 0: operate at end
190  void decrObjSize(ObjSzType,ObjSzType offs=-1);
191  bool incrObjSize(ObjSzType,ObjSzType offs=-1,const void* =0);
192 
193 protected:
194 
197 
198  class ObjData
199  {
200  public:
201 
202  typedef unsigned char BufType;
203 
204  ObjData() : buf_(0), bufsz_(0)
205  { objs_.allowNull(true); }
206  ObjData(const ObjData&);
207  ~ObjData() { delete [] buf_; }
208 
209  const void* getObj(bool,ArrIdxType,ObjSzType) const;
210  void putObj(bool,ArrIdxType,ObjSzType,const void*);
211  bool addObjSpace(bool,ArrIdxType,ObjSzType);
212  void removeObj(bool,ArrIdxType,ObjSzType);
213  void decrObjSize(ObjSzType orgsz,ObjSzType newsz,
214  ObjSzType at_offs);
215  bool incrObjSize(ObjSzType,ObjSzType,ObjSzType,
216  const void*);
217 
218  private:
219 
220  ObjectSet<const void> objs_; // contains const bool* when mandata
221 
222  BufType* buf_;
223  BufSzType bufsz_;
224  bool manageBufCapacity(ObjSzType);
225 
226  };
227 
228  const ObjSzType objsz_;
229  const bool mandata_;
230  bool allowdup_;
231 
232  IdxSet frsts_;
235 
236  static ArrIdxType findIndexFor(const IdxSet&,IdxType,bool* found=0);
237  const void* gtObj(const SPos&) const;
238  bool addObj(SPos&,IdxType,const void*);
239  void putObj(const SPos&,const void*);
240  void addEntry(const Pos::IdxPair&,const void*,SPos&);
241 
242  // All 'gt' functions return unchecked
243  inline IdxType gtFrst( const SPos& pos ) const
244  { return frsts_[pos.i]; }
245  inline IdxType gtScnd( const SPos& pos ) const
246  { return gtScndSet(pos)[pos.j]; }
247  inline IdxPair gtIdxPair( const SPos& pos ) const
248  { return IdxPair( gtFrst(pos), gtScnd(pos) ); }
249  inline IdxSet& gtScndSet( const SPos& pos )
250  { return *scndsets_[pos.i]; }
251  inline const IdxSet& gtScndSet( const SPos& pos ) const
252  { return *scndsets_[pos.i]; }
253  inline ObjData& gtObjData( const SPos& pos )
254  { return *objdatas_[pos.i]; }
255  inline const ObjData& gtObjData( const SPos& pos ) const
256  { return *objdatas_[pos.i]; }
257  inline IdxSet& gtScndSet( ArrIdxType idx )
258  { return *scndsets_[idx]; }
259  inline const IdxSet& gtScndSet( ArrIdxType idx ) const
260  { return *scndsets_[idx]; }
261  inline ObjData& gtObjData( ArrIdxType idx )
262  { return *objdatas_[idx]; }
263  inline const ObjData& gtObjData( ArrIdxType idx ) const
264  { return *objdatas_[idx]; }
265 
266 };
267 
268 
269 inline bool IdxPairDataSet::SPos::operator >( const SPos& oth ) const
270 {
271  if ( i > oth.i )
272  return true;
273  return i == oth.i && j > oth.j;
274 }
275 
276 
277 inline bool IdxPairDataSet::SPos::operator <( const SPos& oth ) const
278 {
279  if ( i < oth.i )
280  return true;
281  return i == oth.i && j < oth.j;
282 }
283 
284 
285 } // namespace Pos
286 
287 
288 #endif
Interval< IdxType > crlRange(IdxType inl=-1) const
Definition: posidxpairdataset.h:181
#define mExpClass(module)
Definition: commondefs.h:160
ArrIdxType nrCrls(IdxType inl) const
Definition: posidxpairdataset.h:172
const ObjSzType objsz_
Definition: posidxpairdataset.h:228
ObjData()
Definition: posidxpairdataset.h:204
OD class for stream write common access to the user log file, or std::cout in batch progs...
Definition: od_ostream.h:26
const IdxSet & gtScndSet(const SPos &pos) const
Definition: posidxpairdataset.h:251
bool operator==(const ArrayNDInfo &a1, const ArrayNDInfo &a2)
Definition: arrayndinfo.h:53
bool hasCrl(IdxType crl) const
Definition: posidxpairdataset.h:176
IdxSet & gtScndSet(ArrIdxType idx)
Definition: posidxpairdataset.h:257
bool managesData() const
Definition: posidxpairdataset.h:105
bool hasRow(IdxType row) const
Definition: posidxpairdataset.h:177
ArrIdxType nrFirst() const
Definition: posidxpairdataset.h:143
ObjectSet< ObjData > objdatas_
Definition: posidxpairdataset.h:234
#define od_int64
Definition: plftypes.h:36
od_int64 BufSzType
Definition: posidxpairdataset.h:196
Interval< IdxType > rowRange() const
Definition: posidxpairdataset.h:180
IdxPair with position indices; base class for BinID et al.
Definition: posidxpair.h:29
const bool mandata_
Definition: posidxpairdataset.h:229
bool hasCol(IdxType col) const
Definition: posidxpairdataset.h:178
TypeSet< IdxType >::size_type ArrIdxType
Definition: posidxpairdataset.h:66
IdxPair gtIdxPair(const SPos &pos) const
Definition: posidxpairdataset.h:247
BufType * buf_
Definition: posidxpairdataset.h:222
const IdxSet & gtScndSet(ArrIdxType idx) const
Definition: posidxpairdataset.h:259
Interval of values.
Definition: commontypes.h:31
OD class for stream read.
Definition: od_istream.h:24
ArrIdxType j
Definition: posidxpairdataset.h:89
Definition: posidxpairdataset.h:198
Interval< IdxType > inlRange() const
Definition: posidxpairdataset.h:179
ArrIdxType i
Definition: posidxpairdataset.h:89
IdxSet frsts_
Definition: posidxpairdataset.h:232
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
A sorted set of IdxPairs and associated data buffer.
Definition: posidxpairdataset.h:61
ObjectSet< const void > objs_
Definition: posidxpairdataset.h:220
Set of (small) copyable elements.
Definition: commontypes.h:30
Horizontal sampling (inline and crossline range and steps).
Definition: trckeysampling.h:27
const ObjData & gtObjData(const SPos &pos) const
Definition: posidxpairdataset.h:255
ObjectSet< IdxSet > scndsets_
Definition: posidxpairdataset.h:233
SPos findFirst(const IdxPair &ip) const
Definition: posidxpairdataset.h:118
ArrIdxType nrRows() const
Definition: posidxpairdataset.h:173
IdxPair::IdxType IdxType
Definition: posidxpairdataset.h:65
Position.
Definition: commontypes.h:42
bool allowdup_
Definition: posidxpairdataset.h:230
od_int64 GlobIdxType
Definition: posidxpairdataset.h:68
ObjData & gtObjData(ArrIdxType idx)
Definition: posidxpairdataset.h:261
bool operator!=(const ArrayNDInfo &a1, const ArrayNDInfo &a2)
Definition: arrayndinfo.h:62
void reset()
Definition: posidxpairdataset.h:80
const T * find(const ObjectSet< T > &os, const S &val)
Get const object in set.
Definition: objectset.h:183
ArrIdxType nrInls() const
Definition: posidxpairdataset.h:171
bool includes(const IdxPair &ip) const
Definition: posidxpairdataset.h:145
Position info, often segmented.
Definition: posinfo.h:40
bool isValid() const
Definition: posidxpairdataset.h:87
TypeSet< IdxType > IdxSet
Definition: posidxpairdataset.h:195
IdxType gtScnd(const SPos &pos) const
Definition: posidxpairdataset.h:245
bool isEmpty() const
Definition: posidxpairdataset.h:99
Index_Type IdxType
Definition: idxpair.h:34
BufSzType bufsz_
Definition: posidxpairdataset.h:223
ObjData & gtObjData(const SPos &pos)
Definition: posidxpairdataset.h:253
bool hasInl(IdxType inl) const
Definition: posidxpairdataset.h:175
od_int64 ObjSzType
Definition: posidxpairdataset.h:67
IdxSet & gtScndSet(const SPos &pos)
Definition: posidxpairdataset.h:249
SPos(ArrIdxType ii=-1, ArrIdxType jj=-1)
Definition: posidxpairdataset.h:78
unsigned char BufType
Definition: posidxpairdataset.h:202
void(* EntryCreatedFn)(IdxPairDataSet &, int spos_i, int spos_j)
Definition: posidxpairdataset.h:27
const ObjData & gtObjData(ArrIdxType idx) const
Definition: posidxpairdataset.h:263
IdxType gtFrst(const SPos &pos) const
Definition: posidxpairdataset.h:243
Set Position: position in IdxPairDataSet.
Definition: posidxpairdataset.h:76
Position info for an entire 3D cube. The LineData&#39;s are not sorted.
Definition: posinfo.h:95
bool allowsDuplicateIdxPairs() const
Definition: posidxpairdataset.h:106
Interval< IdxType > colRange(IdxType row=-1) const
Definition: posidxpairdataset.h:183
ObjSzType objSize() const
Definition: posidxpairdataset.h:104
~ObjData()
Definition: posidxpairdataset.h:207
ArrIdxType nrCols(IdxType row) const
Definition: posidxpairdataset.h:174
SPos find(const IdxPair &ip) const
Definition: posidxpairdataset.h:116

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