00001
00002 #include "bmvv_tomography_manager.h"
00003
00004
00005
00006
00007 #include <vcl_cstdlib.h>
00008 #include <vcl_iostream.h>
00009 #include <vil1/vil1_load.h>
00010 #include <vil1/vil1_save.h>
00011 #include <bxml/bxml_vtol_io.h>
00012 #include <vgui/vgui.h>
00013 #include <vgui/vgui_find.h>
00014 #include <vgui/vgui_macro.h>
00015 #include <vgui/vgui_dialog.h>
00016 #include <vgui/vgui_image_tableau.h>
00017 #include <vgui/vgui_viewer2D_tableau.h>
00018 #include <vgui/vgui_grid_tableau.h>
00019 #include <vgui/vgui_shell_tableau.h>
00020 #include <bgui/bgui_image_tableau.h>
00021 #include <bgui/bgui_vtol2D_tableau.h>
00022 #include <bgui/bgui_picker_tableau.h>
00023 #include <sdet/sdet_detector_params.h>
00024 #include <sdet/sdet_detector.h>
00025 #include <sdet/sdet_region_proc_params.h>
00026 #include <sdet/sdet_region_proc.h>
00027 #include <brip/brip_vil1_float_ops.h>
00028 #include <btom/btom_slice_simulator.h>
00029
00030
00031 bmvv_tomography_manager *bmvv_tomography_manager::instance_ = 0;
00032
00033
00034
00035 bmvv_tomography_manager *bmvv_tomography_manager::instance()
00036 {
00037 if (!instance_)
00038 {
00039 instance_ = new bmvv_tomography_manager();
00040 instance_->init();
00041 }
00042 return bmvv_tomography_manager::instance_;
00043 }
00044
00045
00046
00047
00048 bmvv_tomography_manager::
00049 bmvv_tomography_manager() : vgui_wrapper_tableau()
00050 {
00051 }
00052
00053 bmvv_tomography_manager::~bmvv_tomography_manager()
00054 {
00055 }
00056
00057
00058
00059
00060
00061 void bmvv_tomography_manager::init()
00062 {
00063 grid_ = vgui_grid_tableau_new(2,1);
00064 grid_->set_grid_size_changeable(true);
00065 unsigned int col=0, row = 0;
00066 for (; col<2; col++)
00067 {
00068 vgui_image_tableau_sptr itab = bgui_image_tableau_new();
00069 bgui_vtol2D_tableau_sptr btab = bgui_vtol2D_tableau_new(itab);
00070 vtol_tabs_.push_back(btab);
00071 bgui_picker_tableau_new pcktab(btab);
00072 vgui_viewer2D_tableau_sptr v2d = vgui_viewer2D_tableau_new(pcktab);
00073 grid_->add_at(v2d, col, row);
00074 }
00075 vgui_shell_tableau_sptr shell = vgui_shell_tableau_new(grid_);
00076 this->add_child(shell);
00077 }
00078
00079
00080
00081
00082
00083
00084
00085 bool bmvv_tomography_manager::handle(const vgui_event &e)
00086 {
00087 return this->child.handle(e);
00088 }
00089
00090
00091
00092
00093
00094 bgui_picker_tableau_sptr
00095 bmvv_tomography_manager::get_picker_tableau_at(unsigned col, unsigned row)
00096 {
00097 vgui_tableau_sptr top_tab = grid_->get_tableau_at(col, row);
00098 if (top_tab)
00099 {
00100 bgui_picker_tableau_sptr tt;
00101 tt.vertical_cast(vgui_find_below_by_type_name(top_tab,
00102 vcl_string("bgui_picker_tableau")));
00103 if (tt)
00104 return tt;
00105 }
00106 vgui_macro_warning << "Unable to get bgui_picker_tableau at (" << col << ", "
00107 << row << ")\n";
00108 return 0;
00109 }
00110
00111
00112
00113
00114
00115 bgui_picker_tableau_sptr bmvv_tomography_manager::get_selected_picker_tableau()
00116 {
00117 unsigned int row =0, col=0;
00118 grid_->get_last_selected_position(&col, &row);
00119 return this->get_picker_tableau_at(col, row);
00120 }
00121
00122
00123
00124
00125
00126
00127 bgui_vtol2D_tableau_sptr bmvv_tomography_manager::get_vtol2D_tableau_at(unsigned col, unsigned row)
00128 {
00129 if (row!=0)
00130 return 0;
00131 bgui_vtol2D_tableau_sptr btab = 0;
00132 if (col==0||col==1)
00133 btab = vtol_tabs_[col];
00134 return btab;
00135 }
00136
00137
00138
00139
00140 bgui_vtol2D_tableau_sptr bmvv_tomography_manager::get_selected_vtol2D_tableau()
00141 {
00142 unsigned int row =0, col=0;
00143 grid_->get_last_selected_position(&col, &row);
00144 return this->get_vtol2D_tableau_at(col, row);
00145 }
00146
00147 void bmvv_tomography_manager::quit()
00148 {
00149 vcl_exit(1);
00150 }
00151
00152
00153
00154
00155 void bmvv_tomography_manager::load_image()
00156 {
00157 bool greyscale = false;
00158 vgui_dialog load_image_dlg("Load Image");
00159 static vcl_string image_filename = "";
00160 static vcl_string ext = "*.*";
00161 load_image_dlg.file("Image Filename:", ext, image_filename);
00162 load_image_dlg.checkbox("greyscale ", greyscale);
00163 if (!load_image_dlg.ask())
00164 return;
00165 img_ = vil1_load(image_filename.c_str());
00166 bgui_vtol2D_tableau_sptr btab = this->get_selected_vtol2D_tableau();
00167 if (btab)
00168 {
00169 vgui_image_tableau_sptr itab = btab->get_image_tableau();
00170 itab->set_image(img_);
00171 return;
00172 }
00173 vcl_cout << "In bmvv_tomography_manager::load_image() - null tableau\n";
00174 }
00175
00176
00177
00178
00179 void bmvv_tomography_manager::save_sinogram()
00180 {
00181 if (!sino_||!img_)
00182 {
00183 vcl_cout << "In bmvv_tomography_manager::save_sinogram() - no images\n";
00184 return;
00185 }
00186 vgui_dialog load_image_dlg("Save Sinogram");
00187 static vcl_string image_filename = "", sino_filename="";
00188 static vcl_string ext = "*.*";
00189 load_image_dlg.file("Image Filename:", ext, image_filename);
00190 load_image_dlg.file("Sinogram Filename:", ext, sino_filename);
00191 if (!load_image_dlg.ask())
00192 return;
00193 vil1_save(img_, image_filename.c_str(), "tiff");
00194 vil1_save(sino_, sino_filename.c_str(), "tiff");
00195 }
00196
00197
00198
00199
00200 void bmvv_tomography_manager::clear_display()
00201 {
00202 bgui_vtol2D_tableau_sptr btab = this->get_selected_vtol2D_tableau();
00203 if (btab)
00204 btab->clear();
00205 else
00206 vcl_cout << "In bmvv_tomography_manager::clear_display() - null tableau\n";
00207 }
00208
00209
00210
00211
00212 void bmvv_tomography_manager::clear_selected()
00213 {
00214 for (vcl_vector<bgui_vtol2D_tableau_sptr>::iterator bit = vtol_tabs_.begin();
00215 bit != vtol_tabs_.end(); bit++)
00216 if (*bit)
00217 (*bit)->deselect_all();
00218 }
00219
00220
00221
00222
00223
00224 void bmvv_tomography_manager::sinogram()
00225 {
00226 static float scale;
00227 static btom_slice_simulator_params ssp;
00228 vgui_dialog gauss_dialog("Gauss Sinogram");
00229 gauss_dialog.field("N Cylinders ", ssp.ncyl_);
00230 gauss_dialog.field("min radius", ssp.min_xy_sigma_);
00231 gauss_dialog.field("max radius", ssp.max_xy_sigma_);
00232 gauss_dialog.field("display scale", scale);
00233 if (!gauss_dialog.ask())
00234 return;
00235 btom_slice_simulator ss(ssp);
00236 vil1_memory_image_of<float> sinogram;
00237 vil1_memory_image_of<float> reconst;
00238 ss.gaussian_sinogram(sinogram, reconst);
00239
00240 sino_= brip_vil1_float_ops::convert_to_byte(sinogram, 0.0, scale);
00241
00242 img_ = brip_vil1_float_ops::convert_to_byte(reconst);
00243 bgui_vtol2D_tableau_sptr btab0 = vtol_tabs_[0];
00244 bgui_vtol2D_tableau_sptr btab1 = vtol_tabs_[1];
00245 if (btab0)
00246 {
00247 vgui_image_tableau_sptr itab = btab0->get_image_tableau();
00248 itab->set_image(img_);
00249 }
00250 if (btab1)
00251 {
00252 vgui_image_tableau_sptr itab = btab1->get_image_tableau();
00253 itab->set_image(sino_);
00254 }
00255 }