casacore
Loading...
Searching...
No Matches
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: casa-feedback@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#ifndef IMAGES_REGIONMANAGER_H
28#define IMAGES_REGIONMANAGER_H
29
30#include <casacore/casa/aips.h>
31#include <casacore/casa/Quanta/Quantum.h>
32#include <casacore/coordinates/Coordinates/CoordinateSystem.h>
33#include <casacore/lattices/LRegions/RegionType.h>
34#include <casacore/tables/Tables/Table.h>
35#include <casacore/casa/Arrays/ArrayFwd.h>
36
37namespace casacore {
38
48class LogIO;
49class String;
50class Record;
51class WCRegion;
52class WCBox;
53class ImageRegion;
54
56 public:
57 // blank constructor
60 virtual ~RegionManager();
61 String absreltype(const Int absrelval = 0);
62
63 // Some little but useful tidbits.
64 static Bool isPixelRegion(const ImageRegion& reg);
65 static Bool isWorldRegion(const ImageRegion& reg);
66 void setcoordsys(const CoordinateSystem& csys);
68
69 // LCSlicer box
70 Record* box(const Vector<Double>& blc, const Vector<Double>& trc, const Vector<Double>& inc,
71 const String& absrel, const Bool frac, const String& comment = "");
72 // LCBox box
73 static Record* box(const Vector<Double>& blc, const Vector<Double>& trc, const Vector<Int>& shape,
74 const String& comment = "");
76 const Vector<Int>& pixelaxes, const CoordinateSystem& csys, const String& absrel,
77 const String& comment);
78 Record* wbox(const Vector<String>& blc, const Vector<String>& trc, const Vector<Int>& pixelaxes,
79 const CoordinateSystem& csys, const String& absrel, const String& comment);
81 const Vector<Int>& pixelaxes, const String& absrel, const String& comment);
82 Record* wbox(const Vector<String>& blc, const Vector<String>& trc, const Vector<Int>& pixelaxes,
83 const String& absrel, const String& comment);
85 const Vector<Int>& pixelaxes, const CoordinateSystem& csys,
86 const String& absrel = "abs");
87 // Wpolygon with coordsys and if pixelaxes[0] is -1 then its assumed
88 // to be 0,1,...
90 const Vector<Int>& pixelaxes, const CoordinateSystem& csys,
91 const String& absrel);
92 // wpolygon version without csys...throws an exception if
93 // setcoordsys is not run
95 const Vector<Int>& pixelaxes, const String& absrel);
96
97 static ImageRegion* wellipse(const Quantity& xc, const Quantity& yc, const Quantity& a,
98 const Quantity& b, const Quantity& pa, const uInt pixelAxis0,
99 const uInt pixelAxis1, const CoordinateSystem& csys,
100 const String& absrel);
101
102 // wellipse version without csys...throws an exception if
103 // setcoordsys is not run
104 ImageRegion* wellipse(const Quantity& xc, const Quantity& yc, const Quantity& a,
105 const Quantity& b, const Quantity& pa, const uInt pixelAxis0,
106 const uInt pixelAxis1, const String& absrel) const;
107
108 static ImageRegion* wsphere(const Vector<Quantity>& center, const Quantity& radius,
109 const Vector<Int>& pixelaxes, const CoordinateSystem& csys,
110 const String& absrel);
111 // wsphere version without csys...throws an exception if
112 // setcoordsys is not run
113 ImageRegion* wsphere(const Vector<Quantity>& center, const Quantity& radius,
114 const Vector<Int>& pixelaxes, const String& absrel) const;
115
116 static ImageRegion* wellipsoid(const Vector<Quantity>& center, const Vector<Quantity>& radii,
117 const Vector<Int>& pixelaxes, const CoordinateSystem& csys,
118 const String& absrel);
119
121 const Vector<Int>& pixelaxes, const String& absrel) const;
122
123 static ImageRegion* wshell(const Vector<Quantity>& center, const Vector<Quantity>& innerRadii,
124 const Vector<Quantity>& outerRadii, const Vector<Int>& pixelaxes,
125 const CoordinateSystem& csys, const String& absrel);
126
127 ImageRegion* wshell(const Vector<Quantity>& center, const Vector<Quantity>& innerRadii,
128 const Vector<Quantity>& outerRadii, const Vector<Int>& pixelaxes,
129 const String& absrel) const;
130
131 static ImageRegion* wmask(const String& command);
132
133 /**************************************************************
134 ** Routines for combining regions **
135 ** **
136 ** Note: Many of the WCXxx classes which are used to do the **
137 ** work can take multiple regions at once, why not **
138 ** accept a ptr block of Image Regions then? **
139 **************************************************************/
140
141 // Various versions of creating a complement region
145
146 // Various versions of concatenating a region onto another.
151
152 // Various versions of handling the difference of regions
153 ImageRegion* doDifference(const WCRegion& reg1, const WCRegion& reg2);
156
157 // Different versions of intersecting regions
158 ImageRegion* doIntersection(const WCRegion& reg1, const WCRegion& reg2);
161
162 // Different versions of unioning regions
163 ImageRegion* doUnion(const WCRegion& reg1, const WCRegion& reg2);
165 ImageRegion* doUnion(const ImageRegion& reg1, const ImageRegion& reg2) const;
166
167 /**************************************************************
168 ** Routines for reading/writing regions **
169 **************************************************************/
170
171 // Reading of a file containing an ImageRegion in the AipsIO format dump
172 static Record* readImageFile(String filename, String regionname);
173 // Writing a file of the AipsIO dump of the record representation of the region
174 static Bool writeImageFile(const String& file, const String& regionname,
175 const Record& regionRecord);
176
177 // save region into a table (image, blank table or any other such)
178 String imageRegionToTable(const String& tabName, const ImageRegion& imreg, const String& regName,
179 Bool asmask = False);
180
181 String recordToTable(const String& tabName, const RecordInterface& rec,
182 const String& regName = "", Bool asmask = False);
183 // recover region from table
184 Record* tableToRecord(const String& tabName, const String& regname);
185
186 // names of regions in table
188
189 // Remove a region from table...refuse is regionname is ""
190 Bool removeRegionInTable(const String& tabName, const String& regName);
191
192 protected:
193 inline LogIO* _getLog() const { return itsLog; }
194
195 private:
197 std::unique_ptr<CoordinateSystem> itsCSys;
198 // Function to return the internal Table object to the RegionHandler.
199 static Table& getTable(void* ptr, Bool writable);
200 // Convert a string to Quantity
201 void toQuantity(Quantity& out, const String& in);
203};
204
205} // namespace casacore
206#endif
std::unique_ptr< CoordinateSystem > itsCSys
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
ImageRegion * doConcatenation(const Block< const ImageRegion * > &regions, const TableRecord &box)
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 * 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)
ImageRegion * doconcatenation(const Block< const WCRegion * > &regions, const WCBox &box)
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)
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.
Record * wbox(const Vector< String > &blc, const Vector< String > &trc, const Vector< Int > &pixelaxes, const CoordinateSystem &csys, const String &absrel, const String &comment)
ImageRegion * doComplement(const Block< const WCRegion * > &reg1)
ImageRegion * doIntersection(const Block< const WCRegion * > &reg1)
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")
ImageRegion * doDifference(const Block< const WCRegion * > &reg1)
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.
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 * doUnion(const Block< 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:355
For temporary backward namespace compatibility, use casa as alias for casacore.
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:42
unsigned int uInt
Definition aipstype.h:49
IPosition shape(const RecordFieldId &) const
Get the actual shape of this field.
const String & comment(const RecordFieldId &) const override
Get the comment for this field.
RecordInterface()
The default constructor creates an empty record with a variable structure.
int Int
Definition aipstype.h:48
bool Bool
Define the standard types used by Casacore.
Definition aipstype.h:40
Quantum< Double > Quantity
Definition Quantum.h:40