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
30//# Includes
31#include <casacore/casa/aips.h>
32#include <casacore/casa/Arrays/Vector.h>
33#include <casacore/casa/Containers/Block.h>
34#include <casacore/casa/Json/JsonKVMap.h>
35#include <casacore/lattices/Lattices/Lattice.h>
36#include <casacore/lattices/Lattices/LatticeConcat.h>
37#include <casacore/images/Images/ImageInterface.h>
38
39namespace casacore { //# NAMESPACE CASACORE - BEGIN
40
41//# Forward Declarations
42class CoordinateSystem;
43template <class T> class ImageSummary;
44template <class T> class MaskedLattice;
45
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
114// <motivation>
115// Image concatentation is a useful enduser requirement.
116// </motivation>
117
118// <todo asof="1999/10/23">
119// <li> Offer the ability to increase the dimensionality of
120// the output image
121// </todo>
122
123
124template <class T> class ImageConcat : public ImageInterface<T>
125{
126public:
127
128// Constructor. Specify the pixel axis for concatenation
130 Bool combineMiscInfo=True);
131
132// Construct the object from a Json file with the given name.
133// This constructor is usually called by ImageOpener::openImageConcat.
134 ImageConcat (const JsonKVMap&, const String& fileName);
135
136// Default constructor, Sets the concatenation axis to 0
138
139// Copy constructor (reference semantics)
141
142// Destructor
143 virtual ~ImageConcat();
144
145// Assignment operator (reference semantics)
147
148// Make a copy of the object (reference semantics).
149 virtual ImageInterface<T>* cloneII() const;
150
151// Save the image in file 'image.concat' in a directory with the given name.
152// An exception is thrown if such a directory or file already exists.
153// It can be opened by ImageOpener::openImage(Concat).
154 virtual void save (const String& fileName) const;
155
156// Replace the miscinfo in the ConcatImage, which writes the image.concat file.
157// It can fail if, e.g., the directory to write to is not writable.
158 virtual Bool setMiscInfo (const RecordInterface& newInfo);
159
160 // Set the ImageInfo in the super class ImageInterface and in each
161 // underlying image. If needed, its restoring beam is split along the
162 // frequency or polarisation axis and set in each underlying image.
163 virtual Bool setImageInfo(const ImageInfo& info);
164
165// Get the image type (returns name of derived class).
166 virtual String imageType() const;
167
168// Is the lattice persistent and can it be loaded by other processes as well?
169 virtual Bool isPersistent() const;
170
171// Sets a new image into the list to be concatenated.
172// If relax is False, throws an exception if the images
173// are not contiguous along the concatenation axis.
174// If relax is True, it will create a non-regular TabularCoordinate
175// for non-contiguous images if the coordinates are monotonic.
176// Otherwise, it just uses the coordinates of the image
178
179// Add a clone of the lattice to the list to be concatenated.
180// You can only concatenate a lattice with an image if
181// you have first used setImage to set an image (this
182// provides the CooridinateSystem information)
184
185// Return the number of images/lattices set so far
186 uInt nimages() const
187 { return latticeConcat_p.nlattices(); }
188
189// Returns the current concatenation axis (0 relative)
190 uInt axis () const
191 { return latticeConcat_p.axis(); }
192
193// Returns the number of dimensions of the *input* images/lattices
194// Returns 0 if none yet set.
196 { return latticeConcat_p.latticeDim(); }
197
198// Return a reference to the i-th image.
200 { return dynamic_cast<ImageInterface<T>&>(*(latticeConcat_p.lattice(i))); }
201
202// Handle the (un)locking and syncing, etc.
203// <group>
204 virtual Bool lock (FileLocker::LockType, uInt nattempts);
205 virtual void unlock();
207 virtual void resync();
208 virtual void flush();
209 virtual void tempClose();
210 virtual void reopen();
211// </group>
212
213// Return the name of the current ImageInterface object.
214// If the object is persistent, it returns its file name.
215// Otherwise it returns the string "Concatenation :"
216 virtual String name (Bool stripPath=False) const;
217
218// Has the object really a mask?
219 virtual Bool isMasked() const;
220
221// Does the image have a pixelmask?
222 virtual Bool hasPixelMask() const;
223
224// Get access to the pixelmask.
225// An exception is thrown if the image does not have a pixelmask
226// <group>
227 virtual const Lattice<Bool>& pixelMask() const;
229 // </group>
230
231// Get the region used (always returns 0)
232 virtual const LatticeRegion* getRegionPtr() const;
233
234// If all of the underlying lattices are writable returns True
235 virtual Bool isWritable() const;
236
237// Return the shape of the concatenated image
238 virtual IPosition shape() const;
239
240
241// Return the best cursor shape. It will try to return the best cusrsor of the
242//smallest constituent image along the non-direction axes (in order to minimize
243//bouncing from one image to another while iterating which may involve lots of
244//open and tempclose).
245 virtual IPosition doNiceCursorShape (uInt maxPixels) const;
246
247// Do the actual get of the data.
248// The return value is always False, thus the buffer does not reference
249// another array. Generally the user should use function getSlice
250 virtual Bool doGetSlice (Array<T>& buffer, const Slicer& section);
251
252// Do the actual get of the mask data.
253// The return value is always False, thus the buffer does not reference
254// another array. Generally the user should use function getMaskSlice
255 virtual Bool doGetMaskSlice (Array<Bool>& buffer, const Slicer& section);
256
257// Do the actual put of the data into the Lattice. This will change the
258// underlying images (if they are writable) that were used to create the
259// ImageConcat object. It throws an exception if not writable.
260// Generally the user should use function putSlice
261 virtual void doPutSlice (const Array<T>& sourceBuffer,
262 const IPosition& where,
263 const IPosition& stride);
264
265// Throws an excpetion as you cannot reshape an ImageConcat object
266 virtual void resize(const TiledShape&);
267
268// Check class invariants.
269 virtual Bool ok() const;
270
271// These are the implementations of the LatticeIterator letters.
272// <note> not for public use </note>
274 (const LatticeNavigator &navigator,
275 Bool useRef) const;
276
277
278private:
284 mutable String fileName_p; // Empty if not persistent
289
290 Double coordConvert(Int& worldAxis, LogIO& os,
291 const CoordinateSystem& cSys,
292 uInt axis, Double pixelCoord) const;
293
294 void _checkContiguous(const IPosition& shape1,
295 const CoordinateSystem& cSys1,
296 const CoordinateSystem& cSys2,
297 LogIO& os, uInt axis, Bool relax);
298
301 Bool relax);
302
304 const Vector<Int>& stokes2);
305
306 // Updates the CoordinateSystem in the ImageConcat image. The first lattice must
307 // be an image. The first lattice is contiguous by definition. The Coordinate
308 // System for the first image must be set before calling this function. For
309 // the first image, this function just sets up worldValues and pixelValues
311
313
314 //# Make members of parent class known.
315public:
316 using ImageInterface<T>::logger;
318 using ImageInterface<T>::units;
320protected:
323};
324
325
326
327} //# NAMESPACE CASACORE - END
328
329#ifndef CASACORE_NO_AUTO_TEMPLATES
330#include <casacore/images/Images/ImageConcat.tcc>
331#endif //# CASACORE_NO_AUTO_TEMPLATES
332#endif
Type
This enum lists the types of the derived classes.
Definition Coordinate.h:141
LockType
Define the possible lock types.
Definition FileLocker.h:93
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:223
this file contains all the compiler specific defines
Definition mainpage.dox:28
const Bool False
Definition aipstype.h:42
unsigned int uInt
Definition aipstype.h:49
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