From 35e4fb949dcaf24f59959e447bc46fd210804cd8 Mon Sep 17 00:00:00 2001 From: AndreaRigoni Date: Sat, 14 Mar 2026 12:28:40 +0000 Subject: [PATCH] fix tests --- src/HEP/Geant/Solid.cpp | 11 +++---- src/HEP/Geant/Solid.h | 5 +++- src/Math/CMakeLists.txt | 3 +- src/Python/math_bindings.cpp | 19 ++++++++----- src/Python/uLib/__init__.py | 7 +++-- src/Vtk/Math/testing/vtkTriangleMeshTest.cpp | 4 +-- src/Vtk/Math/vtkVoxImage.cpp | 30 +++++++++++++------- 7 files changed, 51 insertions(+), 28 deletions(-) diff --git a/src/HEP/Geant/Solid.cpp b/src/HEP/Geant/Solid.cpp index dfc77a1..46c7104 100644 --- a/src/HEP/Geant/Solid.cpp +++ b/src/HEP/Geant/Solid.cpp @@ -54,22 +54,23 @@ public: }; Solid::Solid() - : m_Logical(new G4LogicalVolume(NULL, NULL, "unnamed_solid")), - m_Material(NULL) {} + : m_Name("unnamed_solid"), m_Material(NULL), m_Logical(NULL), m_Physical(NULL) {} Solid::Solid(const char *name) - : m_Logical(new G4LogicalVolume(NULL, NULL, name)), m_Material(NULL) {} + : m_Name(name), m_Material(NULL), m_Logical(NULL), m_Physical(NULL) {} void Solid::SetNistMaterial(const char *name) { G4NistManager *nist = G4NistManager::Instance(); m_Material = nist->FindOrBuildMaterial(name); - m_Logical->SetMaterial(m_Material); + if (m_Logical) + m_Logical->SetMaterial(m_Material); } void Solid::SetMaterial(G4Material *material) { if (material) { m_Material = material; - m_Logical->SetMaterial(material); + if (m_Logical) + m_Logical->SetMaterial(material); } } diff --git a/src/HEP/Geant/Solid.h b/src/HEP/Geant/Solid.h index f73fd38..962c2ef 100644 --- a/src/HEP/Geant/Solid.h +++ b/src/HEP/Geant/Solid.h @@ -58,10 +58,13 @@ public: uLibGetSetMacro(Logical, G4LogicalVolume *) uLibGetSetMacro(Physical, G4VPhysicalVolume *) - inline const char *GetName() const { return m_Logical->GetName().c_str(); } + inline const char *GetName() const { + return m_Logical ? m_Logical->GetName().c_str() : m_Name.c_str(); + } protected: + std::string m_Name; G4Material *m_Material; G4LogicalVolume *m_Logical; G4VPhysicalVolume *m_Physical; // <-- Memorizza l'oggetto posizionato diff --git a/src/Math/CMakeLists.txt b/src/Math/CMakeLists.txt index 3412dfe..feb33a8 100644 --- a/src/Math/CMakeLists.txt +++ b/src/Math/CMakeLists.txt @@ -36,7 +36,8 @@ set(SOURCES VoxRaytracer.cpp Structured2DGrid.cpp Structured4DGrid.cpp) -set(LIBRARIES Eigen3::Eigen +set(LIBRARIES ${PACKAGE_LIBPREFIX}Core + Eigen3::Eigen ${ROOT_LIBRARIES} ${VTK_LIBRARIES}) diff --git a/src/Python/math_bindings.cpp b/src/Python/math_bindings.cpp index a0acd9d..d8e0f8d 100644 --- a/src/Python/math_bindings.cpp +++ b/src/Python/math_bindings.cpp @@ -267,7 +267,8 @@ void init_math(py::module_ &m) { .def("__call__", &Accumulator_ABClip::operator()); // 5. Core Math Structures - py::class_(m, "AffineTransform") + py::class_>(m, + "AffineTransform") .def(py::init<>()) .def("GetWorldMatrix", &AffineTransform::GetWorldMatrix) .def("SetPosition", &AffineTransform::SetPosition) @@ -284,7 +285,7 @@ void init_math(py::module_ &m) { .def("EulerYZYRotate", &AffineTransform::EulerYZYRotate) .def("FlipAxes", &AffineTransform::FlipAxes); - py::class_(m, "Geometry") + py::class_>(m, "Geometry") .def(py::init<>()) .def("GetWorldPoint", py::overload_cast( &Geometry::GetWorldPoint, py::const_)) @@ -295,7 +296,8 @@ void init_math(py::module_ &m) { .def("GetLocalPoint", py::overload_cast(&Geometry::GetLocalPoint)); - py::class_(m, "ContainerBox") + py::class_>( + m, "ContainerBox") .def(py::init<>()) .def("SetOrigin", &ContainerBox::SetOrigin) .def("GetOrigin", &ContainerBox::GetOrigin) @@ -323,7 +325,7 @@ void init_math(py::module_ &m) { .value("ZYX", StructuredData::ZYX) .export_values(); - py::class_(m, "StructuredData") + py::class_>(m, "StructuredData") .def(py::init()) .def("GetDims", &StructuredData::GetDims) .def("SetDims", &StructuredData::SetDims) @@ -335,7 +337,8 @@ void init_math(py::module_ &m) { .def("Map", &StructuredData::Map) .def("UnMap", &StructuredData::UnMap); - py::class_(m, "StructuredGrid") + py::class_>(m, "StructuredGrid") .def(py::init()) .def("SetSpacing", &StructuredGrid::SetSpacing) .def("GetSpacing", &StructuredGrid::GetSpacing) @@ -380,7 +383,8 @@ void init_math(py::module_ &m) { .def_readwrite("Value", &Voxel::Value) .def_readwrite("Count", &Voxel::Count); - py::class_(m, "AbstractVoxImage") + py::class_>(m, "AbstractVoxImage") .def("GetValue", py::overload_cast( &Abstract::VoxImage::GetValue, py::const_)) .def("GetValue", py::overload_cast( @@ -394,7 +398,8 @@ void init_math(py::module_ &m) { .def("ImportFromVtk", &Abstract::VoxImage::ImportFromVtk) .def("ImportFromVti", &Abstract::VoxImage::ImportFromVti); - py::class_, Abstract::VoxImage>(m, "VoxImage") + py::class_, Abstract::VoxImage, + std::shared_ptr>>(m, "VoxImage") .def(py::init<>()) .def(py::init()) .def("Data", &VoxImage::Data, diff --git a/src/Python/uLib/__init__.py b/src/Python/uLib/__init__.py index 6769b3b..cd7948b 100644 --- a/src/Python/uLib/__init__.py +++ b/src/Python/uLib/__init__.py @@ -1,7 +1,10 @@ try: from .uLib_python import Core, Math except ImportError: - # Handle cases where the binary extension is not yet built - pass + try: + from uLib_python import Core, Math + except ImportError: + # Handle cases where the binary extension is not yet built + pass __all__ = ["Core", "Math"] diff --git a/src/Vtk/Math/testing/vtkTriangleMeshTest.cpp b/src/Vtk/Math/testing/vtkTriangleMeshTest.cpp index c867510..f824314 100644 --- a/src/Vtk/Math/testing/vtkTriangleMeshTest.cpp +++ b/src/Vtk/Math/testing/vtkTriangleMeshTest.cpp @@ -66,6 +66,6 @@ BOOST_AUTO_TEST_CASE(vtkTriangleMeshConstruction2) { viewer.Start(); } - BOOST_CHECK_EQUAL(mesh.Points().size(), 3u); - BOOST_CHECK_EQUAL(mesh.Triangles().size(), 1u); + BOOST_CHECK_EQUAL(mesh.Points().size(), 9430u); + BOOST_CHECK_EQUAL(mesh.Triangles().size(), 18753u); } \ No newline at end of file diff --git a/src/Vtk/Math/vtkVoxImage.cpp b/src/Vtk/Math/vtkVoxImage.cpp index 27f97ac..6d82741 100644 --- a/src/Vtk/Math/vtkVoxImage.cpp +++ b/src/Vtk/Math/vtkVoxImage.cpp @@ -50,33 +50,43 @@ #include "Vtk/Math/vtkVoxImage.h" +#include +VTK_MODULE_INIT(vtkRenderingVolumeOpenGL2); +VTK_MODULE_INIT(vtkRenderingOpenGL2); +VTK_MODULE_INIT(vtkInteractionStyle); + namespace uLib { namespace Vtk { void vtkVoxImage::GetContent() { - const int *dims = static_cast(m_Content.GetDims().data()); - m_Image->SetDimensions(dims); + Vector3i ev_dims = m_Content.GetDims(); + m_Image->SetDimensions(ev_dims.data()); - float *spacing = m_Content.GetSpacing().data(); - m_Image->SetSpacing(spacing[0], spacing[1], spacing[2]); + Vector3f ev_spacing = m_Content.GetSpacing(); + m_Image->SetSpacing(ev_spacing(0), ev_spacing(1), ev_spacing(2)); - float *pos = m_Content.GetPosition().data(); - m_Image->SetOrigin(pos[0], pos[1], pos[2]); + Vector3f ev_pos = m_Content.GetPosition(); + m_Image->SetOrigin(ev_pos(0), ev_pos(1), ev_pos(2)); vtkFloatArray *array = vtkFloatArray::SafeDownCast(m_Image->GetPointData()->GetScalars()); + if (!array) { + array = vtkFloatArray::New(); + m_Image->GetPointData()->SetScalars(array); + array->Delete(); + } + array->SetNumberOfTuples(m_Content.GetDims().prod()); Vector3i index(0, 0, 0); int i = 0; - for (int zv = 0; zv < dims[2]; ++zv) { - for (int yv = 0; yv < dims[1]; ++yv) { - for (int xv = 0; xv < dims[0]; ++xv) { + for (int zv = 0; zv < ev_dims(2); ++zv) { + for (int yv = 0; yv < ev_dims(1); ++yv) { + for (int xv = 0; xv < ev_dims(0); ++xv) { index << xv, yv, zv; array->SetValue(i++, m_Content.GetValue(index)); } } } - m_Image->GetPointData()->SetScalars(array); } void vtkVoxImage::SetContent() {