From a6b64c907bcf97b8bae4e0ede633515cc293ac92 Mon Sep 17 00:00:00 2001 From: Simon Giraudot Date: Tue, 27 Sep 2016 15:38:30 +0200 Subject: [PATCH] WIP: operator<< to recover all properties in PLY output --- Point_set_3/include/CGAL/Point_set_3.h | 66 ++++++++++++++++++++++- Point_set_3/include/CGAL/Point_set_3/IO.h | 17 +++--- 2 files changed, 74 insertions(+), 9 deletions(-) diff --git a/Point_set_3/include/CGAL/Point_set_3.h b/Point_set_3/include/CGAL/Point_set_3.h index bafc9beb0bc..8ca67fa8927 100644 --- a/Point_set_3/include/CGAL/Point_set_3.h +++ b/Point_set_3/include/CGAL/Point_set_3.h @@ -760,6 +760,65 @@ public: } /// @} + + /*! + + \ingroup PkgPointSet3 + + \brief Inserts the point set in an output stream in Ascii PLY + format. All properties are inserted in their instanciation order. + + \relates Point_set_3 + */ + template + friend std::ostream& operator<<(std::ostream& os, const Point_set_3

& ps) + { + os << "ply" << std::endl + << "format ascii 1.0" << std::endl + << "comment Generated by the CGAL library" << std::endl + << "element vertex " << ps.number_of_points() << std::endl; + + std::vector prop = ps.m_base.properties(); + for (std::size_t i = 0; i < prop.size(); ++ i) + { + if (prop[i] == "index") + continue; + else if (prop[i] == "point") + os << "property double x" << std::endl + << "property double y" << std::endl + << "property double z" << std::endl; + else if (prop[i] == "normal") + os << "property double nx" << std::endl + << "property double ny" << std::endl + << "property double nz" << std::endl; + else if (ps.m_base.template get(prop[i]).first) + os << "property char " << prop[i] << std::endl; + else if (ps.m_base.template get(prop[i]).first) + os << "property uchar " << prop[i] << std::endl; + else if (ps.m_base.template get(prop[i]).first) + os << "property short " << prop[i] << std::endl; + else if (ps.m_base.template get(prop[i]).first) + os << "property ushort " << prop[i] << std::endl; + else if (ps.m_base.template get(prop[i]).first) + os << "property int " << prop[i] << std::endl; + else if (ps.m_base.template get(prop[i]).first) + os << "property uint " << prop[i] << std::endl; + else if (ps.m_base.template get(prop[i]).first) + os << "property float " << prop[i] << std::endl; + else if (ps.m_base.template get(prop[i]).first) + os << "property double " << prop[i] << std::endl; + else + os << "property " << boost::core::demangle(ps.m_base.get_type(prop[i]).name()) + << " " << prop[i] << std::endl; + } + + os << "end_header" << std::endl; + + for (const_iterator it = ps.begin(); it != ps.end(); ++ it) + os << ps.m_base.to_str(*it); + return os; + } + /*! \name Push Property Maps and Inserters (Advanced) @@ -943,6 +1002,7 @@ public: /// @} + private: /// \cond SKIP_IN_MANUAL void quick_sort_on_indices (std::ptrdiff_t begin, std::ptrdiff_t end) @@ -1005,8 +1065,9 @@ private: \note Garbage is collected in both point sets when calling this function. */ -template -Point_set_3

& operator+=(Point_set_3

& ps, Point_set_3

& other) +template +Point_set_3& operator+=(Point_set_3& ps, + Point_set_3& other) { ps.join(other); return ps; @@ -1015,6 +1076,7 @@ Point_set_3

& operator+=(Point_set_3

& ps, Point_set_3

& other) + } // namespace CGAL diff --git a/Point_set_3/include/CGAL/Point_set_3/IO.h b/Point_set_3/include/CGAL/Point_set_3/IO.h index 013e587b5e7..7da0d341c41 100644 --- a/Point_set_3/include/CGAL/Point_set_3/IO.h +++ b/Point_set_3/include/CGAL/Point_set_3/IO.h @@ -161,14 +161,17 @@ write_ply_point_set( std::ostream& stream, ///< output stream. const Point_set_3& point_set) ///< point set { - if (point_set.has_normal_map()) - return CGAL::write_ply_points_and_normals - (stream, point_set.begin(), point_set.end(), - point_set.point_map(), point_set.normal_map()); + + stream << point_set; + return true; + // if (point_set.has_normal_map()) + // return CGAL::write_ply_points_and_normals + // (stream, point_set.begin(), point_set.end(), + // point_set.point_map(), point_set.normal_map()); - return CGAL::write_ply_points - (stream, point_set.begin(), point_set.end(), - point_set.point_map()); + // return CGAL::write_ply_points + // (stream, point_set.begin(), point_set.end(), + // point_set.point_map()); } } // namespace CGAL