Commit cb5fb6b6 authored by cornimueller's avatar cornimueller
Browse files

[ADD] Added Fiber Transform module to affine transform and save a loaded fiber...

[ADD] Added Fiber Transform module to affine transform and save a loaded fiber dataset using a given matrix and vector (currently hardcoded ...)
parent c80cd8cf
......@@ -157,6 +157,12 @@ public:
*/
WMatrix operator*( const WMatrix& rhs ) const;
/**
* Multiplication with a vector.
* \param rhs The right hand side of the multiplication
*/
WValue< T > operator*( const WValue< T >& rhs ) const;
protected:
private:
size_t m_nbCols; //!< Number of columns of the matrix. The number of rows will be computed by (size/m_nbCols).
......@@ -181,5 +187,20 @@ template< typename T > WMatrix< T > WMatrix< T >::operator*( const WMatrix< T >&
return result;
}
template< typename T > WValue< T > WMatrix< T >::operator*( const WValue< T >& rhs ) const
{
assert( rhs.size() == getNbCols() );
WValue< T > result( getNbRows() );
for( size_t r = 0; r < getNbRows(); ++r)
{
for( size_t i = 0; i < getNbCols(); ++i )
{
result[r] += ( *this )( r, i ) * rhs[i];
}
}
return result;
}
} // End of namespace
#endif // WMATRIX_H
......@@ -46,6 +46,7 @@
#include "../modules/fiberCulling/WMFiberCulling.h"
#include "../modules/fiberDisplay/WMFiberDisplay.h"
#include "../modules/fiberSelection/WMFiberSelection.h"
#include "../modules/fiberTransform/WMFiberTransform.h"
#include "../modules/gaussFiltering/WMGaussFiltering.h"
#include "../modules/hud/WMHud.h"
#include "../modules/marchingCubes/WMMarchingCubes.h"
......@@ -116,6 +117,7 @@ void WModuleFactory::load()
m_prototypes.insert( boost::shared_ptr< WModule >( new WMGeometryGlyphs() ) );
m_prototypes.insert( boost::shared_ptr< WModule >( new WMArbitraryRois() ) );
m_prototypes.insert( boost::shared_ptr< WModule >( new WMMeshReader() ) );
m_prototypes.insert( boost::shared_ptr< WModule >( new WMFiberTransform() ) );
lock.unlock();
......
......@@ -294,8 +294,8 @@ void WMEEGView::moduleMain()
wmath::WPosition position = m_sourceCalculator->calculate( event );
m_roi = WKernel::getRunningKernel()->getRoiManager()->addRoi( new WROIBox(
position - wmath::WVector3D( 10.0, 10.0, 10.0 ),
position + wmath::WVector3D( 10.0, 10.0, 10.0 ) ) );
position - wmath::WVector3D( 5.0, 5.0, 5.0 ),
position + wmath::WVector3D( 5.0, 5.0, 5.0 ) ) );
}
else
{
......
//---------------------------------------------------------------------------
//
// 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 <boost/filesystem/path.hpp>
#include <boost/shared_ptr.hpp>
#include "../../common/WAssert.h"
#include "../../common/WCondition.h"
#include "../../common/WProgress.h"
#include "../../common/WPropertyTypes.h"
#include "../../dataHandler/WDataSetFiberVector.h"
#include "../../dataHandler/WDataSetFibers.h"
#include "../../dataHandler/io/WWriterFiberVTK.h"
#include "../../kernel/WModule.h"
#include "../../kernel/WModuleInputData.h"
#include "../../kernel/WModuleOutputData.h"
#include "WMFiberTransform.h"
WMFiberTransform::WMFiberTransform()
: WModule(),
m_recompute( new WCondition() ),
m_transformationMatrix( 3, 3 )
{
}
boost::shared_ptr< WModule > WMFiberTransform::factory() const
{
// See "src/modules/template/" for an extensively documented example.
return boost::shared_ptr< WModule >( new WMFiberTransform() );
}
void WMFiberTransform::connectors()
{
// Put the code for your connectors here. See "src/modules/template/" for an extensively documented example.
typedef WModuleInputData< WDataSetFibers > FiberInputData; // just an alias
m_fiberInput = boost::shared_ptr< FiberInputData >( new FiberInputData( shared_from_this(), "fiberInput", "A loaded fiber dataset." ) );
typedef WModuleOutputData< WDataSetFibers > FiberOutputData; // just an alias
m_output = boost::shared_ptr< FiberOutputData >( new FiberOutputData( shared_from_this(), "fiberOutput", "The transformed fibers." ) );
addConnector( m_fiberInput );
addConnector( m_output );
// call WModules initialization
WModule::connectors();
}
void WMFiberTransform::properties()
{
// Put the code for your properties here. See "src/modules/template/" for an extensively documented example.
m_save = m_properties->addProperty( "Save result", "If true the transformed fibers are saved to a file", false );
m_savePath = m_properties->addProperty( "Save path", "Where to save the result", boost::filesystem::path( "/no/such/file" ) );
m_run = m_properties->addProperty( "Run", "Do the transformation", WPVBaseTypes::PV_TRIGGER_READY, m_recompute );
m_run->get( true ); // reset so no initial run occurs
m_savePath->addConstraint( PC_NOTEMPTY );
}
void WMFiberTransform::moduleMain()
{
// Put the code for your module's main functionality here.
// See "src/modules/template/" for an extensively documented example.
// When conditions are firing while wait() is not reached: wait terminates
// and behaves as if the appropriate conditions have had fired. But it is
// not detectable how many times a condition has fired.
m_moduleState.setResetable();
m_moduleState.add( m_fiberInput->getDataChangedCondition() );
m_moduleState.add( m_recompute );
// set the transformation matrix and vector
m_transformationMatrix( 0, 0 ) = 0.0;
m_transformationMatrix( 0, 1 ) = -1.0;
m_transformationMatrix( 0, 2 ) = 0.0;
m_transformationMatrix( 1, 0 ) = 1.0;
m_transformationMatrix( 1, 1 ) = 0.0;
m_transformationMatrix( 1, 2 ) = 0.0;
m_transformationMatrix( 2, 0 ) = 0.0;
m_transformationMatrix( 2, 1 ) = 0.0;
m_transformationMatrix( 2, 2 ) = 1.0;
m_transformationVector[0] = 85.0;
m_transformationVector[1] = -80.0;
m_transformationVector[2] = -50.0;
ready();
while ( !m_shutdownFlag() ) // loop until the module container requests the module to quit
{
if ( !m_fiberInput->getData().get() ) // ok, the output has not yet sent data
{
m_moduleState.wait();
continue;
}
if( m_rawDataset != m_fiberInput->getData() ) // in case data has changed
{
m_rawDataset = m_fiberInput->getData();
WAssert( m_rawDataset, "Couldn't load dataset" );
}
WAssert( m_savePath, "No save path property" );
if( m_savePath->get().string() == "/no/such/file" )
{
m_savePath->set( saveFileName( m_rawDataset->getFileName() ) );
}
if( m_run->get( true ) == WPVBaseTypes::PV_TRIGGER_TRIGGERED )
{
update();
m_run->set( WPVBaseTypes::PV_TRIGGER_READY, false );
}
m_moduleState.wait();
}
}
void WMFiberTransform::update()
{
// get parameter from GUI (properties)
bool save = m_save->get();
boost::filesystem::path savePath = m_savePath->get();
boost::shared_ptr< WProgress > progress( new WProgress( "Transforming", 4 + save ) );
m_progress->addSubProgress( progress );
infoLog() << "Start: WDataSetFibers => WDataSetFiberVector";
boost::shared_ptr< WDataSetFiberVector > dataset( new WDataSetFiberVector( m_rawDataset ) );
infoLog() << "Stop: WDataSetFibers => WDataSetFiberVector";
++*progress;
//transform
for( std::size_t fiberID = 0; fiberID < dataset->size(); ++fiberID )
{
wmath::WFiber& fiber = (*dataset)[fiberID];
for( std::size_t positionID = 0; positionID < fiber.size(); ++positionID )
{
fiber[positionID] = m_transformationMatrix * fiber[positionID] + m_transformationVector;
}
}
++*progress;
infoLog() << "Start: WDataSetFibers <= WDataSetFiberVector";
m_output->updateData( dataset->toWDataSetFibers() );
infoLog() << "Stop: WDataSetFibers <= WDataSetFiberVector";
++*progress;
if( save )
{
WWriterFiberVTK w( savePath, true );
w.writeFibs( dataset );
++*progress;
}
progress->finish();
}
boost::filesystem::path WMFiberTransform::saveFileName( std::string dataFileName ) const
{
boost::filesystem::path fibFileName( dataFileName );
return fibFileName.replace_extension( ".transformed.fib" );
}
//---------------------------------------------------------------------------
//
// 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 WMFIBERTRANSFORM_H
#define WMFIBERTRANSFORM_H
#include <string>
#include <boost/filesystem/path.hpp>
#include <boost/shared_ptr.hpp>
#include "../../common/WCondition.h"
#include "../../common/WPropertyTypes.h"
#include "../../common/math/WMatrix.h"
#include "../../common/math/WVector3D.h"
#include "../../dataHandler/WDataSetFiberVector.h"
#include "../../dataHandler/WDataSetFibers.h"
#include "../../kernel/WModule.h"
#include "../../kernel/WModuleInputData.h"
#include "../../kernel/WModuleOutputData.h"
/**
* Transforms a fiber dataset
* \ingroup modules
*/
class WMFiberTransform : public WModule
{
public:
/**
* Constructor
*/
WMFiberTransform();
/**
* 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;
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:
boost::shared_ptr< WModuleInputData< WDataSetFibers > > m_fiberInput; //!< Input connector for a fiber dataset.
boost::shared_ptr< WDataSetFibers > m_rawDataset; //!< Pointer to the fiber data set in WDataSetFibers format
boost::shared_ptr< WModuleOutputData< WDataSetFibers > > m_output; //!< Output connector for the culled fibers
boost::shared_ptr< WCondition > m_recompute; //!< A condition which indicates complete recomputation
WPropBool m_save; //!< If true, transformed fibers are saved to a file
WPropFilename m_savePath; //!< Path where transformed fibers should be stored
WPropTrigger m_run; //!< Indicates if the algorithm should start
wmath::WMatrix< double > m_transformationMatrix; //!< matrix which is multiplied with each point to linear transform it
wmath::WVector3D m_transformationVector; //!< vector which is added to each point (after multiplication with the matrix) to translate it
/**
* ReTransforms the scene.
*/
void update();
/**
* Generates the file name for saving the transformed fibers.
*
* \param dataFileName The file name from which the data is loaded so only the extension will change
* \return Path in which to store the transformed fibers.
*/
boost::filesystem::path saveFileName( std::string dataFileName ) const;
};
inline const std::string WMFiberTransform::getName() const
{
// Specify your module name here. This name must be UNIQUE!
return std::string( "Fiber Transform" );
}
inline const std::string WMFiberTransform::getDescription() const
{
// Specify your module description here. Be detailed. This text is read by the user.
// See "src/modules/template/" for an extensively documented example.
return std::string( "Transforms a fiber dataset" );
}
#endif // WMFIBERTRANSFORM_H
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