Bins1DBase.cxx

Go to the documentation of this file.
00001 
00012 #ifdef _MSC_VER
00013 #include "msdevstudio/MSconfig.h"
00014 #endif
00015 
00016 
00017 #include "Bins1DBase.h"
00018 
00019 #include "datasrcs/DataPointTuple.h"
00020 #include "datasrcs/NTuple.h"
00021 
00022 #include <cassert>
00023 
00024 using std::string;
00025 using std::vector;
00026 
00027 using namespace hippodraw;
00028 
00029 Bins1DBase::Bins1DBase ( const char * name )
00030   : BinsBase ( name ),
00031     binner_axis ( 0 )
00032 {
00033 }
00034 
00035 Bins1DBase::Bins1DBase ( const Bins1DBase & binner )
00036   : BinsBase ( binner ),
00037     binner_axis ( 0 )
00038 {
00039   if ( binner.binner_axis != 0 ) {
00040     binner_axis = binner.binner_axis->clone();
00041   }
00042 
00043   m_values_dirty = true;
00044 }
00045 
00046 Bins1DBase::~Bins1DBase ()
00047 {
00048   if ( binner_axis ) delete binner_axis;
00049 }
00050 
00051 int 
00052 Bins1DBase::
00053 getNumberOfAxes () const
00054 {
00055   return 1;
00056 }
00057 const BinnerAxis * 
00058 Bins1DBase::
00059 getBinnerOn ( hippodraw::Axes::Type axis ) const
00060 {
00061   assert ( axis == Axes::X );
00062 
00063   return binner_axis;
00064 }
00065 
00066 void Bins1DBase::setBinnerOn ( BinnerAxis * binner,
00067                                hippodraw::Axes::Type axis )
00068 {
00069   assert ( axis == Axes::X );
00070 
00071   if ( binner_axis ) delete binner_axis;
00072 
00073   binner_axis = binner;
00074   resize ();
00075   m_values_dirty = true;
00076 }
00077 
00078 double Bins1DBase::getLow ( hippodraw::Axes::Type axis ) const
00079 {
00080   assert ( axis == Axes::X );
00081 
00082   return binner_axis->axisGetLow();
00083 }
00084 
00085 double Bins1DBase::getHigh() const
00086 {
00087   return binner_axis->axisGetHigh();
00088 }
00089 
00090 int Bins1DBase::numberOfBins ( hippodraw::Axes::Type axis ) const
00091 {
00092   assert ( axis == Axes::X );
00093 
00094   return binner_axis->axisNumberOfBins();
00095 }
00096 
00097 void Bins1DBase::setNumberOfBins ( hippodraw::Axes::Type axis, int nb )
00098 {
00099   assert ( axis == Axes::X && nb > 0 );
00100 
00101   binner_axis->axisSetNumberOfBins ( nb );
00102 
00103   resize ();
00104 }
00105 
00106 bool
00107 Bins1DBase::hasEqualWidths () const
00108 {
00109   return binner_axis->hasEqualWidths ();
00110 }
00111 
00112 double
00113 Bins1DBase::binWidth ( int i ) const
00114 {
00115   return binner_axis->axisBinWidth(i);
00116 }
00117 
00118 double
00119 Bins1DBase::scaleFactor () const
00120 {
00121   return binner_axis->scaleFactorWid ();
00122 }
00123 
00124 double
00125 Bins1DBase::binWidth ( hippodraw::Axes::Type axis ) const
00126 {
00127   assert ( axis == Axes::X );
00128 
00129   return binner_axis->getConstWid();
00130 }
00131 
00132 const Range &
00133 Bins1DBase::setBinWidth ( hippodraw::Axes::Type axis, double width )
00134 {
00135   assert ( axis == Axes::X && 
00136            width > 0.0 );
00137 
00138   const Range & range =  binner_axis->setBinWidth ( width );
00139   resize ();
00140 
00141   return range;
00142 }
00143 
00144 double
00145 Bins1DBase::
00146 calcBinWidth ( Axes::Type axis, int parm, bool dragging ) const
00147 {
00148   assert ( axis == Axes::X );
00149   double new_width = binner_axis->calcBinWidth ( parm, dragging );
00150 
00151   return new_width;
00152 }
00153 
00154 double
00155 Bins1DBase::calcOffset ( const std::string & axis, 
00156                          int parm, 
00157                          bool dragging ) const
00158 {
00159   assert ( axis == "X" );
00160 
00161   return binner_axis->calcOffset ( parm, dragging );
00162 }
00163 
00164 double
00165 Bins1DBase::getOffset ( hippodraw::Axes::Type axis ) const
00166 {
00167   assert ( axis == Axes::X );
00168   
00169   return binner_axis->getOffset();
00170 }
00171 
00172 void
00173 Bins1DBase::
00174 setOffset ( hippodraw::Axes::Type axis, double offset )
00175 {
00176   assert ( axis == Axes::X );
00177 
00178   binner_axis->setOffset ( offset );
00179 }
00180 
00181 const Range &
00182 Bins1DBase::
00183 setRange ( hippodraw::Axes::Type axis, const Range & range, bool hold_width )
00184 {
00185   assert ( axis == Axes::X );
00186 
00187   const Range & new_range =  binner_axis->setRange ( range, hold_width );
00188   resize ();
00189 
00190   return new_range;
00191 }
00192 
00193 const Range &
00194 Bins1DBase::
00195 getRange ( hippodraw::Axes::Type axis )
00196 {
00197   assert ( axis == Axes::X );
00198 
00199   return binner_axis->getRange();
00200 }
00201 
00202 void Bins1DBase::resize ()
00203 {
00204   int number = numberOfBins ( Axes::X );
00205   resize ( number );
00206 }
00207 
00208 namespace dp = DataPoint2DTuple;
00209 
00210 NTuple *
00211 Bins1DBase::
00212 prepareNTuple ( unsigned int rows ) const
00213 {
00214   unsigned int columns = 4;
00215   NTuple * ntuple = new NTuple ( columns );
00216   ntuple -> reserve ( rows );
00217 
00218   vector < string > labels;
00219   labels.push_back ( "X" );
00220   labels.push_back ( "Value" );
00221   labels.push_back ( dp::WIDTH );
00222   labels.push_back ( dp::ERROR );
00223 
00224   ntuple->setLabels ( labels );
00225 
00226   return ntuple;
00227 }

Generated for HippoDraw Class Library by doxygen