casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
ImageMetaData.h
Go to the documentation of this file.
00001 //# ImageMetaData.h: Meta information for Images
00002 //# Copyright (C) 2009
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 //# $Id$
00027 
00028 #ifndef IMAGES_IMAGEMETADATA_H
00029 #define IMAGES_IMAGEMETADATA_H
00030 
00031 #include <images/Images/ImageInterface.h>
00032 #include <casa/aips.h>
00033 
00034 namespace casa {
00035 
00036 // <summary>
00037 // A class in which to store and allow read-only access to image metadata.
00038 // </summary>
00039 
00040 // <use visibility=export>
00041 
00042 // <reviewed reviewer="" date="" tests="" demos="">
00043 // </reviewed>
00044 
00045 // <prerequisite>
00046 //   <li> <linkto class=ImageInterface>ImageInterface</linkto>
00047 // </prerequisite>
00048 
00049 // <etymology>
00050 // The ImageMetaData class name is derived from its role as holding image metadata.
00051 // </etymology>
00052 
00053 // <synopsis> 
00054 // The ImageMetaData object is meant to allow access to image metadata (eg, shape,
00055 // coordinate system info such as spectral and polarization axes numbers, etc).
00056 // </synopsis>
00057 
00058 // <example>
00059 // Construct an object of this class by passing the associated image to the constructor.
00060 // <srcblock>
00061 // PagedImage<Float> myImage("myImage");
00062 // ImageMetaData<Float> myImageMetaData(myImage);
00063 // </srcblock>
00064 // </example>
00065 
00066 // <motivation> 
00067 // This class is meant to provide an object-oriented interface for accessing
00068 // image metadata without polluting the ImageInterface and CoordinateSystem
00069 // classes with these methods.
00070 // </motivation>
00071 // <todo>
00072 // Merge ImageInfo class into this class.
00073 // </todo>
00074 
00075 template <class T> class ImageMetaData {
00076 
00077 public:
00078 
00079         ImageMetaData(const ImageInterface<Float> *const &image);
00080 
00081         uInt nChannels() const;
00082 
00083         // Is the specified channel number valid for this image?
00084         Bool isChannelNumberValid(const uInt chan) const;
00085 
00086         // Get the pixel number on the polarization axis of the specified stokes parameter.
00087         // If the specified stokes parameter does not exist in the image, the value returned
00088         // is not gauranteed to be anything other than outside the range of 0 to nStokes-1
00089         // inclusive. Return -1 if the specified stokes parameter is not present or
00090         // if this image does not have a polarization axis.
00091  
00092         Int stokesPixelNumber(const String& stokesString) const;
00093 
00094         // get the stokes parameter at the specified pixel value on the polarization axis.
00095         // returns "" if the specified pixel is out of range or if no polarization axis.
00096 
00097         String stokesAtPixel(const uInt pixel) const;
00098 
00099         // Get the number of stokes parameters in this image.
00100         uInt nStokes() const;
00101 
00102         // is the specified stokes parameter present in the image?
00103         Bool isStokesValid(const String& stokesString) const;
00104 
00105         // Get the shape of the direction axes. Returns a two element
00106         // Vector if there is a direction coordinate, if not returns a zero element
00107         // vector.
00108 
00109         Vector<Int> directionShape() const;
00110 
00111         // if the specified stokes parameter is valid. A message suitable for
00112         // error notification is returned in the form of an in-out parameter
00113         //if one or both of these is invalid.
00114         Bool areChannelAndStokesValid(
00115                 String& message, const uInt chan, const String& stokesString
00116     ) const;
00117 
00118         // convert the header info to a Record and list to logger if verbose=True
00119         Record toRecord(Bool verbose);
00120 
00121 private:
00122         const static String _BEAMMAJOR, _BEAMMINOR, _BEAMPA,
00123                 _BUNIT, _CTYPE, _DATAMAX, _DATAMIN, _EQUINOX, _IMTYPE,
00124                 _MASKS, _MAXPIXPOS, _MAXPOS, _MINPIXPOS, _MINPOS,
00125                 _OBJECT, _OBSDATE, _OBSERVER, _PROJECTION,
00126                 _RESTFREQ, _REFFREQTYPE, _SHAPE, _TELESCOPE;
00127 
00128         // I really would like this to be a shared pointer, but that
00129         // currently causes some major issues for classes that depend on
00130         // this. If I can move ImageAnalysis::setRestoringBeam() into a class
00131         // of its own that will mitigate some difficulties
00132         const ImageInterface<Float> * const _image;
00133         std::auto_ptr<LogIO> _log;
00134         Record _header;
00135 
00136         ImageMetaData() : _image(0), _log(0) {}
00137 
00138         void _toLog() const;
00139 
00140         // precision < 0 => use default precision when printing numbers
00141         void _fieldToLog(const String& field, Int precision=-1) const;
00142 
00143         String _doStandardFormat(Double value, const String& unit) const;
00144 };
00145 
00146 
00147 
00148 } //# NAMESPACE CASA - END
00149 
00150 #ifndef AIPS_NO_TEMPLATE_SRC
00151 #include <imageanalysis/ImageAnalysis/ImageMetaData.tcc>
00152 #endif //# AIPS_NO_TEMPLATE_SRC
00153 
00154 #endif