33 #include <osg/Material>
34 #include <osg/ShapeDrawable>
35 #include <osg/StateAttribute>
36 #include <osgDB/ReadFile>
37 #include <osgDB/WriteFile>
39 #include "WMDirectVolumeRendering.h"
40 #include "WMDirectVolumeRendering.xpm"
41 #include "core/common/WColor.h"
42 #include "core/common/WPropertyHelper.h"
43 #include "core/dataHandler/WDataSetScalar.h"
44 #include "core/graphicsEngine/WGEColormapping.h"
45 #include "core/graphicsEngine/WGEGeodeUtils.h"
46 #include "core/graphicsEngine/WGEManagedGroupNode.h"
47 #include "core/graphicsEngine/WGERequirement.h"
48 #include "core/graphicsEngine/WGETextureUtils.h"
49 #include "core/graphicsEngine/WGEUtils.h"
50 #include "core/graphicsEngine/shaders/WGEShader.h"
51 #include "core/graphicsEngine/shaders/WGEShaderDefine.h"
52 #include "core/graphicsEngine/shaders/WGEShaderDefineOptions.h"
53 #include "core/kernel/WKernel.h"
76 return WMDirectVolumeRendering_xpm;
82 return "Direct Volume Rendering";
88 return "Direct volume rendering of regular volumetric data.";
101 "gradients",
"<u>Optional:</u> Gradient field of the dataset to display." );
112 m_samples =
m_properties->addProperty(
"Sample count",
"The number of samples to walk along the ray during raycasting. A low value "
113 "may cause artifacts whilst a high value slows down rendering.", 256 );
129 "additional calculation/texture overhead and therefore slow down rendering." );
132 "removed with the cost of possible noise artifacts.",
true,
136 "sample count. If disabled, changing the sample count "
137 "varies brightness of the image.",
true,
161 osg::ref_ptr< osg::Image > genWhiteNoise(
size_t resX )
163 std::srand( time( 0 ) );
165 osg::ref_ptr< osg::Image > randImage =
new osg::Image();
166 randImage->allocateImage( resX, resX, 1, GL_LUMINANCE, GL_UNSIGNED_BYTE );
167 unsigned char *randomLuminance = randImage->data();
168 for(
unsigned int x = 0; x < resX; x++ )
170 for(
unsigned int y = 0; y < resX; y++ )
173 unsigned char r = (
unsigned char )( std::rand() % 255 );
174 randomLuminance[ ( y * resX ) + x ] = r;
190 m_shader->addPreprocessor( illuminationAlgoDefines );
212 osg::ref_ptr< osg::Texture1D > tfTexture =
new osg::Texture1D();
213 osg::ref_ptr< osg::Image > tfImage =
new osg::Image();
214 bool updateTF =
false;
225 debugLog() <<
"Module is now ready.";
228 bool rootInserted =
false;
247 std::shared_ptr< WDataSetScalar > dataSet =
m_input->getData();
248 bool dataValid = ( dataSet != NULL );
263 if( ( propUpdated || dataUpdated ) && dataValid )
265 debugLog() <<
"Data changed. Uploading new data as texture.";
271 std::shared_ptr< WGridRegular3D > grid = std::dynamic_pointer_cast< WGridRegular3D >( dataSet->getGrid() );
274 errorLog() <<
"The dataset does not provide a regular grid. Ignoring dataset.";
280 WPosition( grid->getNbCoordsX() - 1, grid->getNbCoordsY() - 1, grid->getNbCoordsZ() - 1 ) );
282 cube->asTransform()->getChild( 0 )->setName(
"_DVR Proxy Cube" );
285 rootNode->setMatrix(
static_cast< WMatrix4d >( grid->getTransform() ) );
290 osg::ref_ptr< WDataTexture3D > texture3D = dataSet->getTexture();
298 osg::StateSet* rootState =
cube->getOrCreateStateSet();
299 rootState->setMode( GL_BLEND, osg::StateAttribute::ON );
300 rootState->setRenderingHint( osg::StateSet::TRANSPARENT_BIN );
306 std::shared_ptr< WDataSetVector > gradients =
m_gradients->getData();
309 debugLog() <<
"Uploading specified gradient field.";
312 osg::ref_ptr< WDataTexture3D > gradTexture3D = gradients->getTexture();
314 gradTexEnableDefine->setActive(
true );
318 gradTexEnableDefine->setActive(
false );
327 jitterEnable->setActive(
false );
330 const size_t size = 64;
331 osg::ref_ptr< WGETexture2D > randTexture =
new WGETexture2D( genWhiteNoise( size ) );
332 randTexture->setFilterMinMag( osg::Texture2D::NEAREST );
333 randTexture->setWrapSTR( osg::Texture2D::REPEAT );
336 jitterEnable->setActive(
true );
337 jitterSizeXDefine->
setValue( size );
344 osg::ref_ptr< osg::Texture1D > tfTexture =
new osg::Texture1D();
345 tfTexture->setDataVariance( osg::Object::DYNAMIC );
349 tfImage->allocateImage( resX, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE );
350 unsigned char *data = tfImage->data();
351 for(
int x = 0; x < resX; x++ )
353 unsigned char r = (
unsigned char )( 0.1 * 255.0 *
static_cast< float >( x ) /
static_cast< float >( resX ) );
354 data[ 4 * x + 0 ] = 255;
355 data[ 4 * x + 1 ] = 255;
356 data[ 4 * x + 2 ] = 255;
357 data[ 4 * x + 3 ] = r;
361 tfTexture->setImage( tfImage );
364 tfTexEnableDefine->setActive(
true );
372 opacityCorrectionEnableDefine->setActive(
true );
376 opacityCorrectionEnableDefine->setActive(
false );
385 maximumIntensityProjectionEnabledDefine->setActive(
true );
389 maximumIntensityProjectionEnabledDefine->setActive(
false );
398 depthProjectionEnabledDefine->setActive(
true );
402 depthProjectionEnabledDefine->setActive(
false );
416 debugLog() <<
"Adding new rendering.";
417 rootNode->insert(
cube );
443 WAssert( dataSet,
"data set" );
444 std::shared_ptr< WValueSetBase > valueSet = dataSet->getValueSet();
445 WAssert( valueSet,
"value set" );
446 std::shared_ptr< WValueSet< unsigned char > > cvalueSet( std::dynamic_pointer_cast<
WValueSet< unsigned char> >( valueSet ) );
453 size_t tfsize = cvalueSet->rawSize();
456 tfImage->allocateImage( tfsize/4, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE );
457 tfImage->setInternalTextureFormat( GL_RGBA );
458 unsigned char* data =
reinterpret_cast< unsigned char*
>( tfImage->data() );
459 std::copy( cvalueSet->rawData(), &cvalueSet->rawData()[ tfsize ], data );
462 tfTexture->dirtyTextureObject();
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.
This class adds some convenience methods to WGEGroupNode.
This requirement ensures an up and running WGE.
This GLSL preprocessor is able to set one define from a list of defines depending on the active optio...
std::shared_ptr< WGEShaderDefineOptions > SPtr
Shared pointer for this class.
void setValue(const ValueType &value)
Sets the new value for this define.
std::shared_ptr< WGEShaderDefine< ValueType > > SPtr
Shared pointer for this class.
void setActive(bool active=true)
(De-)activates the preprocessor.
Class encapsulating the OSG Program class for a more convenient way of adding and modifying shader.
This calls serves a simple purpose: have a texture and its scaling information together which allows ...
A class containing a list of named items.
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 is a basic volume renderer.
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...
WMDirectVolumeRendering()
Default constructor.
std::shared_ptr< WModuleInputData< WDataSetScalar > > m_input
An input connector used to get datasets from other modules.
WPropBool m_depthProjectionEnabled
If active, color coding is done by depth projection mode where the intensity is taken from the alpha ...
WPropBool m_maximumIntensityProjectionEnabled
If active, Maximum intensity projection is used based on the alpha value of the points.
WPropBool m_opacityCorrectionEnabled
If active, the opacity of the classified fragment gets scaled according to sample count to ensure rel...
virtual const std::string getDescription() const
Gives back a description of this module.
std::shared_ptr< WItemSelection > m_localIlluminationSelections
The available shading algorithms.
WPropGroup m_improvementGroup
All properties for those nice improvement methods.
WPropInt m_samples
The number of samples to walk along the ray.
std::shared_ptr< WCondition > m_propCondition
A condition used to notify about changes in several properties.
virtual const char ** getXPMIcon() const
Get the icon for this module in XPM format.
virtual void moduleMain()
Entry point after loading the module.
virtual ~WMDirectVolumeRendering()
Destructor.
osg::ref_ptr< osg::Node > cube
the main geometry node
WPropSelection m_localIlluminationAlgo
The actually selected shading algorithm.
std::shared_ptr< WModuleInputData< WDataSetVector > > m_gradients
The gradient field input.
osg::ref_ptr< WGEShader > m_shader
the DVR shader.
virtual void connectors()
Initialize the connectors this module is using.
std::shared_ptr< WModuleInputData< WDataSetSingle > > m_transferFunction
The transfer function as an input data set.
virtual const std::string getName() const
Gives back the name of this module.
WPropBool m_stochasticJitterEnabled
If true, stochastic jittering is used for image quality improvement.
virtual void properties()
Initialize the properties for this module.
virtual void requirements()
Initialize requirements for this 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.
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.
Base Class for all value set types.
void addTo(WPropSelection prop)
Add the PC_NOTEMPTY constraint to the property.
void addTo(WPropSelection prop)
Add the PC_SELECTONLYONE constraint to the property.
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.