Add the skeleton of texture reading in OFF's file scanner

This commit is contained in:
Mael Rouxel-Labbé 2020-01-28 10:13:40 +01:00
parent adb8410266
commit 09bb265b22
4 changed files with 50 additions and 19 deletions

View File

@ -83,13 +83,13 @@ bool read_OFF(std::istream& in,
} }
// @fixme // @fixme
// if(scanner.has_textures()) if(scanner.has_textures())
// { {
// double nx, ny, nw; double nx, ny, nw;
// scanner.scan_texture(nx, ny, nw); scanner.scan_texture(nx, ny, nw);
// CGAL_assertion(nw != 0); CGAL_assertion(nw != 0);
// *vt_out++ = Texture(nx, ny, nw); *vt_out++ = Texture(nx, ny, nw);
// } }
scanner.skip_to_next_vertex(i); scanner.skip_to_next_vertex(i);

View File

@ -38,6 +38,7 @@ private:
std::size_t m_offset; // index offset for vertices, usually 0. std::size_t m_offset; // index offset for vertices, usually 0.
// Publicly accessible but not that well supported file informations. // Publicly accessible but not that well supported file informations.
bool m_textures; // STOFF detected.
bool m_colors; // COFF detected. bool m_colors; // COFF detected.
bool m_normals; // NOFF format stores also normals at vertices. bool m_normals; // NOFF format stores also normals at vertices.
@ -78,6 +79,7 @@ public:
bool comments() const { return ! m_no_comments; } bool comments() const { return ! m_no_comments; }
std::size_t index_offset() const { return m_offset; } 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_colors() const { return m_colors; } // COFF detected.
bool has_normals() const { return m_normals;} // NOFF format. bool has_normals() const { return m_normals;} // NOFF format.
bool is_homogeneous() const { return m_tag4; } // 4OFF detected. 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_no_comments(bool b) { m_no_comments = b; }
void set_index_offset(std::size_t i) { m_offset = i; } 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_colors(bool b) { m_colors = b; }
void set_normals(bool b) { m_normals = b;} void set_normals(bool b) { m_normals = b;}
void set_homogeneous(bool b) { m_tag4 = b; } void set_homogeneous(bool b) { m_tag4 = b; }

View File

@ -21,14 +21,16 @@
#endif #endif
#include <CGAL/basic.h> #include <CGAL/basic.h>
#include <CGAL/IO/binary_file_io.h>
#include <CGAL/IO/OFF/File_header_OFF.h>
#include <boost/cstdint.hpp>
#include <algorithm>
#include <cstdlib> #include <cstdlib>
#include <cctype> #include <cctype>
#include <cstring> #include <cstring>
#include <iostream> #include <iostream>
#include <CGAL/IO/binary_file_io.h>
#include <CGAL/IO/OFF/File_header_OFF.h>
#include <algorithm>
#include <boost/cstdint.hpp>
namespace CGAL { namespace CGAL {
@ -41,6 +43,7 @@ File_header_OFF::File_header_OFF( bool verbose)
m_binary(false), m_binary(false),
m_no_comments(false), m_no_comments(false),
m_offset(0), m_offset(0),
m_textures(false),
m_colors(false), m_colors(false),
m_normals(false), m_normals(false),
m_tag4(false), m_tag4(false),
@ -57,6 +60,7 @@ File_header_OFF::File_header_OFF(
m_binary(binary), m_binary(binary),
m_no_comments(noc), m_no_comments(noc),
m_offset(0), m_offset(0),
m_textures(false),
m_colors(false), m_colors(false),
m_normals(false), m_normals(false),
m_tag4(false), m_tag4(false),
@ -73,6 +77,7 @@ File_header_OFF::File_header_OFF(
// m_binary(false), // m_binary(false),
// m_no_comments(false), // m_no_comments(false),
// m_offset(0), // m_offset(0),
// m_textures(false),
// m_colors(false), // m_colors(false),
// m_normals(false), // m_normals(false),
// m_tag4(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_binary(binary),
m_no_comments(noc), m_no_comments(noc),
m_offset(0), m_offset(0),
m_textures(false),
m_colors(false), m_colors(false),
m_normals(false), m_normals(false),
m_tag4(false), m_tag4(false),
@ -109,6 +115,7 @@ File_header_OFF::File_header_OFF(
m_binary(false), m_binary(false),
m_no_comments(false), m_no_comments(false),
m_offset(0), m_offset(0),
m_textures(false),
m_colors(false), m_colors(false),
m_normals(false), m_normals(false),
m_tag4(false), m_tag4(false),
@ -126,6 +133,7 @@ File_header_OFF::File_header_OFF(
m_binary(binary), m_binary(binary),
m_no_comments(noc), m_no_comments(noc),
m_offset(0), m_offset(0),
m_textures(false),
m_colors(false), m_colors(false),
m_normals(false), m_normals(false),
m_tag4(false), m_tag4(false),
@ -143,6 +151,7 @@ File_header_OFF::File_header_OFF(
m_binary(false), m_binary(false),
m_no_comments(false), m_no_comments(false),
m_offset(0), m_offset(0),
m_textures(false),
m_colors(false), m_colors(false),
m_normals(false), m_normals(false),
m_tag4(false), m_tag4(false),
@ -163,6 +172,7 @@ File_header_OFF::File_header_OFF(
m_binary(binary), m_binary(binary),
m_no_comments(noc), m_no_comments(noc),
m_offset(0), m_offset(0),
m_textures(false),
m_colors(false), m_colors(false),
m_normals(false), m_normals(false),
m_tag4(false), m_tag4(false),
@ -231,14 +241,15 @@ std::istream& operator>>( std::istream& in, File_header_OFF& h) {
} }
if ( ! in) if ( ! in)
return in; return in;
h.set_skel( false); h.set_skel(false);
h.set_binary( false); h.set_binary(false);
h.set_index_offset( 1); h.set_index_offset(1);
h.set_colors( false); h.set_textures(false),
h.set_normals( false); h.set_colors(false);
h.set_homogeneous( false); h.set_normals(false);
h.set_dimensional( false); h.set_homogeneous(false);
h.set_dimension( 3); h.set_dimensional(false);
h.set_dimension(3);
const int max_keyword = 42; const int max_keyword = 42;
char keyword[max_keyword] = ""; char keyword[max_keyword] = "";
@ -253,6 +264,10 @@ std::istream& operator>>( std::istream& in, File_header_OFF& h) {
} else { } else {
h.set_index_offset( 0); h.set_index_offset( 0);
int j = 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') { if ( j < i && keyword[j] == 'C') {
h.set_colors( true); h.set_colors( true);
j++; j++;

View File

@ -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) void scan_normal(float& x, float& y, float& z)
{ {
if(has_normals()) if(has_normals())