Class ObjWriter.MeshBuffer
java.lang.Object
org.apache.commons.geometry.io.euclidean.threed.obj.ObjWriter.MeshBuffer
- Enclosing class:
ObjWriter
Class used to produce OBJ mesh content from sequences of facets. As facets are added to the buffer
their vertices and normals are converted to OBJ vertex and normal definition strings. Vertices and normals
that produce equal definition strings are shared among all of the facets in the buffer. This process
converts the facet sequence into a compact mesh suitable for writing as OBJ file content.
Ideally, no vertices or normals would be duplicated in an OBJ file. However, when working with very large
geometries it may not be desirable to store values in memory before writing to the output. This
is where the batchSize property comes into play. The batchSize represents the maximum
number of faces that the buffer will store before automatically flushing its contents to the output and
resetting its state. This reduces the amount of memory used by the buffer at the cost of increasing the
likelihood of duplicate vertices and/or normals in the output.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final intMaximum number of faces that will be stored in the buffer before automatically flushing.Map of local face indices to their local normal index.private final List<int[]> List of local face vertex indices.Map of vertex normals to their local index.Map of vertex definition strings to their local index. -
Constructor Summary
ConstructorsConstructorDescriptionMeshBuffer(int batchSize) Construct a new mesh buffer instance with the given batch size. -
Method Summary
Modifier and TypeMethodDescriptionvoidadd(PlaneConvexSubset boundary) Add a boundary to this buffer.voidadd(FacetDefinition facet) Add a facet to this buffer.private voidAdd a face to the buffer.intAdd a normal to the buffer.private intConvert the given vector to on OBJ definition string and add it to the map if not yet present.intAdd a vertex to the buffer.voidflush()Flush the buffer content to the output and reset its state.private voidreset()Reset the buffer state.
-
Field Details
-
batchSize
private final int batchSizeMaximum number of faces that will be stored in the buffer before automatically flushing. -
vertexMap
-
normalMap
-
faceVertices
List of local face vertex indices. -
faceToNormalMap
-
-
Constructor Details
-
MeshBuffer
MeshBuffer(int batchSize) Construct a new mesh buffer instance with the given batch size.- Parameters:
batchSize- batch size; set to -1 to indicate an unlimited size
-
-
Method Details
-
add
Add a facet to this buffer. IfbatchSizeis greater than-1and the number of currently stored faces is greater than or equal tobatchSize, then the buffer content is written to the output and the buffer state is reset.- Parameters:
facet- facet to add- Throws:
UncheckedIOException- if an I/O error occurs
-
add
Add a boundary to this buffer. IfbatchSizeis greater than-1and the number of currently stored faces is greater than or equal tobatchSize, then the buffer content is written to the output and the buffer state is reset.- Parameters:
boundary- boundary to add- Throws:
IllegalArgumentException- if the boundary is infiniteUncheckedIOException- if an I/O error occurs
-
addVertex
Add a vertex to the buffer.- Parameters:
vertex- vertex to add- Returns:
- the index of the vertex in the buffer
-
addNormal
Add a normal to the buffer.- Parameters:
normal- normal to add- Returns:
- the index of the normal in the buffer
-
flush
public void flush()Flush the buffer content to the output and reset its state.- Throws:
UncheckedIOException- if an I/O error occurs
-
addToMap
Convert the given vector to on OBJ definition string and add it to the map if not yet present. The mapped index of the vector is returned.- Parameters:
vec- vector to addmap- map to add the vector to- Returns:
- the index the vector entry is mapped to
-
addFace
Add a face to the buffer. IfbatchSizeis greater than-1and the number of currently stored faces is greater than or equal tobatchSize, then the buffer content is written to the output and the buffer state is reset.- Parameters:
vertices- face verticesnormal- face normal; may be null- Throws:
UncheckedIOException- if an I/O error occurs
-
reset
private void reset()Reset the buffer state.
-