Revert to previous write_{vertex,halfedge,face} signature

This commit is contained in:
Efi Fogel 2002-03-21 11:12:54 +00:00
parent b3b277823c
commit 24ca7fb7a9
6 changed files with 82 additions and 71 deletions

View File

@ -48,13 +48,7 @@ public:
Pm_my_file_writer(std::ostream & o, const PM & pm, bool verbose = false) :
CGAL::Pm_file_writer<PM>(o, pm, verbose) { }
void write_vertex(Vertex_handle v)
{
out() << v->point() <<" ";
out() << v->get_color()<< std::endl;
}
void write_vertex(Vertex_const_handle v)
void write_vertex(Vertex_const_handle v) const
{
out() << v->point() <<" ";
out() << v->get_color()<< std::endl;

View File

@ -3,9 +3,9 @@
* * * Printing the Planar map
# ------------------------------------- Printing Planar map
# ------------------------------------- Begin Planar Map
# --------------------------------------------------------
# Printing number of vertices halfedges and faces in Planar map
# Number of vertices halfedges and faces in Planar map
3 6 2
# 3 vertices
# ------------------------------------------
@ -45,5 +45,5 @@
0
# finish writing face
# ------------------------------------------
# ------------------------------------- End of Planar map
# ------------------------------------- End Planar Map
# --------------------------------------------------------

View File

@ -6,8 +6,8 @@
#include <CGAL/Pm_default_dcel.h>
#include <CGAL/Planar_map_2.h>
#include <CGAL/Pm_segment_traits.h>
#include <CGAL/IO/Pm_iostream.h>
#include <CGAL/IO/write_pm.h>
#include <CGAL/IO/Pm_iostream.h>
#include <iostream>
// #define CGAL_POSTSCRIPT
@ -25,6 +25,8 @@ typedef CGAL::Pm_file_writer<Planar_map> Pm_writer;
int main()
{
Planar_map pm;
Pm_writer verbose_writer(std::cout, pm, true);
Pm_writer writer(std::cout, pm);
std::cout << "* * * Demonstrating a trivial use of IO functions"
<< std::endl << std::endl;
@ -34,7 +36,6 @@ int main()
std::cout << std::endl;
std::cout << "* * * Presenting the use of verbose format" << std::endl;
std::cout << std::endl;
Pm_writer verbose_writer(std::cout, pm, true);
CGAL::write_pm(pm, verbose_writer, std::cout);
std::cout << std::endl;
@ -42,7 +43,6 @@ int main()
<< std::endl;
std::cout << "* * * Printing all halfedges in non verbose format"
<< std::endl << std::endl;
Pm_writer writer(std::cout, pm);
writer.write_halfedges(pm.halfedges_begin(), pm.halfedges_end());
std::cout << std::endl;
std::cout << "* * * Printing all halfedges in a verbose format" << std::endl

View File

@ -1,8 +1,8 @@
* * * Demonstrating a trivial use of IO functions
# ------------------------------------- Printing Planar map
# ------------------------------------- Begin Planar Map
# --------------------------------------------------------
# Printing number of vertices halfedges and faces in Planar map
# Number of vertices halfedges and faces in Planar map
3 6 2
# 3 vertices
# ------------------------------------------
@ -42,14 +42,14 @@
0
# finish writing face
# ------------------------------------------
# ------------------------------------- End of Planar map
# ------------------------------------- End Planar Map
# --------------------------------------------------------
* * * Presenting the use of verbose format
# ------------------------------------- Printing Planar map
# ------------------------------------- Begin Planar Map
# --------------------------------------------------------
# Printing number of vertices halfedges and faces in Planar map
# Number of vertices halfedges and faces in Planar map
3 6 2
# 3 vertices
# ------------------------------------------
@ -95,7 +95,7 @@
0
# finish writing face
# ------------------------------------------
# ------------------------------------- End of Planar map
# ------------------------------------- End Planar Map
# --------------------------------------------------------
* * * Demonstrating the use of the writer class interface.

View File

@ -77,11 +77,11 @@ public:
typedef Inverse_index<Vertex_const_iterator> V_index;
Pm_file_writer(std::ostream & o, const PM & pm, bool verbose = false) :
File_header(verbose), m_out(&o), m_pm(pm)
File_header(verbose), m_out(&o), m_pm(pm), m_h_index(0), m_v_index(0)
{ }
Pm_file_writer(std::ostream & o, const PM & pm, const File_header & h) :
File_header(h), m_out(&o), m_pm(pm)
File_header(h), m_out(&o), m_pm(pm), m_h_index(0), m_v_index(0)
{ }
std::ostream & out() const { return *m_out; }
@ -148,11 +148,13 @@ public:
}
}
void write_vertex(Vertex_const_handle v) const
protected:
virtual void write_vertex(Vertex_const_handle v) const
{
out() << v->point() << std::endl;
}
public:
void write_halfedges_header() const
{
if (no_comments())
@ -189,15 +191,17 @@ public:
write_vertex(h->target());
}
void write_halfedge(Halfedge_const_handle h, const V_index & v_index) const
protected:
virtual void write_halfedge(Halfedge_const_handle h) const
{
if (verbose()) write_halfedge_verbose(h);
else {
write_index(v_index[ Vertex_const_iterator(h->target())]);
write_index(get_v_index(Vertex_const_iterator(h->target())));
out() << h->curve() << std::endl;
}
}
public:
void write_faces_header() const
{
if (no_comments())
@ -208,8 +212,9 @@ public:
out() << "# ------------------------------------------"<< std::endl;
}
}
void write_face(Face_const_handle f, const H_index & h_index) const
protected:
virtual void write_face(Face_const_handle f)
{
int ck;
Holes_const_iterator iccbit;
@ -240,7 +245,7 @@ public:
if (verbose())
write_halfedge_verbose(iter);
else
write_index(h_index[Halfedge_const_iterator(iter)]);
write_index(get_h_index(Halfedge_const_iterator(iter)));
++iter;
} while (iter != first);
@ -273,7 +278,7 @@ public:
if (verbose())
write_halfedge_verbose(iter);
else
write_index(h_index[Halfedge_const_iterator(iter)]);
write_index(get_h_index(Halfedge_const_iterator(iter)));
++iter;
} while (iter != ccb_circ);
@ -284,6 +289,7 @@ public:
out() << "# ------------------------------------------"<< std::endl;
}
public:
void write_vertices(Vertex_const_iterator Vertices_begin,
Vertex_const_iterator Vertices_end) const
{
@ -291,23 +297,51 @@ public:
for (v_iter = Vertices_begin; v_iter != Vertices_end; v_iter++)
write_vertex(v_iter);
}
//
// The handling of the index arrays v_index and h_index is bad.
// One solution is to replace write_halfedge() and write_face() with
// corresponding classes with the index arrays as data members and
// functors to perform the respective operations. Their constructor will
// take the pm as a parameter to compure the index arrays.
//
// void write_halfedges(Halfedge_const_iterator Halfedges_begin,
// Halfedge_const_iterator Halfedges_end)
// {
// Write_halfedge write_halfedge(m_pm);
// Halfedge_const_iterator h_iter;
// for (h_iter = Halfedges_begin; h_iter != Halfedges_end; h_iter++)
// write_halfedge(h_iter);
// }
//
// The class Pm_file_writer could be templated with Write_vertex,
// Write_halfedge, and Write_face.
//
// Also, I don't see any reason why write_pm should be a global function
// and not a member of Pm_file_writer
//
// Efi
void write_halfedges(Halfedge_const_iterator Halfedges_begin,
Halfedge_const_iterator Halfedges_end) const
Halfedge_const_iterator Halfedges_end)
{
V_index v_index(m_pm.vertices_begin(), m_pm.vertices_end());
m_v_index = &v_index;
Halfedge_const_iterator h_iter;
for (h_iter = Halfedges_begin; h_iter != Halfedges_end; h_iter++)
write_halfedge(h_iter, v_index);
write_halfedge(h_iter);
m_v_index = 0;
}
void write_faces(Face_const_iterator Faces_begin,
Face_const_iterator Faces_end) const
Face_const_iterator Faces_end)
{
H_index h_index(m_pm.halfedges_begin(), m_pm.halfedges_end());
m_h_index = &h_index;
Face_const_iterator f_iter;
for (f_iter = Faces_begin; f_iter != Faces_end; ++f_iter)
write_face(f_iter, h_index);
write_face(f_iter);
m_h_index = 0;
}
//void skip_line(){
@ -320,12 +354,26 @@ protected:
out() << index << ' ';
}
std::size_t get_v_index(Vertex_const_iterator vic) const
{
CGAL_assertion(m_v_index);
return (*m_v_index)[vic];
}
std::size_t get_h_index(Halfedge_const_iterator hic) const
{
CGAL_assertion(m_h_index);
return (*m_h_index)[hic];
}
//void write_string(const char *str) {
// out() << str << std::endl;
// }
std::ostream * m_out;
const PM & m_pm;
H_index * m_h_index;
V_index * m_v_index;
};
CGAL_END_NAMESPACE

View File

@ -47,57 +47,26 @@ CGAL_BEGIN_NAMESPACE
template <class PM, class Writer>
void write_pm(const PM & pm, Writer & writer, std::ostream &)
{
//typedef Planar_map_2<Dcel,Traits> PM;
typedef typename PM::Halfedge_const_iterator HCI;
typedef typename PM::Vertex_const_iterator VCI;
typedef typename PM::Face_const_iterator FCI;
typedef Inverse_index<HCI> H_index;
typedef Inverse_index<VCI> V_index;
//H_index h_index(pm.halfedges_begin(), pm.halfedges_end());
//V_index v_index(pm.vertices_begin(), pm.vertices_end());
// Print header. write #vertices, #halfedges, #faces.
writer.write_title("Printing Planar map" /*, pm.number_of_vertices(), pm.number_of_halfedges(), pm.number_of_faces()*/);
writer.write_comment("Printing number of vertices halfedges and faces in Planar map");
writer.write_title("Begin Planar Map");
writer.write_comment("Number of vertices halfedges and faces in Planar map");
writer.write_pm_vhf_sizes(pm.number_of_vertices(),
pm.number_of_halfedges(),
pm.number_of_faces());
writer.write_comment("vertices", pm.number_of_vertices());
//writer.write_vertices(pm.vertices_begin(), pm.vertices_end());
VCI v_iter;
for (v_iter = pm.vertices_begin(); v_iter != pm.vertices_end(); ++v_iter)
writer.write_vertex(v_iter);
writer.write_vertices(pm.vertices_begin(), pm.vertices_end());
writer.write_comment("halfedges", pm.number_of_halfedges());
//writer.write_halfedges_header();
// writer.write_index( v_index[ VCI(ei->target())] );*/
// writer.write_halfedges(pm.halfedges_begin(), pm.halfedges_end());
V_index v_index(pm.vertices_begin(), pm.vertices_end());
HCI h_iter;
for (h_iter = pm.halfedges_begin(); h_iter != pm.halfedges_end(); ++h_iter)
writer.write_halfedge(h_iter, v_index);
writer.write_halfedges(pm.halfedges_begin(), pm.halfedges_end());
writer.write_comment("faces", pm.number_of_faces());
//writer.write_faces_header();
writer.write_faces(pm.faces_begin(), pm.faces_end());
//typename Planar_map_2<Dcel,Traits>::Holes_const_iterator iccbit;
//typename Planar_map_2<Dcel,Traits>::Ccb_halfedge_const_circulator ccb_circ;
//int ck;
// writer.write_faces(pm.faces_begin(), pm.faces_end());
H_index h_index(pm.halfedges_begin(), pm.halfedges_end());
FCI f_iter;
for (f_iter = pm.faces_begin(); f_iter != pm.faces_end(); ++f_iter)
writer.write_face(f_iter, h_index);
writer.write_title("End of Planar map");
writer.write_title("End Planar Map");
//writer.write_footer();
}
CGAL_END_NAMESPACE
#endif