refactor: improve Geant4 solid synchronization and update documentation for VTK integration

This commit is contained in:
AndreaRigoni
2026-04-16 06:51:16 +00:00
parent 24ec326715
commit 865282aefc
6 changed files with 68 additions and 25 deletions

View File

@@ -107,6 +107,8 @@ void Solid::SetTransform(Matrix4f transform) {
}
std::cout << "Solid " << GetName() << " position: " << pos << " rotation: " << m << std::endl;
this->Updated();
}
void Solid::SetParent(Solid *parent) {
@@ -181,11 +183,14 @@ void TessellatedSolid::Update() {
BoxSolid::BoxSolid(const char *name) :
BaseClass(name),
m_ContainerBox(new ContainerBox()),
m_Solid(new G4Box(name, 1, 1, 1))
{}
m_Solid(new G4Box(name, 0.5, 0.5, 0.5))
{
Object::connect(m_ContainerBox, &ContainerBox::Updated, this, &BoxSolid::Update);
Update();
}
BoxSolid::BoxSolid(const char *name, ContainerBox *box) : BaseClass(name) {
m_Solid = new G4Box(name, 1, 1, 1);
m_Solid = new G4Box(name, 0.5, 0.5, 0.5);
m_ContainerBox = box;
Object::connect(box, &ContainerBox::Updated, this, &BoxSolid::Update);
if (m_Logical) {

View File

@@ -53,6 +53,7 @@ public:
void SetMaterial(G4Material *material);
void SetSizeUnit(const char *unit);
// Implementiamo SetParent qui, per tutti.
virtual void SetParent(Solid *parent);
@@ -71,11 +72,8 @@ public:
template < typename Ar >
void serialize(Ar &ar, const unsigned int version) {
ar & m_Name;
ar & boost::serialization::make_nvp("Name", m_Name);
}
protected:
@@ -123,6 +121,7 @@ public:
BoxSolid(const char *name = "");
BoxSolid(const char *name, ContainerBox *box);
virtual G4VSolid* GetG4Solid() const override { return (G4VSolid*)m_Solid; }
ContainerBox* GetObject() const { return m_ContainerBox; }

View File

@@ -25,6 +25,32 @@ int main() {
TEST1(solid.GetMaterial()->GetName() == "G4_AIR");
}
// Test BoxSolid //
{
Geant::BoxSolid boxsolid("test_boxsolid");
boxsolid.SetNistMaterial("G4_AIR");
TEST1(boxsolid.GetLogical() != nullptr);
// TEST1(boxsolid.GetSolid() != nullptr);
}
// Test BoxSolid with a container box //
{
ContainerBox box;
// box.SetPosition(Vector3f(1,1,1));
// box.SetRotation(Rotation(Vector3f(0,1,0), 45_deg));
Geant::BoxSolid boxsolid("test_boxsolid", &box);
boxsolid.SetNistMaterial("G4_AIR");
TEST1(boxsolid.GetLogical() != nullptr);
// TEST1(boxsolid.GetSolid() != nullptr);
// TEST1(boxsolid.GetSolid()->GetXHalfLength() == 0.5);
// TEST1(boxsolid.GetSolid()->GetYHalfLength() == 0.5);
// TEST1(boxsolid.GetSolid()->GetZHalfLength() == 0.5);
}
// Test TessellatedSolid with a simple mesh //
{
Geant::TessellatedSolid tsolid("test_tessellated");

View File

@@ -40,13 +40,15 @@ BoxSolid::~BoxSolid() {
void BoxSolid::Update() {
ConnectionBlock blocker(m_UpdateConnection);
this->UpdateGeometry();
// Ensure base Prop3D properties (color, opacity, etc) and transform are applied
// Ensure base GeantSolid logic (G4Polyhedron and Transform) runs
this->GeantSolid::Update();
// Ensure base Prop3D properties (color, opacity, etc) are applied
this->Prop3D::Update();
}
void BoxSolid::SyncFromVtk() {
this->Prop3D::SyncFromVtk();
if (auto* proxy = vtkProp3D::SafeDownCast(this->GetProxyProp())) {
if (vtkMatrix4x4* mat = proxy->GetUserMatrix()) {
m_BoxContent->SetTransform(VtkToMatrix4f(mat));
@@ -54,16 +56,6 @@ void BoxSolid::SyncFromVtk() {
}
}
void BoxSolid::UpdateGeometry() {
// Sync geometry from G4VSolid provided by GeantSolid (tessellation)
GeantSolid::UpdateGeometry();
}
void BoxSolid::UpdateTransform() {
// Take transform from Prop3D base (which uses GetContent() -> ContainerBox TRS)
this->Prop3D::Update();
}
void BoxSolid::serialize_display(uLib::Archive::display_properties_archive &ar,
const unsigned int version) {
// Expose Geant solid properties and underlying Box/TRS properties

View File

@@ -49,8 +49,6 @@ public:
virtual ~BoxSolid();
virtual void Update() override;
virtual void UpdateGeometry() override;
virtual void UpdateTransform() override;
virtual void SyncFromVtk() override;
virtual uLib::Object *GetContent() const override {