contrib/brl/bbas/bgui/bgui_graph_tableau.h
Go to the documentation of this file.
00001 // This is brl/bbas/bgui/bgui_graph_tableau.h
00002 #ifndef bgui_graph_tableau_h_
00003 #define bgui_graph_tableau_h_
00004 //:
00005 // \file
00006 // \author  K. Kang
00007 // \brief   intended to be general graph tableau
00008 // \verbatim
00009 // modified extensively by J.L. Mundy June 3, 2006
00010 // Added multiple plots December 1, 2007 - JLM
00011 // \endverbatim
00012 #include <vgui/vgui_tableau.h>
00013 #include <vgui/vgui_dialog.h>
00014 #include <vgui/vgui_event.h>
00015 #include <vgui/vgui_soview2D.h>
00016 #include <vgui/vgui_text_tableau.h>
00017 #include <vgui/vgui_easy2D_tableau.h>
00018 #include "bgui_graph_tableau_sptr.h"
00019 
00020 class bgui_graph_tableau : public  vgui_tableau
00021 {
00022  public:
00023 
00024   //: Constructors
00025   bgui_graph_tableau(const unsigned graph_width,
00026                      const unsigned graph_height);
00027 
00028   //: Destructor.
00029   ~bgui_graph_tableau();
00030 
00031   //: Update the graph with new data
00032   //  Single plot
00033   void update(vcl_vector<double> const& pos, vcl_vector<double> const & vals);
00034   void update(vcl_vector<float> const& pos, vcl_vector<float> const & vals);
00035   //: multiple plots. The current implementation requires pos to contain the same horizontal axis values.
00036   // Future plans are to have this class handle multiple position ranges
00037   void update(vcl_vector<vcl_vector<double> > const& pos,
00038               vcl_vector<vcl_vector<double> >const & vals);
00039   //: Clear the data
00040   void clear();
00041 
00042   //: Accessors
00043   float xmin() const {return xmin_;}
00044   float xmax() const {return xmax_;}
00045   float ymin() const {return ymin_;}
00046   float ymax() const {return ymax_;}
00047 
00048   //: Get a conveniently wrapped popup dialog
00049   vgui_dialog* popup_graph(vcl_string const& info,
00050                            const unsigned sizex =0,
00051                            const unsigned sizey=0);
00052 
00053   //: Handles all events for this tableau.
00054   virtual bool handle(const vgui_event&);
00055 
00056  private:
00057   //Utility functions
00058   void init();
00059   void rem();
00060   void del();
00061   void draw_box();
00062   void draw_tics();
00063   void draw_graph();
00064   void draw_multi_graph();
00065   void compute_scale();
00066   float map_x_to_display(const float x);
00067   float map_y_to_display(const float y);
00068   //Members
00069   float xmin_;
00070   float xmax_;
00071   float ymin_;
00072   float ymax_;
00073   float xscale_;
00074   float yscale_;
00075   unsigned left_offset_;
00076   unsigned top_offset_;
00077   unsigned graph_width_;
00078   unsigned graph_height_;
00079   float tic_length_;
00080   vgui_text_tableau_sptr tt_;
00081   vgui_easy2D_tableau_sptr easy_;
00082   //: The graph
00083   vgui_soview2D_linestrip* plot_;
00084   vcl_vector<vgui_soview2D_linestrip*> m_plot_;
00085   //: the tics
00086   float xinc_, yinc_;
00087   float yorigin_;
00088   vcl_vector<vgui_soview2D_lineseg*> xtics_;
00089   vcl_vector<vgui_soview2D_lineseg*> ytics_;
00090   unsigned n_;
00091   float* pos_;
00092   float* vals_;
00093   unsigned n_plots_;
00094   vcl_vector<vcl_vector<double> > mpos_;
00095   vcl_vector<vcl_vector<double> > mvals_;
00096 };
00097 
00098 struct bgui_graph_tableau_new : public bgui_graph_tableau_sptr
00099 {
00100   typedef bgui_graph_tableau_sptr base;
00101   bgui_graph_tableau_new(const unsigned gwidth, const unsigned gheight)
00102     : base(new bgui_graph_tableau(gwidth, gheight)) { }
00103 };
00104 
00105 
00106 #endif // bgui_graph_tableau_h_