VectorOperators.hpp

Go to the documentation of this file.
00001 #pragma ident "$Id: VectorOperators.hpp 3140 2012-06-18 15:03:02Z susancummins $"
00002 
00003 
00004 
00010 #ifndef GPSTK_VECTOR_OPERATORS_HPP
00011 #define GPSTK_VECTOR_OPERATORS_HPP
00012 
00013 //============================================================================
00014 //
00015 //  This file is part of GPSTk, the GPS Toolkit.
00016 //
00017 //  The GPSTk is free software; you can redistribute it and/or modify
00018 //  it under the terms of the GNU Lesser General Public License as published
00019 //  by the Free Software Foundation; either version 2.1 of the License, or
00020 //  any later version.
00021 //
00022 //  The GPSTk is distributed in the hope that it will be useful,
00023 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
00024 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00025 //  GNU Lesser General Public License for more details.
00026 //
00027 //  You should have received a copy of the GNU Lesser General Public
00028 //  License along with GPSTk; if not, write to the Free Software Foundation,
00029 //  Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
00030 //  
00031 //  Copyright 2004, The University of Texas at Austin
00032 //
00033 //============================================================================
00034 
00035 namespace gpstk
00036 {
00037 
00040 
00041 #define VecBaseNewUnaryOperator(func) \
00042  \
00043    template <class T, class BaseClass> \
00044    Vector<T> func(const ConstVectorBase<T, BaseClass>& x) \
00045       { \
00046          BaseClass toReturn(x.size()); \
00047          size_t i; for (i=0; i < x.size(); i++) toReturn[i] = func(x[i]); \
00048          return toReturn; \
00049       }
00050 
00051 //   VecBaseNewUnaryOperator(-)
00052    VecBaseNewUnaryOperator(abs)
00053       VecBaseNewUnaryOperator(acos)
00054       VecBaseNewUnaryOperator(asin)
00055       VecBaseNewUnaryOperator(atan)
00056       VecBaseNewUnaryOperator(cos)
00057       VecBaseNewUnaryOperator(cosh)
00058       VecBaseNewUnaryOperator(exp)
00059       VecBaseNewUnaryOperator(log)
00060       VecBaseNewUnaryOperator(log10)
00061       VecBaseNewUnaryOperator(sinh)
00062       VecBaseNewUnaryOperator(sin)
00063       VecBaseNewUnaryOperator(sqrt)
00064       VecBaseNewUnaryOperator(tan)
00065       VecBaseNewUnaryOperator(tanh)
00066 
00067 #define VecBaseNewBinaryOperator(func, retval) \ \
00069 template <class T, class BaseClass, class BaseClass2> \
00070 retval operator func(const ConstVectorBase<T, BaseClass>& l, \
00071             const ConstVectorBase<T, BaseClass2>& r) \
00072 { \
00073    if (l.size() != r.size()) \
00074    { \
00075       VectorException e("Unequal lengths vectors"); \
00076       GPSTK_THROW(e); \
00077    } \
00078    retval toReturn(l.size()); \
00079    size_t i; \
00080    for (i=0; i < l.size(); i++) toReturn[i] = l[i] func r[i]; \
00081    return toReturn; \
00082 } \ \
00084 template <class T, class BaseClass> \
00085 retval operator func(const ConstVectorBase<T, BaseClass>& l, const T r) \
00086 { \
00087    retval toReturn(l.size()); \
00088    size_t i; \
00089    for (i=0; i < l.size(); i++) toReturn[i] = l[i] func r; \
00090    return toReturn; \
00091 } \ \
00093 template <class T, class BaseClass> \
00094 retval operator func(const T l, const ConstVectorBase<T, BaseClass>& r) \
00095 { \
00096    retval toReturn(r.size()); \
00097    size_t i; \
00098    for (i=0; i < r.size(); i++) toReturn[i] = l func r[i]; \
00099    return toReturn; \
00100 } 
00101 
00102       VecBaseNewBinaryOperator(*, Vector<T>)
00103       VecBaseNewBinaryOperator(/, Vector<T>)
00104       VecBaseNewBinaryOperator(%, Vector<T>)
00105       VecBaseNewBinaryOperator(+, Vector<T>)
00106       VecBaseNewBinaryOperator(-, Vector<T>)
00107       VecBaseNewBinaryOperator(^, Vector<T>)
00108       VecBaseNewBinaryOperator(&, Vector<T>)
00109       VecBaseNewBinaryOperator(|, Vector<T>)
00110 
00111       VecBaseNewBinaryOperator(==, Vector<bool>)
00112       VecBaseNewBinaryOperator(<, Vector<bool>)
00113       VecBaseNewBinaryOperator(>, Vector<bool>)
00114       VecBaseNewBinaryOperator(!=, Vector<bool>)
00115       VecBaseNewBinaryOperator(<=, Vector<bool>)
00116       VecBaseNewBinaryOperator(>=, Vector<bool>)
00117 
00118 #define VecBaseNewBinaryTranscendentalOperator(func, retval) \ \
00120    template <class T, class BaseClass, class BaseClass2> \
00121    retval func(const ConstVectorBase<T, BaseClass>& l, \
00122                const ConstVectorBase<T, BaseClass2>& r) \
00123    { \
00124       retval toReturn(l.size()); \
00125       size_t i; \
00126       for (i=0; i < l.size(); i++) toReturn[i] = func(l[i], r[i]); \
00127       return toReturn; \
00128    } \ \
00130 template <class T, class BaseClass> \
00131 retval func(const ConstVectorBase<T, BaseClass>& l, const T r) \
00132 { \
00133    retval toReturn(l.size()); \
00134    size_t i; \
00135    for (i=0; i < l.size(); i++) toReturn[i] = func(l[i], r); \
00136    return toReturn; \
00137 } \ \
00139 template <class T, class BaseClass> \
00140 retval func(const T l, const ConstVectorBase<T, BaseClass>& r) \
00141 { \
00142    retval toReturn(r.size()); \
00143    size_t i; \
00144    for (i=0; i < r.size(); i++) toReturn[i] = func(l, r[i]); \
00145    return toReturn; \
00146 } 
00147 
00148       VecBaseNewBinaryTranscendentalOperator(atan, Vector<T>)
00149       VecBaseNewBinaryTranscendentalOperator(pow, Vector<T>)
00150 
00152       template <class T, class BaseClass, class BaseClass2> 
00153    Vector<T> cross(const ConstVectorBase<T, BaseClass>& l, 
00154                 const ConstVectorBase<T, BaseClass2>& r) throw(VectorException)
00155 { 
00156    if ((l.size() != 3) && (r.size() != 3))
00157    {
00158       VectorException e("Cross product requires vectors of size 3");
00159       GPSTK_THROW(e);
00160    }
00161    BaseClass toReturn(3);
00162    toReturn[0] = l[1] * r[2] - l[2] * r[1];
00163    toReturn[1] = l[2] * r[0] - l[0] * r[2];
00164    toReturn[2] = l[0] * r[1] - l[1] * r[0];
00165    return toReturn;
00166 } 
00167 
00169 template <class T, class BaseClass>
00170 Vector<T> normalize(const ConstVectorBase<T, BaseClass>& l) 
00171 { return l / norm(l); } 
00172 
00174 template <class T, class BaseClass>
00175 T RSS(const ConstVectorBase<T, BaseClass>& l) 
00176 { return norm(l); } 
00177 
00179 template <class T, class BaseClass>
00180 T RMS(const ConstVectorBase<T, BaseClass>& l) 
00181 { return norm(l)/SQRT(T(l.size())); } 
00182 
00184  
00185 }  // namespace
00186 
00187 #endif
00188 
00189 

Generated on Fri May 24 03:31:14 2013 for GPS ToolKit Software Library by  doxygen 1.3.9.1