core/vgui/vgui_image_tableau.h
Go to the documentation of this file.
00001 // This is core/vgui/vgui_image_tableau.h
00002 #ifndef vgui_image_tableau_h_
00003 #define vgui_image_tableau_h_
00004 //:
00005 // \file
00006 // \brief  Tableau which renders the given image using an image_renderer.
00007 // \author fsm
00008 //
00009 //  Contains classes  vgui_image_tableau  vgui_image_tableau_new
00010 //
00011 // \verbatim
00012 //  Modifications
00013 //   15-AUG-2000 Marko Bacic,Oxford RRG -- Removed legacy ROI
00014 //   09-AUG-2002 K.Y.McGaul - Added Doxygen style comments.
00015 //   05-AUG-2003 Amitha Perera - Added new vil support
00016 //   27-DEC-2004 J.L. Mundy - Added range mapping support
00017 // \endverbatim
00018 
00019 #include <vgui/vgui_tableau.h>
00020 #include <vgui/vgui_image_tableau_sptr.h>
00021 #include <vgui/vgui_range_map_params_sptr.h>
00022 class vgui_image_renderer;
00023 class vil1_image;
00024 #include <vil/vil_image_resource_sptr.h>
00025 
00026 class vgui_vil_image_renderer;
00027 #include <vil/vil_image_view_base.h>
00028 
00029 
00030 struct vgui_image_tableau_new;
00031 
00032 //: Tableau which renders the given image using an image_renderer.
00033 class vgui_image_tableau
00034   : public vgui_tableau
00035 {
00036  protected:
00037   vcl_string name_;
00038   bool pixels_centered_;
00039   vgui_range_map_params_sptr rmp_;
00040   vgui_image_renderer* renderer_;
00041   vgui_vil_image_renderer* vil_renderer_;
00042 
00043  public:
00044   //: Returns the type of this tableau ('vgui_image_tableau').
00045   vcl_string type_name() const;
00046 
00047   //: Returns the filename of the loaded image.
00048   //  It will not know this if the tableau was constructed from
00049   //  a vil1_image, only if the filename was given to the constructor.
00050   vcl_string file_name() const;
00051 
00052   //: Set the filename of the loaded image
00053   //  It could be used to identify a specific image
00054   void set_file_name( const vcl_string & fn ) { name_ = fn; }
00055 
00056   //: Returns a nice version of the name, including details of the image file.
00057   vcl_string pretty_name() const;
00058 
00059   //: Return the image being rendered by this tableau.
00060   virtual vil1_image get_image() const;
00061 
00062   //: Return the image view being rendered by this tableau.
00063   virtual vil_image_view_base_sptr get_image_view() const;
00064 
00065   //: Return the image resource being rendered by this tableau.
00066   virtual vil_image_resource_sptr get_image_resource() const;
00067 
00068   //: Make the given image, the image rendered by this tableau.
00069   virtual void set_image( vil1_image const &img,
00070                           vgui_range_map_params_sptr const& rmp);
00071 
00072   //: Make the given image view, the image rendered by this tableau.
00073   virtual void set_image_view( vil_image_view_base const& img,
00074                                vgui_range_map_params_sptr const& rmp);
00075 
00076   //: Make the given image resource, the image rendered by this tableau.
00077   virtual void set_image_resource( vil_image_resource_sptr const& img,
00078                                    vgui_range_map_params_sptr const& rmp);
00079 
00080   //: Make the given image, the image rendered by this tableau, but keep old range map.
00081   virtual void set_image( vil1_image const &img);
00082 
00083   //: Make the given image view, the image rendered by this tableau, but keep old range map.
00084   virtual void set_image_view( vil_image_view_base const& img);
00085 
00086   //: Make the given image resource, the image rendered by this tableau, but keep old range map.
00087   virtual void set_image_resource( vil_image_resource_sptr const& img);
00088 
00089   //: Make image loaded from the given file, the image rendered by this tableau.
00090   // The image will be stored as a vil_image_view_base, and thus can be
00091   // retrieved with get_image_view() but not with get_image().
00092   virtual void set_image_view( char const* filename,
00093                                vgui_range_map_params_sptr const& rmp = 0);
00094 
00095   //: Make image loaded from the given file, the image rendered by this tableau.
00096   // The image will be stored as a vil1_image, and thus can be
00097   // retrieved with get_image() but not with get_image_view().
00098   virtual void set_image( char const* filename,
00099                           vgui_range_map_params_sptr const& rmp = 0);
00100 
00101   //: Reread the image from file.
00102   virtual void reread_image();
00103 
00104   //: Width of image (0 if none).
00105   virtual unsigned width() const;
00106 
00107   //: Height of image (0 if none).
00108   virtual unsigned height() const;
00109 
00110   //: Returns the box bounding the rendered image.
00111   virtual bool get_bounding_box( float low[3], float high[3] ) const;
00112 
00113   //: Sets coordinate to be in the middle or corner of the pixel.
00114   //  This method controls whether the coordinate (i, j) is the
00115   //  corner of pixel (i, j) or in the middle.
00116   void center_pixels( bool v = true ) { pixels_centered_ = v; }
00117 
00118   //: set the range mapping parameters.
00119   // image (if it exists) is re-rendered with the map.
00120   // the mapping is defined on the input pixel domain [min, max]
00121   // gamma is the usual photometric non-linear correction
00122   // invert reverses the map (a negative version of the image)
00123   // set_mapping should be called before set_image methods to insure
00124   // the first image display has the requested mapping parameters
00125   virtual void set_mapping(vgui_range_map_params_sptr const& rmp);
00126 
00127   vgui_range_map_params_sptr map_params(){return rmp_;}
00128 
00129   //: Handle all events sent to this tableau.
00130   //  In particular, use draw events to render the image contained in
00131   //  this tableau.
00132   virtual bool handle( vgui_event const& e );
00133 
00134   //: Builds a popup menu for the user to modify range mapping
00135   //  Over-rides function in vgui_tableau.
00136   virtual void get_popup(const vgui_popup_params&, vgui_menu &m);
00137 
00138  protected:
00139   friend struct vgui_image_tableau_new;
00140 
00141   //: Constructor - don't use this, use vgui_image_tableau_new.
00142   //  Creates an empty image tableau.
00143   vgui_image_tableau();
00144 
00145   //: Constructor - don't use this, use vgui_image_tableau_new.
00146   //  Creates a tableau displaying the given image.
00147   vgui_image_tableau( vil1_image const& img, vgui_range_map_params_sptr const& rmp = 0);
00148 
00149   //: Constructor - don't use this, use vgui_image_tableau_new.
00150   //  Creates a tableau displaying the given image view.
00151   vgui_image_tableau( vil_image_view_base const& img,
00152                       vgui_range_map_params_sptr const& rmp = 0);
00153 
00154   //: Constructor - don't use this, use vgui_image_tableau_new.
00155   //  Creates a tableau displaying the given image resource.
00156   vgui_image_tableau( vil_image_resource_sptr const& img,
00157                       vgui_range_map_params_sptr const& rmp = 0);
00158 
00159   //: Constructor - don't use this, use vgui_image_tableau_new.
00160   //  Creates a tableau which loads and displays an image from
00161   //  the given file. File loaded as a vil1_image.
00162   vgui_image_tableau( char const* filename,
00163                       vgui_range_map_params_sptr const& rmp = 0);
00164 
00165  protected:
00166   //: Destructor - called by vgui_image_tableau_sptr.
00167   virtual ~vgui_image_tableau();
00168 };
00169 
00170 //: Creates a smart-pointer to a vgui_image_tableau.
00171 struct vgui_image_tableau_new
00172   : public vgui_image_tableau_sptr
00173 {
00174   //: Constructor - creates an empty image tableau.
00175   vgui_image_tableau_new()
00176     : vgui_image_tableau_sptr( new vgui_image_tableau )
00177     { }
00178 
00179   //:  Constructor - creates a tableau displaying the given image.
00180   vgui_image_tableau_new( vil1_image const &t,
00181                           vgui_range_map_params_sptr const& rmp = 0 )
00182     : vgui_image_tableau_sptr( new vgui_image_tableau(t, rmp) )
00183     { }
00184 
00185   //:  Constructor - creates a tableau displaying the given image.
00186   vgui_image_tableau_new( vil_image_view_base const& t,
00187                           vgui_range_map_params_sptr const& rmp = 0 )
00188     : vgui_image_tableau_sptr( new vgui_image_tableau(t, rmp) )
00189     { }
00190 
00191   //:  Constructor - creates a tableau displaying the given image.
00192   vgui_image_tableau_new( vil_image_resource_sptr const& t,
00193                           vgui_range_map_params_sptr const& rmp = 0 )
00194     : vgui_image_tableau_sptr( new vgui_image_tableau(t, rmp) )
00195     { }
00196 
00197   //: Creates a tableau which loads and displays an image from the given file.
00198   // The image will be stored as a vil1_image, and thus can be
00199   // retrieved with get_image() but not with get_image_view().
00200   vgui_image_tableau_new(char const *f,
00201                          vgui_range_map_params_sptr const& rmp = 0)
00202     : vgui_image_tableau_sptr( new vgui_image_tableau(f, rmp) )
00203     { }
00204 };
00205 
00206 #endif // vgui_image_tableau_h_