casacore
LCSlicer.h
Go to the documentation of this file.
1 //# LCSlicer.h: Class to define a rectangular box of interest with strides
2 //# Copyright (C) 1998,1999,2001
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_LCSLICER_H
29 #define LATTICES_LCSLICER_H
30 
31 //# Includes
32 #include <casacore/casa/aips.h>
33 #include <casacore/lattices/LRegions/RegionType.h>
34 #include <casacore/casa/Arrays/Vector.h>
35 #include <casacore/casa/BasicSL/String.h>
36 
37 namespace casacore { //# NAMESPACE CASACORE - BEGIN
38 
39 //# Forward Declarations
40 class IPosition;
41 class Slicer;
42 class TableRecord;
43 
44 
45 // <summary>
46 // Class to define a rectangular box of interest with strides.
47 // </summary>
48 
49 // <use visibility=export>
50 
51 // <reviewed reviewer="" date="" tests="">
52 // </reviewed>
53 
54 // <prerequisite>
55 // <li> <linkto class=Slicer>Slicer</linkto>
56 // </prerequisite>
57 
58 // <synopsis>
59 // The LCSlicer makes it possible to define a rectangular box
60 // with strides. Note that this class is not derived from
61 // <linkto class=LCRegion>LCRegion</linkto>, so it cannot be used in
62 // a compound region object like <linkto class=LCUnion>LCUnion</linkto>.
63 // The reason is that strides make it impossible to use a region
64 // in a compound.
65 // <br>
66 // The slicer region can be defined from an
67 // <linkto class=Slicer>Slicer</linkto> object defining the blc/trc
68 // and a vector (of the same length) containing the strides.
69 // The LCSlicer can be of any type (thus relative, fractional, unspecified),
70 // while the strides can be defined as a number or a fraction.
71 // <br>
72 // It is also possible to construct it directly from a
73 // <linkto class=Slicer>Slicer</linkto> object,
74 // </synopsis>
75 
76 // <example>
77 // <srcblock>
78 // </srcblock>
79 // </example>
80 
81 // <todo asof="1997/11/11">
82 // </todo>
83 
84 class LCSlicer
85 {
86 public:
87  LCSlicer();
88 
89  // Construct a slicer from the blc, trc, and stride (default 1).
90  // The vectors can be different in lengths. The longest determines
91  // the dimensionality of the region. The shorter ones get padded
92  // with default values.
93  // <br> For each axis (or all axes) it can be defined if the blc/trc are
94  // given as pixel coordinates or as fractional values between 0 and 1. In the
95  // latter case the true pixel coordinate is derived from the image shape.
96  // <br> Also the region type can be given, if needed per axis.
97  // <ul>
98  // <li> RegionType::Abs is absolute
99  // <li> RegionType::RelRef is relative to reference pixel given in toSlice().
100  // <li> RegionType::RelCen is relative to image center.
101  // </ul>
102  // <group>
103  LCSlicer (const Vector<Float>& blc, const Vector<Float>& trc,
104  Bool fractionalBlcTrc = False,
106  LCSlicer (const Vector<Float>& blc, const Vector<Float>& trc,
107  const Vector<Float>& inc, Bool fractionalBlcTrc = False,
109  LCSlicer (const Vector<Float>& blc, const Vector<Float>& trc,
110  const Vector<Float>& inc,
111  const Vector<Bool>& fractionalBlc,
112  const Vector<Bool>& fractionalTrc,
113  const Vector<Bool>& fractionalInc,
114  const Vector<Int>& absRelBlc,
115  const Vector<Int>& absRelTrc);
116  LCSlicer (const Vector<Double>& blc, const Vector<Double>& trc,
117  Bool fractionalBlcTrc = False,
119  LCSlicer (const Vector<Double>& blc, const Vector<Double>& trc,
120  const Vector<Double>& inc, Bool fractionalBlcTrc = False,
122  LCSlicer (const Vector<Double>& blc, const Vector<Double>& trc,
123  const Vector<Double>& inc,
124  const Vector<Bool>& fractionalBlc,
125  const Vector<Bool>& fractionalTrc,
126  const Vector<Bool>& fractionalInc,
127  const Vector<Int>& absRelBlc,
128  const Vector<Int>& absRelTrc);
129  LCSlicer (const Slicer& slicer);
130  LCSlicer (const IPosition& blc, const IPosition& trc,
132  LCSlicer (const IPosition& blc, const IPosition& trc,
133  const IPosition& inc,
135  LCSlicer (const IPosition& blc, const IPosition& trc,
136  const IPosition& inc,
137  const Vector<Int>& absRelBlc,
138  const Vector<Int>& absRelTrc);
139  // </group>
140 
141  // Copy constructor (reference semantics).
142  LCSlicer (const LCSlicer& other);
143 
144  ~LCSlicer();
145 
146  // Assignment (copy semantics).
147  LCSlicer& operator= (const LCSlicer& other);
148 
149  // Test for equality.
150  // True is returned when the given region is a slicer with exactly
151  // the same specification as this slicer.
152  // It does not compare the comment.
153  // <group>
154  Bool operator== (const LCSlicer& other) const;
155  Bool operator!= (const LCSlicer& other) const;
156  // </group>
157 
158  // The region is completely specified if it is absolute, not fractional,
159  // and has no unspecified values.
160  Bool isComplete() const;
161 
162  // Get the dimensionality of the region.
163  uInt ndim() const;
164 
165  // Simple accessor functions.
166  // <group>
167  const Vector<Float>& blc() const;
168  const Vector<Float>& trc() const;
169  const Vector<Float>& inc() const;
170  Bool isFractional() const;
171  Bool isAbsolute() const;
172  Bool isUnspecified() const;
173  Bool isStrided() const;
174  // </group>
175 
176  // Get the class name (to store in the record).
177  static String className();
178 
179  // Get the region type. Returns className().
180  String type() const;
181 
182  // Get or set the comment.
183  // <group>
184  const String& comment() const;
185  void setComment (const String& comment);
186  // </group>
187 
188  // Make the region complete using the given reference pixel
189  // and shape. It returns a new region where the relative regions
190  // are made absolute by translating them with respect to the
191  // reference pixel. Furthermore unspecified values are filled
192  // in and fractional values are turned into absolute ones.
193  // <group>
194  Slicer toSlicer (const IPosition& referencePixel,
195  const IPosition& latticeShape) const;
196  Slicer toSlicer (const Vector<Double>& referencePixel,
197  const IPosition& latticeShape) const;
198  Slicer toSlicer (const Vector<Float>& referencePixel,
199  const IPosition& newLatticeShape) const;
200  // </group>
201 
202  // Convert the object to a record.
203  TableRecord toRecord (const String& tableName) const;
204 
205  // Convert to correct object from a record.
206  static LCSlicer* fromRecord (const TableRecord&,
207  const String& tablename);
208 
209 private:
210  // Fill the pixel based flags from the general ones.
211  void fillFlags (Bool fractional, Int absRel,
212  uInt nrblc, uInt nrtrc, uInt nrinc);
213 
214  // Fill the vectors from the values given as doubles.
215  void fillFromDouble (const Vector<Double>& blc,
216  const Vector<Double>& trc,
217  const Vector<Double>& inc);
218 
219  // Fill the vectors from the values given as IPositions.
220  void fillFromIPosition (const IPosition& blc,
221  const IPosition& trc,
222  const IPosition& inc);
223 
224  // Fill the remaining variables.
225  // It also adjust the lengths of the vectors if they are different.
226  // Check if everything is given correctly.
227  void fill();
228 
229  //# Variables
243 };
244 
245 
246 inline Bool LCSlicer::operator!= (const LCSlicer& other) const
247 {
248  return (! operator==(other));
249 }
250 inline uInt LCSlicer::ndim() const
251 {
252  return itsBlc.nelements();
253 }
254 inline const Vector<Float>& LCSlicer::blc() const
255 {
256  return itsBlc;
257 }
258 inline const Vector<Float>& LCSlicer::trc() const
259 {
260  return itsTrc;
261 }
262 inline const Vector<Float>& LCSlicer::inc() const
263 {
264  return itsInc;
265 }
267 {
268  return itsIsFractional;
269 }
271 {
272  return itsIsAbsolute;
273 }
275 {
276  return itsIsUnspecified;
277 }
278 inline Bool LCSlicer::isStrided() const
279 {
280  return itsIsStrided;
281 }
282 inline const String& LCSlicer::comment() const
283 {
284  return itsComment;
285 }
286 inline void LCSlicer::setComment (const String& comment)
287 {
289 }
290 
291 
292 
293 } //# NAMESPACE CASACORE - END
294 
295 #endif
A Vector of integers, for indexing into Array<T> objects.
Definition: IPosition.h:119
void setComment(const String &comment)
Definition: LCSlicer.h:286
int Int
Definition: aipstype.h:47
Bool isAbsolute() const
Definition: LCSlicer.h:270
const String & comment() const
Get or set the comment.
Definition: LCSlicer.h:282
const Vector< Float > & trc() const
Definition: LCSlicer.h:258
size_t nelements() const
How many elements does this array have? Product of all axis lengths.
Definition: ArrayBase.h:99
Vector< Bool > itsFracTrc
Definition: LCSlicer.h:234
Vector< Bool > itsFracInc
Definition: LCSlicer.h:235
Bool isStrided() const
Definition: LCSlicer.h:278
uInt ndim() const
Get the dimensionality of the region.
Definition: LCSlicer.h:250
Vector< Float > itsTrc
Definition: LCSlicer.h:231
Bool isUnspecified() const
Definition: LCSlicer.h:274
static LCSlicer * fromRecord(const TableRecord &, const String &tablename)
Convert to correct object from a record.
AbsRelType
Define if a region is absolute or relative.
Definition: RegionType.h:75
Vector< Float > itsInc
Definition: LCSlicer.h:232
Vector< Int > itsAbsRelBlc
Definition: LCSlicer.h:236
void fillFlags(Bool fractional, Int absRel, uInt nrblc, uInt nrtrc, uInt nrinc)
Fill the pixel based flags from the general ones.
Bool isFractional() const
Definition: LCSlicer.h:266
static String className()
Get the class name (to store in the record).
const Vector< Float > & inc() const
Definition: LCSlicer.h:262
bool Bool
Define the standard types used by Casacore.
Definition: aipstype.h:39
void fill()
Fill the remaining variables.
Bool operator!=(const LCSlicer &other) const
Definition: LCSlicer.h:246
const Bool False
Definition: aipstype.h:41
A hierarchical collection of named fields of various types.
Definition: TableRecord.h:182
const Vector< Float > & blc() const
Simple accessor functions.
Definition: LCSlicer.h:254
Class to define a rectangular box of interest with strides.
Definition: LCSlicer.h:84
Specify which elements to extract from an n-dimensional array.
Definition: Slicer.h:275
Slicer toSlicer(const IPosition &referencePixel, const IPosition &latticeShape) const
Make the region complete using the given reference pixel and shape.
void fillFromDouble(const Vector< Double > &blc, const Vector< Double > &trc, const Vector< Double > &inc)
Fill the vectors from the values given as doubles.
TableRecord toRecord(const String &tableName) const
Convert the object to a record.
Bool operator==(const LCSlicer &other) const
Test for equality.
String: the storage and methods of handling collections of characters.
Definition: String.h:223
void fillFromIPosition(const IPosition &blc, const IPosition &trc, const IPosition &inc)
Fill the vectors from the values given as IPositions.
Vector< Float > itsBlc
Definition: LCSlicer.h:230
String type() const
Get the region type.
Vector< Int > itsAbsRelTrc
Definition: LCSlicer.h:237
LCSlicer & operator=(const LCSlicer &other)
Assignment (copy semantics).
Bool isComplete() const
The region is completely specified if it is absolute, not fractional, and has no unspecified values...
this file contains all the compiler specific defines
Definition: mainpage.dox:28
unsigned int uInt
Definition: aipstype.h:48
Vector< Bool > itsFracBlc
Definition: LCSlicer.h:233