1 #ifndef bwm_observer_mgr_h_ 2 #define bwm_observer_mgr_h_ 3 //: 4 // \file 5 6 #include <vector> 7 #include <iostream> 8 #include <iosfwd> 9 #ifdef _MSC_VER 10 # include <vcl_msvc_warnings.h> 11 #endif 12 #include <vgl/vgl_fwd.h> 13 14 #include "bwm_observer.h" 15 #include "bwm_observer_cam.h" 16 #include "bwm_observable.h" 17 #include "bwm_observable_sptr.h" 18 #include "bwm_observer_rat_cam.h" 19 #include "bwm_corr.h" 20 #include "bwm_corr_sptr.h" 21 #include "bwm_3d_corr_sptr.h" 22 23 24 class bwm_observer_mgr 25 { 26 public: 27 typedef enum {IMAGE_TO_IMAGE, WORLD_TO_IMAGE, WORLD_TO_WORLD, FIDUCIAL_IMAGE_LOCATION} BWM_CORR_MODE; 28 typedef enum {SINGLE_PT_CORR, MULTIPLE_CORRS} BWM_N_CORRS; 29 typedef enum {FEATURE_CORR, TERRAIN_CORR, FIDUCIAL_CORR} BWM_CORR_TYPE; 30 31 static bwm_observer_mgr* instance(); 32 ~bwm_observer_mgr()33 virtual ~bwm_observer_mgr() {} 34 35 static bwm_observer_cam* BWM_MASTER_OBSERVER; 36 37 static bwm_observer_cam* BWM_EO_OBSERVER; 38 39 static bwm_observer_cam* BWM_OTHER_MODE_OBSERVER; 40 41 //: cleans up the correspondences and initializes the system for a new site 42 void clear(); 43 44 std::vector<bwm_observer_cam*> observers_cam() const; 45 std::vector<bwm_observer_rat_cam*> observers_rat_cam() const; 46 47 void add(bwm_observer* o); 48 49 void remove(bwm_observer* observer); 50 51 //: attach the observable to all observers 52 void attach(bwm_observable_sptr obs); 53 54 //: detach the observable from all observers 55 void detach(bwm_observable_sptr obs); 56 57 bool comp_avg_camera_center(vgl_point_3d<double> &cam_center); 58 59 // Correspondence methods 60 void collect_corr(); 61 void set_corr(bwm_corr_sptr corr); 62 bool obs_in_corr(bwm_observer_cam *obs); 63 64 //: returns the corresponding points on an observer 65 std::vector<vgl_point_2d<double> > get_corr_points(bwm_observer_cam *obs); 66 67 //implement me! 68 bool match(bwm_observer_cam *obs, vgl_point_2d<double> pt); 69 void save_corr(std::ostream& s); 70 void save_corr_XML(); 71 void update_corr(bwm_observer_cam* obs,vgl_point_2d<double> old_pt,vgl_point_2d<double> new_pt); 72 void delete_last_corr(); 73 void delete_all_corr(); corr_mode()74 BWM_CORR_MODE corr_mode() const { return corr_mode_; } corr_type()75 BWM_CORR_TYPE corr_type() const { return corr_type_; } n_corrs()76 BWM_N_CORRS n_corrs() const { return n_corrs_; } 77 void set_corr_mode(); set_corr_mode(BWM_CORR_MODE mode)78 void set_corr_mode(BWM_CORR_MODE mode){corr_mode_ = mode;} set_n_corrs(BWM_N_CORRS n)79 void set_n_corrs(BWM_N_CORRS n){n_corrs_ = n;} 80 void move_to_corr(); 81 82 //: picking up corr points are controlled by starting and stopping it start_corr()83 void start_corr() { start_corr_ = true; } stop_corr()84 void stop_corr() { start_corr_ = false; } 85 //: returns true if the correspondence picking started by the main corr menu in_corr_picking()86 bool in_corr_picking() const { return start_corr_; } 87 88 void print_observers(); 89 correspondences()90 std::vector<bwm_corr_sptr> correspondences() 91 {return corr_list_;} 92 93 //: Given a set of image-to-image correspondences, solve for the 3-d world point and adjust the cameras 94 void adjust_camera_offsets(); 95 96 void find_terrain_points(std::vector<vgl_point_3d<double> >& points); 97 98 //============ site to site correspondence methods ============== 99 // methods for selecting correspondences between multiple sites 100 // observables provide the site string name. 3-d points are constructed 101 // from multiple views either as 3-d polygon vertices or polygon centroids. 102 103 //: get all selected soviews to find the corresponding vertices or polygons 104 std::vector<bwm_observable_sptr> 105 all_selected_observables(std::string const& soview_type) const; 106 107 //: requires exactly two selected vertices each in a unique site 108 // (NOT YET IMPLEMENTED) 109 bool add_3d_corr_vertex(); 110 111 //: requires exactly two selected polygons each in a unique site. 112 // Corresponds centroids of the polygons 113 bool add_3d_corr_centroid(); 114 115 116 //: save 3d_corrs as an ascii file 117 void save_3d_corrs() const; 118 static void save_3d_corrs(std::string const& path, 119 std::vector<bwm_3d_corr_sptr> const& corrs); 120 121 //: load 3d_corrs from an ascii file 122 void load_3d_corrs(); 123 static void load_3d_corrs(std::string const& path, 124 std::vector<bwm_3d_corr_sptr>& corrs); 125 private: bwm_observer_mgr()126 bwm_observer_mgr() : start_corr_(false) 127 { 128 corr_mode_ = IMAGE_TO_IMAGE; 129 n_corrs_ = SINGLE_PT_CORR; 130 corr_type_ = FEATURE_CORR; 131 } 132 133 static bwm_observer_mgr* instance_; 134 135 std::vector<bwm_observer* > observers_; 136 137 bool start_corr_; 138 BWM_CORR_MODE corr_mode_; 139 BWM_N_CORRS n_corrs_; 140 BWM_CORR_TYPE corr_type_; 141 std::vector<bwm_corr_sptr> corr_list_; 142 std::vector<bwm_corr_sptr> terrain_corr_list_; 143 std::vector<bwm_3d_corr_sptr> site_to_site_corr_list_; 144 145 #if 0 146 bool world_point_valid_; 147 vgl_point_3d<double> corr_world_pt_; 148 #endif 149 }; 150 151 #endif 152