Class TextStlWriter
- java.lang.Object
-
- org.apache.commons.geometry.io.core.utils.AbstractTextFormatWriter
-
- org.apache.commons.geometry.io.euclidean.threed.stl.TextStlWriter
-
- All Implemented Interfaces:
java.io.Closeable
,java.lang.AutoCloseable
public class TextStlWriter extends AbstractTextFormatWriter
Class for writing the text-based (i.e., "ASCII") STL format.- See Also:
- ASCII STL
-
-
Constructor Summary
Constructors Constructor Description TextStlWriter(java.io.Writer writer)
Construct a new instance for writing STL content to the given writer.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
void
endSolid()
Write the end of the current STL solid definition.void
startSolid()
Write the start of an unnamed STL solid definition.void
startSolid(java.lang.String solidName)
Write the start of an STL solid definition with the given name.private void
writeBeginOrEndLine(java.lang.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(java.util.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 Detail
-
SPACE
private static final char SPACE
Space character.- See Also:
- Constant Field Values
-
name
private java.lang.String name
Name of the current STL solid.
-
started
private boolean started
True if an STL solid definition has been written.
-
-
Method Detail
-
startSolid
public void startSolid()
Write the start of an unnamed STL solid definition. This method is equivalent to callingstlWriter.startSolid(null);
- Throws:
java.io.UncheckedIOException
- if an I/O error occurs
-
startSolid
public void startSolid(java.lang.String solidName)
Write the start of an STL solid definition with the given name.- Parameters:
solidName
- the name of the solid; may be null- Throws:
java.lang.IllegalArgumentException
- ifsolidName
contains new line charactersjava.lang.IllegalStateException
- if a solid definition has already been startedjava.io.UncheckedIOException
- 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:
java.lang.IllegalStateException
- if no solid definition has been startedjava.io.UncheckedIOException
- if an I/O error occurs
-
writeTriangles
public void writeTriangles(PlaneConvexSubset boundary)
Write the given boundary to the output as triangles.- Parameters:
boundary
- boundary to write- Throws:
java.lang.IllegalStateException
- if no solid has been started yetjava.io.UncheckedIOException
- if an I/O error occurs- See Also:
PlaneSubset.toTriangles()
-
writeTriangles
public void writeTriangles(FacetDefinition facet)
Write the given facet definition to the output as triangles.- Parameters:
facet
- facet definition to write- Throws:
java.lang.IllegalStateException
- if no solid has been started yetjava.io.UncheckedIOException
- if an I/O error occurs- See Also:
writeTriangle(Vector3D, Vector3D, Vector3D, Vector3D)
-
writeTriangles
public void writeTriangles(java.util.List<Vector3D> vertices, Vector3D normal)
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:
java.lang.IllegalStateException
- if no solid has been started yet or fewer than 3 vertices are givenjava.io.UncheckedIOException
- if an I/O error occurs
-
writeTriangle
public void writeTriangle(Vector3D p1, Vector3D p2, Vector3D p3, Vector3D normal)
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:
java.lang.IllegalStateException
- if no solid has been started yetjava.io.UncheckedIOException
- if an I/O error occurs
-
close
public void close()
- Specified by:
close
in interfacejava.lang.AutoCloseable
- Specified by:
close
in interfacejava.io.Closeable
- Overrides:
close
in classAbstractTextFormatWriter
-
writeTriangleVertex
private void writeTriangleVertex(Vector3D vertex)
Write a triangle vertex to the output.- Parameters:
vertex
- triangle vertex- Throws:
java.io.UncheckedIOException
- if an I/O error occurs
-
writeVector
private void writeVector(Vector3D vec)
Write a vector to the output.- Parameters:
vec
- vector to write- Throws:
java.io.UncheckedIOException
- if an I/O error occurs
-
writeBeginOrEndLine
private void writeBeginOrEndLine(java.lang.String keyword)
Write the beginning or ending line of the solid definition.- Parameters:
keyword
- keyword at the start of the line- Throws:
java.io.UncheckedIOException
- if an I/O error occurs
-
-