casa  5.7.0-16
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
AnnRegion.h
Go to the documentation of this file.
1 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
2 //# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
3 //# License for more details.
4 //#
5 //# You should have received a copy of the GNU Library General Public License
6 //# along with this library; if not, write to the Free Software Foundation,
7 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
8 //#
9 //# Correspondence concerning AIPS++ should be addressed as follows:
10 //# Internet email: aips2-request@nrao.edu.
11 //# Postal address: AIPS++ Project Office
12 //# National Radio Astronomy Observatory
13 //# 520 Edgemont Road
14 //# Charlottesville, VA 22903-2475 USA
15 //#
16 
17 #ifndef REGIONS_ANNREGION_H
18 #define REGIONS_ANNREGION_H
19 
22 #include <images/Regions/WCBox.h>
26 
27 namespace casa {
28 
29 // <summary>
30 // This class represents a annotation referring to a region specified in an ascii region file as proposed
31 // in CAS-2285
32 // </summary>
33 // <author>Dave Mehringer</author>
34 // <use visibility=export>
35 // <reviewed reviewer="" date="yyyy/mm/dd" tests="" demos="">
36 // </reviewed>
37 // <prerequisite>
38 
39 // </prerequisite>
40 
41 // <etymology>
42 // Holds the specification of an annotation containing a region as specified in ASCII format.
43 // </etymology>
44 
45 // <synopsis>
46 // This class is meant to be a container for all parameters necessary to specify a region per
47 // the format proposal attached to CAS-2285 (https://bugs.nrao.edu/browse/CAS-2285).
48 
49 // Conversions of frequency from one reference frame to another are done here. The position of
50 // the reference pixel in the supplied coordinate system is used when converting frequencies.
51 // </synopsis>
52 
53 class AnnRegion: public AnnotationBase {
54 
55 public:
56 
57  virtual ~AnnRegion();
58 
60 
61  // is this region an annotation only? ie just for graphical rendering?
63 
64  virtual casacore::TableRecord asRecord() const;
65 
66  virtual casacore::ImageRegion asImageRegion() const;
67 
68  // this version is deprecated, use the version that returns
69  // std::shared_ptr instead
71 
72  virtual std::shared_ptr<const casacore::WCRegion> getRegion2() const;
73 
74  // returns true unless overridden.
75  virtual casacore::Bool isRegion() const;
76 
77  void setDifference(const casacore::Bool difference);
78 
80 
81  // get the pixel range included in the spectral selection.
82  // If there is no spectral axis, a zero length vector is returned. Otherwise,
83  // a vector of two values is returned. The zeroth value will always be less
84  // than or equal to the first.
85  std::vector<casacore::Double> getSpectralPixelRange() const;
86 
87 
89  const casacore::Quantity& beginFreq,
90  const casacore::Quantity& endFreq,
91  const casacore::String& freqRefFrame,
92  const casacore::String& dopplerString,
93  const casacore::Quantity& restfreq
94  );
95 
96 protected:
97 
98  // only to be called by subclasses
99 
100  // beginFreq and endFreq can both be 0, in which case
101  // all the spectral range is used if a spectral axis exists in
102  // <src>csys</csys>. If one of <src>beginFreq</src> or <src>endFreq</src>
103  // is given, the other must be given. Frequency units can either conform
104  // to Hz, m/s, or pix. If <src>beginFreq</src> and <src>endFreq</src> are not
105  // specifed or if they are specified in pixel units,
106  // <src>freqRefFrame</src>, <src>dopplerString</src>, and
107  // <src>restfreq</src> are ignored. If provided, <src>beginFreq</src>
108  // and <src>endFreq</src> must conform to the same units.
109  // <src>requireImageRegion</src> indicates whether to rethrow the
110  // ToLCRegionConversionError exception when the region is outside the
111  // image, or to create the AnnRegion object even if the ImageRegion has no
112  // lattice region. The default (true) rethrows the exception to maintain
113  // the previous behavior.
114  // CAS-12631: added for CARTA, which can import regions outside an image.
115  AnnRegion(
116  const Type shape,
117  const casacore::String& dirRefFrameString,
118  const casacore::CoordinateSystem& csys,
119  const casacore::IPosition& imShape,
120  const casacore::Quantity& beginFreq,
121  const casacore::Quantity& endFreq,
122  const casacore::String& freqRefFrame,
123  const casacore::String& dopplerString,
124  const casacore::Quantity& restfreq,
126  const casacore::Bool annotationOnly,
127  casacore::Bool requireImageRegion=true
128  );
129 
130  // use if all coordinate values will be specified in
131  // the same frames as the input coordinate system. frequencies
132  // and the annotationOnly flag can be set after
133  // construction. By default, all frequencies and all polarizations
134  // are used, and the annotationOnly flag is false
135  AnnRegion(
136  const Type shape,
137  const casacore::CoordinateSystem& csys,
138  const casacore::IPosition& imShape,
140  casacore::Bool requireImageRegion=true
141  );
142 
143  // copy constructor
144  AnnRegion(const AnnRegion& other);
145 
146  // assignment operator
147  AnnRegion& operator= (const AnnRegion& rhs);
148 
149  casacore::Bool operator== (const AnnRegion& other) const;
150 
151  // check if image region has a region
153 
154  // extend the direction plane region over spectral and/or polarization
155  // coordinates
156  void _extend();
157 
158  void _toRecord(const casacore::ImageRegion& region);
159 
160  // convert a length in pixels to an angle.
162  const casacore::Quantity& quantity, const casacore::uInt pixelAxis
163  ) const;
164 
165  virtual void _printPrefix(std::ostream& os) const;
166 
167  // subclasses must call this at construction to set their base region
168  // defined in the direction plane
169  void _setDirectionRegion(const casacore::ImageRegion& region);
170 
173 
174 private:
175 
179  std::vector<casacore::Double> _spectralPixelRange;
180 
181  static const casacore::String _class;
182 
184  const casacore::Vector<casacore::Quantity>& freqRange,
186  const casacore::IPosition& pixelAxes
187  ) const;
188 
189  void _init();
190 
192 
193 };
194 
195 // Just need a identifable expection class, compiler can generate implementation implicitly
197 public:
199 };
200 
201 }
202 
203 
204 
205 #endif
A Vector of integers, for indexing into Array&lt;T&gt; objects.
Definition: IPosition.h:119
std::vector< casacore::Double > _spectralPixelRange
Definition: AnnRegion.h:179
A 1-D Specialization of the Array class.
Base class for annotations.
void setDifference(const casacore::Bool difference)
casacore::Bool _constructing
Definition: AnnRegion.h:177
AnnRegion(const Type shape, const casacore::String &dirRefFrameString, const casacore::CoordinateSystem &csys, const casacore::IPosition &imShape, const casacore::Quantity &beginFreq, const casacore::Quantity &endFreq, const casacore::String &freqRefFrame, const casacore::String &dopplerString, const casacore::Quantity &restfreq, const casacore::Vector< casacore::Stokes::StokesTypes > stokes, const casacore::Bool annotationOnly, casacore::Bool requireImageRegion=true)
only to be called by subclasses
This class represents a annotation referring to a region specified in an ascii region file as propose...
Definition: AnnRegion.h:53
void setAnnotationOnly(const casacore::Bool isAnnotationOnly)
casacore::WCBox _makeExtensionBox(const casacore::Vector< casacore::Quantity > &freqRange, const casacore::Vector< casacore::Stokes::StokesTypes > &stokesRange, const casacore::IPosition &pixelAxes) const
casacore::IPosition _imShape
Definition: AnnRegion.h:178
virtual void _printPrefix(std::ostream &os) const
casacore::Quantity _lengthToAngle(const casacore::Quantity &quantity, const casacore::uInt pixelAxis) const
convert a length in pixels to an angle.
virtual casacore::Bool isRegion() const
returns true unless overridden.
casacore::ImageRegion _imageRegion
Definition: AnnRegion.h:172
casacore::Bool _requireImageRegion
Definition: AnnRegion.h:171
std::vector< casacore::Double > getSpectralPixelRange() const
get the pixel range included in the spectral selection.
casacore::Bool _isDifference
Definition: AnnRegion.h:177
casacore::Bool setFrequencyLimits(const casacore::Quantity &beginFreq, const casacore::Quantity &endFreq, const casacore::String &freqRefFrame, const casacore::String &dopplerString, const casacore::Quantity &restfreq)
if freqRefFrame==&quot;&quot; -&gt; use the reference frame of the coordinate system if dopplerString==&quot;&quot; -&gt; use t...
virtual casacore::CountedPtr< const casacore::WCRegion > getRegion() const
this version is deprecated, use the version that returns std::shared_ptr instead
virtual std::shared_ptr< const casacore::WCRegion > getRegion2() const
Referenced counted pointer for constant data.
Definition: VisModelData.h:42
casacore::Bool _isAnnotationOnly
Definition: AnnRegion.h:176
casacore::Bool isAnnotationOnly() const
is this region an annotation only? ie just for graphical rendering?
virtual casacore::TableRecord asRecord() const
Just need a identifable expection class, compiler can generate implementation implicitly.
Definition: AnnRegion.h:196
virtual casacore::ImageRegion asImageRegion() const
AnnRegion & operator=(const AnnRegion &rhs)
assignment operator
casacore::Bool hasImageRegion() const
check if image region has a region
bool Bool
Define the standard types used by Casacore.
Definition: aipstype.h:42
ToLCRegionConversionError(casacore::String msg)
Definition: AnnRegion.h:198
casacore::Bool _hasDirectionRegion()
TableExprNode shape(const TableExprNode &array)
Function operating on any scalar or array resulting in a Double array containing the shape...
Definition: ExprNode.h:1944
A hierarchical collection of named fields of various types.
Definition: TableRecord.h:182
Class to hold a region of interest in an image.
Definition: ImageRegion.h:86
Base class for all Casacore library errors.
Definition: Error.h:134
casacore::Bool operator==(const AnnRegion &other) const
String: the storage and methods of handling collections of characters.
Definition: String.h:223
casacore::Bool isDifference() const
virtual ~AnnRegion()
Class to define a world coordinate box region of interest in an image.
Definition: WCBox.h:292
void _setDirectionRegion(const casacore::ImageRegion &region)
subclasses must call this at construction to set their base region defined in the direction plane ...
Interconvert pixel and world coordinates.
casacore::ImageRegion _directionRegion
Definition: AnnRegion.h:172
static const casacore::String _class
Definition: AnnRegion.h:181
unsigned int uInt
Definition: aipstype.h:51
void _toRecord(const casacore::ImageRegion &region)
void _extend()
extend the direction plane region over spectral and/or polarization coordinates
#define casacore
&lt;X11/Intrinsic.h&gt; #defines true, false, casacore::Bool, and String.
Definition: X11Intrinsic.h:42