00001 // This is brl/bseg/bbgm/bbgm_viewer.h 00002 #ifndef bbgm_viewer_h_ 00003 #define bbgm_viewer_h_ 00004 //: 00005 // \file 00006 // \brief Create a vil_image_view of an image of distributions 00007 // \author Matt Leotta (mleotta@lems.brown.edu) 00008 // \date January 31, 2006 00009 00010 #include "bbgm_image_of.h" 00011 #include "bbgm_image_sptr.h" 00012 #include "bbgm_view_maker.h" 00013 #include "bbgm_view_maker_sptr.h" 00014 #include <vil/vil_image_view.h> 00015 #include <vbl/vbl_ref_count.h> 00016 #include <vnl/vnl_vector.h> 00017 00018 //: base class for viewers 00019 class bbgm_viewer : public vbl_ref_count 00020 { 00021 public: 00022 //: Constructor 00023 bbgm_viewer() : active_component_(0), view_maker_(bbgm_view_maker_sptr(NULL)) 00024 {fail_val_[0] = fail_val_[1] = fail_val_[2] = 0.0;} 00025 //: Destructor 00026 virtual ~bbgm_viewer() {} 00027 00028 //: Probe to see if this viewer can handle this image type 00029 bool probe(const bbgm_image_sptr& dimg) const; 00030 //: Return the maximum number of components if a mixture 00031 // If not a mixture return 1 00032 unsigned int max_components(const bbgm_image_sptr& dimg) const; 00033 //: Apply the operations to the distribution image to produce a vil image 00034 bool apply(const bbgm_image_sptr& dimg, 00035 vil_image_view<double>& image) const; 00036 //: Return the name of this view 00037 virtual vcl_string name() const = 0; 00038 00039 //: Set the value for failure at a pixel 00040 void set_failure_value(const vnl_vector<double>& val) { fail_val_[0] = val[0]; 00041 fail_val_[1] = val[1]; 00042 fail_val_[2] = val[2]; } 00043 //: Set the value for failure at a pixel 00044 void set_active_component(unsigned int val) { active_component_ = val; } 00045 00046 //: Return the active component 00047 unsigned int active_component() const { return active_component_; } 00048 00049 protected: 00050 //: Return a pointer to the view_maker that applies to this image type. 00051 // Return a null pointer if no such view_maker is found 00052 virtual bbgm_view_maker_sptr 00053 find_vm(const vcl_type_info& dist_type) const = 0; 00054 00055 //: the data used when a pixel fails the operation 00056 double fail_val_[3]; 00057 //: the active component to use if the distribution is a mixture 00058 unsigned int active_component_; 00059 //: a cached pointer to the view_maker object last found 00060 mutable bbgm_view_maker_sptr view_maker_; 00061 }; 00062 00063 //============================================================================= 00064 00065 //: A mean viewer 00066 class bbgm_mean_viewer : public bbgm_viewer 00067 { 00068 public: 00069 //: Return the name of this view 00070 virtual vcl_string name() const { return "mean"; } 00071 00072 //: Register a new view_maker 00073 // \return true if successfully registered or false if invalid or already 00074 // registered. 00075 static bool register_view_maker(const bbgm_view_maker_sptr& vm); 00076 00077 //: Return a pointer to the view_maker that applies to this image type. 00078 // Return a null pointer if no such view_maker is found 00079 static bbgm_view_maker_sptr 00080 find_view_maker(const vcl_type_info& dist_type); 00081 00082 protected: 00083 //: A virtual wrapper around the static find function 00084 virtual bbgm_view_maker_sptr 00085 find_vm(const vcl_type_info& dist_type) const 00086 { 00087 return find_view_maker(dist_type); 00088 } 00089 00090 private: 00091 //: The registered view maker objects 00092 static vcl_vector<bbgm_view_maker_sptr> reg_vms; 00093 }; 00094 00095 //============================================================================= 00096 00097 //: A variance viewer 00098 class bbgm_variance_viewer : public bbgm_viewer 00099 { 00100 public: 00101 //: Return the name of this view 00102 virtual vcl_string name() const { return "variance"; } 00103 00104 //: Register a new view_maker 00105 // \return true if successfully registered or false if invalid or already 00106 // registered. 00107 static bool register_view_maker(const bbgm_view_maker_sptr& vm); 00108 00109 //: Return a pointer to the view_maker that applies to this image type. 00110 // Return a null pointer if no such view_maker is found 00111 static bbgm_view_maker_sptr 00112 find_view_maker(const vcl_type_info& dist_type); 00113 00114 protected: 00115 //: A virtual wrapper around the static find function 00116 virtual bbgm_view_maker_sptr 00117 find_vm(const vcl_type_info& dist_type) const 00118 { 00119 return find_view_maker(dist_type); 00120 } 00121 00122 private: 00123 //: The registered view maker objects 00124 static vcl_vector<bbgm_view_maker_sptr> reg_vms; 00125 }; 00126 00127 //============================================================================= 00128 00129 //: A weight viewer 00130 class bbgm_weight_viewer : public bbgm_viewer 00131 { 00132 public: 00133 //: Return the name of this view 00134 virtual vcl_string name() const { return "weight"; } 00135 00136 //: Register a new view_maker 00137 // \return true if successfully registered or false if invalid or already 00138 // registered. 00139 static bool register_view_maker(const bbgm_view_maker_sptr& vm); 00140 00141 //: Return a pointer to the view_maker that applies to this image type. 00142 // Return a null pointer if no such view_maker is found 00143 static bbgm_view_maker_sptr 00144 find_view_maker(const vcl_type_info& dist_type); 00145 00146 protected: 00147 //: A virtual wrapper around the static find function 00148 virtual bbgm_view_maker_sptr 00149 find_vm(const vcl_type_info& dist_type) const 00150 { 00151 return find_view_maker(dist_type); 00152 } 00153 00154 private: 00155 //: The registered view maker objects 00156 static vcl_vector<bbgm_view_maker_sptr> reg_vms; 00157 }; 00158 00159 00160 #endif // bbgm_viewer_h_