Compare commits
2 Commits
865282aefc
...
987d783fdb
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
987d783fdb | ||
|
|
83af9a180f |
@@ -10,6 +10,7 @@
|
|||||||
#include <QList>
|
#include <QList>
|
||||||
#include <QShortcut>
|
#include <QShortcut>
|
||||||
#include <QItemSelectionModel>
|
#include <QItemSelectionModel>
|
||||||
|
#include <functional>
|
||||||
|
|
||||||
ContextPanel::ContextPanel(QWidget* parent)
|
ContextPanel::ContextPanel(QWidget* parent)
|
||||||
: QWidget(parent)
|
: QWidget(parent)
|
||||||
@@ -105,16 +106,35 @@ void ContextPanel::selectObject(uLib::Object* obj) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < m_model->rowCount(); ++i) {
|
// Recursive search helper
|
||||||
QModelIndex idx = m_model->index(i, 0);
|
std::function<QModelIndex(const QModelIndex&)> findIdx = [&](const QModelIndex& parent) -> QModelIndex {
|
||||||
if (idx.internalPointer() == obj) {
|
for (int i = 0; i < m_model->rowCount(parent); ++i) {
|
||||||
QSignalBlocker blocker(m_treeView->selectionModel());
|
QModelIndex idx = m_model->index(i, 0, parent);
|
||||||
m_treeView->selectionModel()->select(idx, QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows);
|
if (idx.internalPointer() == obj) return idx;
|
||||||
m_treeView->scrollTo(idx);
|
|
||||||
m_propertiesPanel->setObject(obj); // Explicitly update properties too
|
if (m_model->rowCount(idx) > 0) {
|
||||||
return;
|
QModelIndex childIdx = findIdx(idx);
|
||||||
|
if (childIdx.isValid()) return childIdx;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return QModelIndex();
|
||||||
|
};
|
||||||
|
|
||||||
|
QModelIndex targetIdx = findIdx(QModelIndex());
|
||||||
|
if (targetIdx.isValid()) {
|
||||||
|
QSignalBlocker blocker(m_treeView->selectionModel());
|
||||||
|
|
||||||
|
// Expand parents so the selection is visible
|
||||||
|
QModelIndex p = targetIdx.parent();
|
||||||
|
while (p.isValid()) {
|
||||||
|
m_treeView->expand(p);
|
||||||
|
p = p.parent();
|
||||||
|
}
|
||||||
|
|
||||||
|
m_treeView->selectionModel()->select(targetIdx, QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows);
|
||||||
|
m_treeView->scrollTo(targetIdx);
|
||||||
|
m_propertiesPanel->setObject(obj);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ContextPanel::clearSelection() {
|
void ContextPanel::clearSelection() {
|
||||||
|
|||||||
@@ -67,6 +67,12 @@ public:
|
|||||||
static uLib::ObjectRegistrar<className> ULIB_REG_CONCAT( \
|
static uLib::ObjectRegistrar<className> ULIB_REG_CONCAT( \
|
||||||
g_ObjectRegistrar_, __LINE__)(registeredName);
|
g_ObjectRegistrar_, __LINE__)(registeredName);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// Object Wrapper
|
||||||
|
|
||||||
template <typename T> class ObjectWrapper {
|
template <typename T> class ObjectWrapper {
|
||||||
public:
|
public:
|
||||||
ObjectWrapper(const std::string &className) {
|
ObjectWrapper(const std::string &className) {
|
||||||
@@ -75,6 +81,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
ObjectWrapper(T *model) : m_model(model) {}
|
ObjectWrapper(T *model) : m_model(model) {}
|
||||||
|
ObjectWrapper(T &model) : m_model(model) {}
|
||||||
|
|
||||||
template <typename U = T,
|
template <typename U = T,
|
||||||
typename = std::enable_if_t<std::is_default_constructible_v<U>>>
|
typename = std::enable_if_t<std::is_default_constructible_v<U>>>
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ int main() {
|
|||||||
|
|
||||||
std::cout << "Testing ObjectWrapper with Non-Default Constructible type..." << std::endl;
|
std::cout << "Testing ObjectWrapper with Non-Default Constructible type..." << std::endl;
|
||||||
NonDefault nd(10);
|
NonDefault nd(10);
|
||||||
uLib::ObjectWrapper<NonDefault> w2(&nd);
|
uLib::ObjectWrapper<NonDefault> w2(nd);
|
||||||
|
|
||||||
// The following would NOT compile without SFINAE:
|
// The following would NOT compile without SFINAE:
|
||||||
// uLib::ObjectWrapper<NonDefault> w3;
|
// uLib::ObjectWrapper<NonDefault> w3;
|
||||||
|
|||||||
@@ -150,11 +150,58 @@ int testing_hrt_class() {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class B : public virtual Object {
|
||||||
|
uLibTypeMacro(B, Object)
|
||||||
|
ULIB_SERIALIZE_ACCESS
|
||||||
|
|
||||||
|
public:
|
||||||
|
B() : m_b(1234567), m_a(nullptr) {}
|
||||||
|
|
||||||
|
int m_b;
|
||||||
|
|
||||||
|
// reference to A (serializes through ID)
|
||||||
|
A *m_a;
|
||||||
|
};
|
||||||
|
|
||||||
|
ULIB_SERIALIZABLE_OBJECT(B)
|
||||||
|
ULIB_SERIALIZE_OBJECT(B, Object) {
|
||||||
|
ar & "Object B : " & "--> m_b = " & AR(m_b) & "--> m_a = " & AR(m_a);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int test_referece_serialization() {
|
||||||
|
A a;
|
||||||
|
{
|
||||||
|
B b,b2 ;
|
||||||
|
b.m_a = &a;
|
||||||
|
b2.m_a = &a;
|
||||||
|
|
||||||
|
std::ofstream file("test_ref.xml");
|
||||||
|
Archive::xml_oarchive(file) << NVP(b) << NVP(b2);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
B b,b2;
|
||||||
|
{
|
||||||
|
std::ifstream file("test_ref.xml");
|
||||||
|
Archive::xml_iarchive(file) >> NVP(b) >> NVP(b2);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (b.m_a->a() == a.a() && b2.m_a->a() == a.a());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
BEGIN_TESTING(Serialize Test);
|
BEGIN_TESTING(Serialize Test);
|
||||||
|
|
||||||
TEST1(test_V3f());
|
TEST1(test_V3f());
|
||||||
TEST1(testing_xml_class());
|
TEST1(testing_xml_class());
|
||||||
|
TEST1(test_referece_serialization());
|
||||||
// TEST1(testing_hrt_class());
|
// TEST1(testing_hrt_class());
|
||||||
|
|
||||||
END_TESTING;
|
END_TESTING;
|
||||||
|
|||||||
@@ -35,12 +35,14 @@
|
|||||||
#include <Geant4/G4TriangularFacet.hh>
|
#include <Geant4/G4TriangularFacet.hh>
|
||||||
#include <Geant4/G4Box.hh>
|
#include <Geant4/G4Box.hh>
|
||||||
#include <Geant4/G4PVPlacement.hh>
|
#include <Geant4/G4PVPlacement.hh>
|
||||||
|
#include <cstddef>
|
||||||
|
|
||||||
|
|
||||||
#include "Math/Dense.h"
|
#include "Math/Dense.h"
|
||||||
#include "Math/Transform.h"
|
#include "Math/Transform.h"
|
||||||
|
|
||||||
#include "Solid.h"
|
#include "Solid.h"
|
||||||
|
#include "uLibInterface.hh"
|
||||||
|
|
||||||
namespace uLib {
|
namespace uLib {
|
||||||
namespace Geant {
|
namespace Geant {
|
||||||
@@ -55,18 +57,17 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
Solid::Solid()
|
Solid::Solid()
|
||||||
: m_Name("unnamed_solid"), m_Material(NULL), m_Logical(NULL), m_Physical(NULL),
|
: m_Material(nullptr), m_Logical(nullptr) {
|
||||||
m_Position(new G4ThreeVector(0,0,0)), m_Rotation(NULL) {}
|
}
|
||||||
|
|
||||||
Solid::Solid(const char *name)
|
Solid::Solid(const char *name)
|
||||||
: m_Name(name), m_Material(NULL), m_Logical(NULL), m_Physical(NULL),
|
: m_Name(name), m_Material(nullptr), m_Logical(nullptr) {
|
||||||
m_Position(new G4ThreeVector(0,0,0)), m_Rotation(NULL) {}
|
|
||||||
|
|
||||||
Solid::~Solid() {
|
|
||||||
if (m_Position) delete m_Position;
|
|
||||||
if (m_Rotation) delete m_Rotation;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Solid::~Solid() {}
|
||||||
|
|
||||||
|
void Solid::Update() {}
|
||||||
|
|
||||||
void Solid::SetNistMaterial(const char *name) {
|
void Solid::SetNistMaterial(const char *name) {
|
||||||
G4NistManager *nist = G4NistManager::Instance();
|
G4NistManager *nist = G4NistManager::Instance();
|
||||||
G4Material *mat = nist->FindOrBuildMaterial(name);
|
G4Material *mat = nist->FindOrBuildMaterial(name);
|
||||||
@@ -85,31 +86,11 @@ void Solid::SetMaterial(G4Material *material) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Solid::SetTransform(Matrix4f transform) {
|
void Solid::SetTransform(Matrix4f transform) {
|
||||||
uLib::AffineTransform t;
|
m_Transform.FromMatrix(transform);
|
||||||
t.SetMatrix(transform);
|
m_Transform.Updated();
|
||||||
|
|
||||||
// 2. Extract position and rotation for Geant4
|
|
||||||
Vector3f pos = t.GetPosition();
|
|
||||||
if (!m_Position) m_Position = new G4ThreeVector();
|
|
||||||
*m_Position = G4ThreeVector(pos(0), pos(1), pos(2));
|
|
||||||
|
|
||||||
// Create a G4 rotation matrix from the 4x4 matrix
|
|
||||||
Matrix3f m = t.GetRotation();
|
|
||||||
if (!m_Rotation) m_Rotation = new G4RotationMatrix();
|
|
||||||
m_Rotation->set(G4ThreeVector(m(0,0), m(1,0), m(2,0)),
|
|
||||||
G4ThreeVector(m(0,1), m(1,1), m(2,1)),
|
|
||||||
G4ThreeVector(m(0,2), m(1,2), m(2,2)));
|
|
||||||
|
|
||||||
// 3. If object is already placed, update its transformation
|
|
||||||
if (m_Physical) {
|
|
||||||
m_Physical->SetTranslation(*m_Position);
|
|
||||||
m_Physical->SetRotation(m_Rotation);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::cout << "Solid " << GetName() << " position: " << pos << " rotation: " << m << std::endl;
|
|
||||||
|
|
||||||
this->Updated();
|
|
||||||
}
|
|
||||||
|
|
||||||
void Solid::SetParent(Solid *parent) {
|
void Solid::SetParent(Solid *parent) {
|
||||||
if (!m_Logical) {
|
if (!m_Logical) {
|
||||||
@@ -133,8 +114,8 @@ void Solid::SetParent(Solid *parent) {
|
|||||||
|
|
||||||
// G4PVPlacement
|
// G4PVPlacement
|
||||||
m_Physical = new G4PVPlacement(
|
m_Physical = new G4PVPlacement(
|
||||||
m_Rotation, // Rotation
|
ToG4Transform(m_Transform), // Rotation
|
||||||
*m_Position, // Position (translation) inside the parent
|
GetPosition(), // Position (translation) inside the parent
|
||||||
m_Logical, // The logical volume of this solid (the child)
|
m_Logical, // The logical volume of this solid (the child)
|
||||||
GetName(), // Name of the physical volume
|
GetName(), // Name of the physical volume
|
||||||
parentLogical, // The logical volume of the parent (nullptr if it's the World volume)
|
parentLogical, // The logical volume of the parent (nullptr if it's the World volume)
|
||||||
@@ -182,15 +163,15 @@ void TessellatedSolid::Update() {
|
|||||||
|
|
||||||
BoxSolid::BoxSolid(const char *name) :
|
BoxSolid::BoxSolid(const char *name) :
|
||||||
BaseClass(name),
|
BaseClass(name),
|
||||||
|
m_Density(1.0),
|
||||||
m_ContainerBox(new ContainerBox()),
|
m_ContainerBox(new ContainerBox()),
|
||||||
m_Solid(new G4Box(name, 0.5, 0.5, 0.5))
|
m_Solid(new G4Box(name, 1, 1, 1))
|
||||||
{
|
{}
|
||||||
Object::connect(m_ContainerBox, &ContainerBox::Updated, this, &BoxSolid::Update);
|
|
||||||
Update();
|
|
||||||
}
|
|
||||||
|
|
||||||
BoxSolid::BoxSolid(const char *name, ContainerBox *box) : BaseClass(name) {
|
BoxSolid::BoxSolid(const char *name, ContainerBox *box) :
|
||||||
m_Solid = new G4Box(name, 0.5, 0.5, 0.5);
|
BaseClass(name),
|
||||||
|
m_Density(1.0) {
|
||||||
|
m_Solid = new G4Box(name, 1, 1, 1);
|
||||||
m_ContainerBox = box;
|
m_ContainerBox = box;
|
||||||
Object::connect(box, &ContainerBox::Updated, this, &BoxSolid::Update);
|
Object::connect(box, &ContainerBox::Updated, this, &BoxSolid::Update);
|
||||||
if (m_Logical) {
|
if (m_Logical) {
|
||||||
@@ -199,6 +180,7 @@ BoxSolid::BoxSolid(const char *name, ContainerBox *box) : BaseClass(name) {
|
|||||||
Update();
|
Update();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void BoxSolid::Update() {
|
void BoxSolid::Update() {
|
||||||
if (m_ContainerBox) {
|
if (m_ContainerBox) {
|
||||||
Vector3f size = m_ContainerBox->GetSize();
|
Vector3f size = m_ContainerBox->GetSize();
|
||||||
|
|||||||
@@ -28,11 +28,15 @@
|
|||||||
|
|
||||||
#include "Core/Object.h"
|
#include "Core/Object.h"
|
||||||
#include "Geant/Matter.h"
|
#include "Geant/Matter.h"
|
||||||
|
#include "Math/Transform.h"
|
||||||
#include <Geant4/G4LogicalVolume.hh>
|
#include <Geant4/G4LogicalVolume.hh>
|
||||||
#include "Math/ContainerBox.h"
|
#include "Math/ContainerBox.h"
|
||||||
#include "Math/Dense.h"
|
#include "Math/Dense.h"
|
||||||
#include "Math/TriangleMesh.h"
|
#include "Math/TriangleMesh.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class G4Material;
|
class G4Material;
|
||||||
class G4LogicalVolume;
|
class G4LogicalVolume;
|
||||||
class G4TessellatedSolid;
|
class G4TessellatedSolid;
|
||||||
@@ -42,28 +46,17 @@ namespace uLib {
|
|||||||
namespace Geant {
|
namespace Geant {
|
||||||
|
|
||||||
class Solid : public Object {
|
class Solid : public Object {
|
||||||
public:
|
|
||||||
uLibTypeMacro(Solid, Object)
|
uLibTypeMacro(Solid, Object)
|
||||||
|
ULIB_SERIALIZE_ACCESS
|
||||||
|
ULIB_DECLARE_PROPERTIES(Solid)
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
Solid();
|
Solid();
|
||||||
Solid(const char *name);
|
Solid(const char *name);
|
||||||
virtual ~Solid();
|
virtual ~Solid();
|
||||||
|
|
||||||
void SetNistMaterial(const char *name);
|
|
||||||
void SetMaterial(G4Material *material);
|
|
||||||
|
|
||||||
void SetSizeUnit(const char *unit);
|
|
||||||
|
|
||||||
// Implementiamo SetParent qui, per tutti.
|
|
||||||
virtual void SetParent(Solid *parent);
|
|
||||||
|
|
||||||
// Setters per la posizione (necessari per il piazzamento)
|
|
||||||
void SetTransform(Matrix4f transform);
|
|
||||||
|
|
||||||
uLibGetMacro(Material, G4Material *)
|
|
||||||
uLibGetSetMacro(Logical, G4LogicalVolume *)
|
|
||||||
uLibGetSetMacro(Physical, G4VPhysicalVolume *)
|
|
||||||
|
|
||||||
virtual G4VSolid* GetG4Solid() const { return nullptr; }
|
virtual G4VSolid* GetG4Solid() const { return nullptr; }
|
||||||
|
|
||||||
inline const char *GetName() const {
|
inline const char *GetName() const {
|
||||||
@@ -72,20 +65,57 @@ public:
|
|||||||
|
|
||||||
template < typename Ar >
|
template < typename Ar >
|
||||||
void serialize(Ar &ar, const unsigned int version) {
|
void serialize(Ar &ar, const unsigned int version) {
|
||||||
ar & boost::serialization::make_nvp("Name", m_Name);
|
ar & HRP("Name", m_Name);
|
||||||
|
ar & HRP("Material", m_Material);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
virtual void Update();
|
||||||
|
|
||||||
|
protected:
|
||||||
std::string m_Name;
|
std::string m_Name;
|
||||||
G4Material *m_Material;
|
|
||||||
G4LogicalVolume *m_Logical;
|
|
||||||
G4VPhysicalVolume *m_Physical; // <-- Memorizza l'oggetto posizionato
|
|
||||||
G4ThreeVector *m_Position; // <-- Offset rispetto al centro del padre
|
|
||||||
G4RotationMatrix* m_Rotation; // <-- Rotazione rispetto al padre
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
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 nullptr; }
|
||||||
|
|
||||||
|
inline const char *GetName() const {
|
||||||
|
return m_Logical ? m_Logical->GetName().c_str() : 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);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
virtual void Update();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
std::string m_Name;
|
||||||
|
Material *m_Material;
|
||||||
|
|
||||||
|
G4LogicalVolume *m_Logical;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -95,8 +125,10 @@ public:
|
|||||||
|
|
||||||
TessellatedSolid();
|
TessellatedSolid();
|
||||||
TessellatedSolid(const char *name);
|
TessellatedSolid(const char *name);
|
||||||
|
|
||||||
void SetMesh(TriangleMesh &mesh);
|
void SetMesh(TriangleMesh &mesh);
|
||||||
uLibGetMacro(Solid, G4TessellatedSolid *)
|
uLibGetMacro(Solid, G4TessellatedSolid *)
|
||||||
|
|
||||||
virtual G4VSolid* GetG4Solid() const override { return (G4VSolid*)m_Solid; }
|
virtual G4VSolid* GetG4Solid() const override { return (G4VSolid*)m_Solid; }
|
||||||
|
|
||||||
const TriangleMesh& GetMesh() const { return m_Mesh; }
|
const TriangleMesh& GetMesh() const { return m_Mesh; }
|
||||||
@@ -115,9 +147,11 @@ private :
|
|||||||
|
|
||||||
|
|
||||||
class BoxSolid : public Solid {
|
class BoxSolid : public Solid {
|
||||||
|
uLibTypeMacro(BoxSolid, Solid)
|
||||||
|
ULIB_SERIALIZE_ACCESS
|
||||||
|
ULIB_DECLARE_PROPERTIES(BoxSolid)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
uLibTypeMacro(BoxSolid, Solid)
|
|
||||||
|
|
||||||
BoxSolid(const char *name = "");
|
BoxSolid(const char *name = "");
|
||||||
BoxSolid(const char *name, ContainerBox *box);
|
BoxSolid(const char *name, ContainerBox *box);
|
||||||
@@ -128,14 +162,15 @@ public:
|
|||||||
|
|
||||||
template < typename Ar >
|
template < typename Ar >
|
||||||
void serialize(Ar &ar, const unsigned int version) {
|
void serialize(Ar &ar, const unsigned int version) {
|
||||||
ar & boost::serialization::base_object<BaseClass>(*this);
|
// ar & boost::serialization::base_object<BaseClass>(*this);
|
||||||
ar & m_ContainerBox;
|
ar & HRP("Density", m_Density, "g/cm3");
|
||||||
}
|
}
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void Update();
|
void Update();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
float m_Density;
|
||||||
ContainerBox *m_ContainerBox;
|
ContainerBox *m_ContainerBox;
|
||||||
G4Box *m_Solid;
|
G4Box *m_Solid;
|
||||||
};
|
};
|
||||||
|
|||||||
51
src/HEP/Geant/uLibInterface.hh
Normal file
51
src/HEP/Geant/uLibInterface.hh
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
#ifndef ULIB_GEANT_ULIB_INTERFACE_HH
|
||||||
|
#define ULIB_GEANT_ULIB_INTERFACE_HH
|
||||||
|
|
||||||
|
#include "Math/Transform.h"
|
||||||
|
#include <Geant4/G4Transform3D.hh>
|
||||||
|
#include <Geant4/G4ThreeVector.hh>
|
||||||
|
#include <Geant4/G4RotationMatrix.hh>
|
||||||
|
|
||||||
|
namespace uLib {
|
||||||
|
namespace Geant {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Converts a uLib::Matrix4f to a Geant4 G4Transform3D.
|
||||||
|
*/
|
||||||
|
inline G4Transform3D ToG4Transform(const Matrix4f& m) {
|
||||||
|
return G4Transform3D(
|
||||||
|
m(0, 0), m(0, 1), m(0, 2), m(0, 3),
|
||||||
|
m(1, 0), m(1, 1), m(1, 2), m(1, 3),
|
||||||
|
m(2, 0), m(2, 1), m(2, 2), m(2, 3)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Converts a uLib::AffineTransform to a Geant4 G4Transform3D.
|
||||||
|
*/
|
||||||
|
inline G4Transform3D ToG4Transform(const AffineTransform& at) {
|
||||||
|
return ToG4Transform(at.GetMatrix());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Converts a uLib::Vector3f to a Geant4 G4ThreeVector.
|
||||||
|
*/
|
||||||
|
inline G4ThreeVector ToG4Vector(const Vector3f& v) {
|
||||||
|
return G4ThreeVector(v(0), v(1), v(2));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Converts a uLib::Matrix3f to a Geant4 G4RotationMatrix.
|
||||||
|
*/
|
||||||
|
inline G4RotationMatrix ToG4Rotation(const Matrix3f& m) {
|
||||||
|
G4RotationMatrix rot;
|
||||||
|
rot.set(G4ThreeVector(m(0, 0), m(1, 0), m(2, 0)),
|
||||||
|
G4ThreeVector(m(0, 1), m(1, 1), m(2, 1)),
|
||||||
|
G4ThreeVector(m(0, 2), m(1, 2), m(2, 2)));
|
||||||
|
return rot;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace Geant
|
||||||
|
} // namespace uLib
|
||||||
|
|
||||||
|
#endif // ULIB_GEANT_ULIB_INTERFACE_HH
|
||||||
@@ -246,6 +246,7 @@ uLibTypeMacro(TRS, AffineTransform) ULIB_SERIALIZE_ACCESS
|
|||||||
}
|
}
|
||||||
|
|
||||||
Matrix4f GetMatrix() const { return this->GetAffineMatrix().matrix(); }
|
Matrix4f GetMatrix() const { return this->GetAffineMatrix().matrix(); }
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
inline std::ostream &operator<<(std::ostream &os, const TRS &trs) {
|
inline std::ostream &operator<<(std::ostream &os, const TRS &trs) {
|
||||||
|
|||||||
@@ -26,36 +26,11 @@ namespace Vtk {
|
|||||||
|
|
||||||
BoxSolid::BoxSolid(Geant::BoxSolid *content)
|
BoxSolid::BoxSolid(Geant::BoxSolid *content)
|
||||||
: GeantSolid(content), m_BoxContent(content) {
|
: GeantSolid(content), m_BoxContent(content) {
|
||||||
this->InstallPipe();
|
|
||||||
|
|
||||||
// Connect the model's Updated event to updateTransform to ensure VTK sync
|
|
||||||
m_UpdateConnection = Object::connect(m_BoxContent, &uLib::Object::Updated, this, &BoxSolid::Update);
|
|
||||||
|
|
||||||
// Initial sync
|
|
||||||
this->Update();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
BoxSolid::~BoxSolid() {
|
BoxSolid::~BoxSolid() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void BoxSolid::Update() {
|
|
||||||
ConnectionBlock blocker(m_UpdateConnection);
|
|
||||||
// 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));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void BoxSolid::serialize_display(uLib::Archive::display_properties_archive &ar,
|
void BoxSolid::serialize_display(uLib::Archive::display_properties_archive &ar,
|
||||||
const unsigned int version) {
|
const unsigned int version) {
|
||||||
// Expose Geant solid properties and underlying Box/TRS properties
|
// Expose Geant solid properties and underlying Box/TRS properties
|
||||||
|
|||||||
@@ -48,13 +48,6 @@ public:
|
|||||||
BoxSolid(Geant::BoxSolid *content);
|
BoxSolid(Geant::BoxSolid *content);
|
||||||
virtual ~BoxSolid();
|
virtual ~BoxSolid();
|
||||||
|
|
||||||
virtual void Update() override;
|
|
||||||
virtual void SyncFromVtk() override;
|
|
||||||
|
|
||||||
virtual uLib::Object *GetContent() const override {
|
|
||||||
return m_BoxContent ? (::uLib::Object*)m_BoxContent->GetObject() : nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual void serialize_display(uLib::Archive::display_properties_archive &ar,
|
virtual void serialize_display(uLib::Archive::display_properties_archive &ar,
|
||||||
const unsigned int version = 0) override;
|
const unsigned int version = 0) override;
|
||||||
|
|
||||||
@@ -67,7 +60,6 @@ protected:
|
|||||||
virtual void InstallPipe() override;
|
virtual void InstallPipe() override;
|
||||||
|
|
||||||
Geant::BoxSolid *m_BoxContent;
|
Geant::BoxSolid *m_BoxContent;
|
||||||
uLib::Connection m_UpdateConnection;
|
|
||||||
|
|
||||||
ULIB_DECLARE_PROPERTIES(BoxSolid)
|
ULIB_DECLARE_PROPERTIES(BoxSolid)
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -24,6 +24,7 @@
|
|||||||
//////////////////////////////////////////////////////////////////////////////*/
|
//////////////////////////////////////////////////////////////////////////////*/
|
||||||
|
|
||||||
#include "vtkGeantSolid.h"
|
#include "vtkGeantSolid.h"
|
||||||
|
#include "Core/Monitor.h"
|
||||||
|
|
||||||
#include <vtkActor.h>
|
#include <vtkActor.h>
|
||||||
#include <vtkPolyData.h>
|
#include <vtkPolyData.h>
|
||||||
@@ -34,6 +35,7 @@
|
|||||||
#include <vtkSmartPointer.h>
|
#include <vtkSmartPointer.h>
|
||||||
#include <vtkTransform.h>
|
#include <vtkTransform.h>
|
||||||
#include <vtkMatrix4x4.h>
|
#include <vtkMatrix4x4.h>
|
||||||
|
#include "Vtk/Math/vtkDense.h"
|
||||||
|
|
||||||
#include <Geant4/G4VSolid.hh>
|
#include <Geant4/G4VSolid.hh>
|
||||||
#include <Geant4/G4Polyhedron.hh>
|
#include <Geant4/G4Polyhedron.hh>
|
||||||
@@ -45,6 +47,14 @@ namespace Vtk {
|
|||||||
GeantSolid::GeantSolid(Content *content)
|
GeantSolid::GeantSolid(Content *content)
|
||||||
: m_SolidActor(vtkActor::New()), m_Content(content) {
|
: m_SolidActor(vtkActor::New()), m_Content(content) {
|
||||||
this->InstallPipe();
|
this->InstallPipe();
|
||||||
|
if (m_Content) {
|
||||||
|
m_UpdateConnection = Object::connect(m_Content, &uLib::Object::Updated, [this]() {
|
||||||
|
std::cout << "GeantSolid: Signal Updated received." << std::endl;
|
||||||
|
this->Update();
|
||||||
|
});
|
||||||
|
// Mandatory initial update to generate geometry and apply initial transform
|
||||||
|
this->Update();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
GeantSolid::~GeantSolid() {
|
GeantSolid::~GeantSolid() {
|
||||||
@@ -58,8 +68,21 @@ vtkPolyData *GeantSolid::GetPolyData() const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void GeantSolid::Update() {
|
void GeantSolid::Update() {
|
||||||
|
ConnectionBlock blocker(m_UpdateConnection);
|
||||||
this->UpdateGeometry();
|
this->UpdateGeometry();
|
||||||
this->UpdateTransform();
|
this->UpdateTransform();
|
||||||
|
this->Prop3D::Update();
|
||||||
|
}
|
||||||
|
|
||||||
|
void GeantSolid::SyncFromVtk() {
|
||||||
|
if (!m_Content) return;
|
||||||
|
this->Prop3D::SyncFromVtk();
|
||||||
|
|
||||||
|
if (auto* proxy = vtkProp3D::SafeDownCast(this->GetProxyProp())) {
|
||||||
|
if (vtkMatrix4x4* mat = proxy->GetUserMatrix()) {
|
||||||
|
m_Content->SetTransform(VtkToMatrix4f(mat));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void GeantSolid::UpdateGeometry() {
|
void GeantSolid::UpdateGeometry() {
|
||||||
@@ -114,32 +137,35 @@ void GeantSolid::UpdateTransform() {
|
|||||||
if (!m_Content || !m_SolidActor)
|
if (!m_Content || !m_SolidActor)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// Apply the Geant4 transform (position/rotation) if placed
|
// Apply the Geant4 transform (position/rotation/scaling)
|
||||||
if (m_Content->GetPhysical()) {
|
G4ThreeVector pos = m_Content->GetPosition();
|
||||||
auto *phys = m_Content->GetPhysical();
|
const G4RotationMatrix *rot = m_Content->GetRotation();
|
||||||
G4ThreeVector pos = phys->GetTranslation();
|
G4ThreeVector scale = m_Content->GetScaling();
|
||||||
const G4RotationMatrix *rot = phys->GetRotation();
|
|
||||||
|
|
||||||
vtkSmartPointer<vtkTransform> transform = vtkSmartPointer<vtkTransform>::New();
|
std::cout << "GeantSolid: Updating transform. Pos: " << pos.x() << " " << pos.y() << " " << pos.z()
|
||||||
|
<< " Scale: " << scale.x() << " " << scale.y() << " " << scale.z() << std::endl;
|
||||||
|
|
||||||
|
vtkNew<vtkTransform> transform;
|
||||||
transform->Identity();
|
transform->Identity();
|
||||||
transform->Translate(pos.x(), pos.y(), pos.z());
|
transform->Translate(pos.x(), pos.y(), pos.z());
|
||||||
|
|
||||||
if (rot) {
|
if (rot) {
|
||||||
// G4RotationMatrix stores the inverse of the rotation for placement
|
G4RotationMatrix invRot = *rot;
|
||||||
G4RotationMatrix invRot = rot->inverse();
|
|
||||||
double elements[16] = {
|
double elements[16] = {
|
||||||
invRot.xx(), invRot.xy(), invRot.xz(), 0,
|
invRot.xx(), invRot.xy(), invRot.xz(), 0,
|
||||||
invRot.yx(), invRot.yy(), invRot.yz(), 0,
|
invRot.yx(), invRot.yy(), invRot.yz(), 0,
|
||||||
invRot.zx(), invRot.zy(), invRot.zz(), 0,
|
invRot.zx(), invRot.zy(), invRot.zz(), 0,
|
||||||
0, 0, 0, 1
|
0, 0, 0, 1
|
||||||
};
|
};
|
||||||
vtkSmartPointer<vtkMatrix4x4> mat = vtkSmartPointer<vtkMatrix4x4>::New();
|
vtkNew<vtkMatrix4x4> mat;
|
||||||
mat->DeepCopy(elements);
|
mat->DeepCopy(elements);
|
||||||
transform->Concatenate(mat);
|
transform->Concatenate(mat);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
transform->Scale(scale.x(), scale.y(), scale.z());
|
||||||
|
|
||||||
m_SolidActor->SetUserTransform(transform);
|
m_SolidActor->SetUserTransform(transform);
|
||||||
}
|
m_SolidActor->Modified();
|
||||||
}
|
}
|
||||||
|
|
||||||
void GeantSolid::InstallPipe() {
|
void GeantSolid::InstallPipe() {
|
||||||
|
|||||||
@@ -52,15 +52,19 @@ public:
|
|||||||
virtual class vtkPolyData *GetPolyData() const override;
|
virtual class vtkPolyData *GetPolyData() const override;
|
||||||
|
|
||||||
virtual void Update() override;
|
virtual void Update() override;
|
||||||
|
virtual void SyncFromVtk() override;
|
||||||
|
|
||||||
virtual void UpdateGeometry();
|
virtual void UpdateGeometry();
|
||||||
virtual void UpdateTransform();
|
virtual void UpdateTransform();
|
||||||
|
|
||||||
|
virtual uLib::Object *GetContent() const override { return (uLib::Object*)m_Content; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void InstallPipe();
|
virtual void InstallPipe();
|
||||||
|
|
||||||
vtkActor *m_SolidActor;
|
|
||||||
Content *m_Content;
|
Content *m_Content;
|
||||||
|
vtkActor *m_SolidActor;
|
||||||
|
uLib::Connection m_UpdateConnection;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Vtk
|
} // namespace Vtk
|
||||||
|
|||||||
@@ -33,6 +33,8 @@ public:
|
|||||||
/** @brief Synchronizes all managed prop3ds back to their models. */
|
/** @brief Synchronizes all managed prop3ds back to their models. */
|
||||||
virtual void SyncFromVtk() override;
|
virtual void SyncFromVtk() override;
|
||||||
|
|
||||||
|
virtual Object* GetContent() const override { return (Object*)m_Context; }
|
||||||
|
|
||||||
public:
|
public:
|
||||||
virtual void Prop3DAdded(Prop3D* prop3d);
|
virtual void Prop3DAdded(Prop3D* prop3d);
|
||||||
virtual void Prop3DRemoved(Prop3D* prop3d);
|
virtual void Prop3DRemoved(Prop3D* prop3d);
|
||||||
|
|||||||
Reference in New Issue
Block a user