AXOM
Axom provides a robust, flexible software infrastructure for the development of multi-physics applications and computational tools.
axom::primal::Polyhedron< T, NDIMS > Class Template Reference

Represents a convex polyhedron defined by an array of points and optionally their neighbors (a point is a neighbor of another point if there is an edge between them) More...

#include </home/docs/checkouts/readthedocs.org/user_builds/axom/checkouts/latest/src/axom/primal/geometry/Polyhedron.hpp>

Public Types

using PointType = Point< T, NDIMS >
 
using VectorType = Vector< T, NDIMS >
 
using NumArrayType = NumericArray< T, NDIMS >
 

Public Member Functions

 Polyhedron ()=default
 
AXOM_HOST_DEVICE int numVertices () const
 
AXOM_HOST_DEVICE int addVertex (const PointType &pt)
 Appends a vertex to the list of vertices. More...
 
AXOM_HOST_DEVICE void addNeighbors (const PointType &pt, std::initializer_list< std::int8_t > nbrs)
 Stores nbrs as the neighbors of vertex pt. If vertex pt is not in the polyhedron, neighbors are not added. More...
 
AXOM_HOST_DEVICE void addNeighbors (int vtxId, std::initializer_list< std::int8_t > nbrs)
 Stores nbrs as the neighbors of vertex at a given index. More...
 
AXOM_HOST_DEVICE void addNeighbors (int vtxId, int nbr)
 Adds a single nbr as the neighbor of vertex at a given index. More...
 
AXOM_HOST_DEVICE void clear ()
 
CoordsgetVertices ()
 
AXOM_HOST_DEVICE PointTypeoperator[] (int idx)
 
AXOM_HOST_DEVICE const PointTypeoperator[] (int idx) const
 
AXOM_HOST_DEVICE NeighborsgetNeighbors ()
 
AXOM_HOST_DEVICE int getNumNeighbors (int i) const
 
AXOM_HOST_DEVICE Neighbors::VertexNbrsgetNeighbors (int i)
 
AXOM_HOST_DEVICE const Neighbors::VertexNbrsgetNeighbors (int i) const
 
AXOM_HOST_DEVICE PointType centroid () const
 Computes the centroid as the average of the polyhedron's vertex positions. More...
 
AXOM_HOST_DEVICE void getFaces (int *faces, int *face_size, int *face_offset, int &face_count) const
 Helper function to find the faces of the Polyhedron, assuming the vertex neighbors are in counter-clockwise ordering. More...
 
AXOM_HOST_DEVICE double signedVolume () const
 Computes the signed volume of the polyhedron. More...
 
AXOM_HOST_DEVICE double volume () const
 Returns the absolute (unsigned) volume of the polyhedron. More...
 
std::ostream & print (std::ostream &os) const
 Simple formatted print of a polyhedron instance. More...
 
AXOM_HOST_DEVICE bool isValid () const
 Simple check for validity of a polyhedron. More...
 
AXOM_HOST_DEVICE bool hasDuplicateVertices (double eps=1.e-10) const
 Check if any vertices are duplicate, within a tolerance. More...
 
AXOM_HOST_DEVICE bool hasNeighbors () const
 Check if vertex neighbors information is available. More...
 

Static Public Member Functions

static AXOM_HOST_DEVICE Polyhedron from_primitive (const Hexahedron< T, NDIMS > &hex, bool tryFixOrientation=false)
 Creates a Polyhedron from a given Hexahedron's vertices. More...
 
static AXOM_HOST_DEVICE Polyhedron from_primitive (const Octahedron< T, NDIMS > &oct, bool tryFixOrientation=false)
 Creates a Polyhedron from a given Octahedron's vertices. More...
 
static AXOM_HOST_DEVICE Polyhedron from_primitive (const Tetrahedron< T, NDIMS > &tet, bool tryFixOrientation=false)
 Creates a Polyhedron from a given Tetrahedron's vertices. More...
 

Static Public Attributes

constexpr static int MAX_VERTS = NeighborCollection::MAX_VERTS
 

Detailed Description

template<typename T, int NDIMS = 3>
class axom::primal::Polyhedron< T, NDIMS >

Represents a convex polyhedron defined by an array of points and optionally their neighbors (a point is a neighbor of another point if there is an edge between them)

Template Parameters
Tthe coordinate type, e.g., double, float, etc.
NDIMSthe number of dimensions
Note
The Polyhedron functions do not check that points defining a face are coplanar. It is the responsibility of the caller to pass a valid set of points and neighbors representing a convex polyhedron.
The polyhedron neighbors should be ordered counter clockwise as when viewing the polyhedron externally.

         3--------2          +y
        /|       /|
       / |      / |           ^
      7--------6  |           |
      |  0-----|--1           |
      | /      | /            -----> +x
      |/       |/            /
      4--------5            /
                           <
                          +z

      

For example, vertex 5 above should have neighbors (4,1,6).

Note
The Polyhedron functions do not check that neighbors are ordered counter clockwise. It is the responsibility of the caller to pass a valid neighbors ordering.

Member Typedef Documentation

◆ PointType

template<typename T , int NDIMS = 3>
using axom::primal::Polyhedron< T, NDIMS >::PointType = Point<T, NDIMS>

◆ VectorType

template<typename T , int NDIMS = 3>
using axom::primal::Polyhedron< T, NDIMS >::VectorType = Vector<T, NDIMS>

◆ NumArrayType

template<typename T , int NDIMS = 3>
using axom::primal::Polyhedron< T, NDIMS >::NumArrayType = NumericArray<T, NDIMS>

Constructor & Destructor Documentation

◆ Polyhedron()

template<typename T , int NDIMS = 3>
axom::primal::Polyhedron< T, NDIMS >::Polyhedron ( )
default

Default constructor for an empty polyhedron

Member Function Documentation

◆ numVertices()

template<typename T , int NDIMS = 3>
AXOM_HOST_DEVICE int axom::primal::Polyhedron< T, NDIMS >::numVertices ( ) const
inline

Return the number of vertices in the polyhedron

◆ addVertex()

template<typename T , int NDIMS = 3>
AXOM_HOST_DEVICE int axom::primal::Polyhedron< T, NDIMS >::addVertex ( const PointType pt)
inline

Appends a vertex to the list of vertices.

Returns
The index where the vertex was inserted into.

References axom::primal::Polyhedron< T, NDIMS >::MAX_VERTS, and SLIC_ASSERT.

◆ addNeighbors() [1/3]

template<typename T , int NDIMS = 3>
AXOM_HOST_DEVICE void axom::primal::Polyhedron< T, NDIMS >::addNeighbors ( const PointType pt,
std::initializer_list< std::int8_t >  nbrs 
)
inline

Stores nbrs as the neighbors of vertex pt. If vertex pt is not in the polyhedron, neighbors are not added.

Note
pt should be a vertex of this polyhedron. Otherwise, pt may not be found due to floating point precision differences.
Parameters
[in]ptThe vertex to add neighbors
[in]nbrsThe neighbors to add to the list of neighbors

References axom::primal::NeighborCollection::addNeighbors().

◆ addNeighbors() [2/3]

template<typename T , int NDIMS = 3>
AXOM_HOST_DEVICE void axom::primal::Polyhedron< T, NDIMS >::addNeighbors ( int  vtxId,
std::initializer_list< std::int8_t >  nbrs 
)
inline

Stores nbrs as the neighbors of vertex at a given index.

Note
Caller is responsible for ensuring a given vertex has enough space remaining to fit the new neighbors.
Parameters
[in]vtxIdThe vertex id to add neighbors
[in]nbrsThe neighbors to add to the list of neighbors
Precondition
vtxId < getVertices()

References axom::primal::NeighborCollection::addNeighbors().

◆ addNeighbors() [3/3]

template<typename T , int NDIMS = 3>
AXOM_HOST_DEVICE void axom::primal::Polyhedron< T, NDIMS >::addNeighbors ( int  vtxId,
int  nbr 
)
inline

Adds a single nbr as the neighbor of vertex at a given index.

Note
Caller is responsible for ensuring a given vertex has enough space remaining to fit the new neighbor.
Parameters
[in]vtxIdThe vertex id to add the neighbor
[in]nbrThe neighbor to add to the list of neighbors
Precondition
vtxId < getVertices()

References axom::primal::NeighborCollection::addNeighbors().

◆ clear()

template<typename T , int NDIMS = 3>
AXOM_HOST_DEVICE void axom::primal::Polyhedron< T, NDIMS >::clear ( )
inline

Clears the list of vertices and neighbors

References axom::primal::NeighborCollection::clear().

◆ getVertices()

template<typename T , int NDIMS = 3>
Coords& axom::primal::Polyhedron< T, NDIMS >::getVertices ( )
inline

Retrieves the vertices

◆ operator[]() [1/2]

template<typename T , int NDIMS = 3>
AXOM_HOST_DEVICE PointType& axom::primal::Polyhedron< T, NDIMS >::operator[] ( int  idx)
inline

Retrieves the vertex at index idx

◆ operator[]() [2/2]

template<typename T , int NDIMS = 3>
AXOM_HOST_DEVICE const PointType& axom::primal::Polyhedron< T, NDIMS >::operator[] ( int  idx) const
inline

Retrieves the vertex at index idx

◆ getNeighbors() [1/3]

template<typename T , int NDIMS = 3>
AXOM_HOST_DEVICE Neighbors& axom::primal::Polyhedron< T, NDIMS >::getNeighbors ( )
inline

Retrieves the neighbors

◆ getNumNeighbors()

template<typename T , int NDIMS = 3>
AXOM_HOST_DEVICE int axom::primal::Polyhedron< T, NDIMS >::getNumNeighbors ( int  i) const
inline

◆ getNeighbors() [2/3]

template<typename T , int NDIMS = 3>
AXOM_HOST_DEVICE Neighbors::VertexNbrs& axom::primal::Polyhedron< T, NDIMS >::getNeighbors ( int  i)
inline

Retrieves the neighbors for vertex i

◆ getNeighbors() [3/3]

template<typename T , int NDIMS = 3>
AXOM_HOST_DEVICE const Neighbors::VertexNbrs& axom::primal::Polyhedron< T, NDIMS >::getNeighbors ( int  i) const
inline

Retrieves the neighbors for vertex i

◆ centroid()

template<typename T , int NDIMS = 3>
AXOM_HOST_DEVICE PointType axom::primal::Polyhedron< T, NDIMS >::centroid ( ) const
inline

Computes the centroid as the average of the polyhedron's vertex positions.

Returns
The centroid of the polyhedron's vertices
Precondition
polyhedron.isValid() is true

References axom::primal::Polyhedron< T, NDIMS >::isValid(), axom::primal::Polyhedron< T, NDIMS >::numVertices(), and SLIC_ASSERT.

◆ getFaces()

template<typename T , int NDIMS = 3>
AXOM_HOST_DEVICE void axom::primal::Polyhedron< T, NDIMS >::getFaces ( int *  faces,
int *  face_size,
int *  face_offset,
int &  face_count 
) const
inline

Helper function to find the faces of the Polyhedron, assuming the vertex neighbors are in counter-clockwise ordering.

Parameters
[out]facesis the vertex indices for faces
[out]face_offsetis the offset for each face
[out]face_sizeis the number of vertices for each face
[out]face_countis the number of faces
Warning
Function is experimental, input parameters and/or output may change in the future.
Note
This function does not check that the provided buffers are large enough to hold all values. It is the responsibility of the caller to know ahead of time and pass buffers with appropriate size.
Function is based off extractFaces() in Mike Owen's PolyClipper.
Precondition
polyhedron vertex neighbors are defined

References axom::primal::NeighborCollection::getNumNeighbors(), axom::primal::Polyhedron< T, NDIMS >::MAX_VERTS, and axom::primal::Polyhedron< T, NDIMS >::numVertices().

◆ signedVolume()

template<typename T , int NDIMS = 3>
AXOM_HOST_DEVICE double axom::primal::Polyhedron< T, NDIMS >::signedVolume ( ) const
inline

Computes the signed volume of the polyhedron.

Returns
The signed volume of the polyhedron
Note
Function is based off moments() in Mike Owen's PolyClipper.
Precondition
polyhedron vertex neighbors are defined, and polyhedron is 3D
See also
volume()

References axom::primal::Polyhedron< T, NDIMS >::getFaces(), axom::primal::Polyhedron< T, NDIMS >::hasDuplicateVertices(), axom::primal::Polyhedron< T, NDIMS >::hasNeighbors(), axom::primal::Polyhedron< T, NDIMS >::isValid(), axom::primal::Polyhedron< T, NDIMS >::MAX_VERTS, axom::primal::Vector< T, NDIMS >::scalar_triple_product(), and SLIC_CHECK_MSG.

◆ volume()

template<typename T , int NDIMS = 3>
AXOM_HOST_DEVICE double axom::primal::Polyhedron< T, NDIMS >::volume ( ) const
inline

Returns the absolute (unsigned) volume of the polyhedron.

See also
signedVolume()

References axom::utilities::abs(), and axom::primal::Polyhedron< T, NDIMS >::signedVolume().

◆ print()

template<typename T , int NDIMS = 3>
std::ostream& axom::primal::Polyhedron< T, NDIMS >::print ( std::ostream &  os) const
inline

Simple formatted print of a polyhedron instance.

Parameters
osThe output stream to write to
Returns
A reference to the modified ostream

References axom::primal::Polyhedron< T, NDIMS >::getNeighbors(), axom::primal::NeighborCollection::getNumNeighbors(), axom::primal::Polyhedron< T, NDIMS >::hasNeighbors(), and axom::primal::Polyhedron< T, NDIMS >::numVertices().

◆ isValid()

template<typename T , int NDIMS = 3>
AXOM_HOST_DEVICE bool axom::primal::Polyhedron< T, NDIMS >::isValid ( ) const
inline

Simple check for validity of a polyhedron.

Initial check is that the polyhedron has four or more vertices

Returns
True, if the polyhedron is valid, False otherwise

◆ hasDuplicateVertices()

template<typename T , int NDIMS = 3>
AXOM_HOST_DEVICE bool axom::primal::Polyhedron< T, NDIMS >::hasDuplicateVertices ( double  eps = 1.e-10) const
inline

Check if any vertices are duplicate, within a tolerance.

Parameters
[in]epsThe tolerance
Returns
True, if the polyhedron has duplicate vertices, False otherwise

References axom::utilities::isNearlyEqual().

◆ hasNeighbors()

template<typename T , int NDIMS = 3>
AXOM_HOST_DEVICE bool axom::primal::Polyhedron< T, NDIMS >::hasNeighbors ( ) const
inline

Check if vertex neighbors information is available.

Checks if neighbors is not empty

Returns
True, if the polyhedron has neighbors info for each vertex, False otherwise

References axom::primal::NeighborCollection::getNumNeighbors().

◆ from_primitive() [1/3]

template<typename T , int NDIMS = 3>
static AXOM_HOST_DEVICE Polyhedron axom::primal::Polyhedron< T, NDIMS >::from_primitive ( const Hexahedron< T, NDIMS > &  hex,
bool  tryFixOrientation = false 
)
inlinestatic

Creates a Polyhedron from a given Hexahedron's vertices.

Parameters
[in]hexThe hexahedron
[in]tryFixOrientationIf true, checks if the signed volume of the Polyhedron is negative and swaps the order of some vertices in that shape to try to obtain a nonnegative signed volume. Defaults to false.
Returns
A Polyhedron with the Hexahedron's vertices and added vertex neighbors
Note
The Hexahedron is assumed to have a specific vertex order:
*
*          4--------7          +z
*         /|       /|               +y
*        / |      / |           ^  >
*       5--------6  |           | /
*       |  0-----|--3           |/
*       | /      | /            -----> +x
*       |/       |/
*       1--------2
*
* 
  The Polyhedron's vertex neighbors are created assuming this vertex
  ordering.
Warning
tryFixOrientation flag does not guarantee the Polyhedron's vertex order will be valid. It is the responsiblity of the caller to pass a Hexahedron with a valid vertex order. Otherwise, if the Hexahedron has an invalid vertex order, the returned Polyhedron will have a non-positive and/or unexpected volume.
If tryFixOrientation flag is false and some of the shapes have a negative signed volume, the returned Polyhedron will have a non-positive and/or unexpected volume.

References axom::primal::Polyhedron< T, NDIMS >::addNeighbors(), axom::primal::Polyhedron< T, NDIMS >::addVertex(), and axom::primal::Polyhedron< T, NDIMS >::signedVolume().

◆ from_primitive() [2/3]

template<typename T , int NDIMS = 3>
static AXOM_HOST_DEVICE Polyhedron axom::primal::Polyhedron< T, NDIMS >::from_primitive ( const Octahedron< T, NDIMS > &  oct,
bool  tryFixOrientation = false 
)
inlinestatic

Creates a Polyhedron from a given Octahedron's vertices.

Parameters
[in]octThe octahedron
[in]tryFixOrientationIf true, checks if the signed volume of the Polyhedron is negative and swaps the order of some vertices in that shape to try to obtain a nonnegative signed volume. Defaults to false.
Returns
A Polyhedron with the Octahedron's vertices and added vertex neighbors
Note
The Octahedron is assumed to have a specific vertex order: (view looking down from +z axis):
*
*            4                +z
*            /\                    +y
*       0 --/  \-- 2           ^  >
*         \/    \ /            | /
*         /      \             |/
*       5 -------- 3           -----> +x
*            \/
*            1
*
* 
  The Polyhedron's vertex neighbors are created assuming this vertex
  ordering.
Warning
tryFixOrientation flag does not guarantee the Polyhedron's vertex order will be valid. It is the responsiblity of the caller to pass an Octahedron with a valid vertex order. Otherwise, if the Octahedron has an invalid vertex order, the returned Polyhedron will have a non-positive and/or unexpected volume.
If tryFixOrientation flag is false and some of the shapes have a negative signed volume, the returned Polyhedron will have a non-positive and/or unexpected volume.

References axom::primal::Polyhedron< T, NDIMS >::addNeighbors(), axom::primal::Polyhedron< T, NDIMS >::addVertex(), and axom::primal::Polyhedron< T, NDIMS >::signedVolume().

◆ from_primitive() [3/3]

template<typename T , int NDIMS = 3>
static AXOM_HOST_DEVICE Polyhedron axom::primal::Polyhedron< T, NDIMS >::from_primitive ( const Tetrahedron< T, NDIMS > &  tet,
bool  tryFixOrientation = false 
)
inlinestatic

Creates a Polyhedron from a given Tetrahedron's vertices.

Parameters
[in]tetThe tetrahedron
[in]tryFixOrientationIf true, checks if the signed volume of the Polyhedron is negative and swaps the order of some vertices in that shape to try to obtain a nonnegative signed volume. Defaults to false.
Returns
A Polyhedron with the Tetrahedron's vertices and added vertex neighbors
Note
The Tetrahedron is assumed to have a specific vertex order:
*
*              3                    +z
*             / \\                       +y
*            /   \ \                 ^  >
*           /     \  \               | /
*          /       \   \             |/
*         /         \    2           -----> +x
*        /           \  /
*       /_____________\/
*      0               1
*
* 
  The Polyhedron's vertex neighbors are created assuming this vertex
  ordering.
Warning
tryFixOrientation flag does not guarantee the Polyhedron's vertex order will be valid. It is the responsiblity of the caller to pass a Tetrahedron with a valid vertex order. Otherwise, if the Tetrahedron has an invalid vertex order, the returned Polyhedron will have a non-positive and/or unexpected volume.
If tryFixOrientation flag is false and some of the shapes have a negative signed volume, the returned Polyhedron will have a non-positive and/or unexpected volume.

References axom::primal::Polyhedron< T, NDIMS >::addNeighbors(), axom::primal::Polyhedron< T, NDIMS >::addVertex(), and axom::primal::Tetrahedron< T, NDIMS >::signedVolume().

Member Data Documentation

◆ MAX_VERTS

template<typename T , int NDIMS = 3>
constexpr static int axom::primal::Polyhedron< T, NDIMS >::MAX_VERTS = NeighborCollection::MAX_VERTS
staticconstexpr

The documentation for this class was generated from the following file: