AnnRegion.h

Go to the documentation of this file.
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         // this version is deprecated, use the version that returns
00069         // SHARED_PTR instead
00070         virtual CountedPtr<const WCRegion> getRegion() const;
00071 
00072         virtual SHARED_PTR<const WCRegion> getRegion2() const;
00073 
00074         // returns True unless overridden.
00075         virtual Bool isRegion() const;
00076 
00077         void setDifference(const Bool difference);
00078 
00079         Bool isDifference() const;
00080 
00081         // get the pixel range included in the spectral selection.
00082         // If there is no spectral axis, a zero length vector is returned. Otherwise,
00083         // a vector of two values is returned. The zeroth value will always be less
00084         // than or equal to the first.
00085         vector<Double> getSpectralPixelRange() const;
00086 
00087 
00088         Bool setFrequencyLimits(
00089                 const Quantity& beginFreq,
00090                 const Quantity& endFreq,
00091                 const String& freqRefFrame,
00092                 const String& dopplerString,
00093                 const Quantity& restfreq
00094         );
00095 
00096 protected:
00097 
00098         // only to be called by subclasses
00099 
00100         // beginFreq and endFreq can both be 0, in which case
00101         // all the spectral range is used if a spectral axis exists in
00102         // <src>csys</csys>. If one of <src>beginFreq</src> or <src>endFreq</src>
00103         // is given, the other must be given. Frequency units can either conform
00104         // to Hz, m/s, or pix. If <src>beginFreq</src> and <src>endFreq</src> are not
00105         // specifed or if they are specified in pixel units,
00106         // <src>freqRefFrame</src>, <src>dopplerString</src>, and
00107         // <src>restfreq</src> are ignored. If provided, <src>beginFreq</src>
00108         // and <src>endFreq</src> must conform to the same units.
00109         AnnRegion(
00110                 const Type shape,
00111                 const String& dirRefFrameString,
00112                 const CoordinateSystem& csys,
00113                 const IPosition& imShape,
00114                 const Quantity& beginFreq,
00115                 const Quantity& endFreq,
00116                 const String& freqRefFrame,
00117                 const String& dopplerString,
00118                 const Quantity& restfreq,
00119                 const Vector<Stokes::StokesTypes> stokes,
00120                 const Bool annotationOnly
00121         );
00122 
00123         // use if all coordinate values will be specified in
00124         // the same frames as the input coordinate system. frequencies
00125         // and the annotationOnly flag can be set after
00126         // construction. By default, all frequencies and all polarizations
00127         // are used, and the annotationOnly flag is False
00128         AnnRegion(
00129                 const Type shape,
00130                 const CoordinateSystem& csys,
00131                 const IPosition& imShape,
00132                 const Vector<Stokes::StokesTypes>& stokes
00133         );
00134 
00135         // copy constructor
00136         AnnRegion(const AnnRegion& other);
00137 
00138         // assignment operator
00139         AnnRegion& operator= (const AnnRegion& rhs);
00140 
00141         Bool operator== (const AnnRegion& other) const;
00142 
00143 
00144         // extend the direction plane region over spectral and/or polarization
00145         // coordinates
00146         void _extend();
00147 
00148         void _toRecord(const ImageRegion& region);
00149 
00150         // convert a length in pixels to an angle.
00151         Quantity _lengthToAngle(
00152                 const Quantity& quantity, const uInt pixelAxis
00153         ) const;
00154 
00155         virtual void _printPrefix(ostream& os) const;
00156 
00157         // subclasses must call this at construction to set their base region
00158         // defined in the direction plane
00159         void _setDirectionRegion(const ImageRegion& region);
00160 
00161 private:
00162 
00163         Bool _isAnnotationOnly;
00164         Bool _isDifference, _constructing;
00165         ImageRegion _imageRegion, _directionRegion;
00166         IPosition _imShape;
00167         vector<Double> _spectralPixelRange;
00168 
00169         static const String _class;
00170 
00171         WCBox _makeExtensionBox(
00172                 const Vector<Quantity>& freqRange,
00173                 const Vector<Stokes::StokesTypes>& stokesRange,
00174                 const IPosition& pixelAxes
00175         ) const;
00176 
00177         void _init();
00178 
00179 };
00180 
00181 // Just need a identifable expection class, compiler can generate implementation implicitly
00182 class ToLCRegionConversionError : public AipsError {
00183 public:
00184         ToLCRegionConversionError(String msg) : AipsError(msg) {}
00185 };
00186 
00187 }
00188 
00189 
00190 
00191 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on 31 Aug 2016 for casa by  doxygen 1.6.1