Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

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     m_x_cap ( 0 ),
00036     m_y_cap ( 0 )
00037 {
00038 }
00039 
00040 ErrorBarRep::~ErrorBarRep()
00041 {
00042 }
00043 
00044 RepBase * ErrorBarRep::clone()
00045 {
00046   return new ErrorBarRep( *this );
00047 }
00048 
00049 void ErrorBarRep::setXError ( bool flag )
00050 {
00051   m_x_flag = flag;
00052 }
00053 
00054 void ErrorBarRep::setYError ( bool flag )
00055 {
00056   m_y_flag = flag;
00057 }
00058 
00059 void ErrorBarRep::drawXError ( double x, double y, double error,
00060                                ViewBase & vb, const TransformBase & tb )
00061 {
00062   try {
00063     const BinaryTransform & t 
00064       = dynamic_cast < const BinaryTransform & > ( tb );
00065 
00066     double bull;
00067     if( !m_x_cap ){
00068 
00069       double thi = m_y_range.high();
00070       double tlo = m_y_range.low();
00071       t.transform( bull, thi );
00072       t.transform( bull, tlo );
00073 
00074       Range new_range( tlo, thi );
00075       m_y_range = new_range;
00076       m_x_cap = m_y_range.length() * 0.01;
00077     }
00078 
00079     double xhi = x + error; //0.5 * error;
00080     double xlo = x - error; //0.5 * error;
00081 
00082     t.transform( x, y );
00083     t.transform( xlo, bull );
00084     t.transform( xhi, bull );
00085 
00086     // The line.
00087     m_x_err.push_back ( xhi );
00088     m_y_err.push_back ( y );
00089     m_x_err.push_back ( xlo );
00090     m_y_err.push_back ( y );
00091 
00092     // The right cap.
00093     m_x_err.push_back ( xhi );
00094     m_x_err.push_back ( xhi );
00095     m_y_err.push_back ( y + m_x_cap );
00096     m_y_err.push_back ( y - m_x_cap );
00097 
00098     // The left cap.
00099     m_x_err.push_back ( xlo );
00100     m_x_err.push_back ( xlo );
00101     m_y_err.push_back ( y + m_x_cap );
00102     m_y_err.push_back ( y - m_x_cap );
00103   }
00104   catch ( ... ) {
00105     assert ( false );
00106   }
00107 }
00108 
00114 void ErrorBarRep::drawYError ( double x, double y, double error,
00115                                ViewBase & vb, const TransformBase & tb )
00116 {
00117   try {
00118     const BinaryTransform & t 
00119       = dynamic_cast < const BinaryTransform & > ( tb );
00120 
00121     double bull = 0.0;
00122     if( !m_y_cap ){
00123 
00124       double thi = m_x_range.high();
00125       double tlo = m_x_range.low();
00126       t.transform( thi, bull );
00127       t.transform( tlo, bull );
00128 
00129       Range new_range( tlo, thi );
00130       m_x_range = new_range;
00131       m_y_cap = m_x_range.length() * 0.01;
00132     }
00133 
00134     double yhi = y + error; //0.5 * error;
00135     double ylo = y - error; //0.5 * error;
00136 
00137     t.transform( x, y );
00138     t.transform( bull, ylo );
00139     t.transform( bull, yhi );
00140 
00141     // The line.
00142     m_x_err.push_back ( x );
00143     m_y_err.push_back ( yhi );
00144     m_x_err.push_back ( x );
00145     m_y_err.push_back ( ylo );
00146 
00147     // The top cap.
00148     m_x_err.push_back ( x + m_y_cap );
00149     m_y_err.push_back ( yhi );
00150     m_x_err.push_back ( x - m_y_cap );
00151     m_y_err.push_back ( yhi );
00152 
00153     // The bottom cap.
00154     m_x_err.push_back ( x + m_y_cap );
00155     m_y_err.push_back ( ylo );
00156     m_x_err.push_back ( x - m_y_cap );
00157     m_y_err.push_back ( ylo );
00158   }
00159   catch ( ... ) {
00160     assert ( false );
00161   }
00162 }
00163 namespace dp = hippodraw::DataPoint2DTuple;
00164 
00165 void
00166 ErrorBarRep::
00167 drawProjectedValues ( const DataSource * ntuple,
00168                       TransformBase * transform,
00169                       ViewBase * view )
00170 {
00171   if ( m_x_flag == false &&
00172        m_y_flag == false ) return;
00173 
00174   unsigned int size = ntuple -> rows ();
00175   if ( size == 0 ) return;
00176 
00177   m_x_err.clear ();
00178   m_y_err.clear ();
00179 
00180   unsigned int new_size = 0;
00181   if ( m_x_flag ) {
00182     new_size += 6 * size;
00183   }
00184   if ( m_y_flag ) {
00185     new_size += 6 * size;
00186   }
00187 
00188   m_x_err.reserve ( new_size );
00189   m_y_err.reserve ( new_size );
00190 
00191   getRanges ( ntuple );
00192 
00193   for ( unsigned int i = 0; i < size; i++ ) {
00194     const vector < double > & row = ntuple -> getRow ( i );
00195     double x = row [ dp::X ];
00196     double y = row [ dp::Y ];
00197 
00198     if ( m_x_flag == true ) {
00199       double err = row [ dp::XERR ];
00200       drawXError ( x, y, err, *view, *transform );
00201     }
00202 
00203     if ( m_y_flag == true ) {
00204       double err = row [ dp::YERR ];
00205       drawYError ( x, y, err, *view, *transform );
00206     }
00207   }
00208 
00209   const HippoRectangle & user_rect = view -> getUserRect ();
00210   user_rect.makeInBounds ( m_x_err, m_y_err );
00211 
00212   const Color & cur_color = color ();
00213   view -> drawLines ( m_x_err, m_y_err, Line::Solid, cur_color, m_size );
00214   m_x_cap = m_y_cap = 0;
00215 }
00216 
00217 void
00218 ErrorBarRep::
00219 getRanges ( const DataSource * ntuple )
00220 {
00221   const vector < double > & x = ntuple -> getColumn ( dp::X );
00222   const vector < double > & y = ntuple -> getColumn ( dp::Y );
00223 
00224   m_x_range = Range ( x );
00225   m_y_range = Range ( y );
00226 }

Generated for HippoDraw-1.14.8.5 by doxygen 1.4.3