-
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?
Conversation
this PR should be a draft |
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.
I think the general idea of the algorithm itself is there but there are some issues on the coding side. Every method will get a Mesh
as input and will return a Mesh
as output. You are currently still using the IGL style matrices. They should be avoided if possible.
Oh and please set this PR as "draft".
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 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.
@@ -62,23 +62,34 @@ wmtk::TriMesh extract_subset_2d( | |||
|
|||
|
|||
// Note: the above is a draft version of the algo, implemented in bad, drafted data structure | |||
// The following is new code to be finished, commented out to compile | |||
// 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 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.
|
||
namespace wmtk{ | ||
namespace components { | ||
wmtk::TriMesh extract_subset(long dimension, const wmtk::TriMesh& m, std::vector<size_t> tag){ |
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
// 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 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.
std::vector<Tuple> triangles = m.get_all(wmtk::PrimitiveType::Face); | ||
return internal::extract_subset_2d(vertices, triangles, tag); | ||
} | ||
case 3: { |
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.
Add a default
case that contains throw "not implemented";
or something similar.
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.
Btw if you throw a string literal it causes weird outputs. Make sure to throw a runtime error
|
||
//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 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.
|
||
// 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 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.
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 comment
The reason will be displayed to describe this comment to others. Learn more.
should also be size_t
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 comment
The reason will be displayed to describe this comment to others. Learn more.
points_in.row(i) = points[i]
#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 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.
What is the progress here? Given the new multimesh structure there's extra things to develop in this concept of extracting a subset. There are others working on the extraction of a subset with codimension so it'd be good to unify the API for both/make sure both implementations have the appropriate similarities |
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.
Please take a look at the code I referenced for the usage of attributes.
|
||
|
||
TEST_CASE("manual test case", "[components][extract_subset][2D]") | ||
TEST_CASE("3 neighbors test case", "[components][extract_subset][2D]") |
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.
write test case names with underscores: "3_neighbors_test_case"
|
||
// NOTE: I don't know why the following line gives me a linking error of undefined reference... | ||
// wmtk::TriMesh new_tm = wmtk::components::extract_subset(tm, tag_handle, 2); | ||
wmtk::TriMesh new_tm = wmtk::components::internal::extract_subset_2d(tm, tag_handle); |
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.
If I see it correctly, you didn't set extract_subset_2d
in the internal
namespace. That is why it cannot find it.
V.row(1) << 0; // ont tri is not tagged | ||
V.row(2) << 1; | ||
V.row(3) << 1; | ||
auto tag_handle = wmtk::mesh_utils::set_matrix_attribute(V, "tag", wmtk::PrimitiveType::Face, tm); |
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.
That way of setting values should be only used if you want to assign a value to each vertex at once. It is mostly for the case that you load data from a file. In general, you should follow this example:
TEST_CASE("test_accessor_basic") |
register_attribute
can also take a default value for its attribute:
wildmeshing-toolkit/src/wmtk/Mesh.hpp
Line 97 in 764ca0e
MeshAttributeHandle<T> register_attribute( |
You might want to use that to default everything to something signaling invalidness like
-1
.
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.
According to the commit history f1b7140, this functionality is update on Oct 5. So in our current branch there is no such interface right now.
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.
I did a merge just now.
this task seems quite similar to #502 |
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@
## main #426 +/- ##
==========================================
+ Coverage 85.46% 85.54% +0.07%
==========================================
Files 210 212 +2
Lines 5987 6086 +99
==========================================
+ Hits 5117 5206 +89
- Misses 870 880 +10
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
…ented and everything needs tests
…ical endpoints? or split on midpoint
…hing now in one internal file
…troublesome to do if-statement everywhere in the second half of the algo
… to the new algorithm, finish but with bug
…_manifold_edge test case runs with "duplicate index conflict" Runtime Error: tet#2 corner local id 2 with gid 2 has already got assigned index = 2 before adjusting
… attribute by local vid, instead of order of gettting them
…ed print statements
…to the # of face since there is one more region outside
…han 8 tets. NEED visualization component
Create a component: to extract a subset/submesh of a given mesh according to a given tag