ComplexData.h

Go to the documentation of this file.
00001 /*
00002  * The information in this file is
00003  * Copyright(c) 2007 Ball Aerospace & Technologies Corporation
00004  * and is subject to the terms and conditions of the
00005  * GNU Lesser General Public License Version 2.1
00006  * The license text is available from   
00007  * http://www.gnu.org/licenses/lgpl.html
00008  */
00009 
00010 #ifndef COMPLEXDATA_H
00011 #define COMPLEXDATA_H
00012 
00013 #include <complex>
00014 #include "DataVariantValidator.h"
00015 #include "EnumWrapper.h"
00016 
00017 /**
00018  * Specifies the various components of complex data.
00019  */
00020 enum ComplexComponentEnum { COMPLEX_MAGNITUDE, COMPLEX_PHASE, COMPLEX_INPHASE, COMPLEX_QUADRATURE };
00021 
00022 /**
00023  * @EnumWrapper ::ComplexComponentEnum.
00024  */
00025 typedef EnumWrapper<ComplexComponentEnum> ComplexComponent;
00026 
00027 /**
00028  *  Contains integer real and imaginary values.
00029  *
00030  *  @see     FloatComplex
00031  */
00032 class IntegerComplex
00033 {
00034 public:
00035    /**
00036     *  Creates an default IntegerComplex object.
00037     */
00038    IntegerComplex() : mReal(0), mImaginary(0) {}
00039 
00040    /**
00041     *  Creates an IntegerComplex object with initial values.
00042     *
00043     *  @param   real
00044     *           The real or in-phase component value.
00045     *  @param   imaginary
00046     *           The imaginary or quadrature component value.
00047     */
00048    IntegerComplex(short real, short imaginary) : mReal(real), mImaginary(imaginary) {}
00049    IntegerComplex(double real) : mReal((short)real), mImaginary(0) {}
00050 
00051    double operator[] (ComplexComponent component) const
00052    {
00053       double dValue = 0.0;
00054       switch (component)
00055       {
00056          case COMPLEX_MAGNITUDE:
00057             dValue = (double) getMagnitude();
00058             break;
00059 
00060          case COMPLEX_PHASE:
00061             dValue = (double) getPhase();
00062             break;
00063 
00064          case COMPLEX_INPHASE:
00065             dValue = (double) mReal;
00066             break;
00067 
00068          case COMPLEX_QUADRATURE:
00069             dValue = (double) mImaginary;
00070             break;
00071 
00072          default:
00073             break;
00074       }
00075 
00076       return dValue;
00077    }
00078 
00079    /**
00080     *  Returns the magnitude of the data.
00081     *
00082     *  @return  The magnitude.
00083     */
00084    float getMagnitude() const
00085    {
00086       std::complex<float> complexData(mReal, mImaginary);
00087       return std::abs(complexData);
00088    }
00089 
00090    /**
00091     *  Returns the phase angle of the data.
00092     *
00093     *  @return  The phase angle in radians.
00094     */
00095    float getPhase() const
00096    {
00097       std::complex<float> complexData(mReal, mImaginary);
00098       return std::arg(complexData);
00099    }
00100 
00101    short mReal;
00102    short mImaginary;
00103 };
00104 
00105 /**
00106  *  Contains floating point real and imaginary values.
00107  *
00108  *  @see     IntegerComplex
00109  */
00110 class FloatComplex
00111 {
00112 public:
00113    /**
00114     *  Creates an default FloatComplex object.
00115     */
00116    FloatComplex() : mReal(0.0f), mImaginary(0.0f) {}
00117 
00118    /**
00119     *  Creates an FloatComplex object with initial values.
00120     *
00121     *  @param   real
00122     *           The real or in-phase component value.
00123     *  @param   imaginary
00124     *           The imaginary or quadrature component value.
00125     */
00126    FloatComplex(float real, float imaginary) : mReal(real), mImaginary(imaginary) {}
00127    FloatComplex(double real) : mReal((float)real), mImaginary(0.0f) {}
00128 
00129    double operator[] (ComplexComponent component) const
00130    {
00131       double dValue = 0.0;
00132       switch (component)
00133       {
00134          case COMPLEX_MAGNITUDE:
00135             dValue = (double) getMagnitude();
00136             break;
00137 
00138          case COMPLEX_PHASE:
00139             dValue = (double) getPhase();
00140             break;
00141 
00142          case COMPLEX_INPHASE:
00143             dValue = (double) mReal;
00144             break;
00145 
00146          case COMPLEX_QUADRATURE:
00147             dValue = (double) mImaginary;
00148             break;
00149 
00150          default:
00151             break;
00152       }
00153 
00154       return dValue;
00155    }
00156 
00157    /**
00158     *  Returns the magnitude of the data.
00159     *
00160     *  @return  The magnitude.
00161     */
00162    float getMagnitude() const
00163    {
00164       std::complex<float> complexData(mReal, mImaginary);
00165       return std::abs(complexData);
00166    }
00167 
00168    /**
00169     *  Returns the phase angle of the data.
00170     *
00171     *  @return  The phase angle in radians.
00172     */
00173    float getPhase() const
00174    {
00175       std::complex<float> complexData(mReal, mImaginary);
00176       return std::arg(complexData);
00177    }
00178 
00179    float mReal;
00180    float mImaginary;
00181 };
00182 
00183 /**
00184  * \cond INTERNAL
00185  * This template specialization is required to allow this type to be put into a DataVariant.
00186  */
00187 template <> class VariantTypeValidator<ComplexComponent> {};
00188 template <> class VariantTypeValidator<IntegerComplex> {};
00189 template <> class VariantTypeValidator<FloatComplex> {};
00190 /// \endcond
00191 
00192 #endif   // COMPLEXDATA_H

Software Development Kit - Opticks 4.9.0 Build 16218