1 #ifndef bsvg_element_h_
2 #define bsvg_element_h_
3 //:
4 // \file
5 // \brief Primitives of an SVG library using bxml
6 //
7 //           files created in svg format may be rendered by any web browser.
8 //
9 //           So far, added basic shapes: rectangle, line, ellipse, polyline.
10 //           Other shapes supported by SVG can also be added such as polygon etc. Just subclass from bsvg_element class and write a constructor.
11 //
12 // \author Ozge C. Ozcanli (Brown)
13 // \date   April 21, 2009
14 //
15 // \verbatim
16 //  Modifications
17 //   Ozge C. Ozcanli - July 08, 09 - ported to vxl from local repository - minor fixes
18 // \endverbatim
19 
20 #include <bxml/bxml_document.h>
21 
22 class bsvg_element : public bxml_element
23 {
24  public:
bsvg_element(const std::string & name)25   bsvg_element(const std::string& name) : bxml_element(name) {}
26   //:  rotation angle is specified in degrees, e.g. 90
27   void set_transformation(float trans_x, float trans_y, float rot_angle);
28   void set_location(float trans_x, float trans_y);
29   //: adds rotation to an existing translation if any angle is specified in degrees, e.g. 90
30   void set_rotation(float rot_angle);
31   void set_fill_color(const std::string& c);
32   //: turns the given red, green, blue values in range [0,255] to #00 00 00 notation (Hex color) for each color
33   void set_fill_color(unsigned red, unsigned green, unsigned blue);
34   void set_stroke_color(const std::string& c);
35   //: turns the given red, green, blue values in range [0,255] to #00 00 00 notation (Hex color) for each color
36   void set_stroke_color(unsigned red, unsigned green, unsigned blue);
37   void set_stroke_width(float w);
38   //: 0 <= opacity <= 1
39   void set_fill_opacity(float o);
40   //: 0 <= opacity <= 1
41   void set_stroke_opacity(float o);
42 };
43 
44 class bsvg_text : public bsvg_element
45 {
46  public:
bsvg_text(const std::string & msg)47   bsvg_text(const std::string& msg) : bsvg_element("text") { this->append_text(msg); }
48   void set_font_size(int s);
49 };
50 
51 //: an SVG tag to group elements.
52 //  e.g. define a group translation and rotation then apply it to all the members of the group
53 //  or define a stroke-color, fill opacity etc. once and apply it to all the group
54 class bsvg_group : public bsvg_element
55 {
56  public:
bsvg_group()57   bsvg_group() : bsvg_element("g") { this->append_text("\n"); }
add_element(const bxml_data_sptr & element)58   bool add_element(const bxml_data_sptr& element) { this->append_data(element); this->append_text("\n"); return true; }
59 };
60 
61 class bsvg_ellipse : public bsvg_element
62 {
63  public:
64   bsvg_ellipse(float rx, float ry);
65 };
66 
67 class bsvg_rectangle : public bsvg_element
68 {
69  public:
70   bsvg_rectangle(float x, float y, float width, float height);
71 };
72 
73 class bsvg_line : public bsvg_element
74 {
75  public:
76   bsvg_line(float x1, float y1, float x2, float y2);
77 };
78 
79 //: tip of the arrow will be at x, y and the length will be l
80 class bsvg_arrow_head : public bsvg_group
81 {
82  public:
83   bsvg_arrow_head(float x, float y, float l);
84 };
85 
86 class bsvg_polyline : public bsvg_element
87 {
88  public:
89   bsvg_polyline(const std::vector<float>& xs, const std::vector<float>& ys);
90 };
91 
92 //: draw a splice e.g. for a "pie chart".
93 //  A splice is an arc of a full circle given by start and end angles and the
94 //  arc is closed at the ends by lines from and to the center of the circle pass
95 //  the angles in radians in range [0,2pi]
96 //  when long_arc = true plots the arc (end_angle, start_angle) (so goes the other way around the circle)
97 class bsvg_splice : public bsvg_group
98 {
99  public:
100   bsvg_splice(float center_x, float center_y, float radius, float start_angle, float end_angle, bool long_arc = false);
101 };
102 
103 #endif  // bsvg_element_h_
104