1
//---------------------------------------------------------------------------
3
// Project: OpenWalnut ( http://www.openwalnut.org )
5
// Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
6
// For more information see http://www.openwalnut.org/copying
8
// This file is part of OpenWalnut.
10
// OpenWalnut is free software: you can redistribute it and/or modify
11
// it under the terms of the GNU Lesser General Public License as published by
12
// the Free Software Foundation, either version 3 of the License, or
13
// (at your option) any later version.
15
// OpenWalnut is distributed in the hope that it will be useful,
16
// but WITHOUT ANY WARRANTY; without even the implied warranty of
17
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18
// GNU Lesser General Public License for more details.
20
// You should have received a copy of the GNU Lesser General Public License
21
// along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
23
//---------------------------------------------------------------------------
25
#ifndef WGRIDTRANSFORMORTHO_TEST_H
26
#define WGRIDTRANSFORMORTHO_TEST_H
33
#include <boost/shared_ptr.hpp>
35
#include <cxxtest/TestSuite.h>
37
#include "../../common/exceptions/WPreconditionNotMet.h"
39
#include "../WGridTransformOrtho.h"
42
* Tests the WGridTransform class.
44
class WGridTransformTest : public CxxTest::TestSuite
48
* Test if all data fields get initialized correctly. Constructors should throw
49
* a WPreconditionNotMet exception if any input values are invalid.
51
void testInstantiation()
54
TS_ASSERT_THROWS_NOTHING( WGridTransformOrtho v() );
55
WGridTransformOrtho v;
56
TS_ASSERT_EQUALS( v.getOffsetX(), 1.0 );
57
TS_ASSERT_EQUALS( v.getOffsetY(), 1.0 );
58
TS_ASSERT_EQUALS( v.getOffsetZ(), 1.0 );
59
compareVectors( v.getUnitDirectionX(), WVector3d( 1.0, 0.0, 0.0 ), 0.0001 );
60
compareVectors( v.getUnitDirectionY(), WVector3d( 0.0, 1.0, 0.0 ), 0.0001 );
61
compareVectors( v.getUnitDirectionZ(), WVector3d( 0.0, 0.0, 1.0 ), 0.0001 );
62
compareVectors( v.getDirectionX(), WVector3d( 1.0, 0.0, 0.0 ), 0.0001 );
63
compareVectors( v.getDirectionY(), WVector3d( 0.0, 1.0, 0.0 ), 0.0001 );
64
compareVectors( v.getDirectionZ(), WVector3d( 0.0, 0.0, 1.0 ), 0.0001 );
65
compareVectors( v.getOrigin(), WVector3d( 0.0, 0.0, 0.0 ), 0.0001 );
68
TS_ASSERT_THROWS_NOTHING( WGridTransformOrtho v( 2.2, 3.3, -1.0 ) );
69
TS_ASSERT_THROWS( WGridTransformOrtho v( 0.0, 0.0, 1.0 ), WPreconditionNotMet );
70
TS_ASSERT_THROWS( WGridTransformOrtho v( 0.0, 2.0, 1.0 ), WPreconditionNotMet );
71
TS_ASSERT_THROWS( WGridTransformOrtho v( 1.0, 1.0, 0.0 ), WPreconditionNotMet );
74
WGridTransformOrtho v( 2.2, 3.3, -1.0 );
75
TS_ASSERT_EQUALS( v.getOffsetX(), 2.2 );
76
TS_ASSERT_EQUALS( v.getOffsetY(), 3.3 );
77
TS_ASSERT_EQUALS( v.getOffsetZ(), 1.0 );
78
compareVectors( v.getUnitDirectionX(), WVector3d( 1.0, 0.0, 0.0 ), 0.0001 );
79
compareVectors( v.getUnitDirectionY(), WVector3d( 0.0, 1.0, 0.0 ), 0.0001 );
80
compareVectors( v.getUnitDirectionZ(), WVector3d( 0.0, 0.0, -1.0 ), 0.0001 );
81
compareVectors( v.getDirectionX(), WVector3d( 2.2, 0.0, 0.0 ), 0.0001 );
82
compareVectors( v.getDirectionY(), WVector3d( 0.0, 3.3, 0.0 ), 0.0001 );
83
compareVectors( v.getDirectionZ(), WVector3d( 0.0, 0.0, -1.0 ), 0.0001 );
84
compareVectors( v.getOrigin(), WVector3d( 0.0, 0.0, 0.0 ), 0.0001 );
87
WMatrix< double > mat( 4, 4 );
93
TS_ASSERT_THROWS( WGridTransformOrtho v( mat ), WPreconditionNotMet );
96
WMatrix< double > mat( 4, 4 );
103
TS_ASSERT_THROWS( WGridTransformOrtho v( mat ), WPreconditionNotMet );
106
WMatrix< double > mat( 4, 4 );
117
WGridTransformOrtho v( mat );
118
TS_ASSERT_EQUALS( v.getOffsetX(), sqrt( 8.0 ) );
119
TS_ASSERT_EQUALS( v.getOffsetY(), sqrt( 18.0 ) );
120
TS_ASSERT_EQUALS( v.getOffsetZ(), 4.4 );
121
TS_ASSERT_DELTA( length( v.getUnitDirectionX() - WVector3d( 0.5 * sqrt( 2.0 ), 0.5 * sqrt( 2.0 ), 0.0 ) ), 0.0, 1e-13 );
122
TS_ASSERT_DELTA( length( v.getUnitDirectionY() - WVector3d( -0.5 * sqrt( 2.0 ), 0.5 * sqrt( 2.0 ), 0.0 ) ), 0.0, 1e-13 );
123
compareVectors( v.getUnitDirectionZ(), WVector3d( 0.0, 0.0, 1.0 ), 0.0001 );
124
compareVectors( v.getDirectionX(), WVector3d( 2.0, 2.0, 0.0 ), 0.0001 );
125
compareVectors( v.getDirectionY(), WVector3d( -3.0, 3.0, 0.0 ), 0.0001 );
126
compareVectors( v.getDirectionZ(), WVector3d( 0.0, 0.0, 4.4 ), 0.0001 );
127
compareVectors( v.getOrigin(), WVector3d( 1.0, 2.0, 0.5 ), 0.0001 );
132
* Different constructors should not yield differently initialized
135
void testCompareConstructors()
137
WMatrix< double > mat( 4, 4 );
143
WGridTransformOrtho t1( mat );
144
WGridTransformOrtho t2( 2.2, 3.3, 4.4 );
146
TS_ASSERT_EQUALS( t1.getOffsetX(), t2.getOffsetX() );
147
TS_ASSERT_EQUALS( t1.getOffsetY(), t2.getOffsetY() );
148
TS_ASSERT_EQUALS( t1.getOffsetZ(), t2.getOffsetZ() );
150
compareVectors( t1.getDirectionX(), t2.getDirectionX(), 0.0001 );
151
compareVectors( t1.getDirectionY(), t2.getDirectionY(), 0.0001 );
152
compareVectors( t1.getDirectionZ(), t2.getDirectionZ(), 0.0001 );
154
compareVectors( t1.getOrigin(), t2.getOrigin(), 0.0001 );
158
* Test transformation from grid space to world space.
160
void testTransformationToWorldSpace()
163
// test identity transform
164
WVector3d v( -7.64, 8.73, -0.0063 );
165
WGridTransformOrtho t;
167
compareVectors( v, t.positionToWorldSpace( v ), 0.0001 );
168
compareVectors( v, t.directionToWorldSpace( v ), 0.0001 );
172
WGridTransformOrtho t( 2.2, 3.3, 4.4 );
173
WVector3d v( 1.0, 1.0, 1.0 );
175
compareVectors( WVector3d( 2.2, 3.3, 4.4 ), t.positionToWorldSpace( v ), 0.0001 );
176
compareVectors( WVector3d( 2.2, 3.3, 4.4 ), t.directionToWorldSpace( v ), 0.0001 );
180
WMatrix< double > mat( 4, 4 );
189
WGridTransformOrtho t( mat );
190
WVector3d v( 1.0, 1.0, 1.0 );
192
compareVectors( WVector3d( 3.2, 5.3, 4.9 ), t.positionToWorldSpace( v ), 0.0001 );
193
compareVectors( WVector3d( 2.2, 3.3, 4.4 ), t.directionToWorldSpace( v ), 0.0001 );
196
WMatrix< double > mat( 4, 4 );
207
WGridTransformOrtho t( mat );
208
WVector3d v( 1.0, 1.0, 1.0 );
210
WVector3d w = t.positionToWorldSpace( v );
211
TS_ASSERT_DELTA( 0.0, w[ 0 ], 0.0001 );
212
TS_ASSERT_DELTA( 7.0, w[ 1 ], 0.0001 );
213
TS_ASSERT_DELTA( 4.9, w[ 2 ], 0.0001 );
214
compareVectors( WVector3d( -1.0, 5.0, 4.4 ), t.directionToWorldSpace( v ), 0.0001 );
219
* Test transformation from world space to grid space.
221
void testTransformationToGridSpace()
224
// test identity transform
225
WVector3d v( -7.64, 8.73, -0.0063 );
226
WGridTransformOrtho t;
228
compareVectors( v, t.positionToGridSpace( v ), 0.0001 );
229
compareVectors( v, t.directionToGridSpace( v ), 0.0001 );
233
WGridTransformOrtho t( 2.2, 3.3, 4.4 );
234
WVector3d v( 2.2, 3.3, 4.4 );
236
compareVectors( WVector3d( 1.0, 1.0, 1.0 ), t.positionToGridSpace( v ), 0.0001 );
237
compareVectors( WVector3d( 1.0, 1.0, 1.0 ), t.directionToGridSpace( v ), 0.0001 );
241
WMatrix< double > mat( 4, 4 );
250
WGridTransformOrtho t( mat );
252
compareVectors( WVector3d( 1.0, 1.0, 1.0 ), t.positionToGridSpace( WVector3d( 3.2, 5.3, 4.9 ) ), 0.0001 );
253
compareVectors( WVector3d( 1.0, 1.0, 1.0 ), t.directionToGridSpace( WVector3d( 2.2, 3.3, 4.4 ) ), 0.0001 );
256
WMatrix< double > mat( 4, 4 );
267
WGridTransformOrtho t( mat );
269
TS_ASSERT_DELTA( length( WVector3d( 1.0, 1.0, 1.0 ) // NOLINT
270
- t.positionToGridSpace( WVector3d( 0.0, 7.0, 4.9 ) ) ), 0.0, 1e-13 );
271
TS_ASSERT_DELTA( length( WVector3d( 1.0, 1.0, 1.0 ) // NOLINT
272
- t.directionToGridSpace( WVector3d( -1.0, 5.0, 4.4 ) ) ), 0.0, 1e-13 );
278
* Compares two vectors, element by element.
280
* \param v1 The first vector.
281
* \param v2 The second vector.
282
* \param delta The maximum absolute difference between the elements of the vectors.
284
void compareVectors( WVector3d const& v1, WVector3d const& v2, double delta ) const
286
TS_ASSERT_DELTA( v1[ 0 ], v2[ 0 ], delta );
287
TS_ASSERT_DELTA( v1[ 1 ], v2[ 1 ], delta );
288
TS_ASSERT_DELTA( v1[ 2 ], v2[ 2 ], delta );
292
#endif // WGRIDTRANSFORMORTHO_TEST_H