Commit b80f184d authored by Mathias Goldau's avatar Mathias Goldau
Browse files

[ADD #210] New stub for WMVoxelizer, and enabled compatibles also for WModules.

parent bb432264
......@@ -27,16 +27,19 @@
#include <boost/shared_ptr.hpp>
#include "WFiberCluster.h"
#include "../../common/WLimits.h"
#include "../../dataHandler/WDataSetFibers.h"
#include "../../math/fiberSimilarity/WDLTMetric.h"
#include "../WLimits.h"
#include "../WTransferable.h"
#include "WFiberCluster.h"
WFiberCluster::WFiberCluster()
: WTransferable()
{
}
WFiberCluster::WFiberCluster( size_t index )
: WTransferable()
{
m_memberIndices.push_back( index );
}
......
......@@ -26,17 +26,19 @@
#define WFIBERCLUSTER_H
#include <list>
#include <string>
#include <vector>
#include <boost/shared_ptr.hpp>
#include "../../common/WColor.h"
#include "../../dataHandler/WDataSetFibers.h"
#include "../WColor.h"
#include "../WTransferable.h"
/**
* Represents a cluster of indices of a WDataSetFibers.
*/
class WFiberCluster
class WFiberCluster : public WTransferable
{
friend class WFiberClusterTest;
public:
......@@ -102,6 +104,22 @@ public:
*/
WColor getColor() const;
/**
* The only reason for implementing is here, to prevent this class from
* beeing abstract.
*
*\return A name.
*/
virtual const std::string getName() const;
/**
* The only reason for implementing is here, to prevent this class from
* beeing abstract.
*
*\return A name.
*/
virtual const std::string getDescription() const;
/**
* \param other The other fiber which should be compared
* \return true If both clusters having same fibers IN SAME ORDER!
......@@ -158,6 +176,16 @@ inline WColor WFiberCluster::getColor() const
return m_color;
}
inline const std::string WFiberCluster::getName() const
{
return "FiberCluster";
}
inline const std::string WFiberCluster::getDescription() const
{
return "A collection of indices for fibers representing a fiber cluster";
}
inline bool WFiberCluster::operator==( const WFiberCluster& other ) const
{
return m_memberIndices == other.m_memberIndices;
......
......@@ -158,24 +158,25 @@ void WQtDatasetBrowser::selectTreeItem()
if ( m_treeWidget->selectedItems().at( 0 )->type() == 1 )
{
module = ( ( WQtDatasetTreeItem* ) m_treeWidget->selectedItems().at( 0 ) )->getModule();
// create ribbon menu entry
m_mainWindow->getCompatiblesToolBar()->addTab( QString( "Compatible Modules" ), false );
std::set< boost::shared_ptr< WModule > > comps = WModuleFactory::getModuleFactory()->getCompatiblePrototypes( module );
for ( std::set< boost::shared_ptr< WModule > >::iterator iter = comps.begin(); iter != comps.end(); ++iter )
{
WQtPushButton* button = m_mainWindow->getCompatiblesToolBar()->addPushButton( QString( ( *iter )->getName().c_str() ),
QString( "Compatible Modules" ),
m_mainWindow->getIconManager()->getIcon( "load" ),
QString( ( *iter )->getName().c_str() ) );
connect( button, SIGNAL( pushButtonPressed( QString ) ), m_mainWindow, SLOT( slotActivateModule( QString ) ) );
}
}
else
{
module = ( ( WQtModuleTreeItem* ) m_treeWidget->selectedItems().at( 0 ) )->getModule();
}
// every module may have compatibles: create ribbon menu entry
m_mainWindow->getCompatiblesToolBar()->addTab( QString( "Compatible Modules" ), false );
std::set< boost::shared_ptr< WModule > > comps = WModuleFactory::getModuleFactory()->getCompatiblePrototypes( module );
for ( std::set< boost::shared_ptr< WModule > >::iterator iter = comps.begin(); iter != comps.end(); ++iter )
{
WQtPushButton* button = m_mainWindow->getCompatiblesToolBar()->addPushButton( QString( ( *iter )->getName().c_str() ),
QString( "Compatible Modules" ),
m_mainWindow->getIconManager()->getIcon( "load" ),
QString( ( *iter )->getName().c_str() ) );
connect( button, SIGNAL( pushButtonPressed( QString ) ), m_mainWindow, SLOT( slotActivateModule( QString ) ) );
}
// create properties
std::vector < WProperty* >props = module->getProperties()->getPropertyVector();
......
......@@ -28,25 +28,23 @@
#include <typeinfo>
#include "../common/WLogger.h"
#include "../modules/data/WMData.h"
#include "../modules/navSlices/WMNavSlices.h"
#include "../modules/coordinateSystem/WMCoordinateSystem.h"
#include "../modules/fiberDisplay/WMFiberDisplay.h"
#include "../modules/fiberCulling/WMFiberCulling.h"
#include "../modules/fiberClustering/WMFiberClustering.h"
#include "../modules/marchingCubes/WMMarchingCubes.h"
#include "../modules/data/WMData.h"
#include "../modules/distanceMap/WMDistanceMap.h"
#include "../modules/eegTest/WMEEGTest.h"
#include "../modules/textureList/WMTextureList.h"
#include "../modules/hud/WMHud.h"
#include "../modules/eegView/WMEEGView.h"
#include "../modules/fiberClustering/WMFiberClustering.h"
#include "../modules/fiberCulling/WMFiberCulling.h"
#include "../modules/fiberDisplay/WMFiberDisplay.h"
#include "../modules/hud/WMHud.h"
#include "../modules/marchingCubes/WMMarchingCubes.h"
#include "../modules/navSlices/WMNavSlices.h"
#include "../modules/prototypeBoxManipulation/WMPrototypeBoxManipulation.h"
#include "exceptions/WPrototypeUnknown.h"
#include "exceptions/WPrototypeNotUnique.h"
#include "../modules/textureList/WMTextureList.h"
#include "../modules/voxelizer/WMVoxelizer.h"
#include "WModuleFactory.h"
#include "exceptions/WPrototypeNotUnique.h"
#include "exceptions/WPrototypeUnknown.h"
// factory instance as singleton
boost::shared_ptr< WModuleFactory > WModuleFactory::m_instance = boost::shared_ptr< WModuleFactory >();
......@@ -83,6 +81,7 @@ void WModuleFactory::load()
m_prototypes.insert( boost::shared_ptr< WModule >( new WMHud() ) );
m_prototypes.insert( boost::shared_ptr< WModule >( new WMEEGView() ) );
m_prototypes.insert( boost::shared_ptr< WModule >( new WMPrototypeBoxManipulation() ) );
m_prototypes.insert( boost::shared_ptr< WModule >( new WMVoxelizer() ) );
lock.unlock();
......
......@@ -3,4 +3,4 @@ ADD_SUBDIRECTORY( fiberCulling )
ADD_SUBDIRECTORY( fiberClustering )
ADD_SUBDIRECTORY( marchingCubes )
ADD_SUBDIRECTORY( coordinateSystem )
ADD_SUBDIRECTORY( voxelizer )
......@@ -313,10 +313,13 @@ void WMFiberClustering::connectors()
{
using boost::shared_ptr;
typedef WModuleInputData< WDataSetFibers > FiberInputData; // just an alias
typedef WModuleOutputData< WDataSetSingle > SingleOutputData; // -"-
m_fiberInput = shared_ptr< FiberInputData >( new FiberInputData( shared_from_this(), "fiberInput", "A loaded fiber dataset." ) );
m_blurredClusters = shared_ptr< SingleOutputData >( new SingleOutputData( shared_from_this(), "DataSetOutput", "gsdjf g" ) );
addConnector( m_fiberInput );
addConnector( m_blurredClusters );
WModule::connectors(); // call WModules initialization
}
......
FILE( GLOB_RECURSE MODULES_SRC "*.cpp" )
# Unit tests
IF( CXXTEST_FOUND )
CXXTEST_ADD_TESTS_FROM_LIST( "${MODULES_SRC}"
"kernel"
)
ENDIF( CXXTEST_FOUND )
//---------------------------------------------------------------------------
//
// 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/shared_ptr.hpp>
#include <osg/Geode>
#include <osg/Geometry>
#include "../../common/WColor.h"
#include "../../common/WLogger.h"
#include "../../dataHandler/WDataSetFibers.h"
#include "../../dataHandler/WSubject.h"
#include "../../graphicsEngine/WGraphicsEngine.h"
#include "../../kernel/WKernel.h"
#include "../../math/WFiber.h"
#include "../../utils/WColorUtils.h"
#include "WMVoxelizer.h"
WMVoxelizer::WMVoxelizer()
: WModule()
{
}
WMVoxelizer::~WMVoxelizer()
{
}
boost::shared_ptr< WModule > WMVoxelizer::factory() const
{
return boost::shared_ptr< WModule >( new WMVoxelizer() );
}
//osg::ref_ptr< osg::Geode > WMVoxelizer::generateGrid() const
//{
// using osg::ref_ptr;
// ref_ptr< osg::Vec3Array > vertices = ref_ptr< osg::Vec3Array >( new osg::Vec3Array );
// ref_ptr< osg::Vec4Array > colors = ref_ptr< osg::Vec4Array >( new osg::Vec4Array );
// ref_ptr< osg::Geometry > geometry = ref_ptr< osg::Geometry >( new osg::Geometry );
//
// boost::shared_ptr< WGridRegular3D > grid = boost::shared_dynamic_cast< WGridRegular3D >( ( *m_dataSet ).getGrid() );
// assert( grid.get() );
// const wmath::WPosition& origin = grid->getOrigin();
// double dx = grid->getOffsetX();
// double dy = grid->getOffsetY();
// double dz = grid->getOffsetZ();
// double nbCoordsX = 8;
// double nbCoordsY = 8;
// double nbCoordsZ = 10;
//
//
// for( size_t x = 0; x < nbCoordsX; ++x )
// {
// vertices->push_back( osg::Vec3( x * dx, 0, 0 ) );
// vertices->push_back( osg::Vec3( x * dx, 0, nbCoordsZ * dz ) );
// vertices->push_back( osg::Vec3( x * dx, nbCoordsY * dy, nbCoordsZ * dz ) );
// vertices->push_back( osg::Vec3( x * dx, nbCoordsY * dy, 0 ) );
// vertices->push_back( osg::Vec3( x * dx, 0, 0 ) );
// geometry->addPrimitiveSet( new osg::DrawArrays( osg::PrimitiveSet::LINE_STRIP, vertices->size() - 5, 5 ) );
// for( size_t i = 0; i < nbCoordsZ; ++i )
// {
// vertices->push_back( osg::Vec3( x * dx, 0, i * dz ) );
// vertices->push_back( osg::Vec3( x * dx, nbCoordsY * dy, i * dz ) );
// geometry->addPrimitiveSet( new osg::DrawArrays( osg::PrimitiveSet::LINES, vertices->size() - 2, 2 ) );
// }
// }
// for( size_t y = 0; y < nbCoordsY; ++y )
// {
// vertices->push_back( osg::Vec3( 0, y * dy, 0 ) );
// vertices->push_back( osg::Vec3( 0, y * dy, nbCoordsZ * dz ) );
// vertices->push_back( osg::Vec3( nbCoordsX * dx, y * dy, nbCoordsZ * dz ) );
// vertices->push_back( osg::Vec3( nbCoordsX * dx, y * dy, 0 ) );
// vertices->push_back( osg::Vec3( 0, y * dy, 0 ) );
// geometry->addPrimitiveSet( new osg::DrawArrays( osg::PrimitiveSet::LINE_STRIP, vertices->size() -5 , 5 ) );
// for( size_t i = 0; i < nbCoordsZ; ++i )
// {
// vertices->push_back( osg::Vec3( 0 , y * dy, i * dz ) );
// vertices->push_back( osg::Vec3( nbCoordsX * dx, y * dy, i * dz ) );
// geometry->addPrimitiveSet( new osg::DrawArrays( osg::PrimitiveSet::LINES, vertices->size() - 2, 2 ) );
// }
// }
// for( size_t z = 0; z < nbCoordsZ; ++z )
// {
// vertices->push_back( osg::Vec3( 0, 0, z * dz ) );
// vertices->push_back( osg::Vec3( nbCoordsX * dx, 0, z * dz ) );
// vertices->push_back( osg::Vec3( nbCoordsX * dx, nbCoordsY * dy, z * dz ) );
// vertices->push_back( osg::Vec3( 0, nbCoordsY * dy, z * dz ) );
// vertices->push_back( osg::Vec3( 0, 0, z * dz ) );
// geometry->addPrimitiveSet( new osg::DrawArrays( osg::PrimitiveSet::LINE_STRIP, vertices->size() - 5, 5 ) );
// }
// for( size_t x = 0; x < nbCoordsX; ++x )
// {
// for( size_t y = 0; y < nbCoordsY; ++y )
// {
// vertices->push_back( osg::Vec3( x * dx, y * dy, 0 ) );
// vertices->push_back( osg::Vec3( x * dx, y * dy, nbCoordsZ * dz ) );
// geometry->addPrimitiveSet( new osg::DrawArrays( osg::PrimitiveSet::LINES, vertices->size() - 2, 2 ) );
// }
// }
// // draw quad
// vertices->push_back( osg::Vec3( , , ) );
// geometry->addPrimitiveSet( new osg::DrawArrays( osg::PrimitiveSet::LINES, vertices->size() - 2, 2 ) );
//
// geometry->setVertexArray( vertices );
// colors->push_back( osg::Vec4( 0.3, 0.3, 0.3, 0 ) );
// geometry->setColorArray( colors );
// geometry->setColorBinding( osg::Geometry::BIND_OVERALL );
// osg::ref_ptr< osg::Geode > geode = osg::ref_ptr< osg::Geode >( new osg::Geode );
// geode->addDrawable( geometry.get() );
// return geode;
//}
////void WMVoxelizer::addCuboid( ref_ptr< osg::Geometry > geometry,
//// const WPosition& lowerLeft,
//// const WPosition& upperRight,
//// const WColor& color,
//// double transparency
//// ) const
////{
//// using osg::ref_ptr;
//// ref_ptr< osg::Vec3Array > vertices = geometry->getVertexArray();
//// ref_ptr< osg::Vec4Array > colors = geometry->getColorArray();
//// geometry->addPrimitiveSet( new osg::DrawArrays( osg::PrimitiveSet::QUAD_STRIP, vertices->size() - 2, 2 ) );
////}
void WMVoxelizer::moduleMain()
{
// additional fire-condition: "data changed" flag
m_moduleState.add( m_input->getDataChangedCondition() );
ready();
while ( !m_shutdownFlag() ) // loop until the module container requests the module to quit
{
// m_dataSet = m_input->getData();
// if ( !( m_dataSet.get() ) ) // ok, the output has not yet sent data
// {
// m_moduleState.wait();
// continue;
// }
update();
m_moduleState.wait(); // waits for firing of m_moduleState ( dataChanged, shutdown, etc. )
// May be called twice
WKernel::getRunningKernel()->getGraphicsEngine()->getScene()->removeChild( m_osgNode.get() );
}
}
void WMVoxelizer::update()
{
// remove nodes if they are any
WKernel::getRunningKernel()->getGraphicsEngine()->getScene()->removeChild( m_osgNode.get() );
// create new node
m_osgNode = osg::ref_ptr< osg::Group >( new osg::Group );
// m_osgNode->addChild( generateGrid().get() );
m_osgNode->getOrCreateStateSet()->setMode( GL_LIGHTING, osg::StateAttribute::OFF );
WKernel::getRunningKernel()->getGraphicsEngine()->getScene()->addChild( m_osgNode.get() );
}
void WMVoxelizer::connectors()
{
using boost::shared_ptr;
typedef WModuleInputData< const WFiberCluster > InputData; // just an alias
m_input = shared_ptr< InputData >( new InputData( shared_from_this(), "voxelInput", "A loaded dataset with grid." ) );
addConnector( m_input );
WModule::connectors(); // call WModules initialization
}
void WMVoxelizer::properties()
{
m_properties->addString( getName(), getDescription() );
// this bool is hidden
m_properties->addBool( "active", true, true )->connect( boost::bind( &WMVoxelizer::slotPropertyChanged, this, _1 ) );
}
void WMVoxelizer::slotPropertyChanged( std::string propertyName )
{
if( propertyName == "active" )
{
if ( m_properties->getValue< bool >( propertyName ) )
{
m_osgNode->setNodeMask( 0xFFFFFFFF );
}
else
{
m_osgNode->setNodeMask( 0x0 );
}
}
else
{
// instead of WLogger we must use std::cerr since WLogger needs to much time!
std::cerr << propertyName << std::endl;
assert( 0 && "This property name is not supported by this function yet." );
}
}
//---------------------------------------------------------------------------
//
// 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 WMVOXELIZER_H
#define WMVOXELIZER_H
#include <string>
#include <utility>
#include <osg/Geode>
#include "../../common/datastructures/WFiberCluster.h"
#include "../../dataHandler/WDataSetSingle.h"
#include "../../kernel/WModule.h"
#include "../../kernel/WModuleInputData.h"
class WMVoxelizer : public WModule
{
friend class WMVoxelizerTest;
public:
/**
* Constructs new FiberTestModule
*/
WMVoxelizer();
/**
* Destructs this FiberTestModule
*/
virtual ~WMVoxelizer();
/**
* 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;
/**
* Determine what to do if a property was changed.
* \param propertyName Name of the property.
*/
void slotPropertyChanged( std::string propertyName );
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();
void update();
/**
* Mark the given Voxel as visited by the Rasterization Algorithm.
*/
void putVoxel( const wmath::WPosition& center );
/**
* Builds an OSG geode where all voxels inside the dataSet which are not
* zero are drawn as cuboids.
*/
void drawVoxel() const;
/**
* Generates a list of vertices representing a QUAD_STRIP for a cuboid
* where the center is given as WPosition.
*
*\param center The center of the cuboid.
*\param margin The margin from the center to the voxel boundaries.
*
*\return The array of vertices.
*/
osg::ref_ptr< osg::Vec3Array > generateCuboidVertices( const wmath::WPosition& center, double margin ) const;
/**
* Construtcs out of the given boundary vertices a new dataset.
*
*\param lowerLeft The front lower left vertex.
*\param upperRight The back upper right.
*
*\return The dataset where to store our voxel.
*/
boost::shared_ptr< WDataSetSingle > createDataSet( const wmath::WPosition& lowerLeft,
const wmath::WPosition& upperRight ) const;
/**
* Creates two vertices describing the bounding box of a cluster.
*
*\param cluster With its fibers
*
*\return Pair of WPositions: first == front lower left, second == back upper right
*/
std::pair< wmath::WPosition, wmath::WPosition > createBoundingBox( const WFiberCluster& cluster ) const;
private:
/**
* Input connector for a fiber cluster dataset.
*/
boost::shared_ptr< WModuleInputData< const WFiberCluster > > m_input;
/**
* OSG node for this module. All other OSG nodes of this module should be
* placed as child to this node.
*/
osg::ref_ptr< osg::Group > m_osgNode;
};
inline const std::string WMVoxelizer::getName() const
{
return std::string( "Voxelizer" );
}
inline const std::string WMVoxelizer::getDescription() const
{
return std::string( "Detects voxel of a given grid via a WGeometry." );
}
#endif // WMVOXELIZER_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/>.
//
//---------------------------------------------------------------------------
#ifndef WVOXELIZER_TEST_H
#define WVOXELIZER_TEST_H
#include <cxxtest/TestSuite.h>
#include "../WVoxelizer.h"
/**