31 #include <osg/Material>
32 #include <osg/MatrixTransform>
33 #include <osg/Projection>
34 #include <osg/ShapeDrawable>
35 #include <osg/StateAttribute>
37 #include "WMSurfaceParameterAnimator.h"
38 #include "WMSurfaceParameterAnimator.xpm"
39 #include "core/common/WBoundingBox.h"
40 #include "core/common/WColor.h"
41 #include "core/dataHandler/WDataTexture3D.h"
42 #include "core/graphicsEngine/WGEGeodeUtils.h"
43 #include "core/graphicsEngine/WGEUtils.h"
44 #include "core/graphicsEngine/callbacks/WGEShaderAnimationCallback.h"
45 #include "core/graphicsEngine/shaders/WGEShader.h"
46 #include "core/kernel/WKernel.h"
70 return WMSurfaceParameterAnimator_xpm;
76 return "Surface Parameter Animator";
82 return "This module can show parameters defined on surfaces using various types of animation.";
88 m_input = std::shared_ptr< WModuleInputData < WDataSetSingle > >(
96 m_tracesInput = std::shared_ptr< WModuleInputData < WDataSetSingle > >(
112 m_isoValue =
m_properties->addProperty(
"Isovalue",
"The Isovalue used whenever the Isosurface Mode is turned on.",
114 m_stepCount =
m_properties->addProperty(
"Step count",
"The number of steps to walk along the ray during raycasting. A low value"
115 "may cause artifacts whilst a high value slows down rendering.", 250 );
119 m_alpha =
m_properties->addProperty(
"Opacity %",
"The opacity in %. Transparency = 100 - Opacity.", 100 );
121 m_isoColor =
m_properties->addProperty(
"Iso color",
"The color to blend the isosurface with.", WColor( 0.0, 0.0, 0.0, 1.0 ),
124 m_size1 =
m_properties->addProperty(
"Beam1 size",
"The relative size of the first beam. A value of 0 gets mapped to the "
125 "smallest size, whilst 100 gets mapped to the largest. This is typically "
126 "one third of the size of the voxelized surface.", 10 );
127 m_size2 =
m_properties->addProperty(
"Beam2 size",
"The relative size of the second beam. A value of 0 gets mapped to the "
128 "smallest size, whilst 100 gets mapped to the largest. This is typically "
129 "one third of the size of the voxelized surface.", 50 );
130 m_speed1 =
m_properties->addProperty(
"Beam1 speed",
"The relative speed of the beam. This speed relates to the clock used.", 25 );
131 m_speed2 =
m_properties->addProperty(
"Beam2 speed",
"The relative speed of the beam. This speed relates to the clock used.", 25 );
132 m_parameterScale =
m_properties->addProperty(
"Parameter scale",
"Scaling the parameter space on the fly creates consistently sized and fast "
133 "beams over multiple WMSurfaceParameterAnimator instances.", 1.0 );
143 cube->asTransform()->getChild( 0 )->setName(
"DVR Proxy Cube" );
147 osg::StateSet* rootState = cube->getOrCreateStateSet();
149 osg::ref_ptr< WGETexture3D > texture3D =
m_dataSet->getTexture();
150 osg::ref_ptr< WGETexture3D > tracesTexture3D =
m_tracesDataSet->getTexture();
151 texture3D->bind( cube, 0 );
152 tracesTexture3D->bind( cube, 1 );
155 rootState->setMode( GL_BLEND, osg::StateAttribute::ON );
161 osg::ref_ptr< osg::Uniform > isovalue =
new osg::Uniform(
"u_isovalue",
static_cast< float >(
m_isoValue->get() / 100.0 ) );
164 osg::ref_ptr< osg::Uniform > steps =
new osg::Uniform(
"u_steps",
m_stepCount->get() );
167 osg::ref_ptr< osg::Uniform > alpha =
new osg::Uniform(
"u_alpha",
static_cast< float >(
m_alpha->get() / 100.0 ) );
170 osg::ref_ptr< osg::Uniform > animationTime =
new osg::Uniform(
"u_animationTime", 0 );
173 osg::ref_ptr< osg::Uniform > size1 =
new osg::Uniform(
"u_size1", 0 );
174 osg::ref_ptr< osg::Uniform > size2 =
new osg::Uniform(
"u_size2", 0 );
178 osg::ref_ptr< osg::Uniform > speed1 =
new osg::Uniform(
"u_speed1", 0 );
179 osg::ref_ptr< osg::Uniform > speed2 =
new osg::Uniform(
"u_speed2", 0 );
183 osg::ref_ptr< osg::Uniform > paramScale =
new osg::Uniform(
"u_parameterScale", 1.0f );
186 osg::ref_ptr< osg::Uniform > saturation =
new osg::Uniform(
"u_saturation", 1.0f );
189 rootState->addUniform( isovalue );
190 rootState->addUniform( steps );
191 rootState->addUniform( alpha );
192 rootState->addUniform( animationTime );
193 rootState->addUniform( size1 );
194 rootState->addUniform( size2 );
195 rootState->addUniform( speed1 );
196 rootState->addUniform( speed2 );
197 rootState->addUniform( paramScale );
198 rootState->addUniform( saturation );
232 std::shared_ptr< WDataSetSingle > newDataSet =
m_input->getData();
233 std::shared_ptr< WDataSetSingle > newTracesDataSet =
m_tracesInput->getData();
236 bool dataValid = ( newDataSet && newTracesDataSet );
252 if( dataChanged && dataValid )
257 debugLog() <<
"Data changed. Uploading new data as texture.";
260 std::shared_ptr< WGridRegular3D > grid = std::dynamic_pointer_cast< WGridRegular3D >(
m_dataSet->getGrid() );
263 errorLog() <<
"The dataset does not provide a regular grid. Ignoring dataset.";
268 osg::ref_ptr< osg::Node > cube =
renderSurface( grid->getBoundingBox() );
275 debugLog() <<
"Adding new rendering.";
292 osg::ref_ptr< osg::Material > mat =
new osg::Material();
294 node->getOrCreateStateSet()->setAttribute( mat, osg::StateAttribute::ON );
299 traverse( node, nv );
305 if( m_module->m_isoValue->changed() && ( uniform->getName() ==
"u_isovalue" ) )
307 uniform->set(
static_cast< float >( m_module->m_isoValue->get(
true ) ) / 100.0f );
309 if( m_module->m_stepCount->changed() && ( uniform->getName() ==
"u_steps" ) )
311 uniform->set( m_module->m_stepCount->get(
true ) );
313 if( m_module->m_alpha->changed() && ( uniform->getName() ==
"u_alpha" ) )
315 uniform->set(
static_cast< float >( m_module->m_alpha->get(
true ) / 100.0 ) );
317 if( m_module->m_alpha->changed() && ( uniform->getName() ==
"u_size1" ) )
319 uniform->set(
static_cast< float >( m_module->m_alpha->get(
true ) / 100.0 ) );
321 if( m_module->m_size1->changed() && ( uniform->getName() ==
"u_size1" ) )
323 uniform->set( m_module->m_size1->get(
true ) );
325 if( m_module->m_size2->changed() && ( uniform->getName() ==
"u_size2" ) )
327 uniform->set( m_module->m_size2->get(
true ) );
329 if( m_module->m_speed1->changed() && ( uniform->getName() ==
"u_speed1" ) )
331 uniform->set( m_module->m_speed1->get(
true ) );
333 if( m_module->m_speed2->changed() && ( uniform->getName() ==
"u_speed2" ) )
335 uniform->set( m_module->m_speed2->get(
true ) );
337 if( m_module->m_parameterScale->changed() && ( uniform->getName() ==
"u_parameterScale" ) )
339 uniform->set(
static_cast< float >( m_module->m_parameterScale->get(
true ) ) );
341 if( m_module->m_saturation->changed() && ( uniform->getName() ==
"u_saturation" ) )
343 uniform->set(
static_cast< float >( m_module->m_saturation->get(
true ) ) / 100.0f );
virtual void wait() const
Wait for the condition.
void setResetable(bool resetable=true, bool autoReset=true)
Sets the resetable flag.
virtual void add(std::shared_ptr< WCondition > condition)
Adds another condition to the set of conditions to wait for.
Class to encapsulate boost::condition_variable_any.
Class to wrap around the osg Group node and providing a thread safe add/removal mechanism.
This is a uniform callback setting the uniform to the current time in milliseconds,...
Class encapsulating the OSG Program class for a more convenient way of adding and modifying shader.
static WKernel * getRunningKernel()
Returns pointer to the currently running kernel.
std::shared_ptr< WGraphicsEngine > getGraphicsEngine() const
Returns pointer to currently running instance of graphics engine.
Node callback to change the color of the shapes inside the root node.
bool m_initialUpdate
Denotes whether the update callback is called the first time.
virtual void operator()(osg::Node *node, osg::NodeVisitor *nv)
operator () - called during the update traversal.
WMSurfaceParameterAnimator * m_module
Pointer used to access members of the module to modify the node.
This module is a ray-tracing based isosurface using special methods for animating particle flow on it...
WPropInt m_isoValue
The Isovalue used in the case m_isoSurface is true.
virtual const std::string getDescription() const
Gives back a description of this module.
WPropInt m_speed2
The speed of beam 2 on the surface.
std::shared_ptr< WCondition > m_propCondition
A condition used to notify about changes in several properties.
std::shared_ptr< WDataSetSingle > m_tracesDataSet
The dataset containing the fiber traces in each voxel in m_dataSet.
virtual ~WMSurfaceParameterAnimator()
Destructor.
WPropInt m_saturation
Saturation of final rendering.
std::shared_ptr< WModuleInputData< WDataSetSingle > > m_input
An input connector used to get datasets from other modules.
std::shared_ptr< WDataSetSingle > m_dataSet
This is a pointer to the dataset the module is currently working on.
WPropInt m_speed1
The speed of beam 1 on the surface.
WPropDouble m_parameterScale
Scaling the parameter space ensures consistent sizes and speeds along multiple WMSurfaceParameterAnim...
virtual const std::string getName() const
Gives back the name of this module.
WPropInt m_alpha
The alpha transparency used for the rendering.
WPropColor m_isoColor
The color used when in isosurface mode for blending.
osg::ref_ptr< osg::Node > renderSurface(const WBoundingBox &bbox)
Renders the surface to an FBO.
WPropInt m_size1
The size of beam 1.
WPropInt m_stepCount
The number of steps to walk along the ray.
WMSurfaceParameterAnimator()
Default constructor.
virtual void moduleMain()
Entry point after loading the module.
virtual void connectors()
Initialize the connectors this module is using.
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...
osg::ref_ptr< WGEShader > m_shader
the DVR shader.
virtual const char ** getXPMIcon() const
Get the icon for this module in XPM format.
osg::ref_ptr< WGEGroupNode > m_rootNode
The root node used for this modules graphics.
WPropInt m_size2
The size of beam 1.
std::shared_ptr< WModuleInputData< WDataSetSingle > > m_tracesInput
The input for the volumized fiber traces.
virtual void properties()
Initialize the properties for this module.
virtual void activate()
Callback for m_active.
Class representing a single module of OpenWalnut.
boost::filesystem::path m_localPath
The path where the module binary resides in.
virtual void properties()
Initialize properties in this function.
wlog::WStreamedLogger debugLog() const
Logger instance for comfortable debug logging.
void addConnector(std::shared_ptr< WModuleInputConnector > con)
Adds the specified connector to the list of inputs.
std::shared_ptr< WProperties > m_properties
The property object for the module.
void ready()
Call this whenever your module is ready and can react on property changes.
WConditionSet m_moduleState
The internal state of the module.
wlog::WStreamedLogger errorLog() const
Logger instance for comfortable error logging.
virtual void activate()
Callback for m_active.
WPropBool m_active
True whenever the module should be active.
virtual void connectors()
Initialize connectors in this function.
WBoolFlag m_shutdownFlag
Condition getting fired whenever the thread should quit.
osg::ref_ptr< osg::Node > generateSolidBoundingBoxNode(const WBoundingBox &bb, const WColor &color, bool threeDTexCoords=true)
Generates an OSG node for the specified bounding box.