00001
00002 #ifndef bmvv_cal_manager_h_
00003 #define bmvv_cal_manager_h_
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include <vcl_vector.h>
00025 #include <vcl_map.h>
00026 #include <vcl_fstream.h>
00027
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
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
00052 void quit();
00053 void load_image();
00054 void save_image();
00055
00056
00057 void load_world();
00058
00059
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
00067 void load_corrs();
00068 void save_corrs();
00069 void pick_correspondence();
00070 void remove_correspondence();
00071
00072
00073 void pick_vertical();
00074 void save_constraints();
00075
00076
00077 void set_identity_camera();
00078 void solve_camera();
00079 void compute_ransac_homography();
00080 void save_camera();
00081
00082
00083 void map_image_to_world();
00084
00085
00086
00087
00088 void set_height();
00089
00090 void pick_polygon();
00091
00092 void clear_world();
00093
00094 void confirm_polygon();
00095
00096 void save_world();
00097
00098 void save_world_ply2();
00099
00100 void read_world_ply2();
00101
00102
00103 void ply2_to_vrml();
00104
00105 void create_box();
00106
00107 vgui_window* get_window(){return win_;}
00108 void set_window(vgui_window* win){win_=win;}
00109 void init();
00110
00111
00112 virtual bool handle(const vgui_event&);
00113
00114 void load_image_file(vcl_string image_filename, bool greyscale);
00115 protected:
00116
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
00166 vgl_p_matrix<double> cam_;
00167
00168 vgl_p_matrix<double> prev_cam_;
00169
00170 vcl_vector<vgl_line_segment_2d<double> > verticals_;
00171
00172 double height_;
00173
00174 vsol_polygon_3d_sptr new_poly_;
00175
00176 vcl_vector<vsol_polygon_3d_sptr> polys_;
00177
00178 vcl_vector<vsol_polygon_2d_sptr> proj_polys_;
00179
00180 vcl_vector<vcl_vector<unsigned> > indexed_face_set_;
00181 };
00182
00183 #endif // bmvv_cal_manager_h_