diff --git a/BGL/include/CGAL/boost/graph/IO/OFF.h b/BGL/include/CGAL/boost/graph/IO/OFF.h index 25de24461d2..b50939957a2 100644 --- a/BGL/include/CGAL/boost/graph/IO/OFF.h +++ b/BGL/include/CGAL/boost/graph/IO/OFF.h @@ -136,20 +136,29 @@ bool write_OFF_BGL(std::ostream& os, template -bool write_OFF(std::ostream& os, const FaceGraph& g, const CGAL_BGL_NP_CLASS& np) +bool write_OFF(std::ostream& os, const FaceGraph& g, const CGAL_BGL_NP_CLASS& np, + typename boost::disable_if< + typename boost::has_range_const_iterator::type + >::type* =0) { return IO::internal::write_OFF_BGL(os, g, np); } template -bool write_OFF(const char* fname, const FaceGraph& g, const CGAL_BGL_NP_CLASS& np) +bool write_OFF(const char* fname, const FaceGraph& g, const CGAL_BGL_NP_CLASS& np + ,typename boost::disable_if< + typename boost::has_range_const_iterator::type + >::type* =0) { std::ofstream out(fname); return write_OFF(out, g, np); } template -bool write_OFF(const std::string& fname, const FaceGraph& g, const CGAL_BGL_NP_CLASS& np) +bool write_OFF(const std::string& fname, const FaceGraph& g, const CGAL_BGL_NP_CLASS& np + ,typename boost::disable_if< + typename boost::has_range_const_iterator::type + >::type* =0) { return write_OFF(fname.c_str(), g, np); } diff --git a/BGL/test/BGL/CMakeLists.txt b/BGL/test/BGL/CMakeLists.txt index 4ec7f9d683e..f3a19f68776 100644 --- a/BGL/test/BGL/CMakeLists.txt +++ b/BGL/test/BGL/CMakeLists.txt @@ -125,4 +125,17 @@ if (VTK_FOUND) message(STATUS "Tests that use VTK will not be compiled.") endif() endif() + find_path(3MF_INCLUDE_DIR + NAMES Model/COM/NMR_DLLInterfaces.h + DOC "Path to lib3MF headers" + ) + find_library(3MF_LIBRARIES NAMES 3MF DOC "Path to the lib3MF library") + if(3MF_LIBRARIES AND 3MF_INCLUDE_DIR AND EXISTS "${3MF_INCLUDE_DIR}/Model/COM/NMR_DLLInterfaces.h") + include_directories(${3MF_INCLUDE_DIR}) + create_single_source_cgal_program( test_3mf_to_sm.cpp ) + target_link_libraries(test_3mf_to_sm PRIVATE ${3MF_LIBRARIES}) + add_definitions(-DCGAL_LINKED_WITH_3MF) + else() + message(STATUS "NOTICE : This program requires the lib3MF library, and will not be compiled.") + endif() endif() #VTK_FOUND diff --git a/Stream_support/test/Stream_support/data/test.3mf b/BGL/test/BGL/data/test.3mf similarity index 100% rename from Stream_support/test/Stream_support/data/test.3mf rename to BGL/test/BGL/data/test.3mf diff --git a/Stream_support/test/Stream_support/test_3mf_to_sm.cpp b/BGL/test/BGL/test_3mf_to_sm.cpp similarity index 97% rename from Stream_support/test/Stream_support/test_3mf_to_sm.cpp rename to BGL/test/BGL/test_3mf_to_sm.cpp index f76f522718f..80fd5135865 100644 --- a/Stream_support/test/Stream_support/test_3mf_to_sm.cpp +++ b/BGL/test/BGL/test_3mf_to_sm.cpp @@ -99,7 +99,7 @@ int main(int argc, char** argv) colors.clear(); vertex_id_map.clear(); i = 0; - + vpm = get(boost::vertex_point, tube); for(auto v : tube.vertices()) { @@ -127,8 +127,8 @@ int main(int argc, char** argv) meshes.resize(2); meshes[0] = sphere; meshes[1] = tube; - // @fixme this should be in BGL - CGAL::write_triangle_meshes_to_3mf("meshes.3mf", meshes, names); + + //CGAL::write_triangle_meshes_to_3mf("meshes.3mf", meshes, names); std::cout<<"OK."< bool read_OFF( - std::istream& stream, ///< input stream. - OutputIterator output) + std::istream& stream, + OutputIterator output, + typename std::enable_if< + CGAL::is_iterator::value + >::type* =0) { return read_OFF::type> (stream, output, CGAL::parameters::all_default()); diff --git a/Point_set_processing_3/include/CGAL/IO/read_xyz_points.h b/Point_set_processing_3/include/CGAL/IO/read_xyz_points.h index ff7bd8d22bf..4404c0c8a62 100644 --- a/Point_set_processing_3/include/CGAL/IO/read_xyz_points.h +++ b/Point_set_processing_3/include/CGAL/IO/read_xyz_points.h @@ -294,8 +294,11 @@ bool read_XYZ(const std::string& fname, template bool read_XYZ( - std::istream& stream, ///< input stream. - OutputIterator output) + std::istream& stream, + OutputIterator output, + typename std::enable_if< + CGAL::is_iterator::value + >::type* =0) { return read_XYZ::type> (stream, output, CGAL::parameters::all_default()); diff --git a/Point_set_processing_3/include/CGAL/IO/write_off_points.h b/Point_set_processing_3/include/CGAL/IO/write_off_points.h index 1cb5be8b051..06673eb11f5 100644 --- a/Point_set_processing_3/include/CGAL/IO/write_off_points.h +++ b/Point_set_processing_3/include/CGAL/IO/write_off_points.h @@ -19,6 +19,7 @@ #include #include #include +#include #include @@ -115,7 +116,10 @@ bool write_OFF( const char* fname, const PointRange& points, - const NamedParameters& np) + const NamedParameters& np + ,typename boost::disable_if< + typename boost::has_range_const_iterator::type + >::type* =0) { std::ofstream os(fname); return write_OFF(os, points, np); @@ -127,7 +131,10 @@ bool write_OFF( const std::string& fname, const PointRange& points, - const NamedParameters& np) + const NamedParameters& np + ,typename boost::disable_if< + typename boost::has_range_const_iterator::type + >::type* =0) { return write_OFF(fname.c_str(), points, np); } @@ -160,7 +167,10 @@ template bool write_OFF( std::ostream& stream, ///< output stream. - const PointRange& points) + const PointRange& points, + typename boost::enable_if< + typename boost::has_range_const_iterator::type + >::type* =0) { return write_OFF (stream, points, CGAL::Point_set_processing_3::parameters::all_default(points)); @@ -170,7 +180,10 @@ template bool write_OFF( const char* fname, - const PointRange& points) + const PointRange& points, + typename boost::enable_if< + typename boost::has_range_const_iterator::type + >::type* =0) { std::ofstream os(fname); return write_OFF(os, points, CGAL::Point_set_processing_3::parameters::all_default(points)); @@ -180,7 +193,10 @@ template bool write_OFF( const std::string& fname, - const PointRange& points) + const PointRange& points + ,typename boost::enable_if< + typename boost::has_range_const_iterator::type + >::type* =0) { return write_OFF(fname, points, CGAL::Point_set_processing_3::parameters::all_default(points)); } diff --git a/Polyhedron/demo/Polyhedron/Plugins/IO/3mf_io_plugin.cpp b/Polyhedron/demo/Polyhedron/Plugins/IO/3mf_io_plugin.cpp index 90f036e8cea..f13769809b2 100644 --- a/Polyhedron/demo/Polyhedron/Plugins/IO/3mf_io_plugin.cpp +++ b/Polyhedron/demo/Polyhedron/Plugins/IO/3mf_io_plugin.cpp @@ -6,8 +6,7 @@ #include #include -#include -#include +#include #include #include "Scene_surface_mesh_item.h" @@ -241,14 +240,14 @@ class Io_3mf_plugin: color.set_rgb(c.red(), c.green(), c.blue()); } - CGAL::write_mesh_to_model(points, triangles, colors, + CGAL::IO::write_mesh_to_model(points, triangles, colors, sm_item->name().toStdString(), &pMeshObject, pModel); } for(Scene_points_with_normal_item* pts_item : pts_items) { QColor qc = pts_item->color(); CGAL::Color color(qc.red(), qc.green(), qc.blue()); - CGAL::write_point_cloud_to_model(pts_item->point_set()->points(), color, + CGAL::IO::write_point_cloud_to_model(pts_item->point_set()->points(), color, pts_item->name().toStdString(), &pMeshObject, pModel); } @@ -259,12 +258,12 @@ class Io_3mf_plugin: { QColor qc = pol_item->color(); CGAL::Color color(qc.red(), qc.green(), qc.blue()); - CGAL::write_polyline_to_model(*pol_it,color, + CGAL::IO::write_polyline_to_model(*pol_it,color, pol_item->name().toStdString(), &pMeshObject, pModel); } } - CGAL::export_model_to_file(fi.filePath().toUtf8().toStdString(), pModel); + CGAL::IO::export_model_to_file(fi.filePath().toUtf8().toStdString(), pModel); items = to_return; return true; } diff --git a/Polyhedron/demo/Polyhedron/Plugins/IO/CMakeLists.txt b/Polyhedron/demo/Polyhedron/Plugins/IO/CMakeLists.txt index 869b934d728..441b9835e95 100644 --- a/Polyhedron/demo/Polyhedron/Plugins/IO/CMakeLists.txt +++ b/Polyhedron/demo/Polyhedron/Plugins/IO/CMakeLists.txt @@ -67,11 +67,11 @@ if(has_cxx_rvalues LESS 0 OR has_cxx_variadic LESS 0) message(STATUS "NOTICE : LAS/PLY IO examples require a C++11 compiler and will not be compiled.") else() set(needed_cxx_features cxx_rvalue_references cxx_variadic_templates) - + polyhedron_demo_plugin(ply_plugin PLY_io_plugin KEYWORDS IO PointSetProcessing Classification PMP) target_link_libraries(ply_plugin PUBLIC scene_points_with_normal_item scene_polygon_soup_item scene_surface_mesh_item scene_textured_item) target_compile_features(ply_plugin PRIVATE ${needed_cxx_features}) - + if (LASLIB_FOUND) polyhedron_demo_plugin(las_plugin LAS_io_plugin KEYWORDS IO PointSetProcessing Classification) target_link_libraries(las_plugin PUBLIC scene_points_with_normal_item) @@ -93,6 +93,7 @@ if(3MF_LIBRARIES AND 3MF_INCLUDE_DIR AND EXISTS "${3MF_INCLUDE_DIR}/Model/COM/NM include_directories(${3MF_INCLUDE_DIR}) polyhedron_demo_plugin(3mf_io_plugin 3mf_io_plugin KEYWORDS IO PMP) target_link_libraries(3mf_io_plugin PRIVATE scene_surface_mesh_item scene_points_with_normal_item scene_polylines_item ${3MF_LIBRARIES}) + add_definitions(-DCGAL_LINKED_WITH_3MF) else() message(STATUS "NOTICE : The 3mf_io_plugin requires the lib3MF library in a version < 2.0, and will not be compiled.") endif() diff --git a/Polyhedron/demo/Polyhedron/Scene_points_with_normal_item.cpp b/Polyhedron/demo/Polyhedron/Scene_points_with_normal_item.cpp index 9d21e363538..b39185fbf2a 100644 --- a/Polyhedron/demo/Polyhedron/Scene_points_with_normal_item.cpp +++ b/Polyhedron/demo/Polyhedron/Scene_points_with_normal_item.cpp @@ -16,6 +16,7 @@ #include #include #include +#include #include #include diff --git a/Stream_support/include/CGAL/IO/3MF.h b/Stream_support/include/CGAL/IO/3MF.h index b88b8d8c3a9..8801f7e9363 100644 --- a/Stream_support/include/CGAL/IO/3MF.h +++ b/Stream_support/include/CGAL/IO/3MF.h @@ -32,51 +32,6 @@ namespace CGAL { //////////////////////////////////////////////////////////////////////////////////////////////////// /// Read -/*! - * \ingroup IOstreamFunctions - * - * \brief extracts ranges of points and triangles from a 3mf file. - * - * \tparam PointRanges a model of the concepts `RandomAccessContainer` and - * `BackInsertionSequence` whose `value type` is - * a model of the concepts `RandomAccessContainer` and `BackInsertionSequence` - * whose `value type` is the point type. - * \tparam PolygonRanges a model of the concept `RandomAccessContainer` whose - * `value_type` is a model of the concept `RandomAccessContainer` - * whose `value_type` is a model of the concept `RandomAccessContainer` whose - * `value_type` is std::size_t. - * \tparam ColorRanges a model of the concepts `RandomAccessContainer` and - * `BackInsertionSequence` whose `value type` is - * a model of the concepts `RandomAccessContainer` and `BackInsertionSequence` - * whose `value type` is `CGAL::Color`. - * - * \param file_name the name of the 3mf file to read. - * \param all_points a `PointRanges` that will contain the points of the meshes in `file_name`. - * Each of these meshes will add a range of its points. - * \param all_polygons a `PolygonRanges` that will contain the triangles of the meshes in `file_name`. - * Each of these meshes will add a range of its triangles. A `triangle` of - * `all_polygons[i]` contains the indices of its points in `all_points[i]`. - * \param all_colors will contain the color of each triangle for each soup. - * \param names will contain the name of each mesh in `file_name` if any. - * If the i'th mesh has no name, it will be called "Unknown Mesh" in names. - * - * \return the number of soups read. - */ -template -int read_triangle_soups_from_3mf(const std::string& file_name, - PointRanges& all_points, - PolygonRanges& all_polygons, - ColorRanges& all_colors, - std::vector& names) -{ - typedef typename PointRanges::value_type PointRange; - typedef typename PolygonRanges::value_type PolygonRange; - typedef typename ColorRanges::value_type ColorRange; - return read_from_3mf - (file_name, all_points, all_polygons, all_colors, names, - extract_soups); -} template @@ -413,6 +368,52 @@ int read_from_3mf(const std::string& file_name, return all_points.size(); } + +/*! + * \ingroup IOstreamFunctions + * + * \brief extracts ranges of points and triangles from a 3mf file. + * + * \tparam PointRanges a model of the concepts `RandomAccessContainer` and + * `BackInsertionSequence` whose `value type` is + * a model of the concepts `RandomAccessContainer` and `BackInsertionSequence` + * whose `value type` is the point type. + * \tparam PolygonRanges a model of the concept `RandomAccessContainer` whose + * `value_type` is a model of the concept `RandomAccessContainer` + * whose `value_type` is a model of the concept `RandomAccessContainer` whose + * `value_type` is std::size_t. + * \tparam ColorRanges a model of the concepts `RandomAccessContainer` and + * `BackInsertionSequence` whose `value type` is + * a model of the concepts `RandomAccessContainer` and `BackInsertionSequence` + * whose `value type` is `CGAL::Color`. + * + * \param file_name the name of the 3mf file to read. + * \param all_points a `PointRanges` that will contain the points of the meshes in `file_name`. + * Each of these meshes will add a range of its points. + * \param all_polygons a `PolygonRanges` that will contain the triangles of the meshes in `file_name`. + * Each of these meshes will add a range of its triangles. A `triangle` of + * `all_polygons[i]` contains the indices of its points in `all_points[i]`. + * \param all_colors will contain the color of each triangle for each soup. + * \param names will contain the name of each mesh in `file_name` if any. + * If the i'th mesh has no name, it will be called "Unknown Mesh" in names. + * + * \return the number of soups read. + */ +template +int read_triangle_soups_from_3mf(const std::string& file_name, + PointRanges& all_points, + PolygonRanges& all_polygons, + ColorRanges& all_colors, + std::vector& names) +{ + typedef typename PointRanges::value_type PointRange; + typedef typename PolygonRanges::value_type PolygonRange; + typedef typename ColorRanges::value_type ColorRange; + return read_from_3mf + (file_name, all_points, all_polygons, all_colors, names, + extract_soups); +} //////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////// /// Write @@ -468,10 +469,10 @@ bool write_triangle_soups_to_3mf(const std::string& file_name, } std::vector colors(all_polygons[id].size()); - write_mesh_to_model(all_points[id], all_polygons[id], colors, name, &pMeshObject, pModel); + IO::write_mesh_to_model(all_points[id], all_polygons[id], colors, name, &pMeshObject, pModel); } - return export_model_to_file(file_name, pModel); + return IO::export_model_to_file(file_name, pModel); } } // namespace CGAL diff --git a/Stream_support/include/CGAL/IO/3MF/write_3mf.h b/Stream_support/include/CGAL/IO/3MF/write_3mf.h index 4ef835d01e6..9470d2bc281 100644 --- a/Stream_support/include/CGAL/IO/3MF/write_3mf.h +++ b/Stream_support/include/CGAL/IO/3MF/write_3mf.h @@ -24,6 +24,9 @@ #include #include +/* + * \attention Only versions inferior to 2.0 of lib3mf are supported. + * */ namespace CGAL { namespace tmf_internal { @@ -59,7 +62,7 @@ NMR::MODELMESHCOLOR_SRGB fnCreateColor(unsigned char red, unsigned char green, } // namespace tmf_internal -namespace 3MF { +namespace IO { bool add_build_item(NMR::PLib3MFModel * pModel, NMR::PLib3MFModelMeshObject* pMeshObject) @@ -357,12 +360,8 @@ bool write_polyline_to_model(const PointRange& points, return write_points(points, color, pc_name, pMeshObject, pModel); } -} // namespace 3MF +} // namespace IO } // namespace CGAL - * - * \attention Only versions inferior to 2.0 of lib3mf are supported. - * - * \attention Only versions inferior to 2.0 of lib3mf are supported. #endif // CGAL_LINKED_WITH_3MF diff --git a/Stream_support/include/CGAL/IO/OFF.h b/Stream_support/include/CGAL/IO/OFF.h index 2090bffb3f1..444577ef74f 100644 --- a/Stream_support/include/CGAL/IO/OFF.h +++ b/Stream_support/include/CGAL/IO/OFF.h @@ -251,7 +251,10 @@ bool write_OFF(std::ostream& os, template bool write_OFF(std::ostream& os, const PointRange& points, - const PolygonRange& polygons) + const PolygonRange& polygons + ,typename boost::enable_if< + typename boost::has_range_const_iterator::type + >::type* =0) { return write_OFF(os, points, polygons, parameters::all_default()); } @@ -277,7 +280,10 @@ bool write_OFF(const char* fname, template bool write_OFF(const char* fname, const PointRange& points, - const PolygonRange& polygons) + const PolygonRange& polygons + ,typename boost::enable_if< + typename boost::has_range_const_iterator::type + >::type* =0) { return write_OFF(fname, points, polygons, parameters::all_default()); } @@ -294,7 +300,10 @@ bool write_OFF(const std::string& fname, template bool write_OFF(const std::string& fname, const PointRange& points, - const PolygonRange& polygons) + const PolygonRange& polygons + ,typename boost::enable_if< + typename boost::has_range_const_iterator::type + >::type* =0) { return write_OFF(fname, points, polygons, parameters::all_default()); } diff --git a/Stream_support/test/Stream_support/CMakeLists.txt b/Stream_support/test/Stream_support/CMakeLists.txt index 2a5cd413054..63a22e7254c 100644 --- a/Stream_support/test/Stream_support/CMakeLists.txt +++ b/Stream_support/test/Stream_support/CMakeLists.txt @@ -8,26 +8,12 @@ project( Stream_support_Tests ) find_package(CGAL QUIET) if ( CGAL_FOUND ) - find_path(3MF_INCLUDE_DIR - NAMES Model/COM/NMR_DLLInterfaces.h - DOC "Path to lib3MF headers" - ) - find_library(3MF_LIBRARIES NAMES 3MF DOC "Path to the lib3MF library") + # create a target per cppfile file(GLOB cppfiles RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp) foreach(cppfile ${cppfiles}) - if ( "${cppfile}" STREQUAL "test_3mf_to_sm.cpp" ) - if(3MF_LIBRARIES AND 3MF_INCLUDE_DIR AND EXISTS "${3MF_INCLUDE_DIR}/Model/COM/NMR_DLLInterfaces.h") - include_directories(${3MF_INCLUDE_DIR}) - create_single_source_cgal_program( "${cppfile}" ) - target_link_libraries(test_3mf_to_sm PRIVATE ${3MF_LIBRARIES}) - else() - message(STATUS "NOTICE : This program requires the lib3MF library, and will not be compiled.") - endif() - else() create_single_source_cgal_program( "${cppfile}" ) - endif() endforeach() else()