Wildmeshing Toolkit
Operation.hpp
Go to the documentation of this file.
1 #pragma once
2 
5 
6 #include <wmtk/Tuple.hpp>
9 
10 
11 namespace wmtk {
12 class Mesh;
13 
14 namespace operations {
15 
16 
17 // namespace utils {
18 // class MultiMeshEdgeSplitFunctor;
19 // class MultiMeshEdgeCollapseFunctor;
20 
21 // } // namespace utils
22 
23 class Operation
24 {
25 public:
26  // friend class utils::MultiMeshEdgeSplitFunctor;
27  // friend class utils::MultiMeshEdgeCollapseFunctor;
28 
30  virtual ~Operation();
31 
32  // main entry point of the operator by the scheduler
33  virtual std::vector<simplex::Simplex> operator()(const simplex::Simplex& simplex);
34 
35  virtual double priority(const simplex::Simplex& simplex) const
36  {
37  return m_priority == nullptr ? 0 : m_priority(simplex);
38  }
39 
40  virtual bool use_random_priority() const { return m_use_random_priority; }
41  virtual bool& use_random_priority() { return m_use_random_priority; }
42 
43  virtual PrimitiveType primitive_type() const = 0;
44 
45  const Mesh& mesh() const { return m_mesh; }
46  Mesh& mesh() { return m_mesh; }
47 
48  void add_invariant(std::shared_ptr<Invariant> invariant) { m_invariants.add(invariant); }
49 
50  void set_priority(const std::function<double(const simplex::Simplex&)>& func)
51  {
52  m_priority = func;
53  }
54 
55  std::shared_ptr<const operations::AttributeTransferStrategyBase> get_transfer_strategy(
56  const attribute::MeshAttributeHandle& attribute);
57 
58 
60  const std::shared_ptr<const operations::AttributeTransferStrategyBase>& other);
61 
63  const attribute::MeshAttributeHandle& attribute,
64  const std::shared_ptr<const operations::AttributeTransferStrategyBase>& other);
65 
67 
68  virtual void reserve_enough_simplices();
69 
70 protected:
74  virtual std::vector<simplex::Simplex> execute(const simplex::Simplex& simplex) = 0;
75 
79  virtual std::vector<simplex::Simplex> unmodified_primitives(
80  const simplex::Simplex& simplex) const = 0;
81 
82  // does invariant pre-checks
83  virtual bool before(const simplex::Simplex& simplex) const;
84  // does invariant pre-checks
85  virtual bool after(
86  const std::vector<simplex::Simplex>& unmods,
87  const std::vector<simplex::Simplex>& mods) const;
88 
89 
90  void apply_attribute_transfer(const std::vector<simplex::Simplex>& direct_mods);
91 
92 
93 private:
95  bool m_use_random_priority = false;
96 
97 
98 protected:
99  std::function<double(const simplex::Simplex&)> m_priority = nullptr;
100 
102 
103  std::vector<std::shared_ptr<const operations::AttributeTransferStrategyBase>>
105 };
106 
107 } // namespace operations
108 } // namespace wmtk
void add(std::shared_ptr< Invariant > invariant)
void set_transfer_strategy(const attribute::MeshAttributeHandle &attribute, const std::shared_ptr< const operations::AttributeTransferStrategyBase > &other)
Definition: Operation.cpp:43
void add_invariant(std::shared_ptr< Invariant > invariant)
Definition: Operation.hpp:48
virtual bool after(const std::vector< simplex::Simplex > &unmods, const std::vector< simplex::Simplex > &mods) const
Definition: Operation.cpp:135
void set_priority(const std::function< double(const simplex::Simplex &)> &func)
Definition: Operation.hpp:50
const Mesh & mesh() const
Definition: Operation.hpp:45
virtual PrimitiveType primitive_type() const =0
void clear_attribute_transfer_strategies()
Definition: Operation.cpp:38
virtual std::vector< simplex::Simplex > execute(const simplex::Simplex &simplex)=0
returns an empty vector in case of failure
std::shared_ptr< const operations::AttributeTransferStrategyBase > get_transfer_strategy(const attribute::MeshAttributeHandle &attribute)
Definition: Operation.cpp:26
virtual double priority(const simplex::Simplex &simplex) const
Definition: Operation.hpp:35
virtual void reserve_enough_simplices()
Definition: Operation.cpp:195
std::vector< std::shared_ptr< const operations::AttributeTransferStrategyBase > > m_attr_transfer_strategies
Definition: Operation.hpp:104
virtual std::vector< simplex::Simplex > operator()(const simplex::Simplex &simplex)
Definition: Operation.cpp:66
void add_transfer_strategy(const std::shared_ptr< const operations::AttributeTransferStrategyBase > &other)
Definition: Operation.cpp:59
virtual std::vector< simplex::Simplex > unmodified_primitives(const simplex::Simplex &simplex) const =0
Returns all simplices that will be potentially affected by the operation.
invariants::InvariantCollection m_invariants
Definition: Operation.hpp:101
virtual bool use_random_priority() const
Definition: Operation.hpp:40
virtual bool before(const simplex::Simplex &simplex) const
Definition: Operation.cpp:97
virtual bool & use_random_priority()
Definition: Operation.hpp:41
std::function< double(const simplex::Simplex &)> m_priority
Definition: Operation.hpp:99
void apply_attribute_transfer(const std::vector< simplex::Simplex > &direct_mods)
Definition: Operation.cpp:142
Definition: Accessor.hpp:6