📄 fig_stream.h
字号:
{ 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<int> (_scale * CGAL::to_double(p.x() - _bound_rect.xmin())); iy = static_cast<int> (_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<Point_2> 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 <class Input_iterator> 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 <class Input_iterator> 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<int> (_scale * std::sqrt(CGAL::to_double(squared_radius_x))); int ry = static_cast<int> (_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 <class Input_iterator> 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<int> (_scale * CGAL::to_double(_arrow_width)); int height = static_cast<int> (_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<char>(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
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -