XYZ2NED.cpp

Go to the documentation of this file.
00001 #pragma ident "$Id: XYZ2NED.cpp 1325 2008-07-29 14:33:43Z architest $"
00002 
00009 //============================================================================
00010 //
00011 //  This file is part of GPSTk, the GPS Toolkit.
00012 //
00013 //  The GPSTk is free software; you can redistribute it and/or modify
00014 //  it under the terms of the GNU Lesser General Public License as published
00015 //  by the Free Software Foundation; either version 2.1 of the License, or
00016 //  any later version.
00017 //
00018 //  The GPSTk is distributed in the hope that it will be useful,
00019 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
00020 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00021 //  GNU Lesser General Public License for more details.
00022 //
00023 //  You should have received a copy of the GNU Lesser General Public
00024 //  License along with GPSTk; if not, write to the Free Software Foundation,
00025 //  Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00026 //
00027 //  Dagoberto Salazar - gAGE ( http://www.gage.es ). 2007, 2008
00028 //
00029 //============================================================================
00030 
00031 
00032 #include "XYZ2NED.hpp"
00033 
00034 
00035 namespace gpstk
00036 {
00037 
00038       // Index initially assigned to this class
00039    int XYZ2NED::classIndex = 7300000;
00040 
00041 
00042       // Returns an index identifying this object.
00043    int XYZ2NED::getIndex() const
00044    { return index; }
00045 
00046 
00047       // Returns a string identifying this object.
00048    std::string XYZ2NED::getClassName() const
00049    { return "XYZ2NED"; }
00050 
00051 
00052 
00053       /* Common constructor taking reference point Position object
00054        *
00055        * @param refPos    Reference point Position object.
00056        */
00057    XYZ2NED::XYZ2NED(const Position& refPos)
00058    {
00059 
00060       setLatLon( refPos.getGeodeticLatitude(),
00061                  refPos.getLongitude() );
00062 
00063       setIndex();
00064 
00065    }  // End of 'XYZ2NED::XYZ2NED()'
00066 
00067 
00068 
00069       /* Method to set the latitude of the reference point, in degrees.
00070        *
00071        * @param lat      Latitude of the reference point, in degrees.
00072        *
00073        * @warning If parameter 'lat' is outside the +90/-90 degrees range,
00074        * then latitude will be set to 0 degrees.
00075        */
00076    XYZ2NED& XYZ2NED::setLat(const double& lat)
00077    {
00078 
00079          // Don't allow latitudes out of the -90/+90 interval
00080       if ( (lat > 90.0) ||
00081            (lat < -90.0)  )
00082       {
00083          refLat = 0.0;
00084       }
00085       else
00086       {
00087          refLat = (lat*DEG_TO_RAD);
00088       }
00089 
00090       init();
00091 
00092       return (*this);
00093 
00094    }  // End of method 'XYZ2NED::setLat()'
00095 
00096 
00097 
00098       /* Method to set the longitude of the reference point, in degrees.
00099        *
00100        * @param lon       Longitude of the reference point, in degrees.
00101        */
00102    XYZ2NED& XYZ2NED::setLon(const double& lon)
00103    {
00104 
00105       refLon = (lon*DEG_TO_RAD);
00106 
00107       init();
00108 
00109       return (*this);
00110 
00111    }  // End of method 'XYZ2NED::setLon()'
00112 
00113 
00114 
00115       /* Method to simultaneously set the latitude and longitude of
00116        * the reference point, in degrees.
00117        *
00118        * @param lat        Latitude of the reference point, in degrees.
00119        * @param lon        Longitude of the reference point, in degrees.
00120        *
00121        * @warning If parameter 'lat' is outside the +90/-90 degrees range,
00122        * then latitude will be set to 0 degrees.
00123        */
00124    XYZ2NED& XYZ2NED::setLatLon( const double& lat,
00125                                 const double& lon )
00126    {
00127 
00128          // Don't allow latitudes out of the -90/+90 interval
00129       if ( (lat > 90.0) ||
00130            (lat < -90.0)  )
00131       {
00132          refLat = 0.0;
00133       }
00134       else
00135       {
00136          refLat = (lat*DEG_TO_RAD);
00137       }
00138 
00139       refLon = (lon*DEG_TO_RAD);
00140 
00141       init();
00142 
00143       return (*this);
00144 
00145    }  // End of method 'XYZ2NED::setLatLon()'
00146 
00147 
00148 
00149       // Returns a reference to a satTypeValueMap object after converting
00150       // from a geocentric reference system to a topocentric reference system.
00151       //
00152       // @param gData     Data object holding the data.
00153       //
00154    satTypeValueMap& XYZ2NED::Process(satTypeValueMap& gData)
00155       throw(ProcessingException)
00156    {
00157 
00158       try
00159       {
00160 
00161          Matrix<double> neuMatrix;
00162 
00163             // Get the corresponding geometry/design matrix data
00164          Matrix<double> dMatrix(gData.getMatrixOfTypes(inputSet));
00165 
00166             // Compute the base change. For convenience, we use the property:
00167             // Y = A*B => Y^T = (A*B)^T => Y^T = B^T * A^T
00168          neuMatrix = dMatrix*rotationMatrix;
00169 
00170          gData.insertMatrix(outputSet, neuMatrix);
00171 
00172          return gData;
00173 
00174       }
00175       catch(Exception& u)
00176       {
00177             // Throw an exception if something unexpected happens
00178          ProcessingException e( getClassName() + ":"
00179                                 + StringUtils::asString( getIndex() ) + ":"
00180                                 + u.what() );
00181 
00182          GPSTK_THROW(e);
00183 
00184       }
00185 
00186    }  // End of method 'XYZ2NED::Process()'
00187 
00188 
00189 
00190       // This method builds the rotation matrix according to 'refLat' and
00191       // 'refLon' values.
00192    void XYZ2NED::init()
00193    {
00194 
00195          // First, let's resize rotation matrix and assign the proper values
00196       rotationMatrix.resize(3,3);
00197 
00198          // The clasical rotation matrix is transposed here for convenience
00199       rotationMatrix(0,0) = -std::sin(refLat)*std::cos(refLon);
00200       rotationMatrix(1,0) = -std::sin(refLat)*std::sin(refLon);
00201       rotationMatrix(2,0) = std::cos(refLat);
00202       rotationMatrix(0,1) = -std::sin(refLon);
00203       rotationMatrix(1,1) = std::cos(refLon);
00204       rotationMatrix(2,1) = 0.0;
00205       rotationMatrix(0,2) = -std::cos(refLat)*std::cos(refLon);
00206       rotationMatrix(1,2) = -std::cos(refLat)*std::sin(refLon);
00207       rotationMatrix(2,2) = -std::sin(refLat);
00208 
00209          // Then, fill the sets with the proper types
00210       inputSet.clear();
00211       inputSet.insert(TypeID::dx);
00212       inputSet.insert(TypeID::dy);
00213       inputSet.insert(TypeID::dz);
00214 
00215       outputSet.clear();
00216       outputSet.insert(TypeID::dLat);
00217       outputSet.insert(TypeID::dLon);
00218       outputSet.insert(TypeID::dH);
00219 
00220    }  // End of method 'XYZ2NED::init()'
00221 
00222 
00223 
00224 }  // End of namespace gpstk

Generated on Tue May 22 03:31:02 2012 for GPS ToolKit Software Library by  doxygen 1.3.9.1