core/vgui/vgui_image_renderer.h
Go to the documentation of this file.
00001 // This is core/vgui/vgui_image_renderer.h
00002 #ifndef vgui_image_renderer_h_
00003 #define vgui_image_renderer_h_
00004 //:
00005 // \file
00006 // \brief OpenGL utility to render a vil1_image.
00007 // \author fsm
00008 
00009 #include <vil1/vil1_image.h>
00010 #include <vgui/vgui_range_map_params_sptr.h>
00011 class vgui_section_buffer;
00012 
00013 //: OpenGL utility to render a vil1_image.
00014 //
00015 //  This is not a tableau.
00016 //
00017 //  The image_renderer provides an easy way to render sections of an
00018 //  image. It should manage possibly sub-sampled buffers internally
00019 //  to provide a reasonable trade-off between memory consumption and
00020 //  rendering speed. For a very large image, which cannot be stored
00021 //  in core, locally panning the image should not be too slow because
00022 //  sections can be cached at various levels of resolution.
00023 //
00024 //  It is assumed that the image is located on the plane z=0 and that
00025 //  image pixel indices i,j (i is the column index, j the row index)
00026 //  describe the x,y-locations of the rendered pixels. It is currently
00027 //  undefined where the centre of a pixel is placed.
00028 //
00029 //  Note that the class keeps a vil1_image (as given), so if the
00030 //  underlying image is modified after sections have been taken by
00031 //  this class, inconsistent rendering may result. Call need_resection()
00032 //  to mark all previous sections as invalid.
00033 // \verbatim
00034 // Modifications
00035 // J.L. Mundy - Dec 27 2004 added range map to control dynamic range of display
00036 // \endverbatim
00037 class vgui_image_renderer
00038 {
00039   //: Are the range params those used to form the current buffer
00040   bool old_range_map_params(vgui_range_map_params_sptr const& rmp);
00041 
00042   //: Create a buffer if necessary 
00043   void create_buffer(vgui_range_map_params_sptr const& rmp);
00044 
00045   //: draw the pixels to the frame buffer
00046   void draw_pixels();
00047 
00048   vil1_image the_image;
00049 
00050   vgui_section_buffer *buffer;
00051 
00052   //: a cache for the range map params associated with buffer
00053   vgui_range_map_params_sptr buffer_params;
00054 
00055   //: buffer state variable
00056   bool valid_buffer;
00057 
00058  public:
00059   //: Set this to true to use texture mapping for image rendering.
00060   //  To succeed, it must be set \e before the first \p get_section() is
00061   //  done on the image, i.e. before the first call to render() is made.
00062   bool use_texture_mapping;
00063 
00064   //: Constructor - create an empty image renderer.
00065   vgui_image_renderer();
00066 
00067   //: Destructor - delete image buffer.
00068   ~vgui_image_renderer();
00069 
00070   //: Attach the renderer to a new vil1_image.
00071   void set_image(vil1_image const &);
00072 
00073 
00074   //: Return the vil1_image that this renderer draws
00075   vil1_image get_image() const { return the_image; }
00076 
00077   //: Tell the renderer that the underlying image has been changed.
00078   void reread_image();
00079 
00080   //: Renders the image pixels.
00081   void render(vgui_range_map_params_sptr const& mp = 0);
00082 
00083   //: Render the pixels in hardware using the glPixelMap with range_map data
00084   // Note that some OpenGL environments have no graphics hardware
00085   // but the glPixelMap is still somewhat faster JLM (on a DELL precision)
00086   bool render_directly(vgui_range_map_params_sptr const& mp);
00087 
00088   //: Not yet implemented - for future use.
00089   void need_resection() const;
00090 };
00091 
00092 #endif // vgui_image_renderer_h_