forked from celeritas-project/celeritas
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Raytracer.test.cc
155 lines (133 loc) · 4.66 KB
/
Raytracer.test.cc
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
//----------------------------------*-C++-*----------------------------------//
// Copyright 2024 UT-Battelle, LLC, and other Celeritas developers.
// See the top-level COPYRIGHT file for details.
// SPDX-License-Identifier: (Apache-2.0 OR MIT)
//---------------------------------------------------------------------------//
//! \file geocel/rasterize/Raytracer.test.cc
//---------------------------------------------------------------------------//
#include "geocel/rasterize/Raytracer.hh"
#include <cmath>
#include "geocel/rasterize/Image.hh"
#include "celeritas_test.hh"
#include "../MockGeoTrackView.hh"
namespace celeritas
{
namespace test
{
//---------------------------------------------------------------------------//
int calc_id(MockGeoTrackView const& geo)
{
if (geo.is_outside())
return -1;
return static_cast<int>(geo.pos()[2]);
}
//---------------------------------------------------------------------------//
TEST(MockGeo, tracking)
{
MockGeoTrackView geo;
geo = GeoTrackInitializer{{0, 0, 5.25}, {0, 0, 1}};
EXPECT_EQ(5, geo.volume_id().get());
auto next_step = geo.find_next_step(2.0);
EXPECT_TRUE(next_step.boundary);
EXPECT_SOFT_EQ(0.75, next_step.distance);
geo.move_to_boundary();
EXPECT_EQ(5, geo.volume_id().get());
EXPECT_REAL_EQ(6.0, geo.pos()[2]);
geo.cross_boundary();
EXPECT_EQ(6, geo.volume_id().get());
next_step = geo.find_next_step(1.5);
EXPECT_TRUE(next_step.boundary);
EXPECT_SOFT_EQ(1.0, next_step.distance);
geo.move_to_boundary();
EXPECT_EQ(6, geo.volume_id().get());
geo.cross_boundary();
EXPECT_EQ(7, geo.volume_id().get());
next_step = geo.find_next_step(0.5);
EXPECT_FALSE(next_step.boundary);
EXPECT_SOFT_EQ(0.5, next_step.distance);
geo.move_internal(0.25);
next_step = geo.find_next_step(1.0);
EXPECT_TRUE(next_step.boundary);
EXPECT_SOFT_EQ(0.75, next_step.distance);
geo = GeoTrackInitializer{{0, 0, 4.75}, make_unit_vector(Real3{0, 0, -1})};
EXPECT_EQ(4, geo.volume_id().get());
next_step = geo.find_next_step(100.0);
EXPECT_TRUE(next_step.boundary);
EXPECT_SOFT_EQ(0.75, next_step.distance);
geo = GeoTrackInitializer{{0, 0, 9.75}, make_unit_vector(Real3{0, 4, -3})};
EXPECT_EQ(9, geo.volume_id().get());
next_step = geo.find_next_step(100.0);
EXPECT_TRUE(next_step.boundary);
EXPECT_SOFT_EQ(0.75 * 5.0 / 3.0, next_step.distance);
}
//---------------------------------------------------------------------------//
class RaytracerTest : public ::celeritas::test::Test
{
protected:
void SetUp() override {}
};
TEST_F(RaytracerTest, exact)
{
ImageInput inp;
inp.rightward = {0, 0, 1};
inp.lower_left = {0, 0, 32};
inp.upper_right = {0, 16, 160};
inp.vertical_pixels = 16;
inp.horizontal_divisor = 1;
// Start at {0, 10.5, 32} and move along +z
auto params = std::make_shared<ImageParams>(inp);
Image<MemSpace::host> img(params);
ImageLineView line{params->host_ref(), img.ref(), 5};
MockGeoTrackView geo;
EXPECT_EQ(0, geo.init_count());
Raytracer trace{geo, calc_id, line};
// Position doesn't change until the next pixel
EXPECT_EQ(32, trace(0));
EXPECT_EQ(1, geo.init_count());
EXPECT_VEC_SOFT_EQ((Real3{0, 10.5, 32}), geo.pos());
EXPECT_EQ(33, trace(1));
EXPECT_VEC_SOFT_EQ((Real3{0, 10.5, 33}), geo.pos());
EXPECT_EQ(1, geo.init_count());
EXPECT_EQ(40, trace(8));
EXPECT_EQ(2, geo.init_count());
}
TEST_F(RaytracerTest, offset)
{
ImageInput inp;
inp.rightward = {0, 0, 1};
inp.lower_left = {0, 0, 1.75};
inp.upper_right = {0, 1.0, 16.75};
inp.vertical_pixels = 1;
inp.horizontal_divisor = 1;
auto params = std::make_shared<ImageParams>(inp);
Image<MemSpace::host> img(params);
ImageLineView line{params->host_ref(), img.ref(), 0};
MockGeoTrackView geo;
Raytracer trace{geo, calc_id, line};
for (auto col : range(10))
{
EXPECT_EQ(col + 2, trace(col));
}
EXPECT_EQ(1, geo.init_count());
}
TEST_F(RaytracerTest, megapixels)
{
ImageInput inp;
inp.rightward = {0, 0, 1};
inp.lower_left = {0, 0, 1};
inp.upper_right = {0, 64, 64 * 8};
inp.vertical_pixels = 1;
inp.horizontal_divisor = 1;
auto params = std::make_shared<ImageParams>(inp);
Image<MemSpace::host> img(params);
ImageLineView line{params->host_ref(), img.ref(), 0};
MockGeoTrackView geo;
Raytracer trace{geo, calc_id, line};
EXPECT_EQ(1, trace(0));
EXPECT_EQ(1, geo.init_count());
EXPECT_EQ(65, trace(1));
EXPECT_EQ(2, geo.init_count());
}
//---------------------------------------------------------------------------//
} // namespace test
} // namespace celeritas