Commit bb432264 authored by cornimueller's avatar cornimueller
Browse files

[ADD #212] Added new projection mode "TWO_D" which can be used for 2D-views...

[ADD #212] Added new projection mode "TWO_D" which can be used for 2D-views like the one needed for an EEG display.
parent 3caf16a4
......@@ -41,7 +41,7 @@ public:
*/
enum ProjectionMode
{
ORTHOGRAPHIC, PERSPECTIVE
ORTHOGRAPHIC, PERSPECTIVE, TWO_D
};
/**
......
......@@ -50,7 +50,8 @@ WGEViewer::WGEViewer( std::string name, osg::ref_ptr<WindowData> wdata, int x, i
int width, int height, WGECamera::ProjectionMode projectionMode )
: WGEGraphicsWindow( wdata, x, y, width, height ),
boost::enable_shared_from_this< WGEViewer >(),
m_name( name )
m_name( name ),
m_projectionMode( projectionMode )
{
try
{
......@@ -62,10 +63,22 @@ WGEViewer::WGEViewer( std::string name, osg::ref_ptr<WindowData> wdata, int x, i
case( WGECamera::ORTHOGRAPHIC ):
m_View->getCamera()->setProjectionMatrixAsOrtho(
-120.0 * width / height, 120.0 * width / height, -120.0, 120.0, -1000.0, +1000.0 );
m_View->getCamera()->setProjectionResizePolicy( osg::Camera::HORIZONTAL );
// camera manipulator
m_View->setCameraManipulator( new WGEZoomTrackballManipulator() );
break;
case( WGECamera::PERSPECTIVE ):
m_View->getCamera()->setProjectionMatrixAsPerspective(
30.0, static_cast< double >( width ) / static_cast< double >( height ), 1.0, 1000.0 );
m_View->getCamera()->setProjectionResizePolicy( osg::Camera::HORIZONTAL );
// camera manipulator
m_View->setCameraManipulator( new WGEZoomTrackballManipulator() );
break;
case( WGECamera::TWO_D ):
m_View->getCamera()->setProjectionMatrixAsOrtho2D( 0.0, width, 0.0, height );
m_View->getCamera()->setProjectionResizePolicy( osg::Camera::FIXED );
break;
default:
throw WGEInitFailed( "Unknown projection mode" );
......@@ -73,15 +86,11 @@ WGEViewer::WGEViewer( std::string name, osg::ref_ptr<WindowData> wdata, int x, i
}
m_View->getCamera()->setViewport( 0, 0, width, height );
m_View->getCamera()->setProjectionResizePolicy( osg::Camera::HORIZONTAL );
m_View->getCamera()->setClearColor( osg::Vec4( .9, .9, .9, 1. ) );
// add the stats handler
m_View->addEventHandler( new osgViewer::StatsHandler );
// camera manipulator
m_View->setCameraManipulator( new WGEZoomTrackballManipulator() );
m_View->setLightingMode( osg::View::HEADLIGHT ); // this is the default anyway
m_pickHandler = osg::ref_ptr<WPickHandler>( new WPickHandler() );
......@@ -147,6 +156,11 @@ void WGEViewer::resize( int width, int height )
// also update the camera
m_View->getCamera()->setViewport( 0, 0, width, height );
if( m_projectionMode == WGECamera::TWO_D )
{
m_View->getCamera()->setProjectionMatrixAsOrtho2D( 0.0, width, 0.0, height );
}
}
void WGEViewer::close()
......
......@@ -174,6 +174,11 @@ protected:
*/
std::string m_name;
/**
* The projection mode of the viewer.
*/
WGECamera::ProjectionMode m_projectionMode;
/**
* Reference to the pick handler of the viewer.
*/
......
......@@ -34,6 +34,7 @@
#include "../common/WThreadedRunner.h"
#include "../common/WFlag.h"
#include "../kernel/WModule.h"
#include "../graphicsEngine/WGECamera.h"
/**
......@@ -101,8 +102,9 @@ public:
* Instruct the MainWindow to create a new custom widget.
*
* \param title The title of the widget
* \param projectionMode The kind of projection which should be used
*/
virtual void createCustomWidget( std::string title ) = 0;
virtual void createCustomWidget( std::string title, WGECamera::ProjectionMode projectionMode = WGECamera::ORTHOGRAPHIC ) = 0;
/**
* Instruct the MainWindow to close a custom widget.
......
......@@ -27,9 +27,11 @@
#include "../../common/WConditionOneShot.h"
#include "WCreateCustomDockWidgetEvent.h"
WCreateCustomDockWidgetEvent::WCreateCustomDockWidgetEvent( std::string title, boost::shared_ptr< WConditionOneShot > condition )
WCreateCustomDockWidgetEvent::WCreateCustomDockWidgetEvent(
std::string title, WGECamera::ProjectionMode projectionMode, boost::shared_ptr< WConditionOneShot > condition )
: QEvent( CUSTOM_TYPE ),
m_title( title ),
m_projectionMode( projectionMode ),
m_condition( condition )
{
}
......@@ -39,6 +41,11 @@ std::string WCreateCustomDockWidgetEvent::getTitle() const
return m_title;
}
WGECamera::ProjectionMode WCreateCustomDockWidgetEvent::getProjectionMode() const
{
return m_projectionMode;
}
boost::shared_ptr< WConditionOneShot > WCreateCustomDockWidgetEvent::getCondition() const
{
return m_condition;
......
......@@ -28,6 +28,7 @@
#include <string>
#include <QtCore/QEvent>
#include "../../graphicsEngine/WGECamera.h"
#include "../../common/WConditionOneShot.h"
/**
......@@ -40,9 +41,11 @@ public:
* constructor
*
* \param title The title of the widget to create.
* \param projectionMode The kind of projection which should be used
* \param condition The condition which waits until the widget is created.
*/
explicit WCreateCustomDockWidgetEvent( std::string title, boost::shared_ptr< WConditionOneShot > condition );
explicit WCreateCustomDockWidgetEvent(
std::string title, WGECamera::ProjectionMode projectionMode, boost::shared_ptr< WConditionOneShot > condition );
/**
* Get the title of the widget to create.
......@@ -51,6 +54,13 @@ public:
*/
std::string getTitle() const;
/**
* Get the kind of projection which should be used.
*
* \return the kind of projection which should be used
*/
WGECamera::ProjectionMode getProjectionMode() const;
/**
* Get the condition which waits until the widget is created.
*
......@@ -71,6 +81,11 @@ private:
*/
std::string m_title;
/**
* the kind of projection which should be used
*/
WGECamera::ProjectionMode m_projectionMode;
/**
* Condition which waits until the widget is created.
*/
......
......@@ -292,7 +292,8 @@ void WMainWindow::customEvent( QEvent* event )
WCreateCustomDockWidgetEvent* ccdwEvent = static_cast< WCreateCustomDockWidgetEvent* >( event );
std::string title = ccdwEvent->getTitle();
boost::shared_ptr< WQtCustomDockWidget > widget = boost::shared_ptr< WQtCustomDockWidget >( new WQtCustomDockWidget( title, this ) );
boost::shared_ptr< WQtCustomDockWidget > widget = boost::shared_ptr< WQtCustomDockWidget >(
new WQtCustomDockWidget( title, this, ccdwEvent->getProjectionMode() ) );
addDockWidget( Qt::BottomDockWidgetArea, widget.get() );
// store it in CustomDockWidget list
......
......@@ -227,10 +227,10 @@ boost::signals2::signal1< void, std::string >* WQt4Gui::getPickSignal()
return m_gui->getPickSignal();
}
void WQt4Gui::createCustomWidget( std::string title )
void WQt4Gui::createCustomWidget( std::string title, WGECamera::ProjectionMode projectionMode )
{
boost::shared_ptr< WConditionOneShot > condition( new WConditionOneShot );
QCoreApplication::postEvent( m_gui, new WCreateCustomDockWidgetEvent( title, condition ) );
QCoreApplication::postEvent( m_gui, new WCreateCustomDockWidgetEvent( title, projectionMode, condition ) );
condition->wait();
}
......
......@@ -101,8 +101,9 @@ public:
* Instruct the WMainWindow to create a new custom widget.
*
* \param title The title of the widget
* \param projectionMode The kind of projection which should be used
*/
virtual void createCustomWidget( std::string title );
virtual void createCustomWidget( std::string title, WGECamera::ProjectionMode projectionMode = WGECamera::ORTHOGRAPHIC );
/**
* Instruct the WMainWindow to close a custom widget.
......
......@@ -27,13 +27,13 @@
#include "WQtCustomDockWidget.h"
#include <QtGui/QCloseEvent>
WQtCustomDockWidget::WQtCustomDockWidget( std::string title, QWidget* parent )
WQtCustomDockWidget::WQtCustomDockWidget( std::string title, QWidget* parent, WGECamera::ProjectionMode projectionMode )
: QDockWidget( QString::fromStdString( title ), parent )
{
// setAllowedAreas( Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea );
setFeatures( QDockWidget::DockWidgetMovable | QDockWidget::DockWidgetFloatable );
m_glWidget = boost::shared_ptr< WQtGLWidget >( new WQtGLWidget( title, this, WGECamera::PERSPECTIVE ) );
m_glWidget = boost::shared_ptr< WQtGLWidget >( new WQtGLWidget( title, this, projectionMode ) );
m_glWidget->initialize();
setWidget( m_glWidget.get() );
......
......@@ -40,8 +40,9 @@ public:
*
* \param title the title of the widget
* \param parent the parent of the widget
* \param projectionMode The kind of projection which should be used
*/
WQtCustomDockWidget( std::string title, QWidget* parent );
WQtCustomDockWidget( std::string title, QWidget* parent, WGECamera::ProjectionMode projectionMode );
protected:
/**
......
......@@ -24,8 +24,30 @@
#include <string>
#include "WMEEGView.h"
#include <osgUtil/Optimizer>
#include <osgDB/ReadFile>
#include <osgViewer/Viewer>
#include <osgViewer/CompositeViewer>
#include <osgGA/TrackballManipulator>
#include <osg/Material>
#include <osg/Geode>
#include <osg/BlendFunc>
#include <osg/Depth>
#include <osg/PolygonOffset>
#include <osg/MatrixTransform>
#include <osg/Camera>
#include <osg/RenderInfo>
#include <osgDB/WriteFile>
#include <osgText/Text>
#include "../../kernel/WKernel.h"
#include "../../graphicsEngine/WGEViewer.h"
#include "WMEEGView.h"
WMEEGView::WMEEGView()
: WModule()
......@@ -54,12 +76,137 @@ const std::string WMEEGView::getDescription() const
void WMEEGView::moduleMain()
{
// do initialization
WKernel::getRunningKernel()->getGui()->createCustomWidget( "EEG View" );
WKernel::getRunningKernel()->getGui()->createCustomWidget( "EEG View", WGECamera::TWO_D );
std::cout << "Loaded EEG View widget\n";
boost::shared_ptr< WGEViewer > viewer = WGraphicsEngine::getGraphicsEngine()->getViewerByName( "EEG View" );
viewer->setScene( createText() ); //should created OSG-Nodes be deleted?
ready();
waitForStop();
WKernel::getRunningKernel()->getGui()->closeCustomWidget( "EEG View" );
}
osg::Node* WMEEGView::createText()
{
osg::Geode* geode = new osg::Geode();
std::string timesFont( "fonts/arial.ttf" );
// turn lighting off for the text and disable depth test to ensure its always ontop.
osg::StateSet* stateset = geode->getOrCreateStateSet();
stateset->setMode( GL_LIGHTING, osg::StateAttribute::OFF );
osg::Vec3 position( 150.0f, 800.0f, 0.0f );
osg::Vec3 delta( 0.0f, -120.0f, 0.0f );
{
osgText::Text* text = new osgText::Text;
geode->addDrawable( text );
text->setFont( timesFont );
text->setPosition( position );
text->setText( "Head Up Displays are simple :-)" );
position += delta;
}
{
osgText::Text* text = new osgText::Text;
geode->addDrawable( text );
text->setFont( timesFont );
text->setPosition( position );
text->setText( "All you need to do is create your text in a subgraph." );
position += delta;
}
{
osgText::Text* text = new osgText::Text;
geode->addDrawable( text );
text->setFont( timesFont );
text->setPosition( position );
text->setText( "Then place an osg::Camera above the subgraph\n"
"to create an orthographic projection.\n" );
position += delta;
}
{
osgText::Text* text = new osgText::Text;
geode->addDrawable( text );
text->setFont( timesFont );
text->setPosition( position );
text->setText( "Set the Camera's ReferenceFrame to ABSOLUTE_RF to ensure\n"
"it remains independent from any external model view matrices." );
position += delta;
}
{
osgText::Text* text = new osgText::Text;
geode->addDrawable( text );
text->setFont( timesFont );
text->setPosition( position );
text->setText( "And set the Camera's clear mask to just clear the depth buffer." );
position += delta;
}
{
osgText::Text* text = new osgText::Text;
geode->addDrawable( text );
text->setFont( timesFont );
text->setPosition( position );
text->setText( "And finally set the Camera's RenderOrder to POST_RENDER\n"
"to make sure its drawn last." );
position += delta;
}
{
osg::BoundingBox bb;
for( unsigned int i = 0; i < geode->getNumDrawables(); ++i)
{
bb.expandBy( geode->getDrawable( i )->getBound() );
}
osg::Geometry* geom = new osg::Geometry;
osg::Vec3Array* vertices = new osg::Vec3Array;
float depth = bb.zMin()-0.1;
vertices->push_back( osg::Vec3( bb.xMin(), bb.yMax(), depth ) );
vertices->push_back( osg::Vec3( bb.xMin(), bb.yMin(), depth ) );
vertices->push_back( osg::Vec3( bb.xMax(), bb.yMin(), depth ) );
vertices->push_back( osg::Vec3( bb.xMax(), bb.yMax(), depth ) );
geom->setVertexArray( vertices );
osg::Vec3Array* normals = new osg::Vec3Array;
normals->push_back( osg::Vec3( 0.0f, 0.0f, 1.0f ) );
geom->setNormalArray( normals );
geom->setNormalBinding( osg::Geometry::BIND_OVERALL );
osg::Vec4Array* colors = new osg::Vec4Array;
colors->push_back( osg::Vec4( 1.0f, 1.0, 0.8f, 0.2f ) );
geom->setColorArray( colors );
geom->setColorBinding( osg::Geometry::BIND_OVERALL );
geom->addPrimitiveSet( new osg::DrawArrays( GL_QUADS, 0, 4 ) );
osg::StateSet* stateset = geom->getOrCreateStateSet();
stateset->setMode( GL_BLEND, osg::StateAttribute::ON );
//stateset->setAttribute(new osg::PolygonOffset(1.0f,1.0f),osg::StateAttribute::ON);
stateset->setRenderingHint( osg::StateSet::TRANSPARENT_BIN );
geode->addDrawable( geom );
}
return geode;
}
......@@ -76,6 +76,12 @@ protected:
virtual void moduleMain();
private:
/**
* Sample HUD-Text. Copied from an OSG-Example
*
* \return OSG-Graph
*/
osg::Node* createText();
};
#endif // WMEEGVIEW_H
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