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 
38 
39 namespace casacore {
40 
50  class LogIO;
51  class String;
52  class Record;
53  template<class T> class Vector;
54  class WCRegion;
55  class WCBox;
56  template<class T> class PtrBlock;
57  class ImageRegion;
58 
60  {
61 
62 
63  public:
64 
65  //blank constructor
68  virtual ~RegionManager();
69  String absreltype(const Int absrelval=0);
70 
71  //Some little but useful tidbits.
72  static Bool isPixelRegion(const ImageRegion& reg);
73  static Bool isWorldRegion(const ImageRegion& reg);
74  void setcoordsys(const CoordinateSystem& csys);
75  const CoordinateSystem& getcoordsys() const ;
76 
77  //LCSlicer box
78  Record* box(const Vector<Double>& blc, const Vector<Double>& trc,
79  const Vector<Double>& inc, const String& absrel,
80  const Bool frac, const String& comment="");
81  //LCBox box
82  static Record* box(const Vector<Double>& blc, const Vector<Double>& trc,
83  const Vector<Int>& shape, const String& comment="");
85  const Vector<Quantity>& trc,
86  const Vector<Int>& pixelaxes,
87  const CoordinateSystem& csys,
88  const String& absrel, const String& comment);
89  Record* wbox(const Vector<String>& blc,
90  const Vector<String>& trc,
91  const Vector<Int>& pixelaxes,
92  const CoordinateSystem& csys,
93  const String& absrel, const String& comment);
95  const Vector<Quantity>& trc,
96  const Vector<Int>& pixelaxes,
97  const String& absrel, const String& comment);
98  Record* wbox(const Vector<String>& blc,
99  const Vector<String>& trc,
100  const Vector<Int>& pixelaxes,
101  const String& absrel, const String& comment);
103  const Vector<Quantity>& trc,
104  const Vector<Int>& pixelaxes,
105  const CoordinateSystem& csys,
106  const String& absrel="abs" );
107  //Wpolygon with coordsys and if pixelaxes[0] is -1 then its assumed
108  //to be 0,1,...
110  const Vector<Quantity>& y,
111  const Vector<Int>& pixelaxes,
112  const CoordinateSystem& csys,
113  const String& absrel);
114  //wpolygon version without csys...throws an exception if
115  //setcoordsys is not run
117  const Vector<Quantity>& y,
118  const Vector<Int>& pixelaxes,
119  const String& absrel);
120 
122  const Quantity& xc,
123  const Quantity& yc,
124  const Quantity& a,
125  const Quantity& b,
126  const Quantity& pa,
127  const uInt pixelAxis0,
128  const uInt pixelAxis1,
129  const CoordinateSystem& csys,
130  const String& absrel
131  );
132 
133  //wellipse version without csys...throws an exception if
134  //setcoordsys is not run
136  const Quantity& xc,
137  const Quantity& yc,
138  const Quantity& a,
139  const Quantity& b,
140  const Quantity& pa,
141  const uInt pixelAxis0,
142  const uInt pixelAxis1,
143  const String& absrel
144  ) const;
145 
147  const Vector<Quantity>& center,
148  const Quantity& radius,
149  const Vector<Int>& pixelaxes,
150  const CoordinateSystem& csys,
151  const String& absrel
152  );
153  //wsphere version without csys...throws an exception if
154  //setcoordsys is not run
156  const Vector<Quantity>& center,
157  const Quantity& radius,
158  const Vector<Int>& pixelaxes,
159  const String& absrel
160  ) const;
161 
163  const Vector<Quantity>& center,
164  const Vector<Quantity>& radii,
165  const Vector<Int>& pixelaxes,
166  const CoordinateSystem& csys,
167  const String& absrel
168  );
169 
171  const Vector<Quantity>& center,
172  const Vector<Quantity>& radii,
173  const Vector<Int>& pixelaxes,
174  const String& absrel
175  ) const;
176 
178  const Vector<Quantity>& center,
179  const Vector<Quantity>& innerRadii,
180  const Vector<Quantity>& outerRadii,
181  const Vector<Int>& pixelaxes,
182  const CoordinateSystem& csys,
183  const String& absrel
184  );
185 
187  const Vector<Quantity>& center,
188  const Vector<Quantity>& innerRadii,
189  const Vector<Quantity>& outerRadii,
190  const Vector<Int>& pixelaxes,
191  const String& absrel
192  ) const;
193 
194  static ImageRegion* wmask(const String& command);
195 
196 
197  /**************************************************************
198  ** Routines for combining regions **
199  ** **
200  ** Note: Many of the WCXxx classes which are used to do the **
201  ** work can take multiple regions at once, why not **
202  ** accept a ptr block of Image Regions then? **
203  **************************************************************/
204 
205  //Various versions of creating a complement region
209 
210  //Various versions of concatenating a region onto another.
211  ImageRegion* doConcatenation(const WCRegion& region, const WCBox& box);
215 
216 
217  //Various versions of handling the difference of regions
218  ImageRegion* doDifference(const WCRegion& reg1, const WCRegion& reg2);
220  ImageRegion* doDifference(const ImageRegion& reg1, const ImageRegion& reg2);
221 
222  //Different versions of intersecting regions
223  ImageRegion* doIntersection(const WCRegion& reg1, const WCRegion& reg2);
225  ImageRegion* doIntersection(const ImageRegion& reg1, const ImageRegion& reg2);
226 
227  //Different versions of unioning regions
228  ImageRegion* doUnion(const WCRegion& reg1, const WCRegion& reg2);
230  ImageRegion* doUnion(const ImageRegion& reg1, const ImageRegion& reg2) const;
231 
232 
233  /**************************************************************
234  ** Routines for reading/writing regions **
235  **************************************************************/
236 
237  //Reading of a file containing an ImageRegion in the AipsIO format dump
238  static Record* readImageFile( String filename, String regionname );
239  //Writing a file of the AipsIO dump of the record representation of the region
240  static Bool writeImageFile(const String& file, const String& regionname, const Record& regionRecord);
241 
242 
243  //save region into a table (image, blank table or any other such)
245  const ImageRegion& imreg,
246  const String& regName, Bool asmask=False);
247 
248  String recordToTable(const String& tabName, const RecordInterface& rec,
249  const String& regName="", Bool asmask=False);
250  //recover region from table
251  Record* tableToRecord(const String& tabName, const String& regname);
252 
253  //names of regions in table
255 
256  //Remove a region from table...refuse is regionname is ""
257  Bool removeRegionInTable(const String& tabName, const String& regName);
258 
259 
260  protected:
261  inline LogIO* _getLog() const { return itsLog; }
262 
263  private:
265  std::unique_ptr<CoordinateSystem> itsCSys;
266  // Function to return the internal Table object to the RegionHandler.
267  static Table& getTable (void* ptr, Bool writable);
268  //Convert a string to Quantity
269  void toQuantity(Quantity& out, const String& in);
271 
272  };
273 
274 
275 } // casa namespace
276 #endif
277 
casacore::CoordinateSystem
Definition: CoordinateSystem.h:218
casacore::RegionManager::wbox
Record * wbox(const Vector< String > &blc, const Vector< String > &trc, const Vector< Int > &pixelaxes, const CoordinateSystem &csys, const String &absrel, const String &comment)
casacore::RegionManager::wpolygon
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
casacore::PtrBlock
A drop-in replacement for Block<T*>.
Definition: Block.h:814
casacore::RegionManager::itsCSys
std::unique_ptr< CoordinateSystem > itsCSys
Definition: RegionManager.h:265
casacore::RegionManager::getcoordsys
const CoordinateSystem & getcoordsys() const
casacore::TableRecord
Definition: TableRecord.h:183
casacore::RegionManager::wpolygon
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,...
casacore::RegionManager::wellipsoid
ImageRegion * wellipsoid(const Vector< Quantity > &center, const Vector< Quantity > &radii, const Vector< Int > &pixelaxes, const String &absrel) const
casacore::RegionManager::doComplement
ImageRegion * doComplement(const WCRegion &reg1)
Various versions of creating a complement region.
casacore::RegionManager::wsphere
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
casacore::RegionManager::doConcatenation
ImageRegion * doConcatenation(const WCRegion &region, const WCBox &box)
Various versions of concatenating a region onto another.
casacore::RegionManager::isWorldRegion
static Bool isWorldRegion(const ImageRegion &reg)
casacore::WCRegion
Definition: WCRegion.h:96
casacore::RegionManager::doConcatenation
ImageRegion * doConcatenation(const Record &regions, const TableRecord &box)
casacore::RegionManager::wmask
static ImageRegion * wmask(const String &command)
casacore::RegionManager::wshell
ImageRegion * wshell(const Vector< Quantity > &center, const Vector< Quantity > &innerRadii, const Vector< Quantity > &outerRadii, const Vector< Int > &pixelaxes, const String &absrel) const
casacore::RegionManager::wbox
Record * wbox(const Vector< String > &blc, const Vector< String > &trc, const Vector< Int > &pixelaxes, const String &absrel, const String &comment)
casacore::LogIO
Definition: LogIO.h:168
casacore::RegionManager::removeRegionInTable
Bool removeRegionInTable(const String &tabName, const String &regName)
Remove a region from table...refuse is regionname is "".
casacore::RegionManager::wbox
Record * wbox(const Vector< Quantity > &blc, const Vector< Quantity > &trc, const Vector< Int > &pixelaxes, const String &absrel, const String &comment)
casacore::RegionManager::imageRegionToTable
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)
casacore::WCBox
Definition: WCBox.h:293
casacore::Table
Definition: Table.h:154
casacore::RegionManager::box
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.
casacore::RegionManager::RegionManager
RegionManager(const CoordinateSystem &csys)
casacore::RegionManager::absreltype
String absreltype(const Int absrelval=0)
casacore::RegionManager::itsLog
LogIO * itsLog
Definition: RegionManager.h:264
casacore::False
const Bool False
Definition: aipstype.h:44
casacore::uInt
unsigned int uInt
Definition: aipstype.h:51
casacore::RegionManager::doComplement
ImageRegion * doComplement(const PtrBlock< const WCRegion * > &reg1)
casacore::shape
TableExprNode shape(const TableExprNode &array)
Function operating on any scalar or array resulting in a Double array containing the shape.
Definition: ExprNode.h:1944
casacore::RegionManager::doConcatenation
ImageRegion * doConcatenation(const PtrBlock< const ImageRegion * > &regions, const TableRecord &box)
casacore::RegionManager::wshell
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)
casacore::RegionManager::doIntersection
ImageRegion * doIntersection(const PtrBlock< const WCRegion * > &reg1)
casacore::RegionManager::doDifference
ImageRegion * doDifference(const PtrBlock< const WCRegion * > &reg1)
casacore::RegionManager::writeImageFile
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.
casacore::RegionManager::doconcatenation
ImageRegion * doconcatenation(const PtrBlock< const WCRegion * > &regions, const WCBox &box)
casacore::RegionManager::wbox
Record * wbox(const Vector< Quantity > &blc, const Vector< Quantity > &trc, const Vector< Int > &pixelaxes, const CoordinateSystem &csys, const String &absrel, const String &comment)
casacore::RegionManager::recordToTable
String recordToTable(const String &tabName, const RecordInterface &rec, const String &regName="", Bool asmask=False)
casacore::RegionManager::box
static Record * box(const Vector< Double > &blc, const Vector< Double > &trc, const Vector< Int > &shape, const String &comment="")
LCBox box.
casacore::RegionManager::readImageFile
static Record * readImageFile(String filename, String regionname)
Reading of a file containing an ImageRegion in the AipsIO format dump.
casacore::Int
int Int
Definition: aipstype.h:50
casacore
this file contains all the compiler specific defines
Definition: mainpage.dox:28
casacore::RegionManager::RegionManager
RegionManager()
blank constructor
casacore::RegionManager::wbox
ImageRegion * wbox(const Vector< Quantity > &blc, const Vector< Quantity > &trc, const Vector< Int > &pixelaxes, const CoordinateSystem &csys, const String &absrel="abs")
casacore::RegionManager::_getLog
LogIO * _getLog() const
Definition: RegionManager.h:261
casacore::RegionManager::doDifference
ImageRegion * doDifference(const WCRegion &reg1, const WCRegion &reg2)
Various versions of handling the difference of regions.
casacore::RegionManager::doDifference
ImageRegion * doDifference(const ImageRegion &reg1, const ImageRegion &reg2)
casacore::RegionManager::tableToRecord
Record * tableToRecord(const String &tabName, const String &regname)
recover region from table
casacore::RegionManager::namesInTable
Vector< String > namesInTable(const String &tabName)
names of regions in table
casacore::pa
LatticeExprNode pa(const LatticeExprNode &left, const LatticeExprNode &right)
This function finds 180/pi*atan2(left,right)/2.
casacore::RegionManager::wellipse
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
casacore::RecordInterface
Definition: RecordInterface.h:145
casacore::RegionManager::wellipse
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)
casacore::RegionManager::doUnion
ImageRegion * doUnion(const WCRegion &reg1, const WCRegion &reg2)
Different versions of unioning regions.
casacore::RegionManager::isPixelRegion
static Bool isPixelRegion(const ImageRegion &reg)
Some little but useful tidbits.
casacore::String
String: the storage and methods of handling collections of characters.
Definition: String.h:223
casacore::RegionManager::doIntersection
ImageRegion * doIntersection(const ImageRegion &reg1, const ImageRegion &reg2)
casacore::RegionManager::wellipsoid
static ImageRegion * wellipsoid(const Vector< Quantity > &center, const Vector< Quantity > &radii, const Vector< Int > &pixelaxes, const CoordinateSystem &csys, const String &absrel)
casacore::RegionManager::getTable
static Table & getTable(void *ptr, Bool writable)
Function to return the internal Table object to the RegionHandler.
casacore::Bool
bool Bool
Define the standard types used by Casacore.
Definition: aipstype.h:42
casacore::ImageRegion
Definition: ImageRegion.h:87
casacore::RegionManager::doComplement
ImageRegion * doComplement(const ImageRegion &reg1)
casacore::RegionManager
Definition: RegionManager.h:60
casacore::Record
Definition: Record.h:181
casacore::RegionManager::wsphere
static ImageRegion * wsphere(const Vector< Quantity > &center, const Quantity &radius, const Vector< Int > &pixelaxes, const CoordinateSystem &csys, const String &absrel)
casacore::Vector< Double >
casacore::RegionManager::setcoordsys
void setcoordsys(const CoordinateSystem &csys)
casacore::RegionManager::~RegionManager
virtual ~RegionManager()
casacore::RegionManager::toQuantity
void toQuantity(Quantity &out, const String &in)
Convert a string to Quantity.
casacore::RegionManager::doIntersection
ImageRegion * doIntersection(const WCRegion &reg1, const WCRegion &reg2)
Different versions of intersecting regions.
casacore::Quantum< Double >
casacore::RegionManager::tab_p
Table tab_p
Definition: RegionManager.h:270
casacore::RegionManager::doUnion
ImageRegion * doUnion(const ImageRegion &reg1, const ImageRegion &reg2) const
casacore::RegionManager::doUnion
ImageRegion * doUnion(const PtrBlock< const WCRegion * > &reg1)