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 00059 Map3Projector:: 00060 Map3Projector ( const Map3Projector & projector ) 00061 : ProjectorBase ( projector ), 00062 NTupleProjector( projector ) 00063 { 00064 addPointReps(); 00065 } 00066 00067 ProjectorBase * Map3Projector::clone() 00068 { 00069 return new Map3Projector( *this ); 00070 } 00071 00072 void Map3Projector::changedNTuple () 00073 { 00074 unsigned int cols = m_ntuple->columns () - 1; 00075 00076 if ( m_columns[0] > cols ) m_columns[0] = cols; 00077 if ( m_columns[1] > cols ) m_columns[1] = cols; 00078 if ( m_columns[2] > cols ) m_columns[2] = cols; 00079 } 00080 00085 Range Map3Projector::valueRange() const 00086 { 00087 Range range = dataRange ( m_columns[2] ); 00088 00089 return range; 00090 } 00091 00092 Range 00093 Map3Projector:: 00094 dataRangeOn ( hippodraw::Axes::Type axis ) const 00095 { 00096 assert ( axis == Axes::X || axis == Axes::Y || axis == Axes::Z ); 00097 00098 unsigned int index = 0; 00099 if ( axis == Axes::Y ) index = 1; 00100 if ( axis == Axes::Z ) index = 2; 00101 00102 return dataRange ( m_columns[index] ); 00103 00104 } 00105 00106 double 00107 Map3Projector:: 00108 getPosOn ( hippodraw::Axes::Type axis ) const 00109 { 00110 assert ( axis == Axes::X || axis == Axes::Y || axis == Axes::Z ); 00111 00112 unsigned int index = 0; 00113 if ( axis == Axes::Y ) index = 1; 00114 if ( axis == Axes::Z ) index = 2; 00115 00116 return getPos ( m_columns[index] ); 00117 00118 } 00119 00120 const string & Map3Projector::getZLabel () const 00121 { 00122 return m_ntuple->getLabelAt ( m_columns[2] ); 00123 } 00124 00125 namespace dp = hippodraw::DataPoint3DTuple; 00126 00132 double Map3Projector::getZValue ( double x, double y ) const 00133 { 00134 00135 double retval = 0; 00136 00137 const Range & xr = m_x_axis->getRange ( true ); 00138 const Range & yr = m_y_axis->getRange ( true ); 00139 00140 double xe = xr.length() * 0.01; 00141 double ye = yr.length() * 0.01; 00142 00143 const vector < double > & xs = m_proj_values -> getColumn ( dp::X ); 00144 const vector < double > & ys = m_proj_values -> getColumn ( dp::Y ); 00145 const vector < double > & zs = m_proj_values -> getColumn ( dp::Z ); 00146 unsigned int size = xs.size(); 00147 for ( unsigned int i = 0; i < size; i++ ) { 00148 if ( abs ( x - xs[i] ) < xe && 00149 abs ( y - ys[i] ) < ye ) retval = zs[i]; // last one 00150 } 00151 00152 return retval; 00153 } 00154 00155 void Map3Projector::addPointReps() 00156 { 00157 m_pointreps.push_back ( "ColorSymbol" ); 00158 } 00159 00160 DataSource * 00161 Map3Projector:: 00162 createNTuple () const 00163 { 00164 unsigned int ix = m_columns [ 0 ]; 00165 unsigned int iy = m_columns [ 1 ]; 00166 unsigned int iz = m_columns [ 2 ]; 00167 00168 unsigned int columns = 3; 00169 NTuple * ntuple = new NTuple ( columns ); 00170 vector < string > labels; 00171 labels.push_back ( m_ntuple -> getLabelAt ( ix ) ); 00172 labels.push_back ( m_ntuple -> getLabelAt ( iy ) ); 00173 labels.push_back ( m_ntuple -> getLabelAt ( iz ) ); 00174 ntuple -> setLabels ( labels ); 00175 00176 fillProjectedValues ( ntuple ); 00177 00178 return ntuple; 00179 } 00180 00181 void 00182 Map3Projector:: 00183 fillProjectedValues ( DataSource * ntuple, bool in_range ) const 00184 { 00185 ntuple -> clear (); 00186 00187 unsigned int size = m_ntuple -> rows (); 00188 ntuple -> reserve ( size ); 00189 vector < double > row ( 3 ); // an exception, no errors 00190 00191 unsigned int ix = m_columns [ 0 ]; 00192 unsigned int iy = m_columns [ 1 ]; 00193 unsigned int iz = m_columns [ 2 ]; 00194 00195 for ( unsigned int i = 0; i < size; i++ ) { 00196 if ( acceptRow ( i, m_cut_list ) == false || 00197 ( in_range == true && inRange ( i ) == false ) ) continue; 00198 00199 row[dp::X] = m_ntuple -> valueAt ( i, ix ); 00200 row[dp::Y] = m_ntuple -> valueAt ( i, iy ); 00201 row[dp::Z] = m_ntuple -> valueAt ( i, iz ); 00202 00203 ntuple -> addRow ( row ); 00204 } 00205 } 00206 00207 void 00208 Map3Projector:: 00209 prepareValues () 00210 { 00211 if ( m_proj_values == 0 ) { 00212 m_proj_values = createNTuple (); 00213 } 00214 else { 00215 fillProjectedValues ( m_proj_values, true ); 00216 } 00217 00218 setDirty ( false ); 00219 }