casacore
Loading...
Searching...
No Matches
SubLattice.h
Go to the documentation of this file.
1// # SubLattice.h: A subset of a Lattice or MaskedLattice
2// # Copyright (C) 1997,1998,1999,2000,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 LATTICES_SUBLATTICE_H
27#define LATTICES_SUBLATTICE_H
28
29// # Includes
30#include <casacore/casa/aips.h>
31#include <casacore/lattices/Lattices/MaskedLattice.h>
32#include <casacore/lattices/LRegions/LatticeRegion.h>
33#include <casacore/casa/Arrays/AxesSpecifier.h>
34#include <casacore/casa/Arrays/AxesMapping.h>
35
36namespace casacore { // # NAMESPACE CASACORE - BEGIN
37
38// # Forward Declarations
39
40// <summary>
41// A subset of a Lattice or MaskedLattice
42// </summary>
43
44// <use visibility=export>
45
46// <reviewed reviewer="" date="yyyy/mm/dd" tests="" demos="">
47// </reviewed>
48
49// <prerequisite>
50// <li> <linkto class="Lattice">Lattice</linkto>
51// <li> <linkto class="LatticeRegion">LatticeRegion</linkto>
52// </prerequisite>
53
54// <synopsis>
55// A SubLattice is a lattice referencing a subset of another lattice
56// by means of a <linkto class="Slicer">Slicer</linkto> object.
57// <br>It is useful when only a subset of a lattice needs to be accessed.
58// <p>
59// When the SubLattice is created from a const <src>Lattice</src> object,
60// it is not writable, thus it can only be used as an rvalue.
61// <p>
62// Using an <linkto class=AxesSpecifier>AxesSpecifier</linkto> object
63// it is possible to remove some or all degenerate axes (i.e. axes
64// with length 1) to get a lattice with a lower dimensionality.
65// </synopsis>
66
67// <example>
68// <srcblock>
69// </srcblock>
70// </example>
71
72// <templating arg=T>
73// <li> Any type that can be used by the Tables System can also be used by
74// this class.
75// </templating>
76
77// # <todo asof="yyyy/mm/dd">
78// # </todo>
79
80template <class T>
81class SubLattice : public MaskedLattice<T> {
82 public:
83 // The default constructor creates a SubLattice that is useless for just
84 // about everything, except that it can be assigned to with the assignment
85 // operator.
87
88 // Create a SubLattice from a Lattice.
89 // This results in a SubLattice without a real mask.
90 // <br>The "const Lattice" version yields a non-writable SubLattice,
91 // while for the non-const version one has to specify if the SubLattice
92 // should be writable (if the original lattice is non-writable, the
93 // SubLattice is always set to non-writable).
94 // <note>In the 2nd case the lattice could have been declared const,
95 // but is not to indicate it can be changed. </note>
96 // <group>
98 SubLattice(Lattice<T>& lattice, Bool writableIfPossible, AxesSpecifier = AxesSpecifier());
99 // </group>
100
101 // Create a SubLattice from a MaskedLattice.
102 // <br>The "const MaskedLattice" version yields a non-writable SubLattice,
103 // while for the non-const version one has to specify if the SubLattice
104 // should be writable (if the original lattice is non-writable, the
105 // SubLattice is always set to non-writable).
106 // <note>In the 2nd case the lattice could have been declared const,
107 // but is not to indicate it can be changed. </note>
108 // <group>
110 SubLattice(MaskedLattice<T>& lattice, Bool writableIfPossible, AxesSpecifier = AxesSpecifier());
111 // </group>
112
113 // Create a SubLattice from the given MaskedLattice and region.
114 // Note that the region can be constructed from an
115 // <linkto class=LCRegion>LCRegion</linkto> object or
116 // <linkto class=Slicer>Slicer</linkto> object (with an optional stride).
117 // <br>An exception is thrown if the lattice shape used in the region
118 // differs from the shape of the lattice.
119 // <note>In the 2nd and 4th case the lattice could have been declared const,
120 // but is not to indicate it can be changed. </note>
121 // <group>
124 SubLattice(Lattice<T>& lattice, const LatticeRegion& region, Bool writableIfPossible,
128 SubLattice(MaskedLattice<T>& lattice, const LatticeRegion& region, Bool writableIfPossible,
130 // </group>
131
132 // Create a SubLattice from the given (Masked)Lattice and slicer.
133 // The slicer can be strided.
134 // <br>An exception is thrown if the slicer exceeds the lattice shape.
135 // <note>In the 2nd and 4th case the lattice could have been declared const,
136 // but is not to indicate it can be changed. </note>
137 // <group>
138 SubLattice(const Lattice<T>& lattice, const Slicer& slicer, AxesSpecifier = AxesSpecifier());
139 SubLattice(Lattice<T>& lattice, const Slicer& slicer, Bool writableIfPossible,
141 SubLattice(const MaskedLattice<T>& lattice, const Slicer& slicer,
143 SubLattice(MaskedLattice<T>& lattice, const Slicer& slicer, Bool writableIfPossible,
145 // </group>
146
147 // Copy constructor (reference semantics).
149
150 virtual ~SubLattice();
151
152 // Assignment (reference semantics).
154
155 // Make a copy of the object (reference semantics).
156 virtual MaskedLattice<T>* cloneML() const;
157
158 // Is the lattice masked?
159 // It is if its parent lattice or its region is masked.
160 virtual Bool isMasked() const;
161
162 // A SubLattice is persistent if no region is applied to the parent lattice.
163 // That is true if the region has the same shape as the parent lattice
164 // and the region has no mask.
165 virtual Bool isPersistent() const;
166
167 // Is the SubLattice paged to disk?
168 virtual Bool isPaged() const;
169
170 // Can the lattice data be referenced as an array section?
171 virtual Bool canReferenceArray() const;
172
173 // Is the SubLattice writable?
174 virtual Bool isWritable() const;
175
176 // Handle locking of the SubLattice which is delegated to its parent.
177 // <br>It is strongly recommended to use class
178 // <linkto class=LatticeLocker>LatticeLocker</linkto> to
179 // handle lattice locking. It also contains a more detailed
180 // explanation of the locking process.
181 // <group>
182 virtual Bool lock(FileLocker::LockType, uInt nattempts);
183 virtual void unlock();
185 // </group>
186
187 // Resynchronize the Lattice object with the lattice file.
188 // This function is only useful if no read-locking is used, ie.
189 // if the table lock option is UserNoReadLocking or AutoNoReadLocking.
190 // In that cases the table system does not acquire a read-lock, thus
191 // does not synchronize itself automatically.
192 virtual void resync();
193
194 // Flush the data.
195 virtual void flush();
196
197 // Close the Lattice temporarily (if it is paged to disk).
198 // It'll be reopened automatically when needed or when
199 // <src>reopen</src> is called explicitly.
200 virtual void tempClose();
201
202 // If needed, reopen a temporarily closed Lattice.
203 virtual void reopen();
204
205 // Does the SubLattice have a pixelmask?
206 virtual Bool hasPixelMask() const;
207
208 // Get access to the pixelmask.
209 // An exception is thrown if the SubLattice does not have a pixelmask.
210 // <group>
211 virtual const Lattice<Bool>& pixelMask() const;
213 // </group>
214
215 // Use the given mask as the pixelmask.
216 // If another mask was already used, the new one will be used instead.
217 // It checks if its shape matches the shape of the sublattice.
218 // <br>If <code>mayExist=False</code>, setting the pixelmask is only
219 // possible if the underlying lattice does not have a pixelmask.
220 // <br>If <code>mayExist=True</code>, the resulting pixelmask is the
221 // AND of the given pixelmask and the pixelmask of the underlying lattice.
222 void setPixelMask(const Lattice<Bool>& pixelMask, Bool mayExist);
223
224 // Get a pointer the region/mask object describing this sublattice.
225 virtual const LatticeRegion* getRegionPtr() const;
226
227 // Returns the shape of the SubLattice including all degenerate axes
228 // (i.e. axes with a length of one).
229 virtual IPosition shape() const;
230
231 // Return the name of the parent lattice.
232 virtual String name(Bool stripPath = False) const;
233
234 // This function returns the recommended maximum number of pixels to
235 // include in the cursor of an iterator.
236 virtual uInt advisedMaxPixels() const;
237
238 // Get or put a single element in the lattice.
239 // <group>
240 virtual T getAt(const IPosition& where) const;
241 virtual void putAt(const T& value, const IPosition& where);
242 // </group>
243
244 // Check class internals - used for debugging. Should always return True
245 virtual Bool ok() const;
246
247 // This function is used by the LatticeIterator class to generate an
248 // iterator of the correct type for this Lattice. Not recommended
249 // for general use.
250 virtual LatticeIterInterface<T>* makeIter(const LatticeNavigator& navigator, Bool useRef) const;
251
252 // Do the actual getting of an array of values.
253 virtual Bool doGetSlice(Array<T>& buffer, const Slicer& section);
254
255 // Do the actual getting of an array of values.
256 virtual void doPutSlice(const Array<T>& sourceBuffer, const IPosition& where,
257 const IPosition& stride);
258
259 // Get a section of the mask.
260 virtual Bool doGetMaskSlice(Array<Bool>& buffer, const Slicer& section);
261
262 // Get the best cursor shape.
263 virtual IPosition doNiceCursorShape(uInt maxPixels) const;
264
265 // Set the axes mapping from the specification.
266 const AxesMapping& getAxesMap() const { return itsAxesMap; }
267
268 // Convert the specified position in the sublattice to the corresponding
269 // position in the parent lattice.
270 IPosition positionInParent(const IPosition& subLatticePosition) const {
271 if (itsAxesMap.isRemoved()) {
272 return itsRegion.convert(itsAxesMap.posToOld(subLatticePosition));
273 } else {
274 return itsRegion.convert(subLatticePosition);
275 }
276 }
277
278 // Set the region object using a slicer.
279 // Allows the region to be changed while keeping
280 // the same lattice, so that new SubLattice objects do not have to be
281 // created when one only wants to change the region of interest. Should
282 // only be called when performance is an issue; otherwise, just create
283 // a new SubLattice<T> object.
284 void setRegion(const Slicer& slicer);
285
286 protected:
287 // Set the region object.
288 // It also fills in the parent pointer when the SubLattice is taken
289 // from a MaskedLattice.
290 // The default region is the entire lattice.
291 // <group>
293 void setRegion();
294 // </group>
295
296 // Set the various pointers needed to construct the object.
297 // One of the pointers should be zero.
298 // It takes over the pointer and deletes the object in the destructor.
299 void setPtr(Lattice<T>* latticePtr, MaskedLattice<T>* maskLatPtr, Bool writableIfPossible);
300
301 // Set the axes mapping from the specification.
303
304 private:
305 // Get mask data from region and mask.
306 // <group>
307 Bool getRegionDataSlice(Array<Bool>& buffer, const Slicer& section);
308 Bool getMaskDataSlice(Array<Bool>& buffer, const Slicer& section);
309 // </group>
310
311 // And tmpbuf into buffer. If buffer is a reference, first a copy is made.
312 void andMask(Array<Bool>& buffer, Bool ref, const Array<Bool>& tmpbuf) const;
313
318 Bool itsHasLattPMask; // # has underlying lattice a pixelmask?
319 Lattice<Bool>* itsPixelMask; // # AND of lattice and own pixelmask
320 Lattice<Bool>* itsOwnPixelMask; // # own pixelmask
323};
324
325// # Declare extern templates for often used types.
326extern template class SubLattice<Bool>;
327extern template class SubLattice<Float>;
328
329} // namespace casacore
330
331#ifndef CASACORE_NO_AUTO_TEMPLATES
332#include <casacore/lattices/Lattices/SubLattice.tcc>
333#endif // # CASACORE_NO_AUTO_TEMPLATES
334#endif
LockType
Define the possible lock types.
Definition FileLocker.h:89
MaskedLattice()
Default constructor.
const LatticeRegion & region() const
Get the region used.
String: the storage and methods of handling collections of characters.
Definition String.h:355
SubLattice(Lattice< T > &lattice, const Slicer &slicer, Bool writableIfPossible, AxesSpecifier=AxesSpecifier())
void setPixelMask(const Lattice< Bool > &pixelMask, Bool mayExist)
Use the given mask as the pixelmask.
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...
SubLattice()
The default constructor creates a SubLattice that is useless for just about everything,...
virtual void tempClose()
Close the Lattice temporarily (if it is paged to disk).
virtual Bool ok() const
Check class internals - used for debugging.
Lattice< Bool > * itsPixelMask
Definition SubLattice.h:319
virtual void flush()
Flush the data.
virtual const Lattice< Bool > & pixelMask() const
Get access to the pixelmask.
virtual Bool hasLock(FileLocker::LockType) const
SubLattice(MaskedLattice< T > &lattice, const LatticeRegion &region, Bool writableIfPossible, AxesSpecifier=AxesSpecifier())
SubLattice(Lattice< T > &lattice, const LatticeRegion &region, Bool writableIfPossible, AxesSpecifier=AxesSpecifier())
virtual void doPutSlice(const Array< T > &sourceBuffer, const IPosition &where, const IPosition &stride)
Do the actual getting of an array of values.
virtual const LatticeRegion * getRegionPtr() const
Get a pointer the region/mask object describing this sublattice.
virtual Bool canReferenceArray() const
Can the lattice data be referenced as an array section?
SubLattice(const Lattice< T > &lattice, const Slicer &slicer, AxesSpecifier=AxesSpecifier())
Create a SubLattice from the given (Masked)Lattice and slicer.
void setRegion(const Slicer &slicer)
Set the region object using a slicer.
IPosition positionInParent(const IPosition &subLatticePosition) const
Convert the specified position in the sublattice to the corresponding position in the parent lattice.
Definition SubLattice.h:270
void andMask(Array< Bool > &buffer, Bool ref, const Array< Bool > &tmpbuf) const
And tmpbuf into buffer.
virtual Bool isPersistent() const
A SubLattice is persistent if no region is applied to the parent lattice.
const AxesMapping & getAxesMap() const
Set the axes mapping from the specification.
Definition SubLattice.h:266
SubLattice(const Lattice< T > &lattice, AxesSpecifier=AxesSpecifier())
Create a SubLattice from a Lattice.
virtual Bool isMasked() const
Is the lattice masked?
virtual void putAt(const T &value, const IPosition &where)
Put the value of a single element.
Bool getMaskDataSlice(Array< Bool > &buffer, const Slicer &section)
virtual IPosition shape() const
Returns the shape of the SubLattice including all degenerate axes (i.e.
void setPtr(Lattice< T > *latticePtr, MaskedLattice< T > *maskLatPtr, Bool writableIfPossible)
Set the various pointers needed to construct the object.
SubLattice(const MaskedLattice< T > &lattice, const LatticeRegion &region, AxesSpecifier=AxesSpecifier())
void setAxesMap(const AxesSpecifier &)
Set the axes mapping from the specification.
virtual T getAt(const IPosition &where) const
Get or put a single element in the lattice.
SubLattice(Lattice< T > &lattice, Bool writableIfPossible, AxesSpecifier=AxesSpecifier())
virtual Bool isPaged() const
Is the SubLattice paged to disk?
virtual Bool hasPixelMask() const
Does the SubLattice have a pixelmask?
SubLattice(const MaskedLattice< T > &lattice, AxesSpecifier=AxesSpecifier())
Create a SubLattice from a MaskedLattice.
SubLattice(MaskedLattice< T > &lattice, const Slicer &slicer, Bool writableIfPossible, AxesSpecifier=AxesSpecifier())
void setRegion(const LatticeRegion &region)
Set the region object.
virtual Bool doGetMaskSlice(Array< Bool > &buffer, const Slicer &section)
Get a section of the mask.
virtual Bool doGetSlice(Array< T > &buffer, const Slicer &section)
Do the actual getting of an array of values.
MaskedLattice< T > * itsMaskLatPtr
Definition SubLattice.h:315
virtual Bool isWritable() const
Is the SubLattice writable?
virtual MaskedLattice< T > * cloneML() const
Make a copy of the object (reference semantics).
virtual void unlock()
virtual String name(Bool stripPath=False) const
Return the name of the parent lattice.
SubLattice< T > & operator=(const SubLattice< T > &other)
Assignment (reference semantics).
virtual Bool lock(FileLocker::LockType, uInt nattempts)
Handle locking of the SubLattice which is delegated to its parent.
virtual uInt advisedMaxPixels() const
This function returns the recommended maximum number of pixels to include in the cursor of an iterato...
Bool getRegionDataSlice(Array< Bool > &buffer, const Slicer &section)
Get mask data from region and mask.
AxesMapping itsAxesMap
Definition SubLattice.h:322
AxesSpecifier itsAxesSpec
Definition SubLattice.h:321
Lattice< Bool > * itsOwnPixelMask
Definition SubLattice.h:320
virtual void reopen()
If needed, reopen a temporarily closed Lattice.
virtual IPosition doNiceCursorShape(uInt maxPixels) const
Get the best cursor shape.
SubLattice(const MaskedLattice< T > &lattice, const Slicer &slicer, AxesSpecifier=AxesSpecifier())
virtual void resync()
Resynchronize the Lattice object with the lattice file.
LatticeRegion itsRegion
Definition SubLattice.h:316
SubLattice(const SubLattice< T > &other)
Copy constructor (reference semantics).
Lattice< T > * itsLatticePtr
Definition SubLattice.h:314
SubLattice(MaskedLattice< T > &lattice, Bool writableIfPossible, AxesSpecifier=AxesSpecifier())
virtual Lattice< Bool > & pixelMask()
SubLattice(const Lattice< T > &lattice, const LatticeRegion &region, AxesSpecifier=AxesSpecifier())
Create a SubLattice from the given MaskedLattice and region.
For temporary backward namespace compatibility, use casa as alias for casacore.
Definition mainpage.dox:28
const RecordRep & ref() const
Return a const reference to the underlying RecordRep.
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