Commit 006c255c authored by Mathias Goldau's avatar Mathias Goldau
Browse files

[REMOVE] Module lineGuidedSlice lives now inside the Unmaintained module repository.

parent ba0dbcee
//---------------------------------------------------------------------------
//
// Project: OpenWalnut ( http://www.openwalnut.org )
//
// Copyright 2009 OpenWalnut Community, BSV-Leipzig and CNCF-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 <vector>
#include <utility>
#include "core/common/math/linearAlgebra/WLinearAlgebra.h"
#include "core/common/WAssert.h"
#include "core/common/WLogger.h"
#include "core/dataHandler/datastructures/WFiberCluster.h"
#include "core/dataHandler/WDataHandler.h"
#include "core/dataHandler/WSubject.h"
#include "core/graphicsEngine/WGEColormapping.h"
#include "core/graphicsEngine/WGEGeodeUtils.h"
#include "core/graphicsEngine/WGEUtils.h"
#include "core/graphicsEngine/shaders/WGEShader.h"
#include "core/kernel/WKernel.h"
#include "WMLineGuidedSlice.h"
#include "WMLineGuidedSlice.xpm"
W_LOADABLE_MODULE( WMLineGuidedSlice )
WMLineGuidedSlice::WMLineGuidedSlice():
WModule(),
m_isPicked( false )
{
}
WMLineGuidedSlice::~WMLineGuidedSlice()
{
}
boost::shared_ptr< WModule > WMLineGuidedSlice::factory() const
{
return boost::shared_ptr< WModule >( new WMLineGuidedSlice() );
}
const char** WMLineGuidedSlice::getXPMIcon() const
{
return lineGuidedSlice_xpm;
}
const std::string WMLineGuidedSlice::getName() const
{
return "Line Guided Slice";
}
const std::string WMLineGuidedSlice::getDescription() const
{
return "<font color=\"#0000ff\"><b>[Experimental Status]</b></font> A slice that can be moved along a line. ";
}
void WMLineGuidedSlice::connectors()
{
typedef WModuleInputData< const WFiberCluster > ClusterInputType; // just an alias
m_input = boost::shared_ptr< ClusterInputType >( new ClusterInputType( shared_from_this(),
"cluster",
"A fiber cluster, that can"
" be used to get the centerline from." ) );
addConnector( m_input );
// call WModules initialization
WModule::connectors();
}
void WMLineGuidedSlice::properties()
{
m_pos = m_properties->addProperty( "Slice position", "Position of ths slice along the line.", 0., true );
m_pos->setMin( 0. );
m_pos->setMax( 1. );
WModule::properties();
}
void WMLineGuidedSlice::moduleMain()
{
m_moduleState.add( m_input->getDataChangedCondition() ); // additional fire-condition: "data changed" flag
boost::shared_ptr< WGraphicsEngine > ge = WGraphicsEngine::getGraphicsEngine();
assert( ge );
m_viewer = ge->getViewerByName( "Main View" );
assert( m_viewer );
m_viewer->getPickHandler()->getPickSignal()->connect( boost::bind( &WMLineGuidedSlice::setSlicePosFromPick, this, _1 ) );
// signal ready state
ready();
m_rootNode = osg::ref_ptr< WGEGroupNode >( new WGEGroupNode() );
while( !m_shutdownFlag() ) // loop until the module container requests the module to quit
{
if( !m_input->getData() ) // ok, the output has not yet sent data
{
m_moduleState.wait();
continue;
}
updateCenterLine();
create();
m_moduleState.wait(); // waits for firing of m_moduleState ( dataChanged, shutdown, etc. )
}
// clean up stuff
WKernel::getRunningKernel()->getGraphicsEngine()->getScene()->remove( m_rootNode );
}
void WMLineGuidedSlice::updateCenterLine()
{
debugLog() << "Draw center line.";
assert( m_rootNode );
assert( m_input );
assert( m_input->getData() );
m_centerLine = m_input->getData()->getCenterLine();
if( m_centerLine )
{
debugLog() << "Draw center line representation." << pathLength( *m_centerLine );
m_centerLineGeode = wge::generateLineStripGeode( *m_centerLine, 2.f );
}
else
{
warnLog() << "CenterLine update on non existing CenterLine (null)";
m_centerLineGeode = osg::ref_ptr< osg::Geode >( new osg::Geode() );
}
m_rootNode->insert( m_centerLineGeode );
}
void WMLineGuidedSlice::create()
{
m_sliceNode = osg::ref_ptr<osg::Geode>( new osg::Geode() );
m_sliceNode->setDataVariance( osg::Object::DYNAMIC );
m_sliceNode->setName( "Line Guided Slice" );
m_sliceNode->addDrawable( createGeometry() );
m_rootNode->insert( m_sliceNode );
osg::ref_ptr< WGEShader > shader;
shader = osg::ref_ptr< WGEShader >( new WGEShader( "WMLineGuidedSlice", m_localPath ) );
shader->apply( m_sliceNode );
// Colormapping
WGEColormapping::apply( m_sliceNode, shader );
osg::StateSet* sliceState = m_sliceNode->getOrCreateStateSet();
sliceState->setMode( GL_BLEND, osg::StateAttribute::ON );
m_sliceNode->setUserData( this );
m_sliceNode->addUpdateCallback( new sliceNodeCallback );
WKernel::getRunningKernel()->getGraphicsEngine()->getScene()->insert( m_rootNode );
}
void WMLineGuidedSlice::setSlicePosFromPick( WPickInfo pickInfo )
{
if( pickInfo.getName() == "Line Guided Slice" )
{
boost::unique_lock< boost::shared_mutex > lock;
lock = boost::unique_lock< boost::shared_mutex >( m_updateLock );
WVector2d newPixelPos( pickInfo.getPickPixel() );
if( m_isPicked )
{
float diff = newPixelPos.x() - m_oldPixelPosition.x();
diff *= 0.01;
m_pos->set( m_pos->get() + diff );
lock.unlock();
}
m_oldPixelPosition = newPixelPos;
m_isPicked |= true;
}
else
{
m_isPicked &= false;
}
}
osg::ref_ptr<osg::Geometry> WMLineGuidedSlice::createGeometry()
{
int posOnLine = m_pos->get() * m_centerLine->size();
if( posOnLine > ( m_centerLine->size() - 2. ) )
{
posOnLine = m_centerLine->size() - 2;
}
if( posOnLine < 0 )
{
posOnLine = 0;
}
WAssert( m_centerLine->size() > 1, "To few positions in center line." );
WPosition startPos = ( *m_centerLine )[posOnLine];
WVector3d startSliceNormal = normalize( startPos - ( *m_centerLine )[posOnLine + 1] );
WVector3d sliceVec1 = normalize( cross( WVector3d( 1, 0, 0 ), startSliceNormal ) );
WVector3d sliceVec2 = normalize( cross( sliceVec1, startSliceNormal ) );
osg::ref_ptr<osg::Geometry> sliceGeometry = osg::ref_ptr<osg::Geometry>( new osg::Geometry() );
osg::Vec3Array* sliceVertices = new osg::Vec3Array;
const double radius = 100;
std::vector< WPosition > vertices;
vertices.push_back( startPos + ( sliceVec1 + sliceVec2 ) * radius );
vertices.push_back( startPos + ( -1 * sliceVec1 + sliceVec2 ) * radius );
vertices.push_back( startPos + ( -1 * sliceVec1 - sliceVec2 ) * radius );
vertices.push_back( startPos + ( sliceVec1 - sliceVec2 ) * radius );
const size_t nbVerts = 4;
for( size_t i = 0; i < nbVerts; ++i )
{
sliceVertices->push_back( vertices[i] );
}
sliceGeometry->setVertexArray( sliceVertices );
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 );
return sliceGeometry;
}
void WMLineGuidedSlice::updateGeometry()
{
boost::shared_lock<boost::shared_mutex> slock;
slock = boost::shared_lock<boost::shared_mutex>( m_updateLock );
osg::ref_ptr<osg::Geometry> sliceGeometry = createGeometry();
osg::ref_ptr<osg::Drawable> old = osg::ref_ptr<osg::Drawable>( m_sliceNode->getDrawable( 0 ) );
m_sliceNode->replaceDrawable( old, sliceGeometry );
slock.unlock();
}
//---------------------------------------------------------------------------
//
// Project: OpenWalnut ( http://www.openwalnut.org )
//
// Copyright 2009 OpenWalnut Community, BSV-Leipzig and CNCF-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 WMLINEGUIDEDSLICE_H
#define WMLINEGUIDEDSLICE_H
#include <string>
#include <vector>
#include <utility>
#include <osg/Node>
#include "core/kernel/WModule.h"
#include "core/kernel/WModuleInputData.h"
#include "core/kernel/WModuleOutputData.h"
#include "core/graphicsEngine/WGEViewer.h"
#include "core/graphicsEngine/WPickHandler.h"
// forward declarations
class WFiberCluster;
/**
* Module to compute a plane along a line and color it with a scalar parameter.
* \ingroup modules
*/
class WMLineGuidedSlice : public WModule, public osg::Referenced
{
public:
/**
*
*/
WMLineGuidedSlice();
/**
*
*/
virtual ~WMLineGuidedSlice();
/**
* 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.
* \return The icon.
*/
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();
private:
/**
* Updates the positions of the slice
*/
void updateGeometry();
/**
* Creates the inital geometry.
*/
void create();
/**
* Removes or inserts geode for the center line of the current cluster into this modules group node.
*/
void updateCenterLine();
/**
* Sets slice position 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
*
* \return the geometry
*/
osg::ref_ptr< osg::Geometry > createGeometry();
WPropDouble m_pos; //!< Slice position along line.
WVector2d m_oldPixelPosition; //!< Caches the old picked position to a allow for cmoparison
bool m_isPicked; //!< Indicates whether a slice is currently picked or not.
boost::shared_ptr< WGEViewer > m_viewer; //!< Stores reference to the main viewer
boost::shared_ptr< WModuleInputData< const WFiberCluster > > m_input; //!< Input connector for a fiber cluster
osg::ref_ptr< WGEGroupNode > m_rootNode; //!< The root node for this module.
osg::ref_ptr< osg::Geode > m_sliceNode; //!< OSG node for slice.
osg::ref_ptr< osg::Geode > m_centerLineGeode; //!< OSG center line of the current cluster geode.
boost::shared_mutex m_updateLock; //!< Lock to prevent concurrent threads trying to update the osg node.
boost::shared_ptr< WFiber > m_centerLine; //!< The line that guides the slice.
/**
* Node callback to handle updates properly
*/
class sliceNodeCallback : public osg::NodeCallback
{
public: // NOLINT
/**
* operator ()
*
* \param node the osg node
* \param nv the node visitor
*/
virtual void operator()( osg::Node* node, osg::NodeVisitor* nv )
{
osg::ref_ptr< WMLineGuidedSlice > module = static_cast< WMLineGuidedSlice* > ( node->getUserData() );
if( module )
{
module->updateGeometry();
}
traverse( node, nv );
}
};
};
#endif // WMLINEGUIDEDSLICE_H
/* XPM */
static const char * lineGuidedSlice_xpm[] = {
"32 32 2 1",
" c None",
". c #000000",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" . .... ..... ",
" . . . . . ",
" . . . . . ",
" . . . ",
" . . . ",
" . . ... ",
" . . ..... ... ",
" . . . . ",
" . . . . ",
" . . . . . ",
" . . . . . ",
" ....... .... ..... ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" "};
//---------------------------------------------------------------------------
//
// Project: OpenWalnut ( http://www.openwalnut.org )
//
// Copyright 2009 OpenWalnut Community, BSV-Leipzig and CNCF-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 "WGEColormapping-fragment.glsl"
void main()
{
vec4 col = vec4( 0.0, 0.0, 0.0, 1.0 );
// TODO(wiebel): We need to access two textures here. One for the quantity to show, one for cutting out the interesting part.
col = colormapping();
if( col.a == 0 )
{
discard;
}
gl_FragColor = col;
}
//---------------------------------------------------------------------------
//
// Project: OpenWalnut ( http://www.openwalnut.org )
//
// Copyright 2009 OpenWalnut Community, BSV-Leipzig and CNCF-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 "WGEColormapping-vertex.glsl"
void main()
{
// prepare colormapping
colormapping();
gl_Position = ftransform();
}
......@@ -27,7 +27,6 @@ ADD_MODULE( gaussProcesses )
ADD_MODULE( HARDIToSphericalHarmonics )
ADD_MODULE( histogramView )
ADD_MODULE( imageExtractor )
ADD_MODULE( lineGuidedSlice )
ADD_MODULE( paintTexture )
ADD_MODULE( probTractDisplay )
ADD_MODULE( scalarSegmentation )
......
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