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