Commit c3e12e05 authored by Alexander Wiebel's avatar Alexander Wiebel
Browse files

[MERGE]

parents 8e0581fe d989572a
......@@ -49,6 +49,11 @@ osg::Matrixd WGEZoomTrackballManipulator::getMatrix() const
return osg::Matrixd::scale( 1.0 / m_zoom, 1.0 / m_zoom, 1.0 / m_zoom ) * TrackballManipulator::getMatrix();
}
osg::Matrixd WGEZoomTrackballManipulator::getMatrixWithoutZoom() const
{
return TrackballManipulator::getMatrix();
}
osg::Matrixd WGEZoomTrackballManipulator::getInverseMatrix() const
{
return TrackballManipulator::getInverseMatrix() * osg::Matrixd::scale( m_zoom, m_zoom, m_zoom );
......
......@@ -50,6 +50,13 @@ public:
*/
virtual osg::Matrixd getMatrix() const;
/**
* Get the manipulator only containing rotation and translation.
*
* \return the matrix with translation and rotation.
*/
virtual osg::Matrixd getMatrixWithoutZoom() const;
/**
* Get the position of the manipulator as a inverse matrix of the
* manipulator, typically used as a model view matrix.
......
FILE( GLOB_RECURSE MODULES_SRC "*.cpp" "*.h" )
# Grab module name and setup target directories
GET_FILENAME_COMPONENT( MODULE_NAME ${CMAKE_CURRENT_SOURCE_DIR} NAME )
SET( MODULE_TARGET_DIR ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/modules/${MODULE_NAME} )
SET( CMAKE_LIBRARY_OUTPUT_DIRECTORY ${MODULE_TARGET_DIR} )
SET( CMAKE_RUNTIME_OUTPUT_DIRECTORY ${MODULE_TARGET_DIR} )
SET( MODULE_DIRNAME ${MODULE_NAME} )
SET( MODULE_NAME "OWmodule_${MODULE_NAME}" ) # prefix all module names with "OWmodule_" to separate them from other libs
# Build module lib
ADD_LIBRARY( ${MODULE_NAME} SHARED ${MODULES_SRC} )
TARGET_LINK_LIBRARIES( ${MODULE_NAME} OWkernel )
# Copy local shaders to module target directory
IF( OW_COPY_SHADERS AND EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/shaders ) # copy shaders only if the user wants it
ADD_CUSTOM_TARGET( ${MODULE_NAME}_CopyShaders
COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_SOURCE_DIR}/shaders ${MODULE_TARGET_DIR}/shaders/
COMMENT "Copy shaders of ${MODULE_NAME}"
)
ADD_DEPENDENCIES( ${MODULE_NAME} ${MODULE_NAME}_CopyShaders )
ENDIF()
# Build unit tests
IF( OW_COMPILE_TESTS )
# This ensures that the test is copied to the module directory
SET( CMAKE_RUNTIME_OUTPUT_DIRECTORY ${MODULE_TARGET_DIR} )
CXXTEST_ADD_TESTS_FROM_LIST( "${MODULES_SRC}"
"OWkernel;${MODULE_NAME}"
)
# Copy fixtures if they exist
IF( EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/test/fixtures )
ADD_CUSTOM_TARGET( ${MODULE_NAME}_CopyFixtures
# as the "test" target runs in CMakes temporary build dir, the fixtures need to be placed there too.
COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_SOURCE_DIR}/test/fixtures ${CMAKE_BINARY_DIR}/modules/${MODULE_DIRNAME}/fixtures/
COMMENT "Copy fixtures of ${MODULE_NAME}"
)
ADD_DEPENDENCIES( ${MODULE_NAME} ${MODULE_NAME}_CopyFixtures )
ENDIF( EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/test/fixtures )
ENDIF( OW_COMPILE_TESTS )
//---------------------------------------------------------------------------
//
// 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/ShapeDrawable>
#include <osg/Group>
#include <osg/Geode>
#include <osg/MatrixTransform>
#include <osg/Material>
#include <osg/StateAttribute>
#include <osg/Vec3>
#include <osg/Geometry>
#include "../../kernel/WKernel.h"
#include "../../common/WColor.h"
#include "../../common/WPropertyHelper.h"
#include "../../graphicsEngine/WGEUtils.h"
#include "WMCoordinateHUD.h"
#include "coordinateHUD.xpm"
#include "option_1.xpm"
#include "option_2.xpm"
#include "option_3.xpm"
// This line is needed by the module loader to actually find your module.
W_LOADABLE_MODULE( WMCoordinateHUD )
WMCoordinateHUD::WMCoordinateHUD():WModule()
{
}
WMCoordinateHUD::~WMCoordinateHUD()
{
}
boost::shared_ptr< WModule > WMCoordinateHUD::factory() const
{
return boost::shared_ptr< WModule >( new WMCoordinateHUD() );
}
const char** WMCoordinateHUD::getXPMIcon() const
{
return coordinateHUD_xpm;
}
const std::string WMCoordinateHUD::getName() const
{
return "CoordinateHUD";
}
const std::string WMCoordinateHUD::getDescription() const
{
return "This module is to display a coordinatesystem as HUD.";
}
void WMCoordinateHUD::connectors()
{
}
void WMCoordinateHUD::properties()
{
m_propCondition = boost::shared_ptr< WCondition >( new WCondition() );
// list of alternatives:
m_possibleSelections = boost::shared_ptr< WItemSelection >( new WItemSelection() );
m_possibleSelections->addItem( "colored axis", "colorfull coordinate axis", option_1_xpm );
m_possibleSelections->addItem( "b/w axis", "black & white coordinate axis", option_2_xpm );
m_possibleSelections->addItem( "colored cube", "colorfull coordinate cube", option_3_xpm );
m_aSingleSelection = m_properties->addProperty( "HUD structure",
"Which look should the coordinateHUD have?", m_possibleSelections->getSelector( 2 ),
m_propCondition );
WPropertyHelper::PC_SELECTONLYONE::addTo( m_aSingleSelection );
WPropertyHelper::PC_NOTEMPTY::addTo( m_aSingleSelection );
// set the x axis color if in color axis or color cube mode
}
void WMCoordinateHUD::moduleMain()
{
// added own shader for visualisation as HUD
m_shader = osg::ref_ptr< WShader > ( new WShader( "WMCoordinateHUD" , m_localPath ) );
m_rootNode = new WGEManagedGroupNode( m_active );
m_rootNode->setName( "coordHUDNode" );
m_shader->apply( m_rootNode );
WKernel::getRunningKernel()->getGraphicsEngine()->getScene()->insert( m_rootNode );
// let the main loop awake if the properties changed.
debugLog() << "Entering moduleMain()";
m_moduleState.setResetable( true, true );
m_moduleState.add( m_propCondition );
// signal ready state
ready();
debugLog() << "Module is now ready.";
while( !m_shutdownFlag() )
{
WItemSelector s = m_aSingleSelection->get( true );
debugLog() << "New mode selected: " << s.at( 0 ).name;
if ( s.at( 0 ).name == "colored axis" )
{
buildColorAxis();
}
else if ( s.at( 0 ).name == "b/w axis" )
{
buildBWAxis();
}
else if ( s.at( 0 ).name == "colored cube" )
{
buildColorCube();
}
//update node
m_rootNode->clear();
m_geode->setCullingActive( false ); // this disables frustrum culling for the geode to avoid the coordinate system to disappear.
m_rootNode->setCullingActive( false );
m_rootNode->insert( m_geode );
debugLog() << "Waiting ...";
m_moduleState.wait();
// quit if requested
if ( m_shutdownFlag() )
{
break;
}
}
// remove the node from the graph
WKernel::getRunningKernel()->getGraphicsEngine()->getScene()->remove( m_rootNode );
}
void WMCoordinateHUD::buildColorAxis()
{
// build the geometry & geode for the coordinate axis
osg::ref_ptr< osg::Geode > coordGeode = new osg::Geode();
osg::ref_ptr< osg::Geometry> coordGeom = new osg::Geometry;
// Vertices
osg::Vec3Array* vertices = new osg::Vec3Array;
vertices = buildAxisVertices();
// Colors
osg::Vec4 x_color( 1.0f, 0.0f, 0.0f, 1.0f ); //red
osg::Vec4 y_color( 0.0f, 1.0f, 0.0f, 1.0f ); //green
osg::Vec4 z_color( 0.0f, 0.0f, 1.0f, 1.0f ); //blue
osg::Vec4 neg_color( 1.0f, 1.0f, 1.0f, 1.0f ); //white
// x direction transition from red to white
// y direction transition from green to white
// z direction transition from blue to white
osg::Vec4Array* color = new osg::Vec4Array( 12 );
(*color)[0] = y_color;
(*color)[1] = y_color;
(*color)[2] = x_color;
(*color)[3] = x_color;
(*color)[4] = z_color;
(*color)[5] = z_color;
(*color)[6] = y_color;
(*color)[7] = neg_color;
(*color)[8] = x_color;
(*color)[9] = neg_color;
(*color)[10] = z_color;
(*color)[11] = neg_color;
// add color to geometry
coordGeom->setColorArray( color );
coordGeom->setColorBinding( osg::Geometry::BIND_PER_VERTEX );
// primitives = draw lines between vertices
osg::DrawArrays *da = new osg::DrawArrays( osg::PrimitiveSet::LINES, 0, vertices->size( ) );
// add geometry to geode
coordGeom->setVertexArray( vertices );
coordGeom->addPrimitiveSet( da );
coordGeode->addDrawable( coordGeom );
coordGeode->getOrCreateStateSet()->setMode( GL_LIGHTING, osg::StateAttribute::OFF );
m_geode = coordGeode;
}
void WMCoordinateHUD::buildBWAxis()
{
//build the geometry & geode for the coordinate axis
osg::ref_ptr< osg::Geode > coordGeode = new osg::Geode();
osg::ref_ptr< osg::Geometry> coordGeom = new osg::Geometry;
//Vertices
osg::Vec3Array* vertices = new osg::Vec3Array;
vertices = buildAxisVertices();
//Colors
osg::Vec4 b_color( 0.0f, 0.0f, 0.0f, 1.0f ); //black
osg::Vec4 w_color( 1.0f, 1.0f, 1.0f, 1.0f ); //white
osg::Vec4Array* color = new osg::Vec4Array( 12 );
(*color)[0] = b_color;
(*color)[1] = b_color;
(*color)[2] = b_color;
(*color)[3] = b_color;
(*color)[4] = b_color;
(*color)[5] = b_color;
(*color)[6] = b_color;
(*color)[7] = w_color;
(*color)[8] = b_color;
(*color)[9] = w_color;
(*color)[10] = b_color;
(*color)[11] = w_color;
//add color to geometry
coordGeom->setColorArray( color );
coordGeom->setColorBinding( osg::Geometry::BIND_PER_VERTEX );
//primitives = draw lines between vertices
osg::DrawArrays *da = new osg::DrawArrays( osg::PrimitiveSet::LINES, 0, vertices->size( ) );
//add geometry to geode
coordGeom->setVertexArray( vertices );
coordGeom->addPrimitiveSet( da );
coordGeode->addDrawable( coordGeom );
coordGeode->getOrCreateStateSet()->setMode( GL_LIGHTING, osg::StateAttribute::OFF );
m_geode = coordGeode;
}
void WMCoordinateHUD::buildColorCube()
{
// build the geometry & geode for the coordinate axis
osg::ref_ptr< osg::Geode > coordGeode = new osg::Geode();
osg::ref_ptr< osg::Geometry> coordGeom = new osg::Geometry;
// Vertices
osg::Vec3Array* vertices = new osg::Vec3Array( 36 );
vertices = buildCubeVertices();
// Colors
osg::Vec4 x_color( 0.9f, 0.0f, 0.0f, 1.0f ); // red
osg::Vec4 xl_color( 1.0f, 0.7f, 0.7f, 1.0f ); // lightred
osg::Vec4 y_color( 0.0f, 0.9f, 0.0f, 1.0f ); // green
osg::Vec4 yl_color( 0.7f, 1.0f, 0.7f, 1.0f ); // lightgreen
osg::Vec4 z_color( 0.0f, 0.0f, 0.9f, 1.0f ); // blue
osg::Vec4 zl_color( 0.7f, 0.7f, 1.0f, 1.0f ); // lightblue
osg::Vec4 neg_color( 1.0f, 1.0f, 1.0f, 1.0f ); // white
// x direction transition from red to lightred
// y direction transition from green to lightgreen
// z direction transition from blue to lightblue
osg::Vec4Array* color = new osg::Vec4Array( 12 );
(*color)[0] = (*color)[1] = y_color;
(*color)[2] = (*color)[3] = z_color;
(*color)[4] = (*color)[5] = x_color;
(*color)[6] = (*color)[7] = yl_color;
(*color)[8] = (*color)[9] = zl_color;
(*color)[10] = (*color)[11] = xl_color;
// add color to geometry
coordGeom->setColorArray( color );
coordGeom->setColorBinding( osg::Geometry::BIND_PER_PRIMITIVE );
// primitives = draw lines between vertices
osg::DrawArrays *da = new osg::DrawArrays( osg::PrimitiveSet::TRIANGLES, 0, vertices->size( ) );
// add geometry to geode
coordGeom->setVertexArray( vertices );
coordGeom->addPrimitiveSet( da );
coordGeode->addDrawable( coordGeom );
coordGeode->getOrCreateStateSet()->setMode( GL_LIGHTING, osg::StateAttribute::OFF );
m_geode = coordGeode;
}
osg::Vec3Array* WMCoordinateHUD::buildAxisVertices()
{
// Vertices
float size = 1.0;
osg::Vec3Array* vertices = new osg::Vec3Array;
vertices->push_back( osg::Vec3( 0, 0, 0 ) );
vertices->push_back( osg::Vec3( size, 0, 0 ) );
vertices->push_back( osg::Vec3( 0, 0, 0 ) );
vertices->push_back( osg::Vec3( 0, size, 0 ) );
vertices->push_back( osg::Vec3( 0, 0, 0 ) );
vertices->push_back( osg::Vec3( 0, 0, size ) );
vertices->push_back( osg::Vec3( 0, 0, 0 ) );
vertices->push_back( osg::Vec3( -size, 0, 0 ) );
vertices->push_back( osg::Vec3( 0, 0, 0 ) );
vertices->push_back( osg::Vec3( 0, -size, 0 ) );
vertices->push_back( osg::Vec3( 0, 0, 0 ) );
vertices->push_back( osg::Vec3( 0, 0, -size ) );
return vertices;
}
osg::Vec3Array* WMCoordinateHUD::buildCubeVertices()
{
// Vertices
float s = 0.4;
osg::Vec3Array* vertices = new osg::Vec3Array( 36 );
(*vertices)[15] = (*vertices)[12] = (*vertices)[9] =
(*vertices)[6] = (*vertices)[0] = osg::Vec3( s, s, s ); //1
(*vertices)[33] = (*vertices)[30] = (*vertices)[8] =
(*vertices)[3] = (*vertices)[1] = osg::Vec3( s, -s, s ); //2
(*vertices)[26] = (*vertices)[17] = (*vertices)[5] =
(*vertices)[2] = osg::Vec3( s, s, -s ); //3
(*vertices)[32] = (*vertices)[29] = (*vertices)[25] =
(*vertices)[4] = osg::Vec3( s, -s, -s ); //4
(*vertices)[18] = (*vertices)[13] = (*vertices)[10] =
osg::Vec3( -s, s, s ); //5
(*vertices)[19] = (*vertices)[34] = (*vertices)[21] =
(*vertices)[11] = (*vertices)[7] = osg::Vec3( -s, -s, s ); //6
(*vertices)[27] = (*vertices)[24] = (*vertices)[23] =
(*vertices)[20] = (*vertices)[16] =
(*vertices)[14] = osg::Vec3( -s, s, -s ); //7
(*vertices)[31] = (*vertices)[28] = (*vertices)[22] =
(*vertices)[35] = osg::Vec3( -s, -s, -s ); //8
return vertices;
}
// TODO(ebaum):
// text only shown as huge rectangle with the WMCoordinateHUD shader
// up: kranial, bottom: kaudal, front: anterior, back: posterior,
// left: sinistra, right: dexter
void WMCoordinateHUD::buildCaption()
{
osgText::Text* textOne = new osgText::Text();
osg::ref_ptr< osg::Geode > txtGeode = new osg::Geode();
txtGeode->addDrawable( textOne );
// Set up the parameters for the text we'll add to the HUD:
textOne->setCharacterSize( 25 );
// textOne->setFont("C:/WINDOWS/Fonts/impact.ttf");
textOne->setText( "D" );
textOne->setAxisAlignment( osgText::Text::USER_DEFINED_ROTATION );
textOne->setAutoRotateToScreen( false );
textOne->setCharacterSizeMode( osgText::Text::OBJECT_COORDS );
textOne->setPosition( osg::Vec3( 0, 0.5, 0.5 ) );
textOne->setColor( osg::Vec4( 255, 0, 0, 1 ) );
m_txtGeode = txtGeode;
}
//---------------------------------------------------------------------------
//
// 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 WMCOORDINATEHUD_H
#define WMCOORDINATEHUD_H
#include <string>
#include <osg/Geode>
#include "../../common/WItemSelection.h"
#include "../../common/WItemSelector.h"
#include "../../graphicsEngine/WGEManagedGroupNode.h"
#include "../../graphicsEngine/WGEZoomTrackballManipulator.h"
#include "../../graphicsEngine/WShader.h"
#include "../../kernel/WModule.h"
#include "../../kernel/WModuleInputData.h"
#include "../../kernel/WModuleOutputData.h"
/**
* This module shows a coordinatesystem as HUD.
* The attenuation can be customized to users needs.
*/
class WMCoordinateHUD: public WModule, public osg::Referenced
{
public:
/**
* Default constructor.
*/
WMCoordinateHUD();
/**
* Destructor.
*/
virtual ~WMCoordinateHUD();
/**
* Gives back the name of this module.
* \return the module's name.
*/
virtual const std::string getName() const;
/**
* Gives back a description of this module.
* \return description to module.
*/
virtual const std::string getDescription() const;
/**
* 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;
/**
* Get the icon for this module in XPM format.
*/
virtual const char** getXPMIcon() const;
protected:
/**
* 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();
/**
* Build the geode for colorfull coordinate axis
*/
virtual void buildColorAxis();
/**
* build the geode for black & white coordinate axis
*/
virtual void buildBWAxis();
/**
* build the geode for black & white coordinate cube
*/
virtual void buildColorCube();
/**
* build the geometry of the cube
*/
virtual osg::Vec3Array* buildCubeVertices();
/**
* build the geometry of the axis
*/
virtual osg::Vec3Array* buildAxisVertices();
/**
* create caption for medical plane
*/
virtual void buildCaption();
/**
* The root node used for this modules graphics.
*/
osg::ref_ptr< WGEManagedGroupNode > m_rootNode;
/**
* The geometry rendered by this module.
*/
osg::ref_ptr< osg::Geode > m_geode;
/**
* The caption rendered by this module.
*/
osg::ref_ptr< osg::Geode > m_txtGeode;