00001 #ifndef vpgl_geo_camera_h_
00002 #define vpgl_geo_camera_h_
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #include <vcl_iosfwd.h>
00016 #include <vcl_vector.h>
00017
00018 #include <vpgl/vpgl_lvcs_sptr.h>
00019 #include <vpgl/vpgl_lvcs.h>
00020 #include <vnl/vnl_matrix.h>
00021
00022 #include <vpgl/vpgl_camera.h>
00023
00024 #include <vil/vil_image_resource_sptr.h>
00025
00026 class vpgl_geo_camera : public vpgl_camera<double>
00027 {
00028 public:
00029
00030 vpgl_geo_camera();
00031
00032
00033 vpgl_geo_camera(vnl_matrix<double> trans_matrix,
00034 vpgl_lvcs_sptr lvcs)
00035 : trans_matrix_(trans_matrix), is_utm(false), scale_tag_(false) { this->set_lvcs(lvcs); }
00036
00037
00038 vpgl_geo_camera(vpgl_geo_camera const& rhs);
00039
00040 vpgl_geo_camera(vpgl_camera<double> const& rhs);
00041
00042 static bool init_geo_camera(vil_image_resource_sptr const geotiff_img,
00043 vpgl_lvcs_sptr lvcs,
00044 vpgl_geo_camera*& camera);
00045
00046 ~vpgl_geo_camera() {}
00047
00048 virtual vcl_string type_name() const { return "vpgl_geo_camera"; }
00049
00050
00051 void set_utm(int utm_zone, unsigned northing) { is_utm=true, utm_zone_=utm_zone; northing_=northing; }
00052
00053 void set_lvcs(vpgl_lvcs_sptr lvcs) {lvcs_ = new vpgl_lvcs(*lvcs); }
00054
00055 void set_scale_format(bool scale_tag) { scale_tag_=scale_tag; }
00056
00057 vpgl_lvcs_sptr const lvcs() {return lvcs_;}
00058
00059
00060
00061 void project(const double x, const double y, const double z, double& u, double& v) const;
00062
00063
00064 void backproject(const double u, const double v, double& x, double& y, double& z);
00065
00066
00067 void translate(double tx, double ty, double z);
00068
00069
00070 double pixel_spacing() { if (scale_tag_) return trans_matrix_[0][0];
00071 else return 1.0; }
00072
00073 bool operator ==(vpgl_geo_camera const& rhs) const;
00074
00075 static bool comp_trans_matrix(double sx1, double sy1, double sz1,
00076 vcl_vector<vcl_vector<double> > tiepoints,
00077 vnl_matrix<double>& trans_matrix,
00078 bool scale_tag = false);
00079
00080
00081 virtual vcl_string is_a() const { return vcl_string("vpgl_geo_camera"); }
00082
00083
00084 virtual bool is_class(vcl_string const& cls) const
00085 { return cls==is_a() || cls==vcl_string("vpgl_geo_camera"); }
00086
00087
00088 friend vcl_ostream& operator<<(vcl_ostream& s, vpgl_geo_camera const& p);
00089
00090
00091 friend vcl_istream& operator>>(vcl_istream& s, vpgl_geo_camera& p);
00092
00093
00094
00095 void img_to_global(const double i, const double j,
00096 double& lon, double& lat) const;
00097
00098
00099
00100 void global_to_img(const double lon, const double lat, const double elev,
00101 double& u, double& v) const;
00102
00103
00104
00105 void img_to_global_utm(const double i, const double j,
00106 double& x, double& y) const;
00107
00108
00109
00110 void global_utm_to_img(const double x, const double y, int zone, double elev,
00111 double& u, double& v) const;
00112
00113
00114 void local_to_utm(const double x, const double y, const double z, double& e, double& n, int& utm_zone);
00115
00116 int utm_zone() { return utm_zone_; }
00117
00118 bool img_four_corners_in_utm(const unsigned ni, const unsigned nj, double elev, double& e1, double& n1, double& e2, double& n2);
00119
00120
00121
00122 void img_to_wgs(unsigned i, unsigned j, unsigned k, double& lon, double& lat, double& elev);
00123
00124 #if 0
00125
00126 void wgs_to_img(double lon, double lat,
00127 unsigned& i, unsigned& j);
00128 #endif // 0
00129
00130 private:
00131
00132 vnl_matrix<double> trans_matrix_;
00133
00134 vpgl_lvcs_sptr lvcs_;
00135 bool is_utm;
00136 int utm_zone_;
00137 int northing_;
00138 bool scale_tag_;
00139 };
00140
00141 #endif // vpgl_geo_camera_h_