Moved Arrangement_2 to Arrangement_on_surface_2

This commit is contained in:
Efi Fogel 2007-08-22 12:30:17 +00:00
parent 36de4299af
commit c01f02a84d
14 changed files with 3925 additions and 0 deletions

View File

@ -0,0 +1,121 @@
// Copyright (c) 2005 Tel-Aviv University (Israel).
// All rights reserved.
//
// This file is part of CGAL (www.cgal.org); you may redistribute it under
// the terms of the Q Public License version 1.0.
// See the file LICENSE.QPL distributed with CGAL.
//
// Licensees holding a valid commercial license may use this file in
// accordance with the commercial license agreement provided with the software.
//
// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
//
// $URL$
// $Id$
//
//
// Author(s) : Michal Meyerovitch <gorgymic@post.tau.ac.il>
// Ron Wein <wein@post.tau.ac.il>
// (based on old version by Ester Ezra)
#ifndef CGAL_ARR_IOSTREAM_H
#define CGAL_ARR_IOSTREAM_H
/*! \file
* Definition of the I/O operators for the Arrangement_2<Traits,Dcel> class.
*/
#include <CGAL/Arrangement_2.h>
#include <CGAL/IO/Arr_text_formatter.h>
#include <CGAL/IO/Arrangement_2_writer.h>
#include <CGAL/IO/Arrangement_2_reader.h>
#include <iostream>
CGAL_BEGIN_NAMESPACE
/*!
* Write an arrangement to an output stream using a given formatter.
* \param arr The arrangement.
* \param os The output stream.
* \param format The formatter.
*/
template <class Traits, class Dcel, class Formatter>
std::ostream& write (const Arrangement_2<Traits,Dcel>& arr,
std::ostream& os,
Formatter& format)
{
typedef Arrangement_2<Traits,Dcel> Arrangement_2;
typedef Arrangement_2_writer<Arrangement_2> Arr_writer;
Arr_writer writer (arr);
format.set_out (os);
writer (format);
return (os);
}
/*!
* Output operator (importer).
* \param os The output stream.
* \param arr The arrangement.
*/
template <class Traits, class Dcel>
std::ostream& operator<< (std::ostream& os,
const Arrangement_2<Traits,Dcel>& arr)
{
typedef Arrangement_2<Traits,Dcel> Arrangement_2;
typedef Arrangement_2_writer<Arrangement_2> Arr_writer;
typedef Arr_text_formatter<Arrangement_2> Text_formatter;
Text_formatter text_format (os);
Arr_writer writer (arr);
writer (text_format);
return (os);
}
/*!
* Read an arrangement from an input stream using a given formatter.
* \param arr The arrangement.
* \param os The output stream.
* \param format The formatter.
*/
template <class Traits, class Dcel, class Formatter>
std::istream& read (Arrangement_2<Traits,Dcel>& arr,
std::istream& is,
Formatter& format)
{
typedef Arrangement_2<Traits,Dcel> Arrangement_2;
typedef Arrangement_2_reader<Arrangement_2> Arr_reader;
Arr_reader reader(arr);
format.set_in (is);
reader (format);
return (is);
}
/*!
* Output operator (exporter).
* \param is The input stream.
* \param arr The arrangement.
*/
template <class Traits, class Dcel>
std::istream& operator>> (std::istream& is,
Arrangement_2<Traits,Dcel>& arr)
{
typedef Arrangement_2<Traits,Dcel> Arrangement_2;
typedef Arrangement_2_reader<Arrangement_2> Arr_reader;
typedef Arr_text_formatter<Arrangement_2> Text_formatter;
Text_formatter text_format (is);
Arr_reader reader(arr);
reader (text_format);
return (is);
}
CGAL_END_NAMESPACE
#endif

View File

@ -0,0 +1,94 @@
// Copyright (c) 2005 Tel-Aviv University (Israel).
// All rights reserved.
//
// This file is part of CGAL (www.cgal.org); you may redistribute it under
// the terms of the Q Public License version 1.0.
// See the file LICENSE.QPL distributed with CGAL.
//
// Licensees holding a valid commercial license may use this file in
// accordance with the commercial license agreement provided with the software.
//
// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
//
// $URL$
// $Id$
//
// Author(s) : Efi Fogel <efif@post.tau.ac.il>
#ifndef CGAL_ARR_POSTSCRIPT_FILE_STREAM_H
#define CGAL_ARR_POSTSCRIPT_FILE_STREAM_H
/*! \file
* Postscript output stream for the Arrangement_2<Traits,Dcel> class.
*/
#include <CGAL/IO/Postscript_file_stream.h>
#include <CGAL/Arrangement_2.h>
CGAL_BEGIN_NAMESPACE
/*! Global exporter of an Arrangement_2 object to a Postscript stream */
class Arr_postscript_file_stream : public Postscript_file_stream {
public:
/*! Constructor */
Arr_postscript_file_stream(double w,double h,
leda_string name = "CGAL_arr.ps") :
Postscript_file_stream(w, h, name),
m_point_color(RED), m_curve_color(BLUE)
{}
/*! Constructor */
Arr_postscript_file_stream(leda_string name = "CGAL_arr.ps") :
Postscript_file_stream(name),
m_point_color(RED), m_curve_color(BLUE)
{}
/*! Set the color of the points */
void set_point_color(Color color) { m_point_color = color; }
/*! Obtain the color of the points */
Color point_color() const { return m_point_color; }
/*! Set the color of the curves */
void set_curve_color(Color color) { m_curve_color = color; }
/*! Obtain the color of the curves */
Color curve_color() const { return m_curve_color; }
private:
/*! The color of the points */
Color m_point_color;
/*! The color of the curves */
Color m_curve_color;
};
/*! Export an Arrangement_2 object to a Postscript stream
* \param ps_stream the Postscript stream
* \param arr the arrangement
* \return the Postscript stream
*/
template<typename Traits, typename Dcel> Arr_postscript_file_stream &
operator<<(Arr_postscript_file_stream & ps_stream,
const Arrangement_2<Traits, Dcel> & arr)
{
// Draw the curves:
ps_stream << ps_stream.curve_color();
typename Arrangement_2<Traits, Dcel>::Edge_const_iterator ei;
for (ei = arr.edges_begin(); ei != arr.edges_end(); ++ei) {
ps_stream << ei->curve();
}
// Draw the points:
ps_stream << ps_stream.point_color();
typename Arrangement_2<Traits, Dcel>::Vertex_const_iterator vi;
for (vi = arr.vertices_begin(); vi != arr.vertices_end(); ++vi) {
ps_stream << vi->point();
}
return ps_stream;
}
CGAL_END_NAMESPACE
#endif

View File

@ -0,0 +1,645 @@
// Copyright (c) 2005 Tel-Aviv University (Israel).
// All rights reserved.
//
// This file is part of CGAL (www.cgal.org); you may redistribute it under
// the terms of the Q Public License version 1.0.
// See the file LICENSE.QPL distributed with CGAL.
//
// Licensees holding a valid commercial license may use this file in
// accordance with the commercial license agreement provided with the software.
//
// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
//
// $URL$
// $Id$
//
//
// Author(s) : Michal Meyerovitch <gorgymic@post.tau.ac.il>
// Ron Wein <wein@post.tau.ac.il>
// (based on old version by Ester Ezra)
#ifndef CGAL_ARR_TEXT_FORMATTER_H
#define CGAL_ARR_TEXT_FORMATTER_H
/*! \file
* The header file for the text-formatter classes.
*/
#include <CGAL/basic.h>
#include <iostream>
CGAL_BEGIN_NAMESPACE
/*! \class
* A class defining a textual (ASCII) input/output format for arrangements
* and supports reading and writing an arrangement from or to input/output
* streams.
*/
template <class Arrangement_>
class Arr_text_formatter
{
public:
typedef Arrangement_ Arrangement_2;
typedef typename Arrangement_2::Size Size;
typedef typename Arrangement_2::Dcel Dcel;
typedef typename Arrangement_2::Traits_2 Traits_2;
typedef typename Traits_2::X_monotone_curve_2 X_monotone_curve_2;
typedef typename Traits_2::Point_2 Point_2;
typedef typename Arrangement_2::Vertex_handle Vertex_handle;
typedef typename Arrangement_2::Halfedge_handle Halfedge_handle;
typedef typename Arrangement_2::Face_handle Face_handle;
typedef typename Arrangement_2::Vertex_const_handle Vertex_const_handle;
typedef typename Arrangement_2::Halfedge_const_handle Halfedge_const_handle;
typedef typename Arrangement_2::Face_const_handle Face_const_handle;
protected:
typedef typename Dcel::Vertex DVertex;
typedef typename Dcel::Halfedge DHalfedge;
typedef typename Dcel::Face DFace;
// Data members:
std::ostream *m_out;
IO::Mode m_old_out_mode;
std::istream *m_in;
IO::Mode m_old_in_mode;
public:
/*! Default constructor.*/
Arr_text_formatter ():
m_out (NULL),
m_in (NULL)
{}
/*! Construct an output formatter. */
Arr_text_formatter (std::ostream& os) :
m_out (&os),
m_in(NULL)
{}
/*! Construct an input formatter. */
Arr_text_formatter (std::istream& is) :
m_out(NULL),
m_in(&is)
{}
/*! Destructor. */
virtual ~Arr_text_formatter()
{}
/*! Set the output stream. */
void set_out (std::ostream& os)
{
m_out = &os;
return;
}
/*! Set the input stream. */
void set_in (std::istream& is)
{
m_in = &is;
return;
}
/*! Get the output stream. */
inline std::ostream& out ()
{
CGAL_assertion (m_out != NULL);
return (*m_out);
}
/*! Get the input stream. */
inline std::istream& in ()
{
CGAL_assertion (m_in != NULL);
return (*m_in);
}
/// \name Global write functions.
//@{
/*! Write a begin-arrangement comment. */
void write_arrangement_begin ()
{
CGAL_assertion (m_out != NULL);
m_old_out_mode = get_mode(*m_out);
set_ascii_mode (*m_out);
_write_comment ("BEGIN ARRANGEMENT");
return;
}
/*! Write an end-arrangement comment. */
void write_arrangement_end()
{
_write_comment ("END ARRANGEMENT");
set_mode (*m_out, m_old_out_mode);
return;
}
/*! Write a labeled size value. */
void write_size (const char *label, Size size)
{
_write_comment (label);
out() << size << '\n';
return;
}
/*! Write a begin-vertices comment. */
void write_vertices_begin ()
{
_write_comment ("BEGIN VERTICES");
return;
}
/*! Write an end-vertices comment. */
void write_vertices_end ()
{
_write_comment ("END VERTICES");
return;
}
/*! Write a begin-edges comment. */
void write_edges_begin ()
{
_write_comment ("BEGIN EDGES");
return;
}
/*! Write an end-edges comment. */
void write_edges_end ()
{
_write_comment ("END EDGES");
return;
}
/*! Write a begin-faces comment. */
void write_faces_begin ()
{
_write_comment ("BEGIN FACES");
return;
}
/*! Write an end-faces comment. */
void write_faces_end ()
{
_write_comment ("END FACES");
return;
}
//@}
/// \name Write a vertex.
//@{
void write_vertex_begin ()
{}
void write_vertex_end ()
{
out() << std::endl;
return;
}
virtual void write_point (const Point_2& p)
{
out() << p;
return;
}
virtual void write_vertex_data (Vertex_const_handle )
{}
//@}
/// \name Write an edge.
//@{
void write_edge_begin ()
{}
void write_edge_end ()
{
out() << std::endl;
return;
}
void write_vertex_index (int idx)
{
out() << idx << ' ';
return;
}
virtual void write_x_monotone_curve (const X_monotone_curve_2& cv)
{
out() << cv;
return;
}
virtual void write_halfedge_data (Halfedge_const_handle )
{}
//@}
/// \name Write a face.
//@{
void write_face_begin ()
{
_write_comment ("BEGIN FACE");
return;
}
void write_face_end ()
{
_write_comment ("END FACE");
}
void write_outer_ccb_begin ()
{}
void write_outer_ccb_end ()
{}
void write_holes_begin ()
{}
void write_holes_end ()
{}
virtual void write_face_data (Face_const_handle )
{}
void write_ccb_halfedges_begin()
{}
void write_ccb_halfedges_end()
{
out() << std::endl;
}
void write_halfedge_index (int idx)
{
out() << idx << ' ';
return;
}
void write_isolated_vertices_begin ()
{}
void write_isolated_vertices_end ()
{
out() << std::endl;
}
//@}
/// \name Global read functions.
//@{
/*! Start reading an arrangement. */
void read_arrangement_begin ()
{
CGAL_assertion (m_in != NULL);
m_old_in_mode = get_mode(*m_in);
set_ascii_mode(*m_in);
_skip_comments();
}
/*! Read the arrangement edge. */
void read_arrangement_end()
{
_skip_comments();
set_mode(*m_in, m_old_in_mode);
}
/*! Read a size value (with a label comment line before it). */
Size read_size (const char* /* title */ = NULL)
{
std::size_t val;
_skip_comments();
in() >> val;
_skip_until_EOL();
return (val);
}
/*! Reading the arrangement vertices. */
void read_vertices_begin()
{
_skip_comments();
}
void read_vertices_end()
{
_skip_comments();
}
/*! Reading the arrangement edges. */
void read_edges_begin()
{
_skip_comments();
}
void read_edges_end()
{
_skip_comments();
}
/*! Reading the arrangement faces. */
void read_faces_begin()
{
_skip_comments();
}
void read_faces_end()
{
_skip_comments();
}
//@}
/// \name Reading a vertex.
//@{
void read_vertex_begin ()
{}
void read_vertex_end ()
{}
virtual void read_point (Point_2& p)
{
in() >> p;
_skip_until_EOL();
return;
}
virtual void read_vertex_data (Vertex_handle )
{}
//@}
/// \name Reading an edge.
//@{
void read_edge_begin ()
{}
void read_edge_end ()
{}
int read_vertex_index ()
{
int val;
in() >> val;
return (val);
}
virtual void read_x_monotone_curve (X_monotone_curve_2& cv)
{
in() >> cv;
_skip_until_EOL();
return;
}
virtual void read_halfedge_data (Halfedge_handle )
{}
/// \name Reading a face.
//@{
void read_face_begin ()
{
_skip_comments();
}
void read_face_end ()
{
_skip_comments();
}
void read_outer_ccb_begin ()
{}
void read_outer_ccb_end ()
{}
int read_halfedge_index ()
{
int val;
in() >> val;
return (val);
}
void read_holes_begin ()
{}
void read_holes_end ()
{}
void read_inner_ccb_begin ()
{
_skip_comments();
}
void read_inner_ccb_end ()
{}
void read_ccb_halfedges_begin()
{}
void read_ccb_halfedges_end()
{
_skip_until_EOL ();
}
void read_isolated_vertices_begin ()
{}
void read_isolated_vertices_end ()
{
_skip_until_EOL();
}
virtual void read_face_data (Face_handle )
{}
//@}
protected:
/*! Write a comment line. */
void _write_comment (const char *str)
{
out() << "# " << str << std::endl;
return;
}
/*! Skip until end of line. */
void _skip_until_EOL ()
{
CGAL_assertion (m_in != NULL);
int c;
while ((c = m_in->get()) != EOF && c != '\n');
return;
}
/*! Skip comment lines. */
void _skip_comments ()
{
CGAL_assertion (m_in != NULL);
int c;
while ((c = m_in->get()) != EOF && c == '#')
_skip_until_EOL();
m_in->putback (c);
return;
}
};
/*! \class
* A class defining a textual (ASCII) input/output format for arrangements
* that store auxiliary dat with their face records, as they are templated
* by a face-extended DCEL class.
*/
template <class Arrangement_>
class Arr_face_extended_text_formatter :
public Arr_text_formatter<Arrangement_>
{
public:
typedef Arrangement_ Arrangement_2;
typedef Arr_text_formatter<Arrangement_2> Base;
typedef typename Base::Size Size;
typedef typename Base::Dcel Dcel;
typedef typename Base::Traits_2 Traits_2;
typedef typename Traits_2::X_monotone_curve_2 X_monotone_curve_2;
typedef typename Traits_2::Point_2 Point_2;
typedef typename Base::Vertex_handle Vertex_handle;
typedef typename Base::Halfedge_handle Halfedge_handle;
typedef typename Base::Face_handle Face_handle;
typedef typename Base::Vertex_const_handle Vertex_const_handle;
typedef typename Base::Halfedge_const_handle Halfedge_const_handle;
typedef typename Base::Face_const_handle Face_const_handle;
/*! Default constructor.*/
Arr_face_extended_text_formatter () :
Base ()
{}
/*! Construct an output formatter. */
Arr_face_extended_text_formatter (std::ostream& os) :
Base (os)
{}
/*! Construct an input formatter. */
Arr_face_extended_text_formatter (std::istream& is) :
Base (is)
{}
/*! Write the auxiliary data associated with the given face. */
virtual void write_face_data (Face_const_handle f)
{
this->out() << f->data() << '\n';
}
/*! Read a face-data object and attach it to the given face. */
virtual void read_face_data (Face_handle f)
{
this->in() >> f->data();
this->_skip_until_EOL();
}
};
/*! \class
* A class defining a textual (ASCII) input/output format for arrangements
* that store auxiliary dat with all their DCEL records, as they are templated
* by a extended DCEL class.
*/
template <class Arrangement_>
class Arr_extended_dcel_text_formatter :
public Arr_text_formatter<Arrangement_>
{
public:
typedef Arrangement_ Arrangement_2;
typedef Arr_text_formatter<Arrangement_2> Base;
typedef typename Base::Size Size;
typedef typename Base::Dcel Dcel;
typedef typename Base::Traits_2 Traits_2;
typedef typename Traits_2::X_monotone_curve_2 X_monotone_curve_2;
typedef typename Traits_2::Point_2 Point_2;
typedef typename Base::Vertex_handle Vertex_handle;
typedef typename Base::Halfedge_handle Halfedge_handle;
typedef typename Base::Face_handle Face_handle;
typedef typename Base::Vertex_const_handle Vertex_const_handle;
typedef typename Base::Halfedge_const_handle Halfedge_const_handle;
typedef typename Base::Face_const_handle Face_const_handle;
/*! Default constructor.*/
Arr_extended_dcel_text_formatter () :
Base ()
{}
/*! Construct an output formatter. */
Arr_extended_dcel_text_formatter (std::ostream& os) :
Base (os)
{}
/*! Construct an input formatter. */
Arr_extended_dcel_text_formatter (std::istream& is) :
Base (is)
{}
/*! Write the auxiliary data associated with the given vertex. */
virtual void write_vertex_data (Vertex_const_handle v)
{
this->out() << '\n' << v->data();
}
/*! Read a vertex-data object and attach it to the given vertex. */
virtual void read_vertex_data (Vertex_handle v)
{
this->in() >> v->data();
this->_skip_until_EOL();
}
/*! Write the auxiliary data associated with the given halfedge. */
virtual void write_halfedge_data (Halfedge_const_handle he)
{
this->out() << '\n' << he->data();
}
/*! Read a halfedge-data object and attach it to the given halfedge. */
virtual void read_halfedge_data (Halfedge_handle he)
{
this->in() >> he->data();
this->_skip_until_EOL();
}
/*! Write the auxiliary data associated with the given face. */
virtual void write_face_data (Face_const_handle f)
{
this->out() << f->data() << '\n';
}
/*! Read a face-data object and attach it to the given face. */
virtual void read_face_data (Face_handle f)
{
this->in() >> f->data();
this->_skip_until_EOL();
}
};
CGAL_END_NAMESPACE
#endif

View File

@ -0,0 +1,133 @@
// Copyright (c) 2005 Tel-Aviv University (Israel).
// All rights reserved.
//
// This file is part of CGAL (www.cgal.org); you may redistribute it under
// the terms of the Q Public License version 1.0.
// See the file LICENSE.QPL distributed with CGAL.
//
// Licensees holding a valid commercial license may use this file in
// accordance with the commercial license agreement provided with the software.
//
// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
//
// $URL$
// $Id$
//
//
// Author(s) : Ron Wein <wein@post.tau.ac.il>
#ifndef CGAL_ARR_WITH_HISTORY_2_READER_H
#define CGAL_ARR_WITH_HISTORY_2_READER_H
/*! \file
* The header file for the Arr_with_history_2_reader<Arrangement> class.
*/
#include <CGAL/IO/Arrangement_2_reader.h>
#include <CGAL/Arrangement_2/Arr_with_history_accessor.h>
CGAL_BEGIN_NAMESPACE
/*! \class
* An auxiliary class for reading an arrangement with history from an
* input stream.
*/
template <class ArrWithHistory_>
class Arr_with_history_2_reader : private Arrangement_2_reader<ArrWithHistory_>
{
public:
typedef ArrWithHistory_ Arr_with_history_2;
typedef Arr_with_history_2_reader<Arr_with_history_2> Self;
protected:
typedef Arrangement_2_reader<Arr_with_history_2> Base;
typedef typename Arr_with_history_2::Size Size;
typedef typename Arr_with_history_2::Curve_handle Curve_handle;
typedef typename Arr_with_history_2::Halfedge_handle Halfedge_handle;
typedef Arr_with_history_accessor<Arr_with_history_2> Arr_with_hist_access;
typedef typename Arr_with_history_2::Curve_2 Curve_2;
protected:
// Data members:
Curve_2 m_in_curve;
Arr_with_hist_access m_arr_with_hist_access;
private:
// Copy constructor and assignment operator - not supported.
Arr_with_history_2_reader (const Self& );
Self& operator= (const Self& );
public:
/*! Constructor. */
Arr_with_history_2_reader (Arr_with_history_2& arr) :
Base (arr),
m_arr_with_hist_access (arr)
{}
/*! Read the arrangement. */
template <class Formatter>
void operator()(Formatter& formatter)
{
// Read the arrangement (without history).
Base::operator() (formatter);
// Read the inducing curves.
formatter.read_curves_begin();
const Size number_of_curves = formatter.read_size("number_of_curves");
Size k;
for (k = 0; k < number_of_curves; k++)
_read_curve (formatter);
formatter.read_curves_end();
return;
}
protected:
/*! Read a curve with its induced edges. */
template <class Formatter>
void _read_curve (Formatter& formatter)
{
formatter.read_curve_begin();
// Read the curve.
formatter.read_curve (m_in_curve);
// Insert the curve to the list of inducing curves of the arrangement.
Curve_handle new_cv = m_arr_with_hist_access.new_curve (m_in_curve);
// Read the induced edges.
formatter.read_induced_edges_begin();
const Size number_of_edges = formatter.read_size("induced_edges");
std::size_t curr_idx;
Halfedge_handle curr_he;
Size k;
for (k = 0; k < number_of_edges; k++)
{
curr_idx = formatter.read_halfedge_index();
curr_he = Halfedge_handle (this->m_halfedges[curr_idx]);
// Connect the curve and the edge it induces.
m_arr_with_hist_access.connect_curve_edge (new_cv, curr_he);
}
formatter.read_induced_edges_end();
formatter.read_curve_end();
return;
}
};
CGAL_END_NAMESPACE
#endif

View File

@ -0,0 +1,126 @@
// Copyright (c) 2005 Tel-Aviv University (Israel).
// All rights reserved.
//
// This file is part of CGAL (www.cgal.org); you may redistribute it under
// the terms of the Q Public License version 1.0.
// See the file LICENSE.QPL distributed with CGAL.
//
// Licensees holding a valid commercial license may use this file in
// accordance with the commercial license agreement provided with the software.
//
// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
//
// $URL$
// $Id$
//
//
// Author(s) : Ron Wein <wein@post.tau.ac.il>
#ifndef CGAL_ARR_WITH_HISTORY_2_WRITER_H
#define CGAL_ARR_WITH_HISTORY_2_WRITER_H
/*! \file
* The header file for the Arr_with_history_2_writer<Arrangement> class.
*/
#include <CGAL/IO/Arrangement_2_writer.h>
CGAL_BEGIN_NAMESPACE
/*! \class
* An auxiliary class for writing an arrangement with history to an
* output stream.
*/
template <class ArrWithHistory_>
class Arr_with_history_2_writer : private Arrangement_2_writer<ArrWithHistory_>
{
public:
typedef ArrWithHistory_ Arr_with_history_2;
typedef Arr_with_history_2_writer<Arr_with_history_2> Self;
protected:
typedef Arrangement_2_writer<Arr_with_history_2> Base;
typedef typename Arr_with_history_2::Size Size;
typedef typename Arr_with_history_2::Curve_const_iterator
Curve_const_iterator;
typedef typename Arr_with_history_2::Curve_const_handle
Curve_const_handle;
typedef typename Arr_with_history_2::Halfedge_const_handle
Halfedge_const_handle;
typedef typename Arr_with_history_2::Induced_edge_iterator
Induced_edge_iterator;
private:
// Copy constructor and assignment operator - not supported.
Arr_with_history_2_writer (const Self& );
Self& operator= (const Self& );
public:
/*! Constructor. */
Arr_with_history_2_writer (const Arr_with_history_2& arr) :
Base (arr)
{}
/*! Write the arrangement. */
template <class Formatter>
void operator() (Formatter& formatter)
{
// Write the arrangement (without history).
Base::operator() (formatter);
// Write the inducing curves.
formatter.write_curves_begin();
formatter.write_size ("number_of_curves", this->m_arr.number_of_curves());
Curve_const_iterator cvit;
for (cvit = this->m_arr.curves_begin();
cvit != this->m_arr.curves_end(); ++cvit)
{
_write_curve (formatter, cvit);
}
formatter.write_curves_end();
return;
}
protected:
/*! Write a curve with its induced edges. */
template <class Formatter>
void _write_curve (Formatter& formatter, Curve_const_iterator cvit) const
{
Curve_const_handle cv = cvit;
formatter.write_curve_begin();
// Write the curve.
formatter.write_curve (*cv);
// Write the induced edges.
formatter.write_induced_edges_begin();
formatter.write_size ("induced_edges",
this->m_arr.number_of_induced_edges(cv));
Induced_edge_iterator ieit;
for (ieit = this->m_arr.induced_edges_begin(cv);
ieit != this->m_arr.induced_edges_end(cv); ++ieit)
{
formatter.write_halfedge_index (this->_get_index (*ieit));
}
formatter.write_induced_edges_end();
formatter.write_curve_end();
return;
}
};
CGAL_END_NAMESPACE
#endif

View File

@ -0,0 +1,125 @@
// Copyright (c) 2005 Tel-Aviv University (Israel).
// All rights reserved.
//
// This file is part of CGAL (www.cgal.org); you may redistribute it under
// the terms of the Q Public License version 1.0.
// See the file LICENSE.QPL distributed with CGAL.
//
// Licensees holding a valid commercial license may use this file in
// accordance with the commercial license agreement provided with the software.
//
// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
//
// $URL$
// $Id$
//
//
// Author(s) : Ron Wein <wein@post.tau.ac.il>
#ifndef CGAL_ARR_WITH_HISTORY_IOSTREAM_H
#define CGAL_ARR_WITH_HISTORY_IOSTREAM_H
/*! \file
* Definition of the I/O operators for the
* Arrangement_with_history_2<Traits,Dcel> class.
*/
#include <CGAL/Arrangement_with_history_2.h>
#include <CGAL/IO/Arr_with_history_text_formatter.h>
#include <CGAL/IO/Arr_text_formatter.h>
#include <CGAL/IO/Arr_with_history_2_writer.h>
#include <CGAL/IO/Arr_with_history_2_reader.h>
#include <iostream>
CGAL_BEGIN_NAMESPACE
/*!
* Write an arrangement with history to an output stream using a given
* formatter.
* \param arr The arrangement-with-history instance.
* \param os The output stream.
* \param format The formatter.
*/
template <class Traits, class Dcel, class Formatter>
std::ostream& write (const Arrangement_with_history_2<Traits,Dcel>& arr,
std::ostream& os,
Formatter& format)
{
typedef Arrangement_with_history_2<Traits,Dcel> Arr_with_history_2;
typedef Arr_with_history_2_writer<Arr_with_history_2> Arr_writer;
Arr_writer writer (arr);
format.set_out (os);
writer (format);
return (os);
}
/*!
* Output operator (importer).
* \param os The output stream.
* \param arr The arrangement-with-history instance.
*/
template <class Traits, class Dcel>
std::ostream& operator<< (std::ostream& os,
const Arrangement_with_history_2<Traits,Dcel>& arr)
{
typedef Arrangement_with_history_2<Traits,Dcel> Arr_with_history_2;
typedef Arr_with_history_2_writer<Arr_with_history_2> Arr_writer;
typedef Arr_with_history_text_formatter
<Arr_text_formatter<Arr_with_history_2> > Text_formatter;
Text_formatter text_format (os);
Arr_writer writer (arr);
writer (text_format);
return (os);
}
/*!
* Read an arrangement with history from an input stream using a given
* formatter.
* \param arr The arrangement-with-history instance.
* \param os The output stream.
* \param format The formatter.
*/
template <class Traits, class Dcel, class Formatter>
std::istream& read (Arrangement_with_history_2<Traits,Dcel>& arr,
std::istream& is,
Formatter& format)
{
typedef Arrangement_with_history_2<Traits,Dcel> Arr_with_history_2;
typedef Arr_with_history_2_reader<Arr_with_history_2> Arr_reader;
Arr_reader reader (arr);
format.set_in (is);
reader (format);
return (is);
}
/*!
* Output operator (exporter).
* \param is The input stream.
* \param arr The arrangement-with-history instance.
*/
template <class Traits, class Dcel>
std::istream& operator>> (std::istream& is,
Arrangement_with_history_2<Traits,Dcel>& arr)
{
typedef Arrangement_with_history_2<Traits,Dcel> Arr_with_history_2;
typedef Arr_with_history_2_reader<Arr_with_history_2> Arr_reader;
typedef Arr_with_history_text_formatter
<Arr_text_formatter<Arr_with_history_2> > Text_formatter;
Text_formatter text_format (is);
Arr_reader reader (arr);
reader (text_format);
return (is);
}
CGAL_END_NAMESPACE
#endif

View File

@ -0,0 +1,189 @@
// Copyright (c) 2005 Tel-Aviv University (Israel).
// All rights reserved.
//
// This file is part of CGAL (www.cgal.org); you may redistribute it under
// the terms of the Q Public License version 1.0.
// See the file LICENSE.QPL distributed with CGAL.
//
// Licensees holding a valid commercial license may use this file in
// accordance with the commercial license agreement provided with the software.
//
// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
//
// $URL$
// $Id$
//
//
// Author(s) : Ron Wein <wein@post.tau.ac.il>
#ifndef CGAL_ARR_WITH_HISTORY_TEXT_FORMATTER_H
#define CGAL_ARR_WITH_HISTORY_TEXT_FORMATTER_H
/*! \file
* The header file for the text-formatter classes.
*/
#include <CGAL/basic.h>
#include <iostream>
CGAL_BEGIN_NAMESPACE
/*! \class
* A class defining a textual (ASCII) input/output format for arrangements
* with history and supports reading and writing an arrangement from or to
* input/output streams.
*/
template <class ArrFormatter_>
class Arr_with_history_text_formatter : public ArrFormatter_
{
public:
typedef ArrFormatter_ Base;
typedef Arr_with_history_text_formatter<Base> Self;
typedef typename Base::Arrangement_2 Arr_with_history_2;
typedef typename Arr_with_history_2::Size Size;
typedef typename Arr_with_history_2::Dcel Dcel;
typedef typename Arr_with_history_2::Traits_2 Traits_2;
typedef typename Arr_with_history_2::Curve_2 Curve_2;
typedef typename Arr_with_history_2::X_monotone_curve_2 X_monotone_curve_2;
typedef typename Arr_with_history_2::Point_2 Point_2;
typedef typename Arr_with_history_2::Vertex_handle Vertex_handle;
typedef typename Arr_with_history_2::Halfedge_handle Halfedge_handle;
typedef typename Arr_with_history_2::Face_handle Face_handle;
typedef typename Arr_with_history_2::Vertex_const_handle
Vertex_const_handle;
typedef typename Arr_with_history_2::Halfedge_const_handle
Halfedge_const_handle;
typedef typename Arr_with_history_2::Face_const_handle
Face_const_handle;
/*! Default constructor.*/
Arr_with_history_text_formatter ():
Base ()
{}
/*! Construct an output formatter. */
Arr_with_history_text_formatter (std::ostream& os) :
Base (os)
{}
/*! Construct an input formatter. */
Arr_with_history_text_formatter (std::istream& is) :
Base (is)
{}
/// \name Functions for writing curves.
//@{
/*! Write a begin-curves comment. */
void write_curves_begin ()
{
__write_comment ("BEGIN CURVES");
return;
}
/*! Write an end-curves comment. */
void write_curves_end ()
{
__write_comment ("END CURVES");
return;
}
/*! Write a specific curve. */
void write_curve_begin ()
{}
void write_curve_end ()
{}
void write_curve (const Curve_2& c)
{
this->out() << c << std::endl;
return;
}
void write_induced_edges_begin ()
{}
void write_induced_edges_end ()
{
this->out() << std::endl;
}
//@}
/// \name Functions for reading curves.
//@{
/*! Start reading the curves. */
void read_curves_begin ()
{
__skip_comments();
}
/*! Read the end-curves message. */
void read_curves_end()
{
__skip_comments();
}
/*! Read a specific curve. */
void read_curve_begin ()
{}
void read_curve_end ()
{}
void read_curve (Curve_2& c)
{
this->in() >> c;
__skip_until_EOL();
return;
}
void read_induced_edges_begin ()
{}
void read_induced_edges_end ()
{
__skip_until_EOL();
}
//@}
private:
/*! Write a comment line. */
void __write_comment (const char *str)
{
this->out() << "# " << str << std::endl;
return;
}
/*! Skip until end of line. */
void __skip_until_EOL ()
{
int c;
while ((c = this->in().get()) != EOF && c != '\n');
return;
}
/*! Skip comment lines. */
void __skip_comments ()
{
int c;
while ((c = this->in().get()) != EOF && c == '#')
__skip_until_EOL();
this->in().putback (c);
return;
}
};
CGAL_END_NAMESPACE
#endif

View File

@ -0,0 +1,416 @@
// Copyright (c) 2005 Tel-Aviv University (Israel).
// All rights reserved.
//
// This file is part of CGAL (www.cgal.org); you may redistribute it under
// the terms of the Q Public License version 1.0.
// See the file LICENSE.QPL distributed with CGAL.
//
// Licensees holding a valid commercial license may use this file in
// accordance with the commercial license agreement provided with the software.
//
// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
//
// $URL$
// $Id$
//
//
// Author(s) : Michal Meyerovitch <gorgymic@post.tau.ac.il>
// Ron Wein <wein@post.tau.ac.il>
// (based on old version by Ester Ezra)
#ifndef CGAL_IO_ARRANGEMENT_2_READER_H
#define CGAL_IO_ARRANGEMENT_2_READER_H
/*! \file
* The header file for the Arrangement_2_reader<Arrangement> class.
*/
#include <CGAL/Arr_accessor.h>
#include <CGAL/iterator.h>
#include <CGAL/circulator.h>
#include <algorithm>
#include <iostream>
CGAL_BEGIN_NAMESPACE
/*! \class
* An auxiliary class for reading an arrangement from an input stream.
*/
template <class Arrangement_>
class Arrangement_2_reader
{
public:
typedef Arrangement_ Arrangement_2;
typedef Arrangement_2_reader<Arrangement_2> Self;
protected:
typedef typename Arrangement_2::Size Size;
typedef typename Arrangement_2::Vertex_iterator Vertex_iterator;
typedef typename Arrangement_2::Halfedge_iterator Halfedge_iterator;
typedef typename Arrangement_2::Face_iterator Face_iterator;
typedef typename Arrangement_2::Vertex_handle Vertex_handle;
typedef typename Arrangement_2::Halfedge_handle Halfedge_handle;
typedef typename Arrangement_2::Face_handle Face_handle;
typedef typename Arrangement_2::Dcel Dcel;
typedef typename Arrangement_2::Traits_2 Traits_2;
typedef typename Traits_2::X_monotone_curve_2 X_monotone_curve_2;
typedef typename Traits_2::Point_2 Point_2;
typedef CGAL::Arr_accessor<Arrangement_2> Arr_accessor;
typedef typename Arr_accessor::Dcel_vertex DVertex;
typedef typename Arr_accessor::Dcel_halfedge DHalfedge;
typedef typename Arr_accessor::Dcel_face DFace;
typedef typename Arr_accessor::Dcel_hole DHole;
typedef typename Arr_accessor::Dcel_isolated_vertex DIso_vert;
// Data members:
Arrangement_2& m_arr;
Arr_accessor m_arr_access;
Point_2 m_point;
std::vector<DVertex*> m_vertices;
X_monotone_curve_2 m_curve;
std::vector<DHalfedge*> m_halfedges;
DVertex *v_bl;
DVertex *v_tl;
DVertex *v_br;
DVertex *v_tr;
private:
// Copy constructor and assignment operator - not supported.
Arrangement_2_reader (const Self& );
Self& operator= (const Self& );
public:
/*! Constructor. */
Arrangement_2_reader (Arrangement_2& arr) :
m_arr (arr),
m_arr_access (arr),
v_bl (NULL), v_tl (NULL), v_br (NULL), v_tr (NULL)
{}
/*! Destructor. */
virtual ~Arrangement_2_reader ()
{}
/*! Read the arrangement. */
template <class Formatter>
void operator()(Formatter& formatter)
{
// Clear the exisiting arrangement so it contains no DCEL features.
m_arr_access.clear_all();
// Read the arrangement dimensions.
formatter.read_arrangement_begin();
const Size number_of_vertices = formatter.read_size("number_of_vertices");
const Size number_of_halfedges = 2*formatter.read_size("number_of_edges");
const Size number_of_faces = formatter.read_size("number_of_faces");
Size k;
// Create the four fictitious DCEL vertices.
v_bl = m_arr_access.new_vertex_at_infinity (MINUS_INFINITY,
MINUS_INFINITY);
v_tl = m_arr_access.new_vertex_at_infinity (MINUS_INFINITY,
PLUS_INFINITY);
v_br = m_arr_access.new_vertex_at_infinity (PLUS_INFINITY,
MINUS_INFINITY);
v_tr = m_arr_access.new_vertex_at_infinity (PLUS_INFINITY,
PLUS_INFINITY);
// Read the DCEL vertices and store them in the vertices vector.
formatter.read_vertices_begin();
m_vertices.resize (number_of_vertices);
for (k = 0; k < number_of_vertices; k++)
m_vertices[k] = _read_vertex (formatter);
formatter.read_vertices_end();
// Read the DCEL halfedges and store them in the halfedges vector.
DHalfedge *he = NULL;
formatter.read_edges_begin();
m_halfedges.resize (number_of_halfedges);
for (k = 0; k < number_of_halfedges; k += 2)
{
he = _read_edge (formatter);
m_halfedges[k] = he;
m_halfedges[k + 1] = he->opposite();
}
formatter.read_edges_end();
// Read the DCEL faces.
formatter.read_faces_begin();
for (k = 0; k < number_of_faces; k++)
_read_face (formatter);
formatter.read_faces_end();
formatter.read_arrangement_end();
return;
}
protected:
/*! Read a DCEL vertex. */
template <class Formatter>
DVertex* _read_vertex (Formatter& formatter)
{
formatter.read_vertex_begin();
// Read the infinity types.
Boundary_type inf_x = Boundary_type (formatter.read_vertex_index());
Boundary_type inf_y = Boundary_type (formatter.read_vertex_index());
DVertex *new_v;
if (inf_x == NO_BOUNDARY && inf_y == NO_BOUNDARY)
{
// Read the point associated with the vertex.
formatter.read_point (m_point);
// Allocate a new DCEL vertex and associate it with this point.
new_v = m_arr_access.new_vertex (m_point);
// Read any auxiliary data associated with the vertex.
formatter.read_vertex_data (Vertex_handle (new_v));
}
else
{
// Allocate a vertex at infinity.
new_v = m_arr_access.new_vertex_at_infinity (inf_x, inf_y);
}
formatter.read_vertex_end();
return (new_v);
}
/*! Read a DCEL edge (a pair of twin halfedges). */
template <class Formatter>
DHalfedge* _read_edge (Formatter& formatter)
{
formatter.read_edge_begin();
// Read the indices of the end-vertices and the edge direction.
int source_idx = formatter.read_vertex_index();
int target_idx = formatter.read_vertex_index();
int direction = formatter.read_vertex_index();
DHalfedge *new_he;
DVertex *src_v;
DVertex *trg_v;
if (source_idx == -1)
src_v = v_bl;
else if (source_idx == -2)
src_v = v_tl;
else if (source_idx == -3)
src_v = v_br;
else if (source_idx == -4)
src_v = v_tr;
else
src_v = m_vertices[source_idx];
if (target_idx == -1)
trg_v = v_bl;
else if (target_idx == -2)
trg_v = v_tl;
else if (target_idx == -3)
trg_v = v_br;
else if (target_idx == -4)
trg_v = v_tr;
else
trg_v = m_vertices[target_idx];
if (source_idx >= 0 || target_idx >= 0)
{
// Read the x-monotone curve associated with the edge.
formatter.read_x_monotone_curve (m_curve);
// Allocate a pair of new DCEL halfegdes and associate them with the
// x-monotone curve we read.
new_he = m_arr_access.new_edge (m_curve);
}
else
{
// Allocate a new fictitious edge.
new_he = m_arr_access.new_fictitious_edge();
}
// Set the cross pointers between the twin halfedges and the end vertices.
trg_v->set_halfedge (new_he);
new_he->set_vertex (trg_v);
src_v->set_halfedge (new_he->opposite());
new_he->opposite()->set_vertex (src_v);
// Set the directionf of the halfedges.
if (direction == 0)
{
new_he->set_direction (SMALLER);
}
else
{
CGAL_assertion (direction == 1);
new_he->set_direction (LARGER);
}
// Read any auxiliary data associated with the halfedges.
if (source_idx >= 0 || target_idx >= 0)
{
formatter.read_halfedge_data (Halfedge_handle (new_he));
formatter.read_halfedge_data (Halfedge_handle ((new_he->opposite())));
}
formatter.read_edge_end();
return (new_he);
}
/*! Read a DCEL face. */
template <class Formatter>
void _read_face(Formatter& formatter)
{
formatter.read_face_begin();
// Try reading the outer CCB of the face.
formatter.read_outer_ccb_begin();
const Size outer_size = formatter.read_size ("halfedges_on_outer_CCB");
DFace *new_f = NULL;
DHalfedge *he;
if (outer_size == 0)
{
// Allocate the fictitious DCEL face.
new_f = m_arr_access.new_face();
new_f->set_halfedge (NULL);
}
else
{
// Allocate a new DCEL face and read its outer CCB.
new_f = m_arr_access.new_face();
he = _read_ccb (formatter, new_f, outer_size, NULL);
new_f->set_halfedge (he);
}
formatter.read_outer_ccb_end();
// Read the holes inside the face.
formatter.read_holes_begin();
DHole *new_hole;
const Size n_holes = formatter.read_size ("number_of_holes");
Size inner_size;
Size k;
for (k = 0; k < n_holes; k++)
{
// Allocate a new hole record and set its incident face.
new_hole = m_arr_access.new_hole();
new_hole->set_face (new_f);
// Read the current hole.
inner_size = formatter.read_size ("halfedges_on_inner_CCB");
he = _read_ccb (formatter, new_f, inner_size, new_hole);
new_hole->set_iterator (new_f->add_hole (he));
}
formatter.read_holes_end();
// Read the isolated vertices inside the face.
formatter.read_isolated_vertices_begin();
DIso_vert *new_iso_vert;
Size n_isolated_vertices =
formatter.read_size ("number_of_isolated_vertices");
std::size_t v_idx;
DVertex* iso_v;
for (k = 0; k < n_isolated_vertices; k++)
{
// Allocate a new isolated vertex record and set its incident face.
new_iso_vert = m_arr_access.new_isolated_vertex();
new_iso_vert->set_face (new_f);
// Read the current isolated vertex.
v_idx = formatter.read_vertex_index ();
iso_v = m_vertices[v_idx];
iso_v->set_isolated_vertex (new_iso_vert);
new_iso_vert->set_iterator (new_f->add_isolated_vertex (iso_v));
}
formatter.read_isolated_vertices_end();
// Read any auxiliary data associated with the face.
if (outer_size != 0)
formatter.read_face_data (Face_handle (new_f));
formatter.read_face_end();
return;
}
/*!
* Read a circular boundary of a conncted component.
* \param formatter The formatter.
* \param f The incident DCEL face.
* \param boundary_size The number of halfedges along the boundary.
* \param p_hole If NULL, the CCB corresponds to the outer boundary of f;
* otherwise, it corresponds to an inner component (hole).
* \return A pointer to the first halfedge read.
*/
template <class Formatter>
DHalfedge* _read_ccb (Formatter& formatter,
DFace *f,
Size boundary_size,
DHole *p_hole)
{
formatter.read_ccb_halfedges_begin();
// Find the first halfedge, and set its incident face.
std::size_t first_idx = formatter.read_halfedge_index();
DHalfedge *first_he = m_halfedges [first_idx];
if (p_hole == NULL)
first_he->set_face (f);
else
first_he->set_hole (p_hole);
// Read the rest of the halfedge along the boundary.
std::size_t curr_idx;
DHalfedge *prev_he = first_he;
DHalfedge *curr_he;
Size k;
for (k = 1; k < boundary_size; k++)
{
curr_idx = formatter.read_halfedge_index();
curr_he = m_halfedges[curr_idx];
// Connect the previous halfedge and the current one.
prev_he->set_next (curr_he);
// Set the incident face.
if (p_hole == NULL)
curr_he->set_face (f);
else
curr_he->set_hole (p_hole);
prev_he = curr_he;
}
// Close the circular list be connecting the first and the last halfedges.
prev_he->set_next (first_he);
formatter.read_ccb_halfedges_end();
// Return the first halfedge.
return (first_he);
}
};
CGAL_END_NAMESPACE
#endif // CGAL_IO_ARRANGEMENT_2_READER_H

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,104 @@
// Copyright (c) 2006 Tel-Aviv University (Israel).
// All rights reserved.
//
// This file is part of CGAL (www.cgal.org); you may redistribute it under
// the terms of the Q Public License version 1.0.
// See the file LICENSE.QPL distributed with CGAL.
//
// Licensees holding a valid commercial license may use this file in
// accordance with the commercial license agreement provided with the software.
//
// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
//
// $URL$
// $Id$
//
// Author(s) : Ron Wein <wein@post.tau.ac.il>
#ifndef CGAL_FIG_STREAM_CONIC_ARC_2_H
#define CGAL_FIG_STREAM_CONIC_ARC_2_H
#include <CGAL/IO/Fig_stream.h>
#include <list>
/*!
* Write an x-monotone conic arc to a FIG stream.
*/
template <class Conic_traits>
static void _write_x_monotone_conic_arc
(CGAL::Fig_stream<typename Conic_traits::Alg_kernel>& fs,
const typename Conic_traits::X_monotone_curve_2& cv)
{
typedef typename Conic_traits::Alg_kernel Alg_kernel;
typedef typename Conic_traits::Algebraic Algebraic;
typedef typename Conic_traits::Point_2 Alg_point_2;
typedef typename Alg_kernel::Segment_2 Alg_segment_2;
if (cv.orientation() == CGAL::COLLINEAR)
{
// In case of a linear segment:
Alg_segment_2 seg = Alg_segment_2 (cv.source(), cv.target());
fs << seg;
}
else if (CGAL::compare (cv.r(), cv.s()) == CGAL::EQUAL &&
CGAL::sign (cv.t()) == CGAL::ZERO)
{
// In case of a circular arc:
Algebraic x_mid = (cv.source().x() + cv.target().x()) / 2;
Alg_point_2 q = Alg_point_2(x_mid, 0);
Alg_point_2 p = cv.get_point_at_x (q);
fs.write_circular_arc (cv.source(), p, cv.target());
}
else
{
// Represent the arc as a spline with 5 control points.
Algebraic x;
Alg_point_2 q;
Alg_point_2 cps[5];
int i;
cps[0] = cv.source();
for (i = 1; i <= 3; i++)
{
x = (cv.source().x()*(4 - i) + cv.target().x()*i) / 4;
q = Alg_point_2(x, 0);
cps[i] = cv.get_point_at_x (q);
}
cps[4] = cv.target();
fs.write_spline (cps + 0, cps + 5, 1.0);
}
return;
}
/*!
* Write a conic arc to a FIG stream.
*/
template <class Conic_traits>
void write_conic_arc
(CGAL::Fig_stream<typename Conic_traits::Alg_kernel>& fs,
const typename Conic_traits::Curve_2& cv)
{
typedef typename Conic_traits::X_monotone_curve_2 Conic_arc_2;
// Subdivide the arc into x-monotone sub-arcs.
Conic_traits traits;
std::list<Conic_arc_2> xcvs;
traits.make_x_monotone_2_object() (cv,
std::back_inserter(xcvs));
// Write the x-monotone sub-arcs.
typename std::list<Conic_arc_2>::iterator xit;
for (xit = xcvs.begin(); xit != xcvs.end(); ++xit)
_write_x_monotone_conic_arc<Conic_traits> (fs, *xit);
return;
}
#endif

View File

@ -0,0 +1,47 @@
// Copyright (c) 2005 Tel-Aviv University (Israel).
// All rights reserved.
//
// This file is part of CGAL (www.cgal.org); you may redistribute it under
// the terms of the Q Public License version 1.0.
// See the file LICENSE.QPL distributed with CGAL.
//
// Licensees holding a valid commercial license may use this file in
// accordance with the commercial license agreement provided with the software.
//
// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
//
// $URL$
// $Id$
//
// Author(s) : Efi Fogel <efif@post.tau.ac.il>
#ifndef CGAL_POLYLINE_POSTSCRIPT_FILE_STREAM_H
#define CGAL_POLYLINE_POSTSCRIPT_FILE_STREAM_H
/*! \file
* Postscript output stream for the Polyline_2<SegmentTraits> class.
*/
#include <CGAL/IO/Postscript_file_stream.h>
#include <CGAL/Arr_traits_2/Polyline_2.h>
CGAL_BEGIN_NAMESPACE
/*! Export a Polyline_2 object to a Postscript stream
* \param ps_stream the Postscript stream
* \param polyline the polyline curve
* \return the Postscript stream
*/
template<typename SegmentTraits> Postscript_file_stream &
operator<<(Postscript_file_stream & ps_stream,
const _Polyline_2<SegmentTraits> & polyline)
{
unsigned int i;
for (i = 0; i < polyline.size(); ++i) ps_stream << polyline[i];
return ps_stream;
}
CGAL_END_NAMESPACE
#endif

View File

@ -0,0 +1,111 @@
// Copyright (c) 2005 Tel-Aviv University (Israel).
// All rights reserved.
//
// This file is part of CGAL (www.cgal.org); you may redistribute it under
// the terms of the Q Public License version 1.0.
// See the file LICENSE.QPL distributed with CGAL.
//
// Licensees holding a valid commercial license may use this file in
// accordance with the commercial license agreement provided with the software.
//
// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
//
// $URL$
// $Id$
//
//
// Author(s) : Ron Wein <wein@post.tau.ac.il>
// Efi Fogel <efif@post.tau.ac.il>
#ifndef CGAL_QT_WIDGET_CONIC_ARC_2_H
#define CGAL_QT_WIDGET_CONIC_ARC_2_H
#include <CGAL/IO/Qt_widget.h>
#include <CGAL/Arr_conic_traits_2.h>
#include <list>
CGAL_BEGIN_NAMESPACE
/*!
* Draw an x-monotone conic arc.
*/
template <class ConicArc>
Qt_widget& operator<< (Qt_widget& ws,
const _Conic_x_monotone_arc_2<ConicArc>& cv)
{
// Get the co-ordinates of the curve's source and target.
const double sx = CGAL::to_double(cv.source().x());
const double sy = CGAL::to_double(cv.source().y());
const double tx = CGAL::to_double(cv.target().x());
const double ty = CGAL::to_double(cv.target().y());
if (cv.orientation() == COLLINEAR)
{
// The curve is a segment - simply draw it.
ws.get_painter().drawLine(ws.x_pixel(sx), ws.y_pixel(sy),
ws.x_pixel(tx), ws.y_pixel(ty));
return (ws);
}
// Draw a curves conic arc: As the arc is x-monotone, its source and its
// target has the extreme x-coordinates.
const bool is_source_left = (sx < tx);
const int x_min = is_source_left ? ws.x_pixel(sx) : ws.x_pixel(tx);
const int x_max = is_source_left ? ws.x_pixel(tx) : ws.x_pixel(sx);
const int n = x_max - x_min + 1;
if (n <= 0)
return (ws);
typedef std::pair<double, double> App_point_2;
int i;
App_point_2 *pts = new App_point_2 [n + 1];
cv.polyline_approximation (n, pts);
ws.get_painter().moveTo (ws.x_pixel(pts[0].first),
ws.y_pixel(pts[0].second));
for (i = 1; i <= n; i++)
{
ws.get_painter().lineTo (ws.x_pixel(pts[i].first),
ws.y_pixel(pts[i].second));
}
delete[] pts;
return (ws);
}
/*!
* Draw a conic arc.
*/
template <class Rat_kernel, class Alg_kernel, class Nt_traits>
Qt_widget& operator<<
(Qt_widget& ws,
const typename Arr_conic_traits_2<Rat_kernel,
Alg_kernel,
Nt_traits>::Curve_2& cv)
{
typedef Arr_conic_traits_2<Rat_kernel,
Alg_kernel,
Nt_traits> Conic_traits_2;
typedef typename Conic_traits_2::X_monotone_curve_2 X_monotone_conic_arc_2;
// Break the arc into x-monotone sub-curves and draw each one separately.
Conic_traits_2 traits;
std::list<X_monotone_conic_arc_2> x_arcs;
typename std::list<X_monotone_conic_arc_2>::const_iterator x_iter;
traits.curve_make_x_monotone (cv,
std::back_inserter (x_arcs));
for (x_iter = x_arcs.begin(); x_iter != x_arcs.end(); ++x_iter)
ws << *x_iter;
return (ws);
}
CGAL_END_NAMESPACE
#endif

View File

@ -0,0 +1,54 @@
// Copyright (c) 2005 Tel-Aviv University (Israel).
// All rights reserved.
//
// This file is part of CGAL (www.cgal.org); you may redistribute it under
// the terms of the Q Public License version 1.0.
// See the file LICENSE.QPL distributed with CGAL.
//
// Licensees holding a valid commercial license may use this file in
// accordance with the commercial license agreement provided with the software.
//
// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
//
// $URL$
// $Id$
// $Date$
//
//
// Author(s) : Ron Wein <wein@post.tau.ac.il>
// Efi Fogel <efif@post.tau.ac.il>
#ifndef CGAL_QT_WIDGET_POLYLINE_2_H
#define CGAL_QT_WIDGET_POLYLINE_2_H
#include <CGAL/IO/Qt_widget.h>
#include <CGAL/Arr_linear_traits_2.h>
CGAL_BEGIN_NAMESPACE
/*!
* Export a polyline to a window stream
*/
template <class K>
Qt_widget & operator<<(Qt_widget & ws, const Arr_linear_object_2<K> & o)
{
if(o.is_segment())
{
ws << o.segment();
return ws;
}
if(o.is_ray())
{
ws << o.ray();
return ws;
}
CGAL_assertion(o.is_line());
ws << o.line();
return ws;
}
CGAL_END_NAMESPACE
#endif

View File

@ -0,0 +1,42 @@
// Copyright (c) 2005 Tel-Aviv University (Israel).
// All rights reserved.
//
// This file is part of CGAL (www.cgal.org); you may redistribute it under
// the terms of the Q Public License version 1.0.
// See the file LICENSE.QPL distributed with CGAL.
//
// Licensees holding a valid commercial license may use this file in
// accordance with the commercial license agreement provided with the software.
//
// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
//
// $URL$
// $Id$
// $Date$
//
//
// Author(s) : Ron Wein <wein@post.tau.ac.il>
// Efi Fogel <efif@post.tau.ac.il>
#ifndef CGAL_QT_WIDGET_POLYLINE_2_H
#define CGAL_QT_WIDGET_POLYLINE_2_H
#include <CGAL/IO/Qt_widget.h>
#include <CGAL/Arr_traits_2/Polyline_2.h>
CGAL_BEGIN_NAMESPACE
/*!
* Export a polyline to a window stream
*/
template <class T_SegmentTraits>
Qt_widget & operator<<(Qt_widget & ws, const _Polyline_2<T_SegmentTraits> & cv)
{
for (unsigned int i = 0; i < cv.size(); ++i) ws << cv[i];
return ws;
}
CGAL_END_NAMESPACE
#endif