Countless IO fixes...

Don't have the patience to split it nicely
This commit is contained in:
Mael Rouxel-Labbé 2020-06-21 11:52:08 +02:00
parent f1996bd6b4
commit 2d49f7d702
53 changed files with 998 additions and 737 deletions

View File

@ -7,7 +7,7 @@
#include <CGAL/Classification.h>
#include <CGAL/bounding_box.h>
#include <CGAL/tags.h>
#include <CGAL/IO/read_ply_points.h>
#include <CGAL/IO/read_points.h>
#include <CGAL/Real_timer.h>
@ -52,8 +52,7 @@ int main (int argc, char** argv)
std::vector<Point> pts;
std::cerr << "Reading input" << std::endl;
if (!in
|| !(CGAL::read_PLY (in, std::back_inserter (pts))))
if (!in || !(CGAL::read_points(in, std::back_inserter(pts))))
{
std::cerr << "Error: cannot read " << filename << std::endl;
return EXIT_FAILURE;

View File

@ -3,15 +3,15 @@
// converts 64 to 32 bits integers
#endif
#include <CGAL/Simple_cartesian.h>
#include <CGAL/Classification.h>
#include <CGAL/IO/read_points.h>
#include <cstdlib>
#include <fstream>
#include <iostream>
#include <string>
#include <CGAL/Simple_cartesian.h>
#include <CGAL/Classification.h>
#include <CGAL/IO/read_ply_points.h>
typedef CGAL::Simple_cartesian<double> Kernel;
typedef Kernel::Point_3 Point;
typedef Kernel::Iso_cuboid_3 Iso_cuboid_3;
@ -71,8 +71,7 @@ int main (int argc, char** argv)
std::vector<Point> pts;
std::cerr << "Reading input" << std::endl;
if (!in
|| !(CGAL::read_PLY (in, std::back_inserter (pts))))
if (!in || !(CGAL::read_points(in, std::back_inserter(pts))))
{
std::cerr << "Error: cannot read " << filename << std::endl;
return EXIT_FAILURE;

View File

@ -1,7 +1,7 @@
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/convex_hull_3.h>
#include <CGAL/Extreme_points_traits_adapter_3.h>
#include <CGAL/IO/read_off_points.h>
#include <CGAL/IO/read_points.h>
#include <boost/iterator/counting_iterator.hpp>
@ -23,7 +23,7 @@ int main(int argc, char* argv[])
}
std::vector<Point_3> points;
CGAL::read_off_points(in, std::back_inserter(points));
CGAL::read_points(in, std::back_inserter(points));
//This will contain the extreme vertices
std::vector<std::size_t> extreme_point_indices;

View File

@ -83,12 +83,12 @@ a newline character and each coordinate separated by a white
space. Other formats available are 'OFF', 'PLY' and 'LAS'. \cgal
provides functions to read such formats:
- `read_xyz_points()`
- `read_off_points()`
- `read_ply_points()`
- `read_ply_points_with_properties()` to read additional PLY properties
- `read_las_points()`
- `read_las_points_with_properties()` to read additional LAS properties
- `read_XYZ()`
- `read_OFF()`
- `read_PLY()`
- `read_PLY_with_properties()` to read additional PLY properties
- `read_LAS()`
- `read_LAS_with_properties()` to read additional LAS properties
\cgal also provides a dedicated container `CGAL::Point_set_3` to
handle point sets with additional properties such as normal

View File

@ -16,7 +16,7 @@ int main (int argc, char** argv)
Point_set point_set;
// Reading input in XYZ format
if (!f || !CGAL::read_XYZ (f, point_set))
if (!f || !CGAL::read_point_set(f, point_set))
{
std::cerr<<"Can't read input file "
<<(argc > 1 ? argv[1] : "data/oni.xyz")<< std::endl;

View File

@ -1,6 +1,6 @@
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/Point_set_3.h>
#include <CGAL/IO/read_off_points.h>
#include <fstream>
#include <limits>
@ -19,11 +19,9 @@ int main (int argc, char** argv)
Point_set point_set;
point_set.add_normal_map();
// Reading input in OFF format
if (!f || !CGAL::read_OFF
(f,
point_set.index_back_inserter(), // OutputIterator
CGAL::parameters::point_map(point_set.point_push_map()).
normal_map(point_set.normal_push_map())))
if (!f || !CGAL::read_point_set(f, point_set.index_back_inserter(), // OutputIterator
CGAL::parameters::point_map(point_set.point_push_map())
.normal_map(point_set.normal_push_map())))
{
std::cerr << "Can't read input file " << std::endl;
return EXIT_FAILURE;

View File

@ -72,7 +72,7 @@ std::istream& operator>>(std::istream& is,
CGAL::read_PLY(is, ps);
#ifdef CGAL_LINKED_WITH_LASLIB
else if(line.find("LASF") == 0)
CGAL::read_las_points(is, ps);
CGAL::read_LAS(is, ps);
#endif // LAS
else
CGAL::read_XYZ(is, ps);
@ -171,28 +171,38 @@ std::ostream& operator<<(std::ostream& os,
\tparam Point a `CGAL::Point_3`
\tparam Vector a `CGAL::Vector_3`
\tparam NamedParameters a sequence of \ref bgl_namedparameters "Named Parameters"
\param fname the path to the output file
\param ps the point set.
\param ps the point set
\param np an optional sequence of \ref bgl_namedparameters "Named Parameters" among the ones listed below
\cgalNamedParamsBegin
\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
\return `true` if the writing was successful, `false` otherwise.
*/
template <typename Point,
typename Vector>
bool write_point_set(const std::string& fname,
CGAL::Point_set_3<Point, Vector>& ps)
template <typename Point, typename Vector, typename CGAL_BGL_NP_TEMPLATE_PARAMETERS>
bool write_point_set(const char* fname,
CGAL::Point_set_3<Point, Vector>& ps,
const CGAL_BGL_NP_CLASS& np)
{
const std::string ext = IO::internal::get_file_extension(fname);
if(ext == "xyz")
return write_XYZ(fname, ps);
return write_XYZ(fname, ps, np);
else if(ext == "off")
return write_OFF(fname, ps);
return write_OFF(fname, ps, np);
else if(ext == "ply")
return write_PLY(fname, ps);
return write_PLY(fname, ps, np);
#ifdef CGAL_LINKED_WITH_LASLIB
else if(ext == "las")
return write_LAS(fname, ps);
return write_LAS(fname, ps, np);
#endif
return false;
@ -201,7 +211,19 @@ bool write_point_set(const std::string& fname,
template <typename Point, typename Vector>
bool write_point_set(const char* fname, CGAL::Point_set_3<Point, Vector>& ps)
{
return write_point_set(std::string(fname), ps);
return write_point_set(fname, ps, parameters::all_default());
}
template <typename Point, typename Vector, typename CGAL_BGL_NP_TEMPLATE_PARAMETERS>
bool write_point_set(const std::string& fname, CGAL::Point_set_3<Point, Vector>& ps, const CGAL_BGL_NP_CLASS& np)
{
return write_point_set(fname.c_str(), ps, np);
}
template <typename Point, typename Vector>
bool write_point_set(const std::string& fname, CGAL::Point_set_3<Point, Vector>& ps)
{
return write_point_set(fname.c_str(), ps, parameters::all_default());
}
} // namespace CGAL

View File

@ -65,16 +65,16 @@ void check_if_property_is_used(PointSet& point_set,
\tparam Point a `CGAL::Point_3`
\tparam Vector a `CGAL::Vector_3`
\param stream the input stream
\param point_set the point set.
\param is the input stream
\param point_set the point set
\return `true` if the reading was successful, `false` otherwise.
*/
template <typename Point, typename Vector>
bool read_LAS(std::istream& stream,
bool read_LAS(std::istream& is,
CGAL::Point_set_3<Point, Vector>& point_set)
{
if(!stream)
if(!is)
{
std::cerr << "Error: cannot open file" << std::endl;
return false;
@ -108,7 +108,7 @@ bool read_LAS(std::istream& stream,
bool okay
= read_LAS_with_properties
(stream, point_set.index_back_inserter(),
(is, point_set.index_back_inserter(),
make_las_point_reader(point_set.point_push_map()),
std::make_pair(point_set.push_property_map(intensity), LAS_property::Intensity()),
std::make_pair(point_set.push_property_map(return_number), LAS_property::Return_number()),
@ -172,10 +172,10 @@ bool read_LAS(const std::string& fname, CGAL::Point_set_3<Point, Vector>& point_
\deprecated This function is deprecated since \cgal 5.2, `CGAL::read_LAS()` should be used instead.
*/
template <typename Point, typename Vector>
CGAL_DEPRECATED bool read_las_point_set(std::istream& stream, ///< input stream.
CGAL_DEPRECATED bool read_las_point_set(std::istream& is, ///< input stream.
CGAL::Point_set_3<Point, Vector>& point_set) ///< point set
{
return read_LAS(stream, point_set);
return read_LAS(is, point_set);
}
#endif // CGAL_NO_DEPRECATED_CODE
@ -191,22 +191,36 @@ CGAL_DEPRECATED bool read_las_point_set(std::istream& stream, ///< input stream.
\tparam Point a `CGAL::Point_3`
\tparam Vector a `CGAL::Vector_3`
\tparam NamedParameters a sequence of \ref bgl_namedparameters "Named Parameters"
\param stream the output stream
\param point_set the point set.
\param os the output stream
\param point_set the point set
\param np an optional sequence of \ref bgl_namedparameters "Named Parameters" among the ones listed below
\cgalNamedParamsBegin
\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
\return `true` if the writing was successful, `false` otherwise.
*/
template <typename Point, typename Vector>
bool write_LAS(std::ostream& stream,
CGAL::Point_set_3<Point, Vector>& point_set)
template <typename Point, typename Vector, typename CGAL_BGL_NP_TEMPLATE_PARAMETERS>
bool write_LAS(std::ostream& os,
CGAL::Point_set_3<Point, Vector>& point_set,
const CGAL_BGL_NP_CLASS& np)
{
if(!stream)
if(!os)
{
std::cerr << "Error: cannot open file" << std::endl;
return false;
}
const int precision = parameters::choose_parameter(parameters::get_parameter(np, internal_np::stream_precision), 6);
os << std::setprecision(precision);
typedef CGAL::Point_set_3<Point, Vector> Point_set;
typedef typename Point_set::template Property_map<float> Float_map;
typedef typename Point_set::template Property_map<double> Double_map;
@ -324,7 +338,7 @@ bool write_LAS(std::ostream& stream,
bool okay
= write_LAS_with_properties
(stream, point_set,
(os, point_set,
make_las_point_writer(point_set.point_map()),
std::make_pair(intensity, LAS_property::Intensity()),
std::make_pair(return_number, LAS_property::Return_number()),
@ -367,6 +381,12 @@ bool write_LAS(std::ostream& stream,
return okay;
}
template <typename Point, typename Vector>
bool write_LAS(std::ostream& os, CGAL::Point_set_3<Point, Vector>& point_set)
{
return write_LAS(os, point_set, parameters::all_default());
}
/*!
\ingroup PkgPointSet3IO
@ -374,23 +394,46 @@ bool write_LAS(std::ostream& stream,
\tparam Point a `CGAL::Point_3`
\tparam Vector a `CGAL::Vector_3`
\tparam NamedParameters a sequence of \ref bgl_namedparameters "Named Parameters"
\param fname the path to the output file
\param point_set the point set.
\param point_set the point set
\param np an optional sequence of \ref bgl_namedparameters "Named Parameters" among the ones listed below
\cgalNamedParamsBegin
\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
\return `true` if the writing was successful, `false` otherwise.
*/
template <typename Point, typename Vector, typename CGAL_BGL_NP_TEMPLATE_PARAMETERS>
bool write_LAS(const char* fname, CGAL::Point_set_3<Point, Vector>& point_set, const CGAL_BGL_NP_CLASS& np)
{
std::ofstream os(fname);
return write_LAS(os, point_set, np);
}
template <typename Point, typename Vector>
bool write_LAS(const char* fname, CGAL::Point_set_3<Point, Vector>& point_set)
{
std::ofstream os(fname);
return write_LAS(os, point_set);
return write_LAS(os, point_set, parameters::all_default());
}
template <typename Point, typename Vector, typename CGAL_BGL_NP_TEMPLATE_PARAMETERS>
bool write_LAS(const std::string& fname, CGAL::Point_set_3<Point, Vector>& point_set, const CGAL_BGL_NP_CLASS& np)
{
return write_LAS(fname.c_str(), point_set, np);
}
template <typename Point, typename Vector>
bool write_LAS(const std::string& fname, CGAL::Point_set_3<Point, Vector>& point_set)
{
return write_LAS(fname.c_str(), point_set);
return write_LAS(fname.c_str(), point_set, parameters::all_default());
}
#ifndef CGAL_NO_DEPRECATED_CODE
@ -401,10 +444,10 @@ bool write_LAS(const std::string& fname, CGAL::Point_set_3<Point, Vector>& point
\deprecated This function is deprecated since \cgal 5.2, `CGAL::write_LAS()` should be used instead.
*/
template <typename Point, typename Vector>
CGAL_DEPRECATED bool write_las_point_set(std::ostream& stream, ///< output stream.
CGAL_DEPRECATED bool write_las_point_set(std::ostream& os, ///< output stream.
CGAL::Point_set_3<Point, Vector>& point_set) ///< point set
{
return write_LAS(stream, point_set);
return write_LAS(os, point_set);
}
#endif // CGAL_NO_DEPRECATED_CODE

View File

@ -46,21 +46,20 @@ class Point_set_3;
\tparam Point a `CGAL::Point_3`
\tparam Vector a `CGAL::Vector_3`
\param stream the input stream
\param point_set the point set.
\param is the input stream
\param point_set the point set
\return `true` if the reading was successful, `false` otherwise.
\see \ref IOStreamOFF
*/
template <typename Point, typename Vector>
bool read_OFF(std::istream& stream,
bool read_OFF(std::istream& is,
CGAL::Point_set_3<Point, Vector>& point_set)
{
point_set.add_normal_map();
bool out = CGAL::read_OFF(stream,
point_set.index_back_inserter(),
bool out = CGAL::read_OFF(is, point_set.index_back_inserter(),
CGAL::parameters::point_map(point_set.point_push_map())
.normal_map(point_set.normal_push_map()));
@ -88,16 +87,15 @@ bool read_OFF(std::istream& stream,
\tparam Point a `CGAL::Point_3`
\tparam Vector a `CGAL::Vector_3`
\param fname the path to the input file.
\param point_set the point set.
\param fname the path to the input file
\param point_set the point set
\return `true` if the reading was successful, `false` otherwise.
\see \ref IOStreamOFF
*/
template <typename Point, typename Vector>
bool read_OFF(const char* fname,
CGAL::Point_set_3<Point, Vector>& point_set)
bool read_OFF(const char* fname, CGAL::Point_set_3<Point, Vector>& point_set)
{
std::ifstream is(fname);
return read_OFF(is, point_set);
@ -117,10 +115,10 @@ bool read_OFF(const std::string& fname, CGAL::Point_set_3<Point, Vector>& point_
\deprecated This function is deprecated since \cgal 5.2, `CGAL::read_OFF()` should be used instead.
*/
template <typename Point, typename Vector>
CGAL_DEPRECATED bool read_off_point_set(std::istream& stream, ///< input stream.
CGAL_DEPRECATED bool read_off_point_set(std::istream& is, ///< input stream.
CGAL::Point_set_3<Point, Vector>& point_set) ///< point set.
{
return read_OFF(stream, point_set);
return read_OFF(is, point_set);
}
#endif // CGAL_NO_DEPRECATED_CODE
@ -131,53 +129,98 @@ CGAL_DEPRECATED bool read_off_point_set(std::istream& stream, ///< input stream
/*!
\ingroup PkgPointSet3IO
writes the content of a point set into an output stream in the OFF format.
\tparam Point a `CGAL::Point_3`
\tparam Vector a `CGAL::Vector_3`
\tparam NamedParameters a sequence of \ref bgl_namedparameters "Named Parameters"
\param stream the output stream
\param point_set the point set.
\param os the output stream
\param point_set the point set
\param np an optional sequence of \ref bgl_namedparameters "Named Parameters" among the ones listed below
\cgalNamedParamsBegin
\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
\return `true` if the writing was successful, `false` otherwise.
\see \ref IOStreamOFF
*/
template <typename Point, typename Vector>
bool write_OFF(std::ostream& stream,
const CGAL::Point_set_3<Point, Vector>& point_set)
template <typename Point, typename Vector, typename CGAL_BGL_NP_TEMPLATE_PARAMETERS>
bool write_OFF(std::ostream& os,
const CGAL::Point_set_3<Point, Vector>& point_set,
const CGAL_BGL_NP_CLASS& np)
{
if(point_set.has_normal_map())
return CGAL::write_OFF(stream, point_set,
CGAL::parameters::point_map(point_set.point_map())
.normal_map(point_set.normal_map()));
return Point_set_processing_3::internal::write_OFF_PSP(os, point_set,
np.point_map(point_set.point_map())
.normal_map(point_set.normal_map()));
return CGAL::write_OFF(stream, point_set, CGAL::parameters::point_map(point_set.point_map()));
return Point_set_processing_3::internal::write_OFF_PSP(os, point_set,
np.point_map(point_set.point_map()));
}
template <typename Point, typename Vector>
bool write_OFF(std::ostream& os, const CGAL::Point_set_3<Point, Vector>& point_set)
{
return write_OFF(os, point_set, parameters::all_default());
}
/*!
\ingroup PkgPointSet3IO
writes the content of a point set into an output file in the OFF format.
\tparam Point a `CGAL::Point_3`
\tparam Vector a `CGAL::Vector_3`
\tparam NamedParameters a sequence of \ref bgl_namedparameters "Named Parameters"
\param fname the path to the output file
\param point_set the point set.
\param point_set the point set
\param np an optional sequence of \ref bgl_namedparameters "Named Parameters" among the ones listed below
\cgalNamedParamsBegin
\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
\return `true` if the writing was successful, `false` otherwise.
\see \ref IOStreamOFF
*/
template <typename Point, typename Vector, typename CGAL_BGL_NP_TEMPLATE_PARAMETERS>
bool write_OFF(const char* fname, const CGAL::Point_set_3<Point, Vector>& point_set, const CGAL_BGL_NP_CLASS& np)
{
std::ofstream os(fname);
return write_OFF(os, point_set, np);
}
template <typename Point, typename Vector>
bool write_OFF(const char* fname, const CGAL::Point_set_3<Point, Vector>& point_set)
{
std::ofstream os(fname);
return write_OFF(os, point_set);
return write_OFF(os, point_set, parameters::all_default());
}
template <typename Point, typename Vector, typename CGAL_BGL_NP_TEMPLATE_PARAMETERS>
bool write_OFF(const std::string& fname, const CGAL::Point_set_3<Point, Vector>& point_set, const CGAL_BGL_NP_CLASS& np)
{
return write_OFF(fname.c_str(), point_set, np);
}
template <typename Point, typename Vector>
bool write_OFF(const std::string& fname, const CGAL::Point_set_3<Point, Vector>& point_set)
{
return write_OFF(fname.c_str(), point_set);
return write_OFF(fname.c_str(), point_set, parameters::all_default());
}
#ifndef CGAL_NO_DEPRECATED_CODE
@ -188,10 +231,10 @@ bool write_OFF(const std::string& fname, const CGAL::Point_set_3<Point, Vector>&
\deprecated This function is deprecated since \cgal 5.2, `CGAL::write_OFF()` should be used instead.
*/
template <typename Point, typename Vector>
CGAL_DEPRECATED bool write_off_point_set(std::ostream& stream, ///< output stream.
CGAL_DEPRECATED bool write_off_point_set(std::ostream& os, ///< output stream.
const CGAL::Point_set_3<Point, Vector>& point_set) ///< point set
{
return write_OFF(stream, point_set);
return write_OFF(os, point_set);
}
#endif // CGAL_NO_DEPRECATED_CODE

View File

@ -15,6 +15,8 @@
#include <CGAL/Point_set_3.h>
#include <CGAL/boost/graph/Named_function_parameters.h>
#include <CGAL/boost/graph/named_params_helper.h>
#include <CGAL/IO/PLY.h>
#include <CGAL/IO/io.h>
@ -22,6 +24,11 @@
#include <string>
#include <vector>
#ifdef DOXYGEN_RUNNING
#define CGAL_BGL_NP_TEMPLATE_PARAMETERS NamedParameters
#define CGAL_BGL_NP_CLASS NamedParameters
#endif
namespace CGAL {
template <typename Point, typename Vector>
@ -242,11 +249,11 @@ public:
\see \ref IOStreamPLY
*/
template <typename Point, typename Vector>
bool read_PLY(std::istream& stream,
bool read_PLY(std::istream& is,
CGAL::Point_set_3<Point, Vector>& point_set,
std::string& comments)
{
if(!stream)
if(!is)
{
std::cerr << "Error: cannot open file" << std::endl;
return false;
@ -255,9 +262,9 @@ bool read_PLY(std::istream& stream,
IO::internal::PLY_reader reader(true);
IO::internal::Point_set_3_filler<Point, Vector> filler(point_set);
if(!(reader.init(stream)))
if(!(reader.init(is)))
{
stream.setstate(std::ios::failbit);
is.setstate(std::ios::failbit);
return false;
}
@ -279,8 +286,8 @@ bool read_PLY(std::istream& stream,
for(std::size_t k=0; k<element.number_of_properties(); ++k)
{
IO::internal::PLY_read_number* property = element.property(k);
property->get(stream);
if(stream.fail())
property->get(is);
if(is.fail())
return false;
}
@ -289,14 +296,14 @@ bool read_PLY(std::istream& stream,
}
}
return !stream.bad();
return !is.bad();
}
template <typename Point, typename Vector>
bool read_PLY(std::istream& stream, CGAL::Point_set_3<Point, Vector>& point_set)
bool read_PLY(std::istream& is, CGAL::Point_set_3<Point, Vector>& point_set)
{
std::string dummy;
return read_PLY(stream, point_set, dummy);
return read_PLY(is, point_set, dummy);
}
template <typename Point, typename Vector>
@ -333,19 +340,19 @@ bool read_PLY(const std::string& fname, CGAL::Point_set_3<Point, Vector>& point_
appended to the `comments` string (without the "comment " word).
*/
template <typename Point, typename Vector>
CGAL_DEPRECATED bool read_ply_point_set(std::istream& stream, ///< input stream.
CGAL_DEPRECATED bool read_ply_point_set(std::istream& is, ///< input stream.
CGAL::Point_set_3<Point, Vector>& point_set, ///< point set
std::string& comments) ///< PLY comments.
{
return read_PLY(stream, point_set, comments);
return read_PLY(is, point_set, comments);
}
template <typename Point, typename Vector>
CGAL_DEPRECATED bool read_ply_point_set(std::istream& stream, ///< input stream.
CGAL_DEPRECATED bool read_ply_point_set(std::istream& is, ///< input stream.
CGAL::Point_set_3<Point, Vector>& point_set) ///< point set
{
std::string dummy;
return read_PLY(stream, point_set, dummy);
return read_PLY(is, point_set, dummy);
}
#endif // CGAL_NO_DEPRECATED_CODE
@ -368,18 +375,29 @@ CGAL_DEPRECATED bool read_ply_point_set(std::istream& stream, ///< input stream.
\tparam Point a `CGAL::Point_3`
\tparam Vector a `CGAL::Vector_3`
\tparam NamedParameters a sequence of \ref bgl_namedparameters "Named Parameters"
\param stream the path to the input file.
\param point_set the point set.
\param os the path to the input file
\param point_set the point set
\param comments optional PLY comments
\param np an optional sequence of \ref bgl_namedparameters "Named Parameters" among the ones listed below
\cgalNamedParamsBegin
\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
\return `true` if the reading was successful, `false` otherwise.
\see \ref IOStreamPLY
*/
template <typename Point, typename Vector>
bool write_PLY(std::ostream& stream,
template <typename Point, typename Vector, typename CGAL_BGL_NP_TEMPLATE_PARAMETERS>
bool write_PLY(std::ostream& os,
const CGAL::Point_set_3<Point, Vector>& point_set,
const std::string& comments = std::string())
const std::string& comments,
const CGAL_BGL_NP_CLASS& np)
{
typedef CGAL::Point_set_3<Point, Vector> Point_set;
typedef typename Point_set::Index Index;
@ -396,22 +414,34 @@ bool write_PLY(std::ostream& stream,
typedef typename Point_set::template Property_map<float> Float_map;
typedef typename Point_set::template Property_map<double> Double_map;
stream << "ply" << std::endl
<< ((get_mode(stream) == IO::BINARY) ? "format binary_little_endian 1.0" : "format ascii 1.0") << std::endl
<< "comment Generated by the CGAL library" << std::endl;
using CGAL::parameters::choose_parameter;
using CGAL::parameters::get_parameter;
if(!os)
{
std::cerr << "Error: cannot open file" << std::endl;
return false;
}
const int precision = choose_parameter(get_parameter(np, internal_np::stream_precision), 6);
os << std::setprecision(precision);
os << "ply" << std::endl
<< ((get_mode(os) == IO::BINARY) ? "format binary_little_endian 1.0" : "format ascii 1.0") << std::endl
<< "comment Generated by the CGAL library" << std::endl;
if(comments != std::string())
{
std::istringstream iss (comments);
std::istringstream iss(comments);
std::string line;
while(getline(iss, line))
{
if(line != "Generated by the CGAL library") // Avoid repeating the line if multiple savings
stream << "comment " << line << std::endl;
os << "comment " << line << std::endl;
}
}
stream << "element vertex " << point_set.number_of_points() << std::endl;
os << "element vertex " << point_set.number_of_points() << std::endl;
std::vector<std::string> prop = point_set.base().properties();
std::vector<IO::internal::Abstract_property_printer<Index>*> printers;
@ -425,15 +455,15 @@ bool write_PLY(std::ostream& stream,
{
if(boost::is_same<typename Get_FT_from_map<typename Point_set::Point_map>::type, float>::value)
{
stream << "property float x" << std::endl
<< "property float y" << std::endl
<< "property float z" << std::endl;
os << "property float x" << std::endl
<< "property float y" << std::endl
<< "property float z" << std::endl;
}
else
{
stream << "property double x" << std::endl
<< "property double y" << std::endl
<< "property double z" << std::endl;
os << "property double x" << std::endl
<< "property double y" << std::endl
<< "property double z" << std::endl;
}
printers.push_back(new IO::internal::Property_printer<Index,Point_map>(point_set.point_map()));
continue;
@ -442,15 +472,15 @@ bool write_PLY(std::ostream& stream,
{
if(boost::is_same<typename Get_FT_from_map<typename Point_set::Vector_map>::type, float>::value)
{
stream << "property float nx" << std::endl
<< "property float ny" << std::endl
<< "property float nz" << std::endl;
os << "property float nx" << std::endl
<< "property float ny" << std::endl
<< "property float nz" << std::endl;
}
else
{
stream << "property double nx" << std::endl
<< "property double ny" << std::endl
<< "property double nz" << std::endl;
os << "property double nx" << std::endl
<< "property double ny" << std::endl
<< "property double nz" << std::endl;
}
printers.push_back(new IO::internal::Property_printer<Index,Vector_map>(point_set.normal_map()));
continue;
@ -462,7 +492,7 @@ bool write_PLY(std::ostream& stream,
boost::tie(pmap, okay) = point_set.template property_map<boost::int8_t>(prop[i]);
if(okay)
{
stream << "property char " << prop[i] << std::endl;
os << "property char " << prop[i] << std::endl;
printers.push_back(new IO::internal::Char_property_printer<Index,Int8_map>(pmap));
continue;
}
@ -472,7 +502,7 @@ bool write_PLY(std::ostream& stream,
boost::tie(pmap, okay) = point_set.template property_map<boost::uint8_t>(prop[i]);
if(okay)
{
stream << "property uchar " << prop[i] << std::endl;
os << "property uchar " << prop[i] << std::endl;
printers.push_back(new IO::internal::Char_property_printer<Index,Uint8_map>(pmap));
continue;
}
@ -482,7 +512,7 @@ bool write_PLY(std::ostream& stream,
boost::tie(pmap, okay) = point_set.template property_map<boost::int16_t>(prop[i]);
if(okay)
{
stream << "property short " << prop[i] << std::endl;
os << "property short " << prop[i] << std::endl;
printers.push_back(new IO::internal::Simple_property_printer<Index,Int16_map>(pmap));
continue;
}
@ -492,7 +522,7 @@ bool write_PLY(std::ostream& stream,
boost::tie(pmap, okay) = point_set.template property_map<boost::uint16_t>(prop[i]);
if(okay)
{
stream << "property ushort " << prop[i] << std::endl;
os << "property ushort " << prop[i] << std::endl;
printers.push_back(new IO::internal::Simple_property_printer<Index,Uint16_map>(pmap));
continue;
}
@ -502,7 +532,7 @@ bool write_PLY(std::ostream& stream,
boost::tie(pmap, okay) = point_set.template property_map<boost::int32_t>(prop[i]);
if(okay)
{
stream << "property int " << prop[i] << std::endl;
os << "property int " << prop[i] << std::endl;
printers.push_back(new IO::internal::Simple_property_printer<Index,Int32_map>(pmap));
continue;
}
@ -512,7 +542,7 @@ bool write_PLY(std::ostream& stream,
boost::tie(pmap, okay) = point_set.template property_map<boost::uint32_t>(prop[i]);
if(okay)
{
stream << "property uint " << prop[i] << std::endl;
os << "property uint " << prop[i] << std::endl;
printers.push_back(new IO::internal::Simple_property_printer<Index,Uint32_map>(pmap));
continue;
}
@ -522,7 +552,7 @@ bool write_PLY(std::ostream& stream,
boost::tie(pmap, okay) = point_set.template property_map<boost::int64_t>(prop[i]);
if(okay)
{
stream << "property int " << prop[i] << std::endl;
os << "property int " << prop[i] << std::endl;
printers.push_back(new IO::internal::Simple_property_printer<Index,Int64_map,boost::int32_t>(pmap));
continue;
}
@ -532,7 +562,7 @@ bool write_PLY(std::ostream& stream,
boost::tie(pmap, okay) = point_set.template property_map<boost::uint64_t>(prop[i]);
if(okay)
{
stream << "property uint " << prop[i] << std::endl;
os << "property uint " << prop[i] << std::endl;
printers.push_back(new IO::internal::Simple_property_printer<Index,Uint64_map,boost::uint32_t>(pmap));
continue;
}
@ -542,7 +572,7 @@ bool write_PLY(std::ostream& stream,
boost::tie(pmap, okay) = point_set.template property_map<float>(prop[i]);
if(okay)
{
stream << "property float " << prop[i] << std::endl;
os << "property float " << prop[i] << std::endl;
printers.push_back(new IO::internal::Simple_property_printer<Index,Float_map>(pmap));
continue;
}
@ -552,25 +582,26 @@ bool write_PLY(std::ostream& stream,
boost::tie(pmap, okay) = point_set.template property_map<double>(prop[i]);
if(okay)
{
stream << "property double " << prop[i] << std::endl;
os << "property double " << prop[i] << std::endl;
printers.push_back(new IO::internal::Simple_property_printer<Index,Double_map>(pmap));
continue;
}
}
}
stream << "end_header" << std::endl;
os << "end_header" << std::endl;
for(typename Point_set::const_iterator it = point_set.begin(); it != point_set.end(); ++it)
{
for(std::size_t i=0; i<printers.size(); ++i)
{
printers[i]->print(stream, *it);
if(get_mode(stream) == IO::ASCII)
stream << " ";
printers[i]->print(os, *it);
if(get_mode(os) == IO::ASCII)
os << " ";
}
if(get_mode(stream) == IO::ASCII)
stream << std::endl;
if(get_mode(os) == IO::ASCII)
os << std::endl;
}
for(std::size_t i=0; i<printers.size(); ++i)
@ -578,6 +609,32 @@ bool write_PLY(std::ostream& stream,
return true;
}
template <typename Point, typename Vector, typename CGAL_BGL_NP_TEMPLATE_PARAMETERS>
bool write_PLY(std::ostream& os, const CGAL::Point_set_3<Point, Vector>& point_set, const CGAL_BGL_NP_CLASS& np)
{
return write_PLY(os, point_set, std::string(), np);
}
template <typename Point, typename Vector>
bool write_PLY(std::ostream& os, const CGAL::Point_set_3<Point, Vector>& point_set, const std::string& comments)
{
return write_PLY(os, point_set, comments, parameters::all_default());
}
template <typename Point, typename Vector>
bool write_PLY(std::ostream& os, const CGAL::Point_set_3<Point, Vector>& point_set)
{
return write_PLY(os, point_set, std::string(), parameters::all_default());
}
template <typename Point, typename Vector, typename CGAL_BGL_NP_TEMPLATE_PARAMETERS>
bool write_PLY(const char* fname, const CGAL::Point_set_3<Point, Vector>& point_set,
const std::string& comments, const CGAL_BGL_NP_CLASS& np)
{
std::ofstream os(fname);
return write_PLY(os, point_set, comments, np);
}
template <typename Point, typename Vector>
bool write_PLY(const char* fname, const CGAL::Point_set_3<Point, Vector>& point_set)
{
@ -585,10 +642,43 @@ bool write_PLY(const char* fname, const CGAL::Point_set_3<Point, Vector>& point_
return write_PLY(os, point_set);
}
template <typename Point, typename Vector>
bool write_PLY(const char* fname, const CGAL::Point_set_3<Point, Vector>& point_set, const std::string& comments)
{
std::ofstream os(fname);
return write_PLY(os, point_set, comments, parameters::all_default());
}
template <typename Point, typename Vector, typename CGAL_BGL_NP_TEMPLATE_PARAMETERS>
bool write_PLY(const char* fname, const CGAL::Point_set_3<Point, Vector>& point_set, const CGAL_BGL_NP_CLASS& np)
{
std::ofstream os(fname);
return write_PLY(os, point_set, std::string(), np);
}
template <typename Point, typename Vector, typename CGAL_BGL_NP_TEMPLATE_PARAMETERS>
bool write_PLY(const std::string& fname, const CGAL::Point_set_3<Point, Vector>& point_set,
const std::string& comments, const CGAL_BGL_NP_CLASS& np)
{
return write_PLY(fname.c_str(), point_set, comments, np);
}
template <typename Point, typename Vector>
bool write_PLY(const std::string& fname, const CGAL::Point_set_3<Point, Vector>& point_set, const std::string& comments)
{
return write_PLY(fname.c_str(), point_set, comments, parameters::all_default());
}
template <typename Point, typename Vector, typename CGAL_BGL_NP_TEMPLATE_PARAMETERS>
bool write_PLY(const std::string& fname, const CGAL::Point_set_3<Point, Vector>& point_set, const CGAL_BGL_NP_CLASS& np)
{
return write_PLY(fname.c_str(), point_set, std::string(), np);
}
template <typename Point, typename Vector>
bool write_PLY(const std::string& fname, const CGAL::Point_set_3<Point, Vector>& point_set)
{
return write_PLY(fname.c_str(), point_set);
return write_PLY(fname.c_str(), point_set, std::string(), parameters::all_default());
}
#ifndef CGAL_NO_DEPRECATED_CODE
@ -599,11 +689,11 @@ bool write_PLY(const std::string& fname, const CGAL::Point_set_3<Point, Vector>&
\deprecated This function is deprecated since \cgal 5.2, `CGAL::write_PLY()` should be used instead.
*/
template <typename Point, typename Vector>
CGAL_DEPRECATED bool write_ply_point_set(std::ostream& stream,
CGAL_DEPRECATED bool write_ply_point_set(std::ostream& os,
const CGAL::Point_set_3<Point, Vector>& point_set,
const std::string& comments = std::string())
{
return write_PLY(stream, point_set, comments);
return write_PLY(os, point_set, comments);
}
#endif // CGAL_NO_DEPRECATED_CODE

View File

@ -15,12 +15,19 @@
#include <CGAL/Point_set_3.h>
#include <CGAL/boost/graph/Named_function_parameters.h>
#include <CGAL/boost/graph/named_params_helper.h>
#include <CGAL/IO/read_xyz_points.h>
#include <CGAL/IO/write_xyz_points.h>
#include <fstream>
#include <string>
#ifdef DOXYGEN_RUNNING
#define CGAL_BGL_NP_TEMPLATE_PARAMETERS NamedParameters
#define CGAL_BGL_NP_CLASS NamedParameters
#endif
namespace CGAL {
template <typename Point, typename Vector>
@ -38,7 +45,7 @@ class Point_set_3;
\tparam Point a `CGAL::Point_3`
\tparam Vector a `CGAL::Vector_3`
\param stream the input stream
\param is the input stream
\param point_set the point set
\return `true` if the reading was successful, `false` otherwise.
@ -46,15 +53,14 @@ class Point_set_3;
\see \ref IOStreamXYZ
*/
template <typename Point, typename Vector>
bool read_XYZ(std::istream& stream,
bool read_XYZ(std::istream& is,
CGAL::Point_set_3<Point, Vector>& point_set)
{
point_set.add_normal_map();
bool out = CGAL::read_xyz_points(stream,
point_set.index_back_inserter(),
CGAL::parameters::point_map(point_set.point_push_map())
.normal_map(point_set.normal_push_map()));
bool out = CGAL::read_XYZ(is, point_set.index_back_inserter(),
CGAL::parameters::point_map(point_set.point_push_map())
.normal_map(point_set.normal_push_map()));
bool has_normals = false;
for(typename CGAL::Point_set_3<Point, Vector>::const_iterator it=point_set.begin(); it!=point_set.end(); ++it)
@ -108,10 +114,9 @@ bool read_XYZ(const std::string& fname, CGAL::Point_set_3<Point, Vector>& point_
\deprecated This function is deprecated since \cgal 5.2, `CGAL::read_XYZ()` should be used instead.
*/
template <typename Point, typename Vector>
CGAL_DEPRECATED bool read_xyz_point_set(std::istream& stream, ///< input stream.
CGAL::Point_set_3<Point, Vector>& point_set) ///< point set
CGAL_DEPRECATED bool read_xyz_point_set(std::istream& is, CGAL::Point_set_3<Point, Vector>& point_set)
{
return read_XYZ(stream, point_set);
return read_XYZ(is, point_set);
}
#endif // CGAL_NO_DEPRECATED_CODE
@ -127,24 +132,41 @@ CGAL_DEPRECATED bool read_xyz_point_set(std::istream& stream, ///< input stream.
\tparam Point a `CGAL::Point_3`
\tparam Vector a `CGAL::Vector_3`
\tparam NamedParameters a sequence of \ref bgl_namedparameters "Named Parameters"
\param stream the output stream
\param point_set the point set.
\param os the output stream
\param point_set the point set
\param np an optional sequence of \ref bgl_namedparameters "Named Parameters" among the ones listed below
\cgalNamedParamsBegin
\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
\return `true` if the writing was successful, `false` otherwise.
\see \ref IOStreamXYZ
*/
template <typename Point, typename Vector>
bool write_XYZ(std::ostream& stream,
const CGAL::Point_set_3<Point, Vector>& point_set)
template <typename Point, typename Vector, typename CGAL_BGL_NP_TEMPLATE_PARAMETERS>
bool write_XYZ(std::ostream& os,
const CGAL::Point_set_3<Point, Vector>& point_set,
const CGAL_BGL_NP_CLASS& np)
{
if(point_set.has_normal_map())
return CGAL::write_XYZ(stream, point_set,
CGAL::parameters::point_map(point_set.point_map())
.normal_map(point_set.normal_map()));
return Point_set_processing_3::internal::write_XYZ_PSP(os, point_set,
np.point_map(point_set.point_map())
.normal_map(point_set.normal_map()));
return CGAL::write_XYZ(stream, point_set, CGAL::parameters::point_map(point_set.point_map()));
return Point_set_processing_3::internal::write_XYZ_PSP(os, point_set, np.point_map(point_set.point_map()));
}
template <typename Point, typename Vector>
bool write_XYZ(std::ostream& os, const CGAL::Point_set_3<Point, Vector>& point_set)
{
return write_XYZ(os, point_set, parameters::all_default());
}
/*!
@ -154,25 +176,48 @@ bool write_XYZ(std::ostream& stream,
\tparam Point a `CGAL::Point_3`
\tparam Vector a `CGAL::Vector_3`
\tparam NamedParameters a sequence of \ref bgl_namedparameters "Named Parameters"
\param fname the path to the output file
\param point_set the point set.
\param point_set the point set
\param np an optional sequence of \ref bgl_namedparameters "Named Parameters" among the ones listed below
\cgalNamedParamsBegin
\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
\return `true` if the writing was successful, `false` otherwise.
\see \ref IOStreamXYZ
*/
template <typename Point, typename Vector, typename CGAL_BGL_NP_TEMPLATE_PARAMETERS>
bool write_XYZ(const char* fname, const CGAL::Point_set_3<Point, Vector>& point_set, const CGAL_BGL_NP_CLASS& np)
{
std::ofstream os(fname);
return write_XYZ(os, point_set, np);
}
template <typename Point, typename Vector>
bool write_XYZ(const char* fname, const CGAL::Point_set_3<Point, Vector>& point_set)
{
std::ofstream os(fname);
return write_XYZ(os, point_set);
return write_XYZ(os, point_set, parameters::all_default());
}
template <typename Point, typename Vector, typename CGAL_BGL_NP_TEMPLATE_PARAMETERS>
bool write_XYZ(const std::string& fname, const CGAL::Point_set_3<Point, Vector>& point_set, const CGAL_BGL_NP_CLASS& np)
{
return write_XYZ(fname.c_str(), point_set, np);
}
template <typename Point, typename Vector>
bool write_XYZ(const std::string& fname, const CGAL::Point_set_3<Point, Vector>& point_set)
{
return write_XYZ(fname.c_str(), point_set);
return write_XYZ(fname.c_str(), point_set, parameters::all_default());
}
#ifndef CGAL_NO_DEPRECATED_CODE
@ -183,10 +228,9 @@ bool write_XYZ(const std::string& fname, const CGAL::Point_set_3<Point, Vector>&
\deprecated This function is deprecated since \cgal 5.2, `CGAL::write_XYZ()` should be used instead.
*/
template <typename Point, typename Vector>
CGAL_DEPRECATED bool write_xyz_point_set(std::ostream& stream,
const CGAL::Point_set_3<Point, Vector>& point_set)
CGAL_DEPRECATED bool write_xyz_point_set(std::ostream& os, const CGAL::Point_set_3<Point, Vector>& point_set)
{
return write_XYZ(stream, point_set);
return write_XYZ(os, point_set);
}
#endif // CGAL_NO_DEPRECATED_CODE

View File

@ -1,7 +1,6 @@
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/Point_set_3.h>
#include <CGAL/IO/read_xyz_points.h>
#include <CGAL/IO/write_xyz_points.h>
#include <CGAL/grid_simplify_point_set.h>

View File

@ -10,6 +10,9 @@ simplification, etc.).
\defgroup PkgPointSetProcessing3IO IO (I/O Functions)
\ingroup PkgPointSetProcessing3Ref
\defgroup PkgPointSetProcessing3IODeprecated IO (I/O Functions (Deprecated))
\ingroup PkgPointSetProcessing3IO
\defgroup PkgPointSetProcessing3IOOff IO (OFF Formats)
\ingroup PkgPointSetProcessing3Ref
@ -75,6 +78,11 @@ format.
- `CGAL::vcm_is_on_feature_edge()`
- `CGAL::structure_point_set()`
\cgalCRPSection{IO (All Formats)}
- `CGAL::read_points()`
- `CGAL::write_points()`
\cgalCRPSection{IO (XYZ/OFF Formats)}
- \link PkgPointSetProcessing3IOOff OFF I/O Functions (`read_OFF()` and `write_OFF()`)\endlink
@ -82,10 +90,10 @@ format.
\cgalCRPSection{IO (PLY Format)}
- `CGAL::read_ply_points()`
- `CGAL::read_ply_points_with_properties()`
- `CGAL::write_ply_points()`
- `CGAL::write_ply_points_with_properties()`
- \link PkgPointSetProcessing3IOPly `CGAL::read_PLY()` \endlink
- `CGAL::read_PLY_with_properties()`
- \link PkgPointSetProcessing3IOPly `CGAL::write_PLY()` \endlink
- `CGAL::write_PLY_with_properties()`
- `CGAL::PLY_property<T>`
- `CGAL::make_ply_point_reader()`
- `CGAL::make_ply_point_writer()`
@ -94,16 +102,12 @@ format.
\cgalCRPSection{IO (LAS Format)}
- `CGAL::read_las_points()`
- `CGAL::read_las_points_with_properties()`
- `CGAL::write_las_points()`
- `CGAL::write_las_points_with_properties()`
- `CGAL::read_LAS()`
- `CGAL::read_LAS_with_properties()`
- `CGAL::write_LAS()`
- `CGAL::write_LAS_with_properties()`
- `CGAL::make_las_point_reader()`
- `CGAL::make_las_point_writer()`
\cgalCRPSection{IO (All Formats)}
- `CGAL::read_points()`
- `CGAL::write_points()`
*/

View File

@ -160,14 +160,16 @@ not handle normals and requires the \ref thirdpartyLASlib library.
The following functions are available:
- `read_xyz_points()`
- `read_off_points()`
- `read_ply_points()`
- `read_las_points()`
- `write_xyz_points()`
- `write_off_points()`
- `write_ply_points()`
- `write_las_points()`
- `read_points()`
- `read_XYZ()`
- `read_OFF()`
- `read_PLY()`
- `read_LAS()`
- `write_points()`
- `write_XYZ()`
- `write_OFF()`
- `write_PLY()`
- `write_LAS()`
All of these functions (with the exception of the LAS format) can read
and write either points alone or points with normals (depending on
@ -196,8 +198,8 @@ any structure the user needs. Handling of %LAS files works similarly
with the difference that the property names and types are fixed and
defined by the %LAS standard.
Functions `read_ply_points_with_properties()` and
`read_las_points_with_properties()` allow the user to read any
Functions `read_PLY_with_properties()` and
`read_LAS_with_properties()` allow the user to read any
property needed. The user must provide a set of property handlers that
are used to instantiate number types and complex objects from %PLY/%LAS
properties. This handlers are either:
@ -223,7 +225,7 @@ object, users need to provide an overload of `CGAL::Output_rep`.
\subsubsection Point_set_processing_3Example_ply_read PLY Reading Example
The following example shows how to call
`read_ply_points_with_properties()` to read a point set with points,
`read_PLY_with_properties()` to read a point set with points,
normals, RGB colors and intensity and stores these attributes in a
user-defined container.
@ -232,7 +234,7 @@ user-defined container.
\subsubsection Point_set_processing_3Example_las_read LAS Reading Example
The following example shows how to call
`read_las_points_with_properties()` to read a point set with points
`read_LAS_with_properties()` to read a point set with points
and RGBI colors and stores these attributes in a user-defined
container.

View File

@ -1,8 +1,9 @@
#include <CGAL/Simple_cartesian.h>
#include <CGAL/property_map.h>
#include <CGAL/IO/read_points.h>
#include <CGAL/IO/write_xyz_points.h>
#include <CGAL/bilateral_smooth_point_set.h>
#include <CGAL/IO/read_points.h>
#include <CGAL/IO/write_points.h>
#include <CGAL/property_map.h>
#include <CGAL/tags.h>
#include <utility> // defines std::pair
@ -26,10 +27,9 @@ int main(int argc, char*argv[])
// Reads a .xyz point set file in points[] * with normals *.
std::vector<PointVectorPair> points;
if (!CGAL::read_points(input_filename,
std::back_inserter(points),
CGAL::parameters::point_map(CGAL::First_of_pair_property_map<PointVectorPair>()).
normal_map(CGAL::Second_of_pair_property_map<PointVectorPair>())))
if (!CGAL::read_points(input_filename, std::back_inserter(points),
CGAL::parameters::point_map(CGAL::First_of_pair_property_map<PointVectorPair>())
.normal_map(CGAL::Second_of_pair_property_map<PointVectorPair>())))
{
std::cerr << "Error: cannot read file " << input_filename << std::endl;
return EXIT_FAILURE;
@ -56,11 +56,9 @@ int main(int argc, char*argv[])
//// Save point set.
std::ofstream out(output_filename);
out.precision(17);
if (!out ||
!CGAL::write_XYZ(
out, points,
CGAL::parameters::point_map(CGAL::First_of_pair_property_map<PointVectorPair>()).
normal_map(CGAL::Second_of_pair_property_map<PointVectorPair>())))
if (!out || !CGAL::write_XYZ(out, points,
CGAL::parameters::point_map(CGAL::First_of_pair_property_map<PointVectorPair>())
.normal_map(CGAL::Second_of_pair_property_map<PointVectorPair>())))
{
return EXIT_FAILURE;
}

View File

@ -1,7 +1,8 @@
#include <CGAL/Simple_cartesian.h>
#include <CGAL/edge_aware_upsample_point_set.h>
#include <CGAL/IO/read_points.h>
#include <CGAL/IO/write_xyz_points.h>
#include <CGAL/IO/write_points.h>
#include <vector>
#include <fstream>

View File

@ -1,6 +1,5 @@
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/grid_simplify_point_set.h>
#include <CGAL/IO/read_xyz_points.h>
#include <CGAL/property_map.h>
#include <vector>

View File

@ -1,9 +1,10 @@
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/hierarchy_simplify_point_set.h>
#include <CGAL/IO/read_points.h>
#include <CGAL/IO/write_xyz_points.h>
#include <CGAL/Timer.h>
#include <CGAL/IO/write_points.h>
#include <CGAL/hierarchy_simplify_point_set.h>
#include <CGAL/Memory_sizer.h>
#include <CGAL/Timer.h>
#include <vector>
#include <fstream>

View File

@ -21,7 +21,7 @@
#include <CGAL/mst_orient_normals.h>
#include <CGAL/property_map.h>
#include <CGAL/IO/read_points.h>
#include <CGAL/IO/write_xyz_points.h>
#include <CGAL/IO/write_points.h>
#include <utility> // defines std::pair
#include <vector>

View File

@ -1,6 +1,6 @@
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/property_map.h>
#include <CGAL/IO/read_las_points.h>
#include <CGAL/IO/read_points.h>
#include <utility>
#include <vector>

View File

@ -1,6 +1,6 @@
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/property_map.h>
#include <CGAL/IO/read_ply_points.h>
#include <CGAL/IO/read_points.h>
#include <utility>
#include <vector>

View File

@ -1,6 +1,5 @@
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/estimate_scale.h>
#include <CGAL/IO/read_xyz_points.h>
#include <CGAL/Random.h>
#include <vector>

View File

@ -15,7 +15,7 @@
// This package
#include <CGAL/compute_average_spacing.h>
#include <CGAL/IO/read_xyz_points.h>
#include <CGAL/IO/read_points.h>
#include <deque>
#include <cstdlib>
@ -94,23 +94,18 @@ int main(int argc, char * argv[])
// Loads point set
//***************************************
// File name is:
std::string input_filename = argv[i];
// Reads the point set file in points[].
std::deque<Point> points;
std::cerr << "Open " << input_filename << " for reading..." << std::endl;
std::cerr << "Open " << argv[i] << " for reading..." << std::endl;
// If XYZ file format:
std::ifstream stream(input_filename.c_str());
if(stream &&
CGAL::read_XYZ(stream, std::back_inserter(points)))
if(CGAL::read_points(argv[i], std::back_inserter(points)))
{
std::cerr << "ok (" << points.size() << " points)" << std::endl;
}
else
{
std::cerr << "Error: cannot read file " << input_filename << std::endl;
std::cerr << "Error: cannot read file " << argv[i] << std::endl;
accumulated_fatal_err = EXIT_FAILURE;
continue;
}

View File

@ -15,7 +15,7 @@
// This package
#include <CGAL/bilateral_smooth_point_set.h>
#include <CGAL/IO/read_xyz_points.h>
#include <CGAL/IO/read_points.h>
#include <deque>
#include <cstdlib>
@ -103,26 +103,21 @@ int main(int argc, char * argv[])
// Loads point set
//***************************************
// File name is:
std::string input_filename = argv[i];
// Reads the point set file in points[].
std::deque<PointVectorPair> points;
std::cerr << "Opening " << input_filename << " for reading..." << std::endl;
std::cerr << "Opening " << argv[i] << " for reading..." << std::endl;
// If XYZ file format:
std::ifstream stream(input_filename.c_str());
if(stream &&
CGAL::read_XYZ(stream,
std::back_inserter(points),
CGAL::parameters::point_map(CGAL::First_of_pair_property_map<PointVectorPair>()).
normal_map(CGAL::Second_of_pair_property_map<PointVectorPair>())))
if(CGAL::read_points(argv[i],
std::back_inserter(points),
CGAL::parameters::point_map(CGAL::First_of_pair_property_map<PointVectorPair>())
.normal_map(CGAL::Second_of_pair_property_map<PointVectorPair>())))
{
std::cerr << "ok (" << points.size() << " points)" << std::endl;
}
else
{
std::cerr << "Error: cannot read file " << input_filename << std::endl;
std::cerr << "Error: cannot read file " << argv[i] << std::endl;
accumulated_fatal_err = EXIT_FAILURE;
continue;
}

View File

@ -14,7 +14,7 @@
// This package
#include <CGAL/edge_aware_upsample_point_set.h>
#include <CGAL/IO/read_xyz_points.h>
#include <CGAL/IO/read_points.h>
#include <cstdlib>
#include <fstream>
@ -113,27 +113,21 @@ int main(int argc, char * argv[])
// Loads point set
//***************************************
// File name is:
std::string input_filename = argv[i];
// Reads the point set file in points[].
std::vector<PointVectorPair> points;
std::cerr << "Opening " << input_filename << " for reading..." << std::endl;
std::cerr << "Opening " << argv[i] << " for reading..." << std::endl;
// If XYZ file format:
std::ifstream stream(input_filename.c_str());
if(stream &&
CGAL::read_XYZ
(stream,
std::back_inserter(points),
CGAL::parameters::point_map(CGAL::First_of_pair_property_map<PointVectorPair>()).
normal_map(CGAL::Second_of_pair_property_map<PointVectorPair>())))
if(CGAL::read_points(argv[i],
std::back_inserter(points),
CGAL::parameters::point_map(CGAL::First_of_pair_property_map<PointVectorPair>())
.normal_map(CGAL::Second_of_pair_property_map<PointVectorPair>())))
{
std::cerr << "ok (" << points.size() << " points)" << std::endl;
}
else
{
std::cerr << "Error: cannot read file " << input_filename << std::endl;
std::cerr << "Error: cannot read file " << argv[i] << std::endl;
accumulated_fatal_err = EXIT_FAILURE;
continue;
}

View File

@ -20,8 +20,7 @@
#include <CGAL/mst_orient_normals.h>
#include <CGAL/Point_with_normal_3.h>
#include <CGAL/property_map.h>
#include <CGAL/IO/read_off_points.h>
#include <CGAL/IO/read_xyz_points.h>
#include <CGAL/IO/read_points.h>
#include <vector>
#include <string>
@ -322,12 +321,9 @@ int main(int argc, char * argv[])
extension == ".pwn" || extension == ".PWN")
{
std::ifstream stream(input_filename.c_str());
success = stream &&
CGAL::read_XYZ(stream,
std::back_inserter(points),
CGAL::parameters::normal_map
(CGAL::make_normal_of_point_with_normal_map(PointList::value_type()))
);
success = stream && CGAL::read_XYZ(stream,
std::back_inserter(points),
CGAL::parameters::normal_map(CGAL::make_normal_of_point_with_normal_map(PointList::value_type())));
}
if (success)
{

View File

@ -1,8 +1,6 @@
#include <CGAL/Simple_cartesian.h>
#include <CGAL/property_map.h>
#include <CGAL/IO/read_off_points.h>
#include <CGAL/IO/read_xyz_points.h>
#include <CGAL/IO/read_ply_points.h>
#include <CGAL/IO/read_points.h>
#include <CGAL/config.h>
@ -18,51 +16,39 @@ typedef std::pair<Point_3, Vector_3> PointVectorPair;
bool read(std::string s)
{
std::ifstream fs(s.c_str());
std::vector<PointVectorPair> pv_pairs;
return CGAL::read_XYZ(fs,
back_inserter(pv_pairs),
CGAL::parameters::point_map(CGAL::First_of_pair_property_map<PointVectorPair>()).
normal_map(CGAL::Second_of_pair_property_map<PointVectorPair>()));
return CGAL::read_points(s, back_inserter(pv_pairs),
CGAL::parameters::point_map(CGAL::First_of_pair_property_map<PointVectorPair>())
.normal_map(CGAL::Second_of_pair_property_map<PointVectorPair>()));
}
bool read(std::string s,
std::vector<PointVectorPair>& pv_pairs)
{
std::ifstream fs(s.c_str());
return CGAL::read_XYZ(fs,
back_inserter(pv_pairs),
CGAL::parameters::point_map(CGAL::First_of_pair_property_map<PointVectorPair>()).
normal_map(CGAL::Second_of_pair_property_map<PointVectorPair>()));
return CGAL::read_points(s,
back_inserter(pv_pairs),
CGAL::parameters::point_map(CGAL::First_of_pair_property_map<PointVectorPair>())
.normal_map(CGAL::Second_of_pair_property_map<PointVectorPair>()));
}
bool read_off(std::string s,
std::vector<PointVectorPair>& pv_pairs)
{
std::ifstream fs(s.c_str());
return CGAL::read_OFF(fs,
return CGAL::read_OFF(s,
back_inserter(pv_pairs),
CGAL::parameters::point_map(CGAL::First_of_pair_property_map<PointVectorPair>()).
normal_map(CGAL::Second_of_pair_property_map<PointVectorPair>()));
}
bool read_ply (std::string s,
std::vector<PointVectorPair>& pv_pairs)
bool read_ply(std::string s,
std::vector<PointVectorPair>& pv_pairs)
{
std::ifstream fs(s.c_str());
return CGAL::read_PLY (fs,
back_inserter(pv_pairs),
CGAL::parameters::point_map(CGAL::First_of_pair_property_map<PointVectorPair>()).
normal_map(CGAL::Second_of_pair_property_map<PointVectorPair>()));
return CGAL::read_PLY(s,
back_inserter(pv_pairs),
CGAL::parameters::point_map(CGAL::First_of_pair_property_map<PointVectorPair>()).
normal_map(CGAL::Second_of_pair_property_map<PointVectorPair>()));
}
int main()
{
std::cerr << "### There should be three errors following this line...\n";

View File

@ -1,7 +1,6 @@
#include <CGAL/Simple_cartesian.h>
#include <CGAL/property_map.h>
#include <CGAL/IO/read_off_points.h>
#include <CGAL/IO/read_xyz_points.h>
#include <CGAL/IO/read_points.h>
#include <CGAL/property_map.h>
#include <vector>

View File

@ -15,7 +15,7 @@
// This package
#include <CGAL/remove_outliers.h>
#include <CGAL/IO/read_xyz_points.h>
#include <CGAL/IO/read_points.h>
#include <deque>
#include <string>
@ -105,23 +105,18 @@ int main(int argc, char * argv[])
// Loads point set
//***************************************
// File name is:
std::string input_filename = argv[i];
// Reads the point set file in points[].
std::deque<Point> points;
std::cerr << "Open " << input_filename << " for reading..." << std::endl;
std::cerr << "Open " << argv[i] << " for reading..." << std::endl;
// If XYZ file format:
std::ifstream stream(input_filename.c_str());
if(stream &&
CGAL::read_XYZ(stream, std::back_inserter(points)))
if(CGAL::read_points(argv[i], std::back_inserter(points)))
{
std::cerr << "ok (" << points.size() << " points)" << std::endl;
}
else
{
std::cerr << "Error: cannot read file " << input_filename << std::endl;
std::cerr << "Error: cannot read file " << argv[i] << std::endl;
accumulated_fatal_err = EXIT_FAILURE;
continue;
}

View File

@ -15,7 +15,7 @@
// This package
#include <CGAL/jet_smooth_point_set.h>
#include <CGAL/IO/read_xyz_points.h>
#include <CGAL/IO/read_points.h>
#include <deque>
#include <string>
@ -96,23 +96,18 @@ int main(int argc, char * argv[])
// Loads point set
//***************************************
// File name is:
std::string input_filename = argv[i];
// Reads the point set file in points[].
std::deque<Point> points;
std::cerr << "Open " << input_filename << " for reading..." << std::endl;
std::cerr << "Open " << argv[i] << " for reading..." << std::endl;
// If XYZ file format:
std::ifstream stream(input_filename.c_str());
if(stream &&
CGAL::read_XYZ(stream, std::back_inserter(points)))
if(CGAL::read_points(argv[i], std::back_inserter(points)))
{
std::cerr << "ok (" << points.size() << " points)" << std::endl;
}
else
{
std::cerr << "Error: cannot read file " << input_filename << std::endl;
std::cerr << "Error: cannot read file " << argv[i] << std::endl;
accumulated_fatal_err = EXIT_FAILURE;
continue;
}

View File

@ -1,89 +1,79 @@
#include <CGAL/Simple_cartesian.h>
#include <CGAL/Point_set_3.h>
#include <CGAL/IO/read_points.h>
#include <CGAL/IO/write_points.h>
#include <CGAL/boost/graph/io.h> // Just to try and create ambiguities
#include <CGAL/property_map.h>
#include <vector>
#include <cassert>
#include <string>
#include <fstream>
#include <CGAL/Simple_cartesian.h>
#include <CGAL/property_map.h>
#include <CGAL/IO/read_points.h>
#include <CGAL/IO/write_points.h>
#include <CGAL/Point_set_3/point_set_io.h>
typedef CGAL::Simple_cartesian<double> Kernel;
typedef Kernel::Point_3 Point_3;
typedef Kernel::Vector_3 Vector_3;
const double epsilon = 5e-4;
const double epsilon=5e-4;
template < typename Type >
bool approx_equal_nt(const Type &t1, const Type &t2)
{
if (t1 == t2)
return true;
if (CGAL::abs(t1 - t2) / (CGAL::max)(CGAL::abs(t1), CGAL::abs(t2)) < std::abs(t1)*epsilon)
return true;
if(t1 == t2)
return true;
if(CGAL::abs(t1 - t2) / (CGAL::max)(CGAL::abs(t1), CGAL::abs(t2)) < std::abs(t1)*epsilon)
return true;
std::cout << " Approximate comparison failed between : " << t1 << " and " << t2 << std::endl;
std::cout<<"abs(t1 - t2) = "<<CGAL::abs(t1 - t2)<<"n";
std::cout<<"abs(t1) = "<<CGAL::abs(t1)<<"n";
std::cout<<"abs(t2) = "<<CGAL::abs(t2)<<"n";
std::cout<<"std::abs(t1)*epsilon = "<<std::abs(t1)*epsilon<<"n";
std::cout<<"CGAL::abs(t1 - t2) / (CGAL::max)(CGAL::abs(t1), CGAL::abs(t2) == "<<
CGAL::abs(t1 - t2) / (CGAL::max)(CGAL::abs(t1), CGAL::abs(t2))<<std::endl;
return false;
std::cout << " Approximate comparison failed between : " << t1 << " and " << t2 << std::endl;
std::cout << "abs(t1 - t2) = " <<CGAL::abs(t1 - t2) << "n";
std::cout << "abs(t1) = " <<CGAL::abs(t1) << "n";
std::cout << "abs(t2) = " <<CGAL::abs(t2) << "n";
std::cout << "std::abs(t1)*epsilon = " <<std::abs(t1) * epsilon << "n";
std::cout << "CGAL::abs(t1 - t2) / (CGAL::max)(CGAL::abs(t1), CGAL::abs(t2) == "
<< CGAL::abs(t1 - t2) / (CGAL::max)(CGAL::abs(t1), CGAL::abs(t2)) << std::endl;
return false;
}
typedef std::pair<Point_3, Vector_3> PointVectorPair;
bool ps_are_equal(const CGAL::Point_set_3<Point_3, Vector_3>& ps,
const CGAL::Point_set_3<Point_3, Vector_3>& ps2)
{
if(ps.size() != ps2.size())
return false;
typedef CGAL::Point_set_3<Point_3, Vector_3>::const_iterator Iterator;
for(Iterator it1 = ps.begin(), it2 = ps2.begin();
it1!=ps.end(), it2!=ps2.end(); ++it1, ++it2)
for(Iterator it1 = ps.begin(), it2 = ps2.begin(); it1!=ps.end() && it2!=ps2.end(); ++it1, ++it2)
{
Point_3 p1 = ps.point(*it1);
Point_3 p2 = ps2.point(*it2);
if(!(approx_equal_nt(p1.x(), p2.x())
&& approx_equal_nt(p1.y(), p2.y())
&& approx_equal_nt(p1.z(), p2.z())))
{
const Point_3& p1 = ps.point(*it1);
const Point_3& p2 = ps2.point(*it2);
if(!(approx_equal_nt(p1.x(), p2.x()) && approx_equal_nt(p1.y(), p2.y()) && approx_equal_nt(p1.z(), p2.z())))
return false;
}
}
return true;
}
typedef std::pair<Point_3, Vector_3> PointVectorPair;
bool points_are_equal(const std::vector<Point_3>& ps,
const std::vector<Point_3>& ps2)
const std::vector<Point_3>& ps2)
{
if(ps.size() != ps2.size())
return false;
typedef std::vector<Point_3>::const_iterator Iterator;
for(Iterator it1 = ps.begin(), it2 = ps2.begin();
it1!=ps.end(), it2!=ps2.end(); ++it1, ++it2)
for(Iterator it1 = ps.begin(), it2 = ps2.begin(); it1!=ps.end() && it2!=ps2.end(); ++it1, ++it2)
{
Point_3 p1 = *it1;
Point_3 p2 = *it2;
if(!(approx_equal_nt(p1.x(), p2.x())
&& approx_equal_nt(p1.y(), p2.y())
&& approx_equal_nt(p1.z(), p2.z())))
{
const Point_3& p1 = *it1;
const Point_3& p2 = *it2;
if(!(approx_equal_nt(p1.x(), p2.x()) && approx_equal_nt(p1.y(), p2.y()) && approx_equal_nt(p1.z(), p2.z())))
return false;
}
}
return true;
}
bool test_points_with_np(std::string s)
{
std::vector<PointVectorPair> points;
@ -94,89 +84,133 @@ bool test_points_with_np(std::string s)
points.push_back(std::make_pair(Point_3(1,1,1), Vector_3(1,1,1)));
bool ok = CGAL::write_points(s, points,
CGAL::parameters::point_map(CGAL::First_of_pair_property_map<PointVectorPair>()).
normal_map(CGAL::Second_of_pair_property_map<PointVectorPair>()));
CGAL::parameters::point_map(CGAL::First_of_pair_property_map<PointVectorPair>())
.normal_map(CGAL::Second_of_pair_property_map<PointVectorPair>()));
assert(ok);
std::vector<PointVectorPair> pv_pairs;
ok = CGAL::read_points(s,
std::back_inserter(pv_pairs),
CGAL::parameters::point_map(CGAL::First_of_pair_property_map<PointVectorPair>()).
normal_map(CGAL::Second_of_pair_property_map<PointVectorPair>()));
ok = CGAL::read_points(s, std::back_inserter(pv_pairs),
CGAL::parameters::point_map(CGAL::First_of_pair_property_map<PointVectorPair>())
.normal_map(CGAL::Second_of_pair_property_map<PointVectorPair>()));
assert(ok);
assert(pv_pairs[0] == std::make_pair(Point_3(0,0,0), Vector_3(0,0,0)));
assert(pv_pairs[1] == std::make_pair(Point_3(1,0,0), Vector_3(1,0,0)));
assert(pv_pairs[2] == std::make_pair(Point_3(0,1,0), Vector_3(0,1,0)));
assert(pv_pairs[3] == std::make_pair(Point_3(0,0,1), Vector_3(0,0,1)));
assert(pv_pairs[4] == std::make_pair(Point_3(1,1,1), Vector_3(1,1,1)));
return true;
}
#define CGAL_DEF_TEST_POINT_SET_3_FUNCTION(TYPE, type) \
void test_##TYPE(std::string s) \
{ \
CGAL::Point_set_3<Point_3, Vector_3> ps; \
bool ok = CGAL::read_##TYPE(s, ps); \
assert(ok); \
ps.clear(); \
ok = CGAL::read_##TYPE(s.c_str(), ps); \
assert(ok); \
ps.clear(); \
std::ifstream in(s); \
ok = CGAL::read_##TYPE(in, ps); \
assert(ok); \
const char* ext = type; \
std::string fname = "tmp."; \
fname.append(ext); \
ok = CGAL::write_##TYPE(fname, ps); \
assert(ok); \
ok = CGAL::write_##TYPE(fname, ps, CGAL::parameters::stream_precision(10)); \
assert(ok); \
ok = CGAL::write_##TYPE(fname.c_str(), ps); \
assert(ok); \
ok = CGAL::write_##TYPE(fname.c_str(), ps, CGAL::parameters::stream_precision(10)); \
assert(ok); \
std::ofstream out(fname); \
ok = CGAL::write_##TYPE(out, ps); \
assert(ok); \
std::ofstream out2(fname); \
ok = CGAL::write_##TYPE(out2, ps, CGAL::parameters::stream_precision(10)); \
assert(ok); \
CGAL::Point_set_3<Point_3, Vector_3> ps2; \
std::ifstream is(fname); \
ok = CGAL::read_##TYPE(is, ps2); \
assert(ok); \
assert(ps_are_equal(ps, ps2)); \
ok = CGAL::write_point_set(fname, ps2); \
assert(ok); \
ok = CGAL::write_point_set(fname, ps2, CGAL::parameters::stream_precision(10)); \
assert(ok); \
ok = CGAL::write_point_set(fname.c_str(), ps2); \
assert(ok); \
ok = CGAL::write_point_set(fname.c_str(), ps2, CGAL::parameters::stream_precision(10)); \
assert(ok); \
ps2.clear(); \
ok = CGAL::read_point_set(fname, ps2); \
assert(ok); \
assert(ps_are_equal(ps, ps2)); \
}
#define CGAL_DEF_TEST_PS_FUNCTION(TYPE, type)\
void test_##TYPE(std::string s) \
{ \
CGAL::Point_set_3<Point_3, Vector_3> ps; \
bool ok = CGAL::read_##TYPE(s, ps); \
assert(ok); \
const char* ext= type; \
std::string fname = "tmp."; \
fname.append(ext); \
ok = CGAL::write_##TYPE(fname, ps); \
assert(ok); \
CGAL::Point_set_3<Point_3, Vector_3> ps2; \
std::ifstream is(fname); \
ok = CGAL::read_##TYPE(is, ps2); \
assert(ok); \
assert(ps_are_equal(ps, ps2)); \
ok = CGAL::write_point_set(fname, ps2); \
assert(ok); \
ps2.clear(); \
ok = CGAL::read_point_set(fname, ps2); \
assert(ok); \
assert(ps_are_equal(ps, ps2)); \
}
CGAL_DEF_TEST_PS_FUNCTION(XYZ, "xyz")
CGAL_DEF_TEST_PS_FUNCTION(OFF,"off")
CGAL_DEF_TEST_PS_FUNCTION(PLY,"ply")
CGAL_DEF_TEST_POINT_SET_3_FUNCTION(XYZ, "xyz")
CGAL_DEF_TEST_POINT_SET_3_FUNCTION(OFF, "off")
CGAL_DEF_TEST_POINT_SET_3_FUNCTION(PLY, "ply")
#ifdef CGAL_LINKED_WITH_LASLIB
CGAL_DEF_TEST_PS_FUNCTION(LAS,"las")
CGAL_DEF_TEST_POINT_SET_3_FUNCTION(LAS, "las")
#endif
#undef CGAL_DEF_INITIALIZE_ID_FUCNTION
#define CGAL_DEF_TEST_POINTS_FUNCTION(TYPE, type) \
void test_points_##TYPE(std::string s) \
{ \
std::vector<Point_3> ps; \
bool ok = CGAL::read_##TYPE(s, std::back_inserter(ps)); \
assert(ok); \
const char* ext= type; \
std::string fname = "tmp."; \
fname.append(ext); \
ok = CGAL::write_##TYPE(fname, ps); \
assert(ok); \
std::vector<Point_3> ps2; \
std::ifstream is(fname); \
ok = CGAL::read_##TYPE(is, std::back_inserter(ps2)); \
assert(ok); \
assert(points_are_equal(ps, ps2)); \
ok = CGAL::write_points(fname, ps2); \
assert(ok); \
ps2.clear(); \
ok = CGAL::read_points(fname, std::back_inserter(ps2)); \
assert(ok); \
assert(points_are_equal(ps, ps2)); \
}
#define CGAL_DEF_TEST_POINTS_FUNCTION(TYPE, type) \
void test_points_##TYPE(std::string s) \
{ \
std::vector<Point_3> ps; \
bool ok = CGAL::read_##TYPE(s, std::back_inserter(ps)); \
assert(ok); \
ps.clear(); \
ok = CGAL::read_##TYPE(s.c_str(), std::back_inserter(ps)); \
assert(ok); \
ps.clear(); \
std::ifstream in(s); \
ok = CGAL::read_##TYPE(in, std::back_inserter(ps)); \
assert(ok); \
const char* ext = type; \
std::string fname = "tmp."; \
fname.append(ext); \
ok = CGAL::write_##TYPE(fname, ps); \
assert(ok); \
ok = CGAL::write_##TYPE(fname, ps, CGAL::parameters::stream_precision(10)); \
assert(ok); \
ok = CGAL::write_##TYPE(fname.c_str(), ps); \
assert(ok); \
ok = CGAL::write_##TYPE(fname.c_str(), ps, CGAL::parameters::stream_precision(10)); \
assert(ok); \
std::ofstream out(fname); \
ok = CGAL::write_##TYPE(out, ps); \
assert(ok); \
std::ofstream out2(fname); \
ok = CGAL::write_##TYPE(out2, ps, CGAL::parameters::stream_precision(10)); \
assert(ok); \
std::vector<Point_3> ps2; \
std::ifstream is(fname); \
ok = CGAL::read_##TYPE(is, std::back_inserter(ps2)); \
assert(ok); \
assert(points_are_equal(ps, ps2)); \
ok = CGAL::write_points(fname, ps2); \
assert(ok); \
ps2.clear(); \
ok = CGAL::read_points(fname, std::back_inserter(ps2)); \
assert(ok); \
assert(points_are_equal(ps, ps2)); \
}
CGAL_DEF_TEST_POINTS_FUNCTION(XYZ, "xyz")
CGAL_DEF_TEST_POINTS_FUNCTION(OFF,"off")
CGAL_DEF_TEST_POINTS_FUNCTION(PLY,"ply")
CGAL_DEF_TEST_POINTS_FUNCTION(OFF, "off")
CGAL_DEF_TEST_POINTS_FUNCTION(PLY, "ply")
#ifdef CGAL_LINKED_WITH_LASLIB
CGAL_DEF_TEST_POINTS_FUNCTION(LAS,"las")
CGAL_DEF_TEST_POINTS_FUNCTION(LAS, "las")
#endif
#undef CGAL_DEF_INITIALIZE_ID_FUCNTION
int main()
{
test_XYZ("data/read_test/ok_2.xyz");
@ -189,16 +223,15 @@ int main()
test_points_PLY("data/read_test/simple_ascii.ply");
test_points_PLY("data/read_test/simple.ply");
#ifdef CGAL_LINKED_WITH_LASLIB
#ifdef CGAL_LINKED_WITH_LASLIB
test_LAS("data/read_test/pig_points.las");
test_points_LAS("data/read_test/pig_points.las");
#endif
#endif
test_points_with_np("test.xyz");
test_points_with_np("test.off");
test_points_with_np("test.ply");
// don't test normals with LAS as it is not supported by the format
//don't test normals with LAS as it is not supported by the format
return 0;
return EXIT_SUCCESS;
}

View File

@ -1,7 +1,8 @@
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/vcm_estimate_edges.h>
#include <CGAL/property_map.h>
#include <CGAL/IO/read_off_points.h>
#include <CGAL/IO/read_points.h>
#include <boost/dynamic_bitset.hpp>
@ -25,17 +26,16 @@ std::cout << "=== test_fandisk ===\n";
Covariance expected;
int index;
// Reads a .xyz point set file in points[].
// Reads a point set file in points[].
std::vector<Point> points;
std::vector<Covariance> cov;
boost::dynamic_bitset<std::size_t> on_feature_edge(nb_points);
points.reserve(nb_points);
cov.reserve(nb_points);
std::ifstream stream("data/fandisk.off");
if (!stream ||
!CGAL::read_OFF(stream,
std::back_inserter(points),
CGAL::parameters::point_map(pmap)))
if(CGAL::read_points("data/fandisk.off",
std::back_inserter(points),
CGAL::parameters::point_map(pmap)))
{
std::cerr << "Error: cannot read file data/fandisk.off" << std::endl;
return false;

View File

@ -15,7 +15,7 @@
// This package
#include <CGAL/wlop_simplify_and_regularize_point_set.h>
#include <CGAL/IO/read_xyz_points.h>
#include <CGAL/IO/read_points.h>
#include <vector>
#include <string>
@ -117,23 +117,18 @@ int main(int argc, char * argv[])
// Loads point set
//***************************************
// File name is:
std::string input_filename = argv[i];
// Reads the point set file in points[].
std::vector<Point> points;
std::cerr << "Opening " << input_filename << " for reading..." << std::endl;
std::cerr << "Opening " << argv[i] << " for reading..." << std::endl;
// If XYZ file format:
std::ifstream stream(input_filename.c_str());
if(stream &&
CGAL::read_XYZ(stream, std::back_inserter(points)))
if(CGAL::read_points(argv[i], std::back_inserter(points)))
{
std::cerr << "ok (" << points.size() << " points)" << std::endl;
}
else
{
std::cerr << "Error: cannot read file " << input_filename << std::endl;
std::cerr << "Error: cannot read file " << argv[i] << std::endl;
accumulated_fatal_err = EXIT_FAILURE;
continue;
}

View File

@ -1,5 +1,5 @@
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/IO/read_ply_points.h>
#include <CGAL/IO/read_points.h>
#include <CGAL/property_map.h>
#include <CGAL/Surface_mesh.h>
#include <CGAL/Polygonal_surface_reconstruction.h>

View File

@ -1,5 +1,5 @@
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/IO/read_ply_points.h>
#include <CGAL/IO/read_points.h>
#include <CGAL/property_map.h>
#include <CGAL/Surface_mesh.h>
#include <CGAL/Polygonal_surface_reconstruction.h>

View File

@ -1,8 +1,7 @@
#ifndef POLYFIT_TEST_FRAMEWORK_H_
#define POLYFIT_TEST_FRAMEWORK_H_
#include <CGAL/IO/read_xyz_points.h>
#include <CGAL/IO/read_ply_points.h>
#include <CGAL/IO/read_points.h>
#include <CGAL/property_map.h>
#include <CGAL/Surface_mesh.h>
#include <CGAL/Shape_detection/Efficient_RANSAC.h>

View File

@ -26,6 +26,7 @@
namespace CGAL {
namespace internal {
BOOST_MPL_HAS_XXX_TRAIT_DEF(iterator_category)
BOOST_MPL_HAS_XXX_TRAIT_DEF(value_type)
BOOST_MPL_HAS_XXX_TRAIT_DEF(difference_type)

View File

@ -1,21 +1,18 @@
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/Scale_space_surface_reconstruction_3.h>
#include <CGAL/IO/read_points.h>
#include <CGAL/Timer.h>
#include <fstream>
#include <iostream>
#include <CGAL/Scale_space_surface_reconstruction_3.h>
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/IO/read_off_points.h>
#include <CGAL/Timer.h>
typedef CGAL::Exact_predicates_inexact_constructions_kernel Kernel;
typedef Kernel::Point_3 Point;
typedef CGAL::Scale_space_surface_reconstruction_3<Kernel> Reconstruction;
typedef CGAL::Scale_space_surface_reconstruction_3<Kernel> Reconstruction;
typedef Kernel::Point_3 Point;
typedef Reconstruction::Facet_const_iterator Facet_iterator;
typedef Reconstruction::Facet_const_iterator Facet_iterator;
int main(int argc, char** argv)
{
@ -27,7 +24,7 @@ int main(int argc, char** argv)
std::vector<Point> points;
std::ifstream in(argv[1]);
std::cerr << "Reading " << std::flush;
if( !in || !CGAL::read_off_points( in, std::back_inserter( points ) ) ) {
if( !in || !CGAL::read_points( in, std::back_inserter( points ) ) ) {
std::cerr << "Error: cannot read file" << std::endl;
return EXIT_FAILURE;
}

View File

@ -1,18 +1,15 @@
#include <fstream>
#include <iostream>
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/Point_set_3.h>
#include <CGAL/Point_set_3/IO.h>
#include <CGAL/Scale_space_surface_reconstruction_3.h>
#include <CGAL/Scale_space_reconstruction_3/Advancing_front_mesher.h>
#include <CGAL/Scale_space_reconstruction_3/Jet_smoother.h>
#include <CGAL/IO/read_off_points.h>
#include <CGAL/Timer.h>
#include <fstream>
#include <iostream>
typedef CGAL::Exact_predicates_inexact_constructions_kernel Kernel;
typedef CGAL::Scale_space_surface_reconstruction_3<Kernel> Reconstruction;

View File

@ -1,10 +1,10 @@
#include <fstream>
#include <iostream>
#include <algorithm>
#include <CGAL/Scale_space_surface_reconstruction_3.h>
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/IO/read_off_points.h>
#include <CGAL/IO/read_points.h>
#include <algorithm>
#include <fstream>
#include <iostream>
typedef CGAL::Exact_predicates_inexact_constructions_kernel Kernel;
@ -30,19 +30,23 @@ void dump_reconstruction(const Reconstruction& reconstruct, std::string name)
output << "3 " << *it << std::endl;
}
int main(int argc, char* argv[]) {
int main(int argc, char* argv[])
{
// Read the data.
std::vector<Point> points;
if (argc!=2){
std::cerr << "Error, no input file provided\n";
return 1;
}
std::ifstream in(argv[1]);
std::cout << "Reading " << std::flush;
if( !in || !CGAL::read_off_points( in, std::back_inserter( points ) ) ) {
std::cerr << "Error: cannot read file" << std::endl;
return EXIT_FAILURE;
if( !in || !CGAL::read_points(in, std::back_inserter(points)))
{
std::cerr << "Error: cannot read file" << std::endl;
return EXIT_FAILURE;
}
std::cout << "done: " << points.size() << " points." << std::endl;
// Construct the reconstruction

View File

@ -1,14 +1,13 @@
#include <fstream>
#include <iostream>
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/Scale_space_surface_reconstruction_3.h>
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/IO/read_off_points.h>
#include <CGAL/IO/read_points.h>
#include <CGAL/Timer.h>
#include <fstream>
#include <iostream>
typedef CGAL::Exact_predicates_inexact_constructions_kernel Kernel;
typedef CGAL::Scale_space_surface_reconstruction_3< Kernel > Reconstruction;
@ -21,39 +20,44 @@ typedef Reconstruction::Facet_const_iterator Facet_iterator;
typedef Mesher::Facet_const_iterator Mesher_iterator;
typedef CGAL::Timer Timer;
int main(int argc, char* argv[]) {
if (argc!=2){
int main(int argc, char* argv[])
{
if(argc != 2)
{
std::cerr << "Error, no input file provided\n";
return 1;
}
// Read the data.
std::vector<Point> points;
std::ifstream in(argv[1]);
std::cerr << "Reading " << std::flush;
if( !in || !CGAL::read_off_points( in, std::back_inserter( points ) ) ) {
if(!in || !CGAL::read_points(in, std::back_inserter(points)))
{
std::cerr << "Error: cannot read file" << std::endl;
return EXIT_FAILURE;
}
std::cerr << "done: " << points.size() << " points." << std::endl;
Timer t;
t.start();
// Construct the mesh in a scale space.
Reconstruction reconstruct( points.begin(), points.end() );
Smoother smoother( 10, 200 );
reconstruct.increase_scale (4, smoother);
Reconstruction reconstruct(points.begin(), points.end() );
Smoother smoother(10, 200 );
reconstruct.increase_scale(4, smoother);
Mesher mesher( smoother.squared_radius(),
false, // Do not separate shells
true // Force manifold output
Mesher mesher(smoother.squared_radius(),
false, // Do not separate shells
true // Force manifold output
);
reconstruct.reconstruct_surface( mesher );
reconstruct.reconstruct_surface(mesher);
std::cerr << "Reconstruction done in " << t.time() << " sec." << std::endl;
t.reset();
std::ofstream out ("out.off");
std::ofstream out("out.off");
// Write the reconstruction.
for( Facet_iterator it = reconstruct.facets_begin( ); it != reconstruct.facets_end( ); ++it )
for(Facet_iterator it = reconstruct.facets_begin(); it != reconstruct.facets_end(); ++it )
out << "3 "<< *it << '\n'; // We write a '3' in front so that it can be assembled into an OFF file
std::cerr << "Writing result in " << t.time() << " sec." << std::endl;
@ -61,14 +65,13 @@ int main(int argc, char* argv[]) {
out.close();
t.reset();
std::ofstream garbage ("garbage.off");
std::ofstream garbage("garbage.off");
// Write facets that were removed to force manifold output
for( Mesher_iterator it = mesher.garbage_begin( ); it != mesher.garbage_end( ); ++it )
for(Mesher_iterator it = mesher.garbage_begin(); it != mesher.garbage_end(); ++it )
garbage << "3 "<< *it << '\n'; // We write a '3' in front so that it can be assembled into an OFF file
std::cerr << "Writing garbage facets in " << t.time() << " sec." << std::endl;
garbage.close ();
std::cerr << "Done." << std::endl;
return EXIT_SUCCESS;
}

View File

@ -38,7 +38,7 @@ int run(const char* filename) {
Pwn_vector points;
// Load a point set from a file.
// read_XYZ takes an OutputIterator for storing the points
// read_points takes an OutputIterator for storing the points
// and a property map to store the normal vector with each point.
if (!CGAL::read_points(filename,

View File

@ -1,7 +1,7 @@
#include "include/test_efficient_RANSAC_generators.h"
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/IO/read_xyz_points.h>
#include <CGAL/IO/read_points.h>
#include <CGAL/Simple_cartesian.h>
#include <CGAL/Shape_detection/Efficient_RANSAC.h>
@ -31,15 +31,14 @@ bool test_scene(int argc, char** argv) {
Pwn_vector points;
// Load point set from a file.
// read_xyz_points_and_normals takes an OutputIterator for storing the points
// read_points takes an OutputIterator for storing the points
// and a property map to store the normal vector with each point.
std::ifstream stream((argc > 1) ? argv[1] : "data/cube.pwn");
if (!stream ||
!CGAL::read_XYZ(stream,
std::back_inserter(points),
CGAL::parameters::point_map(Point_map()).
normal_map(Normal_map())))
if (!stream || !CGAL::read_points(stream,
std::back_inserter(points),
CGAL::parameters::point_map(Point_map())
.normal_map(Normal_map())))
{
std::cerr << "Error: cannot read file cube.pwn" << std::endl;
return EXIT_FAILURE;

View File

@ -120,7 +120,7 @@ is .pwn for points with normals.)
\subsection IOStreamZYZInput Reading XYZ files
Objects represented in the `.XYZ` or `.PWN` format can be imported into \cgal's working environment
using the CGAL::Point_set_3 and the function read_xyz_point_set().
using the `CGAL::Point_set_3` and the function `CGAL::read_point_set()`.
\subsection IOStreamXYZOutput Writing XYZ files
The CGAL::Point_set_3 can be exported into a `XYZ` or a `PWN` file using the function

View File

@ -10,26 +10,262 @@ namespace CGAL {
\section IOstreamIntro Introduction
CGAL algorithms and data structures are usually part of a pipeline of algorithms.
Everything is not entirely self-contained.
Need a way to import and export data to known file formats.
Can in addition enhance the existing stream system coming with the STL.
An algorithm is the application of a serie of steps to convert some input data into output data.
As such, it is necessary to have a way to input and output external data into \cgal data structures.
This is achieved using <em>input-output (IO) streams</em> of data, which enables reading and writing
to and from files, the console, or other custom structures.
We first explain which file formats are supported for various types of structures in CGAL.
Then we explain how to customize your stream to read and write objects that do not necessarily already
have an existing overload.
\subsection PMPOutline Outline
Supported file formats are listed on the \link IOStreamSupportedFileFormats following page\endlink.
- \ref IOstreamIO : the most essential data structures of \cgal, its kernel objects, all provide
adapted input and output operators. In addition, \cgal provides tools to enhance
the existing stream system of the STL to easily read and write classes external to \cgal.
- \ref IOstreamSupportedFormats : a number of traditional data structures such as point sets or
polygon meshes have well-established standards specifying
a particular data format to facilitate data exchanges. Formats
supported for \cgal data structures are detailed in this section.
The page \ref IOStreamSupportedFileFormats offers the reversed viewpoint
(file format to \cgal data structure).
\section IOstreamSupportedFormats Importing and Exporting Data
\section IOstreamIO Reading and Writing Data With Streams
CGAL algorithms work on different types of data structures, such as \ref Chapter_Point_Set_3 "point sets",
\ref PolygonSoups "polygon soups", or \ref PMPDef "polygon meshes".
All classes in the \cgal kernel provide input and output operators for
%IO streams. Classes external to \cgal are also supported, by means of `oformat()`
(Section \ref seciofornoncgaltypes "IO for Non CGAL Types").
The basic task of such an operator is to produce a
representation of an object that can be written as a sequence of
characters on devices as a console, a file, or a pipe. In \cgal we distinguish between a raw ascii,
a raw binary, and a pretty printing format.
\code{.cpp}
enum Mode {ASCII = 0, BINARY, PRETTY};
\endcode
In `ASCII` mode, objects are written as
a set of numbers, e.g. the coordinates of a point or
the coefficients of a line, in a machine independent format.
In `BINARY` mode,
data are written in a binary format, e.g. a double is represented
as a sequence of four byte. The format depends on the machine.
The mode `PRETTY`
serves mainly for debugging as the type of the geometric
object is written, as well as the data defining the object. For example
for a point at the origin with Cartesian double coordinates, the output
would be `PointC2(0.0, 0.0)`. At the moment \cgal does not
provide input operations for pretty printed data. By default a stream
is in <span class="textsc">Ascii</span> mode.
\cgal provides the following functions to modify the mode of an IO stream.
\code{.cpp}
IO::Mode set_mode(std::ios& s, IO::Mode m);
IO::Mode set_ascii_mode(std::ios& s);
IO::Mode set_binary_mode(std::ios& s);
IO::Mode set_pretty_mode(std::ios& s);
\endcode
The following functions enable testing whether a stream is in a certain mode:
\code{.cpp}
IO::Mode get_mode(std::ios& s);
bool is_ascii(std::ios& s);
bool is_binary(std::ios& s);
bool is_pretty(std::ios& s);
\endcode
\subsection IOstreamInput Input Operator
\cgal defines input operators for classes that are derived
from the class `istream`. This allows to read from istreams
as `std::cin`, as well as from `std::istringstream` and `std::ifstream`.
The input operator is defined for all classes in the \cgal `Kernel`.
Let `is` be an input stream.
\code{.cpp}
// Extracts object `c` from the stream `is`. Returns `is`.
istream& operator>>(istream& is, Class c);
\endcode
\code{.cpp}
#include <iostream>
#include <fstream>
#include <CGAL/Cartesian.h>
#include <CGAL/Segment_2.h>
typedef CGAL::Point_2< CGAL::Cartesian<double> > Point;
typedef CGAL::Segment_2< CGAL::Cartesian<double> > Segment;
int
main()
{
Point p, q;
Segment s;
CGAL::set_ascii_mode(std::cin);
std::cin >> p >> q;
std::ifstream f("data.txt");
CGAL::set_binary_mode(f);
f >> s >> p;
return 1;
}
\endcode
\subsection IOstreamOutput Output Operator
\cgal defines output operators for classes that are derived
from the class `ostream`. This allows to write to ostreams
as `std::cout` or `std::cerr`, as well as to `std::ostringstream`
and `std::ofstream`.
The output operator is defined for all classes in the \cgal `Kernel` and for the class `Color` (see
Section \ref IOstreamColors) as well.
Let `os` be an output stream.
\code{.cpp}
// Inserts object `c` in the stream `os`. Returns `os`.
ostream& operator<<(ostream& os, Class c);
\endcode
\code{.cpp}
#include <iostream>
#include <fstream>
#include <CGAL/Cartesian.h>
#include <CGAL/Segment_2.h>
typedef CGAL::Point_2< CGAL::Cartesian<double> > Point;
typedef CGAL::Segment_2< CGAL::Cartesian<double> > Segment;
int main()
{
Point p(0,1), q(2,2);
Segment s(p,q);
CGAL::set_pretty_mode(std::cout);
std::cout << p << std::endl << q << std::endl;
std::ofstream f("data.txt");
CGAL::set_binary_mode(f);
f << s << p ;
return 1;
}
\endcode
\subsection seciofornoncgaltypes IO for Non-CGAL Types
\subsubsection IOstreamUsingOutputFormatting Using Output Formatting
To ensure that non-\cgal types are formatted correctly (i.e., respecting `IO::Mode`), `oformat()` can be used.
For types with a `Output_rep` specialization, the respective output routine of `Output_rep`
will be called by `oformat()`. Otherwise, the stream output operator will be called.
\code{.cpp}
std::cout << CGAL::oformat( myobject );
\endcode
Optionally, you can provide a second template parameter `F` as a formatting tag:
\code{.cpp}
std::cout << CGAL::oformat( myobject, My_formatting_tag() );
\endcode
For a list of formatting tags supported by the type `T`, please
refer to the documentation of the respective type.
\subsubsection IOstreamCustomizingOutputFormatting Customizing Output Formatting
In some situations, you want to control the output formatting for a
type `T`. For external types (third party libraries etc.),
there might be problems if their stream output operator does not
respect `IO::Mode`. The purpose of `Output_rep` is to provide a way to
control output formatting that works independently of the object's
stream output operator.
Instead of putting `T` directly into an output stream,
`T` is wrapped into an output representation `Output_rep`. For
convenience, a function `oformat()` exists, which constructs an instance
of `Output_rep`.
If you do not specialize `Output_rep` for `T`, `T`'s
stream output operator is called from within `Output_rep`, by
default. If you want another behaviour for your type `T`, you
have to provide a specialization for that type. Furthermore, you can
provide specializations with a second template parameter (a formatting
tag). The second template parameter defaults to `Null_tag` and means
<I>default behaviour</I>.
For example, specializing `Output_rep` for `CORE::BigRat` (without a
formatting tag parameter) could look like this:
\code{.cpp}
template <class F>
class Output_rep< ::CORE::BigRat, F> {
const ::CORE::BigRat& t;
public:
Output_rep( const ::CORE::BigRat& tt) : t(tt) {}
std::ostream& operator()( std::ostream& out) const {
switch (get_mode(out)) {
case IO::PRETTY:{
if(CGAL_CORE_DENOMINATOR(t) == ::CORE::BigRat(1))
return out <<CGAL_CORE_NUMERATOR(t);
else
return out << CGAL_CORE_NUMERATOR(t)
<< "/"
<< CGAL_CORE_DENOMINATOR(t);
break;
}
default:
return out << CGAL_CORE_NUMERATOR(t)
<< "/"
<< CGAL_CORE_DENOMINATOR(t);
}
}
};
\endcode
\subsection IOstreamColors Colors
An object of the class `Color` is a color available
for drawing operations in many \cgal output streams.
Each color is defined by a triple of integers `(r,g,b)` with
0 \f$ \le \f$ r,g,b \f$ \le \f$ 255, the so-called <I>rgb-value</I> of the color.
There are a 11 predefined `Color` constants available:
`BLACK`, `WHITE`, `GRAY`, `RED`, `GREEN`,
`DEEPBLUE`, `BLUE`, `PURPLE`, `VIOLET`, `ORANGE`,
and `YELLOW`.
\subsection IOstreamStream Stream Support
Three classes are provided by \cgal as adaptors to input and output stream
iterators. The class `Istream_iterator` is an input iterator adaptor and
is particularly useful for classes that are similar but not compatible to
`std::istream`. Similarly, the class `Ostream_iterator` is an output
iterator adaptor. The class `Verbose_ostream` can be used as an output
stream. The stream
output operator `<<` is defined for any type. The class
stores in an internal state a stream and whether the
output is active or not. If the state is active, the stream output
operator `<<` uses the internal stream to output its argument. If
the state is inactive, nothing happens.
\section IOstreamSupportedFormats Importing and Exporting Data using Standard Formats
Although there is a large number of different types of input data structures in \cgal algorithms,
some common data structures such as point sets or polygon meshes appear more often. These
traditional data structures have long been used and specific standards have been created
to facilite information exchange. In the following section, supported file formats are listed
for the most common data structures used in \cgal. A reverse viewpoint, listing the data structures
which can be used for a specific file format is available on \ref IOStreamSupportedFileFormats.
\subsection IOstreamPointSetIO Point Set IO
The CGAL::Point_set_3 is a vector based data structure that contains
a default property (named point) for the coordinates of the points,
and is able to work with dynamic properties.
The class `CGAL::Point_set_3` is the data structure used in \cgal to represent point sets.
It is a vector-based data structure that contains a default property (named point)
for the coordinates of the points, and is able to work with dynamic properties.
The file formats supported for `CGAL::Point_set_3` are detailed in the table below.
<table class="iotable">
<tr>
@ -96,7 +332,7 @@ their indices per face (i.e a vector of 3 integers represent a triangle face).
\subsection IOstreamPolygonMeshIO Polygon Mesh IO
A Polygon Mesh is a 3D structure that refines the concept of `FaceGraph`
with some other restrictions. A more precise definition can be found \ref PMPDef "here".
with some additional restrictions; a more precise definition can be found \ref PMPDef "here".
<table class="iotable">
<tr>
@ -212,231 +448,6 @@ which might look as follows:
\cgalExample{Stream_support/read_xml.cpp}
\section IOstreamIO IO Streams
All classes in the \cgal kernel provide input and output operators for
%IO streams. Classes external to \cgal are also supported, by means of `oformat()`
(Section \ref seciofornoncgaltypes "IO for Non CGAL Types").
The basic task of such an operator is to produce a
representation of an object that can be written as a sequence of
characters on devices as a console, a file, or a pipe. In \cgal we distinguish between a raw ascii,
a raw binary, and a pretty printing format.
\code{.cpp}
enum Mode {ASCII = 0, BINARY, PRETTY};
\endcode
In `ASCII` mode, objects are written as
a set of numbers, e.g. the coordinates of a point or
the coefficients of a line, in a machine independent format.
In `BINARY` mode,
data are written in a binary format, e.g. a double is represented
as a sequence of four byte. The format depends on the machine.
The mode `PRETTY`
serves mainly for debugging as the type of the geometric
object is written, as well as the data defining the object. For example
for a point at the origin with Cartesian double coordinates, the output
would be `PointC2(0.0, 0.0)`. At the moment \cgal does not
provide input operations for pretty printed data. By default a stream
is in <span class="textsc">Ascii</span> mode.
\cgal provides the following functions to modify the mode of an IO stream.
\code{.cpp}
IO::Mode set_mode(std::ios& s, IO::Mode m);
IO::Mode set_ascii_mode(std::ios& s);
IO::Mode set_binary_mode(std::ios& s);
IO::Mode set_pretty_mode(std::ios& s);
\endcode
The following functions enable testing whether a stream is in a certain mode:
\code{.cpp}
IO::Mode get_mode(std::ios& s);
bool is_ascii(std::ios& s);
bool is_binary(std::ios& s);
bool is_pretty(std::ios& s);
\endcode
\subsection IOstreamOutput Output Operator
\cgal defines output operators for classes that are derived
from the class `ostream`. This allows to write to ostreams
as `std::cout` or `std::cerr`, as well as to `std::ostringstream`
and `std::ofstream`.
The output operator is defined for all classes in the \cgal `Kernel` and for the class `Color` (see
Section \ref IOstreamColors) as well.
Let `os` be an output stream.
\code{.cpp}
// Inserts object `c` in the stream `os`. Returns `os`.
ostream& operator<<(ostream& os, Class c);
\endcode
\code{.cpp}
#include <iostream>
#include <fstream>
#include <CGAL/Cartesian.h>
#include <CGAL/Segment_2.h>
typedef CGAL::Point_2< CGAL::Cartesian<double> > Point;
typedef CGAL::Segment_2< CGAL::Cartesian<double> > Segment;
int main()
{
Point p(0,1), q(2,2);
Segment s(p,q);
CGAL::set_pretty_mode(std::cout);
std::cout << p << std::endl << q << std::endl;
std::ofstream f("data.txt");
CGAL::set_binary_mode(f);
f << s << p ;
return 1;
}
\endcode
\subsection IOstreamInput Input Operator
\cgal defines input operators for classes that are derived
from the class `istream`. This allows to read from istreams
as `std::cin`, as well as from `std::istringstream` and `std::ifstream`.
The input operator is defined for all classes in the \cgal `Kernel`.
Let `is` be an input stream.
\code{.cpp}
// Extracts object `c` from the stream `is`. Returns `is`.
istream& operator>>(istream& is, Class c);
\endcode
\code{.cpp}
#include <iostream>
#include <fstream>
#include <CGAL/Cartesian.h>
#include <CGAL/Segment_2.h>
typedef CGAL::Point_2< CGAL::Cartesian<double> > Point;
typedef CGAL::Segment_2< CGAL::Cartesian<double> > Segment;
int
main()
{
Point p, q;
Segment s;
CGAL::set_ascii_mode(std::cin);
std::cin >> p >> q;
std::ifstream f("data.txt");
CGAL::set_binary_mode(f);
f >> s >> p;
return 1;
}
\endcode
\subsection seciofornoncgaltypes IO for Non-CGAL Types
\subsubsection IOstreamUsingOutputFormatting Using Output Formatting
To ensure that non-\cgal types are formatted correctly (i.e., respecting `IO::Mode`), `oformat()` can be used.
For types with a `Output_rep` specialization, the respective output routine of `Output_rep`
will be called by `oformat()`. Otherwise, the stream output operator will be called.
\code{.cpp}
std::cout << CGAL::oformat( myobject );
\endcode
Optionally, you can provide a second template parameter `F` as a formatting tag:
\code{.cpp}
std::cout << CGAL::oformat( myobject, My_formatting_tag() );
\endcode
For a list of formatting tags supported by the type `T`, please
refer to the documentation of the respective type.
\subsubsection IOstreamCustomizingOutputFormatting Customizing Output Formatting
In some situations, you want to control the output formatting for a
type `T`. For external types (third party libraries etc.),
there might be problems if their stream output operator does not
respect `IO::Mode`. The purpose of `Output_rep` is to provide a way to
control output formatting that works independently of the object's
stream output operator.
Instead of putting `T` directly into an output stream,
`T` is wrapped into an output representation `Output_rep`. For
convenience, a function `oformat()` exists, which constructs an instance
of `Output_rep`.
If you do not specialize `Output_rep` for `T`, `T`'s
stream output operator is called from within `Output_rep`, by
default. If you want another behaviour for your type `T`, you
have to provide a specialization for that type. Furthermore, you can
provide specializations with a second template parameter (a formatting
tag). The second template parameter defaults to `Null_tag` and means
<I>default behaviour</I>.
For example, specializing `Output_rep` for `CORE::BigRat` (without a
formatting tag parameter) could look like this:
\code{.cpp}
template <class F>
class Output_rep< ::CORE::BigRat, F> {
const ::CORE::BigRat& t;
public:
Output_rep( const ::CORE::BigRat& tt) : t(tt) {}
std::ostream& operator()( std::ostream& out) const {
switch (get_mode(out)) {
case IO::PRETTY:{
if(CGAL_CORE_DENOMINATOR(t) == ::CORE::BigRat(1))
return out <<CGAL_CORE_NUMERATOR(t);
else
return out << CGAL_CORE_NUMERATOR(t)
<< "/"
<< CGAL_CORE_DENOMINATOR(t);
break;
}
default:
return out << CGAL_CORE_NUMERATOR(t)
<< "/"
<< CGAL_CORE_DENOMINATOR(t);
}
}
};
\endcode
\subsection IOstreamColors Colors
An object of the class `Color` is a color available
for drawing operations in many \cgal output streams.
Each color is defined by a triple of integers `(r,g,b)` with
0 \f$ \le \f$ r,g,b \f$ \le \f$ 255, the so-called <I>rgb-value</I> of the color.
There are a 11 predefined `Color` constants available:
`BLACK`, `WHITE`, `GRAY`, `RED`, `GREEN`,
`DEEPBLUE`, `BLUE`, `PURPLE`, `VIOLET`, `ORANGE`,
and `YELLOW`.
\subsection IOstreamStream Stream Support
Three classes are provided by \cgal as adaptors to input and output stream
iterators. The class `Istream_iterator` is an input iterator adaptor and
is particularly useful for classes that are similar but not compatible to
`std::istream`. Similarly, the class `Ostream_iterator` is an output
iterator adaptor. The class `Verbose_ostream` can be used as an output
stream. The stream
output operator `<<` is defined for any type. The class
stores in an internal state a stream and whether the
output is active or not. If the state is active, the stream output
operator `<<` uses the internal stream to output its argument. If
the state is inactive, nothing happens.
*/
} /* namespace CGAL */

View File

@ -67,8 +67,10 @@ the printing mode.
- \link OffIoFuncs I/O for OFF files (`CGAL::write_OFF()`and `CGAL::read_OFF()`)\endlink
- \link GocadIoFuncs I/O for GOCAD files (`CGAL::write_GOCAD()`and `CGAL::read_GOCAD()`)\endlink
- \link VtpIoFuncs I/O for VTP files (`CGAL::write_VTP()`and `CGAL::read_VTP()`)\endlink
- `GCAL::read_polygon_soup()`
- `GCAL::write_polygon_soup()`
- `GCAL::read_WKT()`
- `CGAL::read_point_WKT()`
- `GCAL::read_multi_point_WKT()`

View File

@ -13,7 +13,7 @@
#ifndef CGAL_IO_GOCAD_H
#define CGAL_IO_GOCAD_H
#include <CGAL/IO/reader_helpers.h>
#include <CGAL/IO/helpers.h>
#include <CGAL/assertions.h>
#include <CGAL/boost/graph/Named_function_parameters.h>

View File

@ -13,7 +13,7 @@
#include <CGAL/IO/OFF/File_scanner_OFF.h>
#include <CGAL/IO/OFF/File_writer_OFF.h>
#include <CGAL/IO/reader_helpers.h>
#include <CGAL/IO/helpers.h>
#include <CGAL/IO/Generic_writer.h>
#include <CGAL/array.h>

View File

@ -202,7 +202,7 @@ public:
template <typename Type>
Type read(std::istream& stream) const
{
if(m_format == 0) // Ascii
if(m_format == 0) // ASCII
{
Type t;
read_ascii(stream, t);

View File

@ -13,7 +13,7 @@
#define CGAL_IO_STL_STL_READER_H
#include <CGAL/IO/io.h>
#include <CGAL/IO/reader_helpers.h>
#include <CGAL/IO/helpers.h>
#include <boost/cstdint.hpp>
#include <boost/range/value_type.hpp>

View File

@ -8,20 +8,20 @@
//
// Author(s) : Mael Rouxel-Labbé
#ifndef CGAL_IO_READER_HELPERS_H
#define CGAL_IO_READER_HELPERS_H
#ifndef CGAL_STREAM_SUPPORT_HELPERS_H
#define CGAL_STREAM_SUPPORT_HELPERS_H
#include <CGAL/array.h>
#include <CGAL/assertions.h>
#include <CGAL/Container_helper.h>
#include <CGAL/Has_member.h>
#include <CGAL/Point_3.h>
#include <CGAL/is_iterator.h>
#include <boost/mpl/logical.hpp>
#include <boost/utility/enable_if.hpp>
#include <CGAL/Container_helper.h>
#include <CGAL/Point_3.h>
#include <boost/mpl/has_xxx.hpp>
namespace CGAL{
namespace CGAL {
namespace IO {
namespace internal {
@ -42,8 +42,32 @@ void fill_point(const double x, const double y, const double z, const double w,
pt[0] = x/w; pt[1] = y/w; pt[2] = z/w;
}
// Functions like 'write_OFF' can take :
// - write_OFF(stream, point_set)
// - write_OFF(stream, pointrange)
// - write_OFF(stream, polygon_mesh)
// so a way to distinguish is needed
BOOST_MPL_HAS_XXX_TRAIT_DEF(Point_set)
template <typename T>
struct is_Point_set_3 : has_Point_set<T> { };
// Point_set_3 also functions as range, so it needs to be excluded
template <typename T>
struct is_Range
: public boost::mpl::and_<
boost::has_range_const_iterator<T>,
boost::mpl::not_<is_Point_set_3<T> > >
{ };
// For polygon meshes
template <typename T>
struct is_Point_set_or_Range_or_Iterator
: public boost::mpl::or_<is_Point_set_3<T>, is_Range<T>, is_iterator<T> >
{ };
} // end namespace internal
} // end namespace IO
} // namespace CGAL
#endif // CGAL_IO_READER_HELPERS_H
#endif // CGAL_STREAM_SUPPORT_HELPERS_H

View File

@ -283,7 +283,7 @@ bool read_OFF_with_or_without_vnormals(std::istream& is,
/// \relates Surface_mesh
/// \ingroup PkgSurfaceMeshIOFunc
///
/// Extracts the surface mesh from an input stream in Ascii OFF, COFF, NOFF, CNOFF
/// Extracts the surface mesh from an input stream in ASCII OFF, COFF, NOFF, CNOFF
/// format and appends it to the surface mesh `sm`.
///
/// The operator reads the point property as well as "v:normal", "v:color", `"v:texcoord"`, and "f:color".

View File

@ -902,7 +902,7 @@ bool write_PLY(std::ostream& os,
return true;
}
/// Extracts the surface mesh from an input stream in Ascii or
/// Extracts the surface mesh from an input stream in ASCII or
/// Binary PLY format and appends it to the surface mesh `sm`.
///
/// - the operator reads the vertex `point` property and the face