Skip to content

Enhance mesh_tester application so it can write STL.#1592

Merged
BradWhitlock merged 16 commits into
developfrom
feature/whitlock/add_stl_writer
Jun 27, 2025
Merged

Enhance mesh_tester application so it can write STL.#1592
BradWhitlock merged 16 commits into
developfrom
feature/whitlock/add_stl_writer

Conversation

@BradWhitlock

@BradWhitlock BradWhitlock commented Jun 25, 2025

Copy link
Copy Markdown
Member

This PR resolves #262 by enhancing the mesh_tester application so it can write STL files.

  • Adds STLWriter class - in quest since the STLReader is there.
    • The STLWriter class can write ascii or binary STL files.
    • Supports 2D shapes and splits into triangles
    • Meshes that contain 3D cell types have their faces written as triangles.
    • A write_stl function was added that calls the STLWriter class for those who prefer a function interface.
  • Quest readers directory renamed to io since there is a writer in there now.
  • Added tests for writing STL files and reading them back in.
  • Enhanced mesh_tester with --format and --binary command line arguments allow STL output (optionally binary).

@kennyweiss kennyweiss left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks @BradWhitlock for this great addition!

Comment thread RELEASE-NOTES.md
- The `primal::BoundingBox` class' `expand()` and `shift()` methods were modified so they do
nothing when called on invalid bounding boxes.
- Updates to [MFEM version 4.8.0][https://github.com/mfem/mfem/releases/tag/v4.8]
- Readers in Quest were moved from a `quest/readers` directory to `quest/io`.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

👍

Comment thread src/axom/quest/io/STLWriter.hpp Outdated
/*!
* \class STLWriter
*
* \brief A simple STL writer for the faces of Mint meshes.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Future leaning suggestion: I think we'll want to update the readers/writers to work with blueprint/BUMP.

Should we emphasize that this works on collections of triangles (or perhaps planar polygons) rather than the input representation (mint)?

Suggested change
* \brief A simple STL writer for the faces of Mint meshes.
* \brief A simple STL writer for a collection of triangular faces with limited support for planar polygons

Obviously, we can change this in the future, so feel free to ignore this suggestion in this PR.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I agree that the readers/writers can eventually provide Conduit interfaces and use Bump internally for accessing those meshes. Future PR.

// Future
struct STLWriter {
//...
#if defined(AXOM_USE_CONDUIT)
   void write(const conduit::Node &mesh);
#endif
//...
};

Comment thread src/axom/quest/io/STLWriter.hpp Outdated
Comment thread src/axom/quest/io/STLWriter.hpp Outdated
Comment on lines +89 to +90
* \brief Determines whether the input mesh looks topologically 2D since
* the mesh dimension seems to reflect the number of coordinate components.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Minor: I'm confused by this comment. Could you please update it?

Specifically, the word "looks" and the reference to "coordinate components" made me think we were going to check if the mesh was (geometrically) planar.

The check in the implementation is about topological cell types (triangle and quad), not about geometric coordinates, which is in line with the function name.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I changed the comments. This functionality was needed when I started using the writer in the mesh_tester. The surface mesh has 3D coordinates. mint::Mesh::getDimension() returns 3 (like the coordinates) but there are no faces, just cells, so we have to iterate over the cells rather than using mint::for_all_faces.

Comment thread src/axom/quest/io/STLWriter.cpp Outdated
Comment thread src/axom/quest/io/STLWriter.cpp Outdated
for(int comp = 0; comp < 3; comp++)
{
n32[comp] = static_cast<float32>(N[comp]);
coords32[0][comp] = static_cast<float32>(coords[0][comp]);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Aside: I didn't appreciate until now that binary STLs use floats for the geometry and normals

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Great tests!

@Arlie-Capps Arlie-Capps left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thank you, Brad! Much appreciated.

@BradWhitlock
BradWhitlock merged commit 939cdfd into develop Jun 27, 2025
15 checks passed
@BradWhitlock
BradWhitlock deleted the feature/whitlock/add_stl_writer branch June 27, 2025 23:27
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.

Export triangle meshes in STL format

3 participants