~ubuntu-branches/ubuntu/wily/openwalnut/wily-proposed

« back to all changes in this revision

Viewing changes to .pc/gcc5.patch/src/core/dataHandler/test/WGridTransformOrtho_test.h

  • Committer: Package Import Robot
  • Author(s): Michael Terry
  • Date: 2015-08-12 13:14:55 UTC
  • Revision ID: package-import@ubuntu.com-20150812131455-cwndvoy9wwx34ya2
Tags: 1.4.0~rc1+hg3a3147463ee2-1ubuntu4
* debian/patches/gcc5.patch:
  - Work around incompatibility between boost+gcc5 and Qt4, fixing FTBFS

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//---------------------------------------------------------------------------
 
2
//
 
3
// Project: OpenWalnut ( http://www.openwalnut.org )
 
4
//
 
5
// Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
 
6
// For more information see http://www.openwalnut.org/copying
 
7
//
 
8
// This file is part of OpenWalnut.
 
9
//
 
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.
 
14
//
 
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.
 
19
//
 
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/>.
 
22
//
 
23
//---------------------------------------------------------------------------
 
24
 
 
25
#ifndef WGRIDTRANSFORMORTHO_TEST_H
 
26
#define WGRIDTRANSFORMORTHO_TEST_H
 
27
 
 
28
#include <cstdio>
 
29
#include <sstream>
 
30
#include <string>
 
31
#include <vector>
 
32
 
 
33
#include <boost/shared_ptr.hpp>
 
34
 
 
35
#include <cxxtest/TestSuite.h>
 
36
 
 
37
#include "../../common/exceptions/WPreconditionNotMet.h"
 
38
 
 
39
#include "../WGridTransformOrtho.h"
 
40
 
 
41
/**
 
42
 * Tests the WGridTransform class.
 
43
 */
 
44
class WGridTransformTest : public CxxTest::TestSuite
 
45
{
 
46
public:
 
47
    /**
 
48
     * Test if all data fields get initialized correctly. Constructors should throw
 
49
     * a WPreconditionNotMet exception if any input values are invalid.
 
50
     */
 
51
    void testInstantiation()
 
52
    {
 
53
        {
 
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 );
 
66
        }
 
67
        {
 
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 );
 
72
        }
 
73
        {
 
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 );
 
85
        }
 
86
        {
 
87
            WMatrix< double > mat( 4, 4 );
 
88
            mat.makeIdentity();
 
89
            mat( 0, 0 ) = 2.2;
 
90
            mat( 1, 1 ) = 3.3;
 
91
            mat( 2, 2 ) = 0.0;
 
92
 
 
93
            TS_ASSERT_THROWS( WGridTransformOrtho v( mat ), WPreconditionNotMet );
 
94
        }
 
95
        {
 
96
            WMatrix< double > mat( 4, 4 );
 
97
            mat.makeIdentity();
 
98
            mat( 0, 0 ) = 2.2;
 
99
            mat( 1, 0 ) = 0.1;
 
100
            mat( 1, 1 ) = 3.3;
 
101
            mat( 2, 2 ) = 1.0;
 
102
 
 
103
            TS_ASSERT_THROWS( WGridTransformOrtho v( mat ), WPreconditionNotMet );
 
104
        }
 
105
        {
 
106
            WMatrix< double > mat( 4, 4 );
 
107
            mat.makeIdentity();
 
108
            mat( 0, 0 ) = 2.0;
 
109
            mat( 1, 0 ) = 2.0;
 
110
            mat( 1, 1 ) = 3.0;
 
111
            mat( 0, 1 ) = -3.0;
 
112
            mat( 2, 2 ) = 4.4;
 
113
            mat( 0, 3 ) = 1.0;
 
114
            mat( 1, 3 ) = 2.0;
 
115
            mat( 2, 3 ) = 0.5;
 
116
 
 
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 );
 
128
        }
 
129
    }
 
130
 
 
131
    /**
 
132
     * Different constructors should not yield differently initialized
 
133
     * data fields.
 
134
     */
 
135
    void testCompareConstructors()
 
136
    {
 
137
        WMatrix< double > mat( 4, 4 );
 
138
        mat.makeIdentity();
 
139
        mat( 0, 0 ) = 2.2;
 
140
        mat( 1, 1 ) = 3.3;
 
141
        mat( 2, 2 ) = 4.4;
 
142
 
 
143
        WGridTransformOrtho t1( mat );
 
144
        WGridTransformOrtho t2( 2.2, 3.3, 4.4 );
 
145
 
 
146
        TS_ASSERT_EQUALS( t1.getOffsetX(), t2.getOffsetX() );
 
147
        TS_ASSERT_EQUALS( t1.getOffsetY(), t2.getOffsetY() );
 
148
        TS_ASSERT_EQUALS( t1.getOffsetZ(), t2.getOffsetZ() );
 
149
 
 
150
        compareVectors( t1.getDirectionX(), t2.getDirectionX(), 0.0001 );
 
151
        compareVectors( t1.getDirectionY(), t2.getDirectionY(), 0.0001 );
 
152
        compareVectors( t1.getDirectionZ(), t2.getDirectionZ(), 0.0001 );
 
153
 
 
154
        compareVectors( t1.getOrigin(), t2.getOrigin(), 0.0001 );
 
155
    }
 
156
 
 
157
    /**
 
158
     * Test transformation from grid space to world space.
 
159
     */
 
160
    void testTransformationToWorldSpace()
 
161
    {
 
162
        {
 
163
            // test identity transform
 
164
            WVector3d v( -7.64, 8.73, -0.0063 );
 
165
            WGridTransformOrtho t;
 
166
 
 
167
            compareVectors( v, t.positionToWorldSpace( v ), 0.0001 );
 
168
            compareVectors( v, t.directionToWorldSpace( v ), 0.0001 );
 
169
        }
 
170
 
 
171
        {
 
172
            WGridTransformOrtho t( 2.2, 3.3, 4.4 );
 
173
            WVector3d v( 1.0, 1.0, 1.0 );
 
174
 
 
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 );
 
177
        }
 
178
 
 
179
        {
 
180
            WMatrix< double > mat( 4, 4 );
 
181
            mat.makeIdentity();
 
182
            mat( 0, 0 ) = 2.2;
 
183
            mat( 1, 1 ) = 3.3;
 
184
            mat( 2, 2 ) = 4.4;
 
185
            mat( 0, 3 ) = 1.0;
 
186
            mat( 1, 3 ) = 2.0;
 
187
            mat( 2, 3 ) = 0.5;
 
188
 
 
189
            WGridTransformOrtho t( mat );
 
190
            WVector3d v( 1.0, 1.0, 1.0 );
 
191
 
 
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 );
 
194
        }
 
195
        {
 
196
            WMatrix< double > mat( 4, 4 );
 
197
            mat.makeIdentity();
 
198
            mat( 0, 0 ) = 2.0;
 
199
            mat( 1, 0 ) = 2.0;
 
200
            mat( 1, 1 ) = 3.0;
 
201
            mat( 0, 1 ) = -3.0;
 
202
            mat( 2, 2 ) = 4.4;
 
203
            mat( 0, 3 ) = 1.0;
 
204
            mat( 1, 3 ) = 2.0;
 
205
            mat( 2, 3 ) = 0.5;
 
206
 
 
207
            WGridTransformOrtho t( mat );
 
208
            WVector3d v( 1.0, 1.0, 1.0 );
 
209
 
 
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 );
 
215
        }
 
216
    }
 
217
 
 
218
    /**
 
219
     * Test transformation from world space to grid space.
 
220
     */
 
221
    void testTransformationToGridSpace()
 
222
    {
 
223
        {
 
224
            // test identity transform
 
225
            WVector3d v( -7.64, 8.73, -0.0063 );
 
226
            WGridTransformOrtho t;
 
227
 
 
228
            compareVectors( v, t.positionToGridSpace( v ), 0.0001 );
 
229
            compareVectors( v, t.directionToGridSpace( v ), 0.0001 );
 
230
        }
 
231
 
 
232
        {
 
233
            WGridTransformOrtho t( 2.2, 3.3, 4.4 );
 
234
            WVector3d v( 2.2, 3.3, 4.4 );
 
235
 
 
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 );
 
238
        }
 
239
 
 
240
        {
 
241
            WMatrix< double > mat( 4, 4 );
 
242
            mat.makeIdentity();
 
243
            mat( 0, 0 ) = 2.2;
 
244
            mat( 1, 1 ) = 3.3;
 
245
            mat( 2, 2 ) = 4.4;
 
246
            mat( 0, 3 ) = 1.0;
 
247
            mat( 1, 3 ) = 2.0;
 
248
            mat( 2, 3 ) = 0.5;
 
249
 
 
250
            WGridTransformOrtho t( mat );
 
251
 
 
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 );
 
254
        }
 
255
        {
 
256
            WMatrix< double > mat( 4, 4 );
 
257
            mat.makeIdentity();
 
258
            mat( 0, 0 ) = 2.0;
 
259
            mat( 1, 0 ) = 2.0;
 
260
            mat( 1, 1 ) = 3.0;
 
261
            mat( 0, 1 ) = -3.0;
 
262
            mat( 2, 2 ) = 4.4;
 
263
            mat( 0, 3 ) = 1.0;
 
264
            mat( 1, 3 ) = 2.0;
 
265
            mat( 2, 3 ) = 0.5;
 
266
 
 
267
            WGridTransformOrtho t( mat );
 
268
 
 
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 );
 
273
        }
 
274
    }
 
275
 
 
276
private:
 
277
    /**
 
278
     * Compares two vectors, element by element.
 
279
     *
 
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.
 
283
     */
 
284
    void compareVectors( WVector3d const& v1, WVector3d const& v2, double delta ) const
 
285
    {
 
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 );
 
289
    }
 
290
};
 
291
 
 
292
#endif  // WGRIDTRANSFORMORTHO_TEST_H