Commit 59f4c946 authored by Alexander Wiebel's avatar Alexander Wiebel
Browse files

[ADD] navSlices can be moved by right mouse button in gl widget now.

Handling still has to be improved. The corresponding GUI buttons are not
updated yet
parent 374b0bfb
......@@ -26,6 +26,7 @@
#include <list>
#include <string>
#include <vector>
#include <utility>
#include <boost/shared_ptr.hpp>
#include <boost/signals2/signal.hpp>
......@@ -42,6 +43,7 @@
#include "../../dataHandler/WSubject.h"
#include "../../dataHandler/WValueSet.h"
#include "../../graphicsEngine/WShader.h"
#include "../../graphicsEngine/WGraphicsEngine.h"
#include "../../kernel/WKernel.h"
#include "../../kernel/WModule.h"
#include "../../kernel/WModuleConnector.h"
......@@ -54,7 +56,8 @@ bool WMNavSlices::m_navsliceRunning = false;
WMNavSlices::WMNavSlices():
WModule(),
m_textureChanged( true )
m_textureChanged( true ),
m_isPicked( false )
{
// WARNING: initializing connectors inside the constructor will lead to an exception.
// Implement WModule::initializeConnectors instead.
......@@ -142,6 +145,15 @@ void WMNavSlices::notifyTextureChange()
void WMNavSlices::moduleMain()
{
boost::shared_ptr< WGraphicsEngine > ge = WGraphicsEngine::getGraphicsEngine();
assert( ge );
boost::shared_ptr< WGEViewer > viewer = ge->getViewerByName( "main" );
assert( viewer );
// m_viewer = viewer;
// m_pickHandler = m_viewer->getPickHandler();
// m_pickHandler->getPickSignal()->connect( boost::bind( &WROIBox::registerRedrawRequest, this, _1 ) );
viewer->getPickHandler()->getPickSignal()->connect( boost::bind( &WMNavSlices::setSlicePosFromPick, this, _1 ) );
// signal ready state
ready();
......@@ -158,7 +170,6 @@ void WMNavSlices::moduleMain()
// clean up stuff
// NOTE: ALAWAYS remove your osg nodes!
// Please, please always check for NULL
boost::shared_ptr< WGEViewer > viewer = WKernel::getRunningKernel()->getGraphicsEngine()->getViewerByName( "axial" );
if ( viewer )
{
viewer->getScene()->remove( m_zSliceNode );
......@@ -187,11 +198,11 @@ void WMNavSlices::create()
m_rootNode = osg::ref_ptr< WGEGroupNode >( new WGEGroupNode() );
m_xSliceNode = osg::ref_ptr<osg::Geode>( new osg::Geode() );
m_xSliceNode->setName( "X-Slice" );
m_xSliceNode->setName( "Sagittal Slice" );
m_ySliceNode = osg::ref_ptr<osg::Geode>( new osg::Geode() );
m_ySliceNode->setName( "Y-Slice" );
m_ySliceNode->setName( "Coronal Slice" );
m_zSliceNode = osg::ref_ptr<osg::Geode>( new osg::Geode() );
m_zSliceNode->setName( "Z-Slice" );
m_zSliceNode->setName( "Axial Slice" );
m_xSliceNode->addDrawable( createGeometry( 0 ) );
m_ySliceNode->addDrawable( createGeometry( 1 ) );
......@@ -226,13 +237,53 @@ void WMNavSlices::create()
viewer = WKernel::getRunningKernel()->getGraphicsEngine()->getViewerByName( "sagittal" );
if ( viewer )
{
viewer->getScene()->insert( m_ySliceNode );
viewer->getScene()->insert( m_xSliceNode );
}
viewer = WKernel::getRunningKernel()->getGraphicsEngine()->getViewerByName( "coronal" );
if ( viewer )
{
viewer->getScene()->insert( m_xSliceNode );
viewer->getScene()->insert( m_ySliceNode );
}
}
void WMNavSlices::setSlicePosFromPick( WPickInfo pickInfo )
{
if ( pickInfo.getName() == "Axial Slice"
|| pickInfo.getName() == "Coronal Slice"
|| pickInfo.getName() == "Sagittal Slice" )
{
boost::unique_lock< boost::shared_mutex > lock;
lock = boost::unique_lock< boost::shared_mutex >( m_updateLock );
std::pair< float, float > newPixelPos( pickInfo.getPickPixelPosition() );
if ( m_isPicked )
{
float diffX = newPixelPos.first - m_oldPixelPosition.first;
float diffY = newPixelPos.second - m_oldPixelPosition.second;
float diff = ( fabs( diffX ) > fabs( diffY ) ) ? diffX : diffY;
if ( pickInfo.getName() == "Axial Slice" )
{
m_axialPos->set( m_axialPos->get() + diff );
}
if ( pickInfo.getName() == "Coronal Slice" )
{
m_coronalPos->set( m_coronalPos->get() + diff );
}
if ( pickInfo.getName() == "Sagittal Slice" )
{
m_sagittalPos->set( m_sagittalPos->get() + diff );
}
lock.unlock();
}
m_oldPixelPosition = newPixelPos;
m_isPicked |= true;
}
else
{
m_isPicked &= false;
}
}
......@@ -266,10 +317,10 @@ osg::ref_ptr<osg::Geometry> WMNavSlices::createGeometry( int slice )
{
case 0:
{
sliceVertices->push_back( osg::Vec3( 0, yPos, 0 ) );
sliceVertices->push_back( osg::Vec3( 0, yPos, maxDim ) );
sliceVertices->push_back( osg::Vec3( maxDim, yPos, maxDim ) );
sliceVertices->push_back( osg::Vec3( maxDim, yPos, 0 ) );
sliceVertices->push_back( osg::Vec3( xPos, 0, 0 ) );
sliceVertices->push_back( osg::Vec3( xPos, 0, maxDim ) );
sliceVertices->push_back( osg::Vec3( xPos, maxDim, maxDim ) );
sliceVertices->push_back( osg::Vec3( xPos, maxDim, 0 ) );
sliceGeometry->setVertexArray( sliceVertices );
int c = 0;
......@@ -281,19 +332,19 @@ osg::ref_ptr<osg::Geometry> WMNavSlices::createGeometry( int slice )
float maxY = ( float )( grid->getNbCoordsY() );
float maxZ = ( float )( grid->getNbCoordsZ() );
//float texX = xSlice / maxX;
float texY = ySlice / maxY;
float texX = xSlice / maxX;
//float texY = ySlice / maxY;
//float texZ = zSlice / maxZ;
float texXOff = 255.0 / maxX;
//float texYOff = 255.0 / maxY;
//float texXOff = 255.0 / maxX;
float texYOff = 255.0 / maxY;
float texZOff = 255.0 / maxZ;
osg::Vec3Array* texCoords = new osg::Vec3Array;
texCoords->push_back( wv3D2ov3( grid->transformTexCoord( wmath::WPosition( 0.0, texY, 0.0 ) ) ) );
texCoords->push_back( wv3D2ov3( grid->transformTexCoord( wmath::WPosition( 0.0, texY, texZOff ) ) ) );
texCoords->push_back( wv3D2ov3( grid->transformTexCoord( wmath::WPosition( texXOff, texY, texZOff ) ) ) );
texCoords->push_back( wv3D2ov3( grid->transformTexCoord( wmath::WPosition( texXOff, texY, 0.0 ) ) ) );
texCoords->push_back( wv3D2ov3( grid->transformTexCoord( wmath::WPosition( texX, 0.0, 0.0 ) ) ) );
texCoords->push_back( wv3D2ov3( grid->transformTexCoord( wmath::WPosition( texX, 0.0, texZOff ) ) ) );
texCoords->push_back( wv3D2ov3( grid->transformTexCoord( wmath::WPosition( texX, texYOff, texZOff ) ) ) );
texCoords->push_back( wv3D2ov3( grid->transformTexCoord( wmath::WPosition( texX, texYOff, 0.0 ) ) ) );
sliceGeometry->setTexCoordArray( c, texCoords );
++c;
}
......@@ -301,10 +352,10 @@ osg::ref_ptr<osg::Geometry> WMNavSlices::createGeometry( int slice )
}
case 1:
{
sliceVertices->push_back( osg::Vec3( xPos, 0, 0 ) );
sliceVertices->push_back( osg::Vec3( xPos, 0, maxDim ) );
sliceVertices->push_back( osg::Vec3( xPos, maxDim, maxDim ) );
sliceVertices->push_back( osg::Vec3( xPos, maxDim, 0 ) );
sliceVertices->push_back( osg::Vec3( 0, yPos, 0 ) );
sliceVertices->push_back( osg::Vec3( 0, yPos, maxDim ) );
sliceVertices->push_back( osg::Vec3( maxDim, yPos, maxDim ) );
sliceVertices->push_back( osg::Vec3( maxDim, yPos, 0 ) );
sliceGeometry->setVertexArray( sliceVertices );
int c = 0;
......@@ -316,19 +367,19 @@ osg::ref_ptr<osg::Geometry> WMNavSlices::createGeometry( int slice )
float maxY = ( float )( grid->getNbCoordsY() );
float maxZ = ( float )( grid->getNbCoordsZ() );
float texX = xSlice / maxX;
//float texY = ySlice / maxY;
//float texX = xSlice / maxX;
float texY = ySlice / maxY;
//float texZ = zSlice / maxZ;
//float texXOff = 255.0 / maxX;
float texYOff = 255.0 / maxY;
float texXOff = 255.0 / maxX;
//float texYOff = 255.0 / maxY;
float texZOff = 255.0 / maxZ;
osg::Vec3Array* texCoords = new osg::Vec3Array;
texCoords->push_back( wv3D2ov3( grid->transformTexCoord( wmath::WPosition( texX, 0.0, 0.0 ) ) ) );
texCoords->push_back( wv3D2ov3( grid->transformTexCoord( wmath::WPosition( texX, 0.0, texZOff ) ) ) );
texCoords->push_back( wv3D2ov3( grid->transformTexCoord( wmath::WPosition( texX, texYOff, texZOff ) ) ) );
texCoords->push_back( wv3D2ov3( grid->transformTexCoord( wmath::WPosition( texX, texYOff, 0.0 ) ) ) );
texCoords->push_back( wv3D2ov3( grid->transformTexCoord( wmath::WPosition( 0.0, texY, 0.0 ) ) ) );
texCoords->push_back( wv3D2ov3( grid->transformTexCoord( wmath::WPosition( 0.0, texY, texZOff ) ) ) );
texCoords->push_back( wv3D2ov3( grid->transformTexCoord( wmath::WPosition( texXOff, texY, texZOff ) ) ) );
texCoords->push_back( wv3D2ov3( grid->transformTexCoord( wmath::WPosition( texXOff, texY, 0.0 ) ) ) );
sliceGeometry->setTexCoordArray( c, texCoords );
++c;
}
......
......@@ -28,6 +28,7 @@
#include <list>
#include <string>
#include <vector>
#include <utility>
#include <osg/Node>
......@@ -192,6 +193,12 @@ private:
*/
void create();
/**
* Sets slice positions from interaction in the main GL widget
* \param pickInfo The information provided by the pick handler
*/
void setSlicePosFromPick( WPickInfo pickInfo );
/**
* Initial creation function for the slice geometry
* \param slice ID of the slice to be drawn. 0=y, 1=x, 2=z
......@@ -204,6 +211,9 @@ private:
*/
void initUniforms( osg::StateSet* rootState );
std::pair< float, float > m_oldPixelPosition; //!< Caches the old picked position to a allow for cmoparison
bool m_isPicked; //!< Indicates whether a slice is currently picked or not.
/**
* the root node for this module
*/
......
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