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

bmvv_cal_manager.h

Go to the documentation of this file.
00001 // This is brl/bmvl/bmvv/bmvv_cal_manager.h
00002 #ifndef bmvv_cal_manager_h_
00003 #define bmvv_cal_manager_h_
00004 //----------------------------------------------------------------------------
00005 //:
00006 // \file
00007 // \brief Manager for camera calibration
00008 // \author
00009 //   J.L. Mundy
00010 //
00011 // Currently works on a single view. Provides interactive tools for
00012 // corresponding 3-d points to 2-d image locations. Also provides for
00013 // the solution of planar camera models (homographies).  The homography can be
00014 // extended to a vgl_p_matrix by selecting a number of points off the
00015 // ground plane. In addition there are several simple 3-d modeling tools:
00016 //      o Backproject a polygon onto a X-Y world plane (specified Z)
00017 //      o Create a 3-d box from three points on the roof face (specified Z)
00018 //
00019 // \verbatim
00020 //  Modifications:
00021 //   J.L. Mundy Jan 15, 2005    Initial version.
00022 // \endverbatim
00023 //-----------------------------------------------------------------------------
00024 #include <vcl_vector.h>
00025 #include <vcl_map.h>
00026 #include <vcl_fstream.h>
00027 //#include <vil1/vil1_image.h>
00028 #include <vil/vil_image_resource_sptr.h>
00029 #include <vgl/algo/vgl_p_matrix.h>
00030 #include <vsol/vsol_point_2d_sptr.h>
00031 #include <vsol/vsol_polygon_2d_sptr.h>
00032 #include <vsol/vsol_polygon_3d_sptr.h>
00033 #include <vgui/vgui_wrapper_tableau.h>
00034 #include <bgui/bgui_image_tableau_sptr.h>
00035 #include <vgui/vgui_range_map_params_sptr.h>
00036 #include <vgui/vgui_event.h>
00037 #include <vgui/vgui_soview2D.h>
00038 #include <bgui/bgui_vtol2D_tableau_sptr.h>
00039 #include <bgui/bgui_picker_tableau_sptr.h>
00040 
00041 class vgui_window;
00042 class vgui_soview;
00043 //: A manager for displaying segmentation results.
00044 class bmvv_cal_manager : public vgui_wrapper_tableau
00045 {
00046  public:
00047   bmvv_cal_manager();
00048  ~bmvv_cal_manager();
00049   static bmvv_cal_manager *instance();
00050 
00051   //: methods for menu callbacks
00052   void quit();
00053   void load_image();
00054   void save_image();
00055 
00056   //: 3-d points and polygons representing a world model
00057   void load_world();
00058 
00059   //: viewing functions
00060   void adjust_contrast();
00061   void set_range_params();
00062   void clear_display();
00063   void clear_selected();
00064   void load_image_and_camera();
00065 
00066   //: pairs of corresponding 2-d image and 3-d world points
00067   void load_corrs();
00068   void save_corrs();
00069   void pick_correspondence();
00070   void remove_correspondence();
00071 
00072   //: world-to-image correspondences and vertical lines for constrained cameras
00073   void pick_vertical();
00074   void save_constraints();
00075 
00076   //: camera modeling
00077   void set_identity_camera();
00078   void solve_camera();
00079   void compute_ransac_homography();
00080   void save_camera();
00081 
00082   //: backproject an image onto the world plane
00083   void map_image_to_world();
00084 
00085   // == modeling functions ==
00086 
00087   //: set the create XY plane height (Z)
00088   void set_height();
00089   //: define a polygon on the create plane
00090   void pick_polygon();
00091   //: clear all current world information
00092   void clear_world();
00093   //: insert a created polygon into the world data structures
00094   void confirm_polygon();
00095   //: save the world information in cal format
00096   void save_world();
00097   //: save the world information in ply2 format (a single indexed face set)
00098   void save_world_ply2();
00099   //: read the world information in ply2 format (a single indexed face set)
00100   void read_world_ply2();
00101   //: Convert boxes in a merged indexed face set to individual boxes in VRML
00102   // (A temporary tool to unmerge files consisting of all boxes)
00103   void ply2_to_vrml();
00104   //: Create a box in the world from three top face corner points on the create plane.  The bottom plane is at Z=0.
00105   void create_box();
00106   //: access to the window
00107   vgui_window* get_window(){return win_;}
00108   void set_window(vgui_window* win){win_=win;}
00109   void init();
00110 
00111   //: the virtual handle function
00112   virtual bool handle(const vgui_event&);
00113 
00114   void load_image_file(vcl_string image_filename, bool greyscale);
00115  protected:
00116   //: internal utility methods
00117   void draw_corr_point(const float x, const float y);
00118   void draw_vsol_points(const int cam,
00119                         vcl_vector<vsol_point_2d_sptr> const & points,
00120                         bool clear = true,
00121                         const float r = 0,
00122                         const float g = 1,
00123                         const float b = 0);
00124 
00125   void draw_vsol_point(const int cam,
00126                        vsol_point_2d_sptr const & point,
00127                        bool clear = false,
00128                        const float r = 0,
00129                        const float g = 1,
00130                        const float b = 0);
00131 
00132 void draw_vsol_polygon_3d(vsol_polygon_3d_sptr const & poly,
00133                           bool clear, const float r=0, const float g=1,
00134                           const float b=0);
00135 
00136   void draw_polygons_3d(bool clear, const float r,
00137                         const float g, const float b);
00138 
00139   void add_image(vil_image_resource_sptr const& image,
00140                vgui_range_map_params_sptr rmps = 0,
00141                bool greyscale =false);
00142   vil1_image get_image_at(unsigned col, unsigned row);
00143   bool read_corrs(vcl_ifstream& str);
00144   bool draw_correspondences();
00145   bool draw_projected_world_points();
00146   void add_poly_vertices_to_world_pts(vsol_polygon_3d_sptr const& poly);
00147   void clear_correspondences();
00148   void project_world();
00149   int  get_selected_proj_world_pt(vgl_point_2d<double>&  pt);
00150   vgui_range_map_params_sptr
00151     range_params(vil_image_resource_sptr const& image);
00152  private:
00153   vil_image_resource_sptr img_;
00154   vgui_window* win_;
00155   bgui_image_tableau_sptr itab_;
00156   bgui_picker_tableau_sptr ptab_;
00157   bgui_vtol2D_tableau_sptr btab_;
00158   vcl_map<int, int> point_3d_map_;
00159   static bmvv_cal_manager *instance_;
00160   vcl_vector<vgl_point_2d<double> > corrs_;
00161   vcl_vector<bool>  corrs_valid_;
00162   vcl_vector<vgl_point_2d<double> >  proj_image_pts_;
00163   vcl_vector<vgui_soview2D_point* >  corr_sovs_;
00164   vcl_vector<vgl_point_3d<double> > world_;
00165   //: the current camera
00166   vgl_p_matrix<double> cam_;
00167   //: the previous camera before the current solution
00168   vgl_p_matrix<double> prev_cam_;
00169   //: lines in the image corresponding to the vertical direction
00170   vcl_vector<vgl_line_segment_2d<double> > verticals_;
00171   //: the Z height of the create plane
00172   double height_;
00173   //: the polygon just created
00174   vsol_polygon_3d_sptr new_poly_;
00175   //: all the polygons in the world model
00176   vcl_vector<vsol_polygon_3d_sptr> polys_;
00177   //: the 2-d projected form of the polygons
00178   vcl_vector<vsol_polygon_2d_sptr> proj_polys_;
00179   //: an indexed face set for all the polygons in the world
00180   vcl_vector<vcl_vector<unsigned> > indexed_face_set_;
00181 };
00182 
00183 #endif // bmvv_cal_manager_h_

Generated on Thu Jan 10 14:54:21 2008 for contrib/brl/bmvl/bmvv by  doxygen 1.4.4