casacore
Loading...
Searching...
No Matches
ArrayLattice.h
Go to the documentation of this file.
1// # ArrayLattice: Object which converts an Array to a Lattice.
2// # Copyright (C) 1994,1995,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_ARRAYLATTICE_H
27#define LATTICES_ARRAYLATTICE_H
28
29// # Includes
30#include <casacore/casa/aips.h>
31#include <casacore/lattices/Lattices/Lattice.h>
32#include <casacore/casa/Arrays/Array.h>
33
34namespace casacore { // # NAMESPACE CASACORE - BEGIN
35
36// <summary>
37// A memory resident Lattice
38// </summary>
39
40// <use visibility=export>
41
42// <reviewed reviewer="Peter Barnes" date="1999/10/30" tests="tArrayLattice" demos="">
43// </reviewed>
44
45// <prerequisite>
46// <li> <linkto class=Lattice>Lattice</linkto>
47// <li> <linkto class=Array>Array</linkto>
48// </prerequisite>
49
50// <etymology>
51// The ArrayLattice name reflects its role as a Lattice interface to an Array
52// object.
53// </etymology>
54
55// <synopsis>
56// An ArrayLattice is a concrete Lattice class where the data is stored in
57// memory as opposed to the <linkto class=PagedArray>PagedArray</linkto> class
58// where the data is stored on disk. As a result this class is much more
59// suitable to problems which require small Lattices that can fit into the
60// memory of a computer.
61//
62// ArrayLattice imposes another layer of function calls on top of a an
63// Array. As a result they should not be used for generic Array
64// manipulation. They are useful if you have an Array that needs to use
65// Lattice functions or needs to be used with PagedArrays or other Lattice
66// derivatives (like <linkto class=LatticeExpr>LatticeExpr</linkto> or
67// <linkto class=SubLattice>SubLattice</linkto>).
68// For example the LatticeIterator class can iterate through an Array in
69// more ways than any of the ArrayIterator classes can. The examples below
70// illustrate some uses for ArrayLattices.
71// </synopsis>
72
73// <example>
74// All the examples in this section are available in
75// <src>dArrayLattice.cc</src>
76//
77// <h4>Example 1:</h4>
78// In this example an Array of data is converted into an ArrayLattice so that
79// the copyData function can be used to write the data to a PagedArray which
80// will be stored on disk.
81// <srcblock>
82// // make an Array and fill it with data.
83// Array<Float> myArray(IPosition(3, 64, 64, 2));
84// indgen(myArray); // fills the Array with 0,1,2,....,64*64*2-1
85// // construct the ArrayLattice
86// ArrayLattice<Float> myLattice(myArray);
87// // make a PagedArray to store the data on disk
88// PagedArray<Float> myPagedArray(myLattice.shape(), "myTestData.array");
89// // now copy the data onto disk
90// myPagedArray.copyData (myLattice);
91// </srcblock>
92// Note that it could be done in a somewhat simpler way as:
93// <srcblock>
94// // make an Array and fill it with data.
95// Array<Float> myArray(IPosition(3, 64, 64, 2));
96// indgen(myArray); // fills the Array with 0,1,2,....,64*64*2-1
97// // make a PagedArray to store the data on disk
98// PagedArray<Float> myPagedArray(myLattice.shape(), "myTestData.array");
99// // now put the data onto disk
100// myPagedArray.put (myArray);
101// </srcblock>
102//
103// <h4>Example 2:</h4>
104// The <linkto class=ArrayIterator>ArrayIterator</linkto> class (or its
105// derivatives the <linkto class=VectorIterator>VectorIterator</linkto> and the
106// <linkto class=MatrixIterator>MatrixIterator</linkto> classes) do not allow
107// the user to specify a cursor shape. In this example a Cube class will be
108// converted into an ArrayLattice so that an ArrLatticeIter can be used to
109// access the data spectrum by spectrum (assuming the z-axis is frequency).
110//
111// <srcblock>
112// Cube<Float> arr(64,64,128);
113// // assume that the data gets put into the cube somehow
114// // now construct an ArrayLattice from this cube.
115// ArrayLattice<Float> lat(arr);
116// // Construct an iterator that returns the 128-element spectra one at a time
117// ArrLatticeIter<Float> iter(lat, IPosition(3,1,1,128));
118// // construct a Matrix to hold the results
119// Matrix<Float> channelSum(64,64);
120// // and do the summation one spectrum at a time
121// for (iter.reset(); !iter.atEnd(); iter++)
122// channelSum(iter.position().getFirst(2)) = sum(iter.cursor());
123// </srcblock>
124//
125// There are more examples in the <linkto class=Lattice>Lattice</linkto> class
126// and many of the examples in the
127// <linkto class=PagedArray>PagedArray</linkto> class will also be instructive.
128// </example>
129
130// <motivation>
131// We needed a way of creating Lattices but with Casacore Array characteristics.
132// </motivation>
133
134// # <todo asof="1997/05/31">
135// # </todo>
136
137// <linkfrom anchor="ArrayLattice" classes="Lattice PagedArray">
138// <here>ArrayLattice</here> - a memory based Lattice.
139// </linkfrom>
140
141template <class T>
142class ArrayLattice : public Lattice<T> {
143 // # Make members of parent class known.
144 public:
145 using Lattice<T>::ndim;
146
147 public:
148 // The default constructor creates a ArrayLattice that is useless for just
149 // about everything, except that it can be assigned to with the assignment
150 // operator.
152
153 // Construct an ArrayLattice with the specified shape.
154 // It results in a writable lattice.
155 explicit ArrayLattice(const IPosition& shape);
156
157 // Construct an ArrayLattice that references the given Array.
158 // By default it results in a writable lattice.
160
161 // Construct an ArrayLattice that references the given Array.
162 // It results in a non-writable lattice.
164
165 // The copy constructor uses reference semantics.
167
168 virtual ~ArrayLattice();
169
170 // The assignment operator uses copy semantics.
172
173 // Make a copy of the object (reference semantics).
174 virtual Lattice<T>* clone() const;
175
176 // The lattice data can be referenced as an array section.
177 virtual Bool canReferenceArray() const;
178
179 // Is the lattice writable?
180 virtual Bool isWritable() const;
181
182 // returns the shape of the ArrayLattice.
183 virtual IPosition shape() const;
184
185 // Set all of the elements in the Lattice to a value.
186 virtual void set(const T& value);
187
188 // Return the Array of the data within this Lattice.
189 // <group>
191 const Array<T>& asArray() const;
192 // </group>
193
194 // Return the value of the single element located at the argument
195 // IPosition.
196 // Note that operator() (defined in the base class) can also be used.
197 virtual T getAt(const IPosition& where) const;
198
199 // Put the value of a single element.
200 virtual void putAt(const T& value, const IPosition& where);
201
202 // Check for internal consistency. Returns False if
203 // something nasty has happened to the ArrayLattice.
204 virtual Bool ok() const;
205
206 // Returns the maximum recommended number of pixels for a cursor.
207 // For this class this is equal to the number of pixels in the lattice.
208 virtual uInt advisedMaxPixels() const;
209
210 // Get a slice in an optimized way (specifically for ArrLatticeIter).
211 // It returns in <src>buffer</src> a reference to the lattice array.
212 void getIterSlice(Array<T>& buffer, const IPosition& start, const IPosition& end,
213 const IPosition& incr);
214
215 protected:
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 putting of an array of values.
220 virtual void doPutSlice(const Array<T>& sourceBuffer, const IPosition& where,
221 const IPosition& stride);
222
223 private:
226};
227
228} // namespace casacore
229
230#ifndef CASACORE_NO_AUTO_TEMPLATES
231#include <casacore/lattices/Lattices/ArrayLattice.tcc>
232#endif // # CASACORE_NO_AUTO_TEMPLATES
233#endif
virtual T getAt(const IPosition &where) const
Return the value of the single element located at the argument IPosition.
virtual Bool canReferenceArray() const
The lattice data can be referenced as an array section.
ArrayLattice< T > & operator=(const ArrayLattice< T > &other)
The assignment operator uses copy semantics.
ArrayLattice(Array< T > &array, Bool isWritable=True)
Construct an ArrayLattice that references the given Array.
Array< T > & asArray()
Return the Array of the data within this Lattice.
ArrayLattice(const Array< T > &array)
Construct an ArrayLattice that references the given Array.
virtual Bool doGetSlice(Array< T > &buffer, const Slicer &section)
Do the actual getting of an array of values.
ArrayLattice()
The default constructor creates a ArrayLattice that is useless for just about everything,...
virtual void doPutSlice(const Array< T > &sourceBuffer, const IPosition &where, const IPosition &stride)
Do the actual putting of an array of values.
const Array< T > & asArray() const
ArrayLattice(const ArrayLattice< T > &other)
The copy constructor uses reference semantics.
virtual Bool ok() const
Check for internal consistency.
virtual IPosition shape() const
returns the shape of the ArrayLattice.
ArrayLattice(const IPosition &shape)
Construct an ArrayLattice with the specified shape.
virtual Bool isWritable() const
Is the lattice writable?
void getIterSlice(Array< T > &buffer, const IPosition &start, const IPosition &end, const IPosition &incr)
Get a slice in an optimized way (specifically for ArrLatticeIter).
virtual Lattice< T > * clone() const
Make a copy of the object (reference semantics).
virtual uInt advisedMaxPixels() const
Returns the maximum recommended number of pixels for a cursor.
virtual void putAt(const T &value, const IPosition &where)
Put the value of a single element.
virtual void set(const T &value)
Set all of the elements in the Lattice to a value.
virtual uInt ndim() const
Return the number of axes in this Lattice.
Lattice()
Define default constructor to satisfy compiler.
Definition Lattice.h:390
For temporary backward namespace compatibility, use casa as alias for casacore.
Definition mainpage.dox:28
T * array
The actual storage.
Definition Block.h:689
unsigned int uInt
Definition aipstype.h:49
bool Bool
Define the standard types used by Casacore.
Definition aipstype.h:40
const Bool True
Definition aipstype.h:41
NewDelAllocator< T > NewDelAllocator< T >::value
Definition Allocator.h:360
iterator end()
Definition Block.h:601