Main Page | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Class Members | File Members

bmvv_recon_manager.cxx

Go to the documentation of this file.
00001 // This is brl/bmvl/bmvv/bmvv_recon_manager.cxx
00002 #include "bmvv_recon_manager.h"
00003 //:
00004 // \file
00005 // \author J.L. Mundy
00006 
00007 #include <vcl_cstdlib.h> // for vcl_exit()
00008 #include <vcl_iostream.h>
00009 #include <vcl_fstream.h>
00010 #include <vil1/vil1_load.h>
00011 #include <vil1/vil1_memory_image_of.h>
00012 #include <vnl/vnl_numeric_traits.h>
00013 #include <vnl/vnl_math.h>
00014 #include <vgl/algo/vgl_h_matrix_2d.h>
00015 #include <vgl/algo/vgl_p_matrix.h>
00016 #include <vgui/vgui.h>
00017 #include <vgui/vgui_find.h>
00018 #include <vgui/vgui_style.h>
00019 #include <vgui/vgui_macro.h>
00020 #include <vgui/vgui_dialog.h>
00021 #include <vgui/vgui_soview2D.h>
00022 #include <vgui/vgui_image_tableau.h>
00023 #include <vgui/vgui_viewer2D_tableau.h>
00024 #include <vgui/vgui_grid_tableau.h>
00025 #include <vgui/vgui_shell_tableau.h>
00026 #include <bgui/bgui_image_tableau.h>
00027 #include <bgui/bgui_vtol2D_tableau.h>
00028 #include <bgui/bgui_picker_tableau.h>
00029 #include <brip/brip_vil1_float_ops.h>
00030 #include <brct/brct_plane_sweeper_params.h>
00031 #include <brct/brct_volume_processor_params.h>
00032 #include <brct/brct_dense_reconstructor.h>
00033 #include <brct/brct_algos.h>
00034 #include <vsol/vsol_point_2d.h>
00035 #include <vsol/vsol_point_3d.h>
00036 //static live_video_manager instance
00037 bmvv_recon_manager *bmvv_recon_manager::instance_ = 0;
00038 //===============================================================
00039 //: The singleton pattern - only one instance of the manager can occur
00040 //==============================================================
00041 bmvv_recon_manager *bmvv_recon_manager::instance()
00042 {
00043   if (!instance_)
00044   {
00045     instance_ = new bmvv_recon_manager();
00046     instance_->init();
00047   }
00048   return bmvv_recon_manager::instance_;
00049 }
00050 
00051 //==================================================================
00052 //: constructors/destructor
00053 //==================================================================
00054 bmvv_recon_manager::
00055 bmvv_recon_manager() : vgui_wrapper_tableau(),
00056                        sweep_(brct_plane_sweeper_params()),
00057                        vproc_(brct_volume_processor_params())
00058 {
00059   images_set_ = false;
00060   harris_set_ = false;
00061   plane_ = 0;
00062 }
00063 
00064 bmvv_recon_manager::~bmvv_recon_manager()
00065 {
00066 }
00067 
00068 //======================================================================
00069 //: set up the tableaux at each grid cell
00070 //  the vtol2D_tableaux have been initialized in the constructor
00071 //======================================================================
00072 void bmvv_recon_manager::init()
00073 {
00074   grid_ = vgui_grid_tableau_new(2,1);
00075   grid_->set_grid_size_changeable(true);
00076   for (unsigned int col=0, row=0; col<2; ++col)
00077   {
00078     vgui_image_tableau_sptr itab = bgui_image_tableau_new();
00079     bgui_vtol2D_tableau_sptr btab = bgui_vtol2D_tableau_new(itab);
00080     vtol_tabs_.push_back(btab);
00081     bgui_picker_tableau_new pcktab(btab);
00082     vgui_viewer2D_tableau_sptr v2d = vgui_viewer2D_tableau_new(pcktab);
00083     grid_->add_at(v2d, col, row);
00084   }
00085   vgui_shell_tableau_sptr shell = vgui_shell_tableau_new(grid_);
00086   this->add_child(shell);
00087 }
00088 
00089 //=========================================================================
00090 //: make an event handler
00091 // note that we have to get an adaptor and set the tableau to receive events
00092 // this handler does nothing but is a place holder for future event processing
00093 // For now, just pass the events down to the child tableaux
00094 //=========================================================================
00095 bool bmvv_recon_manager::handle(const vgui_event &e)
00096 {
00097   return this->child.handle(e);
00098 }
00099 
00100 //====================================================================
00101 //: Gets the picker tableau at the given position.
00102 //  Returns a null tableau if it fails
00103 //====================================================================
00104 bgui_picker_tableau_sptr
00105 bmvv_recon_manager::get_picker_tableau_at(unsigned col, unsigned row)
00106 {
00107   vgui_tableau_sptr top_tab = grid_->get_tableau_at(col, row);
00108   if (top_tab)
00109   {
00110     bgui_picker_tableau_sptr tt;
00111     tt.vertical_cast(vgui_find_below_by_type_name(top_tab,
00112                                                   vcl_string("bgui_picker_tableau")));
00113     if (tt)
00114       return tt;
00115   }
00116   vgui_macro_warning << "Unable to get bgui_picker_tableau at (" << col << ", "
00117                      << row << ")\n";
00118   return 0;
00119 }
00120 
00121 //====================================================================
00122 //: Gets the picker tableau at the currently selected grid position
00123 //  Returns a null tableau if it fails
00124 //====================================================================
00125 bgui_picker_tableau_sptr bmvv_recon_manager::get_selected_picker_tableau()
00126 {
00127   unsigned int row=0, col=0;
00128   grid_->get_last_selected_position(&col, &row);
00129   return this->get_picker_tableau_at(col, row);
00130 }
00131 
00132 //====================================================================
00133 //: Gets the picker tableau at the given position.
00134 //  if col, row are out of bounds then null is returned
00135 //  row is currently not used but may be when we have more than 2 cameras
00136 //====================================================================
00137 bgui_vtol2D_tableau_sptr bmvv_recon_manager::get_vtol2D_tableau_at(unsigned col, unsigned row)
00138 {
00139   if (row!=0)
00140     return 0;
00141   bgui_vtol2D_tableau_sptr btab = 0;
00142   if (col==0||col==1)
00143     btab = vtol_tabs_[col];
00144   return btab;
00145 }
00146 
00147 
00148 //=================================================================
00149 //: Get the vtol_2D_tableau at the currently selected grid cell.
00150 //=================================================================
00151 bgui_vtol2D_tableau_sptr bmvv_recon_manager::get_selected_vtol2D_tableau()
00152 {
00153   unsigned int row =0, col=0;
00154   grid_->get_last_selected_position(&col, &row);
00155   return this->get_vtol2D_tableau_at(col, row);
00156 }
00157 
00158 int bmvv_recon_manager::get_cam()
00159 {
00160   unsigned int row =0, col=0;
00161   grid_->get_last_selected_position(&col, &row);
00162   if (!row&&!col)
00163     return 0;
00164   return 1;
00165 }
00166 
00167 void bmvv_recon_manager::quit()
00168 {
00169   vcl_exit(1);
00170 }
00171 
00172 //=========================================================================
00173 //: load an image an put it in the currently selected grid cell
00174 //=========================================================================
00175 void bmvv_recon_manager::load_image_file(vcl_string image_filename, bool /* greyscale */, unsigned col, unsigned row)
00176 {
00177   img_ = vil1_load(image_filename.c_str());
00178   bgui_vtol2D_tableau_sptr btab = this->get_vtol2D_tableau_at(col, row);
00179   if (btab)
00180   {
00181     vgui_image_tableau_sptr itab = btab->get_image_tableau();
00182     itab->set_image(img_);
00183     return;
00184   }
00185   vcl_cout << "In bmvv_recon_manager::load_image_file() - null tableau\n";
00186 }
00187 
00188 //=========================================================================
00189 //: load an image an put it in the currently selected grid cell
00190 //=========================================================================
00191 void bmvv_recon_manager::load_image()
00192 {
00193   static bool greyscale = false;
00194   vgui_dialog load_image_dlg("Load Image");
00195   static vcl_string image_filename = "";
00196   static vcl_string ext = "*.*";
00197   load_image_dlg.file("Image Filename:", ext, image_filename);
00198   load_image_dlg.checkbox("greyscale ", greyscale);
00199   if (!load_image_dlg.ask())
00200     return;
00201   vil1_image temp = vil1_load(image_filename.c_str());
00202   if (greyscale)
00203   {
00204     vil1_memory_image_of<unsigned char> temp1 =
00205     brip_vil1_float_ops::convert_to_grey(temp);
00206     img_ = temp1;
00207   }
00208   else
00209     img_ = temp;
00210 
00211   bgui_vtol2D_tableau_sptr btab = this->get_selected_vtol2D_tableau();
00212   if (btab)
00213   {
00214     vgui_image_tableau_sptr itab = btab->get_image_tableau();
00215     itab->set_image(img_);
00216     itab->post_redraw();
00217     images_set_ = false;
00218     harris_set_ = false;
00219     return;
00220   }
00221   vcl_cout << "In bmvv_recon_manager::load_image() - null tableau\n";
00222 }
00223 
00224 //===================================================================
00225 //: Clear the display
00226 //===================================================================
00227 void bmvv_recon_manager::clear_display()
00228 {
00229   bgui_vtol2D_tableau_sptr btab = this->get_selected_vtol2D_tableau();
00230   if (btab)
00231     btab->clear_all();
00232   else
00233     vcl_cout << "In bmvv_recon_manager::clear_display() - null tableau\n";
00234 }
00235 
00236 //===================================================================
00237 //: clear all selections in both panes
00238 //===================================================================
00239 void bmvv_recon_manager::clear_selected()
00240 {
00241   for (vcl_vector<bgui_vtol2D_tableau_sptr>::iterator bit = vtol_tabs_.begin();
00242        bit != vtol_tabs_.end(); bit++)
00243     if (*bit)
00244       (*bit)->deselect_all();
00245 }
00246 
00247 
00248 //====================================================================
00249 //: Gets the image at the given position.
00250 //  if col, row are out of bounds then null is returned
00251 //  row is currently not used but may be when we have more than 2 cameras
00252 //====================================================================
00253 vil1_image bmvv_recon_manager::get_image_at(unsigned col, unsigned row)
00254 {
00255   bgui_vtol2D_tableau_sptr btab = this->get_vtol2D_tableau_at(col, row);
00256   if (btab)
00257   {
00258     vgui_image_tableau_sptr itab = btab->get_image_tableau();
00259     return itab->get_image();
00260   }
00261   vcl_cout << "In bmvv_recon_manager::get_image_at() - null tableau\n";
00262   return 0;
00263 }
00264 
00265 void bmvv_recon_manager::read_3d_points()
00266 {
00267   vgui_dialog load_3d_points_dlg("Load 3d Points");
00268   static vcl_string points_filename = "";
00269   static vcl_string ext = "*.*";
00270   load_3d_points_dlg.file("Planar 3-d Points File:", ext, points_filename);
00271   if (!load_3d_points_dlg.ask())
00272     return;
00273   cal_.read_data(points_filename);
00274 }
00275 
00276 void bmvv_recon_manager::initial_model_projection()
00277 {
00278   bgui_vtol2D_tableau_sptr btab = this->get_selected_vtol2D_tableau();
00279   if (!btab)
00280     return;
00281   vgui_dialog initial_project_dlg("Project Model (Inital)");
00282   initial_project_dlg.field("World Plane", plane_);
00283   if (!initial_project_dlg.ask())
00284     return;
00285   vgui_image_tableau_sptr itab = btab->get_image_tableau();
00286   vil1_image image = itab->get_image();
00287   if (!image)
00288     return;
00289   int width = image.width(), height = image.height();
00290   cal_.set_image_size(brct_plane_calibrator::LEFT, width, height);
00291   cal_.set_image_size(brct_plane_calibrator::RIGHT, width, height);
00292   if (!cal_.compute_initial_homographies())
00293   {
00294     vcl_cout << "In initial_model_projection() - problem computing initial homographies\n";
00295     return;
00296   }
00297   vcl_vector<vgl_point_2d<double> > pts_2d =
00298     cal_.projected_3d_points_initial(plane_, this->get_cam());
00299   btab->set_point_radius(5.0f);
00300   int i = 0;
00301   for (vcl_vector<vgl_point_2d<double> >::iterator pit = pts_2d.begin();
00302       pit != pts_2d.end(); pit++, i++)
00303     {
00304       vgui_soview2D_point* sov = btab->add_point((*pit).x(), (*pit).y());
00305       int id = sov->get_id();
00306       point_3d_map_[id]=i;
00307     }
00308   btab->post_redraw();
00309 }
00310 
00311 void bmvv_recon_manager::model_projection()
00312 {
00313  bgui_vtol2D_tableau_sptr btab = this->get_selected_vtol2D_tableau();
00314   if (!btab)
00315     return;
00316  vgui_dialog initial_project_dlg("Project Model");
00317   initial_project_dlg.field("World Plane", plane_);
00318   if (!initial_project_dlg.ask())
00319     return;
00320   vcl_vector<vgl_point_2d<double> > pts_2d =
00321     cal_.projected_3d_points(plane_, this->get_cam());
00322   btab->set_point_radius(5.0f);
00323   int i = 0;
00324   for (vcl_vector<vgl_point_2d<double> >::iterator pit = pts_2d.begin();
00325       pit != pts_2d.end(); pit++, i++)
00326     {
00327       vgui_soview2D_point* sov = btab->add_point((*pit).x(), (*pit).y());
00328       int id = sov->get_id();
00329       point_3d_map_[id]=i;
00330     }
00331   btab->post_redraw();
00332 }
00333 
00334 brct_plane_corr_sptr bmvv_recon_manager::get_selected_corr()
00335 {
00336   bgui_vtol2D_tableau_sptr btab = this->get_selected_vtol2D_tableau();
00337   if (!btab)
00338     return (brct_plane_corr*)0;
00339   vcl_vector<unsigned> ids = btab->get_selected();
00340   //take the last selected
00341   int n = ids.size();
00342   if (!n)
00343   {
00344     vcl_cout << "Nothing selected\n";
00345     return (brct_plane_corr*)0;
00346   }
00347   int i = point_3d_map_[ids[n-1]];
00348   return cal_.corr(plane_, i);
00349 }
00350 
00351 void bmvv_recon_manager::print_selected_corr()
00352 {
00353   brct_plane_corr_sptr corr = this->get_selected_corr();
00354   vcl_cout << *corr << vcl_endl;
00355 }
00356 
00357 void bmvv_recon_manager::draw_corr_point(const float x, const float y)
00358 {
00359  bgui_vtol2D_tableau_sptr btab = this->get_selected_vtol2D_tableau();
00360  if (!btab)
00361     return;
00362  btab->set_point_radius(3.0f);
00363  btab->set_foreground(0.0f, 1.0f, 0.0f);
00364  btab->add_point(x, y);
00365  btab->post_redraw();
00366 }
00367 
00368 void bmvv_recon_manager::pick_corr()
00369 {
00370   brct_plane_corr_sptr corr = this->get_selected_corr();
00371   if (!corr)
00372     return;
00373   bgui_picker_tableau_sptr ptab = this->get_selected_picker_tableau();
00374   if (!ptab)
00375     return;
00376   float x=0, y=0;
00377   ptab->pick_point(&x,&y);
00378   corr->set_match(this->get_cam(), x, y);
00379   this->draw_corr_point(x, y);
00380 }
00381 
00382 void bmvv_recon_manager::write_corrs()
00383 {
00384   vgui_dialog corr_dlg("Write Correspondences");
00385   static vcl_string corr_file = "";
00386   static vcl_string ext = "*.*";
00387   corr_dlg.file("Correspondence File", ext, corr_file);
00388   if (!corr_dlg.ask())
00389     return;
00390   if (!cal_.write_corrs(corr_file))
00391     vcl_cout << "In bmvv_recon_manager::write_corrs() - failed write\n";
00392 }
00393 
00394 void bmvv_recon_manager::read_corrs()
00395 {
00396   vgui_dialog corr_dlg("Read Correspondences");
00397   static vcl_string corr_file = "";
00398   static vcl_string ext = "*.*";
00399   corr_dlg.file("Correspondence File", ext, corr_file);
00400   if (!corr_dlg.ask())
00401     return;
00402   if (!cal_.read_corrs(corr_file))
00403     vcl_cout << "In bmvv_recon_manager::read_corrs() - failed read\n";
00404 }
00405 
00406 void bmvv_recon_manager::compute_homographies()
00407 {
00408   if (!cal_.compute_homographies())
00409     vcl_cout << "In bmvv_recon_manager::compute_homographies() - failed\n";
00410 }
00411 
00412 void bmvv_recon_manager::write_homographies()
00413 {
00414   vgui_dialog homg_dlg("Write Homographies");
00415   static vcl_string homg_file = "";
00416   static vcl_string ext = "*.*";
00417   homg_dlg.file("Homgraphy File", ext, homg_file);
00418   if (!homg_dlg.ask())
00419     return;
00420   if (!cal_.write_homographies(homg_file))
00421     vcl_cout << "In bmvv_recon_manager::write_homgraphies() - failed\n";
00422 }
00423 
00424 void bmvv_recon_manager::read_homographies()
00425 {
00426   vgui_dialog homg_dlg("Read Homographies");
00427   static vcl_string homg_file = "";
00428   static vcl_string ext = "*.*";
00429   homg_dlg.file("Homgraphy File", ext, homg_file);
00430   if (!homg_dlg.ask())
00431     return;
00432   if (!sweep_.read_homographies(homg_file))
00433     vcl_cout << "In bmvv_recon_manager::read_homgraphies() - failed\n";
00434 }
00435 
00436 void bmvv_recon_manager::project_image()
00437 {
00438  bgui_vtol2D_tableau_sptr btab = this->get_selected_vtol2D_tableau();
00439  if (!btab)
00440    return;
00441  vgui_image_tableau_sptr itab = btab->get_image_tableau();
00442  vil1_image image = itab->get_image();
00443  if (!image)
00444  {
00445    vcl_cout << "In bmvv_recon_manager::project_image() -"
00446             << " no image loaded in selected pane\n";
00447    return;
00448  }
00449  vgui_dialog image_project_dlg("Project Image");
00450   image_project_dlg.field("World Plane", plane_);
00451   if (!image_project_dlg.ask())
00452     return;
00453   int cam = this->get_cam();
00454   sweep_.set_image(cam, image);
00455   vil1_memory_image_of<unsigned char> pimg =
00456     sweep_.project_image_to_plane(plane_, cam);
00457   itab->set_image(pimg);
00458   itab->post_redraw();
00459 }
00460 
00461 void bmvv_recon_manager::set_images()
00462 {
00463   for (int cam = 0; cam<2; cam++)
00464   {
00465     bgui_vtol2D_tableau_sptr btab = vtol_tabs_[cam];
00466     vgui_image_tableau_sptr itab = btab->get_image_tableau();
00467     vil1_image image = itab->get_image();
00468     if (!image)
00469     {
00470       vcl_cout << "In bmvv_recon_manager::set_images()-"
00471                << " not enought images\n";
00472       return;
00473     }
00474     if (!sweep_.set_image(cam, image))
00475     {
00476       vcl_cout << "In bmvv_recon_manager::set_images()-"
00477                << " can't set image "<< cam << vcl_endl;
00478       return;
00479     }
00480   }
00481   images_set_ = true;
00482   harris_set_ = false;
00483 }
00484 
00485 void bmvv_recon_manager::overlapping_projections()
00486 {
00487   if (!images_set_)
00488   {
00489     vcl_cout << "In bmvv_recon_manager::overlapping_projections() -"
00490              << " images not set\n";
00491     return;
00492   }
00493   vgui_dialog image_project_dlg("Overlapping Projections");
00494   image_project_dlg.field("World Plane", plane_);
00495   if (!image_project_dlg.ask())
00496     return;
00497   vcl_vector<vil1_memory_image_of<float> > imgs;
00498   if (!sweep_.overlapping_projections(plane_, imgs))
00499   {
00500     vcl_cout << "In bmvv_recon_manager::overlapping_projections()-"
00501              << " overlap failed\n";
00502         return;
00503   }
00504   for (int cam = 0; cam<2; cam++)
00505   {
00506     bgui_vtol2D_tableau_sptr btab = vtol_tabs_[cam];
00507     vgui_image_tableau_sptr itab = btab->get_image_tableau();
00508     vil1_memory_image_of<unsigned char> temp =
00509       brip_vil1_float_ops::convert_to_byte(imgs[cam], 0, 255);
00510     itab->set_image(temp);
00511     itab->post_redraw();
00512   }
00513 }
00514 
00515 void bmvv_recon_manager::overlapping_projections_z()
00516 {
00517   if (!images_set_)
00518   {
00519     vcl_cout << "In bmvv_recon_manager::overlapping_projections_z() -"
00520              << " images not set\n";
00521     return;
00522   }
00523   static double z;
00524   vgui_dialog image_project_dlg("Overlapping Projections at Z");
00525   image_project_dlg.field("Depth z value", z);
00526   if (!image_project_dlg.ask())
00527     return;
00528   vcl_vector<vil1_memory_image_of<float> > imgs;
00529   if (!sweep_.overlapping_projections(z, imgs))
00530   {
00531     vcl_cout << "In bmvv_recon_manager::overlapping_projections()-"
00532              << " overlap failed\n";
00533         return;
00534   }
00535   for (int cam = 0; cam<2; cam++)
00536   {
00537     bgui_vtol2D_tableau_sptr btab = vtol_tabs_[cam];
00538     vgui_image_tableau_sptr itab = btab->get_image_tableau();
00539     vil1_memory_image_of<unsigned char> temp =
00540       brip_vil1_float_ops::convert_to_byte(imgs[cam], 0, 255);
00541     itab->set_image(temp);
00542     itab->post_redraw();
00543   }
00544 }
00545 
00546 void bmvv_recon_manager::
00547 draw_vsol_points(const int cam, vcl_vector<vsol_point_2d_sptr> const & points,
00548                  bool clear, const float r, const float g, const float b)
00549 {
00550   bgui_vtol2D_tableau_sptr btab = vtol_tabs_[cam];
00551   if (!btab)
00552   {
00553     vcl_cout << "In bmvv_recon_manager::draw_vsol_points(..) -"
00554              << " null btol tableau for pane " << cam << vcl_endl;
00555     return;
00556   }
00557   if (clear)
00558     btab->clear_all();
00559   vgui_style_sptr style = vgui_style::new_style(r, g, b, 3, 0);
00560   for (vcl_vector<vsol_point_2d_sptr>::const_iterator pit = points.begin();
00561       pit != points.end(); pit++)
00562     btab->add_vsol_point_2d(*pit, style);
00563 }
00564 
00565 void bmvv_recon_manager::
00566 draw_vsol_point(const int cam, vsol_point_2d_sptr const & point,
00567                 bool clear, const float r, const float g, const float b)
00568 {
00569   bgui_vtol2D_tableau_sptr btab = vtol_tabs_[cam];
00570   if (!btab)
00571   {
00572     vcl_cout << "In bmvv_recon_manager::draw_vsol_point(..) -"
00573              << " null btol tableau for pane " << cam << vcl_endl;
00574     return;
00575   }
00576   if (clear)
00577     btab->clear_all();
00578   vgui_style_sptr style = vgui_style::new_style(r, g, b, 3, 0);
00579   btab->add_vsol_point_2d(point,style);
00580 }
00581 
00582 //: color is determined by depth
00583 void bmvv_recon_manager::
00584 draw_vsol_3d_points(const int cam, vcl_vector<vsol_point_3d_sptr> const& pts3d,
00585                     bool clear)
00586 {
00587   bgui_vtol2D_tableau_sptr btab = vtol_tabs_[cam];
00588   if (!btab)
00589   {
00590     vcl_cout << "In bmvv_recon_manager::draw_vsol_3d_points(..) -"
00591              << " null btol tableau for pane " << cam << vcl_endl;
00592     return;
00593   }
00594   if (clear)
00595     btab->clear_all();
00596   double zmin = vnl_numeric_traits<double>::maxval, zmax = -zmin;
00597   for (vcl_vector<vsol_point_3d_sptr>::const_iterator pit = pts3d.begin();
00598       pit != pts3d.end(); pit++)
00599   {
00600     zmin = vnl_math_min(zmin, (*pit)->z());
00601     zmax = vnl_math_max(zmax, (*pit)->z());
00602   }
00603   double d = zmax-zmin, s = 1;
00604   if (d)
00605     s = 1/d;
00606   for (vcl_vector<vsol_point_3d_sptr>::const_iterator pit = pts3d.begin();
00607       pit != pts3d.end(); pit++)
00608   {
00609     float f = (float)(((*pit)->z()-zmin)*s);
00610     vcl_cout << "f(" << (*pit)->z() << ")=" << f << vcl_endl;
00611     vsol_point_2d_sptr p = new vsol_point_2d((*pit)->x(), (*pit)->y());
00612     vgui_style_sptr style = vgui_style::new_style(f, 0, 1-f, 3, 0);
00613     btab->add_vsol_point_2d(p,style);
00614   }
00615 }
00616 
00617 void bmvv_recon_manager::compute_harris_corners()
00618 {
00619   if (!images_set_)
00620   {
00621     vcl_cout << "In bmvv_recon_manager::compute_harris_corners() -"
00622              << " images not set\n";
00623     return;
00624   }
00625   vgui_dialog harris_dialog("Compute Harris Corners");
00626   harris_dialog.field("sigma", sweep_.hdp_.sigma_);
00627   harris_dialog.field("thresh", sweep_.hdp_.thresh_);
00628   harris_dialog.field("N = 2n+1, (n)", sweep_.hdp_.n_);
00629   harris_dialog.field("Max No Corners(percent)", sweep_.hdp_.percent_corners_);
00630   harris_dialog.field("scale_factor", sweep_.hdp_.scale_factor_);
00631   if (!harris_dialog.ask())
00632     return;
00633   if (!sweep_.compute_harris())
00634     return;
00635   for (int cam = 0; cam<2; cam++)
00636   {
00637     vcl_vector<vsol_point_2d_sptr> points = sweep_.harris_corners(cam);
00638     this->draw_vsol_points(cam, points);
00639   }
00640   harris_set_ = true;
00641 }
00642 
00643 void bmvv_recon_manager::overlapping_harris_proj_z()
00644 {
00645   if (!images_set_||!harris_set_)
00646   {
00647     vcl_cout << "In bmvv_recon_manager::overlapping_projections_z() -"
00648              << " images not set or harris not ready\n";
00649     return;
00650   }
00651   static double z;
00652   vgui_dialog image_project_dlg("Overlapping Harris Projections at Z");
00653   image_project_dlg.field("Depth z value", z);
00654   if (!image_project_dlg.ask())
00655     return;
00656   vcl_vector<vil1_memory_image_of<float> > imgs;
00657   vcl_vector<vcl_vector<vsol_point_2d_sptr> > harris_corners;
00658   if (!sweep_.overlapping_projections(z, imgs, harris_corners))
00659   {
00660     vcl_cout << "In bmvv_recon_manager::overlapping_projections()-"
00661              << " overlap failed\n";
00662         return;
00663   }
00664   for (int cam = 0; cam<2; cam++)
00665   {
00666     bgui_vtol2D_tableau_sptr btab = vtol_tabs_[cam];
00667     vgui_image_tableau_sptr itab = btab->get_image_tableau();
00668     vil1_memory_image_of<unsigned char> temp =
00669       brip_vil1_float_ops::convert_to_byte(imgs[cam], 0, 255);
00670     itab->set_image(temp);
00671     itab->post_redraw();
00672     this->draw_vsol_points(cam, harris_corners[cam]);
00673   }
00674 }
00675 
00676 void bmvv_recon_manager::cross_correlate_plane()
00677 {
00678   if (!images_set_)
00679   {
00680     vcl_cout << "In bmvv_recon_manager::overlapping_projections() -"
00681              << " images not set\n";
00682     return;
00683   }
00684  vgui_dialog cc_plane_dlg("Cross Correlate Plane");
00685   cc_plane_dlg.field("World Plane", plane_);
00686   cc_plane_dlg.field("Corr Display Range (min)", sweep_.corr_min_);
00687   cc_plane_dlg.field("Corr Display Range (max)", sweep_.corr_max_);
00688   cc_plane_dlg.field("Correlation Sigma", sweep_.corr_sigma_);
00689 
00690   if (!cc_plane_dlg.ask())
00691     return;
00692   vil1_memory_image_of<unsigned char> cc =
00693     sweep_.cross_correlate_projections(plane_);
00694   if (!cc)
00695   {
00696     vcl_cout << "In bmvv_recon_manager::cross_correlate_plane()-"
00697              << " correlation failed\n";
00698     return;
00699   }
00700   bgui_vtol2D_tableau_sptr btab = vtol_tabs_[0];
00701   vgui_image_tableau_sptr itab = btab->get_image_tableau();
00702   itab->set_image(cc);
00703   itab->post_redraw();
00704 }
00705 
00706 void bmvv_recon_manager::cross_correlate_z()
00707 {
00708   if (!images_set_)
00709   {
00710     vcl_cout << "In bmvv_recon_manager::overlapping_projections() -"
00711              << " images not set\n";
00712     return;
00713   }
00714   static double z = 0;
00715   vgui_dialog cc_z_dlg("Cross Correlate Z");
00716   cc_z_dlg.field("World Plane", z);
00717   cc_z_dlg.field("Corr Display Range (min)", sweep_.corr_min_);
00718   cc_z_dlg.field("Corr Display Range (max)", sweep_.corr_max_);
00719   cc_z_dlg.field("Corr Sigma", sweep_.corr_sigma_);
00720   if (!cc_z_dlg.ask())
00721     return;
00722   vil1_memory_image_of<unsigned char> cc =
00723     sweep_.cross_correlate_projections(z);
00724   if (!cc)
00725   {
00726     vcl_cout << "In bmvv_recon_manager::cross_correlate_z()-"
00727              << " correlation failed\n";
00728     return;
00729   }
00730   bgui_vtol2D_tableau_sptr btab = vtol_tabs_[0];
00731   vgui_image_tableau_sptr itab = btab->get_image_tableau();
00732   itab->set_image(cc);
00733   itab->post_redraw();
00734 }
00735 
00736 void bmvv_recon_manager::cross_correlate_harris_z()
00737 {
00738   if (!images_set_||!harris_set_)
00739   {
00740     vcl_cout << "In bmvv_recon_manager::overlapping_projections() -"
00741              << " images or harris corners not set\n";
00742     return;
00743   }
00744   static double z = 0;
00745   vgui_dialog cc_z_harris_dlg("Cross Correlate Harris Corners at Z");
00746   cc_z_harris_dlg.field("World Plane", z);
00747   cc_z_harris_dlg.field("Match radius", sweep_.point_radius_);
00748   cc_z_harris_dlg.field("Corr radius", sweep_.corr_radius_);
00749   cc_z_harris_dlg.field("Correlation Threshold", sweep_.corr_thresh_);
00750   if (!cc_z_harris_dlg.ask())
00751     return;
00752   vil1_image img;
00753   vcl_vector<vsol_point_2d_sptr> matched_corners, back_proj_cnrs, orig_cnrs0;
00754 
00755   if (!sweep_.cross_correlate_proj_corners(z, img,
00756                                           matched_corners,
00757                                           back_proj_cnrs,
00758                                           orig_cnrs0))
00759     {
00760       vcl_cout << "In bmvv_recon_manager::cross_correlate_harris_z()-"
00761                << " correlation failed\n";
00762       return;
00763     }
00764   bgui_vtol2D_tableau_sptr btab = vtol_tabs_[1];
00765   vgui_image_tableau_sptr itab = btab->get_image_tableau();
00766   itab->set_image(img);
00767   itab->post_redraw();
00768   this->draw_vsol_points(0, orig_cnrs0);
00769   this->draw_vsol_points(0, back_proj_cnrs, false, 1, 0, 0);
00770   this->draw_vsol_points(1, matched_corners);
00771 }
00772 
00773 void bmvv_recon_manager::depth_image()
00774 {
00775   if (!images_set_)
00776   {
00777     vcl_cout << "In bmvv_recon_manager::overlapping_projections() -"
00778              << " images not set\n";
00779     return;
00780   }
00781   vgui_dialog depth_dlg("Compute Depth Image");
00782   depth_dlg.field("Min Z", sweep_.zmin_);
00783   depth_dlg.field("Max Z", sweep_.zmax_);
00784   depth_dlg.field("N Depth Planes", sweep_.nz_);
00785   depth_dlg.field("Corr Display Range (min)", sweep_.corr_min_);
00786   depth_dlg.field("Corr Display Range (max)", sweep_.corr_max_);
00787   depth_dlg.field("Corr Sigma", sweep_.corr_sigma_);
00788   depth_dlg.field("Correlation Threshold", sweep_.corr_thresh_);
00789   depth_dlg.field("Mean Intensity Threshold", sweep_.intensity_thresh_);
00790   if (!depth_dlg.ask())
00791     return;
00792   vil1_memory_image_of<unsigned char> depth, max_corr;
00793   if (!sweep_.depth_image(depth, max_corr))
00794   {
00795     vcl_cout << "In bmvv_recon_manager::depth_image()-"
00796              << " depth image failed\n";
00797     return;
00798   }
00799   bgui_vtol2D_tableau_sptr btab = vtol_tabs_[0];
00800   vgui_image_tableau_sptr itab = btab->get_image_tableau();
00801   itab->set_image(depth);
00802   itab->post_redraw();
00803   btab = vtol_tabs_[1];
00804   itab = btab->get_image_tableau();
00805   itab->set_image(max_corr);
00806   itab->post_redraw();
00807 }
00808 
00809 void bmvv_recon_manager::z_corr_image()
00810 {
00811  bgui_vtol2D_tableau_sptr btab = this->get_selected_vtol2D_tableau();
00812  if (!btab)
00813    return;
00814  vgui_image_tableau_sptr itab = btab->get_image_tableau();
00815  static int z = 0;
00816  vgui_dialog z_corr_dlg("Z-Correlation Image");
00817   z_corr_dlg.field("Z index", z);
00818   z_corr_dlg.field("Corr Display Range (min)", sweep_.corr_min_);
00819   z_corr_dlg.field("Corr Display Range (max)", sweep_.corr_max_);
00820   if (!z_corr_dlg.ask())
00821     return;
00822 
00823   vil1_memory_image_of<unsigned char> z_image = sweep_.z_corr_image(z);
00824   if (!z_image)
00825   {
00826     vcl_cout << "No Z_corr_images available\n";
00827     return;
00828   }
00829   itab->set_image(z_image);
00830   itab->post_redraw();
00831 }
00832 
00833 void bmvv_recon_manager::harris_depth_match()
00834 {
00835   if (!images_set_||!harris_set_)
00836   {
00837     vcl_cout << "In bmvv_recon_manager::harris_depth_match() -"
00838              << " images or harris corners not set\n";
00839     return;
00840   }
00841   vgui_dialog depth_dlg("Compute Harris Depth Match");
00842   depth_dlg.field("Min Z", sweep_.zmin_);
00843   depth_dlg.field("Max Z", sweep_.zmax_);
00844   depth_dlg.field("N Depth Planes", sweep_.nz_);
00845   depth_dlg.field("Corr Display Range (min)", sweep_.corr_min_);
00846   depth_dlg.field("Corr Display Range (max)", sweep_.corr_max_);
00847   depth_dlg.field("Point Match Radius", sweep_.point_radius_);
00848   depth_dlg.field("Correlation Window Radius", sweep_.corr_radius_);
00849   depth_dlg.field("CorrelationSigma", sweep_.corr_sigma_);
00850   depth_dlg.field("Correlation Threshold", sweep_.corr_thresh_);
00851   depth_dlg.field("Mean Intensity Threshold", sweep_.intensity_thresh_);
00852   if (!depth_dlg.ask())
00853