1 // This is core/vgui/vgui_image_tableau.h
2 #ifndef vgui_image_tableau_h_
3 #define vgui_image_tableau_h_
4 //:
5 // \file
6 // \brief  Tableau which renders the given image using an image_renderer.
7 // \author fsm
8 //
9 //  Contains classes  vgui_image_tableau  vgui_image_tableau_new
10 //
11 // \verbatim
12 //  Modifications
13 //   15-AUG-2000 Marko Bacic,Oxford RRG -- Removed legacy ROI
14 //   09-AUG-2002 K.Y.McGaul - Added Doxygen style comments.
15 //   05-AUG-2003 Amitha Perera - Added new vil support
16 //   27-DEC-2004 J.L. Mundy - Added range mapping support
17 // \endverbatim
18 
19 #include "vgui_tableau.h"
20 #include "vgui_image_tableau_sptr.h"
21 #include "vgui_range_map_params_sptr.h"
22 class vgui_image_renderer;
23 class vil1_image;
24 #include <vil/vil_image_resource_sptr.h>
25 
26 class vgui_vil_image_renderer;
27 #include <vil/vil_image_view_base.h>
28 
29 
30 struct vgui_image_tableau_new;
31 
32 //: Tableau which renders the given image using an image_renderer.
33 class vgui_image_tableau
34   : public vgui_tableau
35 {
36  protected:
37   std::string name_;
38   bool pixels_centered_;
39   vgui_range_map_params_sptr rmp_;
40   vgui_image_renderer* renderer_;
41   vgui_vil_image_renderer* vil_renderer_;
42 
43  public:
44   //: Returns the type of this tableau ('vgui_image_tableau').
45   std::string type_name() const;
46 
47   //: Returns the filename of the loaded image.
48   //  It will not know this if the tableau was constructed from
49   //  a vil1_image, only if the filename was given to the constructor.
50   std::string file_name() const;
51 
52   //: Set the filename of the loaded image
53   //  It could be used to identify a specific image
set_file_name(const std::string & fn)54   void set_file_name( const std::string & fn ) { name_ = fn; }
55 
56   //: Returns a nice version of the name, including details of the image file.
57   std::string pretty_name() const;
58 
59   //: Return the image being rendered by this tableau.
60   virtual vil1_image get_image() const;
61 
62   //: Return the image view being rendered by this tableau.
63   virtual vil_image_view_base_sptr get_image_view() const;
64 
65   //: Return the image resource being rendered by this tableau.
66   virtual vil_image_resource_sptr get_image_resource() const;
67 
68   //: Make the given image, the image rendered by this tableau.
69   virtual void set_image( vil1_image const &img,
70                           vgui_range_map_params_sptr const& rmp);
71 
72   //: Make the given image view, the image rendered by this tableau.
73   virtual void set_image_view( vil_image_view_base const& img,
74                                vgui_range_map_params_sptr const& rmp);
75 
76   //: Make the given image resource, the image rendered by this tableau.
77   virtual void set_image_resource( vil_image_resource_sptr const& img,
78                                    vgui_range_map_params_sptr const& rmp);
79 
80   //: Make the given image, the image rendered by this tableau, but keep old range map.
81   virtual void set_image( vil1_image const &img);
82 
83   //: Make the given image view, the image rendered by this tableau, but keep old range map.
84   virtual void set_image_view( vil_image_view_base const& img);
85 
86   //: Make the given image resource, the image rendered by this tableau, but keep old range map.
87   virtual void set_image_resource( vil_image_resource_sptr const& img);
88 
89   //: Make image loaded from the given file, the image rendered by this tableau.
90   // The image will be stored as a vil_image_view_base, and thus can be
91   // retrieved with get_image_view() but not with get_image().
92   virtual void set_image_view( char const* filename,
93                                vgui_range_map_params_sptr const& rmp = nullptr);
94 
95   //: Make image loaded from the given file, the image rendered by this tableau.
96   // The image will be stored as a vil1_image, and thus can be
97   // retrieved with get_image() but not with get_image_view().
98   virtual void set_image( char const* filename,
99                           vgui_range_map_params_sptr const& rmp = nullptr);
100 
101   //: Reread the image from file.
102   virtual void reread_image();
103 
104   //: Width of image (0 if none).
105   virtual unsigned width() const;
106 
107   //: Height of image (0 if none).
108   virtual unsigned height() const;
109 
110   //: Returns the box bounding the rendered image.
111   virtual bool get_bounding_box( float low[3], float high[3] ) const;
112 
113   //: Sets coordinate to be in the middle or corner of the pixel.
114   //  This method controls whether the coordinate (i, j) is the
115   //  corner of pixel (i, j) or in the middle.
116   void center_pixels( bool v = true ) { pixels_centered_ = v; }
117 
118   //: set the range mapping parameters.
119   // image (if it exists) is re-rendered with the map.
120   // the mapping is defined on the input pixel domain [min, max]
121   // gamma is the usual photometric non-linear correction
122   // invert reverses the map (a negative version of the image)
123   // set_mapping should be called before set_image methods to insure
124   // the first image display has the requested mapping parameters
125   virtual void set_mapping(vgui_range_map_params_sptr const& rmp);
126 
map_params()127   vgui_range_map_params_sptr map_params(){return rmp_;}
128 
129   //: Handle all events sent to this tableau.
130   //  In particular, use draw events to render the image contained in
131   //  this tableau.
132   virtual bool handle( vgui_event const& e );
133 
134   //: Builds a popup menu for the user to modify range mapping
135   //  Over-rides function in vgui_tableau.
136   virtual void get_popup(const vgui_popup_params&, vgui_menu &m);
137 
138  protected:
139   friend struct vgui_image_tableau_new;
140 
141   //: Constructor - don't use this, use vgui_image_tableau_new.
142   //  Creates an empty image tableau.
143   vgui_image_tableau();
144 
145   //: Constructor - don't use this, use vgui_image_tableau_new.
146   //  Creates a tableau displaying the given image.
147   vgui_image_tableau( vil1_image const& img, vgui_range_map_params_sptr const& rmp = nullptr);
148 
149   //: Constructor - don't use this, use vgui_image_tableau_new.
150   //  Creates a tableau displaying the given image view.
151   vgui_image_tableau( vil_image_view_base const& img,
152                       vgui_range_map_params_sptr const& rmp = nullptr);
153 
154   //: Constructor - don't use this, use vgui_image_tableau_new.
155   //  Creates a tableau displaying the given image resource.
156   vgui_image_tableau( vil_image_resource_sptr const& img,
157                       vgui_range_map_params_sptr const& rmp = nullptr);
158 
159   //: Constructor - don't use this, use vgui_image_tableau_new.
160   //  Creates a tableau which loads and displays an image from
161   //  the given file. File loaded as a vil1_image.
162   vgui_image_tableau( char const* filename,
163                       vgui_range_map_params_sptr const& rmp = nullptr);
164 
165  protected:
166   //: Destructor - called by vgui_image_tableau_sptr.
167   virtual ~vgui_image_tableau();
168 };
169 
170 //: Creates a smart-pointer to a vgui_image_tableau.
171 struct vgui_image_tableau_new
172   : public vgui_image_tableau_sptr
173 {
174   //: Constructor - creates an empty image tableau.
vgui_image_tableau_newvgui_image_tableau_new175   vgui_image_tableau_new()
176     : vgui_image_tableau_sptr( new vgui_image_tableau )
177     { }
178 
179   //:  Constructor - creates a tableau displaying the given image.
180   vgui_image_tableau_new( vil1_image const &t,
181                           vgui_range_map_params_sptr const& rmp = nullptr )
vgui_image_tableau_sptrvgui_image_tableau_new182     : vgui_image_tableau_sptr( new vgui_image_tableau(t, rmp) )
183     { }
184 
185   //:  Constructor - creates a tableau displaying the given image.
186   vgui_image_tableau_new( vil_image_view_base const& t,
187                           vgui_range_map_params_sptr const& rmp = nullptr )
vgui_image_tableau_sptrvgui_image_tableau_new188     : vgui_image_tableau_sptr( new vgui_image_tableau(t, rmp) )
189     { }
190 
191   //:  Constructor - creates a tableau displaying the given image.
192   vgui_image_tableau_new( vil_image_resource_sptr const& t,
193                           vgui_range_map_params_sptr const& rmp = nullptr )
vgui_image_tableau_sptrvgui_image_tableau_new194     : vgui_image_tableau_sptr( new vgui_image_tableau(t, rmp) )
195     { }
196 
197   //: Creates a tableau which loads and displays an image from the given file.
198   // The image will be stored as a vil1_image, and thus can be
199   // retrieved with get_image() but not with get_image_view().
200   vgui_image_tableau_new(char const *f,
201                          vgui_range_map_params_sptr const& rmp = nullptr)
vgui_image_tableau_sptrvgui_image_tableau_new202     : vgui_image_tableau_sptr( new vgui_image_tableau(f, rmp) )
203     { }
204 };
205 
206 #endif // vgui_image_tableau_h_
207