Handle deprecated code (deprecated warnings + test)

This commit is contained in:
Simon Giraudot 2018-05-29 10:18:42 +02:00
parent 71f9425256
commit 9a5a4770a5
6 changed files with 219 additions and 6 deletions

View File

@ -28,6 +28,7 @@
#include <CGAL/Classification/Local_eigen_analysis.h>
/// \cond SKIP_IN_MANUAL
#ifndef CGAL_NO_DEPRECATED_CODE
namespace CGAL {
@ -92,6 +93,7 @@ public:
Its default name is "linearity".
*/
CGAL_DEPRECATED_MSG("you are using the deprecated feature Linearity, please update your code with Eigenvalue instead")
class Linearity
#ifdef DOXYGEN_RUNNING
: public Feature_base
@ -139,6 +141,7 @@ public:
Its default name is "planarity".
*/
CGAL_DEPRECATED_MSG("you are using the deprecated feature Planarity, please update your code with Eigenvalue instead")
class Planarity
#ifdef DOXYGEN_RUNNING
: public Feature_base
@ -186,6 +189,7 @@ public:
Its default name is "sphericity".
*/
CGAL_DEPRECATED_MSG("you are using the deprecated feature Sphericity, please update your code with Eigenvalue instead")
class Sphericity
#ifdef DOXYGEN_RUNNING
: public Feature_base
@ -233,6 +237,7 @@ public:
Its default name is "omnivariance".
*/
CGAL_DEPRECATED_MSG("you are using the deprecated feature Omnivariance, please update your code with Eigenvalue instead")
class Omnivariance
#ifdef DOXYGEN_RUNNING
: public Feature_base
@ -277,6 +282,7 @@ public:
Its default name is "anisotropy".
*/
CGAL_DEPRECATED_MSG("you are using the deprecated feature Anisotropy, please update your code with Eigenvalue instead")
class Anisotropy
#ifdef DOXYGEN_RUNNING
: public Feature_base
@ -324,6 +330,7 @@ public:
Its default name is "eigentropy".
*/
CGAL_DEPRECATED_MSG("you are using the deprecated feature Eigentropy, please update your code with Eigenvalue instead")
class Eigentropy
#ifdef DOXYGEN_RUNNING
: public Feature_base
@ -377,6 +384,7 @@ public:
Its default name is "surface_variation".
*/
CGAL_DEPRECATED_MSG("you are using the deprecated feature Surface_variation, please update your code with Eigenvalue instead")
class Surface_variation
#ifdef DOXYGEN_RUNNING
: public Feature_base
@ -417,6 +425,7 @@ public:
} // namespace CGAL
#endif
/// \endcond
#endif // CGAL_CLASSIFICATION_FEATURES_EIGEN_H

View File

@ -29,6 +29,7 @@
#include <CGAL/Classification/Feature_base.h>
/// \cond SKIP_IN_MANUAL
#ifndef CGAL_NO_DEPRECATED_CODE
namespace CGAL {
@ -83,6 +84,7 @@ namespace Feature {
is `CGAL::Classification::RGB_Color`.
*/
template <typename GeomTraits, typename PointRange, typename ColorMap>
CGAL_DEPRECATED_MSG("you are using the deprecated feature Hsv, please update your code with Color_channel instead")
class Hsv : public Feature_base
{
public:
@ -169,6 +171,7 @@ public:
} // namespace CGAL
#endif
/// \endcond
#endif // CGAL_CLASSIFICATION_FEATURE_HSV_H

View File

@ -281,6 +281,64 @@ public:
/// @}
/// \cond SKIP_IN_MANUAL
#ifndef CGAL_NO_DEPRECATED_CODE
// deprecated
template <typename VectorMap = Default,
typename ColorMap = Default,
typename EchoMap = Default>
CGAL_DEPRECATED_MSG("you are using a deprecated constructor of CGAL::Classification::Point_set_feature_generator, please update your code")
Point_set_feature_generator(Feature_set& features,
const PointRange& input,
PointMap point_map,
std::size_t nb_scales,
VectorMap normal_map = VectorMap(),
ColorMap color_map = ColorMap(),
EchoMap echo_map = EchoMap(),
float voxel_size = -1.f)
: m_input (input), m_point_map (point_map)
{
m_bbox = CGAL::bounding_box
(boost::make_transform_iterator (m_input.begin(), CGAL::Property_map_to_unary_function<PointMap>(m_point_map)),
boost::make_transform_iterator (m_input.end(), CGAL::Property_map_to_unary_function<PointMap>(m_point_map)));
CGAL::Real_timer t; t.start();
m_scales.reserve (nb_scales);
m_scales.push_back (new Scale (m_input, m_point_map, m_bbox, voxel_size));
if (voxel_size == -1.f)
voxel_size = m_scales[0]->grid_resolution();
for (std::size_t i = 1; i < nb_scales; ++ i)
{
voxel_size *= 2;
m_scales.push_back (new Scale (m_input, m_point_map, m_bbox, voxel_size, m_scales[i-1]->grid));
}
t.stop();
CGAL_CLASSIFICATION_CERR << "Scales computed in " << t.time() << " second(s)" << std::endl;
t.reset();
typedef typename Default::Get<VectorMap, typename GeomTraits::Vector_3 >::type
Vmap;
typedef typename Default::Get<ColorMap, RGB_Color >::type
Cmap;
typedef typename Default::Get<EchoMap, std::size_t >::type
Emap;
generate_point_based_features (features);
generate_normal_based_features (features, get_parameter<Vmap>(normal_map));
generate_color_based_features (features, get_parameter<Cmap>(color_map));
generate_echo_based_features (features, get_parameter<Emap>(echo_map));
}
// Functions to remove when deprecated constructor is removed
void generate_normal_based_features(const CGAL::Constant_property_map<Iterator, typename GeomTraits::Vector_3>&) { }
void generate_color_based_features(const CGAL::Constant_property_map<Iterator, RGB_Color>&) { }
void generate_echo_based_features(const CGAL::Constant_property_map<Iterator, std::size_t>&) { }
#endif
virtual ~Point_set_feature_generator()
{
clear();

View File

@ -85,10 +85,17 @@ if( WIN32 )
endif()
create_single_source_cgal_program( "test_classification_point_set.cpp" CXX_FEATURES ${needed_cxx_features} )
if(TARGET test_classification_point_set)
target_link_libraries(test_classification_point_set PUBLIC ${classification_linked_libraries})
if (TBB_FOUND)
CGAL_target_use_TBB( test_classification_point_set )
endif()
endif()
create_single_source_cgal_program( "deprecated_test_classification_point_set.cpp" CXX_FEATURES ${needed_cxx_features} )
if(TARGET deprecated_test_classification_point_set)
target_link_libraries(deprecated_test_classification_point_set PUBLIC ${classification_linked_libraries})
if (TBB_FOUND)
CGAL_target_use_TBB( deprecated_test_classification_point_set )
endif()
endif()

View File

@ -0,0 +1,136 @@
#include <CGAL/internal/disable_deprecation_warnings_and_errors.h>
#if defined (_MSC_VER) && !defined (_WIN64)
#pragma warning(disable:4244) // boost::number_distance::distance()
// converts 64 to 32 bits integers
#endif
#include <cstdlib>
#include <fstream>
#include <iostream>
#include <string>
#include <CGAL/Simple_cartesian.h>
#include <CGAL/Classification.h>
#include <CGAL/Point_set_3.h>
#include <CGAL/Random.h>
typedef CGAL::Simple_cartesian<double> Kernel;
typedef Kernel::Point_3 Point;
typedef Kernel::Vector_3 Vector;
typedef CGAL::Point_set_3<Point> Point_set;
typedef Point_set::Point_map Point_map;
typedef Kernel::Iso_cuboid_3 Iso_cuboid_3;
namespace Classification = CGAL::Classification;
typedef Classification::Label_handle Label_handle;
typedef Classification::Feature_handle Feature_handle;
typedef Classification::Label_set Label_set;
typedef Classification::Feature_set Feature_set;
typedef Classification::Sum_of_weighted_features_classifier Classifier;
typedef Classification::Point_set_feature_generator<Kernel, Point_set, Point_map> Feature_generator;
typedef Point_set::Property_map<std::size_t> Size_t_map;
typedef Point_set::Property_map<Classification::RGB_Color> Color_map;
int main (int, char**)
{
Point_set pts;
pts.add_normal_map();
bool map_added = false;
Size_t_map echo_map;
Color_map color_map;
boost::tie (echo_map, map_added) = pts.add_property_map<std::size_t> ("echo");
CGAL_assertion (map_added);
boost::tie (color_map, map_added) = pts.add_property_map<Classification::RGB_Color> ("color");
CGAL_assertion (map_added);
for (std::size_t i = 0; i < 1000; ++ i)
{
Point_set::iterator it
= pts.insert (Point (CGAL::get_default_random().get_double(),
CGAL::get_default_random().get_double(),
CGAL::get_default_random().get_double()),
Vector (CGAL::get_default_random().get_double(),
CGAL::get_default_random().get_double(),
CGAL::get_default_random().get_double()));
echo_map[*it] = std::size_t(CGAL::get_default_random().get_int(0, 4));
color_map[*it] = CGAL::make_array ((unsigned char)(CGAL::get_default_random().get_int(0, 255)),
(unsigned char)(CGAL::get_default_random().get_int(0, 255)),
(unsigned char)(CGAL::get_default_random().get_int(0, 255)));
}
Feature_set features;
Feature_generator generator (features, pts, pts.point_map(),
5, // using 5 scales
pts.normal_map(),
color_map, echo_map);
CGAL_assertion (generator.number_of_scales() == 5);
CGAL_assertion (features.size() == 80);
Label_set labels;
std::vector<int> training_set (pts.size(), -1);
for (std::size_t i = 0; i < 20; ++ i)
{
std::ostringstream oss;
oss << "label_" << i;
Label_handle lh = labels.add(oss.str().c_str());
for (std::size_t j = 0; j < 10; ++ j)
training_set[std::size_t(CGAL::get_default_random().get_int(0, int(training_set.size())))] = int(i);
}
CGAL_assertion (labels.size() == 20);
Classifier classifier (labels, features);
classifier.train<CGAL::Sequential_tag> (training_set, 800);
#ifdef CGAL_LINKED_WITH_TBB
classifier.train<CGAL::Parallel_tag> (training_set, 800);
#endif
std::vector<int> label_indices(pts.size(), -1);
Classification::classify<CGAL::Sequential_tag>
(pts, labels, classifier, label_indices);
Classification::classify_with_local_smoothing<CGAL::Sequential_tag>
(pts, pts.point_map(), labels, classifier,
generator.neighborhood().sphere_neighbor_query(0.01f),
label_indices);
Classification::classify_with_graphcut<CGAL::Sequential_tag>
(pts, pts.point_map(), labels, classifier,
generator.neighborhood().k_neighbor_query(12),
0.2f, 10, label_indices);
#ifdef CGAL_LINKED_WITH_TBB
Classification::classify<CGAL::Sequential_tag>
(pts, labels, classifier, label_indices);
Classification::classify_with_local_smoothing<CGAL::Sequential_tag>
(pts, pts.point_map(), labels, classifier,
generator.neighborhood().sphere_neighbor_query(0.01f),
label_indices);
Classification::classify_with_graphcut<CGAL::Sequential_tag>
(pts, pts.point_map(), labels, classifier,
generator.neighborhood().k_neighbor_query(12),
0.2f, 10, label_indices);
#endif
Classification::Evaluation evaluation (labels, training_set, label_indices);
return EXIT_SUCCESS;
}

View File

@ -74,12 +74,12 @@ int main (int, char**)
features.begin_parallel_additions();
#endif
Feature_generator generator (features, pts, pts.point_map(), 5); // using 5 scales
Feature_generator generator (pts, pts.point_map(), 5); // using 5 scales
generator.generate_point_based_features();
generator.generate_normal_based_features(pts.normal_map());
generator.generate_color_based_features(color_map);
generator.generate_echo_based_features(echo_map);
generator.generate_point_based_features(features);
generator.generate_normal_based_features(features, pts.normal_map());
generator.generate_color_based_features(features, color_map);
generator.generate_echo_based_features(features, echo_map);
#ifdef CGAL_LINKED_WITH_TBB
features.end_parallel_additions();