Commit cd63ad29 authored by Sebastian Eichelbaum's avatar Sebastian Eichelbaum

[ADD] - added fiber creation module skel

parent 86f5f2c1
FILE( GLOB_RECURSE MODULES_SRC "*.cpp" "*.h" )
# Grab module name and setup target directories
GET_FILENAME_COMPONENT( MODULE_NAME ${CMAKE_CURRENT_SOURCE_DIR} NAME )
SET( MODULE_TARGET_DIR ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/modules/${MODULE_NAME} )
SET( CMAKE_LIBRARY_OUTPUT_DIRECTORY ${MODULE_TARGET_DIR} )
SET( CMAKE_RUNTIME_OUTPUT_DIRECTORY ${MODULE_TARGET_DIR} )
SET( MODULE_DIRNAME ${MODULE_NAME} )
SET( MODULE_NAME "${OWmodulesPrefix}_${MODULE_NAME}" ) # prefix all module names with "OWmodule_" to separate them from other libs
SET( ${MODULE_NAME}_COMBINER_SRC ${MODULES_SRC} )
SET( ${MODULE_NAME}_ALL_CPP ${MODULES_SRC} )
FILE( GLOB_RECURSE ${MODULE_NAME}_REMOVE_H "*.h" )
LIST( REMOVE_ITEM ${MODULE_NAME}_ALL_CPP ${${MODULE_NAME}_REMOVE_H} )
IF( EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/test/" )
FILE( GLOB_RECURSE ${MODULE_NAME}_REMOVE_TEST "test/*.cpp" "test/*.h" )
LIST( REMOVE_ITEM ${MODULE_NAME}_ALL_CPP ${${MODULE_NAME}_REMOVE_TEST} )
LIST( REMOVE_ITEM ${MODULE_NAME}_COMBINER_SRC ${${MODULE_NAME}_REMOVE_TEST} )
ENDIF( EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/test/" )
LIST( LENGTH ${MODULE_NAME}_ALL_CPP cpp_count )
IF( ${cpp_count} GREATER 3 )
IF( OW_BUILD_AS_ONE_BIG_FILE )
SET( UNITY_BUILD_FILE_NAME "${MODULE_NAME}UnityBuildFile.cpp" )
GENERATE_UNITY_BUILD_FILE( ${MODULE_NAME}_ALL_CPP )
ADD_LIBRARY( ${MODULE_NAME} SHARED ${UNITY_BUILD_FILE_NAME} ${${MODULE_NAME}_COMBINER_SRC} )
ENDIF( OW_BUILD_AS_ONE_BIG_FILE )
ENDIF( ${cpp_count} GREATER 3 )
IF( ( NOT OW_BUILD_AS_ONE_BIG_FILE ) OR NOT ( ${cpp_count} GREATER 3 ) )
ADD_LIBRARY( ${MODULE_NAME} SHARED ${${MODULE_NAME}_COMBINER_SRC} )
ENDIF( ( NOT OW_BUILD_AS_ONE_BIG_FILE ) OR NOT ( ${cpp_count} GREATER 3 ) )
# Build module lib
#ADD_LIBRARY( ${MODULE_NAME} SHARED ${MODULES_SRC} )
TARGET_LINK_LIBRARIES( ${MODULE_NAME} ${OWKernelName} )
IF(MSVC_IDE)
SET_TARGET_PROPERTIES( ${MODULE_NAME} PROPERTIES PREFIX "../")
ENDIF(MSVC_IDE)
# Copy local shaders to module target directory
IF( OW_COPY_SHADERS AND EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/shaders ) # copy shaders only if the user wants it
ADD_CUSTOM_TARGET( ${MODULE_NAME}_CopyShaders
COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_SOURCE_DIR}/shaders ${MODULE_TARGET_DIR}/shaders/
COMMENT "Copy shaders of ${MODULE_NAME}"
)
ADD_DEPENDENCIES( ${MODULE_NAME} ${MODULE_NAME}_CopyShaders )
ENDIF()
# Build unit tests
IF( OW_COMPILE_TESTS )
# This ensures that the test is copied to the module directory
SET( CMAKE_RUNTIME_OUTPUT_DIRECTORY ${MODULE_TARGET_DIR} )
CXXTEST_ADD_TESTS_FROM_LIST( "${MODULES_SRC}"
"${OWKernelName};${MODULE_NAME}"
)
# Copy fixtures if they exist
IF( EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/test/fixtures )
ADD_CUSTOM_TARGET( ${MODULE_NAME}_CopyFixtures
# as the "test" target runs in CMakes temporary build dir, the fixtures need to be placed there too.
COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_SOURCE_DIR}/test/fixtures ${CMAKE_BINARY_DIR}/modules/${MODULE_DIRNAME}/fixtures/
COMMENT "Copy fixtures of ${MODULE_NAME}"
)
ADD_DEPENDENCIES( ${MODULE_NAME} ${MODULE_NAME}_CopyFixtures )
ENDIF( EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/test/fixtures )
ENDIF( OW_COMPILE_TESTS )
//---------------------------------------------------------------------------
//
// 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 <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include "../../kernel/WKernel.h"
#include "../../common/WPropertyHelper.h"
#include "../../common/math/WMath.h"
#include "../../dataHandler/WDataHandler.h"
#include "../../dataHandler/WDataTexture3D.h"
#include "WMFiberCreator.h"
#include "WMFiberCreator.xpm"
// 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( WMFiberCreator )
WMFiberCreator::WMFiberCreator():
WModule()
{
}
WMFiberCreator::~WMFiberCreator()
{
// Cleanup!
}
boost::shared_ptr< WModule > WMFiberCreator::factory() const
{
return boost::shared_ptr< WModule >( new WMFiberCreator() );
}
const char** WMFiberCreator::getXPMIcon() const
{
return WMFiberCreator_xpm;
}
const std::string WMFiberCreator::getName() const
{
return "Fiber Creator";
}
const std::string WMFiberCreator::getDescription() const
{
return "This module can create fiber datasets using certain schemes. This can be useful to test your algorithms against special artificial "
"data that shows certain strengths or weaknesses of your module.";
}
void WMFiberCreator::connectors()
{
// the selected fibers go to this output
m_fiberOutput = WModuleOutputData< WDataSetFibers >::createAndAdd( shared_from_this(), "out", "The created fiber data." );
// call WModule's initialization
WModule::connectors();
}
void WMFiberCreator::properties()
{
m_propCondition = boost::shared_ptr< WCondition >( new WCondition() );
// call WModule's initialization
WModule::properties();
}
inline double getSegmentVector( size_t segment, size_t offset, boost::shared_ptr< std::vector< float > > verts, double* vec )
{
// get segment coordinates
double x = verts->at( ( 3 * segment ) + offset + 0 ) - verts->at( ( 3 * ( segment + 1 ) ) + offset + 0 );
double y = verts->at( ( 3 * segment ) + offset + 1 ) - verts->at( ( 3 * ( segment + 1 ) ) + offset + 1 );
double z = verts->at( ( 3 * segment ) + offset + 2 ) - verts->at( ( 3 * ( segment + 1 ) ) + offset + 2 );
// get length
double len = std::sqrt( x * x + y * y + z * z );
// create vector from this and the previous point
vec[0] = x / len;
vec[1] = y / len;
vec[2] = z / len;
return len;
}
void WMFiberCreator::moduleMain()
{
// get notified about data changes
m_moduleState.setResetable( true, true );
// Remember the condition provided to some properties in properties()? The condition can now be used with this condition set.
m_moduleState.add( m_propCondition );
ready();
/*
m_fibCurvatureColors = WDataSetFibers::ColorArray();
m_fibLengthColors = WDataSetFibers::ColorArray();
// main loop
while ( !m_shutdownFlag() )
{
debugLog() << "Waiting ...";
m_moduleState.wait();
// woke up since the module is requested to finish?
if ( m_shutdownFlag() )
{
break;
}
// To query whether an input was updated, simply ask the input:
bool dataUpdated = m_fiberInput->handledUpdate();
boost::shared_ptr< WDataSetFibers > dataSet = m_fiberInput->getData();
bool dataValid = ( dataSet );
bool propUpdated = m_baseColor->changed() || m_scaleColor->changed();
// reset everything if input was disconnected/invalid
if ( !dataValid )
{
debugLog() << "Resetting output.";
m_fiberOutput->reset();
continue;
}
if ( dataValid && !( dataUpdated || propUpdated ) )
{
continue;
}
// remove old colorings
dataSet->removeColorScheme( m_fibCurvatureColors ); // this can be safely used with NULL pointers
dataSet->removeColorScheme( m_fibLengthColors );
// get the fiber definitions
boost::shared_ptr< std::vector< size_t > > fibStart = dataSet->getLineStartIndexes();
boost::shared_ptr< std::vector< size_t > > fibLen = dataSet->getLineLengths();
boost::shared_ptr< std::vector< float > > fibVerts = dataSet->getVertices();
m_fibCurvatureColors = WDataSetFibers::ColorArray( new WDataSetFibers::ColorArray::element_type() );
m_fibLengthColors = WDataSetFibers::ColorArray( new WDataSetFibers::ColorArray::element_type() );
WDataSetFibers::ColorScheme::ColorMode colorMode = WDataSetFibers::ColorScheme::RGBA;
m_fibCurvatureColors->resize( colorMode * ( fibVerts->size() / 3 ), 0.0 ); // create an RGBA coloring
m_fibLengthColors->resize( colorMode * ( fibVerts->size() / 3 ), 0.0 ); // create an RGBA coloring
// progress indication
boost::shared_ptr< WProgress > progress1 = boost::shared_ptr< WProgress >( new WProgress( "Coloring fibers.",
fibStart->size() ) );
boost::shared_ptr< WProgress > progress2 = boost::shared_ptr< WProgress >( new WProgress( "Scaling Colors.",
fibStart->size() ) );
m_progress->addSubProgress( progress1 );
m_progress->addSubProgress( progress2 );
// for fastness:
WColor baseColor = m_baseColor->get( true );
double baseColorR = baseColor[0];
double baseColorG = baseColor[1];
double baseColorB = baseColor[2];
double baseColorA = baseColor[3];
WColor scaleColor = m_scaleColor->get( true );
double scaleColorR = scaleColor[0];
double scaleColorG = scaleColor[1];
double scaleColorB = scaleColor[2];
double scaleColorA = scaleColor[3];
// for each fiber:
debugLog() << "Iterating over all fibers.";
std::vector< double > maxSegLengths;
maxSegLengths.resize( fibStart->size(), 0.0 );
for( size_t fidx = 0; fidx < fibStart->size() ; ++fidx )
{
++*progress1;
// the start vertex index
size_t sidx = fibStart->at( fidx ) * 3;
size_t cidx = fibStart->at( fidx ) * colorMode;
// the length of the fiber, if a fiber is smaller than two segments, skip it ( it already is colored white by default )
size_t len = fibLen->at( fidx );
if ( len < 3 )
{
continue;
}
// get the first vector and second vertex
double prev[3];
// we do not need zero length segments
if ( getSegmentVector( 0, sidx, fibVerts, &prev[0] ) == 0.0 )
{
continue;
}
// walk along the fiber
double lenLast = 0.0;
double lenMax = 0.0;
for ( size_t k = 1; k < len - 1; ++k ) // len -1 because we interpret it as segments
{
// get the vector of this segment
double current[3];
// we do not need zero length segments
double segLen = getSegmentVector( k, sidx, fibVerts, &current[0] );
if ( segLen == 0.0 )
{
continue;
}
// how to calculate the curvature?
// -------------------------------
// Variant 1:
// calculate angle between both segments
// double dot = ( current[0] * prev[0] ) + ( current[1] * prev[1] ) + ( current[2] * prev[2] );
// dot = std::max( -1.0, std::min( dot, 1.0 ) ); // dot must not be larger than 1. Unfortunately it might get
// larger in the 10^-10th.
// get angle and curvature
// double angleRad = std::acos( dot );
// double curvature2 = 2.0 * angleRad / ( lenLast + segLen );
// Variant 2:
double x = ( 2.0 / ( lenLast + segLen ) ) * ( current[0] - prev[0] );
double y = ( 2.0 / ( lenLast + segLen ) ) * ( current[1] - prev[1] );
double z = ( 2.0 / ( lenLast + segLen ) ) * ( current[2] - prev[2] );
double curvature = std::sqrt( x*x + y*y + z*z );
( *m_fibCurvatureColors )[ ( colorMode * k ) + cidx + 0 ] = baseColorR + ( 1.5 * scaleColorR * curvature );
( *m_fibCurvatureColors )[ ( colorMode * k ) + cidx + 1 ] = baseColorG + ( 1.5 * scaleColorG * curvature );
( *m_fibCurvatureColors )[ ( colorMode * k ) + cidx + 2 ] = baseColorB + ( 1.5 * scaleColorB * curvature );
( *m_fibCurvatureColors )[ ( colorMode * k ) + cidx + 3 ] = baseColorA + ( 1.5 * scaleColorA * curvature );
( *m_fibLengthColors )[ ( colorMode * k ) + cidx + 0 ] = segLen;
( *m_fibLengthColors )[ ( colorMode * k ) + cidx + 1 ] = 0.0;
( *m_fibLengthColors )[ ( colorMode * k ) + cidx + 2 ] = 0.0;
( *m_fibLengthColors )[ ( colorMode * k ) + cidx + 3 ] = 1.0;
prev[0] = current[0];
prev[1] = current[1];
prev[2] = current[2];
lenLast = segLen;
lenMax = std::max( segLen, lenMax );
}
maxSegLengths[ fidx ] = lenMax;
}
progress1->finish();
// finally, apply the global scalings needed
debugLog() << "Iterating over all fibers for scaling per fiber.";
for( size_t fidx = 0; fidx < fibStart->size() ; ++fidx )
{
++*progress2;
// the start vertex index
size_t cidx = fibStart->at( fidx ) * colorMode;
size_t len = fibLen->at( fidx );
if ( len < 3 )
{
continue;
}
// walk along the fiber
for ( size_t k = 1; k < len - 1; ++k ) // len -1 because we interpret it as segments
{
double relSegLen = ( *m_fibLengthColors )[ ( colorMode * k ) + cidx + 0 ] / maxSegLengths[ fidx ];
( *m_fibLengthColors )[ ( colorMode * k ) + cidx + 0 ] = baseColorR + ( scaleColorR * relSegLen );
( *m_fibLengthColors )[ ( colorMode * k ) + cidx + 1 ] = baseColorG + ( scaleColorG * relSegLen );
( *m_fibLengthColors )[ ( colorMode * k ) + cidx + 2 ] = baseColorB + ( scaleColorB * relSegLen );
( *m_fibLengthColors )[ ( colorMode * k ) + cidx + 3 ] = baseColorA + ( scaleColorA * relSegLen );
}
}
progress2->finish();
// add the new scheme
dataSet->addColorScheme( m_fibCurvatureColors, "Curvature Coloring",
"The speed of changing angles between consecutive segments represents the color." );
dataSet->addColorScheme( m_fibLengthColors, "Segment Length Coloring",
"The length of a segment in relation to the longest segment in the fiber." );
// forward the data
m_fiberOutput->updateData( dataSet );
// remove the progress indicators
m_progress->removeSubProgress( progress1 );
m_progress->removeSubProgress( progress2 );
debugLog() << "Done";
}*/
}
//---------------------------------------------------------------------------
//
// 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 WMFIBERCREATOR_H
#define WMFIBERCREATOR_H
#include <string>
#include "../../dataHandler/WDataSetFibers.h"
#include "../../kernel/WModule.h"
#include "../../kernel/WModuleOutputData.h"
/**
* This module creates fiber datasets using some scheme, like spirals. This is very useful tool for papers where artificial data is needed
* sometimes to create images showing some certain strength or weakness.
*
* \ingroup modules
*/
class WMFiberCreator: public WModule
{
public:
/**
* Default constructor.
*/
WMFiberCreator();
/**
* Destructor.
*/
virtual ~WMFiberCreator();
/**
* 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.
*/
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();
private:
/**
* The output connector used to provide the calculated data to other modules.
*/
boost::shared_ptr< WModuleOutputData< WDataSetFibers > > m_fiberOutput;
/**
* A condition used to notify about changes in several properties.
*/
boost::shared_ptr< WCondition > m_propCondition;
};
#endif // WMFIBERCREATOR_H
/* XPM */
static const char * WMFiberCreator_xpm[] = {
"16 16 58 1",
" c None",
". c #8162D6",
"+ c #7568DD",
"@ c #6366D8",
"# c #8479E0",
"$ c #8699DF",
"% c #2227DB",
"& c #7C71D9",
"* c #6251D2",
"= c #6C69D7",
"- c #7673DD",
"; c #9089E1",
"> c #8B9ADF",
", c #22DB4E",
"' c #6597C1",
") c #698ECE",
"! c #6B71D1",
"~ c #828CBA",
"{ c #000000",
"] c #8795E4",
"^ c #8BA5C4",
"/ c #7CB0AF",
"( c #85BD95",
"_ c #6B96B4",
": c #6A8BBB",
"< c #6C9B9F",
"[ c #4A8984",
"} c #948EC5",
"| c #8BA7BA",
"1 c #6DC298",
"2 c #60C673",
"3 c #66CC6D",
"4 c #7CABBA",
"5 c #63AC9D",
"6 c #9FA3BF",
"7 c #6BBC8E",
"8 c #DB2222",
"9 c #62CC5F",
"0 c #6DC353",
"a c #71B792",
"b c #7DC669",
"c c #53BE78",
"d c #85AE81",
"e c #917CE0",
"f c #7BA364",
"g c #74BC56",
"h c #58C24C",
"i c #70C669",
"j c #83B282",
"k c #65A18E",
"l c #6FBD57",
"m c #69BD5E",
"n c #60B364",
"o c #53BF53",
"p c #6DC468",
"q c #6DAE8C",
"r c #6FAE9C",
"s c #81C869",
" ",
" ",
" ",
" .+@# ",
" $%&*=-;> ",
" ,'%)!~{]^/( ",
" _,:%<[{{}|123 ",
" 45,,%%{{678890 ",
" abc,d%{e888fgh ",
" ijk,,%{88lmnop ",
" %{qr ",
" s,,{ ",
" ",
" ",
" ",
" "};
......@@ -8,15 +8,16 @@ ADD_SUBDIRECTORY( clusterDisplayVoxels )
ADD_SUBDIRECTORY( clusterParamDisplay )
ADD_SUBDIRECTORY( clusterSlicer )
ADD_SUBDIRECTORY( contourTree )
ADD_SUBDIRECTORY( dataTypeConversion )
ADD_SUBDIRECTORY( datasetManipulator )
ADD_SUBDIRECTORY( datasetProfile )
ADD_SUBDIRECTORY( dataTypeConversion )
ADD_SUBDIRECTORY( deterministicFTMori )
ADD_SUBDIRECTORY( detTractClustering )
ADD_SUBDIRECTORY( detTractCulling )
ADD_SUBDIRECTORY( deterministicFTMori )
ADD_SUBDIRECTORY( directVolumeRendering )
ADD_SUBDIRECTORY( effectiveConnectivityCluster )
ADD_SUBDIRECTORY( eigenSystem )
ADD_SUBDIRECTORY( fiberCreator )
ADD_SUBDIRECTORY( fiberDisplaySimple )
ADD_SUBDIRECTORY( fiberParameterColoring )
ADD_SUBDIRECTORY( fiberResampling )
......
......@@ -163,6 +163,8 @@ void WMTemplate::connectors()
new WModuleInputData< WDataSetSingle >( shared_from_this(),
"in", "The dataset to display" )
);
// Alternative for lazy ones
// m_input = WModuleInputData< WDataSetSingle >::createAndAdd( shared_from_this(), "in", "The dataset to display" );
// This creates an input connector which can receive WDataSetSingle. It will never be able to connect to output connectors providing just a
// WDataSet (which is the father class of WDataSetSingle), but it will be able to be connected to an output connector with a type derived
......
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