Skip to content

Commit

Permalink
formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
rjanvier committed Apr 16, 2024
1 parent 7f93722 commit 4e65bc6
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 9 deletions.
4 changes: 2 additions & 2 deletions include/nn_search.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ template <typename real_t>
static std::pair<nb::ndarray<nb::numpy, uint32_t, nb::ndim<2>>, nb::ndarray<nb::numpy, real_t, nb::ndim<2>>>
nanoflann_knn_search(RefCloud<real_t> data, RefCloud<real_t> query, const uint32_t knn)
{
using kd_tree_t = nanoflann::KDTreeEigenMatrixAdaptor<RefCloud<real_t>, 3, nanoflann::metric_L2_Simple >;
using kd_tree_t = nanoflann::KDTreeEigenMatrixAdaptor<RefCloud<real_t>, 3, nanoflann::metric_L2_Simple>;

if (knn > data.rows()) { throw std::invalid_argument("knn size is greater than the data point cloud size"); }

Expand Down Expand Up @@ -87,7 +87,7 @@ static std::pair<nb::ndarray<nb::numpy, int32_t, nb::ndim<2>>, nb::ndarray<nb::n
nanoflann_radius_search(
RefCloud<real_t> data, RefCloud<real_t> query, const real_t search_radius, const uint32_t max_knn)
{
using kd_tree_t = nanoflann::KDTreeEigenMatrixAdaptor<RefCloud<real_t>, 3, nanoflann::metric_L2_Simple >;
using kd_tree_t = nanoflann::KDTreeEigenMatrixAdaptor<RefCloud<real_t>, 3, nanoflann::metric_L2_Simple>;

if (max_knn > data.rows())
{
Expand Down
19 changes: 12 additions & 7 deletions include/pca.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,12 @@ using DRefMatrixCloud = nb::DRef<const MatrixCloud<real_t>>;

// epsilon definition, for now same for float an double
// the eps is meant to stabilize the division when the cloud's 3rd eigenvalue is near 0
template <typename real_t> constexpr real_t epsilon;
template <> constexpr float epsilon<float> = 1e-3f;
template <> constexpr double epsilon<double> = 1e-3;
template <typename real_t>
constexpr real_t epsilon;
template <>
constexpr float epsilon<float> = 1e-3f;
template <>
constexpr double epsilon<double> = 1e-3;

template <typename real_t>
struct PCAResult
Expand Down Expand Up @@ -146,7 +149,9 @@ static inline real_t compute_eigentropy(const PCAResult<real_t>& pca)
// http://lareg.ensg.eu/labos/matis/pdf/articles_revues/2015/isprs_wjhm_15.pdf
const real_t val_sum = pca.val.sum() + epsilon<real_t>;
const Vec3<real_t> e = pca.val / val_sum;
return (-e(0) * std::log(e(0) + epsilon<real_t>) - e(1) * std::log(e(1) + epsilon<real_t>) - e(2) * std::log(e(2) + epsilon<real_t>));
return (
-e(0) * std::log(e(0) + epsilon<real_t>) - e(1) * std::log(e(1) + epsilon<real_t>) -
e(2) * std::log(e(2) + epsilon<real_t>));
};

/**
Expand Down Expand Up @@ -222,8 +227,8 @@ void compute_selected_features(
const real_t val2 = std::sqrt(pca.val(2));
const real_t val0_fact = real_t(1.0) / (val0 + epsilon<real_t>);

const auto compute_feature = [val0, val1, val2, val0_fact, &pca](
const EFeatureID feature_id, const size_t output_id, auto* feature_results)
const auto compute_feature =
[val0, val1, val2, val0_fact, &pca](const EFeatureID feature_id, const size_t output_id, auto* feature_results)
{
switch (feature_id)
{
Expand Down Expand Up @@ -283,7 +288,7 @@ void compute_selected_features(
case EFeatureID::Verticality:
// The verticality as defined in most of the papers
// http://lareg.ensg.eu/labos/matis/pdf/articles_revues/2015/isprs_wjhm_15.pdf
feature_results[output_id] = real_t(1.0) - std::abs(pca.v2.normalized()(2));
feature_results[output_id] = real_t(1.0) - std::abs(pca.v2(2));
break;
case EFeatureID::Eigentropy:
feature_results[output_id] = compute_eigentropy(pca);
Expand Down
2 changes: 2 additions & 0 deletions tests/test_pgeof.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ def test_knn():
k_new, _ = pgeof.knn_search(xyz, xyz, knn)
np.testing.assert_equal(k_legacy, k_new)


def test_radius_search():
knn = 10
radius = 0.2
Expand All @@ -25,6 +26,7 @@ def test_radius_search():
k_new, _ = pgeof.radius_search(xyz, xyz, radius, knn)
np.testing.assert_equal(k_legacy, k_new)


def test_pgeof_multiscale():
# Generate a random synthetic point cloud and NNs
xyz, nn, nn_ptr = random_nn(10000, 50)
Expand Down

0 comments on commit 4e65bc6

Please sign in to comment.