Class SimpleTriangleMesh
java.lang.Object
org.apache.commons.geometry.euclidean.threed.mesh.SimpleTriangleMesh
- All Implemented Interfaces:
BoundarySource<PlaneConvexSubset>,BoundarySource3D,Linecastable3D,Mesh<TriangleMesh.Face>,TriangleMesh
A simple implementation of the
TriangleMesh interface. This class ensures that
faces always contain 3 valid references into the vertex list but does not enforce that
the referenced vertices are unique or that they define a triangle with non-zero size. For
example, a mesh could contain a face with 3 vertices that are considered equivalent by the
configured precision context. Attempting to call the TriangleMesh.Face.getPolygon()
method on such a face results in an exception. The
Mesh.Face.definesPolygon() method can be used to determine if a face defines
a valid triangle.
Instances of this class are guaranteed to be immutable.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classBuilder class for creating mesh instances.private final classInternal class for iterating through the mesh faces and extracting a value from each.private static final classComparator used to sort vectors using non-strict ("fuzzy") comparisons.private final classInternal implementation ofTriangleMesh.Face.Nested classes/interfaces inherited from interface org.apache.commons.geometry.euclidean.threed.mesh.TriangleMesh
TriangleMesh.Face -
Field Summary
Fields -
Constructor Summary
ConstructorsModifierConstructorDescriptionprivateSimpleTriangleMesh(List<Vector3D> vertices, List<int[]> faces, Bounds3D bounds, org.apache.commons.numbers.core.Precision.DoubleEquivalence precision) Construct a new instance from a vertex list and set of faces. -
Method Summary
Modifier and TypeMethodDescriptionReturn a stream containing the boundaries for this instance.static SimpleTriangleMesh.Builderbuilder(org.apache.commons.numbers.core.Precision.DoubleEquivalence precision) Return a builder for creating new triangle mesh objects.private <T> Stream<T> Create a stream containing the results of applyingfnto each face in the mesh.faces()Get an iterable containing all faces in the mesh.static SimpleTriangleMeshfrom(Collection<Vector3D> vertices, Collection<int[]> faces, org.apache.commons.numbers.core.Precision.DoubleEquivalence precision) Construct a new triangle mesh from the given vertices and face indices.static SimpleTriangleMeshfrom(BoundarySource3D boundarySrc, org.apache.commons.numbers.core.Precision.DoubleEquivalence precision) Construct a new mesh instance containing all triangles from the given boundary source.static SimpleTriangleMeshfrom(Vector3D[] vertices, int[][] faces, org.apache.commons.numbers.core.Precision.DoubleEquivalence precision) Construct a new triangle mesh from the given vertices and face indices.Get aBounds3Dobject defining the axis-aligned box containing all vertices in the boundaries for this instance.getFace(int index) Get a face from the mesh by its index.intGet the number of faces in the mesh.getFaces()Get a list containing all faces in the mesh.org.apache.commons.numbers.core.Precision.DoubleEquivalenceGet the precision context for the mesh.intGet the number of vertices in the mesh.Get a list containing all vertices in the mesh.toString()toTriangleMesh(org.apache.commons.numbers.core.Precision.DoubleEquivalence meshPrecision) Return this instance if the given precision context is equal to the current precision context.Return a new, transformed mesh by applying the given transform to all vertices.Return the boundaries of this instance as a stream ofTriangle3Dinstances.vertices()Get an iterable containing the vertices in the mesh.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface org.apache.commons.geometry.euclidean.threed.BoundarySource3D
linecast, linecastFirst, toList, toTreeMethods inherited from interface org.apache.commons.geometry.euclidean.threed.line.Linecastable3D
linecast, linecastFirst
-
Field Details
-
vertices
Vertices in the mesh. -
faces
Faces in the mesh. -
bounds
The bounds of the mesh. -
precision
private final org.apache.commons.numbers.core.Precision.DoubleEquivalence precisionObject used for floating point comparisons.
-
-
Constructor Details
-
SimpleTriangleMesh
private SimpleTriangleMesh(List<Vector3D> vertices, List<int[]> faces, Bounds3D bounds, org.apache.commons.numbers.core.Precision.DoubleEquivalence precision) Construct a new instance from a vertex list and set of faces. No validation is performed on the input.- Parameters:
vertices- vertex listfaces- face indices listbounds- mesh boundsprecision- precision context used when creating face polygons
-
-
Method Details
-
vertices
Get an iterable containing the vertices in the mesh.- Specified by:
verticesin interfaceMesh<TriangleMesh.Face>- Returns:
- an iterable containing the vertices in the mesh
-
getVertices
Get a list containing all vertices in the mesh.- Specified by:
getVerticesin interfaceMesh<TriangleMesh.Face>- Returns:
- a list containing all vertices in the mesh
-
getVertexCount
public int getVertexCount()Get the number of vertices in the mesh.- Specified by:
getVertexCountin interfaceMesh<TriangleMesh.Face>- Returns:
- the number of vertices in the mesh
-
faces
Get an iterable containing all faces in the mesh.- Specified by:
facesin interfaceMesh<TriangleMesh.Face>- Returns:
- an iterable containing all faces in the mesh
-
getFaces
Get a list containing all faces in the mesh.- Specified by:
getFacesin interfaceMesh<TriangleMesh.Face>- Returns:
- a list containing all faces in the mesh
-
getFaceCount
public int getFaceCount()Get the number of faces in the mesh.- Specified by:
getFaceCountin interfaceMesh<TriangleMesh.Face>- Returns:
- the number of faces in the mesh
-
getFace
Get a face from the mesh by its index.- Specified by:
getFacein interfaceMesh<TriangleMesh.Face>- Parameters:
index- the index of the mesh to retrieve- Returns:
- the face at the given index
-
getBounds
Get aBounds3Dobject defining the axis-aligned box containing all vertices in the boundaries for this instance. Null is returned if any boundary is infinite or no vertices are found.- Specified by:
getBoundsin interfaceBoundarySource3D- Returns:
- the bounding box for this instance or null if no valid bounds could be determined
-
getPrecision
public org.apache.commons.numbers.core.Precision.DoubleEquivalence getPrecision()Get the precision context for the mesh. This context is used during construction of faceTriangle3Dinstances.- Returns:
- the precision context for the mesh
-
boundaryStream
Return a stream containing the boundaries for this instance.- Specified by:
boundaryStreamin interfaceBoundarySource<PlaneConvexSubset>- Returns:
- a stream containing the boundaries for this instance
-
triangleStream
Return the boundaries of this instance as a stream ofTriangle3Dinstances. AnIllegalStateExceptionexception is thrown while reading from the stream if any boundary cannot be converted to a triangle (i.e. if it has infinite size).- Specified by:
triangleStreamin interfaceBoundarySource3D- Returns:
- a stream of triangles representing the instance boundaries
- See Also:
-
transform
Return a new, transformed mesh by applying the given transform to all vertices. Faces and vertex ordering are not affected.- Specified by:
transformin interfaceMesh<TriangleMesh.Face>- Specified by:
transformin interfaceTriangleMesh- Parameters:
transform- transform to apply- Returns:
- a new, transformed mesh
-
toTriangleMesh
public SimpleTriangleMesh toTriangleMesh(org.apache.commons.numbers.core.Precision.DoubleEquivalence meshPrecision) Return this instance if the given precision context is equal to the current precision context. Otherwise, create a new mesh with the given precision context but the same vertices, faces, and bounds.- Specified by:
toTriangleMeshin interfaceBoundarySource3D- Parameters:
meshPrecision- precision context to use when generating face polygons- Returns:
- a mesh instance with the given precision context and the same mesh structure as the current instance
-
toString
-
createFaceStream
Create a stream containing the results of applyingfnto each face in the mesh.- Type Parameters:
T- Stream element type- Parameters:
fn- function used to extract the stream values from each face- Returns:
- a stream containing the results of applying
fnto each face in the mesh
-
builder
public static SimpleTriangleMesh.Builder builder(org.apache.commons.numbers.core.Precision.DoubleEquivalence precision) Return a builder for creating new triangle mesh objects.- Parameters:
precision- precision object used for floating point comparisons- Returns:
- a builder for creating new triangle mesh objects
-
from
public static SimpleTriangleMesh from(Vector3D[] vertices, int[][] faces, org.apache.commons.numbers.core.Precision.DoubleEquivalence precision) Construct a new triangle mesh from the given vertices and face indices.- Parameters:
vertices- vertices for the meshfaces- face indices for the meshprecision- precision context used for floating point comparisons- Returns:
- a new triangle mesh 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 vertex list
-
from
public static SimpleTriangleMesh from(Collection<Vector3D> vertices, Collection<int[]> faces, org.apache.commons.numbers.core.Precision.DoubleEquivalence precision) Construct a new triangle mesh from the given vertices and face indices.- Parameters:
vertices- vertices for the meshfaces- face indices for the meshprecision- precision context used for floating point comparisons- Returns:
- a new triangle mesh 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 vertex list
-
from
public static SimpleTriangleMesh from(BoundarySource3D boundarySrc, org.apache.commons.numbers.core.Precision.DoubleEquivalence precision) Construct a new mesh instance containing all triangles from the given boundary source. Equivalent vertices are reused wherever possible.- Parameters:
boundarySrc- boundary source to construct a mesh fromprecision- precision context used for floating point comparisons- Returns:
- new mesh instance containing all triangles from the given boundary source
- Throws:
IllegalStateException- if any boundary in the boundary source has infinite size and cannot be converted to triangles
-