30 #include <osg/Projection>
32 #include "WMColormapper.h"
33 #include "WMColormapper.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"
66 return WMColormapper_xpm;
76 return "Can use the input as a texture that can be mapped to the navslices and so on.";
91 m_defaultName =
m_properties->addProperty(
"Default Name",
"This specifies the name to use for textures which are not yet named.",
92 std::string(
"Unnamed" ),
true );
94 WPropGroup colorBarGroup =
m_properties->addPropertyGroup(
"Colorbar",
"The colorbar with several properties." );
95 m_showColorbar = colorBarGroup->addProperty(
"Show Colorbar",
"If true, a colorbar is shown for the current colormap.",
false );
97 WPropGroup colorBarBorderGroup = colorBarGroup->addPropertyGroup(
"Border",
"The colorbar border properties." );
98 WPropGroup colorBarNameLabelGroup = colorBarGroup->addPropertyGroup(
"Name Label",
"The colorbar name label properties." );
99 WPropGroup colorBarLabelsGroup = colorBarGroup->addPropertyGroup(
"Labels",
"The colorbar label properties." );
101 m_colorBarBorder = colorBarBorderGroup->addProperty(
"Show Border",
"If true, a thin white border is shown around the colorbar.",
true );
102 m_colorBarBorderColor = colorBarBorderGroup->addProperty(
"Border Color",
"Color of the border around the colorbar.",
103 WColor( 1.0, 1.0, 1.0, 1.0 ) );
105 m_colorBarName = colorBarNameLabelGroup->addProperty(
"Show Name",
"If true, a shortened version of the data name is shown.",
true );
106 m_colorBarNameSize = colorBarNameLabelGroup->addProperty(
"Text Size",
"This defines the size of a character in normalized screen coordinates."
107 "A value of 1 means the char is as large as the view.", 0.015 );
111 m_colorBarNameColor = colorBarNameLabelGroup->addProperty(
"Name Color",
"Color of the name text", WColor( 0.9, 0.9, 0.9, 1.0 ) );
112 m_colorBarNameOutlineColor = colorBarNameLabelGroup->addProperty(
"Name Outline Color",
"Color of the name outline", defaultColor::BLACK );
118 m_colorbarNamePosition = colorBarNameLabelGroup->addProperty(
"Colorbar Name Position",
"Where to place the name.",
124 m_colorBarLabels = colorBarLabelsGroup->addProperty(
"Colorbar Labels",
"This defines the number of labels.", 10 );
127 m_colorBarLabelsSize = colorBarLabelsGroup->addProperty(
"Text Size",
"This defines the size of a character in normalized screen coordinates."
128 "A value of 1 means the char is as large as the view.", 0.015 );
131 m_colorBarLabelsColor = colorBarLabelsGroup->addProperty(
"Label Color",
"Color of the label text", WColor( 0.9, 0.9, 0.9, 1.0 ) );
132 m_colorBarLabelsOutlineColor = colorBarLabelsGroup->addProperty(
"Label Outline Color",
"Color of the label outline.", defaultColor::BLACK );
133 m_colorBarLabelsBarColor = colorBarLabelsGroup->addProperty(
"Label Bar Color",
"Color of the small bar for each label.", defaultColor::WHITE );
146 std::string format( std::string str,
size_t maxLen = 45 )
149 WAssert( maxLen >= 9,
"MaxLen has to be 9 or more." );
150 std::ostringstream ss;
153 if( str.length() > maxLen )
155 size_t keep = maxLen - 3;
156 size_t keepFront = keep / 2;
157 size_t keepEnd = keep - keepFront;
159 ss << str.substr( 0, keepFront ) <<
" [...] " << str.substr( str.length() - keepEnd, keepEnd );
176 template<
typename T >
177 std::string format( T number )
179 std::ostringstream ss;
192 osg::ref_ptr< WGEShader > colormapShader = osg::ref_ptr< WGEShader > (
new WGEShader(
"WMColormapper",
m_localPath ) );
217 std::shared_ptr< WDataSetSingle > dataSet =
m_input->getData();
220 if( dataSet && dataSet->isTexture() )
227 m_barProjection->getOrCreateStateSet()->setRenderBinDetails( 15,
"RenderBin" );
228 m_barProjection->getOrCreateStateSet()->setDataVariance( osg::Object::DYNAMIC );
229 m_barProjection->getOrCreateStateSet()->setMode( GL_DEPTH_TEST, osg::StateAttribute::OFF );
230 m_barProjection->getOrCreateStateSet()->setMode( GL_LIGHTING, osg::StateAttribute::OFF );
232 float borderWidth = 0.001;
236 osg::ref_ptr< osg::Geode > colorBarBorder =
wge::genFinitePlane( osg::Vec3( 0.025 - borderWidth, 0.1 - borderWidth, -0.1 ),
237 osg::Vec3( 0.025 + 2.0 * borderWidth, 0.0, -0.1 ),
238 osg::Vec3( 0.0, 0.8 + 2.0 * borderWidth, -0.1 ) );
244 dataSet->getTexture()->colormap() ) );
248 osg::ref_ptr< WGELabel > nameLabel =
new WGELabel();
249 nameLabel->setText( format( dataSet->getTexture()->name()->get() ) );
250 nameLabel->setPosition( osg::Vec3( 0.015, 0.93, 0.0 ) );
251 nameLabel->setCharacterSize( 0.020 );
252 nameLabel->setLayout( osgText::TextBase::LEFT_TO_RIGHT );
253 nameLabel->setAlignment( osgText::Text::BASE_LINE );
259 osg::ref_ptr< osg::MatrixTransform > matrix =
new osg::MatrixTransform();
260 matrix->setMatrix( osg::Matrix::identity() );
261 matrix->setReferenceFrame( osg::Transform::ABSOLUTE_RF );
265 osg::ref_ptr< osg::Geode > labels =
new osg::Geode();
266 labels->addDrawable( nameLabel );
282 matrix->addChild( colorBarBorder );
285 matrix->addChild( labels );
288 m_valueMin = dataSet->getTexture()->minimum()->get();
296 if( dataSet && dataSet->isTexture() && ( dataSet->getTexture()->name()->get() == std::string(
"Unnamed" ) ) )
298 dataSet->getTexture()->name()->setRecommendedValue(
m_defaultName->get() );
304 debugLog() <<
"Replacing texture \"" <<
m_lastDataSet->getTexture()->name()->get() <<
"\" with \"" <<
305 dataSet->getTexture()->name()->get() <<
"\".";
309 std::vector< std::string > excludes;
310 excludes.push_back(
"Minimum" );
311 excludes.push_back(
"Scale" );
312 dataSet->getTexture()->getProperties()->set(
m_lastDataSet->getTexture()->getProperties(), excludes,
true );
317 m_properties->addProperty( dataSet->getTexture()->getProperties() );
318 m_infoProperties->addProperty( dataSet->getTexture()->getInformationProperties() );
337 if( dataSet && dataSet->isTexture() )
377 osg::ref_ptr< osg::Vec4Array > colors =
new osg::Vec4Array;
379 dynamic_cast< osg::Geometry*
>( border )->setColorArray( colors );
388 l->setText( format(
m_lastDataSet->getTexture()->name()->get() ) );
396 l->setPosition( osg::Vec3( 0.015, 0.9, 0.0 ) );
398 l->setLayout( osgText::TextBase::VERTICAL );
401 l->setPosition( osg::Vec3( 0.015, 0.06, 0.0 ) );
403 l->setLayout( osgText::TextBase::LEFT_TO_RIGHT );
406 l->setPosition( osg::Vec3( 0.015, 0.93, 0.0 ) );
408 l->setLayout( osgText::TextBase::LEFT_TO_RIGHT );
433 const double labelXPos = 0.060;
434 osg::Geode* g = scaleLabels->asGeode();
435 g->removeDrawables( 0, g->getNumDrawables() );
438 double coordStep = 0.8 /
static_cast< double >( num - 1 );
439 double valueStep =
m_valueScale /
static_cast< double >( num - 1 );
454 osg::Vec3Array* lineVerts =
new osg::Vec3Array();
457 for(
size_t i = 0; i < num; ++i )
459 double value = valueMin + ( valueStep * i );
462 osg::ref_ptr< WGELabel > label =
new WGELabel();
463 label->setPosition( osg::Vec3( labelXPos, 0.1 + i * coordStep, 0.0 ) );
464 label->setText( format( value ) );
466 label->setAlignment( osgText::Text::LEFT_CENTER );
470 g->addDrawable( label );
473 lineVerts->push_back( osg::Vec3( labelXPos - 0.010, 0.1 + i * coordStep, 0.0 ) );
474 lineVerts->push_back( osg::Vec3( labelXPos - 0.005, 0.1 + i * coordStep, 0.0 ) );
478 osg::Geometry* lines =
new osg::Geometry();
479 lines->setVertexArray( lineVerts );
480 osg::Vec4Array* color =
new osg::Vec4Array();
482 lines->setColorArray( color );
483 lines->setColorBinding( osg::Geometry::BIND_OVERALL );
484 lines->addPrimitiveSet(
new osg::DrawArrays( GL_LINES, 0, lineVerts->size() ) );
485 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.
static void replaceTexture(osg::ref_ptr< WGETexture3D > old, osg::ref_ptr< WGETexture3D > newTex, std::string name="")
Replaces the specified texture with the given new one.
static void registerTexture(osg::ref_ptr< WGETexture3D > texture, std::string name="")
Register the specified texture to the colormapper.
static void deregisterTexture(osg::ref_ptr< WGETexture3D > texture)
De-register the specified texture to the colormapper.
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.
T getLength() const
The length of the interval.
const T & getLower() const
Get the lower value of the interval.
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 simply registers the given dataset to the texture handling mechanism.
virtual const std::string getDescription() const
Gives back a description of this module.
osg::ref_ptr< osg::Geode > m_colorBar
The colorbar.
std::shared_ptr< WCondition > m_propCondition
A condition used to notify about changes in several properties.
WPropDouble m_colorBarNameSize
Character size of the name label.
std::shared_ptr< WModuleInputData< WDataSetSingle > > m_input
Input connector required by this module.
WIntervalDouble m_windowLevel
Window level.
WPropColor m_colorBarLabelsColor
Color bar color: labels text.
bool m_windowLevelEnabled
True if window leveling is active.
std::shared_ptr< WDataSetSingle > m_lastDataSet
This is a pointer to the dataset the module is currently working on.
virtual void moduleMain()
Entry point after loading the module.
osg::ref_ptr< osg::Projection > m_barProjection
The projection node for the colorbar and labels.
WPropDouble m_colorBarLabelsSize
Character size of the labels.
void updateColorbarScale(osg::Node *scaleLabels)
Callback which adds/removes scale labels to the colorbar.
std::shared_ptr< WItemSelection > m_possibleNamePositions
A list of colorbar name positions.
virtual void connectors()
Initialize the connectors this module is using.
virtual void activate()
Callback for m_active.
WPropInt m_colorBarLabels
The number of colorbar labels.
virtual const std::string getName() const
Gives back the name of this module.
WPropColor m_colorBarNameColor
Color bar color: name text.
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...
WPropBool m_showColorbar
If true, a colorbar is shown.
WPropBool m_colorBarBorder
Show the border?
bool m_needScaleUpdate
If true, the labels get re-drawn.
virtual void properties()
Initialize the properties for this module.
WPropSelection m_colorbarNamePosition
Position of the colorbar name.
double m_valueMin
The min of the current dataset.
WPropColor m_colorBarBorderColor
Color bar color: border.
WPropString m_defaultName
This property holds the name of the texture to use if the texture itself is unnamed.
double m_valueScale
The scaling factor of the current dataset.
virtual const char ** getXPMIcon() const
Get the icon for this module in XPM format.
WPropBool m_colorBarName
Show colorbar name?
osg::ref_ptr< osg::Geode > m_scaleLabels
The colorbar scale labels.
void updateColorbarBorder(osg::Drawable *border)
Callback for updating the border of the colorbar.
WPropColor m_colorBarLabelsOutlineColor
Color bar color: labels outline color.
~WMColormapper()
Destructor.
WMColormapper()
Standard constructor.
WPropColor m_colorBarLabelsBarColor
Color bar color: labels bar color.
void updateColorbarName(osg::Drawable *label)
Updates the label for the dataset name.
WPropColor m_colorBarNameOutlineColor
Color bar color: name outline color.
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.
std::shared_ptr< WProperties > m_infoProperties
The property object for the module containing only module whose purpose is "PV_PURPOSE_INFORMNATION".
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.
void addTo(WPropSelection prop)
Add the PC_NOTEMPTY constraint to the property.
void addTo(WPropSelection prop)
Add the PC_SELECTONLYONE constraint to the property.
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.