29 #include <osg/LightModel>
30 #include <osgGA/StateSetManipulator>
31 #include <osgGA/TrackballManipulator>
32 #include <osgViewer/ViewerEventHandlers>
33 #include <osgWidget/Util>
34 #include <osgWidget/ViewerEventHandlers>
35 #include <osgWidget/WindowManager>
37 #include "WMDatasetProfile.h"
38 #include "WMDatasetProfile.xpm"
39 #include "core/kernel/WKernel.h"
40 #include "core/kernel/WSelectionManager.h"
45 WMDatasetProfile::WMDatasetProfile():
51 WMDatasetProfile::~WMDatasetProfile()
64 return WMDatasetProfile_xpm;
68 return "Dataset Profile";
73 return "Show values along a 3D profile through the dataset as a graph.";
79 m_input = std::shared_ptr< WModuleInputData < WDataSetScalar > >(
101 "Add a segment and a corresponding manipulator knob to profile.",
106 "Color of the curve representing the data profile graph.",
107 WColor( 0.2, 0.2, 0.2, 1.0 ) );
110 "Length of profile segments. Needs to activated by Use Length property",
117 "Use value of voxel closest to sample or interpolate between surrounding values.",
155 std::shared_ptr< WDataSetScalar > newDataSet =
m_input->getData();
156 bool dataChanged = (
m_dataSet != newDataSet );
157 bool dataValid = ( newDataSet != NULL );
164 m_grid = std::dynamic_pointer_cast< WGridRegular3D >(
m_dataSet->getGrid() );
188 for(
size_t i = 0; i <
knobs.size(); ++i )
201 for(
size_t i = 0; i <
knobs.size(); ++i )
203 knobs[i]->setLockX(
false );
204 knobs[i]->setLockY(
false );
205 knobs[i]->setLockZ(
false );
212 for(
size_t i = 0; i <
knobs.size(); ++i )
214 knobs[i]->setZ( center[2] );
215 knobs[i]->setLockZ(
true );
219 for(
size_t i = 0; i <
knobs.size(); ++i )
221 knobs[i]->setY( center[1] );
222 knobs[i]->setLockY(
true );
226 for(
size_t i = 0; i <
knobs.size(); ++i )
228 knobs[i]->setX( center[0] );
229 knobs[i]->setLockX(
true );
238 for(
size_t i = 0; i <
knobs.size() - 1; ++i )
243 float l = sqrt( ( p1[0] - p2[0] ) * ( p1[0] - p2[0] ) +
244 ( p1[1] - p2[1] ) * ( p1[1] - p2[1] ) +
245 ( p1[2] - p2[2] ) * ( p1[2] - p2[2] ) );
251 if( ( fabs( l -
static_cast<float>(
m_propLength->get(
true ) ) ) ) > 0.001 )
253 knobs[i+1]->setPosition( p1 + vec * mult );
272 m_lineGeode = osg::ref_ptr< osg::Geode >(
new osg::Geode() );
277 = std::shared_ptr< boost::function< void() > >(
new boost::function< void() >( boost::bind( &
WMDatasetProfile::setDirty,
this ) ) );
286 int height = viewer->getCamera()->getViewport()->height();
287 int width = viewer->getCamera()->getViewport()->width();
295 m_wm =
new osgWidget::WindowManager( viewer, 0.0f, 0.0f, MASK_2D );
298 m_camera->getOrCreateStateSet()->setMode( GL_LIGHTING, osg::StateAttribute::PROTECTED | osg::StateAttribute::OFF );
300 m_camera->setProjectionMatrix( osg::Matrix::ortho2D( 0.0, width, 0.0f, height ) );
301 m_camera->setReferenceFrame( osg::Transform::ABSOLUTE_RF );
302 m_camera->setViewMatrix( osg::Matrix::identity() );
303 m_camera->setClearMask( GL_DEPTH_BUFFER_BIT );
304 m_camera->setRenderOrder( WGECamera::POST_RENDER );
309 viewer->addEventHandler(
new osgWidget::MouseHandler(
m_wm ) );
310 viewer->addEventHandler(
new osgWidget::KeyboardHandler(
m_wm ) );
311 viewer->addEventHandler(
new osgWidget::ResizeHandler(
m_wm,
m_camera ) );
312 viewer->addEventHandler(
new osgWidget::CameraSwitchHandler(
m_wm,
m_camera ) );
313 viewer->addEventHandler(
new osgViewer::StatsHandler() );
314 viewer->addEventHandler(
new osgViewer::WindowSizeHandler() );
315 viewer->addEventHandler(
new osgGA::StateSetManipulator( viewer->getCamera()->getOrCreateStateSet() ) );
317 m_wm->resizeAllWindows();
324 osg::ref_ptr<WROISphere> s = osg::ref_ptr<WROISphere>(
new WROISphere( pos, 2.5 ) );
326 knobs.push_back( s );
329 for(
size_t i = 0; i <
knobs.size(); ++i )
331 knobs[i]->setColor( osg::Vec4( 0.0, 1.0, 1.0, 1.0 ) );
333 knobs[0]->setColor( osg::Vec4( 0.0, 1.0, 0.0, 1.0 ) );
334 knobs[
knobs.size()- 1]->setColor( osg::Vec4( 1.0, 0.0, 0.0, 1.0 ) );
343 osg::ref_ptr< osg::Vec3Array > vertices = osg::ref_ptr< osg::Vec3Array >(
new osg::Vec3Array );
344 osg::ref_ptr< osg::Vec4Array > colors = osg::ref_ptr< osg::Vec4Array >(
new osg::Vec4Array );
345 osg::ref_ptr< osg::Geometry > geometry = osg::ref_ptr< osg::Geometry >(
new osg::Geometry );
347 for(
size_t i = 0; i <
knobs.size(); ++i )
349 vertices->push_back( osg::Vec3(
knobs[i]->getPosition() ) );
352 geometry->addPrimitiveSet(
new osg::DrawArrays( osg::PrimitiveSet::LINE_STRIP, 0, vertices->size() ) );
353 geometry->setVertexArray( vertices );
356 geometry->setColorArray( colors );
357 geometry->setColorBinding( osg::Geometry::BIND_OVERALL );
360 osg::StateSet* state =
m_lineGeode->getOrCreateStateSet();
361 state->setMode( GL_LIGHTING, osg::StateAttribute::OFF | osg::StateAttribute::PROTECTED );
367 int height = viewer->getCamera()->getViewport()->height();
368 int width = viewer->getCamera()->getViewport()->width();
384 for(
size_t i = 0; i <
knobs.size(); ++i )
393 for(
size_t i = 0; i <
knobs.size(); ++i )
404 osg::ref_ptr< osg::Geode > newGeode = osg::ref_ptr< osg::Geode >(
new osg::Geode() );
406 osg::ref_ptr< osg::Vec3Array > vertices = osg::ref_ptr< osg::Vec3Array >(
new osg::Vec3Array );
407 osg::ref_ptr< osg::Vec4Array > colors = osg::ref_ptr< osg::Vec4Array >(
new osg::Vec4Array );
408 osg::ref_ptr< osg::Geometry > geometry = osg::ref_ptr< osg::Geometry >(
new osg::Geometry );
415 vertices->push_back( osg::Vec3( i, 10, 0 ) );
420 vertices->push_back( osg::Vec3( 10, 10, 0 ) );
421 vertices->push_back( osg::Vec3( i, 10, 0 ) );
423 vertices->push_back( osg::Vec3( 10, yStep, 0 ) );
424 vertices->push_back( osg::Vec3( i, yStep, 0 ) );
426 vertices->push_back( osg::Vec3( 10, yStep * 2, 0 ) );
427 vertices->push_back( osg::Vec3( i, yStep * 2, 0 ) );
429 vertices->push_back( osg::Vec3( 10, yStep * 3, 0 ) );
430 vertices->push_back( osg::Vec3( i, yStep * 3, 0 ) );
435 vertices->push_back( osg::Vec3( 10, 10, 0 ) );
436 vertices->push_back( osg::Vec3( i, 10, 0 ) );
439 geometry->addPrimitiveSet(
new osg::DrawArrays( osg::PrimitiveSet::LINES, 0, vertices->size() ) );
440 geometry->setVertexArray( vertices );
442 WColor color( 0.7, 0.7, 0.7, 1.0 );
443 colors->push_back( color );
444 geometry->setColorArray( colors );
445 geometry->setColorBinding( osg::Geometry::BIND_OVERALL );
448 osg::StateSet* state =
m_lineGeode->getOrCreateStateSet();
449 state->setMode( GL_LIGHTING, osg::StateAttribute::OFF | osg::StateAttribute::PROTECTED );
451 newGeode->addDrawable( geometry );
460 return osg::ref_ptr< osg::Geode >();
463 osg::ref_ptr< osg::Geode > newGeode = osg::ref_ptr< osg::Geode >(
new osg::Geode() );
465 osg::ref_ptr< osg::Vec3Array > vertices = osg::ref_ptr< osg::Vec3Array >(
new osg::Vec3Array );
466 osg::ref_ptr< osg::Vec4Array > colors = osg::ref_ptr< osg::Vec4Array >(
new osg::Vec4Array );
467 osg::ref_ptr< osg::Geometry > geometry = osg::ref_ptr< osg::Geometry >(
new osg::Geometry );
469 std::vector<float>knobPositions;
471 float max =
m_dataSet->getValueSet()->getMaximumValue();
474 float overallLength = 0;
475 std::vector<float> segmentLengths;
476 for(
size_t k = 0; k <
knobs.size() - 1 ; ++k )
479 segmentLengths.push_back( length( p ) );
480 overallLength += length( p );
485 for(
size_t k = 0; k <
knobs.size() - 1 ; ++k )
487 float l1 = segmentLengths[k] / overallLength;
490 knobPositions.push_back( x );
491 WPosition p1 = (
knobs[k+1]->getPosition() -
knobs[k]->getPosition() ) /
static_cast<float>( steps );
493 for(
int i = 0; i < steps; ++i )
498 value =
m_dataSet->interpolate(
knobs[k]->getPosition() + p1 * i, &success );
508 vertices->push_back( osg::Vec3( x, y, 0 ) );
511 knobPositions.push_back( x );
513 for(
size_t j = 0; j < knobPositions.size(); ++j )
515 vertices->push_back( osg::Vec3( knobPositions[j],
m_oldViewHeight / 2, 0 ) );
516 vertices->push_back( osg::Vec3( knobPositions[j], 10, 0 ) );
519 geometry->addPrimitiveSet(
new osg::DrawArrays( osg::PrimitiveSet::LINE_STRIP, 0, vertices->size() - knobPositions.size() * 2 ) );
520 geometry->setVertexArray( vertices );
522 geometry->addPrimitiveSet(
new osg::DrawArrays( osg::PrimitiveSet::LINES, vertices->size() - ( knobPositions.size() ) * 2,
523 ( knobPositions.size() + 1 ) * 2 ) );
526 geometry->setColorArray( colors );
527 geometry->setColorBinding( osg::Geometry::BIND_OVERALL );
530 osg::StateSet* state =
m_lineGeode->getOrCreateStateSet();
531 state->setMode( GL_LIGHTING, osg::StateAttribute::OFF | osg::StateAttribute::PROTECTED );
533 newGeode->addDrawable( geometry );
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.
Class for wrapping around the OSG Camera class.
This callback allows you a simple usage of callbacks in your module.
This class adds some convenience methods to WGEGroupNode.
static std::shared_ptr< WGraphicsEngine > getGraphicsEngine()
Returns instance of the graphics engine.
A class containing a list of named items.
std::shared_ptr< WSelectionManager > getSelectionManager()
get for selection manager
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.
Someone should add some documentation here.
WPropSelection m_snapSelection
Selection property for clusters.
std::shared_ptr< WGridRegular3D > m_grid
stores a pointer to the grid we use;
osg::ref_ptr< osg::Geode > createGraphGeode()
creates an osg node that contains the graph
int m_oldViewWidth
stores the old viewport resolution to check whether a resize happened
WGECamera * m_camera
stores the camera object
WPropBool m_propUseLength
enforce lengths
bool m_dirty
dirty flag to indicate that redrawing is needed
WPropTrigger m_propAddKnobTrigger
Adds a knob.
virtual const std::string getDescription() const
Gives back a description of this module.
std::vector< osg::ref_ptr< WROISphere > > knobs
stores pointers to the control knobs
osg::ref_ptr< WGEManagedGroupNode > m_rootNode
The root node used for this modules graphics.
osg::ref_ptr< osg::Geode > m_lineGeode
The geometry rendered by this module.
std::shared_ptr< WDataSetScalar > m_dataSet
This is a pointer to the dataset the module is currently working on.
osg::ref_ptr< WGEManagedGroupNode > m_graphNode
Pointer to the graph group node.
std::shared_ptr< WItemSelection > m_snapSelectionsList
A list of cluster selection methods.
osg::ref_ptr< osg::Geode > m_graphGeode
osg node for the graph
virtual const std::string getName() const
Gives back the name of this module.
virtual void moduleMain()
Entry point after loading the module.
osg::ref_ptr< osg::Geode > m_graphGridGeode
osg node for the grid
void addKnob(WPosition pos)
adds a control knob
int m_oldViewHeight
stores the old viewport resolution to check whether a resize happened
virtual void connectors()
Initialize the connectors this module is using.
osg::ref_ptr< osg::Geode > createGraphGridGeode()
creates an osg node that contains the underlying grid
void updateCallback()
update function, called with each update pass of the osg render loop
std::shared_ptr< boost::function< void() > > m_changeRoiSignal
Signal that can be used to update the graph.
WPropInt m_propNumSamples
number of sample points on the graph
void setDirty()
sets the dirty flag, used as callback for control knob changes
void init()
initializes the controls and osg nodes
std::shared_ptr< WCondition > m_propCondition
A condition used to notify about changes in several properties.
std::shared_ptr< WModuleInputData< WDataSetScalar > > m_input
An input connector that accepts order 1 datasets.
WPropBool m_propInterpolate
interpolate the graph
virtual const char ** getXPMIcon() const
Get the icon for this module in XPM format.
void update()
updates the osg nodes
virtual void properties()
Initialize the properties for this module.
WPropDouble m_propLength
length between knobs
WPropColor m_graphColor
color of the graph
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...
osgWidget::WindowManager * m_wm
stores a pointer to the window manager used for osg wdgets and overlay stuff
virtual void requirements()
Initialize requirements for this module.
Class representing a single module of OpenWalnut.
virtual void properties()
Initialize properties in this function.
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.
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.
A sphere representing a region of interest.
WBoolFlag m_shutdownFlag
Condition getting fired whenever the thread should quit.
@ PV_TRIGGER_READY
Trigger property: is ready to be triggered (again)
void addTo(WPropSelection prop)
Add the PC_SELECTONLYONE constraint to the property.