Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
13e007d
Added sectorArea() to BezierCurve, CurvedPolygon class with area func…
davidgunderman Jul 17, 2019
c2e5479
Added some helper functions in BezierCurve and CurvedPolygon
davidgunderman Jul 23, 2019
20a135b
Added more CurvedPolygon tests
davidgunderman Jul 23, 2019
4bf7636
More curved polygon tests
davidgunderman Jul 24, 2019
23fcc1c
Added tolerances to CurvedPolygon functions, unit tests for area, dt …
davidgunderman Jul 25, 2019
151835c
Improves documentation, error checking and testing of binomialCoeffic…
kennyweiss Jul 26, 2019
d4c3337
Makes Matrix's default constructor public
kennyweiss Jul 26, 2019
beab6f8
Refactors and tests the BezierCurve sectorArea() weights calculation
kennyweiss Jul 26, 2019
13b1544
Reworks memoization of BezierCurve::sectorArea() matrices
kennyweiss Jun 11, 2021
e628052
Added sectorMoment() to BezierCurve, moment() to CurvedPolygon, tests…
davidgunderman Jul 26, 2019
f5daa38
Build system: Adds missing openmp and/or mpi dependency to quest test…
kennyweiss Jul 29, 2019
0b203fe
Added reverseorientation functions to BezierCurve and CurvedPolygon c…
davidgunderman Aug 16, 2019
55d8649
Renamed sectorMoment to sectorCentroid in BezierCurve class and tweak…
davidgunderman Aug 27, 2019
0a456e0
More tolerance tweaking
davidgunderman Sep 18, 2019
35ff2a0
Reformatted tests for CurvedPolygon
davidgunderman Sep 30, 2019
feed77e
Added/refactored some CurvedPolygon tests
davidgunderman Oct 1, 2019
4611077
Bugfixes for curved polygon tests in MSVC
kennyweiss Oct 8, 2019
6e1c302
primal's BezierCurve::dt should return a Vector rather than a Point
kennyweiss Oct 8, 2019
a73c6cd
Minor updates to CurvedPolygon
kennyweiss Oct 8, 2019
638f85f
Fixes warnings from clang compiler
kennyweiss Jun 12, 2021
6e84b7f
Minor cleanup for BezierCurve and CurvedPolygon classes and tests
kennyweiss Jun 12, 2021
2d6cc60
Use initializer lists to construct points and vectors for Bezier curv…
kennyweiss Jun 12, 2021
eeec51e
Bugfix: Curved polygon with only two edges can be closed
kennyweiss Jun 15, 2021
e680f86
Adds empty() and boundingBox() to primal::CurvedPolygon
kennyweiss Jun 20, 2021
62fc789
Includes axom/config.hpp in primal's intersect header
kennyweiss Jun 20, 2021
1446ba9
Renamed `primal::Polygon::centroid()` to `primal::Polygon::vertexMean()`
kennyweiss Nov 23, 2021
ad93e45
Use axom::Array in primal::Polygon instead of std::vector
kennyweiss Nov 23, 2021
2c18c8e
Outsources moment computation (area and centroid) in BezierCurve and …
kennyweiss Nov 23, 2021
c4ea106
Adds linear interpolation `lerp` function to axom utilities
kennyweiss Nov 23, 2021
b65b41b
Outsources implementation details for compute_sector and compute_area…
kennyweiss Nov 23, 2021
28cb69c
Opt: perform in-place BezierCurve::reverseOrientation()
kennyweiss Nov 25, 2021
8ea7ee5
Opt: perform in-place CurvedPolygon::reverseOrientation()
kennyweiss Nov 25, 2021
f9edc6e
Slight clean up of `primal::CurvedPolygon::isClosed()`
kennyweiss Nov 25, 2021
a8850ac
BezierCurve intersection only works in 2D, so remove NDIMS template p…
kennyweiss Nov 29, 2021
312326b
Updates copyright year
Jan 13, 2022
c699374
Updates RELEASE-NOTES
kennyweiss Jun 17, 2022
f59b94c
Minor changes per PR suggestions
kennyweiss Jun 22, 2022
7dca106
Minor clarifications to README
kennyweiss Jun 22, 2022
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
2 changes: 2 additions & 0 deletions .mailmap
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@ Benjamin Curtice Corbett <corbett5@llnl.gov> Benjamin Corbett <corbett5@llnl.
Benjamin Curtice Corbett <corbett5@llnl.gov> Ben Corbett <32752943+corbett5@users.noreply.github.com>
Brian Manh Hien Han <han12@llnl.gov> Brian Han <han12@llnl.gov>
Brian Manh Hien Han <han12@llnl.gov> Brian Manh Hien Han <han12@rzansel19.coral.llnl.gov>
Brian T.N. Gunney <gunney1@llnl.gov> Brian Gunney <45609916+gunney1@users.noreply.github.com>
Chris White <white238@llnl.gov> Christopher A. White <white238@llnl.gov>
Cyrus D. Harrison <harrison37@llnl.gov> Cyrus Harrison <cyrush@llnl.gov>
Cyrus D. Harrison <harrison37@llnl.gov> Cyrus Harrison <harrison37@llnl.gov>
Cyrus D. Harrison <harrison37@llnl.gov> Cyrus <cyrush@llnl.gov>
Daniel Taller <taller1@llnl.gov> Danny Taller <66029857+dtaller@users.noreply.github.com>
Esteban Pauli <pauli2@llnl.gov> Esteban Pauli <40901502+estebanpauli@users.noreply.github.com>
Evan Taylor Desantola <desantola1@llnl.gov> Evan Taylor DeSantola <desantola1@llnl.gov>
George Zagaris <zagaris2@llnl.gov> George Zagaris <george.zagaris@gmail.com>
Expand Down
5 changes: 5 additions & 0 deletions RELEASE-NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ The Axom project release numbers follow [Semantic Versioning](http://semver.org/
- Adds an overload to quest's `SignedDistance` query to return the closest point on the surface
to the query point and the surface normal at that point. Also exposes this functionality
in quest's signed_distance C API.
- Adds utility function for linear interpolation (`lerp`) of two numbers
- Adds utility function to compute binomial coefficients
- Adds a `CurvedPolygon` class to primal representing a polygon with `BezierCurves` as edges
- Adds functions to compute the moments (area, centroid) of a `CurvedPolygon`

### Changed
- Axom now requires C++14 and will default to that if not specified via `BLT_CXX_STD`.
Expand Down Expand Up @@ -140,6 +144,7 @@ The Axom project release numbers follow [Semantic Versioning](http://semver.org/
and added a new derived class `sidre::IndexedCollection`
- Spin: `BVH::findPoints/Rays/BoundingBoxes()` candidate search methods now accept an `axom::ArrayView<IndexType>`
for the `offsets` and `counts` output arrays, and return `candidates` as an `axom::Array<IndexType>`.
- Renamed `primal::Polygon::centroid()` to `primal::Polygon::vertexMean()` because it was not actually computing the centroid.

### Fixed
- Fixed a bug relating to swap and assignment operations for multidimensional `axom::Array`s
Expand Down
11 changes: 5 additions & 6 deletions src/axom/core/numerics/Matrix.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,11 @@ template <typename T>
class Matrix
{
public:
/*!
* \brief Default constructor
*/
Matrix() : m_rows(0), m_cols(0), m_data(nullptr), m_usingExternal(false) { }

/*!
* \brief Constructor, creates a Matrix with the given rows and columns.
*
Expand Down Expand Up @@ -527,12 +532,6 @@ class Matrix
/// @}

private:
/*!
* \brief Default constructor. Does nothing.
* \note Made private to prevent host-code from calling this.
*/
Matrix() : m_rows(0), m_cols(0), m_data(nullptr) {};

/// \name Private Helper Methods
/// @{

Expand Down
136 changes: 136 additions & 0 deletions src/axom/core/tests/utils_utilities.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,3 +158,139 @@ TEST(utils_utilities, floor_ceil)
EXPECT_EQ(-5.0, axom::utilities::ceil(val));
}
}

//------------------------------------------------------------------------------
TEST(utils_utilities, binomial_coefficient)
{
std::cout << "Testing binomial coefficient function." << std::endl;

// test n less than zero
{
const int n = -1;
const int exp = 0;
for(int k = -1; k < 10; ++k)
{
auto binom_k_n = axom::utilities::binomialCoefficient(n, k);
EXPECT_EQ(exp, binom_k_n);
}
}

// test n := 0
{
const int n = 0;

EXPECT_EQ(1, axom::utilities::binomialCoefficient(n, 0));

EXPECT_EQ(0, axom::utilities::binomialCoefficient(n, -1));
EXPECT_EQ(0, axom::utilities::binomialCoefficient(n, 1));
}

// test n := 1
{
const int n = 1;

EXPECT_EQ(0, axom::utilities::binomialCoefficient(n, -1));

EXPECT_EQ(1, axom::utilities::binomialCoefficient(n, 0));
EXPECT_EQ(1, axom::utilities::binomialCoefficient(n, 1));

EXPECT_EQ(0, axom::utilities::binomialCoefficient(n, 2));
}

// test n := 2
{
const int n = 2;

EXPECT_EQ(1, axom::utilities::binomialCoefficient(n, 0));
EXPECT_EQ(2, axom::utilities::binomialCoefficient(n, 1));
EXPECT_EQ(1, axom::utilities::binomialCoefficient(n, 2));
}

// test n := 3
{
const int n = 3;

EXPECT_EQ(1, axom::utilities::binomialCoefficient(n, 0));
EXPECT_EQ(3, axom::utilities::binomialCoefficient(n, 1));
EXPECT_EQ(3, axom::utilities::binomialCoefficient(n, 2));
EXPECT_EQ(1, axom::utilities::binomialCoefficient(n, 3));
}

// test n := 4
{
const int n = 4;

EXPECT_EQ(1, axom::utilities::binomialCoefficient(n, 0));
EXPECT_EQ(4, axom::utilities::binomialCoefficient(n, 1));
EXPECT_EQ(6, axom::utilities::binomialCoefficient(n, 2));
EXPECT_EQ(4, axom::utilities::binomialCoefficient(n, 3));
EXPECT_EQ(1, axom::utilities::binomialCoefficient(n, 4));
}

// test recurrence relation nCk = (n-1)C(k-1) + (n-1)C(k)
{
for(int n = 1; n < 10; ++n)
{
for(int k = 1; k <= n; ++k)
{
auto binom_n_k = axom::utilities::binomialCoefficient(n, k);
auto binom_n1_k1 = axom::utilities::binomialCoefficient(n - 1, k - 1);
auto binom_n1_k = axom::utilities::binomialCoefficient(n - 1, k);

EXPECT_EQ(binom_n_k, binom_n1_k1 + binom_n1_k);
}
}
}
}

TEST(utils_utilities, lerp)
{
std::cout << "Testing lerp function." << std::endl;

{
double A = 0.;
double B = 1.;

EXPECT_DOUBLE_EQ(0., axom::utilities::lerp(A, B, 0.));
EXPECT_DOUBLE_EQ(1., axom::utilities::lerp(A, B, 1.));
EXPECT_DOUBLE_EQ(.5, axom::utilities::lerp(A, B, .5));

for(double t = -2.0; t < 2.0; t += 0.05)
{
EXPECT_DOUBLE_EQ(t, axom::utilities::lerp(A, B, t));
}
}

// Test endpoint interpolation
{
const double lower = -.23; // Arbitrary end points
const double upper = 5.73;
for(int i = 0; i < 100; ++i)
{
double A = axom::utilities::random_real(lower, upper);
double B = axom::utilities::random_real(lower, upper);

EXPECT_DOUBLE_EQ(A, axom::utilities::lerp(A, B, 0.));
EXPECT_DOUBLE_EQ(B, axom::utilities::lerp(B, A, 0.));
EXPECT_DOUBLE_EQ(B, axom::utilities::lerp(A, B, 1.));
EXPECT_DOUBLE_EQ(A, axom::utilities::lerp(B, A, 1.));
}
}

// Compute using different form
{
const double lower = -.23; // Arbitrary end points
const double upper = 5.73;
for(int i = 0; i < 100; ++i)
{
double A = axom::utilities::random_real(lower, upper);
double B = axom::utilities::random_real(lower, upper);

// Test interpolation and also extrapolation beyond endpoints.
double t = axom::utilities::random_real(-1.5, 1.5);

double exp = A + (B - A) * t;
EXPECT_NEAR(exp, axom::utilities::lerp(A, B, t), 1e-12);
}
}
}
27 changes: 25 additions & 2 deletions src/axom/core/utilities/Utilities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
// SPDX-License-Identifier: (BSD-3-Clause)

/*!
*
* \file
* \file Utilities.cpp
*
* \brief Implementation file for utility functions.
*
Expand Down Expand Up @@ -39,5 +38,29 @@ void processAbort()
#endif
}

int binomialCoefficient(int n, int k)
{
if(k > n || k < 0) // check if out-of-bounds
{
return 0;
}
if(k == n || k == 0) // early return
{
return 1;
}
if(k > n - k) // exploit symmetry to reduce work
{
k = n - k;
}

int val = 1;
for(int i = 1; i <= k; ++i)
{
val *= (n - k + i);
val /= i;
}
return val;
}

} // end namespace utilities
} // end namespace axom
17 changes: 17 additions & 0 deletions src/axom/core/utilities/Utilities.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,15 @@ inline AXOM_HOST_DEVICE void swap(T& a, T& b)
b = tmp;
}

/*!
* \brief returns the linear interpolation of \a A and \a B at \a t. i.e. (1-t)A+tB
*/
template <typename T>
inline AXOM_HOST_DEVICE T lerp(T A, T B, T t)
{
return (1 - t) * A + t * B;
}

/*!
* \brief Returns the base 2 logarithm of the input.
* \param [in] val The input value
Expand Down Expand Up @@ -163,6 +172,14 @@ inline AXOM_HOST_DEVICE T clampLower(T val, T lower)
return val < lower ? lower : val;
}

/*!
* \brief Computes the binomial coefficient `n choose k`
*
* \return \f$ {n\choose k} = n! / (k! * (n-k)!)\f$
* when \f$ n \ge k \ge 0 \f$, 0 otherwise.
*/
int binomialCoefficient(int n, int k);

/*!
* \brief Returns a random real number within the specified interval
*
Expand Down
5 changes: 4 additions & 1 deletion src/axom/primal/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ set( primal_headers
## geometry
geometry/BezierCurve.hpp
geometry/BoundingBox.hpp
geometry/CurvedPolygon.hpp
geometry/OrientedBoundingBox.hpp
geometry/OrientationResult.hpp
geometry/NumericArray.hpp
Expand All @@ -42,14 +43,16 @@ set( primal_headers
operators/orientation.hpp
operators/squared_distance.hpp
operators/compute_bounding_box.hpp
operators/compute_moments.hpp
operators/in_sphere.hpp
operators/split.hpp

operators/detail/clip_impl.hpp
operators/detail/compute_moments_impl.hpp
operators/detail/intersect_bezier_impl.hpp
operators/detail/intersect_ray_impl.hpp
operators/detail/intersect_bounding_box_impl.hpp
operators/detail/intersect_impl.hpp
operators/detail/intersect_ray_impl.hpp

## utils
utils/ZipIndexable.hpp
Expand Down
Loading