casa
$Rev:20696$
|
00001 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 00002 //# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public 00003 //# License for more details. 00004 //# 00005 //# You should have received a copy of the GNU Library General Public License 00006 //# along with this library; if not, write to the Free Software Foundation, 00007 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA. 00008 //# 00009 //# Correspondence concerning AIPS++ should be addressed as follows: 00010 //# Internet email: aips2-request@nrao.edu. 00011 //# Postal address: AIPS++ Project Office 00012 //# National Radio Astronomy Observatory 00013 //# 520 Edgemont Road 00014 //# Charlottesville, VA 22903-2475 USA 00015 //# 00016 00017 #ifndef REGIONS_ANNREGION_H 00018 #define REGIONS_ANNREGION_H 00019 00020 #include <coordinates/Coordinates/CoordinateSystem.h> 00021 #include <imageanalysis/Annotations/AnnotationBase.h> 00022 #include <images/Regions/WCBox.h> 00023 #include <images/Regions/ImageRegion.h> 00024 #include <measures/Measures/MDirection.h> 00025 #include <measures/Measures/MFrequency.h> 00026 00027 namespace casa { 00028 00029 // <summary> 00030 // This class represents a annotation referring to a region specified in an ascii region file as proposed 00031 // in CAS-2285 00032 // </summary> 00033 // <author>Dave Mehringer</author> 00034 // <use visibility=export> 00035 // <reviewed reviewer="" date="yyyy/mm/dd" tests="" demos=""> 00036 // </reviewed> 00037 // <prerequisite> 00038 00039 // </prerequisite> 00040 00041 // <etymology> 00042 // Holds the specification of an annotation containing a region as specified in ASCII format. 00043 // </etymology> 00044 00045 // <synopsis> 00046 // This class is meant to be a container for all parameters necessary to specify a region per 00047 // the format proposal attached to CAS-2285 (https://bugs.nrao.edu/browse/CAS-2285). 00048 00049 // Conversions of frequency from one reference frame to another are done here. The position of 00050 // the reference pixel in the supplied coordinate system is used when converting frequencies. 00051 // </synopsis> 00052 00053 class AnnRegion: public AnnotationBase { 00054 00055 public: 00056 00057 virtual ~AnnRegion(); 00058 00059 void setAnnotationOnly(const Bool isAnnotationOnly); 00060 00061 // is this region an annotation only? ie just for graphical rendering? 00062 Bool isAnnotationOnly() const; 00063 00064 virtual TableRecord asRecord() const; 00065 00066 virtual ImageRegion asImageRegion() const; 00067 00068 virtual WCRegion* getRegion() const; 00069 00070 // returns True unless overridden. 00071 virtual Bool isRegion() const; 00072 00073 void setDifference(const Bool difference); 00074 00075 Bool isDifference() const; 00076 00077 // get the pixel range included in the spectral selection. 00078 // If there is no spectral axis, a zero length vector is returned. Otherwise, 00079 // a vector of two values is returned. The zeroth value will always be less 00080 // than or equal to the first. 00081 vector<Double> getSpectralPixelRange() const; 00082 00083 00084 00085 protected: 00086 00087 // only to be called by subclasses 00088 00089 // beginFreq and endFreq can both be 0, in which case 00090 // all the spectral range is used if a spectral axis exists in 00091 // <src>csys</csys>. If one of <src>beginFreq</src> or <src>endFreq</src> 00092 // is given, the other must be given. Frequency units can either conform 00093 // to Hz, m/s, or pix. If <src>beginFreq</src> and <src>endFreq</src> are not 00094 // specifed or if they are specified in pixel units, 00095 // <src>freqRefFrame</src>, <src>dopplerString</src>, and 00096 // <src>restfreq</src> are ignored. If provided, <src>beginFreq</src> 00097 // and <src>endFreq</src> must conform to the same units. 00098 AnnRegion( 00099 const Type shape, 00100 const String& dirRefFrameString, 00101 const CoordinateSystem& csys, 00102 const IPosition& imShape, 00103 const Quantity& beginFreq, 00104 const Quantity& endFreq, 00105 const String& freqRefFrame, 00106 const String& dopplerString, 00107 const Quantity& restfreq, 00108 const Vector<Stokes::StokesTypes> stokes, 00109 const Bool annotationOnly 00110 ); 00111 00112 // use if all coordinate values will be specified in 00113 // the same frames as the input coordinate system. frequencies 00114 // and the annotationOnly flag can be set after 00115 // construction. By default, all frequencies and all polarizations 00116 // are used, and the annotationOnly flag is False 00117 AnnRegion( 00118 const Type shape, 00119 const CoordinateSystem& csys, 00120 const IPosition& imShape, 00121 const Vector<Stokes::StokesTypes>& stokes 00122 ); 00123 00124 // implicitly defined copy constructor is fine 00125 // AnnRegion(AnnRegion& other); 00126 00127 // copy constructor 00128 AnnRegion(const AnnRegion& other); 00129 00130 // assignment operator 00131 AnnRegion& operator= (const AnnRegion& rhs); 00132 00133 // extend the direction plane region over spectral and/or polarization 00134 // coordinates 00135 void _extend(); 00136 00137 void _toRecord(const ImageRegion& region); 00138 00139 // convert a length in pixels to an angle. 00140 Quantity _lengthToAngle( 00141 const Quantity& quantity, const uInt pixelAxis 00142 ) const; 00143 00144 virtual void _printPrefix(ostream& os) const; 00145 00146 // subclasses must call this at construction to set their base region 00147 // defined in the direction plane 00148 void _setDirectionRegion(const ImageRegion& region); 00149 00150 Bool _setFrequencyLimits( 00151 const Quantity& beginFreq, 00152 const Quantity& endFreq, 00153 const String& freqRefFrame, 00154 const String& dopplerString, 00155 const Quantity& restfreq 00156 ); 00157 00158 00159 private: 00160 00161 Bool _isAnnotationOnly; 00162 Bool _isDifference, _constructing; 00163 ImageRegion _imageRegion, _directionRegion; 00164 IPosition _imShape; 00165 vector<Double> _spectralPixelRange; 00166 00167 static const String _class; 00168 00169 00170 WCBox _makeExtensionBox( 00171 const Vector<Quantity>& freqRange, 00172 const Vector<Stokes::StokesTypes>& stokesRange, 00173 const IPosition& pixelAxes 00174 ) const; 00175 00176 void _init(); 00177 00178 }; 00179 00180 // Just need a identifable expection class, compiler can generate implementation implicitly 00181 class ToLCRegionConversionError : public AipsError { 00182 public: 00183 ToLCRegionConversionError(String msg) : AipsError(msg) {} 00184 }; 00185 00186 } 00187 00188 00189 00190 #endif