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// # Includes
30#include <casacore/casa/aips.h>
31#include <casacore/casa/Arrays/ArrayFwd.h>
32#include <casacore/images/Images/ImageInterface.h>
33#include <casacore/casa/Arrays/AxesSpecifier.h>
34
35namespace casacore { // # NAMESPACE CASACORE - BEGIN
36
37// # Forward Declarations
38class IPosition;
40class Slicer;
41template <class T>
42class SubLattice;
44template <class T>
46class String;
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
83template <class T>
84class SubImage : public ImageInterface<T> {
85 public:
86 // The default constructor
88
89 // Create a SubImage from a Image.
90 // This results in a SubImage without a real mask.
91 // <br>The "const Image" version yields a non-writable SubImage,
92 // while for the non-const version one has to specify if the SubImage
93 // should be writable (if the original image is non-writable, the
94 // SubImage is always set to non-writable).
95 // <br>If preserveAxesOrder is True, the axes order will be preserved. This
96 // is only important in cases where pixel axes are to be dropped, if not
97 // the axes order will be preserved. If False and pixel axes are dropped,
98 // the order of the coordinates will be preserved, but not necessarily
99 // the axes.
100 // <group>
102 Bool preserveAxesOrder = False);
104 Bool preserveAxesOrder = False);
105 // </group>
106
107 // Create a SubImage from the given Image and region.
108 // <br>An exception is thrown if the image shape used in the region
109 // differs from the shape of the image.
110 // <group>
112 AxesSpecifier = AxesSpecifier(), Bool preserveAxesOrder = False);
113 SubImage(ImageInterface<T>& image, const LattRegionHolder& region, Bool writableIfPossible,
114 AxesSpecifier = AxesSpecifier(), Bool preserveAxesOrder = False);
115 // </group>
116
117 // Create a SubImage from the given Image and slicer.
118 // The slicer can be strided.
119 // <br>An exception is thrown if the slicer exceeds the image shape.
120 // <group>
122 Bool preserveAxesOrder = False);
123 SubImage(ImageInterface<T>& image, const Slicer& slicer, Bool writableIfPossible,
124 AxesSpecifier = AxesSpecifier(), Bool preserveAxesOrder = False);
125 // </group>
126
127 // Copy constructor (reference semantics).
128 SubImage(const SubImage<T>& other);
129
130 virtual ~SubImage();
131
132 // Assignment (reference semantics).
134
135 // Make a copy of the object (reference semantics).
136 // <group>
137 virtual ImageInterface<T>* cloneII() const;
138 // </group>
139
140 // Get the image type (returns name of derived class).
141 virtual String imageType() const;
142
143 // Is the SubImage masked?
144 // It is if its parent image or its region is masked.
145 virtual Bool isMasked() const;
146
147 // Does the image object have a pixelmask?
148 // It does if its parent has a pixelmask.
149 virtual Bool hasPixelMask() const;
150
151 // Get access to the pixelmask in use (thus to the pixelmask of the parent).
152 // An exception is thrown if the parent does not have a pixelmask.
153 // <group>
154 virtual const Lattice<Bool>& pixelMask() const;
156 // </group>
157
158 // A SubImage is persistent if no region is applied to the parent image.
159 // That is true if the region has the same shape as the parent image
160 // and the region has no mask.
161 virtual Bool isPersistent() const;
162
163 // Is the SubImage paged to disk?
164 virtual Bool isPaged() const;
165
166 // Can the lattice data be referenced as an array section?
167 virtual Bool canReferenceArray() const;
168
169 // Is the SubImage writable?
170 virtual Bool isWritable() const;
171
172 // Get the region/mask object describing this subImage.
173 virtual const LatticeRegion* getRegionPtr() const;
174
175 // Returns the shape of the SubImage including all degenerate axes
176 // (i.e. axes with a length of one).
177 virtual IPosition shape() const;
178
179 // Returns the number of axes in this SubImage. This includes all
180 // degenerate axes.
181 virtual uInt ndim() const;
182
183 // Returns the total number of elements in this SubImage.
184 virtual size_t nelements() const;
185
186 // returns a value of "True" if this instance of Lattice and 'other' have
187 // the same shape, otherwise returns a value of "False".
188 virtual Bool conform(const Lattice<T>& other) const;
189
190 // This function returns the recommended maximum number of pixels to
191 // include in the cursor of an iterator.
192 virtual uInt advisedMaxPixels() const;
193
194 // Get access to the attribute handler (of the parent image).
195 // If a handler keyword does not exist yet, it is created if
196 // <src>createHandler</src> is set.
197 // Otherwise the handler is empty and no groups can be created for it.
198 virtual ImageAttrHandler& attrHandler(Bool createHandler = False);
199
200 // Get or put a single element in the lattice.
201 // <group>
202 virtual T getAt(const IPosition& where) const;
203 virtual void putAt(const T& value, const IPosition& where);
204 // </group>
205
206 // Function which changes the shape of the SubImage.
207 // Throws an exception as resizing a SubImage is not possible.
208 virtual void resize(const TiledShape& newShape);
209
210 // Return the name of the parent ImageInterface object.
211 virtual String name(Bool stripPath = False) const;
212
213 // Check class invariants.
214 virtual Bool ok() const;
215
216 // Do the actual getting of an array of values.
217 virtual Bool doGetSlice(Array<T>& buffer, const Slicer& section);
218
219 // Do the actual getting of an array of values.
220 virtual void doPutSlice(const Array<T>& sourceBuffer, const IPosition& where,
221 const IPosition& stride);
222
223 // Get a section of the mask.
224 virtual Bool doGetMaskSlice(Array<Bool>& buffer, const Slicer& section);
225
226 // This function is used by the LatticeIterator class to generate an
227 // iterator of the correct type for this Lattice. Not recommended
228 // for general use.
229 virtual LatticeIterInterface<T>* makeIter(const LatticeNavigator& navigator, Bool useRef) const;
230
231 // Get the best cursor shape.
232 virtual IPosition doNiceCursorShape(uInt maxPixels) const;
233
234 // Handle the (un)locking and syncing, etc.
235 // <group>
236 virtual Bool lock(FileLocker::LockType, uInt nattempts);
237 virtual void unlock();
239 virtual void resync();
240 virtual void flush();
241 virtual void tempClose();
242 virtual void reopen();
243 // </group>
244
245 private:
246 // Set the coordinates.
247 // It removes world axes if the subimage has axes removed.
248 // <br>If preserveAxesOrder is True and axes are dropped, it will preserve
249 // the order of the axes as well as the order of the coordinates.
250 void setCoords(const CoordinateSystem& coords, Bool preserveAxesOrder);
251 void setCoords(const CoordinateSystem& coords);
252
253 // Set the other members to the one in itsImagePtr.
255
256 // Set the members to the subset (in particular, the beamset).
257 void setMembers(const Slicer& slicer);
258
259 // Helper
260 void convertIPosition(Vector<Float>& x, const IPosition& pos) const;
261
262 // # itsImagePtr points to the parent image.
265
266 // # Make members of parent class known.
267 public:
268 using ImageInterface<T>::logger;
269
270 protected:
272};
273
274// # Declare extern templates for often used types.
275extern template class SubImage<Float>;
276extern template class SubImage<Complex>;
277
278} // namespace casacore
279
280#ifndef CASACORE_NO_AUTO_TEMPLATES
281#include <casacore/images/Images/SubImage.tcc>
282#endif // # CASACORE_NO_AUTO_TEMPLATES
283#endif
LockType
Define the possible lock types.
Definition FileLocker.h:89
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:355
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?
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:264
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:263
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?
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.
For temporary backward namespace compatibility, use casa as alias for casacore.
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
NewDelAllocator< T > NewDelAllocator< T >::value
Definition Allocator.h:360