00001 #ifndef vpgl_lvcs_h_
00002 #define vpgl_lvcs_h_
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036 #include <vcl_iostream.h>
00037 #include <vsl/vsl_binary_io.h>
00038 #include <vbl/vbl_ref_count.h>
00039 #include <vpgl/vpgl_dll.h>
00040 class vpgl_lvcs : public vbl_ref_count
00041 {
00042
00043
00044 public:
00045 enum LenUnits {FEET, METERS};
00046 enum AngUnits {RADIANS, DEG};
00047 enum cs_names { wgs84 =0, nad27n, wgs72, utm, NumNames};
00048 VPGL_DLL_DATA static const char* cs_name_strings[];
00049 static vpgl_lvcs::cs_names str_to_enum(const char*);
00050
00051 vpgl_lvcs(double orig_lat=0,
00052 double orig_lon=0,
00053 double orig_elev=0,
00054 cs_names cs_name=wgs84,
00055 double lat_scale=0,
00056 double lon_scale=0,
00057 AngUnits ang_unit = DEG,
00058 LenUnits len_unit=METERS,
00059 double lox=0,
00060 double loy=0,
00061 double theta=0);
00062
00063 vpgl_lvcs(double orig_lat,
00064 double orig_lon,
00065 double orig_elev,
00066 cs_names cs_name,
00067 AngUnits ang_unit = DEG,
00068 LenUnits len_unit=METERS);
00069
00070 vpgl_lvcs(double lat_low, double lon_low,
00071 double lat_high, double lon_high,
00072 double elev,
00073 cs_names cs_name=wgs84,
00074 AngUnits ang_unit=DEG, LenUnits elev_unit=METERS);
00075
00076 vpgl_lvcs(const vpgl_lvcs&);
00077 vpgl_lvcs& operator=(const vpgl_lvcs&);
00078
00079
00080
00081 void local_to_global(const double lx, const double ly, const double lz,
00082 cs_names cs_name,
00083 double& lon, double& lat, double& gz,
00084 AngUnits output_ang_unit=DEG,
00085 LenUnits output_len_unit=METERS);
00086
00087 void global_to_local(const double lon, const double lat, const double gz,
00088 cs_names cs_name,
00089 double& lx, double& ly, double& lz,
00090 AngUnits output_ang_unit=DEG,
00091 LenUnits output_len_unit=METERS);
00092
00093 void radians_to_degrees(double& lon, double& lat, double& z);
00094 double radians_to_degrees(const double val);
00095 void degrees_to_dms(double, int& degrees, int& minutes, double& seconds);
00096 void radians_to_dms(double, int& degrees, int& minutes, double& seconds);
00097
00098
00099 void get_origin(double& lat, double& lon, double& elev) const;
00100 void get_scale(double& lat, double& lon) const;
00101 void get_transform(double& lox, double& loy, double& theta) const;
00102 void set_transform(const double lox, const double loy, const double theta);
00103 void set_origin(const double lon, const double lat, const double elev);
00104 cs_names get_cs_name() const;
00105 inline LenUnits local_length_unit() const{return this->localXYZUnit_;}
00106 inline AngUnits geo_angle_unit() const {return this->geo_angle_unit_;}
00107 void print(vcl_ostream&) const;
00108 bool save(vcl_string fname) { vcl_ofstream of(fname.c_str()); if (of) { print(of); return true; } return false; }
00109 void read(vcl_istream& strm);
00110 friend vcl_ostream& operator << (vcl_ostream& os, const vpgl_lvcs& local_coord_sys);
00111 friend vcl_istream& operator >> (vcl_istream& os, vpgl_lvcs& local_coord_sys);
00112 bool operator==(vpgl_lvcs const& r) const;
00113
00114 void get_utm_origin(double& x, double& y, double& elev, int& zone) const;
00115
00116
00117
00118 protected:
00119 void compute_scale();
00120 void local_transform(double& x, double& y);
00121 void inverse_local_transform(double& x, double& y);
00122 void set_angle_conversions(AngUnits ang_unit, double& to_radians,
00123 double& to_degrees);
00124 void set_length_conversions(LenUnits len_unit, double& to_meters,
00125 double& to_feet);
00126 private:
00127
00128
00129
00130 protected:
00131 cs_names local_cs_name_;
00132 double localCSOriginLat_;
00133 double localCSOriginLon_;
00134 double localCSOriginElev_;
00135 double lat_scale_;
00136 double lon_scale_;
00137 AngUnits geo_angle_unit_;
00138 LenUnits localXYZUnit_;
00139 double lox_;
00140 double loy_;
00141 double theta_;
00142
00143 double localUTMOrigin_X_East_;
00144 double localUTMOrigin_Y_North_;
00145 int localUTMOrigin_Zone_;
00146 };
00147
00148
00149 inline void vpgl_lvcs::get_scale(double& lat, double& lon) const
00150 {
00151 lat = lat_scale_;
00152 lon = lon_scale_;
00153 }
00154
00155
00156 inline vpgl_lvcs::cs_names vpgl_lvcs::get_cs_name() const
00157 { return local_cs_name_; }
00158
00159
00160
00161 inline void vpgl_lvcs::get_origin(double& lat, double& lon, double& elev) const
00162 {
00163 lat = localCSOriginLat_;
00164 lon = localCSOriginLon_;
00165 elev = localCSOriginElev_;
00166 }
00167
00168 inline void vpgl_lvcs::get_utm_origin(double& x, double& y, double& elev, int& zone) const
00169 {
00170 x = localUTMOrigin_X_East_;
00171 y = localUTMOrigin_Y_North_;
00172 zone = localUTMOrigin_Zone_;
00173 elev = localCSOriginElev_;
00174 }
00175
00176
00177
00178 inline void vpgl_lvcs::get_transform(double& lox, double& loy, double& theta) const
00179 {
00180 lox = lox_;
00181 loy = loy_;
00182 theta = theta_;
00183 }
00184
00185
00186
00187 inline void vpgl_lvcs::set_transform(const double lox, const double loy,
00188 const double theta)
00189 {
00190 lox_ = lox;
00191 loy_ = loy;
00192 theta_ = theta;
00193 }
00194
00195
00196
00197 inline void vpgl_lvcs::set_origin(const double lon, const double lat, const double elev)
00198 {
00199 localCSOriginLon_ = lon;
00200 localCSOriginLat_ = lat;
00201 localCSOriginElev_ = elev;
00202 }
00203
00204 inline void vpgl_lvcs::radians_to_dms(double rad, int& degrees, int& minutes, double& seconds)
00205 {
00206 degrees_to_dms(radians_to_degrees(rad), degrees, minutes, seconds);
00207 }
00208 #endif // vpgl_lvcs_h_
00209