Class SimpleTriangleMesh.Builder
java.lang.Object
org.apache.commons.geometry.euclidean.threed.mesh.SimpleTriangleMesh.Builder
- Enclosing class:
SimpleTriangleMesh
Builder class for creating mesh instances.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final Bounds3D.Builder
Object used to construct the 3D bounds of the vertex list.private boolean
Flag set to true once a mesh is constructed from this builder.private final ArrayList
<int[]> List of face vertex indices.private final org.apache.commons.numbers.core.Precision.DoubleEquivalence
Precision context used for floating point comparisons; this value may be null if vertices are not to be combined in this builder.Map of vertices to their first occurrence in the vertex list.List of vertices. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprivate
Builder
(org.apache.commons.numbers.core.Precision.DoubleEquivalence precision) Construct a new builder. -
Method Summary
Modifier and TypeMethodDescriptionaddFace
(int[] face) Append a face to this mesh.addFace
(int index1, int index2, int index3) Append a face to this mesh.addFaceAndVertices
(Vector3D p1, Vector3D p2, Vector3D p3) Add a face and its vertices to this mesh.addFaces
(int[][] faceIndices) Append a group of faces to this mesh.addFaces
(Collection<int[]> faceIndices) Append a group of faces to this mesh.addFaceUsingVertices
(Vector3D p1, Vector3D p2, Vector3D p3) Add a face to this mesh, only adding vertices to the vertex list if equivalent vertices are not found.private int
addToVertexIndexMap
(Vector3D vertex, int targetIdx, Map<? super Vector3D, Integer> map) Add a vertex to the given vertex index map.private int
addToVertexList
(Vector3D vertex) Append the given vertex to the end of the vertex list.int
Add a vertex directly to the vertex list, returning the index of the added vertex.addVertices
(Collection<? extends Vector3D> newVertices) Add a group of vertices directly to the vertex list.addVertices
(Vector3D[] newVertices) Add a group of vertices directly to the vertex list.build()
Build a triangle mesh containing the vertices and faces in this builder.ensureFaceCapacity
(int numFaces) Ensure that this instance has enough capacity to store at leastnumFaces
number of faces without reallocating space.ensureVertexCapacity
(int numVertices) Ensure that this instance has enough capacity to store at leastnumVertices
number of vertices without reallocating space.int
Get the current number of faces in this mesh.getVertex
(int index) Get the vertex at the given index.int
Get the current number of vertices in this mesh.Get the vertex index map, creating and initializing it if needed.int
Use a vertex in the constructed mesh.private void
Throw an exception if the builder has been used to construct a mesh instance and can no longer be modified.private int
validateVertexIndex
(int idx) Throw an exception if the given vertex index is not valid.
-
Field Details
-
vertices
List of vertices. -
vertexIndexMap
Map of vertices to their first occurrence in the vertex list. -
faces
List of face vertex indices. -
boundsBuilder
Object used to construct the 3D bounds of the vertex list. -
precision
private final org.apache.commons.numbers.core.Precision.DoubleEquivalence precisionPrecision context used for floating point comparisons; this value may be null if vertices are not to be combined in this builder. -
built
private boolean builtFlag set to true once a mesh is constructed from this builder.
-
-
Constructor Details
-
Builder
private Builder(org.apache.commons.numbers.core.Precision.DoubleEquivalence precision) Construct a new builder.- Parameters:
precision
- precision context used for floating point comparisons; may be null if vertices are not to be combined in this builder.
-
-
Method Details
-
useVertex
Use a vertex in the constructed mesh. If an equivalent vertex already exist, as determined by the configuredPrecision.DoubleEquivalence
, then the index of the previously added vertex is returned. Otherwise, the given vertex is added to the vertex list and the index of the new entry is returned. This is in contrast with theaddVertex(Vector3D)
, which always adds a new entry to the vertex list.- Parameters:
vertex
- vertex to use- Returns:
- the index of the added vertex or an equivalent vertex that was added previously
- See Also:
-
addVertex
Add a vertex directly to the vertex list, returning the index of the added vertex. The vertex is added regardless of whether or not an equivalent vertex already exists in the list. This is in contrast with theuseVertex(Vector3D)
method, which only adds a new entry to the vertex list if an equivalent one does not already exist.- Parameters:
vertex
- the vertex to append- Returns:
- the index of the appended vertex in the vertex list
-
addVertices
Add a group of vertices directly to the vertex list. No equivalent vertices are reused.- Parameters:
newVertices
- vertices to append- Returns:
- this instance
- See Also:
-
addVertices
Add a group of vertices directly to the vertex list. No equivalent vertices are reused.- Parameters:
newVertices
- vertices to append- Returns:
- this instance
- See Also:
-
ensureVertexCapacity
Ensure that this instance has enough capacity to store at leastnumVertices
number of vertices without reallocating space. This can be used to help improve performance and memory usage when creating meshes with large numbers of vertices.- Parameters:
numVertices
- the number of vertices to ensure that this instance can contain- Returns:
- this instance
-
getVertexCount
public int getVertexCount()Get the current number of vertices in this mesh.- Returns:
- the current number of vertices in this mesh
-
getVertex
Get the vertex at the given index.- Parameters:
index
- index of the vertex to retrieve- Returns:
- vertex at the given index
- Throws:
IndexOutOfBoundsException
- if the index is out of bounds of the mesh vertex list
-
addFace
Append a face to this mesh.- Parameters:
index1
- index of the first vertex in the faceindex2
- index of the second vertex in the faceindex3
- index of the third vertex in the face- Returns:
- this instance
- Throws:
IllegalArgumentException
- if any of the arguments is not a valid index into the current vertex list
-
addFace
Append a face to this mesh.- Parameters:
face
- array containing the 3 vertex indices defining the face- Returns:
- this instance
- Throws:
IllegalArgumentException
- ifface
does not contain exactly 3 elements or if any of the vertex indices is not a valid index into the current vertex list
-
addFaces
Append a group of faces to this mesh.- Parameters:
faceIndices
- faces to append- Returns:
- this instance
- Throws:
IllegalArgumentException
- if any of the face index arrays does not have exactly 3 elements or if any index is not a valid index into the current vertex list
-
addFaces
Append a group of faces to this mesh.- Parameters:
faceIndices
- faces to append- Returns:
- this instance
- Throws:
IllegalArgumentException
- if any of the face index arrays does not have exactly 3 elements or if any index is not a valid index into the current vertex list
-
addFaceUsingVertices
Add a face to this mesh, only adding vertices to the vertex list if equivalent vertices are not found.- Parameters:
p1
- first face vertexp2
- second face vertexp3
- third face vertex- Returns:
- this instance
- See Also:
-
addFaceAndVertices
Add a face and its vertices to this mesh. The vertices are always added to the vertex list, regardless of whether or not equivalent vertices exist in the vertex list.- Parameters:
p1
- first face vertexp2
- second face vertexp3
- third face vertex- Returns:
- this instance
- See Also:
-
ensureFaceCapacity
Ensure that this instance has enough capacity to store at leastnumFaces
number of faces without reallocating space. This can be used to help improve performance and memory usage when creating meshes with large numbers of faces.- Parameters:
numFaces
- the number of faces to ensure that this instance can contain- Returns:
- this instance
-
getFaceCount
public int getFaceCount()Get the current number of faces in this mesh.- Returns:
- the current number of faces in this meshr
-
build
Build a triangle mesh containing the vertices and faces in this builder.- Returns:
- a triangle mesh containing the vertices and faces in this builder
-
getVertexIndexMap
Get the vertex index map, creating and initializing it if needed.- Returns:
- the vertex index map
-
addToVertexIndexMap
Add a vertex to the given vertex index map. The vertex is inserted and mapped totargetidx
if an equivalent vertex does not already exist. The index now associated with the given vertex or its equivalent is returned.- Parameters:
vertex
- vertex to addtargetIdx
- the index to associate with the vertex if no equivalent vertex has already been mappedmap
- vertex index map- Returns:
- the index now associated with the given vertex or its equivalent
-
addToVertexList
Append the given vertex to the end of the vertex list. The index of the vertex is returned.- Parameters:
vertex
- the vertex to append- Returns:
- the index of the appended vertex
-
validateVertexIndex
private int validateVertexIndex(int idx) Throw an exception if the given vertex index is not valid.- Parameters:
idx
- vertex index to validate- Returns:
- the validated index
- Throws:
IllegalArgumentException
- if the given index is not a valid index into the vertices list
-
validateCanModify
private void validateCanModify()Throw an exception if the builder has been used to construct a mesh instance and can no longer be modified.
-