diff --git a/Arrangement_on_surface_2/include/CGAL/IO/Arr_iostream.h b/Arrangement_on_surface_2/include/CGAL/IO/Arr_iostream.h new file mode 100644 index 00000000000..70e9db2e370 --- /dev/null +++ b/Arrangement_on_surface_2/include/CGAL/IO/Arr_iostream.h @@ -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 +// Ron Wein +// (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 class. + */ + +#include +#include +#include +#include +#include + +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 +std::ostream& write (const Arrangement_2& arr, + std::ostream& os, + Formatter& format) +{ + typedef Arrangement_2 Arrangement_2; + typedef Arrangement_2_writer 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 +std::ostream& operator<< (std::ostream& os, + const Arrangement_2& arr) +{ + typedef Arrangement_2 Arrangement_2; + typedef Arrangement_2_writer Arr_writer; + typedef Arr_text_formatter 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 +std::istream& read (Arrangement_2& arr, + std::istream& is, + Formatter& format) +{ + typedef Arrangement_2 Arrangement_2; + typedef Arrangement_2_reader 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 +std::istream& operator>> (std::istream& is, + Arrangement_2& arr) +{ + typedef Arrangement_2 Arrangement_2; + typedef Arrangement_2_reader Arr_reader; + typedef Arr_text_formatter Text_formatter; + + Text_formatter text_format (is); + Arr_reader reader(arr); + + reader (text_format); + return (is); +} + +CGAL_END_NAMESPACE + +#endif diff --git a/Arrangement_on_surface_2/include/CGAL/IO/Arr_postscript_file_stream.h b/Arrangement_on_surface_2/include/CGAL/IO/Arr_postscript_file_stream.h new file mode 100644 index 00000000000..112e36b944f --- /dev/null +++ b/Arrangement_on_surface_2/include/CGAL/IO/Arr_postscript_file_stream.h @@ -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 + +#ifndef CGAL_ARR_POSTSCRIPT_FILE_STREAM_H +#define CGAL_ARR_POSTSCRIPT_FILE_STREAM_H + +/*! \file + * Postscript output stream for the Arrangement_2 class. + */ + +#include +#include + +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 Arr_postscript_file_stream & +operator<<(Arr_postscript_file_stream & ps_stream, + const Arrangement_2 & arr) +{ + // Draw the curves: + ps_stream << ps_stream.curve_color(); + typename Arrangement_2::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::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 diff --git a/Arrangement_on_surface_2/include/CGAL/IO/Arr_text_formatter.h b/Arrangement_on_surface_2/include/CGAL/IO/Arr_text_formatter.h new file mode 100644 index 00000000000..bfb505e2c6a --- /dev/null +++ b/Arrangement_on_surface_2/include/CGAL/IO/Arr_text_formatter.h @@ -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 +// Ron Wein +// (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 +#include + +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 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 Arr_face_extended_text_formatter : + public Arr_text_formatter +{ + +public: + + typedef Arrangement_ Arrangement_2; + typedef Arr_text_formatter 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 Arr_extended_dcel_text_formatter : + public Arr_text_formatter +{ +public: + + typedef Arrangement_ Arrangement_2; + typedef Arr_text_formatter 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 diff --git a/Arrangement_on_surface_2/include/CGAL/IO/Arr_with_history_2_reader.h b/Arrangement_on_surface_2/include/CGAL/IO/Arr_with_history_2_reader.h new file mode 100644 index 00000000000..b6da7e8cb64 --- /dev/null +++ b/Arrangement_on_surface_2/include/CGAL/IO/Arr_with_history_2_reader.h @@ -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 +#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 class. + */ + +#include +#include + +CGAL_BEGIN_NAMESPACE + +/*! \class + * An auxiliary class for reading an arrangement with history from an + * input stream. + */ +template +class Arr_with_history_2_reader : private Arrangement_2_reader +{ +public: + + typedef ArrWithHistory_ Arr_with_history_2; + typedef Arr_with_history_2_reader Self; + +protected: + + typedef Arrangement_2_reader 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_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 + 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 + 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 diff --git a/Arrangement_on_surface_2/include/CGAL/IO/Arr_with_history_2_writer.h b/Arrangement_on_surface_2/include/CGAL/IO/Arr_with_history_2_writer.h new file mode 100644 index 00000000000..0dbb07e20c6 --- /dev/null +++ b/Arrangement_on_surface_2/include/CGAL/IO/Arr_with_history_2_writer.h @@ -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 + +#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 class. + */ + +#include + +CGAL_BEGIN_NAMESPACE + +/*! \class + * An auxiliary class for writing an arrangement with history to an + * output stream. + */ +template +class Arr_with_history_2_writer : private Arrangement_2_writer +{ +public: + + typedef ArrWithHistory_ Arr_with_history_2; + typedef Arr_with_history_2_writer Self; + +protected: + + typedef Arrangement_2_writer 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 + 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 + 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 diff --git a/Arrangement_on_surface_2/include/CGAL/IO/Arr_with_history_iostream.h b/Arrangement_on_surface_2/include/CGAL/IO/Arr_with_history_iostream.h new file mode 100644 index 00000000000..fcd55d27dbe --- /dev/null +++ b/Arrangement_on_surface_2/include/CGAL/IO/Arr_with_history_iostream.h @@ -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 + +#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 class. + */ + +#include +#include +#include +#include +#include +#include + +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 +std::ostream& write (const Arrangement_with_history_2& arr, + std::ostream& os, + Formatter& format) +{ + typedef Arrangement_with_history_2 Arr_with_history_2; + typedef Arr_with_history_2_writer 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 +std::ostream& operator<< (std::ostream& os, + const Arrangement_with_history_2& arr) +{ + typedef Arrangement_with_history_2 Arr_with_history_2; + typedef Arr_with_history_2_writer Arr_writer; + typedef Arr_with_history_text_formatter + > 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 +std::istream& read (Arrangement_with_history_2& arr, + std::istream& is, + Formatter& format) +{ + typedef Arrangement_with_history_2 Arr_with_history_2; + typedef Arr_with_history_2_reader 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 +std::istream& operator>> (std::istream& is, + Arrangement_with_history_2& arr) +{ + typedef Arrangement_with_history_2 Arr_with_history_2; + typedef Arr_with_history_2_reader Arr_reader; + typedef Arr_with_history_text_formatter + > Text_formatter; + + Text_formatter text_format (is); + Arr_reader reader (arr); + + reader (text_format); + return (is); +} + +CGAL_END_NAMESPACE + +#endif diff --git a/Arrangement_on_surface_2/include/CGAL/IO/Arr_with_history_text_formatter.h b/Arrangement_on_surface_2/include/CGAL/IO/Arr_with_history_text_formatter.h new file mode 100644 index 00000000000..056ff8dc52f --- /dev/null +++ b/Arrangement_on_surface_2/include/CGAL/IO/Arr_with_history_text_formatter.h @@ -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 + +#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 +#include + +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 Arr_with_history_text_formatter : public ArrFormatter_ +{ +public: + + typedef ArrFormatter_ Base; + typedef Arr_with_history_text_formatter 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 diff --git a/Arrangement_on_surface_2/include/CGAL/IO/Arrangement_2_reader.h b/Arrangement_on_surface_2/include/CGAL/IO/Arrangement_2_reader.h new file mode 100644 index 00000000000..eb9c767d25d --- /dev/null +++ b/Arrangement_on_surface_2/include/CGAL/IO/Arrangement_2_reader.h @@ -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 +// Ron Wein +// (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 class. + */ + +#include +#include +#include +#include +#include + +CGAL_BEGIN_NAMESPACE + +/*! \class + * An auxiliary class for reading an arrangement from an input stream. + */ +template +class Arrangement_2_reader +{ +public: + + typedef Arrangement_ Arrangement_2; + typedef Arrangement_2_reader 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 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 m_vertices; + X_monotone_curve_2 m_curve; + std::vector 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 + 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 + 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 + 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 + 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 + 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 diff --git a/Arrangement_on_surface_2/include/CGAL/IO/Fig_stream.h b/Arrangement_on_surface_2/include/CGAL/IO/Fig_stream.h new file mode 100644 index 00000000000..92915f2aac4 --- /dev/null +++ b/Arrangement_on_surface_2/include/CGAL/IO/Fig_stream.h @@ -0,0 +1,1718 @@ +// 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 + +#ifndef CGAL_FIG_STREAM_H +#define CGAL_FIG_STREAM_H + +#include +#include + +#include +#include +#include + +CGAL_BEGIN_NAMESPACE + +/*! + * FIG colors. + */ +enum Fig_color +{ + // Predefined colors: + FIG_BLACK = 0, + FIG_BLUE = 1, + FIG_GREEN = 2, + FIG_CYAN = 3, + FIG_RED = 4, + FIG_MAGENTA = 5, + FIG_YELLOW = 6, + FIG_WHITE = 7, + FIG_BLUE_1 = 8, FIG_BLUE_2 = 9, FIG_BLUE_3 = 10, FIG_BLUE_4 = 11, + FIG_GREEN_1 = 12, FIG_GREEN_2 = 13, FIG_GREEN_3 = 14, + FIG_CYAN_1 = 15, FIG_CYAN_2 = 16, FIG_CYAN_3 = 17, + FIG_RED_1 = 18, FIG_RED_2 = 19, FIG_RED_3 = 20, + FIG_MAGENTA_1 = 21, FIG_MAGENTA_2 = 22, FIG_MAGENTA_3 = 23, + FIG_BROWN_1 = 24, FIG_BROWN_2 = 25, FIG_BROWN_3 = 26, + FIG_PINK_1 = 27, FIG_PINK_2 = 28, FIG_PINK_3 = 29, FIG_PINK_4 = 30, + FIG_GOLD = 31, + + // User-defined colors: + FIG_FIRST_USER_DEFINED_COLOR = 32, + FIG_LAST_USER_DEFINED_COLOR = 543 +}; + +/*! + * FIG line styles. + */ +enum Fig_line_style +{ + FIG_SOLID = 0, + FIG_DASHED = 1, + FIG_DOTTED = 2, + FIG_DASH_DOTTED = 3, + FIG_DASH_DOUBLE_DOTTED = 4, + FIG_DASH_TRIPLE_DOTTED = 5 +}; + +#define FIG_DEFAULT_STYLE_VALUE 4.0 + +/*! + * FIG fill styles. + */ +enum Fig_fill_style +{ + FIG_NOT_FILLED = -1, + FIG_FILL_BLACK = 0, + /// Values from 1 to 19 are shades of the color from darker to lighter. + FIG_FILLED = 20, + /// Values from 21 to 39 are tints of the color from the color to white. + FIG_FILL_WHITE = 40, + FIG_LEFT_DIAG_30DEG = 41, + FIG_RIGHT_DIAG_30DEG = 42, + FIG_CROSS_DIAG_30DEG = 43, + FIG_LEFT_DIAG_45DEG = 44, + FIG_RIGHT_DIAG_45DEG = 45, + FIG_CROSS_DIAG_45DEG = 46, + FIG_HORIZONTAL_BRICKS = 47, + FIG_VERTICAL_BRICKS = 48, + FIG_HORIZONTAL_LINES = 49, + FIG_VERTICAL_LINES = 50, + FIG_CROSS_LINES = 51, + FIG_HORIZONTAL_RIGHT_SHINGLES = 52, + FIG_HORIZONTAL_LEFT_SHINGLES = 53, + FIG_VERTICAL_RIGHT_SHINGLES = 54, + FIG_VERTICAL_LEFT_SHINGLES = 55, + FIG_FISH_SCALES = 56, + FIG_SMALL_FISH_SCALES = 57, + FIG_CIRCLES = 58, + FIG_HEXAGONS = 59, + FIG_OCTAGONS = 60, + FIG_HORIZONTAL_TIRE_TREADS = 61, + FIG_VERTICAL_TIRE_TREADS = 62 +}; + +/*! + * FIG arrow types. + */ +enum Fig_arrow_type +{ + FIG_STICK = 0, + FIG_TRIANGLE = 1, + FIG_INDENTED_BUTT = 2, + FIG_POINTED_BUTT = 3 +}; + +/*! + * Arrow modes (not based on the FIG format). + */ +enum Fig_arrow_mode +{ + FIG_NO_ARROW, + FIG_FORWARD_ARROW, + FIG_BACKWARD_ARROW, + FIG_BOTH_ARROWS +}; + +/*! + * Point styles (not based on the FIG format). + */ +enum Fig_point_style +{ + FIG_CROSS, + FIG_PLUS, + FIG_CIRCLE, + FIG_DISC, + FIG_SQUARE, + FIG_BOX, + FIG_RHOMBUS, + FIG_DIAMOND +}; + +/*! + * FIG fonts. + */ +enum Fig_font +{ + FIG_ROMAN = 1, + FIG_BOLD = 2, + FIG_ITALIC = 3, + FIG_SANS_SERIF = 4, + FIG_TYPEWRITER = 5 +}; + +/*! + * Depth constants. + */ +enum Fig_depth +{ + FIG_MIN_DEPTH = 0, + FIG_DEFAULT_DEPTH = 50, + FIG_MAX_DEPTH = 99 +}; + +/*! + * \class A class for writing geometric objects in a FIG format (version 3.2). + * For more details, see: http://www.xfig.org/userman/fig-format.html + */ +template +class Fig_stream +{ +public: + + typedef Kernel_ Kernel; + + // Define the kernel objects. + typedef typename Kernel::FT NT; + typedef typename Kernel::Point_2 Point_2; + typedef typename Kernel::Segment_2 Segment_2; + typedef typename Kernel::Ray_2 Ray_2; + typedef typename Kernel::Line_2 Line_2; + typedef typename Kernel::Triangle_2 Triangle_2; + typedef typename Kernel::Iso_rectangle_2 Iso_rectangle_2; + typedef Polygon_2 Polygon_2; + typedef typename Kernel::Circle_2 Circle_2; + +protected: + + // Data members: + std::ofstream _ofile; // The output file. + + Iso_rectangle_2 _bound_rect; // A rectangle bounding the workspace. + int _width; // Figure width (in pixels). + int _height; // Figure height (in pixels). + double _scale; // Scaling factor. + + int _depth; + + Fig_color _color; + int _line_width; + Fig_line_style _line_style; + double _style_value; + + Fig_color _fill_color; + Fig_fill_style _fill_style; + + Fig_point_style _point_style; + NT _point_size; + + Fig_arrow_mode _arrow_mode; + Fig_arrow_type _arrow_type; + NT _arrow_width; + NT _arrow_height; + + Fig_font _font; + int _font_size; + + bool colors[FIG_LAST_USER_DEFINED_COLOR + 1]; + + // Kernel functors. + typename Kernel::Intersect_2 intersect_func; + +private: + + // Copy constructor and assignment operator - not supported. + Fig_stream (const Fig_stream& ); + const Fig_stream& operator= (const Fig_stream& ); + +public: + + /// \name Constructors and destructor. + //@{ + + /*! + * Default constructor. + */ + Fig_stream () : + _width (0), + _height (0), + _scale (0), + _depth (FIG_DEFAULT_DEPTH), + _color (FIG_BLACK), + _line_width (1), + _line_style (FIG_SOLID), + _style_value (FIG_DEFAULT_STYLE_VALUE), + _fill_color (FIG_WHITE), + _fill_style (FIG_NOT_FILLED), + _point_style (FIG_DISC), + _arrow_mode (FIG_NO_ARROW), + _arrow_type (FIG_STICK), + _font (FIG_ROMAN), + _font_size (12) + { + // Reset all colors. + _reset_colors (); + + // Construct the necessary kernel functors. + Kernel ker; + + intersect_func = ker.intersect_2_object(); + } + + /*! + * Constructor. + * \param filename The name of the output FIG file. + * \param rect A rectangle bounding the logical drawing area. + * \param width The physical width of the figure (in FIG units). + * \param height The physical height of the figure (in FIG units). + * \pre The bounding rectangle is valid and the physical dimensions are + * both positive. + */ + Fig_stream (const char *filename, + const Iso_rectangle_2& rect, + const int& width = 12000, + const int& height = 12000) : + _width (0), + _height (0), + _scale (0), + _depth (FIG_DEFAULT_DEPTH), + _color (FIG_BLACK), + _line_width (1), + _line_style (FIG_SOLID), + _style_value (FIG_DEFAULT_STYLE_VALUE), + _fill_color (FIG_WHITE), + _fill_style (FIG_NOT_FILLED), + _point_style (FIG_DISC), + _arrow_mode (FIG_NO_ARROW), + _arrow_type (FIG_STICK), + _font (FIG_ROMAN), + _font_size (12) + { + // Reset all colors. + _reset_colors (); + + // Construct the necessary kernel functors. + Kernel ker; + + intersect_func = ker.intersect_2_object(); + + // Open the file. + open (filename, rect, width, height); + } + + /*! + * Destructor. + */ + virtual ~Fig_stream () + { + _ofile.close(); + } + //@} + + /// \name Openning and closing the file. + //@{ + + /*! + * Check whether the file is open. + */ + bool is_open () + { + return (_ofile.is_open()); + } + + /*! + * Open a FIG file. + * \param filename The name of the output FIG file. + * \param rect A rectangle bounding the logical drawing area. + * \param width The physical width of the figure (in FIG units). + * \param height The physical height of the figure (in FIG units). + * \pre The bounding rectangle is valid and the physical dimensions are + * both positive. + * \return Whether the file was successfully opened. + */ + bool open (const char *filename, + const Iso_rectangle_2& rect, + const int& width = 12000, + const int& height = 12000) + { + CGAL_precondition (width > 0); + CGAL_precondition (height > 0); + CGAL_precondition (rect.xmax() > rect.xmin()); + CGAL_precondition (rect.ymax() > rect.ymin()); + + // Reset all colors. + _reset_colors (); + + // Close the current output file, if necessary. + if (_ofile.is_open()) + _ofile.close(); + + // Open the output file. + _ofile.open (filename); + + // Set the logical and physical dimensions. + _bound_rect = rect; + _width = width; + _height = height; + + // Compute the scale. + const double x_scale = width / CGAL::to_double(rect.xmax() - rect.xmin()); + const double y_scale = height / CGAL::to_double(rect.ymax() - rect.ymin()); + _scale = (x_scale < y_scale) ? x_scale : y_scale; + + // Set the default point size and arrow dimensions. + _point_size = (rect.xmax() - rect.xmin()) / NT(500); + _arrow_width = _point_size; + _arrow_height = 2*_point_size; + + // End here if the file is not opened. + if (! _ofile.is_open()) + return (false); + + // Write the FIG header. + _ofile << "#FIG 3.2" << std::endl; + _ofile << "Landscape" << std::endl; + _ofile << "Center" << std::endl; + _ofile << "Inches" << std::endl; + _ofile << "Letter" << std::endl; + _ofile << "100.00" << std::endl; + _ofile << "Single" << std::endl; + _ofile << "-2" << std::endl; + _ofile << "1200 2" << std::endl; + + return (true); + } + + /*! + * Close the FIG file. + */ + void close () + { + if (_ofile.is_open()) + _ofile.close(); + + // Reset all colors. + _reset_colors (); + } + //@} + + /// \name Accessing drawing properties. + //@{ + + /*! + * Get the depth. + */ + int depth () const + { + return (depth); + } + + /*! + * Get the color. + */ + Fig_color color () const + { + return (_color); + } + + /*! + * Get the line width. + */ + int line_width () const + { + return (line_width); + } + + /*! + * Get the line style. + */ + Fig_line_style line_style () const + { + return (_line_style); + } + + /*! + * Get the style value. + */ + double style_value () const + { + return (_style_value); + } + + /*! + * Get the fill color. + */ + Fig_color fill_color () const + { + return (_fill_color); + } + + /*! + * Get the fill style. + */ + Fig_fill_style fill_style () const + { + return (_fill_style); + } + + /*! + * Get the point style. + */ + Fig_point_style point_style () const + { + return (_point_style); + } + + /*! + * Get the point size. + */ + const NT& point_size () const + { + return (_point_size); + } + + /*! + * Get the arrow drawing mode (this mode is relevent when drawing segments, + * polylines, circular arcs or splines). + */ + Fig_arrow_mode arrow_mode () const + { + return (_arrow_mode); + } + + /*! + * Get the arrow type. + */ + Fig_arrow_type arrow_type () const + { + return (_arrow_type); + } + + /*! + * Get the arrow width. + */ + const NT& arrow_width () const + { + return (_arrow_width); + } + + /*! + * Get the arrow height. + */ + const NT& arrow_height () const + { + return (_arrow_height); + } + + /*! + * Get the font. + */ + Fig_font font () const + { + return (_font); + } + + /*! + * Get the font size. + */ + int font_size () const + { + return (_font_size); + } + //@} + + /// \name Set the drawing properties. + //@{ + + /*! + * Set the depth. + */ + void set_depth (const int& depth) + { + if (depth < static_cast(FIG_MIN_DEPTH)) + _depth = static_cast(FIG_MIN_DEPTH); + else if (depth > static_cast(FIG_MAX_DEPTH)) + _depth = static_cast(FIG_MAX_DEPTH); + else + _depth = depth; + + return; + } + + /*! + * Set the color. + * \pre The color must be defined. + */ + void set_color (const Fig_color& color) + { + CGAL_precondition (color_defined (color)); + + if (color_defined (color)) + _color = color; + + return; + } + + /*! + * Set the line width. + */ + void set_line_width (const unsigned int& width) + { + _line_width = static_cast(width); + return; + } + + /*! + * Set the line style. + */ + void set_line_style (const Fig_line_style& style) + { + _line_style = style; + return; + } + + /*! + * Set the style value. + */ + void set_style_value (const double& val) + { + CGAL_precondition (val > 0); + + _style_value = val; + return; + } + + /*! + * Set the fill color. + * \pre The color must be defined. + */ + void set_fill_color (const Fig_color& color) + { + CGAL_precondition (color_defined (color)); + + if (color_defined (color)) + _fill_color = color; + + return; + } + + /*! + * Set the fill style. + */ + void set_fill_style (const Fig_fill_style& style) + { + _fill_style = style; + return; + } + + /*! + * Set the point style. + */ + void set_point_style (const Fig_point_style& style) + { + _point_style = style; + return; + } + + /*! + * Set the point size. + */ + void set_point_size (const NT& size) + { + _point_size = CGAL::abs(size); + return; + } + + /*! + * Set the arrow drawing mode. This mode will be applied when drawing + * segments, polylines, circular arcs or splines. + */ + void set_arrow_mode (const Fig_arrow_mode& mode) + { + _arrow_mode = mode; + return; + } + + /*! + * Set the arrow type. + */ + void set_arrow_type (const Fig_arrow_type& type) + { + _arrow_type = type; + return; + } + + /*! + * Set the arrow width. + */ + void set_arrow_width (const NT& width) + { + _arrow_width = CGAL::abs(width); + return; + } + + /*! + * Get the arrow height. + */ + void set_arrow_height (const NT& height) + { + _arrow_height = CGAL::abs(height); + return; + } + + /*! + * Set the font. + */ + void set_font (const Fig_font& font) + { + _font = font; + return; + } + + /*! + * Set the font size. + */ + void set_font_size (const unsigned int& size) + { + _font_size = static_cast(size); + return; + } + //@} + + /// \name Defining colors. + //@{ + + /*! + * Check if a color is defined. + */ + bool color_defined (const Fig_color& color) const + { + int col = static_cast(color); + + if (col < 0 || col > FIG_LAST_USER_DEFINED_COLOR) + return (false); + + return (colors[col]); + } + + /*! + * Add a user-defined color. + * Use this function after openning the FIG stream and before writing any + * other object (i.e. before calling the write_ () functions). + * \param color The color. + * \param r The red component (0 - 255). + * \param g The green component (0 - 255). + * \param b The blue component (0 - 255). + * \pre The color must be undefined. + */ + void define_color (const Fig_color& color, + const unsigned char& r, + const unsigned char& g, + const unsigned char& b) + { + CGAL_precondition (color_defined (color)); + CGAL_precondition (_ofile.is_open()); + + if (color_defined (color)) + return; + + // Prepare a string desribing the color. + char color_desc [10]; + + sprintf ("#%02x%02x%02x", r, g, b); + + // Write the color to the FIG file. + _ofile << "0 " // Desginates a color pseudo-object. + << static_cast(color) << ' ' + << color_desc << std::endl; + + // Mark that the color is now defined. + colors[static_cast(color)] = true; + + return; + } + + //@} + + /// \name Writing objects. + //@{ + + /*! + * Write a point. + */ + void write_point (const Point_2& p) + { + CGAL_precondition (_ofile.is_open()); + + //is the point outside the iso-rectangle? + if(_bound_rect.has_on_unbounded_side(p)) + return; + + switch (_point_style) + { + case (FIG_CROSS): + case (FIG_PLUS): + { + // Draw two segments intersecting at p. + Point_2 s1, t1; + Point_2 s2, t2; + + if (_point_style == FIG_PLUS) + { + // Draw a '+'. + s1 = Point_2 (p.x() - _point_size, p.y()); + t1 = Point_2 (p.x() + _point_size, p.y()); + s2 = Point_2 (p.x(), p.y() - _point_size); + t2 = Point_2 (p.x(), p.y() + _point_size); + } + else + { + // Draw an 'x'. + s1 = Point_2 (p.x() - _point_size, p.y() - _point_size); + t1 = Point_2 (p.x() + _point_size, p.y() + _point_size); + s2 = Point_2 (p.x() - _point_size, p.y() + _point_size); + t2 = Point_2 (p.x() + _point_size, p.y() - _point_size); + } + + // Draw solid lines with width 1. + _write_segment (Segment_2(s1, t1), + _color, 1, FIG_SOLID, _style_value, + false); + _write_segment (Segment_2(s2, t2), + _color, 1, FIG_SOLID, _style_value, + false); + + break; + } + + case (FIG_CIRCLE): + { + // Draw an empty circle (use a solid line with width 1). + _write_ellipse (p, + CGAL::square(_point_size), + CGAL::square(_point_size), + _color, 1, FIG_SOLID, _style_value, + FIG_WHITE, FIG_NOT_FILLED); + + break; + } + + case (FIG_DISC): + { + // Draw a filled disc. + _write_ellipse (p, + CGAL::square(_point_size), + CGAL::square(_point_size), + _color, 1, FIG_SOLID, _style_value, + _color, FIG_FILLED); + + break; + } + + case (FIG_SQUARE): + case (FIG_BOX): + case (FIG_RHOMBUS): + case (FIG_DIAMOND): + { + // Prepare the rectangle vertices. + std::vector vertices (4); + + if (_point_style == FIG_SQUARE || _point_style == FIG_BOX) + { + vertices[0] = Point_2 (p.x() - _point_size, p.y() - _point_size); + vertices[1] = Point_2 (p.x() - _point_size, p.y() + _point_size); + vertices[2] = Point_2 (p.x() + _point_size, p.y() + _point_size); + vertices[3] = Point_2 (p.x() + _point_size, p.y() - _point_size); + } + else + { + vertices[0] = Point_2 (p.x(), p.y() - _point_size); + vertices[1] = Point_2 (p.x() + _point_size, p.y()); + vertices[2] = Point_2 (p.x(), p.y() + _point_size); + vertices[3] = Point_2 (p.x() - _point_size, p.y()); + } + + if (_point_style == FIG_SQUARE || _point_style == FIG_RHOMBUS) + { + // Draw an empty rectangular shape (use a solid line with width 1). + _write_polygon (4, vertices.begin(), vertices.end(), + _color, 1, FIG_SOLID, _style_value, + FIG_WHITE, FIG_NOT_FILLED); + } + else + { + // Draw a filled rectangular shape. + _write_polygon (4, vertices.begin(), vertices.end(), + _color, 1, FIG_SOLID, _style_value, + _color, FIG_FILLED); + } + + break; + } + } + + return; + } + + /*! + * Write a segment. + */ + void write_segment (const Segment_2& seg) + { + CGAL_precondition (_ofile.is_open()); + + // Clip the ray using the bounding rectangle. + CGAL::Object obj = intersect_func (_bound_rect, seg); + Segment_2 clipped_seg; + + // Draw only the clipped segment (draw nothing if the segment does not + // intersect the bounding rectangle). + if (CGAL::assign (clipped_seg, obj)) + { + _write_segment (clipped_seg, + _color, _line_width, _line_style, _style_value, + false); + } + + return; + } + + /*! + * Write a ray. + */ + void write_ray (const Ray_2& ray) + { + CGAL_precondition (_ofile.is_open()); + + // Clip the ray using the bounding rectangle. + CGAL::Object obj = intersect_func (_bound_rect, ray); + Segment_2 seg; + + // Draw only the clipped segment (draw nothing if the ray does not + // intersect the bounding rectangle). + if (CGAL::assign (seg, obj)) + { + _write_segment (seg, + _color, _line_width, _line_style, _style_value, + false); + } + + return; + } + + /*! + * Write a line. + */ + void write_line (const Line_2& line) + { + CGAL_precondition (_ofile.is_open()); + + // Clip the ray using the bounding rectangle. + CGAL::Object obj = intersect_func (_bound_rect, line); + Segment_2 seg; + + // Draw only the clipped segment (draw nothing if the ray does not + // intersect the bounding rectangle). + if (CGAL::assign (seg, obj)) + { + _write_segment (seg, + _color, _line_width, _line_style, _style_value, + false); + } + + return; + } + + /*! + * Write a triangle. + */ + void write_triangle (const Triangle_2& tri) + { + CGAL_precondition (_ofile.is_open()); + + std::vector vertices(3); + + vertices[0] = tri.vertex(0); + vertices[1] = tri.vertex(1); + vertices[2] = tri.vertex(2); + + _write_polygon (3, vertices.begin(), vertices.end(), + _color, _line_width, _line_style, _style_value, + _fill_color, _fill_style); + return; + } + + /*! + * Write an iso-rectangle. + */ + void write_rectangle (const Iso_rectangle_2& rect) + { + CGAL_precondition (_ofile.is_open()); + + std::vector vertices(4); + + vertices[0] = rect.vertex(0); + vertices[1] = rect.vertex(1); + vertices[2] = rect.vertex(2); + vertices[3] = rect.vertex(3); + + _write_polygon (4, vertices.begin(), vertices.end(), + _color, _line_width, _line_style, _style_value, + _fill_color, _fill_style); + return; + } + + /*! + * Write a polyline. + * \param begin An iterator of the control points (of type Point_2). + * \param end A past-the-end iterator for the control points. + */ + template + void write_polyline (const Input_iterator& begin, const Input_iterator& end) + { + CGAL_precondition (_ofile.is_open()); + + _write_polyline (begin, end, + _color, _line_width, _line_style, _style_value, false); + return; + } + + /*! + * Write a polygon. + */ + void write_polygon (const Polygon_2& pgn) + { + CGAL_precondition (_ofile.is_open()); + + _write_polygon (pgn.size(), + pgn.vertices_begin(), pgn.vertices_end(), + _color, _line_width, _line_style, _style_value, + _fill_color, _fill_style); + return; + } + + /*! + * Write a circle. + */ + void write_circle (const Circle_2& circ) + { + CGAL_precondition (_ofile.is_open()); + + _write_ellipse (circ.center(), + circ.squared_radius(), circ.squared_radius(), + _color, _line_width, _line_style, _style_value, + _fill_color, _fill_style); + return; + } + + /*! + * Write a canonical ellipse. + * \param center The center of the ellipse (the intersection of its axes). + * \param r1_squared The squared length of the axis parallel to the x-axis. + * \param r2_squared The squared length of the axis parallel to the y-axis. + */ + void write_ellipse (const Point_2& center, + const NT& r1_squared, const NT& r2_squared) + { + CGAL_precondition (_ofile.is_open()); + + _write_ellipse (center, + r1_squared, r2_squared, + _color, _line_width, _line_style, _style_value, + _fill_color, _fill_style); + return; + } + + /*! + * Write a circular arc. + * \param p1 The source point of the arc. + * \param p2 A midpoint on the arc. + * \param p3 The target point of the arc. + * \pre The three points are not collinear. + */ + void write_circular_arc (const Point_2& p1, + const Point_2& p2, + const Point_2& p3) + { + CGAL_precondition (_ofile.is_open()); + + _write_arc (p1, p2, p3, + _color, _line_width, _line_style, _style_value); + return; + } + + /*! + * Write a spline. + * \param begin An iterator of the control points (of type Point_2). + * \param end A past-the-end iterator for the control points. + * \param factor A shape factor for the spline: A value in the range [-1,1], + * where negative values are used for interpolated splines + * and positive values for approximated splines. + * The default value if 1. + */ + template + void write_spline (const Input_iterator& begin, const Input_iterator& end, + const float& factor = 1) + { + CGAL_precondition (_ofile.is_open()); + + if (begin == end) + return; + + // Normalize the shape factor. + float shape_factor; + + if (factor > 1) + shape_factor = 1; + else if (factor < -1) + shape_factor = -1; + else + shape_factor = factor; + + _write_spline (begin, end, shape_factor, + _color, _line_width, _line_style, _style_value); + } + + /*! + * Write a text box. + * \param pos The lower-left corner of the text box. + * \param text The text to write. + * \param angle The angle (in radians) that the text forms with the x-axis + * (0 by default). + */ + void write_text (const Point_2& pos, + const char *text, + const double& angle = 0) + { + CGAL_precondition (_ofile.is_open()); + + if (text == NULL || strlen(text) == 0) + return; + + _write_text (pos, + reinterpret_cast(text), strlen(text), + angle, + _color, _font, _font_size); + return; + } + //@} + + /// \name Setting the draw properties via the << operator. + //@{ + + /*! + * Set the depth. + */ + Fig_stream& operator<< (const Fig_depth& depth) + { + set_depth (static_cast(depth)); + return (*this); + } + + /*! + * Set the color. + */ + Fig_stream& operator<< (const Fig_color& color) + { + set_color (color); + return (*this); + } + + /*! + * Set the line style. + */ + Fig_stream& operator<< (const Fig_line_style& style) + { + set_line_style (style); + return (*this); + } + + /*! + * Set the fill style. + */ + Fig_stream& operator<< (const Fig_fill_style& style) + { + set_fill_style (style); + return (*this); + } + + /*! + * Set the point style. + */ + Fig_stream& operator<< (const Fig_point_style& style) + { + set_point_style (style); + return (*this); + } + + /*! + * Set the arrow drawing mode. This mode will be applied when drawing + * segments, polylines, circular arcs or splines. + */ + Fig_stream& operator<< (const Fig_arrow_mode& mode) + { + set_arrow_mode (mode); + return (*this); + } + + /*! + * Set the arrow type. + */ + Fig_stream& operator<< (const Fig_arrow_type& type) + { + set_arrow_type (type); + return (*this); + } + + /*! + * Set the font. + */ + Fig_stream& operator<< (const Fig_font& font) + { + set_font (font); + return (*this); + } + //@} + + /// \name Drawing objects via the << operator. + //@{ + + /*! + * Write a point. + */ + Fig_stream& operator<< (const Point_2& p) + { + write_point (p); + return (*this); + } + + /*! + * Write a line segment. + */ + Fig_stream& operator<< (const Segment_2& seg) + { + write_segment (seg); + return (*this); + } + + /*! + * Write a ray. + */ + Fig_stream& operator<< (const Ray_2& ray) + { + write_ray (ray); + return (*this); + } + + /*! + * Write a line. + */ + Fig_stream& operator<< (const Line_2& line) + { + write_line (line); + return (*this); + } + + /*! + * Write a triangle. + */ + Fig_stream& operator<< (const Triangle_2& tri) + { + write_triangle (tri); + return (*this); + } + + /*! + * Write a rectangle. + */ + Fig_stream& operator<< (const Iso_rectangle_2& rect) + { + write_rectangle (rect); + return (*this); + } + + /*! + * Write a polygon. + */ + Fig_stream& operator<< (const Polygon_2& pgn) + { + write_polygon (pgn); + return (*this); + } + + /*! + * Write a circle. + */ + Fig_stream& operator<< (const Circle_2& circ) + { + write_circle (circ); + return (*this); + } + //@} + +protected: + + /*! + * Convert a point to FIG units. + */ + void _convert_point (const Point_2& p, + int& ix, int& iy) const + { + ix = static_cast (_scale * + CGAL::to_double(p.x() - _bound_rect.xmin())); + iy = static_cast (_scale * + CGAL::to_double( _bound_rect.ymax() - p.y())); + return; + } + + /*! + * Write a segment. + */ + void _write_segment (const Segment_2& seg, + const Fig_color& line_color, + const int& line_width, + const Fig_line_style& line_style, + const double& style_value, + const bool& draw_arrows) + { + // Convert the segment to a polyline with two points and write it. + std::vector points (2); + + points[0] = seg.source(); + points[1] = seg.target(); + + _write_polyline (points.begin(), points.end(), + line_color, line_width, line_style, style_value, + draw_arrows); + return; + } + + /*! + * Write a polyline. + */ + template + void _write_polyline (Input_iterator begin, Input_iterator end, + const Fig_color& line_color, + const int& line_width, + const Fig_line_style& line_style, + const double& style_value, + const bool& draw_arrows) + { + // Check if we should draw arrows. + bool forward_arrow = false; + bool backward_arrow = false; + + if (draw_arrows) + { + forward_arrow = (_arrow_mode == FIG_FORWARD_ARROW) || + (_arrow_mode == FIG_BOTH_ARROWS); + backward_arrow = (_arrow_mode == FIG_BACKWARD_ARROW) || + (_arrow_mode == FIG_BOTH_ARROWS); + } + + // Count the number of points in the spline. + int n_points = std::distance (begin, end); + + // Write the segment properties. + _ofile << "2 1 " // Desginate a polyline. + << line_style << ' ' + << line_width << ' ' + << line_color << ' ' + << FIG_WHITE << ' ' // Fill color (dummy). + << _depth << ' ' + << "0 " // Pen style (not in use, always 0). + << FIG_NOT_FILLED << ' ' + << style_value << ' ' + << "0 " // Join style (always 0). + << "0 " // Cap style (always 0). + << "-1 " // Radius (not in use for lines). + << forward_arrow << ' ' + << backward_arrow << ' ' + << n_points << std::endl; + + // Write the points defining the polyline. + bool is_first = true; + int ix, iy; + + while (begin != end) + { + if (is_first) + { + _ofile << '\t'; + is_first = false; + } + else + { + _ofile << ' '; + } + + _convert_point (*begin, ix, iy); + _ofile << ix << ' ' << iy; + + begin++; + } + _ofile << std::endl; + + // Write the arrows, if necessary. + if (forward_arrow) + _write_arrow_line (); + + if (backward_arrow) + _write_arrow_line (); + + return; + } + + /*! + * Write a polygon, reprsented as a range of points. + */ + template + void _write_polygon (const int n_points, + Input_iterator begin, Input_iterator end, + const Fig_color& line_color, + const int line_width, + const Fig_line_style& line_style, + const double& style_value, + const Fig_color& fill_color, + const Fig_fill_style& fill_style) + { + // Write the polyline properties. + _ofile << "2 3 " // Desginate a polygon. + << line_style << ' ' + << line_width << ' ' + << line_color << ' ' + << fill_color << ' ' + << _depth << ' ' + << "0 " // Pen style (not in use, always 0). + << fill_style << ' ' + << style_value << ' ' + << "0 " // Join style (always 0). + << "0 " // Cap style (always 0). + << "-1 " // Radius (not in use for lines). + << "0 " // No forward arrow. + << "0 " // No backward arrow. + << n_points + 1 << std::endl; + + // Write the points. + bool is_first = true; + Point_2 first = *begin; + int ix, iy; + + while (begin != end) + { + if (is_first) + { + _ofile << '\t'; + is_first = false; + } + else + { + _ofile << ' '; + } + + _convert_point (*begin, ix, iy); + _ofile << ix << ' ' << iy; + + begin++; + } + + // Write the first point again. + _convert_point (first, ix, iy); + _ofile << ' ' << ix << ' ' << iy << std::endl; + + return; + } + + /*! + * Write an ellipse. + */ + void _write_ellipse (const Point_2& center, + const NT& squared_radius_x, + const NT& squared_radius_y, + const Fig_color& line_color, + const int& line_width, + const Fig_line_style& line_style, + const double& style_value, + const Fig_color& fill_color, + const Fig_fill_style& fill_style) + { + // Write the ellipse properties. + _ofile << "1 1 " // Desginate an ellipse. + << line_style << ' ' + << line_width << ' ' + << line_color << ' ' + << fill_color << ' ' + << _depth << ' ' + << "0 " // Pen style (not in use, always 0). + << fill_style << ' ' + << style_value << ' ' + << "1 " // Direction (always 1). + << "0.000 "; // Angle (in radians). + + // Write the center point. + int ix, iy; + + _convert_point (center, ix, iy); + _ofile << ' ' << ix << ' ' << iy; + + // Write the radii. + int rx = static_cast (_scale * + std::sqrt(CGAL::to_double(squared_radius_x))); + int ry = static_cast (_scale * + std::sqrt(CGAL::to_double(squared_radius_y))); + + _ofile << ' ' << rx << ' ' << ry; + + // Write the start point (the center) and the end point (one corner of + // the rectangles bounding the ellipse). + _ofile << ' ' << ix << ' ' << iy + << ' ' << (ix + rx) << ' ' << (iy +ry) << std::endl; + + return; + } + + /*! + * Write an arc. + */ + void _write_arc (const Point_2& p1, const Point_2& p2, const Point_2& p3, + const Fig_color& line_color, + const int& line_width, + const Fig_line_style& line_style, + const double& style_value) + { + // Check if we should draw arrows. + bool forward_arrow; + bool backward_arrow; + + forward_arrow = (_arrow_mode == FIG_FORWARD_ARROW) || + (_arrow_mode == FIG_BOTH_ARROWS); + backward_arrow = (_arrow_mode == FIG_BACKWARD_ARROW) || + (_arrow_mode == FIG_BOTH_ARROWS); + + // Construct the supporting circle of the arc and use its center and + // orientation. + Circle_2 circ (p1, p2, p3); + int orient = (circ.orientation() == CGAL::CLOCKWISE) ? 0 : 1; + + // Write the arc properties. + _ofile << "5 1 " // Desginate an open arc. + << line_style << ' ' + << line_width << ' ' + << line_color << ' ' + << FIG_WHITE << ' ' // Fill color (dummy). + << _depth << ' ' + << "0 " // Pen style (not in use, always 0). + << FIG_NOT_FILLED << ' ' + << style_value << ' ' + << "0 " // Cap style (always 0). + << orient << ' ' + << forward_arrow << ' ' + << backward_arrow << ' '; + + // Write the center of the circle. + int ix, iy; + + _convert_point (circ.center(), ix, iy); + _ofile << ix << ' ' << iy; + + // Write the three points defining the arc. + _convert_point (p1, ix, iy); + _ofile << ' ' << ix << ' ' << iy; + + _convert_point (p2, ix, iy); + _ofile << ' ' << ix << ' ' << iy; + + _convert_point (p3, ix, iy); + _ofile << ' ' << ix << ' ' << iy << std::endl; + + // Write the arrows, if necessary. + if (forward_arrow) + _write_arrow_line (); + + if (backward_arrow) + _write_arrow_line (); + + return; + } + + /*! + * Write a spline + */ + template + void _write_spline (Input_iterator begin, Input_iterator end, + const float& factor, + const Fig_color& line_color, + const int& line_width, + const Fig_line_style& line_style, + const double& style_value) + { + // Check if we should draw arrows. + bool forward_arrow; + bool backward_arrow; + + forward_arrow = (_arrow_mode == FIG_FORWARD_ARROW) || + (_arrow_mode == FIG_BOTH_ARROWS); + backward_arrow = (_arrow_mode == FIG_BACKWARD_ARROW) || + (_arrow_mode == FIG_BOTH_ARROWS); + + // Count the number of points in the spline. + int n_points = std::distance (begin, end); + + // Write the spline properties. + _ofile << "3 0 " // Desginate an open spline. + << line_style << ' ' + << line_width << ' ' + << line_color << ' ' + << FIG_WHITE << ' ' // Fill color (dummy). + << _depth << ' ' + << "0 " // Pen style (not in use, always 0). + << FIG_NOT_FILLED << ' ' + << style_value << ' ' + << "0 " // Cap style (always 0). + << forward_arrow << ' ' + << backward_arrow << ' ' + << n_points << std::endl; + + // Write the points defining the spline. + bool is_first = true; + int ix, iy; + + while (begin != end) + { + if (is_first) + { + _ofile << '\t'; + is_first = false; + } + else + { + _ofile << ' '; + } + + _convert_point (*begin, ix, iy); + _ofile << ix << ' ' << iy; + + begin++; + } + _ofile << std::endl; + + // Write the shape factors: 0 for the endpoints and (factor) for each + // of the midpoints. + int i; + + _ofile << '\t' << "0.000"; + for (i = 0; i < n_points - 2; i++) + _ofile << ' ' << factor; + _ofile << '\t' << "0.000" << std::endl; + + // Write the arrows, if necessary. + if (forward_arrow) + _write_arrow_line (); + + if (backward_arrow) + _write_arrow_line (); + + return; + } + + /*! + * Write an arrow line. + */ + void _write_arrow_line () + { + int width = static_cast (_scale * CGAL::to_double(_arrow_width)); + int height = static_cast (_scale * CGAL::to_double(_arrow_height)); + + _ofile << _arrow_type << ' ' + << "0 " // Arrow style (always 0). + << _line_width << ' ' + << width << ' ' + << height << std::endl; + return; + } + + /*! + * Write a text box. + */ + void _write_text (const Point_2& pos, + const unsigned char *text, + const int& len_text, + const double& angle, + const Fig_color& font_color, + const Fig_font& font, + const int& font_size) + { + // Compute the text-box dimensions. + const int text_height = font_size * 1200 / 80; + const int text_width = len_text * font_size * 1200 / 160; + + // Write the text properties. + _ofile << "4 0 " // Desginate left-justified text. + << font_color << ' ' + << _depth << ' ' + << "0 " // Pen style (not in use, always 0). + << font << ' ' + << font_size << ' ' + << angle << ' ' + << "2 " // Indicates a special LaTeX font. + << text_height << ' ' + << text_width; + + // Write the position coordinates. + int ix, iy; + + _convert_point (pos, ix, iy); + _ofile << ' ' << ix << ' ' << iy << ' '; + + // Write the text. + char oct[10]; + int i; + + for (i = 0; i < len_text; i++) + { + if (text[i] >= ' ' && text[i] < 128 && text[i] != '\\') + { + // If the current character is printable, just write it. + _ofile << static_cast(text[i]); + } + else + { + // Convert the current character to an octal string and write it. + sprintf (oct, "\\%03o", text[i]); + _ofile << oct; + } + } + + // Write the end-of-string sequence. + _ofile << "\\001" << std::endl; + + return; + } + + /*! + * Reset all user-defined colors. + */ + void _reset_colors () + { + int i; + + for (i = 0; i < FIG_FIRST_USER_DEFINED_COLOR; i++) + colors[i] = true; + + for (i = FIG_FIRST_USER_DEFINED_COLOR; + i < FIG_LAST_USER_DEFINED_COLOR; i++) + { + colors[i] = false; + } + + return; + } +}; + +CGAL_END_NAMESPACE + +#endif diff --git a/Arrangement_on_surface_2/include/CGAL/IO/Fig_stream_Conic_arc_2.h b/Arrangement_on_surface_2/include/CGAL/IO/Fig_stream_Conic_arc_2.h new file mode 100644 index 00000000000..c07c1027322 --- /dev/null +++ b/Arrangement_on_surface_2/include/CGAL/IO/Fig_stream_Conic_arc_2.h @@ -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 + +#ifndef CGAL_FIG_STREAM_CONIC_ARC_2_H +#define CGAL_FIG_STREAM_CONIC_ARC_2_H + +#include +#include + +/*! + * Write an x-monotone conic arc to a FIG stream. + */ +template +static void _write_x_monotone_conic_arc + (CGAL::Fig_stream& 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 +void write_conic_arc + (CGAL::Fig_stream& 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 xcvs; + + traits.make_x_monotone_2_object() (cv, + std::back_inserter(xcvs)); + + // Write the x-monotone sub-arcs. + typename std::list::iterator xit; + + for (xit = xcvs.begin(); xit != xcvs.end(); ++xit) + _write_x_monotone_conic_arc (fs, *xit); + + return; +} + +#endif diff --git a/Arrangement_on_surface_2/include/CGAL/IO/Polyline_2_postscript_file_stream.h b/Arrangement_on_surface_2/include/CGAL/IO/Polyline_2_postscript_file_stream.h new file mode 100644 index 00000000000..6b6bca78d26 --- /dev/null +++ b/Arrangement_on_surface_2/include/CGAL/IO/Polyline_2_postscript_file_stream.h @@ -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 + +#ifndef CGAL_POLYLINE_POSTSCRIPT_FILE_STREAM_H +#define CGAL_POLYLINE_POSTSCRIPT_FILE_STREAM_H + +/*! \file + * Postscript output stream for the Polyline_2 class. + */ + +#include +#include + +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 Postscript_file_stream & +operator<<(Postscript_file_stream & ps_stream, + const _Polyline_2 & polyline) +{ + unsigned int i; + for (i = 0; i < polyline.size(); ++i) ps_stream << polyline[i]; + return ps_stream; +} + +CGAL_END_NAMESPACE + +#endif diff --git a/Arrangement_on_surface_2/include/CGAL/IO/Qt_widget_Conic_arc_2.h b/Arrangement_on_surface_2/include/CGAL/IO/Qt_widget_Conic_arc_2.h new file mode 100644 index 00000000000..b7a165788f0 --- /dev/null +++ b/Arrangement_on_surface_2/include/CGAL/IO/Qt_widget_Conic_arc_2.h @@ -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 +// Efi Fogel + +#ifndef CGAL_QT_WIDGET_CONIC_ARC_2_H +#define CGAL_QT_WIDGET_CONIC_ARC_2_H + +#include +#include +#include + +CGAL_BEGIN_NAMESPACE + +/*! + * Draw an x-monotone conic arc. + */ +template +Qt_widget& operator<< (Qt_widget& ws, + const _Conic_x_monotone_arc_2& 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 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 +Qt_widget& operator<< + (Qt_widget& ws, + const typename Arr_conic_traits_2::Curve_2& cv) +{ + typedef Arr_conic_traits_2 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_arcs; + typename std::list::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 diff --git a/Arrangement_on_surface_2/include/CGAL/IO/Qt_widget_Linear_object_2.h b/Arrangement_on_surface_2/include/CGAL/IO/Qt_widget_Linear_object_2.h new file mode 100644 index 00000000000..c22396e6ae1 --- /dev/null +++ b/Arrangement_on_surface_2/include/CGAL/IO/Qt_widget_Linear_object_2.h @@ -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 +// Efi Fogel + +#ifndef CGAL_QT_WIDGET_POLYLINE_2_H +#define CGAL_QT_WIDGET_POLYLINE_2_H + +#include +#include + +CGAL_BEGIN_NAMESPACE + +/*! + * Export a polyline to a window stream + */ +template +Qt_widget & operator<<(Qt_widget & ws, const Arr_linear_object_2 & 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 diff --git a/Arrangement_on_surface_2/include/CGAL/IO/Qt_widget_Polyline_2.h b/Arrangement_on_surface_2/include/CGAL/IO/Qt_widget_Polyline_2.h new file mode 100644 index 00000000000..3f3b944c5cc --- /dev/null +++ b/Arrangement_on_surface_2/include/CGAL/IO/Qt_widget_Polyline_2.h @@ -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 +// Efi Fogel + +#ifndef CGAL_QT_WIDGET_POLYLINE_2_H +#define CGAL_QT_WIDGET_POLYLINE_2_H + +#include +#include + +CGAL_BEGIN_NAMESPACE + +/*! + * Export a polyline to a window stream + */ +template +Qt_widget & operator<<(Qt_widget & ws, const _Polyline_2 & cv) +{ + for (unsigned int i = 0; i < cv.size(); ++i) ws << cv[i]; + return ws; +} + +CGAL_END_NAMESPACE + +#endif