25 #ifndef WDATASETSCALAR_TEST_H
26 #define WDATASETSCALAR_TEST_H
31 #include <boost/random.hpp>
32 #include <cxxtest/TestSuite.h>
34 #include "../../common/WLogger.h"
35 #include "../WDataSetScalar.h"
58 std::shared_ptr< std::vector< double > > data(
new std::vector< double >( grid->size() ) );
59 for(
size_t i = 0; i < grid->size(); ++i )
63 std::shared_ptr< WValueSet< double > > valueSet(
new WValueSet< double >( 0, 1, data, W_DT_DOUBLE ) );
68 TS_ASSERT_EQUALS( ds.
interpolate( WPosition::zero(), &success ), ( *data )[0] );
99 mat( 0, 0 ) = 1.0 / sqrt( 2.0 );
100 mat( 0, 1 ) = 1.0 / sqrt( 2.0 );
101 mat( 1, 0 ) = -1.0 / sqrt( 2.0 );
102 mat( 1, 1 ) = 1.0 / sqrt( 2.0 );
106 std::shared_ptr< WGridRegular3D > grid(
new WGridRegular3D( 5, 3, 3, v ) );
107 std::shared_ptr< std::vector< double > > data(
new std::vector< double >( grid->size() ) );
108 for(
size_t i = 0; i < grid->size(); ++i )
112 std::shared_ptr< WValueSet< double > > valueSet(
new WValueSet< double >( 0, 1, data, W_DT_DOUBLE ) );
115 bool success =
false;
117 TS_ASSERT_EQUALS( ds.
interpolate( WPosition::zero(), &success ), ( *data )[0] );
118 TS_ASSERT( success );
119 TS_ASSERT_DELTA( ds.
interpolate( grid->getTransform().positionToWorldSpace(
WPosition( 1, 0, 0 ) ), &success ), ( *data )[1], 1e-9 );
120 TS_ASSERT( success );
121 TS_ASSERT_DELTA( ds.
interpolate( grid->getTransform().positionToWorldSpace(
WPosition( 0, 1, 0 ) ), &success ), ( *data )[5], 1e-9 );
122 TS_ASSERT( success );
123 TS_ASSERT_DELTA( ds.
interpolate( grid->getTransform().positionToWorldSpace(
WPosition( 1, 1, 0 ) ), &success ), ( *data )[6], 1e-9 );
124 TS_ASSERT( success );
125 TS_ASSERT_DELTA( ds.
interpolate( grid->getTransform().positionToWorldSpace(
WPosition( 0, 0, 1 ) ), &success ), ( *data )[15], 1e-9 );
126 TS_ASSERT( success );
127 TS_ASSERT_DELTA( ds.
interpolate( grid->getTransform().positionToWorldSpace(
WPosition( 1, 0, 1 ) ), &success ), ( *data )[16], 1e-9 );
128 TS_ASSERT( success );
129 TS_ASSERT_DELTA( ds.
interpolate( grid->getTransform().positionToWorldSpace(
WPosition( 0, 1, 1 ) ), &success ), ( *data )[20], 1e-9 );
130 TS_ASSERT( success );
131 TS_ASSERT_DELTA( ds.
interpolate( grid->getTransform().positionToWorldSpace(
WPosition( 1, 1, 1 ) ), &success ), ( *data )[21], 1e-9 );
132 TS_ASSERT( success );
134 TS_ASSERT_DELTA( ds.
interpolate( grid->getTransform().positionToWorldSpace(
WPosition( 0.3, 0.4, 0.5 ) ), &success ), 9.8, 1e-9 );
135 TS_ASSERT( success );
136 TS_ASSERT_DELTA( ds.
interpolate( grid->getTransform().positionToWorldSpace(
WPosition( 0.5, 0.5, 0.5 ) ), &success ), 10.5, 1e-9 );
137 TS_ASSERT( success );
145 boost::random::mt19937 rng;
146 boost::random::uniform_int_distribution<> urnd( 3, 20 );
147 boost::random::uniform_real_distribution<> drnd( -1000.0, +1000.0 );
155 std::size_t sx = urnd( rng );
156 std::size_t sy = urnd( rng );
157 std::size_t sz = urnd( rng );
159 boost::random::uniform_real_distribution<> prndx( 0.0, ( sx - 1.000000001 ) * mat( 0, 0 ) );
160 boost::random::uniform_real_distribution<> prndy( 0.0, ( sy - 1.000000001 ) * mat( 1, 1 ) );
161 boost::random::uniform_real_distribution<> prndz( 0.0, ( sz - 1.000000001 ) * mat( 2, 2 ) );
164 std::shared_ptr< WGridRegular3D > grid(
new WGridRegular3D( sx, sy, sz, v ) );
165 std::shared_ptr< std::vector< double > > data(
new std::vector< double >( grid->size() ) );
167 for( std::size_t k = 0; k < grid->size(); ++k )
169 data->at( k ) = drnd( rng );
172 std::shared_ptr< WValueSet< double > > valueSet(
new WValueSet< double >( 0, 1, data, W_DT_DOUBLE ) );
175 for( std::size_t k = 0; k < 1000; ++k )
179 m( 0, 3 ) = drnd( rng );
180 m( 1, 3 ) = drnd( rng );
181 m( 2, 3 ) = drnd( rng );
184 std::shared_ptr< WGridRegular3D > tGrid(
new WGridRegular3D( sx, sy, sz, t ) );
185 std::shared_ptr< WValueSet< double > > tValueSet(
new WValueSet< double >( 0, 1, data, W_DT_DOUBLE ) );
189 for( std::size_t i = 0; i < 100; ++i )
191 WVector3d p( prndx( rng ), prndy( rng ), prndz( rng ) );
192 WVector3d q( p[ 0 ] + m( 0, 3 ), p[ 1 ] + m( 1, 3 ), p[ 2 ] + m( 2, 3 ) );
Tests for the data set type containing only scalars.
void testInterpolateInRotatedGrid(void)
Test if the interpolate function works also for rotated grids reasonable.
void setUp()
Setup logger and other stuff for each test.
void testInterpolate(void)
Test if the interpolate function works reasonable.
void testTranslatedGridInterpolation()
Check whether interpolation works for a translated dataset.
This data set type contains scalars as values.
double interpolate(const WPosition &pos, bool *success) const
Interpolate the value for the valueset at the given position.
A grid that has parallelepiped cells which all have the same proportion.
static void startup(std::ostream &output=std::cout, LogLevel level=LL_DEBUG)
Create the first and only instance of the logger as it is a singleton.
WMatrix & makeIdentity()
Makes the matrix contain the identity matrix, i.e.
This only is a 3d double vector.
Base Class for all value set types.