28 #include <osg/LineWidth>
30 #include "../callbacks/WGEFunctorCallback.h"
31 #include "../WGEGeodeUtils.h"
32 #include "WGEGridNode.h"
35 m_boundaryGeode( new osg::Geode() ),
36 m_innerGridGeode( new osg::Geode() ),
37 m_labelGeode( new osg::Geode() ),
39 m_gridGeometryUpdate( true ),
41 m_bbColor( WColor( 0.3, 0.3, 0.3, 1.0 ) ),
42 m_gridColor( WColor( 0.1, 0.1, 0.1, 1.0 ) ),
54 label->setAlignment( osgText::Text::CENTER_TOP );
55 label->setColor( osg::Vec4( 1.0f, 1.0f, 1.0f, 1.0f ) );
61 label->setPosition( osg::Vec3( 0.0, 0.0, 0.0 ) );
62 label->setCharacterSize( 6 );
68 label->setPosition( osg::Vec3( 1.0, 0.0, 0.0 ) );
74 label->setPosition( osg::Vec3( 1.0, 1.0, 0.0 ) );
80 label->setPosition( osg::Vec3( 0.0, 1.0, 0.0 ) );
87 label->setPosition( osg::Vec3( 0.0, 0.0, 1.0 ) );
93 label->setPosition( osg::Vec3( 1.0, 0.0, 1.0 ) );
99 label->setPosition( osg::Vec3( 1.0, 1.0, 1.0 ) );
105 label->setPosition( osg::Vec3( 0.0, 1.0, 1.0 ) );
120 getOrCreateStateSet()->setMode( GL_BLEND, osg::StateAttribute::OFF );
122 getOrCreateStateSet()->setMode( GL_LIGHTING, osg::StateAttribute::OFF | osg::StateAttribute::PROTECTED );
226 std::string vec2str( osg::Vec3 vec )
228 std::ostringstream os;
230 os <<
"(" << vec[0] <<
"," << vec[1] <<
"," << vec[2] <<
")";
242 osg::Matrix m = osg::Matrix::scale( grid->getNbCoordsX() - 1, grid->getNbCoordsY() - 1, grid->getNbCoordsZ() - 1 ) *
243 static_cast< osg::Matrixd
>(
static_cast< WMatrix4d >( grid->getTransform() ) );
247 for(
size_t i = 0; i < 8; ++i )
258 osg::ref_ptr< osg::Vec4Array > colors = osg::ref_ptr< osg::Vec4Array >(
new osg::Vec4Array );
260 m_boundaryGeode->getDrawable( 0 )->asGeometry()->setColorArray( colors );
261 m_boundaryGeode->getDrawable( 0 )->asGeometry()->setColorBinding( osg::Geometry::BIND_OVERALL );
266 osg::ref_ptr< osg::Vec4Array > colors = osg::ref_ptr< osg::Vec4Array >(
new osg::Vec4Array );
269 m_innerGridGeode->getDrawable( 0 )->asGeometry()->setColorBinding( osg::Geometry::BIND_OVERALL );
284 osg::Geometry* gridGeometry =
new osg::Geometry();
285 osg::ref_ptr< osg::Vec3Array > vertArray =
new osg::Vec3Array( grid->size() );
287 osg::DrawElementsUInt* gridElement =
new osg::DrawElementsUInt( osg::PrimitiveSet::LINES, 0 );
288 gridElement->reserve( grid->size() * 2 );
290 size_t sx = grid->getNbCoordsX();
291 size_t sy = grid->getNbCoordsY();
292 size_t sz = grid->getNbCoordsZ();
293 for(
unsigned int vertIdX = 0; vertIdX < sx; ++vertIdX )
295 for(
unsigned int vertIdY = 0; vertIdY < sy; ++vertIdY )
297 for(
unsigned int vertIdZ = 0; vertIdZ < sz; ++vertIdZ )
299 size_t id = vertIdX + vertIdY * sx + vertIdZ * sx * sy;
301 ( *vertArray )[id][0] =
static_cast< float >( vertIdX ) /
static_cast< float >( sx - 1 );
302 ( *vertArray )[id][1] =
static_cast< float >( vertIdY ) /
static_cast< float >( sy - 1 );
303 ( *vertArray )[id][2] =
static_cast< float >( vertIdZ ) /
static_cast< float >( sz - 1 );
305 if( vertIdX < sx - 1 )
307 gridElement->push_back(
id );
308 gridElement->push_back(
id + 1 );
311 if( vertIdY < sy - 1 )
313 gridElement->push_back(
id );
314 gridElement->push_back(
id + sx );
317 if( vertIdZ < sz - 1 )
319 gridElement->push_back(
id );
320 gridElement->push_back(
id + sx * sy );
327 gridGeometry->setVertexArray( vertArray );
328 gridGeometry->addPrimitiveSet( gridElement );
330 osg::ref_ptr< osg::Vec4Array > colors = osg::ref_ptr< osg::Vec4Array >(
new osg::Vec4Array );
333 gridGeometry->setColorArray( colors );
334 gridGeometry->setColorBinding( osg::Geometry::BIND_OVERALL );
This callback allows you a simple usage of callbacks in your module.
osg::ref_ptr< osg::Geode > m_boundaryGeode
The geometry for the boundary.
WGELabel::SPtr m_borderLabels[8]
The labels at the corner.
bool m_gridUpdate
If true, the labels and geometry gets adapted properly.
osg::ref_ptr< osg::Geode > m_labelGeode
The geode keeping the labels.
virtual ~WGEGridNode()
Destructor.
void setGridLineWidth(int linewidth=1)
Set the line width of the gird.
void setEnableLabels(bool enable=true)
En- or disable labels on the boundary corners.
void setGridColor(const WColor &color)
Sets the color of the rendered grid.
bool m_showLabels
If true, labels get used.
int getGridLineWidth() const
Get the line width of the gird.
void callback(osg::Node *node)
The actual callback handling changes in the grid.
WColor m_bbColor
The color of bbox/grid.
WGridRegular3D::ConstSPtr getGrid() const
Returns the currently set grid.
bool m_showGrid
True if the grid should be rendered.
bool m_gridGeometryUpdate
If true, the inner grid geometry gets recreated.
WSharedObject< WGridRegular3D::ConstSPtr > m_grid
The actual grid which should be represented by this node.
bool m_showBBox
True if the bbox should be rendered.
void setEnableGrid(bool enable=true)
En- or disable grid mode.
osg::ref_ptr< osg::Geode > m_innerGridGeode
The geometry for the whole grid.
bool getEnableBBox() const
Returns whether bbox mode is enabled or not.
int m_boxLineWidth
The line width of the box.
void setBoxLineWidth(int linewidth=4)
Set the line width of the bounding box.
bool getEnableGrid() const
Returns whether grid mode is enabled or not.
void setBBoxColor(const WColor &color)
Sets the color of the rendered bbox.
WColor m_gridColor
The color of the grid.
void setGrid(WGridRegular3D::ConstSPtr grid)
Updates the node to use the new specified grid.
int getBoxLineWidth() const
get the line width of the bounding box.
WGEGridNode(WGridRegular3D::ConstSPtr grid)
Creates a node representing the specified grid.
void setEnableBBox(bool enable=true)
En- or disable bbox mode.
bool getEnableLabels() const
Returns whether labels on the corners are enabled or not.
const WColor & getBBoxColor() const
The currently set color used for rendering the bbox.
const WColor & getGridColor() const
The currently set color used for rendering the grid.
int m_gridLineWidth
Line width used for the grid.
osg::ref_ptr< WGELabel > SPtr
Convenience typedef for a osg::ref_ptr< WGELabel >.
std::shared_ptr< const WGridRegular3DTemplate > ConstSPtr
Convenience typedef for a std::shared_ptr< const WGridRegular3DTemplate >.
ReadTicket getReadTicket() const
Returns a ticket to get read access to the contained data.
WriteTicket getWriteTicket(bool suppressNotify=false) const
Returns a ticket to get write access to the contained data.
osg::ref_ptr< osg::Geometry > createUnitCubeAsLines(const WColor &color, bool asLines=false)
Creates a osg::Geometry containing an unit cube as line-strips, having 3D texture coordinates.