00001 // This is core/vgui/vgui_vil_image_renderer.h 00002 #ifndef vgui_vil_image_renderer_h_ 00003 #define vgui_vil_image_renderer_h_ 00004 //: 00005 // \file 00006 // \brief OpenGL utility to render a vil_image_view. 00007 // \author Amitha 00008 // 00009 // Cut-n-paste and modify from vil1_image_renderer. 00010 // \verbatim 00011 // Modifications 00012 // J.L. Mundy - Dec 27 2004 added range map to control dynamic range of display 00013 // \endverbatim 00014 #include <vil/vil_image_resource_sptr.h> 00015 #include <vil/vil_memory_chunk.h> 00016 #include <vgui/vgui_range_map_params_sptr.h> 00017 00018 class vgui_section_buffer; 00019 00020 //: OpenGL utility to render a vil_image_view. 00021 // 00022 // This is not a tableau. 00023 // 00024 // The vil_image_renderer provides an easy way to render sections of an 00025 // image. It should manage possibly sub-sampled buffers internally 00026 // to provide a reasonable trade-off between memory consumption and 00027 // rendering speed. For a very large image, which cannot be stored 00028 // in core, locally panning the image should not be too slow because 00029 // sections can be cached at various levels of resolution. 00030 // 00031 // It is assumed that the image is located on the plane z=0 and that 00032 // image pixel indices i,j (i is the column index, j the row index) 00033 // describe the x,y-locations of the rendered pixels. It is currently 00034 // undefined where the centre of a pixel is placed. 00035 // 00036 // Note that the class keeps a vil_image_resource (as given) 00037 // The image is rendered by extracting appropriate views from the resource 00038 // There are different modes of rendering based on flags set on the 00039 // vgui_range_map_params range mapping class. The states are: 00040 // 00041 // 1) rmp == null - a buffer is created for the entire image and 00042 // the buffer supplies glPixels to the display. Range map tables 00043 // are used where appropriate. No pyramid image support 00044 // 00045 // 2) rmp->use_glPixelMap && rmp->cache_mapped_pix 00046 // pyramid images are handled properly and 00047 // the range maps are used to generate the scaled pyramid view buffer. 00048 // gl hardware maps are not used. gl pixels are generated 00049 // in software using the maps. Rendering is limited to the current 00050 // viewport. The buffer is updated only if the viewport changes 00051 // 00052 // 3) rmp->use_glPixelMap && !rmp->cache_mapped_pix 00053 // pyramid images are handled properly and 00054 // the range maps are loaded into gl hardware for rendering. 00055 // The pyramid image data that drives the hardware is cached as 00056 // a memory_chunk, but not a pre-mapped glPixel buffer as in 2). 00057 // The memory_chunk is only updated if the viewport changes. 00058 // 00059 class vgui_vil_image_renderer 00060 { 00061 //: Are the range params those used to form the current buffer 00062 bool old_range_map_params(vgui_range_map_params_sptr const& rmp); 00063 00064 //: Render the pixels in hardware using the glPixelMap with range_map data 00065 // Note that some OpenGL environments have no graphics hardware 00066 // but the glPixelMap is still somewhat faster JLM (on a DELL precision) 00067 bool render_directly(vgui_range_map_params_sptr const& mp); 00068 00069 //: Create a buffer if necessary 00070 void create_buffer(vgui_range_map_params_sptr const& rmp); 00071 00072 //: Create a buffer with viewport dimensions 00073 void create_buffer(vgui_range_map_params_sptr const& rmp, 00074 unsigned x0, unsigned y0, unsigned x1, unsigned y1, 00075 float zoomx, float zoomy); 00076 00077 //: Create a buffer from specified resource corresponding to a pyramid zoom level 00078 void create_buffer(vgui_range_map_params_sptr const& rmp, 00079 float zoomx, float zoomy, 00080 vil_image_resource_sptr const& ir); 00081 00082 //: draw the pixels to the frame buffer 00083 void draw_pixels(); 00084 00085 //: Stores the image data (pixels, dimensions, etc). 00086 vil_image_resource_sptr the_image_; 00087 00088 //: Stored the GL pixels corresponding to the image data 00089 vgui_section_buffer* buffer_; 00090 00091 //: a cache for the range map params associated with buffer 00092 vgui_range_map_params_sptr buffer_params_; 00093 00094 //: buffer state variable 00095 bool valid_buffer_; 00096 00097 //: a cache when rendering using the gl hardware map 00098 vil_memory_chunk_sptr vbuf_; 00099 00100 unsigned x0_, y0_, w_, h_; // viewport parameters 00101 float zx_, zy_; // zoomx and zoomy values of the viewport 00102 unsigned sni_, snj_; //size of the pyramid view 00103 00104 public: 00105 //: Constructor - create an empty image renderer. 00106 vgui_vil_image_renderer(); 00107 00108 //: Destructor - delete image buffer. 00109 ~vgui_vil_image_renderer(); 00110 00111 //: Attach the renderer to a new view. 00112 // 00113 void set_image_resource( vil_image_resource_sptr const& ); 00114 00115 //: Return the image resource that this renderer draws. 00116 vil_image_resource_sptr get_image_resource() const; 00117 00118 //: Tell the renderer that the underlying image data has been changed. 00119 void reread_image(); 00120 00121 //: Renders the image pixels. If mp not null then render over an interval 00122 void render(vgui_range_map_params_sptr const& mp); 00123 }; 00124 00125 #endif // vgui_vil_image_renderer_h_