⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fig_stream.h

📁 很多二维 三维几何计算算法 C++ 类库
💻 H
📖 第 1 页 / 共 3 页
字号:
// 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: svn+ssh://scm.gforge.inria.fr/svn/cgal/branches/CGAL-3.3-branch/Arrangement_2/include/CGAL/IO/Fig_stream.h $// $Id: Fig_stream.h 36312 2007-02-15 16:08:11Z efif $// // Author(s)     : Ron Wein           <wein@post.tau.ac.il>#ifndef CGAL_FIG_STREAM_H#define CGAL_FIG_STREAM_H#include <CGAL/basic.h>#include <CGAL/Polygon_2.h>#include <vector>#include <fstream>#include <stdio.h>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 Kernel_>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<Kernel>                      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<Kernel>& );  const Fig_stream<Kernel>& operator= (const Fig_stream<Kernel>& );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<int>(FIG_MIN_DEPTH))      _depth = static_cast<int>(FIG_MIN_DEPTH);    else if (depth > static_cast<int>(FIG_MAX_DEPTH))      _depth = static_cast<int>(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<int>(width);    return;  }  /*!   * Set the line style.   */  void set_line_style (const Fig_line_style& style)  {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -