00001 // This is core/vgui/vgui_easy2D_tableau.h 00002 #ifndef vgui_easy2D_tableau_h_ 00003 #define vgui_easy2D_tableau_h_ 00004 #ifdef VCL_NEEDS_PRAGMA_INTERFACE 00005 #pragma interface 00006 #endif 00007 //: 00008 // \file 00009 // \author Philip C. Pritchett, Robotics Research Group, University of Oxford 00010 // \date 24 Sep 1999 00011 // \brief Tableau to display two-dimensional geometric objects. 00012 // 00013 // Contains classes: vgui_easy2D_tableau vgui_easy2D_tableau_new 00014 // 00015 // \verbatim 00016 // Modifications 00017 // 24-SEP-1999 P.Pritchett - Initial version. 00018 // 20-JUL-2000 Marko Bacic - Provided support for printing linestrips 00019 // 25-APR-2002 domi at vision.ee.ethz.ch - make print_psfile work without 00020 // image tableau 00021 // 26-APR-2002 K.Y.McGaul - Added some doxygen-style documentation. 00022 // 01-OCT-2002 K.Y.McGaul - Moved vgui_easy2D to vgui_easy2D_tableau. 00023 // - Added functions clear, remove, get_all. 00024 // \endverbatim 00025 00026 #include <vgui/vgui_displaylist2D_tableau.h> 00027 #include <vgui/vgui_parent_child_link.h> 00028 #include <vgui/vgui_image_tableau.h> 00029 #include <vgui/vgui_easy2D_tableau_sptr.h> 00030 #include <vgui/vgui_style_sptr.h> 00031 00032 class vgui_soview2D; 00033 class vgui_soview2D_point; 00034 class vgui_soview2D_lineseg; 00035 class vgui_soview2D_infinite_line; 00036 class vgui_soview2D_circle; 00037 class vgui_soview2D_ellipse; 00038 class vgui_soview2D_linestrip; 00039 class vgui_soview2D_polygon; 00040 class vgui_soview2D_image; 00041 class vil1_image; 00042 00043 //: Tableau to display two-dimensional geometric objects. 00044 // 00045 // Two dimensional geometric objects (see vgui_soview2D) such as lines, 00046 // points, circles, etc can be added using add, or add_point, add_line, 00047 // add_circle, etc. 00048 // 00049 // The constructor of this tableau can accept a child tableau such as an 00050 // image or clear tableau on top of which the geometric objects will be 00051 // displayed (so for example, lines can be drawn on an image). To display 00052 // objects on a non-black, plain coloured background use a clear_tableau 00053 // and set its colour. 00054 // 00055 // To remove objects call remove(vgui_soview*). The vgui_soview* is returned 00056 // by add(), or you can get a list of all soviews using get_all(). To remove 00057 // all objects use clear(). 00058 // 00059 // The geometric objects on the easy2D (and any underlying image) can be saved 00060 // as PostScript by calling print_psfile. (If you just wish to save an image 00061 // of your easy2D you may want to use vgui_utils::dump_colour_buffer instead). 00062 class vgui_easy2D_tableau : public vgui_displaylist2D_tableau 00063 { 00064 public: 00065 //: Constructor - don't use this, use vgui_easy2D_tableau_new. 00066 // Create an easy2D with the given name. 00067 vgui_easy2D_tableau(const char* n="unnamed"); 00068 00069 //: Constructor - don't use this, use vgui_easy2D_tableau_new. 00070 // Creates an easy2D with the given image tableau as child. 00071 vgui_easy2D_tableau(vgui_image_tableau_sptr const&, const char* n="unnamed"); 00072 00073 //: Constructor - don't use this, use vgui_easy2D_tableau_new. 00074 // Creates an easy2D with the given child tableau. 00075 vgui_easy2D_tableau(vgui_tableau_sptr const&, const char* n="unnamed"); 00076 00077 //: Handle all events sent to this tableau. 00078 // In particular, use draw events to draw 2-dimensional geometric objects. 00079 bool handle(const vgui_event& e); 00080 00081 //: Returns the name given to this tableau in the constructor. 00082 vcl_string name() const { return name_; } 00083 00084 //: Returns the filename of the child image if there is one, else the name. 00085 vcl_string file_name() const; 00086 00087 //: Returns a nice version of the type, including details of any image file. 00088 vcl_string pretty_name() const; 00089 00090 //: Returns the type of this tableau ('vgui_easy2D_tableau'). 00091 vcl_string type_name() const; 00092 00093 //: Set the child tableau to be the given image_tableau. 00094 void set_image(vcl_string const& image); 00095 00096 //: Set the child tableau to be the given tableau. 00097 void set_child(vgui_tableau_sptr const&); 00098 00099 //: Set the colour of objects to the given red, green, blue, alpha values. 00100 void set_foreground(float r, float g, float b, float a = 1.0f); 00101 00102 //: Set the width of lines to the given width. 00103 void set_line_width(float w); 00104 00105 //: Set the radius of points to the given radius. 00106 void set_point_radius(float r); 00107 00108 //: Add the given two-dimensional object to the display. 00109 void add(vgui_soview2D*); 00110 00111 //: Add a point at the given position to the display. 00112 vgui_soview2D_point* add_point(float x, float y); 00113 00114 //: Add a finite line with the given start and end points to the display. 00115 // Note that this will be added as a vgui_lineseg (not 00116 // vgui_line - which doesn't exist). 00117 vgui_soview2D_lineseg* add_line(float x0, float y0, float x1, float y1); 00118 00119 //: Add an infinite line (ax + by +c = 0) to the display. 00120 vgui_soview2D_infinite_line* add_infinite_line(float a, float b, float c); 00121 00122 //: Add a circle with the given centre and radius to the display. 00123 vgui_soview2D_circle* add_circle(float x, float y, float r); 00124 00125 //: Add an ellipse with a given center, width, height, and angle 00126 vgui_soview2D_ellipse* add_ellipse(float x, float y, float w, 00127 float h, float phi); 00128 00129 //: Add a point with the given projective coordinates. 00130 vgui_soview2D_point* add_point_3dv(double const p[3]); 00131 00132 //: Add a line with the given projective start and end points. 00133 vgui_soview2D_lineseg* add_line_3dv_3dv(double const p1[3], 00134 double const p2[3]); 00135 00136 //: Add an infinite line with the given projective coordinates. 00137 vgui_soview2D_infinite_line* add_infinite_line_3dv(double const l[3]); 00138 00139 //: Add a circle with the given centre (in projective coords) and radius. 00140 vgui_soview2D_circle* add_circle_3dv(double const point[3], float r); 00141 00142 //: Add a linestrip with the given n vertices to the display. 00143 vgui_soview2D_linestrip* add_linestrip(unsigned n, float const *x, 00144 float const *y); 00145 00146 //: Add polygon with the given n vertices to the display. 00147 vgui_soview2D_polygon* add_polygon(unsigned n, float const *x, 00148 float const *y); 00149 00150 //: Remove the given soview from the display. 00151 void remove(vgui_soview* vso) { vgui_displaybase_tableau::remove(vso); } 00152 00153 //: Clear all soviews from the display. 00154 void clear() { vgui_displaybase_tableau::clear(); } 00155 00156 //: Returns a list of all soviews on the display. 00157 vcl_vector<vgui_soview*> const &get_all() const 00158 { return vgui_displaybase_tableau::get_all(); } 00159 00160 //: If the child tableau is an image_tableau, return this. 00161 vgui_image_tableau_sptr get_image_tableau() const { return image_image; } 00162 00163 //: Screen dump to postscript file. 00164 // Specify the optional arguments in case this tableau does not contain 00165 // an image tableau, or if you want a smaller part of the image printed. 00166 // If wd or ht are 0, no image is printed at all. 00167 void print_psfile(vcl_string filename, int reduction_factor, 00168 bool print_geom_objs, int wd=-1, int ht=-1); 00169 00170 #if 0 // deprecated method 00171 // \deprecated in favour of the overloaded versions with an image parameter. 00172 // This used to work without a segfault if you were lucky. 00173 // The newer versions that take an image parameter will work more reliably. 00174 vgui_soview2D_image* add_image(float x, float y, float w, float h, char *data, unsigned int format, unsigned int type); 00175 #endif 00176 00177 //: Add an image at the given position to the display. 00178 // 00179 // Alpha blending will be turned on iff the view has 4 planes. 00180 // 00181 vgui_soview2D_image* add_image( float x, float y, vil_image_view_base const& img ); 00182 00183 //: Add an image at the given position to the display. 00184 // 00185 // Alpha blending will be turned on iff the image has 4 components. 00186 // 00187 vgui_soview2D_image* add_image( float x, float y, vil1_image const& img ); 00188 00189 protected: 00190 //: Destructor - called by vgui_easy2D_tableau_sptr. 00191 ~vgui_easy2D_tableau() { } 00192 00193 //: Child tableau if there is one. 00194 vgui_parent_child_link image_slot; 00195 00196 //: Child image tableau, if there is one. 00197 vgui_image_tableau_sptr image_image; 00198 00199 //: Name of this tableau. 00200 vcl_string name_; 00201 00202 //: the style of the objects 00203 vgui_style_sptr style_; 00204 }; 00205 00206 //: Create a smart-pointer to a vgui_easy2D_tableau tableau. 00207 struct vgui_easy2D_tableau_new : public vgui_easy2D_tableau_sptr 00208 { 00209 //: Constructor - create an easy2D with the given name. 00210 vgui_easy2D_tableau_new(char const *n="unnamed") : 00211 vgui_easy2D_tableau_sptr(new vgui_easy2D_tableau(n)) { } 00212 00213 //: Constructor - create an easy2D with the given image tableau as child. 00214 vgui_easy2D_tableau_new(vgui_image_tableau_sptr const& i, char const* n="unnamed") : 00215 vgui_easy2D_tableau_sptr(new vgui_easy2D_tableau(i, n)) { } 00216 00217 //: Constructor - create an easy2D with the given child tableau. 00218 vgui_easy2D_tableau_new(vgui_tableau_sptr const& i, char const* n="unnamed") : 00219 vgui_easy2D_tableau_sptr(new vgui_easy2D_tableau(i, n)) { } 00220 }; 00221 00222 #endif // vgui_easy2D_tableau_h_