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// <summary>
42// Abstract base class to define a region of interest in lattice coordinates.
43// </summary>
44
45// <use visibility=export>
46
47// <reviewed reviewer="" date="" tests="">
48// </reviewed>
49
50// <prerequisite>
51// <li> <linkto class=Slicer>Slicer</linkto>
52// </prerequisite>
53
54// <synopsis>
55// The LCRegion class is the abstract base class for various types
56// of LCRegion's (e.g. <linkto class=LCEllipsoid>LCEllipsoid</linkto>,
57// <linkto class=LCBox>LCBox</linkto>).
58// It contains the minimal bounding box of the region and, if needed,
59// a mask with the same shape as the bounding box. A mask element
60// is true if the element is inside the box.
61// <p>
62// Each LCRegion object must be able to convert itself to and from a record.
63// In that way they can be made persistent (in for example a Table).
64// <p>
65// The LCRegion can be used in several Lattices and Images classes and
66// functions to limit the area to operate on.
67// </synopsis>
68
69// <example>
70// <srcblock>
71// </srcblock>
72// </example>
73
74// <motivation>
75// The Slicer class is too limited as a region, because it can only
76// describe a rectangular region. Specialized classes are needed to
77// describe arbitrary regions. They need a base class to combine them.
78// </motivation>
79
80// # <todo asof="1997/11/11">
81// # <li>
82// # </todo>
83
84class LCRegion : public Lattice<Bool> {
85 public:
87
88 // Construct with the lattice shape only.
90
91 // Copy constructor (copy semantics).
92 LCRegion(const LCRegion& other);
93
94 virtual ~LCRegion();
95
96 // Equality
97 friend Bool operator==(const LCRegion& lhs, const LCRegion& rhs) { return lhs.equals(rhs); }
98
99 // Make a copy of the derived object.
100 // <group>
101 virtual Lattice<Bool>* clone() const;
102 virtual LCRegion* cloneRegion() const = 0;
103 // </group>
104
105 // Handle deletion of the region by deleting possible tables.
106 // The default implementation does nothing.
107 virtual void handleDelete();
108
109 // Handle renaming the region by renaming possible tables.
110 // The default implementation does nothing.
111 virtual void handleRename(const String& newName, Bool overwrite);
112
113 // Region type. Returns className() of derived class.
114 virtual String type() const = 0;
115
116 // Get or set the comment.
117 // <group>
118 const String& comment() const;
119 void setComment(const String& comment);
120 // </group>
121
122 // Does the region have a mask?
123 virtual Bool hasMask() const = 0;
124
125 // Construct another LCRegion (for e.g. another lattice) by moving
126 // this one. It recalculates the bounding box and mask.
127 // A positive translation value indicates "to right".
128 // <group>
129 LCRegion* translate(const IPosition& translateVector) const;
130 LCRegion* translate(const IPosition& translateVector, const IPosition& newLatticeShape) const;
131 LCRegion* translate(const Vector<Float>& translateVector) const;
132 LCRegion* translate(const Vector<Float>& translateVector, const IPosition& newLatticeShape) const;
133 // </group>
134
135 // Give the full lattice shape.
136 const IPosition& latticeShape() const;
137
138 // Give the bounding box.
139 const Slicer& boundingBox() const;
140
141 // Expand a slicer or position in the region to the full lattice.
142 // This converts the positions in the region to positions
143 // in the entire lattice.
144 // <group>
145 Slicer expand(const Slicer& slicer) const;
146 IPosition expand(const IPosition& index) const;
147 // </group>
148
149 // Convert the (derived) object to a record.
150 // The record can be used to make the object persistent.
151 // The <src>tableName</src> argument can be used by derived
152 // classes (e.g. LCPagedMask) to put very large objects.
153 virtual TableRecord toRecord(const String& tableName) const = 0;
154
155 // Convert correct object from a record.
156 static LCRegion* fromRecord(const TableRecord&, const String& tableName);
157
158 // Return the dimensionality of the region.
159 virtual uInt ndim() const;
160
161 // Return the shape of the region (i.e. of its bounding box).
162 virtual IPosition shape() const;
163
164 // Usually the lattice (i.e. the region mask) is not writable.
165 virtual Bool isWritable() const;
166
167 // Regions can usually not be put; i.e. no putSlice, etc. can be
168 // done on their masks.
169 // Hence LCRegion throws by default an exception for the
170 // following functions.
171 // <group>
172 virtual void doPutSlice(const Array<Bool>& sourceBuffer, const IPosition& where,
173 const IPosition& stride);
174 virtual void set(const Bool& value);
175 virtual void apply(Bool (*function)(Bool));
176 virtual void apply(Bool (*function)(const Bool&));
177 virtual void apply(const Functional<Bool, Bool>& function);
178 virtual void putAt(const Bool& value, const IPosition& where);
179 virtual void copyData(const Lattice<Bool>& from);
180 // </group>
181
182 protected:
183 // Assignment (copy semantics) is only useful for derived classes.
185
186 virtual Bool equals(const LCRegion& other) const = 0;
187
188 // Sometimes it is inconvenient for a derived class to set the bounding
189 // box in the constructor. So it can be set explicitly.
190 // It fills in the possibly undefined Slicer values.
191 // It may even be needed to set the lattice shape.
192 // <group>
195 // </group>
196
197 // Do the actual translate in a derived class.
198 virtual LCRegion* doTranslate(const Vector<Float>& translateVector,
199 const IPosition& newLatticeShape) const = 0;
200
201 // Define the type and class name in the record.
202 void defineRecordFields(RecordInterface& record, const String& className) const;
203
204 private:
208};
209
210inline const Slicer& LCRegion::boundingBox() const { return itsBoundingBox; }
211inline const IPosition& LCRegion::latticeShape() const { return itsShape; }
212inline LCRegion* LCRegion::translate(const IPosition& translateVector) const {
213 return translate(translateVector, itsShape);
214}
215inline LCRegion* LCRegion::translate(const Vector<Float>& translateVector) const {
216 return translate(translateVector, itsShape);
217}
218inline const String& LCRegion::comment() const { return itsComment; }
220
221} // namespace casacore
222
223#endif
static LCRegion * fromRecord(const TableRecord &, const String &tableName)
Convert correct object from a record.
Slicer itsBoundingBox
Definition LCRegion.h:206
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:219
virtual String type() const =0
Region type.
LCRegion * translate(const IPosition &translateVector) const
Construct another LCRegion (for e.g.
Definition LCRegion.h:212
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:218
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:205
virtual uInt ndim() const
Return the dimensionality of the region.
virtual void apply(const Functional< Bool, Bool > &function)
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 Bool equals(const LCRegion &other) const =0
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:210
IPosition expand(const IPosition &index) const
virtual LCRegion * cloneRegion() const =0
const IPosition & latticeShape() const
Give the full lattice shape.
Definition LCRegion.h:211
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.
friend Bool operator==(const LCRegion &lhs, const LCRegion &rhs)
Equality.
Definition LCRegion.h:97
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:355
For temporary backward namespace compatibility, use casa as alias for casacore.
Definition mainpage.dox:28
unsigned int uInt
Definition aipstype.h:49
RecordInterface()
The default constructor creates an empty record with a variable structure.
bool Bool
Define the standard types used by Casacore.
Definition aipstype.h:40
NewDelAllocator< T > NewDelAllocator< T >::value
Definition Allocator.h:360