31 #include <osg/Material>
32 #include <osg/ShapeDrawable>
33 #include <osg/StateAttribute>
35 #include "WMIsosurfaceRaytracer.h"
36 #include "WMIsosurfaceRaytracer.xpm"
37 #include "core/common/WColor.h"
38 #include "core/common/WPropertyHelper.h"
39 #include "core/dataHandler/WDataSetScalar.h"
40 #include "core/dataHandler/WDataSetVector.h"
41 #include "core/dataHandler/WDataTexture3D.h"
42 #include "core/graphicsEngine/WGEColormapping.h"
43 #include "core/graphicsEngine/WGEGeodeUtils.h"
44 #include "core/graphicsEngine/WGEManagedGroupNode.h"
45 #include "core/graphicsEngine/WGERequirement.h"
46 #include "core/graphicsEngine/WGETextureUtils.h"
47 #include "core/graphicsEngine/WGEUtils.h"
48 #include "core/graphicsEngine/callbacks/WGENodeMaskCallback.h"
49 #include "core/graphicsEngine/postprocessing/WGEPostprocessingNode.h"
50 #include "core/graphicsEngine/shaders/WGEPropertyUniform.h"
51 #include "core/graphicsEngine/shaders/WGEShader.h"
52 #include "core/graphicsEngine/shaders/WGEShaderDefineOptions.h"
53 #include "core/graphicsEngine/shaders/WGEShaderPropertyDefine.h"
54 #include "core/graphicsEngine/shaders/WGEShaderPropertyDefineOptions.h"
55 #include "core/kernel/WKernel.h"
78 return isosurfaceraytracer_xpm;
84 return "Isosurface Raytracer";
90 return "This module shows a fast raytraced isosurface of the specified scalar dataset.";
96 m_input = std::shared_ptr< WModuleInputData < WDataSetScalar > >(
115 m_isoValue =
m_properties->addProperty(
"Isovalue",
"The isovalue used whenever the isosurface Mode is turned on.",
118 m_isoColor =
m_properties->addProperty(
"Iso color",
"The color to blend the isosurface with.", WColor( 1.0, 1.0, 1.0, 1.0 ),
121 m_stepCount =
m_properties->addProperty(
"Step count",
"The number of steps to walk along the ray during raycasting. A low value "
122 "may cause artifacts whilst a high value slows down rendering.", 250 );
126 m_epsilon =
m_properties->addProperty(
"Epsilon",
"The value defines the precision of iso-value checking. The lower the "
127 "value, the higher the precision.", 0.1 );
131 m_alpha =
m_properties->addProperty(
"Opacity %",
"The opacity in %. Transparency = 1 - Opacity.", 1.0 );
135 m_colormapRatio =
m_properties->addProperty(
"Colormap ratio",
"The intensity of the colormap in contrast to surface shading.", 0.5 );
139 m_phongShading =
m_properties->addProperty(
"Phong shading",
"If enabled, Phong shading gets applied on a per-pixel basis.",
true );
141 m_phongNoSpec =
m_properties->addProperty(
"No specular highlights",
"Disables specular highlights on the surface. This is especially "
142 "useful when these highlights tamper with the colormap.",
false );
145 "noise effect.",
true );
147 m_borderClip =
m_properties->addProperty(
"Border clip",
"If enabled, a certain area on the volume boundary can be clipped. This is useful "
148 "for noise and non-peeled data but will consume a lot of GPU power.",
false );
190 debugLog() <<
"Module is now ready.";
193 osg::ref_ptr< WGEGroupNode > rootNode =
new WGEGroupNode();
205 postNode->insert( rootNode,
m_shader );
206 bool postNodeInserted =
false;
226 std::shared_ptr< WDataSetScalar > dataSet =
m_input->getData();
227 bool dataValid = ( dataSet != NULL );
244 if( dataUpdated && dataValid )
246 debugLog() <<
"Data changed. Uploading new data as texture.";
248 m_isoValue->setMin( dataSet->getTexture()->minimum()->get() );
249 m_isoValue->setMax( dataSet->getTexture()->scale()->get() + dataSet->getTexture()->minimum()->get() );
250 m_isoValue->setRecommendedValue( dataSet->getTexture()->minimum()->get() + ( 0.5 * dataSet->getTexture()->scale()->get() ) );
253 std::shared_ptr< WGridRegular3D > grid = std::dynamic_pointer_cast< WGridRegular3D >( dataSet->getGrid() );
256 errorLog() <<
"The dataset does not provide a regular grid. Ignoring dataset.";
262 WPosition( grid->getNbCoordsX() - 1, grid->getNbCoordsY() - 1, grid->getNbCoordsZ() - 1 ) );
264 cube->asTransform()->getChild( 0 )->setName(
"_DVR Proxy Cube" );
267 rootNode->setMatrix(
static_cast< WMatrix4d >( grid->getTransform() ) );
270 osg::StateSet* rootState = cube->getOrCreateStateSet();
276 osg::ref_ptr< WGETexture3D > texture3D = dataSet->getTexture();
277 texture3D->bind( cube );
289 const size_t size = 64;
294 std::shared_ptr< WDataSetVector > gradients =
m_gradients->getData();
297 debugLog() <<
"Uploading specified gradient field.";
300 osg::ref_ptr< WDataTexture3D > gradTexture3D = gradients->getTexture();
302 gradTexEnableDefine->setActive(
true );
306 gradTexEnableDefine->setActive(
false );
311 debugLog() <<
"Adding new rendering.";
313 rootNode->insert( cube );
316 if( !postNodeInserted )
318 postNodeInserted =
true;
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.
static void apply(osg::ref_ptr< osg::Node > node, WMatrix4d preTransform=WMatrix4d::identity(), osg::ref_ptr< WGEShader > shader=osg::ref_ptr< WGEShader >(), size_t startTexUnit=0)
Apply the colormapping to the specified node.
Class to wrap around the osg Group node and providing a thread safe add/removal mechanism.
This callback is useful to en-/disable nodes using the node mask based on properties.
This class enables you to add arbitrary nodes that get post-processed in screen space.
This requirement ensures an up and running WGE.
std::shared_ptr< WGEShaderDefine< ValueType > > SPtr
Shared pointer for this class.
std::shared_ptr< WGEShaderPreprocessor > SPtr
Shared pointer for this class.
This is a WGEShaderDefineOptions class which additionally uses a property to automatically control th...
This class is able to provide arbitrary values as define statements in GLSL code.
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.
This module builds the base for fast raytracing of isosurfacesin OpenWalnut.
std::shared_ptr< WModuleInputData< WDataSetScalar > > m_input
An input connector used to get datasets from other modules.
osg::ref_ptr< WGEShader > m_shader
the DVR shader.
virtual void properties()
Initialize the properties for this module.
virtual ~WMIsosurfaceRaytracer()
Destructor.
WPropDouble m_epsilon
The numeric precision used for iso-checking.
virtual void requirements()
Initialize requirements for this module.
WPropDouble m_isoValue
The Isovalue used in the case m_isoSurface is true.
virtual const std::string getName() const
Gives back the name of this module.
WPropBool m_phongNoSpec
Some special coloring mode for disabling specular hightlights.
virtual const std::string getDescription() const
Gives back a description of this module.
virtual const char ** getXPMIcon() const
Get the icon for this module in XPM format.
WPropColor m_isoColor
The color used when in isosurface mode for blending.
WPropBool m_stochasticJitter
If true, the ray-tracer uses stochastic jitter to improve image quality.
WPropDouble m_alpha
The alpha transparency used for the rendering.
WPropDouble m_borderClipDistance
The distance used for clipping.
std::shared_ptr< WModuleInputData< WDataSetVector > > m_gradients
The gradient field input.
WMIsosurfaceRaytracer()
Default constructor.
WPropBool m_phongShading
If true, per-pixel-phong shading is applied to the surface.
WPropInt m_stepCount
The number of steps to walk along the ray.
virtual void connectors()
Initialize the connectors this module is using.
WPropBool m_borderClip
If true, a certain border area can be clipped.
WPropDouble m_colormapRatio
The ratio between colormap and normal surface color.
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...
std::shared_ptr< WCondition > m_propCondition
A condition used to notify about changes in several properties.
virtual void moduleMain()
Entry point after loading the module.
Class representing a single module of OpenWalnut.
boost::filesystem::path m_localPath
The path where the module binary resides in.
Requirements m_requirements
The list of requirements.
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.
WPropBool m_active
True whenever the module should be active.
virtual void connectors()
Initialize connectors in this function.
This only is a 3d double vector.
WBoolFlag m_shutdownFlag
Condition getting fired whenever the thread should quit.
void enableTransparency(osg::ref_ptr< osg::Node > node)
Enable transparency for the given node.
osg::ref_ptr< WGETexture< osg::Texture1D > > genWhiteNoiseTexture(size_t sizeX, size_t channels)
This generates an 1D texture only containing white noise in its channels.
void bindTexture(osg::ref_ptr< osg::Node > node, osg::ref_ptr< WDataTexture3D > texture, size_t unit=0, std::string prefix="")
Binds the specified texture to the specified unit.
osg::ref_ptr< osg::Node > generateSolidBoundingBoxNode(const WBoundingBox &bb, const WColor &color, bool threeDTexCoords=true)
Generates an OSG node for the specified bounding box.