XYZ2NEU.cpp

Go to the documentation of this file.
00001 #pragma ident "$Id: XYZ2NEU.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 "XYZ2NEU.hpp"
00033 
00034 
00035 namespace gpstk
00036 {
00037 
00038 
00039       // Index initially assigned to this class
00040    int XYZ2NEU::classIndex = 7200000;
00041 
00042 
00043       // Returns an index identifying this object.
00044    int XYZ2NEU::getIndex() const
00045    { return index; }
00046 
00047 
00048       // Returns a string identifying this object.
00049    std::string XYZ2NEU::getClassName() const
00050    { return "XYZ2NEU"; }
00051 
00052 
00053 
00054       /* Common constructor taking reference point Position object
00055        *
00056        * @param refPos    Reference point Position object.
00057        */
00058    XYZ2NEU::XYZ2NEU(const Position& refPos)
00059    {
00060 
00061       setLatLon( refPos.getGeodeticLatitude(),
00062                  refPos.getLongitude() );
00063 
00064       setIndex();
00065 
00066    }  // End of 'XYZ2NEU::XYZ2NEU()'
00067 
00068 
00069 
00070       /* Method to set the latitude of the reference point, in degrees.
00071        *
00072        * @param lat      Latitude of the reference point, in degrees.
00073        *
00074        * @warning If parameter 'lat' is outside the +90/-90 degrees range,
00075        * then latitude will be set to 0 degrees.
00076        */
00077    XYZ2NEU& XYZ2NEU::setLat(const double& lat)
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 'XYZ2NEU::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    XYZ2NEU& XYZ2NEU::setLon(const double& lon)
00103    {
00104 
00105       refLon = (lon*DEG_TO_RAD);
00106 
00107       init();
00108 
00109       return (*this);
00110 
00111    }  // End of method 'XYZ2NEU::setLon()'
00112 
00113 
00114 
00115       /* Method to simultaneously set the latitude and longitude of the
00116        *  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    XYZ2NEU& XYZ2NEU::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 'XYZ2NEU::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& XYZ2NEU::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 'XYZ2NEU::Process()'
00187 
00188 
00189 
00190       // This method builds the rotation matrix according to 'refLat'
00191       // and 'refLon' values.
00192    void XYZ2NEU::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 'XYZ2NEU::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