casacore
Loading...
Searching...
No Matches
LCRegion.h
Go to the documentation of this file.
1//# LCRegion.h: Abstract base class to define a region of interest in lattice coordinates
2//# Copyright (C) 1998,1999,2000,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: 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_LCREGION_H
27#define LATTICES_LCREGION_H
28
29//# Includes
30#include <casacore/casa/aips.h>
31#include <casacore/lattices/Lattices/Lattice.h>
32#include <casacore/casa/Arrays/IPosition.h>
33#include <casacore/casa/Arrays/Slicer.h>
34
35namespace casacore { //# NAMESPACE CASACORE - BEGIN
36
37//# Forward Declarations
38class TableRecord;
39class RecordInterface;
40
41
42// <summary>
43// Abstract base class to define a region of interest in lattice coordinates.
44// </summary>
45
46// <use visibility=export>
47
48// <reviewed reviewer="" date="" tests="">
49// </reviewed>
50
51// <prerequisite>
52// <li> <linkto class=Slicer>Slicer</linkto>
53// </prerequisite>
54
55// <synopsis>
56// The LCRegion class is the abstract base class for various types
57// of LCRegion's (e.g. <linkto class=LCEllipsoid>LCEllipsoid</linkto>,
58// <linkto class=LCBox>LCBox</linkto>).
59// It contains the minimal bounding box of the region and, if needed,
60// a mask with the same shape as the bounding box. A mask element
61// is true if the element is inside the box.
62// <p>
63// Each LCRegion object must be able to convert itself to and from a record.
64// In that way they can be made persistent (in for example a Table).
65// <p>
66// The LCRegion can be used in several Lattices and Images classes and
67// functions to limit the area to operate on.
68// </synopsis>
69
70// <example>
71// <srcblock>
72// </srcblock>
73// </example>
74
75// <motivation>
76// The Slicer class is too limited as a region, because it can only
77// describe a rectangular region. Specialized classes are needed to
78// describe arbitrary regions. They need a base class to combine them.
79// </motivation>
80
81//# <todo asof="1997/11/11">
82//# <li>
83//# </todo>
84
85class LCRegion : public Lattice<Bool>
86{
87public:
89
90 // Construct with the lattice shape only.
92
93 // Copy constructor (copy semantics).
94 LCRegion (const LCRegion& other);
95
96 virtual ~LCRegion();
97
98 // Equality
99 virtual Bool operator== (const LCRegion& other) const;
100
101 // Non-equality. Be careful, do not use this anywhere in the derived
102 // class structure. You must use, e.g.,
103 // <src>if (! LCRegion::operator== (...))</src>
104 // rather than <src>if (LCRegion::operator!= (...))</src> as the
105 // latter will invoke an infinite loop. It is ok to use when applying
106 // to a concrete class object.
107 Bool operator!= (const LCRegion& other) const;
108
109 // Make a copy of the derived object.
110 // <group>
111 virtual Lattice<Bool>* clone() const;
112 virtual LCRegion* cloneRegion() const = 0;
113 // </group>
114
115 // Handle deletion of the region by deleting possible tables.
116 // The default implementation does nothing.
117 virtual void handleDelete();
118
119 // Handle renaming the region by renaming possible tables.
120 // The default implementation does nothing.
121 virtual void handleRename (const String& newName, Bool overwrite);
122
123 // Region type. Returns className() of derived class.
124 virtual String type() const = 0;
125
126 // Get or set the comment.
127 // <group>
128 const String& comment() const;
129 void setComment (const String& comment);
130 // </group>
131
132 // Does the region have a mask?
133 virtual Bool hasMask() const = 0;
134
135 // Construct another LCRegion (for e.g. another lattice) by moving
136 // this one. It recalculates the bounding box and mask.
137 // A positive translation value indicates "to right".
138 // <group>
139 LCRegion* translate (const IPosition& translateVector) const;
140 LCRegion* translate (const IPosition& translateVector,
141 const IPosition& newLatticeShape) const;
142 LCRegion* translate (const Vector<Float>& translateVector) const;
143 LCRegion* translate (const Vector<Float>& translateVector,
144 const IPosition& newLatticeShape) const;
145 // </group>
146
147 // Give the full lattice shape.
148 const IPosition& latticeShape() const;
149
150 // Give the bounding box.
151 const Slicer& boundingBox() const;
152
153 // Expand a slicer or position in the region to the full lattice.
154 // This converts the positions in the region to positions
155 // in the entire lattice.
156 // <group>
157 Slicer expand (const Slicer& slicer) const;
158 IPosition expand (const IPosition& index) const;
159 // </group>
160
161 // Convert the (derived) object to a record.
162 // The record can be used to make the object persistent.
163 // The <src>tableName</src> argument can be used by derived
164 // classes (e.g. LCPagedMask) to put very large objects.
165 virtual TableRecord toRecord (const String& tableName) const = 0;
166
167 // Convert correct object from a record.
169 const String& tableName);
170
171 // Return the dimensionality of the region.
172 virtual uInt ndim() const;
173
174 // Return the shape of the region (i.e. of its bounding box).
175 virtual IPosition shape() const;
176
177 // Usually the lattice (i.e. the region mask) is not writable.
178 virtual Bool isWritable() const;
179
180 // Regions can usually not be put; i.e. no putSlice, etc. can be
181 // done on their masks.
182 // Hence LCRegion throws by default an exception for the
183 // following functions.
184 // <group>
185 virtual void doPutSlice (const Array<Bool>& sourceBuffer,
186 const IPosition& where,
187 const IPosition& stride);
188 virtual void set (const Bool& value);
189 virtual void apply (Bool (*function)(Bool));
190 virtual void apply (Bool (*function)(const Bool&));
191 virtual void apply (const Functional<Bool,Bool>& function);
192 virtual void putAt (const Bool& value, const IPosition& where);
193 virtual void copyData (const Lattice<Bool>& from);
194 // </group>
195
196protected:
197 // Assignment (copy semantics) is only useful for derived classes.
199
200 // Sometimes it is inconvenient for a derived class to set the bounding
201 // box in the constructor. So it can be set explicitly.
202 // It fills in the possibly undefined Slicer values.
203 // It may even be needed to set the lattice shape.
204 // <group>
207 const Slicer& boundingBox);
208 // </group>
209
210 // Do the actual translate in a derived class.
211 virtual LCRegion* doTranslate (const Vector<Float>& translateVector,
212 const IPosition& newLatticeShape) const = 0;
213
214 // Define the type and class name in the record.
216 const String& className) const;
217
218private:
222};
223
224
225inline const Slicer& LCRegion::boundingBox() const
226{
227 return itsBoundingBox;
228}
230{
231 return itsShape;
232}
233inline LCRegion* LCRegion::translate (const IPosition& translateVector) const
234{
235 return translate (translateVector, itsShape);
236}
237inline LCRegion* LCRegion::translate (const Vector<Float>& translateVector)
238 const
239{
240 return translate (translateVector, itsShape);
241}
242inline const String& LCRegion::comment() const
243{
244 return itsComment;
245}
246inline void LCRegion::setComment (const String& comment)
247{
249}
250
251inline Bool LCRegion::operator!= (const LCRegion& other) const
252//
253// Watch out ! You must not, in the derived class structure,
254// invoke LCRegion::operator!= If you do, you will be stuck
255// in a time warp, as this will just fetch the
256// operator== of the concrete class and you start all over again.
257// You must use always use !LCRegion::operator==. It is ok in application
258// code using the concrete class to say
259// if (x != y) where x and y are, say, LCBoxes.
260{
261 return (!operator==(other));
262}
263
264
265
266
267} //# NAMESPACE CASACORE - END
268
269#endif
static LCRegion * fromRecord(const TableRecord &, const String &tableName)
Convert correct object from a record.
virtual Bool operator==(const LCRegion &other) const
Equality
Slicer itsBoundingBox
Definition LCRegion.h:220
virtual Bool isWritable() const
Usually the lattice (i.e.
LCRegion(const LCRegion &other)
Copy constructor (copy semantics).
void setComment(const String &comment)
Definition LCRegion.h:246
virtual String type() const =0
Region type.
LCRegion * translate(const IPosition &translateVector) const
Construct another LCRegion (for e.g.
Definition LCRegion.h:233
void setShapeAndBoundingBox(const IPosition &latticeShape, const Slicer &boundingBox)
void defineRecordFields(RecordInterface &record, const String &className) const
Define the type and class name in the record.
virtual void copyData(const Lattice< Bool > &from)
Copy the data from the given lattice to this one.
const String & comment() const
Get or set the comment.
Definition LCRegion.h:242
Slicer expand(const Slicer &slicer) const
Expand a slicer or position in the region to the full lattice.
virtual void apply(Bool(*function)(const Bool &))
IPosition itsShape
Definition LCRegion.h:219
virtual uInt ndim() const
Return the dimensionality of the region.
virtual void apply(const Functional< Bool, Bool > &function)
Bool operator!=(const LCRegion &other) const
Non-equality.
Definition LCRegion.h:251
virtual void doPutSlice(const Array< Bool > &sourceBuffer, const IPosition &where, const IPosition &stride)
Regions can usually not be put; i.e.
virtual TableRecord toRecord(const String &tableName) const =0
Convert the (derived) object to a record.
LCRegion * translate(const Vector< Float > &translateVector, const IPosition &newLatticeShape) const
LCRegion & operator=(const LCRegion &other)
Assignment (copy semantics) is only useful for derived classes.
virtual void handleRename(const String &newName, Bool overwrite)
Handle renaming the region by renaming possible tables.
const Slicer & boundingBox() const
Give the bounding box.
Definition LCRegion.h:225
IPosition expand(const IPosition &index) const
virtual LCRegion * cloneRegion() const =0
const IPosition & latticeShape() const
Give the full lattice shape.
Definition LCRegion.h:229
virtual LCRegion * doTranslate(const Vector< Float > &translateVector, const IPosition &newLatticeShape) const =0
Do the actual translate in a derived class.
virtual void apply(Bool(*function)(Bool))
Replace every element, x, of the Lattice with the result of f(x).
virtual Lattice< Bool > * clone() const
Make a copy of the derived object.
LCRegion(const IPosition &latticeShape)
Construct with the lattice shape only.
virtual void handleDelete()
Handle deletion of the region by deleting possible tables.
LCRegion * translate(const IPosition &translateVector, const IPosition &newLatticeShape) const
virtual IPosition shape() const
Return the shape of the region (i.e.
virtual void set(const Bool &value)
Set all elements in the Lattice to the given value.
void setBoundingBox(const Slicer &boundingBox)
Sometimes it is inconvenient for a derived class to set the bounding box in the constructor.
virtual Bool hasMask() const =0
Does the region have a mask?
virtual void putAt(const Bool &value, const IPosition &where)
Put the value of a single element.
String: the storage and methods of handling collections of characters.
Definition String.h:223
this file contains all the compiler specific defines
Definition mainpage.dox:28
unsigned int uInt
Definition aipstype.h:49
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.