casacore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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>
38 
39 namespace 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
65  RegionManager();
66  RegionManager(const CoordinateSystem& csys);
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);
74  const CoordinateSystem& getcoordsys() const ;
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="");
83  Record* wbox(const Vector<Quantity>& blc,
84  const Vector<Quantity>& trc,
85  const Vector<Int>& pixelaxes,
86  const CoordinateSystem& csys,
87  const String& absrel, const String& comment);
88  Record* wbox(const Vector<String>& blc,
89  const Vector<String>& trc,
90  const Vector<Int>& pixelaxes,
91  const CoordinateSystem& csys,
92  const String& absrel, const String& comment);
93  Record* wbox(const Vector<Quantity>& blc,
94  const Vector<Quantity>& trc,
95  const Vector<Int>& pixelaxes,
96  const String& absrel, const String& comment);
97  Record* wbox(const Vector<String>& blc,
98  const Vector<String>& trc,
99  const Vector<Int>& pixelaxes,
100  const String& absrel, const String& comment);
101  ImageRegion* wbox(const Vector<Quantity>& blc,
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 
120  static ImageRegion* wellipse(
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 
145  static ImageRegion* wsphere(
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 
161  static ImageRegion* wellipsoid(
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 
176  static ImageRegion* wshell(
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
205  ImageRegion* doComplement(const WCRegion& reg1);
207  ImageRegion* doComplement(const ImageRegion& reg1);
208 
209  //Various versions of concatenating a region onto another.
210  ImageRegion* doConcatenation(const WCRegion& region, const WCBox& box);
211  ImageRegion* doconcatenation(const PtrBlock<const WCRegion*>& regions, const WCBox& box);
213  ImageRegion* doConcatenation(const Record& regions, const TableRecord& box);
214 
215 
216  //Various versions of handling the difference of regions
217  ImageRegion* doDifference(const WCRegion& reg1, const WCRegion& reg2);
219  ImageRegion* doDifference(const ImageRegion& reg1, const ImageRegion& reg2);
220 
221  //Different versions of intersecting regions
222  ImageRegion* doIntersection(const WCRegion& reg1, const WCRegion& reg2);
224  ImageRegion* doIntersection(const ImageRegion& reg1, const ImageRegion& 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)
243  String imageRegionToTable(const String& tabName,
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
253  Vector<String> namesInTable(const String& tabName);
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 
static ImageRegion * wmask(const String &command)
int Int
Definition: aipstype.h:50
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 Record * readImageFile(String filename, String regionname)
Reading of a file containing an ImageRegion in the AipsIO format dump.
Main interface class to a read/write table.
Definition: Table.h:157
ImageRegion * doDifference(const WCRegion &reg1, const WCRegion &reg2)
Various versions of handling the difference of regions.
String absreltype(const Int absrelval=0)
ImageRegion * doUnion(const WCRegion &reg1, const WCRegion &reg2)
Different versions of unioning regions.
Bool removeRegionInTable(const String &tabName, const String &regName)
Remove a region from table...refuse is regionname is &quot;&quot;.
LogIO * _getLog() const
ostream-like interface to creating log messages.
Definition: LogIO.h:167
std::unique_ptr< CoordinateSystem > itsCSys
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,...
static Bool isPixelRegion(const ImageRegion &reg)
Some little but useful tidbits.
void toQuantity(Quantity &out, const String &in)
Convert a string to Quantity.
Record * wbox(const Vector< Quantity > &blc, const Vector< Quantity > &trc, const Vector< Int > &pixelaxes, const CoordinateSystem &csys, const String &absrel, const String &comment)
LatticeExprNode pa(const LatticeExprNode &left, const LatticeExprNode &right)
This function finds 180/pi*atan2(left,right)/2.
static ImageRegion * wsphere(const Vector< Quantity > &center, const Quantity &radius, const Vector< Int > &pixelaxes, const CoordinateSystem &csys, const String &absrel)
Vector< String > namesInTable(const String &tabName)
names of regions in table
static Bool isWorldRegion(const ImageRegion &reg)
ImageRegion * doIntersection(const WCRegion &reg1, const WCRegion &reg2)
Different versions of intersecting regions.
A hierarchical collection of named fields of various types.
Definition: Record.h:180
bool Bool
Define the standard types used by Casacore.
Definition: aipstype.h:42
const CoordinateSystem & getcoordsys() const
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 ImageRegion * wellipsoid(const Vector< Quantity > &center, const Vector< Quantity > &radii, const Vector< Int > &pixelaxes, const CoordinateSystem &csys, const String &absrel)
const Bool False
Definition: aipstype.h:44
A drop-in replacement for Block&lt;T*&gt;.
Definition: Block.h:814
TableExprNode shape(const TableExprNode &array)
Function operating on any scalar or array resulting in a Double array containing the shape...
Definition: ExprNode.h:1987
A hierarchical collection of named fields of various types.
Definition: TableRecord.h:185
ImageRegion * doconcatenation(const PtrBlock< const WCRegion * > &regions, const WCBox &box)
Class to hold a region of interest in an image.
Definition: ImageRegion.h:86
Record * tableToRecord(const String &tabName, const String &regname)
recover region from table
ImageRegion * doConcatenation(const WCRegion &region, const WCBox &box)
Various versions of concatenating a region onto another.
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.
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)
Base class to define world coordinate regions of interest in an image.
Definition: WCRegion.h:95
String: the storage and methods of handling collections of characters.
Definition: String.h:225
Abstract base class for Record classes.
String recordToTable(const String &tabName, const RecordInterface &rec, const String &regName="", Bool asmask=False)
ImageRegion * doComplement(const WCRegion &reg1)
Various versions of creating a complement region.
RegionManager()
blank constructor
Class to define a world coordinate box region of interest in an image.
Definition: WCBox.h:292
static Table & getTable(void *ptr, Bool writable)
Function to return the internal Table object to the RegionHandler.
void setcoordsys(const CoordinateSystem &csys)
Interconvert pixel and world coordinates.
unsigned int uInt
Definition: aipstype.h:51
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.