diff --git a/CMakeLists.txt b/CMakeLists.txt index 5eb6067..52717e0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -19,6 +19,18 @@ endif() 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 if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") 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}) find_package(Eigen3 CONFIG REQUIRED) -get_target_property(EIGEN3_INCLUDE_DIRS Eigen3::Eigen INTERFACE_INCLUDE_DIRECTORIES) -include_directories(${EIGEN3_INCLUDE_DIRS}) +# if(NOT EIGEN3_INCLUDE_DIRS) +# get_target_property(EIGEN3_INCLUDE_DIRS Eigen3::Eigen INTERFACE_INCLUDE_DIRECTORIES) +# else() +# include_directories(${EIGEN3_INCLUDE_DIRS}) +# endif() find_package(OpenMP) diff --git a/conanfile.txt b/conanfile.txt index 8c12c50..36dcc70 100644 --- a/conanfile.txt +++ b/conanfile.txt @@ -1,5 +1,5 @@ [requires] -eigen/3.4.0 +# eigen/5.0.1 boost/1.86.0 # pybind11/3.0.2 hdf5/1.14.3 diff --git a/src/Core/Object.cpp b/src/Core/Object.cpp index 8ae3cbd..9f861b0 100644 --- a/src/Core/Object.cpp +++ b/src/Core/Object.cpp @@ -111,10 +111,10 @@ PropertyBase* Object::GetProperty(const std::string& name) const { void Object::NotifyPropertiesUpdated() { for (auto* p : d->m_Properties) p->Updated(); for (auto* p : d->m_DynamicProperties) p->Updated(); + this->Updated(); } void Object::Updated() { ULIB_SIGNAL_EMIT(Object::Updated); } -void Object::PropertyUpdated() { ULIB_SIGNAL_EMIT(Object::PropertyUpdated); } //////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// diff --git a/src/Core/Object.h b/src/Core/Object.h index 5ac02e9..da87bbb 100644 --- a/src/Core/Object.h +++ b/src/Core/Object.h @@ -78,28 +78,30 @@ public: Object(const Object ©); virtual ~Object(); - virtual const char * GetClassName() const { return type_name(); } - virtual const char * type_name() const { return "Object"; } + virtual const char *GetClassName() const { return type_name(); } + virtual const char *type_name() const { return "Object"; } - const std::string& GetInstanceName() const; - void SetInstanceName(const std::string& name); - - /** @brief Temporarily blocks all signal emissions from this object. Returns previous state. */ + const std::string &GetInstanceName() const; + void SetInstanceName(const std::string &name); + + /** @brief Temporarily blocks all signal emissions from this object. Returns + * previous state. */ bool blockSignals(bool block); - + /** @brief Checks if signals are currently blocked. */ bool signalsBlocked() const; //////////////////////////////////////////////////////////////////////////// // PROPERTIES // - virtual void RegisterProperty(PropertyBase* property); - virtual void RegisterDynamicProperty(PropertyBase* property); - virtual void RegisterDisplayProperty(PropertyBase* property); - virtual const std::vector& GetProperties() const; - virtual const std::vector& GetDisplayProperties() const; - PropertyBase* GetProperty(const std::string& name) const; + virtual void RegisterProperty(PropertyBase *property); + virtual void RegisterDynamicProperty(PropertyBase *property); + virtual void RegisterDisplayProperty(PropertyBase *property); + virtual const std::vector &GetProperties() const; + virtual const std::vector &GetDisplayProperties() 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(); //////////////////////////////////////////////////////////////////////////// @@ -109,7 +111,7 @@ public: virtual void DeepCopy(const Object ©); /** @brief Returns a nested context for children objects, if any. */ - virtual ObjectsContext* GetChildren() { return nullptr; } + virtual ObjectsContext *GetChildren() { return nullptr; } //////////////////////////////////////////////////////////////////////////// // SERIALIZATION // @@ -117,13 +119,20 @@ public: template void serialize(ArchiveT &ar, const unsigned int version); - virtual void serialize(Archive::xml_oarchive & ar, const unsigned int version) {} - virtual void serialize(Archive::xml_iarchive & ar, const unsigned int version) {} - virtual void serialize(Archive::text_oarchive & 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) {} + virtual void serialize(Archive::xml_oarchive &ar, + const unsigned int version) {} + virtual void serialize(Archive::xml_iarchive &ar, + const unsigned int version) {} + virtual void serialize(Archive::text_oarchive &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 void save_override(ArchiveT &ar, const unsigned int version) {} @@ -137,9 +146,8 @@ public: //////////////////////////////////////////////////////////////////////////// // SIGNALS // - signals: +signals: virtual void Updated(); - virtual void PropertyUpdated(); // Qt4 style connector // static bool connect(const Object *ob1, const char *signal_name, @@ -160,14 +168,14 @@ public: connect(typename FunctionPointer::Object *sender, Func1 sigf, typename FunctionPointer::Object *receiver, Func2 slof) { SignalBase *sigb = sender->findOrAddSignal(sigf); - return ConnectSignal::SignalSignature>(sigb, slof, - receiver); + return ConnectSignal::SignalSignature>( + sigb, slof, receiver); } // Lambda/Function object connector // template static Connection connect(typename FunctionPointer::Object *sender, - Func1 sigf, SlotT slof) { + Func1 sigf, SlotT slof) { SignalBase *sigb = sender->findOrAddSignal(sigf); typedef typename FunctionPointer::SignalSignature SigSignature; typedef typename Signal::type SigT; @@ -183,9 +191,10 @@ public: } template - static inline Connection connect(SignalBase *sigb, FuncT slof, Object *receiver) { - return ConnectSignal::SignalSignature>(sigb, slof, - receiver); + static inline Connection connect(SignalBase *sigb, FuncT slof, + Object *receiver) { + return ConnectSignal::SignalSignature>( + sigb, slof, receiver); } template diff --git a/src/Core/Property.h b/src/Core/Property.h index 0501646..acf9348 100644 --- a/src/Core/Property.h +++ b/src/Core/Property.h @@ -53,9 +53,6 @@ public: return GetGroup() + "." + GetName(); } - // Signal support - signals: - virtual void Updated() override { ULIB_SIGNAL_EMIT(PropertyBase::Updated); } // Serialization support for different uLib archives 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 Updated() override { PropertyBase::Updated(); this->PropertyChanged(); } protected: std::string m_name; @@ -263,7 +259,7 @@ public: if (m_DisplayOnly) { m_Object->RegisterDisplayProperty(newP); Object* obj = m_Object; - Object::connect(newP, &PropertyBase::Updated, [obj]() { obj->Updated(); }); + Object::connect(newP, &Object::Updated, [obj]() { obj->Updated(); }); } else { m_Object->RegisterDynamicProperty(newP); } @@ -277,7 +273,7 @@ public: if (m_DisplayOnly) { m_Object->RegisterDisplayProperty(p); Object* obj = m_Object; - Object::connect(p, &PropertyBase::Updated, [obj]() { obj->Updated(); }); + Object::connect(p, &Object::Updated, [obj]() { obj->Updated(); }); } else { m_Object->RegisterDynamicProperty(p); } @@ -300,7 +296,7 @@ public: if (m_Object) { EnumProperty* p = new EnumProperty(m_Object, t.name(), (int*)&const_cast&>(t).value(), t.labels(), t.units() ? t.units() : "", GetCurrentGroup()); 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); } } } @@ -308,7 +304,7 @@ public: if (m_Object) { EnumProperty* p = new EnumProperty(m_Object, t.name(), (int*)&const_cast&>(t).value(), t.labels(), t.units() ? t.units() : "", GetCurrentGroup()); 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); } } } diff --git a/src/Math/Dense.h b/src/Math/Dense.h index 6aec366..a5259a7 100644 --- a/src/Math/Dense.h +++ b/src/Math/Dense.h @@ -50,9 +50,9 @@ // #include #include -#include -#include "Core/Types.h" #include "Core/Property.h" +#include "Core/Types.h" +#include //// BOOST SERIALIZATION /////////////////////////////////////////////////////// @@ -150,7 +150,6 @@ typedef Eigen::MatrixXi MatrixXi; typedef Eigen::MatrixXf MatrixXf; typedef Eigen::MatrixXd MatrixXd; - //////////////////////////////////////////////////////////////////////////////// // Vector String interaction /////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// @@ -192,7 +191,7 @@ std::string VectorxT_ToString(const Eigen::Matrix &vec) { // } template -void operator >> (std::string &str, Eigen::Matrix &vec) { +void operator>>(std::string &str, Eigen::Matrix &vec) { VectorxT_StringTo(vec, str); } @@ -205,9 +204,7 @@ public: typedef Eigen::Matrix BaseClass; _HPoint3f() : BaseClass(0, 0, 0, p) {} - _HPoint3f(int rows, int cols) : BaseClass() { - this->operator()(3) = p; - } + _HPoint3f(int rows, int cols) : BaseClass() { this->operator()(3) = p; } _HPoint3f(float x, float y, float z) : BaseClass(x, y, z, p) {} _HPoint3f(Vector3f &in) : BaseClass(in.homogeneous()) { this->operator()(3) = p; @@ -250,24 +247,24 @@ struct _HError3f { HVector3f position_error; HVector3f direction_error; }; - typedef struct _HError3f HError3f; - - inline std::ostream &operator<<(std::ostream &stream, const HError3f &err) { - stream << "HError3f(" << "ept[" << err.position_error.transpose() - << "] , edr[" << err.direction_error.transpose() << "]) "; - return stream; - } - -typedef Property ScalariProperty; -typedef Property ScalaruiProperty; -typedef Property ScalarlProperty; -typedef Property ScalarulProperty; -typedef Property ScalarfProperty; -typedef Property ScalardProperty; +typedef struct _HError3f HError3f; -typedef Property Vector1iProperty; -typedef Property Vector1fProperty; -typedef Property Vector1dProperty; +inline std::ostream &operator<<(std::ostream &stream, const HError3f &err) { + stream << "HError3f(" << "ept[" << err.position_error.transpose() + << "] , edr[" << err.direction_error.transpose() << "]) "; + return stream; +} + +typedef Property ScalariProperty; +typedef Property ScalaruiProperty; +typedef Property ScalarlProperty; +typedef Property ScalarulProperty; +typedef Property ScalarfProperty; +typedef Property ScalardProperty; + +typedef Property Vector1iProperty; +typedef Property Vector1fProperty; +typedef Property Vector1dProperty; typedef Property Vector2iProperty; typedef Property Vector3iProperty; @@ -294,9 +291,9 @@ typedef Property Matrix3dProperty; typedef Property Matrix4dProperty; typedef Property HVector3fProperty; -typedef Property HPoint3fProperty; +typedef Property HPoint3fProperty; - } // namespace uLib +} // namespace uLib //////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// diff --git a/src/Math/Transform.h b/src/Math/Transform.h index bf5d4b4..82d07d3 100644 --- a/src/Math/Transform.h +++ b/src/Math/Transform.h @@ -23,8 +23,6 @@ //////////////////////////////////////////////////////////////////////////////*/ - - /* * Copyright (C) 2012 Andrea Rigoni Garola * @@ -45,142 +43,120 @@ * */ - #ifndef U_TRANSFORM_H #define U_TRANSFORM_H -#include -#include "Math/Units.h" #include "Math/Dense.h" - +#include "Math/Units.h" +#include namespace uLib { - - -using Eigen::Isometry3f; using Eigen::Isometry3d; +using Eigen::Isometry3f; -using Eigen::Affine3f; using Eigen::Affine3d; +using Eigen::Affine3f; -using Eigen::Projective3f; using Eigen::Projective3d; - - - - - - +using Eigen::Projective3f; //////////////////////////////////////////////////////////////////////////////// ///////// AFFINE TRANSFORM WRAPPER ////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// - - class AffineTransform : virtual public Object { public: - uLibTypeMacro(AffineTransform, Object) -protected: +uLibTypeMacro(AffineTransform, Object) protected : - Affine3f m_T; - AffineTransform *m_Parent; + Affine3f m_T; + AffineTransform *m_Parent; public: - AffineTransform() : - m_T(Matrix4f::Identity()), - m_Parent(NULL) - {} + AffineTransform() : m_T(Matrix4f::Identity()), m_Parent(NULL) {} - AffineTransform(AffineTransform *parent) : - m_T(Matrix4f::Identity()), - m_Parent(parent) - {} + AffineTransform(AffineTransform *parent) + : m_T(Matrix4f::Identity()), m_Parent(parent) {} - AffineTransform(const AffineTransform ©) : - m_T(copy.m_T), - m_Parent(copy.m_Parent) - {} + AffineTransform(const AffineTransform ©) + : m_T(copy.m_T), 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; } - Matrix4f& GetMatrix () { return m_T.matrix(); } - const Matrix4f& GetMatrix () const { return m_T.matrix(); } + void SetMatrix(const Matrix4f &mat) { m_T.matrix() = mat; } + Matrix4f &GetMatrix() { return m_T.matrix(); } + const Matrix4f &GetMatrix() const { return m_T.matrix(); } - Matrix4f GetWorldMatrix() const - { - if(!m_Parent) return m_T.matrix(); - else return m_Parent->GetWorldMatrix() * m_T.matrix(); // T = B * A // - } + Matrix4f GetWorldMatrix() const { + if (!m_Parent) + return m_T.matrix(); + else + return m_Parent->GetWorldMatrix() * m_T.matrix(); // T = B * A // + } - void SetWorldMatrix(const Matrix4f &mat) - { - if(!m_Parent) m_T.matrix() = mat; - else m_T.matrix() = m_Parent->GetWorldMatrix().inverse() * mat; - } + void SetWorldMatrix(const Matrix4f &mat) { + if (!m_Parent) + m_T.matrix() = 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; } - Vector3f GetPosition() const { return this->m_T.translation(); } + Vector3f GetPosition() const { return this->m_T.translation(); } - void SetRotation(const Matrix3f &m) { this->m_T.linear() = m; } + void SetRotation(const Matrix3f &m) { this->m_T.linear() = m; } - Matrix3f GetRotation() const { return this->m_T.rotation(); } + Matrix3f GetRotation() const { return this->m_T.rotation(); } - void Translate(const Vector3f &v) { this->m_T.translate(v); } + void Translate(const Vector3f &v) { this->m_T.translate(v); } - void Scale(const Vector3f &v) { this->m_T.scale(v); } + void Scale(const Vector3f &v) { this->m_T.scale(v); } - Vector3f GetScale() const { - return Vector3f(this->m_T.linear().col(0).norm(), - this->m_T.linear().col(1).norm(), - this->m_T.linear().col(2).norm()); - } + Vector3f GetScale() const { + return Vector3f(this->m_T.linear().col(0).norm(), + this->m_T.linear().col(1).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) { + axis.normalize(); // prehaps not necessary ( see eigens ) + Eigen::AngleAxisf ax(angle, axis); + this->m_T.rotate(Eigen::Quaternion(ax)); + } - void Rotate(const float angle, Vector3f axis) - { - axis.normalize(); // prehaps not necessary ( see eigens ) - Eigen::AngleAxisf ax(angle,axis); - this->m_T.rotate(Eigen::Quaternion(ax)); - } + void Rotate(const Vector3f euler_axis) { + float angle = euler_axis.norm(); + Rotate(angle, euler_axis); + } - void Rotate(const Vector3f euler_axis) { - float angle = euler_axis.norm(); - 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) { + this->m_T.rotate(Eigen::Quaternion(q)); + } - void QuaternionRotate(const Vector4f &q) - { this->m_T.rotate(Eigen::Quaternion(q)); } + void EulerYZYRotate(const Vector3f &e) { + Matrix3f mat; + mat = Eigen::AngleAxisf(e.x(), Vector3f::UnitY()) * + Eigen::AngleAxisf(e.y(), Vector3f::UnitZ()) * + Eigen::AngleAxisf(e.z(), Vector3f::UnitY()); + m_T.rotate(mat); + } - void EulerYZYRotate(const Vector3f &e) { - Matrix3f mat; - mat = Eigen::AngleAxisf(e.x(), Vector3f::UnitY()) - * Eigen::AngleAxisf(e.y(), Vector3f::UnitZ()) - * Eigen::AngleAxisf(e.z(), Vector3f::UnitY()); - m_T.rotate(mat); - } - - void FlipAxes(int first, int second) - { - Matrix3f mat = Matrix3f::Identity(); - mat.col(first).swap(mat.col(second)); - m_T.rotate(mat); - } + void FlipAxes(int first, int second) { + Matrix3f mat = Matrix3f::Identity(); + mat.col(first).swap(mat.col(second)); + m_T.rotate(mat); + } }; - - //////////////////////////////////////////////////////////////////////////////// ///////// TRS PARAMETERS ///////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// @@ -189,116 +165,99 @@ typedef Eigen::Affine3f AffineMatrix; class TRS : public AffineTransform { - uLibTypeMacro(TRS, AffineTransform) - ULIB_SERIALIZE_ACCESS +uLibTypeMacro(TRS, AffineTransform) ULIB_SERIALIZE_ACCESS // ULIB_DECLARE_PROPERTIES(TRS) -public: + public : Vector3f position = Vector3f::Zero(); - Vector3f rotation = Vector3f::Zero(); - Vector3f scaling = Vector3f::Ones(); + Vector3f rotation = Vector3f::Zero(); + Vector3f scaling = Vector3f::Ones(); - TRS() = default; + TRS() = default; - TRS(const class AffineTransform& at) { - this->FromMatrix(at.GetMatrix()); - } + TRS(const class AffineTransform &at) { this->FromMatrix(at.GetMatrix()); } - TRS(const Matrix4f& mat) { - this->FromMatrix(mat); - } + TRS(const Matrix4f &mat) { this->FromMatrix(mat); } - void FromMatrix(const Matrix4f& mat) { - this->position = mat.block<3,1>(0,3); - - Matrix3f linear = mat.block<3,3>(0,0); - this->scaling(0) = linear.col(0).norm(); - this->scaling(1) = linear.col(1).norm(); - this->scaling(2) = linear.col(2).norm(); - - Matrix3f rot = linear; - if (this->scaling(0) > 1e-6) rot.col(0) /= this->scaling(0); - 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); - this->rotation = Vector3f(euler(2), euler(1), euler(0)); - - this->SetMatrix(mat); - this->NotifyPropertiesUpdated(); - } + void FromMatrix(const Matrix4f &mat) { + this->position = mat.block<3, 1>(0, 3); - void SetPosition(const Vector3f &v) { - position = v; - this->AffineTransform::SetPosition(v); - } - - void SetRotation(const Vector3f &v) { - rotation = v; - this->SyncMatrix(); - } - - void SetOrientation(const Vector3f &v) { SetRotation(v); } - - void SetScale(const Vector3f &v) { - scaling = v; - this->SyncMatrix(); - } + Matrix3f linear = mat.block<3, 3>(0, 0); + this->scaling(0) = linear.col(0).norm(); + this->scaling(1) = linear.col(1).norm(); + this->scaling(2) = linear.col(2).norm(); - void SyncMatrix() { - this->GetTransform() = GetAffineMatrix(); - } + Matrix3f rot = linear; + if (this->scaling(0) > 1e-6) + rot.col(0) /= this->scaling(0); + if (this->scaling(1) > 1e-6) + rot.col(1) /= this->scaling(1); + if (this->scaling(2) > 1e-6) + rot.col(2) /= this->scaling(2); - void Updated() override { - this->SyncMatrix(); - this->NotifyPropertiesUpdated(); - this->AffineTransform::Updated(); - } + Vector3f euler = rot.canonicalEulerAngles(2, 1, 0); + this->rotation = Vector3f(euler(2), euler(1), euler(0)); - template - void serialize(ArchiveT & ar, const unsigned int version) { - ar & HRPU(position, "mm"); - ar & HRPU(rotation, "rad"); - ar & HRP(scaling); - } - + this->SetMatrix(mat); + this->NotifyPropertiesUpdated(); + } - AffineMatrix GetAffineMatrix() const { - AffineMatrix m = AffineMatrix::Identity(); - m.translate(position); - m.rotate(Eigen::AngleAxisf(rotation.z(), Vector3f::UnitZ())); - m.rotate(Eigen::AngleAxisf(rotation.y(), Vector3f::UnitY())); - m.rotate(Eigen::AngleAxisf(rotation.x(), Vector3f::UnitX())); - m.scale(scaling); - return m; - } + void SetPosition(const Vector3f &v) { + position = v; + this->AffineTransform::SetPosition(v); + } - Matrix4f GetMatrix() const { - return this->GetAffineMatrix().matrix(); - } + void SetRotation(const Vector3f &v) { + rotation = v; + this->SyncMatrix(); + } + void SetOrientation(const Vector3f &v) { SetRotation(v); } - - + void SetScale(const Vector3f &v) { + scaling = v; + this->SyncMatrix(); + } + + void SyncMatrix() { this->GetTransform() = GetAffineMatrix(); } + + void Updated() override { + this->SyncMatrix(); + this->NotifyPropertiesUpdated(); + this->AffineTransform::Updated(); + } + + template + void serialize(ArchiveT &ar, const unsigned int version) { + ar &HRPU(position, "mm"); + ar &HRPU(rotation, "rad"); + ar &HRP(scaling); + } + + AffineMatrix GetAffineMatrix() const { + AffineMatrix m = AffineMatrix::Identity(); + m.translate(position); + m.rotate(Eigen::AngleAxisf(rotation.z(), Vector3f::UnitZ())); + m.rotate(Eigen::AngleAxisf(rotation.y(), Vector3f::UnitY())); + m.rotate(Eigen::AngleAxisf(rotation.x(), Vector3f::UnitX())); + m.scale(scaling); + return m; + } + + Matrix4f GetMatrix() const { return this->GetAffineMatrix().matrix(); } }; - - - - -inline std::ostream& operator<<(std::ostream& os, const TRS& trs) { - os << trs.position << " " << trs.rotation << " " << trs.scaling; - return os; +inline std::ostream &operator<<(std::ostream &os, const TRS &trs) { + os << trs.position << " " << trs.rotation << " " << trs.scaling; + return os; } -inline std::istream& operator>>(std::istream& is, TRS& trs) { - is >> trs.position >> trs.rotation >> trs.scaling; - return is; +inline std::istream &operator>>(std::istream &is, TRS &trs) { + is >> trs.position >> trs.rotation >> trs.scaling; + return is; } -} // uLib +} // namespace uLib - - -#endif//U_TRANSFORM_H +#endif // U_TRANSFORM_H diff --git a/src/Root/CMakeLists.txt b/src/Root/CMakeLists.txt index 9ad53e4..85985a4 100644 --- a/src/Root/CMakeLists.txt +++ b/src/Root/CMakeLists.txt @@ -33,7 +33,11 @@ set(DICTIONARY_HEADERS muCastorMCTrack.h SkinDetectorWriter.h) 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) root_generate_dictionary(${rDictName} ${DICTIONARY_HEADERS} diff --git a/src/Root/muCastorMCTrack.h b/src/Root/muCastorMCTrack.h index ff422d9..fbd578b 100644 --- a/src/Root/muCastorMCTrack.h +++ b/src/Root/muCastorMCTrack.h @@ -1,88 +1,84 @@ #ifndef muCastor_MCTRACK_H #define muCastor_MCTRACK_H -//######################################## -// muCastorMCTrack class -// Created at the University of Brescia, Italy -// Date: December 2011 -// Autors: Germano Bonomi germano.bonomi@ing.unibs.it -// Martin Subieta martin.subieta@ing.unibs.it -//######################################## +// ######################################## +// muCastorMCTrack class +// Created at the University of Brescia, Italy +// Date: December 2011 +// Autors: Germano Bonomi germano.bonomi@ing.unibs.it +// Martin Subieta martin.subieta@ing.unibs.it +// ######################################## -#include -#include "vector" +#include "Detectors/MuonScatter.h" #include "TObject.h" #include "TParticle.h" -#include "Detectors/MuonScatter.h" +#include "vector" +#include class TClonesArray; -class muCastorMCTrack : public TObject -{ - - public: +class muCastorMCTrack : public TObject { +public: /** Default constructor **/ muCastorMCTrack(); /** Constructor from TParticle **/ - muCastorMCTrack(TParticle* particle); + muCastorMCTrack(TParticle *particle); /** Destructor **/ virtual ~muCastorMCTrack(); - void Reset(); - + void Reset(); /** Accessors **/ - Int_t GetFirstDaughter() const { return fDaughter[0];} - Int_t GetMother() const { return fMother[0];} + Int_t GetFirstDaughter() const { return fDaughter[0]; } + Int_t GetMother() const { return fMother[0]; } /** Modifiers **/ - virtual void AddPoint(TLorentzVector pos, TLorentzVector mom); - virtual void SetFirstDaughter(Int_t trkid) { fDaughter[0] = trkid; } - virtual void SetLastDaughter(Int_t trkid) { fDaughter[1] = trkid; } + virtual void AddPoint(TLorentzVector pos, TLorentzVector mom); + virtual void SetFirstDaughter(Int_t trkid) { fDaughter[0] = trkid; } + virtual void SetLastDaughter(Int_t trkid) { fDaughter[1] = trkid; } - inline void Dump() { - std::cout << "muCastorMCTrack\n" - << "PDG code: " << fPdgCode << "\n" - << "Momentum: " << fPx << ", " << fPy << ", " << fPz << "\n" - << "Position: " << fVx << ", " << fVy << ", " << fVz << "\n" - << "Npoints: " << fNpoints << "\n"; - return; - } + inline void Dump() { + std::cout << "muCastorMCTrack\n" + << "PDG code: " << fPdgCode << "\n" + << "Momentum: " << fPx << ", " << fPy << ", " << fPz << "\n" + << "Position: " << fVx << ", " << fVy << ", " << fVz << "\n" + << "Npoints: " << fNpoints << "\n"; + return; + } 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 fMother[2]; // Indices of the mother particles + Int_t fDaughter[2]; // Indices of the daughter particles - Int_t fPdgCode; // PDG code of the particle - Int_t fMother[2]; // Indices of the mother particles - Int_t fDaughter[2]; // Indices of the daughter particles + Double_t fPx; // x component of momentum + Double_t fPy; // y component of momentum + Double_t fPz; // z component of momentum + Double_t fE; // Energy - Double_t fPx; // x component of momentum - Double_t fPy; // y component of momentum - Double_t fPz; // z component of momentum - Double_t fE; // Energy + Double_t fVx; // x of production vertex + Double_t fVy; // y of production vertex + Double_t fVz; // z of production vertex + Double_t fVt; // t of production vertex - Double_t fVx; // x of production vertex - Double_t fVy; // y of production vertex - Double_t fVz; // z of production vertex - Double_t fVt; // t of production vertex - - Int_t fPointsSize; // capacity of points array - Int_t fNpoints; // number of stored points - Double_t *fPntPosX; //[fNpoints] array of points (x) belonging to this track - Double_t *fPntPosY; //[fNpoints] array of points (y) belonging to this track - Double_t *fPntPosZ; //[fNpoints] array of points (z) belonging to this track - Double_t *fPntT; //[fNpoints] array of points (t) belonging to this track - Double_t *fPntMomX; //[fNpoints] array of points (px) belonging to this track - Double_t *fPntMomY; //[fNpoints] array of points (py) 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 - - ClassDef(muCastorMCTrack,1); + Int_t fPointsSize; // capacity of points array + Int_t fNpoints; // number of stored points + Double_t *fPntPosX; //[fNpoints] array of points (x) belonging to this track + Double_t *fPntPosY; //[fNpoints] array of points (y) belonging to this track + Double_t *fPntPosZ; //[fNpoints] array of points (z) belonging to this track + Double_t *fPntT; //[fNpoints] array of points (t) belonging to this track + Double_t *fPntMomX; //[fNpoints] array of points (px) belonging to this track + Double_t *fPntMomY; //[fNpoints] array of points (py) 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 + ClassDef(muCastorMCTrack, 1); }; -uLib::MuonScatter &operator << (uLib::MuonScatter &mu, const muCastorMCTrack &bsmu); -#endif //muCastor_MCTRACK_H +uLib::MuonScatter &operator<<(uLib::MuonScatter &mu, + const muCastorMCTrack &bsmu); +#endif // muCastor_MCTRACK_H diff --git a/src/Vtk/HEP/Detectors/vtkMuonEvent.h b/src/Vtk/HEP/Detectors/vtkMuonEvent.h index bd842f7..255b4db 100644 --- a/src/Vtk/HEP/Detectors/vtkMuonEvent.h +++ b/src/Vtk/HEP/Detectors/vtkMuonEvent.h @@ -61,9 +61,9 @@ public: Content &GetModel(); 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); diff --git a/src/Vtk/Math/vtkQuadMesh.h b/src/Vtk/Math/vtkQuadMesh.h index 71c1484..520410c 100644 --- a/src/Vtk/Math/vtkQuadMesh.h +++ b/src/Vtk/Math/vtkQuadMesh.h @@ -54,11 +54,11 @@ public: void ReadFromStlFile(const char *filename); - virtual class vtkPolyData *GetPolyData() const; + vtkPolyData *GetPolyData() const override; virtual void contentUpdate(); - virtual void Update(); + void Update() override; uLib::Object *GetContent() const override { return (uLib::Object *)m_model.get(); } diff --git a/src/Vtk/Math/vtkTriangleMesh.h b/src/Vtk/Math/vtkTriangleMesh.h index 5487864..b7e6d34 100644 --- a/src/Vtk/Math/vtkTriangleMesh.h +++ b/src/Vtk/Math/vtkTriangleMesh.h @@ -54,11 +54,11 @@ public: void ReadFromStlFile(const char *filename); - virtual class vtkPolyData *GetPolyData() const; + vtkPolyData *GetPolyData() const override; virtual void contentUpdate(); - virtual void Update(); + void Update() override; uLib::Object *GetContent() const override { return (uLib::Object *)m_model.get(); } diff --git a/src/Vtk/uLibVtkInterface.cxx b/src/Vtk/uLibVtkInterface.cxx index 80f1d84..6dbd2bf 100644 --- a/src/Vtk/uLibVtkInterface.cxx +++ b/src/Vtk/uLibVtkInterface.cxx @@ -291,7 +291,7 @@ public: Prop3D::Prop3D() : Object(), pd(new Prop3DData(this)) { ULIB_ACTIVATE_DISPLAY_PROPERTIES; 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); } } diff --git a/src/Vtk/uLibVtkInterface.h b/src/Vtk/uLibVtkInterface.h index b22eca5..9f41ae2 100644 --- a/src/Vtk/uLibVtkInterface.h +++ b/src/Vtk/uLibVtkInterface.h @@ -222,7 +222,7 @@ public: m_Prop3D->RegisterDisplayProperty(p); Vtk::Prop3D *prop3d = m_Prop3D; - uLib::Object::connect(p, &uLib::PropertyBase::Updated, + uLib::Object::connect(p, &uLib::Object::Updated, [prop3d]() { prop3d->Update(); }); } } @@ -236,7 +236,7 @@ public: t.labels(), t.units() ? t.units() : "", GetCurrentGroup()); m_Prop3D->RegisterDisplayProperty(p); Vtk::Prop3D *prop3d = m_Prop3D; - uLib::Object::connect(p, &uLib::PropertyBase::Updated, + uLib::Object::connect(p, &uLib::Object::Updated, [prop3d]() { prop3d->Update(); }); } } @@ -295,7 +295,7 @@ public: if (m_Prop3D) { m_Prop3D->RegisterDisplayProperty(&p); Vtk::Prop3D *prop3d = m_Prop3D; - uLib::Object::connect(&p, &uLib::PropertyBase::Updated, + uLib::Object::connect(&p, &uLib::Object::Updated, [prop3d]() { prop3d->Update(); }); } }