Class StlBoundaryWriteHandler3D

java.lang.Object
org.apache.commons.geometry.io.euclidean.threed.AbstractBoundaryWriteHandler3D
org.apache.commons.geometry.io.euclidean.threed.stl.StlBoundaryWriteHandler3D
All Implemented Interfaces:
BoundaryWriteHandler<PlaneConvexSubset,BoundarySource3D>, BoundaryWriteHandler3D

public class StlBoundaryWriteHandler3D extends AbstractBoundaryWriteHandler3D
BoundaryWriteHandler3D implementation for writing STL content. Because of its compact nature, all STL content is written in binary format, as opposed the text (i.e. "ASCII") format. Callers should use the TextStlWriter class directly in order to create text STL content.
  • Field Details

    • DEFAULT_BUFFER_SIZE

      private static final int DEFAULT_BUFFER_SIZE
      Initial size of the data buffer.
      See Also:
    • initialBufferSize

      private int initialBufferSize
      Initial size of data buffers used during write operations.
  • Constructor Details

    • StlBoundaryWriteHandler3D

      public StlBoundaryWriteHandler3D()
  • Method Details

    • getFormat

      public GeometryFormat getFormat()
      Get the data format supported by this handler.
      Returns:
      data format supported by this handler
    • getinitialBufferSize

      public int getinitialBufferSize()
      Get the initial size of the data buffers used by this instance.

      The buffer is used in situations where it is not clear how many triangles will ultimately be written to the output. In these cases, the triangle data is first written to an internal buffer. Once all triangles are written, the STL header containing the total triangle count is written to the output, followed by the buffered triangle data.

      Returns:
      initial buffer size
    • setInitialBufferSize

      public void setInitialBufferSize(int initialBufferSize)
      Set the initial size of the data buffers used by this instance.

      The buffer is used in situations where it is not clear how many triangles will ultimately be written to the output. In these cases, the triangle data is first written to an internal buffer. Once all triangles are written, the STL header containing the total triangle count is written to the output, followed by the buffered triangle data.

      Parameters:
      initialBufferSize - initial buffer size
    • write

      public void write(BoundarySource3D src, GeometryOutput out)
      Write all boundaries from src to the given output, using the data format for the instance.
      Specified by:
      write in interface BoundaryWriteHandler<PlaneConvexSubset,BoundarySource3D>
      Overrides:
      write in class AbstractBoundaryWriteHandler3D
      Parameters:
      src - boundary source
      out - output to write to
    • write

      public void write(Stream<? extends PlaneConvexSubset> boundaries, GeometryOutput out)
      Write all boundaries in the stream to the given output using the data format supported by this instance. The stream passed as an argument is not closed, meaning that callers are responsible for closing the stream if necessary (for example, if the stream fetches data from the file system).
      Parameters:
      boundaries - stream containing boundaries to write
      out - output to write to
    • writeFacets

      public void writeFacets(Stream<? extends FacetDefinition> facets, GeometryOutput out)
      Write all facets in the stream to the output using the data format supported by this instance. The stream passed as an argument is not closed, meaning that callers are responsible for closing the stream if necessary (for example, if the stream fetches data from the file system).
      Parameters:
      facets - stream containing facets to write
      out - output to write to
    • writeWithHeader

      private void writeWithHeader(ByteArrayOutputStream triangleBuffer, int count, GeometryOutput out)
      Write the given triangle data prefixed with an STL header to the output stream from out.
      Parameters:
      triangleBuffer - buffer containing STL triangle data
      count - number of triangles in triangleBuffer
      out - output to write to
      Throws:
      UncheckedIOException - if an I/O error occurs
    • writeTriangleMesh

      private void writeTriangleMesh(TriangleMesh mesh, GeometryOutput output)
      Write all triangles in the given mesh to the output using the binary STL format.
      Parameters:
      mesh - mesh to write
      output - output to write to
      Throws:
      UncheckedIOException - if an I/O error occurs
    • getFacetAttributeValue

      private int getFacetAttributeValue(FacetDefinition facet)
      Get the attribute value that should be used for the given facet.
      Parameters:
      facet - facet to get the attribute value for
      Returns:
      attribute value