OpendTect-6_4  6.4
densitycalc.h
Go to the documentation of this file.
1 #ifndef densitycalc_h
2 #define densitycalc_h
3 
4 /*+
5 ________________________________________________________________________
6 
7  CopyRight: (C) dGB Beheer B.V.
8  Author: Satyaki
9  Date: Aug 2009
10  RCS: $Id$
11 ________________________________________________________________________
12 
13 -*/
14 
16 
17 #include "arraynd.h"
18 #include "mathexpression.h"
19 #include "polygon.h"
20 #include "rowcol.h"
21 #include "task.h"
22 #include "threadlock.h"
23 
24 #include "uidatapointset.h"
25 #include "uiworld2ui.h"
26 
27 
29 
32 public:
37  const char* header);
38 
39  od_int64 nrDone() const;
40  uiString uiNrDoneText() const;
41  od_int64 nrIterations() const;
42  bool doWork(od_int64 start,od_int64 stop,int);
43 
44  bool isSelectionValid(uiDataPointSet::DRowID);
45  void setNrBins(int nrbinx,int nrbiny);
46  void setWorld2Ui(const uiWorld2Ui&);
47  void setMathObj(Math::Expression*);
48  void setModifiedColIds(
50 
51  void setDPSChangeable(bool yn);
52  void setRemSelected(bool yn);
53  void setCurGroup(int curgrp);
54 
55  void setCellXSize(float sz);
56  void setCellYSize(float sz);
57  void setCellSize(float sz);
58  int indexSize() const;
59 
60  void setAreaType(int areatype);
61  int areaType() const;
62 
63  void getFreqData(Array2D<float>&) const;
64 
65  const TypeSet<RowCol>& selRCs() const;
66  const Interval<int>& usedXPixRg() const;
67 
68 
69 protected:
85  bool changedps_;
86  bool removesel_;
87  int curgrp_;
88  int indexsz_;
89  int nrdone_;
90  float cellxsize_;
91  float cellysize_;
92  int areatype_;
93 };
94 
95 
99  const ObjectSet<SelectionGrp>& grps,
100  const char* header )
101  : ParallelTask( header )
102  , uidps_( uidps )
103  , dps_( uidps.pointSet() )
104  , selgrpset_( grps )
105  , data_( data )
106  , freqdata_( 0 )
107  , x_( x )
108  , y_( y )
109  , mathobj_( 0 )
110  , xpixrg_( x_.axis_->pixRange() )
111  , ypixrg_( y_.axis_->pixRange() )
112  , usedxpixrg_( Interval<int> (0,0) )
113  , changedps_( false )
114  , removesel_( false )
115  , curgrp_( 0 )
116  , nrdone_( 0 )
117  , indexsz_( 0 )
118  , cellxsize_( 1.0 )
119  , cellysize_( 1.0 )
120  , areatype_( 0 )
121 {
122  if ( data_ )
123  {
124  const int celldatawdth = data_->info().getSize(0)%mNINT32(cellxsize_)
125  ? data_->info().getSize(0)/mNINT32(cellxsize_) + 1
127  const int celldataheight = data_->info().getSize(1)%mNINT32(cellysize_)
128  ? data_->info().getSize(1)/mNINT32(cellysize_) + 1
130  freqdata_ = new Array2DImpl<float>( celldatawdth, celldataheight );
131  freqdata_->setAll( (float)0 );
132  }
133 }
134 
136 { return nrdone_; }
137 
139 { return tr("Points done");}
140 
142 { return dps_.size(); }
143 
144 inline void DensityCalc::setWorld2Ui( const uiWorld2Ui& w2ui )
145 { w2ui_ = w2ui; }
146 
148 { mathobj_ = mobj; }
149 
152 { modcolidxs_ = ids; }
153 
154 inline void DensityCalc::setDPSChangeable( bool yn )
155 { changedps_ = yn; }
156 
157 inline void DensityCalc::setRemSelected( bool yn )
158 { removesel_ = yn; }
159 
160 inline void DensityCalc::setCurGroup( int curgrp )
161 { curgrp_ = curgrp; }
162 
163 inline void DensityCalc::setCellXSize( float sz )
164 { cellxsize_ = sz; }
165 
166 inline void DensityCalc::setCellYSize( float sz )
167 { cellysize_ = sz; }
168 
169 inline void DensityCalc::setCellSize( float sz)
170 { cellxsize_ = cellysize_ = sz; }
171 
172 inline int DensityCalc::indexSize() const
173 { return indexsz_; }
174 
176 { return selrowcols_; }
177 
179 { return usedxpixrg_; }
180 
181 inline void DensityCalc::setAreaType(int areatype)
182 { areatype_ = areatype; }
183 
184 inline int DensityCalc::areaType() const
185 { return areatype_; }
186 
188 {
189  if ( modcolidxs_.size() && mathobj_ )
190  {
191  for ( int idx=0; idx<modcolidxs_.size(); idx++ )
192  {
193  const float yval = uidps_.getValue( modcolidxs_[idx], rid, true );
194  mathobj_->setVariableValue( idx, yval );
195  }
196 
197  const float result = mCast(float,mathobj_->getValue());
198  if ( mIsZero(result,mDefEps) || mIsUdf(result) )
199  return false;
200  }
201  return true;
202 }
203 
204 
205 void DensityCalc::setNrBins( int nrbinx, int nrbiny )
206 {
207  if ( !freqdata_ )
208  freqdata_ = new Array2DImpl<float>( nrbinx, nrbiny );
209  else
210  {
212  arrimpl->setSize( nrbinx, nrbiny );
213  }
214 
215  freqdata_->setAll( (float)0 );
216 }
217 
218 
219 bool DensityCalc::doWork( od_int64 start, od_int64 stop, int )
220 {
222  for ( ; rid<=stop; rid++ )
223  {
224  nrdone_++;
225  if ( dps_.isInactive(rid) || (curgrp_>0 && dps_.group(rid)!=curgrp_) )
226  continue;
227 
228  const float xval = uidps_.getValue( x_.colid_, rid, true );
229  const float yval = uidps_.getValue( y_.colid_, rid, true );
230  if ( mIsUdf(xval) || mIsUdf(yval) ) continue;
231 
232  uiWorldPoint wpt( (double)x_.axis_->getPix(xval),
233  (double)y_.axis_->getPix(yval) );
234  uiPoint pos( x_.axis_->getPix(xval), y_.axis_->getPix(yval) );
235  uiPoint datapt = w2ui_.transform( wpt );
236 
237  if ( !xpixrg_.includes(pos.x,true) || !ypixrg_.includes(pos.y,true) )
238  continue;
239 
240  if ( usedxpixrg_.width() == 0 && usedxpixrg_.start == 0 )
241  usedxpixrg_ = Interval<int>( pos.x, pos.x );
242  else
243  usedxpixrg_.include( pos.x );
244 
245  bool ptselected = false;
246  bool ptremoved = false;
247  if ( selgrpset_.size() && (changedps_ || removesel_) )
248  {
249  for ( int idx=0; idx<selgrpset_.size(); idx++ )
250  {
251  const SelectionGrp* selgrp = selgrpset_[idx];
252  for ( int selidx=0; selidx<selgrp->size(); selidx++ )
253  {
254  if ( !selgrp->isValidIdx(selidx) ) continue;
255  const SelectionArea& selarea =
256  selgrp->getSelectionArea( selidx );
257 
258  if ( selarea.isInside(pos) )
259  {
260  Threads::Locker lckr( lock_ );
261  if ( !isSelectionValid(rid) )
262  continue;
263  if ( removesel_ )
264  {
265  dps_.setInactive( rid, true );
266  ptremoved = true;
267  }
268  else
269  {
270  ptselected = true;
272  selarea.id_) );
273  RowCol rcol( uidps_.tRowID(rid),
274  uidps_.tColID(y_.colid_) );
275  selrowcols_ += rcol;
276  }
277  }
278  }
279  }
280  }
281 
282  if ( !ptselected )
283  dps_.setSelected( rid, -1 );
284  if ( !data_->info().validPos(datapt.x,datapt.y) )
285  continue;
286  const int freqx = mNINT32(datapt.x/cellxsize_);
287  const int freqy = mNINT32(datapt.y/cellysize_);
288  if ( !areatype_ )
289  freqdata_->set( freqx, freqy,
290  ptremoved ? 0 : freqdata_->get(freqx,freqy) + (float)1 );
291  else if ( areatype_==1 && ptselected )
292  freqdata_->set( freqx, freqy,
293  ptremoved ? 0 : freqdata_->get(freqx,freqy) + (float)1 );
294  else if ( areatype_==2 && !ptselected )
295  freqdata_->set( freqx, freqy,
296  ptremoved ? 0 : freqdata_->get(freqx,freqy) + (float)1 );
297 
298  if ( data_ )
299  {
300  for ( int idx=0; idx<mNINT32(cellxsize_); idx++ )
301  {
302  for ( int idy=0; idy<mNINT32(cellysize_); idy++ )
303  data_->set( freqx*mNINT32(cellxsize_)+idx,
304  freqy*mNINT32(cellysize_)+idy,
305  ptremoved ? 0 : freqdata_->get(freqx,freqy) );
306  }
307  if ( indexsz_ < mNINT32(data_->get(datapt.x,datapt.y)) )
308  indexsz_ = mNINT32(data_->get(datapt.x,datapt.y));
309  }
310  }
311 
312  return true;
313 }
314 
315 
317 {
318  mDynamicCastGet(Array2DImpl<float>*,freqdataimpl,&freqdata)
319  if ( !freqdataimpl ) return;
320  freqdataimpl->setSize( freqdata_->info().getSize(0),
321  freqdata_->info().getSize(1) );
322  for ( int idx=0; idx<freqdata_->info().getSize(0); idx++ )
323  {
324  for ( int idy=0; idy<freqdata_->info().getSize(1); idy++ )
325  freqdata.set( idx, idy, freqdata_->get(idx,idy) );
326  }
327 }
328 
329 
330 #endif
Class to provide coordinate conversion between a cartesian coordinate system (or any other transforme...
Definition: uiworld2ui.h:55
#define mIsUdf(val)
Use mIsUdf to check for undefinedness of simple types.
Definition: undefval.h:287
static uiString tr(const char *text, const char *disambiguation=0, int pluralnr=-1)
Definition: paralleltask.h:67
Locks the lock, shutting out access from other threads if needed.
Definition: threadlock.h:85
calculates densities for teh density display of a crossplot
Definition: densitycalc.h:30
A lock of a type that (hopefully) suits your needs. To use it, you need the Locker class...
Definition: threadlock.h:53
bool doWork(od_int64 start, od_int64 stop, int)
Definition: densitycalc.h:219
Set of data points with group selection.
Definition: datapointset.h:48
Interval< int > xpixrg_
Definition: densitycalc.h:81
Array2D< float > * freqdata_
Definition: densitycalc.h:78
virtual T get(int p0, int p1) const =0
void setMathObj(Math::Expression *)
Definition: densitycalc.h:147
uiWorld2Ui w2ui_
Definition: densitycalc.h:74
Math::Expression * mathobj_
Definition: densitycalc.h:72
#define mODTextTranslationClass(clss)
Definition: uistring.h:38
#define mIsZero(x, eps)
Definition: commondefs.h:53
Interval< int > usedxpixrg_
Definition: densitycalc.h:82
bool isSelectionValid(uiDataPointSet::DRowID)
Definition: densitycalc.h:187
#define mCast(tp, v)
Definition: commondefs.h:124
#define od_int64
Definition: plftypes.h:36
DataPointSet & dps_
Definition: densitycalc.h:71
int RowID
Definition: datapointset.h:52
bool isInactive(RowID rid) const
Definition: datapointset.h:174
uiString uiNrDoneText() const
will be nrDoneText() in 7.x
Definition: densitycalc.h:138
DensityCalc(uiDataPointSet &, Array2D< float > *data, uiDataPointSetCrossPlotter::AxisData &x, uiDataPointSetCrossPlotter::AxisData &y, const ObjectSet< SelectionGrp > &, const char *header)
Definition: densitycalc.h:96
uiDataPointSetCrossPlotter::AxisData & y_
Definition: densitycalc.h:80
float cellysize_
Definition: densitycalc.h:91
void setInactive(RowID, bool)
Definition: uistring.h:89
const Interval< int > & usedXPixRg() const
Definition: densitycalc.h:178
virtual bool validPos(int, int) const
unsigned short group(RowID) const
void setAreaType(int areatype)
Definition: densitycalc.h:181
virtual void set(int, int, T)=0
Generalization of a task that can be run in parallel.
Definition: paralleltask.h:66
virtual double getValue() const =0
bool isValidIdx(int idx) const
size_type size() const
Definition: objectset.h:50
Array2D< float > * data_
Definition: densitycalc.h:77
virtual int getSize(int dim) const =0
uiDataPointSetCrossPlotter::AxisData & x_
Definition: densitycalc.h:79
#define mNINT32(x)
Definition: commondefs.h:45
Definition: uidatapointsetcrossplot.h:94
DataPointSet::ColID colid_
Definition: uidatapointsetcrossplot.h:106
void setDPSChangeable(bool yn)
Definition: densitycalc.h:154
void setCurGroup(int curgrp)
Definition: densitycalc.h:160
bool getSelectionArea(SelectionArea &, int id) const
uiAxisHandler * axis_
Definition: uiaxisdata.h:53
TRowID tRowID(DRowID did=-99) const
DataPointSet::RowID DRowID
Definition: uidatapointset.h:51
T width(bool allowrev=true) const
Definition: ranges.h:451
void setCellXSize(float sz)
Definition: densitycalc.h:163
Definition: uidpscrossplottools.h:66
virtual void setVariableValue(int, double)
void setWorld2Ui(const uiWorld2Ui &)
Definition: densitycalc.h:144
int getPix(float absval) const
uiWorldPoint transform(uiPoint p) const
void setModifiedColIds(const TypeSet< uiDataPointSet::DColID > &)
Definition: densitycalc.h:150
TypeSet< uiDataPointSet::DColID > modcolidxs_
Definition: densitycalc.h:76
#define mDynamicCastGet(typ, out, in)
Definition: commondefs.h:131
#define mDefEps
Definition: commondefs.h:58
virtual void setAll(T)
Definition: arraynd.h:386
void setSelected(RowID, int selgrp)
Interval< int > ypixrg_
Definition: densitycalc.h:83
float cellxsize_
Definition: densitycalc.h:90
IdxPair used for its row() and col().
Definition: rowcol.h:25
Parsed Math expression.
Definition: mathexpression.h:32
int areatype_
Definition: densitycalc.h:92
int size() const
size_type size() const
Definition: typeset.h:254
bool removesel_
Definition: densitycalc.h:86
void include(const T &, bool allowrev=true)
Definition: ranges.h:531
int areaType() const
Definition: densitycalc.h:184
uiDataPointSet & uidps_
Definition: densitycalc.h:70
int getSelectionGroupIdx(int selaareaid) const
void setRemSelected(bool yn)
Definition: densitycalc.h:157
void setCellYSize(float sz)
Definition: densitycalc.h:166
int nrdone_
Definition: densitycalc.h:89
Edit DataPointSet.
Definition: uidatapointset.h:44
Threads::Lock lock_
Definition: densitycalc.h:84
TypeSet< RowCol > selrowcols_
Definition: densitycalc.h:75
bool includes(const X &, bool allowrev) const
Definition: ranges.h:482
int indexsz_
Definition: densitycalc.h:88
bool changedps_
Definition: densitycalc.h:85
const TypeSet< RowCol > & selRCs() const
Definition: densitycalc.h:175
T start
Definition: ranges.h:92
int curgrp_
Definition: densitycalc.h:87
void getFreqData(Array2D< float > &) const
Definition: densitycalc.h:316
#define mClass(module)
Definition: commondefs.h:164
virtual const Array2DInfo & info() const =0
int indexSize() const
Definition: densitycalc.h:172
const ObjectSet< SelectionGrp > & selgrpset_
Definition: densitycalc.h:73
od_int64 nrDone() const
May be -1, i.e. class does not report nrdone.
Definition: densitycalc.h:135
int size() const
Definition: datapointset.h:159
TColID tColID(DColID did=-99) const
void setNrBins(int nrbinx, int nrbiny)
Definition: densitycalc.h:205
void setCellSize(float sz)
Definition: densitycalc.h:169
od_int64 nrIterations() const
Definition: densitycalc.h:141
float getValue(DColID did, DRowID rid, bool userunits) const
Definition: uidatapointset.h:264

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