Wildmeshing Toolkit
AttributeTransferConfiguration.cpp
Go to the documentation of this file.
2 #include <spdlog/spdlog.h>
11 namespace wmtk::operations {
12 namespace internal {
13 
14 
15 namespace {
16 template <typename Derived>
17 auto filter_to_derived(const std::vector<std::shared_ptr<const AttributeTransferEdge>>& edges)
18 {
19  return wmtk::utils::filter_pointers_to_derived<const AttributeTransferEdge, const Derived>(
20  edges);
21 }
22 
23 
24 } // namespace
25 
27 {
28 public:
29  void add(const std::shared_ptr<const AttributeTransferEdge>&);
30 
31 
32  // This returns a copy because this copy should be passed into some object eventually / i don't intend on keeping the internal data structure as a vector in the long term
33  std::vector<std::shared_ptr<const AttributeTransferEdge>> linearized_strategies() const;
34  std::vector<std::shared_ptr<const NewAttributeStrategy>> linearized_new_strategies() const;
35  std::vector<std::shared_ptr<const AttributeTransferStrategyBase>>
37 
38 private:
39  std::vector<std::shared_ptr<const AttributeTransferEdge>> m_strats;
40 };
41 
42 void AttributeTransferConfigurationPimpl::add(const std::shared_ptr<const AttributeTransferEdge>& s)
43 {
44  m_strats.emplace_back(s);
45 }
46 std::vector<std::shared_ptr<const AttributeTransferEdge>>
48 {
49  return m_strats;
50 }
51 
52 
54  -> std::vector<std::shared_ptr<const NewAttributeStrategy>>
55 {
56  return filter_to_derived<NewAttributeStrategy>(linearized_strategies());
57 }
59  -> std::vector<std::shared_ptr<const AttributeTransferStrategyBase>>
60 {
61  return filter_to_derived<AttributeTransferStrategyBase>(linearized_strategies());
62 }
63 } // namespace internal
65  : m_impl(std::make_unique<internal::AttributeTransferConfigurationPimpl>())
66 {}
69 {
70  m_impl->add(a.shared_from_this());
71 }
73  -> std::vector<std::shared_ptr<const AttributeTransferEdge>>
74 {
75  return m_impl->linearized_strategies();
76 }
77 
79  -> std::vector<std::shared_ptr<const NewAttributeStrategy>>
80 {
81  return m_impl->linearized_new_strategies();
82 }
84  -> std::vector<std::shared_ptr<const AttributeTransferStrategyBase>>
85 {
86  return m_impl->linearized_transfer_strategies();
87 }
88 
90  const attribute::MeshAttributeHandle& attribute,
93 {
94  auto ptr = std::visit(
95  [&](auto&& val) noexcept -> std::shared_ptr<const AttributeTransferEdge> {
96  using HandleType = typename std::decay_t<decltype(val)>;
97  if constexpr (attribute::MeshAttributeHandle::template handle_type_is_basic<
98  HandleType>()) {
99  using T = typename HandleType::Type;
101 
102  std::shared_ptr<OpType> tmp = std::make_shared<OpType>(attribute);
103  tmp->set_strategy(spine);
104  tmp->set_rib_strategy(rib);
105 
106  return tmp;
107  } else {
108  return {};
109  }
110  },
111  attribute.handle());
112  add(*ptr);
113 }
114 
115 // convenience for creating collapse starting/new edges
117  const attribute::MeshAttributeHandle& attribute,
119 {
120  auto ptr = std::visit(
121  [&](auto&& val) noexcept -> std::shared_ptr<const AttributeTransferEdge> {
122  using HandleType = typename std::decay_t<decltype(val)>;
123  if constexpr (attribute::MeshAttributeHandle::template handle_type_is_basic<
124  HandleType>()) {
125  using T = typename HandleType::Type;
127 
128  std::shared_ptr<OpType> tmp = std::make_shared<OpType>(attribute);
129  tmp->set_strategy(strategy);
130  return tmp;
131  } else {
132  return {};
133  }
134  },
135  attribute.handle());
136  add(*ptr);
137 }
138 
140 void AttributeTransferConfiguration::apply(EdgeSplit& split, bool clear) const
141 {
142  if (clear) {
145  }
146  auto new_strats =
147  internal::filter_to_derived<BaseSplitNewAttributeStrategy>(linearized_strategies());
148  for (const auto& s : new_strats) {
149  const auto targets = s->targets();
150  assert(targets.size() == 1); // unclear if we ever will have more than 1 target.
151  split.set_new_attribute_strategy(targets[0], s);
152  }
153 
154  for (const auto& s : linearized_transfer_strategies()) {
155  const auto targets = s->targets();
156  assert(targets.size() == 1); // unclear if we ever will have more than 1 target.
157  split.set_transfer_strategy(targets[0], s);
158  }
159 }
161 void AttributeTransferConfiguration::apply(EdgeCollapse& collapse, bool clear) const
162 {
163  if (clear) {
166  }
167 
168  auto new_strats =
169  internal::filter_to_derived<BaseCollapseNewAttributeStrategy>(linearized_strategies());
170  spdlog::info(
171  "{} {} {}",
172  linearized_strategies().size(),
173  new_strats.size(),
175 
176  for (const auto& s : new_strats) {
177  const auto targets = s->targets();
178  assert(targets.size() == 1); // unclear if we ever will have more than 1 target.
179  collapse.set_new_attribute_strategy(targets[0], s);
180  }
181 
182  for (const auto& s : linearized_transfer_strategies()) {
183  const auto targets = s->targets();
184  assert(targets.size() == 1); // unclear if we ever will have more than 1 target.
185  collapse.set_transfer_strategy(targets[0], s);
186  }
187 }
188 } // namespace wmtk::operations
std::unique_ptr< internal::AttributeTransferConfigurationPimpl > m_impl
void add_split_new(const attribute::MeshAttributeHandle &attribute, const wmtk::operations::SplitBasicStrategy &spine=wmtk::operations::SplitBasicStrategy::Default, const wmtk::operations::SplitRibBasicStrategy &rib=wmtk::operations::SplitRibBasicStrategy::Default)
std::vector< std::shared_ptr< const AttributeTransferStrategyBase > > linearized_transfer_strategies() const
std::vector< std::shared_ptr< const AttributeTransferEdge > > linearized_strategies() const
void apply(EdgeSplit &split, bool clear=false) const
std::vector< std::shared_ptr< const NewAttributeStrategy > > linearized_new_strategies() const
void add_collapse_new(const attribute::MeshAttributeHandle &attribute, const wmtk::operations::CollapseBasicStrategy &strategy=wmtk::operations::CollapseBasicStrategy::Default)
void set_new_attribute_strategy(const attribute::MeshAttributeHandle &attribute, const std::shared_ptr< const operations::BaseCollapseNewAttributeStrategy > &other)
void set_new_attribute_strategy(const attribute::MeshAttributeHandle &attribute, const std::shared_ptr< const operations::BaseSplitNewAttributeStrategy > &other)
Definition: EdgeSplit.cpp:85
void set_transfer_strategy(const attribute::MeshAttributeHandle &attribute, const std::shared_ptr< const operations::AttributeTransferStrategyBase > &other)
Definition: Operation.cpp:43
void clear_attribute_transfer_strategies()
Definition: Operation.cpp:38
std::vector< std::shared_ptr< const AttributeTransferStrategyBase > > linearized_transfer_strategies() const
std::vector< std::shared_ptr< const NewAttributeStrategy > > linearized_new_strategies() const
void add(const std::shared_ptr< const AttributeTransferEdge > &)
std::vector< std::shared_ptr< const AttributeTransferEdge > > linearized_strategies() const
std::vector< std::shared_ptr< const AttributeTransferEdge > > m_strats
Definition: autodiff.h:995
std::vector< Simplex > make_unique(const Mesh &m, const std::vector< Simplex > &s)
Definition: make_unique.cpp:8
std::vector< Tuple > edges(const Mesh &m, const Simplex &simplex)