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
BoundaryWriteHandler3Dimplementation 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 theTextStlWriterclass directly in order to create text STL content.
-
-
Field Summary
Fields Modifier and Type Field Description private static intDEFAULT_BUFFER_SIZEInitial size of the data buffer.private intinitialBufferSizeInitial size of data buffers used during write operations.
-
Constructor Summary
Constructors Constructor Description StlBoundaryWriteHandler3D()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private intgetFacetAttributeValue(FacetDefinition facet)Get the attribute value that should be used for the given facet.GeometryFormatgetFormat()Get thedata formatsupported by this handler.intgetinitialBufferSize()Get the initial size of the data buffers used by this instance.voidsetInitialBufferSize(int initialBufferSize)Set the initial size of the data buffers used by this instance.voidwrite(java.util.stream.Stream<? extends PlaneConvexSubset> boundaries, GeometryOutput out)Write all boundaries in the stream to the given output using the data format supported by this instance.voidwrite(BoundarySource3D src, GeometryOutput out)Write all boundaries fromsrcto the given output, using the data format for the instance.voidwriteFacets(java.util.stream.Stream<? extends FacetDefinition> facets, GeometryOutput out)Write allfacetsin the stream to the output using the data format supported by this instance.private voidwriteTriangleMesh(TriangleMesh mesh, GeometryOutput output)Write all triangles in the given mesh to the output using the binary STL format.private voidwriteWithHeader(java.io.ByteArrayOutputStream triangleBuffer, int count, GeometryOutput out)Write the given triangle data prefixed with an STL header to the output stream fromout.-
Methods inherited from class org.apache.commons.geometry.io.euclidean.threed.AbstractBoundaryWriteHandler3D
writeFacets
-
-
-
-
Field Detail
-
DEFAULT_BUFFER_SIZE
private static final int DEFAULT_BUFFER_SIZE
Initial size of the data buffer.- See Also:
- Constant Field Values
-
initialBufferSize
private int initialBufferSize
Initial size of data buffers used during write operations.
-
-
Method Detail
-
getFormat
public GeometryFormat getFormat()
Get thedata formatsupported 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 fromsrcto the given output, using the data format for the instance.- Specified by:
writein interfaceBoundaryWriteHandler<PlaneConvexSubset,BoundarySource3D>- Overrides:
writein classAbstractBoundaryWriteHandler3D- Parameters:
src- boundary sourceout- output to write to
-
write
public void write(java.util.stream.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 writeout- output to write to
-
writeFacets
public void writeFacets(java.util.stream.Stream<? extends FacetDefinition> facets, GeometryOutput out)
Write allfacetsin 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 writeout- output to write to
-
writeWithHeader
private void writeWithHeader(java.io.ByteArrayOutputStream triangleBuffer, int count, GeometryOutput out)Write the given triangle data prefixed with an STL header to the output stream fromout.- Parameters:
triangleBuffer- buffer containing STL triangle datacount- number of triangles intriangleBufferout- output to write to- Throws:
java.io.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 writeoutput- output to write to- Throws:
java.io.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
-
-