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