casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
Converter.h
Go to the documentation of this file.
00001 //# Copyright (C) 2005
00002 //# Associated Universities, Inc. Washington DC, USA.
00003 //#
00004 //# This library is free software; you can redistribute it and/or modify it
00005 //# under the terms of the GNU Library General Public License as published by
00006 //# the Free Software Foundation; either version 2 of the License, or (at your
00007 //# option) any later version.
00008 //#
00009 //# This library is distributed in the hope that it will be useful, but WITHOUT
00010 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00011 //# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
00012 //# License for more details.
00013 //#
00014 //# You should have received a copy of the GNU Library General Public License
00015 //# along with this library; if not, write to the Free Software Foundation,
00016 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
00017 //#
00018 //# Correspondence concerning AIPS++ should be addressed as follows:
00019 //#        Internet email: aips2-request@nrao.edu.
00020 //#        Postal address: AIPS++ Project Office
00021 //#                        National Radio Astronomy Observatory
00022 //#                        520 Edgemont Road
00023 //#                        Charlottesville, VA 22903-2475 USA
00024 //#
00025 
00026 #ifndef CONVERTER_H_
00027 #define CONVERTER_H_
00028 
00029 #include <QList>
00030 #include <QString>
00031 #include <casa/Arrays/Vector.h>
00032 #include <coordinates/Coordinates/SpectralCoordinate.h>
00033 namespace casa {
00034 
00035 class Converter {
00036 public:
00037         Converter( const QString& oldUnits, const QString& newUnits);
00038 
00039         //Factory for producing the appropriate converter.
00040         //Note:  user is responsible for deleting the converter.
00041         static Converter* getConverter( const QString& oldUnits,const QString& newUnits );
00042         static void setSpectralCoordinate( SpectralCoordinate coordinate );
00043         static void setRestFrequency( double restFrequency );
00044         static void convert( Vector<double> &resultValues, int sourceIndex, int destIndex);
00045 
00046         bool setVelocityUnits( const QString& units );
00047         bool setWavelengthUnits( const QString& units );
00048         QString getNewUnits() const;
00049 
00050 
00051 
00052         //Abstract methods to be implemented by subclasses.
00053         //virtual float convert( float oldValue ) const = 0;
00054         virtual double toPixel( double value ) = 0;
00055         virtual Vector<double> convert( const Vector<double>& oldValues ) = 0;
00056         virtual double convert ( double oldValue );
00057         virtual ~Converter();
00058 
00059 protected:
00060         static const QList<QString> FREQUENCY_UNITS;
00061         static const QList<QString> WAVELENGTH_UNITS;
00062         static const QList<QString> VELOCITY_UNITS;
00063 
00064         QString oldUnits;
00065         QString newUnits;
00066         static SpectralCoordinate spectralCoordinate;
00067         typedef enum {FREQUENCY_UNIT, VELOCITY_UNIT, WAVELENGTH_UNIT, CHANNEL_UNIT, UNRECOGNIZED } UnitType;
00068 
00069 private:
00070         static UnitType getUnitType( const QString& unit );
00071 
00072 };
00073 
00074 } /* namespace casa */
00075 #endif /* CONVERTER_H_ */