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

Component extract_subset #426

Draft
wants to merge 72 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
72 commits
Select commit Hold shift + click to select a range
3aa11fb
create dummy component extract subset&CMakeLists
ahighmoon Sep 28, 2023
3921e20
finish 2d extract subset by convert old vectices id to new
ahighmoon Oct 12, 2023
1be4189
correct extract_subset_2d interface w/o implementation
ahighmoon Oct 19, 2023
dcf2723
failed attempt to add fv/vf accessors
ahighmoon Oct 19, 2023
5504abb
change argument to MeshAttributeHandle, w/ one linking error in test …
ahighmoon Nov 5, 2023
476bb22
Merge branch 'main' into dzint/component_extract_subset
ahighmoon Nov 9, 2023
472a219
finish a version of ds adaption w/ linking error from external
ahighmoon Nov 9, 2023
06e9114
fix linking error and remove all unnecessary comments
ahighmoon Nov 10, 2023
3203b4c
change test case to 2d tet and change argument of extract_subset to r…
ahighmoon Nov 10, 2023
b6c5f36
fix internal bug and pass all tag tests on 2d tet
ahighmoon Nov 12, 2023
de1533e
add comments and another geometric config for test
ahighmoon Nov 12, 2023
db6d98c
init the topology algo, compiles and links fine
ahighmoon Nov 16, 2023
d299091
finish 1st version of topo algo, compiles, bdry function to be implem…
ahighmoon Nov 18, 2023
886909a
remove unnecessary bdry determine func, add manual test case of 3+4
ahighmoon Nov 18, 2023
b4b4d7f
fixing calcing cc using dfs recursion
ahighmoon Nov 19, 2023
da5b811
finish finding vertex copies and ready for reconstruct mesh
ahighmoon Nov 28, 2023
9faab15
finish mesh reconstruction
ahighmoon Nov 28, 2023
407b2b5
change helper functions to inline in the header, some performance mod…
ahighmoon Nov 28, 2023
183fabc
move utils functions back to cpp file
ahighmoon Nov 29, 2023
1fc1002
init the test validness & manifold functions
ahighmoon Nov 29, 2023
24c5142
test manifold conditions per vertex
ahighmoon Nov 29, 2023
c24e525
finish manifold test func on the return mesh
ahighmoon Nov 29, 2023
152cb95
refactor, extract get_connection into another func
ahighmoon Nov 29, 2023
7f7fa10
2d tet doesn't satisfy the manifold function, remove it from test cases
ahighmoon Nov 29, 2023
efc311e
remove print
ahighmoon Nov 29, 2023
b0fd76a
add random test based on delaunay2d, from previous manifold-extractio…
ahighmoon Nov 30, 2023
b39e35f
format
ahighmoon Nov 30, 2023
1a1a7b5
init the files for 3d topo algp dev
ahighmoon Dec 1, 2023
7a30eb7
refactor and remove some auto
ahighmoon Dec 1, 2023
822c722
fixing all autos
ahighmoon Dec 1, 2023
5d55b33
add some comments to internal algo
ahighmoon Dec 1, 2023
65ca4eb
move some util functions in topo_2d to utils so other files could use…
ahighmoon Dec 1, 2023
09ac3a4
change some code in extract_subset_2d to new defined util funcs
ahighmoon Dec 1, 2023
1471fed
generalize util functions to fit trimesh and tetmesh, linking error
ahighmoon Dec 1, 2023
7a946dd
add more templates, still linking error
ahighmoon Dec 1, 2023
3f2744e
change vertex_on_bdry function to existing implement, code runs fine …
ahighmoon Dec 6, 2023
2d8d2f6
move all util functions to utils so other files could use, runs fine
ahighmoon Dec 6, 2023
55f22c6
change some code in extract_subset_2d to new defined util funcs and f…
ahighmoon Dec 6, 2023
34d00a4
finish extract_subset_3d without error
ahighmoon Dec 6, 2023
2603077
Merge branch 'dzint/component_extract_subset' of https://github.com/w…
ahighmoon Dec 6, 2023
2da433c
fix all errors and redundency
ahighmoon Dec 6, 2023
a23f82f
fix minor bug, prev commit message is wrong
ahighmoon Dec 6, 2023
777cd32
save temp work in step 2 of topo_separate_3d
ahighmoon Dec 6, 2023
bcfd83e
copy & adapt the 2d case to 3d. question: to create dup edge on ident…
ahighmoon Dec 6, 2023
cb53ea9
finish topo_3d algo, extremely messy but should be correct
ahighmoon Dec 7, 2023
fdd4b5b
init the 3d_manifold test function
ahighmoon Dec 7, 2023
73cfe5e
refactor the function signature to handle 2d and 3d all at once
ahighmoon Dec 20, 2023
c08131c
[NOT proven correct] add first version of is_disk and is_sphere funct…
ahighmoon Dec 21, 2023
961cc25
remove redundant dimension argument, fix wrong use of m.capacity()
ahighmoon Feb 5, 2024
ad34515
move prev to attic & implement algo in new_topo_separate & create du…
ahighmoon Feb 7, 2024
1d757f1
save work, attempt to combine 2 functions into new_topo_sep
ahighmoon Feb 7, 2024
d3f23a4
add initial check for only processing tagged top simplices
ahighmoon Feb 7, 2024
5d89c64
finish new_topo_sep middle part, did experiments with top_dimension_c…
ahighmoon Feb 7, 2024
931b10c
finish reconstruction part
ahighmoon Feb 7, 2024
3afccbe
remove files unneed
ahighmoon Feb 7, 2024
2c56235
restore utils.cpp temporarily, seg fault
ahighmoon Feb 7, 2024
29327cd
restore the gen_submesh file since they are actually needed
ahighmoon Feb 8, 2024
ed177b2
[Save work] algo ok, but compile/linking error
ahighmoon Feb 11, 2024
be76d8b
finish the extract_submesh task without considering positions, everyt…
ahighmoon Feb 11, 2024
f8ecc61
Add coordinates preserving section
ahighmoon Feb 11, 2024
be2b55a
Move submesh functionality back to its own file; Note: because it is …
ahighmoon Feb 11, 2024
6cb1ed2
finish main algorithm, test on 3+4 test case and passes all 4 asserti…
ahighmoon Feb 11, 2024
92445ac
add coordinates preserving logic to topo_sep function
ahighmoon Feb 11, 2024
e656a30
remove unused accessor argument of topo_sep
ahighmoon Feb 11, 2024
4a8c362
minor changes
ahighmoon Feb 11, 2024
106aca6
[Save Temp work] in the middle of adjusting generate_submesh function…
ahighmoon Feb 11, 2024
bdcdfc1
finish generate_submesh, test passes on 3+4 2D case without coordinates
ahighmoon Feb 12, 2024
0b8e485
[Save Temp Work] restored some test cases in the test file, now 2_non…
ahighmoon Feb 12, 2024
6cfce0b
fix bug! in topo_sep func, should ALWAYS access and change the vertex…
ahighmoon Feb 12, 2024
3b5353c
restore the test case of 6_cycle_tets in 3D, passed it; remove unneed…
ahighmoon Feb 12, 2024
63e9562
change the way to determine planar graph : in calc euler char, add 1 …
ahighmoon Feb 12, 2024
5a7757b
add 3D random test case, now reports error for every mesh with more t…
ahighmoon Feb 12, 2024
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
4 changes: 2 additions & 2 deletions components/wmtk_components/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

add_subdirectory(input)
add_subdirectory(isotropic_remeshing)
add_subdirectory(mesh_info)
add_subdirectory(output)
add_subdirectory(output)
add_subdirectory(extract_subset)
5 changes: 5 additions & 0 deletions components/wmtk_components/extract_subset/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
set(SRC_FILES
internal/extract_subset_2d.hpp
internal/extract_subset_2d.cpp
)
target_sources(wildmeshing_components PRIVATE ${SRC_FILES})
22 changes: 22 additions & 0 deletions components/wmtk_components/extract_subset/extract_subset.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#include "extract_subset.hpp"


namespace wmtk{
namespace components {
wmtk::TriMesh extract_subset(long dimension, const wmtk::TriMesh& m, std::vector<size_t> tag){
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change the order of parameters: mesh, tag, dimension

switch (dimension){
case 2: {
// return internal::extrace_subset_2d();
std::vector<Tuple> vertices = m.get_all(wmtk::PrimitiveType::Vertex);
std::vector<Tuple> triangles = m.get_all(wmtk::PrimitiveType::Face);
return internal::extract_subset_2d(vertices, triangles, tag);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A Tuple without it's corresponding mesh is useless. The tuple is a handle that can only be evaluated in combination with its mesh.

}
case 3: {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a default case that contains throw "not implemented"; or something similar.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Btw if you throw a string literal it causes weird outputs. Make sure to throw a runtime error

// to be implemented
}
}

}

}
}
11 changes: 11 additions & 0 deletions components/wmtk_components/extract_subset/extract_subset.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#pragma once

#include <vector>
#include "wmtk/Mesh.hpp"
#include <wmtk/TriMesh.hpp>
#include "wmtk/Primitive.hpp"
#include "internal/extract_subset_2d.hpp"

namespace wmtk::components{
wmtk::TriMesh extract_subset(long dimension, const wmtk::TriMesh& m, std::vector<size_t> tag);
} // namespace wmtk::components
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
#include "extract_subset_2d.hpp"

wmtk::TriMesh extract_subset_2d(
const std::vector<Eigen::Vector2d>& points,
Eigen::MatrixXi& triangles, std::vector<size_t> tag){

int nb_vertex = points.size();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be const and it should be a size_t just like points.size(). If you want it to be an int for whatever reason, you should convert it explicitly because size_t to int is a narrowing conversion and it will produce a warning.

int nb_vertex_in = 0;
int nb_tri_in = tag.size();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same es for nb_vertex

// maintain a vector of bool, true if an old vertex is preserved after extraction
std::vector<bool> vertices_in_bool(nb_vertex);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can set the values directly in the constructor

std::vector<bool> vertices_in_bool(nb_vertex, false);

for (int k = 0; k < nb_vertex; ++k) {vertices_in_bool[k] = false;}

Eigen::MatrixXi faces_in;
faces_in.resize(nb_tri_in, 3);

//tag the preserved ones and count number of vertex in new extraction
for (size_t k = 0; k < nb_tri_in; ++k){
for (size_t k2 = 0; k2 < 3; ++k2) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know why you are using k and k2 here but the convention is to use i and j. Please change that, otherwise it might be confusing.

// faces_in(k, k2) = triangles(tag[k], k2);
vertices_in_bool[triangles(tag[k], k2)] = true;
}
}
for (bool b: vertices_in_bool) {
if (b) nb_vertex_in ++;
}

// construct a map from old vertex id to new new id
std::map<int, int> old2new;
int j = 0;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

j is more than a counter variable here, give it a more descriptive name.

for (int i = 0; i < nb_vertex; ++i){
// ignore the not extracted vertices
if (vertices_in_bool[i]){
// old vertex id i map to new vertex id j, where j increases by count
old2new.insert({i, j});
j++;
}
}
assert(j == nb_vertex_in);

wmtk::TriMesh mesh;
wmtk::RowVectors3l tris;
tris.resize(nb_tri_in, 3);
for (unsigned int i = 0; i < nb_tri_in; ++i){
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should also be size_t

// only put in the extracted ones
size_t tri = tag[i];
tris.row(i) << old2new[triangles(tri, 0)], old2new[triangles(tri, 1)], old2new[triangles(tri, 2)];
}
mesh.initialize(tris);

Eigen::MatrixXd points_in;
points_in.resize(nb_vertex_in, 2);
for (int i = 0; i < nb_vertex; ++i){
if (vertices_in_bool[i]){
points_in(old2new[i], 0) = points[i][0];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

points_in.row(i) = points[i]

points_in(old2new[i], 1) = points[i][1];
}
}
wmtk::mesh_utils::set_matrix_attribute(points_in, "position", wmtk::PrimitiveType::Vertex, mesh);
return mesh;
}


// Note: the above is a draft version of the algo, implemented in bad, drafted data structure
// The following is new code to be finished
wmtk::TriMesh extract_subset_2d(std::vector<wmtk::Tuple> vertices, std::vector<wmtk::Tuple> triangles, std::vector<size_t> tag){
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't really understand the parameters here. Why vertices and triangles? I think you should have a Mesh as input in combination with an Attribute that is used as tag.

Minor comment:
The return value should also just be a Mesh. This code can be written in a generic enough way so that it works for extracting triangles or just a bunch of edges. However, we can do the generalization as soon as the basic concept is there, so don't worry about that for now.

assert(tag.size() <= triangles.size());

int nb_vertex = vertices.size();
int nb_vertex_in = 0;
int nb_tri_in = tag.size();
std::vector<bool> vertices_in_bool(nb_vertex);
for (int k = 0; k < nb_vertex; ++k) {vertices_in_bool[k] = false;}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like you are not using an auto formatter. We have a .clang-format file in our repository. Please install an auto formatter and use this format file. I recommend also to activate "format on save". That way it is sure that you never forget formatting before you commit.

Eigen::MatrixXi faces_in;
faces_in.resize(nb_tri_in, 3);

//tag the preserved ones and count number of vertex in new extraction
for (size_t k = 0; k < nb_tri_in; ++k){
// wmtk::attribute::MeshAttributeHandle<long> m_vf_handle;
// wmtk::attribute::MeshAttributeHandle<long> m_vf_handle;
// wmtk::ConstAccessor<long> vf_accessor = wmtk::Mesh::create_const_accessor<long>(m_vf_handle);
// auto f = vf_accessor.index_access().scalar_attribute(k);
// wmtk::ConstAccessor<long> fv_accessor = wmtk::Mesh::create_const_accessor<long>(m_fv_handle);
// auto fv = fv_accessor.index_access().vector_attribute(f);
for (size_t k2 = 0; k2 < 3; ++k2) {
// if (fv(k2) == k){

// }

// vertices_in_bool[triangles(tag[k], k2)] = true;
}
}
// for (bool b: vertices_in_bool) {
// if (b) nb_vertex_in ++;
// }

// // construct a map from old vertex id to new new id
// std::map<int, int> old2new;
// int j = 0;
// for (int i = 0; i < nb_vertex; ++i){
// // ignore the not extracted vertices
// if (vertices_in_bool[i]){
// // old vertex id i map to new vertex id j, where j increases by count
// old2new.insert({i, j});
// j++;
// }
// }
// assert(j == nb_vertex_in);

wmtk::TriMesh mesh;
// wmtk::RowVectors3l tris;
// tris.resize(nb_tri_in, 3);
// for (unsigned int i = 0; i < nb_tri_in; ++i){
// // only put in the extracted ones
// size_t tri = tag[i];
// tris.row(i) << old2new[triangles(tri, 0)], old2new[triangles(tri, 1)], old2new[triangles(tri, 2)];
// }
// mesh.initialize(tris);

// Eigen::MatrixXd points_in;
// points_in.resize(nb_vertex_in, 2);
// for (int i = 0; i < nb_vertex; ++i){
// if (vertices_in_bool[i]){
// points_in(old2new[i], 0) = points[i][0];
// points_in(old2new[i], 1) = points[i][1];
// }
// }
// wmtk::mesh_utils::set_matrix_attribute(points_in, "position", wmtk::PrimitiveType::Vertex, mesh);
return mesh;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#pragma once

#include <vector>
#include <wmtk/TriMesh.hpp>
#include <wmtk/utils/mesh_utils.hpp>
#include <wmtk/Primitive.hpp>
#include "wmtk/Mesh.hpp"
#include "wmtk/Tuple.hpp"
#include <wmtk/Accessor.hpp>
#include <wmtk/attribute/AttributeHandle.hpp>

namespace wmtk::components::internal {
wmtk::TriMesh extract_subset_2d(
const std::vector<Eigen::Vector2d>& points,
Eigen::MatrixXd& vertices,
Eigen::MatrixXi& triangles, std::vector<size_t> tag);

wmtk::TriMesh extract_subset_2d(
std::vector<Tuple> vertices,
std::vector<Tuple> triangles,
std::vector<size_t> tag);
}

// namespace wmtk::components::internal
1 change: 1 addition & 0 deletions tests/components/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ set(TEST_SOURCES
test_component_mesh_info.cpp
test_component_output.cpp
test_component_isotropic_remeshing.cpp
test_component_extract_subset.cpp
)
target_sources(wmtk_tests PRIVATE ${TEST_SOURCES})

Expand Down
8 changes: 8 additions & 0 deletions tests/components/test_component_extract_subset.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#include <wmtk_components/extract_subset/internal/extract_subset_2d.hpp>
#include <catch2/catch_test_macros.hpp>


TEST_CASE("manual test case", "[components][extract_subset][2D]")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test cases should not have spaces in their name, use _ instead: manual_test_case.

Furthermore, test case names should be very descriptive because all test cases share the same scope.

{

}