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