casacore
Loading...
Searching...
No Matches
LatticeConcat.h
Go to the documentation of this file.
1// # LatticeConcat.h: concatenate lattices along an axis
2// # Copyright (C) 1996,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_LATTICECONCAT_H
27#define LATTICES_LATTICECONCAT_H
28
29// # Includes
30#include <casacore/casa/aips.h>
31#include <casacore/lattices/Lattices/MaskedLattice.h>
32#include <casacore/casa/Containers/Block.h>
33
34namespace casacore { // # NAMESPACE CASACORE - BEGIN
35
36// # Forward Declarations
37class IPosition;
38class Slicer;
39
40// <summary>
41// Concatenates lattices along a specified axis
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=MaskedLattice>MaskedLattice</linkto> (base class)
51// </prerequisite>
52
53// <etymology>
54// This is a class designed to concatenate lattices along a specified axis
55// </etymology>
56
57// <synopsis>
58// This is a class designed to concatenate lattices along a specified
59// axis. This means you can join them together. E.g.,
60// join lattices of shape [10,20,30] and [10,20,40] into a lattice
61// of shape [10,20,70].
62//
63// In addition, you can increase the dimensionality
64// and join lattices [10,20] and [10,20] to [10,20,2]. This is
65// done by specifying the concatenation axis to be higher than
66// currently exists in the input lattices
67//
68// The LatticeConcat object does not copy the input lattices, it
69// just references them. You can use the Lattice<T>::copyData(Lattice<T>)
70// function to fill an output lattice with the concatenated input lattices.
71//
72// If you use the putSlice function, be aware that it will change the
73// underlying lattices if they are writable.
74// </synopsis>
75//
76// <example>
77// <srcBlock>
78//
80//
81// ArrayLattice<Float> al1(a1); al1.set(1.0);
82// ArrayLattice<Float> al2(a2); al2.set(10.0);
83//
85//
86// SubLattice<Float> ml1(al1, True);
87// SubLattice<Float> ml2(al2, True);
88//
90//
91// LatticeConcat<Float> lc (1);
92// lc.setLattice(ml1);
93// lc.setLattice(ml2);
94//
96//
97// ArrayLattice<Float> al3(lc.shape());
98// SubLattice<Float> ml3(al3, True);
99//
101//
102// ml3.copyData(lc);
103//
104//
105// </srcBlock>
106// In this example no masks are involved. See tLatticeConcat
107// for more examples.
108// </example>
109
110//
111// <motivation>
112// Image concatentation is a useful enduser requirement. An object of
113// this class is contained by an ImageConcat object.
114// </motivation>
115
116// <todo asof="1999/10/23">
117// </todo>
118
119template <class T>
120class LatticeConcat : public MaskedLattice<T> {
121 public:
122 // Constructor. Argument <src>axis</src> specifies the concatenation
123 // axis (0 relative). If this is one more than the number of axes
124 // in the input lattices (set with function <src>setLattice</src>)
125 // then the resultant concatenated lattice has dimension
126 // one greater than that the input lattices.
127 // Argument <src>tempClose</src> specifies whether you wish
128 // all internal lattice copies to be
129 // opened/closed on demand, rather than just being left open.
130 // This prevents open file limits being reached
132
133 // Default constructor. Sets the concatenation axis to 0
134 // and tempClose is True
136
137 // Copy constructor (reference semantics)
139
140 // Destructor
141 virtual ~LatticeConcat();
142
143 // Assignment operator (reference semantics)
145
146 // Adds a clone of the lattice to the list to be concatenated.
147 // Exception thrown if lattices are incompatible
149
150 // Return the number of lattices set so far
151 uInt nlattices() const { return lattices_p.nelements(); }
152
153 // Returns the current concatenation axis (0 relative)
154 uInt axis() const { return axis_p; }
155
156 // Set the tempClose state.
157 void setTempClose(Bool tmpClose) { tempClose_p = tmpClose; }
158
159 // Returns the tempClose constructor state
160 Bool isTempClose() const { return tempClose_p; }
161
162 // Returns the number of dimensions of the *input* lattices (may be different
163 // by one from output lattice). Returns 0 if none yet set.
165
166 // Return pointer for specified lattice. Do not delete it.
167 MaskedLattice<T>* lattice(uInt i) const { return lattices_p[i]; }
168
169 // Handle the (un)locking and syncing, etc.
170 // <group>
171 virtual Bool lock(FileLocker::LockType, uInt nattempts);
172 virtual void unlock();
174 virtual void resync();
175 virtual void flush();
176 virtual void tempClose();
177 virtual void reopen();
178 // </group>
179
180 // Close/reopen a specific lattice. It is your responsibility to leave the
181 // LatticeConcat object in a fully closed state. So always pair
182 // a reopen with a tempClose.
183 // <group>
184 void tempClose(uInt which);
185 void reopen(uInt which);
186 // </group>
187
188 // Name. Since many lattices may go into the concatenation, the name
189 // is rather meaningless. Returns the string "Concatenation :"
190 virtual String name(Bool stripPath = False) const;
191
192 // Make a copy of the derived object (reference semantics).
193 virtual LatticeConcat<T>* cloneML() const;
194
195 // Has the object really a mask?
196 virtual Bool isMasked() const;
197
198 // Get the region used (always returns 0).
199 virtual const LatticeRegion* getRegionPtr() const;
200
201 // If all of the underlying lattices are writable returns True
202 virtual Bool isWritable() const;
203
204 // Does the lattice have a pixelmask?
205 virtual Bool hasPixelMask() const;
206
207 // Get access to the pixelmask.
208 // An exception is thrown if the lattice does not have a pixelmask
209 // <group>
210 virtual const Lattice<Bool>& pixelMask() const;
212 // </group>
213
214 // Find the shape that the concatenated lattice will be.
215 // Returns a null IPosition if function setLattice has not yet
216 // been called
217 virtual IPosition shape() const;
218
219 // Return the best cursor shape. This isn't very meaningful for a LatticeConcat
220 // Lattice since it isn't on disk ! But if you do copy it out, this is
221 // what you should use. The maxPixels aregument is ignored.
222 virtual IPosition doNiceCursorShape(uInt maxPixels) const;
223
224 // Do the actual get of the data.
225 // The return value is always False, thus the buffer does not reference
226 // another array. Generally the user should use function getSlice
227 virtual Bool doGetSlice(Array<T>& buffer, const Slicer& section);
228
229 // Do the actual get of the mask data.
230 // The return value is always False, thus the buffer does not reference
231 // another array. Generally the user should use function getMaskSlice
232 virtual Bool doGetMaskSlice(Array<Bool>& buffer, const Slicer& section);
233
234 // Do the actual put of the data into the Lattice. This will change the underlying
235 // lattices (if they are writable) that were used to create the
236 // LatticeConcat object. It throws an exception if not writable.
237 // Generally the user should use function putSlice
238 virtual void doPutSlice(const Array<T>& sourceBuffer, const IPosition& where,
239 const IPosition& stride);
240
241 private:
247 //
249 //
250 void setup1(IPosition& blc, IPosition& trc, IPosition& stride, IPosition& blc2, IPosition& trc2,
251 IPosition& blc3, IPosition& trc3, IPosition& stride3, const Slicer& section);
253 const IPosition& blc, const IPosition& trc, const IPosition& stride, Int start);
254 Bool getSlice1(Array<T>& buffer, const Slicer& section, uInt nLattices);
255 Bool getSlice2(Array<T>& buffer, const Slicer& section, uInt nLattices);
256 Bool putSlice1(const Array<T>& buffer, const IPosition& where, const IPosition& stride,
257 uInt nLattices);
258
259 Bool putSlice2(const Array<T>& buffer, const IPosition& where, const IPosition& stride,
260 uInt nLattices);
261 Bool getMaskSlice1(Array<Bool>& buffer, const Slicer& section, uInt nLattices);
262 Bool getMaskSlice2(Array<Bool>& buffer, const Slicer& section, uInt nLattices);
263};
264
265} // namespace casacore
266
267#ifndef CASACORE_NO_AUTO_TEMPLATES
268#include <casacore/lattices/Lattices/LatticeConcat.tcc>
269#endif // # CASACORE_NO_AUTO_TEMPLATES
270#endif
LockType
Define the possible lock types.
Definition FileLocker.h:89
virtual const Lattice< Bool > & pixelMask() const
Get access to the pixelmask.
LatticeConcat< T > & operator=(const LatticeConcat< T > &other)
Assignment operator (reference semantics).
virtual LatticeConcat< T > * cloneML() const
Make a copy of the derived object (reference semantics).
Bool isTempClose() const
Returns the tempClose constructor state.
virtual void tempClose()
Temporarily close the lattice.
LatticeConcat()
Default constructor.
Bool getMaskSlice1(Array< Bool > &buffer, const Slicer &section, uInt nLattices)
Slicer setup2(Bool &first, IPosition &blc2, IPosition &trc2, Int shape2, Int axis, const IPosition &blc, const IPosition &trc, const IPosition &stride, Int start)
virtual IPosition shape() const
Find the shape that the concatenated lattice will be.
Bool getSlice2(Array< T > &buffer, const Slicer &section, uInt nLattices)
virtual ~LatticeConcat()
Destructor.
virtual Bool lock(FileLocker::LockType, uInt nattempts)
Handle the (un)locking and syncing, etc.
virtual void resync()
Resynchronize the Lattice object with the lattice file.
void setup1(IPosition &blc, IPosition &trc, IPosition &stride, IPosition &blc2, IPosition &trc2, IPosition &blc3, IPosition &trc3, IPosition &stride3, const Slicer &section)
virtual Lattice< Bool > & pixelMask()
virtual void reopen()
Explicitly reopen the temporarily closed lattice.
void setTempClose(Bool tmpClose)
Set the tempClose state.
uInt nlattices() const
Return the number of lattices set so far.
virtual void flush()
Flush the data (but do not unlock).
uInt latticeDim() const
Returns the number of dimensions of the input lattices (may be different by one from output lattice).
virtual Bool doGetSlice(Array< T > &buffer, const Slicer &section)
Do the actual get of the data.
void setLattice(MaskedLattice< T > &lattice)
Adds a clone of the lattice to the list to be concatenated.
virtual Bool hasPixelMask() const
Does the lattice have a pixelmask?
Block< MaskedLattice< T > * > lattices_p
LatticeConcat(uInt axis, Bool tempClose=True)
Constructor.
LatticeConcat(const LatticeConcat< T > &other)
Copy constructor (reference semantics).
virtual Bool hasLock(FileLocker::LockType) const
Bool putSlice2(const Array< T > &buffer, const IPosition &where, const IPosition &stride, uInt nLattices)
virtual void unlock()
void reopen(uInt which)
virtual void doPutSlice(const Array< T > &sourceBuffer, const IPosition &where, const IPosition &stride)
Do the actual put of the data into the Lattice.
MaskedLattice< T > * lattice(uInt i) const
Return pointer for specified lattice.
virtual String name(Bool stripPath=False) const
Name.
virtual Bool doGetMaskSlice(Array< Bool > &buffer, const Slicer &section)
Do the actual get of the mask data.
void checkAxis(uInt axis, uInt ndim) const
virtual IPosition doNiceCursorShape(uInt maxPixels) const
Return the best cursor shape.
uInt axis() const
Returns the current concatenation axis (0 relative).
virtual const LatticeRegion * getRegionPtr() const
Get the region used (always returns 0).
Bool getSlice1(Array< T > &buffer, const Slicer &section, uInt nLattices)
Bool getMaskSlice2(Array< Bool > &buffer, const Slicer &section, uInt nLattices)
LatticeConcat< Bool > * pPixelMask_p
virtual Bool isWritable() const
If all of the underlying lattices are writable returns True.
void tempClose(uInt which)
Close/reopen a specific lattice.
Bool putSlice1(const Array< T > &buffer, const IPosition &where, const IPosition &stride, uInt nLattices)
virtual Bool isMasked() const
Has the object really a mask?
MaskedLattice()
Default constructor.
String: the storage and methods of handling collections of characters.
Definition String.h:355
struct Node * first
Definition malloc.h:325
For temporary backward namespace compatibility, use casa as alias for casacore.
Definition mainpage.dox:28
const Bool False
Definition aipstype.h:42
LatticeExprNode ndim(const LatticeExprNode &expr)
1-argument function to get the dimensionality of a lattice.
unsigned int uInt
Definition aipstype.h:49
int Int
Definition aipstype.h:48
bool Bool
Define the standard types used by Casacore.
Definition aipstype.h:40
const Bool True
Definition aipstype.h:41