forked from celeritas-project/celeritas
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CsgUnitBuilder.cc
119 lines (100 loc) · 3.47 KB
/
CsgUnitBuilder.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
//----------------------------------*-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 orange/orangeinp/detail/CsgUnitBuilder.cc
//---------------------------------------------------------------------------//
#include "CsgUnitBuilder.hh"
namespace celeritas
{
namespace orangeinp
{
namespace detail
{
//---------------------------------------------------------------------------//
/*!
* Set a bounding box for a node.
*/
void CsgUnitBuilder::set_bbox(NodeId n, BBox const& bbox)
{
CELER_EXPECT(n < unit_->bboxes.size());
CELER_EXPECT(!unit_->bboxes[n.unchecked_get()]);
unit_->bboxes[n.unchecked_get()] = bbox;
}
//---------------------------------------------------------------------------//
/*!
* Mark a CSG node as a volume of real space.
*/
LocalVolumeId CsgUnitBuilder::insert_volume(NodeId n)
{
CELER_EXPECT(n < unit_->tree.size());
LocalVolumeId result{static_cast<size_type>(unit_->volumes.size())};
unit_->volumes.push_back(n);
unit_->fills.resize(unit_->volumes.size());
CELER_ENSURE(*unit_);
return result;
}
//---------------------------------------------------------------------------//
/*!
* Fill a volume node with a material.
*/
void CsgUnitBuilder::fill_volume(LocalVolumeId v, MaterialId m)
{
CELER_EXPECT(v < unit_->fills.size());
CELER_EXPECT(m);
unit_->fills[v.unchecked_get()] = m;
}
//---------------------------------------------------------------------------//
/*!
* Fill a volume node with a daughter.
*/
void CsgUnitBuilder::fill_volume(LocalVolumeId v,
UniverseId u,
VariantTransform&& vt)
{
CELER_EXPECT(v < unit_->fills.size());
CELER_EXPECT(!is_filled(unit_->fills[v.unchecked_get()]));
CELER_EXPECT(u);
Daughter new_daughter;
new_daughter.universe_id = u;
new_daughter.transform_id
= TransformId{static_cast<size_type>(unit_->transforms.size())};
// Add transform
unit_->transforms.push_back(std::move(vt));
// Save fill
unit_->fills[v.unchecked_get()] = std::move(new_daughter);
CELER_ENSURE(is_filled(unit_->fills[v.unchecked_get()]));
}
//---------------------------------------------------------------------------//
/*!
* Set an exterior node.
*
* This should be called only once (but this could be relaxed if needed).
*/
void CsgUnitBuilder::set_exterior(NodeId n)
{
CELER_EXPECT(n < unit_->tree.size());
CELER_EXPECT(!unit_->exterior);
unit_->exterior = n;
}
//---------------------------------------------------------------------------//
/*!
* Get a variant surface from a node ID.
*/
VariantSurface const& CsgUnitBuilder::get_surface_impl(NodeId nid) const
{
CELER_EXPECT(nid < unit_->tree.size());
using SurfaceNode = ::celeritas::csg::Surface;
// Get the surface ID from the tree
auto const& node = unit_->tree[nid];
CELER_ASSUME(std::holds_alternative<SurfaceNode>(node));
LocalSurfaceId lsid = std::get<SurfaceNode>(node).id;
// Get the variant surfaces from the unit
CELER_EXPECT(lsid < unit_->surfaces.size());
return unit_->surfaces[lsid.unchecked_get()];
}
//---------------------------------------------------------------------------//
} // namespace detail
} // namespace orangeinp
} // namespace celeritas