/*////////////////////////////////////////////////////////////////////////////// // CMT Cosmic Muon Tomography project ////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova All rights reserved Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it > ------------------------------------------------------------------ This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 3.0 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library. //////////////////////////////////////////////////////////////////////////////*/ #ifndef SOLID_H #define SOLID_H #include "Core/Object.h" #include "Geant/Matter.h" #include "Math/Transform.h" #include #include "Math/ContainerBox.h" #include "Math/Dense.h" #include "Math/TriangleMesh.h" class G4Material; class G4LogicalVolume; class G4TessellatedSolid; class G4Box; namespace uLib { namespace Geant { class Solid : public Object { uLibTypeMacro(Solid, Object) ULIB_SERIALIZE_ACCESS ULIB_DECLARE_PROPERTIES(Solid) public: Solid(); Solid(const char *name); virtual ~Solid(); virtual G4VSolid* GetG4Solid() const { return nullptr; } inline const char *GetName() const { return m_Name.c_str(); } template < typename Ar > void serialize(Ar &ar, const unsigned int version) { ar & HRP("Name", m_Name); } public slots: virtual void Update(); protected: std::string m_Name; }; class LogicalVolume : public Object { uLibTypeMacro(LogicalVolume, Object) ULIB_SERIALIZE_ACCESS ULIB_DECLARE_PROPERTIES(LogicalVolume) public: LogicalVolume(); LogicalVolume(const char *name); virtual ~LogicalVolume(); 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(); } void SetSolid(SmartPointer solid) { m_Solid = solid; } void SetMaterial(SmartPointer 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); } public slots: virtual void Update(); protected: std::string m_Name; SmartPointer m_Material; SmartPointer m_Solid; G4LogicalVolume *m_Logical; }; 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 void serialize(Ar &ar, const unsigned int version) { ar & boost::serialization::base_object(*this); ar & HRP("Name", m_Name); ar & HRP("Logical", m_Logical); } public slots: void Update(); protected: std::string m_Name; SmartPointer m_Logical; G4VPhysicalVolume *m_Physical; ULIB_DECLARE_PROPERTIES(PhysicalVolume) }; class TessellatedSolid : public Solid { uLibTypeMacro(TessellatedSolid, Solid) ULIB_SERIALIZE_ACCESS public: TessellatedSolid(); TessellatedSolid(const char *name); void SetMesh(const TriangleMesh *mesh); uLibGetMacro(Solid, G4TessellatedSolid *) virtual G4VSolid* GetG4Solid() const override { return (G4VSolid*)m_Solid; } const TriangleMesh* GetMesh() const { return m_Mesh.get(); } virtual void Update() override; protected: SmartPointer m_Mesh; G4TessellatedSolid *m_Solid; //ULIB_DECLARE_PROPERTIES(TessellatedSolid) }; //////////////////////////////////////////////////////////////////////////////// //// BOX SOLID ///////////////////////////////////////////////////////////////// class BoxSolid : public Solid { uLibTypeMacro(BoxSolid, Solid) ULIB_SERIALIZE_ACCESS public: BoxSolid(); BoxSolid(const char *name); BoxSolid(const char *name, SmartPointer 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(*this); ar & HRP("Container", m_ContainerBox); } private: SmartPointer m_ContainerBox; G4Box *m_Solid; ULIB_DECLARE_PROPERTIES(BoxSolid) }; } // namespace Geant } // namespace uLib #endif // SOLID_H