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, FileWriter writer) : m_out(out), m_writer(writer) { }
|
||||
|
||||
template <typename Point_3, typename Polygon_3>
|
||||
bool operator()(const std::vector<Point_3>& points,
|
||||
const std::vector<Polygon_3>& polygons)
|
||||
template <typename PointRange_3, typename PolygonRange_3>
|
||||
bool operator()(const PointRange_3& points,
|
||||
const PolygonRange_3& polygons)
|
||||
{
|
||||
typedef typename PointRange_3::value_type Point_3;
|
||||
typedef typename PolygonRange_3::value_type Polygon_3;
|
||||
if(m_out.fail())
|
||||
return false;
|
||||
|
||||
|
|
|
|||
|
|
@ -110,7 +110,7 @@ bool read_OFF(std::istream& is,
|
|||
if(!is.good())
|
||||
return false;
|
||||
|
||||
IO::internal::resize(polygons[i], no);
|
||||
CGAL::internal::resize(polygons[i], no);
|
||||
for(std::size_t j=0; j<no; ++j)
|
||||
{
|
||||
std::size_t id;
|
||||
|
|
|
|||
|
|
@ -22,17 +22,20 @@ namespace CGAL {
|
|||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/// Read
|
||||
|
||||
template <class Point_3, class Polygon_3, class Color_rgb>
|
||||
//HEdgesRange" = range of std::pair<unsigned int, unsigned int>
|
||||
//HUVRange = range of std::pair<float, float>
|
||||
template <class PointRange, class PolygonRange, class ColorRange, class HEdgesRange, class HUVRange>
|
||||
bool read_PLY(std::istream& is,
|
||||
std::vector<Point_3>& points,
|
||||
std::vector<Polygon_3>& polygons,
|
||||
std::vector<std::pair<unsigned int, unsigned int> >& hedges,
|
||||
std::vector<Color_rgb>& fcolors,
|
||||
std::vector<Color_rgb>& vcolors,
|
||||
std::vector<std::pair<float, float> >& huvs,
|
||||
PointRange& points,
|
||||
PolygonRange& polygons,
|
||||
HEdgesRange& hedges,
|
||||
ColorRange& fcolors,
|
||||
ColorRange& vcolors,
|
||||
HUVRange& huvs,
|
||||
bool /* verbose */ = false)
|
||||
{
|
||||
typedef typename PointRange::value_type Point_3;
|
||||
typedef typename ColorRange::value_type Color_rgb;
|
||||
if(!is.good())
|
||||
{
|
||||
std::cerr << "Error: cannot open file" << std::endl;
|
||||
|
|
@ -181,18 +184,19 @@ bool read_PLY(std::istream& is,
|
|||
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,
|
||||
std::vector<Point_3>& points,
|
||||
std::vector<Polygon_3>& polygons,
|
||||
std::vector<Color_rgb>& fcolors,
|
||||
std::vector<Color_rgb>& vcolors,
|
||||
PointRange& points,
|
||||
PolygonRange& polygons,
|
||||
ColorRange& fcolors,
|
||||
ColorRange& vcolors,
|
||||
bool /* verbose */ = false)
|
||||
{
|
||||
|
||||
std::vector<std::pair<unsigned int, unsigned int> > dummy_pui;
|
||||
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.
|
||||
*
|
||||
* `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
|
||||
*/
|
||||
template <class Point_3, class Polygon_3>
|
||||
template <class PointRange, class PolygonRange>
|
||||
bool
|
||||
read_PLY(std::istream& is,
|
||||
std::vector<Point_3>& points,
|
||||
std::vector<Polygon_3>& polygons,
|
||||
PointRange& points,
|
||||
PolygonRange& polygons,
|
||||
bool /* verbose */ = false)
|
||||
{
|
||||
typedef typename PointRange::value_type Point_3;
|
||||
if(!is.good())
|
||||
{
|
||||
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.
|
||||
*
|
||||
* `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
|
||||
*/
|
||||
template <class Point_3, class Polygon_3>
|
||||
template <class PointRange, class PolygonRange>
|
||||
bool write_PLY(std::ostream& out,
|
||||
const std::vector<Point_3>& points,
|
||||
const std::vector<Polygon_3>& polygons)
|
||||
const PointRange& points,
|
||||
const PolygonRange& polygons)
|
||||
{
|
||||
|
||||
typedef typename PointRange::value_type Point_3;
|
||||
typedef typename PolygonRange::value_type Polygon_3;
|
||||
if(!out.good())
|
||||
{
|
||||
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)...);
|
||||
}
|
||||
|
||||
template <typename Integer, class Polygon_3, class Color_rgb>
|
||||
template <typename Integer, class PolygonRange, class ColorRange>
|
||||
bool read_PLY_faces(std::istream& in,
|
||||
IO::internal::PLY_element& element,
|
||||
std::vector< Polygon_3 >& polygons,
|
||||
std::vector< Color_rgb >& fcolors,
|
||||
PolygonRange& polygons,
|
||||
ColorRange& fcolors,
|
||||
const char* vertex_indices_tag)
|
||||
{
|
||||
typedef typename PolygonRange::value_type Polygon_3;
|
||||
typedef typename ColorRange::value_type Color_rgb;
|
||||
bool has_colors = false;
|
||||
std::string rtag = "r", gtag = "g", btag = "b";
|
||||
|
||||
|
|
|
|||
|
|
@ -170,7 +170,7 @@ std::ostream& write_STL(std::ostream& out,
|
|||
const PointRange& points,
|
||||
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 CGAL::Kernel_traits<Point>::Kernel K;
|
||||
typedef typename K::Vector_3 Vector_3;
|
||||
|
|
|
|||
|
|
@ -49,7 +49,7 @@ bool read_ASCII_facet(std::istream& is,
|
|||
double x,y,z;
|
||||
Point p;
|
||||
Triangle ijk;
|
||||
IO::internal::resize(ijk, 3);
|
||||
CGAL::internal::resize(ijk, 3);
|
||||
|
||||
while(is >> s)
|
||||
{
|
||||
|
|
@ -236,7 +236,7 @@ bool parse_binary_STL(std::istream& is,
|
|||
}
|
||||
|
||||
Triangle ijk;
|
||||
IO::internal::resize(ijk, 3);
|
||||
CGAL::internal::resize(ijk, 3);
|
||||
|
||||
for(int j=0; j<3; ++j)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -30,6 +30,7 @@ typedef std::vector<CGAL::Color> ColorRange;
|
|||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
#ifdef CGAL_LINKED_WITH_3MF
|
||||
const char* file_name=(argc == 2) ? argv[1] : "data/test.3mf";
|
||||
|
||||
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);
|
||||
|
||||
std::cout<<"OK."<<std::endl;
|
||||
#endif //CGAL_LINKED_WITH_3MF
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ int main ()
|
|||
faces[3].push_back(3);
|
||||
|
||||
std::ofstream os("tetra.stl");
|
||||
CGAL::write_STL(ps, faces, os);
|
||||
CGAL::write_STL(os, ps, faces);
|
||||
if(!os)
|
||||
{
|
||||
std::cerr<<"error during STL writing."<<std::endl;
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
// file: test/Support_stream/VRML2.C
|
||||
|
||||
#include <CGAL/Simple_cartesian.h>
|
||||
#include <CGAL/IO/VRML_2_ostream.h>
|
||||
#include <CGAL/IO/VRML/VRML_2_ostream.h>
|
||||
#include <iostream>
|
||||
|
||||
typedef CGAL::Simple_cartesian<double> Kernel;
|
||||
|
|
|
|||
Loading…
Reference in New Issue