Commit 4d91c51d authored by Mathias Goldau's avatar Mathias Goldau

[REMOVE] Module boundaryCurves, as isoLine module will take care on that and...

[REMOVE] Module boundaryCurves, as isoLine module will take care on that and has a quite better name, regarding what it really does, and not what it is intended to be used for.
parent e8bb6a99
//---------------------------------------------------------------------------
//
// 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 "core/common/WProperties.h"
#include "core/dataHandler/WDataSetScalar.h"
#include "WBoundaryBuilder.h"
WBoundaryBuilder::WBoundaryBuilder( boost::shared_ptr< const WDataSetScalar > texture, boost::shared_ptr< const WProperties > properties,
boost::array< osg::ref_ptr< WGEManagedGroupNode >, 3 > *slices )
: m_texture( texture ),
m_slices( *slices ) // copy the pointers
{
m_slicePos[0] = properties->findProperty( "Slices" )->toPropGroup()->findProperty( "Sagittal Position" )->toPropDouble();
m_slicePos[1] = properties->findProperty( "Slices" )->toPropGroup()->findProperty( "Coronal Position" )->toPropDouble();
m_slicePos[2] = properties->findProperty( "Slices" )->toPropGroup()->findProperty( "Axial Position" )->toPropDouble();
m_grayMatter = properties->findProperty( "Gray Matter" )->toPropDouble();
m_whiteMatter = properties->findProperty( "White Matter" )->toPropDouble();
m_gmColor = properties->findProperty( "Gray Matter Color" )->toPropColor();
m_wmColor = properties->findProperty( "White Matter Color" )->toPropColor();
}
WBoundaryBuilder::~WBoundaryBuilder()
{
}
//---------------------------------------------------------------------------
//
// 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 WBOUNDARYBUILDER_H
#define WBOUNDARYBUILDER_H
#include <boost/array.hpp>
#include <boost/shared_ptr.hpp>
#include <osg/ref_ptr>
#include "core/common/WProperties.h"
#include "core/graphicsEngine/shaders/WGEShader.h"
#include "core/graphicsEngine/WGEManagedGroupNode.h"
// forward declarations
class WGEManagedGroupNode;
class WDataSetScalar;
/**
* Abstract base class for a boundary builder which needs serveral input paramertes \ref WBoundaryBuilder constructor
* and provides an interface: \ref run for generating the graphics.
*/
class WBoundaryBuilder
{
public:
/**
* Constructs an builder instance.
*
* \param texture The underlying scalar dataset to compute those boundaries for
* \param properties Properties, like slice positions, thresholds etc.
* \param slices Slice geodes which are controlled (hide/unhide) by the module.
*/
WBoundaryBuilder( boost::shared_ptr< const WDataSetScalar > texture,
boost::shared_ptr< const WProperties > properties,
boost::array< osg::ref_ptr< WGEManagedGroupNode >, 3 > *slices );
/**
* Destructs this.
*/
virtual ~WBoundaryBuilder();
/**
* Starts rendering and finally insert result in output.
*
* \param output Where to put/insert the results.
* \param sliceNum If given -1 all slice will perform an update, otherwise only the slice with the given slice number.
*/
virtual void run( osg::ref_ptr< WGEManagedGroupNode > output, const char sliceNum = -1 ) = 0;
protected:
/**
* The underlying scalar dataset to compute those boundaries for.
*/
boost::shared_ptr< const WDataSetScalar > m_texture;
/**
* The three slice positions.
* 0 : xSlice, 1 : ySlice, 2 : zSlice
*/
boost::array< WPropDouble, 3 > m_slicePos;
/**
* Pointer to the three slices.
* 0 : xSlice, 1 : ySlice, 2 : zSlice
*/
boost::array< osg::ref_ptr< WGEManagedGroupNode >, 3 > m_slices;
/**
* Gray matter threshold.
*/
WPropDouble m_grayMatter;
/**
* White matter threshold.
*/
WPropDouble m_whiteMatter;
/**
* Shader generating the curves of gray and white matter.
*/
osg::ref_ptr< WGEShader > m_shader;
/**
* Gray matter color.
*/
WPropColor m_gmColor;
/**
* White matter color.
*/
WPropColor m_wmColor;
private:
};
#endif // WBOUNDARYBUILDER_H
//---------------------------------------------------------------------------
//
// 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 "core/dataHandler/WDataSetScalar.h"
#include "core/dataHandler/WGridRegular3D.h"
#include "core/graphicsEngine/shaders/WGEPropertyUniform.h"
#include "core/graphicsEngine/WGEGeodeUtils.h"
#include "core/graphicsEngine/WGEManagedGroupNode.h"
#include "WBoundaryFragments.h"
WBoundaryFragments::WBoundaryFragments( boost::shared_ptr< const WDataSetScalar > texture, boost::shared_ptr< const WProperties > properties,
boost::array< osg::ref_ptr< WGEManagedGroupNode >, 3 > *slices, boost::filesystem::path localPath )
: WBoundaryBuilder( texture, properties, slices )
{
m_shader = osg::ref_ptr< WGEShader > ( new WGEShader( "WMBoundaryCurvesWMGM-Fragments", localPath ) );
}
void WBoundaryFragments::run( osg::ref_ptr< WGEManagedGroupNode > output, const char /* sliceNum */ )
{
boost::shared_ptr< WGridRegular3D > grid = boost::shared_dynamic_cast< WGridRegular3D >( m_texture->getGrid() );
// create a new geodes containing the slices
m_slices[0]->addChild( wge::genFinitePlane( grid->getOrigin(), grid->getNbCoordsY() * grid->getDirectionY(),
grid->getNbCoordsZ() * grid->getDirectionZ() ) );
m_slices[1]->addChild( wge::genFinitePlane( grid->getOrigin(), grid->getNbCoordsX() * grid->getDirectionX(),
grid->getNbCoordsZ() * grid->getDirectionZ() ) );
m_slices[2]->addChild( wge::genFinitePlane( grid->getOrigin(), grid->getNbCoordsX() * grid->getDirectionX(),
grid->getNbCoordsY() * grid->getDirectionY() ) );
osg::ref_ptr< osg::Uniform > u_grayMatter = new WGEPropertyUniform< WPropDouble >( "u_grayMatter", m_grayMatter );
osg::ref_ptr< osg::Uniform > u_whiteMatter = new WGEPropertyUniform< WPropDouble >( "u_whiteMatter", m_whiteMatter );
osg::ref_ptr< osg::Uniform > u_gmColor = new WGEPropertyUniform< WPropColor >( "u_gmColor", m_gmColor );
osg::ref_ptr< osg::Uniform > u_wmColor = new WGEPropertyUniform< WPropColor >( "u_wmColor", m_wmColor );
for( char i = 0; i < 3; ++i )
{
m_shader->apply( m_slices[i] );
wge::bindTexture( m_slices[i], m_texture->getTexture() );
osg::StateSet *ss = m_slices[i]->getOrCreateStateSet();
ss->addUniform( u_grayMatter );
ss->addUniform( u_whiteMatter );
ss->addUniform( u_gmColor );
ss->addUniform( u_wmColor );
ss->addUniform( new WGEPropertyUniform< WPropDouble >( "u_vertexShift", m_slicePos[i] ) );
ss->addUniform( new osg::Uniform( "u_vertexShiftDirection", static_cast< osg::Vec3f >( getDirections< double >( grid )[i] ) ) );
output->insert( m_slices[i] );
}
}
//---------------------------------------------------------------------------
//
// 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 WBOUNDARYFRAGMENTS_H
#define WBOUNDARYFRAGMENTS_H
#include <boost/filesystem.hpp>
#include <osg/ref_ptr>
#include "core/graphicsEngine/shaders/WGEShader.h"
#include "core/graphicsEngine/WGEManagedGroupNode.h"
#include "WBoundaryBuilder.h"
// forward declarations
class WDataSetScalar;
/**
* Constructs the boundary surface curves of the WM and GM via a shader approach.
*/
class WBoundaryFragments : public WBoundaryBuilder
{
public:
/**
* Constructs an builder instance.
*
* \param texture The underlying scalar dataset to compute those boundaries for
* \param properties Properties, like slice positions, thresholds etc.
* \param slices Slice geodes which are controlled (hide/unhide) by the module.
* \param localPath Path where to search for the shaders.
*/
WBoundaryFragments( boost::shared_ptr< const WDataSetScalar > texture,
boost::shared_ptr< const WProperties > properties,
boost::array< osg::ref_ptr< WGEManagedGroupNode >, 3 > *slices,
boost::filesystem::path localPath );
/**
* Starts rendering and finally insert result in output.
*
* \param output Where to put/insert the results.
* \param sliceNum If given -1 all slice will perform an update, otherwise only the slice with the given slice number.
*/
virtual void run( osg::ref_ptr< WGEManagedGroupNode > output, const char sliceNum = -1 );
protected:
private:
};
#endif // WBOUNDARYFRAGMENTS_H
This diff is collapsed.
//---------------------------------------------------------------------------
//
// 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 WBOUNDARYLINES_H
#define WBOUNDARYLINES_H
#include <list>
#include <utility>
#include <vector>
#include <boost/array.hpp>
#include <boost/unordered_map.hpp>
#include <osg/Geometry>
#include "core/common/WBoundingBox.h"
#include "WBoundaryBuilder.h"
// forward declarations
template< typename T >
class WGridRegular3DTemplate;
class WDataSetScalar;
/**
* Computes boundary lines with an iso lines approach instead of the fragment shader.
*/
class WBoundaryLines : public WBoundaryBuilder
{
public:
/**
* Constructs an builder instance.
*
* \param texture The underlying scalar dataset to compute those boundaries for
* \param properties Properties, like slice positions, thresholds etc.
* \param slices Slice geodes which are controlled (hide/unhide) by the module.
* \param localPath The path where the shaders reside
*/
WBoundaryLines( boost::shared_ptr< const WDataSetScalar > texture,
boost::shared_ptr< const WProperties > properties,
boost::array< osg::ref_ptr< WGEManagedGroupNode >, 3 > *slices,
boost::filesystem::path localPath );
/**
* Starts rendering and finally insert result in output.
*
* \param output Where to put/insert the results.
* \param sliceNum If given -1 all slice will perform an update, otherwise only the slice with the given slice number.
*/
virtual void run( osg::ref_ptr< WGEManagedGroupNode > output, const char sliceNum = -1 );
protected:
private:
/**
* Map for edgeID -> ( neighbourEdgeID1, neighbourEdgeID2 ).
*/
typedef boost::unordered_map< size_t, std::pair< int , int > > EdgeNeighbourMap;
/**
* Two pointIDs describing an edge.
*/
typedef std::pair< std::size_t, std::size_t > Edge;
//todo(math): Edge is wrong here, since that are not point but EdgeIDs
/**
* Vector of segments where two edgeIDs describing an segment.
*/
typedef std::vector< Edge > SegmentVector;
/**
* List of segments where two edgeIDs describing an segment.
*/
typedef std::list< Edge > SegmentList;
/**
* Creates for each slice number the corresponding geodes for a bounding box as well
* for the boundary curves.
*
* \param sliceNum For which slice the geode should be generated.
*
* \return A WGEGroupNode containing the bb geode as well as the boundary curve geode.
*/
osg::ref_ptr< WGEGroupNode > generateSlice( const unsigned char sliceNum ) const;
/**
* In order to compute iso lines of the gray and white matter for a specific slice, we need a grid to operate on. This
* grid represents a WGridRegular2DIn3D but the last dimension/numCoordsZ() is set to 1.
*
* \param sliceNum For which slice the grid should be generated.
* \param resolution The size of the cells in that grid.
*
* \return The 2D grid for the given slice.
*/
boost::shared_ptr< WGridRegular3DTemplate< double > > generateSliceGrid( const unsigned char sliceNum, const double resolution ) const;
/**
* Extracts the sequence of edges representing a line strip, where the first element in the hash map is a member of.
*
* \param l The hash map, containing edge numbers as keys and their left and right neighbour as the value pair.
*
* \return List of edge number of the line strip.
*/
std::list< size_t > extractLineStripEdges( EdgeNeighbourMap *l ) const;
/**
* Constructs a hash map where each grid edgeID ( the key ), has a pair of neighbour edgeIDs ( value ).
*
* \param segments List of segments given as pair of edgeIDs.
*
* \return The edge neighbour map.
*/
boost::shared_ptr< EdgeNeighbourMap > generateEdgeNeighbourMap( const SegmentList& segments ) const;
/**
* Construct a iso lines geometry for the given isovalue.
*
* \param isoValue The iso value
* \param map Containing edgeIDs as keys and
* \param edgeIDToPointIDs
* \param interpolates
* \param sliceGrid
*
* \return The osg geometry.
*/
osg::ref_ptr< osg::Geometry > traverseEdgeHashMap( double isoValue, boost::shared_ptr< WBoundaryLines::EdgeNeighbourMap > map,
const std::vector< Edge >& edgeIDToPointIDs, const std::vector< double > &interpolates,
boost::shared_ptr< const WGridRegular3DTemplate< double > > sliceGrid ) const;
/**
* Generates the bounding boxes for all three slices.
*/
void computeSliceBB();
/**
* Boundingboxes for each slice.
* 0 : xSlice, 1 : ySlice, 2 : zSlice
*/
boost::array< WBoundingBox, 3 > m_sliceBB;
/**
* Shortcut for the WRegularGrid3D given via the m_texture dataset.
*/
boost::shared_ptr< WGridRegular3DTemplate< double > > m_grid;
/**
* Defines the size of quads to be processed for the iso curve computation.
*/
WPropDouble m_resolution;
};
#endif // WBOUNDARYLINES_H
//---------------------------------------------------------------------------
//
// 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 <boost/array.hpp>
#include "core/dataHandler/WDataSetScalar.h"
#include "core/dataHandler/WGridRegular3D.h"
#include "core/graphicsEngine/WGEManagedGroupNode.h"
#include "core/kernel/WKernel.h"
#include "core/kernel/WModuleInputData.h"
#include "WBoundaryBuilder.h"
#include "WBoundaryFragments.h"
#include "WBoundaryLines.h"
#include "WMBoundaryCurvesWMGM.h"
#include "WMBoundaryCurvesWMGM.xpm"
// This line is needed by the module loader to actually find your module. Do not remove. Do NOT add a ";" here.
W_LOADABLE_MODULE( WMBoundaryCurvesWMGM )
WMBoundaryCurvesWMGM::WMBoundaryCurvesWMGM():
WModule()
{
}
WMBoundaryCurvesWMGM::~WMBoundaryCurvesWMGM()
{
// Cleanup!
}
boost::shared_ptr< WModule > WMBoundaryCurvesWMGM::factory() const
{
return boost::shared_ptr< WModule >( new WMBoundaryCurvesWMGM() );
}
const char** WMBoundaryCurvesWMGM::getXPMIcon() const
{
return WMBoundaryCurvesWMGM_xpm;
}
const std::string WMBoundaryCurvesWMGM::getName() const
{
return "Boundary Curves WMGM";
}
const std::string WMBoundaryCurvesWMGM::getDescription() const
{
return "Boundary Curves of Gray Matter White Matter";
}
void WMBoundaryCurvesWMGM::connectors()
{
m_textureIC = WModuleInputData< WDataSetScalar >::createAndAdd( shared_from_this(), "textureInput", "The image for the two curves." );
// call WModule's initialization
WModule::connectors();
}
void WMBoundaryCurvesWMGM::properties()
{
WPropGroup sliceGroup = m_properties->addPropertyGroup( "Slices", "Group of slices for the GM and WM curves." );
m_showSlice[0] = sliceGroup->addProperty( "Show Sagittal", "Show GM and WM boundary curves on sagittal slice.", true );
m_showSlice[1] = sliceGroup->addProperty( "Show Coronal", "Show GM and WM boundary curves on coronal slice.", true );
m_showSlice[2] = sliceGroup->addProperty( "Show Axial", "Show GM and WM boundary curves on axial slice.", true );
// The slice positions. These get update externally.
// TODO(all): this should somehow be connected to the nav slices.
boost::function< void ( boost::shared_ptr< WPropertyBase > ) > callBack = boost::bind( &WMBoundaryCurvesWMGM::rerunBuilder, this, _1 ); // NOLINT extra space before (, which is not a function call
m_slicePos[0] = sliceGroup->addProperty( "Sagittal Position", "Slice X position.", 0.0, callBack );
m_slicePos[1] = sliceGroup->addProperty( "Coronal Position", "Slice Y position.", 0.0, callBack );
m_slicePos[2] = sliceGroup->addProperty( "Axial Position", "Slice Z position.", 0.0, callBack );
// since we don't know anything yet => make them unusable
for( char i = 0; i < 3; ++i )
{
m_slicePos[i]->setMin( 0 );
m_slicePos[i]->setMax( 0 );
}
m_grayMatter = m_properties->addProperty( "Gray Matter", "Isovalue specifying the Gray-Matter-CSF border.", 0.2, callBack );
m_grayMatter->setMin( 0.0 );
m_grayMatter->setMax( 1.0 );
m_whiteMatter = m_properties->addProperty( "White Matter", "Isovalue specifying the White-Matter-Gray-Matter border.", 0.4, callBack );
m_whiteMatter->setMin( 0.0 );
m_whiteMatter->setMax( 1.0 );
WPropColor gmColor = m_properties->addProperty( "Gray Matter Color", "Color for the GM border", WColor( 0.0, 0.0, 0.0, 1.0 ) );
WPropColor wmColor = m_properties->addProperty( "White Matter Color", "Color for the WM border", WColor( 0.5, 0.5, 0.5, 1.0 ) );
m_resolution = m_properties->addProperty( "Resolution", "Size of the quads, used for sampling the Iso-Lines", 1.0, callBack );
m_resolution->setMin( 0.1 ); // will take very very very long!!!
m_resolution->setMax( 3.0 );
// for selecting the strategy
boost::shared_ptr< WItemSelection > strategies( new WItemSelection() );
strategies->addItem( "Iso-Lines", "Marching lines" );
strategies->addItem( "Iso-Fragments", "Small environment" );
m_strategySelector = m_properties->addProperty( "Strategy", "How the boundary curves should be draw", strategies->getSelectorFirst() );
WPropertyHelper::PC_SELECTONLYONE::addTo( m_strategySelector );
WPropertyHelper::PC_NOTEMPTY::addTo( m_strategySelector );
// call WModule's initialization
WModule::properties();
}
void WMBoundaryCurvesWMGM::rerunBuilder( boost::shared_ptr< WPropertyBase > /* prop */ )
{
boost::unique_lock< boost::mutex > lock( m_updateMutex );
// debugLog() << "Start builder rerun";
if( m_builder && m_output && ( m_strategySelector->get().at( 0 )->getName() == "Iso-Lines" ) )
{
// full update
if( m_grayMatter->changed() || m_whiteMatter->changed() || m_resolution->changed() )
{
m_grayMatter->get( true );
m_whiteMatter->get( true );
m_resolution->get( true );