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