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
131  explicit ImageConcat (uInt axis, Bool tempClose=True);
132 
133 // Construct the object from a Json file with the given name.
134 // This constructor is usually called by ImageOpener::openImageConcat.
135  ImageConcat (const JsonKVMap&, const String& fileName);
136 
137 // Default constructor, Sets the concatenation axis to 0
138  ImageConcat();
139 
140 // Copy constructor (reference semantics)
141  ImageConcat (const ImageConcat<T> &other);
142 
143 // Destructor
144  virtual ~ImageConcat();
145 
146 // Assignment operator (reference semantics)
148 
149 // Make a copy of the object (reference semantics).
150  virtual ImageInterface<T>* cloneII() const;
151 
152 // Save the image in file 'image.concat' in a directory with the given name.
153 // An exception is thrown if such a directory or file already exists.
154 // It can be opened by ImageOpener::openImage(Concat).
155  virtual void save (const String& fileName) const;
156 
157 // Get the image type (returns name of derived class).
158  virtual String imageType() const;
159 
160 // Is the lattice persistent and can it be loaded by other processes as well?
161  virtual Bool isPersistent() const;
162 
163 // Sets a new image into the list to be concatenated.
164 // If relax is False, throws an exception if the images
165 // are not contiguous along the concatenation axis.
166 // If relax is True, it will create a non-regular TabularCoordinate
167 // for non-contiguous images if the coordinates are monotonic.
168 // Otherwise, it just uses the coordinates of the image
169  void setImage (ImageInterface<T>& image, Bool relax);
170 
171 // Add a clone of the lattice to the list to be concatenated.
172 // You can only concatenate a lattice with an image if
173 // you have first used setImage to set an image (this
174 // provides the CooridinateSystem information)
175  void setLattice (MaskedLattice<T>& lattice);
176 
177 // Return the number of images/lattices set so far
178  uInt nimages() const
179  { return latticeConcat_p.nlattices(); }
180 
181 // Returns the current concatenation axis (0 relative)
182  uInt axis () const
183  { return latticeConcat_p.axis(); }
184 
185 // Returns the number of dimensions of the *input* images/lattices
186 // Returns 0 if none yet set.
187  uInt imageDim() const
188  { return latticeConcat_p.latticeDim(); }
189 
190 // Handle the (un)locking and syncing, etc.
191 // <group>
192  virtual Bool lock (FileLocker::LockType, uInt nattempts);
193  virtual void unlock();
194  virtual Bool hasLock (FileLocker::LockType) const;
195  virtual void resync();
196  virtual void flush();
197  virtual void tempClose();
198  virtual void reopen();
199 // </group>
200 
201 // Return the name of the current ImageInterface object.
202 // If the object is persistent, it returns its file name.
203 // Otherwise it returns the string "Concatenation :"
204  virtual String name (Bool stripPath=False) const;
205 
206 // Has the object really a mask?
207  virtual Bool isMasked() const;
208 
209 // Does the image have a pixelmask?
210  virtual Bool hasPixelMask() const;
211 
212 // Get access to the pixelmask.
213 // An exception is thrown if the image does not have a pixelmask
214 // <group>
215  virtual const Lattice<Bool>& pixelMask() const;
216  virtual Lattice<Bool>& pixelMask();
217  // </group>
218 
219 // Get the region used (always returns 0)
220  virtual const LatticeRegion* getRegionPtr() const;
221 
222 // If all of the underlying lattices are writable returns True
223  virtual Bool isWritable() const;
224 
225 // Return the shape of the concatenated image
226  virtual IPosition shape() const;
227 
228 
229 // Return the best cursor shape. This isn't very meaningful for an ImageConcat
230 // Image since it isn't on disk ! But if you do copy it out, this is
231 // what you should use. The maxPixels aregument is ignored.
232  virtual IPosition doNiceCursorShape (uInt maxPixels) const;
233 
234 // Do the actual get of the data.
235 // The return value is always False, thus the buffer does not reference
236 // another array. Generally the user should use function getSlice
237  virtual Bool doGetSlice (Array<T>& buffer, const Slicer& section);
238 
239 // Do the actual get of the mask data.
240 // The return value is always False, thus the buffer does not reference
241 // another array. Generally the user should use function getMaskSlice
242  virtual Bool doGetMaskSlice (Array<Bool>& buffer, const Slicer& section);
243 
244 // Do the actual put of the data into the Lattice. This will change the
245 // underlying images (if they are writable) that were used to create the
246 // ImageConcat object. It throws an exception if not writable.
247 // Generally the user should use function putSlice
248  virtual void doPutSlice (const Array<T>& sourceBuffer,
249  const IPosition& where,
250  const IPosition& stride);
251 
252 // Throws an excpetion as you cannot reshape an ImageConcat object
253  virtual void resize(const TiledShape&);
254 
255 // Check class invariants.
256  virtual Bool ok() const;
257 
258 // These are the implementations of the LatticeIterator letters.
259 // <note> not for public use </note>
261  (const LatticeNavigator &navigator,
262  Bool useRef) const;
263 
264 
265 private:
270  mutable String fileName_p; // Empty if not persistent
275 
276  Double coordConvert(Int& worldAxis, LogIO& os,
277  const CoordinateSystem& cSys,
278  uInt axis, Double pixelCoord) const;
279 
280  void _checkContiguous(const IPosition& shape1,
281  const CoordinateSystem& cSys1,
282  const CoordinateSystem& cSys2,
283  LogIO& os, uInt axis, Bool relax);
284 
286  const ImageInterface<T>& image,
287  Bool relax);
288 
289  Vector<Int> makeNewStokes(const Vector<Int>& stokes1,
290  const Vector<Int>& stokes2);
291 
292  // Updates the CoordinateSystem in the ImageConcat image. The first lattice must
293  // be an image. The first lattice is contiguous by definition. The Coordinate
294  // System for the first image must be set before calling this function. For
295  // the first image, this function just sets up worldValues and pixelValues
296  void setCoordinates();
297 
299 
300  //# Make members of parent class known.
301 public:
306 protected:
309 };
310 
311 
312 
313 } //# NAMESPACE CASACORE - END
314 
315 #ifndef CASACORE_NO_AUTO_TEMPLATES
316 #include <casacore/images/Images/ImageConcat.tcc>
317 #endif //# CASACORE_NO_AUTO_TEMPLATES
318 #endif
A Vector of integers, for indexing into Array<T> objects.
Definition: IPosition.h:119
Concatenates lattices along a specified axis.
virtual ~ImageConcat()
Destructor.
virtual Bool isWritable() const
If all of the underlying lattices are writable returns True.
int Int
Definition: aipstype.h:50
Coordinate::Type originalAxisType_p
Definition: ImageConcat.h:274
Provides and lists information about the header of an image.
Definition: ImageConcat.h:45
void _updatePixelAndWorldValues(uInt iIm)
virtual void doPutSlice(const Array< T > &sourceBuffer, const IPosition &where, const IPosition &stride)
Do the actual put of the data into the Lattice.
virtual const LatticeRegion * getRegionPtr() const
Get the region used (always returns 0)
virtual IPosition doNiceCursorShape(uInt maxPixels) const
Return the best cursor shape.
virtual Bool isMasked() const
Has the object really a mask?
void checkNonConcatAxisCoordinates(LogIO &os, const ImageInterface< T > &image, Bool relax)
Double coordConvert(Int &worldAxis, LogIO &os, const CoordinateSystem &cSys, uInt axis, Double pixelCoord) const
virtual Bool ok() const
Check class invariants.
Concatenates images along a specified axis.
Definition: ImageConcat.h:126
virtual void resize(const TiledShape &)
Throws an excpetion as you cannot reshape an ImageConcat object.
virtual Bool doGetSlice(Array< T > &buffer, const Slicer &section)
Do the actual get of the data.
A templated, abstract base class for array-like objects with masks.
Definition: ImageConcat.h:46
ostream-like interface to creating log messages.
Definition: LogIO.h:167
virtual void unlock()
Vector< Double > worldValues_p
Definition: ImageConcat.h:273
virtual Bool doGetMaskSlice(Array< Bool > &buffer, const Slicer &section)
Do the actual get of the mask data.
virtual Bool isPersistent() const
Is the lattice persistent and can it be loaded by other processes as well?
virtual ImageInterface< T > * cloneII() const
Make a copy of the object (reference semantics).
A base class for Lattice iterators.
Definition: ImageExpr.h:46
Define the shape and tile shape.
Definition: TiledShape.h:99
void setLattice(MaskedLattice< T > &lattice)
Add a clone of the lattice to the list to be concatenated.
uInt axis() const
Returns the current concatenation axis (0 relative)
Definition: ImageConcat.h:182
virtual void flush()
Flush the data (but do not unlock).
A base class for astronomical images.
virtual Bool lock(FileLocker::LockType, uInt nattempts)
Handle the (un)locking and syncing, etc.
Class to hold a collection of JSON key:value pairs.
Definition: JsonKVMap.h:69
double Double
Definition: aipstype.h:55
virtual void resync()
Resynchronize the Lattice object with the lattice file.
virtual String imageType() const
Get the image type (returns name of derived class).
virtual void save(const String &fileName) const
Save the image in file &#39;image.concat&#39; in a directory with the given name.
virtual LatticeIterInterface< T > * makeIter(const LatticeNavigator &navigator, Bool useRef) const
These are the implementations of the LatticeIterator letters.
bool Bool
Define the standard types used by Casacore.
Definition: aipstype.h:42
virtual const Lattice< Bool > & pixelMask() const
Get access to the pixelmask.
const Bool False
Definition: aipstype.h:44
Vector< Double > pixelValues_p
Definition: ImageConcat.h:272
void setCoordinates()
Updates the CoordinateSystem in the ImageConcat image.
ImageConcat< T > & operator=(const ImageConcat< T > &other)
Assignment operator (reference semantics)
template <class T, class U> class vector;
Definition: Array.h:169
Type
This enum lists the types of the derived classes.
Definition: Coordinate.h:144
virtual void reopen()
Explicitly reopen the temporarily closed lattice.
virtual IPosition shape() const
Return the shape of the concatenated image.
Specify which elements to extract from an n-dimensional array.
Definition: Slicer.h:289
uInt nimages() const
Return the number of images/lattices set so far.
Definition: ImageConcat.h:178
Vector< Int > makeNewStokes(const Vector< Int > &stokes1, const Vector< Int > &stokes2)
virtual String name(Bool stripPath=False) const
Return the name of the current ImageInterface object.
void _checkContiguous(const IPosition &shape1, const CoordinateSystem &cSys1, const CoordinateSystem &cSys2, LogIO &os, uInt axis, Bool relax)
uInt imageDim() const
Returns the number of dimensions of the input images/lattices Returns 0 if none yet set...
Definition: ImageConcat.h:187
String: the storage and methods of handling collections of characters.
Definition: String.h:223
An optionally strided region in a Lattice.
Definition: LatticeRegion.h:74
virtual Bool hasPixelMask() const
Does the image have a pixelmask?
LatticeConcat< T > latticeConcat_p
Definition: ImageConcat.h:266
virtual void tempClose()
Temporarily close the lattice.
LockType
Define the possible lock types.
Definition: FileLocker.h:95
virtual Bool hasLock(FileLocker::LockType) const
Vector< Bool > isImage_p
Definition: ImageConcat.h:271
const Bool True
Definition: aipstype.h:43
this file contains all the compiler specific defines
Definition: mainpage.dox:28
Interconvert pixel and world coordinates.
unsigned int uInt
Definition: aipstype.h:51
Abstract base class to steer lattice iterators.
void setImage(ImageInterface< T > &image, Bool relax)
Sets a new image into the list to be concatenated.
ImageConcat()
Default constructor, Sets the concatenation axis to 0.