20#include <lagrange/common.h>
21#include <lagrange/utils/warning.h>
26template <
typename _AttributeArray>
30 using AttributeArray = _AttributeArray;
31 using Scalar =
typename AttributeArray::Scalar;
34 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
36 std::vector<std::string> get_attribute_names()
const
38 std::vector<std::string> names;
39 for (
const auto& itr : m_data) {
40 names.push_back(itr.first);
45 bool has_attribute(
const std::string& name)
const {
return m_data.find(name) != m_data.end(); }
47 void add_attribute(
const std::string& name) { m_data.insert({name, AttributeArray()}); }
49 template <
typename Derived>
50 void add_attribute(
const std::string& name,
const Eigen::PlainObjectBase<Derived>& value)
52 m_data.insert({name, value});
55 template <
typename Derived>
56 void set_attribute(
const std::string& name,
const Eigen::PlainObjectBase<Derived>& value)
58 auto itr = m_data.find(name);
59 if (itr == m_data.end()) {
60 std::stringstream err_msg;
61 err_msg <<
"Attributes::set_attribute() failed: Attribute \"" << name
62 <<
"\" does not exists.";
63 throw std::runtime_error(err_msg.str());
68 const AttributeArray& get_attribute(
const std::string& name)
const
70 auto itr = m_data.find(name);
71 if (itr == m_data.end()) {
72 std::stringstream err_msg;
73 err_msg <<
"Attributes::get_attribute() failed: Attribute \"" << name
74 <<
"\" does not exists.";
75 throw std::runtime_error(err_msg.str());
80 void remove_attribute(
const std::string& name)
82 auto itr = m_data.find(name);
83 if (itr == m_data.end()) {
84 std::stringstream err_msg;
85 err_msg <<
"Attributes::remove_attribute() failed: Attribute \"" << name
86 <<
"\" does not exists.";
87 throw std::runtime_error(err_msg.str());
92 template <
typename Derived>
93 void import_attribute(
const std::string& name, Eigen::PlainObjectBase<Derived>& attr)
95 auto itr = m_data.find(name);
96 if (itr == m_data.end()) {
97 std::stringstream err_msg;
98 err_msg <<
"Attributes::import_attribute() failed: Attribute \"" << name
99 <<
"\" does not exists.";
100 throw std::runtime_error(err_msg.str());
105 template <
typename Derived>
106 void export_attribute(
const std::string& name, Eigen::PlainObjectBase<Derived>& attr)
108 auto itr = m_data.find(name);
109 if (itr == m_data.end()) {
110 std::stringstream err_msg;
111 err_msg <<
"Attributes::export_attribute() failed: Attribute \"" << name
112 <<
"\" does not exists.";
113 throw std::runtime_error(err_msg.str());
118 template <
typename Archive>
119 void serialize(Archive& ar)
125 ar.object([&](
auto& ar) {
126 ar(
"data", DATA) & m_data;
128 LA_IGNORE_SHADOW_WARNING_END
132 std::map<std::string, AttributeArray> m_data;
135template <
typename AttributeArray,
typename Archive>
138 attributes.serialize(ar);
Legacy attribute class.
Definition: Attributes.h:28
#define LA_IGNORE_SHADOW_WARNING_BEGIN
Ignore shadow warnings.
Definition: warning.h:68
Main namespace for Lagrange.
Definition: AABBIGL.h:30
void move_data(Eigen::DenseBase< Derived1 > &from, Eigen::DenseBase< Derived2 > &to)
Move data from one Eigen obj to another.
Definition: common.h:61