Wildmeshing Toolkit
TetMesh.hpp
Go to the documentation of this file.
1 #pragma once
2 
5 #include "MeshCRTP.hpp"
6 
7 namespace wmtk {
8 namespace operations::utils {
9 class MultiMeshEdgeSplitFunctor;
10 class MultiMeshEdgeCollapseFunctor;
11 class UpdateEdgeOperationMultiMeshMapFunctor;
12 } // namespace operations::utils
13 class TetMesh : public MeshCRTP<TetMesh>
14 {
15 public:
16  friend class MeshCRTP<TetMesh>;
20  template <typename U, typename MeshType, int Dim>
21  friend class attribute::Accessor;
22  TetMesh();
23  ~TetMesh() override;
24  TetMesh(const TetMesh& o) = delete;
25  TetMesh(TetMesh&& o);
26  TetMesh& operator=(const TetMesh& o) = delete;
28 
29  Tuple switch_tuple(const Tuple& tuple, PrimitiveType type) const final override;
30  bool is_ccw(const Tuple& tuple) const final override;
31  using Mesh::is_boundary;
32  bool is_boundary(PrimitiveType pt, const Tuple& tuple) const final override;
33  bool is_boundary_vertex(const Tuple& tuple) const;
34  bool is_boundary_edge(const Tuple& tuple) const;
35  bool is_boundary_face(const Tuple& tuple) const;
36 
37  bool is_valid(const Tuple& tuple) const final override;
38 
39  void initialize(
40  Eigen::Ref<const RowVectors4l> TV,
41  Eigen::Ref<const RowVectors6l> TE,
42  Eigen::Ref<const RowVectors4l> TF,
43  Eigen::Ref<const RowVectors4l> TT,
44  Eigen::Ref<const VectorXl> VT,
45  Eigen::Ref<const VectorXl> ET,
46  Eigen::Ref<const VectorXl> FT);
47  void initialize(Eigen::Ref<const RowVectors4l> T, bool is_free = false);
48  void initialize_free(int64_t count);
49 
50  bool is_connectivity_valid() const final override;
51 
52  std::vector<std::vector<TypedAttributeHandle<int64_t>>> connectivity_attributes()
53  const final override;
54 
55  Tuple switch_vertex(const Tuple& tuple) const;
56  Tuple switch_edge(const Tuple& tuple) const;
57  Tuple switch_face(const Tuple& tuple) const;
58  Tuple switch_tetrahedron(const Tuple& tuple) const;
59 
60  // get the four vertex tuples in the tv matrix with the same order
61  std::vector<Tuple> orient_vertices(const Tuple& t) const override;
62 
63 
64 protected:
65  void make_cached_accessors();
66  int64_t id(const Tuple& tuple, PrimitiveType type) const;
67  using MeshCRTP<TetMesh>::id; // getting the (simplex) prototype
68 
69 
70  int64_t id_vertex(const Tuple& tuple) const { return id(tuple, PrimitiveType::Vertex); }
71  int64_t id_edge(const Tuple& tuple) const { return id(tuple, PrimitiveType::Edge); }
72  int64_t id_face(const Tuple& tuple) const { return id(tuple, PrimitiveType::Triangle); }
73  int64_t id_tet(const Tuple& tuple) const { return id(tuple, PrimitiveType::Tetrahedron); }
74 
82  Tuple tuple_from_id(const PrimitiveType type, const int64_t gid) const final override;
83  Tuple tuple_from_global_ids(int64_t tid, int64_t fid, int64_t eid, int64_t vid) const;
84 
85  // private:
86 protected:
87  class TetMeshOperationExecutor;
91 
96 
97  std::unique_ptr<attribute::Accessor<int64_t, TetMesh>> m_vt_accessor;
98  std::unique_ptr<attribute::Accessor<int64_t, TetMesh>> m_et_accessor;
99  std::unique_ptr<attribute::Accessor<int64_t, TetMesh>> m_ft_accessor;
100 
101  std::unique_ptr<attribute::Accessor<int64_t, TetMesh>> m_tv_accessor;
102  std::unique_ptr<attribute::Accessor<int64_t, TetMesh>> m_te_accessor;
103  std::unique_ptr<attribute::Accessor<int64_t, TetMesh>> m_tf_accessor;
104  std::unique_ptr<attribute::Accessor<int64_t, TetMesh>> m_tt_accessor;
105 
106 public:
107  Tuple vertex_tuple_from_id(int64_t id) const;
108  Tuple edge_tuple_from_id(int64_t id) const;
109  Tuple face_tuple_from_id(int64_t id) const;
110  Tuple tet_tuple_from_id(int64_t id) const;
111 };
112 
113 inline Tuple TetMesh::switch_vertex(const Tuple& tuple) const
114 {
115  return switch_tuple(tuple, PrimitiveType::Vertex);
116 }
117 inline Tuple TetMesh::switch_edge(const Tuple& tuple) const
118 {
119  return switch_tuple(tuple, PrimitiveType::Edge);
120 }
121 inline Tuple TetMesh::switch_face(const Tuple& tuple) const
122 {
123  return switch_tuple(tuple, PrimitiveType::Triangle);
124 }
125 inline Tuple TetMesh::switch_tetrahedron(const Tuple& tuple) const
126 {
128 }
129 
130 inline int64_t TetMesh::id(const Tuple& tuple, PrimitiveType type) const
131 {
132  switch (type) {
133  case PrimitiveType::Vertex: {
134  auto tv = m_tv_accessor->const_vector_attribute<4>(tuple);
135  return tv(tuple.m_local_vid);
136  break;
137  }
138  case PrimitiveType::Edge: {
139  auto te = m_te_accessor->const_vector_attribute<6>(tuple);
140  return te(tuple.m_local_eid);
141  break;
142  }
144  auto tf = m_tf_accessor->const_vector_attribute<4>(tuple);
145  return tf(tuple.m_local_fid);
146  break;
147  }
149  return tuple.m_global_cid;
150  break;
151  }
152  default: assert(false); // "Tuple id: Invalid primitive type"
153  }
154 
155  return -1;
156 }
157 
158 } // namespace wmtk
A Curiously Recurring Template Pattern shim to enable generic specialization of functions.
Definition: MeshCRTP.hpp:24
int64_t id(const Tuple &tuple, PrimitiveType type) const
return the global id of the Tuple of the given dimension
Definition: Mesh.hpp:1021
bool is_free() const
Definition: Mesh.hpp:988
bool is_boundary(const simplex::Simplex &tuple) const
check if a simplex lies on a boundary or not
Definition: Mesh.cpp:107
TypedAttributeHandle< int64_t > m_tt_handle
Definition: TetMesh.hpp:95
std::unique_ptr< attribute::Accessor< int64_t, TetMesh > > m_tv_accessor
Definition: TetMesh.hpp:101
TetMesh & operator=(const TetMesh &o)=delete
TetMesh(const TetMesh &o)=delete
TypedAttributeHandle< int64_t > m_vt_handle
Definition: TetMesh.hpp:87
Tuple tuple_from_id(const PrimitiveType type, const int64_t gid) const final override
internal function that returns the tuple of requested type, and has the global index cid
Definition: TetMesh.cpp:224
Tuple switch_edge(const Tuple &tuple) const
Definition: TetMesh.hpp:117
int64_t id_face(const Tuple &tuple) const
Definition: TetMesh.hpp:72
bool is_boundary_vertex(const Tuple &tuple) const
Definition: TetMesh.cpp:386
std::unique_ptr< attribute::Accessor< int64_t, TetMesh > > m_et_accessor
Definition: TetMesh.hpp:98
void make_cached_accessors()
Definition: TetMesh.cpp:66
std::vector< std::vector< TypedAttributeHandle< int64_t > > > connectivity_attributes() const final override
Returns a vector of vectors of attribute handles.
Definition: TetMesh.cpp:567
std::unique_ptr< attribute::Accessor< int64_t, TetMesh > > m_tt_accessor
Definition: TetMesh.hpp:104
Tuple switch_tuple(const Tuple &tuple, PrimitiveType type) const final override
switch the orientation of the Tuple of the given dimension
Definition: TetMesh.cpp:250
Tuple tuple_from_global_ids(int64_t tid, int64_t fid, int64_t eid, int64_t vid) const
Definition: TetMesh.cpp:583
bool is_boundary(const simplex::Simplex &tuple) const
check if a simplex lies on a boundary or not
Definition: Mesh.cpp:107
TypedAttributeHandle< int64_t > m_tv_handle
Definition: TetMesh.hpp:92
bool is_boundary_edge(const Tuple &tuple) const
Definition: TetMesh.cpp:374
Tuple edge_tuple_from_id(int64_t id) const
Definition: TetMesh.cpp:173
Tuple switch_face(const Tuple &tuple) const
Definition: TetMesh.hpp:121
Tuple face_tuple_from_id(int64_t id) const
Definition: TetMesh.cpp:191
void initialize_free(int64_t count)
Definition: TetMesh.cpp:148
Tuple switch_vertex(const Tuple &tuple) const
Definition: TetMesh.hpp:113
Tuple tet_tuple_from_id(int64_t id) const
Definition: TetMesh.cpp:212
std::unique_ptr< attribute::Accessor< int64_t, TetMesh > > m_tf_accessor
Definition: TetMesh.hpp:103
TypedAttributeHandle< int64_t > m_tf_handle
Definition: TetMesh.hpp:94
bool is_ccw(const Tuple &tuple) const final override
TODO this needs dimension?
Definition: TetMesh.cpp:314
int64_t id_tet(const Tuple &tuple) const
Definition: TetMesh.hpp:73
Tuple vertex_tuple_from_id(int64_t id) const
Definition: TetMesh.cpp:155
int64_t id_vertex(const Tuple &tuple) const
Definition: TetMesh.hpp:70
int64_t id_edge(const Tuple &tuple) const
Definition: TetMesh.hpp:71
void initialize(Eigen::Ref< const RowVectors4l > TV, Eigen::Ref< const RowVectors6l > TE, Eigen::Ref< const RowVectors4l > TF, Eigen::Ref< const RowVectors4l > TT, Eigen::Ref< const VectorXl > VT, Eigen::Ref< const VectorXl > ET, Eigen::Ref< const VectorXl > FT)
Definition: TetMesh.cpp:79
Tuple switch_tetrahedron(const Tuple &tuple) const
Definition: TetMesh.hpp:125
TypedAttributeHandle< int64_t > m_te_handle
Definition: TetMesh.hpp:93
bool is_connectivity_valid() const final override
Definition: TetMesh.cpp:400
TypedAttributeHandle< int64_t > m_et_handle
Definition: TetMesh.hpp:89
std::unique_ptr< attribute::Accessor< int64_t, TetMesh > > m_ft_accessor
Definition: TetMesh.hpp:99
TypedAttributeHandle< int64_t > m_ft_handle
Definition: TetMesh.hpp:90
~TetMesh() override
std::unique_ptr< attribute::Accessor< int64_t, TetMesh > > m_vt_accessor
Definition: TetMesh.hpp:97
std::unique_ptr< attribute::Accessor< int64_t, TetMesh > > m_te_accessor
Definition: TetMesh.hpp:102
bool is_valid(const Tuple &tuple) const final override
check validity of tuple including its hash
Definition: TetMesh.cpp:320
bool is_boundary_face(const Tuple &tuple) const
Definition: TetMesh.cpp:368
std::vector< Tuple > orient_vertices(const Tuple &t) const override
Definition: TetMesh.cpp:614
int8_t m_local_vid
Definition: Tuple.hpp:47
int8_t m_local_eid
Definition: Tuple.hpp:48
int64_t m_global_cid
Definition: Tuple.hpp:46
int8_t m_local_fid
Definition: Tuple.hpp:49
A CachingAccessor that uses tuples for accessing attributes instead of indices.
Definition: Accessor.hpp:25
Handle that represents attributes for some mesh.
Definition: autodiff.h:995
Definition: Accessor.hpp:6