Skip to content

Commit

Permalink
minor fixes for release
Browse files Browse the repository at this point in the history
  • Loading branch information
teseoch committed Oct 18, 2023
1 parent 2cccc3a commit 2ac4dee
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 53 deletions.
5 changes: 4 additions & 1 deletion src/wmtk/TriMesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,10 @@ Tuple TriMesh::switch_tuple(const Tuple& tuple, PrimitiveType type) const
}
case PrimitiveType::Vertex:
case PrimitiveType::Edge: return autogen::tri_mesh::local_switch_tuple(tuple, type);
case PrimitiveType::Tetrahedron: assert(false);
case PrimitiveType::Tetrahedron: {
assert(false);
return autogen::tri_mesh::local_switch_tuple(tuple, type);
}
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/wmtk/attribute/AttributeCacheData.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@

namespace wmtk {
template <typename T>
struct AttributeCacheData
class AttributeCacheData
{
public:
using Vector = Eigen::Matrix<T, Eigen::Dynamic, 1>;
template <typename Derived>
AttributeCacheData(const Eigen::MatrixBase<Derived>& a, bool d = false)
Expand Down
2 changes: 1 addition & 1 deletion src/wmtk/operations/tri_mesh/EdgeCollapse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ EdgeCollapse::EdgeCollapse(
const OperationSettings<EdgeCollapse>& settings)
: TriMeshOperation(m)
, TupleOperation(settings.invariants, t)
, m_settings{settings}
// , m_settings(settings)
{
assert(m_settings.are_invariants_initialized());
}
Expand Down
2 changes: 1 addition & 1 deletion src/wmtk/operations/tri_mesh/EdgeCollapse.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class EdgeCollapse : public TriMeshOperation, private TupleOperation

private:
Tuple m_output_tuple;
const OperationSettings<EdgeCollapse>& m_settings;
// const OperationSettings<EdgeCollapse>& m_settings;
};

} // namespace tri_mesh
Expand Down
86 changes: 37 additions & 49 deletions tests/test_example_meshes.cpp
Original file line number Diff line number Diff line change
@@ -1,30 +1,31 @@

#include <spdlog/spdlog.h>
#include <array>
#include <catch2/catch_test_macros.hpp>
#include <wmtk/utils/Logger.hpp>
#include "tools/DEBUG_TriMesh.hpp"
#include "tools/TriMesh_examples.hpp"
#include <wmtk/utils/Logger.hpp>
#include <array>

using namespace wmtk;
using namespace wmtk::tests;
namespace {
struct MeshDebugInfo
{
std::string name = "RENAME ME";
long boundary_curves = -1;// number of distinct boundary curves in the mesh
long genus = -1;// TODO (also what definition of genus?)
long simply_connected_components = -1;// TODO (face-face connected topologies)
bool is_oriented = false;// TODO (make sure nface neighbors use opposite orientation
long boundary_curves = -1; // number of distinct boundary curves in the mesh
long genus = -1; // TODO (also what definition of genus?)
long simply_connected_components = -1; // TODO (face-face connected topologies)
bool is_oriented = false; // TODO (make sure nface neighbors use opposite orientation
// the number of simplices (vertex, edge, then face)
std::array<long, 3> simplex_counts = std::array<long,3>{{-1,-1,-1}};
std::array<long, 3> simplex_counts = std::array<long, 3>{{-1, -1, -1}};
};

std::array<long, 3> trimesh_simplex_counts(const TriMesh& m)
{
return std::array<long, 3>{{long(m.get_all(PrimitiveType::Vertex).size()),
long(m.get_all(PrimitiveType::Edge).size()),
long(m.get_all(PrimitiveType::Face).size())}};
return std::array<long, 3>{
{long(m.get_all(PrimitiveType::Vertex).size()),
long(m.get_all(PrimitiveType::Edge).size()),
long(m.get_all(PrimitiveType::Face).size())}};
}


Expand All @@ -33,9 +34,9 @@ std::array<long, 3> trimesh_simplex_counts(const TriMesh& m)
* @param m the mesh
* @param component_ids output the component id of each face
* @return the number of simply connected components
*/
*/

int trimesh_simply_connected_components(const DEBUG_TriMesh& m, std::vector<int> &component_ids)
int trimesh_simply_connected_components(const DEBUG_TriMesh& m, std::vector<int>& component_ids)
{
component_ids.resize(m.capacity(PrimitiveType::Face), -1);
const auto all_face_tuples = m.get_all(PrimitiveType::Face);
Expand All @@ -56,20 +57,18 @@ int trimesh_simply_connected_components(const DEBUG_TriMesh& m, std::vector<int>
component_ids[cur_fid] = component_id;
auto f_tuple = m.tuple_from_face_id(cur_fid);
// push all adjacent faces
for (int j = 0; j < 3; ++j)
{
if (!m.is_boundary(f_tuple))
{
for (int j = 0; j < 3; ++j) {
if (!m.is_boundary(f_tuple)) {
auto adj_face_tuple = m.switch_tuple(f_tuple, PrimitiveType::Face);
long adj_fid = m.id(adj_face_tuple, PrimitiveType::Face);
if (component_ids[adj_fid] == -1) {
q.push(adj_fid);
}
}
}
f_tuple = m.switch_edge(m.switch_vertex(f_tuple));
}
}
}

component_id++;
}

Expand All @@ -87,8 +86,7 @@ int trimesh_boundary_loops_count(const DEBUG_TriMesh& m)
std::vector<int> boundary_loop_ids(m.capacity(PrimitiveType::Edge), -1);
const auto all_edge_tuples = m.get_all(PrimitiveType::Edge);
int boundary_loop_id = 0;
for (auto edge_tuple : all_edge_tuples)
{
for (auto edge_tuple : all_edge_tuples) {
if (!m.is_boundary(edge_tuple)) {
continue;
}
Expand All @@ -100,20 +98,18 @@ int trimesh_boundary_loops_count(const DEBUG_TriMesh& m)
Tuple cur_edge = edge_tuple;
long cur_eid = m.id(cur_edge, PrimitiveType::Edge);
// find one boundary loop
while (boundary_loop_ids[eid] == -1 || cur_eid != eid)
{
while (boundary_loop_ids[eid] == -1 || cur_eid != eid) {
boundary_loop_ids[cur_eid] = boundary_loop_id;

// find next boundary edge
cur_edge = m.switch_edge(m.switch_vertex(cur_edge));
while(!m.is_boundary(cur_edge))
{
while (!m.is_boundary(cur_edge)) {
cur_edge = m.switch_edge(m.switch_face(cur_edge));
}

cur_eid = m.id(cur_edge, PrimitiveType::Edge);
}

boundary_loop_id++;
}

Expand All @@ -129,32 +125,29 @@ int trimesh_euler_characteristic(const DEBUG_TriMesh& m)

int trimesh_genus(const DEBUG_TriMesh& m)
{
if (trimesh_simply_connected_components(m) != 1)
{
if (trimesh_simply_connected_components(m) != 1) {
wmtk::logger().error("not a connected surface\n");
throw std::runtime_error("GenusComputeError");
}
return (2 - trimesh_euler_characteristic(m)) / 2;
}



void run_debug_trimesh(const DEBUG_TriMesh& m, const MeshDebugInfo& info)
{
fmt::print("Running run_debug_trimesh on {}\n", info.name);

// validate that the info is ok
REQUIRE(info.boundary_curves >= 0);
REQUIRE(info.simply_connected_components>= 0);
for(const long count: info.simplex_counts) {
REQUIRE(info.simply_connected_components >= 0);
for (const long count : info.simplex_counts) {
REQUIRE(count >= 0);
}

REQUIRE(m.is_connectivity_valid());
if (info.genus >= 0)
{
if (info.genus >= 0) {
CHECK(trimesh_genus(m) == info.genus);
}
}
CHECK(trimesh_simply_connected_components(m) == info.simply_connected_components);
CHECK(trimesh_simplex_counts(m) == info.simplex_counts);
REQUIRE(trimesh_boundary_loops_count(m) == info.boundary_curves);
Expand All @@ -163,30 +156,25 @@ void run_debug_trimesh(const DEBUG_TriMesh& m, const MeshDebugInfo& info)
auto e_tups = m.get_all(PrimitiveType::Edge);
auto f_tups = m.get_all(PrimitiveType::Face);

REQUIRE(v_count == v_tups.size());
REQUIRE(e_count == e_tups.size());
REQUIRE(f_count == f_tups.size());
REQUIRE(v_count == long(v_tups.size()));
REQUIRE(e_count == long(e_tups.size()));
REQUIRE(f_count == long(f_tups.size()));
for (const auto& v_tup : v_tups) {
fmt::print("vertex {} is active\n", m.id( v_tup, PrimitiveType::Vertex));
fmt::print("vertex {} is active\n", m.id(v_tup, PrimitiveType::Vertex));
}
for (const auto& e_tup : e_tups) {
long id = m.id(e_tup, PrimitiveType::Edge);
long a = m.id(e_tup, PrimitiveType::Vertex);
long b = m.id(m.switch_tuple(e_tup, PrimitiveType::Vertex), PrimitiveType::Vertex );
long b = m.id(m.switch_tuple(e_tup, PrimitiveType::Vertex), PrimitiveType::Vertex);
fmt::print("edge {} is active with vertices {} {}\n", id, a, b);
}
for (const auto& f_tup : f_tups) {
long id = m.id(f_tup, PrimitiveType::Face);
long a = m.id(f_tup, PrimitiveType::Vertex);
long b = m.id(m.switch_tuple(f_tup, PrimitiveType::Vertex), PrimitiveType::Vertex );
long b = m.id(m.switch_tuple(f_tup, PrimitiveType::Vertex), PrimitiveType::Vertex);
long c = m.id(
m.switch_tuple(
m.switch_tuple(f_tup, PrimitiveType::Edge
),
PrimitiveType::Vertex
),
PrimitiveType::Vertex
);
m.switch_tuple(m.switch_tuple(f_tup, PrimitiveType::Edge), PrimitiveType::Vertex),
PrimitiveType::Vertex);
fmt::print("face {} is active with vertices {} {} {}\n", id, a, b, c);
}
}
Expand Down Expand Up @@ -250,7 +238,7 @@ TEST_CASE("test_debug_trimeshes_three_individuals")
MeshDebugInfo info;
info.name = "three_individuals";
info.genus = -1; // not applicable here
info.boundary_curves = 3;// each triangle is individual
info.boundary_curves = 3; // each triangle is individual
info.simply_connected_components = 3;
info.simplex_counts = std::array<long, 3>{{6, 9, 3}};
run_debug_trimesh(m, info);
Expand Down

0 comments on commit 2ac4dee

Please sign in to comment.