Skip to content

Commit

Permalink
Merge pull request #1212 from LLNL/feature/han12/intersection_improve…
Browse files Browse the repository at this point in the history
…ments

Intersection-based Primal improvements
  • Loading branch information
bmhan12 committed Nov 15, 2023
2 parents cb4cc02 + 84fb6e9 commit e4acf4a
Show file tree
Hide file tree
Showing 11 changed files with 418 additions and 266 deletions.
15 changes: 10 additions & 5 deletions RELEASE-NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,16 @@ The Axom project release numbers follow [Semantic Versioning](http://semver.org/

## [Unreleased] - Release date yyyy-mm-dd

### Added
- Primal: Adds a `Quadrilateral` primitive
- Primal: Adds a `compute_bounding_box()` operator for computing the bounding
box of a `Quadrilateral`
- Primal: Adds a `clip()` operator for clipping a tetrahedron against the
half-space defined by a plane
- Primal: Adds a `checkAndFixOrientation()` function to `primal::Tetrahedron`
that swaps the order of vertices if the signed volume of the Tetrahedron is
negative, resulting in the signed volume becoming positive.

### Changed
- `MarchingCubes` and `DistributedClosestPoint` classes changed from requiring the Blueprint
coordset name to requiring the Blueprint topology name. The changed interface methods are:
Expand All @@ -31,11 +41,6 @@ The Axom project release numbers follow [Semantic Versioning](http://semver.org/
returns the signed volume.
- Primal: `intersection_volume()` operators changed from returning a signed
volume to an unsigned volume.
- Primal: Adds a `Quadrilateral` primitive
- Primal: Adds a `compute_bounding_box()` operator for computing the bounding
box of a `Quadrilateral`
- Primal: Adds a `clip()` operator for clipping a tetrahedron against the
half-space defined by a plane

### Fixed
- quest's `SamplingShaper` now properly handles material names containing underscores
Expand Down
6 changes: 3 additions & 3 deletions src/axom/primal/examples/hex_tet_volume.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ void check_intersection_volumes(const Input& params)
// reduce the number of operations.
RAJA::ReduceSum<REDUCE_POL, double> total_intersect_vol(0.0);
constexpr double EPS = 1e-10;
constexpr bool checkSign = true;
constexpr bool tryFixOrientation = true;

// The lower of the two sizes (NUM_HEXES, NUM_TETS) is used to factor out
// every pair of hexahedron and tetrahedron indices.
Expand All @@ -251,7 +251,7 @@ void check_intersection_volumes(const Input& params)
total_intersect_vol += intersection_volume(hexes_view[i / NUM_TETS],
tets_view[i % NUM_TETS],
EPS,
checkSign);
tryFixOrientation);
});
}
else
Expand All @@ -262,7 +262,7 @@ void check_intersection_volumes(const Input& params)
total_intersect_vol += intersection_volume(hexes_view[i % NUM_HEXES],
tets_view[i / NUM_HEXES],
EPS,
checkSign);
tryFixOrientation);
});
}

Expand Down
228 changes: 126 additions & 102 deletions src/axom/primal/geometry/Polyhedron.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -669,40 +669,48 @@ class Polyhedron
}

/*!
* \brief Creates a Polyhedron from a given Hexahedron's vertices.
*
* \param [in] hex The hexahedron
* \param [in] checkSign If true (default is false), checks if the
* signed volume of the Polyhedron is positive. If signed volume
* is negative, order of some vertices will be swapped.
*
* \return A Polyhedron with the Hexahedron's vertices and added
* vertex neighbors
*
* \note The Hexahedron is assumed to have a specific vertex order:
* \verbatim
*
* 4--------7 +z
* /| /| +y
* / | / | ^ >
* 5--------6 | | /
* | 0-----|--3 |/
* | / | / -----> +x
* |/ |/
* 1--------2
*
* \endverbatim
*
* The Polyhedron's vertex neighbors are created assuming this vertex
* ordering.
*
* \note checkSign 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.
*/
* \brief Creates a Polyhedron from a given Hexahedron's vertices.
*
* \param [in] hex The hexahedron
* \param [in] tryFixOrientation If 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.
*
* \return A Polyhedron with the Hexahedron's vertices and added
* vertex neighbors
*
* \note The Hexahedron is assumed to have a specific vertex order:
* \verbatim
*
* 4--------7 +z
* /| /| +y
* / | / | ^ >
* 5--------6 | | /
* | 0-----|--3 |/
* | / | / -----> +x
* |/ |/
* 1--------2
*
* \endverbatim
*
* 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.
*
* \warning 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.
*
*/
AXOM_HOST_DEVICE
static Polyhedron from_primitive(const Hexahedron<T, NDIMS>& hex,
bool checkSign = false)
bool tryFixOrientation = false)
{
// Initialize our polyhedron to return
Polyhedron<T, NDIMS> poly;
Expand All @@ -726,7 +734,7 @@ class Polyhedron
poly.addNeighbors(7, {3, 4, 6});

// Reverses order of vertices 1,3 and 5,7 if signed volume is negative
if(checkSign)
if(tryFixOrientation)
{
if(poly.signedVolume() < 0)
{
Expand All @@ -739,42 +747,50 @@ class Polyhedron
}

/*!
* \brief Creates a Polyhedron from a given Octahedron's vertices.
*
* \param [in] oct The octahedron
* \param [in] checkSign If true (default is false), checks if the
* signed volume of the Polyhedron is positive. If signed volume
* is negative, order of some vertices will be swapped.
*
* \return 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):
*
* \verbatim
*
* 4 +z
* /\ +y
* 0 --/ \-- 2 ^ >
* \/ \ / | /
* / \ |/
* 5 -------- 3 -----> +x
* \/
* 1
*
* \endverbatim
*
* The Polyhedron's vertex neighbors are created assuming this vertex
* ordering.
*
* \note checkSign flag does not guarantee the Polyhedron's vertex order
* will be valid. It is the responsiblity of the caller to pass
* a Octahedron with a valid vertex order.
*/
* \brief Creates a Polyhedron from a given Octahedron's vertices.
*
* \param [in] oct The octahedron
* \param [in] tryFixOrientation If 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.
*
* \return 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):
*
* \verbatim
*
* 4 +z
* /\ +y
* 0 --/ \-- 2 ^ >
* \/ \ / | /
* / \ |/
* 5 -------- 3 -----> +x
* \/
* 1
*
* \endverbatim
*
* 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.
*
* \warning 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.
*
*/
AXOM_HOST_DEVICE
static Polyhedron from_primitive(const Octahedron<T, NDIMS>& oct,
bool checkSign = false)
bool tryFixOrientation = false)
{
// Initialize our polyhedron to return
Polyhedron<T, NDIMS> poly;
Expand All @@ -794,7 +810,7 @@ class Polyhedron
poly.addNeighbors(5, {0, 1, 3, 4});

// Reverses order of vertices 1,2 and 4,5 if volume is negative.
if(checkSign)
if(tryFixOrientation)
{
if(poly.signedVolume() < 0)
{
Expand All @@ -807,41 +823,49 @@ class Polyhedron
}

/*!
* \brief Creates a Polyhedron from a given Tetrahedron's vertices.
*
* \param [in] tet The tetrahedron
* \param [in] checkSign If true (default is false), checks if the
* signed volume of the Polyhedron is positive. If signed volume
* is negative, order of some vertices will be swapped.
*
* \return A Polyhedron with the Tetrahedron's vertices and added
* vertex neighbors
*
* \note The Tetrahedron is assumed to have a specific vertex order:
* \verbatim
*
* 3 +z
* / \\ +y
* / \ \ ^ >
* / \ \ | /
* / \ \ |/
* / \ 2 -----> +x
* / \ /
* /_____________\/
* 0 1
*
* \endverbatim
*
* The Polyhedron's vertex neighbors are created assuming this vertex
* ordering.
*
* \note checkSign 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.
*/
* \brief Creates a Polyhedron from a given Tetrahedron's vertices.
*
* \param [in] tet The tetrahedron
* \param [in] tryFixOrientation If 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.
*
* \return A Polyhedron with the Tetrahedron's vertices and added
* vertex neighbors
*
* \note The Tetrahedron is assumed to have a specific vertex order:
* \verbatim
*
* 3 +z
* / \\ +y
* / \ \ ^ >
* / \ \ | /
* / \ \ |/
* / \ 2 -----> +x
* / \ /
* /_____________\/
* 0 1
*
* \endverbatim
*
* 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.
*
* \warning 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.
*
*/
AXOM_HOST_DEVICE
static Polyhedron from_primitive(const Tetrahedron<T, NDIMS>& tet,
bool checkSign = false)
bool tryFixOrientation = false)
{
// Initialize our polyhedron to return
Polyhedron<T, NDIMS> poly;
Expand All @@ -857,7 +881,7 @@ class Polyhedron
poly.addNeighbors(3, {0, 1, 2});

// Reverses order of vertices 1 and 2 if signed volume is negative
if(checkSign)
if(tryFixOrientation)
{
if(tet.signedVolume() < 0)
{
Expand Down
14 changes: 14 additions & 0 deletions src/axom/primal/geometry/Tetrahedron.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,20 @@ class Tetrahedron
AXOM_HOST_DEVICE
double volume() const { return axom::utilities::abs(signedVolume()); }

/*!
* \brief Swaps the order of vertices if the signed volume of the
* tetrahedron is negative. Signed volume will become positive.
* \sa signedVolume()
*/
AXOM_HOST_DEVICE
void checkAndFixOrientation()
{
if(signedVolume() < 0)
{
axom::utilities::swap<PointType>(m_points[1], m_points[2]);
}
}

/**
* \brief Returns the circumsphere (circumscribing sphere) of the tetrahedron
*
Expand Down

0 comments on commit e4acf4a

Please sign in to comment.