Class TextStlWriter
- All Implemented Interfaces:
Closeable
,AutoCloseable
- See Also:
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionTextStlWriter
(Writer writer) Construct a new instance for writing STL content to the given writer. -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
void
endSolid()
Write the end of the current STL solid definition.void
Write the start of an unnamed STL solid definition.void
startSolid
(String solidName) Write the start of an STL solid definition with the given name.private void
writeBeginOrEndLine
(String keyword) Write the beginning or ending line of the solid definition.void
writeTriangle
(Vector3D p1, Vector3D p2, Vector3D p3, Vector3D normal) Write a triangle to the output.void
writeTriangles
(List<Vector3D> vertices, Vector3D normal) Write the facet defined by the given vertices and normal to the output as triangles.void
writeTriangles
(PlaneConvexSubset boundary) Write the given boundary to the output as triangles.void
writeTriangles
(FacetDefinition facet) Write the given facet definition to the output as triangles.private void
writeTriangleVertex
(Vector3D vertex) Write a triangle vertex to the output.private void
writeVector
(Vector3D vec) Write a vector to the output.Methods inherited from class org.apache.commons.geometry.io.core.utils.AbstractTextFormatWriter
getDoubleFormat, getLineSeparator, getWriter, setDoubleFormat, setLineSeparator, write, write, write, write, writeNewLine
-
Field Details
-
SPACE
private static final char SPACESpace character.- See Also:
-
name
Name of the current STL solid. -
started
private boolean startedTrue if an STL solid definition has been written.
-
-
Constructor Details
-
TextStlWriter
Construct a new instance for writing STL content to the given writer.- Parameters:
writer
- writer to write to
-
-
Method Details
-
startSolid
public void startSolid()Write the start of an unnamed STL solid definition. This method is equivalent to callingstlWriter.startSolid(null);
- Throws:
UncheckedIOException
- if an I/O error occurs
-
startSolid
Write the start of an STL solid definition with the given name.- Parameters:
solidName
- the name of the solid; may be null- Throws:
IllegalArgumentException
- ifsolidName
contains new line charactersIllegalStateException
- if a solid definition has already been startedUncheckedIOException
- if an I/O error occurs
-
endSolid
public void endSolid()Write the end of the current STL solid definition. This method is called automatically onclose()
if needed.- Throws:
IllegalStateException
- if no solid definition has been startedUncheckedIOException
- if an I/O error occurs
-
writeTriangles
Write the given boundary to the output as triangles.- Parameters:
boundary
- boundary to write- Throws:
IllegalStateException
- if no solid has been started yetUncheckedIOException
- if an I/O error occurs- See Also:
-
writeTriangles
Write the given facet definition to the output as triangles.- Parameters:
facet
- facet definition to write- Throws:
IllegalStateException
- if no solid has been started yetUncheckedIOException
- if an I/O error occurs- See Also:
-
writeTriangles
Write the facet defined by the given vertices and normal to the output as triangles. If the the given list of vertices contains more than 3 vertices, it is converted to triangles using a triangle fan. Callers are responsible for ensuring that the given vertices represent a valid convex polygon.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:
vertices
- vertices defining the facetnormal
- facet normal; may be null- Throws:
IllegalStateException
- if no solid has been started yet or fewer than 3 vertices are givenUncheckedIOException
- if an I/O error occurs
-
writeTriangle
Write a triangle to the output.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
- facet normal; may be null- Throws:
IllegalStateException
- if no solid has been started yetUncheckedIOException
- if an I/O error occurs
-
close
public void close()- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Overrides:
close
in classAbstractTextFormatWriter
-
writeTriangleVertex
Write a triangle vertex to the output.- Parameters:
vertex
- triangle vertex- Throws:
UncheckedIOException
- if an I/O error occurs
-
writeVector
Write a vector to the output.- Parameters:
vec
- vector to write- Throws:
UncheckedIOException
- if an I/O error occurs
-
writeBeginOrEndLine
Write the beginning or ending line of the solid definition.- Parameters:
keyword
- keyword at the start of the line- Throws:
UncheckedIOException
- if an I/O error occurs
-