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/lattices/Lattices/Lattice.h>
37 #include <casacore/lattices/Lattices/LatticeConcat.h>
38 #include <casacore/images/Images/ImageInterface.h>
39 
40 namespace casacore { //# NAMESPACE CASACORE - BEGIN
41 
42 //# Forward Declarations
43 class CoordinateSystem;
44 template <class T> class ImageSummary;
45 template <class T> class MaskedLattice;
46 
47 
48 // <summary>
49 // Concatenates images along a specified axis
50 // </summary>
51 
52 // <use visibility=export>
53 
54 // <reviewed reviewer="" date="yyyy/mm/dd" tests="" demos="">
55 // </reviewed>
56 
57 // <prerequisite>
58 // <li> <linkto class=LatticeConcat>LatticeConcat</linkto>
59 // <li> <linkto class=ImageInterface>ImageInterface</linkto>
60 // </prerequisite>
61 
62 // <etymology>
63 // This is a class designed to concatenate images along a specified axis
64 // </etymology>
65 
66 // <synopsis>
67 // This is a class designed to concatenate images along a specified
68 // axis. This means you can join them together. E.g.,
69 // join images of shape [10,20,30] and [10,20,40] into a lattice
70 // of shape [10,20,70].
71 //
72 // The ImageConcat object does not copy the input images, it
73 // just references them. You can use the Lattice<T>::copyData(Lattice<T>)
74 // function to fill an output image with the concatenated input images
75 //
76 // If you use the putSlice function, be aware that it will change the
77 // underlying images if they are writable.
78 //
79 // You can also concatenate a lattice to an image.
80 // </synopsis>
81 //
82 // <example>
83 // <srcblock>
84 // IPosition shape(2, 10, 20);
85 // PagedImage<Float> im1(shape, CoordinateUtil::defaultCoords2D(),
86 // "tImageConcat_tmp1.img");
87 // im1.set(1.0);
88 // PagedImage<Float> im2(shape, CoordinateUtil::defaultCoords2D(),
89 // "tImageConcat_tmp2.img");
90 // im2.set(2.0);
91 //
93 //
94 // ImageConcat<Float> concat(0);
95 //
97 //
98 // concat.setImage(im1, True);
99 // concat.setImage(im2, True);
100 //
102 //
103 // PagedImage<Float> im3(concat.shape(), CoordinateUtil::defaultCoords2D(),
104 // "tImageConcat_tmp3.img");
105 //
107 //
108 // im3.copyData(concat);
109 //
110 // </srcblock>
111 // See tImageConcat.cc for more examples.
112 // </example>
113 
114 
115 // <motivation>
116 // Image concatentation is a useful enduser requirement.
117 // </motivation>
118 
119 // <todo asof="1999/10/23">
120 // <li> Offer the ability to increase the dimensionality of
121 // the output image
122 // </todo>
123 
124 
125 template <class T> class ImageConcat : public ImageInterface<T>
126 {
127 public:
128 
129 // Constructor. Specify the pixel axis for concatenation
130  explicit ImageConcat (uInt axis, Bool tempClose=True);
131 
132 // Construct the object from an AipsIO file with the given name.
133  ImageConcat (AipsIO& aio, const String& fileName);
134 
135 // Default constructor, Sets the concatenation axis to 0
136  ImageConcat();
137 
138 // Copy constructor (reference semantics)
139  ImageConcat (const ImageConcat<T> &other);
140 
141 // Destructor
142  virtual ~ImageConcat();
143 
144 // Assignment operator (reference semantics)
146 
147 // Make a copy of the object (reference semantics).
148  virtual ImageInterface<T>* cloneII() const;
149 
150 // Save the image in an AipsIO file with the given name.
151 // It can be opened by the constructor taking a file name.
152  virtual void save (const String& fileName) const;
153 
154 // Get the image type (returns name of derived class).
155  virtual String imageType() const;
156 
157 // Is the lattice persistent and can it be loaded by other processes as well?
158  virtual Bool isPersistent() const;
159 
160 // Sets a new image into the list to be concatenated.
161 // If relax is False, throws an exception if the images
162 // are not contiguous along the concatenation axis.
163 // If relax is True, it will create a non-regular TabularCoordinate
164 // for non-contiguous images if the coordinates are monotonic.
165 // Otherwise, it just uses the coordinates of the image
166  void setImage (ImageInterface<T>& image, Bool relax);
167 
168 // Add a clone of the lattice to the list to be concatenated.
169 // You can only concatenate a lattice with an image if
170 // you have first used setImage to set an image (this
171 // provides the CooridinateSystem information)
172  void setLattice (MaskedLattice<T>& lattice);
173 
174 // Return the number of images/lattices set so far
175  uInt nimages() const
176  { return latticeConcat_p.nlattices(); }
177 
178 // Returns the current concatenation axis (0 relative)
179  uInt axis () const
180  { return latticeConcat_p.axis(); }
181 
182 // Returns the number of dimensions of the *input* images/lattices
183 // Returns 0 if none yet set.
184  uInt imageDim() const
185  { return latticeConcat_p.latticeDim(); }
186 
187 // Handle the (un)locking and syncing, etc.
188 // <group>
189  virtual Bool lock (FileLocker::LockType, uInt nattempts);
190  virtual void unlock();
191  virtual Bool hasLock (FileLocker::LockType) const;
192  virtual void resync();
193  virtual void flush();
194  virtual void tempClose();
195  virtual void reopen();
196 // </group>
197 
198 // Return the name of the current ImageInterface object.
199 // If the object is persistent, it returns its file name.
200 // Otherwise it returns the string "Concatenation :"
201  virtual String name (Bool stripPath=False) const;
202 
203 // Has the object really a mask?
204  virtual Bool isMasked() const;
205 
206 // Does the image have a pixelmask?
207  virtual Bool hasPixelMask() const;
208 
209 // Get access to the pixelmask.
210 // An exception is thrown if the image does not have a pixelmask
211 // <group>
212  virtual const Lattice<Bool>& pixelMask() const;
213  virtual Lattice<Bool>& pixelMask();
214  // </group>
215 
216 // Get the region used (always returns 0)
217  virtual const LatticeRegion* getRegionPtr() const;
218 
219 // If all of the underlying lattices are writable returns True
220  virtual Bool isWritable() const;
221 
222 // Return the shape of the concatenated image
223  virtual IPosition shape() const;
224 
225 
226 // Return the best cursor shape. This isn't very meaningful for an ImageConcat
227 // Image since it isn't on disk ! But if you do copy it out, this is
228 // what you should use. The maxPixels aregument is ignored.
229  virtual IPosition doNiceCursorShape (uInt maxPixels) const;
230 
231 // Do the actual get of the data.
232 // The return value is always False, thus the buffer does not reference
233 // another array. Generally the user should use function getSlice
234  virtual Bool doGetSlice (Array<T>& buffer, const Slicer& section);
235 
236 // Do the actual get of the mask data.
237 // The return value is always False, thus the buffer does not reference
238 // another array. Generally the user should use function getMaskSlice
239  virtual Bool doGetMaskSlice (Array<Bool>& buffer, const Slicer& section);
240 
241 // Do the actual put of the data into the Lattice. This will change the
242 // underlying images (if they are writable) that were used to create the
243 // ImageConcat object. It throws an exception if not writable.
244 // Generally the user should use function putSlice
245  virtual void doPutSlice (const Array<T>& sourceBuffer,
246  const IPosition& where,
247  const IPosition& stride);
248 
249 // Throws an excpetion as you cannot reshape an ImageConcat object
250  virtual void resize(const TiledShape&);
251 
252 // Check class invariants.
253  virtual Bool ok() const;
254 
255 // These are the implementations of the LatticeIterator letters.
256 // <note> not for public use </note>
258  (const LatticeNavigator &navigator,
259  Bool useRef) const;
260 
261 
262 private:
267  mutable String fileName_p; // Empty if not persistent
272 
273  Double coordConvert(Int& worldAxis, LogIO& os,
274  const CoordinateSystem& cSys,
275  uInt axis, Double pixelCoord) const;
276 
277  void _checkContiguous(const IPosition& shape1,
278  const CoordinateSystem& cSys1,
279  const CoordinateSystem& cSys2,
280  LogIO& os, uInt axis, Bool relax);
281 
283  const ImageInterface<T>& image,
284  Bool relax);
285 
286  Vector<Int> makeNewStokes(const Vector<Int>& stokes1,
287  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
293  void setCoordinates();
294 
296 
297  //# Make members of parent class known.
298 public:
303 protected:
306 };
307 
308 
309 
310 } //# NAMESPACE CASACORE - END
311 
312 #ifndef CASACORE_NO_AUTO_TEMPLATES
313 #include <casacore/images/Images/ImageConcat.tcc>
314 #endif //# CASACORE_NO_AUTO_TEMPLATES
315 #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:47
Coordinate::Type originalAxisType_p
Definition: ImageConcat.h:271
Provides and lists information about the header of an image.
Definition: ImageConcat.h:44
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)
AipsIO is the object persistency mechanism of Casacore.
Definition: AipsIO.h:168
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:125
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:45
ostream-like interface to creating log messages.
Definition: LogIO.h:167
virtual void unlock()
Vector< Double > worldValues_p
Definition: ImageConcat.h:270
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:179
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.
double Double
Definition: aipstype.h:52
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 an AipsIO file 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:39
virtual const Lattice< Bool > & pixelMask() const
Get access to the pixelmask.
const Bool False
Definition: aipstype.h:41
Vector< Double > pixelValues_p
Definition: ImageConcat.h:269
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:275
uInt nimages() const
Return the number of images/lattices set so far.
Definition: ImageConcat.h:175
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:184
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:263
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:268
const Bool True
Definition: aipstype.h:40
this file contains all the compiler specific defines
Definition: mainpage.dox:28
Interconvert pixel and world coordinates.
unsigned int uInt
Definition: aipstype.h:48
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.