30 #include <osg/Projection>
32 #include "WMTransferFunctionColorBar.h"
33 #include "WMTransferFunctionColorBar.xpm"
34 #include "core/dataHandler/WDataTexture3D.h"
35 #include "core/graphicsEngine/WGEColormapping.h"
36 #include "core/graphicsEngine/WGEGeodeUtils.h"
37 #include "core/graphicsEngine/callbacks/WGEFunctorCallback.h"
38 #include "core/graphicsEngine/callbacks/WGENodeMaskCallback.h"
39 #include "core/graphicsEngine/shaders/WGEShader.h"
40 #include "core/graphicsEngine/widgets/labeling/WGELabel.h"
41 #include "core/kernel/WKernel.h"
65 return WMTransferFunctionColorBar_xpm;
70 return "Transfer Function Color Bar";
75 return "Can use the input as a texture that can be mapped to the navslices and so on.";
90 WPropGroup colorBarGroup =
m_properties->addPropertyGroup(
"Colorbar",
"The colorbar with several properties." );
91 m_colorBarBorder = colorBarGroup->addProperty(
"Show Border",
"If true, a thin white border is shown around the colorbar.",
true );
92 m_colorBarName = colorBarGroup->addProperty(
"Show Name",
"If true, a shortened version of the data name is shown.",
true );
93 m_colorBarLabels = colorBarGroup->addProperty(
"Colorbar Labels",
"This defines the number of labels.", 10 );
100 std::string(
"TransferFunction" ),
true ),
113 template<
typename T >
114 std::string format( T number )
116 std::ostringstream ss;
131 osg::ref_ptr< WGEShader > colormapShader = osg::ref_ptr< WGEShader > (
new WGEShader(
"WMTransferFunctionColorBar",
m_localPath ) );
156 std::shared_ptr< WDataSetSingle > dataSet =
m_input->getData();
165 m_barProjection->getOrCreateStateSet()->setRenderBinDetails( 15,
"RenderBin" );
166 m_barProjection->getOrCreateStateSet()->setDataVariance( osg::Object::DYNAMIC );
167 m_barProjection->getOrCreateStateSet()->setMode( GL_DEPTH_TEST, osg::StateAttribute::OFF );
168 m_barProjection->getOrCreateStateSet()->setMode( GL_LIGHTING, osg::StateAttribute::OFF );
170 float borderWidth = 0.001;
174 m_colorBar->setName(
"Transfer Function Color Bar" );
175 osg::ref_ptr< osg::Geode > colorBarBorder =
wge::genFinitePlane( osg::Vec3( 0.025 - borderWidth, 0.1 - borderWidth, -0.1 ),
176 osg::Vec3( 0.025 + 2.0 * borderWidth, 0.0, -0.1 ),
177 osg::Vec3( 0.0, 0.8 + 2.0 * borderWidth, -0.1 ) );
181 WAssert( dataSet,
"data set" );
182 std::shared_ptr< WValueSetBase > valueSet = dataSet->getValueSet();
183 WAssert( valueSet,
"value set" );
184 std::shared_ptr< WValueSet< unsigned char > > cvalueSet( std::dynamic_pointer_cast<
WValueSet< unsigned char> >( valueSet ) );
191 size_t tfsize = cvalueSet->rawSize();
192 const unsigned char* orig = cvalueSet->rawData();
193 unsigned char* data =
new unsigned char[ tfsize ];
194 std::copy( orig, &orig[ tfsize ], data );
195 osg::ref_ptr < osg::Image > tfImg(
new osg::Image() );
196 tfImg->setImage( tfsize/4, 1, 1, GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE,
197 data, osg::Image::USE_NEW_DELETE );
198 osg::ref_ptr< osg::Texture1D > tfTexture =
new osg::Texture1D();
199 tfTexture->setImage( tfImg );
204 osg::ref_ptr< WGELabel > nameLabel =
new WGELabel();
205 nameLabel->setPosition( osg::Vec3( 0.015, 0.9, 0.0 ) );
207 nameLabel->setCharacterSize( 0.015 );
208 nameLabel->setLayout( osgText::TextBase::VERTICAL );
209 nameLabel->setAlignment( osgText::Text::BASE_LINE );
212 osg::ref_ptr< osg::MatrixTransform > matrix =
new osg::MatrixTransform();
213 matrix->setMatrix( osg::Matrix::identity() );
214 matrix->setReferenceFrame( osg::Transform::ABSOLUTE_RF );
217 osg::ref_ptr< osg::Geode > labels =
new osg::Geode();
218 labels->addDrawable( nameLabel );
228 matrix->addChild( colorBarBorder );
231 matrix->addChild( labels );
236 m_valueMin = dataSet->getTexture()->minimum()->get();
275 const double labelXPos = 0.060;
276 osg::Geode* g = scaleLabels->asGeode();
277 g->removeDrawables( 0, g->getNumDrawables() );
280 double coordStep = 0.8 /
static_cast< double >( num - 1 );
281 double valueStep =
m_valueScale /
static_cast< double >( num - 1 );
289 osg::Vec3Array* lineVerts =
new osg::Vec3Array();
292 for(
size_t i = 0; i < num; ++i )
294 double value =
m_valueMin + ( valueStep * i );
297 osg::ref_ptr< WGELabel > label =
new WGELabel();
298 label->setPosition( osg::Vec3( labelXPos, 0.1 + i * coordStep, 0.0 ) );
299 label->setText( format( value ) );
300 label->setCharacterSize( 0.015 );
301 label->setAlignment( osgText::Text::LEFT_CENTER );
303 g->addDrawable( label );
306 lineVerts->push_back( osg::Vec3( labelXPos - 0.010, 0.1 + i * coordStep, 0.0 ) );
307 lineVerts->push_back( osg::Vec3( labelXPos - 0.005, 0.1 + i * coordStep, 0.0 ) );
311 osg::Geometry* lines =
new osg::Geometry();
312 lines->setVertexArray( lineVerts );
313 osg::Vec3Array* color =
new osg::Vec3Array();
314 color->push_back( osg::Vec3( 1.0, 1.0, 1.0 ) );
315 lines->setColorArray( color );
316 lines->setColorBinding( osg::Geometry::BIND_OVERALL );
317 lines->addPrimitiveSet(
new osg::DrawArrays( GL_LINES, 0, lineVerts->size() ) );
318 g->addDrawable( lines );
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 callback allows you a simple usage of callbacks in your module.
This callback is useful to en-/disable nodes using the node mask based on properties.
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 simply registers the given dataset to the texture handling mechanism.
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...
WPropDouble m_maxScaleValue
Maximum scaling factor of the current dataset.
std::shared_ptr< WModuleInputData< WDataSetSingle > > m_input
Input connector required by this module.
osg::ref_ptr< osg::Geode > m_scaleLabels
The colorbar scale labels.
WPropBool m_colorBarName
Show colorbar name?
WPropString m_colorBarDescription
Description of the color bar.
WMTransferFunctionColorBar()
Standard constructor.
virtual void moduleMain()
Entry point after loading the module.
virtual const char ** getXPMIcon() const
Get the icon for this module in XPM format.
osg::ref_ptr< osg::Projection > m_barProjection
The projection node for the colorbar and labels.
virtual const std::string getDescription() const
Gives back a description of this module.
osg::ref_ptr< osg::Geode > m_colorBar
The colorbar.
~WMTransferFunctionColorBar()
Destructor.
WPropInt m_colorBarLabels
The number of colorbar labels.
bool m_customScale
Whether a custom min max was set.
double m_valueMin
The min of the current dataset.
virtual void activate()
Callback for m_active.
virtual void connectors()
Initialize the connectors this module is using.
virtual void properties()
Initialize the properties for this module.
std::shared_ptr< WCondition > m_propCondition
A condition used to notify about changes in several properties.
void updateColorbarScale(osg::Node *scaleLabels)
Callback which adds/removes scale labels to the colorbar.
double m_valueScale
The scaling factor of the current dataset.
WPropDouble m_minScaleValue
Minimum scaling factor of the current dataset.
WPropBool m_colorBarBorder
Show the border?
virtual const std::string getName() const
Gives back the name of this module.
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 removeConnectors()
Removes all connectors properly.
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.
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.
Base Class for all value set types.
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::Geode > genFinitePlane(double xSize, double ySize, const WPlane &p, const WColor &color=WColor(0.0, 0.7, 0.7, 1.0), bool border=false)
Generates a geode out of a Plane with a fixed size in direction of the vectors which span that plane.