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