00001
00012 #ifdef _MSC_VER
00013
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 <cmath>
00029
00030 #include <cassert>
00031
00032 using std::string;
00033 using std::vector;
00034
00035 using namespace hippodraw;
00036
00037 SymbolPointRep::
00038 SymbolPointRep ( hippodraw::Symbol::Type symbol, float size )
00039 : PointRepBase ( "Symbol", size ),
00040 m_plot_symbol( symbol )
00041 {
00042 m_error_rep = new ErrorBarRep();
00043 }
00044
00045 SymbolPointRep::SymbolPointRep ( )
00046 : PointRepBase ( "Symbol", 2.0 ),
00047 m_plot_symbol( Symbol::SOLIDSQUARE )
00048 {
00049 m_error_rep = new ErrorBarRep();
00050 }
00051
00052 SymbolPointRep::SymbolPointRep ( const SymbolPointRep & point_rep )
00053 : PointRepBase( point_rep ),
00054 m_x( point_rep.m_x ),
00055 m_y( point_rep.m_y ),
00056 m_x_flag( point_rep.m_x_flag ),
00057 m_y_flag( point_rep.m_y_flag ),
00058 m_plot_symbol( point_rep.m_plot_symbol )
00059 {
00060 RepBase * clone = point_rep.m_error_rep->clone();
00061 m_error_rep = dynamic_cast< ErrorBarRep * > ( clone );
00062 }
00063
00064 SymbolPointRep::~SymbolPointRep()
00065 {
00066 delete m_error_rep;
00067 }
00068
00069 RepBase * SymbolPointRep::clone()
00070 {
00071 return new SymbolPointRep( *this );
00072 }
00073
00074 void SymbolPointRep::setColor ( const Color & color )
00075 {
00076 RepBase::setColor ( color );
00077
00078 if ( m_error_rep ) {
00079 m_error_rep->setColor ( color );
00080 }
00081 }
00082
00083 void SymbolPointRep::setStyle ( unsigned int symbol )
00084 {
00085 m_plot_symbol = Symbol::convert ( symbol );
00086 }
00087
00088 unsigned int
00089 SymbolPointRep::
00090 getStyle ( ) const
00091 {
00092 return m_plot_symbol;
00093 }
00094
00095 void
00096 SymbolPointRep::
00097 setErrorOn ( Axes::Type axis, bool flag )
00098 {
00099 if ( axis == Axes::X ) {
00100 m_error_rep -> setXError ( flag );
00101 m_x_flag = flag;
00102 }
00103 else if ( axis == Axes::Y ) {
00104 m_error_rep -> setYError ( flag );
00105 m_y_flag = flag;
00106 }
00107 }
00108
00109 bool SymbolPointRep::xError () const
00110 {
00111 return m_x_flag;
00112 }
00113
00114 bool SymbolPointRep::yError () const
00115 {
00116 return m_y_flag;
00117 }
00118
00121 void
00122 SymbolPointRep::
00123 transformPoints ( const TransformBase & tb,
00124 ViewBase & )
00125 {
00126 try {
00127 const BinaryTransform & tf
00128 = dynamic_cast < const BinaryTransform & > ( tb );
00129
00130 tf.transform ( m_x, m_y );
00131 }
00132 catch ( ... ) {
00133 assert ( false );
00134 }
00135 }
00136
00137 void
00138 SymbolPointRep::
00139 rotate ( double & lat, double & lon,
00140 double alpha, double beta, double gamma, bool negative )
00141 {
00142 if ( negative == false ) lat-=180.0;
00143
00144
00145 lat = M_PI * lat / 180.0;
00146 lon = M_PI * lon / 180.0;
00147 alpha = M_PI * alpha / 180.0;
00148 beta = M_PI * beta / 180.0;
00149 gamma = M_PI * gamma / 180.0;
00150
00151
00152
00153 double x = cos( lat ) * cos( lon );
00154 double y = sin( lat ) * cos( lon );
00155 double z = sin( lon );
00156
00157
00158 double rx = x;
00159 double ry = y * cos( alpha ) + z * sin( alpha );
00160 double rz = - y * sin( alpha ) + z * cos( alpha );
00161
00162 x = rx; y = ry; z = rz;
00163
00164
00165 rx = x * cos( beta ) - z * sin( beta );
00166 ry = y;
00167 rz = x * sin( beta ) + z * cos( beta );
00168
00169 x = rx; y = ry; z = rz;
00170
00171
00172 rx = x * cos( gamma ) + y * sin( gamma );
00173 ry = - x * sin( gamma ) + y * cos( gamma );
00174 rz = z;
00175
00176 x = rx; y = ry; z = rz;
00177
00178
00179 lon = ( 180.0 / M_PI ) * asin( z );
00180 lat = ( 180.0 / M_PI ) * atan2( y, x );
00181
00182 if (negative==false) lat+=180.0;
00183
00184 }
00185
00186 namespace dp = hippodraw::DataPoint2DTuple;
00187
00190 void
00191 SymbolPointRep::
00192 drawProjectedValues ( const DataSource * ntuple,
00193 TransformBase * transform,
00194 ViewBase * view )
00195 {
00196 unsigned int size = ntuple -> rows ();
00197 if ( size == 0 ) return;
00198
00199 const BinaryTransform * tf
00200 = dynamic_cast < BinaryTransform * > ( transform );
00201 assert ( tf != 0 );
00202 beginPlot ( size, tf, view );
00203
00204 for ( unsigned int i = 0; i < size; i++ ) {
00205 drawProjectedValue ( i, ntuple, tf, view );
00206 }
00207
00208 const Color & cur_color = color ();
00209
00210
00211 tf -> transform (m_x, m_y);
00212 view -> drawPoints ( m_x, m_y, m_plot_symbol, m_size, cur_color );
00213
00214 if ( m_x_flag || m_y_flag ) {
00215 m_error_rep -> drawProjectedValues ( ntuple, transform, view );
00216 }
00217 }
00218
00219 void
00220 SymbolPointRep::
00221 beginPlot ( unsigned int size,
00222 const BinaryTransform * tf,
00223 const ViewBase * view )
00224 {
00225 m_x.clear ();
00226 m_y.clear ();
00227
00228 m_x.reserve ( size );
00229 m_y.reserve ( size );
00230
00231 c_x_range = view -> getRange ( Axes::X );
00232 c_y_range = view -> getRange ( Axes::Y );
00233
00234 if ( tf -> isPeriodic () ) {
00235 c_periodic_tf = dynamic_cast < const PeriodicBinaryTransform * > ( tf );
00236 c_beta = c_periodic_tf -> xOffset ();
00237 c_gamma = c_periodic_tf -> yOffset ();
00238 c_max_x = c_periodic_tf -> limitX().high();
00239 }
00240 }
00241
00242 bool
00243 SymbolPointRep::
00244 drawProjectedValue ( unsigned int i,
00245 const DataSource * ntuple,
00246 const BinaryTransform * tf,
00247 ViewBase * view )
00248 {
00249 bool retval = false;
00250
00251 const vector < double > & row = ntuple -> getRow ( i );
00252 double x = row [ dp::X ];
00253 double y = row [ dp::Y ];
00254
00255 double xtemp = x;
00256 double ytemp = y;
00257
00258 if ( tf -> isPeriodic() )
00259 {
00260 xtemp = c_periodic_tf -> moduloSubX ( x, c_beta );
00261 ytemp = c_periodic_tf -> moduloSubY ( y, c_gamma );
00262
00263
00264 rotate ( x, y, 0.0, c_beta, c_gamma, (c_max_x==180.0) );
00265 }
00266
00267 const Range & xrange = view -> getRange ( Axes::X );
00268 const Range & yrange = view -> getRange ( Axes::Y );
00269
00270 if ( xrange.includes ( xtemp ) &&
00271 yrange.includes ( ytemp ) )
00272 {
00273
00274 m_x.push_back ( x );
00275 m_y.push_back ( y );
00276 retval = true;
00277 }
00278
00279 return retval;
00280 }
00281
00282 bool
00283 SymbolPointRep::
00284 uses ( Symbol::Type ) const
00285 {
00286 return true;
00287 }
00288
00289 void
00290 SymbolPointRep::
00291 setSize ( float value )
00292 {
00293 RepBase::setSize ( value );
00294
00295 m_error_rep -> setSize ( value / 4. );
00296 }