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

Conversation

ahighmoon
Copy link
Collaborator

Create a component: to extract a subset/submesh of a given mesh according to a given tag

@daniel-zint daniel-zint linked an issue Oct 13, 2023 that may be closed by this pull request
@daniel-zint
Copy link
Contributor

this PR should be a draft

Copy link
Contributor

@daniel-zint daniel-zint left a 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;}
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.

@@ -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){
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.


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

// 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.

std::vector<Tuple> triangles = m.get_all(wmtk::PrimitiveType::Face);
return internal::extract_subset_2d(vertices, triangles, tag);
}
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


//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.


// 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.

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

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]

#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.

@mtao
Copy link
Collaborator

mtao commented Oct 28, 2023

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

@ahighmoon ahighmoon marked this pull request as draft November 1, 2023 17:20
Copy link
Contributor

@daniel-zint daniel-zint left a 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]")
Copy link
Contributor

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);
Copy link
Contributor

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);
Copy link
Contributor

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:

MeshAttributeHandle<T> register_attribute(

You might want to use that to default everything to something signaling invalidness like -1.

Copy link
Collaborator Author

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.

Copy link
Collaborator Author

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.

@mtao
Copy link
Collaborator

mtao commented Nov 9, 2023

this task seems quite similar to #502
@daniel-zint do you want to take a look and determine how these two PRs should interact?

Copy link

codecov bot commented Nov 10, 2023

Codecov Report

Attention: 8 lines in your changes are missing coverage. Please review.

Comparison is base (754f335) 85.46% compared to head (de1533e) 85.54%.
Report is 1345 commits behind head on main.

❗ Current head de1533e differs from pull request most recent head 5a7757b. Consider uploading reports for the commit 5a7757b to get more accurate results

Files Patch % Lines
.../wmtk_components/extract_subset/extract_subset.cpp 72.00% 7 Missing ⚠️
...ents/extract_subset/internal/extract_subset_2d.cpp 98.43% 1 Missing ⚠️
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     
Flag Coverage Δ
wildmeshing 85.54% <91.01%> (+0.07%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

…troublesome to do if-statement everywhere in the second half of the algo
…_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
…to the # of face since there is one more region outside
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Component extract_subset
3 participants