Commit baf70860 by reichenbach

[FIX] applied previous fix to the interpolation functions

parent 87ccf191
......@@ -119,7 +119,7 @@ double WDataSetScalar::interpolate( const WPosition& pos, bool* success ) const
WGridRegular3D::CellVertexArray vertexIds = grid->getCellVertexIds( cellId );
WPosition localPos = grid->getTransform().positionToGridSpace( pos - grid->getPosition( vertexIds[0] ) );
WPosition localPos = grid->getTransform().directionToGridSpace( pos - grid->getPosition( vertexIds[0] ) );
double lambdaX = localPos[0];
double lambdaY = localPos[1];
......
......@@ -96,11 +96,12 @@ WSymmetricSphericalHarmonic< double > WDataSetSphericalHarmonics::interpolate( c
// ids of vertices for interpolation
WGridRegular3D::CellVertexArray vertexIds = m_gridRegular3D->getCellVertexIds( cellId );
WPosition localPos = pos - m_gridRegular3D->getPosition( vertexIds[0] );
WPosition localPos = m_gridRegular3D->getTransform().directionToGridSpace( pos - m_gridRegular3D->getPosition( vertexIds[0] ) );
double lambdaX = localPos[0];
double lambdaY = localPos[1];
double lambdaZ = localPos[2];
double lambdaX = localPos[0] / m_gridRegular3D->getOffsetX();
double lambdaY = localPos[1] / m_gridRegular3D->getOffsetY();
double lambdaZ = localPos[2] / m_gridRegular3D->getOffsetZ();
WValue< double > h( 8 );
// lZ lY
// | /
......
......@@ -107,7 +107,7 @@ namespace
*vertexIds = grid->getCellVertexIds( cellId );
WPosition localPos = grid->getTransform().positionToGridSpace( pos - grid->getPosition( ( *vertexIds )[0] ) );
WPosition localPos = grid->getTransform().directionToGridSpace( pos - grid->getPosition( ( *vertexIds )[0] ) );
double lambdaX = localPos[0];
double lambdaY = localPos[1];
......
......@@ -29,6 +29,8 @@
#include <cxxtest/TestSuite.h>
#include <boost/random.hpp>
#include "../../common/WLogger.h"
#include "../WDataSetScalar.h"
......@@ -135,6 +137,68 @@ public:
TS_ASSERT_DELTA( ds.interpolate( grid->getTransform().positionToWorldSpace( WPosition( 0.5, 0.5, 0.5 ) ), &success ), 10.5, 1e-9 );
TS_ASSERT( success );
}
/**
* Check whether interpolation works for a translated dataset.
*/
void testTranslatedGridInterpolation()
{
boost::random::mt19937 rng;
boost::random::uniform_int_distribution<> urnd( 3, 20 );
boost::random::uniform_real_distribution<> drnd( -1000.0, +1000.0 );
WMatrix< double > mat( 4, 4 );
mat.makeIdentity();
mat( 0, 0 ) = 1.7;
mat( 1, 1 ) = 1.7;
mat( 2, 2 ) = 1.7;
std::size_t sx = urnd( rng );
std::size_t sy = urnd( rng );
std::size_t sz = urnd( rng );
boost::random::uniform_real_distribution<> prndx( 0.0, ( sx - 1.000000001 ) * mat( 0, 0 ) );
boost::random::uniform_real_distribution<> prndy( 0.0, ( sy - 1.000000001 ) * mat( 1, 1 ) );
boost::random::uniform_real_distribution<> prndz( 0.0, ( sz - 1.000000001 ) * mat( 2, 2 ) );
WGridTransformOrtho v( mat );
boost::shared_ptr< WGridRegular3D > grid( new WGridRegular3D( sx, sy, sz, v ) );
boost::shared_ptr< std::vector< double > > data( new std::vector< double >( grid->size() ) );
for( std::size_t k = 0; k < grid->size(); ++k )
{
data->at( k ) = drnd( rng );
}
boost::shared_ptr< WValueSet< double > > valueSet( new WValueSet< double >( 0, 1, data, W_DT_DOUBLE ) );
WDataSetScalar ds( valueSet, grid );
for( std::size_t k = 0; k < 1000; ++k )
{
WMatrix< double > m = mat;
m( 0, 3 ) = drnd( rng );
m( 1, 3 ) = drnd( rng );
m( 2, 3 ) = drnd( rng );
WGridTransformOrtho t( m );
boost::shared_ptr< WGridRegular3D > tGrid( new WGridRegular3D( sx, sy, sz, t ) );
boost::shared_ptr< WValueSet< double > > tValueSet( new WValueSet< double >( 0, 1, data, W_DT_DOUBLE ) );
WDataSetScalar tds( tValueSet, tGrid );
// test random positions in the dataset
for( std::size_t i = 0; i < 100; ++i )
{
WVector3d p( prndx( rng ), prndy( rng ), prndz( rng ) );
WVector3d q( p[ 0 ] + m( 0, 3 ), p[ 1 ] + m( 1, 3 ), p[ 2 ] + m( 2, 3 ) );
bool s1, s2;
TS_ASSERT_DELTA( ds.interpolate( p, &s1 ), tds.interpolate( q, &s2 ), 1e-9 );
TS_ASSERT( s1 );
TS_ASSERT( s2 );
}
}
}
};
#endif // WDATASETSCALAR_TEST_H
......@@ -29,6 +29,7 @@
#include <cmath>
#include <boost/array.hpp>
#include <boost/random.hpp>
#include <cxxtest/TestSuite.h>
......@@ -229,6 +230,73 @@ public:
TS_ASSERT( success );
}
/**
* Check whether interpolation works for a translated dataset.
*/
void testTranslatedGridInterpolation()
{
boost::random::mt19937 rng;
boost::random::uniform_int_distribution<> urnd( 3, 20 );
boost::random::uniform_real_distribution<> drnd( -1000.0, +1000.0 );
WMatrix< double > mat( 4, 4 );
mat.makeIdentity();
mat( 0, 0 ) = 1.7;
mat( 1, 1 ) = 1.7;
mat( 2, 2 ) = 1.7;
std::size_t sx = urnd( rng );
std::size_t sy = urnd( rng );
std::size_t sz = urnd( rng );
boost::random::uniform_real_distribution<> prndx( 0.0, ( sx - 1.000000001 ) * mat( 0, 0 ) );
boost::random::uniform_real_distribution<> prndy( 0.0, ( sy - 1.000000001 ) * mat( 1, 1 ) );
boost::random::uniform_real_distribution<> prndz( 0.0, ( sz - 1.000000001 ) * mat( 2, 2 ) );
WGridTransformOrtho v( mat );
boost::shared_ptr< WGridRegular3D > grid( new WGridRegular3D( sx, sy, sz, v ) );
boost::shared_ptr< std::vector< double > > data( new std::vector< double >( grid->size() * 3 ) );
for( std::size_t k = 0; k < grid->size(); ++k )
{
data->at( 3 * k + 0 ) = drnd( rng );
data->at( 3 * k + 1 ) = drnd( rng );
data->at( 3 * k + 2 ) = drnd( rng );
}
boost::shared_ptr< WValueSet< double > > valueSet( new WValueSet< double >( 1, 3, data, W_DT_DOUBLE ) );
WDataSetVector ds( valueSet, grid );
for( std::size_t k = 0; k < 1000; ++k )
{
WMatrix< double > m = mat;
m( 0, 3 ) = drnd( rng );
m( 1, 3 ) = drnd( rng );
m( 2, 3 ) = drnd( rng );
WGridTransformOrtho t( m );
boost::shared_ptr< WGridRegular3D > tGrid( new WGridRegular3D( sx, sy, sz, t ) );
boost::shared_ptr< WValueSet< double > > tValueSet( new WValueSet< double >( 1, 3, data, W_DT_DOUBLE ) );
WDataSetVector tds( tValueSet, tGrid );
// test random positions in the dataset
for( std::size_t i = 0; i < 100; ++i )
{
WVector3d p( prndx( rng ), prndy( rng ), prndz( rng ) );
WVector3d q( p[ 0 ] + m( 0, 3 ), p[ 1 ] + m( 1, 3 ), p[ 2 ] + m( 2, 3 ) );
bool s1, s2;
TS_ASSERT( delta( ds.interpolate( p, &s1 ), tds.interpolate( q, &s2 ), 1e-9 ) );
TS_ASSERT( s1 );
TS_ASSERT( s2 );
TS_ASSERT( delta( ds.eigenVectorInterpolate( p, &s1 ), tds.eigenVectorInterpolate( q, &s2 ), 1e-9 ) );
TS_ASSERT( s1 );
TS_ASSERT( s2 );
}
}
}
private:
/**
* Computes if both vectors are almost similar and their components do not differ from a certain given delta.
......
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