casacore
ImageRegion.h
Go to the documentation of this file.
1 //# ImageRegion.h: Class to hold a region of interest in an image
2 //# Copyright (C) 1998,1999,2000
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 IMAGES_IMAGEREGION_H
29 #define IMAGES_IMAGEREGION_H
30 
31 //# Includes
32 #include <casacore/casa/aips.h>
33 #include <casacore/lattices/LRegions/LattRegionHolder.h>
34 
35 namespace casacore { //# NAMESPACE CASACORE - BEGIN
36 
37 //# Forward Declarations
38 class CoordinateSystem;
39 class IPosition;
40 class LCRegion;
41 class LCSlicer;
42 class WCRegion;
43 class String;
44 class TableRecord;
45 
46 
47 // <summary>
48 // Class to hold a region of interest in an image.
49 // </summary>
50 
51 // <use visibility=export>
52 
53 // <reviewed reviewer="" date="" tests="">
54 // </reviewed>
55 
56 // <prerequisite>
57 // <li> <linkto class=LCSlicer>LCSlicer</linkto>
58 // <li> <linkto class=WCRegion>WCRegion</linkto>
59 // </prerequisite>
60 
61 // <synopsis>
62 // The only purpose of ImageRegion is to have a single object for
63 // the various kinds of regions. It can hold a
64 // <linkto class=LCRegion>LCRegion</linkto>,
65 // <linkto class=LCSlicer>LCSlicer</linkto>, and
66 // <linkto class=WCRegion>WCRegion</linkto>.
67 // </synopsis>
68 
69 // <example>
70 // <srcblock>
71 // </srcblock>
72 // </example>
73 
74 // <motivation>
75 // It was felt that making an abstract base class LatticeRegion for
76 // LCRegion and WCRegion would create undesirable dependencies of
77 // module Lattices on module Coordinates. E.g. it would be impossible
78 // to have a function toWCRegion.
79 // Therefore the container class ImageRegion is chosen.
80 // </motivation>
81 
82 //# <todo asof="1997/11/11">
83 //# <li>
84 //# </todo>
85 
87 {
88 public:
89  // Default constructor (has no region at all).
91 
92  // Construct from a region based on lattice coordinates.
94 
95  // Construct from a slicer based on lattice coordinates.
97 
98  // Construct from a region based on world coordinates.
100 
101  // Similar constructors as above, but using a pointer.
102  // It takes over the pointer, so the user should not delete the
103  // object. It is deleted by the ImageRegion destructor.
104  // <group>
105  explicit ImageRegion (LCRegion*);
106  explicit ImageRegion (LCSlicer*);
107  explicit ImageRegion (WCRegion*);
108  // </group>
109 
110  // Copy constructor (copy semantics).
111  ImageRegion (const ImageRegion& other);
112 
113  virtual ~ImageRegion();
114 
115  // Assignment (copy semantics).
117 
118  // Clone the object.
119  virtual ImageRegion* clone() const;
120 
121  // Comparison
122  virtual Bool operator==(const LattRegionHolder& other) const;
123 
124  // Create an ImageRegion from a lattice expression. Returned pointer
125  // is created via new(); it is the caller's responsibility to delete it.
126  static ImageRegion* fromLatticeExpression(const String& latticeExpression);
127 
128  // Create an ImageRegion from a record. The returned pointer is created via
129  // new(). It's the callers responsibility to delete it.
130  // If a null pointer is passed in for <src>logger</src> no logging is done,
131  // otherwise informational messages regarding bounding boxes are emitted
132  // to the <src>logger</src> object.
133  static ImageRegion* fromRecord (LogIO *logger,
134  const CoordinateSystem& coords,
135  const IPosition& imShape,
136  const Record& regionRecord);
137 
138  // Test if the underlying region is an WCRegion.
139  virtual Bool isWCRegion() const;
140 
141  // Get the region as a pointer to WCRegion.
142  // An exception is thrown if the region is not the correct type.
143  // Functions <src>isWCRegion()</src> can be used to test the type.
144  virtual const WCRegion* asWCRegionPtr() const;
145 
146  // Get the region as an LCSlicer or WCRegion.
147  // An exception is thrown if the region is not the correct type.
148  // Functions <src>isWCRegion()</src>, etc. can be used to test the type.
149  // <group>
150  const LCRegion& asLCRegion() const;
151  const LCSlicer& asLCSlicer() const;
152  const WCRegion& asWCRegion() const;
153  // </group>
154 
155  // Get the region as a writable mask.
156  // It throws an exception if the region is not an LCRegion or if
157  // its mask is not writable.
159 
160  // Convert to a LatticeRegion using the given coordinate system
161  // (with reference pixel) and shape.
162  // It will also make the region complete (absolute and non-fractional).
164  const IPosition& shape) const;
165 
166  // Convert to an LCRegion using the given coordinate system
167  // (with reference pixel) and shape.
168  // It will also make the region complete (absolute and non-fractional).
169  // An exception is thrown if the region type is a LCSlicer.
170  // The axes argument tells which axes to use from the coordinate
171  // system and shape.
173  const IPosition& shape) const;
174 
175  // Convert the (derived) object to a record.
176  // The record can be used to make the object persistent.
177  TableRecord toRecord (const String& tableName) const;
178 
179  // Convert correct object from a record.
181  const String& tableName);
182 
183  // Form a compound from this and the other region.
184  // <group>
185  virtual LattRegionHolder* makeUnion (const LattRegionHolder& other) const;
187  (const LattRegionHolder& other) const;
189  (const LattRegionHolder& other) const;
191  // </group>
192 
193 private:
195 };
196 
197 
198 inline const LCRegion& ImageRegion::asLCRegion() const
199 {
200  return *asLCRegionPtr();
201 }
202 
203 inline const LCSlicer& ImageRegion::asLCSlicer() const
204 {
205  return *asLCSlicerPtr();
206 }
207 
208 inline const WCRegion& ImageRegion::asWCRegion() const
209 {
210  return *asWCRegionPtr();
211 }
212 
213 
214 
215 } //# NAMESPACE CASACORE - END
216 
217 #endif
virtual LattRegionHolder * makeIntersection(const LattRegionHolder &other) const
const LCRegion & asLCRegion() const
Get the region as an LCSlicer or WCRegion.
Definition: ImageRegion.h:198
static ImageRegion * fromLatticeExpression(const String &latticeExpression)
Create an ImageRegion from a lattice expression.
ImageRegion(LCSlicer *)
LCRegion * toLCRegion(const CoordinateSystem &cSys, const IPosition &shape) const
Convert to an LCRegion using the given coordinate system (with reference pixel) and shape.
ImageRegion(const LCSlicer &)
Construct from a slicer based on lattice coordinates.
TableRecord toRecord(const String &tableName) const
Convert the (derived) object to a record.
virtual ImageRegion * clone() const
Clone the object.
ImageRegion()
Default constructor (has no region at all).
ImageRegion(const LCRegion &)
Construct from a region based on lattice coordinates.
virtual LattRegionHolder * makeDifference(const LattRegionHolder &other) const
ImageRegion(LCRegion *)
Similar constructors as above, but using a pointer.
ImageRegion(WCRegion *)
static ImageRegion * fromRecord(LogIO *logger, const CoordinateSystem &coords, const IPosition &imShape, const Record &regionRecord)
Create an ImageRegion from a record.
ImageRegion(const ImageRegion &other)
Copy constructor (copy semantics).
const WCRegion & asWCRegion() const
Definition: ImageRegion.h:208
virtual LattRegionHolder * makeComplement() const
virtual LatticeRegion toLatticeRegion(const CoordinateSystem &cSys, const IPosition &shape) const
Convert to a LatticeRegion using the given coordinate system (with reference pixel) and shape.
virtual Bool operator==(const LattRegionHolder &other) const
Comparison.
const LCSlicer & asLCSlicer() const
Definition: ImageRegion.h:203
ImageRegion & operator=(const ImageRegion &other)
Assignment (copy semantics).
virtual const WCRegion * asWCRegionPtr() const
Get the region as a pointer to WCRegion.
ImageRegion(const WCRegion &)
Construct from a region based on world coordinates.
LCRegion & asMask()
Get the region as a writable mask.
virtual LattRegionHolder * makeUnion(const LattRegionHolder &other) const
Form a compound from this and the other region.
virtual Bool isWCRegion() const
Test if the underlying region is an WCRegion.
static ImageRegion * fromRecord(const TableRecord &, const String &tableName)
Convert correct object from a record.
const LCSlicer * asLCSlicerPtr() const
const LCRegion * asLCRegionPtr() const
Get the region as a pointer to a LCRegion, LCSlicer, or WCRegion.
String: the storage and methods of handling collections of characters.
Definition: String.h:225
this file contains all the compiler specific defines
Definition: mainpage.dox:28
TableExprNode shape(const TableExprNode &array)
Function operating on any scalar or array resulting in a Double array containing the shape.
Definition: ExprNode.h:1987
bool Bool
Define the standard types used by Casacore.
Definition: aipstype.h:42