-
Notifications
You must be signed in to change notification settings - Fork 17
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
base: main
Are you sure you want to change the base?
Changes from 4 commits
3aa11fb
3921e20
1be4189
dcf2723
5504abb
476bb22
472a219
06e9114
3203b4c
b6c5f36
de1533e
db6d98c
d299091
886909a
b4b4d7f
da5b811
9faab15
407b2b5
183fabc
1fc1002
24c5142
c24e525
152cb95
7f7fa10
efc311e
b0fd76a
b39e35f
1a1a7b5
7a30eb7
822c722
5d55b33
65ca4eb
09ac3a4
1471fed
7a946dd
3f2744e
2d8d2f6
55f22c6
34d00a4
2603077
2da433c
a23f82f
777cd32
bcfd83e
cb53ea9
fdd4b5b
73cfe5e
c08131c
961cc25
ad34515
1d757f1
d3f23a4
5d89c64
931b10c
3afccbe
2c56235
29327cd
ed177b2
be76d8b
f8ecc61
be2b55a
6cb1ed2
92445ac
e656a30
4a8c362
106aca6
bdcdfc1
0b8e485
6cfce0b
3b5353c
63e9562
5a7757b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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) |
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}) |
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){ | ||
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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A |
||
} | ||
case 3: { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add a There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
} | ||
} | ||
|
||
} | ||
|
||
} | ||
} |
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(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should be |
||
int nb_vertex_in = 0; | ||
int nb_tri_in = tag.size(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same es for |
||
// maintain a vector of bool, true if an old vertex is preserved after extraction | ||
std::vector<bool> vertices_in_bool(nb_vertex); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can set the values directly in the constructor
|
||
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) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't know why you are using |
||
// 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; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
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){ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should also be |
||
// 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]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
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){ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't really understand the parameters here. Why Minor comment: |
||
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;} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
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]") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Test cases should not have spaces in their name, use Furthermore, test case names should be very descriptive because all test cases share the same scope. |
||
{ | ||
|
||
} |
There was a problem hiding this comment.
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