3 Commits

20 changed files with 380 additions and 391 deletions

View File

@@ -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)

View File

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

View File

@@ -59,6 +59,10 @@ public:
GenericMFPtr sloptr;
std::string slostr;
};
~ObjectPrivate() {
for (auto& s : sigv) delete s.signal;
}
std::string m_InstanceName;
std::vector<Signal> sigv;
@@ -71,7 +75,13 @@ public:
// Implementations of Property methods
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 {
@@ -80,6 +90,10 @@ const std::vector<PropertyBase*>& Object::GetDisplayProperties() const {
void Object::RegisterProperty(PropertyBase* 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);
}
}
@@ -105,16 +119,19 @@ PropertyBase* Object::GetProperty(const std::string& name) const {
for (auto* p : d->m_DynamicProperties) {
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;
}
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_DynamicProperties) p->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) {
delete p;
}
for (auto* p : d->m_DisplayProperties) {
delete p;
}
delete d;
}

View File

@@ -78,28 +78,30 @@ public:
Object(const Object &copy);
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<PropertyBase*>& GetProperties() const;
virtual const std::vector<PropertyBase*>& 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<PropertyBase *> &GetProperties() const;
virtual const std::vector<PropertyBase *> &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 &copy);
/** @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 <class ArchiveT>
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 <class ArchiveT>
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<Func1>::Object *sender, Func1 sigf,
typename FunctionPointer<Func2>::Object *receiver, Func2 slof) {
SignalBase *sigb = sender->findOrAddSignal(sigf);
return ConnectSignal<typename FunctionPointer<Func1>::SignalSignature>(sigb, slof,
receiver);
return ConnectSignal<typename FunctionPointer<Func1>::SignalSignature>(
sigb, slof, receiver);
}
// Lambda/Function object connector //
template <typename Func1, typename SlotT>
static Connection connect(typename FunctionPointer<Func1>::Object *sender,
Func1 sigf, SlotT slof) {
Func1 sigf, SlotT slof) {
SignalBase *sigb = sender->findOrAddSignal(sigf);
typedef typename FunctionPointer<Func1>::SignalSignature SigSignature;
typedef typename Signal<SigSignature>::type SigT;
@@ -183,9 +191,10 @@ public:
}
template <typename FuncT>
static inline Connection connect(SignalBase *sigb, FuncT slof, Object *receiver) {
return ConnectSignal<typename FunctionPointer<FuncT>::SignalSignature>(sigb, slof,
receiver);
static inline Connection connect(SignalBase *sigb, FuncT slof,
Object *receiver) {
return ConnectSignal<typename FunctionPointer<FuncT>::SignalSignature>(
sigb, slof, receiver);
}
template <typename FuncT>

View File

@@ -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;
@@ -106,6 +103,7 @@ public:
// Accessors
const T& Get() const { return *m_value; }
void Set(const T& value) {
if (!m_value) return;
T val = 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; }
@@ -169,7 +167,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 +260,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 +274,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 +297,7 @@ public:
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());
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 +305,7 @@ public:
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());
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); }
}
}

View File

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

View File

@@ -50,9 +50,9 @@
// #include <Eigen/src/Core/Matrix.h>
#include <stdlib.h>
#include <Eigen/Dense>
#include "Core/Types.h"
#include "Core/Property.h"
#include "Core/Types.h"
#include <Eigen/Dense>
//// 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<T, size, 1> &vec) {
// }
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);
}
@@ -205,9 +204,7 @@ public:
typedef Eigen::Matrix<Scalarf, 4, 1> 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<Scalari> ScalariProperty;
typedef Property<Scalarui> ScalaruiProperty;
typedef Property<Scalarl> ScalarlProperty;
typedef Property<Scalarul> ScalarulProperty;
typedef Property<Scalarf> ScalarfProperty;
typedef Property<Scalard> ScalardProperty;
typedef struct _HError3f HError3f;
typedef Property<Vector1i> Vector1iProperty;
typedef Property<Vector1f> Vector1fProperty;
typedef Property<Vector1d> 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<Scalari> ScalariProperty;
typedef Property<Scalarui> ScalaruiProperty;
typedef Property<Scalarl> ScalarlProperty;
typedef Property<Scalarul> ScalarulProperty;
typedef Property<Scalarf> ScalarfProperty;
typedef Property<Scalard> ScalardProperty;
typedef Property<Vector1i> Vector1iProperty;
typedef Property<Vector1f> Vector1fProperty;
typedef Property<Vector1d> Vector1dProperty;
typedef Property<Vector2i> Vector2iProperty;
typedef Property<Vector3i> Vector3iProperty;
@@ -294,9 +291,9 @@ typedef Property<Matrix3d> Matrix3dProperty;
typedef Property<Matrix4d> Matrix4dProperty;
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>
*
@@ -45,142 +43,120 @@
*
*/
#ifndef U_TRANSFORM_H
#define U_TRANSFORM_H
#include <Eigen/Geometry>
#include "Math/Units.h"
#include "Math/Dense.h"
#include "Math/Units.h"
#include <Eigen/Geometry>
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 &copy) :
m_T(copy.m_T),
m_Parent(copy.m_Parent)
{}
AffineTransform(const AffineTransform &copy)
: 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<float>(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<float>(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<float>(q));
}
void QuaternionRotate(const Vector4f &q)
{ this->m_T.rotate(Eigen::Quaternion<float>(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 <class ArchiveT>
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 <class ArchiveT>
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

View File

@@ -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}

View File

@@ -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 <iostream>
#include "vector"
#include "Detectors/MuonScatter.h"
#include "TObject.h"
#include "TParticle.h"
#include "Detectors/MuonScatter.h"
#include "vector"
#include <iostream>
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

View File

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

View File

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

View File

@@ -15,11 +15,11 @@ using namespace uLib;
int main() {
std::cout << "Creating ContainerBox..." << std::endl;
ContainerBox box(Vector3f(1.0, 1.0, 1.0)); // 1x1x1 unit box
box.SetInstanceName("MyTestBox");
ContainerBox* box = new ContainerBox(Vector3f(1.0, 1.0, 1.0)); // 1x1x1 unit box
box->SetInstanceName("MyTestBox");
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.SetColor(1.0, 0.0, 0.0); // Red

View File

@@ -43,50 +43,43 @@
#include "Vtk/Math/vtkDense.h"
namespace uLib {
namespace Vtk {
struct ContainerBoxData {
vtkSmartPointer<vtkActor> m_Cube;
vtkSmartPointer<vtkActor> m_Axes;
vtkSmartPointer<vtkAssembly> m_VtkAsm;
uLib::Connection m_UpdateSignal;
vtkSmartPointer<vtkActor> m_Cube;
vtkSmartPointer<vtkActor> m_Axes;
vtkSmartPointer<vtkAssembly> m_VtkAsm;
uLib::Connection m_UpdateSignal;
ContainerBoxData() : m_Cube(vtkSmartPointer<vtkActor>::New()),
m_Axes(vtkSmartPointer<vtkActor>::New()),
m_VtkAsm(vtkSmartPointer<vtkAssembly>::New()) {}
~ContainerBoxData() {
}
ContainerBoxData()
: m_Cube(vtkSmartPointer<vtkActor>::New()),
m_Axes(vtkSmartPointer<vtkActor>::New()),
m_VtkAsm(vtkSmartPointer<vtkAssembly>::New()) {}
~ContainerBoxData() {}
};
ContainerBox::ContainerBox(ContainerBox::Content *content)
: d(new ContainerBoxData()), ObjectWrapper(content) {
: d(new ContainerBoxData()),
ObjectWrapper(content ? content : new Content()) {
this->InstallPipe();
d->m_UpdateSignal =
Object::connect(this->m_model.get(), &uLib::Object::Updated, this, &ContainerBox::Update);
d->m_UpdateSignal = Object::connect(
this->m_model.get(), &uLib::Object::Updated, this, &ContainerBox::Update);
}
ContainerBox::~ContainerBox() {
delete d;
}
ContainerBox::~ContainerBox() { delete d; }
vtkPolyData *ContainerBox::GetPolyData() const {
// TODO
return NULL;
}
void ContainerBox::Update() {
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) {
// Apply the full volume matrix (TRS * m_LocalT)
vtkNew<vtkMatrix4x4> m;
@@ -100,32 +93,28 @@ void ContainerBox::Update() {
this->Prop3D::Update();
}
void ContainerBox::SyncFromVtk() {
RecursiveMutex::ScopedLock lock(this->m_UpdateMutex);
if (!this->m_model) return;
if (!this->m_model)
return;
vtkProp3D* root = this->GetProxyProp();
if (!root) return;
vtkProp3D *root = this->GetProxyProp();
if (!root)
return;
// VTK -> Model: Extract new world TRS from proxy, which matches the model's TRS center
vtkMatrix4x4* rootMat = root->GetUserMatrix();
// VTK -> Model: Extract new world TRS from proxy, which matches the model's
// TRS center
vtkMatrix4x4 *rootMat = root->GetUserMatrix();
Matrix4f vtkWorld = VtkToMatrix4f(rootMat);
// Synchronize TRS property members from the updated local matrix
this->m_model->FromMatrix(vtkWorld);
// Since we modified the model, notify observers, but block the loop back to VTK
// ConnectionBlock blocker(d->m_UpdateSignal);
// Since we modified the model, notify observers, but block the loop back to
// VTK ConnectionBlock blocker(d->m_UpdateSignal);
this->m_model->Updated();
}
void ContainerBox::InstallPipe() {
if (!this->m_model)
return;
@@ -133,7 +122,7 @@ void ContainerBox::InstallPipe() {
// CUBE
vtkSmartPointer<vtkCubeSource> cube = vtkSmartPointer<vtkCubeSource>::New();
vtkSmartPointer<vtkPolyDataMapper> mapper =
vtkSmartPointer<vtkPolyDataMapper>::New();
cube->SetBounds(0, 1, 0, 1, 0, 1);
@@ -160,11 +149,11 @@ void ContainerBox::InstallPipe() {
mapper = vtkSmartPointer<vtkPolyDataMapper>::New();
mapper->SetInputConnection(axes->GetOutputPort());
mapper->Update();
d->m_VtkAsm->AddPart(d->m_Cube);
d->m_VtkAsm->AddPart(d->m_Axes);
this->SetProp(d->m_VtkAsm);
// vtkProp3D* root = d->m_VtkAsm;
// if (root) {
// this->ApplyProp3DTransform(root);

View File

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

View File

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

View File

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

View File

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

View File

@@ -290,9 +290,6 @@ 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);
}
}
Prop3D::~Prop3D()

View File

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