25 #ifndef WMVECTORPLOT_H
26 #define WMVECTORPLOT_H
33 #include <osg/Geometry>
35 #include "core/common/math/linearAlgebra/WPosition.h"
36 #include "core/dataHandler/WDataSetVector.h"
37 #include "core/graphicsEngine/shaders/WGEShader.h"
38 #include "core/kernel/WKernel.h"
39 #include "core/kernel/WModule.h"
40 #include "core/kernel/WModuleInputData.h"
41 #include "core/kernel/WModuleOutputData.h"
64 virtual const std::string
getName()
const;
78 virtual std::shared_ptr< WModule >
factory()
const;
119 template<
typename ValueType >
143 std::shared_ptr< WModuleInputData< WDataSetVector > >
m_input;
181 template<
typename ValueType >
184 std::shared_ptr< WProgress > progress(
new WProgress(
"Vector Plot", 4 ) );
189 std::shared_ptr< WGridRegular3D > grid = std::dynamic_pointer_cast< WGridRegular3D >(
m_dataSet->getGrid() );
190 std::shared_ptr< WValueSet< ValueType > > vals = std::dynamic_pointer_cast< WValueSet< ValueType > >(
m_dataSet->getValueSet() );
192 int maxX = grid->getNbCoordsX() - 1;
193 int maxY = grid->getNbCoordsY() - 1;
194 int maxZ = grid->getNbCoordsZ() - 1;
199 m_xSlice->setMax( grid->getNbCoordsX() - 1 );
200 m_ySlice->setMax( grid->getNbCoordsY() - 1 );
201 m_zSlice->setMax( grid->getNbCoordsZ() - 1 );
203 WPosition texPos = grid->worldCoordToTexCoord( current );
204 double xSlice = texPos[0] * grid->getNbCoordsX() - 0.5;
205 double ySlice = texPos[1] * grid->getNbCoordsY() - 0.5;
206 double zSlice = texPos[2] * grid->getNbCoordsZ() - 0.5;
216 ref_ptr< osg::Vec3Array > vertices = ref_ptr< osg::Vec3Array >(
new osg::Vec3Array );
217 ref_ptr< osg::Vec4Array > colors = ref_ptr< osg::Vec4Array >(
new osg::Vec4Array );
218 ref_ptr< osg::Geometry > geometry = ref_ptr< osg::Geometry >(
new osg::Geometry );
220 WColor color =
m_aColor->get(
true );
222 float scaling =
m_scale->get(
true );
224 if( ( ( *m_dataSet ).getValueSet()->order() == 1 ) && ( ( *m_dataSet ).getValueSet()->dimension() == 3 ) )
228 for(
int x = 0; x < nbX; ++x )
230 for(
int y = 0; y < nbY; ++y )
232 float vecCompX = vals->getScalar( ( x + y * nbX +
static_cast< int >( zSlice ) * nbX * nbY ) * 3 ) / 2. * scaling;
233 float vecCompY = vals->getScalar( ( x + y * nbX +
static_cast< int >( zSlice ) * nbX * nbY ) * 3 + 1 ) / 2. * scaling;
234 float vecCompZ = vals->getScalar( ( x + y * nbX +
static_cast< int >( zSlice ) * nbX * nbY ) * 3 + 2 ) / 2. * scaling;
238 vertices->push_back( osg::Vec3( x - vecCompX, y - vecCompY, zSlice - vecCompZ ) );
239 vertices->push_back( osg::Vec3( x + vecCompX, y + vecCompY, zSlice + vecCompZ ) );
242 colors->push_back( osg::Vec4( fabs( vecCompX ), fabs( vecCompY ), fabs( vecCompZ ), 1.0 ) );
243 colors->push_back( osg::Vec4( fabs( vecCompX ), fabs( vecCompY ), fabs( vecCompZ ), 1.0 ) );
247 colors->push_back( color );
248 colors->push_back( color );
253 vertices->push_back( osg::Vec3( x - vecCompX, y - vecCompY, zSlice - 0.01f ) );
254 vertices->push_back( osg::Vec3( x + vecCompX, y + vecCompY, zSlice - 0.01f ) );
255 vertices->push_back( osg::Vec3( x - vecCompX, y - vecCompY, zSlice + 0.01f ) );
256 vertices->push_back( osg::Vec3( x + vecCompX, y + vecCompY, zSlice + 0.01f ) );
259 colors->push_back( osg::Vec4( fabs( vecCompX ), fabs( vecCompY ), fabs( vecCompZ ), 1.0 ) );
260 colors->push_back( osg::Vec4( fabs( vecCompX ), fabs( vecCompY ), fabs( vecCompZ ), 1.0 ) );
261 colors->push_back( osg::Vec4( fabs( vecCompX ), fabs( vecCompY ), fabs( vecCompZ ), 1.0 ) );
262 colors->push_back( osg::Vec4( fabs( vecCompX ), fabs( vecCompY ), fabs( vecCompZ ), 1.0 ) );
266 colors->push_back( color );
267 colors->push_back( color );
268 colors->push_back( color );
269 colors->push_back( color );
280 for(
int x = 0; x < nbX; ++x )
282 for(
int z = 0; z < nbZ; ++z )
284 float vecCompX = vals->getScalar( ( x +
static_cast< int >( ySlice ) * nbX + z * nbX * nbY ) * 3 ) / 2. * scaling;
285 float vecCompY = vals->getScalar( ( x +
static_cast< int >( ySlice ) * nbX + z * nbX * nbY ) * 3 + 1 ) / 2. * scaling;
286 float vecCompZ = vals->getScalar( ( x +
static_cast< int >( ySlice ) * nbX + z * nbX * nbY ) * 3 + 2 ) / 2. * scaling;
290 vertices->push_back( osg::Vec3( x - vecCompX, ySlice - vecCompY, z - vecCompZ ) );
291 vertices->push_back( osg::Vec3( x + vecCompX, ySlice + vecCompY, z + vecCompZ ) );
294 colors->push_back( osg::Vec4( fabs( vecCompX ), fabs( vecCompY ), fabs( vecCompZ ), 1.0 ) );
295 colors->push_back( osg::Vec4( fabs( vecCompX ), fabs( vecCompY ), fabs( vecCompZ ), 1.0 ) );
299 colors->push_back( color );
300 colors->push_back( color );
305 vertices->push_back( osg::Vec3( x - vecCompX, ySlice - 0.01f, z - vecCompZ ) );
306 vertices->push_back( osg::Vec3( x + vecCompX, ySlice - 0.01f, z + vecCompZ ) );
307 vertices->push_back( osg::Vec3( x - vecCompX, ySlice + 0.01f, z - vecCompZ ) );
308 vertices->push_back( osg::Vec3( x + vecCompX, ySlice + 0.01f, z + vecCompZ ) );
311 colors->push_back( osg::Vec4( fabs( vecCompX ), fabs( vecCompY ), fabs( vecCompZ ), 1.0 ) );
312 colors->push_back( osg::Vec4( fabs( vecCompX ), fabs( vecCompY ), fabs( vecCompZ ), 1.0 ) );
313 colors->push_back( osg::Vec4( fabs( vecCompX ), fabs( vecCompY ), fabs( vecCompZ ), 1.0 ) );
314 colors->push_back( osg::Vec4( fabs( vecCompX ), fabs( vecCompY ), fabs( vecCompZ ), 1.0 ) );
318 colors->push_back( color );
319 colors->push_back( color );
320 colors->push_back( color );
321 colors->push_back( color );
332 for(
int y = 0; y < nbY; ++y )
334 for(
int z = 0; z < nbZ; ++z )
336 float vecCompX = vals->getScalar( (
static_cast< int >( xSlice ) + y * nbX + z * nbX * nbY ) * 3 ) / 2. * scaling;
337 float vecCompY = vals->getScalar( (
static_cast< int >( xSlice ) + y * nbX + z * nbX * nbY ) * 3 + 1 ) / 2. * scaling;
338 float vecCompZ = vals->getScalar( (
static_cast< int >( xSlice ) + y * nbX + z * nbX * nbY ) * 3 + 2 ) / 2. * scaling;
342 vertices->push_back( osg::Vec3( xSlice + vecCompX, y + vecCompY, z + vecCompZ ) );
343 vertices->push_back( osg::Vec3( xSlice - vecCompX, y - vecCompY, z - vecCompZ ) );
346 colors->push_back( osg::Vec4( fabs( vecCompX ), fabs( vecCompY ), fabs( vecCompZ ), 1.0 ) );
347 colors->push_back( osg::Vec4( fabs( vecCompX ), fabs( vecCompY ), fabs( vecCompZ ), 1.0 ) );
351 colors->push_back( color );
352 colors->push_back( color );
357 vertices->push_back( osg::Vec3( xSlice - 0.01f, y + vecCompY, z + vecCompZ ) );
358 vertices->push_back( osg::Vec3( xSlice - 0.01f, y - vecCompY, z - vecCompZ ) );
359 vertices->push_back( osg::Vec3( xSlice + 0.01f, y + vecCompY, z + vecCompZ ) );
360 vertices->push_back( osg::Vec3( xSlice + 0.01f, y - vecCompY, z - vecCompZ ) );
363 colors->push_back( osg::Vec4( fabs( vecCompX ), fabs( vecCompY ), fabs( vecCompZ ), 1.0 ) );
364 colors->push_back( osg::Vec4( fabs( vecCompX ), fabs( vecCompY ), fabs( vecCompZ ), 1.0 ) );
365 colors->push_back( osg::Vec4( fabs( vecCompX ), fabs( vecCompY ), fabs( vecCompZ ), 1.0 ) );
366 colors->push_back( osg::Vec4( fabs( vecCompX ), fabs( vecCompY ), fabs( vecCompZ ), 1.0 ) );
370 colors->push_back( color );
371 colors->push_back( color );
372 colors->push_back( color );
373 colors->push_back( color );
385 for(
size_t i = 0; i < vertices->size(); ++i )
387 osg::DrawElementsUInt* line =
new osg::DrawElementsUInt( osg::PrimitiveSet::LINES, 0 );
388 line->push_back( i );
389 line->push_back( i + 1 );
391 geometry->addPrimitiveSet( line );
395 geometry->setVertexArray( vertices );
396 geometry->setColorArray( colors );
397 geometry->setColorBinding( osg::Geometry::BIND_PER_VERTEX );
std::shared_ptr< WSelectionManager > getSelectionManager()
get for selection manager
static WKernel * getRunningKernel()
Returns pointer to the currently running kernel.
Show an glyph plot (in this case the glyphs are arrows) of a vector data set.
virtual void activate()
Callback for m_active.
virtual void connectors()
Initialize the connectors this module is using.
WPropBool m_showOnAxial
indicates whether the vector should be shown on axial slice
void transformVerts(osg::ref_ptr< osg::Vec3Array > verts)
Transforms the given vertices according to m_matrix.
osg::ref_ptr< WGEShader > m_shader
the shader object for this module
WPropBool m_coloringMode
indicates a set color or direction color coding.
std::shared_ptr< WDataSetVector > m_dataSet
This is a pointer to the dataset the module is currently working on.
WPropBool m_projectOnSlice
projects the vectors on the slice.
WPropBool m_showOnSagittal
indicates whether the vector should be shown on sagittal slice
void updateCallback()
The update callback that is called for the osg node of this module.
osg::ref_ptr< osg::Geode > m_rootNode
The root node used for this modules graphics.
WPropDouble m_scale
Scaling of arrow length.
WPropDouble m_xSlice
x position of the slice
virtual void moduleMain()
Entry point after loading the module.
virtual const char ** getXPMIcon() const
Get the icon for this module in XPM format.
WPropBool m_showOnCoronal
indicates whether the vector should be shown on coronal slice
virtual void properties()
Initialize the properties for this module.
osg::ref_ptr< osg::Geometry > buildPlotSlices()
Creates a vector plot on the currently selected slices.
virtual const std::string getDescription() const
Gives back a description of this module.
std::shared_ptr< WModuleInputData< WDataSetVector > > m_input
An input connector used to get datasets from other modules.
virtual const std::string getName() const
Gives back the name of this module.
WPropDouble m_ySlice
y position of the slice
std::shared_ptr< std::vector< WPosition > > m_positions
list of positions to plot vectors on, this will come from a selection tool class
virtual ~WMVectorPlot()
Destructor.
virtual std::shared_ptr< WModule > factory() const
Due to the prototype design pattern used to build modules, this method returns a new instance of this...
WMVectorPlot()
Default constructor.
WPosition m_oldPos
The previous position of the slides.
WPropDouble m_zSlice
z position of the slice
Class representing a single module of OpenWalnut.
std::shared_ptr< WProgressCombiner > m_progress
Progress indicator used as parent for all progress' of this module.
This only is a 3d double vector.
Class managing progress inside of modules.