Wildmeshing Toolkit
TriMesh.hpp
Go to the documentation of this file.
1 #pragma once
2 
5 #include "MeshCRTP.hpp"
6 #include "Tuple.hpp"
7 
8 #include <Eigen/Core>
9 
10 namespace wmtk {
11 namespace operations::utils {
12 class MultiMeshEdgeSplitFunctor;
13 class MultiMeshEdgeCollapseFunctor;
14 class UpdateEdgeOperationMultiMeshMapFunctor;
15 } // namespace operations::utils
16 
17 
18 class TriMesh : public MeshCRTP<TriMesh>
19 {
20 public:
21  friend class MeshCRTP<TriMesh>;
25  template <typename U, typename MeshType, int Dim>
26  friend class attribute::Accessor;
29  TriMesh();
30  TriMesh(const TriMesh& o) = delete;
31  TriMesh& operator=(const TriMesh& o) = delete;
32  TriMesh(TriMesh&& o);
34  ~TriMesh() override;
35  void make_cached_accessors();
36 
37 
38  Tuple switch_tuple(const Tuple& tuple, PrimitiveType type) const final override; // CRTP
39  // override
40 
41 
42  bool is_ccw(const Tuple& tuple) const final override; // CRTP override
43  using Mesh::is_boundary;
44  bool is_boundary(PrimitiveType pt, const Tuple& tuple) const final override; // CRTP override
45  bool is_boundary_vertex(const Tuple& tuple) const;
46  bool is_boundary_edge(const Tuple& tuple) const;
47 
48  void initialize(
49  Eigen::Ref<const RowVectors3l> FV,
50  Eigen::Ref<const RowVectors3l> FE,
51  Eigen::Ref<const RowVectors3l> FF,
52  Eigen::Ref<const VectorXl> VF,
53  Eigen::Ref<const VectorXl> EF);
54  void initialize(Eigen::Ref<const RowVectors3l> F, bool make_free = false);
55  void initialize_free(int64_t count);
56 
57  bool is_valid(const Tuple& tuple) const final override;
58 
59  bool is_connectivity_valid() const final override;
60 
61  std::vector<std::vector<TypedAttributeHandle<int64_t>>> connectivity_attributes()
62  const override;
63 
64  Tuple switch_vertex(const Tuple& tuple) const;
65  Tuple switch_edge(const Tuple& tuple) const;
66  Tuple switch_face(const Tuple& tuple) const;
67 
68  std::vector<Tuple> orient_vertices(const Tuple& t) const override;
69 
70 protected:
71  int64_t id(const Tuple& tuple, PrimitiveType type) const;
72  using MeshCRTP<TriMesh>::id; // getting the (simplex) prototype
73 
74  int64_t id_vertex(const Tuple& tuple) const { return id(tuple, PrimitiveType::Vertex); }
75  int64_t id_edge(const Tuple& tuple) const { return id(tuple, PrimitiveType::Edge); }
76  int64_t id_face(const Tuple& tuple) const { return id(tuple, PrimitiveType::Triangle); }
77 
85  Tuple tuple_from_id(const PrimitiveType type, const int64_t gid)
86  const final override; // CRTP override
87  Tuple tuple_from_global_ids(int64_t fid, int64_t eid, int64_t vid) const;
88 
89 protected:
92 
96 
97  std::unique_ptr<attribute::Accessor<int64_t, TriMesh>> m_vf_accessor = nullptr;
98  std::unique_ptr<attribute::Accessor<int64_t, TriMesh>> m_ef_accessor = nullptr;
99  std::unique_ptr<attribute::Accessor<int64_t, TriMesh>> m_fv_accessor = nullptr;
100  std::unique_ptr<attribute::Accessor<int64_t, TriMesh>> m_fe_accessor = nullptr;
101  std::unique_ptr<attribute::Accessor<int64_t, TriMesh>> m_ff_accessor = nullptr;
102 
103 
104  Tuple vertex_tuple_from_id(int64_t id) const;
105  Tuple edge_tuple_from_id(int64_t id) const;
106  Tuple face_tuple_from_id(int64_t id) const;
107 
108 
110  static Tuple with_different_cid(const Tuple& t, int64_t cid);
111 };
112 
113 inline Tuple TriMesh::switch_vertex(const Tuple& tuple) const
114 {
115  return switch_tuple(tuple, PrimitiveType::Vertex);
116 }
117 inline Tuple TriMesh::switch_edge(const Tuple& tuple) const
118 {
119  return switch_tuple(tuple, PrimitiveType::Edge);
120 }
121 inline Tuple TriMesh::switch_face(const Tuple& tuple) const
122 {
123  return switch_tuple(tuple, PrimitiveType::Triangle);
124 }
125 inline int64_t TriMesh::id(const Tuple& tuple, PrimitiveType type) const
126 {
127  switch (type) {
128  case PrimitiveType::Vertex: {
129  assert(Mesh::is_valid(tuple));
130  int64_t v = m_fv_accessor->const_topological_scalar_attribute(tuple, PrimitiveType::Vertex);
131  return v;
132  }
133  case PrimitiveType::Edge: {
134  assert(Mesh::is_valid(tuple));
135  int64_t v = m_fe_accessor->const_topological_scalar_attribute(tuple, PrimitiveType::Edge);
136  return v;
137  }
139  return tuple.m_global_cid;
140  }
141  case PrimitiveType::Tetrahedron: [[fallthrough]];
142  default: assert(false); // "Tuple id: Invalid primitive type"
143  }
144 
145  return -1;
146 }
147 } // 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:1020
bool is_boundary(const simplex::Simplex &tuple) const
check if a simplex lies on a boundary or not
Definition: Mesh.cpp:106
virtual bool is_valid(const Tuple &tuple) const
check validity of tuple including its hash
Definition: Mesh.cpp:112
std::vector< std::vector< TypedAttributeHandle< int64_t > > > connectivity_attributes() const override
Returns a vector of vectors of attribute handles.
Definition: TriMesh.cpp:525
Tuple switch_face(const Tuple &tuple) const
Definition: TriMesh.hpp:121
Tuple face_tuple_from_id(int64_t id) const
Definition: TriMesh.cpp:328
Tuple switch_tuple(const Tuple &tuple, PrimitiveType type) const final override
switch the orientation of the Tuple of the given dimension
Definition: TriMesh.cpp:98
int64_t id_face(const Tuple &tuple) const
Definition: TriMesh.hpp:76
bool is_boundary_vertex(const Tuple &tuple) const
Definition: TriMesh.cpp:77
attribute::TypedAttributeHandle< int64_t > m_vf_handle
Definition: TriMesh.hpp:90
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: TriMesh.cpp:267
TriMesh & operator=(const TriMesh &o)=delete
std::unique_ptr< attribute::Accessor< int64_t, TriMesh > > m_ef_accessor
Definition: TriMesh.hpp:98
int64_t id_vertex(const Tuple &tuple) const
Definition: TriMesh.hpp:74
bool is_boundary(const simplex::Simplex &tuple) const
check if a simplex lies on a boundary or not
Definition: Mesh.cpp:106
bool is_valid(const Tuple &tuple) const final override
check validity of tuple including its hash
Definition: TriMesh.cpp:340
Tuple vertex_tuple_from_id(int64_t id) const
Definition: TriMesh.cpp:288
bool is_connectivity_valid() const final override
Definition: TriMesh.cpp:370
Tuple tuple_from_global_ids(int64_t fid, int64_t eid, int64_t vid) const
Definition: TriMesh.cpp:244
void make_cached_accessors()
Definition: TriMesh.cpp:23
std::unique_ptr< attribute::Accessor< int64_t, TriMesh > > m_fe_accessor
Definition: TriMesh.hpp:100
std::unique_ptr< attribute::Accessor< int64_t, TriMesh > > m_fv_accessor
Definition: TriMesh.hpp:99
int64_t id_edge(const Tuple &tuple) const
Definition: TriMesh.hpp:75
void initialize_free(int64_t count)
Definition: TriMesh.cpp:235
Tuple switch_edge(const Tuple &tuple) const
Definition: TriMesh.hpp:117
static Tuple with_different_cid(const Tuple &t, int64_t cid)
Definition: TriMesh.cpp:518
void initialize(Eigen::Ref< const RowVectors3l > FV, Eigen::Ref< const RowVectors3l > FE, Eigen::Ref< const RowVectors3l > FF, Eigen::Ref< const VectorXl > VF, Eigen::Ref< const VectorXl > EF)
Definition: TriMesh.cpp:175
attribute::TypedAttributeHandle< int64_t > m_ff_handle
Definition: TriMesh.hpp:95
attribute::TypedAttributeHandle< int64_t > m_ef_handle
Definition: TriMesh.hpp:91
std::unique_ptr< attribute::Accessor< int64_t, TriMesh > > m_ff_accessor
Definition: TriMesh.hpp:101
bool is_boundary_edge(const Tuple &tuple) const
Definition: TriMesh.cpp:71
bool is_ccw(const Tuple &tuple) const final override
TODO this needs dimension?
Definition: TriMesh.cpp:169
attribute::TypedAttributeHandle< int64_t > m_fv_handle
Definition: TriMesh.hpp:93
Tuple switch_vertex(const Tuple &tuple) const
Definition: TriMesh.hpp:113
TriMesh(const TriMesh &o)=delete
Tuple edge_tuple_from_id(int64_t id) const
Definition: TriMesh.cpp:307
std::vector< Tuple > orient_vertices(const Tuple &t) const override
Definition: TriMesh.cpp:540
std::unique_ptr< attribute::Accessor< int64_t, TriMesh > > m_vf_accessor
Definition: TriMesh.hpp:97
attribute::TypedAttributeHandle< int64_t > m_fe_handle
Definition: TriMesh.hpp:94
~TriMesh() override
int64_t m_global_cid
Definition: Tuple.hpp:46
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