18 SceneBuilder<double> b;
19 const int sph = b.addLeaf(kSphere, {0.06});
20 const int shaft = b.addLeaf(kHollowCylinder, {0.03, 0.4, 0.03});
22 b.addLeaf(kBox, {0.12, 0.02, 0.03}, Transform<double>{Vec3<double>{0.13, 0, 0}});
23 const int stir = b.addUnion(shaft, blade);
24 const int ell = b.addLeaf(kEllipsoid, {0.09, 0.05, 0.04});
25 for (
int i = 0; i < 40; ++i)
26 b.addInstance(sph, Transform<double>{Vec3<double>{rng.u(0, 1), rng.u(0, 1), rng.u(0, 1)}});
27 const double a45 = 0.7853981633974483;
28 b.addInstance(stir, Transform<double>{Vec3<double>{0.5, 0.5, 0.5},
29 Quat<double>{0, std::sin(a45), 0, std::cos(a45)}, 1.2});
30 b.addInstance(ell, Transform<double>{Vec3<double>{0.2, 0.7, 0.3}});
31 const SceneView<double>
sv =
b.view();
32 for (
bool periodic : {
true,
false}) {
33 const PeriodicBox<double>
box{1.0, 1.0, 1.0,
periodic};
34 CandidateGrid<double>
g = buildSceneCandidateGrid(sv, {0, 0, 0}, {1, 1, 1},
box);
35 const auto gv =
g.view();
36 const double* br =
g.instBoundR.data();
38 for (
int t = 0;
t < 60000; ++
t) {
39 const Vec3<double>
p{
rng.u(-0.2, 1.2),
rng.u(-0.2, 1.2),
rng.u(-0.2, 1.2)};
40 const double ref = evalScenePeriodic(sv, p, box, br);
41 const double got = evalSceneGrid(sv, p, box, gv, br);
44 const long bin = gv.binOf(p);
45 std::printf(
"[%s] p=(%.6f,%.6f,%.6f) ref=%.12g got=%.12g bin=%ld list=[",
46 periodic ?
"per" :
"open",
p.
x,
p.
y,
p.
z,
ref, got, bin);
48 for (
int k = gv.offsets[bin];
k < gv.offsets[bin + 1]; ++
k)
49 std::printf(
"%d ", gv.items[k]);
54 for (
int i = 0;
i <
sv.instanceCount; ++
i) {
55 const double d = evalInstancePeriodic(sv, i, p, box, br[i]);
61 std::printf(
" argmin=%d dist=%.12g boundR[argmin]=%.4f\n", win, best, br[win]);
66 std::printf(
"%s: %d/60000 mismatches\n", periodic ?
"periodic" :
"open", bad);