public class TextFacetDefinitionWriter extends AbstractTextFormatWriter
x
, y
, and z
components in that order. At least 3 vertices are
required for each facet but more can be specified. The facet normal is defined implicitly
from the facet vertices using the right-hand rule (i.e. vertices are arranged counter-clockwise).
Delimiters can be configured for both vertex components
and
vertices
. This allows a wide range of outputs to be configured, from standard
CSV format
to formats designed for easy human readability.
Examples
The examples below demonstrate output from two square facets using different writer configurations.
Default
The default writer configuration uses distinct vertex and vertex component separators to make it easier to visually distinguish vertices. Comments are supported and facets are allowed to have any geometrically valid number of vertices. This format is designed for human readability and ease of editing.
# two square facets 0 0 0; 1 0 0; 1 1 0; 0 1 0 0 0 0; 0 1 0; 0 1 1; 0 0 1
CSV
The example below uses a comma as both the vertex and vertex component separators to produce
a standard CSV format. The facet vertex count is set to 3 to ensure that each row has the same number
of columns and all numbers are written with at least a single fraction digit to ensure proper interpretation
as floating point data. Comments are not supported. This configuration is produced by the
csvFormat(Writer)
factory method.
0.0,0.0,0.0,1.0,0.0,0.0,1.0,1.0,0.0 0.0,0.0,0.0,1.0,1.0,0.0,0.0,1.0,0.0 0.0,0.0,0.0,0.0,1.0,0.0,0.0,1.0,1.0 0.0,0.0,0.0,0.0,1.0,1.0,0.0,0.0,1.0
TextFacetDefinitionReader
Constructor and Description |
---|
TextFacetDefinitionWriter(Writer writer)
Construct a new instance that writes facet information to the given writer.
|
Modifier and Type | Method and Description |
---|---|
static TextFacetDefinitionWriter |
csvFormat(Writer writer)
Construct a new instance configured to write CSV output to the given writer.
|
String |
getCommentToken()
Get the string used to begin comment lines in the output.
|
int |
getFacetVertexCount()
Get the number of vertices required per facet or
-1 if no specific
number is required. |
String |
getVertexComponentSeparator()
Get the string used to separate vertex components (ie, individual x, y, z values).
|
String |
getVertexSeparator()
Get the string used to separate facet vertices.
|
void |
setCommentToken(String commentToken)
Set the string used to begin comment lines in the output.
|
void |
setFacetVertexCount(int vertexCount)
Set the number of vertices required per facet.
|
void |
setVertexComponentSeparator(String sep)
Set the string used to separate vertex components (ie, individual x, y, z values).
|
void |
setVertexSeparator(String sep)
Set the string used to separate facet vertices.
|
void |
write(BoundarySource3D src)
Write all boundaries in the argument to the output.
|
void |
write(FacetDefinition facet)
Write the vertices in the argument to the output.
|
void |
write(List<Vector3D> vertices)
Write a list of vertices defining a facet as a single line of text to the output.
|
void |
write(PlaneConvexSubset convexSubset)
Write the vertices defining the argument to the output.
|
void |
writeBlankLine()
Write a blank line to the output.
|
void |
writeComment(String comment)
Write a comment to the output.
|
close, getDoubleFormat, getLineSeparator, getWriter, setDoubleFormat, setLineSeparator, write, write, write, write, writeNewLine
public TextFacetDefinitionWriter(Writer writer)
writer
- writer to write output topublic String getVertexComponentSeparator()
public void setVertexComponentSeparator(String sep)
sep
- string used to separate vertex componentspublic String getVertexSeparator()
public void setVertexSeparator(String sep)
sep
- string used to separate facet verticespublic int getFacetVertexCount()
-1
if no specific
number is required. The default value is .-1
if any geometricallly
valid number is allowed (ie, any number greater than or equal to 3)public void setFacetVertexCount(int vertexCount)
-1
to allow any geometrically valid number of vertices
(ie, any number greater than or equal to 3).vertexCount
- number of vertices required per facet or -1
to allow any numberIllegalArgumentException
- if the argument would produce invalid geometries (ie, is
greater than -1 and less than 3)public String getCommentToken()
public void setCommentToken(String commentToken)
commentToken
- comment token stringIllegalArgumentException
- if the argument is empty or begins with whitespacepublic void writeComment(String comment)
comment
- comment string to writeIllegalStateException
- if the configured comment token
is nullUncheckedIOException
- if an I/O error occurspublic void writeBlankLine()
UncheckedIOException
- if an I/O error occurspublic void write(BoundarySource3D src)
facet vertex count
has been set to 3
, then each
boundary is converted to triangles before being written. Otherwise, the boundaries are
written as-is.src
- object providing the boundaries to writeIllegalArgumentException
- if any boundary has infinite size or a
facet vertex count
has been configured and a boundary
cannot be represented using the required number of verticesUncheckedIOException
- if an I/O error occurspublic void write(PlaneConvexSubset convexSubset)
facet vertex count
has been set to 3
, then the convex subset
is converted to triangles before being written to the output. Otherwise, the argument
vertices are written as-is.convexSubset
- convex subset to writeIllegalArgumentException
- if the argument has infinite size or a
facet vertex count
has been configured and the number of required
vertices does not match the number present in the argumentUncheckedIOException
- if an I/O error occurspublic void write(FacetDefinition facet)
facet
- facet containing the vertices to writeIllegalArgumentException
- if a facet vertex count
has been configured and the number of required vertices does not match the number
present in the argumentUncheckedIOException
- if an I/O error occurspublic void write(List<Vector3D> vertices)
vertex component separator
and vertices are separated with the
configured vertex separator
.vertices
- vertices to writeIllegalArgumentException
- if the vertex list contains less than 3 vertices or a
facet vertex count
has been configured and the number of required
vertices does not match the number givenUncheckedIOException
- if an I/O error occursgetVertexComponentSeparator()
,
getVertexSeparator()
,
getFacetVertexCount()
public static TextFacetDefinitionWriter csvFormat(Writer writer)
0.0,0.0,0.0,1.0,0.0,0.0,1.0,1.0,0.0 0.0,0.0,0.0,1.0,1.0,0.0,0.0,1.0,0.0
writer
- writer to write output toCopyright © 2016–2021 The Apache Software Foundation. All rights reserved.