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