ErrorBarRep.cxx

Go to the documentation of this file.
00001 
00012 #ifdef _MSC_VER
00013 // include max() and min() missing from MicroSoft Visual C++
00014 #include "msdevstudio/MSconfig.h"
00015 #endif //_MSC_VER
00016 
00017 #include "ErrorBarRep.h"
00018 
00019 #include "datasrcs/DataPointTuple.h"
00020 #include "datasrcs/DataSource.h"
00021 #include "graphics/ViewBase.h"
00022 #include "transforms/BinaryTransform.h"
00023 
00024 #include <cassert>
00025 
00026 using std::string;
00027 using std::vector;
00028 
00029 using namespace hippodraw;
00030 
00031 ErrorBarRep::ErrorBarRep ( )
00032   : RepBase ( "ErrorBar", 0 ),
00033     m_x_flag ( false ),
00034     m_y_flag ( false )
00035 {
00036 }
00037 
00038 ErrorBarRep::~ErrorBarRep()
00039 {
00040 }
00041 
00042 RepBase * ErrorBarRep::clone()
00043 {
00044   return new ErrorBarRep( *this );
00045 }
00046 
00047 void ErrorBarRep::setXError ( bool flag )
00048 {
00049   m_x_flag = flag;
00050 }
00051 
00052 void ErrorBarRep::setYError ( bool flag )
00053 {
00054   m_y_flag = flag;
00055 }
00056 
00057 void
00058 ErrorBarRep::
00059 drawXError ( double x, double y, double error,
00060              const TransformBase & tb )
00061 {
00062   try {
00063     const BinaryTransform & t 
00064       = dynamic_cast < const BinaryTransform & > ( tb );
00065 
00066     double bull;
00067 
00068     double thi = m_y_range.high();
00069     double tlo = m_y_range.low();
00070     t.transform( bull, thi );
00071     t.transform( bull, tlo );
00072 
00073     Range new_range( tlo, thi );
00074     m_y_range = new_range;
00075 
00076     double xhi = x + error;
00077     double xlo = x - error;
00078 
00079     t.transform( x, y );
00080     t.transform( xlo, bull );
00081     t.transform( xhi, bull );
00082 
00083     // The line.
00084     m_x_err.push_back ( xhi );
00085     m_y_err.push_back ( y );
00086     m_x_err.push_back ( xlo );
00087     m_y_err.push_back ( y );
00088 
00089   }
00090   catch ( ... ) {
00091     assert ( false );
00092   }
00093 }
00094 
00095 void
00096 ErrorBarRep::
00097 drawYError ( double x, double y, double error,
00098              const TransformBase & tb )
00099 {
00100   try {
00101     const BinaryTransform & t 
00102       = dynamic_cast < const BinaryTransform & > ( tb );
00103 
00104     double bull = 0.0;
00105 
00106     double thi = m_x_range.high();
00107     double tlo = m_x_range.low();
00108     t.transform( thi, bull );
00109     t.transform( tlo, bull );
00110 
00111     Range new_range( tlo, thi );
00112     m_x_range = new_range;
00113 
00114     double yhi = y + error; //0.5 * error;
00115     double ylo = y - error; //0.5 * error;
00116 
00117     t.transform( x, y );
00118     t.transform( bull, ylo );
00119     t.transform( bull, yhi );
00120 
00121     // The line.
00122     m_x_err.push_back ( x );
00123     m_y_err.push_back ( yhi );
00124     m_x_err.push_back ( x );
00125     m_y_err.push_back ( ylo );
00126 
00127   }
00128   catch ( ... ) {
00129     assert ( false );
00130   }
00131 }
00132 namespace dp = hippodraw::DataPoint2DTuple;
00133 
00134 void
00135 ErrorBarRep::
00136 drawProjectedValues ( const DataSource * ntuple,
00137                       TransformBase * transform,
00138                       ViewBase * view )
00139 {
00140   if ( m_x_flag == false &&
00141        m_y_flag == false ) return;
00142 
00143   unsigned int size = ntuple -> rows ();
00144   if ( size == 0 ) return;
00145 
00146   m_x_err.clear ();
00147   m_y_err.clear ();
00148 
00149   unsigned int new_size = 0;
00150   if ( m_x_flag ) {
00151     new_size += 6 * size;
00152   }
00153   if ( m_y_flag ) {
00154     new_size += 6 * size;
00155   }
00156 
00157   m_x_err.reserve ( new_size );
00158   m_y_err.reserve ( new_size );
00159 
00160   getRanges ( view );
00161 
00162   for ( unsigned int i = 0; i < size; i++ ) {
00163     const vector < double > & row = ntuple -> getRow ( i );
00164     double x = row [ dp::X ];
00165     double y = row [ dp::Y ];
00166 
00167     if ( m_x_flag == true ) {
00168       double err = row [ dp::XERR ];
00169       drawXError ( x, y, err, *transform );
00170     }
00171 
00172     if ( m_y_flag == true ) {
00173       double err = row [ dp::YERR ];
00174       drawYError ( x, y, err, *transform );
00175     }
00176   }
00177 
00178   const Rect & user_rect = view -> getUserRect ();
00179   user_rect.makeInBounds ( m_x_err, m_y_err );
00180   const Color & cur_color = color ();
00181 
00182   view -> drawLines ( m_x_err, m_y_err, Line::Solid, cur_color, m_size );
00183 }
00184 
00185 void
00186 ErrorBarRep::
00187 getRanges ( const ViewBase * view )
00188 {
00189   m_x_range = view -> getRange ( Axes::X );
00190   m_y_range = view -> getRange ( Axes::Y );
00191 }

Generated for HippoDraw Class Library by doxygen