casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
QualityCoordinate.h
Go to the documentation of this file.
00001 //# QualityCoordinate.h: Interconvert between pixel number and Quality value.
00002 //# Copyright (C) 1997,1998,1999,2000,2001,2002,2003,2004
00003 //# Associated Universities, Inc. Washington DC, USA.
00004 //#
00005 //# This library is free software; you can redistribute it and/or modify it
00006 //# under the terms of the GNU Library General Public License as published by
00007 //# the Free Software Foundation; either version 2 of the License, or (at your
00008 //# option) any later version.
00009 //#
00010 //# This library is distributed in the hope that it will be useful, but WITHOUT
00011 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00012 //# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
00013 //# License for more details.
00014 //#
00015 //# You should have received a copy of the GNU Library General Public License
00016 //# along with this library; if not, write to the Free Software Foundation,
00017 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
00018 //#
00019 //# Correspondence concerning AIPS++ should be addressed as follows:
00020 //#        Internet email: aips2-request@nrao.edu.
00021 //#        Postal address: AIPS++ Project Office
00022 //#                        National Radio Astronomy Observatory
00023 //#                        520 Edgemont Road
00024 //#                        Charlottesville, VA 22903-2475 USA
00025 //#
00026 //#
00027 //# $Id: QualityCoordinate.h 20886 2010-04-29 14:06:56Z gervandiepen $
00028 
00029 
00030 #ifndef COORDINATES_QUALITYCOORDINATE_H
00031 #define COORDINATES_QUALITYCOORDINATE_H
00032 
00033 #include <casa/aips.h>
00034 #include <coordinates/Coordinates/Coordinate.h>
00035 #include <measures/Measures/Quality.h>
00036 #include <casa/Containers/Block.h>
00037 #include <casa/Arrays/Vector.h>
00038 
00039 namespace casa { //# NAMESPACE CASA - BEGIN
00040 
00041 
00042 
00043 // <summary>
00044 // Interconvert between pixel and Quality value.
00045 // </summary>
00046 
00047 // <use visibility=export>
00048 
00049 // <reviewed tests="tQualityCoordinate">
00050 // </reviewed>
00051 //
00052 // <prerequisite>
00053 //   <li> <linkto class=Coordinate>Coordinate</linkto>
00054 //   <li> <linkto class=Quality>Quality</linkto>
00055 // </prerequisite>
00056 //
00057 // <synopsis>
00058 // </synopsis>
00059 //
00060 // <note role=caution>
00061 // All pixel coordinates are zero relative.
00062 // </note>
00063 //
00064 // <example>
00065 // In this example we create a QualityCoordinate containing 'DATA'
00066 // and 'ERROR'
00067 // <srcblock>
00068 //   Vector<Int> newQuality(2);
00069 //   newQuality(0) = Quality::DATA;
00070 //   newQuality(1) = Quality::ERROR;
00071 //   qual = QualityCoordinate(newQuality);
00072 // </srcblock>
00073 // </example>
00074 //
00075 // <motivation>
00076 // </motivation>
00077 //
00078 
00079 class QualityCoordinate : public Coordinate
00080 {
00081 public:
00082 
00083     // The length of whichQuality is the length of the axis, and the values
00084     // define which quality are in which axis value. Often the vector will be of
00085     // length 2 and will contain Quality::DATA, and ERROR.
00086     explicit QualityCoordinate(const Vector<Int> &whichQuality);
00087 
00088     // Copy constructor (copy semantics)
00089     QualityCoordinate(const QualityCoordinate &other);
00090 
00091     // Assignment (copy semantics)
00092     QualityCoordinate &operator=(const QualityCoordinate &other);
00093 
00094     // Destructor.
00095     virtual ~QualityCoordinate();
00096 
00097     // Returns Coordinates::QUALITY.
00098     virtual Coordinate::Type type() const;
00099 
00100     // Always returns the String "Quality".
00101     virtual String showType() const;
00102 
00103     // Always returns 1.
00104     // <group>
00105     virtual uInt nPixelAxes() const;
00106     virtual uInt nWorldAxes() const;
00107     // </group>
00108 
00109     // Convert a pixel to a world coordinate or vice versa. Returns True
00110     // if the conversion succeeds, otherwise it returns False and method
00111     // <src>errorMessage</src> returns an error message.
00112     // The output vectors are appropriately resized before use.
00113     // <group>
00114     virtual Bool toWorld(Vector<Double> &world, 
00115                                 const Vector<Double> &pixel) const;
00116     virtual Bool toPixel(Vector<Double> &pixel, 
00117                                 const Vector<Double> &world) const;
00118     // </group>
00119 
00120     // Interconvert between pixel and world as a Quality type.
00121     // It returns False if no conversion could be done.
00122     // <group>
00123     Bool toPixel(Int &pixel, Quality::QualityTypes quality) const;
00124     Bool toWorld(Quality::QualityTypes &quality, Int pixel) const;
00125     // </group>
00126 
00127     // Interconvert between world stored as a Double and world stored as
00128     // a Quality type.  Since these functions are static, any valid
00129     // Quality type can be used.  The second function returns
00130     // Quality::Undefined if world is illegal.
00131     // <group>
00132     static Double toWorld (Quality::QualityTypes quality);
00133     static Quality::QualityTypes toWorld (Double world);
00134     // </group>
00135 
00136     // Make absolute coordinates relative and vice-versa. 
00137     // For the QualityCoordinate relative world coordinates are defined to be the
00138     // same as absolute world coordinates.  Relative pixels do have meaning
00139     // and are implemented (rel = abs - refPix)
00140     // <group>
00141     virtual void makePixelRelative (Vector<Double>& pixel) const;
00142     virtual void makePixelAbsolute (Vector<Double>& pixel) const;
00143     virtual void makeWorldRelative (Vector<Double>& world) const;
00144     virtual void makeWorldAbsolute (Vector<Double>& world) const;
00145     // </group>
00146  
00147 
00148     // Get the Quality values (Quality::QualityType) that we constructed
00149     // with into a vector
00150     Vector<Int> quality() const;
00151 
00152     // Set a new vector of Quality values (a vector of Quality::QualityType)
00153     void setQuality (const Vector<Int> &whichQuality);
00154    
00155     // Report the value of the requested attribute.
00156     // <group>
00157     virtual Vector<String> worldAxisNames() const;
00158     virtual Vector<Double> referencePixel() const;
00159     virtual Matrix<Double> linearTransform() const;
00160     virtual Vector<Double> increment() const;
00161     virtual Vector<Double> referenceValue() const;
00162     // </group>
00163 
00164     // Set the value of the requested attribute.  For the QualityCoordinate,
00165     // these have no effect (always return True) except for setWorldAxisNames.
00166     // <group>
00167     virtual Bool setWorldAxisNames(const Vector<String> &names);
00168     virtual Bool setReferencePixel(const Vector<Double> &refPix);
00169     virtual Bool setLinearTransform(const Matrix<Double> &xform);
00170     virtual Bool setIncrement(const Vector<Double> &inc) ;
00171     virtual Bool setReferenceValue(const Vector<Double> &refval) ;
00172     // </group>
00173 
00174     // The set function has no effect as the units must be empty for a QualityCoordinate
00175     // Always returns True
00176     // <group>
00177     virtual Bool setWorldAxisUnits(const Vector<String> &units);
00178     virtual Vector<String> worldAxisUnits() const;
00179     // </group>
00180 
00181     // Set the world min and max ranges, for use in function <src>toMix</src>,
00182     // for  a lattice of the given shape (for this coordinate).
00183     // The implementation here gives world coordinates at the start 
00184     // and end of the Quality axis.
00185     // The output vectors are resized.  Returns False if fails (and
00186     // then <src>setDefaultWorldMixRanges</src> generates the ranges)
00187     // with a reason in <src>errorMessage()</src>.
00188     // The <src>setDefaultWorldMixRanges</src> function
00189     // gives you [-1e99->1e99]. 
00190     // <group>
00191     virtual Bool setWorldMixRanges (const IPosition& shape);
00192     virtual void setDefaultWorldMixRanges ();
00193     //</group>
00194 
00195     // Format a QualityCoordinate world value with the common format
00196     // interface (refer to the base class <linkto class=Coordinate>Coordinate</linkto>
00197     // for basics.
00198     //
00199     // A QualityCoordinate is formatted differently from other Coordinate
00200     // types.  The world value is converted to the character representation
00201     // as defined by the enum <src>QualityTypes</src> in the class
00202     // <linkto class=Quality>Quality</linkto>.
00203     //
00204     // Thus, all other arguments to do with formatting and precision are ignored.
00205     virtual String format(String& units,
00206                           Coordinate::formatType format,
00207                           Double worldValue,
00208                           uInt worldAxis,
00209                           Bool isAbsolute=True,
00210                           Bool showAsAbsolute=True,
00211                           Int precision = -1, Bool usePrecForMixed=False) const;
00212 
00213     // Comparison function. Any private Double data members are compared    
00214     // with the specified fractional tolerance.  Don't compare on the specified     
00215     // axes in the Coordinate.  If the comparison returns False,  method
00216     // errorMessage returns a message about why.
00217     // <group>
00218     virtual Bool near(const Coordinate& other,  
00219                       Double tol=1e-6) const;
00220     virtual Bool near(const Coordinate& other,  
00221                       const Vector<Int>& excludeAxes,
00222                       Double tol=1e-6) const;
00223     // </group>
00224 
00225     // Save the QualityCoordinate into the supplied record using the supplied field name.
00226     // The field must not exist, otherwise <src>False</src> is returned.
00227     virtual Bool save(RecordInterface &container,
00228                     const String &fieldName) const;
00229 
00230     // Recover the QualityCoordinate from a record.
00231     // A null pointer means that the restoration did not succeed - probably 
00232     // because fieldName doesn't exist or doesn't contain a CoordinateSystem.
00233     static QualityCoordinate* restore(const RecordInterface &container,
00234                                      const String &fieldName);
00235 
00236     // Make a copy of the QualityCoordinate using new. The caller is responsible for calling
00237     // delete.
00238     virtual Coordinate *clone() const;
00239 
00240 
00241     // Comparison only made for specified axes in this and other Coordinate
00242     virtual Bool doNearPixel (const Coordinate& other,
00243                               const Vector<Bool>&  thisAxes,
00244                               const Vector<Bool>& otherAxes,
00245                               Double tol=1.0e-6) const; 
00246 
00247 private:
00248 
00249     Bool toWorld(Double& world,  const Double pixel) const;
00250     Bool toPixel(Double& pixel,  const Double world) const;
00251 //
00252     Block<Int> values_p;
00253 
00254     // Keep these for subimaging purposes.
00255     Double crval_p, crpix_p, matrix_p, cdelt_p;
00256     String name_p;
00257     String unit_p;
00258     Int nValues_p;
00259 
00260     // Undefined and inaccessible
00261     QualityCoordinate();
00262 };
00263 
00264 } //# NAMESPACE CASA - END
00265 
00266 
00267 #endif
00268