Skip to content

Commit

Permalink
Merge branch '466-add-local_switch_tuple-for-edgemesh' of https://git…
Browse files Browse the repository at this point in the history
…hub.com/wildmeshing/wildmeshing-toolkit into 434-edgemesh-to-trimesh-multimesh-register
  • Loading branch information
zlyfunction committed Oct 19, 2023
2 parents 4765f0b + c060f20 commit bf90519
Show file tree
Hide file tree
Showing 9 changed files with 98 additions and 11 deletions.
6 changes: 5 additions & 1 deletion src/wmtk/autogen/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,14 @@ set(SRC_FILES
tri_mesh/local_id_table_offset.cpp
tri_mesh/local_id_table_offset.hpp

edge_mesh/local_switch_tuple.hpp
edge_mesh/local_switch_tuple.cpp
edge_mesh/is_ccw.hpp
edge_mesh/is_ccw.cpp

is_ccw.hpp
is_ccw.cpp
local_switch_tuple.hpp
local_switch_tuple.cpp

)
target_sources(wildmeshing_toolkit PRIVATE ${SRC_FILES})
17 changes: 17 additions & 0 deletions src/wmtk/autogen/edge_mesh/is_ccw.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@

#include "is_ccw.hpp"
#include <cassert>
#include <wmtk/utils/TupleInspector.hpp>

namespace wmtk::autogen::edge_mesh {
bool is_ccw(const Tuple& tuple)
{
assert(tuple_is_valid_for_ccw(tuple));
using namespace utils;
return TupleInspector::local_vid(tuple) == 0;
}
bool tuple_is_valid_for_ccw(const Tuple& tuple)
{
return true;
}
} // namespace wmtk::autogen::edge_mesh
8 changes: 8 additions & 0 deletions src/wmtk/autogen/edge_mesh/is_ccw.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#pragma once
#include <wmtk/Tuple.hpp>

namespace wmtk::autogen::edge_mesh {
bool is_ccw(const Tuple& t);
// validates whether the tuple local ids are valid for computing ccw'ness
bool tuple_is_valid_for_ccw(const Tuple& t);
} // namespace wmtk::autogen::edge_mesh
27 changes: 27 additions & 0 deletions src/wmtk/autogen/edge_mesh/local_switch_tuple.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#include "local_switch_tuple.hpp"
#include <stdexcept>
#include <wmtk/utils/TupleInspector.hpp>

namespace wmtk::autogen::edge_mesh {
Tuple local_switch_tuple(const Tuple& tuple, PrimitiveType pt)
{
using namespace utils;
const long global_cid = TupleInspector::global_cid(tuple);
const long hash = TupleInspector::hash(tuple);
switch (pt) {
case PrimitiveType::Vertex:
return Tuple(
1 - TupleInspector::local_vid(tuple),
TupleInspector::local_eid(tuple),
TupleInspector::local_fid(tuple),
global_cid,
hash);

case PrimitiveType::Edge:
case PrimitiveType::Face:
case PrimitiveType::Tetrahedron:
default: throw std::runtime_error("Tuple switch: Invalid primitive type"); break;
}
return Tuple();
}
} // namespace wmtk::autogen::edge_mesh
7 changes: 7 additions & 0 deletions src/wmtk/autogen/edge_mesh/local_switch_tuple.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#pragma once
#include <wmtk/Primitive.hpp>
#include <wmtk/Tuple.hpp>

namespace wmtk::autogen::edge_mesh {
Tuple local_switch_tuple(const Tuple& t, PrimitiveType pt);
}
6 changes: 4 additions & 2 deletions src/wmtk/autogen/is_ccw.cpp
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
#include "is_ccw.hpp"
#include <wmtk/Tuple.hpp>
#include <wmtk/autogen/edge_mesh/is_ccw.hpp>
#include <wmtk/autogen/tet_mesh/is_ccw.hpp>
#include <wmtk/autogen/tri_mesh/is_ccw.hpp>

namespace wmtk::autogen {
bool is_ccw(PrimitiveType pt, const Tuple& t)
{
switch (pt) {
case PrimitiveType::Face: return tri_mesh::is_ccw(t);
case PrimitiveType::Tetrahedron: return tet_mesh::is_ccw(t);
case PrimitiveType::Edge: return edge_mesh::is_ccw(t);
case PrimitiveType::Vertex:
case PrimitiveType::Edge:
default: throw "notimplemented";
}
return false;
Expand All @@ -21,8 +23,8 @@ bool tuple_is_valid_for_ccw(PrimitiveType pt, const Tuple& t)
switch (pt) {
case PrimitiveType::Face: return tri_mesh::tuple_is_valid_for_ccw(t);
case PrimitiveType::Tetrahedron: return tet_mesh::tuple_is_valid_for_ccw(t);
case PrimitiveType::Edge: return edge_mesh::tuple_is_valid_for_ccw(t);
case PrimitiveType::Vertex:
case PrimitiveType::Edge:
default: throw "notimplemented";
}
return false;
Expand Down
5 changes: 3 additions & 2 deletions src/wmtk/autogen/local_switch_tuple.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "local_switch_tuple.hpp"
#include <wmtk/autogen/edge_mesh/local_switch_tuple.hpp>
#include <wmtk/autogen/tet_mesh/local_switch_tuple.hpp>
#include <wmtk/autogen/tri_mesh/local_switch_tuple.hpp>
namespace wmtk::autogen {
Expand All @@ -7,8 +8,8 @@ Tuple local_switch_tuple(PrimitiveType mesh_type, const Tuple& t, PrimitiveType
switch (mesh_type) {
case PrimitiveType::Face: return tri_mesh::local_switch_tuple(t, pt);
case PrimitiveType::Tetrahedron: return tet_mesh::local_switch_tuple(t, pt);
case PrimitiveType::Vertex:
case PrimitiveType::Edge: throw "notimplemented";
case PrimitiveType::Edge: return edge_mesh::local_switch_tuple(t, pt);
case PrimitiveType::Vertex: throw("not implemented");
}
return Tuple();
}
Expand Down
4 changes: 2 additions & 2 deletions src/wmtk/multimesh/utils/local_switch_tuple.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#include "local_switch_tuple.hpp"
#include <wmtk/Tuple.hpp>
#include <wmtk/autogen/edge_mesh/local_switch_tuple.hpp>
#include <wmtk/autogen/tet_mesh/local_switch_tuple.hpp>
#include <wmtk/autogen/tri_mesh/local_switch_tuple.hpp>

namespace wmtk::multimesh::utils {

Tuple local_switch_tuple(
Expand All @@ -14,8 +14,8 @@ Tuple local_switch_tuple(
case PrimitiveType::Face: return autogen::tri_mesh::local_switch_tuple(source, primitive_type);
case PrimitiveType::Tetrahedron:
return autogen::tet_mesh::local_switch_tuple(source, primitive_type);
case PrimitiveType::Edge: return autogen::edge_mesh::local_switch_tuple(source, primitive_type);
case PrimitiveType::Vertex:
case PrimitiveType::Edge:
default: return Tuple();
}
}
Expand Down
29 changes: 25 additions & 4 deletions tests/test_autogen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#include <iostream>
#include <tuple>
#include <wmtk/Tuple.hpp>
#include <wmtk/autogen/edge_mesh/is_ccw.hpp>
#include <wmtk/autogen/edge_mesh/local_switch_tuple.hpp>
#include <wmtk/autogen/is_ccw.hpp>
#include <wmtk/autogen/local_switch_tuple.hpp>
#include <wmtk/autogen/tet_mesh/autogenerated_tables.hpp>
Expand Down Expand Up @@ -42,8 +44,8 @@ long max_tuple_count(PrimitiveType pt)
case PrimitiveType::Face: return long(std::size(wmtk::autogen::tri_mesh::auto_2d_table_ccw));
case PrimitiveType::Tetrahedron:
return long(std::size(wmtk::autogen::tet_mesh::auto_3d_table_ccw));
case PrimitiveType::Vertex:
case PrimitiveType::Edge: break;
case PrimitiveType::Edge: return 2;
case PrimitiveType::Vertex: break;
}
return -1;
}
Expand All @@ -65,8 +67,10 @@ Tuple tuple_from_offset_id(PrimitiveType pt, int offset)
leid = r[1];
lfid = r[2];
} break;
case PrimitiveType::Vertex:
case PrimitiveType::Edge: break;
case PrimitiveType::Edge: {
lvid = offset;
} break;
case PrimitiveType::Vertex: break;
}

Tuple r(lvid, leid, lfid, gcid, hash);
Expand Down Expand Up @@ -183,6 +187,13 @@ TEST_CASE("tuple_autogen_id_inversion", "[tuple]")

TEST_CASE("tuple_autogen_ptype_is_ccw_equivalent", "[tuple]")
{
{
auto tuples = all_valid_local_tuples(PrimitiveType::Edge);
for (const auto& t : tuples) {
CHECK(edge_mesh::is_ccw(t) == is_ccw(PrimitiveType::Edge, t));
}
}

{
auto tuples = all_valid_local_tuples(PrimitiveType::Face);
for (const auto& t : tuples) {
Expand Down Expand Up @@ -230,6 +241,16 @@ TEST_CASE("tuple_autogen_local_id_inversion", "[tuple]")

TEST_CASE("tuple_autogen_ptype_local_switch_tuple_equivalent", "[tuple]")
{
{
auto tuples = all_valid_local_tuples(PrimitiveType::Edge);
for (const auto& t : tuples) {
for (PrimitiveType pt : primitives_up_to(PrimitiveType::Edge)) {
CHECK(
edge_mesh::local_switch_tuple(t, pt) ==
local_switch_tuple(PrimitiveType::Edge, t, pt));
}
}
}
{
auto tuples = all_valid_local_tuples(PrimitiveType::Face);
for (const auto& t : tuples) {
Expand Down

0 comments on commit bf90519

Please sign in to comment.