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  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
139  ImageConcat();
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 // Get the image type (returns name of derived class).
163  virtual String imageType() const;
164 
165 // Is the lattice persistent and can it be loaded by other processes as well?
166  virtual Bool isPersistent() const;
167 
168 // Sets a new image into the list to be concatenated.
169 // If relax is False, throws an exception if the images
170 // are not contiguous along the concatenation axis.
171 // If relax is True, it will create a non-regular TabularCoordinate
172 // for non-contiguous images if the coordinates are monotonic.
173 // Otherwise, it just uses the coordinates of the image
174  void setImage (ImageInterface<T>& image, Bool relax);
175 
176 // Add a clone of the lattice to the list to be concatenated.
177 // You can only concatenate a lattice with an image if
178 // you have first used setImage to set an image (this
179 // provides the CooridinateSystem information)
180  void setLattice (MaskedLattice<T>& lattice);
181 
182 // Return the number of images/lattices set so far
183  uInt nimages() const
184  { return latticeConcat_p.nlattices(); }
185 
186 // Returns the current concatenation axis (0 relative)
187  uInt axis () const
188  { return latticeConcat_p.axis(); }
189 
190 // Returns the number of dimensions of the *input* images/lattices
191 // Returns 0 if none yet set.
192  uInt imageDim() const
193  { return latticeConcat_p.latticeDim(); }
194 
195 // Handle the (un)locking and syncing, etc.
196 // <group>
197  virtual Bool lock (FileLocker::LockType, uInt nattempts);
198  virtual void unlock();
199  virtual Bool hasLock (FileLocker::LockType) const;
200  virtual void resync();
201  virtual void flush();
202  virtual void tempClose();
203  virtual void reopen();
204 // </group>
205 
206 // Return the name of the current ImageInterface object.
207 // If the object is persistent, it returns its file name.
208 // Otherwise it returns the string "Concatenation :"
209  virtual String name (Bool stripPath=False) const;
210 
211 // Has the object really a mask?
212  virtual Bool isMasked() const;
213 
214 // Does the image have a pixelmask?
215  virtual Bool hasPixelMask() const;
216 
217 // Get access to the pixelmask.
218 // An exception is thrown if the image does not have a pixelmask
219 // <group>
220  virtual const Lattice<Bool>& pixelMask() const;
221  virtual Lattice<Bool>& pixelMask();
222  // </group>
223 
224 // Get the region used (always returns 0)
225  virtual const LatticeRegion* getRegionPtr() const;
226 
227 // If all of the underlying lattices are writable returns True
228  virtual Bool isWritable() const;
229 
230 // Return the shape of the concatenated image
231  virtual IPosition shape() const;
232 
233 
234 // Return the best cursor shape. This isn't very meaningful for an ImageConcat
235 // Image since it isn't on disk ! But if you do copy it out, this is
236 // what you should use. The maxPixels aregument is ignored.
237  virtual IPosition doNiceCursorShape (uInt maxPixels) const;
238 
239 // Do the actual get of the data.
240 // The return value is always False, thus the buffer does not reference
241 // another array. Generally the user should use function getSlice
242  virtual Bool doGetSlice (Array<T>& buffer, const Slicer& section);
243 
244 // Do the actual get of the mask data.
245 // The return value is always False, thus the buffer does not reference
246 // another array. Generally the user should use function getMaskSlice
247  virtual Bool doGetMaskSlice (Array<Bool>& buffer, const Slicer& section);
248 
249 // Do the actual put of the data into the Lattice. This will change the
250 // underlying images (if they are writable) that were used to create the
251 // ImageConcat object. It throws an exception if not writable.
252 // Generally the user should use function putSlice
253  virtual void doPutSlice (const Array<T>& sourceBuffer,
254  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>
266  (const LatticeNavigator &navigator,
267  Bool useRef) const;
268 
269 
270 private:
276  mutable String fileName_p; // Empty if not persistent
281 
282  Double coordConvert(Int& worldAxis, LogIO& os,
283  const CoordinateSystem& cSys,
284  uInt axis, Double pixelCoord) const;
285 
286  void _checkContiguous(const IPosition& shape1,
287  const CoordinateSystem& cSys1,
288  const CoordinateSystem& cSys2,
289  LogIO& os, uInt axis, Bool relax);
290 
292  const ImageInterface<T>& image,
293  Bool relax);
294 
295  Vector<Int> makeNewStokes(const Vector<Int>& stokes1,
296  const Vector<Int>& stokes2);
297 
298  // Updates the CoordinateSystem in the ImageConcat image. The first lattice must
299  // be an image. The first lattice is contiguous by definition. The Coordinate
300  // System for the first image must be set before calling this function. For
301  // the first image, this function just sets up worldValues and pixelValues
302  void setCoordinates();
303 
305 
306  //# Make members of parent class known.
307 public:
312 protected:
315 };
316 
317 
318 
319 } //# NAMESPACE CASACORE - END
320 
321 #ifndef CASACORE_NO_AUTO_TEMPLATES
322 #include <casacore/images/Images/ImageConcat.tcc>
323 #endif //# CASACORE_NO_AUTO_TEMPLATES
324 #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:280
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.
virtual Bool setMiscInfo(const RecordInterface &newInfo)
Replace the miscinfo in the ConcatImage, which writes the image.concat file.
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:279
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:47
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:187
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:72
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:278
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:183
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:192
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:271
Abstract base class for Record classes.
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:277
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.