Skip to content

Conversation

@masterleinad
Copy link
Collaborator

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.

Copy link
Member

@Rombur Rombur left a 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,
Copy link
Member

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?

Copy link
Collaborator Author

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

Choose a reason for hiding this comment

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

What does this do?

Copy link
Collaborator Author

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
Copy link
Member

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?

Copy link
Collaborator Author

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.

Copy link
Member

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?

Copy link
Collaborator Author

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.

Copy link
Member

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?

Copy link
Collaborator Author

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
Copy link
Member

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?

Copy link
Collaborator Author

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

Choose a reason for hiding this comment

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

What are these points?

Copy link
Collaborator Author

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)
Copy link
Member

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?

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 just picked something that worked for the meshes provided. I would need more examples to find better numbers.

Copy link
Collaborator Author

@masterleinad masterleinad left a 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,
Copy link
Collaborator Author

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

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
Copy link
Collaborator Author

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

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
Copy link
Collaborator Author

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)
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 just picked something that worked for the meshes provided. I would need more examples to find better numbers.

Copy link
Member

@Rombur Rombur left a 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
Copy link
Member

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";
Copy link
Member

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?

Copy link
Collaborator Author

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;
Copy link
Member

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.

@masterleinad masterleinad force-pushed the snap_to_tessellated_mesh branch from 95a9a5f to 70fe2d7 Compare May 24, 2024 15:51
@masterleinad masterleinad changed the title [WIP] Add snap_to_tessellated_mesh Add snap_to_tessellated_mesh Jun 18, 2024
@masterleinad
Copy link
Collaborator Author

The only thing missing here is automatic testing. This pull requests includes tests and a Dockerfile that installs all dependencies.

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.

2 participants