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

[PATCH #40] New module: unifyEvecs. This realigns vectors, by mirroring them...

[PATCH #40] New module: unifyEvecs. This realigns vectors, by mirroring them (if neccessary) into the same halfspace.
parent fb0c7f71
......@@ -34,9 +34,10 @@ ADD_MODULE( probTractDisplay )
ADD_MODULE( scalarSegmentation )
ADD_MODULE( schmahmannPandyaSlices )
ADD_MODULE( splineSurface )
ADD_MODULE( surfaceIllustrator )
ADD_MODULE( surfaceParameterAnimator )
ADD_MODULE( unifyEvecs )
ADD_MODULE( webglSupport )
ADD_MODULE( surfaceIllustrator )
IF( Teem_FOUND )
ADD_MODULE( teemGlyphs ${Teem_LIBRARIES} )
......
//---------------------------------------------------------------------------
//
// 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 "core/dataHandler/WDataSetVector.h"
#include "core/kernel/WKernel.h"
#include "modules/emptyIcon.xpm" // Please put a real icon here.
#include "WMUnifyEvecs.h"
// This line is needed by the module loader to actually find your module. Do not remove. Do NOT add a ";" here.
W_LOADABLE_MODULE( WMUnifyEvecs )
WMUnifyEvecs::WMUnifyEvecs():
WModule()
{
}
WMUnifyEvecs::~WMUnifyEvecs()
{
}
boost::shared_ptr< WModule > WMUnifyEvecs::factory() const
{
return boost::shared_ptr< WModule >( new WMUnifyEvecs() );
}
const char** WMUnifyEvecs::getXPMIcon() const
{
return emptyIcon_xpm; // Please put a real icon here.
}
const std::string WMUnifyEvecs::getName() const
{
return "Unify Evecs";
}
const std::string WMUnifyEvecs::getDescription() const
{
return "This module may switch orientation of vectors, so they are aligned in some halfspace as best as possible.";
}
void WMUnifyEvecs::connectors()
{
m_vectorIC = WModuleInputData< WDataSetVector >::createAndAdd( shared_from_this(), "vectors", "Some vector dataset." );
m_vectorOC = WModuleOutputData< WDataSetVector >::createAndAdd( shared_from_this(), "alignedVectors",
"Dataset where vectors are aligned inside the halfspace" );
WModule::connectors();
}
void WMUnifyEvecs::properties()
{
WModule::properties();
}
void WMUnifyEvecs::requirements()
{
}
namespace
{
boost::shared_ptr< WDataSetVector > alignVectors( boost::shared_ptr< WDataSetVector > vectors )
{
size_t numVecs = vectors->getValueSet()->size();
std::vector< WVector3d > newData;
newData.reserve( numVecs );
for( size_t i = 0; i < numVecs; ++i )
{
newData.push_back( vectors->getVectorAt( i ) );
}
boost::shared_ptr< WGridRegular3D > grid = boost::shared_dynamic_cast< WGridRegular3D >( vectors->getGrid() );
if( !grid )
{
return vectors;
}
boost::shared_ptr< std::vector< double > > data( new std::vector< double > );
for( size_t i = 0; i < numVecs; ++i )
{
std::vector< size_t > neighbours = grid->getNeighbours( i );
for( size_t j = 0; j < neighbours.size(); ++j )
{
double sign = 1.0;
if( neighbours[j] > i ) // just to speed up and ensure that once vectors written to data will never be changed afterwards
{
if( dot( newData[i], newData[ neighbours[j] ] ) < 0.0 )
{
sign = -1.0;
}
newData[ neighbours[ j ] ] *= sign;
}
}
// newData[i] will never change from now on anymore
data->push_back( newData[i][0] );
data->push_back( newData[i][1] );
data->push_back( newData[i][2] );
}
boost::shared_ptr< WValueSet< double > > values( new WValueSet< double >( 1, 3, data, W_DT_DOUBLE ) );
return boost::shared_ptr< WDataSetVector >( new WDataSetVector( values, grid ) );
}
}
void WMUnifyEvecs::moduleMain()
{
// get notified about data changes
m_moduleState.setResetable( true, true );
m_moduleState.add( m_vectorIC->getDataChangedCondition() );
ready();
// main loop
while( !m_shutdownFlag() )
{
infoLog() << "Waiting ...";
m_moduleState.wait();
// woke up since the module is requested to finish?
if( m_shutdownFlag() )
{
break;
}
// save data behind connectors since it might change during processing
boost::shared_ptr< WDataSetVector > vectors = m_vectorIC->getData();
if( !vectors ) // if data valid
{
continue;
}
m_vectorOC->updateData( alignVectors( vectors ) );
}
}
//---------------------------------------------------------------------------
//
// 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 WMUNIFYEVECS_H
#define WMUNIFYEVECS_H
#include <string>
#include <osg/Geode>
#include "core/kernel/WModule.h"
#include "core/kernel/WModuleInputData.h"
#include "core/kernel/WModuleOutputData.h"
/**
* This module aligns diffusion directions so that they are inside of the same halfspace.
* This is done mainly for trilinear interpolation which would produce artifacts otherwise.
* \ingroup modules
*/
class WMUnifyEvecs: public WModule
{
public:
/**
*
*/
WMUnifyEvecs();
/**
*
*/
virtual ~WMUnifyEvecs();
/**
* 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();
/**
* Initialize requirements for this module.
*/
virtual void requirements();
private:
/**
* Input connector for the vector dataset.
*/
boost::shared_ptr< WModuleInputData< WDataSetVector > > m_vectorIC;
/**
* Output connector for the vector dataset.
*/
boost::shared_ptr< WModuleOutputData< WDataSetVector > > m_vectorOC;
};
#endif // WMUNIFYEVECS_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