SymbolPointRep.cxx
Go to the documentation of this file.
1 
12 #ifdef _MSC_VER
13 // include max() and min() missing from Microsoft Visual C++
14 #include "msdevstudio/MSconfig.h"
15 #endif //_MSC_VER
16 
17 #include "SymbolPointRep.h"
18 
19 #include "ErrorBarRep.h"
20 
22 #include "datasrcs/DataSource.h"
23 #include "graphics/ViewBase.h"
24 
27 
28 #include <cmath>
29 
30 #include <cassert>
31 
32 using std::string;
33 using std::vector;
34 
35 using namespace hippodraw;
36 
39  : PointRepBase ( "Symbol", size ),
40  m_plot_symbol( symbol )
41 {
42  m_error_rep = new ErrorBarRep();
43 }
44 
46  : PointRepBase ( "Symbol", 2.0 ),
47  m_plot_symbol( Symbol::SOLIDSQUARE )
48 {
49  m_error_rep = new ErrorBarRep();
50 }
51 
53  : PointRepBase( point_rep ),
54  m_x( point_rep.m_x ),
55  m_y( point_rep.m_y ),
56  m_x_flag( point_rep.m_x_flag ),
57  m_y_flag( point_rep.m_y_flag ),
58  m_plot_symbol( point_rep.m_plot_symbol )
59 {
60  RepBase * clone = point_rep.m_error_rep->clone();
61  m_error_rep = dynamic_cast< ErrorBarRep * > ( clone );
62 }
63 
65 {
66  delete m_error_rep;
67 }
68 
70 {
71  return new SymbolPointRep( *this );
72 }
73 
74 void SymbolPointRep::setColor ( const Color & color )
75 {
76  RepBase::setColor ( color );
77 
78  if ( m_error_rep ) {
79  m_error_rep->setColor ( color );
80  }
81 }
82 
83 void SymbolPointRep::setStyle ( unsigned int symbol )
84 {
85  m_plot_symbol = Symbol::convert ( symbol );
86 }
87 
88 unsigned int
90 getStyle ( ) const
91 {
92  return m_plot_symbol;
93 }
94 
95 void
97 setErrorOn ( Axes::Type axis, bool flag )
98 {
99  if ( axis == Axes::X ) {
100  m_error_rep -> setXError ( flag );
101  m_x_flag = flag;
102  }
103  else if ( axis == Axes::Y ) {
104  m_error_rep -> setYError ( flag );
105  m_y_flag = flag;
106  }
107 }
108 
110 {
111  return m_x_flag;
112 }
113 
115 {
116  return m_y_flag;
117 }
118 
121 void
124  ViewBase & )
125 {
126  try {
127  const BinaryTransform & tf
128  = dynamic_cast < const BinaryTransform & > ( tb );
129 
130  tf.transform ( m_x, m_y );
131  }
132  catch ( ... ) {
133  assert ( false );
134  }
135 }
136 
137 void
139 rotate ( double & lat, double & lon,
140  double alpha, double beta, double gamma, bool negative )
141 {
142  if ( negative == false ) lat-=180.0;
143 
144  // convert to radians from degrees
145  lat = M_PI * lat / 180.0;
146  lon = M_PI * lon / 180.0;
147  alpha = M_PI * alpha / 180.0;
148  beta = M_PI * beta / 180.0;
149  gamma = M_PI * gamma / 180.0;
150 
151  // Convert the latitude and longitudes into the cartesian coordinates
152  // Assume a unit sphere ( Radii does not matter in rotation )
153  double x = cos( lat ) * cos( lon );
154  double y = sin( lat ) * cos( lon );
155  double z = sin( lon );
156 
157  // First give a rotation about the x axis ( conventionally denoted by alpha )
158  double rx = x;
159  double ry = y * cos( alpha ) + z * sin( alpha );
160  double rz = - y * sin( alpha ) + z * cos( alpha );
161 
162  x = rx; y = ry; z = rz;
163 
164  // Now give a rotation about the y axis ( conventionally denoted by beta )
165  rx = x * cos( beta ) - z * sin( beta );
166  ry = y;
167  rz = x * sin( beta ) + z * cos( beta );
168 
169  x = rx; y = ry; z = rz;
170 
171  // Now give a rotation about the z axis ( conventionally denoted by gamma )
172  rx = x * cos( gamma ) + y * sin( gamma );
173  ry = - x * sin( gamma ) + y * cos( gamma );
174  rz = z;
175 
176  x = rx; y = ry; z = rz;
177 
178  // Convert back to latitude and longitudes ( in degrees )
179  lon = ( 180.0 / M_PI ) * asin( z );
180  lat = ( 180.0 / M_PI ) * atan2( y, x );
181 
182  if (negative==false) lat+=180.0;
183 
184 }
185 
186 namespace dp = hippodraw::DataPoint2DTuple;
187 
190 void
193  TransformBase * transform,
194  ViewBase * view )
195 {
196  unsigned int size = ntuple -> rows ();
197  if ( size == 0 ) return;
198 
199  const BinaryTransform * tf
200  = dynamic_cast < BinaryTransform * > ( transform );
201  assert ( tf != 0 );
202  beginPlot ( size, tf, view );
203 
204  for ( unsigned int i = 0; i < size; i++ ) {
205  drawProjectedValue ( i, ntuple, tf, view );
206  }
207 
208  const Color & cur_color = color ();
209 
210  // Transform vector
211  tf -> transform (m_x, m_y);
212  view -> drawPoints ( m_x, m_y, m_plot_symbol, m_size, cur_color );
213 
214  if ( m_x_flag || m_y_flag ) {
215  m_error_rep -> drawProjectedValues ( ntuple, transform, view );
216  }
217 }
218 
219 void
221 beginPlot ( unsigned int size,
222  const BinaryTransform * tf,
223  const ViewBase * view )
224 {
225  m_x.clear ();
226  m_y.clear ();
227 
228  m_x.reserve ( size );
229  m_y.reserve ( size );
230 
231  c_x_range = view -> getRange ( Axes::X );
232  c_y_range = view -> getRange ( Axes::Y );
233 
234  if ( tf -> isPeriodic () ) {
235  c_periodic_tf = dynamic_cast < const PeriodicBinaryTransform * > ( tf );
236  c_beta = c_periodic_tf -> xOffset ();
237  c_gamma = c_periodic_tf -> yOffset ();
238  c_max_x = c_periodic_tf -> limitX().high();
239  }
240 }
241 
242 bool
244 drawProjectedValue ( unsigned int i,
245  const DataSource * ntuple,
246  const BinaryTransform * tf,
247  ViewBase * view )
248 {
249  bool retval = false;
250 
251  const vector < double > & row = ntuple -> getRow ( i );
252  double x = row [ dp::X ];
253  double y = row [ dp::Y ];
254 
255  double xtemp = x;
256  double ytemp = y;
257 
258  if ( tf -> isPeriodic() )
259  {
260  xtemp = c_periodic_tf -> moduloSubX ( x, c_beta );
261  ytemp = c_periodic_tf -> moduloSubY ( y, c_gamma );
262 
263  // Rotation should preserve [0,360] or [-180,180] range
264  rotate ( x, y, 0.0, c_beta, c_gamma, (c_max_x==180.0) );
265  }
266 
267  const Range & xrange = view -> getRange ( Axes::X );
268  const Range & yrange = view -> getRange ( Axes::Y );
269 
270  if ( xrange.includes ( xtemp ) &&
271  yrange.includes ( ytemp ) )
272  {
273  //tf -> transform( x, y );
274  m_x.push_back ( x );
275  m_y.push_back ( y );
276  retval = true;
277  }
278 
279  return retval;
280 }
281 
282 bool
285 {
286  return true;
287 }
288 
289 void
291 setSize ( float value )
292 {
293  RepBase::setSize ( value );
294 
295  m_error_rep -> setSize ( value / 4. );
296 }

Generated for HippoDraw Class Library by doxygen