R/W for points in OFF format is now in CGAL/IO/OFF.h

This commit is contained in:
Andreas Fabri 2025-10-25 09:58:21 +01:00
parent 592b8824ec
commit 37b6a7214d
5 changed files with 231 additions and 183 deletions

View File

@ -61,7 +61,7 @@ The following table lists some \cgal data structures that have I/O functions com
</tr> </tr>
<tr> <tr>
<td>Any point range</td> <td>Any point range</td>
<td>\link PkgPointSetProcessing3IOOff CGAL::IO::read_OFF(const std::string&, PointOutputIterator)\endlink</td> <td>\link PkgStreamSupportIoFuncsOFF CGAL::IO::read_OFF(const std::string&, PointOutputIterator)\endlink</td>
</tr> </tr>
<tr> <tr>
<td>Polygon Soup</td> <td>Polygon Soup</td>
@ -89,7 +89,7 @@ The following table lists some \cgal data structures that have I/O functions com
</tr> </tr>
<tr> <tr>
<td>Any point range</td> <td>Any point range</td>
<td>\link PkgPointSetProcessing3IOOff CGAL::IO::write_OFF(const std::string&, const PointRange&)\endlink</td> <td>\link PkgStreamSupportIoFuncsOFF CGAL::IO::write_OFF(const std::string&, const PointRange&)\endlink</td>
</tr> </tr>
<tr> <tr>
<td>Polygon Soup</td> <td>Polygon Soup</td>

View File

@ -332,6 +332,213 @@ bool write_OFF(const std::string& fname,
return writer(points, polygons, np); return writer(points, polygons, np);
} }
/**
\ingroup PkgStreamSupportIoFuncsOFF
\brief reads points (positions + normals, if available), using the \ref IOStreamOFF.
\tparam OutputIteratorValueType type of objects that can be put in `PointOutputIterator`.
It must be a model of `DefaultConstructible` and defaults to `value_type_traits<PointOutputIterator>::%type`.
It can be omitted when the default is fine.
\tparam PointOutputIterator iterator over output points.
\tparam NamedParameters a sequence of \ref bgl_namedparameters "Named Parameters"
\param is input stream
\param output output iterator over points
\param np an optional sequence of \ref bgl_namedparameters "Named Parameters" among the ones listed below
\cgalNamedParamsBegin
\cgalParamNBegin{point_map}
\cgalParamDescription{a property map associating points to the elements of the point range}
\cgalParamType{a model of `WritablePropertyMap` with value type `geom_traits::Point_3`}
\cgalParamDefault{`CGAL::Identity_property_map<geom_traits::Point_3>`}
\cgalParamNEnd
\cgalParamNBegin{normal_map}
\cgalParamDescription{a property map associating normals to the elements of the point range}
\cgalParamType{a model of `WritablePropertyMap` with value type `geom_traits::Vector_3`}
\cgalParamDefault{If this parameter is omitted, normals in the input stream are ignored.}
\cgalParamNEnd
\cgalParamNBegin{geom_traits}
\cgalParamDescription{an instance of a geometric traits class}
\cgalParamType{a model of `Kernel`}
\cgalParamDefault{a \cgal Kernel deduced from the point type, using `CGAL::Kernel_traits`}
\cgalParamNEnd
\cgalNamedParamsEnd
\returns `true` if reading was successful, `false` otherwise.
\sa \ref IOStreamOFF
*/
template <typename OutputIteratorValueType,
typename PointOutputIterator,
typename CGAL_NP_TEMPLATE_PARAMETERS>
bool read_OFF(std::istream& is,
PointOutputIterator output,
const CGAL_NP_CLASS& np = parameters::default_values()
#ifndef DOXYGEN_RUNNING
, std::enable_if_t<CGAL::is_iterator<PointOutputIterator>::value>* = nullptr
#endif
);
/**
\ingroup PkgStreamSupportIoFuncsOFF
\brief reads points (positions + normals, if available), using the \ref IOStreamOFF.
\tparam OutputIteratorValueType type of objects that can be put in `PointOutputIterator`.
It must be a model of `DefaultConstructible` and defaults to `value_type_traits<PointOutputIterator>::%type`.
It can be omitted when the default is fine.
\tparam PointOutputIterator iterator over output points.
\tparam NamedParameters a sequence of \ref bgl_namedparameters "Named Parameters"
\param fname input file name
\param output output iterator over points
\param np optional sequence of \ref bgl_namedparameters "Named Parameters" among the ones listed below.
\cgalNamedParamsBegin
\cgalParamNBegin{point_map}
\cgalParamDescription{a property map associating points to the elements of the point range}
\cgalParamType{a model of `WritablePropertyMap` with value type `geom_traits::Point_3`}
\cgalParamDefault{`CGAL::Identity_property_map<geom_traits::Point_3>`}
\cgalParamNEnd
\cgalParamNBegin{normal_map}
\cgalParamDescription{a property map associating normals to the elements of the point range}
\cgalParamType{a model of `WritablePropertyMap` with value type `geom_traits::Vector_3`}
\cgalParamDefault{If this parameter is omitted, normals in the input stream are ignored.}
\cgalParamNEnd
\cgalParamNBegin{geom_traits}
\cgalParamDescription{an instance of a geometric traits class}
\cgalParamType{a model of `Kernel`}
\cgalParamDefault{a \cgal Kernel deduced from the point type, using `CGAL::Kernel_traits`}
\cgalParamNEnd
\cgalNamedParamsEnd
\returns `true` if reading was successful, `false` otherwise.
\sa \ref IOStreamOFF
*/
template <typename OutputIteratorValueType,
typename PointOutputIterator,
typename CGAL_NP_TEMPLATE_PARAMETERS>
bool read_OFF(const std::string& fname,
PointOutputIterator output,
const CGAL_NP_CLASS& np = parameters::default_values()
#ifndef DOXYGEN_RUNNING
, std::enable_if_t<CGAL::is_iterator<PointOutputIterator>::value>* = nullptr
#endif
);
/**
\ingroup PkgStreamSupportIoFuncsOFF
\brief writes the range of `points` (positions + normals, if available), using the \ref IOStreamOFF.
\tparam PointRange is a model of `ConstRange`. The value type of
its iterator is the key type of the named parameter `point_map`.
\tparam NamedParameters a sequence of \ref bgl_namedparameters "Named Parameters"
\param os output stream
\param points input point range
\param np an optional sequence of \ref bgl_namedparameters "Named Parameters" among the ones listed below
\cgalNamedParamsBegin
\cgalParamNBegin{point_map}
\cgalParamDescription{a property map associating points to the elements of the point range}
\cgalParamType{a model of `ReadablePropertyMap` with value type `geom_traits::Point_3`}
\cgalParamDefault{`CGAL::Identity_property_map<geom_traits::Point_3>`}
\cgalParamNEnd
\cgalParamNBegin{normal_map}
\cgalParamDescription{a property map associating normals to the elements of the point range}
\cgalParamType{a model of `ReadablePropertyMap` with value type `geom_traits::Vector_3`}
\cgalParamDefault{If this parameter is omitted, normals are not written in the output stream.}
\cgalParamNEnd
\cgalParamNBegin{geom_traits}
\cgalParamDescription{an instance of a geometric traits class}
\cgalParamType{a model of `Kernel`}
\cgalParamDefault{a \cgal Kernel deduced from the point type, using `CGAL::Kernel_traits`}
\cgalParamNEnd
\cgalParamNBegin{stream_precision}
\cgalParamDescription{a parameter used to set the precision (i.e. how many digits are generated) of the output stream}
\cgalParamType{int}
\cgalParamDefault{the precision of the stream `os`}
\cgalParamNEnd
\cgalNamedParamsEnd
\returns `true` if writing was successful, `false` otherwise.
*/
template <typename PointRange, typename CGAL_NP_TEMPLATE_PARAMETERS>
bool write_OFF(std::ostream& os,
const PointRange& points,
const CGAL_NP_CLASS& np = parameters::default_values()
#ifndef DOXYGEN_RUNNING
, std::enable_if_t<internal::is_Range<PointRange>::value>* = nullptr
#endif
);
/**
\ingroup PkgStreamSupportIoFuncsOFF
\brief writes the range of `points` (positions + normals, if available), using the \ref IOStreamOFF.
\tparam PointRange is a model of `ConstRange`. The value type of
its iterator is the key type of the named parameter `point_map`.
\tparam NamedParameters a sequence of \ref bgl_namedparameters "Named Parameters"
\param filename the path to the output file
\param points input point range
\param np an optional sequence of \ref bgl_namedparameters "Named Parameters" among the ones listed below
\cgalNamedParamsBegin
\cgalParamNBegin{point_map}
\cgalParamDescription{a property map associating points to the elements of the point range}
\cgalParamType{a model of `ReadablePropertyMap` with value type `geom_traits::Point_3`}
\cgalParamDefault{`CGAL::Identity_property_map<geom_traits::Point_3>`}
\cgalParamNEnd
\cgalParamNBegin{normal_map}
\cgalParamDescription{a property map associating normals to the elements of the point range}
\cgalParamType{a model of `ReadablePropertyMap` with value type `geom_traits::Vector_3`}
\cgalParamDefault{If this parameter is omitted, normals are not written in the output file.}
\cgalParamNEnd
\cgalParamNBegin{geom_traits}
\cgalParamDescription{an instance of a geometric traits class}
\cgalParamType{a model of `Kernel`}
\cgalParamDefault{a \cgal Kernel deduced from the point type, using `CGAL::Kernel_traits`}
\cgalParamNEnd
\cgalParamNBegin{stream_precision}
\cgalParamDescription{a parameter used to set the precision (i.e. how many digits are generated) of the output stream}
\cgalParamType{int}
\cgalParamDefault{`6`}
\cgalParamNEnd
\cgalNamedParamsEnd
\returns `true` if writing was successful, `false` otherwise.
\sa \ref IOStreamOFF
*/
template <typename PointRange,
typename CGAL_NP_TEMPLATE_PARAMETERS>
bool write_OFF(const std::string& filename,
const PointRange& points,
const CGAL_NP_CLASS& np = parameters::default_values()
#ifndef DOXYGEN_RUNNING
, std::enable_if_t<internal::is_Range<PointRange>::value>* = nullptr
#endif
);
} // namespace IO } // namespace IO
} // namespace CGAL } // namespace CGAL

View File

@ -24,10 +24,12 @@
#include <CGAL/Kernel_traits.h> #include <CGAL/Kernel_traits.h>
#include <CGAL/iterator.h> #include <CGAL/iterator.h>
#include <CGAL/type_traits/is_iterator.h> #include <CGAL/type_traits/is_iterator.h>
#include <CGAL/IO/OFF.h>
#include <CGAL/Named_function_parameters.h> #include <CGAL/Named_function_parameters.h>
#include <CGAL/boost/graph/named_params_helper.h> #include <CGAL/boost/graph/named_params_helper.h>
#include <iostream> #include <iostream>
#include <fstream> #include <fstream>
#include <sstream> #include <sstream>
@ -38,54 +40,14 @@ namespace CGAL {
namespace IO { namespace IO {
/** // doxygen in ../OFF.h
\ingroup PkgPointSetProcessing3IOOff
\brief reads points (positions + normals, if available), using the \ref IOStreamOFF.
\tparam OutputIteratorValueType type of objects that can be put in `PointOutputIterator`.
It must be a model of `DefaultConstructible` and defaults to `value_type_traits<PointOutputIterator>::%type`.
It can be omitted when the default is fine.
\tparam PointOutputIterator iterator over output points.
\tparam NamedParameters a sequence of \ref bgl_namedparameters "Named Parameters"
\param is input stream
\param output output iterator over points
\param np an optional sequence of \ref bgl_namedparameters "Named Parameters" among the ones listed below
\cgalNamedParamsBegin
\cgalParamNBegin{point_map}
\cgalParamDescription{a property map associating points to the elements of the point range}
\cgalParamType{a model of `WritablePropertyMap` with value type `geom_traits::Point_3`}
\cgalParamDefault{`CGAL::Identity_property_map<geom_traits::Point_3>`}
\cgalParamNEnd
\cgalParamNBegin{normal_map}
\cgalParamDescription{a property map associating normals to the elements of the point range}
\cgalParamType{a model of `WritablePropertyMap` with value type `geom_traits::Vector_3`}
\cgalParamDefault{If this parameter is omitted, normals in the input stream are ignored.}
\cgalParamNEnd
\cgalParamNBegin{geom_traits}
\cgalParamDescription{an instance of a geometric traits class}
\cgalParamType{a model of `Kernel`}
\cgalParamDefault{a \cgal Kernel deduced from the point type, using `CGAL::Kernel_traits`}
\cgalParamNEnd
\cgalNamedParamsEnd
\returns `true` if reading was successful, `false` otherwise.
\sa \ref IOStreamOFF
*/
template <typename OutputIteratorValueType, template <typename OutputIteratorValueType,
typename PointOutputIterator, typename PointOutputIterator,
typename CGAL_NP_TEMPLATE_PARAMETERS> typename CGAL_NP_TEMPLATE_PARAMETERS>
bool read_OFF(std::istream& is, bool read_OFF(std::istream& is,
PointOutputIterator output, PointOutputIterator output,
const CGAL_NP_CLASS& np = parameters::default_values() const CGAL_NP_CLASS& np,
#ifndef DOXYGEN_RUNNING std::enable_if_t<CGAL::is_iterator<PointOutputIterator>::value>*
, std::enable_if_t<CGAL::is_iterator<PointOutputIterator>::value>* = nullptr
#endif
) )
{ {
using parameters::choose_parameter; using parameters::choose_parameter;
@ -197,54 +159,14 @@ bool read_OFF(std::istream& is,
return true; return true;
} }
/** // doxygen in ../OFF.h
\ingroup PkgPointSetProcessing3IOOff
\brief reads points (positions + normals, if available), using the \ref IOStreamOFF.
\tparam OutputIteratorValueType type of objects that can be put in `PointOutputIterator`.
It must be a model of `DefaultConstructible` and defaults to `value_type_traits<PointOutputIterator>::%type`.
It can be omitted when the default is fine.
\tparam PointOutputIterator iterator over output points.
\tparam NamedParameters a sequence of \ref bgl_namedparameters "Named Parameters"
\param fname input file name
\param output output iterator over points
\param np optional sequence of \ref bgl_namedparameters "Named Parameters" among the ones listed below.
\cgalNamedParamsBegin
\cgalParamNBegin{point_map}
\cgalParamDescription{a property map associating points to the elements of the point range}
\cgalParamType{a model of `WritablePropertyMap` with value type `geom_traits::Point_3`}
\cgalParamDefault{`CGAL::Identity_property_map<geom_traits::Point_3>`}
\cgalParamNEnd
\cgalParamNBegin{normal_map}
\cgalParamDescription{a property map associating normals to the elements of the point range}
\cgalParamType{a model of `WritablePropertyMap` with value type `geom_traits::Vector_3`}
\cgalParamDefault{If this parameter is omitted, normals in the input stream are ignored.}
\cgalParamNEnd
\cgalParamNBegin{geom_traits}
\cgalParamDescription{an instance of a geometric traits class}
\cgalParamType{a model of `Kernel`}
\cgalParamDefault{a \cgal Kernel deduced from the point type, using `CGAL::Kernel_traits`}
\cgalParamNEnd
\cgalNamedParamsEnd
\returns `true` if reading was successful, `false` otherwise.
\sa \ref IOStreamOFF
*/
template <typename OutputIteratorValueType, template <typename OutputIteratorValueType,
typename PointOutputIterator, typename PointOutputIterator,
typename CGAL_NP_TEMPLATE_PARAMETERS> typename CGAL_NP_TEMPLATE_PARAMETERS>
bool read_OFF(const std::string& fname, bool read_OFF(const std::string& fname,
PointOutputIterator output, PointOutputIterator output,
const CGAL_NP_CLASS& np = parameters::default_values() const CGAL_NP_CLASS& np,
#ifndef DOXYGEN_RUNNING , std::enable_if_t<CGAL::is_iterator<PointOutputIterator>::value>*
, std::enable_if_t<CGAL::is_iterator<PointOutputIterator>::value>* = nullptr
#endif
) )
{ {
std::ifstream is(fname); std::ifstream is(fname);

View File

@ -13,8 +13,8 @@
// //
// Author(s) : Pierre Alliez and Laurent Saboret // Author(s) : Pierre Alliez and Laurent Saboret
#ifndef CGAL_IO_PLY_WRITE_OFF_POINTS_H #ifndef CGAL_IO_OFF_WRITE_OFF_POINTS_H
#define CGAL_IO_PLY_WRITE_OFF_POINTS_H #define CGAL_IO_OFF_WRITE_OFF_POINTS_H
#include <CGAL/IO/helpers.h> #include <CGAL/IO/helpers.h>
#include <CGAL/IO/OFF.h> #include <CGAL/IO/OFF.h>
@ -24,6 +24,7 @@
#include <CGAL/property_map.h> #include <CGAL/property_map.h>
#include <CGAL/Iterator_range.h> #include <CGAL/Iterator_range.h>
#include <CGAL/assertions.h> #include <CGAL/assertions.h>
#include <CGAL/IO/OFF.h>
#include <iostream> #include <iostream>
#include <fstream> #include <fstream>
@ -87,110 +88,24 @@ bool write_OFF_PSP(std::ostream& os,
namespace IO { namespace IO {
/** // // doxygen in ../OFF.h
\ingroup PkgPointSetProcessing3IOOff
\brief writes the range of `points` (positions + normals, if available), using the \ref IOStreamOFF.
\tparam PointRange is a model of `ConstRange`. The value type of
its iterator is the key type of the named parameter `point_map`.
\tparam NamedParameters a sequence of \ref bgl_namedparameters "Named Parameters"
\param os output stream
\param points input point range
\param np an optional sequence of \ref bgl_namedparameters "Named Parameters" among the ones listed below
\cgalNamedParamsBegin
\cgalParamNBegin{point_map}
\cgalParamDescription{a property map associating points to the elements of the point range}
\cgalParamType{a model of `ReadablePropertyMap` with value type `geom_traits::Point_3`}
\cgalParamDefault{`CGAL::Identity_property_map<geom_traits::Point_3>`}
\cgalParamNEnd
\cgalParamNBegin{normal_map}
\cgalParamDescription{a property map associating normals to the elements of the point range}
\cgalParamType{a model of `ReadablePropertyMap` with value type `geom_traits::Vector_3`}
\cgalParamDefault{If this parameter is omitted, normals are not written in the output stream.}
\cgalParamNEnd
\cgalParamNBegin{geom_traits}
\cgalParamDescription{an instance of a geometric traits class}
\cgalParamType{a model of `Kernel`}
\cgalParamDefault{a \cgal Kernel deduced from the point type, using `CGAL::Kernel_traits`}
\cgalParamNEnd
\cgalParamNBegin{stream_precision}
\cgalParamDescription{a parameter used to set the precision (i.e. how many digits are generated) of the output stream}
\cgalParamType{int}
\cgalParamDefault{the precision of the stream `os`}
\cgalParamNEnd
\cgalNamedParamsEnd
\returns `true` if writing was successful, `false` otherwise.
*/
template <typename PointRange, typename CGAL_NP_TEMPLATE_PARAMETERS> template <typename PointRange, typename CGAL_NP_TEMPLATE_PARAMETERS>
bool write_OFF(std::ostream& os, bool write_OFF(std::ostream& os,
const PointRange& points, const PointRange& points,
const CGAL_NP_CLASS& np = parameters::default_values() const CGAL_NP_CLASS& np,
#ifndef DOXYGEN_RUNNING std::enable_if_t<internal::is_Range<PointRange>::value>*
, std::enable_if_t<internal::is_Range<PointRange>::value>* = nullptr
#endif #endif
) )
{ {
return Point_set_processing_3::internal::write_OFF_PSP(os, points, np); return Point_set_processing_3::internal::write_OFF_PSP(os, points, np);
} }
/** // // doxygen in ../OFF.h
\ingroup PkgPointSetProcessing3IOOff
\brief writes the range of `points` (positions + normals, if available), using the \ref IOStreamOFF.
\tparam PointRange is a model of `ConstRange`. The value type of
its iterator is the key type of the named parameter `point_map`.
\tparam NamedParameters a sequence of \ref bgl_namedparameters "Named Parameters"
\param filename the path to the output file
\param points input point range
\param np an optional sequence of \ref bgl_namedparameters "Named Parameters" among the ones listed below
\cgalNamedParamsBegin
\cgalParamNBegin{point_map}
\cgalParamDescription{a property map associating points to the elements of the point range}
\cgalParamType{a model of `ReadablePropertyMap` with value type `geom_traits::Point_3`}
\cgalParamDefault{`CGAL::Identity_property_map<geom_traits::Point_3>`}
\cgalParamNEnd
\cgalParamNBegin{normal_map}
\cgalParamDescription{a property map associating normals to the elements of the point range}
\cgalParamType{a model of `ReadablePropertyMap` with value type `geom_traits::Vector_3`}
\cgalParamDefault{If this parameter is omitted, normals are not written in the output file.}
\cgalParamNEnd
\cgalParamNBegin{geom_traits}
\cgalParamDescription{an instance of a geometric traits class}
\cgalParamType{a model of `Kernel`}
\cgalParamDefault{a \cgal Kernel deduced from the point type, using `CGAL::Kernel_traits`}
\cgalParamNEnd
\cgalParamNBegin{stream_precision}
\cgalParamDescription{a parameter used to set the precision (i.e. how many digits are generated) of the output stream}
\cgalParamType{int}
\cgalParamDefault{`6`}
\cgalParamNEnd
\cgalNamedParamsEnd
\returns `true` if writing was successful, `false` otherwise.
\sa \ref IOStreamOFF
*/
template <typename PointRange, template <typename PointRange,
typename CGAL_NP_TEMPLATE_PARAMETERS> typename CGAL_NP_TEMPLATE_PARAMETERS>
bool write_OFF(const std::string& filename, bool write_OFF(const std::string& filename,
const PointRange& points, const PointRange& points,
const CGAL_NP_CLASS& np = parameters::default_values() const CGAL_NP_CLASS& np, std::enable_if_t<internal::is_Range<PointRange>::value>*
#ifndef DOXYGEN_RUNNING
, std::enable_if_t<internal::is_Range<PointRange>::value>* = nullptr
#endif
) )
{ {
std::ofstream os(filename); std::ofstream os(filename);
@ -202,4 +117,4 @@ bool write_OFF(const std::string& filename,
} // namespace CGAL } // namespace CGAL
#endif // CGAL_IO_PLY_WRITE_OFF_POINTS_H #endif // CGAL_IO_OFF_WRITE_OFF_POINTS_H

View File

@ -8,5 +8,9 @@
// //
// Author(s) : Simon Giraudot // Author(s) : Simon Giraudot
#include <CGAL/IO/OFF/read_off_points.h> #ifndef CGAL_IO_READ_OFF_POINTS_H
#define CGAL_IO_READ_OFF_POINTS_H
#include <CGAL/IO/OFF.h>
#endif // CGAL_IO_READ_OFF_POINTS_H