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,98 +14,100 @@
|
|||
//
|
||||
// Author(s) : Lutz Kettner <kettner@mpi-sb.mpg.de>
|
||||
|
||||
|
||||
#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 <iostream>
|
||||
|
||||
namespace CGAL {
|
||||
|
||||
// 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:
|
||||
// Publicly accessible file informations.
|
||||
std::size_t n_vertices;
|
||||
// Publicly accessible file informations.
|
||||
std::size_t n_vertices;
|
||||
std::size_t n_facets;
|
||||
bool m_skel; // SKEL format instead of OFF.
|
||||
bool m_binary; // OFF in binary format.
|
||||
bool m_no_comments; // no comments in output.
|
||||
std::size_t m_offset; // index offset for vertices, usually 0.
|
||||
bool m_skel; // SKEL format instead of OFF.
|
||||
bool m_binary; // OFF in binary format.
|
||||
bool m_no_comments; // no comments in output.
|
||||
std::size_t m_offset; // index offset for vertices, usually 0.
|
||||
|
||||
// Publicly accessible but not that well supported file informations.
|
||||
bool m_colors; // COFF detected.
|
||||
bool m_normals; // NOFF format stores also normals at vertices.
|
||||
// Publicly accessible but not that well supported file informations.
|
||||
bool m_colors; // COFF detected.
|
||||
bool m_normals; // NOFF format stores also normals at vertices.
|
||||
|
||||
// More privately used file informations to scan the file.
|
||||
bool m_tag4; // 4OFF detected.
|
||||
bool m_tagDim; // nOFF detected (will not be supported).
|
||||
int m_dim; // dimension for nOFF (will not be supported).
|
||||
|
||||
// More privately used file informations to scan the file.
|
||||
bool m_tag4; // 4OFF detected.
|
||||
bool m_tagDim; // nOFF detected (will not be supported).
|
||||
int m_dim; // dimension for nOFF (will not be supported).
|
||||
public:
|
||||
typedef File_header_OFF Self;
|
||||
typedef File_header_extended_OFF Base;
|
||||
typedef File_header_OFF Self;
|
||||
typedef File_header_extended_OFF Base;
|
||||
|
||||
explicit File_header_OFF( bool verbose = false);
|
||||
File_header_OFF( bool binary, bool noc, bool skel,
|
||||
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,
|
||||
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,
|
||||
bool binary, bool noc, bool skel);
|
||||
File_header_OFF( std::size_t v, std::size_t h, std::size_t f,
|
||||
const File_header_extended_OFF& ext_header);
|
||||
File_header_OFF( std::size_t v, std::size_t h, std::size_t f,
|
||||
const File_header_extended_OFF& ext_header,
|
||||
bool binary, bool noc, bool skel);
|
||||
explicit File_header_OFF(bool verbose = false);
|
||||
File_header_OFF(bool binary, bool noc, bool skel, 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,
|
||||
bool binary, bool noc, bool skel, bool verbose = false);
|
||||
|
||||
Self& operator= ( const Base& base) { (Base&)(*this) = base;
|
||||
return *this;
|
||||
}
|
||||
std::size_t size_of_vertices() const { return n_vertices; }
|
||||
std::size_t size_of_facets() const { return n_facets; }
|
||||
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);
|
||||
File_header_OFF(std::size_t v, std::size_t h, std::size_t f,
|
||||
const File_header_extended_OFF& ext_header);
|
||||
File_header_OFF(std::size_t v, std::size_t h, std::size_t f,
|
||||
const File_header_extended_OFF& ext_header,
|
||||
bool binary, bool noc, bool skel);
|
||||
|
||||
bool skel() const { return m_skel; } // SKEL format.
|
||||
bool off() const { return ! m_skel; } // OFF format.
|
||||
bool binary() const { return m_binary; } // binary format.
|
||||
bool ascii() const { return ! m_binary; } // ASCII format.
|
||||
bool no_comments() const { return m_no_comments; }
|
||||
bool comments() const { return ! m_no_comments; }
|
||||
Self& operator= (const Base& base) { (Base&)(*this) = base; return *this; }
|
||||
|
||||
std::size_t index_offset() const { return m_offset; }
|
||||
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.
|
||||
// nOFF detected. (will not be supported).
|
||||
bool n_dimensional() const { return m_tagDim; }
|
||||
// dimension for nOFF (will not be supported).
|
||||
int dimension() const { return m_dim; }
|
||||
std::size_t size_of_vertices() const { return n_vertices; }
|
||||
std::size_t size_of_facets() const { return n_facets; }
|
||||
|
||||
void set_vertices( std::size_t n) { n_vertices = n; }
|
||||
void set_facets( std::size_t n) { n_facets = n; }
|
||||
bool skel() const { return m_skel; } // SKEL format.
|
||||
bool off() const { return ! m_skel; } // OFF format.
|
||||
bool binary() const { return m_binary; } // binary format.
|
||||
bool ascii() const { return ! m_binary; } // ASCII format.
|
||||
bool no_comments() const { return m_no_comments; }
|
||||
bool comments() const { return ! m_no_comments; }
|
||||
|
||||
void set_skel( bool b) { m_skel = b; }
|
||||
void set_binary( bool b) { m_binary = b; }
|
||||
void set_no_comments( bool b) { m_no_comments = b; }
|
||||
void set_index_offset( std::size_t i) { m_offset = i; }
|
||||
std::size_t index_offset() const { return m_offset; }
|
||||
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.
|
||||
|
||||
void set_colors( bool b) { m_colors = b; }
|
||||
void set_normals( bool b) { m_normals = b;}
|
||||
void set_homogeneous( bool b) { m_tag4 = b; }
|
||||
void set_dimensional( bool b) { m_tagDim = b; }
|
||||
void set_dimension( int i) { m_dim = i; }
|
||||
Self& operator+=( const Self& header);
|
||||
// nOFF detected. (will not be supported).
|
||||
bool n_dimensional() const { return m_tagDim; }
|
||||
// dimension for nOFF (will not be supported).
|
||||
int dimension() const { return m_dim; }
|
||||
|
||||
void set_vertices(std::size_t n) { n_vertices = n; }
|
||||
void set_facets(std::size_t n) { n_facets = n; }
|
||||
|
||||
void set_skel(bool b) { m_skel = b; }
|
||||
void set_binary(bool b) { m_binary = b; }
|
||||
void set_no_comments(bool b) { m_no_comments = b; }
|
||||
void set_index_offset(std::size_t i) { m_offset = i; }
|
||||
|
||||
void set_colors(bool b) { m_colors = b; }
|
||||
void set_normals(bool b) { m_normals = b;}
|
||||
void set_homogeneous(bool b) { m_tag4 = b; }
|
||||
void set_dimensional(bool b) { m_tagDim = b; }
|
||||
void set_dimension(int i) { m_dim = i; }
|
||||
Self& operator+=(const Self& 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.
|
||||
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
|
||||
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load Diff
|
|
@ -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; }
|
||||
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 /*halfedges*/,
|
||||
std::size_t facets,
|
||||
bool normals = false)
|
||||
{
|
||||
m_out = &o;
|
||||
m_out = &os;
|
||||
|
||||
m_header.set_vertices(vertices);
|
||||
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