ImageMetaDataRW.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_IMAGEMETADATARW_H
00029 #define IMAGES_IMAGEMETADATARW_H
00030 
00031 #include <imageanalysis/ImageAnalysis/ImageMetaDataBase.h>
00032 
00033 #include <casa/aips.h>
00034 
00035 #include <memory>
00036 
00037 namespace casa {
00038 
00039 // <summary>
00040 // A class in which to store and allow read-write access to image metadata.
00041 // </summary>
00042 
00043 // <use visibility=export>
00044 
00045 // <reviewed reviewer="" date="" tests="" demos="">
00046 // </reviewed>
00047 
00048 // <prerequisite>
00049 //   <li> <linkto class=ImageInterface>ImageInterface</linkto>
00050 // </prerequisite>
00051 
00052 // <etymology>
00053 // The ImageMetaDataRW class name is derived from its role as holding image metadata
00054 // and providing read-write access.
00055 // </etymology>
00056 
00057 // <synopsis> 
00058 // The ImageMetaDataRW object is meant to allow access to image metadata (eg, shape,
00059 // coordinate system info such as spectral and polarization axes numbers, etc). It allows
00060 // write access to some values. This class contains the writable methods and extends
00061 // ImageMetaData which contains the read-only methods.
00062 // </synopsis>
00063 
00064 // <example>
00065 // Construct an object of this class by passing the associated image to the constructor.
00066 // <srcblock>
00067 // PagedImage<Float> myImage("myImage");
00068 // ImageMetaDataRW<Float> myImageMetaData(myImage);
00069 // </srcblock>
00070 // </example>
00071 
00072 // <motivation> 
00073 // This class is meant to provide an object-oriented interface for accessing
00074 // image metadata without polluting the ImageInterface and CoordinateSystem
00075 // classes with these methods.
00076 // </motivation>
00077 
00078 class ImageMetaDataRW : public ImageMetaDataBase {
00079 
00080 public:
00081 
00082     ImageMetaDataRW() = delete;
00083 
00084     ImageMetaDataRW(SPIIF image);
00085     ImageMetaDataRW(SPIIC image);
00086 
00087     // remove, if possible, the specified parameter. Returns True if removal
00088     // was successful.
00089     Bool remove(const String& key);
00090 
00091     // remove the specified mask. If the empty string is given, all masks will
00092     // be removed. Returns True if successful, False otherwise or if the specfied
00093     // mask does not exist.
00094     Bool removeMask(const String& maskName);
00095 
00096     Record toRecord(Bool verbose) const;
00097 
00098     // add a key-value pair
00099     Bool add(const String& key, const ValueHolder& value);
00100 
00101     // set (update) the value associated with the key.
00102     Bool set(const String& key, const ValueHolder& value);
00103 
00104     // set the coordinate system from a Record.
00105     void setCsys(const Record& coordinates);
00106 
00107 protected:
00108 
00109     SPCIIF _getFloatImage() const {return _floatImage;}
00110 
00111     SPCIIC _getComplexImage() const {return _complexImage;}
00112 
00113     const ImageInfo& _getInfo() const;
00114 
00115     const CoordinateSystem& _getCoords() const;
00116 
00117     Vector<String> _getAxisNames() const;
00118 
00119     Vector<String> _getAxisUnits() const;
00120 
00121     GaussianBeam _getBeam() const;
00122 
00123     String _getBrightnessUnit() const;
00124 
00125     String _getImType() const;
00126 
00127     vector<Quantity> _getIncrements() const;
00128 
00129     Vector<String> _getMasks() const;
00130 
00131     String _getObject() const;
00132 
00133     String _getEquinox() const;
00134 
00135     MEpoch _getObsDate() const;
00136 
00137     String _getObserver() const;
00138 
00139     String _getProjection() const;
00140 
00141     String _getRefFreqType() const;
00142 
00143     Vector<Double> _getRefPixel() const;
00144 
00145     Vector<Quantity> _getRefValue() const;
00146 
00147     Quantity _getRestFrequency() const;
00148 
00149     String _getTelescope() const;
00150 
00151     Record _getStatistics() const;
00152 
00153     Vector<String> _getStokes() const;
00154 
00155 private:
00156     SPIIF _floatImage;
00157     SPIIC _complexImage;
00158 
00159     // These are mutable because they are only to be set once and
00160     // then cached. If this contract is broken, and they are set elsewhere
00161     // defects will likely occur.
00162     mutable String _bunit, _imtype, _object, _equinox, _observer, _projection,
00163         _reffreqtype, _telescope;
00164     mutable MEpoch _obsdate;
00165     mutable Quantity _restFreq;
00166     mutable Vector<String> _masks, _stokes;
00167     mutable GaussianBeam _beam;
00168     mutable Vector<String> _axisNames, _axisUnits;
00169     mutable Vector<Double> _refPixel;
00170     mutable vector<Quantity> _refVal, _increment;
00171     mutable Record _header, _stats;
00172 
00173     std::unique_ptr<CoordinateSystem> _makeCoordinateSystem(
00174         const Record& coordinates, const IPosition& shape
00175     );
00176 
00177     void _setCoordinateValue(const String& key, const ValueHolder& value);
00178 
00179     String  _getString(const String& key, const ValueHolder& value) const;
00180 
00181     void _setUserDefined(const String& key, const ValueHolder& v);
00182 
00183     Bool _setUnit(const String& unit);
00184 
00185     Bool _setCsys(const CoordinateSystem& csys);
00186 
00187     Bool _setImageInfo(const ImageInfo& info);
00188 
00189     const TableRecord _miscInfo() const;
00190 
00191     void _setMiscInfo(const TableRecord& rec);
00192 
00193     Bool _hasRegion(const String& maskName) const;
00194 
00195     static Quantity _getQuantity(const ValueHolder& v);
00196 
00197     Bool _isWritable() const;
00198 
00199     template <class T, class U> void _modHistory(
00200         const String& func, const String& keyword,
00201         const T& oldVal, const U& newVal
00202     );
00203 
00204     template <class T> void _addHistory(
00205         const String& func, const String& keyword, const T& newVal
00206     );
00207 
00208     void _toHistory(const String& origin, const String& record);
00209 
00210     template <class T> static String _quotify(const T& val);
00211 };
00212 
00213 }
00214 
00215 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on 31 Aug 2016 for casa by  doxygen 1.6.1