WIP: operator<< to recover all properties in PLY output

This commit is contained in:
Simon Giraudot 2016-09-27 15:38:30 +02:00
parent 17c3c777fe
commit a6b64c907b
2 changed files with 74 additions and 9 deletions

View File

@ -761,6 +761,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 <typename P>
friend std::ostream& operator<<(std::ostream& os, const Point_set_3<P>& 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<std::string> 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<boost::int8_t>(prop[i]).first)
os << "property char " << prop[i] << std::endl;
else if (ps.m_base.template get<boost::uint8_t>(prop[i]).first)
os << "property uchar " << prop[i] << std::endl;
else if (ps.m_base.template get<boost::int16_t>(prop[i]).first)
os << "property short " << prop[i] << std::endl;
else if (ps.m_base.template get<boost::uint16_t>(prop[i]).first)
os << "property ushort " << prop[i] << std::endl;
else if (ps.m_base.template get<boost::int32_t>(prop[i]).first)
os << "property int " << prop[i] << std::endl;
else if (ps.m_base.template get<boost::uint32_t>(prop[i]).first)
os << "property uint " << prop[i] << std::endl;
else if (ps.m_base.template get<float>(prop[i]).first)
os << "property float " << prop[i] << std::endl;
else if (ps.m_base.template get<double>(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 <typename P>
Point_set_3<P>& operator+=(Point_set_3<P>& ps, Point_set_3<P>& other)
template <typename Point, typename Vector>
Point_set_3<Point, Vector>& operator+=(Point_set_3<Point, Vector>& ps,
Point_set_3<Point, Vector>& other)
{
ps.join(other);
return ps;
@ -1015,6 +1076,7 @@ Point_set_3<P>& operator+=(Point_set_3<P>& ps, Point_set_3<P>& other)
} // namespace CGAL

View File

@ -161,14 +161,17 @@ write_ply_point_set(
std::ostream& stream, ///< output stream.
const Point_set_3<Point, Vector>& 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());
return CGAL::write_ply_points
(stream, point_set.begin(), point_set.end(),
point_set.point_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());
}
} // namespace CGAL