-
Notifications
You must be signed in to change notification settings - Fork 0
Add snap_to_tessellated_mesh #1
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
base: main
Are you sure you want to change the base?
Add snap_to_tessellated_mesh #1
Conversation
Rombur
left a comment
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.
This could use more comments, I don't think I followed everything you were doing. Add the .clang-format from adamantine to the repo.
|
|
||
| #include <deal.II/opencascade/manifold_lib.h> | ||
|
|
||
| dealii::Point<3> my_closest_point(const std::vector<TopoDS_Face> &faces, |
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.
Why are you using your own function and not closest_point() directly?
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.
Because we might want to use only part of the Surface to avoid, e.,g., the top and bottom face.
| for (unsigned int i = 0; i < normals.size(); ++i) { | ||
| for (unsigned int j = i + 1; j < normals.size(); ++j) { | ||
| auto product = normals[i] * normals[j]; | ||
| minimum_product = std::min(product, minimum_product); |
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.
What does this do?
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.
We are trying to figure out if all the normals point roughly in the same direction. Since the input file is tessellated, the products are either 0,1, or -1.
If the normals point in different directions, we identify the vertex as a corner and treat it differently.
| if (minimum_product > .5) { | ||
| vertex(0) = proj(0); | ||
| vertex(1) = proj(1); | ||
| // vertex(2) = proj(2); // hourglass |
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.
Why are you getting the z component if you plan to ignore it anyway? Wouldn't it make more sense to search for the closest point in the xy-plane instead?
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.
As the description in the pull request said, none of the iges files I was working with, was entirely conforming with the respective vtk file.
For the hourglass mesh, the iges file is rotated such that the printing direction coincides with the y-axis instead of the z-axis. Thus, we we need to use coordinates 0 and 2 instead of 0 and 1 for that example.
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.
Is this just a case where the iges is aligned with a x/y/z axis or sometimes it's totally random and you need to perform a rotation to match the iges and the vtk file?
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.
For the files provided, I needed to figure out the transformation but ultimately the user should make sure that the files match.
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.
Why did the file not match and would one ensure that they do match?
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.
There is not all that much we can do to detect if the files match apart from checking that the bounding boxes are roughly the same. For the curved wall example, I needed to scale the mesh by a factor of 100 and for the hourglass mesh swap y- and z-component and shift the mesh by 0.07 in x-direction.
All this shouldn't be a problem if STL file (to create the VTK file) and the IGES file are created at the same time.
As I said earlier, we could try to create the VTK file in deal.II from the STL file avoiding OpenFOAM which would also help avoiding these problems (but takes obviously more effort).
|
|
||
| bool exclude_z_faces = false; | ||
|
|
||
| // We don't care about faces with z-normal so exclude them here |
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.
Is that always true or we just don't care about the bottom and the top face?
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.
The code ignores TopoDS::Faces that are planes with z-normal. This might or might not be a good choice depending on the input files. It should not be detrimental if the face is indeed planar but might be problematic if we wrongly detect it to be planar.
In general, this should help mostly with the edges at the top and bottom.
| auto point_0 = dealii::OpenCASCADE::point<3>(SurfToProj->Value(u1, v1)); | ||
| auto point_1 = dealii::OpenCASCADE::point<3>(SurfToProj->Value(u1, v2)); | ||
| auto point_2 = dealii::OpenCASCADE::point<3>(SurfToProj->Value(u2, v1)); | ||
| auto point_3 = dealii::OpenCASCADE::point<3>(SurfToProj->Value(u2, v2)); |
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.
What are these points?
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.
The four corners of the face.
| double deviation_from_z = | ||
| normal / normal.norm() * dealii::Tensor<1, 3>({0, 0, 1}); | ||
|
|
||
| if (std::abs(deviation) > .1 || std::abs(deviation_from_z) < .9) |
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.
How did you pick these numbers?
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 just picked something that worked for the meshes provided. I would need more examples to find better numbers.
masterleinad
left a comment
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'll add more comments.
|
|
||
| #include <deal.II/opencascade/manifold_lib.h> | ||
|
|
||
| dealii::Point<3> my_closest_point(const std::vector<TopoDS_Face> &faces, |
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.
Because we might want to use only part of the Surface to avoid, e.,g., the top and bottom face.
| for (unsigned int i = 0; i < normals.size(); ++i) { | ||
| for (unsigned int j = i + 1; j < normals.size(); ++j) { | ||
| auto product = normals[i] * normals[j]; | ||
| minimum_product = std::min(product, minimum_product); |
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.
We are trying to figure out if all the normals point roughly in the same direction. Since the input file is tessellated, the products are either 0,1, or -1.
If the normals point in different directions, we identify the vertex as a corner and treat it differently.
| if (minimum_product > .5) { | ||
| vertex(0) = proj(0); | ||
| vertex(1) = proj(1); | ||
| // vertex(2) = proj(2); // hourglass |
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.
As the description in the pull request said, none of the iges files I was working with, was entirely conforming with the respective vtk file.
For the hourglass mesh, the iges file is rotated such that the printing direction coincides with the y-axis instead of the z-axis. Thus, we we need to use coordinates 0 and 2 instead of 0 and 1 for that example.
| auto point_0 = dealii::OpenCASCADE::point<3>(SurfToProj->Value(u1, v1)); | ||
| auto point_1 = dealii::OpenCASCADE::point<3>(SurfToProj->Value(u1, v2)); | ||
| auto point_2 = dealii::OpenCASCADE::point<3>(SurfToProj->Value(u2, v1)); | ||
| auto point_3 = dealii::OpenCASCADE::point<3>(SurfToProj->Value(u2, v2)); |
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.
The four corners of the face.
|
|
||
| bool exclude_z_faces = false; | ||
|
|
||
| // We don't care about faces with z-normal so exclude them here |
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.
The code ignores TopoDS::Faces that are planes with z-normal. This might or might not be a good choice depending on the input files. It should not be detrimental if the face is indeed planar but might be problematic if we wrongly detect it to be planar.
In general, this should help mostly with the edges at the top and bottom.
| double deviation_from_z = | ||
| normal / normal.norm() * dealii::Tensor<1, 3>({0, 0, 1}); | ||
|
|
||
| if (std::abs(deviation) > .1 || std::abs(deviation_from_z) < .9) |
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 just picked something that worked for the meshes provided. I would need more examples to find better numbers.
Rombur
left a comment
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.
The code looks ok but we still need:
- a README to explain what the code does, how to install it, and how to run it
- a test to make sure that we don't break the code when we modify it
- a Dockerfile and a GitHub workflow to create a docker image when we push on master because most people are not going to compile deal.II
You can do this in this PR or another one.
| if (minimum_product > .5) { | ||
| vertex(0) = proj(0); | ||
| vertex(1) = proj(1); | ||
| // vertex(2) = proj(2); // hourglass |
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.
Why did the file not match and would one ensure that they do match?
| B.Get(Xmin, Ymin, Zmin, Xmax, Ymax, Zmax); | ||
|
|
||
| std::cout << "Bounding Box: (" << Xmin << ',' << Ymin << ',' << Zmin << "), (" | ||
| << Xmax << ',' << Ymax << ',' << Zmax << ")\n"; |
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.
Any reason to write this on the screen?
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 helps a lot when identifying if the IGES file and the VTK file match. Since most viewers can't display IGES files natively.
| // if the face is indeed planar but might be problematic if we wrongly detect | ||
| // it to be planar. Excluding those faces should mostly help with the edges at | ||
| // the top and bottom of the mesh (assuming thet are planar). | ||
| bool exclude_z_faces = 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.
This should be a command line parameter.
95a9a5f to
70fe2d7
Compare
|
The only thing missing here is automatic testing. This pull requests includes tests and a |
This pull request adds a tool that snaps a tessellated vtk mesh to the geometries surface given by an iges file.
Note that orientation and scaling between the two must match which is not true for the files initially tested on. That's why there are a bunch of comments for curved wall and hourglass.