diff --git a/Classification/include/CGAL/Classification/ETHZ/Random_forest_classifier.h b/Classification/include/CGAL/Classification/ETHZ/Random_forest_classifier.h index 57ba4237a3d..08d0e14663b 100644 --- a/Classification/include/CGAL/Classification/ETHZ/Random_forest_classifier.h +++ b/Classification/include/CGAL/Classification/ETHZ/Random_forest_classifier.h @@ -38,10 +38,12 @@ #include +#if defined(CGAL_LINKED_WITH_BOOST_IOSTREAMS) && defined(CGAL_LINKED_WITH_BOOST_SERIALIZATION) #include #include #include #include +#endif #ifdef BOOST_MSVC # pragma warning(pop) @@ -327,6 +329,9 @@ public: [Serialization](https://www.boost.org/libs/serialization) and [IO Streams](https://www.boost.org/libs/iostreams) (compiled with the GZIP dependency). */ +#if defined(DOXYGEN_RUNNING) || \ + (defined(CGAL_LINKED_WITH_BOOST_IOSTREAMS) && \ + defined(CGAL_LINKED_WITH_BOOST_SERIALIZATION)) static void convert_deprecated_configuration_to_new_format (std::istream& input, std::ostream& output) { Label_set dummy_labels; @@ -335,10 +340,13 @@ public: classifier.load_deprecated_configuration(input); classifier.save_configuration(output); } +#endif /// @} /// \cond SKIP_IN_MANUAL +#if defined(CGAL_LINKED_WITH_BOOST_IOSTREAMS) && \ + defined(CGAL_LINKED_WITH_BOOST_SERIALIZATION) void load_deprecated_configuration (std::istream& input) { CGAL::internal::liblearning::RandomForest::ForestParams params; @@ -350,7 +358,7 @@ public: boost::archive::text_iarchive ias(ins); ias >> BOOST_SERIALIZATION_NVP(*m_rfc); } - /// \endcond +#endif }; diff --git a/Classification/include/CGAL/Classification/ETHZ/internal/random-forest/common-libraries.hpp b/Classification/include/CGAL/Classification/ETHZ/internal/random-forest/common-libraries.hpp index bff2a2c8e7a..7b3beeb7f45 100644 --- a/Classification/include/CGAL/Classification/ETHZ/internal/random-forest/common-libraries.hpp +++ b/Classification/include/CGAL/Classification/ETHZ/internal/random-forest/common-libraries.hpp @@ -40,7 +40,9 @@ #endif #include #include +#if defined(CGAL_LINKED_WITH_BOOST_IOSTREAMS) && defined(CGAL_LINKED_WITH_BOOST_SERIALIZATION) #include +#endif #include #include #include @@ -93,6 +95,7 @@ struct ForestParams { min_samples_per_node(5), sample_reduction(0.368f) {} +#if defined(CGAL_LINKED_WITH_BOOST_IOSTREAMS) && defined(CGAL_LINKED_WITH_BOOST_SERIALIZATION) template void serialize(Archive& ar, unsigned /*version*/) { @@ -105,6 +108,7 @@ struct ForestParams { ar & BOOST_SERIALIZATION_NVP(min_samples_per_node); ar & BOOST_SERIALIZATION_NVP(sample_reduction); } +#endif void write (std::ostream& os) { @@ -173,6 +177,7 @@ struct QuadraticSplitter { data_points[i_sample] = std::make_pair(sample_fval, sample_class); } } +#if defined(CGAL_LINKED_WITH_BOOST_IOSTREAMS) && defined(CGAL_LINKED_WITH_BOOST_SERIALIZATION) template void serialize(Archive& ar, unsigned /*version*/) { @@ -180,6 +185,7 @@ struct QuadraticSplitter { ar & BOOST_SERIALIZATION_NVP(w); ar & BOOST_SERIALIZATION_NVP(threshold); } +#endif }; struct LinearSplitter { @@ -211,12 +217,14 @@ struct LinearSplitter { data_points[i_sample] = std::make_pair(sample_fval, sample_class); } } +#if defined(CGAL_LINKED_WITH_BOOST_IOSTREAMS) && defined(CGAL_LINKED_WITH_BOOST_SERIALIZATION) template void serialize(Archive& ar, unsigned /*version*/) { ar & BOOST_SERIALIZATION_NVP(w); ar & BOOST_SERIALIZATION_NVP(threshold); } +#endif }; struct AxisAlignedSplitter { @@ -256,12 +264,14 @@ struct AxisAlignedSplitter { data_points.push_back(std::make_pair(sample_fval, sample_class)); } } +#if defined(CGAL_LINKED_WITH_BOOST_IOSTREAMS) && defined(CGAL_LINKED_WITH_BOOST_SERIALIZATION) template void serialize(Archive& ar, unsigned /*version*/) { ar & BOOST_SERIALIZATION_NVP(feature); ar & BOOST_SERIALIZATION_NVP(threshold); } +#endif void write (std::ostream& os) { @@ -274,7 +284,6 @@ struct AxisAlignedSplitter { is.read((char*)(&feature), sizeof(int)); is.read((char*)(&threshold), sizeof(FeatureType)); } - }; struct AxisAlignedRandomSplitGenerator { diff --git a/Classification/include/CGAL/Classification/ETHZ/internal/random-forest/forest.hpp b/Classification/include/CGAL/Classification/ETHZ/internal/random-forest/forest.hpp index baf9fa9f109..e19eaf450cc 100644 --- a/Classification/include/CGAL/Classification/ETHZ/internal/random-forest/forest.hpp +++ b/Classification/include/CGAL/Classification/ETHZ/internal/random-forest/forest.hpp @@ -223,12 +223,14 @@ public: return sum/trees.size(); } #endif +#if defined(CGAL_LINKED_WITH_BOOST_IOSTREAMS) && defined(CGAL_LINKED_WITH_BOOST_SERIALIZATION) template void serialize(Archive& ar, unsigned /* version */) { ar & BOOST_SERIALIZATION_NVP(params); ar & BOOST_SERIALIZATION_NVP(trees); } +#endif void write (std::ostream& os) { diff --git a/Classification/include/CGAL/Classification/ETHZ/internal/random-forest/node-gini.hpp b/Classification/include/CGAL/Classification/ETHZ/internal/random-forest/node-gini.hpp index 28ffea5af60..71daa606699 100644 --- a/Classification/include/CGAL/Classification/ETHZ/internal/random-forest/node-gini.hpp +++ b/Classification/include/CGAL/Classification/ETHZ/internal/random-forest/node-gini.hpp @@ -97,11 +97,13 @@ public: return std::make_pair(best_thresh, float(best_loss)); } +#if defined(CGAL_LINKED_WITH_BOOST_IOSTREAMS) && defined(CGAL_LINKED_WITH_BOOST_SERIALIZATION) template void serialize(Archive& ar, unsigned /* version */) { ar & boost::serialization::make_nvp("base", boost::serialization::base_object< Node< NodeGini, ForestParams, Splitter > >(*this)); } +#endif }; } diff --git a/Classification/include/CGAL/Classification/ETHZ/internal/random-forest/node.hpp b/Classification/include/CGAL/Classification/ETHZ/internal/random-forest/node.hpp index 10fa83fcdac..088a5a115a1 100644 --- a/Classification/include/CGAL/Classification/ETHZ/internal/random-forest/node.hpp +++ b/Classification/include/CGAL/Classification/ETHZ/internal/random-forest/node.hpp @@ -21,8 +21,15 @@ #define CGAL_INTERNAL_LIBLEARNING_RANDOMFORESTS_NODE_H #include "../dataview.h" #include "common-libraries.hpp" + +#if defined(CGAL_LINKED_WITH_BOOST_IOSTREAMS) && defined(CGAL_LINKED_WITH_BOOST_SERIALIZATION) #include #include +#else +#include +#include +#endif + #if VERBOSE_NODE_LEARNING #include #endif @@ -228,6 +235,7 @@ public: right->train(samples, labels, sample_idxes + offset_right, n_samples_right, split_generator, gen); } +#if defined(CGAL_LINKED_WITH_BOOST_IOSTREAMS) && defined(CGAL_LINKED_WITH_BOOST_SERIALIZATION) template void serialize(Archive& ar, unsigned /*version*/) { @@ -243,6 +251,7 @@ public: ar & BOOST_SERIALIZATION_NVP(right); } } +#endif void write (std::ostream& os) { diff --git a/Classification/include/CGAL/Classification/ETHZ/internal/random-forest/tree.hpp b/Classification/include/CGAL/Classification/ETHZ/internal/random-forest/tree.hpp index c0578614c1a..ba75c6e2f98 100644 --- a/Classification/include/CGAL/Classification/ETHZ/internal/random-forest/tree.hpp +++ b/Classification/include/CGAL/Classification/ETHZ/internal/random-forest/tree.hpp @@ -18,7 +18,11 @@ #define CGAL_INTERNAL_LIBLEARNING_RANDOMFOREST_TREE_H #include "../dataview.h" #include "common-libraries.hpp" +#if defined(CGAL_LINKED_WITH_BOOST_IOSTREAMS) && defined(CGAL_LINKED_WITH_BOOST_SERIALIZATION) #include +#else +#include +#endif namespace CGAL { namespace internal { @@ -115,12 +119,15 @@ public: return n_common/sqrt((n_common + n_1)*(n_common + n_2)); } #endif + +#if defined(CGAL_LINKED_WITH_BOOST_IOSTREAMS) && defined(CGAL_LINKED_WITH_BOOST_SERIALIZATION) template void serialize(Archive& ar, unsigned /*version*/) { ar & BOOST_SERIALIZATION_NVP(params); ar & BOOST_SERIALIZATION_NVP(root_node); } +#endif void write (std::ostream& os) { diff --git a/Installation/cmake/modules/CGAL_target_use_Boost_IOStreams.cmake b/Installation/cmake/modules/CGAL_target_use_Boost_IOStreams.cmake index d57f785d54f..57077271398 100644 --- a/Installation/cmake/modules/CGAL_target_use_Boost_IOStreams.cmake +++ b/Installation/cmake/modules/CGAL_target_use_Boost_IOStreams.cmake @@ -6,7 +6,7 @@ set(CGAL_target_use_Boost_IOStreams_included TRUE) function(CGAL_target_use_Boost_IOStreams target) if( WIN32 ) - # to avoid a warning with old cmake + # to avoid a warning with old cmake set(_Boost_BZIP2_HEADERS "boost/iostreams/filter/bzip2.hpp") set(_Boost_ZLIB_HEADERS "boost/iostreams/filter/zlib.hpp") find_package( Boost OPTIONAL_COMPONENTS bzip2 zlib) @@ -19,7 +19,7 @@ function(CGAL_target_use_Boost_IOStreams target) else() target_link_libraries(${target} PUBLIC ${Boost_IOSTREAMS_LIBRARY}) endif() - + if( WIN32 ) if (Boost_ZLIB_FOUND AND Boost_BZIP2_FOUND) target_link_libraries(${target} PUBLIC ${Boost_ZLIB_LIBRARY} ${Boost_BZIP2_LIBRARY}) @@ -36,4 +36,6 @@ function(CGAL_target_use_Boost_IOStreams target) endif() endif() + target_compile_options( ${target} PUBLIC -DCGAL_LINKED_WITH_BOOST_IOSTREAMS) + endfunction() diff --git a/Installation/cmake/modules/CGAL_target_use_Boost_Serialization.cmake b/Installation/cmake/modules/CGAL_target_use_Boost_Serialization.cmake index d6ae805efd8..2bf47b467ff 100644 --- a/Installation/cmake/modules/CGAL_target_use_Boost_Serialization.cmake +++ b/Installation/cmake/modules/CGAL_target_use_Boost_Serialization.cmake @@ -11,4 +11,6 @@ function(CGAL_target_use_Boost_Serialization target) target_link_libraries(${target} PUBLIC ${Boost_SERIALIZATION_LIBRARY}) endif() + target_compile_options( ${target} PUBLIC -DCGAL_LINKED_WITH_BOOST_SERIALIZATION) + endfunction()