Commit 1b572677 authored by schurade's avatar schurade
Browse files

[ADD] first work on a HUD module

parent 6eaf5efd
......@@ -135,14 +135,10 @@ void WGEGraphicsWindow::keyEvent( KeyEvents eventType, int key )
switch( eventType )
{
case KEYPRESS:
m_GraphicsWindow->getEventQueue()->keyPress(
static_cast<osgGA::GUIEventAdapter::KeySymbol>( key )
);
m_GraphicsWindow->getEventQueue()->keyPress( static_cast<osgGA::GUIEventAdapter::KeySymbol>( key ) );
break;
case KEYRELEASE:
m_GraphicsWindow->getEventQueue()->keyRelease(
static_cast<osgGA::GUIEventAdapter::KeySymbol>( key )
);
m_GraphicsWindow->getEventQueue()->keyRelease( static_cast<osgGA::GUIEventAdapter::KeySymbol>( key ) );
break;
}
}
......@@ -152,19 +148,13 @@ void WGEGraphicsWindow::mouseEvent( MouseEvents eventType, int x, int y, int but
switch( eventType )
{
case MOUSEPRESS:
m_GraphicsWindow->getEventQueue()->mouseButtonPress(
x, y, button
);
m_GraphicsWindow->getEventQueue()->mouseButtonPress( x, y, button );
break;
case MOUSERELEASE:
m_GraphicsWindow->getEventQueue()->mouseButtonRelease(
x, y, button
);
m_GraphicsWindow->getEventQueue()->mouseButtonRelease( x, y, button );
break;
case MOUSEDOUBLECLICK:
m_GraphicsWindow->getEventQueue()->mouseDoubleButtonPress(
x, y, button
);
m_GraphicsWindow->getEventQueue()->mouseDoubleButtonPress( x, y, button );
break;
case MOUSEMOVE:
m_GraphicsWindow->getEventQueue()->mouseMotion( x, y );
......
......@@ -36,6 +36,7 @@
#include <osgGA/AnimationPathManipulator>
#include <osgGA/TerrainManipulator>
#include <osgViewer/ViewerEventHandlers>
#include <osgViewer/View>
#include <osgDB/ReadFile>
......@@ -85,6 +86,8 @@ WGEViewer::WGEViewer( std::string name, osg::ref_ptr<WindowData> wdata, int x, i
osg::ref_ptr<osgText::Text> updateText = new osgText::Text;
m_View->addEventHandler( new WPickHandler( updateText.get() ) );
keyEvent( WGEViewer::KEYPRESS, ' ' );
}
catch( ... )
{
......
......@@ -197,22 +197,31 @@ void WQtDatasetBrowser::selectTreeItem()
void WQtDatasetBrowser::changeTreeItem()
{
if ( m_treeWidget->selectedItems().size() == 0 || m_treeWidget->selectedItems().at( 0 )->type() != 1 )
if ( m_treeWidget->selectedItems().size() == 1 && m_treeWidget->selectedItems().at( 0 )->type() == 1 )
{
return;
}
boost::shared_ptr< WModule >module =( ( WQtDatasetTreeItem* ) m_treeWidget->selectedItems().at( 0 ) )->getModule();
if ( m_treeWidget->selectedItems().at( 0 )->checkState( 0 ) )
{
module->getProperties()->setValue<bool>( "active", true );
boost::shared_ptr< WModule >module =( ( WQtDatasetTreeItem* ) m_treeWidget->selectedItems().at( 0 ) )->getModule();
if ( m_treeWidget->selectedItems().at( 0 )->checkState( 0 ) )
{
module->getProperties()->setValue<bool>( "active", true );
}
else
{
module->getProperties()->setValue<bool>( "active", false );
}
emit dataSetBrowserEvent( QString( "textureChanged" ), true );
}
else
else if ( m_treeWidget->selectedItems().size() == 1 && m_treeWidget->selectedItems().at( 0 )->type() == 3 )
{
module->getProperties()->setValue<bool>( "active", false );
boost::shared_ptr< WModule >module =( ( WQtModuleTreeItem* ) m_treeWidget->selectedItems().at( 0 ) )->getModule();
if ( m_treeWidget->selectedItems().at( 0 )->checkState( 0 ) )
{
module->getProperties()->setValue<bool>( "active", true );
}
else
{
module->getProperties()->setValue<bool>( "active", false );
}
}
emit dataSetBrowserEvent( QString( "textureChanged" ), true );
}
void WQtDatasetBrowser::addTabWidgetContent( WQtDSBWidget* content )
......
......@@ -134,8 +134,10 @@ void WKernel::threadMain()
// default modules
m_moduleContainer->add( m_moduleFactory->create( m_moduleFactory->getPrototypeByName( "Navigation Slice Module" ) ) , true );
m_moduleContainer->add( m_moduleFactory->create( m_moduleFactory->getPrototypeByName( "Coordinate System Module" ) ) , true );
m_moduleContainer->add( m_moduleFactory->create( m_moduleFactory->getPrototypeByName( "HUD" ) ) , true );
m_moduleContainer->add( m_moduleFactory->create( m_moduleFactory->getPrototypeByName( "Fiber Display Module" ) ) , true );
// actually there is nothing more to do here
waitForStop();
......
......@@ -39,6 +39,7 @@
#include "../modules/distanceMap/WMDistanceMap.h"
#include "../modules/eegTest/WMEEGTest.h"
#include "../modules/textureList/WMTextureList.h"
#include "../modules/hud/WMHud.h"
#include "exceptions/WPrototypeUnknown.h"
#include "exceptions/WPrototypeNotUnique.h"
......@@ -77,6 +78,7 @@ void WModuleFactory::load()
m_prototypes.insert( boost::shared_ptr< WModule >( new WMMarchingCubes() ) );
m_prototypes.insert( boost::shared_ptr< WModule >( new WMDistanceMap() ) );
m_prototypes.insert( boost::shared_ptr< WModule >( new WMTextureList() ) );
m_prototypes.insert( boost::shared_ptr< WModule >( new WMHud() ) );
lock.unlock();
......
......@@ -77,6 +77,7 @@ void WMCoordinateSystem::connectToGui()
void WMCoordinateSystem::properties()
{
m_properties->addBool( "dataSetAdded", false, true );
( m_properties->addBool( "active", true, true ) )->connect( boost::bind( &WMCoordinateSystem::slotPropertyChanged, this, _1 ) );
m_properties->addInt( "axialPos", 80 );
m_properties->addInt( "coronalPos", 100 );
......@@ -416,3 +417,18 @@ void WMCoordinateSystem::findBoundingBox()
}
}
}
void WMCoordinateSystem::slotPropertyChanged( std::string propertyName )
{
if ( propertyName == "active" )
{
if ( m_properties->getValue<bool>( "active" ) )
{
m_rootNode->setNodeMask( 0xFFFFFFFF );
}
else
{
m_rootNode->setNodeMask( 0x0 );
}
}
}
......@@ -99,6 +99,12 @@ private:
*/
void properties();
/**
* Gets signaled from the properties object when something was changed
*/
void slotPropertyChanged( std::string propertyName );
/**
* initial creation function for the slice geometry
*/
......
//---------------------------------------------------------------------------
//
// Project: OpenWalnut ( http://www.openwalnut.org )
//
// Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
// For more information see http://www.openwalnut.org/copying
//
// This file is part of OpenWalnut.
//
// OpenWalnut is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// OpenWalnut is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
//
//---------------------------------------------------------------------------
#include <string>
#include <osg/MatrixTransform>
#include <osg/Projection>
#include "../../kernel/WKernel.h"
#include "WMHud.h"
WMHud::WMHud()
{
}
WMHud::~WMHud()
{
}
boost::shared_ptr< WModule > WMHud::factory() const
{
return boost::shared_ptr< WModule >( new WMHud() );
}
const std::string WMHud::getName() const
{
return "HUD";
}
const std::string WMHud::getDescription() const
{
return "This module provides several HUD's for status displays";
}
void WMHud::connectors()
{
}
void WMHud::properties()
{
( m_properties->addBool( "active", true, true ) )->connect( boost::bind( &WMHud::slotPropertyChanged, this, _1 ) );
m_properties->addBool( "showHUD1", false );
}
void WMHud::notifyDataChange( boost::shared_ptr<WModuleConnector> /*input*/,
boost::shared_ptr<WModuleConnector> /*output*/ )
{
}
void WMHud::moduleMain()
{
init();
// Since the modules run in a separate thread: wait
waitForStop();
// clean up stuff
// NOTE: ALLAWAYS remove your osg nodes!
WKernel::getRunningKernel()->getGraphicsEngine()->getScene()->removeChild( m_rootNode );
}
void WMHud::connectToGui()
{
WKernel::getRunningKernel()->getGui()->connectProperties( m_properties );
WKernel::getRunningKernel()->getGui()->addModuleToBrowser( shared_from_this() );
}
void WMHud::init()
{
m_rootNode = osg::ref_ptr< osg::Projection >( new osg::Projection );
m_rootNode->setName( "HUDNode" );
// Initialize the projection matrix for viewing everything we
// will add as descendants of this node. Use screen coordinates
// to define the horizontal and vertical extent of the projection
// matrix. Positions described under this node will equate to
// pixel coordinates.
m_rootNode->setMatrix( osg::Matrix::ortho2D( 0, 1024, 0, 768 ) );
// For the HUD model view matrix use an identity matrix
osg::MatrixTransform* HUDModelViewMatrix = new osg::MatrixTransform;
HUDModelViewMatrix->setMatrix( osg::Matrix::identity() );
// Make sure the model view matrix is not affected by any transforms
// above it in the scene graph
HUDModelViewMatrix->setReferenceFrame( osg::Transform::ABSOLUTE_RF );
// Add the HUD projection matrix as a child of the root node
// and the HUD model view matrix as a child of the projection matrix
// Anything under this node will be viewed using this projection matrix
// and positioned with this model view matrix.
//root->addChild(HUDProjectionMatrix);
WKernel::getRunningKernel()->getGraphicsEngine()->getScene()->addChild( m_rootNode );
m_rootNode->addChild( HUDModelViewMatrix );
// Add the Geometry node to contain HUD geometry as a child of the
// HUD model view matrix.
m_HUDs = osg::ref_ptr<osg::Group>( new osg::Group() );
// A geometry node for our HUD
osg::ref_ptr<osg::Geode> HUDGeode = osg::ref_ptr<osg::Geode>( new osg::Geode() );
HUDModelViewMatrix->addChild( m_HUDs );
m_HUDs->addChild( HUDGeode );
// Set up geometry for the HUD and add it to the HUD
osg::Geometry* HUDBackgroundGeometry = new osg::Geometry();
osg::Vec3Array* HUDBackgroundVertices = new osg::Vec3Array;
HUDBackgroundVertices->push_back( osg::Vec3( 600, 0, -1 ) );
HUDBackgroundVertices->push_back( osg::Vec3( 1024, 0, -1 ) );
HUDBackgroundVertices->push_back( osg::Vec3( 1024, 100, -1 ) );
HUDBackgroundVertices->push_back( osg::Vec3( 600, 100, -1 ) );
osg::DrawElementsUInt* HUDBackgroundIndices = new osg::DrawElementsUInt( osg::PrimitiveSet::POLYGON, 0 );
HUDBackgroundIndices->push_back( 0 );
HUDBackgroundIndices->push_back( 1 );
HUDBackgroundIndices->push_back( 2 );
HUDBackgroundIndices->push_back( 3 );
osg::Vec4Array* HUDcolors = new osg::Vec4Array;
HUDcolors->push_back( osg::Vec4( 0.8f, 0.8f, 0.8f, 0.8f ) );
osg::Vec3Array* HUDnormals = new osg::Vec3Array;
HUDnormals->push_back( osg::Vec3( 0.0f, 0.0f, 1.0f ) );
HUDBackgroundGeometry->setNormalArray( HUDnormals );
HUDBackgroundGeometry->setNormalBinding( osg::Geometry::BIND_OVERALL );
HUDBackgroundGeometry->addPrimitiveSet( HUDBackgroundIndices );
HUDBackgroundGeometry->setVertexArray( HUDBackgroundVertices );
HUDBackgroundGeometry->setColorArray( HUDcolors );
HUDBackgroundGeometry->setColorBinding( osg::Geometry::BIND_OVERALL );
HUDGeode->addDrawable( HUDBackgroundGeometry );
// Create and set up a state set using the texture from above
osg::StateSet* HUDStateSet = new osg::StateSet();
HUDGeode->setStateSet( HUDStateSet );
// For this state set, turn blending on (so alpha texture looks right)
HUDStateSet->setMode( GL_BLEND, osg::StateAttribute::ON );
// Disable depth testing so geometry is draw regardless of depth values
// of geometry already draw.
HUDStateSet->setMode( GL_DEPTH_TEST, osg::StateAttribute::OFF );
HUDStateSet->setRenderingHint( osg::StateSet::TRANSPARENT_BIN );
// Need to make sure this geometry is draw last. RenderBins are handled
// in numerical order so set bin number to 11
HUDStateSet->setRenderBinDetails( 11, "RenderBin" );
m_rootNode->setUserData( this );
m_rootNode->setUpdateCallback( new HUDNodeCallback );
}
void WMHud::update()
{
}
void WMHud::slotPropertyChanged( std::string propertyName )
{
if ( propertyName == "active" )
{
if ( m_properties->getValue<bool>( "active" ) )
{
m_rootNode->setNodeMask( 0xFFFFFFFF );
}
else
{
m_rootNode->setNodeMask( 0x0 );
}
}
}
//---------------------------------------------------------------------------
//
// Project: OpenWalnut ( http://www.openwalnut.org )
//
// Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
// For more information see http://www.openwalnut.org/copying
//
// This file is part of OpenWalnut.
//
// OpenWalnut is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// OpenWalnut is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
//
//---------------------------------------------------------------------------
#ifndef WMHUD_H
#define WMHUD_H
#include <string>
#include <osg/Group>
#include <osg/Geode>
#include <osg/Geometry>
#include <osg/Node>
#include "../../kernel/WModule.h"
/**
* This module implements several onscreen status displays
*/
class WMHud : public WModule, public osg::Referenced
{
public:
/**
* standard constructor
*/
WMHud();
/**
* destructor
*/
virtual ~WMHud();
/**
* \par Description
* Gives back the name of this module.
* \return the module's name.
*/
virtual const std::string getName() const;
/**
* \par Description
* Gives back a description of this module.
* \return description to module.
*/
virtual const std::string getDescription() const;
/**
* Connect the listener function of the module to the gui signals
* this has to be called after full initialization fo the gui
*/
void connectToGui();
protected:
/**
* \par Description
* Entry point after loading the module. Runs in separate thread.
*/
virtual void moduleMain();
/**
* Initialize the connectors this module is using.
*/
virtual void connectors();
/**
* Initialize the properties for this module.
*/
virtual void properties();
/**
* Receive DATA_CHANGE notifications.
*
* \param input the input connector that got the change signal. Typically it is one of the input connectors from this module.
* \param output the output connector that sent the signal. Not part of this module instance.
*/
virtual void notifyDataChange( boost::shared_ptr<WModuleConnector> input,
boost::shared_ptr<WModuleConnector> output );
/**
* Due to the prototype design pattern used to build modules, this method returns a new instance of this method. NOTE: it
* should never be initialized or modified in some other way. A simple new instance is required.
*
* \return the prototype used to create every module in OpenWalnut.
*/
virtual boost::shared_ptr< WModule > factory() const;
private:
// Projection node for defining view frustrum for HUD
osg::ref_ptr<osg::Projection> m_rootNode;
osg::ref_ptr<osg::Group>m_HUDs;
void init();
void update();
/**
* Gets signaled from the properties object when something was changed
*/
void slotPropertyChanged( std::string propertyName );
class HUDNodeCallback : public osg::NodeCallback
{
public: // NOLINT
virtual void operator()( osg::Node* node, osg::NodeVisitor* nv )
{
osg::ref_ptr< WMHud > module = static_cast< WMHud* > ( node->getUserData() );
if ( module )
{
module->update();
}
traverse( node, nv );
}
};
};
#endif // WMHUD_H
......@@ -104,7 +104,8 @@ void WMNavSlices::connectors()
void WMNavSlices::properties()
{
m_properties->addBool( "textureChanged", false, true );
//( m_properties->addBool( "active", true, true ) )->connect( boost::bind( &WMNavSlices::slotPropertyChanged, this, _1 ) );
m_properties->addBool( "active", true, true );
m_properties->addInt( "axialPos", 80 );
m_properties->addInt( "coronalPos", 100 );
m_properties->addInt( "sagittalPos", 80 );
......
......@@ -174,7 +174,7 @@ private:
class sliceNodeCallback : public osg::NodeCallback
{
public:
public: // NOLINT
virtual void operator()( osg::Node* node, osg::NodeVisitor* nv )
{
osg::ref_ptr< WMNavSlices > module = static_cast< WMNavSlices* > ( node->getUserData() );
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment