contrib/brl/bbas/bxml/bsvg/bsvg_element.h
Go to the documentation of this file.
00001 #ifndef bsvg_element_h_ 
00002 #define bsvg_element_h_
00003 //:
00004 // \file
00005 // \brief Primitives of an SVG library using bxml
00006 //
00007 //           files created in svg format may be rendered by any web browser.
00008 //
00009 //           So far, added basic shapes: rectangle, line, ellipse, polyline. 
00010 //           Other shapes supported by SVG can also be added such as polygon etc. Just subclass from bsvg_element class and write a constructor.
00011 //
00012 // \author Ozge C. Ozcanli (Brown)
00013 // \date   April 21, 2009
00014 //
00015 // \verbatim
00016 //  Modifications
00017 //   Ozge C. Ozcanli - July 08, 09 - ported to vxl from local repository - minor fixes
00018 // \endverbatim
00019 
00020 #include <bxml/bxml_document.h>
00021 
00022 class bsvg_element : public bxml_element
00023 {
00024  public:
00025   bsvg_element(const vcl_string& name) : bxml_element(name) {}
00026   //:  rotation angle is specified in degrees, e.g. 90
00027   void set_transformation(float trans_x, float trans_y, float rot_angle);
00028   void set_location(float trans_x, float trans_y);
00029   //: adds rotation to an existing translation if any angle is specified in degrees, e.g. 90
00030   void set_rotation(float rot_angle);
00031   void set_fill_color(const vcl_string& c);
00032   //: turns the given red, green, blue values in range [0,255] to #00 00 00 notation (Hex color) for each color
00033   void set_fill_color(unsigned red, unsigned green, unsigned blue);
00034   void set_stroke_color(const vcl_string& c);
00035   //: turns the given red, green, blue values in range [0,255] to #00 00 00 notation (Hex color) for each color
00036   void set_stroke_color(unsigned red, unsigned green, unsigned blue);
00037   void set_stroke_width(float w);
00038   //: 0 <= opacity <= 1
00039   void set_fill_opacity(float o);
00040   //: 0 <= opacity <= 1
00041   void set_stroke_opacity(float o);
00042 };
00043 
00044 class bsvg_text : public bsvg_element
00045 {
00046  public:
00047   bsvg_text(const vcl_string& msg) : bsvg_element("text") { this->append_text(msg); }
00048   void set_font_size(int s);
00049 };
00050 
00051 //: an SVG tag to group elements.
00052 //  e.g. define a group translation and rotation then apply it to all the members of the group
00053 //  or define a stroke-color, fill opacity etc. once and apply it to all the group
00054 class bsvg_group : public bsvg_element
00055 {
00056  public:
00057   bsvg_group() : bsvg_element("g") { this->append_text("\n"); }
00058   bool add_element(const bxml_data_sptr& element) { this->append_data(element); this->append_text("\n"); return true; }
00059 };
00060 
00061 class bsvg_ellipse : public bsvg_element
00062 {
00063  public:
00064   bsvg_ellipse(float rx, float ry);
00065 };
00066 
00067 class bsvg_rectangle : public bsvg_element
00068 {
00069  public:
00070   bsvg_rectangle(float x, float y, float width, float height);
00071 };
00072 
00073 class bsvg_line : public bsvg_element
00074 {
00075  public:
00076   bsvg_line(float x1, float y1, float x2, float y2);
00077 };
00078 
00079 //: tip of the arrow will be at x, y and the length will be l
00080 class bsvg_arrow_head : public bsvg_group
00081 {
00082  public:
00083   bsvg_arrow_head(float x, float y, float l);
00084 };
00085 
00086 class bsvg_polyline : public bsvg_element
00087 {
00088  public:
00089   bsvg_polyline(const vcl_vector<float>& xs, const vcl_vector<float>& ys);
00090 };
00091 
00092 //: draw a splice e.g. for a "pie chart".
00093 //  A splice is an arc of a full circle given by start and end angles and the
00094 //  arc is closed at the ends by lines from and to the center of the circle pass
00095 //  the angles in radians in range [0,2pi]
00096 //  when long_arc = true plots the arc (end_angle, start_angle) (so goes the other way around the circle)
00097 class bsvg_splice : public bsvg_group
00098 {
00099  public: 
00100   bsvg_splice(float center_x, float center_y, float radius, float start_angle, float end_angle, bool long_arc = false);
00101 };
00102 
00103 #endif  // bsvg_element_h_