Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/axom/core/utilities/Utilities.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,16 @@ inline AXOM_HOST_DEVICE bool isNearlyEqualRelative(RealType a,
// return abs(a-b) <= max(absThresh, relThresh * maxFabs );
}

/*!
* \brief Sign of a value of any type that supports comparison and
* negation operators.
*/
template <typename T>
inline int sign_of(const T& v, const T& eps = {0})
{
return v > eps ? 1 : v < -eps ? -1 : 0;
}

/*!
* \brief Insertion sort of an array.
* \accelerated
Expand Down
2 changes: 1 addition & 1 deletion src/axom/klee/Geometry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ void Geometry::populateGeomInfo()
m_discreteFunction = axom::Array<double, 2>(2, 2);
m_discreteFunction(0, 0) = 0.0;
m_discreteFunction(0, 1) = cone.getBaseRadius();
m_discreteFunction(1, 1) = cone.getLength();
m_discreteFunction(1, 0) = cone.getLength();
m_discreteFunction(1, 1) = cone.getTopRadius();
m_geomInfo["discreteFunction"].set(m_discreteFunction.data(), m_discreteFunction.size());
m_geomInfo["sorOrigin"].set(cone.getBaseCenter().data(), 3);
Expand Down
3 changes: 2 additions & 1 deletion src/axom/primal/geometry/Cone.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,8 @@ class Cone
}

/*!
* \brief Returns the algebraic volume of the cone
* \brief Returns the algebraic volume of the cone,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please write "signed volume" instead of "algebraic volume". We say "signed volume" elsewhere (such as in Tetrahedron).

* which is negative if the length is negative.
*
* Volume is only defined when NDIMS == 3.
*/
Expand Down
10 changes: 10 additions & 0 deletions src/axom/primal/geometry/CoordinateTransformer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,16 @@ class CoordinateTransformer
*/
CoordinateTransformer(const numerics::Matrix<T>& matrix) { setMatrix(matrix); }

/*!
* @brief Contruct transformer that moves 4 starting points to 4
* destination points.
*/
AXOM_HOST_DEVICE CoordinateTransformer(const primal::Point<T, 3>* startPts,
const primal::Point<T, 3>* destPts)
{
setByTerminusPts(startPts, destPts);
}

/*!
* @brief Set the matrix, discarding the current transformation.
* @param matrix [in] The transformation matrix for homogeneous
Expand Down
20 changes: 20 additions & 0 deletions src/axom/primal/geometry/Sphere.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,18 @@ class Sphere
AXOM_HOST_DEVICE
inline bool intersectsWith(const Sphere<T, NDIMS>& sphere, double TOL = 1.e-9) const;

/*!
* \brief Tests if this sphere completely contains another sphere.
*
* \param [in] other The sphere object to check for containment
* \param [in] margin Amount that this sphere must contain the other sphere by.
* Positive means that the other sphere is "more inside".
*
* \return true if this sphere contains the other, false otherwise.
*/
AXOM_HOST_DEVICE
inline bool contains(const Sphere<T, NDIMS>& other, double margin = 0.0) const;

/*!
* \brief Prints the Sphere information in the given output stream.
* \param [in,out] os the output stream to write to.
Expand Down Expand Up @@ -233,6 +245,14 @@ AXOM_HOST_DEVICE inline bool Sphere<T, NDIMS>::intersectsWith(const Sphere<T, ND
utilities::isNearlyEqual(distance_squared, sum_of_radii_2, TOL));
}

//------------------------------------------------------------------------------
template <typename T, int NDIMS>
AXOM_HOST_DEVICE inline bool Sphere<T, NDIMS>::contains(const Sphere<T, NDIMS>& sphere, double TOL) const
{
const T center_sep = VectorType(sphere.getCenter(), m_center).norm();
return (m_radius > center_sep + sphere.getRadius() + TOL);
}

//------------------------------------------------------------------------------
// implementation of free functions
//------------------------------------------------------------------------------
Expand Down
32 changes: 32 additions & 0 deletions src/axom/primal/tests/primal_sphere.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,31 @@ void check_sphere_intersection()
EXPECT_FALSE(S0.intersectsWith(S3));
}

//------------------------------------------------------------------------------
template <int NDIMS>
void check_sphere_containment()
{
using PointType = primal::Point<double, NDIMS>;
using SphereType = primal::Sphere<double, NDIMS>;

PointType center {0.0, 0.0, 0.0};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please also test this on spheres that are not centered at the origin

double tol = 1e-12;

// STEP 0: test fully containing
SphereType S0;
EXPECT_TRUE(S0.contains(S0, -tol));

// STEP 1: test barely not containing.
center[0] = tol;
SphereType S1(center);
EXPECT_FALSE(S0.contains(S1));

// STEP 2: test partial containment.
center[0] = 0.5;
SphereType S3(center);
EXPECT_FALSE(S0.contains(S3));
}

//------------------------------------------------------------------------------
template <int NDIMS>
void check_copy_constructor()
Expand Down Expand Up @@ -244,6 +269,13 @@ TEST(primal_sphere, sphere_sphere_intersection)
check_sphere_intersection<3>();
}

//------------------------------------------------------------------------------
TEST(primal_sphere, sphere_sphere_containment)
{
check_sphere_containment<2>();
check_sphere_containment<3>();
}

//------------------------------------------------------------------------------
int main(int argc, char* argv[])
{
Expand Down
5 changes: 4 additions & 1 deletion src/axom/quest/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -150,11 +150,14 @@ if(AXOM_ENABLE_KLEE AND AXOM_ENABLE_SIDRE)
if(RAJA_FOUND)
list(APPEND quest_headers MeshClipper.hpp
MeshClipperStrategy.hpp
detail/clipping/Plane3DClipper.hpp
detail/clipping/TetClipper.hpp
detail/clipping/MeshClipperImpl.hpp)
list(APPEND quest_sources MeshClipper.cpp
MeshClipperStrategy.cpp
detail/clipping/Plane3DClipper.cpp
detail/clipping/TetClipper.cpp
MeshClipperStrategy.cpp)
detail/clipping/MeshClipperImpl.hpp)
endif()
endif()

Expand Down
4 changes: 3 additions & 1 deletion src/axom/quest/Discretize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ OctType new_inscribed_oct(const SphereType& sphere, OctType& o, int s, int t, in
*
* This routine allocates an array pointed to by \a out. The caller is responsible
* to free the array.
*
* TODO: If possible, port to GPU (rewrite to be data-parallel).
*/
bool discretize(const SphereType& sphere, int levels, axom::Array<OctType>& out, int& octcount)
{
Expand All @@ -125,7 +127,7 @@ bool discretize(const SphereType& sphere, int levels, axom::Array<OctType>& out,

octcount = count_sphere_octahedra(levels);

out = axom::Array<OctType>(octcount, octcount);
out.resize(octcount);

// index points to an octahedron of the last generation. We'll generate
// new octahedra based on out[index].
Expand Down
3 changes: 2 additions & 1 deletion src/axom/quest/Discretize.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ bool discretize(const SphereType& s, int levels, axom::Array<OctType>& out, int&
/*!
* \brief Given a 2D polyline revolved around the positive X-axis, allocate
* and return a list of Octahedra approximating the shape.
* \param [in] polyline The polyline to revolve around the X-axis
* \param [in] polyline The polyline to revolve around the X-axis.
* Data should be in a host-accessible memory space.
* \param [in] len The number of points in \a polyline
* \param [in] levels The number of refinements to perform, in addition to
* a central level-zero octahedron in each segment
Expand Down
1 change: 0 additions & 1 deletion src/axom/quest/InOutOctree.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
#include "axom/slic.hpp"
#include "axom/slam.hpp"
#include "axom/primal.hpp"
#include "axom/mint.hpp"
#include "axom/spin.hpp"

#include "detail/inout/BlockData.hpp"
Expand Down
13 changes: 8 additions & 5 deletions src/axom/quest/IntersectionShaper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -825,6 +825,7 @@ class IntersectionShaper : public Shaper

// Generate the Octahedra
// (octahedra m_octs will be on device)
m_octs = axom::Array<OctahedronType>(0, 0, axom::execution_space<ExecSpace>::allocatorID());
const bool disc_status =
axom::quest::discretize<ExecSpace>(polyline, polyline_size, m_level, m_octs, m_octcount);

Expand Down Expand Up @@ -1967,13 +1968,15 @@ class IntersectionShaper : public Shaper
if(m_bpGrp)
{
auto fieldsGrp = m_bpGrp->getGroup("fields");
SLIC_ERROR_IF(fieldsGrp == nullptr, "Input blueprint mesh lacks the 'fields' Group/Node.");
for(auto& group : fieldsGrp->groups())
if(fieldsGrp != nullptr)
{
std::string materialName = fieldNameToMaterialName(group.getName());
if(!materialName.empty())
for(auto& group : fieldsGrp->groups())
{
materialNames.emplace_back(materialName);
std::string materialName = fieldNameToMaterialName(group.getName());
if(!materialName.empty())
{
materialNames.emplace_back(materialName);
}
}
}
}
Expand Down
Loading