3 Commits

20 changed files with 380 additions and 391 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

@@ -60,6 +60,10 @@ public:
std::string slostr; std::string slostr;
}; };
~ObjectPrivate() {
for (auto& s : sigv) delete s.signal;
}
std::string m_InstanceName; std::string m_InstanceName;
std::vector<Signal> sigv; std::vector<Signal> sigv;
std::vector<Slot> slov; std::vector<Slot> slov;
@@ -71,7 +75,13 @@ public:
// Implementations of Property methods // Implementations of Property methods
void Object::RegisterDisplayProperty(PropertyBase* prop) { void Object::RegisterDisplayProperty(PropertyBase* prop) {
if (prop) d->m_DisplayProperties.push_back(prop); if (prop) {
for (auto* existing : d->m_DisplayProperties) {
if (existing == prop) return;
if (existing->GetName() == prop->GetName()) return;
}
d->m_DisplayProperties.push_back(prop);
}
} }
const std::vector<PropertyBase*>& Object::GetDisplayProperties() const { const std::vector<PropertyBase*>& Object::GetDisplayProperties() const {
@@ -80,6 +90,10 @@ const std::vector<PropertyBase*>& Object::GetDisplayProperties() const {
void Object::RegisterProperty(PropertyBase* prop) { void Object::RegisterProperty(PropertyBase* prop) {
if (prop) { if (prop) {
for (auto* existing : d->m_Properties) {
if (existing == prop) return;
if (existing->GetName() == prop->GetName()) return;
}
d->m_Properties.push_back(prop); d->m_Properties.push_back(prop);
} }
} }
@@ -105,16 +119,19 @@ PropertyBase* Object::GetProperty(const std::string& name) const {
for (auto* p : d->m_DynamicProperties) { for (auto* p : d->m_DynamicProperties) {
if (p->GetName() == name || p->GetQualifiedName() == name) return p; if (p->GetName() == name || p->GetQualifiedName() == name) return p;
} }
for (auto* p : d->m_DisplayProperties) {
if (p->GetName() == name || p->GetQualifiedName() == name) return p;
}
return nullptr; return nullptr;
} }
void Object::NotifyPropertiesUpdated() { void Object::NotifyPropertiesUpdated() {
// Only notify properties in the primary list to avoid duplicates,
// as all registered properties should be there.
for (auto* p : d->m_Properties) p->Updated(); for (auto* p : d->m_Properties) p->Updated();
for (auto* p : d->m_DynamicProperties) p->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); }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
@@ -147,6 +164,9 @@ Object::~Object() {
for (auto* p : d->m_DynamicProperties) { for (auto* p : d->m_DynamicProperties) {
delete p; delete p;
} }
for (auto* p : d->m_DisplayProperties) {
delete p;
}
delete d; delete d;
} }

View File

@@ -84,7 +84,8 @@ public:
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. */
@@ -99,7 +100,8 @@ public:
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();
//////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////
@@ -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) {}
@@ -139,7 +148,6 @@ public:
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;
@@ -106,6 +103,7 @@ public:
// Accessors // Accessors
const T& Get() const { return *m_value; } const T& Get() const { return *m_value; }
void Set(const T& value) { void Set(const T& value) {
if (!m_value) return;
T val = value; T val = value;
if constexpr (std::is_arithmetic<T>::value) { if constexpr (std::is_arithmetic<T>::value) {
if (m_HasRange) { if (val < m_Min) val = m_Min; if (val > m_Max) val = m_Max; } if (m_HasRange) { if (val < m_Min) val = m_Min; if (val > m_Max) val = m_Max; }
@@ -169,7 +167,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 +260,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 +274,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 +297,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 +305,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

@@ -24,3 +24,5 @@ int main() {
std::cout << "Tests passed (compilation and manual instantiation)!" << std::endl; std::cout << "Tests passed (compilation and manual instantiation)!" << std::endl;
return 0; return 0;
} }

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 ///////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
@@ -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;

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,63 +43,43 @@
* *
*/ */
#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; }
@@ -113,16 +91,18 @@ public:
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,11 +123,9 @@ 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));
@@ -160,27 +138,25 @@ public:
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,8 +165,7 @@ 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 :
@@ -201,13 +176,9 @@ 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);
@@ -218,11 +189,14 @@ public:
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();
@@ -263,7 +235,6 @@ public:
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,19 +245,9 @@ 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;
@@ -297,8 +258,6 @@ inline std::istream& operator>>(std::istream& is, TRS& trs) {
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

@@ -9,19 +9,17 @@
// 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();
@@ -32,7 +30,6 @@ class muCastorMCTrack : public TObject
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]; }
@@ -52,7 +49,6 @@ 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
@@ -81,8 +77,8 @@ public:
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,
const muCastorMCTrack &bsmu);
#endif // muCastor_MCTRACK_H #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

@@ -25,7 +25,6 @@
#include "Vtk/uLibVtkViewer.h" #include "Vtk/uLibVtkViewer.h"
#include "Vtk/Math/vtkContainerBox.h"
#include "Math/Units.h" #include "Math/Units.h"
#include "Vtk/Math/vtkContainerBox.h" #include "Vtk/Math/vtkContainerBox.h"
@@ -36,19 +35,23 @@ using namespace uLib;
int main() { int main() {
BEGIN_TESTING(vtk ContainerBox Test); BEGIN_TESTING(vtk ContainerBox Test);
ContainerBox box; {
box.Scale(Vector3f(1_m,2_m,1_m)); ContainerBox* box = new ContainerBox();
box.SetPosition(Vector3f(0,0,0)); box->Scale(Vector3f(1_m, 2_m, 1_m));
box->SetPosition(Vector3f(0, 0, 0));
Vtk::ContainerBox v_box(&box); Vtk::ContainerBox v_box(box);
v_box.Update(); v_box.Update();
// v_box.SetRepresentation(Vtk::Prop3D::Surface); v_box.SetRepresentation(Vtk::Prop3D::Surface);
// v_box.SetOpacity(0.5); v_box.SetOpacity(0.5);
// v_box.SetSelectable(true); v_box.SetSelectable(true);
}
box.findOrAddSignal(&Object::Updated)->connect([&box](){ Vtk::ContainerBox v_box;
std::cout << "box updated: " << box.GetWorldPoint(HPoint3f(1,1,1)) << std::endl; v_box.findOrAddSignal(&Object::Updated)->connect([&v_box]() {
std::cout << "box updated: "
<< v_box.get()->GetWorldPoint(HPoint3f(1, 1, 1)) << std::endl;
}); });
if (std::getenv("CTEST_PROJECT_NAME") == nullptr) { if (std::getenv("CTEST_PROJECT_NAME") == nullptr) {

View File

@@ -15,11 +15,11 @@ using namespace uLib;
int main() { int main() {
std::cout << "Creating ContainerBox..." << std::endl; std::cout << "Creating ContainerBox..." << std::endl;
ContainerBox box(Vector3f(1.0, 1.0, 1.0)); // 1x1x1 unit box ContainerBox* box = new ContainerBox(Vector3f(1.0, 1.0, 1.0)); // 1x1x1 unit box
box.SetInstanceName("MyTestBox"); box->SetInstanceName("MyTestBox");
std::cout << "Creating VTK representation..." << std::endl; std::cout << "Creating VTK representation..." << std::endl;
Vtk::ContainerBox v_box(&box); Vtk::ContainerBox v_box(box);
v_box.SetRepresentation(Vtk::Prop3D::Wireframe); v_box.SetRepresentation(Vtk::Prop3D::Wireframe);
v_box.SetColor(1.0, 0.0, 0.0); // Red v_box.SetColor(1.0, 0.0, 0.0); // Red

View File

@@ -43,7 +43,6 @@
#include "Vtk/Math/vtkDense.h" #include "Vtk/Math/vtkDense.h"
namespace uLib { namespace uLib {
namespace Vtk { namespace Vtk {
@@ -53,38 +52,32 @@ struct ContainerBoxData {
vtkSmartPointer<vtkAssembly> m_VtkAsm; vtkSmartPointer<vtkAssembly> m_VtkAsm;
uLib::Connection m_UpdateSignal; uLib::Connection m_UpdateSignal;
ContainerBoxData()
ContainerBoxData() : m_Cube(vtkSmartPointer<vtkActor>::New()), : m_Cube(vtkSmartPointer<vtkActor>::New()),
m_Axes(vtkSmartPointer<vtkActor>::New()), m_Axes(vtkSmartPointer<vtkActor>::New()),
m_VtkAsm(vtkSmartPointer<vtkAssembly>::New()) {} m_VtkAsm(vtkSmartPointer<vtkAssembly>::New()) {}
~ContainerBoxData() { ~ContainerBoxData() {}
}
}; };
ContainerBox::ContainerBox(ContainerBox::Content *content) ContainerBox::ContainerBox(ContainerBox::Content *content)
: d(new ContainerBoxData()), ObjectWrapper(content) { : d(new ContainerBoxData()),
ObjectWrapper(content ? content : new Content()) {
this->InstallPipe(); this->InstallPipe();
d->m_UpdateSignal = d->m_UpdateSignal = Object::connect(
Object::connect(this->m_model.get(), &uLib::Object::Updated, this, &ContainerBox::Update); this->m_model.get(), &uLib::Object::Updated, this, &ContainerBox::Update);
} }
ContainerBox::~ContainerBox() { ContainerBox::~ContainerBox() { delete d; }
delete d;
}
vtkPolyData *ContainerBox::GetPolyData() const { vtkPolyData *ContainerBox::GetPolyData() const {
// TODO // TODO
return NULL; return NULL;
} }
void ContainerBox::Update() { void ContainerBox::Update() {
RecursiveMutex::ScopedLock lock(this->m_UpdateMutex); RecursiveMutex::ScopedLock lock(this->m_UpdateMutex);
if (!this->m_model) return; if (!this->m_model)
return;
vtkProp3D *prop = vtkProp3D::SafeDownCast(this->GetProp()); vtkProp3D *prop = vtkProp3D::SafeDownCast(this->GetProp());
if (prop) { if (prop) {
@@ -100,32 +93,28 @@ void ContainerBox::Update() {
this->Prop3D::Update(); this->Prop3D::Update();
} }
void ContainerBox::SyncFromVtk() { void ContainerBox::SyncFromVtk() {
RecursiveMutex::ScopedLock lock(this->m_UpdateMutex); RecursiveMutex::ScopedLock lock(this->m_UpdateMutex);
if (!this->m_model) return; if (!this->m_model)
return;
vtkProp3D *root = this->GetProxyProp(); vtkProp3D *root = this->GetProxyProp();
if (!root) return; if (!root)
return;
// VTK -> Model: Extract new world TRS from proxy, which matches the model's TRS center // VTK -> Model: Extract new world TRS from proxy, which matches the model's
// TRS center
vtkMatrix4x4 *rootMat = root->GetUserMatrix(); vtkMatrix4x4 *rootMat = root->GetUserMatrix();
Matrix4f vtkWorld = VtkToMatrix4f(rootMat); Matrix4f vtkWorld = VtkToMatrix4f(rootMat);
// Synchronize TRS property members from the updated local matrix // Synchronize TRS property members from the updated local matrix
this->m_model->FromMatrix(vtkWorld); this->m_model->FromMatrix(vtkWorld);
// Since we modified the model, notify observers, but block the loop back to VTK // Since we modified the model, notify observers, but block the loop back to
// ConnectionBlock blocker(d->m_UpdateSignal); // VTK ConnectionBlock blocker(d->m_UpdateSignal);
this->m_model->Updated(); this->m_model->Updated();
} }
void ContainerBox::InstallPipe() { void ContainerBox::InstallPipe() {
if (!this->m_model) if (!this->m_model)
return; return;

View File

@@ -42,11 +42,11 @@ class ContainerBox : public Prop3D,
public Polydata, public Polydata,
public uLib::ObjectWrapper<uLib::ContainerBox> { public uLib::ObjectWrapper<uLib::ContainerBox> {
uLibTypeMacro(ContainerBox, Prop3D, Polydata) uLibTypeMacro(ContainerBox, Prop3D,
typedef uLib::ContainerBox Content; Polydata) typedef uLib::ContainerBox Content;
public: public:
ContainerBox(Content *content); ContainerBox(Content *content = nullptr);
~ContainerBox(); ~ContainerBox();
virtual class vtkPolyData *GetPolyData() const override; virtual class vtkPolyData *GetPolyData() const override;

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

@@ -11,6 +11,7 @@
#include "Vtk/uLibVtkInterface.h" #include "Vtk/uLibVtkInterface.h"
#include "Core/Property.h" #include "Core/Property.h"
#include "Math/Dense.h"
#include <iostream> #include <iostream>
#include <cassert> #include <cassert>
#include "testing-prototype.h" #include "testing-prototype.h"
@@ -33,7 +34,7 @@ int main() {
// Verify specific properties exist // Verify specific properties exist
Property<double>* opacityProp = nullptr; Property<double>* opacityProp = nullptr;
Property<double>* colorRProp = nullptr; Property<Vector3d>* colorProp = nullptr;
for (auto* prop : props) { for (auto* prop : props) {
std::cout << " - [" << prop->GetTypeName() << "] " << prop->GetName() std::cout << " - [" << prop->GetTypeName() << "] " << prop->GetName()
@@ -42,13 +43,13 @@ int main() {
if (prop->GetName() == "Opacity") { if (prop->GetName() == "Opacity") {
opacityProp = dynamic_cast<Property<double>*>(prop); opacityProp = dynamic_cast<Property<double>*>(prop);
} }
if (prop->GetName() == "ColorR") { if (prop->GetName() == "Color") {
colorRProp = dynamic_cast<Property<double>*>(prop); colorProp = dynamic_cast<Property<Vector3d>*>(prop);
} }
} }
assert(opacityProp != nullptr && "Opacity property not registered!"); assert(opacityProp != nullptr && "Opacity property not registered!");
assert(colorRProp != nullptr && "ColorR property not registered!"); assert(colorProp != nullptr && "Color property not registered!");
// Test modification via uLib Property interface // Test modification via uLib Property interface
std::cout << "Modifying Opacity via property proxy (0.25)..." << std::endl; std::cout << "Modifying Opacity via property proxy (0.25)..." << std::endl;
@@ -58,9 +59,9 @@ int main() {
assert(opacityProp->Get() == 0.25); assert(opacityProp->Get() == 0.25);
assert(opacityProp->GetValueAsString().find("0.25") != std::string::npos); assert(opacityProp->GetValueAsString().find("0.25") != std::string::npos);
std::cout << "Modifying ColorR via property proxy (0.9)..." << std::endl; std::cout << "Modifying Color via property proxy (0.9, 0.1, 0.1)..." << std::endl;
*colorRProp = 0.9; *colorProp = Vector3d(0.9, 0.1, 0.1);
assert(colorRProp->Get() == 0.9); assert(colorProp->Get().x() == 0.9);
std::cout << "All Prop3D Property Registration Tests PASSED!" << std::endl; std::cout << "All Prop3D Property Registration Tests PASSED!" << std::endl;

View File

@@ -290,9 +290,6 @@ 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()) {
uLib::Object::connect(p, &uLib::PropertyBase::Updated, this, &Prop3D::Update);
}
} }
Prop3D::~Prop3D() Prop3D::~Prop3D()

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(); });
} }
} }