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$
00028 
00029 
00030 #ifndef COORDINATES_QUALITYCOORDINATE_H
00031 #define COORDINATES_QUALITYCOORDINATE_H
00032 
00033 #include <casacore/casa/aips.h>
00034 #include <casacore/coordinates/Coordinates/Coordinate.h>
00035 #include <casacore/measures/Measures/Quality.h>
00036 #include <casacore/casa/Containers/Block.h>
00037 #include <casacore/casa/Arrays/Vector.h>
00038 
00039 namespace casacore { //# NAMESPACE CASACORE - 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     // The Bool parameter in toWorld() is ignored as this coordinate does not
00114     // support a conversion layer frame.
00115     // <group>
00116     virtual Bool toWorld(Vector<Double> &world, 
00117                                 const Vector<Double> &pixel, Bool=True) const;
00118     virtual Bool toPixel(Vector<Double> &pixel, 
00119                                 const Vector<Double> &world) const;
00120     // </group>
00121 
00122     // Interconvert between pixel and world as a Quality type.
00123     // It returns False if no conversion could be done.
00124     // <group>
00125     Bool toPixel(Int &pixel, Quality::QualityTypes quality) const;
00126     Bool toWorld(Quality::QualityTypes &quality, Int pixel) const;
00127     // </group>
00128 
00129     // Interconvert between world stored as a Double and world stored as
00130     // a Quality type.  Since these functions are static, any valid
00131     // Quality type can be used.  The second function returns
00132     // Quality::Undefined if world is illegal.
00133     // <group>
00134     static Double toWorld (Quality::QualityTypes quality);
00135     static Quality::QualityTypes toWorld (Double world);
00136     // </group>
00137 
00138     // Make absolute coordinates relative and vice-versa. 
00139     // For the QualityCoordinate relative world coordinates are defined to be the
00140     // same as absolute world coordinates.  Relative pixels do have meaning
00141     // and are implemented (rel = abs - refPix)
00142     // <group>
00143     virtual void makePixelRelative (Vector<Double>& pixel) const;
00144     virtual void makePixelAbsolute (Vector<Double>& pixel) const;
00145     virtual void makeWorldRelative (Vector<Double>& world) const;
00146     virtual void makeWorldAbsolute (Vector<Double>& world) const;
00147     // </group>
00148  
00149 
00150     // Get the Quality values (Quality::QualityType) that we constructed
00151     // with into a vector
00152     Vector<Int> quality() const;
00153 
00154     // Set a new vector of Quality values (a vector of Quality::QualityType)
00155     void setQuality (const Vector<Int> &whichQuality);
00156    
00157     // Report the value of the requested attribute.
00158     // <group>
00159     virtual Vector<String> worldAxisNames() const;
00160     virtual Vector<Double> referencePixel() const;
00161     virtual Matrix<Double> linearTransform() const;
00162     virtual Vector<Double> increment() const;
00163     virtual Vector<Double> referenceValue() const;
00164     // </group>
00165 
00166     // Set the value of the requested attribute.  For the QualityCoordinate,
00167     // these have no effect (always return True) except for setWorldAxisNames.
00168     // <group>
00169     virtual Bool setWorldAxisNames(const Vector<String> &names);
00170     virtual Bool setReferencePixel(const Vector<Double> &refPix);
00171     virtual Bool setLinearTransform(const Matrix<Double> &xform);
00172     virtual Bool setIncrement(const Vector<Double> &inc) ;
00173     virtual Bool setReferenceValue(const Vector<Double> &refval) ;
00174     // </group>
00175 
00176     // The set function has no effect as the units must be empty for a QualityCoordinate
00177     // Always returns True
00178     // <group>
00179     virtual Bool setWorldAxisUnits(const Vector<String> &units);
00180     virtual Vector<String> worldAxisUnits() const;
00181     // </group>
00182 
00183     // Set the world min and max ranges, for use in function <src>toMix</src>,
00184     // for  a lattice of the given shape (for this coordinate).
00185     // The implementation here gives world coordinates at the start 
00186     // and end of the Quality axis.
00187     // The output vectors are resized.  Returns False if fails (and
00188     // then <src>setDefaultWorldMixRanges</src> generates the ranges)
00189     // with a reason in <src>errorMessage()</src>.
00190     // The <src>setDefaultWorldMixRanges</src> function
00191     // gives you [-1e99->1e99]. 
00192     // <group>
00193     virtual Bool setWorldMixRanges (const IPosition& shape);
00194     virtual void setDefaultWorldMixRanges ();
00195     //</group>
00196 
00197     // Format a QualityCoordinate world value with the common format
00198     // interface (refer to the base class <linkto class=Coordinate>Coordinate</linkto>
00199     // for basics.
00200     //
00201     // A QualityCoordinate is formatted differently from other Coordinate
00202     // types.  The world value is converted to the character representation
00203     // as defined by the enum <src>QualityTypes</src> in the class
00204     // <linkto class=Quality>Quality</linkto>.
00205     //
00206     // Thus, all other arguments to do with formatting and precision are ignored.
00207     virtual String format(String& units,
00208                           Coordinate::formatType format,
00209                           Double worldValue,
00210                           uInt worldAxis,
00211                           Bool isAbsolute=True,
00212                           Bool showAsAbsolute=True,
00213                           Int precision = -1, Bool usePrecForMixed=False) const;
00214 
00215     // Comparison function. Any private Double data members are compared    
00216     // with the specified fractional tolerance.  Don't compare on the specified     
00217     // axes in the Coordinate.  If the comparison returns False,  method
00218     // errorMessage returns a message about why.
00219     // <group>
00220     virtual Bool near(const Coordinate& other,  
00221                       Double tol=1e-6) const;
00222     virtual Bool near(const Coordinate& other,  
00223                       const Vector<Int>& excludeAxes,
00224                       Double tol=1e-6) const;
00225     // </group>
00226 
00227     // Save the QualityCoordinate into the supplied record using the supplied field name.
00228     // The field must not exist, otherwise <src>False</src> is returned.
00229     virtual Bool save(RecordInterface &container,
00230                     const String &fieldName) const;
00231 
00232     // Recover the QualityCoordinate from a record.
00233     // A null pointer means that the restoration did not succeed - probably 
00234     // because fieldName doesn't exist or doesn't contain a CoordinateSystem.
00235     static QualityCoordinate* restore(const RecordInterface &container,
00236                                      const String &fieldName);
00237 
00238     // Make a copy of the QualityCoordinate using new. The caller is responsible for calling
00239     // delete.
00240     virtual Coordinate *clone() const;
00241 
00242 
00243     // Comparison only made for specified axes in this and other Coordinate
00244     virtual Bool doNearPixel (const Coordinate& other,
00245                               const Vector<Bool>&  thisAxes,
00246                               const Vector<Bool>& otherAxes,
00247                               Double tol=1.0e-6) const; 
00248 
00249 private:
00250 
00251     Bool toWorld(Double& world,  const Double pixel) const;
00252     Bool toPixel(Double& pixel,  const Double world) const;
00253 //
00254     Block<Int> values_p;
00255 
00256     // Keep these for subimaging purposes.
00257     Double crval_p, crpix_p, matrix_p, cdelt_p;
00258     String name_p;
00259     String unit_p;
00260     Int nValues_p;
00261 
00262     // Undefined and inaccessible
00263     QualityCoordinate();
00264 };
00265 
00266 } //# NAMESPACE CASACORE - END
00267 
00268 
00269 #endif
00270 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on 31 Aug 2016 for casa by  doxygen 1.6.1