Commit 9438255f authored by reichenbach's avatar reichenbach
Browse files

[CHANGE] grid-branch! removed transform base class and adjusted grid ctor calls

parent e1367d89
......@@ -80,7 +80,7 @@ double WDataSetScalar::interpolate( const wmath::WPosition& pos, bool* success )
boost::shared_ptr< WGridRegular3D > grid = boost::shared_dynamic_cast< WGridRegular3D >( m_grid );
WAssert( grid, "This data set has a grid whose type is not yet supported for interpolation." );
WAssert( grid->isNotRotatedOrSheared(), "Only feasible for grids that are only translated or scaled so far." );
WAssert( grid->isNotRotated(), "Only feasible for grids that are only translated or scaled so far." );
WAssert( ( m_valueSet->order() == 0 && m_valueSet->dimension() == 1 ),
"Only implemented for scalar values so far." );
......
......@@ -68,7 +68,7 @@ wmath::WVector3D WDataSetVector::interpolate( const wmath::WPosition& pos, bool
boost::shared_ptr< WGridRegular3D > grid = boost::shared_dynamic_cast< WGridRegular3D >( m_grid );
WAssert( grid, "This data set has a grid whose type is not yet supported for interpolation." );
WAssert( grid->isNotRotatedOrSheared(), "Only feasible for grids that are only translated or scaled so far." );
WAssert( grid->isNotRotated(), "Only feasible for grids that are only translated or scaled so far." );
WAssert( ( m_valueSet->order() == 1 && m_valueSet->dimension() == 3 ),
"Only implemented for 3D Vectors so far." );
......
......@@ -37,7 +37,7 @@ using wmath::WPosition;
using wmath::WMatrix;
WGridRegular3D::WGridRegular3D( unsigned int nbPosX, unsigned int nbPosY, unsigned int nbPosZ,
boost::shared_ptr< WGridTransform const > transform )
WGridTransformOrtho const transform )
: WGrid( nbPosX * nbPosY * nbPosZ ),
m_nbPosX( nbPosX ),
m_nbPosY( nbPosY ),
......@@ -55,12 +55,12 @@ WPosition WGridRegular3D::getPosition( unsigned int i ) const
WPosition WGridRegular3D::getPosition( unsigned int iX, unsigned int iY, unsigned int iZ ) const
{
wmath::WVector3D i( iX, iY, iZ );
return m_transform->positionToWorldSpace( i );
return m_transform.positionToWorldSpace( i );
}
wmath::WVector3D WGridRegular3D::worldCoordToTexCoord( wmath::WPosition point )
{
wmath::WVector3D r( m_transform->positionToGridSpace( point ) );
wmath::WVector3D r( m_transform.positionToGridSpace( point ) );
// Scale to [0,1]
r[0] = r[0] / m_nbPosX;
......@@ -124,7 +124,7 @@ void WGridRegular3D::initInformationProperties()
int WGridRegular3D::getXVoxelCoord( const wmath::WPosition& pos ) const
{
// the current get*Voxel stuff is too complicated anyway
wmath::WPosition v = m_transform->positionToGridSpace( pos );
wmath::WPosition v = m_transform.positionToGridSpace( pos );
// this part could be refactored into an inline function
v[ 2 ] = modf( v[ 0 ] + 0.5, &v[ 1 ] );
......@@ -134,7 +134,7 @@ int WGridRegular3D::getXVoxelCoord( const wmath::WPosition& pos ) const
int WGridRegular3D::getYVoxelCoord( const wmath::WPosition& pos ) const
{
wmath::WPosition v = m_transform->positionToGridSpace( pos );
wmath::WPosition v = m_transform.positionToGridSpace( pos );
v[ 0 ] = modf( v[ 1 ] + 0.5, &v[ 2 ] );
int i = static_cast< int >( v[ 1 ] >= 0.0 && v[ 1 ] < m_nbPosY - 1.0 );
......@@ -143,7 +143,7 @@ int WGridRegular3D::getYVoxelCoord( const wmath::WPosition& pos ) const
int WGridRegular3D::getZVoxelCoord( const wmath::WPosition& pos ) const
{
wmath::WPosition v = m_transform->positionToGridSpace( pos );
wmath::WPosition v = m_transform.positionToGridSpace( pos );
v[ 0 ] = modf( v[ 2 ] + 0.5, &v[ 1 ] );
int i = static_cast< int >( v[ 2 ] >= 0.0 && v[ 2 ] < m_nbPosZ - 1.0 );
......@@ -159,15 +159,14 @@ wmath::WValue< int > WGridRegular3D::getVoxelCoord( const wmath::WPosition& pos
return result;
}
bool WGridRegular3D::isNotRotatedOrSheared() const
bool WGridRegular3D::isNotRotated() const
{
// this could be changed to a bool function in the transform
return boost::shared_dynamic_cast< WGridTransformOrtho const >( m_transform ) != NULL;
return m_transform.isNotRotated();
}
size_t WGridRegular3D::getCellId( const wmath::WPosition& pos, bool* success ) const
{
WAssert( isNotRotatedOrSheared(), "Only feasible for grids that are only translated or scaled so far." );
WAssert( isNotRotated(), "Only feasible for grids that are only translated or scaled so far." );
wmath::WPosition posRelativeToOrigin = pos - getOrigin();
......@@ -513,7 +512,7 @@ std::vector< size_t > WGridRegular3D::getNeighbours9XZ( size_t id ) const
bool WGridRegular3D::encloses( wmath::WPosition const& pos ) const
{
wmath::WVector3D v = m_transform->positionToGridSpace( pos );
wmath::WVector3D v = m_transform.positionToGridSpace( pos );
if( v[ 0 ] < 0.0 || v[ 0 ] >= m_nbPosX - 1 )
{
......@@ -534,14 +533,14 @@ std::pair< wmath::WPosition, wmath::WPosition > WGridRegular3D::getBoundingBox()
{
// Get the transformed corner points of the regular grid
std::vector< wmath::WPosition > cornerPs;
cornerPs.push_back( m_transform->positionToWorldSpace( wmath::WPosition( 0.0, 0.0, 0.0 ) ) );
cornerPs.push_back( m_transform->positionToWorldSpace( wmath::WPosition( getNbCoordsX() - 1, 0.0, 0.0 ) ) );
cornerPs.push_back( m_transform->positionToWorldSpace( wmath::WPosition( 0.0, getNbCoordsY() - 1, 0.0 ) ) );
cornerPs.push_back( m_transform->positionToWorldSpace( wmath::WPosition( getNbCoordsX() - 1, getNbCoordsY() - 1, 0.0 ) ) );
cornerPs.push_back( m_transform->positionToWorldSpace( wmath::WPosition( 0.0, 0.0, getNbCoordsZ() - 1 ) ) );
cornerPs.push_back( m_transform->positionToWorldSpace( wmath::WPosition( getNbCoordsX() - 1, 0.0, getNbCoordsZ() - 1 ) ) );
cornerPs.push_back( m_transform->positionToWorldSpace( wmath::WPosition( 0.0, getNbCoordsY() - 1, getNbCoordsZ() - 1 ) ) );
cornerPs.push_back( m_transform->positionToWorldSpace( wmath::WPosition( getNbCoordsX() - 1, getNbCoordsY() - 1, getNbCoordsZ() - 1 ) ) );
cornerPs.push_back( m_transform.positionToWorldSpace( wmath::WPosition( 0.0, 0.0, 0.0 ) ) );
cornerPs.push_back( m_transform.positionToWorldSpace( wmath::WPosition( getNbCoordsX() - 1, 0.0, 0.0 ) ) );
cornerPs.push_back( m_transform.positionToWorldSpace( wmath::WPosition( 0.0, getNbCoordsY() - 1, 0.0 ) ) );
cornerPs.push_back( m_transform.positionToWorldSpace( wmath::WPosition( getNbCoordsX() - 1, getNbCoordsY() - 1, 0.0 ) ) );
cornerPs.push_back( m_transform.positionToWorldSpace( wmath::WPosition( 0.0, 0.0, getNbCoordsZ() - 1 ) ) );
cornerPs.push_back( m_transform.positionToWorldSpace( wmath::WPosition( getNbCoordsX() - 1, 0.0, getNbCoordsZ() - 1 ) ) );
cornerPs.push_back( m_transform.positionToWorldSpace( wmath::WPosition( 0.0, getNbCoordsY() - 1, getNbCoordsZ() - 1 ) ) );
cornerPs.push_back( m_transform.positionToWorldSpace( wmath::WPosition( getNbCoordsX() - 1, getNbCoordsY() - 1, getNbCoordsZ() - 1 ) ) );
wmath::WPosition minBB( wlimits::MAX_DOUBLE, wlimits::MAX_DOUBLE, wlimits::MAX_DOUBLE );
wmath::WPosition maxBB( wlimits::MIN_DOUBLE, wlimits::MIN_DOUBLE, wlimits::MIN_DOUBLE );
......@@ -558,5 +557,3 @@ std::pair< wmath::WPosition, wmath::WPosition > WGridRegular3D::getBoundingBox()
return std::make_pair( minBB, maxBB );
}
// TODO(all): compiler warning: warning: unused parameter 'center'
......@@ -65,8 +65,7 @@ public:
* \param transform a grid transformation
*/
WGridRegular3D( unsigned int nbPosX, unsigned int nbPosY, unsigned int nbPosZ,
boost::shared_ptr< WGridTransform const > transform
= boost::shared_ptr< WGridTransform const >( new WGridTransformOrtho() ) );
WGridTransformOrtho const transform = WGridTransformOrtho() );
/**
* Returns the number of samples in x direction.
......@@ -428,13 +427,13 @@ public:
/**
* Return whether the transformations of the grid are only translation and/or scaling
*/
bool isNotRotatedOrSheared() const;
bool isNotRotated() const;
/**
* Returns the transformation used by this grid.
* \return The transformation.
*/
boost::shared_ptr< WGridTransform const > getTransform() const;
WGridTransformOrtho const getTransform() const;
protected:
......@@ -462,7 +461,7 @@ private:
unsigned int m_nbPosZ; //!< Number of positions in z direction
//! The grid's transformation.
boost::shared_ptr< WGridTransform const > const m_transform;
WGridTransformOrtho const m_transform;
};
inline unsigned int WGridRegular3D::getNbCoordsX() const
......@@ -482,61 +481,61 @@ inline unsigned int WGridRegular3D::getNbCoordsZ() const
inline double WGridRegular3D::getOffsetX() const
{
return m_transform->getOffsetX();
return m_transform.getOffsetX();
}
inline double WGridRegular3D::getOffsetY() const
{
return m_transform->getOffsetY();
return m_transform.getOffsetY();
}
inline double WGridRegular3D::getOffsetZ() const
{
return m_transform->getOffsetZ();
return m_transform.getOffsetZ();
}
inline wmath::WVector3D WGridRegular3D::getUnitDirectionX() const
{
return m_transform->getUnitDirectionX();
return m_transform.getUnitDirectionX();
}
inline wmath::WVector3D WGridRegular3D::getUnitDirectionY() const
{
return m_transform->getUnitDirectionY();
return m_transform.getUnitDirectionY();
}
inline wmath::WVector3D WGridRegular3D::getUnitDirectionZ() const
{
return m_transform->getUnitDirectionZ();
return m_transform.getUnitDirectionZ();
}
inline wmath::WVector3D WGridRegular3D::getDirectionX() const
{
return m_transform->getDirectionX();
return m_transform.getDirectionX();
}
inline wmath::WVector3D WGridRegular3D::getDirectionY() const
{
return m_transform->getDirectionY();
return m_transform.getDirectionY();
}
inline wmath::WVector3D WGridRegular3D::getDirectionZ() const
{
return m_transform->getDirectionZ();
return m_transform.getDirectionZ();
}
inline wmath::WPosition WGridRegular3D::getOrigin() const
{
return m_transform->getOrigin();
return m_transform.getOrigin();
}
inline boost::shared_ptr< WGridTransform const > WGridRegular3D::getTransform() const
inline WGridTransformOrtho const WGridRegular3D::getTransform() const
{
return m_transform;
}
inline wmath::WMatrix< double > WGridRegular3D::getTransformationMatrix() const
{
return m_transform->getTransformationMatrix();
return m_transform.getTransformationMatrix();
}
#endif // WGRIDREGULAR3D_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/>.
//
//---------------------------------------------------------------------------
#include "WGridTransform.h"
WGridTransform::~WGridTransform()
{
}
//---------------------------------------------------------------------------
//
// 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 WGRIDTRANSFORM_H
#define WGRIDTRANSFORM_H
#include "../common/math/WVector3D.h"
#include "../common/math/WMatrix.h"
/**
* A class that represents a transformation from grid space to world space.
* Offers several functions for transforming points and vectors between grid and
* world spaces.
*/
class WGridTransform
{
public:
/**
* Destructor.
*/
virtual ~WGridTransform();
/**
* Transforms a position from grid space to world space.
* \param position The position in grid space.
* \return The same position in world space.
*/
virtual wmath::WVector3D positionToWorldSpace( wmath::WVector3D const& position ) const = 0;
/**
* Transforms a position from world space to grid space.
* \param position The position in world space.
* \return The same position in grid space.
*/
virtual wmath::WVector3D positionToGridSpace( wmath::WVector3D const& position ) const = 0;
/**
* Transforms a direction from grid space to world space.
* \param position The direction in grid space.
* \return The same direction in world space.
*/
virtual wmath::WVector3D directionToWorldSpace( wmath::WVector3D const& direction ) const = 0;
/**
* Transforms a position from world space to grid space.
* \param position The position in world space.
* \return The same position in grid space.
*/
virtual wmath::WVector3D directionToGridSpace( wmath::WVector3D const& direction ) const = 0;
/**
* Returns the distance between samples in x direction.
*/
virtual double getOffsetX() const = 0;
/**
* Returns the distance between samples in y direction.
*/
virtual double getOffsetY() const = 0;
/**
* Returns the distance between samples in z direction.
*/
virtual double getOffsetZ() const = 0;
/**
* Returns the vector determining the direction of samples in x direction.
* Adding this vector to a grid position in world coordinates yields the position of the next sample
* along the grids (world coordinate) x-axis.
*/
virtual wmath::WVector3D getDirectionX() const = 0;
/**
* Returns the vector determining the direction of samples in y direction.
* Adding this vector to a grid position in world coordinates yields the position of the next sample
* along the grids (world coordinate) y-axis.
*/
virtual wmath::WVector3D getDirectionY() const = 0;
/**
* Returns the vector determining the direction of samples in z direction.
* Adding this vector to a grid position in world coordinates yields the position of the next sample
* along the grids (world coordinate) z-axis.
*/
virtual wmath::WVector3D getDirectionZ() const = 0;
/**
* Returns the vector determining the unit (normalized) direction of samples in x direction.
*/
virtual wmath::WVector3D getUnitDirectionX() const = 0;
/**
* Returns the vector determining the unit (normalized) direction of samples in y direction.
*/
virtual wmath::WVector3D getUnitDirectionY() const = 0;
/**
* Returns the vector determining the unit (normalized) direction of samples in z direction.
*/
virtual wmath::WVector3D getUnitDirectionZ() const = 0;
/**
* Returns the position of the origin of the grid.
*/
virtual wmath::WPosition getOrigin() const = 0;
/**
* Returns a 4x4 matrix that represents the grid's transformaion.
*/
// NOTE: this is temporary and should be removed as soon as all modules are
// adapted to the grid transform object
virtual wmath::WMatrix< double > getTransformationMatrix() const = 0;
};
#endif // WGRIDTRANSFORM_H
......@@ -177,3 +177,9 @@ wmath::WMatrix< double > WGridTransformOrtho::getTransformationMatrix() const
return mat;
}
bool WGridTransformOrtho::isNotRotated() const
{
return m_directionX == wmath::WVector3D( 1.0, 0.0, 0.0 )
&& m_directionY == wmath::WVector3D( 0.0, 1.0, 0.0 )
&& m_directionZ == wmath::WVector3D( 0.0, 0.0, 1.0 );
}
......@@ -25,14 +25,15 @@
#ifndef WGRIDTRANSFORMORTHO_H
#define WGRIDTRANSFORMORTHO_H
#include "WGridTransform.h"
#include "../common/math/WVector3D.h"
#include "../common/math/WMatrix.h"
/**
* Implements an orthogonal grid transformation.
*
* \class WGridTransformOrtho
*/
class WGridTransformOrtho : public WGridTransform
class WGridTransformOrtho
{
public:
/**
......@@ -58,98 +59,105 @@ public:
/**
* Destructor.
*/
virtual ~WGridTransformOrtho();
~WGridTransformOrtho();
/**
* Transforms a position from grid space to world space.
* \param position The position in grid space.
* \return The same position in world space.
*/
virtual wmath::WVector3D positionToWorldSpace( wmath::WVector3D const& position ) const;
wmath::WVector3D positionToWorldSpace( wmath::WVector3D const& position ) const;
/**
* Transforms a position from world space to grid space.
* \param position The position in world space.
* \return The same position in grid space.
*/
virtual wmath::WVector3D positionToGridSpace( wmath::WVector3D const& position ) const;
wmath::WVector3D positionToGridSpace( wmath::WVector3D const& position ) const;
/**
* Transforms a direction from grid space to world space.
* \param direction The direction in grid space.
* \return The same direction in world space.
*/
virtual wmath::WVector3D directionToWorldSpace( wmath::WVector3D const& direction ) const;
wmath::WVector3D directionToWorldSpace( wmath::WVector3D const& direction ) const;
/**
* Transforms a direction from world space to grid space.
* \param direction The position in world space.
* \return The same position in grid space.
*/
virtual wmath::WVector3D directionToGridSpace( wmath::WVector3D const& direction ) const;
wmath::WVector3D directionToGridSpace( wmath::WVector3D const& direction ) const;
/**
* Returns the distance between samples in x direction.
*/
virtual double getOffsetX() const;
double getOffsetX() const;
/**
* Returns the distance between samples in y direction.
*/
virtual double getOffsetY() const;
double getOffsetY() const;
/**
* Returns the distance between samples in z direction.
*/
virtual double getOffsetZ() const;
double getOffsetZ() const;
/**
* Returns the vector determining the direction of samples in x direction.
* Adding this vector to a grid position in world coordinates yields the position of the next sample
* along the grids (world coordinate) x-axis.
*/
virtual wmath::WVector3D getDirectionX() const;
wmath::WVector3D getDirectionX() const;
/**
* Returns the vector determining the direction of samples in y direction.
* Adding this vector to a grid position in world coordinates yields the position of the next sample
* along the grids (world coordinate) y-axis.
*/
virtual wmath::WVector3D getDirectionY() const;
wmath::WVector3D getDirectionY() const;
/**
* Returns the vector determining the direction of samples in z direction.
* Adding this vector to a grid position in world coordinates yields the position of the next sample
* along the grids (world coordinate) z-axis.
*/
virtual wmath::WVector3D getDirectionZ() const;
wmath::WVector3D getDirectionZ() const;
/**
* Returns the vector determining the unit (normalized) direction of samples in x direction.
*/
virtual wmath::WVector3D getUnitDirectionX() const;
wmath::WVector3D getUnitDirectionX() const;
/**
* Returns the vector determining the unit (normalized) direction of samples in y direction.
*/
virtual wmath::WVector3D getUnitDirectionY() const;
wmath::WVector3D getUnitDirectionY() const;
/**
* Returns the vector determining the unit (normalized) direction of samples in z direction.
*/
virtual wmath::WVector3D getUnitDirectionZ() const;
wmath::WVector3D getUnitDirectionZ() const;
/**
* Returns the position of the origin of the grid.
*/
virtual wmath::WPosition getOrigin() const;
wmath::WPosition getOrigin() const;
/**
* Returns a 4x4 matrix that represents the grid's transformaion.
*/
// NOTE: this is temporary and should be removed as soon as all modules are
// adapted to the grid transform object
virtual wmath::WMatrix< double > getTransformationMatrix() const;
wmath::WMatrix< double > getTransformationMatrix() const;
/**
* Check if this transform does not include a rotation.
*
* \return True, if this transform only scales and translates.
*/
bool isNotRotated() const;
private:
//! normalized direction of the grid's x-axis in world coordinates
......
......@@ -138,7 +138,7 @@ boost::shared_ptr< WDataSetScalar > makeDataSetFromImage( typename itk::Image< T
smat( 3, 1 ) = 0.0;
smat( 3, 2 ) = 0.0;
boost::shared_ptr< WGridTransformOrtho > t( new WGridTransformOrtho( smat ) );
WGridTransformOrtho t( smat );
boost::shared_ptr< WGrid > grid( new WGridRegular3D( s[ 0 ], s[ 1 ], s[ 2 ], t ) );
std::vector< T > v( s[ 0 ] * s[ 1 ] * s[ 2 ] );
......
......@@ -180,9 +180,7 @@ boost::shared_ptr< WDataSet > WReaderNIfTI::load( DataSetType dataSetType )
}
newGrid = boost::shared_ptr< WGridRegular3D >(
new WGridRegular3D( columns, rows, frames,
boost::shared_ptr< WGridTransformOrtho >(
new WGridTransformOrtho( convertMatrix( header->sto_xyz ) ) ) ) );
new WGridRegular3D( columns, rows, frames, WGridTransformOrtho( convertMatrix( header->sto_xyz ) ) ) );
boost::shared_ptr< WDataSet > newDataSet;
// known description
......
......@@ -94,7 +94,7 @@ public:
mat( 1, 1 ) = 0.5;
mat( 2, 2 ) = 2.0;
boost::shared_ptr< WGridTransformOrtho > transform( new WGridTransformOrtho( mat ) );
WGridTransformOrtho transform( mat );
boost::shared_ptr< WGridRegular3D > g( new WGridRegular3D( 3, 3, 3, transform ) );
std::vector< double > v( 27, 4 );
......@@ -151,7 +151,7 @@ public:
mat( 1, 1 ) = 0.5;
mat( 2, 2 ) = 2.0;
boost::shared_ptr< WGridTransformOrtho > transform( new WGridTransformOrtho( mat ) );
WGridTransformOrtho transform( mat );
boost::shared_ptr< WGridRegular3D > g( new WGridRegular3D( 3, 3, 3, transform ) );
std::vector< double > v( 27, 4 );
......@@ -554,7 +554,7 @@ private:
mat( 1, 1 ) = 0.5;
mat( 2, 2 ) = 2.0;
boost::shared_ptr< WGridTransformOrtho > transform( new WGridTransformOrtho( mat ) );
WGridTransformOrtho transform( mat );
boost::shared_ptr< WGridRegular3D > g( new WGridRegular3D( 3, 3, 3, transform ) );
for( int i = 0; i < number; ++i )
......
......@@ -70,7 +70,7 @@ public:
*/
void testSize( void )
{