core/vgui/vgui_blender_tableau.h
Go to the documentation of this file.
00001 // This is core/vgui/vgui_blender_tableau.h
00002 #ifndef vgui_blender_tableau_h_
00003 #define vgui_blender_tableau_h_
00004 #ifdef VCL_NEEDS_PRAGMA_INTERFACE
00005 #pragma interface
00006 #endif
00007 //:
00008 // \file
00009 // \brief  Tableau to blend two images.
00010 // \author Philip C. Pritchett, Robotics Research Group, University of Oxford
00011 // \date   27 Oct 99
00012 //
00013 //  Contains class  vgui_blender_tableau
00014 //
00015 // \verbatim
00016 //  Modifications
00017 //   01-OCT-2002 K.Y.McGaul - Added Doxygen style comments.
00018 //                          - Returns the filename when image loaded from file.
00019 //                          - Moved vgui_image_blender to vgui_blender_tableau.
00020 // \endverbatim
00021 
00022 #include <vgui/vgui_tableau.h>
00023 #include <vgui/vgui_blender_tableau_sptr.h>
00024 #include <vgui/vgui_range_map_params_sptr.h>
00025 #include <vil/vil_fwd.h>
00026 
00027 class vgui_image_renderer;
00028 class vgui_vil_image_renderer;
00029 class vil1_image;
00030 
00031 //: Tableau to blend two images.
00032 //
00033 //  To use this tableau make a vgui_image_tableau containing one of the
00034 //  images to blend and a vgui_blender_tableau containing the other.
00035 //  Put them both in a vgui_composite_tableau.  Set alpha to be less than
00036 //  one to see the blended image.
00037 class vgui_blender_tableau : public vgui_tableau
00038 {
00039  public:
00040   //: Constructor - don't use this, use vgui_blender_tableau_new.
00041   //  Creates a blender with the given image and alpha value.
00042   vgui_blender_tableau(char const* file, vgui_range_map_params_sptr const& rmp = 0,
00043                        float a=1.0);
00044 
00045   //: Constructor - don't use this, use vgui_blender_tableau_new.
00046   //  Creates a blender with the given image and alpha value.
00047   vgui_blender_tableau(vil1_image const& img, vgui_range_map_params_sptr const& rmp = 0,
00048                        float a=1.0);
00049 
00050   //: Constructor - don't use this, use vgui_blender_tableau_new.
00051   //  Creates a blender with the given image and alpha value.
00052   vgui_blender_tableau(vil_image_view_base const& img,
00053                        vgui_range_map_params_sptr const& rmp = 0, float a=1.0);
00054 
00055   //: Constructor - don't use this, use vgui_blender_tableau_new.
00056   //  Creates a blender with the given image and alpha value.
00057   vgui_blender_tableau(vil_image_resource_sptr const& img,
00058                        vgui_range_map_params_sptr const& rmp = 0, float a=1.0);
00059 
00060   //: Handle all events sent to this tableau.
00061   //  In particular use draw events to draw the blended image.
00062   //  Use '/' and '*' key-press events to change alpha.
00063   bool handle(vgui_event const &e);
00064 
00065   //: Return the filename of the loaded image (if it was loaded from file).
00066   vcl_string file_name() const;
00067 
00068   //: Return the type of this tableau ('vgui_blender_tableau').
00069   vcl_string type_name() const;
00070 
00071   //: Tell the blender that the image pixels have been changed.
00072   void reread_image();
00073 
00074   //: set the range mapping parameters.
00075   // image (if it exists) is re-rendered with the map.
00076   // the mapping is defined on the input pixel domain [min, max]
00077   // gamma is the usual photometric non-linear correction
00078   // invert reverses the map (a negative version of the image)
00079   // set_mapping should be called before set_image methods to insure
00080   // the first image display has the requested mapping parameters
00081   virtual void set_mapping(vgui_range_map_params_sptr const& rmp)
00082   { rmp_ = rmp; }
00083 
00084   vgui_range_map_params_sptr map_params(){return rmp_;}
00085 
00086  protected:
00087   //: Image renderer to draw the images.
00088   vgui_image_renderer        *renderer_;
00089   vgui_vil_image_renderer    *vil_renderer_;
00090   vgui_range_map_params_sptr rmp_;
00091 
00092   //: Amount of this image to display (1.0 for all, 0.0 for none).
00093   float alpha_;
00094 
00095   //: Destructor - called by vgui_blender_tableau_sptr.
00096  ~vgui_blender_tableau();
00097 
00098   //: Filename (if the image was loaded from a file).
00099   vcl_string filename_;
00100 };
00101 
00102 //: Creates a smart-pointer to a vgui_blender_tableau.
00103 struct vgui_blender_tableau_new : public vgui_blender_tableau_sptr
00104 {
00105   //: Constructor - create a blender with the given image and alpha value.
00106   vgui_blender_tableau_new(char const* file, vgui_range_map_params_sptr const& rmp=0, float a=1.0)
00107     : vgui_blender_tableau_sptr(new vgui_blender_tableau(file, rmp, a)) { }
00108 
00109   //: Constructor - create a blender with the given image and alpha value.
00110   vgui_blender_tableau_new(vil1_image const& img,
00111                            vgui_range_map_params_sptr const& rmp=0, float a=1.0)
00112     : vgui_blender_tableau_sptr(new vgui_blender_tableau(img, rmp, a)) { }
00113 
00114   //: Constructor - create a blender with the given image and alpha value.
00115   vgui_blender_tableau_new(vil_image_resource_sptr const& img,
00116                            vgui_range_map_params_sptr const& rmp=0, float a=1.0)
00117     : vgui_blender_tableau_sptr(new vgui_blender_tableau(img, rmp, a)) { }
00118 
00119   //: Constructor - create a blender with the given image and alpha value.
00120   vgui_blender_tableau_new(vil_image_view_base const& img,
00121                            vgui_range_map_params_sptr const& rmp=0, float a=1.0)
00122     : vgui_blender_tableau_sptr(new vgui_blender_tableau(img, rmp, a)) { }
00123 };
00124 
00125 #endif // vgui_blender_tableau_h_