casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
RegionHandlerHDF5.h
Go to the documentation of this file.
00001 //# RegionHandlerHDF5.h: Class for keeping regions in an HDF5 file
00002 //# Copyright (C) 2008
00003 //# Associated Universities, Inc. Washington DC, USA.
00004 //#
00005 //# This library is free software; you can redistribute it and/or modify it
00006 //# under the terms of the GNU Library General Public License as published by
00007 //# the Free Software Foundation; either version 2 of the License, or (at your
00008 //# option) any later version.
00009 //#
00010 //# This library is distributed in the hope that it will be useful, but WITHOUT
00011 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00012 //# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
00013 //# License for more details.
00014 //#
00015 //# You should have received a copy of the GNU Library General Public License
00016 //# along with this library; if not, write to the Free Software Foundation,
00017 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
00018 //#
00019 //# Correspondence concerning AIPS++ should be addressed as follows:
00020 //#        Internet email: aips2-request@nrao.edu.
00021 //#        Postal address: AIPS++ Project Office
00022 //#                        National Radio Astronomy Observatory
00023 //#                        520 Edgemont Road
00024 //#                        Charlottesville, VA 22903-2475 USA
00025 //#
00026 //# $Id: RegionHandlerHDF5.h 20615 2009-06-09 02:16:01Z Malte.Marquarding $
00027 
00028 #ifndef IMAGES_REGIONHANDLERHDF5_H
00029 #define IMAGES_REGIONHANDLERHDF5_H
00030 
00031 //# Includes
00032 #include <images/Regions/RegionHandler.h>
00033 #include <casa/HDF5/HDF5File.h>
00034 #include <tables/Tables/TableRecord.h>
00035 
00036 namespace casa { //# NAMESPACE CASA - BEGIN
00037 
00038 
00039 // <summary>
00040 // Class for keeping regions in an HDF5 file.
00041 // </summary>
00042 
00043 // <use visibility=local>
00044 
00045 // <reviewed reviewer="" date="" tests="tHDF5Image2.cc" demos="">
00046 // </reviewed>
00047 
00048 // <prerequisite>
00049 //   <li> <linkto class=HDF5Image>HDF5Image</linkto>
00050 //   <li> <linkto class=ImageRegion>ImageRegion</linkto>
00051 // </prerequisite>
00052 
00053 // <synopsis> 
00054 // Persistent regions are stored as subrecords of the table keywords
00055 // "regions" and "masks". The user can choose one of both keywords.
00056 // Keyword "masks" is meant for true image masks, i.e. telling for
00057 // each pixel if it is good or bad. Keyword "regions" is meant for
00058 // true regions in an image.
00059 // <p>
00060 // This class handles defining, getting and removing such regions.
00061 // It is used by class <linkto class=PagedImage</linkto>, but it can also
00062 // be used by other code to handle regions in other tables.
00063 // <p>
00064 // Another function performed by this class for PagedImage is the
00065 // definition of the default region to be used with an image.
00066 // </synopsis> 
00067 
00068 // <example>
00069 // </example>
00070 
00071 // <motivation>
00072 // This class has 2 purposes:
00073 // <ol>
00074 // <li> This untemplated code can be factored out from the templated
00075 //      Image classes.
00076 // <li> The functions can easily be used by other code.
00077 // </ol>
00078 // </motivation>
00079 
00080 //# <todo asof="1999/02/16">
00081 //# <li>
00082 //# </todo>
00083 
00084 
00085 class RegionHandlerHDF5: public RegionHandler
00086 {
00087 public: 
00088   // The HDF5File object needed for the region operations.
00089   typedef const CountedPtr<HDF5File>& GetCallback (void* objectPtr);
00090 
00091   RegionHandlerHDF5 (GetCallback* callback, void* objectPtr);
00092 
00093   // Copy constructor (copy semantics).
00094   RegionHandlerHDF5 (const RegionHandlerHDF5&);
00095 
00096   virtual ~RegionHandlerHDF5();
00097 
00098   // Assignment (copy semantics).
00099   RegionHandlerHDF5& operator= (const RegionHandlerHDF5&);
00100 
00101   // Make a copy of the object.
00102   virtual RegionHandlerHDF5* clone() const;
00103 
00104   // Set the object pointer for callback function.
00105   virtual void setObjectPtr (void* objectPtr);
00106 
00107   // This class can define and handle regions.
00108   virtual Bool canDefineRegion() const;
00109 
00110   // Set the default mask to the mask with the given name.
00111   // It constructs a ImageRegion object for the new default mask.
00112   // If the table is writable, the setting is persistent by writing
00113   // the name as a keyword.
00114   // If the given maskName is the empty string, the default mask is unset.
00115   virtual void setDefaultMask (const String& maskName);
00116 
00117   // Get the name of the default mask.
00118   // An empty string is returned if no default mask.
00119   virtual String getDefaultMask() const;
00120 
00121   // Define a region belonging to the table.
00122   // The group type determines if it stored as a region or mask.
00123   // If overwrite=False, an exception will be thrown if the region
00124   // already exists in the "regions" or "masks" keyword.
00125   // Otherwise the region will be removed first.
00126   // <br>A False status is returned if the table is not writable
00127   virtual Bool defineRegion (const String& name,
00128                              const ImageRegion& region,
00129                              RegionHandler::GroupType,
00130                              Bool overwrite = False);
00131 
00132   // Does the table have a region with the given name?
00133   virtual Bool hasRegion (const String& name,
00134                           RegionHandler::GroupType = RegionHandler::Any) const;
00135   
00136   // Get a region belonging to the table.
00137   // A zero pointer is returned if the region does not exist.
00138   // The caller has to delete the <src>ImageRegion</src> object created.
00139   // <br>No exception is thrown if the region does not exist.
00140   virtual ImageRegion* getRegion (const String& name,
00141                                   RegionHandler::GroupType = Any,
00142                                   Bool throwIfUnknown = True) const;
00143 
00144   // Rename a region.
00145   // If a region with the new name already exists, it is deleted or
00146   // an exception is thrown (depending on <src>overwrite</src>).
00147   // The region name is looked up in the given group(s).
00148   // <br>An exception is thrown if the old region name does not exist.
00149   virtual Bool renameRegion (const String& newName,
00150                              const String& oldName,
00151                              RegionHandler::GroupType = Any,
00152                              Bool overwrite = False);
00153 
00154   // Remove a region belonging to the table.
00155   // <br>Optionally an exception is thrown if the region does not exist.
00156   // <br>A False status is returned if the table is not writable
00157   virtual Bool removeRegion (const String& name,
00158                              RegionHandler::GroupType = Any,
00159                              Bool throwIfUnknown = True);
00160 
00161   // Get the names of all regions/masks.
00162   virtual Vector<String> regionNames (RegionHandler::GroupType = Any) const;
00163 
00164   // Make a mask (an LCPagedMask) for a stored lattice (a PagedImage).
00165   // It creates it with the shape and tile shape of the lattice.
00166   virtual ImageRegion makeMask (const LatticeBase& lattice,
00167                                 const String& name);
00168 
00169   // Save the record containing the masking info in the HDF5 file.
00170   // It is only saved if changed or if always is true.
00171   void save (Bool always=False);
00172 
00173   // Restore the record containing the masking info from the HDF5 file.
00174   void restore();
00175 
00176 private:
00177   // Get the file object.
00178   const CountedPtr<HDF5File>& file() const
00179     { return itsCallback (itsObjectPtr); }
00180 
00181   // Find field number of the region group to which a region belongs
00182   // (i.e. the field number of the "regions" or "masks" field).
00183   // <0 is returned if the region does not exist.
00184   // <br>Optionally an exception is thrown if the region does not exist.
00185   virtual Int findRegionGroup (const String& regionName,
00186                                RegionHandler::GroupType = Any,
00187                                Bool throwIfUnknown = True) const;
00188 
00189 
00190   TableRecord  itsRecord;
00191   Bool         itsChanged;        //# Has the record changed?
00192   GetCallback* itsCallback;
00193   void*        itsObjectPtr;
00194 };
00195 
00196 
00197 } //# NAMESPACE CASA - END
00198 
00199 #endif