25 #ifndef WDATASETVECTOR_TEST_H
26 #define WDATASETVECTOR_TEST_H
32 #include <boost/array.hpp>
33 #include <boost/random.hpp>
34 #include <cxxtest/TestSuite.h>
36 #include "../../common/WLogger.h"
37 #include "../WDataSetVector.h"
58 std::shared_ptr< WGridRegular3D > grid(
new WGridRegular3D( 2, 2, 2 ) );
59 boost::array< WPosition, 8 > d = { {
WPosition( 0, 1, 2 ),
WPosition( 3, 4, 5 ),
WPosition( 6, 7, 8 ),
60 WPosition( 9,10,11 ),
WPosition( 12,13,14 ),
WPosition( 15,16,17 ),
WPosition( 18,19,20 ),
WPosition( 21,22,23 ) } };
62 std::shared_ptr< std::vector< double > > data(
new std::vector< double > );
63 for(
size_t i = 0; i < grid->size() * 3; ++i )
69 boost::array< WPosition, 8 > gridPos = { {
WPosition( 0, 0, 0 ),
WPosition( almost1, 0, 0 ),
WPosition( 0, almost1, 0 ),
73 std::shared_ptr< WValueSet< double > > valueSet(
new WValueSet< double >( 1, 3, data, W_DT_DOUBLE ) );
77 for(
size_t i = 0; i < 8; ++i )
82 ss <<
"i:" << i <<
" gridPos(i):" << gridPos[i] <<
" d(i):" << d[i] <<
" interpol:" << ds.
interpolate( gridPos[i], &success ) <<
"\n";
124 std::shared_ptr< std::vector< double > > data(
new std::vector< double > );
125 boost::array< WPosition, 8 > d = { {
WPosition( -1, 0, 0 ),
134 for(
size_t i = 0; i < grid->size(); ++i )
136 data->push_back( d[i][0] );
137 data->push_back( d[i][1] );
138 data->push_back( d[i][2] );
140 std::shared_ptr< WValueSet< double > > valueSet(
new WValueSet< double >( 1, 3, data, W_DT_DOUBLE ) );
143 bool success =
false;
145 TS_ASSERT( success );
147 TS_ASSERT( success );
149 TS_ASSERT( success );
151 TS_ASSERT( success );
153 TS_ASSERT( success );
155 TS_ASSERT( success );
164 std::shared_ptr< WGridRegular3D > grid(
new WGridRegular3D( 3, 4, 5 ) );
165 bool success =
false;
166 std::shared_ptr< std::vector< double > > data(
new std::vector< double >( grid->size() * 3 ) );
167 for(
size_t i = 0; i < grid->size() * 3; ++i )
171 std::shared_ptr< WValueSet< double > > valueSet(
new WValueSet< double >( 1, 3, data, W_DT_DOUBLE ) );
174 TS_ASSERT( !success );
185 mat( 0, 0 ) = 1.0 / sqrt( 2.0 );
186 mat( 0, 1 ) = 1.0 / sqrt( 2.0 );
187 mat( 1, 0 ) = -1.0 / sqrt( 2.0 );
188 mat( 1, 1 ) = 1.0 / sqrt( 2.0 );
192 std::shared_ptr< WGridRegular3D > grid(
new WGridRegular3D( 2, 2, 2, v ) );
193 std::shared_ptr< std::vector< double > > data(
new std::vector< double > );
194 boost::array< WPosition, 8 > d = { {
WPosition( -1, 0, 0 ),
203 for(
size_t i = 0; i < grid->size(); ++i )
205 data->push_back( d[i][0] );
206 data->push_back( d[i][1] );
207 data->push_back( d[i][2] );
209 std::shared_ptr< WValueSet< double > > valueSet(
new WValueSet< double >( 1, 3, data, W_DT_DOUBLE ) );
212 bool success =
false;
213 WPosition pos = grid->getTransform().positionToWorldSpace(
WPosition( 0.0, 0.0, 0.0 ) );
214 TS_ASSERT_EQUALS( ds.
interpolate( pos, &success ), d[0] );
215 TS_ASSERT( success );
216 pos = grid->getTransform().positionToWorldSpace(
WPosition( 0.9999, 0.9999, 0.9999 ) );
218 TS_ASSERT( success );
219 pos = grid->getTransform().positionToWorldSpace(
WPosition( 0.5, 0.5, 0.5 ) );
221 TS_ASSERT( success );
222 pos = grid->getTransform().positionToWorldSpace(
WPosition( 0.0, 0.0, 0.0 ) );
224 TS_ASSERT( success );
225 pos = grid->getTransform().positionToWorldSpace(
WPosition( 0.9999, 0.9999, 0.9999 ) );
227 TS_ASSERT( success );
228 pos = grid->getTransform().positionToWorldSpace(
WPosition( 0.5, 0.5, 0.5 ) );
230 TS_ASSERT( success );
238 boost::random::mt19937 rng;
239 boost::random::uniform_int_distribution<> urnd( 3, 20 );
240 boost::random::uniform_real_distribution<> drnd( -1000.0, +1000.0 );
248 std::size_t sx = urnd( rng );
249 std::size_t sy = urnd( rng );
250 std::size_t sz = urnd( rng );
252 boost::random::uniform_real_distribution<> prndx( 0.0, ( sx - 1.000000001 ) * mat( 0, 0 ) );
253 boost::random::uniform_real_distribution<> prndy( 0.0, ( sy - 1.000000001 ) * mat( 1, 1 ) );
254 boost::random::uniform_real_distribution<> prndz( 0.0, ( sz - 1.000000001 ) * mat( 2, 2 ) );
257 std::shared_ptr< WGridRegular3D > grid(
new WGridRegular3D( sx, sy, sz, v ) );
258 std::shared_ptr< std::vector< double > > data(
new std::vector< double >( grid->size() * 3 ) );
260 for( std::size_t k = 0; k < grid->size(); ++k )
262 data->at( 3 * k + 0 ) = drnd( rng );
263 data->at( 3 * k + 1 ) = drnd( rng );
264 data->at( 3 * k + 2 ) = drnd( rng );
267 std::shared_ptr< WValueSet< double > > valueSet(
new WValueSet< double >( 1, 3, data, W_DT_DOUBLE ) );
270 for( std::size_t k = 0; k < 1000; ++k )
274 m( 0, 3 ) = drnd( rng );
275 m( 1, 3 ) = drnd( rng );
276 m( 2, 3 ) = drnd( rng );
279 std::shared_ptr< WGridRegular3D > tGrid(
new WGridRegular3D( sx, sy, sz, t ) );
280 std::shared_ptr< WValueSet< double > > tValueSet(
new WValueSet< double >( 1, 3, data, W_DT_DOUBLE ) );
284 for( std::size_t i = 0; i < 100; ++i )
286 WVector3d p( prndx( rng ), prndy( rng ), prndz( rng ) );
287 WVector3d q( p[ 0 ] + m( 0, 3 ), p[ 1 ] + m( 1, 3 ), p[ 2 ] + m( 2, 3 ) );
313 for(
int i = 0; result && ( i < 3 ); ++i )
315 result = result && ( std::abs( lhs[i] - rhs[i] ) <= d );
318 std::cout.precision( 10 );
319 std::cout.setf( std::ios::fixed, std::ios::floatfield );
320 std::cout <<
"delta failed! => lhs:" << lhs <<
" rhs:" << rhs <<
" failed: abs(lhs[" << i <<
"] - rhs["
321 << i <<
"])=" << std::abs( lhs[i] - rhs[i] ) <<
", but should be: " << d <<
"\n";
Test basic functionality of WDataSetVector.
void testRotatedGridInterpolate(void)
When the grid for this dataset was rotated the interpolation should still work.
void testInterpolate(void)
An interpolate of an vector is as if every components were interpolated.
void setUp(void)
Constructs unit test environment.
void testEigenVectorInterpolate(void)
Checks if the reorientation of the vectors is applied in eigenVectorInterpolate().
void testTranslatedGridInterpolation()
Check whether interpolation works for a translated dataset.
bool delta(WVector3d lhs, WVector3d rhs, double d)
Computes if both vectors are almost similar and their components do not differ from a certain given d...
void testBoundary_ticket313(void)
Using interpolate on Positions on the boundary of the grid the success flag is true but there should ...
This data set type contains vectors as values.
WVector3d eigenVectorInterpolate(const WPosition &pos, bool *success) const
Interpolates the very same way as interpolate but it assures that all vecs are aligned to point into ...
WVector3d interpolate(const WPosition &pos, bool *success) const
Interpolates the vector field 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.
const double DBL_EPS
Smallest double such: 1.0 + DBL_EPS == 1.0 is still true.