refactor: introduce PhysicalVolume class and update Geant scene hierarchy to use logical and physical volumes
This commit is contained in:
@@ -60,13 +60,12 @@ public:
|
||||
virtual G4VSolid* GetG4Solid() const { return nullptr; }
|
||||
|
||||
inline const char *GetName() const {
|
||||
return m_Logical ? m_Logical->GetName().c_str() : m_Name.c_str();
|
||||
return m_Name.c_str();
|
||||
}
|
||||
|
||||
template < typename Ar >
|
||||
void serialize(Ar &ar, const unsigned int version) {
|
||||
ar & HRP("Name", m_Name);
|
||||
ar & HRP("Material", m_Material);
|
||||
}
|
||||
|
||||
|
||||
@@ -90,16 +89,25 @@ public:
|
||||
LogicalVolume(const char *name);
|
||||
virtual ~LogicalVolume();
|
||||
|
||||
virtual G4VSolid* GetG4Solid() const { return nullptr; }
|
||||
virtual G4VSolid* GetG4Solid() const { return m_Solid ? m_Solid->GetG4Solid() : nullptr; }
|
||||
Solid* GetSolid() const { return m_Solid.Get(); }
|
||||
|
||||
inline const char *GetName() const {
|
||||
return m_Logical ? m_Logical->GetName().c_str() : m_Name.c_str();
|
||||
return m_Logical ? m_Logical->GetName().c_str() : m_Name.c_str();
|
||||
}
|
||||
|
||||
void SetSolid(Solid *solid) { m_Solid = solid; }
|
||||
void SetSolid(SmartPointer<Solid> solid) { m_Solid = solid; }
|
||||
void SetMaterial(Material *material) { m_Material = material; }
|
||||
void SetMaterial(SmartPointer<Material> material) { m_Material = material; }
|
||||
|
||||
G4LogicalVolume* GetG4LogicalVolume() const { return m_Logical; }
|
||||
|
||||
template < typename Ar >
|
||||
void serialize(Ar &ar, const unsigned int version) {
|
||||
ar & HRP("Name", m_Name);
|
||||
ar & HRP("Material", m_Material);
|
||||
ar & HRP("Solid", m_Solid);
|
||||
}
|
||||
|
||||
|
||||
@@ -108,7 +116,8 @@ public slots:
|
||||
|
||||
protected:
|
||||
std::string m_Name;
|
||||
Material *m_Material;
|
||||
SmartPointer<Material> m_Material;
|
||||
SmartPointer<Solid> m_Solid;
|
||||
|
||||
G4LogicalVolume *m_Logical;
|
||||
};
|
||||
@@ -116,6 +125,50 @@ protected:
|
||||
|
||||
|
||||
|
||||
class PhysicalVolume : public TRS {
|
||||
|
||||
uLibTypeMacro(PhysicalVolume, TRS)
|
||||
ULIB_SERIALIZE_ACCESS
|
||||
|
||||
public:
|
||||
|
||||
PhysicalVolume();
|
||||
PhysicalVolume(LogicalVolume *logical);
|
||||
PhysicalVolume(const char *name, LogicalVolume *logical);
|
||||
virtual ~PhysicalVolume();
|
||||
|
||||
LogicalVolume* GetLogical() const { return m_Logical.Get(); }
|
||||
|
||||
virtual G4VPhysicalVolume* GetG4PhysicalVolume() {
|
||||
if (!m_Physical) Update();
|
||||
return m_Physical;
|
||||
}
|
||||
|
||||
const char* GetName() const { return m_Name.c_str(); }
|
||||
|
||||
template <typename Ar>
|
||||
void serialize(Ar &ar, const unsigned int version) {
|
||||
ar & boost::serialization::base_object<TRS>(*this);
|
||||
ar & HRP("Name", m_Name);
|
||||
ar & HRP("Logical", m_Logical);
|
||||
}
|
||||
|
||||
public slots:
|
||||
void Update();
|
||||
|
||||
|
||||
protected:
|
||||
std::string m_Name;
|
||||
SmartPointer<LogicalVolume> m_Logical;
|
||||
|
||||
G4VPhysicalVolume *m_Physical;
|
||||
|
||||
// ULIB_DECLARE_PROPERTIES(PhysicalVolume)
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -126,52 +179,48 @@ public:
|
||||
TessellatedSolid();
|
||||
TessellatedSolid(const char *name);
|
||||
|
||||
void SetMesh(TriangleMesh &mesh);
|
||||
void SetMesh(const TriangleMesh *mesh);
|
||||
uLibGetMacro(Solid, G4TessellatedSolid *)
|
||||
|
||||
virtual G4VSolid* GetG4Solid() const override { return (G4VSolid*)m_Solid; }
|
||||
|
||||
const TriangleMesh& GetMesh() const { return m_Mesh; }
|
||||
const TriangleMesh* GetMesh() const { return m_Mesh.get(); }
|
||||
|
||||
public slots:
|
||||
void Update();
|
||||
virtual void Update() override;
|
||||
|
||||
private :
|
||||
TriangleMesh m_Mesh;
|
||||
protected:
|
||||
SmartPointer<TriangleMesh> m_Mesh;
|
||||
G4TessellatedSolid *m_Solid;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
//// BOX SOLID /////////////////////////////////////////////////////////////////
|
||||
|
||||
class BoxSolid : public Solid {
|
||||
uLibTypeMacro(BoxSolid, Solid)
|
||||
ULIB_SERIALIZE_ACCESS
|
||||
ULIB_DECLARE_PROPERTIES(BoxSolid)
|
||||
|
||||
public:
|
||||
uLibTypeMacro(BoxSolid, Solid)
|
||||
|
||||
BoxSolid(const char *name = "");
|
||||
BoxSolid();
|
||||
BoxSolid(const char *name);
|
||||
BoxSolid(const char *name, ContainerBox *box);
|
||||
|
||||
BoxSolid(const char *name, SmartPointer<ContainerBox> box);
|
||||
|
||||
virtual G4VSolid* GetG4Solid() const override { return (G4VSolid*)m_Solid; }
|
||||
|
||||
virtual void Update() override;
|
||||
ContainerBox* GetObject() const { return m_ContainerBox; }
|
||||
|
||||
template < typename Ar >
|
||||
void serialize(Ar &ar, const unsigned int version) {
|
||||
// ar & boost::serialization::base_object<BaseClass>(*this);
|
||||
ar & HRP("Density", m_Density, "g/cm3");
|
||||
ar & boost::serialization::base_object<Solid>(*this);
|
||||
ar & HRP("Container", m_ContainerBox);
|
||||
}
|
||||
|
||||
public slots:
|
||||
void Update();
|
||||
|
||||
private:
|
||||
float m_Density;
|
||||
ContainerBox *m_ContainerBox;
|
||||
|
||||
SmartPointer<ContainerBox> m_ContainerBox;
|
||||
|
||||
G4Box *m_Solid;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user