Commit c75c8f21 authored by Mathias Goldau's avatar Mathias Goldau
Browse files

[ADD] Now the interpolate function from WDataSetScalar should also work on rotated grids.

parent a4449d94
......@@ -95,7 +95,6 @@ double WDataSetScalar::interpolate( const WPosition& pos, bool* success ) const
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->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." );
......@@ -110,11 +109,11 @@ double WDataSetScalar::interpolate( const WPosition& pos, bool* success ) const
WGridRegular3D::CellVertexArray vertexIds = grid->getCellVertexIds( cellId );
WPosition localPos = pos - grid->getPosition( vertexIds[0] );
WPosition localPos = grid->getTransform().positionToGridSpace( pos - grid->getPosition( vertexIds[0] ) );
double lambdaX = localPos[0] / grid->getOffsetX();
double lambdaY = localPos[1] / grid->getOffsetY();
double lambdaZ = localPos[2] / grid->getOffsetZ();
double lambdaX = localPos[0];
double lambdaY = localPos[1];
double lambdaZ = localPos[2];
std::vector< double > h( 8 );
// lZ lY
// | /
......
......@@ -722,13 +722,11 @@ inline WVector3i WGridRegular3D::getVoxelCoord( const WPosition& pos ) const
inline size_t WGridRegular3D::getCellId( const WPosition& pos, bool* success ) const
{
WAssert( isNotRotated(), "Only feasible for grids that are only translated or scaled so far." );
WPosition posRelativeToOrigin = pos - getOrigin();
WPosition v = m_transform.positionToGridSpace( pos );
double xCellId = floor( posRelativeToOrigin[0] / getOffsetX() );
double yCellId = floor( posRelativeToOrigin[1] / getOffsetY() );
double zCellId = floor( posRelativeToOrigin[2] / getOffsetZ() );
double xCellId = floor( v[0] );
double yCellId = floor( v[1] );
double zCellId = floor( v[2] );
*success = xCellId >= 0 && yCellId >=0 && zCellId >= 0 && xCellId < m_nbPosX - 1 && yCellId < m_nbPosY -1 && zCellId < m_nbPosZ -1;
......
......@@ -86,6 +86,55 @@ public:
TS_ASSERT_DELTA( ds.interpolate( WPosition( 0.5, 0.5, 0.5 ), &success ), 10.5, 1e-9 );
TS_ASSERT( success );
}
/**
* Test if the interpolate function works also for rotated grids reasonable.
*/
void testInterpolateInRotatedGrid( void )
{
// rotation around z with 45 degrees
WMatrix< double > mat( 4, 4 );
mat.makeIdentity();
mat( 0, 0 ) = 1.0 / sqrt( 2.0 );
mat( 0, 1 ) = 1.0 / sqrt( 2.0 );
mat( 1, 0 ) = -1.0 / sqrt( 2.0 );
mat( 1, 1 ) = 1.0 / sqrt( 2.0 );
WGridTransformOrtho v( mat );
boost::shared_ptr< WGridRegular3D > grid( new WGridRegular3D( 5, 3, 3, v ) );
boost::shared_ptr< std::vector< double > > data = boost::shared_ptr< std::vector< double > >( new std::vector< double >( grid->size() ) );
for( size_t i = 0; i < grid->size(); ++i )
{
( *data )[i] = i;
}
boost::shared_ptr< WValueSet< double > > valueSet( new WValueSet< double >( 0, 1, data, W_DT_DOUBLE ) );
WDataSetScalar ds( valueSet, grid );
bool success = false;
TS_ASSERT_EQUALS( ds.interpolate( WPosition::zero(), &success ), ( *data )[0] );
TS_ASSERT( success );
TS_ASSERT_DELTA( ds.interpolate( grid->getTransform().positionToWorldSpace( WPosition( 1, 0, 0 ) ), &success ), ( *data )[1], 1e-9 );
TS_ASSERT( success );
TS_ASSERT_DELTA( ds.interpolate( grid->getTransform().positionToWorldSpace( WPosition( 0, 1, 0 ) ), &success ), ( *data )[5], 1e-9 );
TS_ASSERT( success );
TS_ASSERT_DELTA( ds.interpolate( grid->getTransform().positionToWorldSpace( WPosition( 1, 1, 0 ) ), &success ), ( *data )[6], 1e-9 );
TS_ASSERT( success );
TS_ASSERT_DELTA( ds.interpolate( grid->getTransform().positionToWorldSpace( WPosition( 0, 0, 1 ) ), &success ), ( *data )[15], 1e-9 );
TS_ASSERT( success );
TS_ASSERT_DELTA( ds.interpolate( grid->getTransform().positionToWorldSpace( WPosition( 1, 0, 1 ) ), &success ), ( *data )[16], 1e-9 );
TS_ASSERT( success );
TS_ASSERT_DELTA( ds.interpolate( grid->getTransform().positionToWorldSpace( WPosition( 0, 1, 1 ) ), &success ), ( *data )[20], 1e-9 );
TS_ASSERT( success );
TS_ASSERT_DELTA( ds.interpolate( grid->getTransform().positionToWorldSpace( WPosition( 1, 1, 1 ) ), &success ), ( *data )[21], 1e-9 );
TS_ASSERT( success );
TS_ASSERT_DELTA( ds.interpolate( grid->getTransform().positionToWorldSpace( WPosition( 0.3, 0.4, 0.5 ) ), &success ), 9.8, 1e-9 );
TS_ASSERT( success );
TS_ASSERT_DELTA( ds.interpolate( grid->getTransform().positionToWorldSpace( WPosition( 0.5, 0.5, 0.5 ) ), &success ), 10.5, 1e-9 );
TS_ASSERT( success );
}
};
#endif // WDATASETSCALAR_TEST_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