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// <summary>
44// Base class to define world coordinate regions of interest in an image.
45// </summary>
46
47// <use visibility=export>
48
49// <reviewed reviewer="" date="" tests="">
50// </reviewed>
51//
52// <prerequisite>
53// <li> <linkto class=LCRegion>LCRegion</linkto>
54// </prerequisite>
55//
56// <synopsis>
57// WCRegion is the base class for world coordinate regions.
58// The axes in a WCRegion have names (e.g. RA, DEC, FREQ) and
59// carry sometimes an associated reference frame with it.
60// An WCRegion object is converted to the appropriate
61// <linkto class=LCRegion>LCRegion</linkto> object when they
62// are used to take a subset from an image.
63// LCRegion's are pixel based and are
64// used to access the correct pixels in the image.
65// The conversion has the following rules:
66// <ol>
67// <li> All axes of the region must be axes in the image.
68// <li> An image axis does not have to be an axis in the region.
69// Thus the image can have a higher dimensionality than the region.
70// If that is the case, the region is auto-extended to the image's
71// dimensionality by using the full range for those axes.
72// <li> The order of the axes in region and image do not have to
73// be the same. They get reordered as needed.
74// </ol>
75// </synopsis>
76//
77// <example>
78// <srcblock>
79// </srcblock>
80// </example>
81//
82// <motivation>
83// User should be able to specify their regions in world coordinates
84// as well as lattice coordinates.
85// </motivation>
86//
87// # <todo asof="1997/11/11">
88// # <li>
89// # </todo>
90
91class WCRegion {
92 public:
94
95 // Copy constructor (copy semantics).
96 WCRegion(const WCRegion& other);
97
98 // Destructor
99 virtual ~WCRegion();
100
101 // Comparison
102 // <group>
103 virtual Bool operator==(const WCRegion& other) const;
104 Bool operator!=(const WCRegion& other) const;
105 // </group>
106
107 // Clone a WCRegion object.
108 virtual WCRegion* cloneRegion() const = 0;
109
110 // Return region type.
111 // Just returns the class name of the derived class.
112 virtual String type() const = 0;
113
114 // Get the dimensionality (i.e. the number of axes).
115 // Note that usually all axes have a description, but in some cases
116 // (e.g. WCLELMask) that may not be the case.
117 // The default implementation returns the number of axes in the
118 // axes description.
119 virtual uInt ndim() const;
120
121 // Get the description of all axes.
122 const Record& getAxesDesc() const;
123
124 // Get the description of the given axis.
125 // It is a record containing some fields describing the axis.
126 const Record& getAxisDesc(uInt axis) const;
127
128 // Return the axis number of the description of an axis in the full
129 // axes description.
130 // -1 is returned if not found.
131 Int axisNr(const Record& desc, const Record& axesDesc) const;
132
133 // Are both axis descriptions equal?
134 Bool isAxisDescEqual(const Record& desc1, const Record& desc2) const;
135
136 // Can the region extend itself?
137 // By default it cannot.
138 virtual Bool canExtend() const;
139
140 // Get or set the comment.
141 // <group>
142 const String& comment() const;
143 void setComment(const String& comment);
144 // </group>
145
146 // Convert to an LCRegion using the given new coordinate system and shape.
147 // An exception is thrown if the region's dimensionality is more
148 // than the length of the shape vector or if an axis in the region
149 // is unknown in the new coordinate system..
150 // When less, the default implementation extends the region over the
151 // remaining axes.
152 // <br>If the region does not need to have coordinates (like WCLELMask)
153 // the function has to be overridden.
154 virtual LCRegion* toLCRegion(const CoordinateSystem& cSys, const IPosition& shape) const;
155
156 // Convert to an LCRegion using the given coordinate system and shape.
157 // This function is meant for internal use by WCCompound objects.
158 // <br>pixelAxesMap(i) is the axis in cSys and shape for region axis i.
159 // <br>outOrder(i) is the axis in the output LCRegion for region axis i.
160 // <br>The length of pixelAxesMap and outOrder is the dimensionality of
161 // the output LCRegion. It can be more than the dimensionality of this
162 // WCRegion object. In that case the region gets extended along the
163 // latter axes. If the region cannot extend itself, this function
164 // will create an LCExtension object to extend the region.
165 // <br>Note that initially pixelAxisMap and outOrder are the same,
166 // but when called for regions in compound regions they may start
167 // to differ.
169 const IPosition& pixelAxesMap, const IPosition& outOrder) const;
170
171 // Convert the (derived) object to a record.
172 // The record can be used to make the object persistent.
173 // The <src>tableName</src> argument can be used by derived
174 // classes (e.g. LCPagedMask) to put very large objects.
175 virtual TableRecord toRecord(const String& tableName) const = 0;
176
177 // Convert correct object from a record.
178 static WCRegion* fromRecord(const TableRecord& rec, const String& tableName);
179
180 // Define the type and class name in the record.
181 void defineRecordFields(RecordInterface& record, const String& className) const;
182
183 protected:
184 // Assignment (copy semantics) makes only sense for a derived class.
186
187 // Add an axis with its description.
188 // An exception is thrown if the axis already exists in this region.
189 void addAxisDesc(const Record& axisDesc);
190
191 // Make a description of a pixel axis in the coordinate system.
192 Record makeAxisDesc(const CoordinateSystem& cSys, uInt pixelAxis) const;
193
194 // Make a description of all pixel axes in the coordinate system
195 // (in pixel axes order).
197
198 // Convert to an LCRegion using the given coordinate system and shape.
199 // <br>pixelAxesMap(i) is the axis in cSys and shape for region axis i.
200 // <br>outOrder(i) is the axis in the output LCRegion for region axis i.
201 // <br>They always have the same length.
202 // If the region can extend itself, the length of pixelAxesMap and
203 // outOrder can be more than the dimensionality of the region.
204 // The latter axes in them are the extension axes.
206 const IPosition& pixelAxesMap,
207 const IPosition& extendAxes) const = 0;
208
209 // Convert relative to absolute world as needed
210 void makeWorldAbsolute(Vector<Double>& world, const Vector<Int>& absRel,
211 const CoordinateSystem& cSys, const IPosition& shape) const;
212
213 static void unitInit();
214
215 void checkAxes(const IPosition& pixelAxes, const CoordinateSystem& cSys,
216 const Vector<String>& quantityUnits) const;
217
218 static void convertPixel(Double& pixel, const Double& value, const String& unit, const Int absRel,
219 const Double refPix, const Int shape);
220
221 private:
224};
225
226inline Bool WCRegion::operator!=(const WCRegion& other) const { return (!operator==(other)); }
227inline const String& WCRegion::comment() const { return itsComment; }
229inline const Record& WCRegion::getAxesDesc() const { return itsAxesDesc; }
230
231} // namespace casacore
232
233#endif
String: the storage and methods of handling collections of characters.
Definition String.h:355
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:227
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:228
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:229
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:226
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?
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
For temporary backward namespace compatibility, use casa as alias for casacore.
Definition mainpage.dox:28
unsigned int uInt
Definition aipstype.h:49
IPosition shape(const RecordFieldId &) const
Get the actual shape of this field.
RecordInterface()
The default constructor creates an empty record with a variable structure.
int Int
Definition aipstype.h:48
bool Bool
Define the standard types used by Casacore.
Definition aipstype.h:40
NewDelAllocator< T > NewDelAllocator< T >::value
Definition Allocator.h:360
double Double
Definition aipstype.h:53