mirror of https://github.com/CGAL/cgal
Replace std::vector by ranges in Stream_support IO function APIs
This commit is contained in:
parent
4e6fb685c6
commit
8a535e5e55
|
|
@ -34,10 +34,12 @@ public:
|
||||||
Generic_writer(Stream& out) : m_out(out) { }
|
Generic_writer(Stream& out) : m_out(out) { }
|
||||||
Generic_writer(Stream& out, FileWriter writer) : m_out(out), m_writer(writer) { }
|
Generic_writer(Stream& out, FileWriter writer) : m_out(out), m_writer(writer) { }
|
||||||
|
|
||||||
template <typename Point_3, typename Polygon_3>
|
template <typename PointRange_3, typename PolygonRange_3>
|
||||||
bool operator()(const std::vector<Point_3>& points,
|
bool operator()(const PointRange_3& points,
|
||||||
const std::vector<Polygon_3>& polygons)
|
const PolygonRange_3& polygons)
|
||||||
{
|
{
|
||||||
|
typedef typename PointRange_3::value_type Point_3;
|
||||||
|
typedef typename PolygonRange_3::value_type Polygon_3;
|
||||||
if(m_out.fail())
|
if(m_out.fail())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -110,7 +110,7 @@ bool read_OFF(std::istream& is,
|
||||||
if(!is.good())
|
if(!is.good())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
IO::internal::resize(polygons[i], no);
|
CGAL::internal::resize(polygons[i], no);
|
||||||
for(std::size_t j=0; j<no; ++j)
|
for(std::size_t j=0; j<no; ++j)
|
||||||
{
|
{
|
||||||
std::size_t id;
|
std::size_t id;
|
||||||
|
|
|
||||||
|
|
@ -22,17 +22,20 @@ namespace CGAL {
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
/// Read
|
/// Read
|
||||||
|
//HEdgesRange" = range of std::pair<unsigned int, unsigned int>
|
||||||
template <class Point_3, class Polygon_3, class Color_rgb>
|
//HUVRange = range of std::pair<float, float>
|
||||||
|
template <class PointRange, class PolygonRange, class ColorRange, class HEdgesRange, class HUVRange>
|
||||||
bool read_PLY(std::istream& is,
|
bool read_PLY(std::istream& is,
|
||||||
std::vector<Point_3>& points,
|
PointRange& points,
|
||||||
std::vector<Polygon_3>& polygons,
|
PolygonRange& polygons,
|
||||||
std::vector<std::pair<unsigned int, unsigned int> >& hedges,
|
HEdgesRange& hedges,
|
||||||
std::vector<Color_rgb>& fcolors,
|
ColorRange& fcolors,
|
||||||
std::vector<Color_rgb>& vcolors,
|
ColorRange& vcolors,
|
||||||
std::vector<std::pair<float, float> >& huvs,
|
HUVRange& huvs,
|
||||||
bool /* verbose */ = false)
|
bool /* verbose */ = false)
|
||||||
{
|
{
|
||||||
|
typedef typename PointRange::value_type Point_3;
|
||||||
|
typedef typename ColorRange::value_type Color_rgb;
|
||||||
if(!is.good())
|
if(!is.good())
|
||||||
{
|
{
|
||||||
std::cerr << "Error: cannot open file" << std::endl;
|
std::cerr << "Error: cannot open file" << std::endl;
|
||||||
|
|
@ -181,18 +184,19 @@ bool read_PLY(std::istream& is,
|
||||||
return !is.fail();
|
return !is.fail();
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class Point_3, class Polygon_3, class Color_rgb>
|
template <class PointRange, class PolygonRange, class ColorRange>
|
||||||
bool read_PLY(std::istream& is,
|
bool read_PLY(std::istream& is,
|
||||||
std::vector<Point_3>& points,
|
PointRange& points,
|
||||||
std::vector<Polygon_3>& polygons,
|
PolygonRange& polygons,
|
||||||
std::vector<Color_rgb>& fcolors,
|
ColorRange& fcolors,
|
||||||
std::vector<Color_rgb>& vcolors,
|
ColorRange& vcolors,
|
||||||
bool /* verbose */ = false)
|
bool /* verbose */ = false)
|
||||||
{
|
{
|
||||||
|
|
||||||
std::vector<std::pair<unsigned int, unsigned int> > dummy_pui;
|
std::vector<std::pair<unsigned int, unsigned int> > dummy_pui;
|
||||||
std::vector<std::pair<float, float> > dummy_pf;
|
std::vector<std::pair<float, float> > dummy_pf;
|
||||||
|
|
||||||
return read_PLY<Point_3, Polygon_3, Color_rgb>(is, points, polygons, dummy_pui, fcolors, vcolors, dummy_pf);
|
return read_PLY(is, points, polygons, dummy_pui, fcolors, vcolors, dummy_pf);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
|
|
@ -200,15 +204,22 @@ bool read_PLY(std::istream& is,
|
||||||
*
|
*
|
||||||
* reads the content of `is` into `points` and `polygons`, in the PLY format.
|
* reads the content of `is` into `points` and `polygons`, in the PLY format.
|
||||||
*
|
*
|
||||||
|
* `PointRange` is a model of the concepts `RandomAccessContainer`
|
||||||
|
* and `BackInsertionSequence` whose `value type` is a `CGAL::Point_3`.
|
||||||
|
*
|
||||||
|
* `PolygonRange` is a model of the concepts `RandomAccessContainer`
|
||||||
|
* and `BackInsertionSequence` whose `value type` is `std::size_t`.
|
||||||
|
*
|
||||||
* \see \ref IOStreamPLY
|
* \see \ref IOStreamPLY
|
||||||
*/
|
*/
|
||||||
template <class Point_3, class Polygon_3>
|
template <class PointRange, class PolygonRange>
|
||||||
bool
|
bool
|
||||||
read_PLY(std::istream& is,
|
read_PLY(std::istream& is,
|
||||||
std::vector<Point_3>& points,
|
PointRange& points,
|
||||||
std::vector<Polygon_3>& polygons,
|
PolygonRange& polygons,
|
||||||
bool /* verbose */ = false)
|
bool /* verbose */ = false)
|
||||||
{
|
{
|
||||||
|
typedef typename PointRange::value_type Point_3;
|
||||||
if(!is.good())
|
if(!is.good())
|
||||||
{
|
{
|
||||||
std::cerr << "Error: cannot open file" << std::endl;
|
std::cerr << "Error: cannot open file" << std::endl;
|
||||||
|
|
@ -294,13 +305,21 @@ read_PLY(std::istream& is,
|
||||||
*
|
*
|
||||||
* writes the content of `points` and `polygons` in `out`, in the OFF format.
|
* writes the content of `points` and `polygons` in `out`, in the OFF format.
|
||||||
*
|
*
|
||||||
|
* `PointRange` is a model of the concepts `RandomAccessContainer`
|
||||||
|
* and `BackInsertionSequence` whose `value type` is a `CGAL::Point_3`.
|
||||||
|
*
|
||||||
|
* `PolygonRange` is a model of the concepts `RandomAccessContainer`
|
||||||
|
* and `BackInsertionSequence` whose `value type` is `std::size_t`.
|
||||||
* \see \ref IOStreamOFF
|
* \see \ref IOStreamOFF
|
||||||
*/
|
*/
|
||||||
template <class Point_3, class Polygon_3>
|
template <class PointRange, class PolygonRange>
|
||||||
bool write_PLY(std::ostream& out,
|
bool write_PLY(std::ostream& out,
|
||||||
const std::vector<Point_3>& points,
|
const PointRange& points,
|
||||||
const std::vector<Polygon_3>& polygons)
|
const PolygonRange& polygons)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
typedef typename PointRange::value_type Point_3;
|
||||||
|
typedef typename PolygonRange::value_type Polygon_3;
|
||||||
if(!out.good())
|
if(!out.good())
|
||||||
{
|
{
|
||||||
std::cerr << "Error: cannot open file" << std::endl;
|
std::cerr << "Error: cannot open file" << std::endl;
|
||||||
|
|
|
||||||
|
|
@ -673,13 +673,15 @@ void process_properties(PLY_element& element, OutputValueType& new_element,
|
||||||
std::forward<PropertyMapBinders>(properties)...);
|
std::forward<PropertyMapBinders>(properties)...);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename Integer, class Polygon_3, class Color_rgb>
|
template <typename Integer, class PolygonRange, class ColorRange>
|
||||||
bool read_PLY_faces(std::istream& in,
|
bool read_PLY_faces(std::istream& in,
|
||||||
IO::internal::PLY_element& element,
|
IO::internal::PLY_element& element,
|
||||||
std::vector< Polygon_3 >& polygons,
|
PolygonRange& polygons,
|
||||||
std::vector< Color_rgb >& fcolors,
|
ColorRange& fcolors,
|
||||||
const char* vertex_indices_tag)
|
const char* vertex_indices_tag)
|
||||||
{
|
{
|
||||||
|
typedef typename PolygonRange::value_type Polygon_3;
|
||||||
|
typedef typename ColorRange::value_type Color_rgb;
|
||||||
bool has_colors = false;
|
bool has_colors = false;
|
||||||
std::string rtag = "r", gtag = "g", btag = "b";
|
std::string rtag = "r", gtag = "g", btag = "b";
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -170,7 +170,7 @@ std::ostream& write_STL(std::ostream& out,
|
||||||
const PointRange& points,
|
const PointRange& points,
|
||||||
const TriangleRange& facets)
|
const TriangleRange& facets)
|
||||||
{
|
{
|
||||||
typedef typename boost::range_value<PointRange>::type Triangle;
|
typedef typename boost::range_value<TriangleRange>::type Triangle;
|
||||||
typedef typename boost::range_value<PointRange>::type Point;
|
typedef typename boost::range_value<PointRange>::type Point;
|
||||||
typedef typename CGAL::Kernel_traits<Point>::Kernel K;
|
typedef typename CGAL::Kernel_traits<Point>::Kernel K;
|
||||||
typedef typename K::Vector_3 Vector_3;
|
typedef typename K::Vector_3 Vector_3;
|
||||||
|
|
|
||||||
|
|
@ -49,7 +49,7 @@ bool read_ASCII_facet(std::istream& is,
|
||||||
double x,y,z;
|
double x,y,z;
|
||||||
Point p;
|
Point p;
|
||||||
Triangle ijk;
|
Triangle ijk;
|
||||||
IO::internal::resize(ijk, 3);
|
CGAL::internal::resize(ijk, 3);
|
||||||
|
|
||||||
while(is >> s)
|
while(is >> s)
|
||||||
{
|
{
|
||||||
|
|
@ -236,7 +236,7 @@ bool parse_binary_STL(std::istream& is,
|
||||||
}
|
}
|
||||||
|
|
||||||
Triangle ijk;
|
Triangle ijk;
|
||||||
IO::internal::resize(ijk, 3);
|
CGAL::internal::resize(ijk, 3);
|
||||||
|
|
||||||
for(int j=0; j<3; ++j)
|
for(int j=0; j<3; ++j)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -30,6 +30,7 @@ typedef std::vector<CGAL::Color> ColorRange;
|
||||||
|
|
||||||
int main(int argc, char** argv)
|
int main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
|
#ifdef CGAL_LINKED_WITH_3MF
|
||||||
const char* file_name=(argc == 2) ? argv[1] : "data/test.3mf";
|
const char* file_name=(argc == 2) ? argv[1] : "data/test.3mf";
|
||||||
|
|
||||||
std::vector<PointRange> all_points;
|
std::vector<PointRange> all_points;
|
||||||
|
|
@ -130,6 +131,7 @@ int main(int argc, char** argv)
|
||||||
CGAL::write_triangle_meshes_to_3mf("meshes.3mf", meshes, names);
|
CGAL::write_triangle_meshes_to_3mf("meshes.3mf", meshes, names);
|
||||||
|
|
||||||
std::cout<<"OK."<<std::endl;
|
std::cout<<"OK."<<std::endl;
|
||||||
|
#endif //CGAL_LINKED_WITH_3MF
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -34,7 +34,7 @@ int main ()
|
||||||
faces[3].push_back(3);
|
faces[3].push_back(3);
|
||||||
|
|
||||||
std::ofstream os("tetra.stl");
|
std::ofstream os("tetra.stl");
|
||||||
CGAL::write_STL(ps, faces, os);
|
CGAL::write_STL(os, ps, faces);
|
||||||
if(!os)
|
if(!os)
|
||||||
{
|
{
|
||||||
std::cerr<<"error during STL writing."<<std::endl;
|
std::cerr<<"error during STL writing."<<std::endl;
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
// file: test/Support_stream/VRML2.C
|
// file: test/Support_stream/VRML2.C
|
||||||
|
|
||||||
#include <CGAL/Simple_cartesian.h>
|
#include <CGAL/Simple_cartesian.h>
|
||||||
#include <CGAL/IO/VRML_2_ostream.h>
|
#include <CGAL/IO/VRML/VRML_2_ostream.h>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
typedef CGAL::Simple_cartesian<double> Kernel;
|
typedef CGAL::Simple_cartesian<double> Kernel;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue