Commit 4d765cce authored by Sebastian Eichelbaum's avatar Sebastian Eichelbaum
Browse files

[ADD] added index-based fiber filter. Nice utility to validate...

[ADD] added index-based fiber filter. Nice utility to validate fiber-processing algorithms and such.
parent 2ec0dd7f
//---------------------------------------------------------------------------
//
// 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 <vector>
#include <algorithm>
#include "core/kernel/WKernel.h"
#include "WMFiberFilterIndex.h"
// This line is needed by the module loader to actually find your module. You need to add this to your module too. Do NOT add a ";" here.
W_LOADABLE_MODULE( WMFiberFilterIndex )
WMFiberFilterIndex::WMFiberFilterIndex():
WModule()
{
// Init
}
WMFiberFilterIndex::~WMFiberFilterIndex()
{
// Cleanup!
}
boost::shared_ptr< WModule > WMFiberFilterIndex::factory() const
{
return boost::shared_ptr< WModule >( new WMFiberFilterIndex() );
}
const std::string WMFiberFilterIndex::getName() const
{
// Specify your module name here. This name must be UNIQUE!
return "Fiber Filter Index";
}
const std::string WMFiberFilterIndex::getDescription() const
{
// Specify your module description here. Be detailed. This text is read by the user.
return "This module provides fiber data filtered by fiber index.";
}
void WMFiberFilterIndex::connectors()
{
m_input = WModuleInputData< WDataSetFibers >::createAndAdd( shared_from_this(), "in", "The dataset to filter" );
m_output = WModuleOutputData < WDataSetFibers >::createAndAdd( shared_from_this(), "out", "The filtered dataset" );
// call WModule's initialization
WModule::connectors();
}
void WMFiberFilterIndex::properties()
{
m_propCondition = boost::shared_ptr< WCondition >( new WCondition() );
m_indexProp = m_properties->addProperty( "Index", "Select the fiber with this index.", 0, m_propCondition );
m_indexProp->setMin( 0 );
m_indexProp->setMax( 1 );
WModule::properties();
}
void WMFiberFilterIndex::moduleMain()
{
m_moduleState.setResetable( true, true );
m_moduleState.add( m_input->getDataChangedCondition() );
m_moduleState.add( m_propCondition );
// Signal ready state. Now your module can be connected by the container, which owns the module.
ready();
waitRestored();
// main loop
while( !m_shutdownFlag() )
{
m_moduleState.wait();
// woke up since the module is requested to finish
if( m_shutdownFlag() )
{
break;
}
// Remember the above criteria. We now need to check if the data is valid. After a connect-update, it might be NULL.
boost::shared_ptr< WDataSetFibers > dataSet = m_input->getData();
bool dataValid = ( dataSet );
bool dataChanged = dataSet != m_fibers;
// do something with the data
if( dataChanged )
{
m_fibers = dataSet;
if( dataValid )
{
// The data is valid and we received an update. The data is not NULL but may be the same as in previous loops.
debugLog() << "Data changed. Recalculating output.";
m_indexProp->setMax( m_fibers->size() - 1 );
updateOutput();
}
}
if( m_indexProp->changed( true ) )
{
updateOutput();
}
}
}
void WMFiberFilterIndex::updateOutput()
{
// target memory
boost::shared_ptr< std::vector< float > > vertices( new std::vector< float >() );
boost::shared_ptr< std::vector< size_t > > lineStartIndexes( new std::vector< size_t >() );
boost::shared_ptr< std::vector< size_t > > lineLengths( new std::vector< size_t >() );
boost::shared_ptr< std::vector< size_t > > verticesReverse( new std::vector< size_t >() );
boost::shared_ptr< WProgress > progress1( new WProgress( "Filtering" ) );
m_progress->addSubProgress( progress1 );
size_t idx = m_indexProp->get( true );
// Valid index?
if( idx >= m_fibers->size() )
{
errorLog() << "Index invalid: " << idx << " - data has only " << m_fibers->size() << " lines.";
m_output->reset();
}
// Get vertex data
size_t startIdx = 3 * m_fibers->getStartIndex( idx );
size_t len = m_fibers->getLengthOfLine( idx );
vertices->resize( len * 3 );
std::copy( m_fibers->getVertices()->begin() + startIdx, m_fibers->getVertices()->begin() + startIdx + 3 * len, vertices->begin() );
// As the fiber display has problems with data with less than 3 vertices -> ensure 3
if( len == 2 )
{
len = 3;
// Use the last vertex again -> visually not visible.
vertices->push_back( vertices->at( 3 ) );
vertices->push_back( vertices->at( 4 ) );
vertices->push_back( vertices->at( 5 ) );
}
// the remaining info is trivial
lineStartIndexes->push_back( 0 );
lineLengths->push_back( len );
verticesReverse->resize( len, 0 );
// Update output and finish
boost::shared_ptr< WDataSetFibers> newOutput( new WDataSetFibers( vertices, lineStartIndexes, lineLengths, verticesReverse,
m_fibers->getBoundingBox() ) );
m_output->updateData( newOutput );
progress1->finish();
}
//---------------------------------------------------------------------------
//
// 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 WMFIBERFILTERINDEX_H
#define WMFIBERFILTERINDEX_H
#include <string>
#include "core/dataHandler/WDataSetFibers.h"
#include "core/kernel/WFiberSelector.h"
#include "core/kernel/WModule.h"
#include "core/kernel/WModuleInputData.h"
#include "core/kernel/WModuleOutputData.h"
/**
* This module is intended to allow the user to filter a fiber dataset using the current ROI config
*
* \ingroup modules
*/
class WMFiberFilterIndex: public WModule
{
public:
/**
* Default constructor.
*/
WMFiberFilterIndex();
/**
* Destructor.
*/
virtual ~WMFiberFilterIndex();
/**
* 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:
/**
* An input for the fiber data.
*/
boost::shared_ptr< WModuleInputData< WDataSetFibers > > m_input;
/**
* The output connector for the filtered data.
*/
boost::shared_ptr< WModuleOutputData< WDataSetFibers > > m_output;
/**
* A condition used to notify about changes in several properties.
*/
boost::shared_ptr< WCondition > m_propCondition;
/**
* Trigger output update
*/
WPropInt m_indexProp;
/**
* Fiber data.
*/
WDataSetFibers::SPtr m_fibers;
/**
* Updates the output using the ROI configuration.
*/
void updateOutput();
};
#endif // WMFIBERFILTERINDEX_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/>.
//
//---------------------------------------------------------------------------
// Provide additional material and descriptions for your module. You can
// provide this for multiple modules if you like.
// NOTE: everything but the module name is optional, even if this makes no
// sense at all.
"Fiber Filter Index"
{
// Provide an icon. If the icon exists, it overrides the one provided by your
// getXPMIcon method. This path is relative to your module's resource directory.
icon="icon.png";
// Where to find the module?
website = "http://www.openwalnut.org";
// Provide a description, If you do so, this description overrides the one
// provided by your getDescription method.
// HINT: multi-line strings are not supported. Please provide long texts in
// one line.
description = "This module provides fiber data filtered by fiber index.";
// Provide a list of authors. These authors can have further information associated with them.
author = "OpenWalnut Project";
// Provide author information. Especially a contact address is very handy.
// This associates some URL and Mail contact info to "OpenWalnut Project".
"OpenWalnut Project"
{
url="http://www.openwalnut.org";
email="contact@openwalnut.org";
what="Design, Development and Bug fixing";
};
};
......@@ -14,6 +14,7 @@ ADD_MODULE( datasetProfile )
ADD_MODULE( deterministicFTMori )
ADD_MODULE( effectiveConnectivityCluster )
ADD_MODULE( eigenSystem )
ADD_MODULE( fiberFilterIndex )
ADD_MODULE( fiberFilterROI )
ADD_MODULE( fiberParameterColoring )
ADD_MODULE( fiberSelection )
......
......@@ -228,7 +228,7 @@ void WMReadSimpleTextLineData::load()
WDataSetFibers::LengthArray lengths( new WDataSetFibers::LengthArray::element_type() );
WDataSetFibers::IndexArray lineStartIndices( new WDataSetFibers::IndexArray::element_type() );
WDataSetFibers::IndexArray verticesReverse( new WDataSetFibers::IndexArray::element_type() );
WDataSetFibers::VertexParemeterArray attribs( new WDataSetFibers::VertexParemeterArray::element_type() );
// WDataSetFibers::VertexParemeterArray attribs( new WDataSetFibers::VertexParemeterArray::element_type() );
size_t currentStartIndex = 0;
......
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