casacore
Loading...
Searching...
No Matches
ImageConcat.h
Go to the documentation of this file.
1// # ImageConcat.h: concatenate images along an axis
2// # Copyright (C) 1996,1997,1998,1999,2000,2001,2003
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_IMAGECONCAT_H
27#define IMAGES_IMAGECONCAT_H
28
29// # Includes
30#include <casacore/casa/aips.h>
31#include <casacore/casa/Arrays/Vector.h>
32#include <casacore/casa/Containers/Block.h>
33#include <casacore/casa/Json/JsonKVMap.h>
34#include <casacore/lattices/Lattices/Lattice.h>
35#include <casacore/lattices/Lattices/LatticeConcat.h>
36#include <casacore/images/Images/ImageInterface.h>
37
38namespace casacore { // # NAMESPACE CASACORE - BEGIN
39
40// # Forward Declarations
42template <class T>
43class ImageSummary;
44template <class T>
45class MaskedLattice;
46
47// <summary>
48// Concatenates images along a specified axis
49// </summary>
50
51// <use visibility=export>
52
53// <reviewed reviewer="" date="yyyy/mm/dd" tests="" demos="">
54// </reviewed>
55
56// <prerequisite>
57// <li> <linkto class=LatticeConcat>LatticeConcat</linkto>
58// <li> <linkto class=ImageInterface>ImageInterface</linkto>
59// </prerequisite>
60
61// <etymology>
62// This is a class designed to concatenate images along a specified axis
63// </etymology>
64
65// <synopsis>
66// This is a class designed to concatenate images along a specified
67// axis. This means you can join them together. E.g.,
68// join images of shape [10,20,30] and [10,20,40] into a lattice
69// of shape [10,20,70].
70//
71// The ImageConcat object does not copy the input images, it
72// just references them. You can use the Lattice<T>::copyData(Lattice<T>)
73// function to fill an output image with the concatenated input images
74//
75// If you use the putSlice function, be aware that it will change the
76// underlying images if they are writable.
77//
78// You can also concatenate a lattice to an image.
79// </synopsis>
80//
81// <example>
82// <srcblock>
83// IPosition shape(2, 10, 20);
84// PagedImage<Float> im1(shape, CoordinateUtil::defaultCoords2D(),
85// "tImageConcat_tmp1.img");
86// im1.set(1.0);
87// PagedImage<Float> im2(shape, CoordinateUtil::defaultCoords2D(),
88// "tImageConcat_tmp2.img");
89// im2.set(2.0);
90//
92//
93// ImageConcat<Float> concat(0);
94//
96//
97// concat.setImage(im1, True);
98// concat.setImage(im2, True);
99//
101//
102// PagedImage<Float> im3(concat.shape(), CoordinateUtil::defaultCoords2D(),
103// "tImageConcat_tmp3.img");
104//
106//
107// im3.copyData(concat);
108//
109// </srcblock>
110// See tImageConcat.cc for more examples.
111// </example>
112
113// <motivation>
114// Image concatentation is a useful enduser requirement.
115// </motivation>
116
117// <todo asof="1999/10/23">
118// <li> Offer the ability to increase the dimensionality of
119// the output image
120// </todo>
121
122template <class T>
123class ImageConcat : public ImageInterface<T> {
124 public:
125 // Constructor. Specify the pixel axis for concatenation
126 explicit ImageConcat(uInt axis, Bool tempClose = True, Bool combineMiscInfo = True);
127
128 // Construct the object from a Json file with the given name.
129 // This constructor is usually called by ImageOpener::openImageConcat.
130 ImageConcat(const JsonKVMap&, const String& fileName);
131
132 // Default constructor, Sets the concatenation axis to 0
134
135 // Copy constructor (reference semantics)
137
138 // Destructor
139 virtual ~ImageConcat();
140
141 // Assignment operator (reference semantics)
143
144 // Make a copy of the object (reference semantics).
145 virtual ImageInterface<T>* cloneII() const;
146
147 // Save the image in file 'image.concat' in a directory with the given name.
148 // An exception is thrown if such a directory or file already exists.
149 // It can be opened by ImageOpener::openImage(Concat).
150 virtual void save(const String& fileName) const;
151
152 // Replace the miscinfo in the ConcatImage, which writes the image.concat file.
153 // It can fail if, e.g., the directory to write to is not writable.
154 virtual Bool setMiscInfo(const RecordInterface& newInfo);
155
156 // Set the ImageInfo in the super class ImageInterface and in each
157 // underlying image. If needed, its restoring beam is split along the
158 // frequency or polarisation axis and set in each underlying image.
159 virtual Bool setImageInfo(const ImageInfo& info);
160
161 // Get the image type (returns name of derived class).
162 virtual String imageType() const;
163
164 // Is the lattice persistent and can it be loaded by other processes as well?
165 virtual Bool isPersistent() const;
166
167 // Sets a new image into the list to be concatenated.
168 // If relax is False, throws an exception if the images
169 // are not contiguous along the concatenation axis.
170 // If relax is True, it will create a non-regular TabularCoordinate
171 // for non-contiguous images if the coordinates are monotonic.
172 // Otherwise, it just uses the coordinates of the image
174
175 // Add a clone of the lattice to the list to be concatenated.
176 // You can only concatenate a lattice with an image if
177 // you have first used setImage to set an image (this
178 // provides the CooridinateSystem information)
180
181 // Return the number of images/lattices set so far
182 uInt nimages() const { return latticeConcat_p.nlattices(); }
183
184 // Returns the current concatenation axis (0 relative)
185 uInt axis() const { return latticeConcat_p.axis(); }
186
187 // Returns the number of dimensions of the *input* images/lattices
188 // Returns 0 if none yet set.
189 uInt imageDim() const { return latticeConcat_p.latticeDim(); }
190
191 // Return a reference to the i-th image.
193 return dynamic_cast<ImageInterface<T>&>(*(latticeConcat_p.lattice(i)));
194 }
195
196 // Handle the (un)locking and syncing, etc.
197 // <group>
198 virtual Bool lock(FileLocker::LockType, uInt nattempts);
199 virtual void unlock();
201 virtual void resync();
202 virtual void flush();
203 virtual void tempClose();
204 virtual void reopen();
205 // </group>
206
207 // Return the name of the current ImageInterface object.
208 // If the object is persistent, it returns its file name.
209 // Otherwise it returns the string "Concatenation :"
210 virtual String name(Bool stripPath = False) const;
211
212 // Has the object really a mask?
213 virtual Bool isMasked() const;
214
215 // Does the image have a pixelmask?
216 virtual Bool hasPixelMask() const;
217
218 // Get access to the pixelmask.
219 // An exception is thrown if the image does not have a pixelmask
220 // <group>
221 virtual const Lattice<Bool>& pixelMask() const;
223 // </group>
224
225 // Get the region used (always returns 0)
226 virtual const LatticeRegion* getRegionPtr() const;
227
228 // If all of the underlying lattices are writable returns True
229 virtual Bool isWritable() const;
230
231 // Return the shape of the concatenated image
232 virtual IPosition shape() const;
233
234 // Return the best cursor shape. It will try to return the best cusrsor of the
235 // smallest constituent image along the non-direction axes (in order to minimize
236 // bouncing from one image to another while iterating which may involve lots of
237 // open and tempclose).
238 virtual IPosition doNiceCursorShape(uInt maxPixels) const;
239
240 // Do the actual get of the data.
241 // The return value is always False, thus the buffer does not reference
242 // another array. Generally the user should use function getSlice
243 virtual Bool doGetSlice(Array<T>& buffer, const Slicer& section);
244
245 // Do the actual get of the mask data.
246 // The return value is always False, thus the buffer does not reference
247 // another array. Generally the user should use function getMaskSlice
248 virtual Bool doGetMaskSlice(Array<Bool>& buffer, const Slicer& section);
249
250 // Do the actual put of the data into the Lattice. This will change the
251 // underlying images (if they are writable) that were used to create the
252 // ImageConcat object. It throws an exception if not writable.
253 // Generally the user should use function putSlice
254 virtual void doPutSlice(const Array<T>& sourceBuffer, const IPosition& where,
255 const IPosition& stride);
256
257 // Throws an excpetion as you cannot reshape an ImageConcat object
258 virtual void resize(const TiledShape&);
259
260 // Check class invariants.
261 virtual Bool ok() const;
262
263 // These are the implementations of the LatticeIterator letters.
264 // <note> not for public use </note>
265 virtual LatticeIterInterface<T>* makeIter(const LatticeNavigator& navigator, Bool useRef) const;
266
267 private:
273 mutable String fileName_p; // Empty if not persistent
278
279 Double coordConvert(Int& worldAxis, LogIO& os, const CoordinateSystem& cSys, uInt axis,
280 Double pixelCoord) const;
281
282 void _checkContiguous(const IPosition& shape1, const CoordinateSystem& cSys1,
283 const CoordinateSystem& cSys2, LogIO& os, uInt axis, Bool relax);
284
286
287 Vector<Int> makeNewStokes(const Vector<Int>& stokes1, const Vector<Int>& stokes2);
288
289 // Updates the CoordinateSystem in the ImageConcat image. The first lattice must
290 // be an image. The first lattice is contiguous by definition. The Coordinate
291 // System for the first image must be set before calling this function. For
292 // the first image, this function just sets up worldValues and pixelValues
294
296
297 // # Make members of parent class known.
298 public:
299 using ImageInterface<T>::logger;
301 using ImageInterface<T>::units;
303
304 protected:
307};
308
309} // namespace casacore
310
311#ifndef CASACORE_NO_AUTO_TEMPLATES
312#include <casacore/images/Images/ImageConcat.tcc>
313#endif // # CASACORE_NO_AUTO_TEMPLATES
314#endif
Type
This enum lists the types of the derived classes.
Definition Coordinate.h:139
LockType
Define the possible lock types.
Definition FileLocker.h:89
void setLattice(MaskedLattice< T > &lattice)
Add a clone of the lattice to the list to be concatenated.
ImageConcat(const JsonKVMap &, const String &fileName)
Construct the object from a Json file with the given name.
Vector< Bool > isImage_p
ImageConcat(uInt axis, Bool tempClose=True, Bool combineMiscInfo=True)
Constructor.
uInt axis() const
Returns the current concatenation axis (0 relative).
void setCoordinates()
Updates the CoordinateSystem in the ImageConcat image.
void checkNonConcatAxisCoordinates(LogIO &os, const ImageInterface< T > &image, Bool relax)
virtual Bool setMiscInfo(const RecordInterface &newInfo)
Replace the miscinfo in the ConcatImage, which writes the image.concat file.
ImageInterface< T > & image(uInt i) const
Return a reference to the i-th image.
void _checkContiguous(const IPosition &shape1, const CoordinateSystem &cSys1, const CoordinateSystem &cSys2, LogIO &os, uInt axis, Bool relax)
Vector< Double > worldValues_p
virtual LatticeIterInterface< T > * makeIter(const LatticeNavigator &navigator, Bool useRef) const
These are the implementations of the LatticeIterator letters.
virtual Bool hasLock(FileLocker::LockType) const
virtual Bool setImageInfo(const ImageInfo &info)
Set the ImageInfo in the super class ImageInterface and in each underlying image.
virtual void save(const String &fileName) const
Save the image in file 'image.concat' in a directory with the given name.
virtual void flush()
Flush the data (but do not unlock).
ImageConcat< T > & operator=(const ImageConcat< T > &other)
Assignment operator (reference semantics).
virtual Bool doGetMaskSlice(Array< Bool > &buffer, const Slicer &section)
Do the actual get of the mask data.
virtual Bool hasPixelMask() const
Does the image have a pixelmask?
virtual Bool doGetSlice(Array< T > &buffer, const Slicer &section)
Do the actual get of the data.
virtual Bool isPersistent() const
Is the lattice persistent and can it be loaded by other processes as well?
virtual String name(Bool stripPath=False) const
Return the name of the current ImageInterface object.
virtual Bool isWritable() const
If all of the underlying lattices are writable returns True.
ImageConcat()
Default constructor, Sets the concatenation axis to 0.
virtual void reopen()
Explicitly reopen the temporarily closed lattice.
virtual Lattice< Bool > & pixelMask()
virtual const LatticeRegion * getRegionPtr() const
Get the region used (always returns 0).
void setImage(ImageInterface< T > &image, Bool relax)
Sets a new image into the list to be concatenated.
virtual void doPutSlice(const Array< T > &sourceBuffer, const IPosition &where, const IPosition &stride)
Do the actual put of the data into the Lattice.
Vector< Int > makeNewStokes(const Vector< Int > &stokes1, const Vector< Int > &stokes2)
Double coordConvert(Int &worldAxis, LogIO &os, const CoordinateSystem &cSys, uInt axis, Double pixelCoord) const
virtual Bool ok() const
Check class invariants.
virtual void resize(const TiledShape &)
Throws an excpetion as you cannot reshape an ImageConcat object.
virtual Bool lock(FileLocker::LockType, uInt nattempts)
Handle the (un)locking and syncing, etc.
virtual Bool isMasked() const
Has the object really a mask?
Coordinate::Type originalAxisType_p
LatticeConcat< T > latticeConcat_p
virtual ~ImageConcat()
Destructor.
ImageConcat(const ImageConcat< T > &other)
Copy constructor (reference semantics).
uInt imageDim() const
Returns the number of dimensions of the input images/lattices Returns 0 if none yet set.
virtual IPosition shape() const
Return the shape of the concatenated image.
virtual void unlock()
virtual void resync()
Resynchronize the Lattice object with the lattice file.
Vector< Double > pixelValues_p
virtual ImageInterface< T > * cloneII() const
Make a copy of the object (reference semantics).
virtual String imageType() const
Get the image type (returns name of derived class).
void _updatePixelAndWorldValues(uInt iIm)
uInt nimages() const
Return the number of images/lattices set so far.
virtual IPosition doNiceCursorShape(uInt maxPixels) const
Return the best cursor shape.
virtual void tempClose()
Temporarily close the lattice.
virtual const Lattice< Bool > & pixelMask() const
Get access to the pixelmask.
void setCoordsMember(const CoordinateSystem &coords)
Set the coordinate system variable.
LoggerHolder & logger()
Get access to the LoggerHolder.
virtual const Unit & units() const
void setMiscInfoMember(const RecordInterface &rec)
Set the miscinfo variable.
const CoordinateSystem & coordinates() const
const TableRecord & miscInfo() const
Often we have miscellaneous information we want to attach to an image.
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
const Bool False
Definition aipstype.h:42
unsigned int uInt
Definition aipstype.h:49
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
const Bool True
Definition aipstype.h:41
double Double
Definition aipstype.h:53