Commit c38ae50c authored by Stefan Philips's avatar Stefan Philips
Browse files

[ADD] Data set for symmetric spherical harmonics

parent a33f3b28
//---------------------------------------------------------------------------
//
// 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 <string>
#include <vector>
#include "../common/WAssert.h"
#include "WDataSetSingle.h"
#include "WDataSetSphericalHarmonics.h"
// prototype instance as singleton
boost::shared_ptr< WPrototyped > WDataSetSphericalHarmonics::m_prototype = boost::shared_ptr< WPrototyped >();
WDataSetSphericalHarmonics::WDataSetSphericalHarmonics( boost::shared_ptr< WValueSetBase > newValueSet,
boost::shared_ptr< WGrid > newGrid ) :
WDataSetSingle( newValueSet, newGrid )
{
m_valueSet = boost::shared_dynamic_cast< WValueSet<double> >( newValueSet );
WAssert( newValueSet, "No value set given." );
WAssert( newGrid, "No grid given." );
WAssert( m_valueSet, "No WValueSet<double given." );
}
WDataSetSphericalHarmonics::WDataSetSphericalHarmonics()
: WDataSetSingle()
{
}
WDataSetSphericalHarmonics::~WDataSetSphericalHarmonics()
{
}
boost::shared_ptr< WPrototyped > WDataSetSphericalHarmonics::getPrototype()
{
if ( !m_prototype )
{
m_prototype = boost::shared_ptr< WPrototyped >( new WDataSetSphericalHarmonics() );
}
return m_prototype;
}
wmath::WSymmetricSphericalHarmonic WDataSetSphericalHarmonics::interpolate( const wmath::WPosition& pos, bool* success ) const
{
boost::shared_ptr< WGridRegular3D > grid = boost::shared_dynamic_cast< WGridRegular3D >( m_grid );
*success = grid->encloses( pos );
if( !*success )
{
return wmath::WSymmetricSphericalHarmonic();
}
// ids of vertices for interpolation
std::vector< size_t > vertexIds = grid->getCellVertexIds( grid->getCellId( pos ) );
wmath::WPosition localPos = pos - grid->getPosition( vertexIds[0] );
double lambdaX = localPos[0] / grid->getOffsetX();
double lambdaY = localPos[1] / grid->getOffsetY();
double lambdaZ = localPos[2] / grid->getOffsetZ();
std::vector< double > h( 8 );
// lZ lY
// | /
// | 6___/_7
// |/: /|
// 4_:___5 |
// | :...|.|
// |.2 | 3
// |_____|/ ____lX
// 0 1
h[0] = ( 1 - lambdaX ) * ( 1 - lambdaY ) * ( 1 - lambdaZ );
h[1] = ( lambdaX ) * ( 1 - lambdaY ) * ( 1 - lambdaZ );
h[2] = ( 1 - lambdaX ) * ( lambdaY ) * ( 1 - lambdaZ );
h[3] = ( lambdaX ) * ( lambdaY ) * ( 1 - lambdaZ );
h[4] = ( 1 - lambdaX ) * ( 1 - lambdaY ) * ( lambdaZ );
h[5] = ( lambdaX ) * ( 1 - lambdaY ) * ( lambdaZ );
h[6] = ( 1 - lambdaX ) * ( lambdaY ) * ( lambdaZ );
h[7] = ( lambdaX ) * ( lambdaY ) * ( lambdaZ );
// take
wmath::WValue< double > interpolatedCoefficients( m_valueSet->dimension() );
for( size_t i = 0; i < 8; ++i )
{
interpolatedCoefficients += h[i] * m_valueSet->getWValue( vertexIds[i] );
}
*success = true;
return wmath::WSymmetricSphericalHarmonic( interpolatedCoefficients );
}
wmath::WSymmetricSphericalHarmonic WDataSetSphericalHarmonics::getSphericalHarmonicAt( size_t index ) const
{
if ( index < m_valueSet->size() ) return wmath::WSymmetricSphericalHarmonic( m_valueSet->getWValue( index ) );
return wmath::WSymmetricSphericalHarmonic();
}
const std::string WDataSetSphericalHarmonics::getName() const
{
return "WDataSetSphericalHarmonics";
}
const std::string WDataSetSphericalHarmonics::getDescription() const
{
return "Contains factors for spherical harmonics.";
}
//---------------------------------------------------------------------------
//
// 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 WDATASETSPHERICALHARMONICS_H
#define WDATASETSPHERICALHARMONICS_H
#include <string>
#include <vector>
#include "../common/math/WSymmetricSphericalHarmonic.h"
#include "WValueSet.h"
#include "WDataSetSingle.h"
/**
* This data set type contains spherical harmonic coefficients as values. The index scheme is like in the Descoteaux paper "Regularized, Fast, and Robust Analytical Q-Ball Imaging".
* \ingroup dataHandler
*/
class WDataSetSphericalHarmonics : public WDataSetSingle
{
public:
/**
* Constructs an instance out of an appropriate value set and a grid.
*
* \param newValueSet the value set with the spherical harmonics coefficients to use
* \param newGrid the grid which maps world space to the value set
*/
WDataSetSphericalHarmonics( boost::shared_ptr< WValueSetBase > newValueSet,
boost::shared_ptr< WGrid > newGrid );
/**
* Construct an empty and unusable instance. This is needed for the prototype mechanism.
*/
WDataSetSphericalHarmonics();
/**
* Destroys this DataSet instance
*/
virtual ~WDataSetSphericalHarmonics();
/**
* Returns a prototype instantiated with the true type of the deriving class.
*
* \return the prototype.
*/
static boost::shared_ptr< WPrototyped > getPrototype();
/**
* Interpolates the field of spherical harmonics at the given position
*
* \param pos position to interpolate
* \param success if the position was inside the grid
*
* \return Interpolated spherical harmonic.
*/
wmath::WSymmetricSphericalHarmonic interpolate( const wmath::WPosition &pos, bool *success ) const;
/**
* Get the vector on the given position in value set.
* \note currently only implmented for WVector3D
*
* \param index the position where to get the vector from
*
* \return the vector
*/
wmath::WSymmetricSphericalHarmonic getSphericalHarmonicAt( size_t index ) const;
/**
* Gets the name of this prototype.
*
* \return the name.
*/
virtual const std::string getName() const;
/**
* Gets the description for this prototype.
*
* \return the description
*/
virtual const std::string getDescription() const;
protected:
/**
* The prototype as singleton.
*/
static boost::shared_ptr< WPrototyped > m_prototype;
private:
boost::shared_ptr< WValueSet<double> > m_valueSet;
};
#endif // WDATASETSPHERICALHARMONICS_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