Map3Projector.cxx
Go to the documentation of this file.
1 
12 #ifdef _MSC_VER
13 // Include max() and min() missing from Microsoft Visual C++.
14 #include "msdevstudio/MSconfig.h"
15 #include <math.h>
16 #endif //_MSC_VER
17 
18 #include "Map3Projector.h"
19 
20 #include "axes/AxisModelBase.h"
21 
23 #include "datasrcs/NTuple.h"
24 
25 #include <algorithm>
26 
27 #include <cmath>
28 
29 #include <cassert>
30 
31 using namespace hippodraw;
32 
33 #ifdef ITERATOR_MEMBER_DEFECT
34 using namespace std;
35 #else
36 using std::abs;
37 using std::max;
38 using std::max_element;
39 using std::min;
40 using std::min_element;
41 using std::string;
42 using std::vector;
43 #endif
44 
46  : NTupleProjector ( 3 )
47 {
48  m_binding_options.push_back ( "X" );
49  m_binding_options.push_back ( "Y" );
50  m_binding_options.push_back ( "Z" );
51  m_min_bindings = 3;
52  addPointReps();
53 }
54 
60 Map3Projector ( const Map3Projector & projector )
61  : ProjectorBase ( projector ),
62  NTupleProjector( projector )
63 {
64  addPointReps();
65 }
66 
68 {
69  return new Map3Projector( *this );
70 }
71 
73 {
74  unsigned int cols = m_ntuple->columns () - 1;
75 
76  if ( m_columns[0] > cols ) m_columns[0] = cols;
77  if ( m_columns[1] > cols ) m_columns[1] = cols;
78  if ( m_columns[2] > cols ) m_columns[2] = cols;
79 }
80 
86 {
87  Range range = dataRange ( m_columns[2] );
88 
89  return range;
90 }
91 
92 Range
95 {
96  assert ( axis == Axes::X || axis == Axes::Y || axis == Axes::Z );
97 
98  unsigned int index = 0;
99  if ( axis == Axes::Y ) index = 1;
100  if ( axis == Axes::Z ) index = 2;
101 
102  return dataRange ( m_columns[index] );
103 
104 }
105 
106 double
109 {
110  assert ( axis == Axes::X || axis == Axes::Y || axis == Axes::Z );
111 
112  unsigned int index = 0;
113  if ( axis == Axes::Y ) index = 1;
114  if ( axis == Axes::Z ) index = 2;
115 
116  return getPos ( m_columns[index] );
117 
118 }
119 
120 const string & Map3Projector::getZLabel () const
121 {
122  return m_ntuple->getLabelAt ( m_columns[2] );
123 }
124 
125 namespace dp = hippodraw::DataPoint3DTuple;
126 
132 double Map3Projector::getZValue ( double x, double y ) const
133 {
134 
135  double retval = 0;
136 
137  const Range & xr = m_x_axis->getRange ( true );
138  const Range & yr = m_y_axis->getRange ( true );
139 
140  double xe = xr.length() * 0.01;
141  double ye = yr.length() * 0.01;
142 
143  const vector < double > & xs = m_proj_values -> getColumn ( dp::X );
144  const vector < double > & ys = m_proj_values -> getColumn ( dp::Y );
145  const vector < double > & zs = m_proj_values -> getColumn ( dp::Z );
146  unsigned int size = xs.size();
147  for ( unsigned int i = 0; i < size; i++ ) {
148  if ( abs ( x - xs[i] ) < xe &&
149  abs ( y - ys[i] ) < ye ) retval = zs[i]; // last one
150  }
151 
152  return retval;
153 }
154 
156 {
157  m_pointreps.push_back ( "ColorSymbol" );
158 }
159 
160 DataSource *
162 createNTuple () const
163 {
164  unsigned int ix = m_columns [ 0 ];
165  unsigned int iy = m_columns [ 1 ];
166  unsigned int iz = m_columns [ 2 ];
167 
168  unsigned int columns = 3;
169  NTuple * ntuple = new NTuple ( columns );
170  vector < string > labels;
171  labels.push_back ( m_ntuple -> getLabelAt ( ix ) );
172  labels.push_back ( m_ntuple -> getLabelAt ( iy ) );
173  labels.push_back ( m_ntuple -> getLabelAt ( iz ) );
174  ntuple -> setLabels ( labels );
175 
176  fillProjectedValues ( ntuple );
177 
178  return ntuple;
179 }
180 
181 void
183 fillProjectedValues ( DataSource * ntuple, bool in_range ) const
184 {
185  ntuple -> clear ();
186 
187  unsigned int size = m_ntuple -> rows ();
188  ntuple -> reserve ( size );
189  vector < double > row ( 3 ); // an exception, no errors
190 
191  unsigned int ix = m_columns [ 0 ];
192  unsigned int iy = m_columns [ 1 ];
193  unsigned int iz = m_columns [ 2 ];
194 
195  for ( unsigned int i = 0; i < size; i++ ) {
196  if ( acceptRow ( i, m_cut_list ) == false ||
197  ( in_range == true && inRange ( i ) == false ) ) continue;
198 
199  row[dp::X] = m_ntuple -> valueAt ( i, ix );
200  row[dp::Y] = m_ntuple -> valueAt ( i, iy );
201  row[dp::Z] = m_ntuple -> valueAt ( i, iz );
202 
203  ntuple -> addRow ( row );
204  }
205 }
206 
207 void
210 {
211  if ( m_proj_values == 0 ) {
213  }
214  else {
216  }
217 
218  setDirty ( false );
219 }
AxisModelBase * m_x_axis
The AxisModel along the X axis.
Definition: ProjectorBase.h:88
Map3Projector()
This default constructor binds to the first three columns.
A namespace to set the standard for indexing into 2 dimension data point tuple.
ProjectorBase * clone()
The clone function returns an object of its own kind which is a copy of this object at this moment...
virtual void prepareValues()
Informs the projector to prepare its projected values for plotting.
bool acceptRow(unsigned int i, const CutList_t &cut_list) const
For row i of the column in the DataSource, returns true if all the cuts accept the row...
unsigned int m_min_bindings
The minimum number of columns that must be bound.
virtual const std::string & getLabelAt(unsigned int index) const
Returns the label for the column at index index.
Definition: DataSource.cxx:179
hippodraw::AxisModelBase class interface
std::vector< std::string > m_binding_options
The list of binding options for the Projector.
Type
Axes constants.
Definition: AxesType.h:31
DataSource * m_proj_values
The NTuple representing the result of the projection.
Definition: ProjectorBase.h:80
virtual bool inRange(int row) const
Checks if the entries in a given row are within the range of the axis model.
std::vector< std::string > m_pointreps
Vector of acceptable PointReps.
unsigned int columns() const
Returns the number of columns or data arrays available from this DataSource.
Definition: DataSource.h:458
Namespace for HippoDraw.
Definition: AxesType.cxx:21
const DataSource * m_ntuple
The pointer to the data source being projected.
double getPos(int column) const
Returns the minimum positive value on the specified column.
double length() const
Returns the length of the range object.
Definition: Range.h:156
AxisModelBase * m_y_axis
The AxisModel along the Y axis.
Definition: ProjectorBase.h:92
virtual void changedNTuple()
This function is called when the ntuple has been changed to a new one.
virtual DataSource * createNTuple() const
Creates an NTuple representation of the projected values.
hippodraw::NTuple class interface.
Base class for DataSource.
Definition: DataSource.h:55
intp size(numeric::array arr)
Definition: num_util.cpp:296
hippodraw::Map3Projector class interface
virtual double getZValue(double x, double y) const
Get the z value at the specified point (x,y).
A DataSource class implemented with std::vector<double> to store the column data. ...
Definition: NTuple.h:33
virtual void addPointReps()
Function to add the acceptable point reps.
STL namespace.
Expresses a range of values.
Definition: Range.h:33
The base class for the Projector hierarchy.
Definition: ProjectorBase.h:56
An NTupleProjector is a projector that projects data from an DataSource object.
const std::string & getZLabel() const
Returns the label (title) of the z axis.
CutList_t m_cut_list
A list of cuts that filter the projection.
hippodraw::DataPointTuple namespace interface
virtual void fillProjectedValues(DataSource *ntuple, bool in_range=false) const
virtual Range valueRange() const
Finds the range of the projected values.
A namespace to set the standard for indexing into 3 dimension data point tuple.
Range dataRange(int column) const
Returns the range of data on the specified column.
A derived class of NTupleProjector that maps 3 DataSource columns to a 3-dimensional projection...
Definition: Map3Projector.h:30
virtual double getPosOn(hippodraw::Axes::Type axis) const
Returns the minimum positive value of the data on a specified axis.
virtual Range dataRangeOn(hippodraw::Axes::Type) const
Returns the range of the data on the specified axis.
const Range & getRange(bool scaled) const
Returns the range represented by this AxisModel.
virtual void setDirty(bool value=true)
Sets the dirty flag to value.
std::vector< unsigned int > m_columns
A vector containing indexes to the columns of the DataSource.

Generated for HippoDraw Class Library by doxygen