29 #include <osg/Geometry>
30 #include <osg/MatrixTransform>
31 #include <osg/PositionAttitudeTransform>
32 #include <osgText/Text>
34 #include "WRulerOrtho.h"
35 #include "core/common/WPathHelper.h"
36 #include "core/common/WStringUtils.h"
38 WRulerOrtho::WRulerOrtho( std::shared_ptr<WCoordConverter>coordConverter, osg::Vec3 origin, scaleMode mode,
bool showNumbers ) :
40 m_coordConverter( coordConverter ),
43 m_showNumbers( showNumbers )
57 osg::ref_ptr< osg::Geode > rulerGeode = osg::ref_ptr< osg::Geode >(
new osg::Geode() );
58 osg::ref_ptr< osg::Geometry > geometry;
62 case RULER_ALONG_X_AXIS_SCALE_Y:
65 case RULER_ALONG_X_AXIS_SCALE_Z:
68 case RULER_ALONG_Y_AXIS_SCALE_X:
71 case RULER_ALONG_Y_AXIS_SCALE_Z:
74 case RULER_ALONG_Z_AXIS_SCALE_X:
77 case RULER_ALONG_Z_AXIS_SCALE_Y:
84 osg::DrawElementsUInt* lines =
new osg::DrawElementsUInt( osg::PrimitiveSet::LINES, 0 );
85 for(
size_t i = 0; i < geometry->getVertexArray()->getNumElements(); ++i )
87 lines->push_back( i );
89 geometry->addPrimitiveSet( lines );
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 );
96 osg::StateSet* stateGroup = this->getOrCreateStateSet();
97 stateGroup->setMode( GL_LIGHTING, osg::StateAttribute::OFF | osg::StateAttribute::PROTECTED );
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() );
105 labelGeode->addDrawable( label );
109 label->setBackdropType( osgText::Text::OUTLINE );
110 label->setCharacterSize( 6 );
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 ) );
119 osg::PositionAttitudeTransform* labelXform =
new osg::PositionAttitudeTransform();
120 labelXform->setPosition( position );
122 this->addChild( labelXform );
123 labelXform->addChild( labelGeode );
128 osg::ref_ptr< osg::Geometry > geometry = osg::ref_ptr< osg::Geometry >(
new osg::Geometry() );
129 osg::Vec3Array* vertices =
new osg::Vec3Array;
131 int startX =
static_cast< int > (
m_lb[0] + 0.5 );
141 for(
int i = startX; i <= static_cast< int > (
m_ub[0] ); ++i )
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() ) );
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() ) );
171 for(
int i = -70; i <= 71; ++i )
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() ) );
195 geometry->setVertexArray( vertices );
202 osg::ref_ptr< osg::Geometry > geometry = osg::ref_ptr< osg::Geometry >(
new osg::Geometry() );
203 osg::Vec3Array* vertices =
new osg::Vec3Array;
205 int startX =
static_cast< int > (
m_lb[0] + 0.5 );
215 for(
int i = startX; i <= static_cast< int > (
m_ub[0] ); ++i )
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 ) );
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] ) );
245 for(
int i = -70; i <= 71; ++i )
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] ) );
269 geometry->setVertexArray( vertices );
275 osg::ref_ptr< osg::Geometry > geometry = osg::ref_ptr< osg::Geometry >(
new osg::Geometry() );
276 osg::Vec3Array* vertices =
new osg::Vec3Array;
278 int startY =
static_cast< int > (
m_lb[1] + 0.5 );
288 for(
int i = startY; i <= static_cast< int > (
m_ub[1] ); ++i )
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() ) );
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() ) );
318 for(
int i = -100; i <= 81; ++i )
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() ) );
343 geometry->setVertexArray( vertices );
350 osg::ref_ptr< osg::Geometry > geometry = osg::ref_ptr< osg::Geometry >(
new osg::Geometry() );
351 osg::Vec3Array* vertices =
new osg::Vec3Array;
353 int startY =
static_cast< int > (
m_lb[1] + 0.5 );
363 for(
int i = startY; i <= static_cast< int > (
m_ub[1] ); ++i )
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 ) );
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] ) );
393 for(
int i = -100; i <= 81; ++i )
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] ) );
418 geometry->setVertexArray( vertices );
425 osg::ref_ptr< osg::Geometry > geometry = osg::ref_ptr< osg::Geometry >(
new osg::Geometry() );
426 osg::Vec3Array* vertices =
new osg::Vec3Array;
428 int startZ =
static_cast< int > (
m_lb[2] + 0.5 );
438 for(
int i = startZ; i <= static_cast< int > (
m_ub[2] ); ++i )
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 ) );
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] ) );
468 for(
int i = -50; i <= 81; ++i )
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] ) );
493 geometry->setVertexArray( vertices );
500 osg::ref_ptr< osg::Geometry > geometry = osg::ref_ptr< osg::Geometry >(
new osg::Geometry() );
501 osg::Vec3Array* vertices =
new osg::Vec3Array;
503 int startZ =
static_cast< int > (
m_lb[2] + 0.5 );
513 for(
int i = startZ; i <= static_cast< int > (
m_ub[2] ); ++i )
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 ) );
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] ) );
543 for(
int i = -50; i <= 81; ++i )
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] ) );
568 geometry->setVertexArray( vertices );
577 case RULER_ALONG_X_AXIS_SCALE_Y:
580 case RULER_ALONG_X_AXIS_SCALE_Z:
583 case RULER_ALONG_Y_AXIS_SCALE_X:
586 case RULER_ALONG_Y_AXIS_SCALE_Z:
589 case RULER_ALONG_Z_AXIS_SCALE_X:
592 case RULER_ALONG_Z_AXIS_SCALE_Y:
598 return std::string(
"" );
static Fonts getAllFonts()
The paths to all fonts supported.
void create()
creates the osg node for the ruler representation
std::shared_ptr< WCoordConverter > m_coordConverter
stores pointer to a coordinate converter
bool m_showNumbers
flag to indicate wether to show number labels
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
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
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;
osg::Vec3 m_origin
Origin of the ruler, it will be drawn in the positive direction.
scaleMode m_scaleMode
orientation of ruler
WVector3d m_ub
= m_coordConverter->getBoundingBox().second;
std::string numberToString(int number)
converts a number into a string according to the currently selected coordinate system
class to implement various rulers
std::string toString(const T &value)
Convert a given value to a string.