Class BinaryStlWriter
java.lang.Object
org.apache.commons.geometry.io.euclidean.threed.stl.BinaryStlWriter
- All Implemented Interfaces:
Closeable
,AutoCloseable
Low-level class for writing binary STL content.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final OutputStream
Output stream to write to.private final ByteBuffer
Buffer used to construct triangle definitions. -
Constructor Summary
ConstructorsConstructorDescriptionConstruct a new instance for writing to the given output. -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
private void
Put all double components ofvec
into the internal buffer.void
writeHeader
(byte[] headerContent, int triangleCount) Write binary STL header content.(package private) static void
writeHeader
(byte[] headerContent, int triangleCount, OutputStream out) Write binary STL header content to the given output stream.void
writeTriangle
(Vector3D p1, Vector3D p2, Vector3D p3, Vector3D normal) Write a triangle to the output using a default attribute value of 0.void
writeTriangle
(Vector3D p1, Vector3D p2, Vector3D p3, Vector3D normal, int attributeValue) Write a triangle to the output.
-
Field Details
-
out
Output stream to write to. -
triangleBuffer
Buffer used to construct triangle definitions.
-
-
Constructor Details
-
BinaryStlWriter
Construct a new instance for writing to the given output.- Parameters:
out
- output stream to write to
-
-
Method Details
-
writeHeader
public void writeHeader(byte[] headerContent, int triangleCount) Write binary STL header content. IfheaderContent
is null, the written header will consist entirely of zeros. Otherwise, up to 80 bytes fromheaderContent
are written to the header, with any remaining bytes of the header filled with zeros.- Parameters:
headerContent
- bytes to include in the header; may be nulltriangleCount
- number of triangles to be included in the content- Throws:
UncheckedIOException
- if an I/O error occurs
-
writeTriangle
Write a triangle to the output using a default attribute value of 0. Callers are responsible for ensuring that the number of triangles written matches the number given in the header.If a normal is given, the vertices are ordered using the right-hand rule, meaning that they will be in a counter-clockwise orientation when looking down the normal. Thus, the given point ordering may not be the ordering used in the written content.
- Parameters:
p1
- first pointp2
- second pointp3
- third pointnormal
- triangle normal; may be null- Throws:
UncheckedIOException
- if an I/O error occurs
-
writeTriangle
public void writeTriangle(Vector3D p1, Vector3D p2, Vector3D p3, Vector3D normal, int attributeValue) Write a triangle to the output. Callers are responsible for ensuring that the number of triangles written matches the number given in the header.If a non-zero normal is given, the vertices are ordered using the right-hand rule, meaning that they will be in a counter-clockwise orientation when looking down the normal. If no normal is given, or the given value cannot be normalized, a normal is computed from the triangle vertices, also using the right-hand rule. If this also fails (for example, if the triangle vertices do not define a plane), then the zero vector is used.
- Parameters:
p1
- first pointp2
- second pointp3
- third pointnormal
- triangle normal; may be nullattributeValue
- 2-byte STL triangle attribute value- Throws:
UncheckedIOException
- if an I/O error occurs
-
close
public void close()- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
-
putVector
Put all double components ofvec
into the internal buffer.- Parameters:
vec
- vector to place into the buffer
-
writeHeader
Write binary STL header content to the given output stream. IfheaderContent
is null, the written header will consist entirely of zeros. Otherwise, up to 80 bytes fromheaderContent
are written to the header, with any remaining bytes of the header filled with zeros.- Parameters:
headerContent
-triangleCount
-out
-- Throws:
UncheckedIOException
- if an I/O error occurs
-