casa
$Rev:20696$
|
00001 //# Copyright (C) 1996,1997,1998,1999,2000,2001,2003 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 IMAGES_IMAGEBEAMSET_H 00027 #define IMAGES_IMAGEBEAMSET_H 00028 00029 #include <casa/aips.h> 00030 #include <components/ComponentModels/GaussianBeam.h> 00031 #include <measures/Measures/Stokes.h> 00032 #include <map> 00033 00034 namespace casa { 00035 00036 // <summary> 00037 // Represents a set of restoring beams associated with an image. 00038 // </summary> 00039 00040 // <use visibility=export> 00041 00042 // <reviewed reviewer="" date="yyyy/mm/dd" tests="" demos=""> 00043 // </reviewed> 00044 00045 // <prerequisite> 00046 // </prerequisite> 00047 00048 // <etymology> 00049 // A Set of Beams associated with an Image. 00050 // </etymology> 00051 00052 // <synopsis> 00053 // This class represents a set of restoring beams associated with 00054 // a deconvolved image. 00055 // </synopsis> 00056 // 00057 // <example> 00058 00059 // </example> 00060 00061 00062 // <motivation> 00063 // Restoring beams are used many places in image analysis tasks. 00064 // </motivation> 00065 00066 // <todo> 00067 // </todo> 00068 00069 class ImageBeamSet { 00070 public: 00071 00072 enum AxisType { 00073 SPECTRAL, 00074 POLARIZATION 00075 }; 00076 00077 // Construct an empty beam set. 00078 ImageBeamSet(); 00079 00080 // Construct a beam set from an array of beams with the 00081 // representing the specified image axes. The number of 00082 // dimensions in the <src>beams</src> Array must match 00083 // the number of elements in the <src>axes</src> Vector. 00084 ImageBeamSet( 00085 const Array<GaussianBeam>& beams, 00086 const Vector<AxisType>& axes 00087 ); 00088 00089 // construct an ImageBeamSet representing a single beam 00090 ImageBeamSet(const GaussianBeam& beam); 00091 00092 //create an ImageBeamSet of the specified shape with all 00093 // GaussianBeams initialized to null beams. 00094 ImageBeamSet(const IPosition& shape, const Vector<AxisType>& axes); 00095 00096 //create an ImageBeamSet of the specified shape with all 00097 // GaussianBeams initialized to <src>beam</src>. 00098 ImageBeamSet( 00099 const GaussianBeam& beam, const IPosition& shape, 00100 const Vector<AxisType>& axes 00101 ); 00102 00103 ImageBeamSet(const ImageBeamSet& other); 00104 00105 ~ImageBeamSet(); 00106 00107 ImageBeamSet& operator=(const ImageBeamSet& other); 00108 00109 const GaussianBeam &operator()(const IPosition &) const; 00110 00111 Array<GaussianBeam> operator[] (uInt i) const; 00112 00113 const Array<GaussianBeam>& operator() ( 00114 const IPosition &start, 00115 const IPosition &end 00116 ) const; 00117 00118 Bool operator== (const ImageBeamSet& other) const; 00119 00120 Bool operator!= (const ImageBeamSet& other) const; 00121 00122 // get the axis types associated with the beam array. 00123 const Vector<AxisType>& getAxes() const; 00124 00125 // get the single global beam. If there are multiple beams, 00126 // an exception is thrown. 00127 const GaussianBeam& getBeam() const; 00128 00129 // get the beam at the specified location 00130 const GaussianBeam& getBeam( 00131 const IPosition& position, 00132 const Vector<AxisType>& axes=Vector<AxisType>(0) 00133 ) const; 00134 00135 // set the beam at a given location. Optionally, the axis types can 00136 // be supplied so one can specify the position using a different axis 00137 // ordering than the current object has. If specified, <src>axes</src> 00138 // must have the same number of elements as the dimensionality of the 00139 // current beam set and all axes of the current beam set must be 00140 // elements. 00141 void setBeam( 00142 const GaussianBeam& beam, const IPosition& position 00143 ); 00144 00145 // set the beams from the specified beginning to specified ending positions. 00146 void setBeams( 00147 const IPosition& begin, const IPosition& end, 00148 const Array<GaussianBeam>& beams 00149 ); 00150 00151 // does this beam set contain only a single beam? 00152 Bool hasSingleBeam() const; 00153 00154 // does this beam set contain multiple beams? 00155 Bool hasMultiBeam() const; 00156 00157 static const String& className(); 00158 00159 // return the size of the beam array. 00160 size_t size() const; 00161 00162 // resize the beam array. If pos has a different dimensionality than 00163 // the current beam array, an exception is thrown. 00164 void resize(const IPosition& pos); 00165 00166 // get the beam array 00167 const Array<GaussianBeam>& getBeams() const; 00168 00169 // set the beam array. 00170 void setBeams(const Array<GaussianBeam>& beams); 00171 00172 // get the number of elements in the beam array 00173 size_t nelements() const; 00174 00175 // is the beam array empty? 00176 Bool empty() const; 00177 00178 // get the shape of the beam array 00179 IPosition shape() const; 00180 00181 // get the number of dimensions in the beam array 00182 size_t ndim() const; 00183 00184 // set all beams to the same value 00185 void set(const GaussianBeam& beam); 00186 00187 // get the beam in the set which has the smallest area 00188 GaussianBeam getMinAreaBeam() const; 00189 00190 // get the beam in the set which has the largest area 00191 GaussianBeam getMaxAreaBeam() const; 00192 00193 // get the position of the beam with the maximum area 00194 IPosition getMaxAreaBeamPosition() const; 00195 00196 // get the position of the beam with the minimum area 00197 IPosition getMinAreaBeamPosition() const; 00198 00199 // get maximal area beam and its position in the _beams array for 00200 // the given polarization. Use polarization=-1 if the image has no 00201 // polarization axis to do stats over all the beams. 00202 GaussianBeam getMaxAreaBeamForPol( 00203 IPosition& pos, const Int polarization 00204 ) const; 00205 00206 // get minimal area beam and its position in the _beams array for 00207 // the given polarization. Use polarization=-1 if the image has no 00208 // polarization axis to do stats over all the beams. 00209 GaussianBeam getMinAreaBeamForPol( 00210 IPosition& pos, const Int polarization 00211 ) const; 00212 00213 // get median area beam and its position in the _beams array for 00214 // the given polarization. Use polarization=-1 if the image has no 00215 // polarization axis to do stats over all the beams. 00216 GaussianBeam getMedianAreaBeamForPol( 00217 IPosition& pos, const Int polarization 00218 ) const; 00219 00220 // get the axis number for the specified type. Return -1 if there is no such axis 00221 Int getAxis(const AxisType type) const; 00222 00223 // Get a beam to which all other beams in the set can be convolved. 00224 // If all other beams can be convolved to the maximum area beam in the set, that beam will be returned. 00225 // If not, this is guaranteed to be the minimum area beam to which 00226 // all beams in the set can be convolved if all but one of the beams in the set can be convolved to the beam in the set with the 00227 // largest area. Otherwise, the returned beam may or may not be the smallest possible beam to which all the beams in the set 00228 // can be convolved. 00229 GaussianBeam getCommonBeam() const; 00230 00231 // convert to a record. If <src>exceptionIfNull</src>, an excption will be raised 00232 // if any beam in the set is the null beam. 00233 Record toRecord(Bool exceptionIfNull) const; 00234 00235 // if <src>exceptIfNull</src>, throw an exception if any beam in the record 00236 // is null 00237 static ImageBeamSet fromRecord(const Record& rec, Bool exceptIfNull); 00238 00239 private: 00240 00241 typedef std::map<AxisType, uInt> AxesMap; 00242 static const String _DEFAULT_AREA_UNIT; 00243 00244 Array<GaussianBeam> _beams; 00245 Vector<AxisType> _axes; 00246 Array<Double> _areas; 00247 String _areaUnit; 00248 GaussianBeam _minBeam, _maxBeam; 00249 IPosition _minBeamPos, _maxBeamPos; 00250 vector<IPosition> _maxStokesMap, _minStokesMap, 00251 _medianStokesMap; 00252 AxesMap _axesMap; 00253 00254 IPosition _truePosition( 00255 const IPosition& position, 00256 const Vector<AxisType>& axes 00257 ) const; 00258 00259 static void _checkForDups(const Vector<AxisType>& axes); 00260 00261 void _checkAxisTypeSize( 00262 const Vector<AxisType>& axes 00263 ) const; 00264 00265 void _makeStokesMaps( 00266 const Bool beamsAreIdentical, 00267 const Int affectedStokes=-1 00268 ); 00269 00270 uInt _nStokes() const; 00271 00272 uInt _nChannels() const; 00273 00274 static std::map<AxisType, uInt> _setAxesMap( 00275 const Vector<AxisType>& axisTypes 00276 ); 00277 00278 void _calculateAreas(); 00279 00280 GaussianBeam _getBeamForPol( 00281 IPosition& pos, const vector<IPosition>& map, 00282 const Int polarization 00283 ) const; 00284 00285 static void _transformEllipseByScaling( 00286 Double& transformedMajor, Double& transformedMinor, 00287 Double& transformedPa, Double major, Double minor, 00288 Double pa, Double xScaleFactor, Double yScaleFactor 00289 ); 00290 00291 }; 00292 00293 ostream &operator<<(ostream &os, const ImageBeamSet& beamSet); 00294 00295 } 00296 00297 #endif 00298