28 #include <osg/LineWidth>
30 #include "../../common/math/linearAlgebra/WLinearAlgebra.h"
31 #include "../callbacks/WGEFunctorCallback.h"
32 #include "../WGEGeodeUtils.h"
33 #include "WGEGridNode.h"
36 m_boundaryGeode( new osg::
Geode() ),
37 m_innerGridGeode( new osg::
Geode() ),
38 m_labelGeode( new osg::
Geode() ),
40 m_gridGeometryUpdate( true ),
42 m_bbColor( WColor( 0.3, 0.3, 0.3, 1.0 ) ),
43 m_gridColor( WColor( 0.1, 0.1, 0.1, 1.0 ) )
53 label->setAlignment( osgText::Text::CENTER_TOP );
54 label->setColor( osg::Vec4( 1.0f, 1.0f, 1.0f, 1.0f ) );
60 label->setPosition( osg::Vec3( 0.0, 0.0, 0.0 ) );
61 label->setCharacterSize( 6 );
67 label->setPosition( osg::Vec3( 1.0, 0.0, 0.0 ) );
73 label->setPosition( osg::Vec3( 1.0, 1.0, 0.0 ) );
79 label->setPosition( osg::Vec3( 0.0, 1.0, 0.0 ) );
86 label->setPosition( osg::Vec3( 0.0, 0.0, 1.0 ) );
92 label->setPosition( osg::Vec3( 1.0, 0.0, 1.0 ) );
98 label->setPosition( osg::Vec3( 1.0, 1.0, 1.0 ) );
104 label->setPosition( osg::Vec3( 0.0, 1.0, 1.0 ) );
113 m_boundaryGeode->getOrCreateStateSet()->setAttributeAndModes(
new osg::LineWidth( 4.0 ), osg::StateAttribute::ON );
118 getOrCreateStateSet()->setMode( GL_BLEND, osg::StateAttribute::OFF );
120 getOrCreateStateSet()->setMode( GL_LIGHTING, osg::StateAttribute::OFF | osg::StateAttribute::PROTECTED );
202 std::string vec2str( osg::Vec3 vec )
204 std::ostringstream os;
206 os <<
"(" << vec[0] <<
"," << vec[1] <<
"," << vec[2] <<
")";
218 osg::Matrix m = osg::Matrix::scale( grid->getNbCoordsX() - 1, grid->getNbCoordsY() - 1, grid->getNbCoordsZ() - 1 ) *
219 static_cast< osg::Matrixd >( static_cast< WMatrix4d >( grid->getTransform() ) );
223 for(
size_t i = 0; i < 8; ++i )
234 osg::ref_ptr< osg::Vec4Array > colors = osg::ref_ptr< osg::Vec4Array >(
new osg::Vec4Array );
236 m_boundaryGeode->getDrawable( 0 )->asGeometry()->setColorArray( colors );
241 osg::ref_ptr< osg::Vec4Array > colors = osg::ref_ptr< osg::Vec4Array >(
new osg::Vec4Array );
255 osg::Geometry* gridGeometry =
new osg::Geometry();
256 osg::ref_ptr< osg::Vec3Array > vertArray =
new osg::Vec3Array( grid->size() );
258 osg::DrawElementsUInt* gridElement =
new osg::DrawElementsUInt( osg::PrimitiveSet::LINES, 0 );
259 gridElement->reserve( grid->size() * 2 );
261 size_t sx = grid->getNbCoordsX();
262 size_t sy = grid->getNbCoordsY();
263 size_t sz = grid->getNbCoordsZ();
264 for(
unsigned int vertIdX = 0; vertIdX < sx; ++vertIdX )
266 for(
unsigned int vertIdY = 0; vertIdY < sy; ++vertIdY )
268 for(
unsigned int vertIdZ = 0; vertIdZ < sz; ++vertIdZ )
270 size_t id = vertIdX + vertIdY * sx + vertIdZ * sx * sy;
272 ( *vertArray )[id][0] =
static_cast< float >( vertIdX ) / static_cast< float >( sx - 1 );
273 ( *vertArray )[id][1] =
static_cast< float >( vertIdY ) / static_cast< float >( sy - 1 );
274 ( *vertArray )[id][2] =
static_cast< float >( vertIdZ ) / static_cast< float >( sz - 1 );
276 if( vertIdX < sx - 1 )
278 gridElement->push_back(
id );
279 gridElement->push_back(
id + 1 );
282 if( vertIdY < sy - 1 )
284 gridElement->push_back(
id );
285 gridElement->push_back(
id + sx );
288 if( vertIdZ < sz - 1 )
290 gridElement->push_back(
id );
291 gridElement->push_back(
id + sx * sy );
298 gridGeometry->setVertexArray( vertArray );
299 gridGeometry->addPrimitiveSet( gridElement );
301 osg::ref_ptr< osg::Vec4Array > colors = osg::ref_ptr< osg::Vec4Array >(
new osg::Vec4Array );
304 gridGeometry->setColorArray( colors );
305 gridGeometry->setColorBinding( osg::Geometry::BIND_OVERALL );