From 09bb265b225331ce8d16b576451650db6bb97847 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mael=20Rouxel-Labb=C3=A9?= Date: Tue, 28 Jan 2020 10:13:40 +0100 Subject: [PATCH] Add the skeleton of texture reading in OFF's file scanner --- Stream_support/include/CGAL/IO/OFF.h | 14 +++---- .../include/CGAL/IO/OFF/File_header_OFF.h | 3 ++ .../CGAL/IO/OFF/File_header_OFF_impl.h | 39 +++++++++++++------ .../include/CGAL/IO/OFF/File_scanner_OFF.h | 13 +++++++ 4 files changed, 50 insertions(+), 19 deletions(-) diff --git a/Stream_support/include/CGAL/IO/OFF.h b/Stream_support/include/CGAL/IO/OFF.h index c845523f4b1..67fe17ffc34 100644 --- a/Stream_support/include/CGAL/IO/OFF.h +++ b/Stream_support/include/CGAL/IO/OFF.h @@ -83,13 +83,13 @@ bool read_OFF(std::istream& in, } // @fixme -// if(scanner.has_textures()) -// { -// double nx, ny, nw; -// scanner.scan_texture(nx, ny, nw); -// CGAL_assertion(nw != 0); -// *vt_out++ = Texture(nx, ny, nw); -// } + if(scanner.has_textures()) + { + double nx, ny, nw; + scanner.scan_texture(nx, ny, nw); + CGAL_assertion(nw != 0); + *vt_out++ = Texture(nx, ny, nw); + } scanner.skip_to_next_vertex(i); diff --git a/Stream_support/include/CGAL/IO/OFF/File_header_OFF.h b/Stream_support/include/CGAL/IO/OFF/File_header_OFF.h index e3a1f64ee37..ea19a765652 100644 --- a/Stream_support/include/CGAL/IO/OFF/File_header_OFF.h +++ b/Stream_support/include/CGAL/IO/OFF/File_header_OFF.h @@ -38,6 +38,7 @@ private: std::size_t m_offset; // index offset for vertices, usually 0. // Publicly accessible but not that well supported file informations. + bool m_textures; // STOFF detected. bool m_colors; // COFF detected. bool m_normals; // NOFF format stores also normals at vertices. @@ -78,6 +79,7 @@ public: bool comments() const { return ! m_no_comments; } std::size_t index_offset() const { return m_offset; } + bool has_textures() const { return m_textures; } // STOFF detected. bool has_colors() const { return m_colors; } // COFF detected. bool has_normals() const { return m_normals;} // NOFF format. bool is_homogeneous() const { return m_tag4; } // 4OFF detected. @@ -95,6 +97,7 @@ public: void set_no_comments(bool b) { m_no_comments = b; } void set_index_offset(std::size_t i) { m_offset = i; } + void set_textures(bool b) { m_textures = b; } void set_colors(bool b) { m_colors = b; } void set_normals(bool b) { m_normals = b;} void set_homogeneous(bool b) { m_tag4 = b; } diff --git a/Stream_support/include/CGAL/IO/OFF/File_header_OFF_impl.h b/Stream_support/include/CGAL/IO/OFF/File_header_OFF_impl.h index 83baddb4c99..0cdc25f08e6 100644 --- a/Stream_support/include/CGAL/IO/OFF/File_header_OFF_impl.h +++ b/Stream_support/include/CGAL/IO/OFF/File_header_OFF_impl.h @@ -21,14 +21,16 @@ #endif #include +#include +#include + +#include + +#include #include #include #include #include -#include -#include -#include -#include namespace CGAL { @@ -41,6 +43,7 @@ File_header_OFF::File_header_OFF( bool verbose) m_binary(false), m_no_comments(false), m_offset(0), + m_textures(false), m_colors(false), m_normals(false), m_tag4(false), @@ -57,6 +60,7 @@ File_header_OFF::File_header_OFF( m_binary(binary), m_no_comments(noc), m_offset(0), + m_textures(false), m_colors(false), m_normals(false), m_tag4(false), @@ -73,6 +77,7 @@ File_header_OFF::File_header_OFF( // m_binary(false), // m_no_comments(false), // m_offset(0), +// m_textures(false), // m_colors(false), // m_normals(false), // m_tag4(false), @@ -91,6 +96,7 @@ File_header_OFF::File_header_OFF( std::size_t v, std::size_t h, std::size_t f, m_binary(binary), m_no_comments(noc), m_offset(0), + m_textures(false), m_colors(false), m_normals(false), m_tag4(false), @@ -109,6 +115,7 @@ File_header_OFF::File_header_OFF( m_binary(false), m_no_comments(false), m_offset(0), + m_textures(false), m_colors(false), m_normals(false), m_tag4(false), @@ -126,6 +133,7 @@ File_header_OFF::File_header_OFF( m_binary(binary), m_no_comments(noc), m_offset(0), + m_textures(false), m_colors(false), m_normals(false), m_tag4(false), @@ -143,6 +151,7 @@ File_header_OFF::File_header_OFF( m_binary(false), m_no_comments(false), m_offset(0), + m_textures(false), m_colors(false), m_normals(false), m_tag4(false), @@ -163,6 +172,7 @@ File_header_OFF::File_header_OFF( m_binary(binary), m_no_comments(noc), m_offset(0), + m_textures(false), m_colors(false), m_normals(false), m_tag4(false), @@ -231,14 +241,15 @@ std::istream& operator>>( std::istream& in, File_header_OFF& h) { } if ( ! in) return in; - h.set_skel( false); - h.set_binary( false); - h.set_index_offset( 1); - h.set_colors( false); - h.set_normals( false); - h.set_homogeneous( false); - h.set_dimensional( false); - h.set_dimension( 3); + h.set_skel(false); + h.set_binary(false); + h.set_index_offset(1); + h.set_textures(false), + h.set_colors(false); + h.set_normals(false); + h.set_homogeneous(false); + h.set_dimensional(false); + h.set_dimension(3); const int max_keyword = 42; char keyword[max_keyword] = ""; @@ -253,6 +264,10 @@ std::istream& operator>>( std::istream& in, File_header_OFF& h) { } else { h.set_index_offset( 0); int j = 0; + if ( j+1 < i && keyword[j] == 'S' && keyword[j+1] == 'T') { + h.set_textures( true); + j += 2; + } if ( j < i && keyword[j] == 'C') { h.set_colors( true); j++; diff --git a/Stream_support/include/CGAL/IO/OFF/File_scanner_OFF.h b/Stream_support/include/CGAL/IO/OFF/File_scanner_OFF.h index 1f82122431e..abfe51bc295 100644 --- a/Stream_support/include/CGAL/IO/OFF/File_scanner_OFF.h +++ b/Stream_support/include/CGAL/IO/OFF/File_scanner_OFF.h @@ -245,6 +245,19 @@ public: } } + void scan_texture(float& x, float& y, float& w) + { + // @ todo + CGAL_assertion(false); + } + + void scan_texture(double& x, double& y, double& w) + { + // @ todo + CGAL_assertion(false); + } + + void scan_normal(float& x, float& y, float& z) { if(has_normals())