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

SymbolPointRep.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 "SymbolPointRep.h"
00018 
00019 #include "ErrorBarRep.h"
00020 
00021 #include "datasrcs/DataPointTuple.h"
00022 #include "datasrcs/DataSource.h"
00023 #include "graphics/ViewBase.h"
00024 
00025 #include "projectors/NTupleProjector.h"
00026 #include "transforms/PeriodicBinaryTransform.h"
00027 
00028 #include <cassert>
00029 #include <cmath>
00030 
00031 using namespace hippodraw;
00032 
00033 using std::string;
00034 using std::vector;
00035 
00036 SymbolPointRep::
00037 SymbolPointRep ( hippodraw::Symbol::Type symbol, float size )
00038   : PointRepBase ( "Symbol", size ),
00039     m_plot_symbol( symbol )
00040 {
00041   m_error_rep = new ErrorBarRep();
00042 }
00043 
00044 SymbolPointRep::SymbolPointRep ( )
00045   : PointRepBase ( "Symbol", 2.0 ),
00046     m_plot_symbol( Symbol::SOLIDSQUARE )
00047 {
00048   m_error_rep = new ErrorBarRep();
00049 }
00050 
00051 SymbolPointRep::SymbolPointRep ( const SymbolPointRep & point_rep )
00052   : PointRepBase( point_rep ), 
00053   m_x( point_rep.m_x ),
00054   m_y( point_rep.m_y ),
00055   m_x_flag( point_rep.m_x_flag ),
00056   m_y_flag( point_rep.m_y_flag ),
00057   m_plot_symbol( point_rep.m_plot_symbol )
00058 {
00059   RepBase * clone = point_rep.m_error_rep->clone();
00060   m_error_rep = dynamic_cast< ErrorBarRep * > ( clone );
00061 }
00062 
00063 SymbolPointRep::~SymbolPointRep()
00064 {
00065   delete m_error_rep;
00066 }
00067 
00068 RepBase * SymbolPointRep::clone()
00069 {
00070   return new SymbolPointRep( *this );
00071 }
00072 
00073 void SymbolPointRep::setColor ( const Color & color )
00074 {
00075   RepBase::setColor ( color );
00076 
00077   if ( m_error_rep ) {
00078     m_error_rep->setColor ( color );
00079   }
00080 }
00081 
00082 void SymbolPointRep::setStyle ( unsigned int symbol )
00083 {
00084   m_plot_symbol = Symbol::convert ( symbol );
00085 }
00086 
00087 unsigned int
00088 SymbolPointRep::
00089 getStyle ( ) const
00090 {
00091   return m_plot_symbol;
00092 }
00093 
00094 void
00095 SymbolPointRep::
00096 setErrorOn ( const std::string & axis, bool flag )
00097 {
00098   if ( axis == "x" || axis == "X" ) {
00099     m_error_rep->setXError ( flag );
00100     m_x_flag = flag;
00101   }
00102   if ( axis == "y" || axis == "Y" ) {
00103     m_error_rep->setYError ( flag );
00104     m_y_flag = flag;
00105   }
00106 }
00107 
00108 bool SymbolPointRep::xError () const
00109 {
00110   return m_x_flag;
00111 }
00112 
00113 bool SymbolPointRep::yError () const
00114 {
00115   return m_y_flag;
00116 }
00117 
00118 void SymbolPointRep::transformPoints ( const TransformBase & tb,
00119                                        ViewBase & vb )
00120 {
00121   try {
00122     const BinaryTransform & tf 
00123       = dynamic_cast < const BinaryTransform & > ( tb );
00124 
00125     tf.transform ( m_x, m_y );
00126   }
00127   catch ( ... ) {
00128     assert ( false );
00129   }
00130 }
00131 
00132 void 
00133 SymbolPointRep::
00134 rotate ( double & lat, double & lon,
00135          double alpha, double beta, double gamma )
00136 {
00137   // convert to radians from degrees
00138   lat = M_PI * lat / 180.0; 
00139   lon = M_PI * lon / 180.0;
00140   alpha = M_PI * alpha / 180.0;
00141   beta  = M_PI * beta  / 180.0;
00142   gamma = M_PI * gamma / 180.0; 
00143     
00144   // Convert the latitude and longitudes into the cartesian coordinates
00145   // Assume a unit sphere ( Radii does not matter in rotation )
00146   double x = cos( lat ) * cos( lon );
00147   double y = sin( lat ) * cos( lon );
00148   double z = sin( lon );
00149   
00150   // First give a rotation about the x axis ( conventionally denoted by alpha )
00151   double rx =   x;
00152   double ry =   y * cos( alpha ) + z * sin( alpha );
00153   double rz = - y * sin( alpha ) + z * cos( alpha );
00154   
00155   x = rx; y = ry; z = rz;
00156   
00157   // Now give a rotation about the y axis ( conventionally denoted by beta )
00158   rx =   x * cos( beta ) - z * sin( beta );
00159   ry =   y;
00160   rz =   x * sin( beta ) + z * cos( beta );
00161   
00162   x = rx; y = ry; z = rz;
00163   
00164   // Now give a rotation about the z axis ( conventionally denoted by gamma )
00165   rx =   x * cos( gamma ) + y * sin( gamma );
00166   ry = - x * sin( gamma ) + y * cos( gamma );
00167   rz =   z;
00168   
00169   x = rx; y = ry; z = rz;
00170   
00171   // Convert back to latitude and longitudes ( in degrees )
00172   lon = ( 180.0 / M_PI ) * asin( z );
00173   lat = ( 180.0 / M_PI ) * atan2( y, x );
00174   
00175 }
00176 
00177 namespace dp = hippodraw::DataPoint2DTuple;
00178 
00181 void
00182 SymbolPointRep::
00183 drawProjectedValues ( const DataSource * ntuple,
00184                       TransformBase * transform,
00185                       ViewBase * view )
00186 {
00187   unsigned int size = ntuple -> rows ();
00188   if ( size == 0 ) return;
00189 
00190   const BinaryTransform * tf 
00191     = dynamic_cast < BinaryTransform * > ( transform );
00192   assert ( tf != 0 );
00193   beginPlot ( size, tf, view );
00194 
00195   for ( unsigned int i = 0; i < size; i++ ) {
00196     drawProjectedValue ( i, ntuple, tf, view );
00197   }  
00198 
00199   const Color & cur_color = color ();
00200   view -> drawPoints ( m_x, m_y, m_plot_symbol, m_size, cur_color );
00201 
00202   if ( m_x_flag || m_y_flag ) {
00203     m_error_rep -> drawProjectedValues ( ntuple, transform, view );
00204   }
00205 }
00206 
00207 void
00208 SymbolPointRep::
00209 beginPlot ( unsigned int size,
00210             const BinaryTransform * tf, 
00211             const ViewBase * view )
00212 {
00213   m_x.clear ();
00214   m_y.clear ();
00215 
00216   m_x.reserve ( size );
00217   m_y.reserve ( size );
00218 
00219   c_x_range = view -> getRange ( Axes::X );
00220   c_y_range = view -> getRange ( Axes::Y );
00221 
00222   if ( tf -> isPeriodic () ) {
00223     c_periodic_tf = dynamic_cast < const PeriodicBinaryTransform * > ( tf );
00224     c_beta = c_periodic_tf -> xOffset ();
00225     c_gamma = c_periodic_tf -> yOffset ();
00226   }
00227 }
00228 
00229 bool
00230 SymbolPointRep::
00231 drawProjectedValue ( unsigned int i, 
00232                      const DataSource * ntuple, 
00233                      const BinaryTransform * tf, 
00234                      ViewBase * view )
00235 {
00236   bool retval = false;
00237 
00238   const vector < double > & row = ntuple -> getRow ( i );
00239   double x = row [ dp::X ];
00240   double y = row [ dp::Y ];
00241 
00242   double xtemp = x;
00243   double ytemp = y;
00244 
00245   if ( tf -> isPeriodic() )
00246     {
00247       xtemp = c_periodic_tf  -> moduloSubX ( x, c_beta );
00248       ytemp = c_periodic_tf  -> moduloSubY ( y, c_gamma );
00249       
00250       rotate ( x, y, 0.0, c_beta, c_gamma );
00251     }
00252 
00253   const Range & xrange = view -> getRange ( Axes::X );
00254   const Range & yrange = view -> getRange ( Axes::Y );
00255 
00256   if ( xrange.includes ( xtemp ) && 
00257        yrange.includes ( ytemp ) ) 
00258     {
00259       tf -> transform( x, y );
00260       m_x.push_back ( x );
00261       m_y.push_back ( y );
00262       retval = true;
00263     }
00264 
00265   return retval;
00266 }

Generated for HippoDraw-1.14.8.5 by doxygen 1.4.3