Commit 67eadc62 authored by Sebastian Eichelbaum's avatar Sebastian Eichelbaum
Browse files

[CHANGE] - Gauss Module now also supports datasets with other dimensions than 1 and order 0

parent 8532697d
......@@ -95,7 +95,6 @@ public:
*/
virtual T getScalar( size_t i ) const
{
assert( m_order == 0 && m_dimension == 1 );
return m_data[i];
}
......
......@@ -26,6 +26,7 @@
#define WVALUESETBASE_H
#include <cstddef>
#include <cmath>
#include "WDataHandlerEnums.h"
/**
......@@ -75,6 +76,16 @@ public:
return m_order;
}
/**
* Returns the number of elements of type T per value.
* \note this is dimension to the power of order.
* \return number of elements per value
*/
virtual size_t elementsPerValue() const
{
return std::pow( m_dimension, m_order );
}
/**
* \return Dimension of the values in this ValueSet
*/
......
......@@ -74,10 +74,9 @@ const std::string WMGaussFiltering::getDescription() const
return "Runs a discretized Gauss filter as mask over a simple scalar field.";
}
size_t getId( size_t xDim, size_t yDim, size_t /*zDim*/, size_t x, size_t y,
size_t z )
size_t getId( size_t xDim, size_t yDim, size_t /*zDim*/, size_t x, size_t y, size_t z, size_t offset = 0, size_t elements = 1 )
{
return z * xDim * yDim + y * xDim + x;
return offset + ( elements * ( z * xDim * yDim + y * xDim + x ) );
}
double mask( size_t i, size_t j, size_t k )
......@@ -94,7 +93,7 @@ double mask( size_t i, size_t j, size_t k )
template<typename T> double WMGaussFiltering::filterAtPosition(
boost::shared_ptr<WValueSet<T> > vals, size_t nX, size_t nY, size_t nZ,
size_t x, size_t y, size_t z )
size_t x, size_t y, size_t z, size_t offset )
{
double filtered = 0;
double maskSum = 0;
......@@ -105,8 +104,8 @@ template<typename T> double WMGaussFiltering::filterAtPosition(
{
for( size_t i = 0; i < filterSize; ++i )
{
filtered += mask( i, j, k ) * vals->getScalar( getId( nX, nY,
nZ, x - 1 + i, y - 1 + j, z - 1 + k ) );
filtered += mask( i, j, k ) * vals->getScalar(
getId( nX, nY, nZ, x - 1 + i, y - 1 + j, z - 1 + k, offset, vals->elementsPerValue() ) );
maskSum += mask( i, j, k );
}
}
......@@ -116,32 +115,6 @@ template<typename T> double WMGaussFiltering::filterAtPosition(
return filtered;
}
template< typename T >
boost::shared_ptr< WValueSet< double > > WMGaussFiltering::iterativeFilterField( boost::shared_ptr< WValueSet< T > > vals, unsigned int iterations )
{
// the grid used
boost::shared_ptr<WGridRegular3D> grid = boost::shared_dynamic_cast< WGridRegular3D >( m_dataSet->getGrid() );
assert( grid );
// use a custom progress combiner
boost::shared_ptr< WProgress > prog = boost::shared_ptr< WProgress >(
new WProgress( "Gauss Filter Iteration", iterations * grid->getNbCoordsZ() ) );
m_progress->addSubProgress( prog );
// iterate filter, apply at least once
boost::shared_ptr< WValueSet< double > > valueSet = boost::shared_ptr< WValueSet< double > >(
new WValueSet<double> ( 0, 1, filterField( vals, grid, prog ), W_DT_DOUBLE )
);
for ( unsigned int i = 1; i < iterations; ++i ) // this only runs if iter > 1
{
valueSet = boost::shared_ptr< WValueSet< double > >( new WValueSet<double> ( 0, 1, filterField( valueSet, grid, prog ), W_DT_DOUBLE ) );
}
prog->finish();
return valueSet;
}
template< typename T >
std::vector<double> WMGaussFiltering::filterField( boost::shared_ptr< WValueSet< T > > vals, boost::shared_ptr<WGridRegular3D> grid,
boost::shared_ptr< WProgress > prog )
......@@ -149,7 +122,8 @@ std::vector<double> WMGaussFiltering::filterField( boost::shared_ptr< WValueSet<
size_t nX = grid->getNbCoordsX();
size_t nY = grid->getNbCoordsY();
size_t nZ = grid->getNbCoordsZ();
std::vector<double> newVals( nX * nY * nZ, 0. );
std::vector<double> newVals( vals->elementsPerValue() * nX * nY * nZ, 0. );
for( size_t z = 1; z < nZ - 1; z++ )
{
......@@ -158,7 +132,10 @@ std::vector<double> WMGaussFiltering::filterField( boost::shared_ptr< WValueSet<
{
for( size_t x = 1; x < nX - 1; x++ )
{
newVals[getId( nX, nY, nZ, x, y, z )] = filterAtPosition( vals, nX, nY, nZ, x, y, z );
for ( size_t offset = 0; offset < vals->elementsPerValue(); ++offset )
{
newVals[getId( nX, nY, nZ, x, y, z, offset, vals->elementsPerValue() )] = filterAtPosition( vals, nX, nY, nZ, x, y, z, offset );
}
}
}
}
......@@ -166,6 +143,34 @@ std::vector<double> WMGaussFiltering::filterField( boost::shared_ptr< WValueSet<
return newVals;
}
template< typename T >
boost::shared_ptr< WValueSet< double > > WMGaussFiltering::iterativeFilterField( boost::shared_ptr< WValueSet< T > > vals, unsigned int iterations )
{
// the grid used
boost::shared_ptr<WGridRegular3D> grid = boost::shared_dynamic_cast< WGridRegular3D >( m_dataSet->getGrid() );
assert( grid );
// use a custom progress combiner
boost::shared_ptr< WProgress > prog = boost::shared_ptr< WProgress >(
new WProgress( "Gauss Filter Iteration", iterations * grid->getNbCoordsZ() ) );
m_progress->addSubProgress( prog );
// iterate filter, apply at least once
boost::shared_ptr< WValueSet< double > > valueSet = boost::shared_ptr< WValueSet< double > >(
new WValueSet<double> ( vals->order(), vals->dimension(), filterField( vals, grid, prog ), W_DT_DOUBLE )
);
for ( unsigned int i = 1; i < iterations; ++i ) // this only runs if iter > 1
{
valueSet = boost::shared_ptr< WValueSet< double > >(
new WValueSet<double> ( valueSet->order(), valueSet->dimension(), filterField( valueSet, grid, prog ), W_DT_DOUBLE )
);
}
prog->finish();
return valueSet;
}
void WMGaussFiltering::moduleMain()
{
// let the main loop awake if the data changes or the properties changed.
......
......@@ -127,9 +127,10 @@ private:
* \param x index for x direction
* \param y index for x direction
* \param z index for x direction
* \param offset the offset to add to the index (useful for addressing vector/tensor elements)
*/
template< typename T > double filterAtPosition( boost::shared_ptr< WValueSet< T > > vals,
size_t nX, size_t nY, size_t nZ, size_t x, size_t y, size_t z );
size_t nX, size_t nY, size_t nZ, size_t x, size_t y, size_t z, size_t offset );
/**
* Run the filter over the field.
......
......@@ -121,7 +121,7 @@ float pointDistance( vec3 p1, vec3 p2 )
*/
vec3 getDirection( vec3 point )
{
return abs( ( u_tex1Scale * texture3D( tex1, point ).rgb ) + vec3( u_tex1Min ) );
return normalize( abs( ( u_tex1Scale * texture3D( tex1, point ).rgb ) + vec3( u_tex1Min ) ) );
}
/**
......
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