From bad16c8ebfadf66ff591cd36a5e8fe545c3718eb Mon Sep 17 00:00:00 2001 From: Simon Giraudot Date: Mon, 11 Apr 2016 18:17:48 +0200 Subject: [PATCH] Add convenience function when reading double from float input --- .../include/CGAL/IO/read_ply_points.h | 49 +++++++++++++++++-- 1 file changed, 44 insertions(+), 5 deletions(-) diff --git a/Point_set_processing_3/include/CGAL/IO/read_ply_points.h b/Point_set_processing_3/include/CGAL/IO/read_ply_points.h index 1ccfeb903be..eb257415248 100644 --- a/Point_set_processing_3/include/CGAL/IO/read_ply_points.h +++ b/Point_set_processing_3/include/CGAL/IO/read_ply_points.h @@ -334,11 +334,7 @@ public: template bool does_tag_exist (const char* tag) { - for (std::size_t i = 0; i < m_readers.size (); ++ i) - if (m_readers[i]->name () == tag) - return dynamic_cast*>(m_readers[i]); - - return false; + return does_tag_exist (tag, Type()); } /*! @@ -358,6 +354,49 @@ public: return; } } + + /// \cond SKIP_IN_MANUAL + + // Convenience functions: a float property in the PLY input can be + // directly interpreted as a double without loss of information. + template + bool does_tag_exist (const char* tag, Type) + { + for (std::size_t i = 0; i < m_readers.size (); ++ i) + if (m_readers[i]->name () == tag) + return dynamic_cast*>(m_readers[i]); + return false; + } + bool does_tag_exist (const char* tag, double) + { + for (std::size_t i = 0; i < m_readers.size (); ++ i) + if (m_readers[i]->name () == tag) + return (dynamic_cast*>(m_readers[i]) + || dynamic_cast*>(m_readers[i])); + + return false; + } + void assign (double& t, const char* tag) + { + for (std::size_t i = 0; i < m_readers.size (); ++ i) + if (m_readers[i]->name () == tag) + { + internal::Ply_read_typed_number* + reader_double = dynamic_cast*>(m_readers[i]); + if (reader_double == NULL) + { + internal::Ply_read_typed_number* + reader_float = dynamic_cast*>(m_readers[i]); + assert (reader_float != NULL); + t = reader_float->buffer(); + } + else + t = reader_double->buffer(); + + return; + } + } + /// \endcond };