Commit 44dfd397 authored by Sebastian Eichelbaum's avatar Sebastian Eichelbaum
Browse files

[ADD] added module to normalize vectors and module to merge scalarfields to vectors

parent 0a605c92
......@@ -476,6 +476,15 @@ public:
*/
WGridTransformOrthoTemplate< T > const getTransform() const;
/**
* Compares two grids. Matches the transform and x,y,z resolution.
*
* \param other the one to compare against
*
* \return true if transform and resolution matches
*/
bool operator==( const WGridRegular3DTemplate< T >& other ) const;
protected:
private:
/**
......@@ -1196,6 +1205,15 @@ void WGridRegular3DTemplate< T >::initInformationProperties()
static_cast< double >( getOffsetZ() ) );
}
template< typename T >
bool WGridRegular3DTemplate< T >::operator==( const WGridRegular3DTemplate< T >& other ) const
{
return ( getNbCoordsX() == other.getNbCoordsX() ) &&
( getNbCoordsY() == other.getNbCoordsY() ) &&
( getNbCoordsZ() == other.getNbCoordsZ() ) &&
( m_transform == other.m_transform );
}
// +----------------------+
// | non-member functions |
// +----------------------+
......
......@@ -29,8 +29,6 @@
#include "../common/math/WMatrix.h"
#include "../common/math/linearAlgebra/WLinearAlgebra.h"
/**
* Implements an orthogonal grid transformation.
*
......@@ -232,6 +230,15 @@ public:
template< typename VecType >
void scale( VecType const& scale );
/**
* Compares two grid transforms..
*
* \param other the one to compare against
*
* \return true if transform matches
*/
bool operator==( const WGridTransformOrthoTemplate< T >& other ) const;
private:
/**
* This is a helper function which copies the parameter of another instance to its own.
......@@ -523,4 +530,14 @@ void WGridTransformOrthoTemplate< T >::copyFrom( WGridTransformOrthoTemplate< In
this->m_origin = static_cast< Vector3Type >( input.m_origin );
}
template< typename T >
bool WGridTransformOrthoTemplate< T >::operator==( const WGridTransformOrthoTemplate< T >& other ) const
{
return ( m_unitDirectionX == other.m_unitDirectionX ) &&
( m_unitDirectionY == other.m_unitDirectionY ) &&
( m_unitDirectionZ == other.m_unitDirectionZ ) &&
( m_scaling == other.m_scaling ) &&
( m_origin == other.m_origin );
}
#endif // WGRIDTRANSFORMORTHO_H
......@@ -162,7 +162,7 @@ void WMImageSpaceLIC::properties()
m_numIters = m_advancedLicGroup->addProperty( "Number of Iterations", "How much iterations along a streamline should be done per frame.",
30 );
m_numIters->setMin( 1 );
m_numIters->setMax( 100 );
m_numIters->setMax( 1000 );
// call WModule's initialization
WModule::properties();
......
......@@ -158,7 +158,7 @@ void main()
float dotS = dot( v_normal, vec.xyz );
vec2 dotScaled = ( 1.0 + sign( dotS ) ) * scaleMaxToOne( vecProjected ).xy;
// MPI Paper Hack;
// dotScaled = 40.0*vecProjected.xy;
// dotScaled = 90.0 * vecProjected.xy;
gl_FragData[0] = vec4( vec2( 0.5 ) + ( 0.5 * dotScaled ), light, noise3D );
// MPI PAper Hack:
......
//---------------------------------------------------------------------------
//
// 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 <vector>
#include <string>
#include "core/kernel/WKernel.h"
#include "core/common/WPropertyHelper.h"
#include "core/dataHandler/WDataHandler.h"
#include "WMMergeComponentsToVector.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( WMMergeComponentsToVector )
WMMergeComponentsToVector::WMMergeComponentsToVector():
WModule()
{
}
WMMergeComponentsToVector::~WMMergeComponentsToVector()
{
// Cleanup!
}
boost::shared_ptr< WModule > WMMergeComponentsToVector::factory() const
{
return boost::shared_ptr< WModule >( new WMMergeComponentsToVector() );
}
const std::string WMMergeComponentsToVector::getName() const
{
return "Merge Components To Vector";
}
const std::string WMMergeComponentsToVector::getDescription() const
{
return "Merge components to vector field.";
}
void WMMergeComponentsToVector::connectors()
{
// the dataset to process. Only accept scalar data.
m_scalarInX = WModuleInputData< WDataSetScalar >::createAndAdd( shared_from_this(), "X", "The X component field."
"Needs to be in the same grid as the others." );
m_scalarInY = WModuleInputData< WDataSetScalar >::createAndAdd( shared_from_this(), "Y", "The Y component field."
"Needs to be in the same grid as the others." );
m_scalarInZ = WModuleInputData< WDataSetScalar >::createAndAdd( shared_from_this(), "Z", "The Z component field."
"Needs to be in the same grid as the others." );
// output vector data
m_vectorOut = WModuleOutputData< WDataSetVector >::createAndAdd( shared_from_this(), "merged", "The vector dataset" );
// call WModule's initialization
WModule::connectors();
}
void WMMergeComponentsToVector::properties()
{
m_propCondition = boost::shared_ptr< WCondition >( new WCondition() );
// call WModule's initialization
WModule::properties();
}
void WMMergeComponentsToVector::moduleMain()
{
// get notified about data changes
m_moduleState.setResetable( true, true );
m_moduleState.add( m_scalarInX->getDataChangedCondition() );
m_moduleState.add( m_scalarInY->getDataChangedCondition() );
m_moduleState.add( m_scalarInZ->getDataChangedCondition() );
// 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();
// 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_scalarInX->handledUpdate() ||
m_scalarInY->handledUpdate() ||
m_scalarInZ->handledUpdate();
boost::shared_ptr< WDataSetScalar > dataSetX = m_scalarInX->getData();
boost::shared_ptr< WDataSetScalar > dataSetY = m_scalarInY->getData();
boost::shared_ptr< WDataSetScalar > dataSetZ = m_scalarInZ->getData();
bool dataValid = ( dataSetX && dataSetY && dataSetZ );
// reset output if input was reset/disconnected
if( !dataValid )
{
debugLog() << "Resetting output.";
m_vectorOut->reset();
continue;
}
if( dataValid && !dataUpdated )
{
continue;
}
// loop through each voxel
boost::shared_ptr< WGridRegular3D > gridX = boost::shared_dynamic_cast< WGridRegular3D >( dataSetX->getGrid() );
boost::shared_ptr< WGridRegular3D > gridY = boost::shared_dynamic_cast< WGridRegular3D >( dataSetY->getGrid() );
boost::shared_ptr< WGridRegular3D > gridZ = boost::shared_dynamic_cast< WGridRegular3D >( dataSetZ->getGrid() );
if( !( gridX && gridY && gridZ ) )
{
errorLog() << "Only regular 3D grids allowed.";
continue;
}
// ensure the grids are the same
if( !( ( *gridX ) == ( *gridY ) ) || !( ( *gridX ) == ( *gridZ ) ) )
{
errorLog() << "Grids do not match.";
continue;
}
// prepare progress indicators
boost::shared_ptr< WProgress > progress = boost::shared_ptr< WProgress >( new WProgress( "Processing", dataSetX->getValueSet()->rawSize() ) );
m_progress->addSubProgress( progress );
// FIXME: this should be done using visitors, making it data type invariant. For now, using doubles all the time is enough
if( !( ( dataSetX->getValueSet()->rawSize() == dataSetY->getValueSet()->rawSize() ) &&
( dataSetX->getValueSet()->rawSize() == dataSetZ->getValueSet()->rawSize() ) ) )
{
errorLog() << "Value set sizes do not match.";
continue;
}
// create target valueset
boost::shared_ptr< std::vector< double > > data( new std::vector< double >() );
data->reserve( dataSetX->getValueSet()->rawSize() * 3 );
for( size_t i = 0; i < dataSetX->getValueSet()->rawSize(); ++i )
{
double x = dataSetX->getValueSet()->getScalarDouble( i );
double y = dataSetY->getValueSet()->getScalarDouble( i );
double z = dataSetZ->getValueSet()->getScalarDouble( i );
data->push_back( x );
data->push_back( y );
data->push_back( z );
++( *progress );
}
// create valueset, dataset and update
boost::shared_ptr< WValueSetBase > vs( new WValueSet< double >( 1, 3, data, W_DT_DOUBLE ) );
WDataSetVector::SPtr ds( new WDataSetVector( vs, gridX ) );
m_vectorOut->updateData( ds );
// work done
progress->finish();
m_progress->removeSubProgress( progress );
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 WMMERGECOMPONENTSTOVECTOR_H
#define WMMERGECOMPONENTSTOVECTOR_H
#include <string>
#include "core/dataHandler/WDataSetScalar.h"
#include "core/dataHandler/WDataSetVector.h"
#include "core/kernel/WModule.h"
#include "core/kernel/WModuleInputData.h"
#include "core/kernel/WModuleOutputData.h"
/**
* This modules takes several scalar inputs and merges them to a vector dataset
*
* \ingroup modules
*/
class WMMergeComponentsToVector: public WModule
{
public:
/**
* Default constructor.
*/
WMMergeComponentsToVector();
/**
* Destructor.
*/
virtual ~WMMergeComponentsToVector();
/**
* Gives back the name of this module.
* \return the module's name.
*/
virtual const std::string getName() const;
/**
* Provide description.
*
* \return the description
*/
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 connector used to get datasets from other modules. The connection management between connectors must not be handled by the module.
*/
boost::shared_ptr< WModuleInputData< WDataSetScalar > > m_scalarInX;
/**
* An input connector used to get datasets from other modules. The connection management between connectors must not be handled by the module.
*/
boost::shared_ptr< WModuleInputData< WDataSetScalar > > m_scalarInY;
/**
* An input connector used to get datasets from other modules. The connection management between connectors must not be handled by the module.
*/
boost::shared_ptr< WModuleInputData< WDataSetScalar > > m_scalarInZ;
/**
* The output connector used to provide the calculated data to other modules.
*/
boost::shared_ptr< WModuleOutputData< WDataSetVector > > m_vectorOut;
/**
* A condition used to notify about changes in several properties.
*/
boost::shared_ptr< WCondition > m_propCondition;
};
#endif // WMMERGECOMPONENTSTOVECTOR_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.
// This defines some properties of the module "Template". This must
// match the name specified in WMTemplate::getName().
"Merge Components To Vector"
{
// 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 allows you to combine several given scalar fields to one vector field.";
// 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";
};
};
......@@ -21,6 +21,7 @@ ADD_MODULE( functionalMRIViewer )
ADD_MODULE( HARDIToSphericalHarmonics )
ADD_MODULE( histogramView )
ADD_MODULE( imageExtractor )
ADD_MODULE( mergeComponentsToVector )
ADD_MODULE( paintTexture )
ADD_MODULE( pointRenderer )
ADD_MODULE( probTractDisplay )
......@@ -29,6 +30,7 @@ ADD_MODULE( splineSurface )
ADD_MODULE( surfaceIllustrator )
ADD_MODULE( surfaceParameterAnimator )
ADD_MODULE( vectorAlign )
ADD_MODULE( vectorNormalize )
ADD_MODULE( webglSupport )
IF( Teem_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 <stdint.h>
#include <cmath>
#include <fstream>
#include <iostream>
#include <string>
#include <vector>
#include <boost/variant.hpp>
#include "core/common/math/linearAlgebra/WLinearAlgebra.h"
#include "core/common/WAssert.h"
#include "core/common/WProgress.h"
#include "core/common/WStringUtils.h"
#include "core/common/WTypeTraits.h"
#include "core/common/exceptions/WTypeMismatch.h"
#include "core/dataHandler/WGridRegular3D.h"
#include "core/dataHandler/WDataHandlerEnums.h"
#include "core/dataHandler/WDataHandler.h"
#include "core/dataHandler/exceptions/WDHValueSetMismatch.h"
#include "core/kernel/WKernel.h"
#include "WMVectorNormalize.h"
// This line is needed by the module loader to actually find your module.
W_LOADABLE_MODULE( WMVectorNormalize )
WMVectorNormalize::WMVectorNormalize() :
WModule()
{
// initialize
}
WMVectorNormalize::~WMVectorNormalize()
{
// cleanup
removeConnectors();
}
boost::shared_ptr< WModule > WMVectorNormalize::factory() const
{
return boost::shared_ptr< WModule >( new WMVectorNormalize() );
}
const std::string WMVectorNormalize::getName() const
{
return "Vector Normalize";
}
const std::string WMVectorNormalize::getDescription() const
{
return "Normalize a vector field.";
}
void WMVectorNormalize::connectors()
{
m_inputA = WModuleInputData< WDataSetVector >::createAndAdd( shared_from_this(), "input", "Input vectors." );
m_output = WModuleOutputData< WDataSetVector >::createAndAdd( shared_from_this(), "normalized", "Normalized input." );
// call WModules initialization
WModule::connectors();
}
void WMVectorNormalize::properties()
{
m_propCondition = boost::shared_ptr< WCondition >( new WCondition() );
WModule::properties();
}
/**
* Visitor for discriminating the type of the first valueset.
*/
class VisitorVSetA: public boost::static_visitor< boost::shared_ptr< WValueSetBase > >
{
public:
/**
* Create visitor instance.
*/
VisitorVSetA(): boost::static_visitor< result_type >()
{
}
/**
* Called by boost::varying during static visiting.
*
* \tparam T the real integral type of the first value set.
* \param vsetA the first valueset currently visited.
*
* \return the result from the operation
*/