casacore
Loading...
Searching...
No Matches
WCRegion.h
Go to the documentation of this file.
1//# WCRegion.h: Class to define a region of interest in an image
2//# Copyright (C) 1998,2000,2001
3//# Associated Universities, Inc. Washington DC, USA.
4//#
5//# This library is free software; you can redistribute it and/or modify it
6//# under the terms of the GNU Library General Public License as published by
7//# the Free Software Foundation; either version 2 of the License, or (at your
8//# option) any later version.
9//#
10//# This library is distributed in the hope that it will be useful, but WITHOUT
11//# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12//# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
13//# License for more details.
14//#
15//# You should have received a copy of the GNU Library General Public License
16//# along with this library; if not, write to the Free Software Foundation,
17//# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
18//#
19//# Correspondence concerning AIPS++ should be addressed as follows:
20//# Internet email: casa-feedback@nrao.edu.
21//# Postal address: AIPS++ Project Office
22//# National Radio Astronomy Observatory
23//# 520 Edgemont Road
24//# Charlottesville, VA 22903-2475 USA
25
26#ifndef IMAGES_WCREGION_H
27#define IMAGES_WCREGION_H
28
29//# Includes
30#include <casacore/casa/aips.h>
31#include <casacore/casa/Containers/Record.h>
32#include <casacore/coordinates/Coordinates/CoordinateSystem.h>
33#include <casacore/tables/Tables/TableRecord.h>
34
35namespace casacore { //# NAMESPACE CASACORE - BEGIN
36
37//# Forward Declarations
38class LCRegion;
39class RecordInterface;
40class IPosition;
41class String;
42
43
44// <summary>
45// Base class to define world coordinate regions of interest in an image.
46// </summary>
47
48// <use visibility=export>
49
50// <reviewed reviewer="" date="" tests="">
51// </reviewed>
52//
53// <prerequisite>
54// <li> <linkto class=LCRegion>LCRegion</linkto>
55// </prerequisite>
56//
57// <synopsis>
58// WCRegion is the base class for world coordinate regions.
59// The axes in a WCRegion have names (e.g. RA, DEC, FREQ) and
60// carry sometimes an associated reference frame with it.
61// An WCRegion object is converted to the appropriate
62// <linkto class=LCRegion>LCRegion</linkto> object when they
63// are used to take a subset from an image.
64// LCRegion's are pixel based and are
65// used to access the correct pixels in the image.
66// The conversion has the following rules:
67// <ol>
68// <li> All axes of the region must be axes in the image.
69// <li> An image axis does not have to be an axis in the region.
70// Thus the image can have a higher dimensionality than the region.
71// If that is the case, the region is auto-extended to the image's
72// dimensionality by using the full range for those axes.
73// <li> The order of the axes in region and image do not have to
74// be the same. They get reordered as needed.
75// </ol>
76// </synopsis>
77//
78// <example>
79// <srcblock>
80// </srcblock>
81// </example>
82//
83// <motivation>
84// User should be able to specify their regions in world coordinates
85// as well as lattice coordinates.
86// </motivation>
87//
88//# <todo asof="1997/11/11">
89//# <li>
90//# </todo>
91
92
94{
95public:
97
98 // Copy constructor (copy semantics).
99 WCRegion (const WCRegion& other);
100
101 // Destructor
102 virtual ~WCRegion();
103
104 // Comparison
105 // <group>
106 virtual Bool operator==(const WCRegion& other) const;
107 Bool operator!=(const WCRegion& other) const;
108 // </group>
109
110 // Clone a WCRegion object.
111 virtual WCRegion* cloneRegion() const = 0;
112
113 // Return region type.
114 // Just returns the class name of the derived class.
115 virtual String type() const = 0;
116
117 // Get the dimensionality (i.e. the number of axes).
118 // Note that usually all axes have a description, but in some cases
119 // (e.g. WCLELMask) that may not be the case.
120 // The default implementation returns the number of axes in the
121 // axes description.
122 virtual uInt ndim() const;
123
124 // Get the description of all axes.
125 const Record& getAxesDesc() const;
126
127 // Get the description of the given axis.
128 // It is a record containing some fields describing the axis.
129 const Record& getAxisDesc (uInt axis) const;
130
131 // Return the axis number of the description of an axis in the full
132 // axes description.
133 // -1 is returned if not found.
134 Int axisNr (const Record& desc, const Record& axesDesc) const;
135
136 // Are both axis descriptions equal?
137 Bool isAxisDescEqual (const Record& desc1, const Record& desc2) const;
138
139 // Can the region extend itself?
140 // By default it cannot.
141 virtual Bool canExtend() const;
142
143 // Get or set the comment.
144 // <group>
145 const String& comment() const;
146 void setComment (const String& comment);
147 // </group>
148
149 // Convert to an LCRegion using the given new coordinate system and shape.
150 // An exception is thrown if the region's dimensionality is more
151 // than the length of the shape vector or if an axis in the region
152 // is unknown in the new coordinate system..
153 // When less, the default implementation extends the region over the
154 // remaining axes.
155 // <br>If the region does not need to have coordinates (like WCLELMask)
156 // the function has to be overridden.
157 virtual LCRegion* toLCRegion (const CoordinateSystem& cSys,
158 const IPosition& shape) const;
159
160 // Convert to an LCRegion using the given coordinate system and shape.
161 // This function is meant for internal use by WCCompound objects.
162 // <br>pixelAxesMap(i) is the axis in cSys and shape for region axis i.
163 // <br>outOrder(i) is the axis in the output LCRegion for region axis i.
164 // <br>The length of pixelAxesMap and outOrder is the dimensionality of
165 // the output LCRegion. It can be more than the dimensionality of this
166 // WCRegion object. In that case the region gets extended along the
167 // latter axes. If the region cannot extend itself, this function
168 // will create an LCExtension object to extend the region.
169 // <br>Note that initially pixelAxisMap and outOrder are the same,
170 // but when called for regions in compound regions they may start
171 // to differ.
173 const IPosition& shape,
174 const IPosition& pixelAxesMap,
175 const IPosition& outOrder) const;
176
177 // Convert the (derived) object to a record.
178 // The record can be used to make the object persistent.
179 // The <src>tableName</src> argument can be used by derived
180 // classes (e.g. LCPagedMask) to put very large objects.
181 virtual TableRecord toRecord(const String& tableName) const = 0;
182
183 // Convert correct object from a record.
184 static WCRegion* fromRecord (const TableRecord& rec,
185 const String& tableName);
186
187 // Define the type and class name in the record.
189 const String& className) const;
190
191protected:
192 // Assignment (copy semantics) makes only sense for a derived class.
194
195 // Add an axis with its description.
196 // An exception is thrown if the axis already exists in this region.
197 void addAxisDesc (const Record& axisDesc);
198
199 // Make a description of a pixel axis in the coordinate system.
200 Record makeAxisDesc (const CoordinateSystem& cSys, uInt pixelAxis) const;
201
202 // Make a description of all pixel axes in the coordinate system
203 // (in pixel axes order).
205
206 // Convert to an LCRegion using the given coordinate system and shape.
207 // <br>pixelAxesMap(i) is the axis in cSys and shape for region axis i.
208 // <br>outOrder(i) is the axis in the output LCRegion for region axis i.
209 // <br>They always have the same length.
210 // If the region can extend itself, the length of pixelAxesMap and
211 // outOrder can be more than the dimensionality of the region.
212 // The latter axes in them are the extension axes.
214 const IPosition& shape,
215 const IPosition& pixelAxesMap,
216 const IPosition& extendAxes) const = 0;
217
218// Convert relative to absolute world as needed
220 const Vector<Int>& absRel,
221 const CoordinateSystem& cSys,
222 const IPosition& shape) const;
223
224 static void unitInit();
225
227 const IPosition& pixelAxes,
228 const CoordinateSystem& cSys,
229 const Vector<String>& quantityUnits
230 ) const;
231
232 static void convertPixel(
233 Double& pixel,
234 const Double& value,
235 const String& unit,
236 const Int absRel,
237 const Double refPix,
238 const Int shape
239 );
240private:
243};
244
245
246inline Bool WCRegion::operator!= (const WCRegion& other) const
247{
248 return (!operator==(other));
249}
250inline const String& WCRegion::comment() const
251{
252 return itsComment;
253}
254inline void WCRegion::setComment (const String& comment)
255{
257}
258inline const Record& WCRegion::getAxesDesc() const
259{
260 return itsAxesDesc;
261}
262
263
264
265} //# NAMESPACE CASACORE - END
266
267#endif
String: the storage and methods of handling collections of characters.
Definition String.h:223
Bool isAxisDescEqual(const Record &desc1, const Record &desc2) const
Are both axis descriptions equal?
const String & comment() const
Get or set the comment.
Definition WCRegion.h:250
virtual TableRecord toRecord(const String &tableName) const =0
Convert the (derived) object to a record.
WCRegion(const WCRegion &other)
Copy constructor (copy semantics).
Int axisNr(const Record &desc, const Record &axesDesc) const
Return the axis number of the description of an axis in the full axes description.
static void unitInit()
static void convertPixel(Double &pixel, const Double &value, const String &unit, const Int absRel, const Double refPix, const Int shape)
void setComment(const String &comment)
Definition WCRegion.h:254
Record makeAxesDesc(const CoordinateSystem &cSys) const
Make a description of all pixel axes in the coordinate system (in pixel axes order).
virtual Bool operator==(const WCRegion &other) const
Comparison.
virtual String type() const =0
Return region type.
const Record & getAxesDesc() const
Get the description of all axes.
Definition WCRegion.h:258
void defineRecordFields(RecordInterface &record, const String &className) const
Define the type and class name in the record.
virtual ~WCRegion()
Destructor.
void addAxisDesc(const Record &axisDesc)
Add an axis with its description.
Record makeAxisDesc(const CoordinateSystem &cSys, uInt pixelAxis) const
Make a description of a pixel axis in the coordinate system.
virtual WCRegion * cloneRegion() const =0
Clone a WCRegion object.
virtual LCRegion * doToLCRegion(const CoordinateSystem &cSys, const IPosition &shape, const IPosition &pixelAxesMap, const IPosition &extendAxes) const =0
Convert to an LCRegion using the given coordinate system and shape.
Bool operator!=(const WCRegion &other) const
Definition WCRegion.h:246
const Record & getAxisDesc(uInt axis) const
Get the description of the given axis.
LCRegion * toLCRegionAxes(const CoordinateSystem &cSys, const IPosition &shape, const IPosition &pixelAxesMap, const IPosition &outOrder) const
Convert to an LCRegion using the given coordinate system and shape.
static WCRegion * fromRecord(const TableRecord &rec, const String &tableName)
Convert correct object from a record.
virtual Bool canExtend() const
Can the region extend itself? By default it cannot.
WCRegion & operator=(const WCRegion &other)
Assignment (copy semantics) makes only sense for a derived class.
virtual LCRegion * toLCRegion(const CoordinateSystem &cSys, const IPosition &shape) const
Convert to an LCRegion using the given new coordinate system and shape.
void makeWorldAbsolute(Vector< Double > &world, const Vector< Int > &absRel, const CoordinateSystem &cSys, const IPosition &shape) const
Convert relative to absolute world as needed.
virtual uInt ndim() const
Get the dimensionality (i.e.
void checkAxes(const IPosition &pixelAxes, const CoordinateSystem &cSys, const Vector< String > &quantityUnits) const
this file contains all the compiler specific defines
Definition mainpage.dox:28
unsigned int uInt
Definition aipstype.h:49
TableExprNode shape(const TableExprNode &array)
Function operating on any scalar or array resulting in a Double array containing the shape.
Definition ExprNode.h:1991
int Int
Definition aipstype.h:48
bool Bool
Define the standard types used by Casacore.
Definition aipstype.h:40
LatticeExprNode value(const LatticeExprNode &expr)
This function returns the value of the expression without a mask.
double Double
Definition aipstype.h:53