00001 // This is brl/bbas/bgui/bgui_range_adjuster_tableau.h 00002 #ifndef bgui_range_adjuster_tableau_h_ 00003 #define bgui_range_adjuster_tableau_h_ 00004 //: 00005 // \file 00006 // \author J. L. Mundy based on Matt Leotta's histogram tableau 00007 // \brief Display an interactive histogram to adjust image dynamic range 00008 00009 #include <vil1/vil1_memory_image_of.h> 00010 #include <vil1/vil1_rgb.h> 00011 #include <vgui/vgui_tableau.h> 00012 #include <vgui/vgui_event.h> 00013 #include <vgui/vgui_soview2D.h> 00014 #include <vgui/vgui_easy2D_tableau.h> 00015 #include <vgui/vgui_range_map_params_sptr.h> 00016 #include <bsta/bsta_histogram.h> 00017 #include <bgui/bgui_image_tableau.h> 00018 00019 #include "bgui_range_adjuster_tableau_sptr.h" 00020 00021 class bgui_range_adjuster_tableau : public vgui_easy2D_tableau 00022 { 00023 public: 00024 00025 //: Constructor takes all the labels used on the graph. 00026 bgui_range_adjuster_tableau(const char* n="unnamed"); 00027 00028 bgui_range_adjuster_tableau(vgui_image_tableau_sptr const& it, 00029 const char* n="unnamed"); 00030 00031 bgui_range_adjuster_tableau(vgui_tableau_sptr const& t, const char* n="unnamed"); 00032 00033 //: Returns the type of this tableau ('bgui_range_adjuster_tableau'). 00034 // vcl_string type_name() const { return "bgui_range_adjuster_tableau";} 00035 00036 //: Destructor. 00037 ~bgui_range_adjuster_tableau(); 00038 00039 //: Update the histogram from image resource 00040 bool update(vil_image_resource_sptr const& ir); 00041 00042 //: Update the histogram from image 00043 bool update(vil1_memory_image_of< vil1_rgb<unsigned char> >& img); 00044 00045 //: Update the histogram from client 00046 bool update(); 00047 00048 //: Update the data from a histogram 00049 bool update(const double min, const double max, 00050 vcl_vector<double> const& hist); 00051 00052 00053 //: Low range limit histogram area fraction 00054 double low_range_limit(const double frac); 00055 00056 //: Upper range limit histogram area fraction 00057 double upper_range_limit(const double frac); 00058 00059 //: Use OpenGL Hardware mapping 00060 void set_hardware(bool hardware) { hardware_=hardware; } 00061 00062 //: Handles all events for this tableau. 00063 virtual bool handle(const vgui_event&); 00064 //: Clear the data 00065 void clear(); 00066 00067 //: virtual 00068 private: 00069 //Utility functions 00070 void init(); 00071 void draw_box(); 00072 void draw_histogram(); 00073 00074 vgui_image_tableau_sptr get_child_image_tableau(); 00075 00076 int map_val_to_display(const double val); 00077 double map_display_to_val(const int display_x); 00078 void draw_stretch_bars(); 00079 float screen_to_bar(const float sx); 00080 float bar_to_screen(const float bx); 00081 void adjust_min_bar(const float x); 00082 void adjust_max_bar(const float x); 00083 //Members 00084 double min_; 00085 double max_; 00086 bool hardware_; 00087 vgui_soview2D_lineseg* min_bar_; 00088 vgui_soview2D_lineseg* max_bar_; 00089 int left_offset_; 00090 int top_offset_; 00091 int graph_width_; 00092 int graph_height_; 00093 //: List of points. 00094 vcl_vector<float> xpoints_, ypoints_; 00095 vgui_soview2D_linestrip* plot_; 00096 vcl_vector<double> data_; 00097 bsta_histogram<double> hist_; 00098 }; 00099 00100 00101 //this stuff is needed to establish inheritance between tableau smart pointers 00102 //cloned from xcv_image_tableau 00103 struct bgui_range_adjuster_tableau_new : public bgui_range_adjuster_tableau_sptr 00104 { 00105 typedef bgui_range_adjuster_tableau_sptr base; 00106 00107 bgui_range_adjuster_tableau_new(const char* n="unnamed") : 00108 base(new bgui_range_adjuster_tableau(n)) { } 00109 bgui_range_adjuster_tableau_new(vgui_image_tableau_sptr const& it, 00110 const char* n="unnamed") : 00111 base(new bgui_range_adjuster_tableau(it,n)) { } 00112 00113 bgui_range_adjuster_tableau_new(vgui_tableau_sptr const& t, const char* n="unnamed") 00114 : base(new bgui_range_adjuster_tableau(t, n)) { } 00115 00116 operator vgui_easy2D_tableau_sptr () const { vgui_easy2D_tableau_sptr tt; tt.vertical_cast(*this); return tt; } 00117 }; 00118 00119 #endif // bgui_range_adjuster_tableau_h_