mirror of https://github.com/CGAL/cgal
Use floats everywhere (need for very little memory size)
This commit is contained in:
parent
026a01b140
commit
17343421f5
|
|
@ -31,12 +31,12 @@ class Evaluation
|
|||
{
|
||||
mutable std::map<Label_handle, std::size_t> m_map_labels;
|
||||
|
||||
std::vector<double> m_precision;
|
||||
std::vector<double> m_recall;
|
||||
std::vector<double> m_iou; // intersection over union
|
||||
double m_accuracy;
|
||||
double m_mean_iou;
|
||||
double m_mean_f1;
|
||||
std::vector<float> m_precision;
|
||||
std::vector<float> m_recall;
|
||||
std::vector<float> m_iou; // intersection over union
|
||||
float m_accuracy;
|
||||
float m_mean_iou;
|
||||
float m_mean_f1;
|
||||
|
||||
public:
|
||||
|
||||
|
|
@ -79,9 +79,9 @@ public:
|
|||
|
||||
for (std::size_t j = 0; j < labels.size(); ++ j)
|
||||
{
|
||||
m_precision[j] = true_positives[j] / double(true_positives[j] + false_positives[j]);
|
||||
m_recall[j] = true_positives[j] / double(true_positives[j] + false_negatives[j]);
|
||||
m_iou[j] = true_positives[j] / double(true_positives[j] + false_positives[j] + false_negatives[j]);
|
||||
m_precision[j] = true_positives[j] / float(true_positives[j] + false_positives[j]);
|
||||
m_recall[j] = true_positives[j] / float(true_positives[j] + false_negatives[j]);
|
||||
m_iou[j] = true_positives[j] / float(true_positives[j] + false_positives[j] + false_negatives[j]);
|
||||
|
||||
m_mean_iou += m_iou[j];
|
||||
m_mean_f1 += 2. * (m_precision[j] * m_recall[j])
|
||||
|
|
@ -90,7 +90,7 @@ public:
|
|||
|
||||
m_mean_iou /= labels.size();
|
||||
m_mean_f1 /= labels.size();
|
||||
m_accuracy = sum_true_positives / double(total);
|
||||
m_accuracy = sum_true_positives / float(total);
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -102,7 +102,7 @@ public:
|
|||
the true positives and the false positives.
|
||||
|
||||
*/
|
||||
double precision (Label_handle label) const
|
||||
float precision (Label_handle label) const
|
||||
{
|
||||
return m_precision[m_map_labels[label]];
|
||||
}
|
||||
|
|
@ -115,7 +115,7 @@ public:
|
|||
the true positives and the false negatives.
|
||||
|
||||
*/
|
||||
double recall (Label_handle label) const
|
||||
float recall (Label_handle label) const
|
||||
{
|
||||
return m_recall[m_map_labels[label]];
|
||||
}
|
||||
|
|
@ -131,7 +131,7 @@ public:
|
|||
\f]
|
||||
|
||||
*/
|
||||
double f1_score (Label_handle label) const
|
||||
float f1_score (Label_handle label) const
|
||||
{
|
||||
std::size_t label_idx = m_map_labels[label];
|
||||
return 2. * (m_precision[label_idx] * m_recall[label_idx])
|
||||
|
|
@ -146,7 +146,7 @@ public:
|
|||
the sum of the true positives, of the false positives and of the
|
||||
false negatives.
|
||||
*/
|
||||
double intersection_over_union (Label_handle label) const
|
||||
float intersection_over_union (Label_handle label) const
|
||||
{
|
||||
return m_iou[m_map_labels[label]];
|
||||
}
|
||||
|
|
@ -157,19 +157,19 @@ public:
|
|||
Accuracy is the total number of true positives divided by the
|
||||
total number of provided inliers.
|
||||
*/
|
||||
double accuracy() const { return m_accuracy; }
|
||||
float accuracy() const { return m_accuracy; }
|
||||
|
||||
/*!
|
||||
\brief Returns the mean \f$F_1\f$ score of the training over all
|
||||
labels (see `f1_score()`).
|
||||
*/
|
||||
double mean_f1_score() const { return m_mean_f1; }
|
||||
float mean_f1_score() const { return m_mean_f1; }
|
||||
|
||||
/*!
|
||||
\brief Returns the mean intersection over union of the training
|
||||
over all labels (see `intersection_over_union()`).
|
||||
*/
|
||||
double mean_intersection_over_union() const { return m_mean_iou; }
|
||||
float mean_intersection_over_union() const { return m_mean_iou; }
|
||||
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -48,13 +48,13 @@ namespace Feature {
|
|||
for matrix diagonalization.
|
||||
*/
|
||||
template <typename Geom_traits, typename PointRange, typename PointMap,
|
||||
typename DiagonalizeTraits = CGAL::Default_diagonalize_traits<double,3> >
|
||||
typename DiagonalizeTraits = CGAL::Default_diagonalize_traits<float,3> >
|
||||
class Distance_to_plane : public Feature_base
|
||||
{
|
||||
typedef Classification::Local_eigen_analysis<Geom_traits, PointRange,
|
||||
PointMap, DiagonalizeTraits> Local_eigen_analysis;
|
||||
#ifdef CGAL_CLASSIFICATION_PRECOMPUTE_FEATURES
|
||||
std::vector<double> distance_to_plane_feature;
|
||||
std::vector<float> distance_to_plane_feature;
|
||||
#else
|
||||
const PointRange& input;
|
||||
PointMap point_map;
|
||||
|
|
@ -85,7 +85,7 @@ public:
|
|||
}
|
||||
|
||||
/// \cond SKIP_IN_MANUAL
|
||||
virtual double value (std::size_t pt_index)
|
||||
virtual float value (std::size_t pt_index)
|
||||
{
|
||||
#ifdef CGAL_CLASSIFICATION_PRECOMPUTE_FEATURES
|
||||
return distance_to_plane_feature[pt_index];
|
||||
|
|
|
|||
|
|
@ -55,7 +55,7 @@ public:
|
|||
private:
|
||||
typedef Classification::Image<float> Image_float;
|
||||
|
||||
std::vector<double> echo_scatter;
|
||||
std::vector<float> echo_scatter;
|
||||
|
||||
public:
|
||||
/*!
|
||||
|
|
@ -70,8 +70,8 @@ public:
|
|||
Echo_scatter (const PointRange& input,
|
||||
EchoMap echo_map,
|
||||
const Grid& grid,
|
||||
const double grid_resolution,
|
||||
double radius_neighbors = 1.)
|
||||
const float grid_resolution,
|
||||
float radius_neighbors = 1.)
|
||||
{
|
||||
this->set_name ("echo_scatter");
|
||||
Image_float Scatter(grid.width(), grid.height());
|
||||
|
|
@ -97,7 +97,7 @@ public:
|
|||
for(std::size_t k = squareXmin; k <= squareXmax; k++){
|
||||
for(std::size_t l = squareYmin; l <= squareYmax; l++){
|
||||
|
||||
if(CGAL::sqrt(pow((double)k-i,2)+pow((double)l-j,2))<=(double)0.5*radius_neighbors/grid_resolution){
|
||||
if(CGAL::sqrt(pow((float)k-i,2)+pow((float)l-j,2))<=(float)0.5*radius_neighbors/grid_resolution){
|
||||
|
||||
if(grid.indices(k,l).size()>0){
|
||||
|
||||
|
|
@ -128,12 +128,12 @@ public:
|
|||
for(std::size_t i = 0; i < input.size(); i++){
|
||||
std::size_t I= grid.x(i);
|
||||
std::size_t J= grid.y(i);
|
||||
echo_scatter.push_back((double)Scatter(I,J));
|
||||
echo_scatter.push_back((float)Scatter(I,J));
|
||||
}
|
||||
}
|
||||
|
||||
/// \cond SKIP_IN_MANUAL
|
||||
virtual double value (std::size_t pt_index)
|
||||
virtual float value (std::size_t pt_index)
|
||||
{
|
||||
return echo_scatter[pt_index];
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ namespace Classification {
|
|||
namespace Feature {
|
||||
|
||||
template <typename Geom_traits, typename PointRange, typename PointMap,
|
||||
typename DiagonalizeTraits = CGAL::Default_diagonalize_traits<double,3> >
|
||||
typename DiagonalizeTraits = CGAL::Default_diagonalize_traits<float,3> >
|
||||
class Eigen_feature : public Feature_base
|
||||
{
|
||||
protected:
|
||||
|
|
@ -39,7 +39,7 @@ protected:
|
|||
PointMap, DiagonalizeTraits> Local_eigen_analysis;
|
||||
|
||||
#ifdef CGAL_CLASSIFICATION_PRECOMPUTE_FEATURES
|
||||
std::vector<double> attrib;
|
||||
std::vector<float> attrib;
|
||||
#else
|
||||
const Local_eigen_analysis& eigen;
|
||||
#endif
|
||||
|
|
@ -67,8 +67,8 @@ public:
|
|||
}
|
||||
#endif
|
||||
|
||||
virtual double get_value (const Local_eigen_analysis& eigen, std::size_t i) = 0;
|
||||
virtual double value (std::size_t pt_index)
|
||||
virtual float get_value (const Local_eigen_analysis& eigen, std::size_t i) = 0;
|
||||
virtual float value (std::size_t pt_index)
|
||||
{
|
||||
#ifdef CGAL_CLASSIFICATION_PRECOMPUTE_FEATURES
|
||||
return attrib[pt_index];
|
||||
|
|
@ -99,7 +99,7 @@ public:
|
|||
for matrix diagonalization.
|
||||
*/
|
||||
template <typename Geom_traits, typename PointRange, typename PointMap,
|
||||
typename DiagonalizeTraits = CGAL::Default_diagonalize_traits<double,3> >
|
||||
typename DiagonalizeTraits = CGAL::Default_diagonalize_traits<float,3> >
|
||||
class Linearity : public Eigen_feature<Geom_traits, PointRange, PointMap, DiagonalizeTraits>
|
||||
{
|
||||
typedef Classification::Local_eigen_analysis<Geom_traits, PointRange,
|
||||
|
|
@ -120,7 +120,7 @@ public:
|
|||
}
|
||||
|
||||
/// \cond SKIP_IN_MANUAL
|
||||
virtual double get_value (const Local_eigen_analysis& eigen, std::size_t i)
|
||||
virtual float get_value (const Local_eigen_analysis& eigen, std::size_t i)
|
||||
{
|
||||
const typename Local_eigen_analysis::Eigenvalues& ev = eigen.eigenvalue(i);
|
||||
if (ev[2] < 1e-15)
|
||||
|
|
@ -151,7 +151,7 @@ public:
|
|||
for matrix diagonalization.
|
||||
*/
|
||||
template <typename Geom_traits, typename PointRange, typename PointMap,
|
||||
typename DiagonalizeTraits = CGAL::Default_diagonalize_traits<double,3> >
|
||||
typename DiagonalizeTraits = CGAL::Default_diagonalize_traits<float,3> >
|
||||
class Planarity : public Eigen_feature<Geom_traits, PointRange, PointMap, DiagonalizeTraits>
|
||||
{
|
||||
typedef Classification::Local_eigen_analysis<Geom_traits, PointRange,
|
||||
|
|
@ -172,7 +172,7 @@ public:
|
|||
this->init(input, eigen);
|
||||
}
|
||||
/// \cond SKIP_IN_MANUAL
|
||||
virtual double get_value (const Local_eigen_analysis& eigen, std::size_t i)
|
||||
virtual float get_value (const Local_eigen_analysis& eigen, std::size_t i)
|
||||
{
|
||||
const typename Local_eigen_analysis::Eigenvalues& ev = eigen.eigenvalue(i);
|
||||
if (ev[2] < 1e-15)
|
||||
|
|
@ -204,7 +204,7 @@ public:
|
|||
for matrix diagonalization.
|
||||
*/
|
||||
template <typename Geom_traits, typename PointRange, typename PointMap,
|
||||
typename DiagonalizeTraits = CGAL::Default_diagonalize_traits<double,3> >
|
||||
typename DiagonalizeTraits = CGAL::Default_diagonalize_traits<float,3> >
|
||||
class Sphericity : public Eigen_feature<Geom_traits, PointRange, PointMap, DiagonalizeTraits>
|
||||
{
|
||||
typedef Classification::Local_eigen_analysis<Geom_traits, PointRange,
|
||||
|
|
@ -225,7 +225,7 @@ public:
|
|||
this->init(input, eigen);
|
||||
}
|
||||
/// \cond SKIP_IN_MANUAL
|
||||
virtual double get_value (const Local_eigen_analysis& eigen, std::size_t i)
|
||||
virtual float get_value (const Local_eigen_analysis& eigen, std::size_t i)
|
||||
{
|
||||
const typename Local_eigen_analysis::Eigenvalues& ev = eigen.eigenvalue(i);
|
||||
if (ev[2] < 1e-15)
|
||||
|
|
@ -256,7 +256,7 @@ public:
|
|||
for matrix diagonalization.
|
||||
*/
|
||||
template <typename Geom_traits, typename PointRange, typename PointMap,
|
||||
typename DiagonalizeTraits = CGAL::Default_diagonalize_traits<double,3> >
|
||||
typename DiagonalizeTraits = CGAL::Default_diagonalize_traits<float,3> >
|
||||
class Omnivariance : public Eigen_feature<Geom_traits, PointRange, PointMap, DiagonalizeTraits>
|
||||
{
|
||||
typedef Classification::Local_eigen_analysis<Geom_traits, PointRange,
|
||||
|
|
@ -277,7 +277,7 @@ public:
|
|||
this->init(input, eigen);
|
||||
}
|
||||
/// \cond SKIP_IN_MANUAL
|
||||
virtual double get_value (const Local_eigen_analysis& eigen, std::size_t i)
|
||||
virtual float get_value (const Local_eigen_analysis& eigen, std::size_t i)
|
||||
{
|
||||
const typename Local_eigen_analysis::Eigenvalues& ev = eigen.eigenvalue(i);
|
||||
return (std::pow (std::fabs(ev[0] * ev[1] * ev[2]), 0.333333333));
|
||||
|
|
@ -305,7 +305,7 @@ public:
|
|||
for matrix diagonalization.
|
||||
*/
|
||||
template <typename Geom_traits, typename PointRange, typename PointMap,
|
||||
typename DiagonalizeTraits = CGAL::Default_diagonalize_traits<double,3> >
|
||||
typename DiagonalizeTraits = CGAL::Default_diagonalize_traits<float,3> >
|
||||
class Anisotropy : public Eigen_feature<Geom_traits, PointRange, PointMap, DiagonalizeTraits>
|
||||
{
|
||||
typedef Classification::Local_eigen_analysis<Geom_traits, PointRange,
|
||||
|
|
@ -326,7 +326,7 @@ public:
|
|||
this->init(input, eigen);
|
||||
}
|
||||
/// \cond SKIP_IN_MANUAL
|
||||
virtual double get_value (const Local_eigen_analysis& eigen, std::size_t i)
|
||||
virtual float get_value (const Local_eigen_analysis& eigen, std::size_t i)
|
||||
{
|
||||
const typename Local_eigen_analysis::Eigenvalues& ev = eigen.eigenvalue(i);
|
||||
if (ev[2] < 1e-15)
|
||||
|
|
@ -357,7 +357,7 @@ public:
|
|||
for matrix diagonalization.
|
||||
*/
|
||||
template <typename Geom_traits, typename PointRange, typename PointMap,
|
||||
typename DiagonalizeTraits = CGAL::Default_diagonalize_traits<double,3> >
|
||||
typename DiagonalizeTraits = CGAL::Default_diagonalize_traits<float,3> >
|
||||
class Eigentropy : public Eigen_feature<Geom_traits, PointRange, PointMap, DiagonalizeTraits>
|
||||
{
|
||||
typedef Classification::Local_eigen_analysis<Geom_traits, PointRange,
|
||||
|
|
@ -378,7 +378,7 @@ public:
|
|||
this->init(input, eigen);
|
||||
}
|
||||
/// \cond SKIP_IN_MANUAL
|
||||
virtual double get_value (const Local_eigen_analysis& eigen, std::size_t i)
|
||||
virtual float get_value (const Local_eigen_analysis& eigen, std::size_t i)
|
||||
{
|
||||
const typename Local_eigen_analysis::Eigenvalues& ev = eigen.eigenvalue(i);
|
||||
if (ev[0] < 1e-15
|
||||
|
|
@ -414,7 +414,7 @@ public:
|
|||
for matrix diagonalization.
|
||||
*/
|
||||
template <typename Geom_traits, typename PointRange, typename PointMap,
|
||||
typename DiagonalizeTraits = CGAL::Default_diagonalize_traits<double,3> >
|
||||
typename DiagonalizeTraits = CGAL::Default_diagonalize_traits<float,3> >
|
||||
class Sum_eigenvalues : public Eigen_feature<Geom_traits, PointRange, PointMap, DiagonalizeTraits>
|
||||
{
|
||||
typedef Classification::Local_eigen_analysis<Geom_traits, PointRange,
|
||||
|
|
@ -435,7 +435,7 @@ public:
|
|||
this->init(input, eigen);
|
||||
}
|
||||
/// \cond SKIP_IN_MANUAL
|
||||
virtual double get_value (const Local_eigen_analysis& eigen, std::size_t i)
|
||||
virtual float get_value (const Local_eigen_analysis& eigen, std::size_t i)
|
||||
{
|
||||
return eigen.sum_of_eigenvalues(i);
|
||||
}
|
||||
|
|
@ -463,7 +463,7 @@ public:
|
|||
for matrix diagonalization.
|
||||
*/
|
||||
template <typename Geom_traits, typename PointRange, typename PointMap,
|
||||
typename DiagonalizeTraits = CGAL::Default_diagonalize_traits<double,3> >
|
||||
typename DiagonalizeTraits = CGAL::Default_diagonalize_traits<float,3> >
|
||||
class Surface_variation : public Eigen_feature<Geom_traits, PointRange, PointMap, DiagonalizeTraits>
|
||||
{
|
||||
typedef Classification::Local_eigen_analysis<Geom_traits, PointRange,
|
||||
|
|
@ -484,7 +484,7 @@ public:
|
|||
this->init(input, eigen);
|
||||
}
|
||||
/// \cond SKIP_IN_MANUAL
|
||||
virtual double get_value (const Local_eigen_analysis& eigen, std::size_t i)
|
||||
virtual float get_value (const Local_eigen_analysis& eigen, std::size_t i)
|
||||
{
|
||||
const typename Local_eigen_analysis::Eigenvalues& ev = eigen.eigenvalue(i);
|
||||
if (ev[0] + ev[1] + ev[2] < 1e-15)
|
||||
|
|
|
|||
|
|
@ -56,8 +56,15 @@ class Elevation : public Feature_base
|
|||
|
||||
typedef Image<float> Image_float;
|
||||
typedef Planimetric_grid<Geom_traits, PointRange, PointMap> Grid;
|
||||
|
||||
std::vector<double> elevation_feature;
|
||||
|
||||
#ifdef CGAL_CLASSIFICATION_PRECOMPUTE_FEATURES
|
||||
std::vector<float> elevation_feature;
|
||||
#else
|
||||
const PointRange& input;
|
||||
PointMap point_map;
|
||||
const Grid& grid;
|
||||
Image_float dtm;
|
||||
#endif
|
||||
|
||||
public:
|
||||
/*!
|
||||
|
|
@ -73,8 +80,11 @@ public:
|
|||
Elevation (const PointRange& input,
|
||||
PointMap point_map,
|
||||
const Grid& grid,
|
||||
const double grid_resolution,
|
||||
double radius_dtm = -1.)
|
||||
const float grid_resolution,
|
||||
float radius_dtm = -1.)
|
||||
#ifndef CGAL_CLASSIFICATION_PRECOMPUTE_FEATURES
|
||||
: input(input), point_map(point_map), grid(grid)
|
||||
#endif
|
||||
{
|
||||
this->set_name ("elevation");
|
||||
if (radius_dtm < 0.)
|
||||
|
|
@ -88,7 +98,7 @@ public:
|
|||
{
|
||||
if (grid.indices(i,j).empty())
|
||||
continue;
|
||||
double mean = 0.;
|
||||
float mean = 0.;
|
||||
for (std::size_t k = 0; k < grid.indices(i,j).size(); ++ k)
|
||||
mean += get(point_map, *(input.begin()+grid.indices(i,j)[k])).z();
|
||||
mean /= grid.indices(i,j).size();
|
||||
|
|
@ -106,7 +116,7 @@ public:
|
|||
std::size_t squareXmin = (i < square ? 0 : i - square);
|
||||
std::size_t squareXmax = (std::min)(grid.width() - 1, i + square);
|
||||
|
||||
std::vector<double> z;
|
||||
std::vector<float> z;
|
||||
z.reserve(squareXmax - squareXmin +1 );
|
||||
for(std::size_t k = squareXmin; k <= squareXmax; k++)
|
||||
if (dem(k,j) != 0.)
|
||||
|
|
@ -119,7 +129,11 @@ public:
|
|||
}
|
||||
dem.free();
|
||||
|
||||
#ifdef CGAL_CLASSIFICATION_PRECOMPUTE_FEATURES
|
||||
Image_float dtm(grid.width(),grid.height());
|
||||
#else
|
||||
dtm = Image_float(grid.width(),grid.height());
|
||||
#endif
|
||||
|
||||
for (std::size_t i = 0; i < grid.width(); ++ i)
|
||||
{
|
||||
|
|
@ -127,7 +141,7 @@ public:
|
|||
{
|
||||
std::size_t squareYmin = (j < square ? 0 : j - square);
|
||||
std::size_t squareYmax = (std::min)(grid.height() - 1, j + square);
|
||||
std::vector<double> z;
|
||||
std::vector<float> z;
|
||||
z.reserve(squareYmax - squareYmin +1 );
|
||||
for(std::size_t l = squareYmin; l <= squareYmax; l++)
|
||||
if (dtm_x(i,l) != 0.)
|
||||
|
|
@ -139,20 +153,28 @@ public:
|
|||
}
|
||||
}
|
||||
dtm_x.free();
|
||||
|
||||
|
||||
#ifdef CGAL_CLASSIFICATION_PRECOMPUTE_FEATURES
|
||||
elevation_feature.reserve(input.size());
|
||||
for (std::size_t i = 0; i < input.size(); i++){
|
||||
std::size_t I = grid.x(i);
|
||||
std::size_t J = grid.y(i);
|
||||
elevation_feature.push_back ((double)(get(point_map, *(input.begin()+i)).z()-dtm(I,J)));
|
||||
elevation_feature.push_back ((float)(get(point_map, *(input.begin()+i)).z()-dtm(I,J)));
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
/// \cond SKIP_IN_MANUAL
|
||||
virtual double value (std::size_t pt_index)
|
||||
virtual float value (std::size_t pt_index)
|
||||
{
|
||||
#ifdef CGAL_CLASSIFICATION_PRECOMPUTE_FEATURES
|
||||
return elevation_feature[pt_index];
|
||||
#else
|
||||
std::size_t I = grid.x(pt_index);
|
||||
std::size_t J = grid.y(pt_index);
|
||||
return ((float)(get(point_map, *(input.begin()+pt_index)).z()-dtm(I,J)));
|
||||
#endif
|
||||
}
|
||||
|
||||
/// \endcond
|
||||
|
|
|
|||
|
|
@ -73,13 +73,13 @@ class Hsv : public Feature_base
|
|||
typedef typename Classification::HSV_Color HSV_Color;
|
||||
|
||||
#ifdef CGAL_CLASSIFICATION_PRECOMPUTE_FEATURES
|
||||
std::vector<double> color_feature;
|
||||
std::vector<float> color_feature;
|
||||
#else
|
||||
const PointRange& input;
|
||||
ColorMap color_map;
|
||||
std::size_t m_channel;
|
||||
double m_mean;
|
||||
double m_sd;
|
||||
float m_mean;
|
||||
float m_sd;
|
||||
#endif
|
||||
|
||||
public:
|
||||
|
|
@ -98,7 +98,7 @@ public:
|
|||
Hsv (const PointRange& input,
|
||||
ColorMap color_map,
|
||||
std::size_t channel,
|
||||
double mean, double sd)
|
||||
float mean, float sd)
|
||||
#ifndef CGAL_CLASSIFICATION_PRECOMPUTE_FEATURES
|
||||
: input(input), color_map(color_map), m_channel(channel), m_mean(mean), m_sd(sd)
|
||||
#endif
|
||||
|
|
@ -121,7 +121,7 @@ public:
|
|||
}
|
||||
|
||||
/// \cond SKIP_IN_MANUAL
|
||||
virtual double value (std::size_t pt_index)
|
||||
virtual float value (std::size_t pt_index)
|
||||
{
|
||||
#ifdef CGAL_CLASSIFICATION_PRECOMPUTE_FEATURES
|
||||
return color_feature[pt_index];
|
||||
|
|
|
|||
|
|
@ -54,7 +54,13 @@ class Vertical_dispersion : public Feature_base
|
|||
{
|
||||
typedef Classification::Image<float> Image_float;
|
||||
typedef Classification::Planimetric_grid<Geom_traits, PointRange, PointMap> Grid;
|
||||
std::vector<double> vertical_dispersion;
|
||||
|
||||
#ifdef CGAL_CLASSIFICATION_PRECOMPUTE_FEATURES
|
||||
std::vector<float> vertical_dispersion;
|
||||
#else
|
||||
const Grid& grid;
|
||||
Image_float Dispersion;
|
||||
#endif
|
||||
|
||||
public:
|
||||
/*!
|
||||
|
|
@ -69,14 +75,22 @@ public:
|
|||
Vertical_dispersion (const PointRange& input,
|
||||
PointMap point_map,
|
||||
const Grid& grid,
|
||||
const double grid_resolution,
|
||||
double radius_neighbors = -1.)
|
||||
const float grid_resolution,
|
||||
float radius_neighbors = -1.)
|
||||
#ifndef CGAL_CLASSIFICATION_PRECOMPUTE_FEATURES
|
||||
: grid (grid)
|
||||
#endif
|
||||
{
|
||||
this->set_name ("vertical_dispersion");
|
||||
if (radius_neighbors < 0.)
|
||||
radius_neighbors = 5. * grid_resolution;
|
||||
|
||||
|
||||
#ifdef CGAL_CLASSIFICATION_PRECOMPUTE_FEATURES
|
||||
Image_float Dispersion(grid.width(), grid.height());
|
||||
#else
|
||||
Dispersion = Image_float(grid.width(), grid.height());
|
||||
#endif
|
||||
|
||||
for (std::size_t j = 0; j < grid.height(); j++)
|
||||
for (std::size_t i = 0; i < grid.width(); i++)
|
||||
Dispersion(i,j)=0;
|
||||
|
|
@ -89,7 +103,7 @@ public:
|
|||
|
||||
if(!(grid.mask(i,j)))
|
||||
continue;
|
||||
std::vector<double> hori;
|
||||
std::vector<float> hori;
|
||||
|
||||
std::size_t squareXmin = (i < square ? 0 : i - square);
|
||||
std::size_t squareXmax = (std::min) (grid.width()-1, i + square);
|
||||
|
|
@ -98,8 +112,8 @@ public:
|
|||
|
||||
for(std::size_t k = squareXmin; k <= squareXmax; k++)
|
||||
for(std::size_t l = squareYmin; l <= squareYmax; l++)
|
||||
if(CGAL::sqrt(pow((double)k-i,2)+pow((double)l-j,2))
|
||||
<=(double)0.5*radius_neighbors/grid_resolution
|
||||
if(CGAL::sqrt(pow((float)k-i,2)+pow((float)l-j,2))
|
||||
<=(float)0.5*radius_neighbors/grid_resolution
|
||||
&& (grid.indices(k,l).size()>0))
|
||||
for(std::size_t t=0; t<grid.indices(k,l).size();t++)
|
||||
{
|
||||
|
|
@ -135,18 +149,25 @@ public:
|
|||
}
|
||||
|
||||
}
|
||||
#ifdef CGAL_CLASSIFICATION_PRECOMPUTE_FEATURES
|
||||
for (std::size_t i = 0; i < input.size(); i++)
|
||||
{
|
||||
std::size_t I= grid.x(i);
|
||||
std::size_t J= grid.y(i);
|
||||
vertical_dispersion.push_back((double)Dispersion(I,J));
|
||||
vertical_dispersion.push_back((float)Dispersion(I,J));
|
||||
}
|
||||
|
||||
#endif
|
||||
}
|
||||
/// \cond SKIP_IN_MANUAL
|
||||
virtual double value (std::size_t pt_index)
|
||||
virtual float value (std::size_t pt_index)
|
||||
{
|
||||
#ifdef CGAL_CLASSIFICATION_PRECOMPUTE_FEATURES
|
||||
return vertical_dispersion[pt_index];
|
||||
#else
|
||||
std::size_t I = grid.x(pt_index);
|
||||
std::size_t J = grid.y(pt_index);
|
||||
return ((float)Dispersion(I,J));
|
||||
#endif
|
||||
}
|
||||
/// \endcond
|
||||
};
|
||||
|
|
|
|||
|
|
@ -49,17 +49,15 @@ namespace Feature {
|
|||
for matrix diagonalization.
|
||||
*/
|
||||
template <typename Geom_traits, typename PointRange, typename PointMap,
|
||||
typename DiagonalizeTraits = CGAL::Default_diagonalize_traits<double,3> >
|
||||
typename DiagonalizeTraits = CGAL::Default_diagonalize_traits<float,3> >
|
||||
class Verticality : public Feature_base
|
||||
{
|
||||
typedef Classification::Local_eigen_analysis<Geom_traits, PointRange,
|
||||
PointMap, DiagonalizeTraits> Local_eigen_analysis;
|
||||
|
||||
const typename Geom_traits::Vector_3 vertical;
|
||||
std::vector<double> verticality_feature;
|
||||
#ifndef CGAL_CLASSIFICATION_PRECOMPUTE_FEATURES
|
||||
const Local_eigen_analysis& eigen;
|
||||
#endif
|
||||
std::vector<float> verticality_feature;
|
||||
const Local_eigen_analysis* eigen;
|
||||
|
||||
public:
|
||||
/*!
|
||||
|
|
@ -71,7 +69,7 @@ public:
|
|||
#ifdef CGAL_CLASSIFICATION_PRECOMPUTE_FEATURES
|
||||
Verticality (const PointRange& input,
|
||||
const Local_eigen_analysis& eigen)
|
||||
: vertical (0., 0., 1.)
|
||||
: vertical (0., 0., 1.), eigen(NULL)
|
||||
{
|
||||
this->set_name ("verticality");
|
||||
|
||||
|
|
@ -85,7 +83,7 @@ public:
|
|||
#else
|
||||
Verticality (const PointRange&,
|
||||
const Local_eigen_analysis& eigen)
|
||||
: vertical (0., 0., 1.), eigen (eigen)
|
||||
: vertical (0., 0., 1.), eigen (&eigen)
|
||||
{
|
||||
this->set_name ("verticality");
|
||||
}
|
||||
|
|
@ -103,7 +101,7 @@ public:
|
|||
template <typename VectorMap>
|
||||
Verticality (const PointRange& input,
|
||||
VectorMap normal_map)
|
||||
: vertical (0., 0., 1.)
|
||||
: vertical (0., 0., 1.), eigen(NULL)
|
||||
{
|
||||
this->set_name ("verticality");
|
||||
for (std::size_t i = 0; i < input.size(); i++)
|
||||
|
|
@ -116,12 +114,12 @@ public:
|
|||
|
||||
|
||||
/// \cond SKIP_IN_MANUAL
|
||||
virtual double value (std::size_t pt_index)
|
||||
virtual float value (std::size_t pt_index)
|
||||
{
|
||||
#ifndef CGAL_CLASSIFICATION_PRECOMPUTE_FEATURES
|
||||
if (verticality_feature.empty())
|
||||
if (eigen != NULL)
|
||||
{
|
||||
typename Geom_traits::Vector_3 normal = eigen.normal_vector(pt_index);
|
||||
typename Geom_traits::Vector_3 normal = eigen->normal_vector(pt_index);
|
||||
normal = normal / CGAL::sqrt (normal * normal);
|
||||
return (1. - CGAL::abs(normal * vertical));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -70,7 +70,7 @@ public:
|
|||
position `index`. This method must be implemented by inherited
|
||||
classes.
|
||||
*/
|
||||
virtual double value (std::size_t index) = 0;
|
||||
virtual float value (std::size_t index) = 0;
|
||||
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -56,17 +56,15 @@ namespace Classification {
|
|||
for matrix diagonalization.
|
||||
*/
|
||||
template <typename Geom_traits, typename PointRange, typename PointMap,
|
||||
typename DiagonalizeTraits = CGAL::Default_diagonalize_traits<double,3> >
|
||||
typename DiagonalizeTraits = CGAL::Default_diagonalize_traits<float,3> >
|
||||
class Local_eigen_analysis
|
||||
{
|
||||
public:
|
||||
typedef typename Geom_traits::Point_3 Point;
|
||||
typedef typename Geom_traits::Vector_3 Vector;
|
||||
typedef typename Geom_traits::Plane_3 Plane;
|
||||
typedef CGAL::cpp11::array<float, 3> Eigenvalues; ///< Eigenvalues (sorted in ascending order)
|
||||
|
||||
typedef CGAL::cpp11::array<double, 3> Eigenvalues; ///< Eigenvalues (sorted in ascending order)
|
||||
|
||||
|
||||
private:
|
||||
|
||||
#ifdef CGAL_LINKED_WITH_TBB
|
||||
|
|
@ -77,7 +75,7 @@ private:
|
|||
const PointRange& m_input;
|
||||
PointMap m_point_map;
|
||||
const NeighborQuery& m_neighbor_query;
|
||||
double& m_mean_range;
|
||||
float& m_mean_range;
|
||||
tbb::mutex& m_mutex;
|
||||
|
||||
public:
|
||||
|
|
@ -86,7 +84,7 @@ private:
|
|||
const PointRange& input,
|
||||
PointMap point_map,
|
||||
const NeighborQuery& neighbor_query,
|
||||
double& mean_range,
|
||||
float& mean_range,
|
||||
tbb::mutex& mutex)
|
||||
: m_eigen (eigen), m_input (input), m_point_map (point_map),
|
||||
m_neighbor_query (neighbor_query), m_mean_range (mean_range), m_mutex (mutex)
|
||||
|
|
@ -114,16 +112,17 @@ private:
|
|||
|
||||
};
|
||||
#endif
|
||||
|
||||
std::vector<Eigenvalues> m_eigenvalues;
|
||||
std::vector<double> m_sum_eigenvalues;
|
||||
std::vector<Point> m_centroids;
|
||||
std::vector<Vector> m_smallest_eigenvectors;
|
||||
|
||||
typedef CGAL::cpp11::array<float, 3> float3;
|
||||
std::vector<float3> m_eigenvalues;
|
||||
std::vector<float> m_sum_eigenvalues;
|
||||
std::vector<float3> m_centroids;
|
||||
std::vector<float3> m_smallest_eigenvectors;
|
||||
#ifdef CGAL_CLASSIFICATION_EIGEN_FULL_STORAGE
|
||||
std::vector<Vector> m_middle_eigenvectors;
|
||||
std::vector<Vector> m_largest_eigenvectors;
|
||||
std::vector<float3> m_middle_eigenvectors;
|
||||
std::vector<float3> m_largest_eigenvectors;
|
||||
#endif
|
||||
double m_mean_range;
|
||||
float m_mean_range;
|
||||
|
||||
|
||||
public:
|
||||
|
|
@ -202,12 +201,25 @@ public:
|
|||
/*!
|
||||
\brief Returns the estimated unoriented normal vector of the point at position `index`.
|
||||
*/
|
||||
const Vector& normal_vector (std::size_t index) const { return m_smallest_eigenvectors[index]; }
|
||||
Vector normal_vector (std::size_t index) const
|
||||
{
|
||||
return Vector(double(m_smallest_eigenvectors[index][0]),
|
||||
double(m_smallest_eigenvectors[index][1]),
|
||||
double(m_smallest_eigenvectors[index][2]));
|
||||
}
|
||||
|
||||
/*!
|
||||
\brief Returns the estimated local tangent plane of the point at position `index`.
|
||||
*/
|
||||
Plane plane (std::size_t index) const { return Plane (m_centroids[index], m_smallest_eigenvectors[index]); }
|
||||
Plane plane (std::size_t index) const
|
||||
{
|
||||
return Plane (Point (double(m_centroids[index][0]),
|
||||
double(m_centroids[index][1]),
|
||||
double(m_centroids[index][2])),
|
||||
Vector(double(m_smallest_eigenvectors[index][0]),
|
||||
double(m_smallest_eigenvectors[index][1]),
|
||||
double(m_smallest_eigenvectors[index][2])));
|
||||
}
|
||||
|
||||
/*!
|
||||
\brief Returns the normalized eigenvalues of the point at position `index`.
|
||||
|
|
@ -217,10 +229,10 @@ public:
|
|||
/*!
|
||||
\brief Returns the sum of eigenvalues of the point at position `index`.
|
||||
*/
|
||||
const double& sum_of_eigenvalues (std::size_t index) const { return m_sum_eigenvalues[index]; }
|
||||
const float& sum_of_eigenvalues (std::size_t index) const { return m_sum_eigenvalues[index]; }
|
||||
|
||||
/// \cond SKIP_IN_MANUAL
|
||||
double mean_range() const { return m_mean_range; }
|
||||
float mean_range() const { return m_mean_range; }
|
||||
/// \endcond
|
||||
|
||||
private:
|
||||
|
|
@ -229,21 +241,21 @@ private:
|
|||
{
|
||||
if (neighbor_points.size() == 0)
|
||||
{
|
||||
Eigenvalues v = {{ 0., 0., 0. }};
|
||||
Eigenvalues v = {{ 0.f, 0.f, 0.f }};
|
||||
m_eigenvalues[index] = v;
|
||||
m_centroids[index] = query;
|
||||
m_smallest_eigenvectors[index] = Vector (0., 0., 1.);
|
||||
m_centroids[index] = {{ float(query.x()), float(query.y()), float(query.z()) }};
|
||||
m_smallest_eigenvectors[index] = {{ 0.f, 0.f, 1.f }};
|
||||
#ifdef CGAL_CLASSIFICATION_EIGEN_FULL_STORAGE
|
||||
m_middle_eigenvectors[index] = Vector (0., 1., 0.);
|
||||
m_largest_eigenvectors[index] = Vector (1., 0., 0.);
|
||||
m_middle_eigenvectors[index] = {{ 0.f, 1.f, 0.f }};
|
||||
m_largest_eigenvectors[index] = {{ 1.f, 0.f, 0.f }};
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
|
||||
Point centroid = CGAL::centroid (neighbor_points.begin(), neighbor_points.end());
|
||||
m_centroids[index] = centroid;
|
||||
m_centroids[index] = {{ float(centroid.x()), float(centroid.y()), float(centroid.z()) }};
|
||||
|
||||
CGAL::cpp11::array<double, 6> covariance = {{ 0., 0., 0., 0., 0., 0. }};
|
||||
CGAL::cpp11::array<float, 6> covariance = {{ 0.f, 0.f, 0.f, 0.f, 0.f, 0.f }};
|
||||
|
||||
for (std::size_t i = 0; i < neighbor_points.size(); ++ i)
|
||||
{
|
||||
|
|
@ -256,25 +268,25 @@ private:
|
|||
covariance[5] += d.z () * d.z ();
|
||||
}
|
||||
|
||||
Eigenvalues evalues = {{ 0., 0., 0. }};
|
||||
CGAL::cpp11::array<double, 9> evectors = {{ 0., 0., 0.,
|
||||
0., 0., 0.,
|
||||
0., 0., 0. }};
|
||||
CGAL::cpp11::array<float, 3> evalues = {{ 0.f, 0.f, 0.f }};
|
||||
CGAL::cpp11::array<float, 9> evectors = {{ 0.f, 0.f, 0.f,
|
||||
0.f, 0.f, 0.f,
|
||||
0.f, 0.f, 0.f }};
|
||||
|
||||
DiagonalizeTraits::diagonalize_selfadjoint_covariance_matrix
|
||||
(covariance, evalues, evectors);
|
||||
|
||||
// Normalize
|
||||
double sum = evalues[0] + evalues[1] + evalues[2];
|
||||
if (sum > 0.)
|
||||
float sum = evalues[0] + evalues[1] + evalues[2];
|
||||
if (sum > 0.f)
|
||||
for (std::size_t i = 0; i < 3; ++ i)
|
||||
evalues[i] = evalues[i] / sum;
|
||||
m_sum_eigenvalues[index] = sum;
|
||||
m_eigenvalues[index] = evalues;
|
||||
m_smallest_eigenvectors[index] = Vector (evectors[0], evectors[1], evectors[2]);
|
||||
m_sum_eigenvalues[index] = float(sum);
|
||||
m_eigenvalues[index] = {{ float(evalues[0]), float(evalues[1]), float(evalues[2]) }};
|
||||
m_smallest_eigenvectors[index] = {{ float(evectors[0]), float(evectors[1]), float(evectors[2]) }};
|
||||
#ifdef CGAL_CLASSIFICATION_EIGEN_FULL_STORAGE
|
||||
m_middle_eigenvectors[index] = Vector (evectors[3], evectors[4], evectors[5]);
|
||||
m_largest_eigenvectors[index] = Vector (evectors[6], evectors[7], evectors[8]);
|
||||
m_middle_eigenvectors[index] = {{ float(evectors[3]), float(evectors[4]), float(evectors[5]) }};
|
||||
m_largest_eigenvectors[index] = {{ float(evectors[6]), float(evectors[7]), float(evectors[8]) }};
|
||||
#endif
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -79,7 +79,7 @@ public:
|
|||
Planimetric_grid (const PointRange& input,
|
||||
PointMap point_map,
|
||||
const Iso_cuboid_3& bbox,
|
||||
const double grid_resolution)
|
||||
const float grid_resolution)
|
||||
{
|
||||
std::size_t width = (std::size_t)((bbox.xmax() - bbox.xmin()) / grid_resolution) + 1;
|
||||
std::size_t height = (std::size_t)((bbox.ymax() - bbox.ymin()) / grid_resolution) + 1;
|
||||
|
|
@ -92,7 +92,7 @@ public:
|
|||
m_y.push_back ((std::size_t)((p.y() - bbox.ymin()) / grid_resolution));
|
||||
m_grid(m_x.back(), m_y.back()).push_back (i);
|
||||
}
|
||||
|
||||
std::cerr << "Grid size = " << width * height << std::endl;
|
||||
}
|
||||
|
||||
/*!
|
||||
|
|
|
|||
|
|
@ -89,7 +89,7 @@ template <typename Geom_traits,
|
|||
#else
|
||||
typename ConcurrencyTag = CGAL::Sequential_tag,
|
||||
#endif
|
||||
typename DiagonalizeTraits = CGAL::Default_diagonalize_traits<double,3> >
|
||||
typename DiagonalizeTraits = CGAL::Default_diagonalize_traits<float,3> >
|
||||
class Point_set_feature_generator
|
||||
{
|
||||
|
||||
|
|
@ -147,10 +147,10 @@ private:
|
|||
Neighborhood* neighborhood;
|
||||
Planimetric_grid* grid;
|
||||
Local_eigen_analysis* eigen;
|
||||
double voxel_size;
|
||||
float voxel_size;
|
||||
|
||||
Scale (const PointRange& input, PointMap point_map,
|
||||
const Iso_cuboid_3& bbox, double voxel_size)
|
||||
const Iso_cuboid_3& bbox, float voxel_size)
|
||||
: voxel_size (voxel_size)
|
||||
{
|
||||
CGAL::Real_timer t;
|
||||
|
|
@ -170,7 +170,7 @@ private:
|
|||
t.start();
|
||||
|
||||
eigen = new Local_eigen_analysis (input, point_map, neighborhood->k_neighbor_query(6));
|
||||
double range = eigen->mean_range();
|
||||
float range = eigen->mean_range();
|
||||
if (this->voxel_size < 0)
|
||||
this->voxel_size = range;
|
||||
t.stop();
|
||||
|
|
@ -186,14 +186,27 @@ private:
|
|||
}
|
||||
~Scale()
|
||||
{
|
||||
delete neighborhood;
|
||||
delete grid;
|
||||
if (neighborhood != NULL)
|
||||
delete neighborhood;
|
||||
if (grid != NULL)
|
||||
delete grid;
|
||||
delete eigen;
|
||||
}
|
||||
|
||||
double grid_resolution() const { return voxel_size; }
|
||||
double radius_neighbors() const { return voxel_size * 5; }
|
||||
double radius_dtm() const { return voxel_size * 100; }
|
||||
void reduce_memory_footprint(bool delete_neighborhood)
|
||||
{
|
||||
delete grid;
|
||||
grid = NULL;
|
||||
if (delete_neighborhood)
|
||||
{
|
||||
delete neighborhood;
|
||||
neighborhood = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
float grid_resolution() const { return voxel_size; }
|
||||
float radius_neighbors() const { return voxel_size * 5; }
|
||||
float radius_dtm() const { return voxel_size * 100; }
|
||||
|
||||
};
|
||||
|
||||
|
|
@ -335,6 +348,14 @@ public:
|
|||
{
|
||||
clear();
|
||||
}
|
||||
|
||||
void reduce_memory_footprint()
|
||||
{
|
||||
for (std::size_t i = 0; i < m_scales.size(); ++ i)
|
||||
{
|
||||
m_scales[i]->reduce_memory_footprint(i > 0);
|
||||
}
|
||||
}
|
||||
/// \endcond
|
||||
|
||||
/// \name Data Structures and Parameters
|
||||
|
|
@ -378,7 +399,7 @@ public:
|
|||
\note `generate_features()` must have been called before calling
|
||||
this method.
|
||||
*/
|
||||
double grid_resolution(std::size_t scale = 0) const { return m_scales[scale]->grid_resolution(); }
|
||||
float grid_resolution(std::size_t scale = 0) const { return m_scales[scale]->grid_resolution(); }
|
||||
/*!
|
||||
|
||||
\brief Returns the radius used for neighborhood queries at scale
|
||||
|
|
@ -389,7 +410,7 @@ public:
|
|||
\note `generate_features()` must have been called before calling
|
||||
this method.
|
||||
*/
|
||||
double radius_neighbors(std::size_t scale = 0) const { return m_scales[scale]->radius_neighbors(); }
|
||||
float radius_neighbors(std::size_t scale = 0) const { return m_scales[scale]->radius_neighbors(); }
|
||||
/*!
|
||||
\brief Returns the radius used for digital terrain modeling at
|
||||
scale `scale`. This radius represents the minimum size of a
|
||||
|
|
@ -398,7 +419,7 @@ public:
|
|||
\note `generate_features()` must have been called before calling
|
||||
this method.
|
||||
*/
|
||||
double radius_dtm(std::size_t scale = 0) const { return m_scales[scale]->radius_dtm(); }
|
||||
float radius_dtm(std::size_t scale = 0) const { return m_scales[scale]->radius_dtm(); }
|
||||
|
||||
|
||||
|
||||
|
|
@ -488,12 +509,12 @@ private:
|
|||
using Feature_adder::scale;
|
||||
ColorMap color_map;
|
||||
std::size_t channel;
|
||||
double mean;
|
||||
double sd;
|
||||
float mean;
|
||||
float sd;
|
||||
|
||||
// TODO!
|
||||
Feature_adder_color (Point_set_feature_generator* generator, ColorMap color_map, std::size_t scale,
|
||||
std::size_t channel, double mean, double sd)
|
||||
std::size_t channel, float mean, float sd)
|
||||
: Feature_adder (generator, scale), color_map (color_map),
|
||||
channel (channel), mean (mean), sd (sd) { }
|
||||
|
||||
|
|
@ -588,11 +609,11 @@ private:
|
|||
CGAL::Real_timer t; t.start();
|
||||
|
||||
m_scales.reserve (nb_scales);
|
||||
double voxel_size = - 1.;
|
||||
|
||||
// float voxel_size = 0.05; // WARNING: do not keep (-1 is the right value)
|
||||
float voxel_size = -1;
|
||||
|
||||
m_scales.push_back (new Scale (m_input, m_point_map, m_bbox, voxel_size));
|
||||
voxel_size = m_scales[0]->grid_resolution();
|
||||
|
||||
for (std::size_t i = 1; i < nb_scales; ++ i)
|
||||
{
|
||||
voxel_size *= 2;
|
||||
|
|
|
|||
|
|
@ -142,14 +142,14 @@ public:
|
|||
typedef Point_set_neighborhood::Point value_type; ///<
|
||||
private:
|
||||
const Point_set_neighborhood& neighborhood;
|
||||
double radius;
|
||||
float radius;
|
||||
public:
|
||||
/*!
|
||||
\brief Constructs a range neighbor query object.
|
||||
\param neighborhood point set neighborhood object.
|
||||
\param radius radius of the neighbor query sphere.
|
||||
*/
|
||||
Range_neighbor_query (const Point_set_neighborhood& neighborhood, double radius)
|
||||
Range_neighbor_query (const Point_set_neighborhood& neighborhood, float radius)
|
||||
: neighborhood (neighborhood), radius(radius) { }
|
||||
|
||||
/// \cond SKIP_IN_MANUAL
|
||||
|
|
@ -202,7 +202,7 @@ public:
|
|||
*/
|
||||
Point_set_neighborhood (const PointRange& input,
|
||||
PointMap point_map,
|
||||
double voxel_size)
|
||||
float voxel_size)
|
||||
: m_tree (NULL)
|
||||
{
|
||||
// First, simplify
|
||||
|
|
@ -239,7 +239,7 @@ public:
|
|||
/*!
|
||||
\brief Returns a neighbor query object with fixed radius `radius`.
|
||||
*/
|
||||
Range_neighbor_query range_neighbor_query (const double radius) const
|
||||
Range_neighbor_query range_neighbor_query (const float radius) const
|
||||
{
|
||||
return Range_neighbor_query (*this, radius);
|
||||
}
|
||||
|
|
@ -265,7 +265,7 @@ private:
|
|||
|
||||
template <typename Map>
|
||||
void voxelize_point_set (std::vector<std::size_t>& indices, Map point_map,
|
||||
double voxel_size)
|
||||
float voxel_size)
|
||||
{
|
||||
std::map<Point, std::vector<std::size_t> > grid;
|
||||
|
||||
|
|
@ -292,10 +292,10 @@ private:
|
|||
(pts.end(),
|
||||
CGAL::Property_map_to_unary_function<Map>(point_map)));
|
||||
std::size_t chosen = 0;
|
||||
double min_dist = (std::numeric_limits<double>::max)();
|
||||
float min_dist = (std::numeric_limits<float>::max)();
|
||||
for (std::size_t i = 0; i < pts.size(); ++ i)
|
||||
{
|
||||
double dist = CGAL::squared_distance(get(point_map, pts[i]), centroid);
|
||||
float dist = CGAL::squared_distance(get(point_map, pts[i]), centroid);
|
||||
if (dist < min_dist)
|
||||
{
|
||||
min_dist = dist;
|
||||
|
|
|
|||
|
|
@ -75,7 +75,7 @@ private:
|
|||
std::vector<std::size_t>& m_training_set;
|
||||
const Sum_of_weighted_features_predicate& m_predicate;
|
||||
std::size_t m_label;
|
||||
double& m_confidence;
|
||||
float& m_confidence;
|
||||
std::size_t& m_nb_okay;
|
||||
tbb::mutex& m_mutex;
|
||||
|
||||
|
|
@ -84,7 +84,7 @@ private:
|
|||
Compute_worst_score_and_confidence (std::vector<std::size_t>& training_set,
|
||||
const Sum_of_weighted_features_predicate& predicate,
|
||||
std::size_t label,
|
||||
double& confidence,
|
||||
float& confidence,
|
||||
std::size_t& nb_okay,
|
||||
tbb::mutex& mutex)
|
||||
: m_training_set (training_set)
|
||||
|
|
@ -99,9 +99,9 @@ private:
|
|||
{
|
||||
for (std::size_t k = r.begin(); k != r.end(); ++ k)
|
||||
{
|
||||
std::vector<std::pair<double, std::size_t> > values;
|
||||
std::vector<std::pair<float, std::size_t> > values;
|
||||
|
||||
std::vector<double> v;
|
||||
std::vector<float> v;
|
||||
m_predicate.probabilities (m_training_set[k], v);
|
||||
|
||||
for(std::size_t l = 0; l < v.size(); ++ l)
|
||||
|
|
@ -125,7 +125,7 @@ private:
|
|||
|
||||
Label_set& m_labels;
|
||||
Feature_set& m_features;
|
||||
std::vector<double> m_weights;
|
||||
std::vector<float> m_weights;
|
||||
std::vector<std::vector<Effect> > m_effect_table;
|
||||
mutable std::map<Label_handle, std::size_t> m_map_labels;
|
||||
mutable std::map<Feature_handle, std::size_t> m_map_features;
|
||||
|
|
@ -148,12 +148,12 @@ public:
|
|||
/*!
|
||||
\brief Sets the weight of the feature (`weight` must be positive).
|
||||
*/
|
||||
void set_weight (Feature_handle feature, double weight)
|
||||
void set_weight (Feature_handle feature, float weight)
|
||||
{
|
||||
m_weights[m_map_features[feature]] = weight;
|
||||
}
|
||||
/// \cond SKIP_IN_MANUAL
|
||||
void set_weight (std::size_t feature, double weight)
|
||||
void set_weight (std::size_t feature, float weight)
|
||||
{
|
||||
m_weights[feature] = weight;
|
||||
}
|
||||
|
|
@ -162,12 +162,12 @@ public:
|
|||
/*!
|
||||
\brief Returns the weight of the feature.
|
||||
*/
|
||||
double weight (Feature_handle feature) const
|
||||
float weight (Feature_handle feature) const
|
||||
{
|
||||
return m_weights[m_map_features[feature]];
|
||||
}
|
||||
/// \cond SKIP_IN_MANUAL
|
||||
double weight (std::size_t feature) const
|
||||
float weight (std::size_t feature) const
|
||||
{
|
||||
return m_weights[feature];
|
||||
}
|
||||
|
|
@ -204,7 +204,7 @@ public:
|
|||
/// \endcond
|
||||
|
||||
void probabilities (std::size_t item_index,
|
||||
std::vector<double>& out) const
|
||||
std::vector<float>& out) const
|
||||
{
|
||||
out.resize (m_labels.size());
|
||||
for (std::size_t l = 0; l < m_labels.size(); ++ l)
|
||||
|
|
@ -317,7 +317,7 @@ public:
|
|||
typename std::map<std::string, std::size_t>::iterator
|
||||
found = map_n2f.find (name);
|
||||
if (found != map_n2f.end())
|
||||
m_weights[found->second] = v.second.get<double>("weight");
|
||||
m_weights[found->second] = v.second.get<float>("weight");
|
||||
else
|
||||
{
|
||||
if (verbose)
|
||||
|
|
@ -394,26 +394,32 @@ public:
|
|||
configuration found.
|
||||
*/
|
||||
template <typename ConcurrencyTag>
|
||||
double train (const std::vector<std::size_t>& ground_truth,
|
||||
float train (const std::vector<std::size_t>& ground_truth,
|
||||
std::size_t nb_tests = 300)
|
||||
{
|
||||
std::vector<std::vector<std::size_t> > training_sets (m_labels.size());
|
||||
std::size_t nb_tot = 0;
|
||||
for (std::size_t i = 0; i < ground_truth.size(); ++ i)
|
||||
if (ground_truth[i] != std::size_t(-1))
|
||||
training_sets[ground_truth[i]].push_back (i);
|
||||
{
|
||||
training_sets[ground_truth[i]].push_back (i);
|
||||
++ nb_tot;
|
||||
}
|
||||
|
||||
CGAL_CLASSIFICATION_CERR << "Training using " << nb_tot << " inliers" << std::endl;
|
||||
|
||||
for (std::size_t i = 0; i < m_labels.size(); ++ i)
|
||||
if (training_sets.size() <= i || training_sets[i].empty())
|
||||
std::cerr << "WARNING: \"" << m_labels[i]->name() << "\" doesn't have a training set." << std::endl;
|
||||
|
||||
std::vector<double> best_weights (m_features.size(), 1.);
|
||||
std::vector<float> best_weights (m_features.size(), 1.);
|
||||
|
||||
struct Feature_training
|
||||
{
|
||||
std::size_t i;
|
||||
double wmin;
|
||||
double wmax;
|
||||
double factor;
|
||||
float wmin;
|
||||
float wmax;
|
||||
float factor;
|
||||
|
||||
bool operator<(const Feature_training& other) const
|
||||
{
|
||||
|
|
@ -422,8 +428,8 @@ public:
|
|||
};
|
||||
std::vector<Feature_training> feature_train;
|
||||
std::size_t nb_trials = 100;
|
||||
double wmin = 1e-5, wmax = 1e5;
|
||||
double factor = std::pow (wmax/wmin, 1. / (double)nb_trials);
|
||||
float wmin = 1e-5, wmax = 1e5;
|
||||
float factor = std::pow (wmax/wmin, 1. / (float)nb_trials);
|
||||
|
||||
for (std::size_t j = 0; j < m_features.size(); ++ j)
|
||||
{
|
||||
|
|
@ -431,8 +437,8 @@ public:
|
|||
best_weights[j] = weight(j);
|
||||
|
||||
std::size_t nb_useful = 0;
|
||||
double min = (std::numeric_limits<double>::max)();
|
||||
double max = -(std::numeric_limits<double>::max)();
|
||||
float min = (std::numeric_limits<float>::max)();
|
||||
float max = -(std::numeric_limits<float>::max)();
|
||||
|
||||
set_weight(j, wmin);
|
||||
for (std::size_t i = 0; i < 100; ++ i)
|
||||
|
|
@ -475,17 +481,17 @@ public:
|
|||
estimate_feature_effect(j, training_sets);
|
||||
}
|
||||
|
||||
std::size_t nb_trials_per_feature = 1 + (std::size_t)(nb_tests / (double)(feature_train.size()));
|
||||
std::size_t nb_trials_per_feature = 1 + (std::size_t)(nb_tests / (float)(feature_train.size()));
|
||||
CGAL_CLASSIFICATION_CERR << "Trials = " << nb_tests << ", features = " << feature_train.size()
|
||||
<< ", trials per feature = " << nb_trials_per_feature << std::endl;
|
||||
for (std::size_t i = 0; i < feature_train.size(); ++ i)
|
||||
feature_train[i].factor
|
||||
= std::pow (feature_train[i].wmax / feature_train[i].wmin,
|
||||
1. / (double)nb_trials_per_feature);
|
||||
1. / (float)nb_trials_per_feature);
|
||||
|
||||
|
||||
double best_score = 0.;
|
||||
double best_confidence = 0.;
|
||||
float best_score = 0.;
|
||||
float best_confidence = 0.;
|
||||
boost::tie (best_confidence, best_score)
|
||||
= compute_worst_confidence_and_score<ConcurrencyTag> (0., 0., training_sets);
|
||||
|
||||
|
|
@ -519,7 +525,7 @@ public:
|
|||
{
|
||||
estimate_feature_effect(current_feature_changed, training_sets);
|
||||
|
||||
double worst_confidence = 0., worst_score = 0.;
|
||||
float worst_confidence = 0., worst_score = 0.;
|
||||
boost::tie (worst_confidence, worst_score)
|
||||
= compute_worst_confidence_and_score<ConcurrencyTag> (best_confidence, best_score, training_sets);
|
||||
|
||||
|
|
@ -585,7 +591,7 @@ public:
|
|||
|
||||
private:
|
||||
|
||||
double value (std::size_t label, std::size_t feature, std::size_t index) const
|
||||
float value (std::size_t label, std::size_t feature, std::size_t index) const
|
||||
{
|
||||
if (m_effect_table[label][feature] == FAVORING)
|
||||
return favored (feature, index);
|
||||
|
|
@ -595,19 +601,19 @@ private:
|
|||
return ignored (feature, index);
|
||||
}
|
||||
|
||||
double normalized (std::size_t feature, std::size_t index) const
|
||||
float normalized (std::size_t feature, std::size_t index) const
|
||||
{
|
||||
return (std::max) (0., (std::min) (1., m_features[feature]->value(index) / m_weights[feature]));
|
||||
return (std::max) (0.f, (std::min) (1.f, m_features[feature]->value(index) / m_weights[feature]));
|
||||
}
|
||||
double favored (std::size_t feature, std::size_t index) const
|
||||
float favored (std::size_t feature, std::size_t index) const
|
||||
{
|
||||
return (1. - normalized (feature, index));
|
||||
}
|
||||
double penalized (std::size_t feature, std::size_t index) const
|
||||
float penalized (std::size_t feature, std::size_t index) const
|
||||
{
|
||||
return normalized (feature, index);
|
||||
}
|
||||
double ignored (std::size_t, std::size_t) const
|
||||
float ignored (std::size_t, std::size_t) const
|
||||
{
|
||||
return 0.5;
|
||||
}
|
||||
|
|
@ -621,19 +627,19 @@ private:
|
|||
void estimate_feature_effect (std::size_t feature,
|
||||
std::vector<std::vector<std::size_t> >& training_sets)
|
||||
{
|
||||
std::vector<double> mean (m_labels.size(), 0.);
|
||||
std::vector<float> mean (m_labels.size(), 0.);
|
||||
|
||||
for (std::size_t j = 0; j < m_labels.size(); ++ j)
|
||||
{
|
||||
for (std::size_t k = 0; k < training_sets[j].size(); ++ k)
|
||||
{
|
||||
double val = normalized(feature, training_sets[j][k]);
|
||||
float val = normalized(feature, training_sets[j][k]);
|
||||
mean[j] += val;
|
||||
}
|
||||
mean[j] /= training_sets[j].size();
|
||||
}
|
||||
|
||||
std::vector<double> sd (m_labels.size(), 0.);
|
||||
std::vector<float> sd (m_labels.size(), 0.);
|
||||
|
||||
for (std::size_t j = 0; j < m_labels.size(); ++ j)
|
||||
{
|
||||
|
|
@ -641,7 +647,7 @@ private:
|
|||
|
||||
for (std::size_t k = 0; k < training_sets[j].size(); ++ k)
|
||||
{
|
||||
double val = normalized(feature, training_sets[j][k]);
|
||||
float val = normalized(feature, training_sets[j][k]);
|
||||
sd[j] += (val - mean[j]) * (val - mean[j]);
|
||||
}
|
||||
sd[j] = std::sqrt (sd[j] / training_sets[j].size());
|
||||
|
|
@ -655,15 +661,15 @@ private:
|
|||
}
|
||||
|
||||
template <typename ConcurrencyTag>
|
||||
std::pair<double, double> compute_worst_confidence_and_score (double lower_conf, double lower_score,
|
||||
std::pair<float, float> compute_worst_confidence_and_score (float lower_conf, float lower_score,
|
||||
std::vector<std::vector<std::size_t> >& training_sets)
|
||||
{
|
||||
double worst_confidence = (std::numeric_limits<double>::max)();
|
||||
double worst_score = (std::numeric_limits<double>::max)();
|
||||
float worst_confidence = (std::numeric_limits<float>::max)();
|
||||
float worst_score = (std::numeric_limits<float>::max)();
|
||||
|
||||
for (std::size_t j = 0; j < m_labels.size(); ++ j)
|
||||
{
|
||||
double confidence = 0.;
|
||||
float confidence = 0.;
|
||||
std::size_t nb_okay = 0;
|
||||
|
||||
#ifndef CGAL_LINKED_WITH_TBB
|
||||
|
|
@ -681,9 +687,9 @@ private:
|
|||
{
|
||||
for (std::size_t k = 0; k < training_sets[j].size(); ++ k)
|
||||
{
|
||||
std::vector<std::pair<double, std::size_t> > values;
|
||||
std::vector<std::pair<float, std::size_t> > values;
|
||||
|
||||
std::vector<double> v;
|
||||
std::vector<float> v;
|
||||
probabilities (training_sets[j][k], v);
|
||||
|
||||
for(std::size_t l = 0; l < m_labels.size(); ++ l)
|
||||
|
|
@ -699,8 +705,8 @@ private:
|
|||
}
|
||||
}
|
||||
|
||||
double score = nb_okay / (double)(training_sets[j].size());
|
||||
confidence /= (double)(training_sets[j].size() * m_features.size());
|
||||
float score = nb_okay / (float)(training_sets[j].size());
|
||||
confidence /= (float)(training_sets[j].size() * m_features.size());
|
||||
|
||||
if (confidence < worst_confidence)
|
||||
worst_confidence = confidence;
|
||||
|
|
|
|||
|
|
@ -64,10 +64,10 @@ namespace internal {
|
|||
inline void apply (std::size_t s) const
|
||||
{
|
||||
std::size_t nb_class_best=0;
|
||||
std::vector<double> values;
|
||||
std::vector<float> values;
|
||||
m_predicate.probabilities (s, values);
|
||||
|
||||
double val_class_best = (std::numeric_limits<double>::max)();
|
||||
float val_class_best = (std::numeric_limits<float>::max)();
|
||||
for(std::size_t k = 0; k < m_labels.size(); ++ k)
|
||||
{
|
||||
if(val_class_best > values[k])
|
||||
|
|
@ -87,14 +87,14 @@ namespace internal {
|
|||
{
|
||||
const Label_set& m_labels;
|
||||
const ClassificationPredicate& m_predicate;
|
||||
std::vector<std::vector<double> >& m_values;
|
||||
std::vector<std::vector<float> >& m_values;
|
||||
|
||||
public:
|
||||
|
||||
Classifier_local_smoothing_preprocessing
|
||||
(const Label_set& labels,
|
||||
const ClassificationPredicate& predicate,
|
||||
std::vector<std::vector<double> >& values)
|
||||
std::vector<std::vector<float> >& values)
|
||||
: m_labels (labels), m_predicate (predicate), m_values (values)
|
||||
{ }
|
||||
|
||||
|
|
@ -108,7 +108,7 @@ namespace internal {
|
|||
|
||||
inline void apply (std::size_t s) const
|
||||
{
|
||||
std::vector<double> values;
|
||||
std::vector<float> values;
|
||||
m_predicate.probabilities(s, values);
|
||||
for(std::size_t k = 0; k < m_labels.size(); ++ k)
|
||||
m_values[k][s] = values[k];
|
||||
|
|
@ -121,7 +121,7 @@ namespace internal {
|
|||
const ItemRange& m_input;
|
||||
const ItemMap m_item_map;
|
||||
const Label_set& m_labels;
|
||||
const std::vector<std::vector<double> >& m_values;
|
||||
const std::vector<std::vector<float> >& m_values;
|
||||
const NeighborQuery& m_neighbor_query;
|
||||
std::vector<std::size_t>& m_out;
|
||||
|
||||
|
|
@ -130,7 +130,7 @@ namespace internal {
|
|||
Classifier_local_smoothing (const ItemRange& input,
|
||||
ItemMap item_map,
|
||||
const Label_set& labels,
|
||||
const std::vector<std::vector<double> >& values,
|
||||
const std::vector<std::vector<float> >& values,
|
||||
const NeighborQuery& neighbor_query,
|
||||
std::vector<std::size_t>& out)
|
||||
: m_input (input), m_item_map (item_map), m_labels (labels),
|
||||
|
|
@ -152,13 +152,13 @@ namespace internal {
|
|||
std::vector<std::size_t> neighbors;
|
||||
m_neighbor_query (get (m_item_map, *(m_input.begin()+s)), std::back_inserter (neighbors));
|
||||
|
||||
std::vector<double> mean (m_values.size(), 0.);
|
||||
std::vector<float> mean (m_values.size(), 0.);
|
||||
for (std::size_t n = 0; n < neighbors.size(); ++ n)
|
||||
for (std::size_t j = 0; j < m_values.size(); ++ j)
|
||||
mean[j] += m_values[j][neighbors[n]];
|
||||
|
||||
std::size_t nb_class_best=0;
|
||||
double val_class_best = (std::numeric_limits<double>::max)();
|
||||
float val_class_best = (std::numeric_limits<float>::max)();
|
||||
for(std::size_t k = 0; k < mean.size(); ++ k)
|
||||
{
|
||||
mean[k] /= neighbors.size();
|
||||
|
|
@ -184,7 +184,7 @@ namespace internal {
|
|||
const Label_set& m_labels;
|
||||
const ClassificationPredicate& m_predicate;
|
||||
const NeighborQuery& m_neighbor_query;
|
||||
double m_weight;
|
||||
float m_weight;
|
||||
const std::vector<std::vector<std::size_t> >& m_indices;
|
||||
const std::vector<std::pair<std::size_t, std::size_t> >& m_input_to_indices;
|
||||
std::vector<std::size_t>& m_out;
|
||||
|
|
@ -202,7 +202,7 @@ namespace internal {
|
|||
const Label_set& labels,
|
||||
const ClassificationPredicate& predicate,
|
||||
const NeighborQuery& neighbor_query,
|
||||
double weight,
|
||||
float weight,
|
||||
const std::vector<std::vector<std::size_t> >& indices,
|
||||
const std::vector<std::pair<std::size_t, std::size_t> >& input_to_indices,
|
||||
std::vector<std::size_t>& out)
|
||||
|
|
@ -247,13 +247,13 @@ namespace internal {
|
|||
edge_weights.push_back (m_weight);
|
||||
}
|
||||
|
||||
std::vector<double> values;
|
||||
std::vector<float> values;
|
||||
m_predicate.probabilities(s, values);
|
||||
std::size_t nb_class_best = 0;
|
||||
double val_class_best = (std::numeric_limits<double>::max)();
|
||||
float val_class_best = (std::numeric_limits<float>::max)();
|
||||
for(std::size_t k = 0; k < m_labels.size(); ++ k)
|
||||
{
|
||||
double value = values[k];
|
||||
float value = values[k];
|
||||
probability_matrix[k][j] = value;
|
||||
|
||||
if(val_class_best > value)
|
||||
|
|
@ -321,8 +321,8 @@ namespace internal {
|
|||
{
|
||||
output.resize(input.size());
|
||||
|
||||
std::vector<std::vector<double> > values
|
||||
(labels.size(), std::vector<double> (input.size(), -1.));
|
||||
std::vector<std::vector<float> > values
|
||||
(labels.size(), std::vector<float> (input.size(), -1.));
|
||||
internal::Classifier_local_smoothing_preprocessing<ClassificationPredicate>
|
||||
f1 (labels, predicate, values);
|
||||
internal::Classifier_local_smoothing<ItemRange, ItemMap, NeighborQuery>
|
||||
|
|
@ -359,7 +359,7 @@ namespace internal {
|
|||
const Label_set& labels,
|
||||
const ClassificationPredicate& predicate,
|
||||
const NeighborQuery& neighbor_query,
|
||||
const double weight,
|
||||
const float weight,
|
||||
const std::size_t min_number_of_subdivisions,
|
||||
std::vector<std::size_t>& output)
|
||||
{
|
||||
|
|
@ -367,11 +367,11 @@ namespace internal {
|
|||
(boost::make_transform_iterator (input.begin(), CGAL::Property_map_to_unary_function<ItemWithBboxMap>(bbox_map)),
|
||||
boost::make_transform_iterator (input.end(), CGAL::Property_map_to_unary_function<ItemWithBboxMap>(bbox_map)));
|
||||
|
||||
double Dx = bbox.xmax() - bbox.xmin();
|
||||
double Dy = bbox.ymax() - bbox.ymin();
|
||||
double A = Dx * Dy;
|
||||
double a = A / min_number_of_subdivisions;
|
||||
double l = std::sqrt(a);
|
||||
float Dx = bbox.xmax() - bbox.xmin();
|
||||
float Dy = bbox.ymax() - bbox.ymin();
|
||||
float A = Dx * Dy;
|
||||
float a = A / min_number_of_subdivisions;
|
||||
float l = std::sqrt(a);
|
||||
std::size_t nb_x = std::size_t(Dx / l) + 1;
|
||||
std::size_t nb_y = std::size_t((A / nb_x) / a) + 1;
|
||||
std::size_t nb = nb_x * nb_y;
|
||||
|
|
@ -382,11 +382,11 @@ namespace internal {
|
|||
for (std::size_t y = 0; y < nb_y; ++ y)
|
||||
{
|
||||
bboxes.push_back
|
||||
(CGAL::Bbox_3 (bbox.xmin() + Dx * (x / double(nb_x)),
|
||||
bbox.ymin() + Dy * (y / double(nb_y)),
|
||||
(CGAL::Bbox_3 (bbox.xmin() + Dx * (x / float(nb_x)),
|
||||
bbox.ymin() + Dy * (y / float(nb_y)),
|
||||
bbox.zmin(),
|
||||
bbox.xmin() + Dx * ((x+1) / double(nb_x)),
|
||||
bbox.ymin() + Dy * ((y+1) / double(nb_y)),
|
||||
bbox.xmin() + Dx * ((x+1) / float(nb_x)),
|
||||
bbox.ymin() + Dy * ((y+1) / float(nb_y)),
|
||||
bbox.zmax()));
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue