diff --git a/Classification/include/CGAL/Classification/ETHZ/Random_forest_classifier.h b/Classification/include/CGAL/Classification/ETHZ/Random_forest_classifier.h index e3e196cbca2..e6177577fdc 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) @@ -98,6 +100,9 @@ public: than the ones used by `other`, and in the same order. */ +#if defined(DOXYGEN_RUNNING) || \ + (defined(CGAL_LINKED_WITH_BOOST_IOSTREAMS) && \ + defined(CGAL_LINKED_WITH_BOOST_SERIALIZATION)) Random_forest_classifier (const Random_forest_classifier& other, const Feature_set& features) : m_labels (other.m_labels), m_features (features), m_rfc (nullptr) @@ -106,6 +111,7 @@ public: other.save_configuration(stream); this->load_configuration(stream); } +#endif /// \cond SKIP_IN_MANUAL ~Random_forest_classifier () @@ -280,6 +286,9 @@ public: The output file is written in an GZIP container that is readable by the `load_configuration()` method. */ +#if defined(DOXYGEN_RUNNING) || \ + (defined(CGAL_LINKED_WITH_BOOST_IOSTREAMS) && \ + defined(CGAL_LINKED_WITH_BOOST_SERIALIZATION)) void save_configuration (std::ostream& output) const { boost::iostreams::filtering_ostream outs; @@ -288,6 +297,7 @@ public: boost::archive::text_oarchive oas(outs); oas << BOOST_SERIALIZATION_NVP(*m_rfc); } +#endif /*! \brief Loads a configuration from the stream `input`. @@ -298,6 +308,9 @@ public: the ones present when the file was generated using `save_configuration()`. */ +#if defined(DOXYGEN_RUNNING) || \ + (defined(CGAL_LINKED_WITH_BOOST_IOSTREAMS) && \ + defined(CGAL_LINKED_WITH_BOOST_SERIALIZATION)) void load_configuration (std::istream& input) { CGAL::internal::liblearning::RandomForest::ForestParams params; @@ -311,6 +324,7 @@ public: boost::archive::text_iarchive ias(ins); ias >> BOOST_SERIALIZATION_NVP(*m_rfc); } +#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 ada7b290b06..97e13f532ce 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 }; struct QuadraticSplitter { @@ -149,6 +153,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*/) { @@ -156,6 +161,7 @@ struct QuadraticSplitter { ar & BOOST_SERIALIZATION_NVP(w); ar & BOOST_SERIALIZATION_NVP(threshold); } +#endif }; struct LinearSplitter { @@ -187,12 +193,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 { @@ -232,12 +240,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 }; 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 df904d206b3..6ffe0e0b719 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 get_feature_usage (std::vector& count) const { 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 3133b2f3412..f510119a557 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 get_feature_usage (std::vector& count) const { 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 119466ee2c7..c8a07f020d7 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,16 @@ 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 get_feature_usage (std::vector& count) const { root_node->get_feature_usage(count); 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()