00001
00012 #ifdef _MSC_VER
00013 #include "msdevstudio/MSconfig.h"
00014 #endif
00015
00016 #include "ProjectorBase.h"
00017 #include "ProjectorHelper.h"
00018
00019 #include "axes/AxisModelBase.h"
00020 #include "datasrcs/DataSource.h"
00021 #include "transforms/BinaryTransform.h"
00022
00023
00024 #include <algorithm>
00025
00026 #include <cassert>
00027
00028 #ifdef ITERATOR_MEMBER_DEFECT
00029 using namespace std;
00030 #else
00031 using std::find;
00032 using std::string;
00033 using std::vector;
00034 using std::distance;
00035 #endif
00036
00037 using namespace hippodraw;
00038
00039 ProjectorBase::ProjectorBase ()
00040 : m_isDirty ( true ),
00041 m_proj_values ( 0 ),
00042 m_x_axis ( 0 ),
00043 m_y_axis ( 0 ),
00044 m_z_axis ( 0 )
00045 {
00046 }
00047
00048 ProjectorBase::ProjectorBase ( const ProjectorBase & p )
00049 : Observable (),
00050 Observer (),
00051 m_isDirty ( true ),
00052 m_proj_values ( 0 ),
00053 m_x_axis ( p.m_x_axis ),
00054 m_y_axis ( p.m_y_axis ),
00055 m_z_axis ( p.m_z_axis )
00056 {
00057 }
00058
00059 ProjectorBase::~ProjectorBase ()
00060 {
00061 if ( m_proj_values != 0 ) delete m_proj_values;
00062 }
00063
00064
00065 void ProjectorBase::prepareValues ()
00066 {
00067 setDirty ( false );
00068 }
00069
00070 bool ProjectorBase::isDirty () const
00071 {
00072 return m_isDirty;
00073 }
00074
00075 void ProjectorBase::setDirty ( bool value )
00076 {
00077 m_isDirty = value;
00078
00079 if ( value == true ) notifyObservers ();
00080 }
00081
00082 void
00083 ProjectorBase::
00084 setAxisBinding ( const std::string &,
00085 const std::string & )
00086 {
00087 assert ( false );
00088 }
00089
00090 void
00091 ProjectorBase::
00092 setAxisBindings ( const std::vector < std::string > & )
00093 {
00094 assert ( false );
00095 }
00096
00097 const vector < string > &
00098 ProjectorBase::
00099 getAxisBindings () const
00100 {
00101 assert ( false );
00102 static vector < string > dummy;
00103
00104 return dummy;
00105 }
00106
00107 void
00108 ProjectorBase::
00109 matrixTranspose ( bool )
00110 {
00111
00112 }
00113
00114 int
00115 ProjectorBase::
00116 getNumberOfBins ( hippodraw::Axes::Type ) const
00117 {
00118 return 0;
00119 }
00120
00121 bool ProjectorBase::isAxisBinned ( const std::string & ) const
00122 {
00123 return false;
00124 }
00125
00126 bool ProjectorBase::isValueBinned () const
00127 {
00128 return false;
00129 }
00130
00131 void
00132 ProjectorBase::
00133 setRange ( hippodraw::Axes::Type axis, bool )
00134 {
00135
00136 assert ( axis == Axes::X || axis == Axes::Y || axis == Axes::Z );
00137
00138 if ( axis == Axes::Z ) assert ( m_z_axis != 0 );
00139
00140 setDirty ( true );
00141 }
00142
00143 const Range &
00144 ProjectorBase::
00145 getRange ( hippodraw::Axes::Type axis ) const
00146 {
00147
00148 assert ( axis == Axes::X || axis == Axes::Y || axis == Axes::Z );
00149
00150 if ( axis == Axes::X ) {
00151 return m_x_axis->getRange (false);
00152 }
00153 if ( axis == Axes::Y ) {
00154 return m_y_axis->getRange (false);
00155 }
00156
00157 assert ( m_z_axis != 0 );
00158 return m_z_axis->getRange (false);
00159 }
00160
00161 Range
00162 ProjectorBase::
00163 preferredRange ( hippodraw::Axes::Type axis ) const
00164 {
00165 Range range = dataRangeOn ( axis );
00166
00167 if ( range.length() == 0.0 ) {
00168
00169 double low = range.low ();
00170
00171 if ( axis == Axes::Y &&
00172 low == 0.0 ) {
00173 range.setHigh ( 1.0 );
00174 }
00175 else {
00176 if ( low > 0.0 ) {
00177 range.setLow ( 0.9 * low );
00178 range.setHigh ( 1.1 * low );
00179 }
00180 else {
00181 range.setLow ( 1.1 * low );
00182 range.setHigh ( 0.9 * low );
00183 }
00184 }
00185 }
00186
00187 return range;
00188 }
00189
00190 void
00191 ProjectorBase::
00192 setAxisModel ( hippodraw::Axes::Type axis,
00193 AxisModelBase * axis_model )
00194 {
00195 assert ( axis == Axes::X || axis == Axes::Y || axis == Axes::Z );
00196
00197 if ( axis == Axes::X ) {
00198 m_x_axis = axis_model;
00199 }
00200 if ( axis == Axes::Y ) {
00201 m_y_axis = axis_model;
00202 }
00203
00204 if ( axis == Axes::Z ) {
00205 m_z_axis = axis_model;
00206 }
00207 }
00208
00209 AxisModelBase *
00210 ProjectorBase::
00211 getAxisModel ( hippodraw::Axes::Type axis ) const
00212 {
00213 assert ( axis == Axes::X || axis == Axes::Y || axis == Axes::Z );
00214
00215 if ( axis == Axes::X ) {
00216 return m_x_axis;
00217 }
00218
00219 if ( axis == Axes::Y ) {
00220 return m_y_axis;
00221 }
00222
00223 return m_z_axis;
00224 }
00225
00226 void
00227 ProjectorBase::
00228 setNumberOfBins ( hippodraw::Axes::Type, unsigned int )
00229 {
00230 }
00231
00232 const Range &
00233 ProjectorBase::
00234 setBinWidth ( hippodraw::Axes::Type, double )
00235 {
00236 static Range range ( 0., 1. );
00237 return range;
00238 }
00239
00240 const Range &
00241 ProjectorBase::
00242 setBinWidth ( Axes::Type, int, bool )
00243 {
00244 return m_x_axis -> getRange ( false );
00245
00246 }
00247
00248 void ProjectorBase::setOffset ( const std::string &,
00249 int,
00250 bool )
00251 {
00252 }
00253
00254 void
00255 ProjectorBase::
00256 setOffset ( hippodraw::Axes::Type, double )
00257 {
00258 }
00259
00260 void
00261 ProjectorBase::
00262 reset ( )
00263 {
00264 }
00265
00266 double
00267 ProjectorBase::
00268 getOffset ( hippodraw::Axes::Type ) const
00269 {
00270 return 0.0;
00271 }
00272
00276 double
00277 ProjectorBase::
00278 getAverage ( hippodraw::Axes::Type ) const
00279 {
00280
00281 return 0.0;
00282 }
00283
00287 double
00288 ProjectorBase::
00289 getRMS ( hippodraw::Axes::Type axis )
00290 {
00291 ProjectorHelper helper( getProjectedValues() );
00292
00293 double rms = 0.0;
00294
00295 if ( axis == Axes::X )
00296 rms = helper.stdCoord();
00297
00298 return rms;
00299 }
00300
00302 const std::string & ProjectorBase::getZLabel () const
00303 {
00304 return m_z_label;
00305 }
00306
00307 int
00308 ProjectorBase::
00309 indexOf ( const std::string & label ) const
00310 {
00311 return -1;
00312 }
00313
00314 double
00315 ProjectorBase::
00316 getBinWidth ( hippodraw::Axes::Type ) const
00317 {
00318 return 0.0;
00319 }
00320
00321 double
00322 ProjectorBase::
00323 getZValue ( double, double ) const
00324 {
00325 return 0.0;
00326 }
00327
00328 void
00329 ProjectorBase::
00330 addValues ( const std::vector < double > & )
00331 {
00332
00333 }
00334
00335 const vector <string> & ProjectorBase::getPointReps() const
00336 {
00337 return m_pointreps;
00338 }
00339
00340 NTuple *
00341 ProjectorBase::
00342 getNTupleAfterCuts() const
00343 {
00344 return 0;
00345 }
00346
00347 void
00348 ProjectorBase::
00349 fillColumnAfterCuts(const std::string & column,
00350 std::vector<double> & columnData) const {
00351
00352 }
00353
00354 NTuple *
00355 ProjectorBase::
00356 createNTupleWith ( const std::vector< TupleCut > & cut_list ) const
00357 {
00358 return 0;
00359 }
00360
00361
00362 bool
00363 ProjectorBase::
00364 wantsScaleFactor ( const std::string & ) const
00365 {
00366 return false;
00367 }
00368
00369 const DataSource *
00370 ProjectorBase::
00371 getProjectedValues () const
00372 {
00373 return m_proj_values;
00374 }
00375
00376 const DataSource *
00377 ProjectorBase::
00378 createOldStyleNTuple () const
00379 {
00380 ProjectorBase * projector = const_cast < ProjectorBase * > ( this );
00381 projector -> prepareValues ();
00382
00383 return getProjectedValues ();
00384 }
00385
00386 void
00387 ProjectorBase::
00388 normalizeTo ( double )
00389 {
00390
00391 }
00392
00393 void
00394 ProjectorBase::
00395 setNormalizing ( bool )
00396 {
00397
00398 }
00399
00400 void
00401 ProjectorBase::
00402 update ( const Observable * )
00403 {
00404
00405 }
00406
00407 void
00408 ProjectorBase::
00409 normalizeTo ( const ProjectorBase * )
00410 {
00411
00412 }
00413
00414 void
00415 ProjectorBase::
00416 checkScaling ()
00417 {
00418
00419 }
00420
00421 const std::vector <double> &
00422 ProjectorBase::
00423 getZValues()
00424 {
00425 const DataSource * ds = getProjectedValues ();
00426 const std::vector <double> & oldzval = ds->getColumn (2);
00427 const std::vector < unsigned int > & shape = getShape();
00428
00429 unsigned int x = shape[0];
00430 unsigned int y = shape[1];
00431
00432 m_zval.clear();
00433 m_zval.resize ( x*y, 0.0 );
00434
00435 for ( unsigned int yy = 0; yy<y; yy++ )
00436 for ( unsigned int xx = 0; xx<x; xx++ )
00437 m_zval[yy*x+xx] = oldzval[xx*y+yy];
00438
00439 return m_zval;
00440 }
00441
00442 const std::vector < unsigned int> &
00443 ProjectorBase::
00444 getShape()
00445 {
00446 const DataSource * ds = getProjectedValues ();
00447 return ds->getShape ();
00448 }
00449
00454 const std::vector <double> &
00455 ProjectorBase::
00456 getZAfterTransform(TransformBase * transform)
00457 {
00458 const BinaryTransform * bt
00459 = dynamic_cast <const BinaryTransform *>(transform);
00460
00461 m_zval.clear();
00462
00463
00464 if ( bt-> aspectRatio() == 1.0 )
00465 {
00466 for ( unsigned int j = 0; j < 256; j++ )
00467 for ( unsigned int i = 0; i < 256; i++ )
00468 {
00469 double x= static_cast < double > (i)-128;
00470 double y= static_cast < double > (j)-128;
00471 double z;
00472
00473 bool yes = bt->inverseTransform ( x, y );
00474
00475 if ( yes )
00476 {
00477 z = getZValue ( x, y );
00478 }
00479 else
00480 {
00481 z = 0.0;
00482 }
00483
00484 m_zval.push_back(z);
00485 }
00486 }
00487
00488
00489 else
00490 {
00491 for ( unsigned int j = 0; j < 180; j++ )
00492 for ( unsigned int i = 0; i < 360; i++ )
00493 {
00494 double x= static_cast < double > (i)-180;
00495 double y= static_cast < double > (j)-90;
00496 double z;
00497
00498 bool yes = bt->inverseTransform ( x, y );
00499
00500 if ( yes )
00501 {
00502 z = getZValue ( x, y );
00503 }
00504 else
00505 {
00506 z = 0.0;
00507 }
00508
00509 m_zval.push_back(z);
00510 }
00511 }
00512
00513 return (m_zval);
00514 }
00515
00516 bool
00517 ProjectorBase::
00518 hasDataSourceBindings () const
00519 {
00520 return false;
00521 }
00522
00523 void
00524 ProjectorBase::
00525 setMinEntries(int entries)
00526 {
00527 }
00528
00529 int
00530 ProjectorBase::
00531 getMinEntries ()
00532 {
00533 return -1;
00534 }
00535
00536 bool
00537 ProjectorBase::
00538 isImageConvertable () const
00539 {
00540 return false;
00541 }