mirror of https://github.com/CGAL/cgal
Clean code
This commit is contained in:
parent
9247fdab02
commit
9e2289c63d
|
|
@ -57,7 +57,6 @@ bool write_WRL(const char* fname, const FaceGraph& g) { return write_WRL(fname,
|
|||
template <typename FaceGraph>
|
||||
bool write_WRL(const std::string& fname, const FaceGraph& g) { return write_WRL(fname, g, parameters::all_default()); }
|
||||
|
||||
|
||||
} // namespace CGAL
|
||||
|
||||
#endif // CGAL_BGL_IO_WRL_H
|
||||
|
|
|
|||
|
|
@ -18,13 +18,16 @@
|
|||
#define CGAL_IO_GENERIC_WRITER_H
|
||||
|
||||
#include <CGAL/basic.h>
|
||||
|
||||
#include <iterator>
|
||||
|
||||
namespace CGAL {
|
||||
|
||||
template <class Writer>
|
||||
class I_Generic_writer_vertex_proxy {
|
||||
class I_Generic_writer_vertex_proxy
|
||||
{
|
||||
Writer& m_writer;
|
||||
|
||||
public:
|
||||
typedef typename Writer::Point Point;
|
||||
I_Generic_writer_vertex_proxy(Writer& w) : m_writer(w) {}
|
||||
|
|
@ -52,8 +55,10 @@ public:
|
|||
};
|
||||
|
||||
template <class Writer>
|
||||
class I_Generic_writer_facet_proxy {
|
||||
class I_Generic_writer_facet_proxy
|
||||
{
|
||||
Writer& m_writer;
|
||||
|
||||
public:
|
||||
I_Generic_writer_facet_proxy(Writer& w) : m_writer(w) { }
|
||||
void operator= (std::size_t i) { m_writer.write_facet_index(i); }
|
||||
|
|
@ -63,6 +68,7 @@ template <class Writer>
|
|||
class I_Generic_writer_facet_iterator
|
||||
{
|
||||
Writer& m_writer;
|
||||
|
||||
public:
|
||||
typedef std::output_iterator_tag iterator_category;
|
||||
typedef std::size_t value_type;
|
||||
|
|
@ -86,7 +92,8 @@ public:
|
|||
// the situation where the iterators are copied by value.
|
||||
|
||||
template < class Writer, class Pt >
|
||||
class Generic_writer {
|
||||
class Generic_writer
|
||||
{
|
||||
Writer m_writer;
|
||||
std::size_t m_vertices;
|
||||
std::size_t m_halfedges;
|
||||
|
|
@ -95,6 +102,7 @@ class Generic_writer {
|
|||
std::size_t m_vcnt;
|
||||
std::size_t m_fcnt;
|
||||
std::size_t m_icnt;
|
||||
|
||||
public:
|
||||
typedef Pt Point;
|
||||
typedef Generic_writer< Writer, Pt> Self;
|
||||
|
|
@ -103,50 +111,65 @@ public:
|
|||
|
||||
Generic_writer(const Writer& writer, std::ostream& out,
|
||||
std::size_t v, std::size_t h, std::size_t f)
|
||||
: m_writer( writer), m_vertices(v), m_halfedges(h), m_facets(f),
|
||||
:
|
||||
m_writer(writer),
|
||||
m_vertices(v), m_halfedges(h), m_facets(f),
|
||||
m_vcnt(0), m_fcnt(0), m_icnt(0)
|
||||
{
|
||||
m_writer.write_header(out, v, h, f);
|
||||
}
|
||||
|
||||
const Writer& writer() const { return m_writer; }
|
||||
std::size_t size_of_vertices() const { return m_vertices; }
|
||||
std::size_t size_of_halfedges() const { return m_halfedges; }
|
||||
std::size_t size_of_facets() const { return m_facets; }
|
||||
|
||||
Vertex_iterator vertices_begin() { return Vertex_iterator(*this); }
|
||||
Facet_iterator facets_begin() {
|
||||
if ( m_vcnt != m_vertices) {
|
||||
std::cerr << "error: Generic_writer: wrong number of "
|
||||
"vertices written, " << m_vcnt << " instead of "
|
||||
<< m_vertices << "." << std::endl;
|
||||
Facet_iterator facets_begin()
|
||||
{
|
||||
if(m_vcnt != m_vertices)
|
||||
{
|
||||
std::cerr << "error: Generic_writer: wrong number of vertices written, "
|
||||
<< m_vcnt << " instead of " << m_vertices << "." << std::endl;
|
||||
m_writer.out().clear(std::ios::badbit);
|
||||
}
|
||||
|
||||
m_writer.write_facet_header();
|
||||
if(m_facets == 0)
|
||||
m_writer.write_footer();
|
||||
|
||||
return Facet_iterator(*this);
|
||||
}
|
||||
|
||||
// Interface used by the iterators and their proxies.
|
||||
void write_vertex( const Point& p) {
|
||||
void write_vertex(const Point& p)
|
||||
{
|
||||
++m_vcnt;
|
||||
m_writer.write_vertex(::CGAL::to_double(p.x()),
|
||||
::CGAL::to_double(p.y()),
|
||||
::CGAL::to_double(p.z()));
|
||||
}
|
||||
void write_facet_index( std::size_t i) {
|
||||
if ( m_fcnt > m_facets) {
|
||||
|
||||
void write_facet_index(std::size_t i)
|
||||
{
|
||||
if(m_fcnt > m_facets)
|
||||
{
|
||||
std::cerr << "error: Generic_writer: too many facets written."
|
||||
<< std::endl;
|
||||
m_writer.out().clear(std::ios::badbit);
|
||||
}
|
||||
if ( m_icnt == 0) {
|
||||
|
||||
if(m_icnt == 0)
|
||||
{
|
||||
m_writer.write_facet_begin(i);
|
||||
m_icnt = i;
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
m_writer.write_facet_vertex_index(i);
|
||||
m_icnt--;
|
||||
if ( m_icnt == 0) {
|
||||
if(m_icnt == 0)
|
||||
{
|
||||
m_writer.write_facet_end();
|
||||
m_fcnt++;
|
||||
if(m_fcnt == m_facets)
|
||||
|
|
@ -157,5 +180,5 @@ public:
|
|||
};
|
||||
|
||||
} //namespace CGAL
|
||||
#endif // CGAL_IO_GENERIC_WRITER_H //
|
||||
// EOF //
|
||||
|
||||
#endif // CGAL_IO_GENERIC_WRITER_H
|
||||
|
|
|
|||
|
|
@ -47,7 +47,7 @@ public:
|
|||
|
||||
void write_footer() const { out() << "\n# End of Wavefront obj format #" << std::endl; }
|
||||
|
||||
void write_vertex(const double& x, const double& y, const double& z) {
|
||||
void write_vertex(const double x, const double y, const double z) {
|
||||
out() << "v " << x << ' ' << y << ' ' << z << '\n';
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -25,9 +25,11 @@
|
|||
|
||||
namespace CGAL {
|
||||
|
||||
class CGAL_EXPORT File_writer_OFF {
|
||||
class File_writer_OFF
|
||||
{
|
||||
std::ostream* m_out;
|
||||
File_header_OFF m_header;
|
||||
|
||||
public:
|
||||
File_writer_OFF(bool verbose = false) : m_header(verbose) {}
|
||||
File_writer_OFF(const File_header_OFF& h) : m_header(h) {}
|
||||
|
|
@ -52,34 +54,51 @@ public:
|
|||
out() << m_header;
|
||||
}
|
||||
|
||||
void write_footer() {
|
||||
void write_footer()
|
||||
{
|
||||
if(m_header.ascii() && m_header.comments())
|
||||
out() << "\n\n# End of OFF #";
|
||||
out() << std::endl;
|
||||
}
|
||||
void write_vertex( const double& x, const double& y, const double& z) {
|
||||
if ( m_header.binary()) {
|
||||
|
||||
void write_vertex(const double x, const double y, const double z)
|
||||
{
|
||||
if(m_header.binary())
|
||||
{
|
||||
I_Binary_write_big_endian_float32(out(), float(x));
|
||||
I_Binary_write_big_endian_float32(out(), float(y));
|
||||
I_Binary_write_big_endian_float32(out(), float(z));
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
out() << '\n' << x << ' ' << y << ' ' << z;
|
||||
}
|
||||
}
|
||||
void write_normal( const double& x, const double& y, const double& z) {
|
||||
if ( m_header.binary()) {
|
||||
|
||||
void write_normal(const double x, const double y, const double z)
|
||||
{
|
||||
if(m_header.binary())
|
||||
{
|
||||
I_Binary_write_big_endian_float32(out(), float(x));
|
||||
I_Binary_write_big_endian_float32(out(), float(y));
|
||||
I_Binary_write_big_endian_float32(out(), float(z));
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
out() << ' ' << ' ' << x << ' ' << y << ' ' << z;
|
||||
}
|
||||
}
|
||||
void write_facet_header() {
|
||||
if ( m_header.ascii()) {
|
||||
|
||||
void write_facet_header()
|
||||
{
|
||||
if(m_header.ascii())
|
||||
{
|
||||
if(m_header.no_comments())
|
||||
{
|
||||
out() << '\n';
|
||||
else {
|
||||
}
|
||||
else
|
||||
{
|
||||
out() << "\n\n# " << m_header.size_of_facets()
|
||||
<< " facets\n";
|
||||
out() << "# ------------------------------------------"
|
||||
|
|
@ -87,19 +106,25 @@ public:
|
|||
}
|
||||
}
|
||||
}
|
||||
void write_facet_begin( std::size_t no) {
|
||||
|
||||
void write_facet_begin(std::size_t no)
|
||||
{
|
||||
if(m_header.binary())
|
||||
I_Binary_write_big_endian_integer32(out(), static_cast<boost::int32_t>(no));
|
||||
else
|
||||
out() << no << ' ';
|
||||
}
|
||||
void write_facet_vertex_index( std::size_t index) {
|
||||
|
||||
void write_facet_vertex_index(std::size_t index)
|
||||
{
|
||||
if(m_header.binary())
|
||||
I_Binary_write_big_endian_integer32(out(), static_cast<boost::int32_t>(index));
|
||||
else
|
||||
out() << ' ' << index;
|
||||
}
|
||||
void write_facet_end() {
|
||||
|
||||
void write_facet_end()
|
||||
{
|
||||
if(m_header.binary())
|
||||
I_Binary_write_big_endian_integer32(out(), 0);
|
||||
else
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@
|
|||
// Author(s) : Lutz Kettner <kettner@mpi-sb.mpg.de>
|
||||
|
||||
#ifndef CGAL_IO_FILE_WRITER_INVENTOR_H
|
||||
#define CGAL_IO_FILE_WRITER_INVENTOR_H 1
|
||||
#define CGAL_IO_FILE_WRITER_INVENTOR_H
|
||||
|
||||
#include <CGAL/IO/OI/Inventor_ostream.h>
|
||||
|
||||
|
|
@ -25,19 +25,19 @@ namespace CGAL {
|
|||
|
||||
class File_writer_inventor
|
||||
{
|
||||
std::ostream* m_out;
|
||||
Inventor_ostream_base* m_out;
|
||||
std::size_t m_facets;
|
||||
|
||||
public:
|
||||
File_writer_inventor() {}
|
||||
std::ostream& out() const { return *m_out; }
|
||||
std::ostream& out() const { return m_out->os(); }
|
||||
|
||||
void write_header(Inventor_ostream_base& o,
|
||||
std::size_t vertices,
|
||||
std::size_t halfedges,
|
||||
std::size_t facets)
|
||||
{
|
||||
m_out = &(o.os());
|
||||
m_out = &o;
|
||||
m_facets = facets;
|
||||
|
||||
out() << "# " << vertices << " vertices\n";
|
||||
|
|
@ -55,7 +55,8 @@ public:
|
|||
"} #Separator" << std::endl;
|
||||
}
|
||||
|
||||
void write_vertex( const double& x, const double& y, const double& z) {
|
||||
void write_vertex( const double x, const double y, const double z)
|
||||
{
|
||||
out() << " " << x << ' ' << y << ' ' << z << ',' <<'\n';
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -28,19 +28,19 @@ namespace CGAL {
|
|||
|
||||
class File_writer_VRML_2
|
||||
{
|
||||
std::ostream* m_out;
|
||||
VRML_2_ostream* m_out;
|
||||
std::size_t m_facets;
|
||||
|
||||
public:
|
||||
File_writer_VRML_2() {}
|
||||
std::ostream& out() const { return *m_out; }
|
||||
std::ostream& out() const { return m_out->os(); }
|
||||
|
||||
void write_header(VRML_2_ostream& o,
|
||||
std::size_t vertices,
|
||||
std::size_t halfedges,
|
||||
std::size_t facets)
|
||||
{
|
||||
m_out = &o.os();
|
||||
m_out = &o;
|
||||
m_facets = facets;
|
||||
|
||||
out() << " #-- Begin of Polygon Mesh\n";
|
||||
|
|
@ -67,10 +67,12 @@ public:
|
|||
" } #Group" << std::endl;
|
||||
}
|
||||
|
||||
void write_vertex( const double& x, const double& y, const double& z) {
|
||||
void write_vertex( const double& x, const double& y, const double& z)
|
||||
{
|
||||
out() << " "
|
||||
<< x << ' ' << y << ' ' << z << ',' << '\n';
|
||||
}
|
||||
|
||||
void write_facet_header() const
|
||||
{
|
||||
out() << " ] #point\n"
|
||||
|
|
@ -78,9 +80,7 @@ public:
|
|||
" coordIndex [" << std::endl;
|
||||
}
|
||||
|
||||
void write_facet_begin( std::size_t) {
|
||||
out() << " ";
|
||||
}
|
||||
void write_facet_begin( std::size_t) { out() << " "; }
|
||||
void write_facet_vertex_index( std::size_t idx) { out() << idx << ',';}
|
||||
void write_facet_end() { out() << "-1,\n"; }
|
||||
};
|
||||
|
|
|
|||
|
|
@ -13,10 +13,12 @@
|
|||
#ifndef CGAL_SURFACE_MESH_IO_3MF_H
|
||||
#define CGAL_SURFACE_MESH_IO_3MF_H
|
||||
|
||||
#include <iostream>
|
||||
#include <CGAL/IO/read_3mf.h>
|
||||
#include <CGAL/Surface_mesh.h>
|
||||
|
||||
#include <CGAL/IO/3MF.h>
|
||||
|
||||
#include <iostream>
|
||||
|
||||
namespace CGAL{
|
||||
/*!
|
||||
* Extracts the surface meshes from an input 3mf file and appends it to `output`.
|
||||
|
|
|
|||
Loading…
Reference in New Issue