14#include <lagrange/Logger.h>
15#include <lagrange/common.h>
16#include <lagrange/experimental/Array.h>
17#include <lagrange/experimental/create_array.h>
20namespace experimental {
31 Attribute(std::shared_ptr<ArrayBase> values)
32 : m_values(std::move(values))
35 template <
typename Derived>
36 Attribute(
const Eigen::MatrixBase<Derived>& values)
41 template <
typename Derived>
42 Attribute(Eigen::MatrixBase<Derived>&& values)
44 this->set(std::move(values));
48 std::shared_ptr<const ArrayBase> get()
const {
return m_values; }
49 std::shared_ptr<ArrayBase> get() {
return m_values; }
51 template <
typename Derived>
52 decltype(
auto) get()
const
55 const auto& values = *m_values;
56 return values.get<Derived>();
59 template <
typename Derived>
63 return m_values->get<Derived>();
66 template <
typename Derived>
67 decltype(
auto) view()
const
70 const auto& values = *m_values;
71 return values.view<Derived>();
74 template <
typename Derived>
78 return m_values->view<Derived>();
81 template <
typename Derived>
82 void set(
const Eigen::MatrixBase<Derived>& values)
84 if (m_values ==
nullptr) {
85 m_values = create_array(values.derived());
87 m_values->set(values.derived());
91 template <
typename Derived>
92 void set(Eigen::MatrixBase<Derived>&& values)
95 void* ptr = values.derived().data();
97 if (m_values ==
nullptr) {
98 m_values = create_array(std::move(values.derived()));
100 m_values->set(std::move(values.derived()));
103 void* ptr2 = m_values->data();
105 logger().warn(
"Attribute values are copied when they should have been moved. "
106 "Likely caused by inexact match of `Derived` type.");
111 template <
typename Derived>
112 void set(
const Eigen::ArrayBase<Derived>& values)
114 set(values.matrix());
117 template <
typename Derived>
118 void set(Eigen::ArrayBase<Derived>&& values)
120 set(std::move(values.matrix()));
123 void set(std::shared_ptr<ArrayBase> values) { m_values = std::move(values); }
125 template <
typename Archive>
126 void serialize_impl(Archive& ar)
132 std::shared_ptr<ArrayBase> m_values;
135template <
typename Archive>
136void serialize(
Attribute& attribute, Archive& ar)
138 attribute.serialize_impl(ar);
Definition: Attribute.h:23
LA_CORE_API spdlog::logger & logger()
Retrieves the current logger.
Definition: Logger.cpp:40
#define la_runtime_assert(...)
Runtime assertion check.
Definition: assert.h:169
Main namespace for Lagrange.
Definition: AABBIGL.h:30