OpenWalnut  1.5.0dev
WRulerOrtho.cpp
1 //---------------------------------------------------------------------------
2 //
3 // Project: OpenWalnut ( http://www.openwalnut.org )
4 //
5 // Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
6 // For more information see http://www.openwalnut.org/copying
7 //
8 // This file is part of OpenWalnut.
9 //
10 // OpenWalnut is free software: you can redistribute it and/or modify
11 // it under the terms of the GNU Lesser General Public License as published by
12 // the Free Software Foundation, either version 3 of the License, or
13 // (at your option) any later version.
14 //
15 // OpenWalnut is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU Lesser General Public License for more details.
19 //
20 // You should have received a copy of the GNU Lesser General Public License
21 // along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
22 //
23 //---------------------------------------------------------------------------
24 
25 #include <memory>
26 #include <string>
27 
28 #include <osg/Geode>
29 #include <osg/Geometry>
30 #include <osg/MatrixTransform>
31 #include <osg/PositionAttitudeTransform>
32 #include <osgText/Text>
33 
34 #include "WRulerOrtho.h"
35 #include "core/common/WPathHelper.h"
36 #include "core/common/WStringUtils.h"
37 
38 WRulerOrtho::WRulerOrtho( std::shared_ptr<WCoordConverter>coordConverter, osg::Vec3 origin, scaleMode mode, bool showNumbers ) :
39  WRuler(),
40  m_coordConverter( coordConverter ),
41  m_origin( origin ),
42  m_scaleMode( mode ),
43  m_showNumbers( showNumbers )
44 {
45  m_lb = m_coordConverter->getBoundingBox().getMin();
46  m_ub = m_coordConverter->getBoundingBox().getMax();
47 
48  create();
49 }
50 
52 {
53 }
54 
56 {
57  osg::ref_ptr< osg::Geode > rulerGeode = osg::ref_ptr< osg::Geode >( new osg::Geode() );
58  osg::ref_ptr< osg::Geometry > geometry;
59 
60  switch( m_scaleMode )
61  {
62  case RULER_ALONG_X_AXIS_SCALE_Y:
63  geometry = createXY();
64  break;
65  case RULER_ALONG_X_AXIS_SCALE_Z:
66  geometry = createXZ();
67  break;
68  case RULER_ALONG_Y_AXIS_SCALE_X:
69  geometry = createYX();
70  break;
71  case RULER_ALONG_Y_AXIS_SCALE_Z:
72  geometry = createYZ();
73  break;
74  case RULER_ALONG_Z_AXIS_SCALE_X:
75  geometry = createZX();
76  break;
77  case RULER_ALONG_Z_AXIS_SCALE_Y:
78  geometry = createZY();
79  break;
80  default:
81  break;
82  }
83 
84  osg::DrawElementsUInt* lines = new osg::DrawElementsUInt( osg::PrimitiveSet::LINES, 0 );
85  for( size_t i = 0; i < geometry->getVertexArray()->getNumElements(); ++i )
86  {
87  lines->push_back( i );
88  }
89  geometry->addPrimitiveSet( lines );
90 
91  osg::StateSet* state = geometry->getOrCreateStateSet();
92  state->setMode( GL_LIGHTING, osg::StateAttribute::OFF | osg::StateAttribute::PROTECTED );
93  rulerGeode->addDrawable( geometry );
94  this->addChild( rulerGeode );
95 
96  osg::StateSet* stateGroup = this->getOrCreateStateSet();
97  stateGroup->setMode( GL_LIGHTING, osg::StateAttribute::OFF | osg::StateAttribute::PROTECTED );
98 }
99 
100 void WRulerOrtho::addLabel( osg::Vec3 position, std::string text )
101 {
102  osg::ref_ptr< osgText::Text > label = osg::ref_ptr< osgText::Text >( new osgText::Text() );
103  osg::ref_ptr< osg::Geode > labelGeode = osg::ref_ptr< osg::Geode >( new osg::Geode() );
104 
105  labelGeode->addDrawable( label );
106 
107  // setup font
108  label->setFont( WPathHelper::getAllFonts().Default.string() );
109  label->setBackdropType( osgText::Text::OUTLINE );
110  label->setCharacterSize( 6 );
111 
112  label->setText( text );
113  label->setAxisAlignment( osgText::Text::SCREEN );
114  label->setDrawMode( osgText::Text::TEXT );
115  label->setAlignment( osgText::Text::CENTER_TOP );
116  label->setPosition( osg::Vec3( 0.0, 0.0, 0.0 ) );
117  label->setColor( osg::Vec4( 1.0f, 1.0f, 1.0f, 1.0f ) );
118 
119  osg::PositionAttitudeTransform* labelXform = new osg::PositionAttitudeTransform();
120  labelXform->setPosition( position );
121 
122  this->addChild( labelXform );
123  labelXform->addChild( labelGeode );
124 }
125 
126 osg::ref_ptr< osg::Geometry > WRulerOrtho::createXY()
127 {
128  osg::ref_ptr< osg::Geometry > geometry = osg::ref_ptr< osg::Geometry >( new osg::Geometry() );
129  osg::Vec3Array* vertices = new osg::Vec3Array;
130 
131  int startX = static_cast< int > ( m_lb[0] + 0.5 );
132 
133  switch( m_coordConverter->getCoordinateSystemMode() )
134  {
135  case CS_WORLD:
136  case CS_CANONICAL:
137  {
138  vertices->push_back( osg::Vec3( m_lb[0], m_origin.y(), m_origin.z() ) );
139  vertices->push_back( osg::Vec3( m_ub[0], m_origin.y(), m_origin.z() ) );
140 
141  for( int i = startX; i <= static_cast< int > ( m_ub[0] ); ++i )
142  {
143  float rlength = 1.0;
144  if( m_coordConverter->numberToCsX( i ) % 10 == 0 )
145  {
146  rlength += 1.0;
147  if( m_showNumbers )
148  {
149  addLabel( osg::Vec3( i, m_origin.y(), m_origin.z() ), numberToString( i ) );
150  }
151  }
152  if( m_coordConverter->numberToCsX( i ) % 5 == 0 )
153  {
154  rlength += 1.0;
155  }
156  vertices->push_back( osg::Vec3( i, m_origin.y() - rlength, m_origin.z() ) );
157  vertices->push_back( osg::Vec3( i, m_origin.y() + rlength, m_origin.z() ) );
158  }
159  }
160  break;
161  case CS_TALAIRACH:
162  {
163  WVector3d origin_t = m_coordConverter->w2t( WVector3d( m_origin[0], m_origin[1], m_origin[2] ) );
164 
165  WVector3d pA = m_coordConverter->t2w( WVector3d( origin_t[0], -70, origin_t[2] ) );
166  WVector3d pO = m_coordConverter->t2w( WVector3d( origin_t[0], +70, origin_t[2] ) );
167 
168  vertices->push_back( osg::Vec3( pA[0], pA[1], m_origin.z() ) );
169  vertices->push_back( osg::Vec3( pO[0], pO[1], m_origin.z() ) );
170 
171  for( int i = -70; i <= 71; ++i )
172  {
173  WVector3d tmpPoint = m_coordConverter->t2w( WVector3d( origin_t[0], i, origin_t[2] ) );
174  float rlength = 1.0;
175  if( i % 10 == 0 )
176  {
177  rlength += 1.0;
178  if( m_showNumbers )
179  {
180  addLabel( osg::Vec3( tmpPoint[0], tmpPoint[1], m_origin.z() ), string_utils::toString( i ) );
181  }
182  }
183  if( i % 5 == 0 )
184  {
185  rlength += 1.0;
186  }
187  WVector3d p1 = m_coordConverter->t2w( WVector3d( origin_t[0] - rlength, i, origin_t[2] ) );
188  WVector3d p2 = m_coordConverter->t2w( WVector3d( origin_t[0] + rlength, i, origin_t[2] ) );
189 
190  vertices->push_back( osg::Vec3( p1[0], p1[1], m_origin.z() ) );
191  vertices->push_back( osg::Vec3( p2[0], p2[1], m_origin.z() ) );
192  }
193  }
194  }
195  geometry->setVertexArray( vertices );
196 
197  return geometry;
198 }
199 
200 osg::ref_ptr< osg::Geometry > WRulerOrtho::createXZ()
201 {
202  osg::ref_ptr< osg::Geometry > geometry = osg::ref_ptr< osg::Geometry >( new osg::Geometry() );
203  osg::Vec3Array* vertices = new osg::Vec3Array;
204 
205  int startX = static_cast< int > ( m_lb[0] + 0.5 );
206 
207  switch( m_coordConverter->getCoordinateSystemMode() )
208  {
209  case CS_WORLD:
210  case CS_CANONICAL:
211  {
212  vertices->push_back( osg::Vec3( m_lb[0], m_origin.y(), m_origin.z() ) );
213  vertices->push_back( osg::Vec3( m_ub[0], m_origin.y(), m_origin.z() ) );
214 
215  for( int i = startX; i <= static_cast< int > ( m_ub[0] ); ++i )
216  {
217  float rlength = 1.0;
218  if( m_coordConverter->numberToCsX( i ) % 10 == 0 )
219  {
220  rlength += 1.0;
221  if( m_showNumbers )
222  {
223  addLabel( osg::Vec3( i, m_origin.y(), m_origin.z() ), numberToString( i ) );
224  }
225  }
226  if( m_coordConverter->numberToCsX( i ) % 5 == 0 )
227  {
228  rlength += 1.0;
229  }
230  vertices->push_back( osg::Vec3( i, m_origin.y(), m_origin.z() - rlength ) );
231  vertices->push_back( osg::Vec3( i, m_origin.y(), m_origin.z() + rlength ) );
232  }
233  }
234  break;
235  case CS_TALAIRACH:
236  {
237  WVector3d origin_t = m_coordConverter->w2t( WVector3d( m_origin[0], m_origin[1], m_origin[2] ) );
238 
239  WVector3d pA = m_coordConverter->t2w( WVector3d( origin_t[0], -70, origin_t[2] ) );
240  WVector3d pO = m_coordConverter->t2w( WVector3d( origin_t[0], +70, origin_t[2] ) );
241 
242  vertices->push_back( osg::Vec3( pA[0], m_origin.y(), pA[2] ) );
243  vertices->push_back( osg::Vec3( pO[0], m_origin.y(), pO[2] ) );
244 
245  for( int i = -70; i <= 71; ++i )
246  {
247  WVector3d tmpPoint = m_coordConverter->t2w( WVector3d( origin_t[0], i, origin_t[2] ) );
248  float rlength = 1.0;
249  if( i % 10 == 0 )
250  {
251  rlength += 1.0;
252  if( m_showNumbers )
253  {
254  addLabel( osg::Vec3( tmpPoint[0], m_origin.y(), tmpPoint[2] ), string_utils::toString( i ) );
255  }
256  }
257  if( i % 5 == 0 )
258  {
259  rlength += 1.0;
260  }
261  WVector3d p1 = m_coordConverter->t2w( WVector3d( origin_t[0], i, origin_t[2] - rlength ) );
262  WVector3d p2 = m_coordConverter->t2w( WVector3d( origin_t[0], i, origin_t[2] + rlength ) );
263 
264  vertices->push_back( osg::Vec3( p1[0], m_origin.y(), p1[2] ) );
265  vertices->push_back( osg::Vec3( p2[0], m_origin.y(), p2[2] ) );
266  }
267  }
268  }
269  geometry->setVertexArray( vertices );
270  return geometry;
271 }
272 
273 osg::ref_ptr< osg::Geometry > WRulerOrtho::createYX()
274 {
275  osg::ref_ptr< osg::Geometry > geometry = osg::ref_ptr< osg::Geometry >( new osg::Geometry() );
276  osg::Vec3Array* vertices = new osg::Vec3Array;
277 
278  int startY = static_cast< int > ( m_lb[1] + 0.5 );
279 
280  switch( m_coordConverter->getCoordinateSystemMode() )
281  {
282  case CS_WORLD:
283  case CS_CANONICAL:
284  {
285  vertices->push_back( osg::Vec3( m_origin.x(), m_lb[1], m_origin.z() ) );
286  vertices->push_back( osg::Vec3( m_origin.x(), m_ub[1], m_origin.z() ) );
287 
288  for( int i = startY; i <= static_cast< int > ( m_ub[1] ); ++i )
289  {
290  float rlength = 1.0;
291  if( m_coordConverter->numberToCsY( i ) % 10 == 0 )
292  {
293  rlength += 1.0;
294  if( m_showNumbers )
295  {
296  addLabel( osg::Vec3( m_origin.x(), i, m_origin.z() ), numberToString( i ) );
297  }
298  }
299  if( m_coordConverter->numberToCsY( i ) % 5 == 0 )
300  {
301  rlength += 1.0;
302  }
303  vertices->push_back( osg::Vec3( m_origin.x() - rlength, i, m_origin.z() ) );
304  vertices->push_back( osg::Vec3( m_origin.x() + rlength, i, m_origin.z() ) );
305  }
306  }
307  break;
308  case CS_TALAIRACH:
309  {
310  WVector3d origin_t = m_coordConverter->w2t( WVector3d( m_origin[0], m_origin[1], m_origin[2] ) );
311 
312  WVector3d pA = m_coordConverter->t2w( WVector3d( -100, origin_t[1], origin_t[2] ) );
313  WVector3d pO = m_coordConverter->t2w( WVector3d( 80, origin_t[1], origin_t[2] ) );
314 
315  vertices->push_back( osg::Vec3( pA[0], pA[1], m_origin.z() ) );
316  vertices->push_back( osg::Vec3( pO[0], pO[1], m_origin.z() ) );
317 
318  for( int i = -100; i <= 81; ++i )
319  {
320  WVector3d tmpPoint = m_coordConverter->t2w( WVector3d( i, origin_t[1], origin_t[2] ) );
321  float rlength = 1.0;
322  if( i % 10 == 0 )
323  {
324  rlength += 1.0;
325  if( m_showNumbers )
326  {
327  addLabel( osg::Vec3( tmpPoint[0], tmpPoint[1], m_origin.z() ), string_utils::toString( i ) );
328  }
329  }
330  if( i % 5 == 0 )
331  {
332  rlength += 1.0;
333  }
334  WVector3d p1 = m_coordConverter->t2w( WVector3d( i, origin_t[1] - rlength, origin_t[2] ) );
335  WVector3d p2 = m_coordConverter->t2w( WVector3d( i, origin_t[1] + rlength, origin_t[2] ) );
336 
337  vertices->push_back( osg::Vec3( p1[0], p1[1], m_origin.z() ) );
338  vertices->push_back( osg::Vec3( p2[0], p2[1], m_origin.z() ) );
339  }
340  }
341  break;
342  }
343  geometry->setVertexArray( vertices );
344 
345  return geometry;
346 }
347 
348 osg::ref_ptr< osg::Geometry > WRulerOrtho::createYZ()
349 {
350  osg::ref_ptr< osg::Geometry > geometry = osg::ref_ptr< osg::Geometry >( new osg::Geometry() );
351  osg::Vec3Array* vertices = new osg::Vec3Array;
352 
353  int startY = static_cast< int > ( m_lb[1] + 0.5 );
354 
355  switch( m_coordConverter->getCoordinateSystemMode() )
356  {
357  case CS_WORLD:
358  case CS_CANONICAL:
359  {
360  vertices->push_back( osg::Vec3( m_origin.x(), m_lb[1], m_origin.z() ) );
361  vertices->push_back( osg::Vec3( m_origin.x(), m_ub[1], m_origin.z() ) );
362 
363  for( int i = startY; i <= static_cast< int > ( m_ub[1] ); ++i )
364  {
365  float rlength = 1.0;
366  if( m_coordConverter->numberToCsY( i ) % 10 == 0 )
367  {
368  rlength += 1.0;
369  if( m_showNumbers )
370  {
371  addLabel( osg::Vec3( m_origin.x(), i, m_origin.z() ), numberToString( i ) );
372  }
373  }
374  if( m_coordConverter->numberToCsY( i ) % 5 == 0 )
375  {
376  rlength += 1.0;
377  }
378  vertices->push_back( osg::Vec3( m_origin.x(), i, m_origin.z() - rlength ) );
379  vertices->push_back( osg::Vec3( m_origin.x(), i, m_origin.z() + rlength ) );
380  }
381  }
382  break;
383  case CS_TALAIRACH:
384  {
385  WVector3d origin_t = m_coordConverter->w2t( WVector3d( m_origin[0], m_origin[1], m_origin[2] ) );
386 
387  WVector3d pA = m_coordConverter->t2w( WVector3d( -100, origin_t[1], origin_t[2] ) );
388  WVector3d pO = m_coordConverter->t2w( WVector3d( 80, origin_t[1], origin_t[2] ) );
389 
390  vertices->push_back( osg::Vec3( m_origin.x(), pA[1], pA[2] ) );
391  vertices->push_back( osg::Vec3( m_origin.x(), pO[1], pO[2] ) );
392 
393  for( int i = -100; i <= 81; ++i )
394  {
395  WVector3d tmpPoint = m_coordConverter->t2w( WVector3d( i, 0, origin_t[2] ) );
396  float rlength = 1.0;
397  if( i % 10 == 0 )
398  {
399  rlength += 1.0;
400  if( m_showNumbers )
401  {
402  addLabel( osg::Vec3( m_origin.x(), tmpPoint[1], tmpPoint[2] ), string_utils::toString( i ) );
403  }
404  }
405  if( i % 5 == 0 )
406  {
407  rlength += 1.0;
408  }
409  WVector3d p1 = m_coordConverter->t2w( WVector3d( i, origin_t[1], origin_t[2] - rlength ) );
410  WVector3d p2 = m_coordConverter->t2w( WVector3d( i, origin_t[1], origin_t[2] + rlength ) );
411 
412  vertices->push_back( osg::Vec3( m_origin.x(), p1[1], p1[2] ) );
413  vertices->push_back( osg::Vec3( m_origin.x(), p2[1], p2[2] ) );
414  }
415  }
416  break;
417  }
418  geometry->setVertexArray( vertices );
419 
420  return geometry;
421 }
422 
423 osg::ref_ptr< osg::Geometry > WRulerOrtho::createZX()
424 {
425  osg::ref_ptr< osg::Geometry > geometry = osg::ref_ptr< osg::Geometry >( new osg::Geometry() );
426  osg::Vec3Array* vertices = new osg::Vec3Array;
427 
428  int startZ = static_cast< int > ( m_lb[2] + 0.5 );
429 
430  switch( m_coordConverter->getCoordinateSystemMode() )
431  {
432  case CS_WORLD:
433  case CS_CANONICAL:
434  {
435  vertices->push_back( osg::Vec3( m_origin.x(), m_origin.y(), m_lb[2] ) );
436  vertices->push_back( osg::Vec3( m_origin.x(), m_origin.y(), m_ub[2] ) );
437 
438  for( int i = startZ; i <= static_cast< int > ( m_ub[2] ); ++i )
439  {
440  float rlength = 1.0;
441  if( m_coordConverter->numberToCsZ( i ) % 10 == 0 )
442  {
443  rlength += 1.0;
444  if( m_showNumbers )
445  {
446  addLabel( osg::Vec3( m_origin.x(), m_origin.y(), i ), numberToString( i ) );
447  }
448  }
449  if( m_coordConverter->numberToCsZ( i ) % 5 == 0 )
450  {
451  rlength += 1.0;
452  }
453  vertices->push_back( osg::Vec3( m_origin.x() - rlength, m_origin.y(), i ) );
454  vertices->push_back( osg::Vec3( m_origin.x() + rlength, m_origin.y(), i ) );
455  }
456  }
457  break;
458  case CS_TALAIRACH:
459  {
460  WVector3d origin_t = m_coordConverter->w2t( WVector3d( m_origin[0], m_origin[1], m_origin[2] ) );
461 
462  WVector3d pA = m_coordConverter->t2w( WVector3d( origin_t[0], origin_t[1], -50 ) );
463  WVector3d pO = m_coordConverter->t2w( WVector3d( origin_t[0], origin_t[1], 80 ) );
464 
465  vertices->push_back( osg::Vec3( pA[0], m_origin.y(), pA[2] ) );
466  vertices->push_back( osg::Vec3( pO[0], m_origin.y(), pO[2] ) );
467 
468  for( int i = -50; i <= 81; ++i )
469  {
470  WVector3d tmpPoint = m_coordConverter->t2w( WVector3d( origin_t[0], origin_t[1], i ) );
471  float rlength = 1.0;
472  if( i % 10 == 0 )
473  {
474  rlength += 1.0;
475  if( m_showNumbers )
476  {
477  addLabel( osg::Vec3( tmpPoint[0], m_origin.y(), tmpPoint[2] ), string_utils::toString( i ) );
478  }
479  }
480  if( i % 5 == 0 )
481  {
482  rlength += 1.0;
483  }
484  WVector3d p1 = m_coordConverter->t2w( WVector3d( origin_t[0], origin_t[1] - rlength, i ) );
485  WVector3d p2 = m_coordConverter->t2w( WVector3d( origin_t[0], origin_t[1] + rlength, i ) );
486 
487  vertices->push_back( osg::Vec3( p1[0], m_origin.y(), p1[2] ) );
488  vertices->push_back( osg::Vec3( p2[0], m_origin.y(), p2[2] ) );
489  }
490  }
491  break;
492  }
493  geometry->setVertexArray( vertices );
494 
495  return geometry;
496 }
497 
498 osg::ref_ptr< osg::Geometry > WRulerOrtho::createZY()
499 {
500  osg::ref_ptr< osg::Geometry > geometry = osg::ref_ptr< osg::Geometry >( new osg::Geometry() );
501  osg::Vec3Array* vertices = new osg::Vec3Array;
502 
503  int startZ = static_cast< int > ( m_lb[2] + 0.5 );
504 
505  switch( m_coordConverter->getCoordinateSystemMode() )
506  {
507  case CS_WORLD:
508  case CS_CANONICAL:
509  {
510  vertices->push_back( osg::Vec3( m_origin.x(), m_origin.y(), m_lb[2] ) );
511  vertices->push_back( osg::Vec3( m_origin.x(), m_origin.y(), m_ub[2] ) );
512 
513  for( int i = startZ; i <= static_cast< int > ( m_ub[2] ); ++i )
514  {
515  float rlength = 1.0;
516  if( m_coordConverter->numberToCsZ( i ) % 10 == 0 )
517  {
518  rlength += 1.0;
519  if( m_showNumbers )
520  {
521  addLabel( osg::Vec3( m_origin.x(), m_origin.y(), i ), numberToString( i ) );
522  }
523  }
524  if( m_coordConverter->numberToCsZ( i ) % 5 == 0 )
525  {
526  rlength += 1.0;
527  }
528  vertices->push_back( osg::Vec3( m_origin.x(), m_origin.y() - rlength, i ) );
529  vertices->push_back( osg::Vec3( m_origin.x(), m_origin.y() + rlength, i ) );
530  }
531  }
532  break;
533  case CS_TALAIRACH:
534  {
535  WVector3d origin_t = m_coordConverter->w2t( WVector3d( m_origin[0], m_origin[1], m_origin[2] ) );
536 
537  WVector3d pA = m_coordConverter->t2w( WVector3d( origin_t[0], origin_t[1], -50 ) );
538  WVector3d pO = m_coordConverter->t2w( WVector3d( origin_t[0], origin_t[1], 80 ) );
539 
540  vertices->push_back( osg::Vec3( m_origin.x(), pA[1], pA[2] ) );
541  vertices->push_back( osg::Vec3( m_origin.x(), pO[1], pO[2] ) );
542 
543  for( int i = -50; i <= 81; ++i )
544  {
545  WVector3d tmpPoint = m_coordConverter->t2w( WVector3d( origin_t[0], 0, i ) );
546  float rlength = 1.0;
547  if( i % 10 == 0 )
548  {
549  rlength += 1.0;
550  if( m_showNumbers )
551  {
552  addLabel( osg::Vec3( m_origin.x(), tmpPoint[1], tmpPoint[2] ), string_utils::toString( i ) );
553  }
554  }
555  if( i % 5 == 0 )
556  {
557  rlength += 1.0;
558  }
559  WVector3d p1 = m_coordConverter->t2w( WVector3d( origin_t[0] - rlength, origin_t[1], i ) );
560  WVector3d p2 = m_coordConverter->t2w( WVector3d( origin_t[0] + rlength, origin_t[1], i ) );
561 
562  vertices->push_back( osg::Vec3( m_origin.x(), p1[1], p1[2] ) );
563  vertices->push_back( osg::Vec3( m_origin.x(), p2[1], p2[2] ) );
564  }
565  }
566  break;
567  }
568  geometry->setVertexArray( vertices );
569 
570  return geometry;
571 }
572 
573 std::string WRulerOrtho::numberToString( int number )
574 {
575  switch( m_scaleMode )
576  {
577  case RULER_ALONG_X_AXIS_SCALE_Y:
578  return string_utils::toString( m_coordConverter->numberToCsX( number ) );
579  break;
580  case RULER_ALONG_X_AXIS_SCALE_Z:
581  return string_utils::toString( m_coordConverter->numberToCsX( number ) );
582  break;
583  case RULER_ALONG_Y_AXIS_SCALE_X:
584  return string_utils::toString( m_coordConverter->numberToCsY( number ) );
585  break;
586  case RULER_ALONG_Y_AXIS_SCALE_Z:
587  return string_utils::toString( m_coordConverter->numberToCsY( number ) );
588  break;
589  case RULER_ALONG_Z_AXIS_SCALE_X:
590  return string_utils::toString( m_coordConverter->numberToCsZ( number ) );
591  break;
592  case RULER_ALONG_Z_AXIS_SCALE_Y:
593  return string_utils::toString( m_coordConverter->numberToCsZ( number ) );
594  break;
595  default:
596  break;
597  }
598  return std::string( "" );
599 }
static Fonts getAllFonts()
The paths to all fonts supported.
void create()
creates the osg node for the ruler representation
Definition: WRulerOrtho.cpp:55
std::shared_ptr< WCoordConverter > m_coordConverter
stores pointer to a coordinate converter
Definition: WRulerOrtho.h:71
bool m_showNumbers
flag to indicate wether to show number labels
Definition: WRulerOrtho.h:83
osg::ref_ptr< osg::Geometry > createXZ()
Helper function to create the ruler along the x axis.
void addLabel(osg::Vec3 position, std::string text)
helper function to add a label to the ruler
~WRulerOrtho()
destructor
Definition: WRulerOrtho.cpp:51
osg::ref_ptr< osg::Geometry > createXY()
Helper function to create the ruler along the x axis.
osg::ref_ptr< osg::Geometry > createYZ()
Helper function to create the ruler along the y axis.
WRulerOrtho(std::shared_ptr< WCoordConverter >coordConverter, osg::Vec3 origin, scaleMode mode, bool showNumbers=true)
standard constructor
Definition: WRulerOrtho.cpp:38
osg::ref_ptr< osg::Geometry > createZY()
Helper function to create the ruler along the z axis.
osg::ref_ptr< osg::Geometry > createZX()
Helper function to create the ruler along the z axis.
osg::ref_ptr< osg::Geometry > createYX()
Helper function to create the ruler along the y axis.
WVector3d m_lb
= m_coordConverter->getBoundingBox().first;
Definition: WRulerOrtho.h:85
osg::Vec3 m_origin
Origin of the ruler, it will be drawn in the positive direction.
Definition: WRulerOrtho.h:76
scaleMode m_scaleMode
orientation of ruler
Definition: WRulerOrtho.h:81
WVector3d m_ub
= m_coordConverter->getBoundingBox().second;
Definition: WRulerOrtho.h:86
std::string numberToString(int number)
converts a number into a string according to the currently selected coordinate system
class to implement various rulers
Definition: WRuler.h:34
std::string toString(const T &value)
Convert a given value to a string.
Definition: WStringUtils.h:120