mirror of https://github.com/CGAL/cgal
Reduce memory usage of features
This commit is contained in:
parent
77a590d338
commit
acb17da8c8
|
|
@ -77,14 +77,11 @@ public:
|
|||
#endif
|
||||
{
|
||||
this->set_name ("distance_to_plane");
|
||||
|
||||
#ifndef CGAL_CLASSIFICATION_PRECOMPUTE_FEATURES
|
||||
std::vector<double> distance_to_plane_feature;
|
||||
#endif
|
||||
|
||||
#ifdef CGAL_CLASSIFICATION_PRECOMPUTE_FEATURES
|
||||
for(std::size_t i = 0; i < input.size(); i++)
|
||||
distance_to_plane_feature.push_back
|
||||
(CGAL::sqrt (CGAL::squared_distance (get(point_map, *(input.begin()+i)), eigen.plane(i))));
|
||||
#endif
|
||||
}
|
||||
|
||||
/// \cond SKIP_IN_MANUAL
|
||||
|
|
|
|||
|
|
@ -53,15 +53,19 @@ public:
|
|||
{
|
||||
}
|
||||
|
||||
#ifdef CGAL_CLASSIFICATION_PRECOMPUTE_FEATURES
|
||||
virtual void init (const PointRange& input, const Local_eigen_analysis& eigen)
|
||||
{
|
||||
#ifndef CGAL_CLASSIFICATION_PRECOMPUTE_FEATURES
|
||||
std::vector<double> attrib;
|
||||
#endif
|
||||
|
||||
attrib.reserve (input.size());
|
||||
for (std::size_t i = 0; i < input.size(); ++ i)
|
||||
attrib.push_back (get_value (eigen, i));
|
||||
}
|
||||
#else
|
||||
virtual void init (const PointRange&, const Local_eigen_analysis&)
|
||||
{
|
||||
}
|
||||
#endif
|
||||
|
||||
virtual double get_value (const Local_eigen_analysis& eigen, std::size_t i) = 0;
|
||||
virtual double value (std::size_t pt_index)
|
||||
|
|
|
|||
|
|
@ -103,14 +103,14 @@ public:
|
|||
: input(input), color_map(color_map), m_channel(channel), m_mean(mean), m_sd(sd)
|
||||
#endif
|
||||
{
|
||||
#ifndef CGAL_CLASSIFICATION_PRECOMPUTE_FEATURES
|
||||
std::vector<double> color_feature;
|
||||
#endif
|
||||
|
||||
#ifdef CGAL_CLASSIFICATION_PRECOMPUTE_FEATURES
|
||||
for(std::size_t i = 0; i < input.size();i++)
|
||||
{
|
||||
HSV_Color c = Classification::rgb_to_hsv (get(color_map, *(input.begin()+i)));
|
||||
color_feature.push_back (std::exp (-(c[channel] - mean) * (c[channel] - mean) / (2. * sd * sd)));
|
||||
}
|
||||
#endif
|
||||
|
||||
std::ostringstream oss;
|
||||
if (channel == 0) oss << "hue";
|
||||
|
|
|
|||
|
|
@ -55,7 +55,11 @@ 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
|
||||
|
||||
public:
|
||||
/*!
|
||||
|
|
@ -64,11 +68,12 @@ public:
|
|||
\param input input range.
|
||||
\param eigen class with precomputed eigenvectors and eigenvalues.
|
||||
*/
|
||||
#ifdef CGAL_CLASSIFICATION_PRECOMPUTE_FEATURES
|
||||
Verticality (const PointRange& input,
|
||||
const Local_eigen_analysis& eigen)
|
||||
: vertical (0., 0., 1.)
|
||||
{
|
||||
this->set_name ("verticality");
|
||||
typename Geom_traits::Vector_3 vertical (0., 0., 1.);
|
||||
|
||||
for (std::size_t i = 0; i < input.size(); i++)
|
||||
{
|
||||
|
|
@ -76,8 +81,15 @@ public:
|
|||
normal = normal / CGAL::sqrt (normal * normal);
|
||||
verticality_feature.push_back (1. - CGAL::abs(normal * vertical));
|
||||
}
|
||||
|
||||
}
|
||||
#else
|
||||
Verticality (const PointRange&,
|
||||
const Local_eigen_analysis& eigen)
|
||||
: vertical (0., 0., 1.), eigen (eigen)
|
||||
{
|
||||
this->set_name ("verticality");
|
||||
}
|
||||
#endif
|
||||
|
||||
/*!
|
||||
\brief Constructs the feature using provided normals of points.
|
||||
|
|
@ -91,10 +103,9 @@ public:
|
|||
template <typename VectorMap>
|
||||
Verticality (const PointRange& input,
|
||||
VectorMap normal_map)
|
||||
: vertical (0., 0., 1.)
|
||||
{
|
||||
this->set_name ("verticality");
|
||||
typename Geom_traits::Vector_3 vertical (0., 0., 1.);
|
||||
|
||||
for (std::size_t i = 0; i < input.size(); i++)
|
||||
{
|
||||
typename Geom_traits::Vector_3 normal = get(normal_map, *(input.begin()+i));
|
||||
|
|
@ -107,7 +118,16 @@ public:
|
|||
/// \cond SKIP_IN_MANUAL
|
||||
virtual double value (std::size_t pt_index)
|
||||
{
|
||||
return verticality_feature[pt_index];
|
||||
#ifndef CGAL_CLASSIFICATION_PRECOMPUTE_FEATURES
|
||||
if (verticality_feature.empty())
|
||||
{
|
||||
typename Geom_traits::Vector_3 normal = eigen.normal_vector(pt_index);
|
||||
normal = normal / CGAL::sqrt (normal * normal);
|
||||
return (1. - CGAL::abs(normal * vertical));
|
||||
}
|
||||
else
|
||||
#endif
|
||||
return verticality_feature[pt_index];
|
||||
}
|
||||
/// \endcond
|
||||
};
|
||||
|
|
|
|||
|
|
@ -119,8 +119,10 @@ private:
|
|||
std::vector<double> m_sum_eigenvalues;
|
||||
std::vector<Point> m_centroids;
|
||||
std::vector<Vector> m_smallest_eigenvectors;
|
||||
#ifdef CGAL_CLASSIFICATION_EIGEN_FULL_STORAGE
|
||||
std::vector<Vector> m_middle_eigenvectors;
|
||||
std::vector<Vector> m_largest_eigenvectors;
|
||||
#endif
|
||||
double m_mean_range;
|
||||
|
||||
|
||||
|
|
@ -159,8 +161,10 @@ public:
|
|||
m_sum_eigenvalues.resize (input.size());
|
||||
m_centroids.resize (input.size());
|
||||
m_smallest_eigenvectors.resize (input.size());
|
||||
#ifdef CGAL_CLASSIFICATION_EIGEN_FULL_STORAGE
|
||||
m_middle_eigenvectors.resize (input.size());
|
||||
m_largest_eigenvectors.resize (input.size());
|
||||
#endif
|
||||
|
||||
m_mean_range = 0.;
|
||||
|
||||
|
|
@ -229,8 +233,10 @@ private:
|
|||
m_eigenvalues[index] = v;
|
||||
m_centroids[index] = query;
|
||||
m_smallest_eigenvectors[index] = Vector (0., 0., 1.);
|
||||
#ifdef CGAL_CLASSIFICATION_EIGEN_FULL_STORAGE
|
||||
m_middle_eigenvectors[index] = Vector (0., 1., 0.);
|
||||
m_largest_eigenvectors[index] = Vector (1., 0., 0.);
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -266,9 +272,10 @@ private:
|
|||
m_sum_eigenvalues[index] = sum;
|
||||
m_eigenvalues[index] = evalues;
|
||||
m_smallest_eigenvectors[index] = Vector (evectors[0], evectors[1], 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]);
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in New Issue