00001
00012 #ifdef _MSC_VER
00013
00014 #include "msdevstudio/MSconfig.h"
00015 #endif //_MSC_VER
00016
00017 #include "Profile2DProjector.h"
00018
00019 #include "axes/AxisModelBase.h"
00020
00021 #include "binners/BinsBase.h"
00022 #include "binners/BinsFactory.h"
00023 #include "binners/BinnerAxis.h"
00024 #include "binners/BinnerAxisFactory.h"
00025
00026 #include "datasrcs/DataPointTuple.h"
00027 #include "datasrcs/NTuple.h"
00028
00029 #include <cassert>
00030
00031 using namespace hippodraw;
00032
00033 using std::list;
00034 using std::max;
00035 using std::string;
00036 using std::vector;
00037
00038 Profile2DProjector::Profile2DProjector( )
00039 : BinningProjector ( 2 ),
00040 NTupleProjector ( 3 )
00041 {
00042 m_binding_options.push_back ( "X" );
00043 m_binding_options.push_back ( "Y" );
00044 m_binding_options.push_back ( "Z" );
00045 m_min_bindings = 3;
00046
00047 BinnerAxisFactory * binner_factory = BinnerAxisFactory::instance();
00048 BinnerAxis * x = binner_factory -> create ( "BinnerLinear" );
00049 BinnerAxis * y = binner_factory -> create ( "BinnerLinear" );
00050
00051 BinsFactory * factory = BinsFactory::instance();
00052 m_binner = factory->create ( "Bins2DProfile" );
00053
00054 m_binner->setBinnerOn ( x, Axes::X );
00055 m_binner->setBinnerOn ( y, Axes::Y );
00056 addPointReps();
00057 }
00058
00059 Profile2DProjector::Profile2DProjector( const Profile2DProjector & projector )
00060 : BinningProjector ( projector ),
00061 NTupleProjector ( projector ),
00062 m_value_range( projector.m_value_range )
00063 {
00064 addPointReps();
00065 }
00066
00067 Profile2DProjector::~Profile2DProjector()
00068 {
00069 }
00070
00071 ProjectorBase * Profile2DProjector::clone()
00072 {
00073 return new Profile2DProjector( *this );
00074 }
00075
00076 void Profile2DProjector::changedNTuple()
00077 {
00078 unsigned int cols = m_ntuple->columns () - 1;
00079 if ( m_columns[0] > cols ) m_columns[0] = cols;
00080 if ( m_columns[1] > cols ) m_columns[1] = cols;
00081 if ( m_columns[2] > cols ) m_columns[2] = cols;
00082
00083 m_binner->setDirty();
00084 }
00085
00087 void Profile2DProjector::execute()
00088 {
00089 if ( m_ntuple->isNull () ) return;
00090
00091 unsigned int ix = m_columns[0];
00092 unsigned int iy = m_columns[1];
00093 unsigned int iz = m_columns[2];
00094 unsigned int iw = m_columns[3];
00095
00096 bool have_weight = false;
00097
00098
00099
00100
00101
00102
00103
00104
00105 m_binner->reset();
00106 unsigned int size = m_ntuple -> rows ();
00107 for ( unsigned int i = 0; i < size; i++ )
00108 {
00109 if ( acceptRow ( i ) == false ) continue;
00110
00111 double x = m_ntuple -> valueAt ( i, ix );
00112 double y = m_ntuple -> valueAt ( i, iy );
00113 double z = m_ntuple -> valueAt ( i, iz );
00114
00115 double w = 1.0;
00116 if ( have_weight ) {
00117 w = m_ntuple -> valueAt ( i, iw );
00118 }
00119 m_binner->accumulate( x, y, z, w );
00120 }
00121 }
00122
00123
00124 bool Profile2DProjector::isAxisBinned ( const std::string & axis ) const
00125 {
00126 if ( axis == m_binding_options[0]
00127 || axis == m_binding_options[1] ) return true;
00128 return false;
00129 }
00130
00131 Range Profile2DProjector::valueRange() const
00132 {
00133 if ( isDirty () ) {
00134
00135 Profile2DProjector * p = const_cast <Profile2DProjector *> ( this );
00136 p->prepareValues ();
00137 }
00138
00139 return dataRangeOn ( Axes::Z );
00140 }
00141
00142 namespace dp = hippodraw::DataPoint3DTuple;
00143
00144 Range
00145 Profile2DProjector::
00146 dataRangeOn ( hippodraw::Axes::Type axis ) const
00147 {
00148 assert ( axis == Axes::X || axis == Axes::Y || axis == Axes::Z );
00149 if ( axis == Axes::X ) {
00150 return dataRange ( m_columns[0] );
00151 }
00152 if ( axis == Axes::Y ) {
00153 return dataRange ( m_columns[1] );
00154 }
00155
00156 if ( isDirty () ) {
00157 Profile2DProjector * p = const_cast < Profile2DProjector * > ( this );
00158 p ->prepareValues ();
00159 p -> setDirty ( false );
00160 }
00161 const vector < double > & values = m_proj_values -> getColumn ( dp::Z );
00162
00163 return Range ( values );
00164 }
00165
00168 double
00169 Profile2DProjector::
00170 getPosOn ( hippodraw::Axes::Type axis ) const
00171 {
00172 assert ( axis == Axes::X || axis == Axes::Y || axis == Axes::Z );
00173 if ( axis == Axes::X ) {
00174 return getPos ( m_columns[0] );
00175 }
00176 if ( axis == Axes::Y ) {
00177 return getPos ( m_columns[1] );
00178 }
00179 if ( axis == Axes::Z ) {
00180 return getPos ( m_columns[2] );
00181 }
00182 return DBL_MAX;
00183 }
00184
00186 void
00187 Profile2DProjector::
00188 setRange ( hippodraw::Axes::Type axis, bool const_width )
00189 {
00190 assert ( axis == Axes::X || axis == Axes::Y || axis == Axes::Z );
00191
00192 AxisModelBase * model = 0;
00193 if ( axis == Axes::X ) {
00194 model = m_x_axis;
00195 } else if ( axis == Axes::Y ) {
00196 model = m_y_axis;
00197 }
00198
00199 if ( axis != Axes::Z ) {
00200 const Range & range = model->getRange (false);
00201 if( model->isLog() ) {
00202 if ( range.low() < 0.0 ) return;
00203 model->setRange ( range.low(), range.high(), getPosOn ( Axes::X ) );
00204 const Range & range2 = model->getRange ( false );
00205 setBinnerRange ( axis, range2, const_width );
00206 } else {
00207 setBinnerRange ( axis, range, const_width );
00208 }
00209 }
00210
00211 setDirty ( true );
00212 }
00213
00215 void
00216 Profile2DProjector::
00217 setBinWidth ( hippodraw::Axes::Type axis, double width )
00218 {
00219 if( axis == Axes::Z ) return;
00220 assert ( axis == Axes::X || axis == Axes::Y );
00221
00222 m_binner->setBinWidth ( axis, width );
00223
00224 setDirty ( true );
00225 }
00226
00230 void Profile2DProjector::setBinWidth ( const std::string & axis,
00231 int parm,
00232 bool dragging )
00233 {
00234 if ( axis != "X" &&
00235 axis != "Y" ) return;
00236
00237 double new_width = m_binner->calcBinWidth ( axis, parm, dragging );
00238
00239 if ( axis == "X" ) {
00240 setBinWidth ( Axes::X, new_width );
00241 return;
00242 }
00243 if ( axis == "Y" ) {
00244 setBinWidth ( Axes::Y, new_width );
00245 return;
00246 }
00247 }
00248
00253 void Profile2DProjector::setOffset ( const std::string & axis,
00254 int parm,
00255 bool dragging )
00256 {
00257 if ( ( axis == "X" || axis == "Y" ) == false ) return;
00258
00259 double new_offset = m_binner->calcOffset ( axis, parm, dragging );
00260
00261 Axes::Type at;
00262 if ( axis == "X" ) {
00263 at = Axes::X;
00264 }
00265 else {
00266 at = Axes::Y;
00267 }
00268
00269 if( new_offset == 0.0 ) return;
00270 if( !dragging )
00271 setOffset( at, 0.0 );
00272 else
00273 setOffset( at, new_offset );
00274
00275 setDirty ( true );
00276 }
00277
00278
00279 void
00280 Profile2DProjector::
00281 setOffset ( hippodraw::Axes::Type axis, double offset )
00282 {
00283 if( axis == Axes::Z ) return;
00284 assert ( axis == Axes::X || axis == Axes::Y );
00285
00286 m_binner->setOffset ( axis, offset );
00287 if( axis == Axes::X )
00288 m_x_axis->setRange( m_binner->getRange ( Axes::X ), true );
00289 else
00290 m_y_axis->setRange( m_binner->getRange ( Axes::Y ), true );
00291
00292 setDirty ( true );
00293 }
00294
00295 const string & Profile2DProjector::getZLabel() const
00296 {
00297 return m_ntuple->getLabelAt( m_columns[2] );
00298 }
00299
00300 void Profile2DProjector::addPointReps()
00301 {
00302 m_pointreps.push_back ( "ColorBox" );
00303 m_pointreps.push_back ( "Contour" );
00304 }
00305
00306 void
00307 Profile2DProjector::
00308 setBinnerRange ( hippodraw::Axes::Type axis,
00309 const Range & range, bool const_width )
00310 {
00311 m_binner -> setRange ( axis, range, const_width );
00312 checkScaling ();
00313
00314 setDirty ( true );
00315 }
00316
00317 void
00318 Profile2DProjector::
00319 update ( const Observable * object )
00320 {
00321 const DataSource * datasource
00322 = dynamic_cast < const DataSource * > ( object );
00323
00324 if ( datasource != 0 ) {
00325 NTupleProjector::update ( object );
00326 }
00327 else {
00328 BinningProjector::update ( object );
00329 }
00330 }
00331
00332 void
00333 Profile2DProjector::
00334 willDelete ( const Observable * object )
00335 {
00336 const DataSource * datasource
00337 = dynamic_cast < const DataSource * > ( object );
00338
00339 if ( datasource != 0 ) {
00340 NTupleProjector::willDelete ( object );
00341 }
00342 else {
00343 BinningProjector::willDelete ( object );
00344 }
00345 }