Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new component Regular Space #437

Merged
merged 21 commits into from
Oct 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
10291d4
build the skeleton
Zhouyuan-Chen Oct 11, 2023
f618dbe
add Todo invariant and EdgeSplitWithTag operation
Zhouyuan-Chen Oct 11, 2023
b44c7f1
add FaceSplit basic operation and FaceSplitWithTag
Zhouyuan-Chen Oct 12, 2023
8c07bff
fixed bug in Edge SplitWithTag, FaceSplitWithTag
Zhouyuan-Chen Oct 12, 2023
682486b
Merge remote-tracking branch 'origin/main' into zhouyuan/regular_space
Zhouyuan-Chen Oct 14, 2023
59490ac
test for split face
Zhouyuan-Chen Oct 15, 2023
1276217
remove the && operator in the REQUIRE function
Zhouyuan-Chen Oct 15, 2023
5dce9a1
correct the comments and remove unnecessary code
Zhouyuan-Chen Oct 15, 2023
6ad532a
test for the split edge with tag
Zhouyuan-Chen Oct 15, 2023
b1cf846
check if operations is valid when todotag is 1
Zhouyuan-Chen Oct 15, 2023
298698d
RegularSpace 2d and 1d finished
Zhouyuan-Chen Oct 15, 2023
30eeed4
added RegularSpace API
Zhouyuan-Chen Oct 16, 2023
4561fce
add midsplit operations and some document
Zhouyuan-Chen Oct 17, 2023
fe3882f
Merge branch 'main' into zhouyuan/regular_space
Zhouyuan-Chen Oct 17, 2023
a1ede37
test facesplit
Zhouyuan-Chen Oct 17, 2023
a49a86c
Update wmtk_data.cmake
Zhouyuan-Chen Oct 17, 2023
5017f4a
fixed bugs and add more tests for regular space
Zhouyuan-Chen Oct 18, 2023
fd18030
modify the test, make it cover more code
Zhouyuan-Chen Oct 22, 2023
da26055
clean the test code and make it cover more code
Zhouyuan-Chen Oct 22, 2023
154bd1f
cancel data writer operation(make statement false)
Zhouyuan-Chen Oct 22, 2023
89b8c9c
remove the variables never used
Zhouyuan-Chen Oct 24, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmake/recipes/wmtk_data.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ ExternalProject_Add(
SOURCE_DIR ${WMTK_DATA_ROOT}

GIT_REPOSITORY https://github.com/wildmeshing/data.git
GIT_TAG 1a8d9824a39b2ee77cafea9fd2cf79dc6bb611bd
GIT_TAG 5750f41b8d25345cd8b88ee59a1ee2619e6ce4f1

CONFIGURE_COMMAND ""
BUILD_COMMAND ""
Expand Down
3 changes: 2 additions & 1 deletion components/wmtk_components/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ add_subdirectory(delaunay)
add_subdirectory(input)
add_subdirectory(isotropic_remeshing)
add_subdirectory(mesh_info)
add_subdirectory(output)
add_subdirectory(output)
add_subdirectory(regular_space)
9 changes: 9 additions & 0 deletions components/wmtk_components/regular_space/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@

set(SRC_FILES
internal/RegularSpaceOptions.hpp
internal/RegularSpace.hpp
internal/RegularSpace.cpp
regular_space.hpp
regular_space.cpp
)
target_sources(wildmeshing_components PRIVATE ${SRC_FILES})
218 changes: 218 additions & 0 deletions components/wmtk_components/regular_space/internal/RegularSpace.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,218 @@
#include "RegularSpace.hpp"

#include <wmtk/SimplicialComplex.hpp>
#include <wmtk/operations/tri_mesh/EdgeCollapseToMidpoint.hpp>
#include <wmtk/operations/tri_mesh/EdgeSplitAtMidpoint.hpp>
#include <wmtk/operations/tri_mesh/EdgeSplitWithTag.hpp>
#include <wmtk/operations/tri_mesh/EdgeSwap.hpp>
#include <wmtk/operations/tri_mesh/FaceSplitWithTag.hpp>
#include <wmtk/operations/tri_mesh/VertexTangentialLaplacianSmooth.hpp>

namespace wmtk::components::internal {

RegularSpace::RegularSpace(
TriMesh& mesh,
MeshAttributeHandle<double>& position_handle,
MeshAttributeHandle<long>& vertex_tag,
MeshAttributeHandle<long>& edge_tag,
const long input_tag_value,
const long embedding_tag_value,
const long split_tag_value,
const int dimension,
const bool lock_boundary)
: m_mesh(mesh)
, m_position_handle(position_handle)
, m_vertex_tag(vertex_tag)
, m_edge_tag(edge_tag)
, m_input_tag_value(input_tag_value)
, m_embedding_tag_value(embedding_tag_value)
, m_split_tag_value(split_tag_value)
, m_dimension(dimension)
, m_scheduler(mesh)
, m_lock_boundary(lock_boundary)
{}

void RegularSpace::process()
{
switch (m_dimension) {
case 0: process_in_0d(); break;
case 1: process_in_1d(); break;
case 2: process_in_2d(); break;
default: throw std::runtime_error("settings went wrong!"); break;
}
}

void RegularSpace::process_in_0d()
{
using namespace operations;

wmtk::MeshAttributeHandle<long> todo_edgesplit_same_handle = m_mesh.register_attribute<long>(
std::string("todo_edgesplit_same_tag"),
wmtk::PrimitiveType::Edge,
1);
wmtk::Accessor<long> acc_vertex_tag = m_mesh.create_accessor(m_vertex_tag);
wmtk::Accessor<double> acc_pos = m_mesh.create_accessor(m_position_handle);
wmtk::Accessor<long> acc_todo_edgesplit_same_tag =
m_mesh.create_accessor(todo_edgesplit_same_handle);

// edge split
{
// compute the todo list for the split edge with the same ends
const std::vector<Tuple>& edges = m_mesh.get_all(wmtk::PrimitiveType::Edge);
for (const Tuple& edge : edges) {
long vt0, vt1;
vt0 = acc_vertex_tag.scalar_attribute(edge);
vt1 = acc_vertex_tag.scalar_attribute(m_mesh.switch_vertex(edge));
if (vt0 == m_input_tag_value && vt1 == m_input_tag_value) {
acc_todo_edgesplit_same_tag.scalar_attribute(edge) = 1;
}
}
// using scheduler to do edge splitting
OperationSettings<tri_mesh::EdgeSplitWithTag> settings_split_same;
settings_split_same.edge_tag = m_edge_tag;
settings_split_same.vertex_tag = m_vertex_tag;
settings_split_same.embedding_tag_value = m_embedding_tag_value;
settings_split_same.need_embedding_tag_value = true;
// settings_split_same.position = m_position_handle;
settings_split_same.split_with_tag_settings.split_settings.split_boundary_edges = true;
settings_split_same.split_with_tag_settings.position = m_position_handle;
settings_split_same.split_edge_tag_value = m_embedding_tag_value;
settings_split_same.split_vertex_tag_value = m_split_tag_value;
settings_split_same.split_todo = todo_edgesplit_same_handle;
settings_split_same.initialize_invariants(m_mesh);
m_scheduler.add_operation_type<tri_mesh::EdgeSplitWithTag>(
"edge_split",
settings_split_same);
while (true) {
m_scheduler.run_operation_on_all(PrimitiveType::Edge, "edge_split");
if (m_scheduler.number_of_successful_operations() == 0) {
break;
}
}
}
}

void RegularSpace::process_in_1d()
{
using namespace operations;

wmtk::MeshAttributeHandle<long> todo_facesplit_handle = m_mesh.register_attribute<long>(
std::string("todo_facesplit_tag"),
wmtk::PrimitiveType::Face,
1);
wmtk::MeshAttributeHandle<long> todo_edgesplit_same_handle = m_mesh.register_attribute<long>(
std::string("todo_edgesplit_same_tag"),
wmtk::PrimitiveType::Edge,
1);
// wmtk::MeshAttributeHandle<long> todo_edgesplit_diff_handle = m_mesh.register_attribute<long>(
// std::string("todo_edgesplit_diff_tag"),
// wmtk::PrimitiveType::Edge,
// 1);
wmtk::Accessor<long> acc_vertex_tag = m_mesh.create_accessor(m_vertex_tag);
wmtk::Accessor<long> acc_edge_tag = m_mesh.create_accessor(m_edge_tag);
wmtk::Accessor<double> acc_pos = m_mesh.create_accessor(m_position_handle);
wmtk::Accessor<long> acc_todo_face_tag = m_mesh.create_accessor(todo_facesplit_handle);
wmtk::Accessor<long> acc_todo_edgesplit_same_tag =
m_mesh.create_accessor(todo_edgesplit_same_handle);
// wmtk::Accessor<long> acc_todo_edgesplit_diff_tag =
// m_mesh.create_accessor(todo_edgesplit_diff_handle);

// face split
{
const std::vector<Tuple>& faces = m_mesh.get_all(wmtk::PrimitiveType::Face);
for (const Tuple& face : faces) {
long vt0, vt1, vt2, et0, et1, et2;
vt0 = acc_vertex_tag.scalar_attribute(face);
vt1 = acc_vertex_tag.scalar_attribute(m_mesh.switch_vertex(face));
vt2 = acc_vertex_tag.scalar_attribute(m_mesh.switch_vertex(m_mesh.switch_edge(face)));
et0 = acc_edge_tag.scalar_attribute(face);
et1 = acc_edge_tag.scalar_attribute(m_mesh.switch_edge(face));
et2 = acc_edge_tag.scalar_attribute(m_mesh.switch_vertex(m_mesh.switch_edge(face)));
if (vt0 == m_input_tag_value && vt1 == m_input_tag_value && vt2 == m_input_tag_value &&
et0 == m_input_tag_value && et1 == m_input_tag_value && et2 == m_input_tag_value) {
acc_todo_face_tag.scalar_attribute(face) = 1;
}
}
// using scheduler to do face splitting
OperationSettings<tri_mesh::FaceSplitWithTag> settings_split_face;
settings_split_face.edge_tag = m_edge_tag;
settings_split_face.embedding_tag_value = m_embedding_tag_value;
settings_split_face.need_embedding_tag_value = true;
settings_split_face.face_split_settings.position = m_position_handle;
settings_split_face.split_todo = todo_facesplit_handle;
settings_split_face.split_vertex_tag_value = m_split_tag_value;
settings_split_face.vertex_tag = m_vertex_tag;
settings_split_face.initialize_invariants(m_mesh);
m_scheduler.add_operation_type<tri_mesh::FaceSplitWithTag>(
"facesplit",
settings_split_face);
while (true) {
m_scheduler.run_operation_on_all(PrimitiveType::Face, "facesplit");
if (m_scheduler.number_of_successful_operations() == 0) {
break;
}
}
m_scheduler.run_operation_on_all(PrimitiveType::Face, "facesplit");
}

// edge split
{
// compute the todo list for the split edge with the same ends
const std::vector<Tuple>& edges = m_mesh.get_all(wmtk::PrimitiveType::Edge);
for (const Tuple& edge : edges) {
long vt0, vt1, et0;
vt0 = acc_vertex_tag.scalar_attribute(edge);
vt1 = acc_vertex_tag.scalar_attribute(m_mesh.switch_vertex(edge));
et0 = acc_edge_tag.scalar_attribute(edge);
if (vt0 == m_input_tag_value && vt1 == m_input_tag_value &&
et0 == m_embedding_tag_value) {
acc_todo_edgesplit_same_tag.scalar_attribute(edge) = 1;
}
}
// using scheduler to do edge splitting
OperationSettings<tri_mesh::EdgeSplitWithTag> settings_split_same;
settings_split_same.edge_tag = m_edge_tag;
settings_split_same.vertex_tag = m_vertex_tag;
settings_split_same.embedding_tag_value = m_embedding_tag_value;
settings_split_same.need_embedding_tag_value = true;
// settings_split_same.position = m_position_handle;
settings_split_same.split_with_tag_settings.split_settings.split_boundary_edges = true;
settings_split_same.split_with_tag_settings.position = m_position_handle;
settings_split_same.split_edge_tag_value = m_embedding_tag_value;
settings_split_same.split_vertex_tag_value = m_split_tag_value;
settings_split_same.split_todo = todo_edgesplit_same_handle;
settings_split_same.initialize_invariants(m_mesh);
m_scheduler.add_operation_type<tri_mesh::EdgeSplitWithTag>(
"edge_split",
settings_split_same);
while (true) {
m_scheduler.run_operation_on_all(PrimitiveType::Edge, "edge_split");
if (m_scheduler.number_of_successful_operations() == 0) {
break;
}
}
}

// compute the todo list for the split edge with the different ends
// {
// const std::vector<Tuple>& edges = m_mesh.get_all(wmtk::PrimitiveType::Edge);
// for (const Tuple& edge : edges) {
// long vt0, vt1;
// vt0 = acc_vertex_tag.scalar_attribute(edge);
// vt1 = acc_vertex_tag.scalar_attribute(m_mesh.switch_vertex(edge));
// if ((vt0 == m_input_tag_value && vt1 == m_embedding_tag_value) ||
// (vt1 == m_input_tag_value && vt0 == m_embedding_tag_value)) {
// acc_todo_edgesplit_same_tag.scalar_attribute(edge) = 1;
// }
// }
// }
// using scheduler to do edge splitting
// ...
}

void RegularSpace::process_in_2d()
{
throw std::runtime_error("2 dimension has not been implemented!");
}

} // namespace wmtk::components::internal
65 changes: 65 additions & 0 deletions components/wmtk_components/regular_space/internal/RegularSpace.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#pragma once

#include <wmtk/Scheduler.hpp>
#include <wmtk/TriMesh.hpp>

namespace wmtk::components::internal {

/*
* This class is used to seperate mesh and make sure there are no direct connection
* between independent simplicity collection
*/
class RegularSpace
{
TriMesh& m_mesh;
bool m_lock_boundary;

MeshAttributeHandle<double> m_position_handle; // record position
MeshAttributeHandle<long> m_vertex_tag; // record vertex tag value
MeshAttributeHandle<long> m_edge_tag; // record edge vertex tag value
long m_input_tag_value; // the value used to those simplicity you want to seperate
long m_embedding_tag_value; // the scalffold simplicities' tag value
long m_split_tag_value; // when you split a simplicity, you will set m_split_tag_value to the
// new simplicity
int m_dimension; // operate dimension, 0 for vertex, 1 for edge, 2 for face, 3 for tet

Scheduler m_scheduler;

/*
* seperate edges end with two ends with the same attribute(m_input_tag_value)
*
* If you have serveral vertices in a mesh, you don't want
* those specific vertices with the same attribute directly connect with each
* other, you should use process_in_0d
*/
void process_in_0d();
Zhouyuan-Chen marked this conversation as resolved.
Show resolved Hide resolved
/*
* seperate the face if there the three vertices and edges all tagged with the input_value
* seperate the edge end with two vertices tagged with input_value but the edge itself is not
* marked as the input_value
*
* If you have serveral segments in a mesh, you don't want
* those specific segments with the same attribute directly connect with each
* other, you should use process_in_1d
*/
void process_in_1d();
// we don't need this function I thought, since we can't convert TriMesh to the Mesh. That's
// said TetMesh can't be passes into this class as a TriMesh object.
void process_in_2d();

public:
RegularSpace(
TriMesh& mesh,
MeshAttributeHandle<double>& position_handle,
MeshAttributeHandle<long>& vertex_tag,
MeshAttributeHandle<long>& edge_tag,
const long input_tag_value,
const long embedding_tag_value,
const long split_tag_value,
const int dimension = 1,
const bool lock_boundary = true);

void process();
};

} // namespace wmtk::components::internal
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#pragma once

#include <spdlog/spdlog.h>
#include <nlohmann/json.hpp>

namespace wmtk {
namespace components {
namespace internal {

struct RegularSpaceOptions
{
std::string type; // regular space
std::string input; // mesh input dir
std::string output; // mesh output dir
std::string pos_attribute_name;
std::string vertex_tag_handle_name;
std::string edge_tag_handle_name;
int dimension; // 0-vertex 1-edge 2-face 3-tet
long input_value;
long embedding_value;
long split_value = -1;
bool lock_boundary = true;
};

NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(
RegularSpaceOptions,
type,
input,
output,
pos_attribute_name,
vertex_tag_handle_name,
edge_tag_handle_name,
dimension,
input_value,
embedding_value,
split_value,
lock_boundary);

} // namespace internal
} // namespace components
} // namespace wmtk
Loading