Compare commits
3 Commits
db76513e79
...
22262d3dc6
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
22262d3dc6 | ||
|
|
dfd33e9a9c | ||
|
|
76f29328cd |
@@ -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)
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -60,6 +60,10 @@ public:
|
||||
std::string slostr;
|
||||
};
|
||||
|
||||
~ObjectPrivate() {
|
||||
for (auto& s : sigv) delete s.signal;
|
||||
}
|
||||
|
||||
std::string m_InstanceName;
|
||||
std::vector<Signal> sigv;
|
||||
std::vector<Slot> slov;
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -84,7 +84,8 @@ public:
|
||||
const std::string &GetInstanceName() const;
|
||||
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);
|
||||
|
||||
/** @brief Checks if signals are currently blocked. */
|
||||
@@ -99,7 +100,8 @@ public:
|
||||
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();
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
@@ -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) {}
|
||||
@@ -139,7 +148,6 @@ public:
|
||||
|
||||
signals:
|
||||
virtual void Updated();
|
||||
virtual void PropertyUpdated();
|
||||
|
||||
// Qt4 style connector //
|
||||
static bool connect(const Object *ob1, const char *signal_name,
|
||||
@@ -160,8 +168,8 @@ 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 //
|
||||
@@ -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>
|
||||
|
||||
@@ -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); }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,3 +24,5 @@ int main() {
|
||||
std::cout << "Tests passed (compilation and manual instantiation)!" << std::endl;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -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 ///////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
@@ -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;
|
||||
|
||||
@@ -23,8 +23,6 @@
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////*/
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Copyright (C) 2012 Andrea Rigoni Garola <andrea.rigoni@pd.infn.it>
|
||||
*
|
||||
@@ -45,63 +43,43 @@
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#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;
|
||||
|
||||
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; }
|
||||
|
||||
@@ -113,16 +91,18 @@ public:
|
||||
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; }
|
||||
@@ -143,11 +123,9 @@ public:
|
||||
this->m_T.linear().col(2).norm());
|
||||
}
|
||||
|
||||
|
||||
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 )
|
||||
Eigen::AngleAxisf ax(angle, axis);
|
||||
this->m_T.rotate(Eigen::Quaternion<float>(ax));
|
||||
@@ -160,27 +138,25 @@ public:
|
||||
|
||||
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());
|
||||
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)
|
||||
{
|
||||
void FlipAxes(int first, int second) {
|
||||
Matrix3f mat = Matrix3f::Identity();
|
||||
mat.col(first).swap(mat.col(second));
|
||||
m_T.rotate(mat);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
///////// TRS PARAMETERS /////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
@@ -189,8 +165,7 @@ 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 :
|
||||
@@ -201,13 +176,9 @@ public:
|
||||
|
||||
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);
|
||||
@@ -218,11 +189,14 @@ public:
|
||||
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);
|
||||
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);
|
||||
Vector3f euler = rot.canonicalEulerAngles(2, 1, 0);
|
||||
this->rotation = Vector3f(euler(2), euler(1), euler(0));
|
||||
|
||||
this->SetMatrix(mat);
|
||||
@@ -246,9 +220,7 @@ public:
|
||||
this->SyncMatrix();
|
||||
}
|
||||
|
||||
void SyncMatrix() {
|
||||
this->GetTransform() = GetAffineMatrix();
|
||||
}
|
||||
void SyncMatrix() { this->GetTransform() = GetAffineMatrix(); }
|
||||
|
||||
void Updated() override {
|
||||
this->SyncMatrix();
|
||||
@@ -263,7 +235,6 @@ public:
|
||||
ar &HRP(scaling);
|
||||
}
|
||||
|
||||
|
||||
AffineMatrix GetAffineMatrix() const {
|
||||
AffineMatrix m = AffineMatrix::Identity();
|
||||
m.translate(position);
|
||||
@@ -274,19 +245,9 @@ public:
|
||||
return m;
|
||||
}
|
||||
|
||||
Matrix4f GetMatrix() const {
|
||||
return this->GetAffineMatrix().matrix();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
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;
|
||||
@@ -297,8 +258,6 @@ inline std::istream& operator>>(std::istream& is, TRS& trs) {
|
||||
return is;
|
||||
}
|
||||
|
||||
} // uLib
|
||||
|
||||
|
||||
} // namespace uLib
|
||||
|
||||
#endif // U_TRANSFORM_H
|
||||
|
||||
@@ -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}
|
||||
|
||||
@@ -9,19 +9,17 @@
|
||||
// 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
|
||||
{
|
||||
class muCastorMCTrack : public TObject {
|
||||
|
||||
public:
|
||||
|
||||
/** Default constructor **/
|
||||
muCastorMCTrack();
|
||||
|
||||
@@ -32,7 +30,6 @@ class muCastorMCTrack : public TObject
|
||||
virtual ~muCastorMCTrack();
|
||||
void Reset();
|
||||
|
||||
|
||||
/** Accessors **/
|
||||
Int_t GetFirstDaughter() const { return fDaughter[0]; }
|
||||
Int_t GetMother() const { return fMother[0]; }
|
||||
@@ -52,7 +49,6 @@ class muCastorMCTrack : public TObject
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
/* Private variables - copying private variables of TParticle */
|
||||
|
||||
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
|
||||
|
||||
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
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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));
|
||||
{
|
||||
ContainerBox* box = new ContainerBox();
|
||||
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.SetRepresentation(Vtk::Prop3D::Surface);
|
||||
// v_box.SetOpacity(0.5);
|
||||
// v_box.SetSelectable(true);
|
||||
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;
|
||||
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) {
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -43,7 +43,6 @@
|
||||
|
||||
#include "Vtk/Math/vtkDense.h"
|
||||
|
||||
|
||||
namespace uLib {
|
||||
namespace Vtk {
|
||||
|
||||
@@ -53,38 +52,32 @@ struct ContainerBoxData {
|
||||
vtkSmartPointer<vtkAssembly> m_VtkAsm;
|
||||
uLib::Connection m_UpdateSignal;
|
||||
|
||||
|
||||
ContainerBoxData() : m_Cube(vtkSmartPointer<vtkActor>::New()),
|
||||
ContainerBoxData()
|
||||
: m_Cube(vtkSmartPointer<vtkActor>::New()),
|
||||
m_Axes(vtkSmartPointer<vtkActor>::New()),
|
||||
m_VtkAsm(vtkSmartPointer<vtkAssembly>::New()) {}
|
||||
~ContainerBoxData() {
|
||||
}
|
||||
~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());
|
||||
if (prop) {
|
||||
@@ -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;
|
||||
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();
|
||||
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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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(); });
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user