Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

Map3Projector.cxx

Go to the documentation of this file.
00001 
00012 #ifdef _MSC_VER
00013 // Include max() and min() missing from Microsoft Visual C++.
00014 #include "msdevstudio/MSconfig.h"
00015 #include  <math.h>
00016 #endif //_MSC_VER
00017 
00018 #include "Map3Projector.h"
00019 
00020 #include "axes/AxisModelBase.h"
00021 
00022 #include "datasrcs/DataPointTuple.h"
00023 #include "datasrcs/NTuple.h"
00024 
00025 #include <algorithm>
00026 
00027 #include <cmath>
00028 
00029 #include <cassert>
00030 
00031 using namespace hippodraw;
00032 
00033 #ifdef ITERATOR_MEMBER_DEFECT
00034 using namespace std;
00035 #else
00036 using std::abs;
00037 using std::max;
00038 using std::max_element;
00039 using std::min;
00040 using std::min_element;
00041 using std::string;
00042 using std::vector;
00043 #endif
00044 
00045 Map3Projector::Map3Projector( )
00046   : NTupleProjector ( 3 )
00047 {
00048   m_binding_options.push_back ( "X" );
00049   m_binding_options.push_back ( "Y" );
00050   m_binding_options.push_back ( "Z" );
00051   m_min_bindings = 3;
00052   addPointReps();
00053 }
00054 
00055 Map3Projector::Map3Projector( const Map3Projector & projector )
00056   : NTupleProjector( projector )
00057 {
00058   addPointReps();
00059 }
00060 
00061 Map3Projector::~Map3Projector()
00062 {
00063 }
00064 
00065 ProjectorBase * Map3Projector::clone()
00066 {
00067   return new Map3Projector( *this );
00068 }
00069 
00070 void Map3Projector::changedNTuple ()
00071 {
00072   unsigned int cols = m_ntuple->columns () - 1;
00073 
00074   if ( m_columns[0] > cols ) m_columns[0] = cols;
00075   if ( m_columns[1] > cols ) m_columns[1] = cols;
00076   if ( m_columns[2] > cols ) m_columns[2] = cols;
00077 }
00078 
00083 Range Map3Projector::valueRange() const
00084 {
00085   Range range = dataRange ( m_columns[2] );
00086 
00087   return range;
00088 }
00089 
00090 Range
00091 Map3Projector::
00092 dataRangeOn ( hippodraw::Axes::Type axis ) const
00093 {
00094   assert ( axis == Axes::X || axis == Axes::Y || axis == Axes::Z );
00095 
00096   unsigned int index = 0;
00097   if ( axis == Axes::Y ) index = 1;
00098   if ( axis == Axes::Z ) index = 2;
00099 
00100   return dataRange ( m_columns[index] );
00101 
00102 }
00103 
00104 double
00105 Map3Projector::
00106 getPosOn ( hippodraw::Axes::Type axis ) const
00107 {
00108   assert ( axis == Axes::X || axis == Axes::Y || axis == Axes::Z );
00109 
00110   unsigned int index = 0;
00111   if ( axis == Axes::Y ) index = 1;
00112   if ( axis == Axes::Z ) index = 2;
00113 
00114   return getPos ( m_columns[index] );
00115 
00116 }
00117 
00118 const string & Map3Projector::getZLabel () const
00119 {
00120   return m_ntuple->getLabelAt ( m_columns[2] );
00121 }
00122 
00123 namespace dp = hippodraw::DataPoint3DTuple;
00124 
00130 double Map3Projector::getZValue ( double x, double y ) const
00131 {
00132   
00133   double retval = 0;
00134 
00135   const Range & xr = m_x_axis->getRange ( true );
00136   const Range & yr = m_y_axis->getRange ( true );
00137   
00138   double xe = xr.length() * 0.01;
00139   double ye = yr.length() * 0.01;
00140 
00141   const vector < double > & xs = m_proj_values -> getColumn ( dp::X );
00142   const vector < double > & ys = m_proj_values -> getColumn ( dp::Y );
00143   const vector < double > & zs = m_proj_values -> getColumn ( dp::Z );
00144   unsigned int size = xs.size();
00145   for ( unsigned int i = 0; i < size; i++ ) {
00146     if ( abs ( x - xs[i] ) < xe  &&
00147          abs ( y - ys[i] ) < ye      )  retval = zs[i]; // last one
00148   }
00149 
00150   return retval;
00151 }
00152 
00153 void Map3Projector::addPointReps()
00154 {
00155   m_pointreps.push_back ( "ColorSymbol" );
00156 }
00157 
00158 DataSource *
00159 Map3Projector::
00160 createNTuple () const
00161 {
00162   unsigned int ix = m_columns [ 0 ];
00163   unsigned int iy = m_columns [ 1 ];
00164   unsigned int iz = m_columns [ 2 ];
00165 
00166   unsigned int columns = 3;
00167   NTuple * ntuple = new NTuple ( columns );
00168   vector < string > labels;
00169   labels.push_back ( m_ntuple -> getLabelAt ( ix ) );
00170   labels.push_back ( m_ntuple -> getLabelAt ( iy ) );
00171   labels.push_back ( m_ntuple -> getLabelAt ( iz ) );
00172   ntuple -> setLabels ( labels );
00173 
00174   fillProjectedValues ( ntuple );
00175 
00176   return ntuple;
00177 }
00178 
00179 void
00180 Map3Projector::
00181 fillProjectedValues ( DataSource * ntuple, bool in_range ) const
00182 {
00183   ntuple -> clear ();
00184 
00185   unsigned int size = m_ntuple -> rows ();
00186   ntuple -> reserve ( size );
00187   vector < double > row ( 3 ); // an exception, no errors
00188 
00189   unsigned int ix = m_columns [ 0 ];
00190   unsigned int iy = m_columns [ 1 ];
00191   unsigned int iz = m_columns [ 2 ];
00192 
00193   for ( unsigned int i = 0; i < size; i++ ) {
00194     if ( acceptRow ( i ) == false ||
00195          ( in_range == true && inRange ( i ) == false ) ) continue;
00196 
00197     row[dp::X] = m_ntuple -> valueAt ( i, ix );
00198     row[dp::Y] = m_ntuple -> valueAt ( i, iy );
00199     row[dp::Z] = m_ntuple -> valueAt ( i, iz );
00200 
00201     ntuple -> addRow ( row );
00202   }
00203 }
00204 
00205 void
00206 Map3Projector::
00207 fillDataSource ( DataSource * ntuple, bool in_range ) const
00208 {
00209   ntuple -> clear ();
00210 
00211   unsigned int size = m_ntuple -> rows ();
00212   ntuple -> reserve ( size );
00213   vector < double > row ( 3 ); // an exception, no errors
00214 
00215   unsigned int ix = m_columns [ 0 ];
00216   unsigned int iy = m_columns [ 1 ];
00217   unsigned int iz = m_columns [ 2 ];
00218 
00219   for ( unsigned int i = 0; i < size; i++ ) {
00220     if ( acceptRow ( i ) == false ||
00221          ( in_range == true && inRange ( i ) == false ) ) continue;
00222 
00223     row[dp::X] = m_ntuple -> valueAt ( i, ix );
00224     row[dp::Y] = m_ntuple -> valueAt ( i, iy );
00225     row[dp::Z] = m_ntuple -> valueAt ( i, iz );
00226 
00227     ntuple -> addRow ( row );
00228   }
00229 }
00230 
00231 void
00232 Map3Projector::
00233 prepareValues ()
00234 {
00235   if ( m_proj_values == 0 ) {
00236     m_proj_values = createNTuple ();
00237   }
00238   else {
00239     fillProjectedValues ( m_proj_values, true );
00240   }
00241 
00242   setDirty ( false );
00243 }

Generated for HippoDraw-1.14.8.5 by doxygen 1.4.3