mirror of https://github.com/CGAL/cgal
Integrate File_scanner_OFF_impl into the header
This commit is contained in:
parent
b4862c2361
commit
1edf1e066c
|
|
@ -14,18 +14,20 @@
|
||||||
//
|
//
|
||||||
// Author(s) : Lutz Kettner <kettner@mpi-sb.mpg.de>
|
// Author(s) : Lutz Kettner <kettner@mpi-sb.mpg.de>
|
||||||
|
|
||||||
|
|
||||||
#ifndef CGAL_IO_OFF_FILE_HEADER_OFF_H
|
#ifndef CGAL_IO_OFF_FILE_HEADER_OFF_H
|
||||||
#define CGAL_IO_OFF_FILE_HEADER_OFF_H 1
|
#define CGAL_IO_OFF_FILE_HEADER_OFF_H
|
||||||
|
|
||||||
#include <CGAL/IO/OFF/File_header_extended_OFF.h>
|
#include <CGAL/IO/OFF/File_header_extended_OFF.h>
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
namespace CGAL {
|
namespace CGAL {
|
||||||
|
|
||||||
// Info structure for OFF file headers
|
// Info structure for OFF file headers
|
||||||
// ===================================
|
// ===================================
|
||||||
class CGAL_EXPORT File_header_OFF : public File_header_extended_OFF {
|
class CGAL_EXPORT File_header_OFF
|
||||||
|
: public File_header_extended_OFF
|
||||||
|
{
|
||||||
private:
|
private:
|
||||||
// Publicly accessible file informations.
|
// Publicly accessible file informations.
|
||||||
std::size_t n_vertices;
|
std::size_t n_vertices;
|
||||||
|
|
@ -43,29 +45,28 @@ private:
|
||||||
bool m_tag4; // 4OFF detected.
|
bool m_tag4; // 4OFF detected.
|
||||||
bool m_tagDim; // nOFF detected (will not be supported).
|
bool m_tagDim; // nOFF detected (will not be supported).
|
||||||
int m_dim; // dimension for nOFF (will not be supported).
|
int m_dim; // dimension for nOFF (will not be supported).
|
||||||
|
|
||||||
public:
|
public:
|
||||||
typedef File_header_OFF Self;
|
typedef File_header_OFF Self;
|
||||||
typedef File_header_extended_OFF Base;
|
typedef File_header_extended_OFF Base;
|
||||||
|
|
||||||
explicit File_header_OFF( bool verbose = false);
|
explicit File_header_OFF(bool verbose = false);
|
||||||
File_header_OFF( bool binary, bool noc, bool skel,
|
File_header_OFF(bool binary, bool noc, bool skel, bool verbose = false);
|
||||||
bool verbose = false);
|
//File_header_OFF(int v, int h, int f, bool verbose = false);
|
||||||
//File_header_OFF( int v, int h, int f, bool verbose = false);
|
File_header_OFF(std::size_t v, std::size_t h, std::size_t f,
|
||||||
File_header_OFF( std::size_t v, std::size_t h, std::size_t f,
|
bool binary, bool noc, bool skel, bool verbose = false);
|
||||||
bool binary, bool noc, bool skel,
|
|
||||||
bool verbose = false);
|
File_header_OFF(const File_header_extended_OFF& ext_header);
|
||||||
File_header_OFF( const File_header_extended_OFF& ext_header);
|
File_header_OFF(const File_header_extended_OFF& ext_header,
|
||||||
File_header_OFF( const File_header_extended_OFF& ext_header,
|
|
||||||
bool binary, bool noc, bool skel);
|
bool binary, bool noc, bool skel);
|
||||||
File_header_OFF( std::size_t v, std::size_t h, std::size_t f,
|
File_header_OFF(std::size_t v, std::size_t h, std::size_t f,
|
||||||
const File_header_extended_OFF& ext_header);
|
const File_header_extended_OFF& ext_header);
|
||||||
File_header_OFF( std::size_t v, std::size_t h, std::size_t f,
|
File_header_OFF(std::size_t v, std::size_t h, std::size_t f,
|
||||||
const File_header_extended_OFF& ext_header,
|
const File_header_extended_OFF& ext_header,
|
||||||
bool binary, bool noc, bool skel);
|
bool binary, bool noc, bool skel);
|
||||||
|
|
||||||
Self& operator= ( const Base& base) { (Base&)(*this) = base;
|
Self& operator= (const Base& base) { (Base&)(*this) = base; return *this; }
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
std::size_t size_of_vertices() const { return n_vertices; }
|
std::size_t size_of_vertices() const { return n_vertices; }
|
||||||
std::size_t size_of_facets() const { return n_facets; }
|
std::size_t size_of_facets() const { return n_facets; }
|
||||||
|
|
||||||
|
|
@ -80,32 +81,33 @@ public:
|
||||||
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.
|
||||||
|
|
||||||
// nOFF detected. (will not be supported).
|
// nOFF detected. (will not be supported).
|
||||||
bool n_dimensional() const { return m_tagDim; }
|
bool n_dimensional() const { return m_tagDim; }
|
||||||
// dimension for nOFF (will not be supported).
|
// dimension for nOFF (will not be supported).
|
||||||
int dimension() const { return m_dim; }
|
int dimension() const { return m_dim; }
|
||||||
|
|
||||||
void set_vertices( std::size_t n) { n_vertices = n; }
|
void set_vertices(std::size_t n) { n_vertices = n; }
|
||||||
void set_facets( std::size_t n) { n_facets = n; }
|
void set_facets(std::size_t n) { n_facets = n; }
|
||||||
|
|
||||||
void set_skel( bool b) { m_skel = b; }
|
void set_skel(bool b) { m_skel = b; }
|
||||||
void set_binary( bool b) { m_binary = b; }
|
void set_binary(bool b) { m_binary = b; }
|
||||||
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_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; }
|
||||||
void set_dimensional( bool b) { m_tagDim = b; }
|
void set_dimensional(bool b) { m_tagDim = b; }
|
||||||
void set_dimension( int i) { m_dim = i; }
|
void set_dimension(int i) { m_dim = i; }
|
||||||
Self& operator+=( const Self& header);
|
Self& operator+=(const Self& header);
|
||||||
};
|
};
|
||||||
|
|
||||||
// Write header.
|
// Write header.
|
||||||
CGAL_EXPORT std::ostream& operator<<( std::ostream& out, const File_header_OFF& h);
|
CGAL_EXPORT std::ostream& operator<<(std::ostream& out, const File_header_OFF& h);
|
||||||
|
|
||||||
// Scan header. Marks streams badbit if not in SKEL format nor in OFF.
|
// Scan header. Marks streams badbit if not in SKEL format nor in OFF.
|
||||||
CGAL_EXPORT std::istream& operator>>( std::istream& in, File_header_OFF& h);
|
CGAL_EXPORT std::istream& operator>>(std::istream& in, File_header_OFF& h);
|
||||||
|
|
||||||
} //namespace CGAL
|
} //namespace CGAL
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -15,55 +15,65 @@
|
||||||
// Author(s) : Lutz Kettner <kettner@mpi-sb.mpg.de>
|
// Author(s) : Lutz Kettner <kettner@mpi-sb.mpg.de>
|
||||||
|
|
||||||
#ifndef CGAL_IO_OFF_FILE_SCANNER_OFF_H
|
#ifndef CGAL_IO_OFF_FILE_SCANNER_OFF_H
|
||||||
#define CGAL_IO_OFF_FILE_SCANNER_OFF_H 1
|
#define CGAL_IO_OFF_FILE_SCANNER_OFF_H
|
||||||
|
|
||||||
#include <CGAL/disable_warnings.h>
|
|
||||||
|
|
||||||
#include <CGAL/config.h>
|
#include <CGAL/config.h>
|
||||||
#include <cstddef>
|
|
||||||
#include <CGAL/IO/binary_file_io.h>
|
#include <CGAL/IO/binary_file_io.h>
|
||||||
#include <CGAL/IO/OFF/File_header_OFF.h>
|
#include <CGAL/IO/OFF/File_header_OFF.h>
|
||||||
#include <iostream>
|
|
||||||
#include <sstream>
|
|
||||||
#include <boost/cstdint.hpp>
|
#include <boost/cstdint.hpp>
|
||||||
|
|
||||||
#include <CGAL/Point_3.h>
|
#include <cstddef>
|
||||||
#include <CGAL/Vector_3.h>
|
#include <iostream>
|
||||||
|
#include <sstream>
|
||||||
|
|
||||||
namespace CGAL {
|
namespace CGAL {
|
||||||
|
|
||||||
class CGAL_EXPORT File_scanner_OFF : public File_header_OFF {
|
class File_scanner_OFF
|
||||||
|
: public File_header_OFF
|
||||||
|
{
|
||||||
std::istream& m_in;
|
std::istream& m_in;
|
||||||
bool normals_read;
|
bool normals_read;
|
||||||
|
|
||||||
void skip_comment() { m_in >> skip_comment_OFF; }
|
void skip_comment() { m_in >> skip_comment_OFF; }
|
||||||
|
|
||||||
public:
|
public:
|
||||||
File_scanner_OFF( std::istream& in, bool verbose = false)
|
File_scanner_OFF(std::istream& in, bool verbose = false)
|
||||||
: File_header_OFF(verbose), m_in(in), normals_read(false) {
|
: File_header_OFF(verbose), m_in(in), normals_read(false)
|
||||||
in >> static_cast<File_header_OFF&>( *this);
|
{
|
||||||
|
in >> static_cast<File_header_OFF&>(*this);
|
||||||
}
|
}
|
||||||
File_scanner_OFF( std::istream& in, const File_header_OFF& header)
|
|
||||||
: File_header_OFF(header), m_in(in), normals_read(false) {}
|
File_scanner_OFF(std::istream& in, const File_header_OFF& header)
|
||||||
|
:
|
||||||
|
File_header_OFF(header), m_in(in), normals_read(false)
|
||||||
|
{ }
|
||||||
|
|
||||||
std::istream& in() { return m_in; }
|
std::istream& in() { return m_in; }
|
||||||
|
|
||||||
// The scan_vertex() routine is provided for multiple
|
// The scan_vertex() routine is provided for multiple
|
||||||
// coordinate types to support parameterized polytopes.
|
// coordinate types to support parameterized polytopes.
|
||||||
void scan_vertex( float& x, float& y, float& z) {
|
void scan_vertex(float& x, float& y, float& z)
|
||||||
if ( binary()) {
|
{
|
||||||
I_Binary_read_big_endian_float32( m_in, x);
|
if(binary())
|
||||||
I_Binary_read_big_endian_float32( m_in, y);
|
{
|
||||||
I_Binary_read_big_endian_float32( m_in, z);
|
I_Binary_read_big_endian_float32(m_in, x);
|
||||||
if ( is_homogeneous()) {
|
I_Binary_read_big_endian_float32(m_in, y);
|
||||||
|
I_Binary_read_big_endian_float32(m_in, z);
|
||||||
|
if(is_homogeneous()) {
|
||||||
float w;
|
float w;
|
||||||
I_Binary_read_big_endian_float32( m_in, w);
|
I_Binary_read_big_endian_float32(m_in, w);
|
||||||
x /= w;
|
x /= w;
|
||||||
y /= w;
|
y /= w;
|
||||||
z /= w;
|
z /= w;
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
skip_comment();
|
skip_comment();
|
||||||
m_in >> iformat(x) >> iformat(y) >> iformat(z);
|
m_in >> iformat(x) >> iformat(y) >> iformat(z);
|
||||||
if ( is_homogeneous()) {
|
if(is_homogeneous())
|
||||||
|
{
|
||||||
float w;
|
float w;
|
||||||
m_in >> iformat(w);
|
m_in >> iformat(w);
|
||||||
x /= w;
|
x /= w;
|
||||||
|
|
@ -72,25 +82,32 @@ public:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void scan_vertex( double& x, double& y, double& z) {
|
|
||||||
if ( binary()) {
|
void scan_vertex(double& x, double& y, double& z)
|
||||||
|
{
|
||||||
|
if(binary())
|
||||||
|
{
|
||||||
float f;
|
float f;
|
||||||
I_Binary_read_big_endian_float32( m_in, f);
|
I_Binary_read_big_endian_float32(m_in, f);
|
||||||
x = f;
|
x = f;
|
||||||
I_Binary_read_big_endian_float32( m_in, f);
|
I_Binary_read_big_endian_float32(m_in, f);
|
||||||
y = f;
|
y = f;
|
||||||
I_Binary_read_big_endian_float32( m_in, f);
|
I_Binary_read_big_endian_float32(m_in, f);
|
||||||
z = f;
|
z = f;
|
||||||
if ( is_homogeneous()) {
|
if(is_homogeneous())
|
||||||
I_Binary_read_big_endian_float32( m_in, f);
|
{
|
||||||
|
I_Binary_read_big_endian_float32(m_in, f);
|
||||||
x /= f;
|
x /= f;
|
||||||
y /= f;
|
y /= f;
|
||||||
z /= f;
|
z /= f;
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
skip_comment();
|
skip_comment();
|
||||||
m_in >> iformat(x) >> iformat(y) >> iformat(z);
|
m_in >> iformat(x) >> iformat(y) >> iformat(z);
|
||||||
if ( is_homogeneous()) {
|
if(is_homogeneous())
|
||||||
|
{
|
||||||
double w;
|
double w;
|
||||||
m_in >> iformat(w);
|
m_in >> iformat(w);
|
||||||
x /= w;
|
x /= w;
|
||||||
|
|
@ -99,32 +116,40 @@ public:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void scan_vertex( int& x, int& y, int& z) {
|
|
||||||
if ( binary()) {
|
void scan_vertex(int& x, int& y, int& z)
|
||||||
|
{
|
||||||
|
if(binary())
|
||||||
|
{
|
||||||
float fx, fy, fz;
|
float fx, fy, fz;
|
||||||
I_Binary_read_big_endian_float32( m_in, fx);
|
I_Binary_read_big_endian_float32(m_in, fx);
|
||||||
I_Binary_read_big_endian_float32( m_in, fy);
|
I_Binary_read_big_endian_float32(m_in, fy);
|
||||||
I_Binary_read_big_endian_float32( m_in, fz);
|
I_Binary_read_big_endian_float32(m_in, fz);
|
||||||
if ( is_homogeneous()) {
|
if(is_homogeneous()) {
|
||||||
float fw;
|
float fw;
|
||||||
I_Binary_read_big_endian_float32( m_in, fw);
|
I_Binary_read_big_endian_float32(m_in, fw);
|
||||||
x = int( fx / fw);
|
x = int(fx / fw);
|
||||||
y = int( fy / fw);
|
y = int(fy / fw);
|
||||||
z = int( fz / fw);
|
z = int(fz / fw);
|
||||||
} else {
|
} else {
|
||||||
x = int(fx);
|
x = int(fx);
|
||||||
y = int(fy);
|
y = int(fy);
|
||||||
z = int(fz);
|
z = int(fz);
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
skip_comment();
|
skip_comment();
|
||||||
if ( is_homogeneous()) {
|
if(is_homogeneous())
|
||||||
|
{
|
||||||
double fx, fy, fz, fw;
|
double fx, fy, fz, fw;
|
||||||
m_in >> iformat(fx) >> iformat(fy) >> iformat(fz) >> iformat(fw);
|
m_in >> iformat(fx) >> iformat(fy) >> iformat(fz) >> iformat(fw);
|
||||||
x = int( fx / fw);
|
x = int(fx / fw);
|
||||||
y = int( fy / fw);
|
y = int(fy / fw);
|
||||||
z = int( fz / fw);
|
z = int(fz / fw);
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
double d;
|
double d;
|
||||||
m_in >> iformat(d);
|
m_in >> iformat(d);
|
||||||
x = int(d);
|
x = int(d);
|
||||||
|
|
@ -136,59 +161,74 @@ public:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void scan_vertex( float& x, float& y, float& z, float& w) {
|
void scan_vertex(float& x, float& y, float& z, float& w)
|
||||||
|
{
|
||||||
w = 1;
|
w = 1;
|
||||||
if ( binary()) {
|
if(binary())
|
||||||
I_Binary_read_big_endian_float32( m_in, x);
|
{
|
||||||
I_Binary_read_big_endian_float32( m_in, y);
|
I_Binary_read_big_endian_float32(m_in, x);
|
||||||
I_Binary_read_big_endian_float32( m_in, z);
|
I_Binary_read_big_endian_float32(m_in, y);
|
||||||
if ( is_homogeneous())
|
I_Binary_read_big_endian_float32(m_in, z);
|
||||||
I_Binary_read_big_endian_float32( m_in, w);
|
if(is_homogeneous())
|
||||||
} else {
|
I_Binary_read_big_endian_float32(m_in, w);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
skip_comment();
|
skip_comment();
|
||||||
m_in >> iformat(x) >> iformat(y) >> iformat(z);
|
m_in >> iformat(x) >> iformat(y) >> iformat(z);
|
||||||
if ( is_homogeneous())
|
if(is_homogeneous())
|
||||||
m_in >> iformat(w);
|
m_in >> iformat(w);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void scan_vertex( double& x, double& y, double& z, double& w) {
|
void scan_vertex(double& x, double& y, double& z, double& w)
|
||||||
|
{
|
||||||
w = 1;
|
w = 1;
|
||||||
if ( binary()) {
|
if(binary())
|
||||||
|
{
|
||||||
float f;
|
float f;
|
||||||
I_Binary_read_big_endian_float32( m_in, f);
|
I_Binary_read_big_endian_float32(m_in, f);
|
||||||
x = f;
|
x = f;
|
||||||
I_Binary_read_big_endian_float32( m_in, f);
|
I_Binary_read_big_endian_float32(m_in, f);
|
||||||
y = f;
|
y = f;
|
||||||
I_Binary_read_big_endian_float32( m_in, f);
|
I_Binary_read_big_endian_float32(m_in, f);
|
||||||
z = f;
|
z = f;
|
||||||
if ( is_homogeneous()) {
|
if(is_homogeneous())
|
||||||
I_Binary_read_big_endian_float32( m_in, f);
|
{
|
||||||
|
I_Binary_read_big_endian_float32(m_in, f);
|
||||||
w = f;
|
w = f;
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
skip_comment();
|
skip_comment();
|
||||||
m_in >> iformat(x);
|
m_in >> iformat(x);
|
||||||
m_in >> iformat(y);
|
m_in >> iformat(y);
|
||||||
m_in >> iformat(z);
|
m_in >> iformat(z);
|
||||||
if ( is_homogeneous())
|
if(is_homogeneous())
|
||||||
m_in >> iformat(w);
|
m_in >> iformat(w);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void scan_vertex( int& x, int& y, int& z, int& w) {
|
|
||||||
|
void scan_vertex(int& x, int& y, int& z, int& w)
|
||||||
|
{
|
||||||
w = 1;
|
w = 1;
|
||||||
if ( binary()) {
|
if(binary())
|
||||||
|
{
|
||||||
float f;
|
float f;
|
||||||
I_Binary_read_big_endian_float32( m_in, f);
|
I_Binary_read_big_endian_float32(m_in, f);
|
||||||
x = int(f);
|
x = int(f);
|
||||||
I_Binary_read_big_endian_float32( m_in, f);
|
I_Binary_read_big_endian_float32(m_in, f);
|
||||||
y = int(f);
|
y = int(f);
|
||||||
I_Binary_read_big_endian_float32( m_in, f);
|
I_Binary_read_big_endian_float32(m_in, f);
|
||||||
z = int(f);
|
z = int(f);
|
||||||
if ( is_homogeneous()) {
|
if(is_homogeneous())
|
||||||
I_Binary_read_big_endian_float32( m_in, f);
|
{
|
||||||
|
I_Binary_read_big_endian_float32(m_in, f);
|
||||||
w = int(f);
|
w = int(f);
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
skip_comment();
|
skip_comment();
|
||||||
double d;
|
double d;
|
||||||
m_in >> iformat(d);
|
m_in >> iformat(d);
|
||||||
|
|
@ -197,30 +237,37 @@ public:
|
||||||
y = int(d);
|
y = int(d);
|
||||||
m_in >> iformat(d);
|
m_in >> iformat(d);
|
||||||
z = int(d);
|
z = int(d);
|
||||||
if ( is_homogeneous()) {
|
if(is_homogeneous())
|
||||||
|
{
|
||||||
m_in >> iformat(d);
|
m_in >> iformat(d);
|
||||||
w = int(d);
|
w = int(d);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void scan_normal( float& x, float& y, float& z) {
|
void scan_normal(float& x, float& y, float& z)
|
||||||
if ( has_normals()) {
|
{
|
||||||
|
if(has_normals())
|
||||||
|
{
|
||||||
normals_read = true;
|
normals_read = true;
|
||||||
if ( binary()) {
|
if(binary()) {
|
||||||
I_Binary_read_big_endian_float32( m_in, x);
|
I_Binary_read_big_endian_float32(m_in, x);
|
||||||
I_Binary_read_big_endian_float32( m_in, y);
|
I_Binary_read_big_endian_float32(m_in, y);
|
||||||
I_Binary_read_big_endian_float32( m_in, z);
|
I_Binary_read_big_endian_float32(m_in, z);
|
||||||
if ( is_homogeneous()) {
|
if(is_homogeneous())
|
||||||
|
{
|
||||||
float w;
|
float w;
|
||||||
I_Binary_read_big_endian_float32( m_in, w);
|
I_Binary_read_big_endian_float32(m_in, w);
|
||||||
x /= w;
|
x /= w;
|
||||||
y /= w;
|
y /= w;
|
||||||
z /= w;
|
z /= w;
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
m_in >> iformat(x) >> iformat(y) >> iformat(z);
|
m_in >> iformat(x) >> iformat(y) >> iformat(z);
|
||||||
if ( is_homogeneous()) {
|
if(is_homogeneous())
|
||||||
|
{
|
||||||
float w;
|
float w;
|
||||||
m_in >> iformat(w);
|
m_in >> iformat(w);
|
||||||
x /= w;
|
x /= w;
|
||||||
|
|
@ -230,64 +277,85 @@ public:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void scan_normal( double& x, double& y, double& z) {
|
|
||||||
if ( has_normals()) {
|
void scan_normal(double& x, double& y, double& z)
|
||||||
|
{
|
||||||
|
if(has_normals())
|
||||||
|
{
|
||||||
normals_read = true;
|
normals_read = true;
|
||||||
if ( binary()) {
|
if(binary())
|
||||||
|
{
|
||||||
float fx, fy, fz;
|
float fx, fy, fz;
|
||||||
I_Binary_read_big_endian_float32( m_in, fx);
|
I_Binary_read_big_endian_float32(m_in, fx);
|
||||||
I_Binary_read_big_endian_float32( m_in, fy);
|
I_Binary_read_big_endian_float32(m_in, fy);
|
||||||
I_Binary_read_big_endian_float32( m_in, fz);
|
I_Binary_read_big_endian_float32(m_in, fz);
|
||||||
if ( is_homogeneous()) {
|
if(is_homogeneous())
|
||||||
|
{
|
||||||
float fw;
|
float fw;
|
||||||
I_Binary_read_big_endian_float32( m_in, fw);
|
I_Binary_read_big_endian_float32(m_in, fw);
|
||||||
x = fx / fw;
|
x = fx / fw;
|
||||||
y = fy / fw;
|
y = fy / fw;
|
||||||
z = fz / fw;
|
z = fz / fw;
|
||||||
} else {
|
} else
|
||||||
|
{
|
||||||
x = fx;
|
x = fx;
|
||||||
y = fy;
|
y = fy;
|
||||||
z = fz;
|
z = fz;
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
if ( is_homogeneous()) {
|
else
|
||||||
|
{
|
||||||
|
if(is_homogeneous())
|
||||||
|
{
|
||||||
float fx, fy, fz, fw;
|
float fx, fy, fz, fw;
|
||||||
m_in >> iformat(fx) >> iformat(fy) >> iformat(fz) >> iformat(fw);
|
m_in >> iformat(fx) >> iformat(fy) >> iformat(fz) >> iformat(fw);
|
||||||
x = fx / fw;
|
x = fx / fw;
|
||||||
y = fy / fw;
|
y = fy / fw;
|
||||||
z = fz / fw;
|
z = fz / fw;
|
||||||
} else
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
m_in >> iformat(x) >> iformat(y) >> iformat(z);
|
m_in >> iformat(x) >> iformat(y) >> iformat(z);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void scan_normal( int& x, int& y, int& z) {
|
}
|
||||||
if ( has_normals()) {
|
|
||||||
|
void scan_normal(int& x, int& y, int& z)
|
||||||
|
{
|
||||||
|
if(has_normals())
|
||||||
|
{
|
||||||
normals_read = true;
|
normals_read = true;
|
||||||
if ( binary()) {
|
if(binary())
|
||||||
|
{
|
||||||
float fx, fy, fz;
|
float fx, fy, fz;
|
||||||
I_Binary_read_big_endian_float32( m_in, fx);
|
I_Binary_read_big_endian_float32(m_in, fx);
|
||||||
I_Binary_read_big_endian_float32( m_in, fy);
|
I_Binary_read_big_endian_float32(m_in, fy);
|
||||||
I_Binary_read_big_endian_float32( m_in, fz);
|
I_Binary_read_big_endian_float32(m_in, fz);
|
||||||
if ( is_homogeneous()) {
|
if(is_homogeneous()) {
|
||||||
float fw;
|
float fw;
|
||||||
I_Binary_read_big_endian_float32( m_in, fw);
|
I_Binary_read_big_endian_float32(m_in, fw);
|
||||||
x = int( fx / fw);
|
x = int(fx / fw);
|
||||||
y = int( fy / fw);
|
y = int(fy / fw);
|
||||||
z = int( fz / fw);
|
z = int(fz / fw);
|
||||||
} else {
|
} else {
|
||||||
x = int(fx);
|
x = int(fx);
|
||||||
y = int(fy);
|
y = int(fy);
|
||||||
z = int(fz);
|
z = int(fz);
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
if ( is_homogeneous()) {
|
else
|
||||||
|
{
|
||||||
|
if(is_homogeneous())
|
||||||
|
{
|
||||||
float fx, fy, fz, fw;
|
float fx, fy, fz, fw;
|
||||||
m_in >> iformat(fx) >> iformat(fy) >> iformat(fz) >> iformat(fw);
|
m_in >> iformat(fx) >> iformat(fy) >> iformat(fz) >> iformat(fw);
|
||||||
x = int( fx / fw);
|
x = int(fx / fw);
|
||||||
y = int( fy / fw);
|
y = int(fy / fw);
|
||||||
z = int( fz / fw);
|
z = int(fz / fw);
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
double d;
|
double d;
|
||||||
m_in >> iformat(d);
|
m_in >> iformat(d);
|
||||||
x = int(d);
|
x = int(d);
|
||||||
|
|
@ -300,63 +368,81 @@ public:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void scan_normal( float& x, float& y, float& z, float& w) {
|
void scan_normal(float& x, float& y, float& z, float& w)
|
||||||
|
{
|
||||||
w = 1;
|
w = 1;
|
||||||
if ( has_normals()) {
|
if(has_normals())
|
||||||
|
{
|
||||||
normals_read = true;
|
normals_read = true;
|
||||||
if ( binary()) {
|
if(binary())
|
||||||
I_Binary_read_big_endian_float32( m_in, x);
|
{
|
||||||
I_Binary_read_big_endian_float32( m_in, y);
|
I_Binary_read_big_endian_float32(m_in, x);
|
||||||
I_Binary_read_big_endian_float32( m_in, z);
|
I_Binary_read_big_endian_float32(m_in, y);
|
||||||
if ( is_homogeneous())
|
I_Binary_read_big_endian_float32(m_in, z);
|
||||||
I_Binary_read_big_endian_float32( m_in, w);
|
if(is_homogeneous())
|
||||||
} else {
|
I_Binary_read_big_endian_float32(m_in, w);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
m_in >> iformat(x) >> iformat(y) >> iformat(z);
|
m_in >> iformat(x) >> iformat(y) >> iformat(z);
|
||||||
if ( is_homogeneous())
|
if(is_homogeneous())
|
||||||
m_in >> iformat(w);
|
m_in >> iformat(w);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void scan_normal( double& x, double& y, double& z, double& w) {
|
|
||||||
|
void scan_normal(double& x, double& y, double& z, double& w)
|
||||||
|
{
|
||||||
w = 1;
|
w = 1;
|
||||||
if ( has_normals()) {
|
if(has_normals())
|
||||||
|
{
|
||||||
normals_read = true;
|
normals_read = true;
|
||||||
if ( binary()) {
|
if(binary())
|
||||||
|
{
|
||||||
float f;
|
float f;
|
||||||
I_Binary_read_big_endian_float32( m_in, f);
|
I_Binary_read_big_endian_float32(m_in, f);
|
||||||
x = f;
|
x = f;
|
||||||
I_Binary_read_big_endian_float32( m_in, f);
|
I_Binary_read_big_endian_float32(m_in, f);
|
||||||
y = f;
|
y = f;
|
||||||
I_Binary_read_big_endian_float32( m_in, f);
|
I_Binary_read_big_endian_float32(m_in, f);
|
||||||
z = f;
|
z = f;
|
||||||
if ( is_homogeneous()) {
|
if(is_homogeneous())
|
||||||
I_Binary_read_big_endian_float32( m_in, f);
|
{
|
||||||
|
I_Binary_read_big_endian_float32(m_in, f);
|
||||||
w = f;
|
w = f;
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
m_in >> iformat(x) >> iformat(y) >> iformat(z);
|
m_in >> iformat(x) >> iformat(y) >> iformat(z);
|
||||||
if ( is_homogeneous())
|
if(is_homogeneous())
|
||||||
m_in >> iformat(w);
|
m_in >> iformat(w);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void scan_normal( int& x, int& y, int& z, int& w) {
|
|
||||||
|
void scan_normal(int& x, int& y, int& z, int& w)
|
||||||
|
{
|
||||||
w = 1;
|
w = 1;
|
||||||
if ( has_normals()) {
|
if(has_normals())
|
||||||
|
{
|
||||||
normals_read = true;
|
normals_read = true;
|
||||||
if ( binary()) {
|
if(binary())
|
||||||
|
{
|
||||||
float f;
|
float f;
|
||||||
I_Binary_read_big_endian_float32( m_in, f);
|
I_Binary_read_big_endian_float32(m_in, f);
|
||||||
x = int(f);
|
x = int(f);
|
||||||
I_Binary_read_big_endian_float32( m_in, f);
|
I_Binary_read_big_endian_float32(m_in, f);
|
||||||
y = int(f);
|
y = int(f);
|
||||||
I_Binary_read_big_endian_float32( m_in, f);
|
I_Binary_read_big_endian_float32(m_in, f);
|
||||||
z = int(f);
|
z = int(f);
|
||||||
if ( is_homogeneous()) {
|
if(is_homogeneous()) {
|
||||||
I_Binary_read_big_endian_float32( m_in, f);
|
I_Binary_read_big_endian_float32(m_in, f);
|
||||||
w = int(f);
|
w = int(f);
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
double d;
|
double d;
|
||||||
m_in >> iformat(d);
|
m_in >> iformat(d);
|
||||||
x = int(d);
|
x = int(d);
|
||||||
|
|
@ -364,7 +450,8 @@ public:
|
||||||
y = int(d);
|
y = int(d);
|
||||||
m_in >> iformat(d);
|
m_in >> iformat(d);
|
||||||
z = int(d);
|
z = int(d);
|
||||||
if ( is_homogeneous()) {
|
if(is_homogeneous())
|
||||||
|
{
|
||||||
m_in >> iformat(d);
|
m_in >> iformat(d);
|
||||||
w = int(d);
|
w = int(d);
|
||||||
}
|
}
|
||||||
|
|
@ -530,7 +617,6 @@ public:
|
||||||
|
|
||||||
static CGAL::Color get_color_from_line(std::istream &is)
|
static CGAL::Color get_color_from_line(std::istream &is)
|
||||||
{
|
{
|
||||||
|
|
||||||
std::string color_info;
|
std::string color_info;
|
||||||
bool is_float = false;
|
bool is_float = false;
|
||||||
|
|
||||||
|
|
@ -548,7 +634,7 @@ public:
|
||||||
if(color_info.at(0) == '#')
|
if(color_info.at(0) == '#')
|
||||||
break;
|
break;
|
||||||
//detect if the value is float
|
//detect if the value is float
|
||||||
for(int c = 0; c<static_cast<int>(color_info.length()); c++)
|
for(int c = 0; c<static_cast<int>(color_info.length()); ++c)
|
||||||
{
|
{
|
||||||
if(color_info.at(c) == '.')
|
if(color_info.at(c) == '.')
|
||||||
{
|
{
|
||||||
|
|
@ -556,37 +642,45 @@ public:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//if the value is of float type, convert it into an int
|
//if the value is of float type, convert it into an int
|
||||||
if(is_float)
|
if(is_float)
|
||||||
rgb[index] = static_cast<unsigned char>(atof(color_info.c_str())*255);
|
rgb[index] = static_cast<unsigned char>(atof(color_info.c_str())*255);
|
||||||
//else stores the value
|
//else stores the value
|
||||||
else
|
else
|
||||||
rgb[index] = static_cast<unsigned char>(atoi(color_info.c_str()));
|
rgb[index] = static_cast<unsigned char>(atoi(color_info.c_str()));
|
||||||
index++;
|
|
||||||
|
++index;
|
||||||
if(index == 3)
|
if(index == 3)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
CGAL::Color color;
|
CGAL::Color color;
|
||||||
//if there were only one number, fetch the color in the color map
|
//if there were only one number, fetch the color in the color map
|
||||||
if(index<2)
|
if(index < 2)
|
||||||
color = get_indexed_color(rgb[0]);
|
color = get_indexed_color(rgb[0]);
|
||||||
//else create the coor with the 3 values;
|
//else create the coor with the 3 values;
|
||||||
else
|
else
|
||||||
color = CGAL::Color(rgb[0], rgb[1], rgb[2]);
|
color = CGAL::Color(rgb[0], rgb[1], rgb[2]);
|
||||||
|
|
||||||
return color;
|
return color;
|
||||||
}
|
}
|
||||||
|
|
||||||
void scan_color( unsigned char& r, unsigned char& g, unsigned char& b) {
|
void scan_color(unsigned char& r, unsigned char& g, unsigned char& b)
|
||||||
if ( binary()) {
|
{
|
||||||
|
if(binary())
|
||||||
|
{
|
||||||
float fr, fg, fb;
|
float fr, fg, fb;
|
||||||
I_Binary_read_big_endian_float32( m_in, fr);
|
I_Binary_read_big_endian_float32(m_in, fr);
|
||||||
I_Binary_read_big_endian_float32( m_in, fg);
|
I_Binary_read_big_endian_float32(m_in, fg);
|
||||||
I_Binary_read_big_endian_float32( m_in, fb);
|
I_Binary_read_big_endian_float32(m_in, fb);
|
||||||
r = (unsigned char)(fr);
|
r = (unsigned char)(fr);
|
||||||
g = (unsigned char)(fg);
|
g = (unsigned char)(fg);
|
||||||
b = (unsigned char)(fb);
|
b = (unsigned char)(fb);
|
||||||
|
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
CGAL::Color color = get_color_from_line(m_in);
|
CGAL::Color color = get_color_from_line(m_in);
|
||||||
r = color.red();
|
r = color.red();
|
||||||
g = color.green();
|
g = color.green();
|
||||||
|
|
@ -594,46 +688,136 @@ public:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void skip_to_next_vertex( std::size_t current_vertex);
|
void skip_to_next_vertex(std::size_t current_vertex)
|
||||||
|
{
|
||||||
|
CGAL_assertion(current_vertex < size_of_vertices());
|
||||||
|
if(binary())
|
||||||
|
{
|
||||||
|
float f;
|
||||||
|
if(has_normals() && ! normals_read) {
|
||||||
|
I_Binary_read_big_endian_float32(m_in, f);
|
||||||
|
I_Binary_read_big_endian_float32(m_in, f);
|
||||||
|
I_Binary_read_big_endian_float32(m_in, f);
|
||||||
|
if(is_homogeneous())
|
||||||
|
I_Binary_read_big_endian_float32(m_in, f);
|
||||||
|
}
|
||||||
|
|
||||||
void scan_facet( std::size_t& size, std::size_t CGAL_assertion_code(current_facet)) {
|
if(has_colors())
|
||||||
CGAL_assertion( current_facet < size_of_facets());
|
{
|
||||||
if ( binary()){
|
// It is not well stated in the Geomview manual
|
||||||
boost::int32_t i32;
|
// how color is coded following a vertex. It is
|
||||||
I_Binary_read_big_endian_integer32( m_in, i32);
|
// parsed similar to the optional color for facets.
|
||||||
size = i32;
|
boost::int32_t k;
|
||||||
|
I_Binary_read_big_endian_integer32(m_in, k);
|
||||||
|
if(k<0 || k>4)
|
||||||
|
{
|
||||||
|
m_in.clear(std::ios::badbit);
|
||||||
|
if(verbose())
|
||||||
|
{
|
||||||
|
std::cerr << " " << std::endl;
|
||||||
|
std::cerr << "File_scanner_OFF::" << std::endl;
|
||||||
|
std::cerr << "skip_to_next_vertex(): input error: bad "
|
||||||
|
" number of color indices at vertex "
|
||||||
|
<< current_vertex << "." << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
set_off_header(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
while(k--)
|
||||||
|
{
|
||||||
|
float dummy;
|
||||||
|
I_Binary_read_big_endian_float32(m_in, dummy);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if(has_normals() && ! normals_read)
|
||||||
|
{
|
||||||
|
double dummy;
|
||||||
|
if(is_homogeneous()) {
|
||||||
|
m_in >> dummy >> dummy >> dummy >> dummy;
|
||||||
} else {
|
} else {
|
||||||
|
m_in >> dummy >> dummy >> dummy;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(has_colors()) // skip color entries (1 to 4)
|
||||||
|
m_in >> skip_until_EOL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!m_in)
|
||||||
|
{
|
||||||
|
if(verbose())
|
||||||
|
{
|
||||||
|
std::cerr << " " << std::endl;
|
||||||
|
std::cerr << "File_scanner_OFF::" << std::endl;
|
||||||
|
std::cerr << "skip_to_next_vertex(): input error: cannot read "
|
||||||
|
"OFF file beyond vertex " << current_vertex << "."
|
||||||
|
<< std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
set_off_header(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
normals_read = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void scan_facet(std::size_t& size, std::size_t CGAL_assertion_code(current_facet))
|
||||||
|
{
|
||||||
|
CGAL_assertion(current_facet < size_of_facets());
|
||||||
|
if(binary())
|
||||||
|
{
|
||||||
|
boost::int32_t i32;
|
||||||
|
I_Binary_read_big_endian_integer32(m_in, i32);
|
||||||
|
size = i32;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
skip_comment();
|
skip_comment();
|
||||||
m_in >> size;
|
m_in >> size;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void scan_facet_vertex_index( std::size_t& index,
|
void scan_facet_vertex_index(std::size_t& index,
|
||||||
std::size_t current_facet) {
|
std::size_t current_facet)
|
||||||
if ( binary()){
|
{
|
||||||
|
if(binary()){
|
||||||
boost::int32_t i32;
|
boost::int32_t i32;
|
||||||
I_Binary_read_big_endian_integer32( m_in, i32);
|
I_Binary_read_big_endian_integer32(m_in, i32);
|
||||||
index = i32;
|
index = i32;
|
||||||
} else
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
m_in >> index;
|
m_in >> index;
|
||||||
|
}
|
||||||
|
|
||||||
if( m_in.fail()) {
|
if(m_in.fail())
|
||||||
if ( verbose()) {
|
{
|
||||||
|
if(verbose())
|
||||||
|
{
|
||||||
std::cerr << " " << std::endl;
|
std::cerr << " " << std::endl;
|
||||||
std::cerr << "File_scanner_OFF::" << std::endl;
|
std::cerr << "File_scanner_OFF::" << std::endl;
|
||||||
std::cerr << "scan_facet_vertex_index(): input error: "
|
std::cerr << "scan_facet_vertex_index(): input error: "
|
||||||
"cannot read OFF file beyond facet "
|
"cannot read OFF file beyond facet "
|
||||||
<< current_facet << "." << std::endl;
|
<< current_facet << "." << std::endl;
|
||||||
}
|
}
|
||||||
set_off_header( false);
|
|
||||||
|
set_off_header(false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool error = index < index_offset();
|
bool error = index < index_offset();
|
||||||
index -= index_offset();
|
index -= index_offset();
|
||||||
|
|
||||||
if(error || (index >= size_of_vertices())) {
|
if(error || (index >= size_of_vertices()))
|
||||||
m_in.clear( std::ios::failbit);
|
{
|
||||||
if ( verbose()) {
|
m_in.clear(std::ios::failbit);
|
||||||
|
if(verbose())
|
||||||
|
{
|
||||||
std::cerr << " " << std::endl;
|
std::cerr << " " << std::endl;
|
||||||
std::cerr << "File_scanner_OFF::" << std::endl;
|
std::cerr << "File_scanner_OFF::" << std::endl;
|
||||||
std::cerr << "scan_facet_vertex_index(): input error: "
|
std::cerr << "scan_facet_vertex_index(): input error: "
|
||||||
|
|
@ -641,58 +825,92 @@ public:
|
||||||
<< index + index_offset() << ": is out of range."
|
<< index + index_offset() << ": is out of range."
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
}
|
}
|
||||||
set_off_header( false);
|
|
||||||
|
set_off_header(false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void skip_to_next_facet( std::size_t current_facet);
|
void skip_to_next_facet(std::size_t current_facet)
|
||||||
|
{
|
||||||
|
// Take care of trailing informations like color triples.
|
||||||
|
if(binary())
|
||||||
|
{
|
||||||
|
boost::int32_t k;
|
||||||
|
I_Binary_read_big_endian_integer32(m_in, k);
|
||||||
|
if(k<0 || k>4)
|
||||||
|
{
|
||||||
|
m_in.clear(std::ios::badbit);
|
||||||
|
if(verbose())
|
||||||
|
{
|
||||||
|
std::cerr << " " << std::endl;
|
||||||
|
std::cerr << "File_scanner_OFF::" << std::endl;
|
||||||
|
std::cerr << "skip_to_next_facet(): input error: bad "
|
||||||
|
"number of color indices at vertex "
|
||||||
|
<< current_facet << "." << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
set_off_header(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
while (k--)
|
||||||
|
{
|
||||||
|
float dummy;
|
||||||
|
I_Binary_read_big_endian_float32(m_in, dummy);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
m_in >> skip_until_EOL;
|
||||||
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template < class Point> inline
|
template < class Point> inline
|
||||||
Point&
|
Point& file_scan_vertex(File_scanner_OFF& scanner, Point& p)
|
||||||
file_scan_vertex( File_scanner_OFF& scanner, Point& p) {
|
{
|
||||||
typedef typename Point::R R;
|
typedef typename Point::R R;
|
||||||
typedef typename R::RT RT;
|
typedef typename R::RT RT;
|
||||||
double x, y, z, w;
|
double x, y, z, w;
|
||||||
scanner.scan_vertex( x, y, z, w);
|
|
||||||
if ( w == 1)
|
scanner.scan_vertex(x, y, z, w);
|
||||||
p = Point( RT(x), RT(y), RT(z));
|
|
||||||
|
if(w == 1)
|
||||||
|
p = Point(RT(x), RT(y), RT(z));
|
||||||
else
|
else
|
||||||
p = Point( RT(x), RT(y), RT(z), RT(w));
|
p = Point(RT(x), RT(y), RT(z), RT(w));
|
||||||
|
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
template < class T_Color> inline
|
template < class T_Color> inline
|
||||||
T_Color&
|
T_Color& file_scan_color(File_scanner_OFF& scanner, T_Color& c)
|
||||||
file_scan_color( File_scanner_OFF& scanner, T_Color& c) {
|
{
|
||||||
unsigned char r, g, b;
|
unsigned char r, g, b;
|
||||||
scanner.scan_color(r,g,b);
|
scanner.scan_color(r,g,b);
|
||||||
c = T_Color(r,g,b);
|
c = T_Color(r,g,b);
|
||||||
|
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
|
|
||||||
template < class Vector> inline
|
template < class Vector> inline
|
||||||
Vector&
|
Vector&
|
||||||
file_scan_normal( File_scanner_OFF& scanner, Vector& v) {
|
file_scan_normal(File_scanner_OFF& scanner, Vector& v)
|
||||||
|
{
|
||||||
typedef typename Vector::R R;
|
typedef typename Vector::R R;
|
||||||
typedef typename R::RT RT;
|
typedef typename R::RT RT;
|
||||||
|
|
||||||
double x, y, z, w;
|
double x, y, z, w;
|
||||||
scanner.scan_normal( x, y, z, w);
|
scanner.scan_normal(x, y, z, w);
|
||||||
if ( w == 1)
|
if(w == 1)
|
||||||
v = Vector( RT(x), RT(y), RT(z));
|
v = Vector(RT(x), RT(y), RT(z));
|
||||||
else
|
else
|
||||||
v = Vector( RT(x), RT(y), RT(z), RT(w));
|
v = Vector(RT(x), RT(y), RT(z), RT(w));
|
||||||
|
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
} //namespace CGAL
|
} //namespace CGAL
|
||||||
|
|
||||||
#ifdef CGAL_HEADER_ONLY
|
#endif // CGAL_IO_OFF_FILE_SCANNER_OFF_H
|
||||||
#include <CGAL/IO/OFF/File_scanner_OFF_impl.h>
|
|
||||||
#endif // CGAL_HEADER_ONLY
|
|
||||||
|
|
||||||
#include <CGAL/enable_warnings.h>
|
|
||||||
|
|
||||||
#endif // CGAL_IO_OFF_FILE_SCANNER_OFF_H //
|
|
||||||
// EOF //
|
|
||||||
|
|
|
||||||
|
|
@ -1,125 +0,0 @@
|
||||||
// Copyright (c) 1997
|
|
||||||
// Utrecht University (The Netherlands),
|
|
||||||
// ETH Zurich (Switzerland),
|
|
||||||
// INRIA Sophia-Antipolis (France),
|
|
||||||
// Max-Planck-Institute Saarbruecken (Germany),
|
|
||||||
// and Tel-Aviv University (Israel). All rights reserved.
|
|
||||||
//
|
|
||||||
// This file is part of CGAL (www.cgal.org)
|
|
||||||
//
|
|
||||||
// $URL$
|
|
||||||
// $Id$
|
|
||||||
// SPDX-License-Identifier: LGPL-3.0-or-later OR LicenseRef-Commercial
|
|
||||||
//
|
|
||||||
//
|
|
||||||
// Author(s) : Lutz Kettner <kettner@mpi-sb.mpg.de>
|
|
||||||
|
|
||||||
#ifdef CGAL_HEADER_ONLY
|
|
||||||
#define CGAL_INLINE_FUNCTION inline
|
|
||||||
#else
|
|
||||||
#define CGAL_INLINE_FUNCTION
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <CGAL/basic.h>
|
|
||||||
#include <cstdlib>
|
|
||||||
#include <iostream>
|
|
||||||
#include <CGAL/IO/binary_file_io.h>
|
|
||||||
#include <CGAL/IO/OFF/File_scanner_OFF.h>
|
|
||||||
|
|
||||||
namespace CGAL {
|
|
||||||
|
|
||||||
CGAL_INLINE_FUNCTION
|
|
||||||
void
|
|
||||||
File_scanner_OFF::
|
|
||||||
skip_to_next_vertex( std::size_t current_vertex) {
|
|
||||||
CGAL_assertion( current_vertex < size_of_vertices());
|
|
||||||
if ( binary()) {
|
|
||||||
float f;
|
|
||||||
if ( has_normals() && ! normals_read) {
|
|
||||||
I_Binary_read_big_endian_float32( m_in, f);
|
|
||||||
I_Binary_read_big_endian_float32( m_in, f);
|
|
||||||
I_Binary_read_big_endian_float32( m_in, f);
|
|
||||||
if ( is_homogeneous())
|
|
||||||
I_Binary_read_big_endian_float32( m_in, f);
|
|
||||||
}
|
|
||||||
if ( has_colors()) {
|
|
||||||
// It is not well stated in the Geomview manual
|
|
||||||
// how color is coded following a vertex. It is
|
|
||||||
// parsed similar to the optional color for facets.
|
|
||||||
boost::int32_t k;
|
|
||||||
I_Binary_read_big_endian_integer32( m_in, k);
|
|
||||||
if (k<0 || k>4) {
|
|
||||||
m_in.clear( std::ios::badbit);
|
|
||||||
if ( verbose()) {
|
|
||||||
std::cerr << " " << std::endl;
|
|
||||||
std::cerr << "File_scanner_OFF::" << std::endl;
|
|
||||||
std::cerr << "skip_to_next_vertex(): input error: bad "
|
|
||||||
" number of color indices at vertex "
|
|
||||||
<< current_vertex << "." << std::endl;
|
|
||||||
}
|
|
||||||
set_off_header( false);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
while (k--) {
|
|
||||||
float dummy;
|
|
||||||
I_Binary_read_big_endian_float32( m_in, dummy);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if ( has_normals() && ! normals_read) {
|
|
||||||
double dummy;
|
|
||||||
if ( is_homogeneous()) {
|
|
||||||
m_in >> dummy >> dummy >> dummy >> dummy;
|
|
||||||
} else {
|
|
||||||
m_in >> dummy >> dummy >> dummy;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if ( has_colors()) { // skip color entries (1 to 4)
|
|
||||||
m_in >> skip_until_EOL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if( ! m_in) {
|
|
||||||
if ( verbose()) {
|
|
||||||
std::cerr << " " << std::endl;
|
|
||||||
std::cerr << "File_scanner_OFF::" << std::endl;
|
|
||||||
std::cerr << "skip_to_next_vertex(): input error: cannot read "
|
|
||||||
"OFF file beyond vertex " << current_vertex << "."
|
|
||||||
<< std::endl;
|
|
||||||
}
|
|
||||||
set_off_header( false);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
normals_read = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
CGAL_INLINE_FUNCTION
|
|
||||||
void
|
|
||||||
File_scanner_OFF::
|
|
||||||
skip_to_next_facet( std::size_t current_facet) {
|
|
||||||
// Take care of trailing informations like color triples.
|
|
||||||
if ( binary()) {
|
|
||||||
boost::int32_t k;
|
|
||||||
I_Binary_read_big_endian_integer32( m_in, k);
|
|
||||||
if (k<0 || k>4) {
|
|
||||||
m_in.clear( std::ios::badbit);
|
|
||||||
if ( verbose()) {
|
|
||||||
std::cerr << " " << std::endl;
|
|
||||||
std::cerr << "File_scanner_OFF::" << std::endl;
|
|
||||||
std::cerr << "skip_to_next_facet(): input error: bad "
|
|
||||||
"number of color indices at vertex "
|
|
||||||
<< current_facet << "." << std::endl;
|
|
||||||
}
|
|
||||||
set_off_header( false);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
while (k--) {
|
|
||||||
float dummy;
|
|
||||||
I_Binary_read_big_endian_float32( m_in, dummy);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
m_in >> skip_until_EOL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
} //namespace CGAL
|
|
||||||
// EOF //
|
|
||||||
|
|
@ -38,13 +38,13 @@ public:
|
||||||
File_header_OFF& header() { return m_header; }
|
File_header_OFF& header() { return m_header; }
|
||||||
const File_header_OFF& header() const { return m_header; }
|
const File_header_OFF& header() const { return m_header; }
|
||||||
|
|
||||||
void write_header(std::ostream& out,
|
void write_header(std::ostream& os,
|
||||||
std::size_t vertices,
|
std::size_t vertices,
|
||||||
std::size_t /*halfedges*/,
|
std::size_t /*halfedges*/,
|
||||||
std::size_t facets,
|
std::size_t facets,
|
||||||
bool normals = false)
|
bool normals = false)
|
||||||
{
|
{
|
||||||
m_out = &o;
|
m_out = &os;
|
||||||
|
|
||||||
m_header.set_vertices(vertices);
|
m_header.set_vertices(vertices);
|
||||||
m_header.set_facets(facets);
|
m_header.set_facets(facets);
|
||||||
|
|
|
||||||
|
|
@ -1,24 +0,0 @@
|
||||||
// Copyright (c) 1997
|
|
||||||
// Utrecht University (The Netherlands),
|
|
||||||
// ETH Zurich (Switzerland),
|
|
||||||
// INRIA Sophia-Antipolis (France),
|
|
||||||
// Max-Planck-Institute Saarbruecken (Germany),
|
|
||||||
// and Tel-Aviv University (Israel). All rights reserved.
|
|
||||||
//
|
|
||||||
// This file is part of CGAL (www.cgal.org)
|
|
||||||
//
|
|
||||||
// $URL$
|
|
||||||
// $Id$
|
|
||||||
// SPDX-License-Identifier: LGPL-3.0-or-later OR LicenseRef-Commercial
|
|
||||||
//
|
|
||||||
//
|
|
||||||
// Author(s) : Lutz Kettner <kettner@mpi-sb.mpg.de>
|
|
||||||
|
|
||||||
#ifndef CGAL_HEADER_ONLY
|
|
||||||
|
|
||||||
#include <CGAL/IO/OFF/File_scanner_OFF.h>
|
|
||||||
#include <CGAL/IO/OFF/File_scanner_OFF_impl.h>
|
|
||||||
|
|
||||||
#endif // CGAL_HEADER_ONLY
|
|
||||||
|
|
||||||
// EOF //
|
|
||||||
Loading…
Reference in New Issue