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 theTextStlWriter
class directly in order to create text STL content.
-
-
Field Summary
Fields Modifier and Type Field Description private static int
DEFAULT_BUFFER_SIZE
Initial size of the data buffer.private int
initialBufferSize
Initial 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 int
getFacetAttributeValue(FacetDefinition facet)
Get the attribute value that should be used for the given facet.GeometryFormat
getFormat()
Get thedata format
supported by this handler.int
getinitialBufferSize()
Get the initial size of the data buffers used by this instance.void
setInitialBufferSize(int initialBufferSize)
Set the initial size of the data buffers used by this instance.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.void
write(BoundarySource3D src, GeometryOutput out)
Write all boundaries fromsrc
to the given output, using the data format for the instance.void
writeFacets(java.util.stream.Stream<? extends FacetDefinition> facets, GeometryOutput out)
Write allfacets
in the stream to the output using the data format supported by this instance.private void
writeTriangleMesh(TriangleMesh mesh, GeometryOutput output)
Write all triangles in the given mesh to the output using the binary STL format.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
.-
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 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 fromsrc
to the given output, using the data format for the instance.- Specified by:
write
in interfaceBoundaryWriteHandler<PlaneConvexSubset,BoundarySource3D>
- Overrides:
write
in 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 allfacets
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 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 intriangleBuffer
out
- 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
-
-