@@ -79,26 +79,21 @@ static inline PCAResult<real_t> pca_from_pointcloud(const PointCloud<real_t>& cl
7979 Eigen::SelfAdjointEigenSolver<Eigen::Matrix<real_t , 3 , 3 >> es (cov);
8080
8181 // Sort the values and vectors in order of increasing eigenvalue
82- const auto ev = es.eigenvalues (). real () ;
82+ const auto ev = es.eigenvalues ();
8383
84- std::array<Eigen::Index, 3 > indices = {0 , 1 , 2 };
84+ // Clamp eigen values
85+ Vec3<real_t > val = {(std::max (ev (0 ), real_t (0 .))), (std::max (ev (1 ), real_t (0 .))), (std::max (ev (2 ), real_t (0 .)))};
8586
86- std::sort (
87- std::begin (indices), std::end (indices), [&](Eigen::Index i1, Eigen::Index i2) { return ev (i1) > ev (i2); });
88-
89- Vec3<real_t > val = {
90- (std::max (ev (indices[0 ]), real_t (0 .))), (std::max (ev (indices[1 ]), real_t (0 .))),
91- (std::max (ev (indices[2 ]), real_t (0 .)))};
92- Vec3<real_t > v0 = es.eigenvectors ().col (indices[0 ]).real ();
93- Vec3<real_t > v1 = es.eigenvectors ().col (indices[1 ]).real ();
94- Vec3<real_t > v2 = es.eigenvectors ().col (indices[2 ]).real ();
87+ Vec3<real_t > v0 = es.eigenvectors ().col (0 );
88+ Vec3<real_t > v1 = es.eigenvectors ().col (1 );
89+ Vec3<real_t > v2 = es.eigenvectors ().col (2 );
9590
9691 // To standardize the orientation of eigenvectors, we choose to enforce all eigenvectors
9792 // to be expressed in the Z+ half-space.
98- // Only the third eigenvector (v2) needs to be reoriented because it is the
93+ // Only the third eigenvector (v2 the surface normal ) needs to be reoriented because it is the
9994 // only one used in further computations.
10095 // TODO: In case we want to orient normal, this should be improved
101- if (v2 (2 ) < real_t (0 .)) { v2 = real_t (-1 .) * v2 ; }
96+ if (v2 (2 ) < real_t (0 .)) { v2 * = real_t (-1 .); };
10297 return {val, v0, v1, v2};
10398};
10499
@@ -280,14 +275,12 @@ void compute_selected_features(
280275 pca.val (2 ) * std::abs (pca.v2 (2 ))};
281276
282277 feature_results[output_id] = unary_vector (2 ) / unary_vector.norm ();
283- // TODO: Jakteristics compute this as feature_results[output_id] = real_t(1.0) -
284- // std::abs(pca.v2(2));
285- // It seems to be the most common formula for the verticality in the literature
286278 }
287279 break ;
288280 case EFeatureID::Verticality:
289281 // The verticality as defined in most of the papers
290282 // http://lareg.ensg.eu/labos/matis/pdf/articles_revues/2015/isprs_wjhm_15.pdf
283+ // It's the way it's computed in jakteristics
291284 feature_results[output_id] = real_t (1.0 ) - std::abs (pca.v2 (2 ));
292285 break ;
293286 case EFeatureID::Eigentropy:
0 commit comments