29 #include <osg/LineWidth>
30 #include <osg/MatrixTransform>
33 #include "WMNavigationSlices.h"
34 #include "WMNavigationSlices.xpm"
35 #include "core/common/WPropertyHelper.h"
36 #include "core/common/math/WMath.h"
37 #include "core/graphicsEngine/WGEColormapping.h"
38 #include "core/graphicsEngine/WGEGeodeUtils.h"
39 #include "core/graphicsEngine/WGEUtils.h"
40 #include "core/graphicsEngine/WGraphicsEngine.h"
41 #include "core/graphicsEngine/WPickHandler.h"
42 #include "core/graphicsEngine/callbacks/WGELinearTranslationCallback.h"
43 #include "core/graphicsEngine/callbacks/WGENodeMaskCallback.h"
44 #include "core/graphicsEngine/callbacks/WGEPropertyUniformCallback.h"
45 #include "core/graphicsEngine/callbacks/WGEShaderAnimationCallback.h"
46 #include "core/graphicsEngine/shaders/WGEPropertyUniform.h"
47 #include "core/graphicsEngine/shaders/WGEShader.h"
48 #include "core/graphicsEngine/shaders/WGEShaderDefineOptions.h"
49 #include "core/graphicsEngine/shaders/WGEShaderPropertyDefineOptions.h"
50 #include "core/kernel/WKernel.h"
51 #include "core/kernel/WSelectionManager.h"
73 return WMNavigationSlices_xpm;
78 return "Navigation Slices";
83 return "This module provides slices, orthogonally oriented in the OpenWalnut coordinate system. They allow the fast and easy exploration of "
84 "three-dimensional datasets.";
95 m_noTransparency =
m_properties->addProperty(
"No transparency",
"If checked, transparency is not used. This will show the complete slices.",
143 WVector3d midBB = minV + ( sizes * 0.5 );
146 m_xPos->setMin( minV[0] );
147 m_xPos->setMax( maxV[0] );
148 m_yPos->setMin( minV[1] );
149 m_yPos->setMax( maxV[1] );
150 m_zPos->setMin( minV[2] );
151 m_zPos->setMax( maxV[2] );
153 m_xPos->setHidden(
false );
154 m_yPos->setHidden(
false );
155 m_zPos->setHidden(
false );
158 m_xPos->setRecommendedValue( midBB[0] );
159 m_yPos->setRecommendedValue( midBB[1] );
160 m_zPos->setRecommendedValue( midBB[2] );
166 double maxSizeInv = 1.0 / std::max( sizes[0], std::max( sizes[1], sizes[2] ) );
168 osg::Matrixd::translate( -midBB[0], -midBB[1], -midBB[2] ) *
169 osg::Matrixd::scale( maxSizeInv, maxSizeInv, maxSizeInv ) *
170 osg::Matrixd::translate( 0.0, 0.0, -0.5 )
174 osg::Matrixd::translate( -midBB[0], -midBB[1], -midBB[2] ) *
175 osg::Matrixd::scale( maxSizeInv, maxSizeInv, maxSizeInv ) *
176 osg::Matrixd::rotate( -0.5 * pi(), 1.0, 0.0 , 0.0 ) *
177 osg::Matrixd::translate( 0.0, 0.0, -0.5 )
181 osg::Matrixd::translate( -midBB[0], -midBB[1], -midBB[2] ) *
182 osg::Matrixd::scale( maxSizeInv, maxSizeInv, maxSizeInv ) *
183 osg::Matrixd::rotate( -0.5 * pi(), 1.0, 0.0 , 0.0 ) *
184 osg::Matrixd::rotate( 0.5 * pi(), 0.0, 1.0 , 0.0 ) *
185 osg::Matrixd::translate( 0.0, 0.0, -0.5 )
195 osg::ref_ptr< osg::Node > xSlice =
wge::genFinitePlane( minV, osg::Vec3( 0.0, sizes[1], 0.0 ),
196 osg::Vec3( 0.0, 0.0, sizes[2] ) );
197 xSlice->setName(
"Sagittal Slice" );
198 osg::Uniform* xSliceUniform =
new osg::Uniform(
"u_WorldTransform", osg::Matrixf::identity() );
199 xSlice->getOrCreateStateSet()->addUniform( xSliceUniform );
202 osg::ref_ptr< osg::Node > ySlice =
wge::genFinitePlane( minV, osg::Vec3( sizes[0], 0.0, 0.0 ),
203 osg::Vec3( 0.0, 0.0, sizes[2] ) );
204 ySlice->setName(
"Coronal Slice" );
205 osg::Uniform* ySliceUniform =
new osg::Uniform(
"u_WorldTransform", osg::Matrixf::identity() );
206 ySlice->getOrCreateStateSet()->addUniform( ySliceUniform );
209 osg::ref_ptr< osg::Node > zSlice =
wge::genFinitePlane( minV, osg::Vec3( sizes[0], 0.0, 0.0 ),
210 osg::Vec3( 0.0, sizes[1], 0.0 ) );
211 zSlice->setName(
"Axial Slice" );
212 osg::Uniform* zSliceUniform =
new osg::Uniform(
"u_WorldTransform", osg::Matrixf::identity() );
213 zSlice->getOrCreateStateSet()->addUniform( zSliceUniform );
217 xSlice->setCullingActive(
false );
218 ySlice->setCullingActive(
false );
219 zSlice->setCullingActive(
false );
224 osg::ref_ptr< osg::MatrixTransform > matMainViewX =
new osg::MatrixTransform();
225 matMainViewX->addChild( xSlice );
226 osg::ref_ptr< osg::MatrixTransform > matMainViewY =
new osg::MatrixTransform();
227 matMainViewY->addChild( ySlice );
228 osg::ref_ptr< osg::MatrixTransform > matMainViewZ =
new osg::MatrixTransform();
229 matMainViewZ->addChild( zSlice );
234 osg::ref_ptr< osg::MatrixTransform > matNavViewX =
new osg::MatrixTransform();
235 matNavViewX->addChild( xSlice );
236 osg::ref_ptr< osg::MatrixTransform > matNavViewY =
new osg::MatrixTransform();
237 matNavViewY->addChild( ySlice );
238 osg::ref_ptr< osg::MatrixTransform > matNavViewZ =
new osg::MatrixTransform();
239 matNavViewZ->addChild( zSlice );
265 osg::ref_ptr< osg::Uniform > transparencyUniform =
new osg::Uniform(
"u_noTransparency",
false );
272 osg::ref_ptr< osg::StateSet > state =
m_output->getOrCreateStateSet();
273 state->setRenderingHint( osg::StateSet::TRANSPARENT_BIN );
276 osg::ref_ptr< osg::Uniform > animationUniform =
new osg::Uniform(
"u_timer", 0 );
277 state->addUniform( animationUniform );
281 state->addUniform( transparencyUniform );
282 m_axialOutput->getOrCreateStateSet()->addUniform( transparencyUniform );
284 m_coronalOutput->getOrCreateStateSet()->addUniform( transparencyUniform );
303 m_property( property ),
304 m_pickUniform( new osg::Uniform(
"u_picked", 0.0f ) ),
305 m_dir( negateDirection ? -1.0 : 1.0 )
308 std::shared_ptr< WGEViewer > viewer = ge->getViewerByName(
"Main View" );
312 boost::placeholders::_1 ) );
318 if( pickInfo.
getName() == m_node->getName() )
325 osg::Vec3 startPosScreen( m_oldPixelPosition[ 0 ], m_oldPixelPosition[ 1 ], 0.0 );
326 osg::Vec3 endPosScreen( newPixelPos[ 0 ], newPixelPos[ 1 ], 0.0 );
331 osg::Vec3 moveDirWorld = endPosWorld - startPosWorld;
332 float diff = moveDirWorld *
static_cast< osg::Vec3
>( normal );
334 m_property->set( m_property->get() + m_dir * diff );
337 m_oldPixelPosition = newPixelPos;
339 m_pickUniform->set( 1.0f );
344 m_pickUniform->set( 0.0f );
388 m_axialOutput->getOrCreateStateSet()->addUniform(
new osg::Uniform(
"u_pickColorEnabled", 0.0f ) );
389 m_sagittalOutput->getOrCreateStateSet()->addUniform(
new osg::Uniform(
"u_pickColorEnabled", 0.0f ) );
390 m_coronalOutput->getOrCreateStateSet()->addUniform(
new osg::Uniform(
"u_pickColorEnabled", 0.0f ) );
391 m_output->getOrCreateStateSet()->addUniform(
new osg::Uniform(
"u_pickColorEnabled", 1.0f ) );
393 m_output->getOrCreateStateSet()->setMode( GL_BLEND, osg::StateAttribute::ON );
394 m_axialOutput->getOrCreateStateSet()->setMode( GL_BLEND, osg::StateAttribute::ON );
395 m_sagittalOutput->getOrCreateStateSet()->setMode( GL_BLEND, osg::StateAttribute::ON );
396 m_coronalOutput->getOrCreateStateSet()->setMode( GL_BLEND, osg::StateAttribute::ON );
const vec_type & getMax() const
Gives the back upper right aka maximum corner.
const vec_type & getMin() const
Gives the front lower left aka minimum corner.
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.
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.
static std::shared_ptr< WGEColormapping > instance()
Returns instance of the module factory to use to create modules.
std::vector< osg::ref_ptr< osg::Node > > NodeList
a bunch of nodes.
Class to wrap around the osg Group node and providing a thread safe add/removal mechanism.
This class is an OSG Callback which allows simple linear translation of a matrix transform node along...
This class adds some convenience methods to WGEGroupNode.
This callback is useful to en-/disable nodes using the node mask based on properties.
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 std::shared_ptr< WGraphicsEngine > getGraphicsEngine()
Returns instance of the graphics engine.
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.
std::shared_ptr< PickCallback > SPtr
For the lazy guys.
void pick(WPickInfo pickInfo)
Pick event handler.
osg::ref_ptr< WGECamera > m_camera
The camera under which the node is placed.
boost::signals2::scoped_connection m_pickConnection
The pick connection for the pick() event handler.
PickCallback(osg::ref_ptr< osg::Node > node, WPropDouble property, bool negateDirection=false)
The callback, controlling.
osg::ref_ptr< osg::Uniform > m_pickUniform
This uniform is used to inform the shader about current pick-state.
This module provides simple slices that can be color-mapped.
void initOSG()
Initializes the needed geodes, transformations and vertex arrays.
WPropBool m_showonZ
indicates whether the vector should be shown on slice Z
WPropDouble m_xPos
x position of the slice
WPropBool m_showonX
indicates whether the vector should be shown on slice X
osg::ref_ptr< WGEGroupNode > m_axialOutput
The geode with the slice only for the nav widgets.
virtual void moduleMain()
Entry point after loading the module.
virtual const std::string getDescription() const
Gives back a description of this module.
WMNavigationSlices()
Default constructor.
WPropBool m_noTransparency
if true, the whole slices are shown.
WPropDouble m_zPos
z position of the slice
PickCallback::SPtr m_xSlicePicker
X-Slice pick callback.
osg::ref_ptr< WGEGroupNode > m_sagittalOutput
The geode with the slice only for the nav widgets.
WPropDouble m_yPos
y position of the slice
osg::ref_ptr< WGEManagedGroupNode > m_output
The Geode containing all the slices and the mesh.
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...
PickCallback::SPtr m_zSlicePicker
Z-Slice pick callback.
virtual void connectors()
Initialize the connectors this module is using.
WPropGroup m_sliceGroup
the group contains several slice properties
virtual ~WMNavigationSlices()
Destructor.
virtual const char ** getXPMIcon() const
Get the icon for this module in XPM format.
PickCallback::SPtr m_ySlicePicker
Y-Slice pick callback.
WPropBool m_showonY
indicates whether the vector should be shown on slice Y
virtual const std::string getName() const
Gives back the name of this module.
osg::ref_ptr< WGEGroupNode > m_coronalOutput
The geode with the slice only for the nav widgets.
virtual void properties()
Initialize the properties for 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.
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.
WPropBool m_active
True whenever the module should be active.
virtual void connectors()
Initialize connectors in this function.
Encapsulates info for pick action.
WVector2d getPickPixel() const
Returns the picked pixel coordinates in screen-space.
WVector3d getPickNormal() const
Get normal at position where object was hit.
std::string getName() const
Get name of picked object.
WBoolFlag m_shutdownFlag
Condition getting fired whenever the thread should quit.
osg::ref_ptr< osg::Node > generateCullProxy(const WBoundingBox &bbox)
Generate a proxy cube, which ensures OSG does proper near-far plane calculation and culling.
osg::Vec3 unprojectFromScreen(const osg::Vec3 screen, osg::ref_ptr< WGECamera > camera)
Converts screen coordinates into Camera coordinates.
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.