casacore
RegionManager.h
Go to the documentation of this file.
1//# RegionManager.h: framework independent class that provides
2//# functionality to tool of same name
3//# Copyright (C) 2007
4//# Associated Universities, Inc. Washington DC, USA.
5//#
6//# This program is free software; you can redistribute it and/or modify it
7//# under the terms of the GNU General Public License as published by the Free
8//# Software Foundation; either version 2 of the License, or (at your option)
9//# any later version.
10//#
11//# This program is distributed in the hope that it will be useful, but WITHOUT
12//# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13//# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14//# more details.
15//#
16//# You should have received a copy of the GNU General Public License along
17//# with this program; if not, write to the Free Software Foundation, Inc.,
18//# 675 Massachusetts Ave, Cambridge, MA 02139, USA.
19//#
20//# Correspondence concerning AIPS++ should be addressed as follows:
21//# Internet email: aips2-request@nrao.edu.
22//# Postal address: AIPS++ Project Office
23//# National Radio Astronomy Observatory
24//# 520 Edgemont Road
25//# Charlottesville, VA 22903-2475 USA
26//#
27//# $Id$
28
29#ifndef IMAGES_REGIONMANAGER_H
30#define IMAGES_REGIONMANAGER_H
31
32#include <casacore/casa/aips.h>
33#include <casacore/casa/Quanta/Quantum.h>
34#include <casacore/coordinates/Coordinates/CoordinateSystem.h>
35#include <casacore/lattices/LRegions/RegionType.h>
36#include <casacore/tables/Tables/Table.h>
37#include <casacore/casa/Arrays/ArrayFwd.h>
38
39namespace casacore {
40
50 class LogIO;
51 class String;
52 class Record;
53 class WCRegion;
54 class WCBox;
55 template<class T> class PtrBlock;
56 class ImageRegion;
57
59 {
60
61
62 public:
63
64 //blank constructor
67 virtual ~RegionManager();
68 String absreltype(const Int absrelval=0);
69
70 //Some little but useful tidbits.
71 static Bool isPixelRegion(const ImageRegion& reg);
72 static Bool isWorldRegion(const ImageRegion& reg);
73 void setcoordsys(const CoordinateSystem& csys);
75
76 //LCSlicer box
77 Record* box(const Vector<Double>& blc, const Vector<Double>& trc,
78 const Vector<Double>& inc, const String& absrel,
79 const Bool frac, const String& comment="");
80 //LCBox box
81 static Record* box(const Vector<Double>& blc, const Vector<Double>& trc,
82 const Vector<Int>& shape, const String& comment="");
84 const Vector<Quantity>& trc,
85 const Vector<Int>& pixelaxes,
86 const CoordinateSystem& csys,
87 const String& absrel, const String& comment);
89 const Vector<String>& trc,
90 const Vector<Int>& pixelaxes,
91 const CoordinateSystem& csys,
92 const String& absrel, const String& comment);
94 const Vector<Quantity>& trc,
95 const Vector<Int>& pixelaxes,
96 const String& absrel, const String& comment);
98 const Vector<String>& trc,
99 const Vector<Int>& pixelaxes,
100 const String& absrel, const String& comment);
102 const Vector<Quantity>& trc,
103 const Vector<Int>& pixelaxes,
104 const CoordinateSystem& csys,
105 const String& absrel="abs" );
106 //Wpolygon with coordsys and if pixelaxes[0] is -1 then its assumed
107 //to be 0,1,...
109 const Vector<Quantity>& y,
110 const Vector<Int>& pixelaxes,
111 const CoordinateSystem& csys,
112 const String& absrel);
113 //wpolygon version without csys...throws an exception if
114 //setcoordsys is not run
116 const Vector<Quantity>& y,
117 const Vector<Int>& pixelaxes,
118 const String& absrel);
119
121 const Quantity& xc,
122 const Quantity& yc,
123 const Quantity& a,
124 const Quantity& b,
125 const Quantity& pa,
126 const uInt pixelAxis0,
127 const uInt pixelAxis1,
128 const CoordinateSystem& csys,
129 const String& absrel
130 );
131
132 //wellipse version without csys...throws an exception if
133 //setcoordsys is not run
135 const Quantity& xc,
136 const Quantity& yc,
137 const Quantity& a,
138 const Quantity& b,
139 const Quantity& pa,
140 const uInt pixelAxis0,
141 const uInt pixelAxis1,
142 const String& absrel
143 ) const;
144
146 const Vector<Quantity>& center,
147 const Quantity& radius,
148 const Vector<Int>& pixelaxes,
149 const CoordinateSystem& csys,
150 const String& absrel
151 );
152 //wsphere version without csys...throws an exception if
153 //setcoordsys is not run
155 const Vector<Quantity>& center,
156 const Quantity& radius,
157 const Vector<Int>& pixelaxes,
158 const String& absrel
159 ) const;
160
162 const Vector<Quantity>& center,
163 const Vector<Quantity>& radii,
164 const Vector<Int>& pixelaxes,
165 const CoordinateSystem& csys,
166 const String& absrel
167 );
168
170 const Vector<Quantity>& center,
171 const Vector<Quantity>& radii,
172 const Vector<Int>& pixelaxes,
173 const String& absrel
174 ) const;
175
177 const Vector<Quantity>& center,
178 const Vector<Quantity>& innerRadii,
179 const Vector<Quantity>& outerRadii,
180 const Vector<Int>& pixelaxes,
181 const CoordinateSystem& csys,
182 const String& absrel
183 );
184
186 const Vector<Quantity>& center,
187 const Vector<Quantity>& innerRadii,
188 const Vector<Quantity>& outerRadii,
189 const Vector<Int>& pixelaxes,
190 const String& absrel
191 ) const;
192
193 static ImageRegion* wmask(const String& command);
194
195
196 /**************************************************************
197 ** Routines for combining regions **
198 ** **
199 ** Note: Many of the WCXxx classes which are used to do the **
200 ** work can take multiple regions at once, why not **
201 ** accept a ptr block of Image Regions then? **
202 **************************************************************/
203
204 //Various versions of creating a complement region
208
209 //Various versions of concatenating a region onto another.
214
215
216 //Various versions of handling the difference of regions
217 ImageRegion* doDifference(const WCRegion& reg1, const WCRegion& reg2);
220
221 //Different versions of intersecting regions
222 ImageRegion* doIntersection(const WCRegion& reg1, const WCRegion& reg2);
225
226 //Different versions of unioning regions
227 ImageRegion* doUnion(const WCRegion& reg1, const WCRegion& reg2);
229 ImageRegion* doUnion(const ImageRegion& reg1, const ImageRegion& reg2) const;
230
231
232 /**************************************************************
233 ** Routines for reading/writing regions **
234 **************************************************************/
235
236 //Reading of a file containing an ImageRegion in the AipsIO format dump
237 static Record* readImageFile( String filename, String regionname );
238 //Writing a file of the AipsIO dump of the record representation of the region
239 static Bool writeImageFile(const String& file, const String& regionname, const Record& regionRecord);
240
241
242 //save region into a table (image, blank table or any other such)
244 const ImageRegion& imreg,
245 const String& regName, Bool asmask=False);
246
247 String recordToTable(const String& tabName, const RecordInterface& rec,
248 const String& regName="", Bool asmask=False);
249 //recover region from table
250 Record* tableToRecord(const String& tabName, const String& regname);
251
252 //names of regions in table
254
255 //Remove a region from table...refuse is regionname is ""
256 Bool removeRegionInTable(const String& tabName, const String& regName);
257
258
259 protected:
260 inline LogIO* _getLog() const { return itsLog; }
261
262 private:
264 std::unique_ptr<CoordinateSystem> itsCSys;
265 // Function to return the internal Table object to the RegionHandler.
266 static Table& getTable (void* ptr, Bool writable);
267 //Convert a string to Quantity
268 void toQuantity(Quantity& out, const String& in);
270
271 };
272
273
274} // casa namespace
275#endif
276
A drop-in replacement for Block<T*>.
Definition: Block.h:814
std::unique_ptr< CoordinateSystem > itsCSys
ImageRegion * doconcatenation(const PtrBlock< const WCRegion * > &regions, const WCBox &box)
ImageRegion * wellipse(const Quantity &xc, const Quantity &yc, const Quantity &a, const Quantity &b, const Quantity &pa, const uInt pixelAxis0, const uInt pixelAxis1, const String &absrel) const
wellipse version without csys...throws an exception if setcoordsys is not run
ImageRegion * doUnion(const WCRegion &reg1, const WCRegion &reg2)
Different versions of unioning regions.
Record * wbox(const Vector< Quantity > &blc, const Vector< Quantity > &trc, const Vector< Int > &pixelaxes, const String &absrel, const String &comment)
Vector< String > namesInTable(const String &tabName)
names of regions in table
static ImageRegion * wellipsoid(const Vector< Quantity > &center, const Vector< Quantity > &radii, const Vector< Int > &pixelaxes, const CoordinateSystem &csys, const String &absrel)
ImageRegion * doComplement(const WCRegion &reg1)
Various versions of creating a complement region.
ImageRegion * wellipsoid(const Vector< Quantity > &center, const Vector< Quantity > &radii, const Vector< Int > &pixelaxes, const String &absrel) const
ImageRegion * doDifference(const PtrBlock< const WCRegion * > &reg1)
ImageRegion * doIntersection(const ImageRegion &reg1, const ImageRegion &reg2)
static ImageRegion * wshell(const Vector< Quantity > &center, const Vector< Quantity > &innerRadii, const Vector< Quantity > &outerRadii, const Vector< Int > &pixelaxes, const CoordinateSystem &csys, const String &absrel)
static Bool isWorldRegion(const ImageRegion &reg)
static Record * box(const Vector< Double > &blc, const Vector< Double > &trc, const Vector< Int > &shape, const String &comment="")
LCBox box.
static ImageRegion * wellipse(const Quantity &xc, const Quantity &yc, const Quantity &a, const Quantity &b, const Quantity &pa, const uInt pixelAxis0, const uInt pixelAxis1, const CoordinateSystem &csys, const String &absrel)
static Bool writeImageFile(const String &file, const String &regionname, const Record &regionRecord)
Writing a file of the AipsIO dump of the record representation of the region.
Record * wbox(const Vector< String > &blc, const Vector< String > &trc, const Vector< Int > &pixelaxes, const String &absrel, const String &comment)
String absreltype(const Int absrelval=0)
ImageRegion * wpolygon(const Vector< Quantity > &x, const Vector< Quantity > &y, const Vector< Int > &pixelaxes, const CoordinateSystem &csys, const String &absrel)
Wpolygon with coordsys and if pixelaxes[0] is -1 then its assumed to be 0,1,...
void setcoordsys(const CoordinateSystem &csys)
ImageRegion * doComplement(const ImageRegion &reg1)
String imageRegionToTable(const String &tabName, const ImageRegion &imreg, const String &regName, Bool asmask=False)
save region into a table (image, blank table or any other such)
ImageRegion * doComplement(const PtrBlock< const WCRegion * > &reg1)
String recordToTable(const String &tabName, const RecordInterface &rec, const String &regName="", Bool asmask=False)
ImageRegion * wshell(const Vector< Quantity > &center, const Vector< Quantity > &innerRadii, const Vector< Quantity > &outerRadii, const Vector< Int > &pixelaxes, const String &absrel) const
static ImageRegion * wsphere(const Vector< Quantity > &center, const Quantity &radius, const Vector< Int > &pixelaxes, const CoordinateSystem &csys, const String &absrel)
Record * wbox(const Vector< Quantity > &blc, const Vector< Quantity > &trc, const Vector< Int > &pixelaxes, const CoordinateSystem &csys, const String &absrel, const String &comment)
ImageRegion * doIntersection(const WCRegion &reg1, const WCRegion &reg2)
Different versions of intersecting regions.
static Record * readImageFile(String filename, String regionname)
Reading of a file containing an ImageRegion in the AipsIO format dump.
ImageRegion * doConcatenation(const Record &regions, const TableRecord &box)
LogIO * _getLog() const
static Table & getTable(void *ptr, Bool writable)
Function to return the internal Table object to the RegionHandler.
ImageRegion * doUnion(const PtrBlock< const WCRegion * > &reg1)
Record * wbox(const Vector< String > &blc, const Vector< String > &trc, const Vector< Int > &pixelaxes, const CoordinateSystem &csys, const String &absrel, const String &comment)
static Bool isPixelRegion(const ImageRegion &reg)
Some little but useful tidbits.
ImageRegion * wbox(const Vector< Quantity > &blc, const Vector< Quantity > &trc, const Vector< Int > &pixelaxes, const CoordinateSystem &csys, const String &absrel="abs")
Record * tableToRecord(const String &tabName, const String &regname)
recover region from table
const CoordinateSystem & getcoordsys() const
void toQuantity(Quantity &out, const String &in)
Convert a string to Quantity.
ImageRegion * doConcatenation(const PtrBlock< const ImageRegion * > &regions, const TableRecord &box)
static ImageRegion * wmask(const String &command)
ImageRegion * doUnion(const ImageRegion &reg1, const ImageRegion &reg2) const
RegionManager()
blank constructor
ImageRegion * doDifference(const ImageRegion &reg1, const ImageRegion &reg2)
Bool removeRegionInTable(const String &tabName, const String &regName)
Remove a region from table...refuse is regionname is "".
ImageRegion * wpolygon(const Vector< Quantity > &x, const Vector< Quantity > &y, const Vector< Int > &pixelaxes, const String &absrel)
wpolygon version without csys...throws an exception if setcoordsys is not run
ImageRegion * doDifference(const WCRegion &reg1, const WCRegion &reg2)
Various versions of handling the difference of regions.
ImageRegion * doIntersection(const PtrBlock< const WCRegion * > &reg1)
ImageRegion * wsphere(const Vector< Quantity > &center, const Quantity &radius, const Vector< Int > &pixelaxes, const String &absrel) const
wsphere version without csys...throws an exception if setcoordsys is not run
Record * box(const Vector< Double > &blc, const Vector< Double > &trc, const Vector< Double > &inc, const String &absrel, const Bool frac, const String &comment="")
LCSlicer box.
ImageRegion * doConcatenation(const WCRegion &region, const WCBox &box)
Various versions of concatenating a region onto another.
RegionManager(const CoordinateSystem &csys)
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
LatticeExprNode pa(const LatticeExprNode &left, const LatticeExprNode &right)
This function finds 180/pi*atan2(left,right)/2.
const Bool False
Definition: aipstype.h:44
unsigned int uInt
Definition: aipstype.h:51
TableExprNode shape(const TableExprNode &array)
Function operating on any scalar or array resulting in a Double array containing the shape.
Definition: ExprNode.h:1987
int Int
Definition: aipstype.h:50
bool Bool
Define the standard types used by Casacore.
Definition: aipstype.h:42