casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
RegionManager.h
Go to the documentation of this file.
00001 //# RegionManager.h: framework independent class that provides 
00002 //# functionality to tool of same name
00003 //# Copyright (C) 2007
00004 //# Associated Universities, Inc. Washington DC, USA.
00005 //#
00006 //# This program is free software; you can redistribute it and/or modify it
00007 //# under the terms of the GNU General Public License as published by the Free
00008 //# Software Foundation; either version 2 of the License, or (at your option)
00009 //# any later version.
00010 //#
00011 //# This program is distributed in the hope that it will be useful, but WITHOUT
00012 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00013 //# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
00014 //# more details.
00015 //#
00016 //# You should have received a copy of the GNU General Public License along
00017 //# with this program; if not, write to the Free Software Foundation, Inc.,
00018 //# 675 Massachusetts Ave, Cambridge, MA 02139, USA.
00019 //#
00020 //# Correspondence concerning AIPS++ should be addressed as follows:
00021 //#        Internet email: aips2-request@nrao.edu.
00022 //#        Postal address: AIPS++ Project Office
00023 //#                        National Radio Astronomy Observatory
00024 //#                        520 Edgemont Road
00025 //#                        Charlottesville, VA 22903-2475 USA
00026 
00027 #ifndef IMAGES_REGIONMANAGER_H
00028 #define IMAGES_REGIONMANAGER_H
00029 
00030 #include <casa/Quanta/Quantum.h>
00031 #include <coordinates/Coordinates/CoordinateSystem.h>
00032 #include <lattices/Lattices/RegionType.h>
00033 #include <tables/Tables/Table.h>
00034 
00035 
00036 namespace casa {
00037 
00047   class LogIO;
00048   class String;
00049   class Record;
00050   template<class T> class Vector;
00051   class WCRegion;
00052   class WCBox;
00053   template<class T> class PtrBlock;
00054   class ImageRegion;
00055 
00056   class RegionManager
00057     {
00058       
00059       
00060     public:
00061 
00062       //blank constructor
00063       RegionManager();
00064       RegionManager(const CoordinateSystem& csys);
00065       virtual ~RegionManager();
00066       String absreltype(const Int absrelval=0);
00067 
00068       //Some little but useful tidbits.
00069       static Bool isPixelRegion(const ImageRegion& reg);
00070       static Bool isWorldRegion(const ImageRegion& reg);
00071       void setcoordsys(const CoordinateSystem& csys);
00072       const CoordinateSystem& getcoordsys() const ;
00073       
00074       //LCSlicer box
00075       Record* box(const Vector<Double>& blc, const Vector<Double>& trc, 
00076                   const Vector<Double>& inc, const String& absrel,
00077                   const Bool frac, const String& comment="");
00078       //LCBox box
00079       Record* box(const Vector<Double>& blc, const Vector<Double>& trc, 
00080                   const Vector<Int>& shape, const String& comment="");
00081       Record* wbox(const Vector<Quantity>& blc, 
00082                         const Vector<Quantity>& trc, 
00083                         const Vector<Int>& pixelaxes, 
00084                         const CoordinateSystem& csys,
00085                         const String& absrel, const String& comment);
00086       Record* wbox(const Vector<String>& blc, 
00087                         const Vector<String>& trc, 
00088                         const Vector<Int>& pixelaxes, 
00089                         const CoordinateSystem& csys,
00090                         const String& absrel, const String& comment);
00091       Record* wbox(const Vector<Quantity>& blc, 
00092                         const Vector<Quantity>& trc, 
00093                         const Vector<Int>& pixelaxes, 
00094                         const String& absrel, const String& comment);
00095       Record* wbox(const Vector<String>& blc, 
00096                         const Vector<String>& trc, 
00097                         const Vector<Int>& pixelaxes, 
00098                         const String& absrel, const String& comment);
00099       ImageRegion* wbox(const Vector<Quantity>& blc, 
00100                         const Vector<Quantity>& trc, 
00101                         const Vector<Int>& pixelaxes, 
00102                         const CoordinateSystem& csys,
00103                         const String& absrel="abs" );
00104       //Wpolygon with coordsys and if pixelaxes[0] is -1 then its assumed
00105       //to be 0,1,...
00106       ImageRegion* wpolygon(const Vector<Quantity>& x, 
00107                             const Vector<Quantity>& y, 
00108                             const Vector<Int>& pixelaxes, 
00109                             const CoordinateSystem& csys, 
00110                             const String& absrel);
00111       //wpolygon version without csys...throws an exception if 
00112       //setcoordsys is not run
00113       ImageRegion* wpolygon(const Vector<Quantity>& x, 
00114                             const Vector<Quantity>& y, 
00115                             const Vector<Int>& pixelaxes,  
00116                             const String& absrel);
00117       
00118      static ImageRegion* wellipse(
00119                   const Quantity& xc,
00120                   const Quantity& yc,
00121                   const Quantity& a,
00122                   const Quantity& b,
00123                   const Quantity& pa,
00124                   const uInt pixelAxis0,
00125                   const uInt pixelAxis1,
00126                   const CoordinateSystem& csys,
00127                   const String& absrel
00128       );
00129 
00130       //wellipse version without csys...throws an exception if
00131       //setcoordsys is not run
00132       ImageRegion* wellipse(
00133                   const Quantity& xc,
00134                   const Quantity& yc,
00135                   const Quantity& a,
00136                   const Quantity& b,
00137                   const Quantity& pa,
00138                   const uInt pixelAxis0,
00139                   const uInt pixelAxis1,
00140                   const String& absrel
00141       ) const;
00142 
00143       static ImageRegion* wsphere(
00144                   const Vector<Quantity>& center,
00145                   const Quantity& radius,
00146                   const Vector<Int>& pixelaxes,
00147                   const CoordinateSystem& csys,
00148                   const String& absrel
00149       );
00150       //wsphere version without csys...throws an exception if
00151       //setcoordsys is not run
00152       ImageRegion* wsphere(
00153                   const Vector<Quantity>& center,
00154                   const Quantity& radius,
00155                   const Vector<Int>& pixelaxes,
00156                   const String& absrel
00157       ) const;
00158 
00159       static ImageRegion* wellipsoid(
00160                   const Vector<Quantity>& center,
00161                   const Vector<Quantity>& radii,
00162                   const Vector<Int>& pixelaxes,
00163                   const CoordinateSystem& csys,
00164                   const String& absrel
00165       );
00166 
00167       ImageRegion* wellipsoid(
00168                   const Vector<Quantity>& center,
00169                   const Vector<Quantity>& radii,
00170                   const Vector<Int>& pixelaxes,
00171                   const String& absrel
00172       ) const;
00173 
00174       static ImageRegion* wshell(
00175                   const Vector<Quantity>& center,
00176                   const Vector<Quantity>& innerRadii,
00177                   const Vector<Quantity>& outerRadii,
00178                   const Vector<Int>& pixelaxes,
00179                   const CoordinateSystem& csys,
00180                   const String& absrel
00181       );
00182 
00183       ImageRegion* wshell(
00184                   const Vector<Quantity>& center,
00185                   const Vector<Quantity>& innerRadii,
00186                   const Vector<Quantity>& outerRadii,
00187                   const Vector<Int>& pixelaxes,
00188                   const String& absrel
00189       ) const;
00190 
00191       static ImageRegion* wmask(const String& command);
00192 
00193 
00194       /**************************************************************
00195        ** Routines for combining regions                           **
00196        **                                                          **
00197        ** Note: Many of the WCXxx classes which are used to do the **
00198        **       work can take multiple regions at once, why not    **
00199        **       accept a ptr block of Image Regions then?          **
00200        **************************************************************/
00201 
00202       //Various versions of creating a complement region
00203       ImageRegion*  doComplement(const WCRegion& reg1);
00204       ImageRegion*  doComplement(const PtrBlock<const WCRegion*>& reg1);
00205       ImageRegion*  doComplement(const ImageRegion& reg1);
00206 
00207       //Various versions of concatenating a region onto another.
00208       ImageRegion*  doConcatenation(const WCRegion& region, const WCBox& box);
00209       ImageRegion*  doconcatenation(const PtrBlock<const WCRegion*>& regions, const WCBox& box);
00210       ImageRegion*  doConcatenation(const PtrBlock<const ImageRegion*>& regions, const TableRecord& box);
00211       ImageRegion*  doConcatenation(const Record& regions, const TableRecord& box);
00212 
00213 
00214       //Various versions of handling the difference of regions
00215       ImageRegion*  doDifference(const WCRegion& reg1, const WCRegion& reg2);
00216       ImageRegion*  doDifference(const PtrBlock<const WCRegion*>& reg1);
00217       ImageRegion*  doDifference(const ImageRegion& reg1, const ImageRegion& reg2);
00218       
00219       //Different versions of intersecting regions
00220       ImageRegion*  doIntersection(const WCRegion& reg1, const WCRegion& reg2);
00221       ImageRegion*  doIntersection(const PtrBlock<const WCRegion*>& reg1);
00222       ImageRegion*  doIntersection(const ImageRegion& reg1, const ImageRegion& reg2);
00223 
00224       //Different versions of unioning regions
00225       ImageRegion*  doUnion(const WCRegion& reg1, const WCRegion& reg2);
00226       ImageRegion*  doUnion(const PtrBlock<const WCRegion*>& reg1);
00227       ImageRegion*  doUnion(const ImageRegion& reg1, const ImageRegion& reg2) const;
00228       
00229 
00230       /**************************************************************
00231        ** Routines for reading/writing regions                     **
00232        **************************************************************/
00233 
00234       //Reading of a file containing an ImageRegion in the AipsIO format dump
00235       static Record* readImageFile( String filename, String regionname );
00236       //Writing a file of the AipsIO dump of the record representation of the region
00237       static Bool writeImageFile(const String& file, const String& regionname, const Record& regionRecord);
00238 
00239       
00240       //save region into a table (image, blank table or any other such)
00241       String imageRegionToTable(const String& tabName, 
00242                                 const ImageRegion& imreg,
00243                                 const String& regName, Bool asmask=False); 
00244 
00245       String recordToTable(const String& tabName, const RecordInterface& rec, 
00246                            const String& regName="", Bool asmask=False);
00247       //recover region from table
00248       Record* tableToRecord(const String& tabName,   const String& regname);
00249 
00250       //names of regions in table
00251       Vector<String> namesInTable(const String& tabName);
00252 
00253       //Remove a region from table...refuse is regionname is ""
00254       Bool removeRegionInTable(const String& tabName, const String& regName);
00255 
00256 
00257     protected:
00258       inline LogIO* _getLog() const { return itsLog; }
00259 
00260     private:
00261       LogIO *itsLog;
00262       CoordinateSystem* itsCSys;
00263       // Function to return the internal Table object to the RegionHandler.
00264       static Table& getTable (void* ptr, Bool writable);
00265       //Convert a string to Quantity
00266       void toQuantity(Quantity& out, const String& in);
00267       Table tab_p;
00268 
00269     };
00270 
00271 
00272 } // casa namespace
00273 #endif
00274