Package geomss.geom
Class TriangleList<E extends GeomTriangle>
- java.lang.Object
-
- geomss.geom.AbstractGeomElement<T>
-
- geomss.geom.AbstractGeomList<TriangleList,E>
-
- geomss.geom.TriangleList<E>
-
- Type Parameters:
E
- The type of triangle stored in this list.
- All Implemented Interfaces:
GeomElement<TriangleList>
,GeometryList<TriangleList,E>
,Transformable<TriangleList>
,java.io.Serializable
,java.lang.Cloneable
,java.lang.Comparable
,java.lang.Iterable<E>
,java.util.Collection<E>
,java.util.List<E>
,javolution.lang.Reusable
,javolution.xml.XMLSerializable
public final class TriangleList<E extends GeomTriangle> extends AbstractGeomList<TriangleList,E>
A concrete list ofGeomTriangle
objects. This list is similar to a GeomList, but has methods specifically designed for working with large sets of triangles. All the triangles in a list must have the same physical dimensions.WARNING: This list allows geometry to be stored in different units. If consistent units are required, then the user must specifically convert the list items.
Modified by: Joseph A. Huwaldt
- Version:
- February 17, 2025
- Author:
- Joseph A. Huwaldt, Date: August 28, 2015
- See Also:
- Serialized Form
-
-
Field Summary
-
Fields inherited from class geomss.geom.AbstractGeomElement
RESOURCES
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
add(int index, E value)
Inserts the specifiedGeomTriangle
at the specified position in this list.boolean
addAll(int index, java.util.Collection<? extends E> c)
Inserts all of theGeomTriangle
objects in the specified collection into this list at the specified position.TriangleList<E>
copy()
Returns a copy of thisTriangleList
instanceallocated
by the calling thread (possibly on the stack).TriangleList<Triangle>
copyToReal()
Return a copy of this object with any transformations or subranges removed (applied).Parameter<javax.measure.quantity.Area>
getArea()
Return the total surface area of this list of triangles.int
getPhyDimension()
Returns the number of physical dimensions of this geometry element.TriangleList<E>
getRange(int first, int last)
Returns the range of elements in this list from the specified start and ending indexes.TriangleList<TriangleTrans>
getTransformed(GTransform transform)
Returns transformed version of this element.static TriangleList
newInstance()
Returns a new, empty, preallocated or recycledTriangleList
instance (on the stack when executing in aStackContext
) that can store a list ofGeomTriangle
objects.static TriangleList
newInstance(java.lang.String name)
Returns a new, empty, preallocated or recycledTriangleList
instance (on the stack when executing in aStackContext
) with the specified name, that can store a list ofGeomTriangle
objects.static void
recycle(TriangleList instance)
Recycles a TriangleList instance immediately (on the stack when executing in a StackContext).TriangleList<E>
removeDegenerate(Parameter<javax.measure.quantity.Length> tol)
Return a new triangle list that is identical to this one, but with any degenerate triangles removed.TriangleList<E>
reverse()
Returns an newTriangleList
with the elements in this list in reverse order.E
set(int index, E element)
Replaces theGeomTriangle
at the specified position in this list with the specified element.TriangleList<E>
to(javax.measure.unit.Unit<javax.measure.quantity.Length> unit)
Returns the equivalent to this list but with all the elements stated in the specified unit.TriangleList<E>
toDimension(int newDim)
Return a copy of this list converted to the specified number of physical dimensions.TriangleVertData
toVertData(Parameter<javax.measure.quantity.Length> tol)
Convert this list of Triangle objects into a TriangleVertData structure with a non-repeating (unique) list of vertices, non-degenerate triangles defined by indices into the list of vertices, areas of all the triangles, and normals for all the triangles.static TriangleList<Triangle>
triangulateQuads(PointArray<? extends GeomPoint> quads)
Return a TriangleList containing a simple triangulation of the input array of quadrilateral panels.static <E extends GeomTriangle>
TriangleList<E>valueOf(E... elements)
Return a TriangleList containing theGeomTriangle
objects in the specified array.static <E extends GeomTriangle>
TriangleList<E>valueOf(java.lang.String name, E... elements)
Return a TriangleList containing theGeomTriangle
objects in the specified list.static <E extends GeomTriangle>
TriangleList<E>valueOf(java.lang.String name, java.util.Collection<E> elements)
Return a TriangleList containing theGeomTriangle
objects in the specified collection.static TriangleList<Triangle>
valueOf(java.util.List<? extends GeomPoint> vertices, int[] indexes)
Return a TriangleList containing the triangles-
Methods inherited from class geomss.geom.AbstractGeomList
add, add, add, addAll, addAll, addAll, clear, contains, containsAll, containsGeometry, equals, get, get, getAll, getBoundsMax, getBoundsMin, getFirst, getIndexFromName, getLast, getLimitPoint, getParDimension, getUnit, hashCode, indexOf, isEmpty, isValid, iterator, lastIndexOf, listIterator, listIterator, remove, remove, remove, removeAll, reset, retainAll, size, subList, toArray, toArray, toText, unmodifiableList
-
Methods inherited from class geomss.geom.AbstractGeomElement
addChangeListener, clone, compareTo, getAllUserData, getID, getName, getUserData, putAllUserData, putUserData, removeChangeListener, removeUserData, setName, toString
-
Methods inherited from interface geomss.geom.GeomElement
addChangeListener, getAllUserData, getID, getName, getUserData, putAllUserData, putUserData, removeChangeListener, removeUserData, setName
-
-
-
-
Method Detail
-
newInstance
public static TriangleList newInstance()
Returns a new, empty, preallocated or recycledTriangleList
instance (on the stack when executing in aStackContext
) that can store a list ofGeomTriangle
objects.- Returns:
- A new, empty TriangleList.
-
newInstance
public static TriangleList newInstance(java.lang.String name)
Returns a new, empty, preallocated or recycledTriangleList
instance (on the stack when executing in aStackContext
) with the specified name, that can store a list ofGeomTriangle
objects.- Parameters:
name
- The name to be assigned to this list (may benull
).- Returns:
- A new, empty TriangleList with the specified name.
-
valueOf
public static <E extends GeomTriangle> TriangleList<E> valueOf(java.lang.String name, java.util.Collection<E> elements)
Return a TriangleList containing theGeomTriangle
objects in the specified collection.- Type Parameters:
E
- The type of triangle contained in the returned list of triangles.- Parameters:
name
- The name to be assigned to this list (may benull
).elements
- A collection of triangle elements. May not be null.- Returns:
- A new TriangleList containing the elements in the specified collection.
-
valueOf
public static <E extends GeomTriangle> TriangleList<E> valueOf(java.lang.String name, E... elements)
Return a TriangleList containing theGeomTriangle
objects in the specified list.- Type Parameters:
E
- The type of triangle contained in the returned list of triangles.- Parameters:
name
- The name to be assigned to this list (may benull
).elements
- A list of triangle elements. May not be null.- Returns:
- A new TriangleList containing the elements in the specified list.
-
valueOf
public static <E extends GeomTriangle> TriangleList<E> valueOf(E... elements)
Return a TriangleList containing theGeomTriangle
objects in the specified array.- Type Parameters:
E
- The type of triangle contained in the returned list of triangles.- Parameters:
elements
- An array of triangle elements. May not be null.- Returns:
- A new TriangleList containing the elements in the specified array.
-
valueOf
public static TriangleList<Triangle> valueOf(java.util.List<? extends GeomPoint> vertices, int[] indexes)
Return a TriangleList containing the triangles- Parameters:
vertices
- A list of all the vertices in the list of triangles. May not be null.indexes
- An array of indexes into the vertices list. Each set of 3 consecutive indexes into the vertices list defines a triangle. May not be null.- Returns:
- A new TriangleList containing the elements in the specified collection.
-
triangulateQuads
public static TriangleList<Triangle> triangulateQuads(PointArray<? extends GeomPoint> quads)
Return a TriangleList containing a simple triangulation of the input array of quadrilateral panels. The input quads are triangulated by dividing each quad into two triangles. Any subranges or transforms on the input points is lost by this triangulation.- Parameters:
quads
- An array of quadrilateral panels (defined by a topologically rectangular array of points). May not be null.- Returns:
- A new TriangleList containing a triangulation of the input quads.
-
getPhyDimension
public int getPhyDimension()
Returns the number of physical dimensions of this geometry element. This implementation always returns the physical dimension of the underlyingTriangle
objects or 0 if this list has no Triangle objects in it.- Specified by:
getPhyDimension
in interfaceGeomElement<E extends GeomTriangle>
- Overrides:
getPhyDimension
in classAbstractGeomList<TriangleList,E extends GeomTriangle>
- Returns:
- The number of physical dimensions of this geometry element.
-
getRange
public TriangleList<E> getRange(int first, int last)
Returns the range of elements in this list from the specified start and ending indexes.- Specified by:
getRange
in interfaceGeometryList<TriangleList,E extends GeomTriangle>
- Specified by:
getRange
in classAbstractGeomList<TriangleList,E extends GeomTriangle>
- Parameters:
first
- index of the first element to return (0 returns the 1st element, -1 returns the last, etc).last
- index of the last element to return (0 returns the 1st element, -1 returns the last, etc).- Returns:
- the list of elements in the given range from this list.
- Throws:
java.lang.IndexOutOfBoundsException
- if the given index is out of range:index ≥ size()
-
set
public E set(int index, E element)
Replaces theGeomTriangle
at the specified position in this list with the specified element. Null elements are ignored. The input element must have the same physical dimensions as the other items in this list, or an exception is thrown.- Specified by:
set
in interfacejava.util.List<E extends GeomTriangle>
- Overrides:
set
in classAbstractGeomList<TriangleList,E extends GeomTriangle>
- Parameters:
index
- The index of the element to replace (0 returns the 1st element, -1 returns the last, -2 returns the 2nd from last, etc).element
- The element to be stored at the specified position.null
elements are ignored.- Returns:
- The element previously at the specified position in this list. May not be null.
- Throws:
java.lang.IndexOutOfBoundsException
- - ifindex > size()
DimensionException
- if the input element's dimensions are different from this list's dimensions.
-
add
public void add(int index, E value)
Inserts the specifiedGeomTriangle
at the specified position in this list. Shifts the element currently at that position (if any) and any subsequent elements to the right (adds one to their indices). Null values are ignored. The input element must have the same physical dimensions as the other items in this list, or an exception is thrown.Note: If this method is used concurrent access must be synchronized (the list is not thread-safe).
- Specified by:
add
in interfacejava.util.List<E extends GeomTriangle>
- Overrides:
add
in classAbstractGeomList<TriangleList,E extends GeomTriangle>
- Parameters:
index
- the index at which the specified element is to be inserted. (0 returns the 1st element, -1 returns the last, -2 returns the 2nd from last, etc).value
- The element to be inserted. May not be null.- Throws:
java.lang.IndexOutOfBoundsException
- ifindex > size()
DimensionException
- if the input element's dimensions are different from this list's dimensions.
-
addAll
public boolean addAll(int index, java.util.Collection<? extends E> c)
Inserts all of theGeomTriangle
objects in the specified collection into this list at the specified position. Shifts the element currently at that position (if any) and any subsequent elements to the right (increases their indices). The new elements will appear in this list in the order that they are returned by the specified collection's iterator. The behavior of this operation is unspecified if the specified collection is modified while the operation is in progress. Note that this will occur if the specified collection is this list, and it's nonempty. The input elements must have the same physical dimensions as the other items in this list, or an exception is thrown.- Specified by:
addAll
in interfacejava.util.List<E extends GeomTriangle>
- Overrides:
addAll
in classAbstractGeomList<TriangleList,E extends GeomTriangle>
- Parameters:
index
- index at which to insert first element from the specified collection.c
- Elements to be inserted into this collection. May not be null.- Returns:
true
if this collection changed as a result of the call.- Throws:
DimensionException
- if the input element's dimensions are different from this list's dimensions.
-
reverse
public TriangleList<E> reverse()
Returns an newTriangleList
with the elements in this list in reverse order.- Specified by:
reverse
in interfaceGeometryList<TriangleList,E extends GeomTriangle>
- Specified by:
reverse
in classAbstractGeomList<TriangleList,E extends GeomTriangle>
- Returns:
- A new TriangleList with the elements in this list in reverse order.
-
removeDegenerate
public TriangleList<E> removeDegenerate(Parameter<javax.measure.quantity.Length> tol)
Return a new triangle list that is identical to this one, but with any degenerate triangles removed.- Parameters:
tol
- The tolerance for determining if a triangle is degenerate. A value ofnull
would indicate that exactly zero area is required to be degenerate.- Returns:
- A new triangle list that is identical to this one, but with any degenerate triangles removed.
-
getArea
public Parameter<javax.measure.quantity.Area> getArea()
Return the total surface area of this list of triangles. This is the sum of the area of all the triangles in this list.- Returns:
- The surface area of all the triangles in this list.
-
toDimension
public TriangleList<E> toDimension(int newDim)
Return a copy of this list converted to the specified number of physical dimensions. If the number of dimensions is greater than this element, then zeros are added to the additional dimensions. If the number of dimensions is less than this element, then the extra dimensions are simply dropped (truncated). If the new dimensions are the same as the dimension of this element, then this list is simply returned.- Parameters:
newDim
- The dimension of the element to return.- Returns:
- A copy of this list converted to the new dimensions.
-
to
public TriangleList<E> to(javax.measure.unit.Unit<javax.measure.quantity.Length> unit)
Returns the equivalent to this list but with all the elements stated in the specified unit.- Parameters:
unit
- the length unit of the list to be returned. May not be null.- Returns:
- an equivalent to this list but stated in the specified unit.
- Throws:
javax.measure.converter.ConversionException
- if the the input unit is not a length unit.
-
copy
public TriangleList<E> copy()
Returns a copy of thisTriangleList
instanceallocated
by the calling thread (possibly on the stack).- Returns:
- an identical and independent copy of this object.
-
copyToReal
public TriangleList<Triangle> copyToReal()
Return a copy of this object with any transformations or subranges removed (applied).- Returns:
- A copy of this list with any transformations or subranges removed.
-
getTransformed
public TriangleList<TriangleTrans> getTransformed(GTransform transform)
Returns transformed version of this element. The returned object implementsGeomTransform
and contains transformed versions of the contents of this list as children. Any list elements that are not transformable will simply be added to the output list without transformation.- Parameters:
transform
- The transform to apply to this geometry element. May not be null.- Returns:
- A transformed version of this geometry element.
- Throws:
DimensionException
- if this element is not 3D.
-
toVertData
public TriangleVertData toVertData(Parameter<javax.measure.quantity.Length> tol)
Convert this list of Triangle objects into a TriangleVertData structure with a non-repeating (unique) list of vertices, non-degenerate triangles defined by indices into the list of vertices, areas of all the triangles, and normals for all the triangles. This is handy for converting between this list of triangles and various triangulated file formats.- Parameters:
tol
- The position tolerance used to determine if two vertices are coincident. Passnull
or 0 if all vertices are to be retained.- Returns:
- A TriangleVertData structure with information about the triangles in this list.
-
recycle
public static void recycle(TriangleList instance)
Recycles a TriangleList instance immediately (on the stack when executing in a StackContext).- Parameters:
instance
- The instance to be recycled.
-
-