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