contrib/brl/bbas/bgui/bgui_image_tableau.h
Go to the documentation of this file.
00001 // This is brl/bbas/bgui/bgui_image_tableau.h
00002 #ifndef bgui_image_tableau_h_
00003 #define bgui_image_tableau_h_
00004 //:
00005 // \file
00006 // \author  Marko Bacic (u97mb@robots.ox.ac.uk)
00007 // \brief An image tableau with an associated region of interest.
00008 //
00009 // \verbatim
00010 //  Modifications
00011 //   Marko Bacic    AUG-2000  Initial version.
00012 //   K.Y.McGaul  05-AUG-2002  Print mouse position on status bar.
00013 //   K.Y.McGaul  06-AUG-2002  Print RGB value on status bar.
00014 //   Joseph Mundy   DEC-2002  Copied to brl to serve as a basis for extended functions
00015 //   Peter Vanroose AUG-2004  Moved bgui_roi_tableau_make_roi to separate file
00016 //   Gamze Tunali   SEP-2007  Added class bgui_image_tableau_vp_sc_snapshot
00017 // \endverbatim
00018 
00019 #include "bgui_image_tableau_sptr.h"
00020 #include <vgui/vgui_image_tableau.h>
00021 #include <vgui/vgui_range_map_params_sptr.h>
00022 #include <vil/vil_image_resource.h>
00023 #include <vil/vil_image_view_base.h>
00024 #include <vgui/vgui_text_tableau.h>
00025 #include <vil1/vil1_image.h>
00026 #include <vgui/vgui_gl.h>
00027 
00028 class bgui_image_tableau_vp_sc_snapshot
00029 {
00030  public:
00031   GLint vp[4];
00032   GLint sc[4];
00033   bool sc_was_enabled;
00034 
00035   bgui_image_tableau_vp_sc_snapshot() {
00036     glGetIntegerv(GL_VIEWPORT, vp);
00037 
00038     //vcl_cout << "Saving    [" << vp[0] << ' ' << vp[1] << ' ' << vp[2] << ' ' << vp[3] << vcl_endl;
00039     glGetIntegerv(GL_SCISSOR_BOX, sc);
00040     sc_was_enabled = glIsEnabled(GL_SCISSOR_TEST) == GL_TRUE;
00041   }
00042 
00043   ~bgui_image_tableau_vp_sc_snapshot() {
00044     // restore viewport :
00045     glViewport(vp[0], vp[1], vp[2], vp[3]);
00046     //vcl_cout << "restoring [" << vp[0] << ' ' << vp[1] << ' ' << vp[2] << ' ' << vp[3] << vcl_endl;
00047     // turn off the scissor test, if it wasn't already on, and
00048     // restore old scissor settings :
00049     if (sc_was_enabled)
00050       glEnable(GL_SCISSOR_TEST);
00051     else
00052       glDisable(GL_SCISSOR_TEST);
00053     glScissor(sc[0], sc[1], sc[2], sc[3]);
00054   }
00055 };
00056 
00057 class bgui_image_tableau : public vgui_image_tableau
00058 {
00059  public:
00060   typedef vgui_image_tableau base;
00061 
00062   bgui_image_tableau();
00063 
00064   bgui_image_tableau(vil_image_resource_sptr const & img,
00065                      vgui_range_map_params_sptr const & rmp = 0);
00066 
00067   bgui_image_tableau( vil_image_view_base const & img,
00068                       vgui_range_map_params_sptr const & rmp = 0);
00069 
00070   bgui_image_tableau(vil1_image const & img,
00071                      vgui_range_map_params_sptr const & rmp = 0);
00072 
00073   bgui_image_tableau(char const* filename,
00074                      vgui_range_map_params_sptr const & rmp = 0);
00075 
00076 
00077   vcl_string type_name() const { return "vgui_image_tableau"; }
00078 
00079   //: Return the vil1_image
00080   vil1_image get_image() const;
00081 
00082   //: Return the vil_image_resource
00083   vil_image_resource_sptr get_image_resource() const;
00084 
00085   //: Extract a line of pixel values (force to grey scale)
00086   void image_line(const float col_start,
00087                   const float row_start,
00088                   const float col_end,
00089                   const float row_end,
00090                   vcl_vector<double>& line_pos,
00091                   vcl_vector<double>& vals);
00092 
00093   //: Extract a line of pixel values return color if available
00094   void image_line(const float col_start,
00095                   const float row_start,
00096                   const float col_end,
00097                   const float row_end,
00098                   vcl_vector<double>& line_pos,
00099                   vcl_vector<vcl_vector<double> >& vals);
00100 
00101   //: set handle_motion true
00102   void set_handle_motion() { handle_motion_ = true; }
00103   void unset_handle_motion() { handle_motion_ = false; }
00104 
00105   bool handle_motion() const { return handle_motion_; }
00106 
00107   // true means locked, false unlocked
00108   void lock_linenum(bool b) { locked_ = b; handle_motion_=!b; }
00109   void show_image_path(bool show){show_path_ = show;}
00110   vgui_text_tableau_sptr text_tab(){return tt_;}
00111  protected:
00112   //: Handle all events for this tableau.
00113   bool handle(vgui_event const &e);
00114 
00115   //: get the pixel value as a double. RGB converted to grey.
00116   double get_pixel_value(const unsigned c, const unsigned r);
00117 
00118 //: get the pixel value as color
00119   vcl_vector<double> get_color_pixel_value(const unsigned c, const unsigned r);
00120 
00121   //: Get pixel info from the frame buffer)
00122   void get_pixel_info_from_frame_buffer(const int x, const int y,
00123                                         vgui_event const &e, char* msg);
00124 
00125   //: Get pixel info from the image (rather than frame buffer)
00126   void get_pixel_info_from_image(const int x, const int y,
00127                                  vgui_event const &e, char* msg);
00128 
00129   //: If false this tableau stops handling motion
00130   bool handle_motion_;
00131 
00132   bool locked_;
00133   bool show_path_;
00134   vgui_text_tableau_sptr tt_;
00135 };
00136 
00137 //: Creates a smart-pointer to a bgui_image_tableau.
00138 struct bgui_image_tableau_new : public bgui_image_tableau_sptr {
00139 
00140   //: Constructor - creates an empty image tableau.
00141   bgui_image_tableau_new()
00142     : bgui_image_tableau_sptr( new bgui_image_tableau() )
00143   { }
00144 
00145   //:  Constructors - create a tableau displaying the given image.
00146 
00147   bgui_image_tableau_new(vil_image_resource_sptr const & img,
00148                          vgui_range_map_params_sptr const & rmp = 0)
00149     : bgui_image_tableau_sptr( new bgui_image_tableau(img, rmp) )
00150   { }
00151 
00152   bgui_image_tableau_new(vil_image_view_base const & img,
00153                          vgui_range_map_params_sptr const & rmp = 0)
00154     : bgui_image_tableau_sptr( new bgui_image_tableau(img, rmp) )
00155   { }
00156 
00157   bgui_image_tableau_new(vil1_image const & img,
00158                          vgui_range_map_params_sptr const & rmp = 0)
00159     : bgui_image_tableau_sptr( new bgui_image_tableau(img, rmp) )
00160   { }
00161 
00162   bgui_image_tableau_new(char const* filename,
00163                          vgui_range_map_params_sptr const & rmp = 0)
00164     : bgui_image_tableau_sptr( new bgui_image_tableau(filename, rmp) )
00165   { }
00166 
00167   //:to cast up to a vgui_image_tableau
00168   operator vgui_image_tableau_sptr () const
00169   { vgui_image_tableau_sptr tt; tt.vertical_cast(*this); return tt; }
00170 };
00171 
00172 #endif // bgui_image_tableau_h_