Commit 4300d6a8 authored by schurade's avatar schurade
Browse files

[CHANGE] some refactoring and streamlining

parent 425f27a6
......@@ -125,6 +125,8 @@ void WMCoordinateSystem::createGeometry()
osg::ref_ptr<WRulerOrtho>ruler2 = osg::ref_ptr<WRulerOrtho>( new WRulerOrtho() );
ruler2->create( osg::Vec3( zeroX, fltY, fltZ ), brbY, RULER_ALONG_Y_AXIS_SCALE_X );
ruler1->setName( std::string( "ruler1" ) );
ruler2->setName( std::string( "ruler2" ) );
m_rootNode->addChild( ruler1 );
m_rootNode->addChild( ruler2 );
......@@ -148,9 +150,43 @@ void WMCoordinateSystem::updateGeometry()
findBoundingBox();
//float zeroZ = m_properties->getValue<float>( "axialPos" );
float zeroY = m_properties->getValue<float>( "coronalPos" );
float zeroX = m_properties->getValue<float>( "sagittalPos" );
float fltX = m_properties->getValue<float>( "fltX" );
float fltY = m_properties->getValue<float>( "fltY" );
float fltZ = m_properties->getValue<float>( "fltZ" );
float brbX = m_properties->getValue<float>( "brbX" );
float brbY = m_properties->getValue<float>( "brbY" );
//float brbZ = m_properties->getValue<float>( "brbZ" );
osg::ref_ptr<osg::Drawable> old = osg::ref_ptr<osg::Drawable>( m_boxNode->getDrawable( 0 ) );
m_boxNode->replaceDrawable( old, createGeometryNode() );
for ( size_t i = 0; i < m_rootNode->getNumChildren(); ++i)
{
if ( m_rootNode->getChild( i )->getName() == "ruler1" )
{
m_rootNode->removeChild( i, 1 );
}
if ( m_rootNode->getChild( i )->getName() == "ruler2" )
{
m_rootNode->removeChild( i, 1 );
}
}
osg::ref_ptr<WRulerOrtho>ruler1 = osg::ref_ptr<WRulerOrtho>( new WRulerOrtho() );
ruler1->create( osg::Vec3( fltX, zeroY, fltZ ), brbX - fltX, RULER_ALONG_X_AXIS_SCALE_Y );
osg::ref_ptr<WRulerOrtho>ruler2 = osg::ref_ptr<WRulerOrtho>( new WRulerOrtho() );
ruler2->create( osg::Vec3( zeroX, fltY, fltZ ), brbY - fltY, RULER_ALONG_Y_AXIS_SCALE_X );
ruler1->setName( std::string( "ruler1" ) );
ruler2->setName( std::string( "ruler2" ) );
m_rootNode->addChild( ruler1 );
m_rootNode->addChild( ruler2 );
// *******************************************************************************************************
slock.unlock();
}
......
......@@ -81,7 +81,7 @@ public:
/**
* 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;
......@@ -127,7 +127,7 @@ private:
/**
* node for the bounding box
*/
osg::ref_ptr<WRulerOrtho> m_rulerNode;
osg::ref_ptr<osg::Group> m_rulerNode;
/**
......
......@@ -91,7 +91,7 @@ void WRulerOrtho::create( osg::Vec3 start, float length, scaleMode mode )
vertices->push_back( osg::Vec3( i, start.y() - 3.0, start.z() ) );
vertices->push_back( osg::Vec3( i, start.y() + 3.0, start.z() ) );
addLabel( osg::Vec3( i, start.y() - 3.0, start.z() ), boost::lexical_cast<std::string>( startX + i ) );
addLabel( osg::Vec3( i, start.y() - 3.0, start.z() ), boost::lexical_cast<std::string>( i ) );
}
else if ( i % 5 == 0 )
{
......@@ -132,7 +132,7 @@ void WRulerOrtho::create( osg::Vec3 start, float length, scaleMode mode )
vertices->push_back( osg::Vec3( i, start.y(), start.z() - 3.0 ) );
vertices->push_back( osg::Vec3( i, start.y(), start.z() + 3.0 ) );
addLabel( osg::Vec3( i, start.y(), start.z() - 3.0 ), boost::lexical_cast<std::string>( startX + i ) );
addLabel( osg::Vec3( i, start.y(), start.z() - 3.0 ), boost::lexical_cast<std::string>( i ) );
}
else if ( i % 5 == 0 )
{
......@@ -173,7 +173,7 @@ void WRulerOrtho::create( osg::Vec3 start, float length, scaleMode mode )
vertices->push_back( osg::Vec3( start.x() - 3.0, i, start.z() ) );
vertices->push_back( osg::Vec3( start.x() + 3.0, i, start.z() ) );
addLabel( osg::Vec3( start.x() - 3.0, i, start.z() ), boost::lexical_cast<std::string>( startY + i ) );
addLabel( osg::Vec3( start.x() - 3.0, i, start.z() ), boost::lexical_cast<std::string>( i ) );
}
else if ( i % 5 == 0 )
{
......@@ -214,7 +214,7 @@ void WRulerOrtho::create( osg::Vec3 start, float length, scaleMode mode )
vertices->push_back( osg::Vec3( start.x(), i, start.z() - 3.0 ) );
vertices->push_back( osg::Vec3( start.x(), i, start.z() + 3.0 ) );
addLabel( osg::Vec3( start.x(), i, start.z() - 3.0 ), boost::lexical_cast<std::string>( startY + i ) );
addLabel( osg::Vec3( start.x(), i, start.z() - 3.0 ), boost::lexical_cast<std::string>( i ) );
}
else if ( i % 5 == 0 )
{
......@@ -255,7 +255,7 @@ void WRulerOrtho::create( osg::Vec3 start, float length, scaleMode mode )
vertices->push_back( osg::Vec3( start.x() - 3.0, start.y(), i ) );
vertices->push_back( osg::Vec3( start.x() + 3.0, start.y(), i ) );
addLabel( osg::Vec3( start.x() - 3.0, start.y(), i ), boost::lexical_cast<std::string>( startZ + i ) );
addLabel( osg::Vec3( start.x() - 3.0, start.y(), i ), boost::lexical_cast<std::string>( i ) );
}
else if ( i % 5 == 0 )
{
......@@ -296,7 +296,7 @@ void WRulerOrtho::create( osg::Vec3 start, float length, scaleMode mode )
vertices->push_back( osg::Vec3( start.x(), start.y() - 3.0, i ) );
vertices->push_back( osg::Vec3( start.x(), start.y() + 3.0, i ) );
addLabel( osg::Vec3( start.x(), start.y() - 3.0, i ), boost::lexical_cast<std::string>( startZ + i ) );
addLabel( osg::Vec3( start.x(), start.y() - 3.0, i ), boost::lexical_cast<std::string>( i ) );
}
else if ( i % 5 == 0 )
{
......
......@@ -126,7 +126,7 @@ void WMNavSlices::notifyDataChange( boost::shared_ptr<WModuleConnector> input,
void WMNavSlices::moduleMain()
{
createGeometry();
create();
// Since the modules run in a separate thread: wait
waitForStop();
......@@ -136,7 +136,30 @@ void WMNavSlices::moduleMain()
WKernel::getRunningKernel()->getGraphicsEngine()->getScene()->removeChild( m_rootNode );
}
void WMNavSlices::createGeometry()
void WMNavSlices::create()
{
m_rootNode = osg::ref_ptr<osg::Group>( new osg::Group() );
m_xSliceNode = osg::ref_ptr<osg::Geode>( new osg::Geode() );
m_ySliceNode = osg::ref_ptr<osg::Geode>( new osg::Geode() );
m_zSliceNode = osg::ref_ptr<osg::Geode>( new osg::Geode() );
m_xSliceNode->addDrawable( createGeometry( 0 ) );
m_ySliceNode->addDrawable( createGeometry( 1 ) );
m_zSliceNode->addDrawable( createGeometry( 2 ) );
m_rootNode->addChild( m_xSliceNode );
m_rootNode->addChild( m_ySliceNode );
m_rootNode->addChild( m_zSliceNode );
WKernel::getRunningKernel()->getGraphicsEngine()->getScene()->addChild( m_rootNode );
osg::StateSet* rootState = m_rootNode->getOrCreateStateSet();
initUniforms( rootState );
rootState->setAttributeAndModes( m_shader->getProgramObject(), osg::StateAttribute::ON );
m_rootNode->setUpdateCallback( new sliceNodeCallback( boost::shared_dynamic_cast<WMNavSlices>( shared_from_this() ) ) );
}
osg::ref_ptr<osg::Geometry> WMNavSlices::createGeometry( int slice )
{
float axialPos = ( float )( m_properties->getValue< int >( "axialPos" ) ) + 0.5f;
float coronalPos = ( float )( m_properties->getValue< int >( "coronalPos" ) ) + 0.5f;
......@@ -150,94 +173,59 @@ void WMNavSlices::createGeometry()
float texCoronal = coronalPos / maxCoronal;
float texSagittal = sagittalPos / maxSagittal;
m_rootNode = osg::ref_ptr<osg::Group>( new osg::Group() );
m_xSliceNode = osg::ref_ptr<osg::Geode>( new osg::Geode() );
m_ySliceNode = osg::ref_ptr<osg::Geode>( new osg::Geode() );
m_zSliceNode = osg::ref_ptr<osg::Geode>( new osg::Geode() );
osg::ref_ptr<osg::Geometry> xSliceGeometry = osg::ref_ptr<osg::Geometry>( new osg::Geometry() );
osg::ref_ptr<osg::Geometry> ySliceGeometry = osg::ref_ptr<osg::Geometry>( new osg::Geometry() );
osg::ref_ptr<osg::Geometry> zSliceGeometry = osg::ref_ptr<osg::Geometry>( new osg::Geometry() );
m_xSliceNode->addDrawable( xSliceGeometry );
m_ySliceNode->addDrawable( ySliceGeometry );
m_zSliceNode->addDrawable( zSliceGeometry );
osg::ref_ptr<osg::Geometry> sliceGeometry = osg::ref_ptr<osg::Geometry>( new osg::Geometry() );
osg::Vec3Array* sliceVertices = new osg::Vec3Array;
sliceVertices->push_back( osg::Vec3( 0, coronalPos, 0 ) );
sliceVertices->push_back( osg::Vec3( 0, coronalPos, maxSagittal ) );
sliceVertices->push_back( osg::Vec3( maxAxial, coronalPos, maxSagittal ) );
sliceVertices->push_back( osg::Vec3( maxAxial, coronalPos, 0 ) );
xSliceGeometry->setVertexArray( sliceVertices );
sliceVertices->push_back( osg::Vec3( sagittalPos, 0, 0 ) );
sliceVertices->push_back( osg::Vec3( sagittalPos, 0, maxSagittal ) );
sliceVertices->push_back( osg::Vec3( sagittalPos, maxCoronal, maxSagittal ) );
sliceVertices->push_back( osg::Vec3( sagittalPos, maxCoronal, 0 ) );
ySliceGeometry->setVertexArray( sliceVertices );
sliceVertices->push_back( osg::Vec3( 0, 0, axialPos ) );
sliceVertices->push_back( osg::Vec3( 0, maxCoronal, axialPos ) );
sliceVertices->push_back( osg::Vec3( maxAxial, maxCoronal, axialPos ) );
sliceVertices->push_back( osg::Vec3( maxAxial, 0, axialPos ) );
zSliceGeometry->setVertexArray( sliceVertices );
osg::Vec3Array* texCoords = new osg::Vec3Array;
texCoords->push_back( osg::Vec3( 0.0, texCoronal, 0.0 ) );
texCoords->push_back( osg::Vec3( 0.0, texCoronal, 1.0 ) );
texCoords->push_back( osg::Vec3( 1.0, texCoronal, 1.0 ) );
texCoords->push_back( osg::Vec3( 1.0, texCoronal, 0.0 ) );
xSliceGeometry->setTexCoordArray( 0, texCoords );
texCoords->push_back( osg::Vec3( texSagittal, 0.0, 0.0 ) );
texCoords->push_back( osg::Vec3( texSagittal, 0.0, 1.0 ) );
texCoords->push_back( osg::Vec3( texSagittal, 1.0, 1.0 ) );
texCoords->push_back( osg::Vec3( texSagittal, 1.0, 0.0 ) );
ySliceGeometry->setTexCoordArray( 0, texCoords );
texCoords->push_back( osg::Vec3( 0.0, 0.0, texAxial ) );
texCoords->push_back( osg::Vec3( 0.0, 1.0, texAxial ) );
texCoords->push_back( osg::Vec3( 1.0, 1.0, texAxial ) );
texCoords->push_back( osg::Vec3( 1.0, 0.0, texAxial ) );
zSliceGeometry->setTexCoordArray( 0, texCoords );
osg::DrawElementsUInt* slice0 = new osg::DrawElementsUInt( osg::PrimitiveSet::QUADS, 0 );
slice0->push_back( 3 );
slice0->push_back( 2 );
slice0->push_back( 1 );
slice0->push_back( 0 );
osg::DrawElementsUInt* slice1 = new osg::DrawElementsUInt( osg::PrimitiveSet::QUADS, 0 );
slice1->push_back( 7 );
slice1->push_back( 6 );
slice1->push_back( 5 );
slice1->push_back( 4 );
osg::DrawElementsUInt* slice2 = new osg::DrawElementsUInt( osg::PrimitiveSet::QUADS, 0 );
slice2->push_back( 11 );
slice2->push_back( 10 );
slice2->push_back( 9 );
slice2->push_back( 8 );
xSliceGeometry->addPrimitiveSet( slice0 );
ySliceGeometry->addPrimitiveSet( slice1 );
zSliceGeometry->addPrimitiveSet( slice2 );
m_rootNode->addChild( m_xSliceNode );
m_rootNode->addChild( m_ySliceNode );
m_rootNode->addChild( m_zSliceNode );
WKernel::getRunningKernel()->getGraphicsEngine()->getScene()->addChild( m_rootNode );
osg::StateSet* rootState = m_rootNode->getOrCreateStateSet();
initUniforms( rootState );
switch ( slice )
{
case 0:
sliceVertices->push_back( osg::Vec3( 0, coronalPos, 0 ) );
sliceVertices->push_back( osg::Vec3( 0, coronalPos, maxSagittal ) );
sliceVertices->push_back( osg::Vec3( maxAxial, coronalPos, maxSagittal ) );
sliceVertices->push_back( osg::Vec3( maxAxial, coronalPos, 0 ) );
sliceGeometry->setVertexArray( sliceVertices );
texCoords->push_back( osg::Vec3( 0.0, texCoronal, 0.0 ) );
texCoords->push_back( osg::Vec3( 0.0, texCoronal, 1.0 ) );
texCoords->push_back( osg::Vec3( 1.0, texCoronal, 1.0 ) );
texCoords->push_back( osg::Vec3( 1.0, texCoronal, 0.0 ) );
sliceGeometry->setTexCoordArray( 0, texCoords );
break;
case 1:
sliceVertices->push_back( osg::Vec3( sagittalPos, 0, 0 ) );
sliceVertices->push_back( osg::Vec3( sagittalPos, 0, maxSagittal ) );
sliceVertices->push_back( osg::Vec3( sagittalPos, maxCoronal, maxSagittal ) );
sliceVertices->push_back( osg::Vec3( sagittalPos, maxCoronal, 0 ) );
sliceGeometry->setVertexArray( sliceVertices );
texCoords->push_back( osg::Vec3( texSagittal, 0.0, 0.0 ) );
texCoords->push_back( osg::Vec3( texSagittal, 0.0, 1.0 ) );
texCoords->push_back( osg::Vec3( texSagittal, 1.0, 1.0 ) );
texCoords->push_back( osg::Vec3( texSagittal, 1.0, 0.0 ) );
sliceGeometry->setTexCoordArray( 0, texCoords );
break;
case 2:
sliceVertices->push_back( osg::Vec3( 0, 0, axialPos ) );
sliceVertices->push_back( osg::Vec3( 0, maxCoronal, axialPos ) );
sliceVertices->push_back( osg::Vec3( maxAxial, maxCoronal, axialPos ) );
sliceVertices->push_back( osg::Vec3( maxAxial, 0, axialPos ) );
sliceGeometry->setVertexArray( sliceVertices );
texCoords->push_back( osg::Vec3( 0.0, 0.0, texAxial ) );
texCoords->push_back( osg::Vec3( 0.0, 1.0, texAxial ) );
texCoords->push_back( osg::Vec3( 1.0, 1.0, texAxial ) );
texCoords->push_back( osg::Vec3( 1.0, 0.0, texAxial ) );
sliceGeometry->setTexCoordArray( 0, texCoords );
break;
}
rootState->setAttributeAndModes( m_shader->getProgramObject(), osg::StateAttribute::ON );
osg::DrawElementsUInt* quad = new osg::DrawElementsUInt( osg::PrimitiveSet::QUADS, 0 );
quad->push_back( 3 );
quad->push_back( 2 );
quad->push_back( 1 );
quad->push_back( 0 );
sliceGeometry->addPrimitiveSet( quad );
m_rootNode->setUpdateCallback( new sliceNodeCallback( boost::shared_dynamic_cast<WMNavSlices>( shared_from_this() ) ) );
return sliceGeometry;
}
void WMNavSlices::updateGeometry()
......@@ -259,84 +247,9 @@ void WMNavSlices::updateGeometry()
// m_properties->setValue( "maxCoronal", my );
// m_properties->setValue( "maxSagittal", mz );
// }
float axialPos = ( float )( m_properties->getValue< int >( "axialPos" ) );
float coronalPos = ( float )( m_properties->getValue< int >( "coronalPos" ) );
float sagittalPos = ( float )( m_properties->getValue< int >( "sagittalPos" ) );
float maxAxial = ( float )( m_properties->getValue<int>( "maxAxial") );
float maxCoronal = ( float )( m_properties->getValue<int>( "maxCoronal") );
float maxSagittal = ( float )( m_properties->getValue<int>( "maxSagittal") );
float texAxial = axialPos / maxAxial;
float texCoronal = coronalPos / maxCoronal;
float texSagittal = sagittalPos / maxSagittal;
osg::ref_ptr<osg::Geometry> xSliceGeometry = osg::ref_ptr<osg::Geometry>( new osg::Geometry() );
osg::ref_ptr<osg::Geometry> ySliceGeometry = osg::ref_ptr<osg::Geometry>( new osg::Geometry() );
osg::ref_ptr<osg::Geometry> zSliceGeometry = osg::ref_ptr<osg::Geometry>( new osg::Geometry() );
osg::Vec3Array* sliceVertices = new osg::Vec3Array;
sliceVertices->push_back( osg::Vec3( 0, coronalPos, 0 ) );
sliceVertices->push_back( osg::Vec3( 0, coronalPos, maxSagittal ) );
sliceVertices->push_back( osg::Vec3( maxAxial, coronalPos, maxSagittal ) );
sliceVertices->push_back( osg::Vec3( maxAxial, coronalPos, 0 ) );
xSliceGeometry->setVertexArray( sliceVertices );
sliceVertices->push_back( osg::Vec3( sagittalPos, 0, 0 ) );
sliceVertices->push_back( osg::Vec3( sagittalPos, 0, maxSagittal ) );
sliceVertices->push_back( osg::Vec3( sagittalPos, maxCoronal, maxSagittal ) );
sliceVertices->push_back( osg::Vec3( sagittalPos, maxCoronal, 0 ) );
ySliceGeometry->setVertexArray( sliceVertices );
sliceVertices->push_back( osg::Vec3( 0, 0, axialPos ) );
sliceVertices->push_back( osg::Vec3( 0, maxCoronal, axialPos ) );
sliceVertices->push_back( osg::Vec3( maxAxial, maxCoronal, axialPos ) );
sliceVertices->push_back( osg::Vec3( maxAxial, 0, axialPos ) );
zSliceGeometry->setVertexArray( sliceVertices );
osg::Vec3Array* texCoords = new osg::Vec3Array;
texCoords->push_back( osg::Vec3( 0.0, texCoronal, 0.0 ) );
texCoords->push_back( osg::Vec3( 0.0, texCoronal, 1.0 ) );
texCoords->push_back( osg::Vec3( 1.0, texCoronal, 1.0 ) );
texCoords->push_back( osg::Vec3( 1.0, texCoronal, 0.0 ) );
xSliceGeometry->setTexCoordArray( 0, texCoords );
texCoords->push_back( osg::Vec3( texSagittal, 0.0, 0.0 ) );
texCoords->push_back( osg::Vec3( texSagittal, 0.0, 1.0 ) );
texCoords->push_back( osg::Vec3( texSagittal, 1.0, 1.0 ) );
texCoords->push_back( osg::Vec3( texSagittal, 1.0, 0.0 ) );
ySliceGeometry->setTexCoordArray( 0, texCoords );
texCoords->push_back( osg::Vec3( 0.0, 0.0, texAxial ) );
texCoords->push_back( osg::Vec3( 0.0, 1.0, texAxial ) );
texCoords->push_back( osg::Vec3( 1.0, 1.0, texAxial ) );
texCoords->push_back( osg::Vec3( 1.0, 0.0, texAxial ) );
zSliceGeometry->setTexCoordArray( 0, texCoords );
osg::DrawElementsUInt* slice0 = new osg::DrawElementsUInt( osg::PrimitiveSet::QUADS, 0 );
slice0->push_back( 3 );
slice0->push_back( 2 );
slice0->push_back( 1 );
slice0->push_back( 0 );
osg::DrawElementsUInt* slice1 = new osg::DrawElementsUInt( osg::PrimitiveSet::QUADS, 0 );
slice1->push_back( 7 );
slice1->push_back( 6 );
slice1->push_back( 5 );
slice1->push_back( 4 );
osg::DrawElementsUInt* slice2 = new osg::DrawElementsUInt( osg::PrimitiveSet::QUADS, 0 );
slice2->push_back( 11 );
slice2->push_back( 10 );
slice2->push_back( 9 );
slice2->push_back( 8 );
xSliceGeometry->addPrimitiveSet( slice0 );
ySliceGeometry->addPrimitiveSet( slice1 );
zSliceGeometry->addPrimitiveSet( slice2 );
osg::ref_ptr<osg::Geometry> xSliceGeometry = createGeometry( 0 );
osg::ref_ptr<osg::Geometry> ySliceGeometry = createGeometry( 1 );
osg::ref_ptr<osg::Geometry> zSliceGeometry = createGeometry( 2 );
osg::ref_ptr<osg::Drawable> oldx = osg::ref_ptr<osg::Drawable>( m_xSliceNode->getDrawable( 0 ) );
m_xSliceNode->replaceDrawable( oldx, xSliceGeometry );
......@@ -431,6 +344,9 @@ void WMNavSlices::connectToGui()
void WMNavSlices::initUniforms( osg::StateSet* rootState )
{
boost::shared_lock<boost::shared_mutex> slock;
slock = boost::shared_lock<boost::shared_mutex>( m_updateLock );
m_typeUniforms.push_back( osg::ref_ptr<osg::Uniform>( new osg::Uniform( "type0", 0 ) ) );
m_typeUniforms.push_back( osg::ref_ptr<osg::Uniform>( new osg::Uniform( "type1", 0 ) ) );
m_typeUniforms.push_back( osg::ref_ptr<osg::Uniform>( new osg::Uniform( "type2", 0 ) ) );
......@@ -482,4 +398,5 @@ void WMNavSlices::initUniforms( osg::StateSet* rootState )
rootState->addUniform( m_alphaUniforms[i] );
rootState->addUniform( m_samplerUniforms[i] );
}
slock.unlock();
}
......@@ -92,7 +92,7 @@ public:
/**
* 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;
......@@ -126,10 +126,11 @@ protected:
private:
void create();
/**
* initial creation function for the slice geometry
*/
void createGeometry();
osg::ref_ptr<osg::Geometry> createGeometry( int slice );
/**
* creates and initializes the uniform parameters for the shader
......
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