casacore
Loading...
Searching...
No Matches
SubImage.h
Go to the documentation of this file.
1//# SubImage.h: A (masked) subset of an ImageInterface object
2//# Copyright (C) 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_SUBIMAGE_H
27#define IMAGES_SUBIMAGE_H
28
29
30//# Includes
31#include <casacore/casa/aips.h>
32#include <casacore/casa/Arrays/ArrayFwd.h>
33#include <casacore/images/Images/ImageInterface.h>
34#include <casacore/casa/Arrays/AxesSpecifier.h>
35
36namespace casacore { //# NAMESPACE CASACORE - BEGIN
37
38//# Forward Declarations
39class IPosition;
40class LattRegionHolder;
41class Slicer;
42template <class T> class SubLattice;
43class LatticeNavigator;
44template <class T> class LatticeIterInterface;
45class String;
46
47
48// <summary>
49// A (masked) subset of an ImageInterface object.
50// </summary>
51//
52// <use visibility=export>
53//
54// <reviewed reviewer="" date="" tests="tSubImage.cc">
55// </reviewed>
56//
57// <prerequisite>
58// <li> <linkto class=ImageInterface>ImageInterface</linkto>
59// <li> <linkto class=SubLattice>SubLattice</linkto>
60// </prerequisite>
61//
62// <synopsis>
63// Class SubImage has to be used to apply a region or mask to an image.
64// Several functions are inherited from SubLattice and not declared
65// in this class.
66// <p>
67// Using an <linkto class=AxesSpecifier>AxesSpecifier</linkto> object
68// it is possible to remove some or all degenerate axes (i.e. axes
69// with length 1) to get an image with a lower dimensionality.
70// </synopsis>
71//
72// <example>
73// <srcblock>
74// </srcblock>
75// </example>
76//
77// <motivation>
78// </motivation>
79//
80// <todo asof="1998/02/09">
81// </todo>
82
83
84template <class T> class SubImage: public ImageInterface<T>
85{
86public:
87 // The default constructor
89
90 // Create a SubImage from a Image.
91 // This results in a SubImage without a real mask.
92 // <br>The "const Image" version yields a non-writable SubImage,
93 // while for the non-const version one has to specify if the SubImage
94 // should be writable (if the original image is non-writable, the
95 // SubImage is always set to non-writable).
96 // <br>If preserveAxesOrder is True, the axes order will be preserved. This
97 // is only important in cases where pixel axes are to be dropped, if not
98 // the axes order will be preserved. If False and pixel axes are dropped,
99 // the order of the coordinates will be preserved, but not necessarily
100 // the axes.
101 // <group>
103 AxesSpecifier=AxesSpecifier(), Bool preserveAxesOrder=False);
104 SubImage (ImageInterface<T>& image, Bool writableIfPossible,
105 AxesSpecifier=AxesSpecifier(), Bool preserveAxesOrder=False);
106 // </group>
107
108 // Create a SubImage from the given Image and region.
109 // <br>An exception is thrown if the image shape used in the region
110 // differs from the shape of the image.
111 // <group>
113 AxesSpecifier=AxesSpecifier(), Bool preserveAxesOrder=False);
115 Bool writableIfPossible,
116 AxesSpecifier=AxesSpecifier(), Bool preserveAxesOrder=False);
117 // </group>
118
119 // Create a SubImage from the given Image and slicer.
120 // The slicer can be strided.
121 // <br>An exception is thrown if the slicer exceeds the image shape.
122 // <group>
123 SubImage (const ImageInterface<T>& image, const Slicer& slicer,
124 AxesSpecifier=AxesSpecifier(), Bool preserveAxesOrder=False);
125 SubImage (ImageInterface<T>& image, const Slicer& slicer,
126 Bool writableIfPossible,
127 AxesSpecifier=AxesSpecifier(), Bool preserveAxesOrder=False);
128 // </group>
129
130 // Copy constructor (reference semantics).
131 SubImage (const SubImage<T>& other);
132
133 virtual ~SubImage();
134
135 // Assignment (reference semantics).
137
138 // Make a copy of the object (reference semantics).
139 // <group>
140 virtual ImageInterface<T>* cloneII() const;
141 // </group>
142
143 // Get the image type (returns name of derived class).
144 virtual String imageType() const;
145
146 // Is the SubImage masked?
147 // It is if its parent image or its region is masked.
148 virtual Bool isMasked() const;
149
150 // Does the image object have a pixelmask?
151 // It does if its parent has a pixelmask.
152 virtual Bool hasPixelMask() const;
153
154 // Get access to the pixelmask in use (thus to the pixelmask of the parent).
155 // An exception is thrown if the parent does not have a pixelmask.
156 // <group>
157 virtual const Lattice<Bool>& pixelMask() const;
159 // </group>
160
161 // A SubImage is persistent if no region is applied to the parent image.
162 // That is true if the region has the same shape as the parent image
163 // and the region has no mask.
164 virtual Bool isPersistent() const;
165
166 // Is the SubImage paged to disk?
167 virtual Bool isPaged() const;
168
169 // Can the lattice data be referenced as an array section?
170 virtual Bool canReferenceArray() const;
171
172 // Is the SubImage writable?
173 virtual Bool isWritable() const;
174
175 // Get the region/mask object describing this subImage.
176 virtual const LatticeRegion* getRegionPtr() const;
177
178 // Returns the shape of the SubImage including all degenerate axes
179 // (i.e. axes with a length of one).
180 virtual IPosition shape() const;
181
182 // Returns the number of axes in this SubImage. This includes all
183 // degenerate axes.
184 virtual uInt ndim() const;
185
186 // Returns the total number of elements in this SubImage.
187 virtual size_t nelements() const;
188
189 // returns a value of "True" if this instance of Lattice and 'other' have
190 // the same shape, otherwise returns a value of "False".
191 virtual Bool conform (const Lattice<T>& other) const;
192
193 // This function returns the recommended maximum number of pixels to
194 // include in the cursor of an iterator.
195 virtual uInt advisedMaxPixels() const;
196
197 // Get access to the attribute handler (of the parent image).
198 // If a handler keyword does not exist yet, it is created if
199 // <src>createHandler</src> is set.
200 // Otherwise the handler is empty and no groups can be created for it.
201 virtual ImageAttrHandler& attrHandler (Bool createHandler=False);
202
203 // Get or put a single element in the lattice.
204 // <group>
205 virtual T getAt (const IPosition& where) const;
206 virtual void putAt (const T& value, const IPosition& where);
207 // </group>
208
209 // Function which changes the shape of the SubImage.
210 // Throws an exception as resizing a SubImage is not possible.
211 virtual void resize(const TiledShape& newShape);
212
213 // Return the name of the parent ImageInterface object.
214 virtual String name (Bool stripPath=False) const;
215
216 // Check class invariants.
217 virtual Bool ok() const;
218
219 // Do the actual getting of an array of values.
220 virtual Bool doGetSlice (Array<T>& buffer, const Slicer& section);
221
222 // Do the actual getting of an array of values.
223 virtual void doPutSlice (const Array<T>& sourceBuffer,
224 const IPosition& where,
225 const IPosition& stride);
226
227 // Get a section of the mask.
228 virtual Bool doGetMaskSlice (Array<Bool>& buffer, const Slicer& section);
229
230 // This function is used by the LatticeIterator class to generate an
231 // iterator of the correct type for this Lattice. Not recommended
232 // for general use.
234 (const LatticeNavigator& navigator,
235 Bool useRef) const;
236
237 // Get the best cursor shape.
238 virtual IPosition doNiceCursorShape (uInt maxPixels) const;
239
240 // Handle the (un)locking and syncing, etc.
241 // <group>
242 virtual Bool lock (FileLocker::LockType, uInt nattempts);
243 virtual void unlock();
245 virtual void resync();
246 virtual void flush();
247 virtual void tempClose();
248 virtual void reopen();
249 // </group>
250
251private:
252 // Set the coordinates.
253 // It removes world axes if the subimage has axes removed.
254 // <br>If preserveAxesOrder is True and axes are dropped, it will preserve
255 // the order of the axes as well as the order of the coordinates.
256 void setCoords (const CoordinateSystem& coords, Bool preserveAxesOrder);
257 void setCoords (const CoordinateSystem& coords);
258
259 // Set the other members to the one in itsImagePtr.
261
262 // Set the members to the subset (in particular, the beamset).
263 void setMembers (const Slicer& slicer);
264
265 // Helper
266 void convertIPosition(Vector<Float>& x, const IPosition& pos) const;
267
268
269 //# itsImagePtr points to the parent image.
272
273 //# Make members of parent class known.
274public:
275 using ImageInterface<T>::logger;
276protected:
278};
279
280//# Declare extern templates for often used types.
281 extern template class SubImage<Float>;
282 extern template class SubImage<Complex>;
283
284
285} //# NAMESPACE CASACORE - END
286
287#ifndef CASACORE_NO_AUTO_TEMPLATES
288#include <casacore/images/Images/SubImage.tcc>
289#endif //# CASACORE_NO_AUTO_TEMPLATES
290#endif
LockType
Define the possible lock types.
Definition FileLocker.h:93
void setCoordsMember(const CoordinateSystem &coords)
Set the coordinate system variable.
LoggerHolder & logger()
Get access to the LoggerHolder.
const LatticeRegion & region() const
Get the region used.
String: the storage and methods of handling collections of characters.
Definition String.h:223
SubImage(const ImageInterface< T > &image, const Slicer &slicer, AxesSpecifier=AxesSpecifier(), Bool preserveAxesOrder=False)
Create a SubImage from the given Image and slicer.
virtual Bool doGetMaskSlice(Array< Bool > &buffer, const Slicer &section)
Get a section of the mask.
virtual ImageInterface< T > * cloneII() const
Make a copy of the object (reference semantics).
void setMembers()
Set the other members to the one in itsImagePtr.
virtual Lattice< Bool > & pixelMask()
virtual void unlock()
void convertIPosition(Vector< Float > &x, const IPosition &pos) const
Helper.
SubImage(ImageInterface< T > &image, const LattRegionHolder &region, Bool writableIfPossible, AxesSpecifier=AxesSpecifier(), Bool preserveAxesOrder=False)
SubImage(ImageInterface< T > &image, const Slicer &slicer, Bool writableIfPossible, AxesSpecifier=AxesSpecifier(), Bool preserveAxesOrder=False)
SubImage()
The default constructor.
virtual IPosition doNiceCursorShape(uInt maxPixels) const
Get the best cursor shape.
SubImage(const ImageInterface< T > &image, const LattRegionHolder &region, AxesSpecifier=AxesSpecifier(), Bool preserveAxesOrder=False)
Create a SubImage from the given Image and region.
virtual Bool isPaged() const
Is the SubImage paged to disk?
virtual Bool isPersistent() const
A SubImage is persistent if no region is applied to the parent image.
virtual Bool hasLock(FileLocker::LockType) const
virtual void doPutSlice(const Array< T > &sourceBuffer, const IPosition &where, const IPosition &stride)
Do the actual getting of an array of values.
virtual void resize(const TiledShape &newShape)
Function which changes the shape of the SubImage.
virtual void putAt(const T &value, const IPosition &where)
Put the value of a single element.
virtual Bool hasPixelMask() const
Does the image object have a pixelmask? It does if its parent has a pixelmask.
virtual size_t nelements() const
Returns the total number of elements in this SubImage.
virtual ImageAttrHandler & attrHandler(Bool createHandler=False)
Get access to the attribute handler (of the parent image).
virtual Bool canReferenceArray() const
Can the lattice data be referenced as an array section?
void setCoords(const CoordinateSystem &coords, Bool preserveAxesOrder)
Set the coordinates.
SubLattice< T > * itsSubLatPtr
Definition SubImage.h:271
virtual uInt ndim() const
Returns the number of axes in this SubImage.
SubImage(const ImageInterface< T > &image, AxesSpecifier=AxesSpecifier(), Bool preserveAxesOrder=False)
Create a SubImage from a Image.
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 Bool isWritable() const
Is the SubImage writable?
SubImage(const SubImage< T > &other)
Copy constructor (reference semantics).
virtual void tempClose()
Temporarily close the lattice.
ImageInterface< T > * itsImagePtr
Definition SubImage.h:270
virtual String name(Bool stripPath=False) const
Return the name of the parent ImageInterface object.
void setMembers(const Slicer &slicer)
Set the members to the subset (in particular, the beamset).
virtual T getAt(const IPosition &where) const
Get or put a single element in the lattice.
virtual Bool conform(const Lattice< T > &other) const
returns a value of "True" if this instance of Lattice and 'other' have the same shape,...
virtual Bool isMasked() const
Is the SubImage masked? It is if its parent image or its region is masked.
virtual Bool lock(FileLocker::LockType, uInt nattempts)
Handle the (un)locking and syncing, etc.
virtual LatticeIterInterface< T > * makeIter(const LatticeNavigator &navigator, Bool useRef) const
This function is used by the LatticeIterator class to generate an iterator of the correct type for th...
void setCoords(const CoordinateSystem &coords)
virtual Bool doGetSlice(Array< T > &buffer, const Slicer &section)
Do the actual getting of an array of values.
SubImage(ImageInterface< T > &image, Bool writableIfPossible, AxesSpecifier=AxesSpecifier(), Bool preserveAxesOrder=False)
SubImage< T > & operator=(const SubImage< T > &other)
Assignment (reference semantics).
virtual void reopen()
Explicitly reopen the temporarily closed lattice.
virtual void flush()
Flush the data (but do not unlock).
virtual IPosition shape() const
Returns the shape of the SubImage including all degenerate axes (i.e.
virtual uInt advisedMaxPixels() const
This function returns the recommended maximum number of pixels to include in the cursor of an iterato...
virtual const Lattice< Bool > & pixelMask() const
Get access to the pixelmask in use (thus to the pixelmask of the parent).
virtual Bool ok() const
Check class invariants.
virtual const LatticeRegion * getRegionPtr() const
Get the region/mask object describing this subImage.
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
bool Bool
Define the standard types used by Casacore.
Definition aipstype.h:40
LatticeExprNode value(const LatticeExprNode &expr)
This function returns the value of the expression without a mask.