Go to the documentation of this file.00001
00002
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 #include <labust/blueview/CConverter.hpp>
00035 #include <labust/blueview/TrackerROI.hpp>
00036 #include <labust/math/uBlasOperations.hpp>
00037
00038 using namespace labust::blueview;
00039
00040 CConverter::CConverter(){};
00041
00042 CConverter::~CConverter(){};
00043
00044 void CConverter::llz2xy(const SonarHead& head, const TrackedFeaturePtr tracklet)
00045 {
00046
00047 this->update(head);
00048
00049
00050 std::pair<double,double>
00051 value = deg2meter(tracklet->latlon.x - head.latlon.x,tracklet->latlon.y - head.latlon.y,head.latlon.x);
00052
00053
00054
00055
00056 enum {x = 0,y,z};
00057 vector pos(3);
00058 pos(x) = value.first;
00059 pos(y) = value.second;
00060
00061 pos(z) = tracklet->latlon.z;
00062
00063
00064 matrix inverse;
00065 labust::math::gjinverse(R,inverse);
00066 pos = prod(inverse,pos);
00067
00068
00069 tracklet->position.x = pos(x);
00070 tracklet->position.y = pos(y);
00071 }
00072
00073 void CConverter::xy2llz(const SonarHead& head, const TrackedFeaturePtr tracklet)
00074 {
00075
00076 this->update(head);
00077
00078 enum {x = 0,y,z};
00079 vector pos(3);
00080 pos(x) = tracklet->position.x;
00081 pos(y) = tracklet->position.y;
00082
00083 pos(z) = 0;
00084
00085 pos = prod(R,pos);
00086 std::pair<double,double> value = meter2deg(pos(x), pos(y), head.latlon.x);
00087
00088
00089 tracklet->latlon.x = head.latlon.x + value.first;
00090 tracklet->latlon.y = head.latlon.y + value.second;
00091 tracklet->latlon.z = head.latlon.z + pos(z);
00092 }
00093
00094 void CConverter::meter2pixel(const TrackerROI& roi, const TrackedFeaturePtr tracklet)
00095 {
00096
00097
00098
00099 double pxrange = std::sqrt(std::pow(tracklet->position.y,2) + std::pow(tracklet->position.x,2))/roi.headData.resolution;
00100 double bearing = std::atan2(tracklet->position.y,tracklet->position.x);
00101
00102 tracklet->pposition.y = roi.origin.y - int(pxrange*std::cos(bearing));
00103 tracklet->pposition.x = roi.origin.x + int(pxrange*std::sin(bearing));
00104
00105
00106 }
00107
00108 void CConverter::pixel2meter(const TrackerROI& roi, const TrackedFeaturePtr tracklet)
00109 {
00110
00111
00112
00113 tracklet->position.y = (-roi.origin.x + tracklet->pposition.x)*roi.headData.resolution;
00114 tracklet->position.x = (roi.origin.y - tracklet->pposition.y)*roi.headData.resolution;
00115
00116
00117
00118
00119 }
00120
00121 void CConverter::update(const SonarHead& head)
00122 {
00123 labust::math::rotation_matrix R_hb(0,head.tiltAngle*M_PI/180,head.panAngle*M_PI/180);
00124 labust::math::rotation_matrix R_bn(0,0,head.heading*M_PI/180);
00125
00126 this->R = prod(R_bn(),R_hb());
00127 }
00128
00129 std::pair<double,double> CConverter::meter2deg(double x, double y, double lat)
00130 {
00131 static const double radius = 6378137;
00132 static const double ratio = 0.99664719;
00137 double mpdlat = 111132.954 - 559.822*cos(2*lat*M_PI/180) + 1.175*cos(4*lat*M_PI/180);
00138 double mpdlon = M_PI*radius*cos(atan(ratio*tan(lat*M_PI/180)))/180;
00139
00140 return std::pair<double,double>(x/mpdlat,y/mpdlon);
00141 }
00142
00143 std::pair<double,double> CConverter::deg2meter(double difflat, double difflon, double lat)
00144 {
00145 static const double radius = 6378137;
00146 static const double ratio = 0.99664719;
00151 double mpdlat = 111132.954 - 559.822*cos(2*lat*M_PI/180) + 1.175*cos(4*lat*M_PI/180);
00152 double mpdlon = M_PI*radius*cos(atan(ratio*tan(lat*M_PI/180)))/180;
00153
00154 return std::pair<double,double>(difflat*mpdlat,difflon*mpdlon);
00155 }