casacore
Loading...
Searching...
No Matches
LinearCoordinate.h
Go to the documentation of this file.
1// # LinearCoordinate.h: Assume a general linear relation between pixel and world axes.
2// # Copyright (C) 1997,1998,1999,2000,2001,2002,2003,2004
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 COORDINATES_LINEARCOORDINATE_H
27#define COORDINATES_LINEARCOORDINATE_H
28
29#include <casacore/casa/aips.h>
30#include <casacore/coordinates/Coordinates/Coordinate.h>
31#include <casacore/casa/Arrays/Vector.h>
32#include <wcslib/wcs.h>
33
34namespace casacore { // # NAMESPACE CASACORE - BEGIN
35
36template <class T>
37class Quantum;
38
39// <summary>
40// Interconvert between pixel and a linear world coordinate.
41// </summary>
42
43// <use visibility=export>
44
45// <reviewed reviewer="Peter Barnes" date="1999/12/24" tests="tLinearCoordinate">
46// </reviewed>
47
48// <prerequisite>
49// <li> <linkto class=Coordinate>Coordinate</linkto> defines the fundamental
50// interface to coordinate conversions.
51// </prerequisite>
52//
53// <synopsis>
54// The LinearCoordinate class ties pixel and world axes together through
55// a general linear transformation.
56//
57// <srcblock>
58// world = (cdelt * PC * (pixel - crpix)) + crval
59// </srcblock>
60// Where PC is an NxN matrix; pixel, crval, crpix and world are length N
61// vectors, and cdelt is an NxN diagonal matrix, represented as a length
62// N vector.
63//
64// The LinearCoordinate can contain several uncoupled axes (similar to the way
65// in which the DirectionCoordinate contains two axes).
66// </synopsis>
67//
68// <note role=caution>
69// All pixels coordinates are zero relative.
70// </note>
71//
72// <example>
73// Let's make a LinearCoordinate with just one axis containing
74// a coordinate describing length.
75// <srcblock>
76// Vector<Double> crpix(1); crpix = 0.0;
77// Vector<Double> crval(1); crval = 100.0;
78// Vector<Double> cdelt(1); cdelt = -10.0;
79// Matrix<Double> pc(1,1); pc= 0; pc.diagonal() = 1.0;
80// Vector<String> name(1); name = "length";
81// Vector<String> units(1); units = "km";
82//
83// LinearCoordinate lin(names, units, crval, cdelt, pc, crpix);
84// </srcblock>
85//
86// Now do a coordinate conversion
87//
88// <srcblock>
89// Vector<Double> world, pixel(1);
90// pixel = 2.0;
91// if (!lin.toWorld(world, pixel)) {
92// cerr << "Error : " << lin.errorMessage() << endl;
93// } else {
94// cerr << "pixel, world = " << pixel << world << endl;
95// }
96// </srcblock>
97// The answer should of course be -20km.
98// </example>
99//
100// <motivation>
101// This class is intended for use with axes which do not have specific coordinate
102// types. A "time" axis would be a good example.
103// </motivation>
104//
105// <thrown>
106// <li> AipsError
107// </thrown>
108//
109// <todo asof="2000/01/01">
110// <li> Allow differing numbers of world and pixel axes. Requires a change in
111// WCS or use of a different library.
112// </todo>
113//
114
116 public:
117 // The default constructor makes a LinearCoordinate for which pixel
118 // and world coordinates are equal. <src>naxes</src> gives the number
119 // of axes in the Coordinate.
121
122 // Construct the LinearCoordinate
124 const Vector<Double> &refVal, const Vector<Double> &inc,
125 const Matrix<Double> &pc, const Vector<Double> &refPix);
126
127 // Construct LinearCoordinate with Quantum-based interface.
128 // The units of the increment (<src>inc</src>) will be converted to
129 // those of the reference value (<src>refVal</src>) which will
130 // then serve as the units of the Coordinate.
132 const Vector<Quantum<Double>> &inc, const Matrix<Double> &pc,
133 const Vector<Double> &refPix);
134
135 // Constructor from WCS structure; must hold ONLY a linear wcs structure
136 // Specify whether the absolute pixel coordinates in the wcs structure
137 // are 0- or 1-relative. The coordinate is always constructed with 0-relative
138 // pixel coordinates
139 LinearCoordinate(const wcsprm &wcs, Bool oneRel = True);
140
141 // Copy constructor (copy semantics).
143
144 // Assignment (copy semantics).
146
147 // Destructor.
149
150 // Returns Coordinate::LINEAR.
151 virtual Coordinate::Type type() const;
152
153 // Returns the String "Linear".
154 virtual String showType() const;
155
156 // Returns the number of pixel/world axes. The number of axes is arbitrary,
157 // however the number of world and pixel axes must at present be the same.
158 // <group>
159 virtual uInt nPixelAxes() const;
160 virtual uInt nWorldAxes() const;
161 // </group>
162
163 // Convert a pixel position to a worl position or vice versa. Returns True
164 // if the conversion succeeds, otherwise it returns False and method
165 // errorMessage returns an error message. The output
166 // vectors are appropriately resized. The value of the Bool parameter passed
167 // to toWorld() has no effect as this type of coordinate does not support a
168 // conversion layer frame.
169 // <group>
170 virtual Bool toWorld(Vector<Double> &world, const Vector<Double> &pixel, Bool = True) const;
171 virtual Bool toPixel(Vector<Double> &pixel, const Vector<Double> &world) const;
172 // </group>
173
174 // Return the requested attribute
175 // <group>
178 virtual Vector<Double> increment() const;
182 // </group>
183
184 // Set the value of the requested attributed. Note that these just
185 // change the internal values, they do not cause any recomputation.
186 // <group>
187 virtual Bool setWorldAxisNames(const Vector<String> &names);
188 virtual Bool setReferencePixel(const Vector<Double> &refPix);
190 virtual Bool setIncrement(const Vector<Double> &inc);
191 virtual Bool setReferenceValue(const Vector<Double> &refval);
192 // </group>
193
194 // Set the world axis units. Adjust the increment and
195 // reference value by the ratio of the old and new units.
196 // The units must be compatible with the current units.
197 virtual Bool setWorldAxisUnits(const Vector<String> &units);
198
199 // Overwrite the world axis units with no compatibility
200 // checks or adjustment.
202
203 // Comparison function. Any private Double data members are compared
204 // with the specified fractional tolerance. Don't
205 // compare on the specified
206 // axes in the Coordinate. If the comparison returns False, method
207 // errorMessage contains a message about why.
208 // <group>
209 virtual Bool near(const Coordinate &other, Double tol = 1e-6) const;
210 virtual Bool near(const Coordinate &other, const Vector<Int> &excludeAxes,
211 Double tol = 1e-6) const;
212 // </group>
213
214 // Find the Coordinate for when we Fourier Transform ourselves. This pointer
215 // must be deleted by the caller. Axes specifies which axes of the Coordinate
216 // you wish to transform. Shape specifies the shape of the image
217 // associated with all the axes of the Coordinate. Currently the
218 // output reference pixel is always shape/2. If the pointer returned is 0,
219 // it failed with a message in <src>errorMessage</src>
221 const Vector<Int> &shape) const;
222
223 // Save the LinearCoordinate into the supplied record using the supplied field name.
224 // The field must not already exist, otherwise <src>False</src> is returned.
225 virtual Bool save(RecordInterface &container, const String &fieldName) const;
226
227 // Restore the LinearCoordinate from a record.
228 // A null pointer means that the restoration did not succeed - probably
229 // because fieldName doesn't exist or doesn't contain a CoordinateSystem.
230 static LinearCoordinate *restore(const RecordInterface &container, const String &fieldName);
231
232 // Make a copy of the LinearCoordinate using new. The caller is responsible for calling
233 // delete.
234 virtual Coordinate *clone() const;
235
236 private:
237 // An interface to the WCSLIB linear transformation routines.
238 mutable ::wcsprm wcs_p;
239
240 // Copy private data
241 void copy(const LinearCoordinate &other);
242
243 // Make wcs structure
244 void makeWCS(wcsprm &wcs, uInt naxis, const Vector<Double> &refPix, const Vector<Double> &refVal,
245 const Vector<Double> &incr, const Matrix<Double> &pc, const Vector<String> &units,
246 const Vector<String> &names);
247};
248
249} // namespace casacore
250
251#endif
Coordinate()
Default constructor.
Type
This enum lists the types of the derived classes.
Definition Coordinate.h:139
virtual String showType() const
Returns the String "Linear".
virtual Bool setIncrement(const Vector< Double > &inc)
virtual Matrix< Double > linearTransform() const
virtual uInt nWorldAxes() const
LinearCoordinate(const Vector< String > &names, const Vector< String > &units, const Vector< Double > &refVal, const Vector< Double > &inc, const Matrix< Double > &pc, const Vector< Double > &refPix)
Construct the LinearCoordinate.
virtual Vector< Double > referenceValue() const
virtual Vector< String > worldAxisNames() const
Return the requested attribute.
virtual Vector< String > worldAxisUnits() const
virtual Bool save(RecordInterface &container, const String &fieldName) const
Save the LinearCoordinate into the supplied record using the supplied field name.
virtual ~LinearCoordinate()
Destructor.
void makeWCS(wcsprm &wcs, uInt naxis, const Vector< Double > &refPix, const Vector< Double > &refVal, const Vector< Double > &incr, const Matrix< Double > &pc, const Vector< String > &units, const Vector< String > &names)
Make wcs structure.
LinearCoordinate(const LinearCoordinate &other)
Copy constructor (copy semantics).
virtual Coordinate * makeFourierCoordinate(const Vector< Bool > &axes, const Vector< Int > &shape) const
Find the Coordinate for when we Fourier Transform ourselves.
LinearCoordinate(const Vector< String > &names, const Vector< Quantum< Double > > &refVal, const Vector< Quantum< Double > > &inc, const Matrix< Double > &pc, const Vector< Double > &refPix)
Construct LinearCoordinate with Quantum-based interface.
virtual uInt nPixelAxes() const
Returns the number of pixel/world axes.
virtual Bool setReferencePixel(const Vector< Double > &refPix)
LinearCoordinate(uInt naxes=1)
The default constructor makes a LinearCoordinate for which pixel and world coordinates are equal.
virtual Bool near(const Coordinate &other, Double tol=1e-6) const
Comparison function.
virtual Bool toPixel(Vector< Double > &pixel, const Vector< Double > &world) const
virtual Bool near(const Coordinate &other, const Vector< Int > &excludeAxes, Double tol=1e-6) const
virtual Bool setWorldAxisNames(const Vector< String > &names)
Set the value of the requested attributed.
virtual Bool setReferenceValue(const Vector< Double > &refval)
mutable::wcsprm wcs_p
An interface to the WCSLIB linear transformation routines.
LinearCoordinate & operator=(const LinearCoordinate &other)
Assignment (copy semantics).
Bool overwriteWorldAxisUnits(const Vector< String > &units)
Overwrite the world axis units with no compatibility checks or adjustment.
virtual Bool toWorld(Vector< Double > &world, const Vector< Double > &pixel, Bool=True) const
Convert a pixel position to a worl position or vice versa.
virtual Coordinate::Type type() const
Returns Coordinate::LINEAR.
virtual Bool setLinearTransform(const Matrix< Double > &pc)
static LinearCoordinate * restore(const RecordInterface &container, const String &fieldName)
Restore the LinearCoordinate from a record.
void copy(const LinearCoordinate &other)
Copy private data.
LinearCoordinate(const wcsprm &wcs, Bool oneRel=True)
Constructor from WCS structure; must hold ONLY a linear wcs structure Specify whether the absolute pi...
virtual Vector< Double > increment() const
virtual Bool setWorldAxisUnits(const Vector< String > &units)
Set the world axis units.
virtual Vector< Double > referencePixel() const
virtual Coordinate * clone() const
Make a copy of the LinearCoordinate using new.
String: the storage and methods of handling collections of characters.
Definition String.h:355
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.
bool Bool
Define the standard types used by Casacore.
Definition aipstype.h:40
const Bool True
Definition aipstype.h:41
double Double
Definition aipstype.h:53