DLG4::VolumeBuilders
A fluent interface for Geant4 geometry definition.
Loading...
Searching...
No Matches
VolumeBuildersTypes.hh
Go to the documentation of this file.
1#pragma once
2//
3// Created by Douglas S. Leonard on 6/18/25. All rights Reserved
4// See related files for license, if any is provided.
5//
6// Types for VolumeBuilder classes
7
8#ifndef VOLUMEBUILDERSTYPES_HH
9#define VOLUMEBUILDERSTYPES_HH
10#include <G4ThreeVector.hh>
11#include <memory>
12#include <optional>
13#include <vector>
14
16#include "i_shared_ptr.hh"
17
18#define ONCE_MUTABLE mutable // for linkable objects
19
21 // a shorthand out to the public namespace:
22 namespace VB=DLG4::VolumeBuilders;
23 using namespace VB;
24
25 // Base template alias
26 template <typename T>
28 class ISolidBuilder;
30 class IVolumeBuilder;
31 template <typename T>
32 class VolumeBuilder;
34 class RZBuilder;
35 class BoxBuilder;
36 class FromG4VSolid;
37 template <typename T>
38 class StructureBuilder;
40 class Assembly;
41
47
53
68
71
74
77
82
84
91 using BuilderViewList = std::vector<BuilderView>;
92
99 using StructureViewList = std::vector<StructureView>;
100
101 // For the template base class
102 template <typename U>
104
105 template <typename U>
107
108 using UnitlessG4Transform3D = G4Transform3D;
109 using Unitless3Vec = G4ThreeVector;
115 class Unit3Vec {
116 public:
117 double x, y, z;
118 std::optional<double> units;
119
120 // 3-value constructor - no units specified, raw values
121 Unit3Vec(double x, double y, double z) : x(x), y(y), z(z), units(std::nullopt) {
122 }
123
124 // 4-value constructor - units specified, scale the values
125 Unit3Vec(double u, double x, double y, double z) : x(x), y(y), z(z), units(u) {
126 }
127
128 Unit3Vec(double u, const Unitless3Vec &vec) :
129 x(vec.getX()), y(vec.getY()), z(vec.getZ()), units(u) {
130 }
131
132 [[nodiscard]] G4ThreeVector apply_units(const double dflt_unit) const {
133 auto vec = G4ThreeVector(0, 0, 0);
134 auto unit = this->units.value_or(dflt_unit);
135 vec.setX(this->x * unit);
136 vec.setY(this->y * unit);
137 vec.setZ(this->z * unit);
138 return vec;
139 }
140 };
141
142 template <typename T>
143 std::shared_ptr<T> shared_mutable_this(const std::enable_shared_from_this<T> *obj) {
144 // Call shared_from_this() (returns shared_ptr<const T> if obj is const)
145 auto sp_const = obj->shared_from_this();
146
147 // Cast away constness safely
148 return std::const_pointer_cast<std::remove_const_t<T>>(sp_const);
149 }
150}
151
152//Export names for API usage/tab-completion.
153namespace DLG4::VolumeBuilders {
160
166 using _internals_::Unit3Vec;
168}
169
171 using ::DLG4::VolumeBuilders::_internals_::RZBuilder;
172 using ::DLG4::VolumeBuilders::_internals_::VolumeBuilder;
173 using ::DLG4::VolumeBuilders::_internals_::BoxBuilder;
174 using ::DLG4::VolumeBuilders::_internals_::FromG4VSolid;
175 using ::DLG4::VolumeBuilders::_internals_::Assembly;
176 using ::DLG4::VolumeBuilders::_internals_::StructureBuilder;
177 using ::DLG4::VolumeBuilders::_internals_::VolumeBuilderReference;
178 using ::DLG4::VolumeBuilders::_internals_::StructureBuilderReference;
179}
180#endif //VOLUMEBUILDERSTYPES_HH
A type-erased (data shared view) view of a builder or assembly, ie a "structure.".
Definition Assembly.hh:38
Builder class for simple Box solids.
A solid buider class that just wrap an existing G4VSolid.
a non-fluent polymorphic class to access the derived solid-builder from a base reference: This gets u...
Builder class for RZ mult-plane defined solids.
Definition RZBuilder.hh:131
A type-erased (data shared view) view of a builder or assembly, ie a "structure.".
A type-erased (data shared view) view of a builder or assembly, ie a "structure.".
A 3D vector that carries its own unit information.
Unit3Vec(double u, const Unitless3Vec &vec)
G4ThreeVector apply_units(const double dflt_unit) const
Unit3Vec(double u, double x, double y, double z)
A polymorphic, type-erased builder referencing any specialized builder.
VolumeBuilder: Common functionality for volume builder classes.
SharedPtr< FromG4VSolid > FromG4VSolidPtr
std::shared_ptr< T > shared_mutable_this(const std::enable_shared_from_this< T > *obj)
SharedPtr< VolumeBuilderReference > BuilderView
Common interface for all volume builder types.
std::vector< StructureView > StructureViewList
a user type to hold many structures
std::vector< BuilderView > BuilderViewList
a user type to hold many builders
SharedPtr< StructureBuilderReference > StructureView
Common interface for all structure types.