refactor: unify Object signal system, update property connections, and integrate Eigen3 into Root module

This commit is contained in:
AndreaRigoni
2026-04-09 16:27:58 +00:00
parent 76f29328cd
commit dfd33e9a9c
14 changed files with 294 additions and 318 deletions

View File

@@ -19,6 +19,18 @@ endif()
project(uLib) project(uLib)
option(ULIB_USE_CCACHE "Use ccache for build acceleration" ON)
if(ULIB_USE_CCACHE)
find_program(CCACHE_PROGRAM ccache)
if(CCACHE_PROGRAM)
set(CMAKE_CXX_COMPILER_LAUNCHER "${CCACHE_PROGRAM}")
set(CMAKE_C_COMPILER_LAUNCHER "${CCACHE_PROGRAM}")
endif()
else()
set(CMAKE_CXX_COMPILER_LAUNCHER "")
set(CMAKE_C_COMPILER_LAUNCHER "")
endif()
# Applica la flag SOLO se il compilatore è GCC # Applica la flag SOLO se il compilatore è GCC
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
add_compile_options(-fno-merge-constants) add_compile_options(-fno-merge-constants)
@@ -130,8 +142,11 @@ find_package(Boost 1.45.0 COMPONENTS program_options serialization unit_test_fra
include_directories(${Boost_INCLUDE_DIRS}) include_directories(${Boost_INCLUDE_DIRS})
find_package(Eigen3 CONFIG REQUIRED) find_package(Eigen3 CONFIG REQUIRED)
get_target_property(EIGEN3_INCLUDE_DIRS Eigen3::Eigen INTERFACE_INCLUDE_DIRECTORIES) # if(NOT EIGEN3_INCLUDE_DIRS)
include_directories(${EIGEN3_INCLUDE_DIRS}) # get_target_property(EIGEN3_INCLUDE_DIRS Eigen3::Eigen INTERFACE_INCLUDE_DIRECTORIES)
# else()
# include_directories(${EIGEN3_INCLUDE_DIRS})
# endif()
find_package(OpenMP) find_package(OpenMP)

View File

@@ -1,5 +1,5 @@
[requires] [requires]
eigen/3.4.0 # eigen/5.0.1
boost/1.86.0 boost/1.86.0
# pybind11/3.0.2 # pybind11/3.0.2
hdf5/1.14.3 hdf5/1.14.3

View File

@@ -111,10 +111,10 @@ PropertyBase* Object::GetProperty(const std::string& name) const {
void Object::NotifyPropertiesUpdated() { void Object::NotifyPropertiesUpdated() {
for (auto* p : d->m_Properties) p->Updated(); for (auto* p : d->m_Properties) p->Updated();
for (auto* p : d->m_DynamicProperties) p->Updated(); for (auto* p : d->m_DynamicProperties) p->Updated();
this->Updated();
} }
void Object::Updated() { ULIB_SIGNAL_EMIT(Object::Updated); } void Object::Updated() { ULIB_SIGNAL_EMIT(Object::Updated); }
void Object::PropertyUpdated() { ULIB_SIGNAL_EMIT(Object::PropertyUpdated); }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////

View File

@@ -78,13 +78,14 @@ public:
Object(const Object &copy); Object(const Object &copy);
virtual ~Object(); virtual ~Object();
virtual const char * GetClassName() const { return type_name(); } virtual const char *GetClassName() const { return type_name(); }
virtual const char * type_name() const { return "Object"; } virtual const char *type_name() const { return "Object"; }
const std::string& GetInstanceName() const; const std::string &GetInstanceName() const;
void SetInstanceName(const std::string& name); void SetInstanceName(const std::string &name);
/** @brief Temporarily blocks all signal emissions from this object. Returns previous state. */ /** @brief Temporarily blocks all signal emissions from this object. Returns
* previous state. */
bool blockSignals(bool block); bool blockSignals(bool block);
/** @brief Checks if signals are currently blocked. */ /** @brief Checks if signals are currently blocked. */
@@ -92,14 +93,15 @@ public:
//////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////
// PROPERTIES // // PROPERTIES //
virtual void RegisterProperty(PropertyBase* property); virtual void RegisterProperty(PropertyBase *property);
virtual void RegisterDynamicProperty(PropertyBase* property); virtual void RegisterDynamicProperty(PropertyBase *property);
virtual void RegisterDisplayProperty(PropertyBase* property); virtual void RegisterDisplayProperty(PropertyBase *property);
virtual const std::vector<PropertyBase*>& GetProperties() const; virtual const std::vector<PropertyBase *> &GetProperties() const;
virtual const std::vector<PropertyBase*>& GetDisplayProperties() const; virtual const std::vector<PropertyBase *> &GetDisplayProperties() const;
PropertyBase* GetProperty(const std::string& name) const; PropertyBase *GetProperty(const std::string &name) const;
/** @brief Sends an Updated signal for all properties of this object. useful for real-time UI refresh. */ /** @brief Sends an Updated signal for all properties of this object. useful
* for real-time UI refresh. */
void NotifyPropertiesUpdated(); void NotifyPropertiesUpdated();
//////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////
@@ -109,7 +111,7 @@ public:
virtual void DeepCopy(const Object &copy); virtual void DeepCopy(const Object &copy);
/** @brief Returns a nested context for children objects, if any. */ /** @brief Returns a nested context for children objects, if any. */
virtual ObjectsContext* GetChildren() { return nullptr; } virtual ObjectsContext *GetChildren() { return nullptr; }
//////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////
// SERIALIZATION // // SERIALIZATION //
@@ -117,13 +119,20 @@ public:
template <class ArchiveT> template <class ArchiveT>
void serialize(ArchiveT &ar, const unsigned int version); void serialize(ArchiveT &ar, const unsigned int version);
virtual void serialize(Archive::xml_oarchive & ar, const unsigned int version) {} virtual void serialize(Archive::xml_oarchive &ar,
virtual void serialize(Archive::xml_iarchive & ar, const unsigned int version) {} const unsigned int version) {}
virtual void serialize(Archive::text_oarchive & ar, const unsigned int version) {} virtual void serialize(Archive::xml_iarchive &ar,
virtual void serialize(Archive::text_iarchive & ar, const unsigned int version) {} const unsigned int version) {}
virtual void serialize(Archive::hrt_oarchive & ar, const unsigned int version) {} virtual void serialize(Archive::text_oarchive &ar,
virtual void serialize(Archive::hrt_iarchive & ar, const unsigned int version) {} const unsigned int version) {}
virtual void serialize(Archive::log_archive & ar, const unsigned int version) {} virtual void serialize(Archive::text_iarchive &ar,
const unsigned int version) {}
virtual void serialize(Archive::hrt_oarchive &ar,
const unsigned int version) {}
virtual void serialize(Archive::hrt_iarchive &ar,
const unsigned int version) {}
virtual void serialize(Archive::log_archive &ar, const unsigned int version) {
}
template <class ArchiveT> template <class ArchiveT>
void save_override(ArchiveT &ar, const unsigned int version) {} void save_override(ArchiveT &ar, const unsigned int version) {}
@@ -137,9 +146,8 @@ public:
//////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////
// SIGNALS // // SIGNALS //
signals: signals:
virtual void Updated(); virtual void Updated();
virtual void PropertyUpdated();
// Qt4 style connector // // Qt4 style connector //
static bool connect(const Object *ob1, const char *signal_name, static bool connect(const Object *ob1, const char *signal_name,
@@ -160,8 +168,8 @@ public:
connect(typename FunctionPointer<Func1>::Object *sender, Func1 sigf, connect(typename FunctionPointer<Func1>::Object *sender, Func1 sigf,
typename FunctionPointer<Func2>::Object *receiver, Func2 slof) { typename FunctionPointer<Func2>::Object *receiver, Func2 slof) {
SignalBase *sigb = sender->findOrAddSignal(sigf); SignalBase *sigb = sender->findOrAddSignal(sigf);
return ConnectSignal<typename FunctionPointer<Func1>::SignalSignature>(sigb, slof, return ConnectSignal<typename FunctionPointer<Func1>::SignalSignature>(
receiver); sigb, slof, receiver);
} }
// Lambda/Function object connector // // Lambda/Function object connector //
@@ -183,9 +191,10 @@ public:
} }
template <typename FuncT> template <typename FuncT>
static inline Connection connect(SignalBase *sigb, FuncT slof, Object *receiver) { static inline Connection connect(SignalBase *sigb, FuncT slof,
return ConnectSignal<typename FunctionPointer<FuncT>::SignalSignature>(sigb, slof, Object *receiver) {
receiver); return ConnectSignal<typename FunctionPointer<FuncT>::SignalSignature>(
sigb, slof, receiver);
} }
template <typename FuncT> template <typename FuncT>

View File

@@ -53,9 +53,6 @@ public:
return GetGroup() + "." + GetName(); return GetGroup() + "." + GetName();
} }
// Signal support
signals:
virtual void Updated() override { ULIB_SIGNAL_EMIT(PropertyBase::Updated); }
// Serialization support for different uLib archives // Serialization support for different uLib archives
virtual void serialize(Archive::xml_oarchive & ar, const unsigned int version) override = 0; virtual void serialize(Archive::xml_oarchive & ar, const unsigned int version) override = 0;
@@ -169,7 +166,6 @@ public:
virtual void serialize(Archive::property_register_archive & ar, const unsigned int v) override; virtual void serialize(Archive::property_register_archive & ar, const unsigned int v) override;
virtual void Updated() override { PropertyBase::Updated(); this->PropertyChanged(); }
protected: protected:
std::string m_name; std::string m_name;
@@ -263,7 +259,7 @@ public:
if (m_DisplayOnly) { if (m_DisplayOnly) {
m_Object->RegisterDisplayProperty(newP); m_Object->RegisterDisplayProperty(newP);
Object* obj = m_Object; Object* obj = m_Object;
Object::connect(newP, &PropertyBase::Updated, [obj]() { obj->Updated(); }); Object::connect(newP, &Object::Updated, [obj]() { obj->Updated(); });
} else { } else {
m_Object->RegisterDynamicProperty(newP); m_Object->RegisterDynamicProperty(newP);
} }
@@ -277,7 +273,7 @@ public:
if (m_DisplayOnly) { if (m_DisplayOnly) {
m_Object->RegisterDisplayProperty(p); m_Object->RegisterDisplayProperty(p);
Object* obj = m_Object; Object* obj = m_Object;
Object::connect(p, &PropertyBase::Updated, [obj]() { obj->Updated(); }); Object::connect(p, &Object::Updated, [obj]() { obj->Updated(); });
} else { } else {
m_Object->RegisterDynamicProperty(p); m_Object->RegisterDynamicProperty(p);
} }
@@ -300,7 +296,7 @@ public:
if (m_Object) { if (m_Object) {
EnumProperty* p = new EnumProperty(m_Object, t.name(), (int*)&const_cast<boost::serialization::hrp_enum<T>&>(t).value(), t.labels(), t.units() ? t.units() : "", GetCurrentGroup()); EnumProperty* p = new EnumProperty(m_Object, t.name(), (int*)&const_cast<boost::serialization::hrp_enum<T>&>(t).value(), t.labels(), t.units() ? t.units() : "", GetCurrentGroup());
p->SetReadOnly(t.is_read_only()); p->SetReadOnly(t.is_read_only());
if (m_DisplayOnly) { m_Object->RegisterDisplayProperty(p); Object* obj = m_Object; Object::connect(p, &PropertyBase::Updated, [obj]() { obj->Updated(); }); } if (m_DisplayOnly) { m_Object->RegisterDisplayProperty(p); Object* obj = m_Object; Object::connect(p, &Object::Updated, [obj]() { obj->Updated(); }); }
else { m_Object->RegisterDynamicProperty(p); } else { m_Object->RegisterDynamicProperty(p); }
} }
} }
@@ -308,7 +304,7 @@ public:
if (m_Object) { if (m_Object) {
EnumProperty* p = new EnumProperty(m_Object, t.name(), (int*)&const_cast<boost::serialization::hrp_enum_val<T>&>(t).value(), t.labels(), t.units() ? t.units() : "", GetCurrentGroup()); EnumProperty* p = new EnumProperty(m_Object, t.name(), (int*)&const_cast<boost::serialization::hrp_enum_val<T>&>(t).value(), t.labels(), t.units() ? t.units() : "", GetCurrentGroup());
p->SetReadOnly(t.is_read_only()); p->SetReadOnly(t.is_read_only());
if (m_DisplayOnly) { m_Object->RegisterDisplayProperty(p); Object* obj = m_Object; Object::connect(p, &PropertyBase::Updated, [obj]() { obj->Updated(); }); } if (m_DisplayOnly) { m_Object->RegisterDisplayProperty(p); Object* obj = m_Object; Object::connect(p, &Object::Updated, [obj]() { obj->Updated(); }); }
else { m_Object->RegisterDynamicProperty(p); } else { m_Object->RegisterDynamicProperty(p); }
} }
} }

View File

@@ -50,9 +50,9 @@
// #include <Eigen/src/Core/Matrix.h> // #include <Eigen/src/Core/Matrix.h>
#include <stdlib.h> #include <stdlib.h>
#include <Eigen/Dense>
#include "Core/Types.h"
#include "Core/Property.h" #include "Core/Property.h"
#include "Core/Types.h"
#include <Eigen/Dense>
//// BOOST SERIALIZATION /////////////////////////////////////////////////////// //// BOOST SERIALIZATION ///////////////////////////////////////////////////////
@@ -150,7 +150,6 @@ typedef Eigen::MatrixXi MatrixXi;
typedef Eigen::MatrixXf MatrixXf; typedef Eigen::MatrixXf MatrixXf;
typedef Eigen::MatrixXd MatrixXd; typedef Eigen::MatrixXd MatrixXd;
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// Vector String interaction /////////////////////////////////////////////////// // Vector String interaction ///////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
@@ -192,7 +191,7 @@ std::string VectorxT_ToString(const Eigen::Matrix<T, size, 1> &vec) {
// } // }
template <typename T, int size> template <typename T, int size>
void operator >> (std::string &str, Eigen::Matrix<T, size, 1> &vec) { void operator>>(std::string &str, Eigen::Matrix<T, size, 1> &vec) {
VectorxT_StringTo(vec, str); VectorxT_StringTo(vec, str);
} }
@@ -205,9 +204,7 @@ public:
typedef Eigen::Matrix<Scalarf, 4, 1> BaseClass; typedef Eigen::Matrix<Scalarf, 4, 1> BaseClass;
_HPoint3f() : BaseClass(0, 0, 0, p) {} _HPoint3f() : BaseClass(0, 0, 0, p) {}
_HPoint3f(int rows, int cols) : BaseClass() { _HPoint3f(int rows, int cols) : BaseClass() { this->operator()(3) = p; }
this->operator()(3) = p;
}
_HPoint3f(float x, float y, float z) : BaseClass(x, y, z, p) {} _HPoint3f(float x, float y, float z) : BaseClass(x, y, z, p) {}
_HPoint3f(Vector3f &in) : BaseClass(in.homogeneous()) { _HPoint3f(Vector3f &in) : BaseClass(in.homogeneous()) {
this->operator()(3) = p; this->operator()(3) = p;
@@ -250,13 +247,13 @@ struct _HError3f {
HVector3f position_error; HVector3f position_error;
HVector3f direction_error; HVector3f direction_error;
}; };
typedef struct _HError3f HError3f; typedef struct _HError3f HError3f;
inline std::ostream &operator<<(std::ostream &stream, const HError3f &err) { inline std::ostream &operator<<(std::ostream &stream, const HError3f &err) {
stream << "HError3f(" << "ept[" << err.position_error.transpose() stream << "HError3f(" << "ept[" << err.position_error.transpose()
<< "] , edr[" << err.direction_error.transpose() << "]) "; << "] , edr[" << err.direction_error.transpose() << "]) ";
return stream; return stream;
} }
typedef Property<Scalari> ScalariProperty; typedef Property<Scalari> ScalariProperty;
typedef Property<Scalarui> ScalaruiProperty; typedef Property<Scalarui> ScalaruiProperty;
@@ -296,7 +293,7 @@ typedef Property<Matrix4d> Matrix4dProperty;
typedef Property<HVector3f> HVector3fProperty; typedef Property<HVector3f> HVector3fProperty;
typedef Property<HPoint3f> HPoint3fProperty; typedef Property<HPoint3f> HPoint3fProperty;
} // namespace uLib } // namespace uLib
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////

View File

@@ -23,8 +23,6 @@
//////////////////////////////////////////////////////////////////////////////*/ //////////////////////////////////////////////////////////////////////////////*/
/* /*
* Copyright (C) 2012 Andrea Rigoni Garola <andrea.rigoni@pd.infn.it> * Copyright (C) 2012 Andrea Rigoni Garola <andrea.rigoni@pd.infn.it>
* *
@@ -45,84 +43,66 @@
* *
*/ */
#ifndef U_TRANSFORM_H #ifndef U_TRANSFORM_H
#define U_TRANSFORM_H #define U_TRANSFORM_H
#include <Eigen/Geometry>
#include "Math/Units.h"
#include "Math/Dense.h" #include "Math/Dense.h"
#include "Math/Units.h"
#include <Eigen/Geometry>
namespace uLib { namespace uLib {
using Eigen::Isometry3f;
using Eigen::Isometry3d; using Eigen::Isometry3d;
using Eigen::Isometry3f;
using Eigen::Affine3f;
using Eigen::Affine3d; using Eigen::Affine3d;
using Eigen::Affine3f;
using Eigen::Projective3f;
using Eigen::Projective3d; using Eigen::Projective3d;
using Eigen::Projective3f;
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
///////// AFFINE TRANSFORM WRAPPER ////////////////////////////////////////// ///////// AFFINE TRANSFORM WRAPPER //////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
class AffineTransform : virtual public Object { class AffineTransform : virtual public Object {
public: public:
uLibTypeMacro(AffineTransform, Object) uLibTypeMacro(AffineTransform, Object) protected :
protected:
Affine3f m_T; Affine3f m_T;
AffineTransform *m_Parent; AffineTransform *m_Parent;
public: public:
AffineTransform() : AffineTransform() : m_T(Matrix4f::Identity()), m_Parent(NULL) {}
m_T(Matrix4f::Identity()),
m_Parent(NULL)
{}
AffineTransform(AffineTransform *parent) : AffineTransform(AffineTransform *parent)
m_T(Matrix4f::Identity()), : m_T(Matrix4f::Identity()), m_Parent(parent) {}
m_Parent(parent)
{}
AffineTransform(const AffineTransform &copy) : AffineTransform(const AffineTransform &copy)
m_T(copy.m_T), : m_T(copy.m_T), m_Parent(copy.m_Parent) {}
m_Parent(copy.m_Parent)
{}
Affine3f& GetTransform() { return m_T; } Affine3f &GetTransform() { return m_T; }
AffineTransform *GetParent() const { return this->m_Parent; } AffineTransform *GetParent() const { return this->m_Parent; }
void SetParent(AffineTransform *name) { this->m_Parent = name; } void SetParent(AffineTransform *name) { this->m_Parent = name; }
void SetMatrix (const Matrix4f &mat) { m_T.matrix() = mat; } void SetMatrix(const Matrix4f &mat) { m_T.matrix() = mat; }
Matrix4f& GetMatrix () { return m_T.matrix(); } Matrix4f &GetMatrix() { return m_T.matrix(); }
const Matrix4f& GetMatrix () const { return m_T.matrix(); } const Matrix4f &GetMatrix() const { return m_T.matrix(); }
Matrix4f GetWorldMatrix() const Matrix4f GetWorldMatrix() const {
{ if (!m_Parent)
if(!m_Parent) return m_T.matrix(); return m_T.matrix();
else return m_Parent->GetWorldMatrix() * m_T.matrix(); // T = B * A // else
return m_Parent->GetWorldMatrix() * m_T.matrix(); // T = B * A //
} }
void SetWorldMatrix(const Matrix4f &mat) void SetWorldMatrix(const Matrix4f &mat) {
{ if (!m_Parent)
if(!m_Parent) m_T.matrix() = mat; m_T.matrix() = mat;
else m_T.matrix() = m_Parent->GetWorldMatrix().inverse() * mat; else
m_T.matrix() = m_Parent->GetWorldMatrix().inverse() * mat;
} }
void SetPosition(const Vector3f &v) { this->m_T.translation() = v; } void SetPosition(const Vector3f &v) { this->m_T.translation() = v; }
@@ -143,44 +123,40 @@ public:
this->m_T.linear().col(2).norm()); this->m_T.linear().col(2).norm());
} }
void Rotate(const Matrix3f &m) { this->m_T.rotate(m); } void Rotate(const Matrix3f &m) { this->m_T.rotate(m); }
void Rotate(const float angle, Vector3f axis) void Rotate(const float angle, Vector3f axis) {
{
axis.normalize(); // prehaps not necessary ( see eigens ) axis.normalize(); // prehaps not necessary ( see eigens )
Eigen::AngleAxisf ax(angle,axis); Eigen::AngleAxisf ax(angle, axis);
this->m_T.rotate(Eigen::Quaternion<float>(ax)); this->m_T.rotate(Eigen::Quaternion<float>(ax));
} }
void Rotate(const Vector3f euler_axis) { void Rotate(const Vector3f euler_axis) {
float angle = euler_axis.norm(); float angle = euler_axis.norm();
Rotate(angle,euler_axis); Rotate(angle, euler_axis);
} }
void PreRotate(const Matrix3f &m) { this->m_T.prerotate(m); } void PreRotate(const Matrix3f &m) { this->m_T.prerotate(m); }
void QuaternionRotate(const Vector4f &q) void QuaternionRotate(const Vector4f &q) {
{ this->m_T.rotate(Eigen::Quaternion<float>(q)); } this->m_T.rotate(Eigen::Quaternion<float>(q));
}
void EulerYZYRotate(const Vector3f &e) { void EulerYZYRotate(const Vector3f &e) {
Matrix3f mat; Matrix3f mat;
mat = Eigen::AngleAxisf(e.x(), Vector3f::UnitY()) mat = Eigen::AngleAxisf(e.x(), Vector3f::UnitY()) *
* Eigen::AngleAxisf(e.y(), Vector3f::UnitZ()) Eigen::AngleAxisf(e.y(), Vector3f::UnitZ()) *
* Eigen::AngleAxisf(e.z(), Vector3f::UnitY()); Eigen::AngleAxisf(e.z(), Vector3f::UnitY());
m_T.rotate(mat); m_T.rotate(mat);
} }
void FlipAxes(int first, int second) void FlipAxes(int first, int second) {
{
Matrix3f mat = Matrix3f::Identity(); Matrix3f mat = Matrix3f::Identity();
mat.col(first).swap(mat.col(second)); mat.col(first).swap(mat.col(second));
m_T.rotate(mat); m_T.rotate(mat);
} }
}; };
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
///////// TRS PARAMETERS ///////////////////////////////////////////////////// ///////// TRS PARAMETERS /////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
@@ -189,11 +165,10 @@ typedef Eigen::Affine3f AffineMatrix;
class TRS : public AffineTransform { class TRS : public AffineTransform {
uLibTypeMacro(TRS, AffineTransform) uLibTypeMacro(TRS, AffineTransform) ULIB_SERIALIZE_ACCESS
ULIB_SERIALIZE_ACCESS
// ULIB_DECLARE_PROPERTIES(TRS) // ULIB_DECLARE_PROPERTIES(TRS)
public: public :
Vector3f position = Vector3f::Zero(); Vector3f position = Vector3f::Zero();
Vector3f rotation = Vector3f::Zero(); Vector3f rotation = Vector3f::Zero();
@@ -201,28 +176,27 @@ public:
TRS() = default; TRS() = default;
TRS(const class AffineTransform& at) { TRS(const class AffineTransform &at) { this->FromMatrix(at.GetMatrix()); }
this->FromMatrix(at.GetMatrix());
}
TRS(const Matrix4f& mat) { TRS(const Matrix4f &mat) { this->FromMatrix(mat); }
this->FromMatrix(mat);
}
void FromMatrix(const Matrix4f& mat) { void FromMatrix(const Matrix4f &mat) {
this->position = mat.block<3,1>(0,3); this->position = mat.block<3, 1>(0, 3);
Matrix3f linear = mat.block<3,3>(0,0); Matrix3f linear = mat.block<3, 3>(0, 0);
this->scaling(0) = linear.col(0).norm(); this->scaling(0) = linear.col(0).norm();
this->scaling(1) = linear.col(1).norm(); this->scaling(1) = linear.col(1).norm();
this->scaling(2) = linear.col(2).norm(); this->scaling(2) = linear.col(2).norm();
Matrix3f rot = linear; Matrix3f rot = linear;
if (this->scaling(0) > 1e-6) rot.col(0) /= this->scaling(0); if (this->scaling(0) > 1e-6)
if (this->scaling(1) > 1e-6) rot.col(1) /= this->scaling(1); rot.col(0) /= this->scaling(0);
if (this->scaling(2) > 1e-6) rot.col(2) /= this->scaling(2); if (this->scaling(1) > 1e-6)
rot.col(1) /= this->scaling(1);
if (this->scaling(2) > 1e-6)
rot.col(2) /= this->scaling(2);
Vector3f euler = rot.eulerAngles(2, 1, 0); Vector3f euler = rot.canonicalEulerAngles(2, 1, 0);
this->rotation = Vector3f(euler(2), euler(1), euler(0)); this->rotation = Vector3f(euler(2), euler(1), euler(0));
this->SetMatrix(mat); this->SetMatrix(mat);
@@ -246,9 +220,7 @@ public:
this->SyncMatrix(); this->SyncMatrix();
} }
void SyncMatrix() { void SyncMatrix() { this->GetTransform() = GetAffineMatrix(); }
this->GetTransform() = GetAffineMatrix();
}
void Updated() override { void Updated() override {
this->SyncMatrix(); this->SyncMatrix();
@@ -257,13 +229,12 @@ public:
} }
template <class ArchiveT> template <class ArchiveT>
void serialize(ArchiveT & ar, const unsigned int version) { void serialize(ArchiveT &ar, const unsigned int version) {
ar & HRPU(position, "mm"); ar &HRPU(position, "mm");
ar & HRPU(rotation, "rad"); ar &HRPU(rotation, "rad");
ar & HRP(scaling); ar &HRP(scaling);
} }
AffineMatrix GetAffineMatrix() const { AffineMatrix GetAffineMatrix() const {
AffineMatrix m = AffineMatrix::Identity(); AffineMatrix m = AffineMatrix::Identity();
m.translate(position); m.translate(position);
@@ -274,31 +245,19 @@ public:
return m; return m;
} }
Matrix4f GetMatrix() const { Matrix4f GetMatrix() const { return this->GetAffineMatrix().matrix(); }
return this->GetAffineMatrix().matrix();
}
}; };
inline std::ostream &operator<<(std::ostream &os, const TRS &trs) {
inline std::ostream& operator<<(std::ostream& os, const TRS& trs) {
os << trs.position << " " << trs.rotation << " " << trs.scaling; os << trs.position << " " << trs.rotation << " " << trs.scaling;
return os; return os;
} }
inline std::istream& operator>>(std::istream& is, TRS& trs) { inline std::istream &operator>>(std::istream &is, TRS &trs) {
is >> trs.position >> trs.rotation >> trs.scaling; is >> trs.position >> trs.rotation >> trs.scaling;
return is; return is;
} }
} // uLib } // namespace uLib
#endif // U_TRANSFORM_H
#endif//U_TRANSFORM_H

View File

@@ -33,7 +33,11 @@ set(DICTIONARY_HEADERS muCastorMCTrack.h
SkinDetectorWriter.h) SkinDetectorWriter.h)
set(LIBRARIES ${ROOT_LIBRARIES} set(LIBRARIES ${ROOT_LIBRARIES}
${PACKAGE_LIBPREFIX}Math) ${PACKAGE_LIBPREFIX}Math
Eigen3::Eigen)
get_target_property(EIGEN3_INC Eigen3::Eigen INTERFACE_INCLUDE_DIRECTORIES)
include_directories(${EIGEN3_INC})
set(rDictName ${PACKAGE_LIBPREFIX}RootDict) set(rDictName ${PACKAGE_LIBPREFIX}RootDict)
root_generate_dictionary(${rDictName} ${DICTIONARY_HEADERS} root_generate_dictionary(${rDictName} ${DICTIONARY_HEADERS}

View File

@@ -1,41 +1,38 @@
#ifndef muCastor_MCTRACK_H #ifndef muCastor_MCTRACK_H
#define muCastor_MCTRACK_H #define muCastor_MCTRACK_H
//######################################## // ########################################
// muCastorMCTrack class // muCastorMCTrack class
// Created at the University of Brescia, Italy // Created at the University of Brescia, Italy
// Date: December 2011 // Date: December 2011
// Autors: Germano Bonomi germano.bonomi@ing.unibs.it // Autors: Germano Bonomi germano.bonomi@ing.unibs.it
// Martin Subieta martin.subieta@ing.unibs.it // Martin Subieta martin.subieta@ing.unibs.it
//######################################## // ########################################
#include <iostream> #include "Detectors/MuonScatter.h"
#include "vector"
#include "TObject.h" #include "TObject.h"
#include "TParticle.h" #include "TParticle.h"
#include "Detectors/MuonScatter.h" #include "vector"
#include <iostream>
class TClonesArray; class TClonesArray;
class muCastorMCTrack : public TObject class muCastorMCTrack : public TObject {
{
public:
public:
/** Default constructor **/ /** Default constructor **/
muCastorMCTrack(); muCastorMCTrack();
/** Constructor from TParticle **/ /** Constructor from TParticle **/
muCastorMCTrack(TParticle* particle); muCastorMCTrack(TParticle *particle);
/** Destructor **/ /** Destructor **/
virtual ~muCastorMCTrack(); virtual ~muCastorMCTrack();
void Reset(); void Reset();
/** Accessors **/ /** Accessors **/
Int_t GetFirstDaughter() const { return fDaughter[0];} Int_t GetFirstDaughter() const { return fDaughter[0]; }
Int_t GetMother() const { return fMother[0];} Int_t GetMother() const { return fMother[0]; }
/** Modifiers **/ /** Modifiers **/
virtual void AddPoint(TLorentzVector pos, TLorentzVector mom); virtual void AddPoint(TLorentzVector pos, TLorentzVector mom);
@@ -52,8 +49,7 @@ class muCastorMCTrack : public TObject
} }
public: public:
/* Private variables - copying private variables of TParticle */
/* Private variables - copying private variables of TParticle */
Int_t fPdgCode; // PDG code of the particle Int_t fPdgCode; // PDG code of the particle
Int_t fMother[2]; // Indices of the mother particles Int_t fMother[2]; // Indices of the mother particles
@@ -80,9 +76,9 @@ public:
Double_t *fPntMomZ; //[fNpoints] array of points (pz) belonging to this track Double_t *fPntMomZ; //[fNpoints] array of points (pz) belonging to this track
Double_t *fPntE; //[fNpoints] array of points (E) belonging to this track Double_t *fPntE; //[fNpoints] array of points (E) belonging to this track
ClassDef(muCastorMCTrack,1); ClassDef(muCastorMCTrack, 1);
}; };
uLib::MuonScatter &operator << (uLib::MuonScatter &mu, const muCastorMCTrack &bsmu); uLib::MuonScatter &operator<<(uLib::MuonScatter &mu,
#endif //muCastor_MCTRACK_H const muCastorMCTrack &bsmu);
#endif // muCastor_MCTRACK_H

View File

@@ -61,9 +61,9 @@ public:
Content &GetModel(); Content &GetModel();
uLib::Object* GetContent() const override; uLib::Object* GetContent() const override;
void PrintSelf(std::ostream &o) const; void PrintSelf(std::ostream &o) const override;
virtual vtkPolyData *GetPolyData() const; vtkPolyData *GetPolyData() const override;
void AddPocaPoint(HPoint3f poca); void AddPocaPoint(HPoint3f poca);

View File

@@ -54,11 +54,11 @@ public:
void ReadFromStlFile(const char *filename); void ReadFromStlFile(const char *filename);
virtual class vtkPolyData *GetPolyData() const; vtkPolyData *GetPolyData() const override;
virtual void contentUpdate(); virtual void contentUpdate();
virtual void Update(); void Update() override;
uLib::Object *GetContent() const override { uLib::Object *GetContent() const override {
return (uLib::Object *)m_model.get(); return (uLib::Object *)m_model.get();
} }

View File

@@ -54,11 +54,11 @@ public:
void ReadFromStlFile(const char *filename); void ReadFromStlFile(const char *filename);
virtual class vtkPolyData *GetPolyData() const; vtkPolyData *GetPolyData() const override;
virtual void contentUpdate(); virtual void contentUpdate();
virtual void Update(); void Update() override;
uLib::Object *GetContent() const override { uLib::Object *GetContent() const override {
return (uLib::Object *)m_model.get(); return (uLib::Object *)m_model.get();
} }

View File

@@ -291,7 +291,7 @@ public:
Prop3D::Prop3D() : Object(), pd(new Prop3DData(this)) { Prop3D::Prop3D() : Object(), pd(new Prop3DData(this)) {
ULIB_ACTIVATE_DISPLAY_PROPERTIES; ULIB_ACTIVATE_DISPLAY_PROPERTIES;
for (auto* p : this->GetDisplayProperties()) { for (auto* p : this->GetDisplayProperties()) {
uLib::Object::connect(p, &uLib::PropertyBase::Updated, this, &Prop3D::Update); uLib::Object::connect(p, &uLib::Object::Updated, this, &Prop3D::Update);
} }
} }

View File

@@ -222,7 +222,7 @@ public:
m_Prop3D->RegisterDisplayProperty(p); m_Prop3D->RegisterDisplayProperty(p);
Vtk::Prop3D *prop3d = m_Prop3D; Vtk::Prop3D *prop3d = m_Prop3D;
uLib::Object::connect(p, &uLib::PropertyBase::Updated, uLib::Object::connect(p, &uLib::Object::Updated,
[prop3d]() { prop3d->Update(); }); [prop3d]() { prop3d->Update(); });
} }
} }
@@ -236,7 +236,7 @@ public:
t.labels(), t.units() ? t.units() : "", GetCurrentGroup()); t.labels(), t.units() ? t.units() : "", GetCurrentGroup());
m_Prop3D->RegisterDisplayProperty(p); m_Prop3D->RegisterDisplayProperty(p);
Vtk::Prop3D *prop3d = m_Prop3D; Vtk::Prop3D *prop3d = m_Prop3D;
uLib::Object::connect(p, &uLib::PropertyBase::Updated, uLib::Object::connect(p, &uLib::Object::Updated,
[prop3d]() { prop3d->Update(); }); [prop3d]() { prop3d->Update(); });
} }
} }
@@ -295,7 +295,7 @@ public:
if (m_Prop3D) { if (m_Prop3D) {
m_Prop3D->RegisterDisplayProperty(&p); m_Prop3D->RegisterDisplayProperty(&p);
Vtk::Prop3D *prop3d = m_Prop3D; Vtk::Prop3D *prop3d = m_Prop3D;
uLib::Object::connect(&p, &uLib::PropertyBase::Updated, uLib::Object::connect(&p, &uLib::Object::Updated,
[prop3d]() { prop3d->Update(); }); [prop3d]() { prop3d->Update(); });
} }
} }