File: TestRay.cc

package info (click to toggle)
openvdb 5.2.0-5
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 8,132 kB
  • sloc: cpp: 110,785; ansic: 5,195; makefile: 845; python: 518
file content (494 lines) | stat: -rw-r--r-- 19,773 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
///////////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2012-2018 DreamWorks Animation LLC
//
// All rights reserved. This software is distributed under the
// Mozilla Public License 2.0 ( http://www.mozilla.org/MPL/2.0/ )
//
// Redistributions of source code must retain the above copyright
// and license notice and the following restrictions and disclaimer.
//
// *     Neither the name of DreamWorks Animation nor the names of
// its contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// IN NO EVENT SHALL THE COPYRIGHT HOLDERS' AND CONTRIBUTORS' AGGREGATE
// LIABILITY FOR ALL CLAIMS REGARDLESS OF THEIR BASIS EXCEED US$250.00.
//
///////////////////////////////////////////////////////////////////////////

#include <cppunit/extensions/HelperMacros.h>
#include <openvdb/Exceptions.h>
#include <openvdb/openvdb.h>
#include <openvdb/math/Ray.h>
#include <openvdb/math/DDA.h>
#include <openvdb/math/BBox.h>
#include <openvdb/Types.h>
#include <openvdb/math/Transform.h>
#include <openvdb/tools/LevelSetSphere.h>

#define ASSERT_DOUBLES_EXACTLY_EQUAL(expected, actual) \
    CPPUNIT_ASSERT_DOUBLES_EQUAL((expected), (actual), /*tolerance=*/0.0);

#define ASSERT_DOUBLES_APPROX_EQUAL(expected, actual) \
    CPPUNIT_ASSERT_DOUBLES_EQUAL((expected), (actual), /*tolerance=*/1.e-6);

class TestRay : public CppUnit::TestCase
{
public:
    CPPUNIT_TEST_SUITE(TestRay);
    CPPUNIT_TEST(testInfinity);
    CPPUNIT_TEST(testRay);
    CPPUNIT_TEST(testTimeSpan);
    CPPUNIT_TEST(testDDA);
    CPPUNIT_TEST_SUITE_END();

    void testInfinity();
    void testRay();
    void testTimeSpan();
    void testDDA();
};

CPPUNIT_TEST_SUITE_REGISTRATION(TestRay);

//  the Ray class makes use of infinity=1/0 so we test for it
void
TestRay::testInfinity()
{
    // This code generates compiler warnings which is why it's not
    // enabled by default.
    /*
    const double one=1, zero = 0, infinity = one / zero;
    CPPUNIT_ASSERT_DOUBLES_EQUAL( infinity , infinity,0);//not a NAN
    CPPUNIT_ASSERT_DOUBLES_EQUAL( infinity , infinity+1,0);//not a NAN
    CPPUNIT_ASSERT_DOUBLES_EQUAL( infinity , infinity*10,0);//not a NAN
    CPPUNIT_ASSERT( zero <   infinity);
    CPPUNIT_ASSERT( zero >  -infinity);
    CPPUNIT_ASSERT_DOUBLES_EQUAL( zero ,  one/infinity,0);
    CPPUNIT_ASSERT_DOUBLES_EQUAL( zero , -one/infinity,0);
    CPPUNIT_ASSERT_DOUBLES_EQUAL( infinity  ,  one/zero,0);
    CPPUNIT_ASSERT_DOUBLES_EQUAL(-infinity  , -one/zero,0);

    std::cerr << "inf:        "   << infinity << "\n";
    std::cerr << "1 / inf:    "   << one / infinity << "\n";
    std::cerr << "1 / (-inf): "   << one / (-infinity) << "\n";
    std::cerr << " inf * 0:   "   << infinity * 0 << "\n";
    std::cerr << "-inf * 0:   "   << (-infinity) * 0 << "\n";
    std::cerr << "(inf):      "   << (bool)(infinity) << "\n";
    std::cerr << "inf == inf: "   << (infinity == infinity) << "\n";
    std::cerr << "inf > 0:    "   << (infinity > 0) << "\n";
    std::cerr << "-inf > 0:   "   << ((-infinity) > 0) << "\n";
    */
}

void TestRay::testRay()
{
    using namespace openvdb;
    typedef double             RealT;
    typedef math::Ray<RealT>   RayT;
    typedef RayT::Vec3T        Vec3T;
    typedef math::BBox<Vec3T>  BBoxT;

    {//default constructor
        RayT ray;
        CPPUNIT_ASSERT(ray.eye() == Vec3T(0,0,0));
        CPPUNIT_ASSERT(ray.dir() == Vec3T(1,0,0));
        ASSERT_DOUBLES_APPROX_EQUAL( math::Delta<RealT>::value(), ray.t0());
        ASSERT_DOUBLES_APPROX_EQUAL( std::numeric_limits<RealT>::max(), ray.t1());
    }

    {// simple construction

        Vec3T eye(1.5,1.5,1.5), dir(1.5,1.5,1.5); dir.normalize();
        RealT t0=0.1, t1=12589.0;

        RayT ray(eye, dir, t0, t1);
        CPPUNIT_ASSERT(ray.eye()==eye);
        CPPUNIT_ASSERT(ray.dir()==dir);
        ASSERT_DOUBLES_APPROX_EQUAL( t0, ray.t0());
        ASSERT_DOUBLES_APPROX_EQUAL( t1, ray.t1());
    }

    {// test transformation
        math::Transform::Ptr xform = math::Transform::createLinearTransform();

        xform->preRotate(M_PI, math::Y_AXIS );
        xform->postTranslate(math::Vec3d(1, 2, 3));
        xform->preScale(Vec3R(0.1, 0.2, 0.4));

        Vec3T eye(9,1,1), dir(1,2,0);
        dir.normalize();
        RealT t0=0.1, t1=12589.0;

        RayT ray0(eye, dir, t0, t1);
        CPPUNIT_ASSERT( ray0.test(t0));
        CPPUNIT_ASSERT( ray0.test(t1));
        CPPUNIT_ASSERT( ray0.test(0.5*(t0+t1)));
        CPPUNIT_ASSERT(!ray0.test(t0-1));
        CPPUNIT_ASSERT(!ray0.test(t1+1));
        //std::cerr << "Ray0: " << ray0 << std::endl;
        RayT ray1 = ray0.applyMap( *(xform->baseMap()) );
        //std::cerr << "Ray1: " << ray1 << std::endl;
        RayT ray2 = ray1.applyInverseMap( *(xform->baseMap()) );
        //std::cerr << "Ray2: " << ray2 << std::endl;

        ASSERT_DOUBLES_APPROX_EQUAL( eye[0], ray2.eye()[0]);
        ASSERT_DOUBLES_APPROX_EQUAL( eye[1], ray2.eye()[1]);
        ASSERT_DOUBLES_APPROX_EQUAL( eye[2], ray2.eye()[2]);

        ASSERT_DOUBLES_APPROX_EQUAL( dir[0], ray2.dir()[0]);
        ASSERT_DOUBLES_APPROX_EQUAL( dir[1], ray2.dir()[1]);
        ASSERT_DOUBLES_APPROX_EQUAL( dir[2], ray2.dir()[2]);

        ASSERT_DOUBLES_APPROX_EQUAL( dir[0], 1.0/ray2.invDir()[0]);
        ASSERT_DOUBLES_APPROX_EQUAL( dir[1], 1.0/ray2.invDir()[1]);
        ASSERT_DOUBLES_APPROX_EQUAL( dir[2], 1.0/ray2.invDir()[2]);

        ASSERT_DOUBLES_APPROX_EQUAL( t0, ray2.t0());
        ASSERT_DOUBLES_APPROX_EQUAL( t1, ray2.t1());
    }

    {// test transformation

        // This is the index to world transform
        math::Transform::Ptr xform = math::Transform::createLinearTransform();
        xform->postRotate(M_PI, math::Y_AXIS );
        xform->postTranslate(math::Vec3d(1, 2, 3));
        xform->postScale(Vec3R(0.1, 0.1, 0.1));//voxel size

        // Define a ray in world space
        Vec3T eye(9,1,1), dir(1,2,0);
        dir.normalize();
        RealT t0=0.1, t1=12589.0;
        RayT ray0(eye, dir, t0, t1);
        //std::cerr << "\nWorld Ray0: " << ray0 << std::endl;
        CPPUNIT_ASSERT( ray0.test(t0));
        CPPUNIT_ASSERT( ray0.test(t1));
        CPPUNIT_ASSERT( ray0.test(0.5*(t0+t1)));
        CPPUNIT_ASSERT(!ray0.test(t0-1));
        CPPUNIT_ASSERT(!ray0.test(t1+1));
        Vec3T xyz0[3] = {ray0.start(), ray0.mid(), ray0.end()};

        // Transform the ray to index space
        RayT ray1 = ray0.applyInverseMap( *(xform->baseMap()) );
        //std::cerr << "\nIndex Ray1: " << ray1 << std::endl;
        Vec3T xyz1[3] = {ray1.start(), ray1.mid(), ray1.end()};

        for (int i=0; i<3; ++i) {
            Vec3T pos = xform->baseMap()->applyMap(xyz1[i]);
            //std::cerr << "world0 ="<<xyz0[i] << " transformed index="<< pos << std::endl;
            for (int j=0; j<3; ++j) ASSERT_DOUBLES_APPROX_EQUAL(xyz0[i][j], pos[j]);
        }

        // Transform the ray back to world pace
        RayT ray2 = ray1.applyMap( *(xform->baseMap()) );
        //std::cerr << "\nWorld Ray2: " << ray2 << std::endl;

        ASSERT_DOUBLES_APPROX_EQUAL( eye[0], ray2.eye()[0]);
        ASSERT_DOUBLES_APPROX_EQUAL( eye[1], ray2.eye()[1]);
        ASSERT_DOUBLES_APPROX_EQUAL( eye[2], ray2.eye()[2]);

        ASSERT_DOUBLES_APPROX_EQUAL( dir[0], ray2.dir()[0]);
        ASSERT_DOUBLES_APPROX_EQUAL( dir[1], ray2.dir()[1]);
        ASSERT_DOUBLES_APPROX_EQUAL( dir[2], ray2.dir()[2]);

        ASSERT_DOUBLES_APPROX_EQUAL( dir[0], 1.0/ray2.invDir()[0]);
        ASSERT_DOUBLES_APPROX_EQUAL( dir[1], 1.0/ray2.invDir()[1]);
        ASSERT_DOUBLES_APPROX_EQUAL( dir[2], 1.0/ray2.invDir()[2]);

        ASSERT_DOUBLES_APPROX_EQUAL( t0, ray2.t0());
        ASSERT_DOUBLES_APPROX_EQUAL( t1, ray2.t1());

        Vec3T xyz2[3] = {ray0.start(), ray0.mid(), ray0.end()};

        for (int i=0; i<3; ++i) {
            //std::cerr << "world0 ="<<xyz0[i] << " world2 ="<< xyz2[i] << std::endl;
            for (int j=0; j<3; ++j) ASSERT_DOUBLES_APPROX_EQUAL(xyz0[i][j], xyz2[i][j]);
        }
    }

    {// test bbox intersection

        const Vec3T eye( 2.0, 1.0, 1.0), dir(-1.0, 2.0, 3.0);
        RayT ray(eye, dir);
        RealT t0=0, t1=0;


        // intersects the two faces of the box perpendicular to the y-axis!
        CPPUNIT_ASSERT(ray.intersects(CoordBBox(Coord(0, 2, 2), Coord(2, 4, 6)), t0, t1));
        ASSERT_DOUBLES_APPROX_EQUAL( 0.5, t0);
        ASSERT_DOUBLES_APPROX_EQUAL( 1.5, t1);
        ASSERT_DOUBLES_APPROX_EQUAL( ray(0.5)[1], 2);//lower y component of intersection
        ASSERT_DOUBLES_APPROX_EQUAL( ray(1.5)[1], 4);//higher y component of intersection

        // intersects the lower edge anlong the z-axis of the box
        CPPUNIT_ASSERT(ray.intersects(BBoxT(Vec3T(1.5, 2.0, 2.0), Vec3T(4.5, 4.0, 6.0)), t0, t1));
        ASSERT_DOUBLES_APPROX_EQUAL( 0.5, t0);
        ASSERT_DOUBLES_APPROX_EQUAL( 0.5, t1);
        ASSERT_DOUBLES_APPROX_EQUAL( ray(0.5)[0], 1.5);//lower y component of intersection
        ASSERT_DOUBLES_APPROX_EQUAL( ray(0.5)[1], 2.0);//higher y component of intersection

        // no intersections
        CPPUNIT_ASSERT(!ray.intersects(CoordBBox(Coord(4, 2, 2), Coord(6, 4, 6))));
    }

    {// test sphere intersection
        const Vec3T dir(-1.0, 2.0, 3.0);
        const Vec3T eye( 2.0, 1.0, 1.0);
        RayT ray(eye, dir);
        RealT t0=0, t1=0;

        // intersects twice - second intersection exits sphere in lower y-z-plane
        Vec3T center(2.0,3.0,4.0);
        RealT radius = 1.0f;
        CPPUNIT_ASSERT(ray.intersects(center, radius, t0, t1));
        CPPUNIT_ASSERT(t0 < t1);
        ASSERT_DOUBLES_APPROX_EQUAL( 1.0, t1);
        ASSERT_DOUBLES_APPROX_EQUAL(ray(t1)[1], center[1]);
        ASSERT_DOUBLES_APPROX_EQUAL(ray(t1)[2], center[2]);
        ASSERT_DOUBLES_APPROX_EQUAL((ray(t0)-center).length()-radius, 0);
        ASSERT_DOUBLES_APPROX_EQUAL((ray(t1)-center).length()-radius, 0);

        // no intersection
        center = Vec3T(3.0,3.0,4.0);
        radius = 1.0f;
        CPPUNIT_ASSERT(!ray.intersects(center, radius, t0, t1));
    }

    {// test bbox clip
        const Vec3T dir(-1.0, 2.0, 3.0);
        const Vec3T eye( 2.0, 1.0, 1.0);
        RealT t0=0.1, t1=12589.0;
        RayT ray(eye, dir, t0, t1);

        // intersects the two faces of the box perpendicular to the y-axis!
        CPPUNIT_ASSERT(ray.clip(CoordBBox(Coord(0, 2, 2), Coord(2, 4, 6))));
        ASSERT_DOUBLES_APPROX_EQUAL( 0.5, ray.t0());
        ASSERT_DOUBLES_APPROX_EQUAL( 1.5, ray.t1());
        ASSERT_DOUBLES_APPROX_EQUAL( ray(0.5)[1], 2);//lower y component of intersection
        ASSERT_DOUBLES_APPROX_EQUAL( ray(1.5)[1], 4);//higher y component of intersection

        ray.reset(eye, dir, t0, t1);
        // intersects the lower edge anlong the z-axis of the box
        CPPUNIT_ASSERT(ray.clip(BBoxT(Vec3T(1.5, 2.0, 2.0), Vec3T(4.5, 4.0, 6.0))));
        ASSERT_DOUBLES_APPROX_EQUAL( 0.5, ray.t0());
        ASSERT_DOUBLES_APPROX_EQUAL( 0.5, ray.t1());
        ASSERT_DOUBLES_APPROX_EQUAL( ray(0.5)[0], 1.5);//lower y component of intersection
        ASSERT_DOUBLES_APPROX_EQUAL( ray(0.5)[1], 2.0);//higher y component of intersection

        ray.reset(eye, dir, t0, t1);
        // no intersections
        CPPUNIT_ASSERT(!ray.clip(CoordBBox(Coord(4, 2, 2), Coord(6, 4, 6))));
        ASSERT_DOUBLES_APPROX_EQUAL( t0, ray.t0());
        ASSERT_DOUBLES_APPROX_EQUAL( t1, ray.t1());
    }

    {// test plane intersection

        const Vec3T dir(-1.0, 0.0, 0.0);
        const Vec3T eye( 0.5, 4.7,-9.8);
        RealT t0=1.0, t1=12589.0;
        RayT ray(eye, dir, t0, t1);

        Real t = 0.0;
        CPPUNIT_ASSERT(!ray.intersects(Vec3T( 1.0, 0.0, 0.0), 4.0, t));
        CPPUNIT_ASSERT(!ray.intersects(Vec3T(-1.0, 0.0, 0.0),-4.0, t));
        CPPUNIT_ASSERT( ray.intersects(Vec3T( 1.0, 0.0, 0.0),-4.0, t));
        ASSERT_DOUBLES_APPROX_EQUAL(4.5, t);
        CPPUNIT_ASSERT( ray.intersects(Vec3T(-1.0, 0.0, 0.0), 4.0, t));
        ASSERT_DOUBLES_APPROX_EQUAL(4.5, t);
        CPPUNIT_ASSERT(!ray.intersects(Vec3T( 1.0, 0.0, 0.0),-0.4, t));
    }

    {// test plane intersection

        const Vec3T dir( 0.0, 1.0, 0.0);
        const Vec3T eye( 4.7, 0.5,-9.8);
        RealT t0=1.0, t1=12589.0;
        RayT ray(eye, dir, t0, t1);

        Real t = 0.0;
        CPPUNIT_ASSERT(!ray.intersects(Vec3T( 0.0,-1.0, 0.0), 4.0, t));
        CPPUNIT_ASSERT(!ray.intersects(Vec3T( 0.0, 1.0, 0.0),-4.0, t));
        CPPUNIT_ASSERT( ray.intersects(Vec3T( 0.0, 1.0, 0.0), 4.0, t));
        ASSERT_DOUBLES_APPROX_EQUAL(3.5, t);
        CPPUNIT_ASSERT( ray.intersects(Vec3T( 0.0,-1.0, 0.0),-4.0, t));
        ASSERT_DOUBLES_APPROX_EQUAL(3.5, t);
        CPPUNIT_ASSERT(!ray.intersects(Vec3T( 1.0, 0.0, 0.0), 0.4, t));
    }

}

void TestRay::testTimeSpan()
{
    using namespace openvdb;
    typedef double             RealT;
    typedef math::Ray<RealT>::TimeSpan   TimeSpanT;
    TimeSpanT t(2.0, 5.0);
    ASSERT_DOUBLES_EXACTLY_EQUAL(2.0, t.t0);
    ASSERT_DOUBLES_EXACTLY_EQUAL(5.0, t.t1);
    ASSERT_DOUBLES_APPROX_EQUAL(3.5, t.mid());
    CPPUNIT_ASSERT(t.valid());
    t.set(-1, -1);
    CPPUNIT_ASSERT(!t.valid());
    t.scale(5);
    ASSERT_DOUBLES_EXACTLY_EQUAL(-5.0, t.t0);
    ASSERT_DOUBLES_EXACTLY_EQUAL(-5.0, t.t1);
    ASSERT_DOUBLES_APPROX_EQUAL(-5.0, t.mid());
}

void TestRay::testDDA()
{
    using namespace openvdb;
    typedef math::Ray<double>  RayType;

    {
        typedef math::DDA<RayType,3+4+5> DDAType;
        const RayType::Vec3T dir( 1.0, 0.0, 0.0);
        const RayType::Vec3T eye(-1.0, 0.0, 0.0);
        const RayType ray(eye, dir);
        //std::cerr << ray << std::endl;
        DDAType dda(ray);
        ASSERT_DOUBLES_APPROX_EQUAL(math::Delta<double>::value(), dda.time());
        ASSERT_DOUBLES_APPROX_EQUAL(1.0, dda.next());
        //dda.print();
        dda.step();
        ASSERT_DOUBLES_APPROX_EQUAL(1.0, dda.time());
        ASSERT_DOUBLES_APPROX_EQUAL(4096+1.0, dda.next());
        //dda.print();
    }

    {// Check for the notorious +-0 issue!
        typedef math::DDA<RayType,3> DDAType;

        //std::cerr << "\nPositive zero ray" << std::endl;
        const RayType::Vec3T dir1(1.0, 0.0, 0.0);
        const RayType::Vec3T eye1(2.0, 0.0, 0.0);
        const RayType ray1(eye1, dir1);
        //std::cerr << ray1 << std::endl;
        DDAType dda1(ray1);
        //dda1.print();
        dda1.step();
        //dda1.print();

        //std::cerr << "\nNegative zero ray" << std::endl;
        const RayType::Vec3T dir2(1.0,-0.0,-0.0);
        const RayType::Vec3T eye2(2.0, 0.0, 0.0);
        const RayType ray2(eye2, dir2);
        //std::cerr << ray2 << std::endl;
        DDAType dda2(ray2);
        //dda2.print();
        dda2.step();
        //dda2.print();

        //std::cerr << "\nNegative epsilon ray" << std::endl;
        const RayType::Vec3T dir3(1.0,-1e-9,-1e-9);
        const RayType::Vec3T eye3(2.0, 0.0, 0.0);
        const RayType ray3(eye3, dir3);
        //std::cerr << ray3 << std::endl;
        DDAType dda3(ray3);
        //dda3.print();
        dda3.step();
        //dda3.print();

        //std::cerr << "\nPositive epsilon ray" << std::endl;
        const RayType::Vec3T dir4(1.0,-1e-9,-1e-9);
        const RayType::Vec3T eye4(2.0, 0.0, 0.0);
        const RayType ray4(eye3, dir4);
        //std::cerr << ray4 << std::endl;
        DDAType dda4(ray4);
        //dda4.print();
        dda4.step();
        //dda4.print();

        ASSERT_DOUBLES_APPROX_EQUAL(dda1.time(), dda2.time());
        ASSERT_DOUBLES_APPROX_EQUAL(dda2.time(), dda3.time());
        ASSERT_DOUBLES_APPROX_EQUAL(dda3.time(), dda4.time());
        ASSERT_DOUBLES_APPROX_EQUAL(dda1.next(), dda2.next());
        ASSERT_DOUBLES_APPROX_EQUAL(dda2.next(), dda3.next());
        ASSERT_DOUBLES_APPROX_EQUAL(dda3.next(), dda4.next());
    }

    {// test voxel traversal along both directions of each axis
        typedef math::DDA<RayType> DDAType;
        const RayType::Vec3T eye( 0, 0, 0);
        for (int s = -1; s<=1; s+=2) {
            for (int a = 0; a<3; ++a) {
                const int d[3]={s*(a==0), s*(a==1), s*(a==2)};
                const RayType::Vec3T dir(d[0], d[1], d[2]);
                RayType ray(eye, dir);
                DDAType dda(ray);
                //std::cerr << "\nray: "<<ray<<std::endl;
                //dda.print();
                for (int i=1; i<=10; ++i) {
                    //std::cerr << "i="<<i<<" voxel="<<dda.voxel()<<" time="<<dda.time()<<std::endl;
                    //CPPUNIT_ASSERT(dda.voxel()==Coord(i*d[0], i*d[1], i*d[2]));
                    CPPUNIT_ASSERT(dda.step());
                    ASSERT_DOUBLES_APPROX_EQUAL(i,dda.time());
                }
            }
        }
    }
    {// test Node traversal along both directions of each axis
        typedef math::DDA<RayType,3> DDAType;
        const RayType::Vec3T eye(0, 0, 0);

        for (int s = -1; s<=1; s+=2) {
            for (int a = 0; a<3; ++a) {
                const int d[3]={s*(a==0), s*(a==1), s*(a==2)};
                const RayType::Vec3T dir(d[0], d[1], d[2]);
                RayType ray(eye, dir);
                DDAType dda(ray);
                //std::cerr << "\nray: "<<ray<<std::endl;
                for (int i=1; i<=10; ++i) {
                    //std::cerr << "i="<<i<<" voxel="<<dda.voxel()<<" time="<<dda.time()<<std::endl;
                    //CPPUNIT_ASSERT(dda.voxel()==Coord(8*i*d[0],8*i*d[1],8*i*d[2]));
                    CPPUNIT_ASSERT(dda.step());
                    ASSERT_DOUBLES_APPROX_EQUAL(8*i,dda.time());
                }
            }
        }
    }

    {// test accelerated Node traversal along both directions of each axis
        typedef math::DDA<RayType,3> DDAType;
        const RayType::Vec3T eye(0, 0, 0);

        for (int s = -1; s<=1; s+=2) {
            for (int a = 0; a<3; ++a) {
                const int d[3]={s*(a==0), s*(a==1), s*(a==2)};
                const RayType::Vec3T dir(2*d[0], 2*d[1], 2*d[2]);
                RayType ray(eye, dir);
                DDAType dda(ray);
                //ASSERT_DOUBLES_APPROX_EQUAL(0.0, dda.time());
                //CPPUNIT_ASSERT(dda.voxel()==Coord(0,0,0));
                double next=0;
                //std::cerr << "\nray: "<<ray<<std::endl;
                for (int i=1; i<=10; ++i) {
                    //std::cerr << "i="<<i<<" voxel="<<dda.voxel()<<" time="<<dda.time()<<std::endl;
                    //CPPUNIT_ASSERT(dda.voxel()==Coord(8*i*d[0],8*i*d[1],8*i*d[2]));
                    CPPUNIT_ASSERT(dda.step());
                    ASSERT_DOUBLES_APPROX_EQUAL(4*i, dda.time());
                    if (i>1) ASSERT_DOUBLES_APPROX_EQUAL(dda.time(), next);
                    next = dda.next();
                }
            }
        }
    }

}

// Copyright (c) 2012-2018 DreamWorks Animation LLC
// All rights reserved. This software is distributed under the
// Mozilla Public License 2.0 ( http://www.mozilla.org/MPL/2.0/ )