Skip to content

Commit 04f1459

Browse files
authored
Merge pull request #480 from wildmeshing/dzint/478-add-simplexverticesconst-simplex-s
add `simplex::vertices()`
2 parents 70d6c0f + b240cb4 commit 04f1459

File tree

9 files changed

+496
-39
lines changed

9 files changed

+496
-39
lines changed

src/wmtk/invariants/MinIncidentValenceInvariant.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include "MinIncidentValenceInvariant.hpp"
22

33
#include <wmtk/Mesh.hpp>
4+
#include <wmtk/simplex/faces_single_dimension.hpp>
45
#include <wmtk/simplex/link.hpp>
56

67
namespace wmtk::invariants {
@@ -33,8 +34,11 @@ bool MinIncidentValenceInvariant::is_greater_min_valence(const Tuple& t) const
3334
{
3435
using namespace simplex;
3536

36-
const Simplex v0 = Simplex::vertex(t);
37-
const Simplex v1 = Simplex::vertex(mesh().switch_vertex(t));
37+
const std::vector<Tuple> vs =
38+
faces_single_dimension(mesh(), Simplex::face(t), PrimitiveType::Vertex);
39+
40+
const Simplex v0 = Simplex::vertex(vs[0]);
41+
const Simplex v1 = Simplex::vertex(vs[1]);
3842
const long val0 =
3943
static_cast<long>(link(mesh(), v0).simplex_vector(PrimitiveType::Vertex).size());
4044
const long val1 =

src/wmtk/operations/tri_mesh/EdgeSwapValence.cpp

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include "EdgeSwapValence.hpp"
22
#include <wmtk/SimplicialComplex.hpp>
33
#include <wmtk/TriMesh.hpp>
4+
#include <wmtk/simplex/faces_single_dimension.hpp>
45
#include "EdgeCollapse.hpp"
56
#include "EdgeSplit.hpp"
67
namespace wmtk::operations::tri_mesh {
@@ -19,10 +20,16 @@ std::string EdgeSwapValence::name() const
1920

2021
bool EdgeSwapValence::execute()
2122
{
22-
const Tuple v0 = input_tuple();
23-
const Tuple v1 = mesh().switch_vertex(input_tuple());
24-
const Tuple v2 = mesh().switch_vertex(mesh().switch_edge(input_tuple()));
25-
const Tuple v3 = mesh().switch_vertex(mesh().switch_edge(mesh().switch_face(input_tuple())));
23+
const simplex::Simplex f0 = simplex::Simplex::face(input_tuple());
24+
const simplex::Simplex f1 = simplex::Simplex::face(mesh().switch_face(input_tuple()));
25+
const std::vector<Tuple> vertices_t0 =
26+
simplex::faces_single_dimension(mesh(), f0, PrimitiveType::Vertex);
27+
const std::vector<Tuple> vertices_t1 =
28+
simplex::faces_single_dimension(mesh(), f1, PrimitiveType::Vertex);
29+
const Tuple v0 = vertices_t0[0];
30+
const Tuple v1 = vertices_t0[1];
31+
const Tuple v2 = vertices_t0[2];
32+
const Tuple v3 = vertices_t1[2];
2633
long val0 = static_cast<long>(SimplicialComplex::vertex_one_ring(mesh(), v0).size());
2734
long val1 = static_cast<long>(SimplicialComplex::vertex_one_ring(mesh(), v1).size());
2835
long val2 = static_cast<long>(SimplicialComplex::vertex_one_ring(mesh(), v2).size());

src/wmtk/simplex/CMakeLists.txt

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,8 @@ set(SRC_FILES
1111
top_dimension_cofaces.cpp
1212
top_dimension_cofaces_iterable.hpp
1313
top_dimension_cofaces_iterable.cpp
14-
1514
cofaces_single_dimension.hpp
1615
cofaces_single_dimension.cpp
17-
1816
link.hpp
1917
link.cpp
2018
link_iterable.hpp
@@ -23,17 +21,16 @@ set(SRC_FILES
2321
open_star.cpp
2422
open_star_iterable.hpp
2523
open_star_iterable.cpp
26-
27-
2824
faces.hpp
2925
faces.cpp
3026
faces_iterable.hpp
3127
faces_iterable.cpp
3228
internal/SimplexEqualFunctor.hpp
3329
internal/SimplexLessFunctor.hpp
34-
3530
boundary.hpp
3631
boundary.cpp
32+
faces_single_dimension.hpp
33+
faces_single_dimension.cpp
3734
)
3835
target_sources(wildmeshing_toolkit PRIVATE ${SRC_FILES})
3936
add_subdirectory(utils)

src/wmtk/simplex/boundary.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
#include "SimplexCollection.hpp"
33

44
namespace wmtk::simplex {
5-
// returns all simplices that lie on the boundary of the input simplex (i.e all cofaces)
6-
// This does not include itself
75
SimplexCollection boundary(const Mesh& mesh, const Simplex& simplex, const bool sort_and_clean)
86
{
97
SimplexCollection collection(mesh);
@@ -21,13 +19,13 @@ SimplexCollection boundary(const Mesh& mesh, const Simplex& simplex, const bool
2119
break;
2220
}
2321
case PrimitiveType::Edge: {
24-
for (const auto& s : {Simplex::vertex(t), Simplex::vertex(m.switch_vertex(t))}) {
22+
for (const Simplex& s : {Simplex::vertex(t), Simplex::vertex(m.switch_vertex(t))}) {
2523
collection.add(s);
2624
}
2725
break;
2826
}
2927
case PrimitiveType::Face: {
30-
for (const auto& s :
28+
for (const Simplex& s :
3129
{Simplex::edge(t), //
3230
Simplex::edge(m.switch_tuples(t, {PE})),
3331
Simplex::edge(m.switch_tuples(t, {PV, PE}))}) {
@@ -36,7 +34,7 @@ SimplexCollection boundary(const Mesh& mesh, const Simplex& simplex, const bool
3634
break;
3735
}
3836
case PrimitiveType::Tetrahedron: {
39-
for (const auto& s :
37+
for (const Simplex& s :
4038
{Simplex::face(t), //
4139
Simplex::face(m.switch_tuples(t, {PF})), //
4240
Simplex::face(m.switch_tuples(t, {PE, PF})), //

src/wmtk/simplex/boundary.hpp

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,23 @@
33
#include "SimplexCollection.hpp"
44

55
namespace wmtk::simplex {
6-
// returns all of the boundary simplices of a simplex (i.e k-1 simplices that bound a k-simplex)
7-
// This does not include itself
6+
/**
7+
* @brief Returns all boundary simplices of a simplex.
8+
*
9+
* The boundary simplices are the k-1 simplices that bound the given k-simplex.
10+
* This does not include the given simplex itself!
11+
*
12+
* - tetrahedron: 4 faces
13+
* - face: 3 edges
14+
* - edge: 2 vertices
15+
* - vertex: nothing
16+
*
17+
* @param mesh The mesh containing the simplex
18+
* @param simplex The simplex
19+
* @param sort_and_clean Call `SimplexCollection::sort_and_clean` before returning
20+
*
21+
* @return `SimplexCollection` holding the boundary
22+
*/
823
SimplexCollection
924
boundary(const Mesh& mesh, const Simplex& simplex, const bool sort_and_clean = true);
1025
} // namespace wmtk::simplex

src/wmtk/simplex/faces.hpp

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,22 @@
33
#include "SimplexCollection.hpp"
44

55
namespace wmtk::simplex {
6-
// returns all simplices that lie on the boundary of the input simplex (i.e all cofaces)
7-
// This does not include itself
6+
/**
7+
* @brief Returns all faces of a simplex.
8+
*
9+
* The faces are all lower dimensional simplices that bound the given k-simplex.
10+
* This does not include the given simplex itself!
11+
*
12+
* - tetrahedron: 4 faces, 6 edges, 4 vertices
13+
* - face: 3 edges, 3 vertices
14+
* - edge: 2 vertices
15+
* - vertex: nothing
16+
*
17+
* @param mesh The mesh containing the simplex
18+
* @param simplex The simplex
19+
* @param sort_and_clean Call `SimplexCollection::sort_and_clean` before returning
20+
*
21+
* @return `SimplexCollection` holding the faces
22+
*/
823
SimplexCollection faces(const Mesh& mesh, const Simplex& simplex, const bool sort_and_clean = true);
924
} // namespace wmtk::simplex
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
#include "faces_single_dimension.hpp"
2+
3+
namespace wmtk::simplex {
4+
std::vector<Tuple> vertices(const Mesh& m, const Simplex& simplex)
5+
{
6+
if (simplex.primitive_type() == PrimitiveType::Vertex) {
7+
return {};
8+
}
9+
10+
const Tuple v0 = simplex.tuple();
11+
const Tuple v1 = m.switch_edge(m.switch_vertex(v0));
12+
13+
if (simplex.primitive_type() == PrimitiveType::Edge) {
14+
return {v0, v1};
15+
}
16+
17+
const Tuple v2 = m.switch_vertex(m.switch_edge(v0));
18+
19+
if (simplex.primitive_type() == PrimitiveType::Face) {
20+
return {v0, v1, v2};
21+
}
22+
23+
const Tuple v3 = m.switch_vertex(m.switch_edge(m.switch_face(v0)));
24+
25+
if (simplex.primitive_type() == PrimitiveType::Tetrahedron) {
26+
return {v0, v1, v2, v3};
27+
}
28+
29+
throw std::runtime_error("unknown primitive type");
30+
}
31+
32+
std::vector<Tuple> edges(const Mesh& m, const Simplex& simplex)
33+
{
34+
if (simplex.primitive_type() == PrimitiveType::Vertex ||
35+
simplex.primitive_type() == PrimitiveType::Edge) {
36+
return {};
37+
}
38+
39+
const Tuple e0 = simplex.tuple();
40+
const Tuple e1 = m.switch_edge(m.switch_vertex(e0));
41+
const Tuple e2 = m.switch_vertex(m.switch_edge(e0));
42+
43+
if (simplex.primitive_type() == PrimitiveType::Face) {
44+
return {e0, e1, e2};
45+
}
46+
47+
const Tuple e3 = m.switch_edge(m.switch_face(e0));
48+
const Tuple e4 = m.switch_edge(m.switch_face(e1));
49+
const Tuple e5 = m.switch_edge(m.switch_face(e2));
50+
51+
if (simplex.primitive_type() == PrimitiveType::Tetrahedron) {
52+
return {e0, e1, e2, e3, e4, e5};
53+
}
54+
55+
throw std::runtime_error("unknown primitive type");
56+
}
57+
58+
std::vector<Tuple> faces(const Mesh& m, const Simplex& simplex)
59+
{
60+
if (simplex.primitive_type() == PrimitiveType::Vertex ||
61+
simplex.primitive_type() == PrimitiveType::Edge ||
62+
simplex.primitive_type() == PrimitiveType::Face) {
63+
return {};
64+
}
65+
66+
const Tuple f0 = simplex.tuple();
67+
const Tuple f1 = m.switch_edge(m.switch_face(f0));
68+
const Tuple f2 = m.switch_edge(m.switch_face(m.switch_edge(m.switch_vertex(f0))));
69+
const Tuple f3 = m.switch_edge(m.switch_face(m.switch_vertex(m.switch_edge(f0))));
70+
71+
if (simplex.primitive_type() == PrimitiveType::Tetrahedron) {
72+
return {f0, f1, f2, f3};
73+
}
74+
75+
throw std::runtime_error("unknown primitive type");
76+
}
77+
78+
std::vector<Tuple>
79+
faces_single_dimension(const Mesh& mesh, const Simplex& simplex, const PrimitiveType face_type)
80+
{
81+
switch (face_type) {
82+
case PrimitiveType::Vertex: return vertices(mesh, simplex);
83+
case PrimitiveType::Edge: return edges(mesh, simplex);
84+
case PrimitiveType::Face: return faces(mesh, simplex);
85+
case PrimitiveType::Tetrahedron: return {};
86+
default: throw std::runtime_error("unknown primitive type"); break;
87+
}
88+
}
89+
} // namespace wmtk::simplex
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
#pragma once
2+
3+
#include <wmtk/Primitive.hpp>
4+
5+
#include "SimplexCollection.hpp"
6+
7+
namespace wmtk::simplex {
8+
/**
9+
* @brief Returns a vector with all faces in the boundary of a simplex of the given dimension.
10+
*
11+
* Assuming the following tetrahedron:
12+
*
13+
* 0
14+
* / \\ .
15+
* / \ \ .
16+
* / \ \ .
17+
* / \ \ .
18+
* / \ 3
19+
* / \ /
20+
* / \ /
21+
* 1 ------------- 2
22+
*
23+
*
24+
* Given the tuple representing v(0), e(0,1), f(0,1,2), t(0,1,2,3) we have the following faces:
25+
*
26+
* Tetrahedron:
27+
*
28+
* PrimitiveType::Face
29+
* {
30+
* f(0,1,2),
31+
* f(0,3,1),
32+
* f(1,3,2),
33+
* f(2,3,0)
34+
* }
35+
*
36+
* PrimitiveType::Edge
37+
* {
38+
* e(0,1),
39+
* e(1,2),
40+
* e(2,0),
41+
* e(0,3),
42+
* e(1,3),
43+
* e(2,3)
44+
* }
45+
*
46+
* PrimitiveType::Vertex
47+
* {v(0),v(1),v(2),v(3)}
48+
*
49+
* Triangle:
50+
*
51+
* PrimitiveType::Edge
52+
* {
53+
* e(0,1),
54+
* e(1,2),
55+
* e(2,0)
56+
* }
57+
*
58+
* PrimitiveType::Vertex
59+
* {v(0),v(1),v(2)}
60+
*
61+
* Edge:
62+
*
63+
* PrimitiveType::Vertex
64+
* {v(0),v(1)}
65+
*
66+
* The order is relative to the orientation of the input tuple and guaranteed to be always the same
67+
* (i.e. it is independent of the internal indices).
68+
*
69+
*
70+
* @param mesh The mesh containing the simplex
71+
* @param simplex The simplex
72+
* @param face_type The requested face type
73+
*
74+
* @return A vector of vertices sorted according to the tuple orientation of the simplex
75+
*/
76+
std::vector<Tuple>
77+
faces_single_dimension(const Mesh& mesh, const Simplex& simplex, const PrimitiveType face_type);
78+
} // namespace wmtk::simplex

0 commit comments

Comments
 (0)