Wildmeshing Toolkit
MinOperationSequence.cpp
Go to the documentation of this file.
2 
3 
4 namespace wmtk::operations {
5 
6 
8  Mesh& mesh,
9  const std::vector<std::shared_ptr<Operation>>& operations)
10  : OperationSequence(mesh, operations)
11 {}
12 
14 
15 
16 std::vector<simplex::Simplex> MinOperationSequence::execute_operations(
17  const simplex::Simplex& simplex)
18 {
19  assert(m_value != nullptr);
20  assert(!m_operations.empty());
21 
22  std::vector<std::pair<int64_t, double>> values;
23  values.reserve(m_operations.size());
24 
25  for (int64_t i = 0; i < m_operations.size(); ++i) {
26  values.emplace_back(i, m_value(i, simplex));
27  }
28  std::sort(values.begin(), values.end(), [](const auto& a, const auto& b) {
29  return a.second < b.second;
30  });
31 
32  for (int64_t i = 0; i < m_operations.size(); ++i) {
33  const auto& o = m_operations[values[i].first];
34  const auto out = (*o)(simplex);
35  if (!out.empty()) return out;
36  }
37 
38  return {};
39 }
40 
41 
42 } // namespace wmtk::operations
std::function< double(int64_t, const simplex::Simplex &)> m_value
MinOperationSequence(Mesh &mesh, const std::vector< std::shared_ptr< Operation >> &operations={})
std::vector< simplex::Simplex > execute_operations(const simplex::Simplex &simplex) override
std::vector< std::shared_ptr< Operation > > m_operations