ProjectorBase.cxx
Go to the documentation of this file.
1 
12 #ifdef _MSC_VER
13 #include "msdevstudio/MSconfig.h"
14 #endif
15 
16 #include "ProjectorBase.h"
17 #include "ProjectorHelper.h"
18 
19 #include "axes/AxisModelBase.h"
20 #include "datasrcs/DataSource.h"
22 
23 
24 #include <algorithm>
25 
26 #include <cassert>
27 
28 #ifdef ITERATOR_MEMBER_DEFECT
29 using namespace std;
30 #else
31 using std::find;
32 using std::string;
33 using std::vector;
34 using std::distance;
35 #endif
36 
37 using namespace hippodraw;
38 
39 ProjectorBase::ProjectorBase ()
40  : m_isDirty ( true ),
41  m_proj_values ( 0 ),
42  m_x_axis ( 0 ),
43  m_y_axis ( 0 ),
44  m_z_axis ( 0 )
45 {
46 }
47 
49  : Observable (),
50  Observer (),
51  m_isDirty ( true ),
52  m_proj_values ( 0 ),
53  m_x_axis ( p.m_x_axis ),
54  m_y_axis ( p.m_y_axis ),
55  m_z_axis ( p.m_z_axis )
56 {
57 }
58 
60 {
61  if ( m_proj_values != 0 ) delete m_proj_values;
62 }
63 
64 /* virtual */
66 {
67  setDirty ( false );
68 }
69 
71 {
72  return m_isDirty;
73 }
74 
75 void ProjectorBase::setDirty ( bool value )
76 {
77  m_isDirty = value;
78 
79  if ( value == true ) notifyObservers ();
80 }
81 
82 void
84 setAxisBinding ( const std::string &,
85  const std::string & )
86 {
87  assert ( false );
88 }
89 
90 void
92 setAxisBindings ( const std::vector < std::string > & )
93 {
94  assert ( false );
95 }
96 
97 const vector < string > &
100 {
101  assert ( false );
102  static vector < string > dummy;
103 
104  return dummy;
105 }
106 
107 void
110 {
111  // does nothing
112 }
113 
114 int
117 {
118  return 0;
119 }
120 
121 bool ProjectorBase::isAxisBinned ( const std::string & ) const
122 {
123  return false;
124 }
125 
127 {
128  return false;
129 }
130 
131 void
134 {
135  // The only supported axis so far...
136  assert ( axis == Axes::X || axis == Axes::Y || axis == Axes::Z );
137 
138  if ( axis == Axes::Z ) assert ( m_z_axis != 0 );
139 
140  setDirty ( true );
141 }
142 
143 const Range &
146 {
147  // All the axis supported so far
148  assert ( axis == Axes::X || axis == Axes::Y || axis == Axes::Z );
149 
150  if ( axis == Axes::X ) {
151  return m_x_axis->getRange (false);
152  }
153  if ( axis == Axes::Y ) {
154  return m_y_axis->getRange (false);
155  }
156  //else
157  assert ( m_z_axis != 0 );
158  return m_z_axis->getRange (false);
159 }
160 
161 Range
164 {
165  Range range = dataRangeOn ( axis );
166 
167  if ( range.length() == 0.0 ) {
168 
169  double low = range.low ();
170 
171  if ( axis == Axes::Y &&
172  low == 0.0 ) {
173  range.setHigh ( 1.0 );
174  }
175  else {
176  if ( low > 0.0 ) {
177  range.setLow ( 0.9 * low );
178  range.setHigh ( 1.1 * low );
179  }
180  else {
181  range.setLow ( 1.1 * low );
182  range.setHigh ( 0.9 * low );
183  }
184  }
185  }
186 
187  return range;
188 }
189 
190 void
193  AxisModelBase * axis_model )
194 {
195  assert ( axis == Axes::X || axis == Axes::Y || axis == Axes::Z );
196 
197  if ( axis == Axes::X ) {
198  m_x_axis = axis_model;
199  }
200  if ( axis == Axes::Y ) {
201  m_y_axis = axis_model;
202  }
203 
204  if ( axis == Axes::Z ) {
205  m_z_axis = axis_model;
206  }
207 }
208 
212 {
213  assert ( axis == Axes::X || axis == Axes::Y || axis == Axes::Z );
214 
215  if ( axis == Axes::X ) {
216  return m_x_axis;
217  }
218 
219  if ( axis == Axes::Y ) {
220  return m_y_axis;
221  }
222 
223  return m_z_axis;
224 }
225 
226 void
229 {
230 }
231 
232 const Range &
235 {
236  static Range range ( 0., 1. );
237  return range;
238 }
239 
240 const Range &
242 setBinWidth ( Axes::Type, int, bool )
243 {
244  return m_x_axis -> getRange ( false );
245 
246 }
247 
248 void ProjectorBase::setOffset ( const std::string &,
249  int,
250  bool )
251 {
252 }
253 
254 void
257 {
258 }
259 
260 void
262 reset ( )
263 {
264 }
265 
266 double
269 {
270  return 0.0;
271 }
272 
276 double
279 {
280  // Never used as subclasses do the work.
281  return 0.0;
282 }
283 
287 double
290 {
292 
293  double rms = 0.0;
294 
295  if ( axis == Axes::X )
296  rms = helper.stdCoord();
297 
298  return rms;
299 }
300 
302 const std::string & ProjectorBase::getZLabel () const
303 {
304  return m_z_label;
305 }
306 
307 int
309 indexOf ( const std::string & label ) const
310 {
311  return -1;
312 }
313 
314 double
317 {
318  return 0.0;
319 }
320 
321 double
323 getZValue ( double, double ) const
324 {
325  return 0.0;
326 }
327 
328 void
330 addValues ( const std::vector < double > & )
331 {
332  // do nothing
333 }
334 
335 const vector <string> & ProjectorBase::getPointReps() const
336 {
337  return m_pointreps;
338 }
339 
340 NTuple *
343 {
344  return 0;
345 }
346 
347 void
349 fillColumnAfterCuts(const std::string & column,
350  std::vector<double> & columnData) const {
351 // do nothing by default
352 }
353 
354 NTuple *
356 createNTupleWith ( const std::vector< TupleCut > & cut_list ) const
357 {
358  return 0;
359 }
360 
361 
362 bool
364 wantsScaleFactor ( const std::string & ) const
365 {
366  return false;
367 }
368 
369 const DataSource *
372 {
373  return m_proj_values;
374 }
375 
376 const DataSource *
379 {
380  ProjectorBase * projector = const_cast < ProjectorBase * > ( this );
381  projector -> prepareValues ();
382 
383  return getProjectedValues ();
384 }
385 
386 void
388 normalizeTo ( double )
389 {
390  // does nothing
391 }
392 
393 void
396 {
397  // does nothing
398 }
399 
400 void
402 update ( const Observable * )
403 {
404  // does nothing
405 }
406 
407 void
410 {
411  // does nothing
412 }
413 
414 void
417 {
418  // does nothing
419 }
420 
421 const std::vector <double> &
424 {
425  const DataSource * ds = getProjectedValues ();
426  const std::vector <double> & oldzval = ds->getColumn (2);
427  const std::vector < unsigned int > & shape = getShape();
428 
429  unsigned int x = shape[0];
430  unsigned int y = shape[1];
431 
432  m_zval.clear();
433  m_zval.resize ( x*y, 0.0 );
434 
435  for ( unsigned int yy = 0; yy<y; yy++ )
436  for ( unsigned int xx = 0; xx<x; xx++ )
437  m_zval[yy*x+xx] = oldzval[xx*y+yy];
438 
439  return m_zval;
440 }
441 
442 const std::vector < unsigned int> &
445 {
446  const DataSource * ds = getProjectedValues ();
447  return ds->getShape ();
448 }
449 
454 const std::vector <double> &
457 {
458  const BinaryTransform * bt
459  = dynamic_cast <const BinaryTransform *>(transform);
460 
461  m_zval.clear();
462 
463  // Lambert 256*256
464  if ( bt-> aspectRatio() == 1.0 )
465  {
466  for ( unsigned int j = 0; j < 256; j++ )
467  for ( unsigned int i = 0; i < 256; i++ )
468  {
469  double x= static_cast < double > (i)-128;
470  double y= static_cast < double > (j)-128;
471  double z;
472 
473  bool yes = bt->inverseTransform ( x, y );
474 
475  if ( yes )
476  {
477  z = getZValue ( x, y );
478  }
479  else
480  {
481  z = 0.0;
482  }
483 
484  m_zval.push_back(z);
485  }
486  }
487 
488  // Hammer 360*180
489  else
490  {
491  for ( unsigned int j = 0; j < 180; j++ )
492  for ( unsigned int i = 0; i < 360; i++ )
493  {
494  double x= static_cast < double > (i)-180;
495  double y= static_cast < double > (j)-90;
496  double z;
497 
498  bool yes = bt->inverseTransform ( x, y );
499 
500  if ( yes )
501  {
502  z = getZValue ( x, y );
503  }
504  else
505  {
506  z = 0.0;
507  }
508 
509  m_zval.push_back(z);
510  }
511  }
512 
513  return (m_zval);
514 }
515 
516 bool
519 {
520  return false;
521 }
522 
523 void
525 setMinEntries(int entries)
526 {
527 }
528 
529 int
532 {
533  return -1;
534 }
535 
536 bool
539 {
540  return false;
541 }
const std::vector< double > & getZAfterTransform(TransformBase *transform)
Return Z values after binary transform.
virtual void setOffset(const std::string &axis, int parm, bool dragging)
Sets the bin offset.
virtual void matrixTranspose(bool yes)
Transposes the X and Y axis.
std::vector< std::string > m_pointreps
Vector of acceptable PointReps.
AxisModelBase * m_x_axis
The AxisModel along the X axis.
Definition: ProjectorBase.h:88
column
The column indices for 2 dimension data point tuple.
AxisModelBase * m_z_axis
The AxisModel along the Z axis.
Definition: ProjectorBase.h:96
std::vector< double > m_zval
Sorted Z values in this projector.
virtual NTuple * getNTupleAfterCuts() const
Template for projectors that can return subsets of the NTuple used by the DataRep.
virtual int getMinEntries()
Get the minimum entries/bin.
void setHigh(double x)
Sets the maximum of the range object.
Definition: Range.cxx:106
virtual void setRange(Axes::Type axis, bool const_width=true)
Sets the range of the selected axis.
virtual const std::vector< unsigned int > & getShape() const
Returns the shape of the data elements.
Definition: DataSource.cxx:313
const DataSource * getProjectedValues() const
Returns DataSource representation of projected values.
virtual void checkScaling()
Checks for scaling the display of the axis range.
virtual bool isValueBinned() const
Returns true if the projected values are the result of binning.
hippodraw::BinaryTransform class interface
virtual const std::vector< std::string > & getAxisBindings() const
Returns the axis bindings.
virtual int getNumberOfBins(Axes::Type) const
Returns the number of bins.
double length() const
Returns the length of the range object.
Definition: Range.h:156
virtual void fillColumnAfterCuts(const std::string &column, std::vector< double > &columnData) const
Fill the vector with values from named column with the present set of cuts applied.
hippodraw::AxisModelBase class interface
Part of an implementation of the Observable Observer pattern based on the example implementation in t...
Definition: Observer.h:34
virtual const Range & getRange(Axes::Type) const
Returns the Range along the specified axis.
virtual void normalizeTo(const ProjectorBase *target)
Sets the target of normalization.
AxisModelBase * m_y_axis
The AxisModel along the Y axis.
Definition: ProjectorBase.h:92
virtual bool hasDataSourceBindings() const
Returns true if projector has binding to a DataSource.
virtual void update(const Observable *)
Implements the Observer pattern.
A concreate implementation of the FunctionHelper class.
A transform that transforms coordinates from one coordinate system to another.
Definition: TransformBase.h:35
virtual void notifyObservers() const
Notifies Observer objects of a change.
Definition: Observable.cxx:93
virtual bool wantsScaleFactor(const std::string &axis) const
Returns whether the projector wants scale factor.
virtual void setDirty(bool value=true)
Sets the dirty flag to value.
A DataSource class implemented with std::vector to store the column data. ...
Definition: NTuple.h:33
double low() const
Returns the minimum of the range object.
Definition: Range.cxx:87
virtual bool isAxisBinned(const std::string &axis) const
Returns true if specified axis is binned.
virtual bool isImageConvertable() const
Returns true if the projected values can converted to an image.
virtual double getOffset(Axes::Type axis) const
Returns the offset of the axis.
const std::vector< std::string > & getPointReps() const
Return the vector of Point Reps.
A transform that transforms coordinates from one 2D coordinate system to another. ...
const std::vector< double > & getZValues()
Return all Z values.
virtual double getBinWidth(Axes::Type axis) const
Returns the bin width of the axis.
virtual double getAverage(Axes::Type axis) const
Get the Average of all projected values on the specified axis.
virtual const std::vector< double > & getColumn(const std::string &name) const
Returns the data in the column with label name.
Definition: DataSource.cxx:243
hippodraw::DataSource class interface.
virtual void setAxisModel(Axes::Type axis, AxisModelBase *)
Sets the AxisModel for axis axis.
bool m_isDirty
Marks the object as dirty.
Definition: ProjectorBase.h:65
virtual void setNormalizing(bool on)
Sets the scaling number of entries on if on is true, otherwise turns if off.
std::string m_z_label
Dummy member so that getZLabel can return a reference.
Namespace for HippoDraw.
Definition: AxesType.cxx:21
Type
Axes constants.
Definition: AxesType.h:31
virtual Range dataRangeOn(Axes::Type) const =0
Returns the range of the raw data.
Base class for DataSource.
Definition: DataSource.h:55
virtual void addValues(const std::vector< double > &v)
Add values to the projection.
ProjectorBase()
The default constructor.
Part of an implementation of the Observable-Observer pattern based on the example in the GOF Patterns...
Definition: Observable.h:39
virtual void reset()
Resets the bins.
DataSource * m_proj_values
The NTuple representing the result of the projection.
Definition: ProjectorBase.h:80
virtual void prepareValues()
Informs the projector to prepare its projected values for plotting.
virtual void setAxisBinding(const std::string &axis, const std::string &label)
Sets the axis binding.
virtual double getZValue(double x, double y) const
Get the z value at the specified point (x,y).
virtual void setAxisBindings(const std::vector< std::string > &bindings)
Sets the axis binding.
virtual double stdCoord() const
Returns the standard deviation of the coordinates along the X axis in the data set.
virtual NTuple * createNTupleWith(const std::vector< TupleCut > &cut_list) const
Creates a NTuple from the projector's DataSource object using cut_list for not including rows that do...
const Range & getRange(bool scaled) const
Returns the range represented by this AxisModel.
void setLow(double x)
Sets the minimum of the range object.
Definition: Range.cxx:93
virtual double getRMS(Axes::Type axis)
Returns the RMS.
virtual bool inverseTransform(double &x, double &y) const =0
Transform the transformed coordinates on X and Y axis back to the original true data space...
virtual Range preferredRange(Axes::Type) const
Returns the preferred Range.
virtual AxisModelBase * getAxisModel(Axes::Type axis) const
Get the AxisModel for axis axis.
virtual const Range & setBinWidth(Axes::Type axis, double width)
Sets the bin width.
virtual void setNumberOfBins(Axes::Type axis, unsigned int number)
Sets the number of bins.
virtual int indexOf(const std::string &label) const
Returns the index of the label.
std::vector< intptr_t > shape(numeric::array arr)
Definition: num_util.cpp:317
virtual void setMinEntries(int entries)
Set the minimum entries/bin.
STL namespace.
const std::vector< unsigned int > & getShape()
Get the shape of the projected values.
The AxisModelBase class maintains the Range and scaling of an axis.
Definition: AxisModelBase.h:33
virtual ~ProjectorBase()
The virtual destructor.
virtual const DataSource * createOldStyleNTuple() const
virtual const std::string & getZLabel() const
Finds the Z axis label of the plot.
bool isDirty() const
Returns true if the projector has been marked dirty.
Expresses a range of values.
Definition: Range.h:33
ProjectorHelper class interface.
The base class for the Projector hierarchy.
Definition: ProjectorBase.h:56
hippodraw::ProjectorBase class interface.

Generated for HippoDraw Class Library by doxygen