DLG4::VolumeBuilders
A fluent interface for Geant4 geometry definition.
Loading...
Searching...
No Matches
VolumeBuilderTypes.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 VOLUMEBUILDERTYPES_HH
9#define VOLUMEBUILDERTYPES_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
20namespace DLG4::VolumeBuilders {
21 // Base template alias
22 template <typename T>
24 class ISolidBuilder;
26 class IVolumeBuilder;
27 template <typename T>
28 class VolumeBuilder;
30 class RZBuilder;
31 class BoxBuilder;
32 class FromG4VSolid;
33 template <typename T>
34 class StructureBuilder;
36 class Assembly;
37
43
49
64
67
70
73
78
80
87 using BuilderViewList = std::vector<BuilderView>;
88
95 using StructureViewList = std::vector<StructureView>;
96
97 // For the template base class
98 template <typename U>
100
101 template <typename U>
103
104 using UnitlessG4Transform3D = G4Transform3D;
105 using Unitless3Vec = G4ThreeVector;
111 class Unit3Vec {
112 public:
113 double x, y, z;
114 std::optional<double> units;
115
116 // 3-value constructor - no units specified, raw values
117 Unit3Vec(double x, double y, double z) : x(x), y(y), z(z), units(std::nullopt) {
118 }
119
120 // 4-value constructor - units specified, scale the values
121 Unit3Vec(double u, double x, double y, double z) : x(x), y(y), z(z), units(u) {
122 }
123
124 Unit3Vec(double u, const Unitless3Vec &vec) :
125 x(vec.getX()), y(vec.getY()), z(vec.getZ()), units(u) {
126 }
127
128 [[nodiscard]] G4ThreeVector apply_units(const double dflt_unit) const {
129 auto vec = G4ThreeVector(0, 0, 0);
130 auto unit = this->units.value_or(dflt_unit);
131 vec.setX(this->x * unit);
132 vec.setY(this->y * unit);
133 vec.setZ(this->z * unit);
134 return vec;
135 }
136 };
137
138 template <typename T>
139 std::shared_ptr<T> shared_mutable_this(const std::enable_shared_from_this<T> *obj) {
140 // Call shared_from_this() (returns shared_ptr<const T> if obj is const)
141 auto sp_const = obj->shared_from_this();
142
143 // Cast away constness safely
144 return std::const_pointer_cast<std::remove_const_t<T>>(sp_const);
145 }
146}
147#endif //VOLUMEBUILDERTYPES_HH
A type-erased (data shared view) view of a builder or assembly, ie a "structure.".
Definition Assembly.hh:46
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:132
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)
Unit3Vec(double x, double y, double z)
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.
A wrapper for std::shared_ptr that allows and facilitates many implicit(i) type conversions.
std::shared_ptr< T > shared_mutable_this(const std::enable_shared_from_this< T > *obj)
std::vector< StructureView > StructureViewList
a user type to hold many structures
G4Transform3D UnitlessG4Transform3D
std::vector< BuilderView > BuilderViewList
a user type to hold many builders