00001 // This is brl/bseg/bbgm/bbgm_viewer.cxx 00002 //: 00003 // \file 00004 00005 #include "bbgm_viewer.h" 00006 #include "bbgm_view_maker.h" 00007 #include "bbgm_apply.h" 00008 #include <vil/vil_image_view.h> 00009 00010 00011 //: Probe to see if this viewer can handle this image type 00012 bool bbgm_viewer::probe(const bbgm_image_sptr& dimg) const 00013 { 00014 if (!dimg) 00015 return false; 00016 00017 if (!view_maker_ || view_maker_->dist_typeid() != dimg->dist_typeid()) 00018 view_maker_ = this->find_vm(dimg->dist_typeid()); 00019 00020 return view_maker_ != 0; 00021 } 00022 00023 00024 //: Return the maximum number of components if a mixture 00025 // If not a mixture return 1 00026 unsigned int bbgm_viewer::max_components(const bbgm_image_sptr& dimg) const 00027 { 00028 if (!dimg) 00029 return 0; 00030 00031 if (!view_maker_ || view_maker_->dist_typeid() != dimg->dist_typeid()) 00032 view_maker_ = this->find_vm(dimg->dist_typeid()); 00033 if (!view_maker_) 00034 return 0; 00035 return view_maker_->max_components(dimg); 00036 } 00037 00038 00039 //: Apply the operations to the distribution image to produce a vil image 00040 bool bbgm_viewer::apply(const bbgm_image_sptr& dimg, 00041 vil_image_view<double>& image) const 00042 { 00043 if (!dimg) 00044 return false; 00045 00046 if (!view_maker_ || view_maker_->dist_typeid() != dimg->dist_typeid()) 00047 view_maker_ = this->find_vm(dimg->dist_typeid()); 00048 if (!view_maker_) 00049 return false; 00050 return view_maker_->apply(dimg, image, fail_val_, active_component_); 00051 } 00052 00053 00054 //============================================================================= 00055 00056 //: initialize the static vector of registered types 00057 vcl_vector<bbgm_view_maker_sptr> bbgm_mean_viewer::reg_vms; 00058 00059 //: Register a new view_maker 00060 // \return true if successfully registered or false if invalid or already 00061 // registered. 00062 bool bbgm_mean_viewer::register_view_maker(const bbgm_view_maker_sptr& vm) 00063 { 00064 if (!vm) // don't add null pointers 00065 return false; 00066 00067 // replace existing type match 00068 typedef vcl_vector<bbgm_view_maker_sptr>::iterator vm_itr; 00069 for (vm_itr i=reg_vms.begin(); i!=reg_vms.end(); ++i) 00070 if ((*i)->dist_typeid() == vm->dist_typeid()){ 00071 *i = vm; 00072 return true; 00073 } 00074 00075 // add to the collection if no duplicate found 00076 reg_vms.push_back(vm); 00077 return true; 00078 } 00079 00080 00081 //: Return a pointer to the view_maker that applies to this image type. 00082 // Return a null pointer if no such view_maker is found 00083 bbgm_view_maker_sptr 00084 bbgm_mean_viewer::find_view_maker(const vcl_type_info& dist_type) 00085 { 00086 typedef vcl_vector<bbgm_view_maker_sptr>::const_iterator vm_itr; 00087 for (vm_itr i=reg_vms.begin(); i!=reg_vms.end(); ++i) 00088 if ((*i)->dist_typeid() == dist_type) 00089 return *i; 00090 return bbgm_view_maker_sptr(NULL); 00091 } 00092 00093 //============================================================================= 00094 00095 //: initialize the static vector of registered types 00096 vcl_vector<bbgm_view_maker_sptr> bbgm_variance_viewer::reg_vms; 00097 00098 //: Register a new view_maker 00099 // \return true if successfully registered or false if invalid or already 00100 // registered. 00101 bool bbgm_variance_viewer::register_view_maker(const bbgm_view_maker_sptr& vm) 00102 { 00103 if (!vm) // don't add null pointers 00104 return false; 00105 00106 // replace existing type match 00107 typedef vcl_vector<bbgm_view_maker_sptr>::iterator vm_itr; 00108 for (vm_itr i=reg_vms.begin(); i!=reg_vms.end(); ++i) 00109 if ((*i)->dist_typeid() == vm->dist_typeid()){ 00110 *i = vm; 00111 return true; 00112 } 00113 00114 // add to the collection if no duplicate found 00115 reg_vms.push_back(vm); 00116 return true; 00117 } 00118 00119 00120 //: Return a pointer to the view_maker that applies to this image type. 00121 // Return a null pointer if no such view_maker is found 00122 bbgm_view_maker_sptr 00123 bbgm_variance_viewer::find_view_maker(const vcl_type_info& dist_type) 00124 { 00125 typedef vcl_vector<bbgm_view_maker_sptr>::const_iterator vm_itr; 00126 for (vm_itr i=reg_vms.begin(); i!=reg_vms.end(); ++i) 00127 if ((*i)->dist_typeid() == dist_type) 00128 return *i; 00129 return bbgm_view_maker_sptr(NULL); 00130 } 00131 00132 00133 //============================================================================= 00134 00135 //: initialize the static vector of registered types 00136 vcl_vector<bbgm_view_maker_sptr> bbgm_weight_viewer::reg_vms; 00137 00138 //: Register a new view_maker 00139 // \return true if successfully registered or false if invalid or already 00140 // registered. 00141 bool bbgm_weight_viewer::register_view_maker(const bbgm_view_maker_sptr& vm) 00142 { 00143 if (!vm) // don't add null pointers 00144 return false; 00145 00146 // replace existing type match 00147 typedef vcl_vector<bbgm_view_maker_sptr>::iterator vm_itr; 00148 for (vm_itr i=reg_vms.begin(); i!=reg_vms.end(); ++i) 00149 if ((*i)->dist_typeid() == vm->dist_typeid()){ 00150 *i = vm; 00151 return true; 00152 } 00153 00154 // add to the collection if no duplicate found 00155 reg_vms.push_back(vm); 00156 return true; 00157 } 00158 00159 00160 //: Return a pointer to the view_maker that applies to this image type. 00161 // Return a null pointer if no such view_maker is found 00162 bbgm_view_maker_sptr 00163 bbgm_weight_viewer::find_view_maker(const vcl_type_info& dist_type) 00164 { 00165 typedef vcl_vector<bbgm_view_maker_sptr>::const_iterator vm_itr; 00166 for (vm_itr i=reg_vms.begin(); i!=reg_vms.end(); ++i) 00167 if ((*i)->dist_typeid() == dist_type) 00168 return *i; 00169 return bbgm_view_maker_sptr(NULL); 00170 } 00171