casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
RegionHandlerTable.h
Go to the documentation of this file.
00001 //# RegionHandlerTable.h: Class for keeping regions in memory
00002 //# Copyright (C) 2000
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: RegionHandlerTable.h 20615 2009-06-09 02:16:01Z Malte.Marquarding $
00027 
00028 #ifndef IMAGES_REGIONHANDLERTABLE_H
00029 #define IMAGES_REGIONHANDLERTABLE_H
00030 
00031 
00032 //# Includes
00033 #include <images/Regions/RegionHandler.h>
00034 
00035 namespace casa { //# NAMESPACE CASA - BEGIN
00036 
00037 //# Forward declarations
00038 class Table;
00039 
00040 
00041 // <summary>
00042 // Class for keeping regions in memory.
00043 // </summary>
00044 
00045 // <use visibility=local>
00046 
00047 // <reviewed reviewer="" date="" tests="tPagedImage2.cc" demos="">
00048 // </reviewed>
00049 
00050 // <prerequisite>
00051 //   <li> <linkto class=PagedImage>PagedImage</linkto>
00052 //   <li> <linkto class=ImageRegion>ImageRegion</linkto>
00053 // </prerequisite>
00054 
00055 // <synopsis> 
00056 // Persistent regions are stored as subrecords of the table keywords
00057 // "regions" and "masks". The user can choose one of both keywords.
00058 // Keyword "masks" is meant for true image masks, i.e. telling for
00059 // each pixel if it is good or bad. Keyword "regions" is meant for
00060 // true regions in an image.
00061 // <p>
00062 // This class handles defining, getting and removing such regions.
00063 // It is used by class <linkto class=PagedImage</linkto>, but it can also
00064 // be used by other code to handle regions in other tables.
00065 // <p>
00066 // Another function performed by this class for PagedImage is the
00067 // definition of the default region to be used with an image.
00068 // </synopsis> 
00069 
00070 // <example>
00071 // </example>
00072 
00073 // <motivation>
00074 // This class has 2 purposes:
00075 // <ol>
00076 // <li> This untemplated code can be factored out from the templated
00077 //      Image classes.
00078 // <li> The functions can easily be used by other code.
00079 // </ol>
00080 // </motivation>
00081 
00082 //# <todo asof="1999/02/16">
00083 //# <li>
00084 //# </todo>
00085 
00086 
00087 class RegionHandlerTable: public RegionHandler
00088 {
00089 public: 
00090   // Define the signature of the function being called to get
00091   // the table object needed for the region operations.
00092   typedef Table& GetCallback (void* objectPtr, Bool writable);
00093 
00094   RegionHandlerTable (GetCallback* callback, void* objectPtr);
00095 
00096   // Copy constructor (copy semantics).
00097   RegionHandlerTable (const RegionHandlerTable&);
00098 
00099   virtual ~RegionHandlerTable();
00100 
00101   // Assignment (copy semantics).
00102   RegionHandlerTable& operator= (const RegionHandlerTable&);
00103 
00104   // Make a copy of the object.
00105   virtual RegionHandlerTable* clone() const;
00106 
00107   // Set the object pointer for callback function.
00108   virtual void setObjectPtr (void* objectPtr);
00109 
00110   // This class can define and handle regions.
00111   virtual Bool canDefineRegion() const;
00112 
00113   // Set the default mask to the mask with the given name.
00114   // It constructs a ImageRegion object for the new default mask.
00115   // If the table is writable, the setting is persistent by writing
00116   // the name as a keyword.
00117   // If the given maskName is the empty string, the default mask is unset.
00118   virtual void setDefaultMask (const String& maskName);
00119 
00120   // Get the name of the default mask.
00121   // An empty string is returned if no default mask.
00122   virtual String getDefaultMask() const;
00123 
00124   // Define a region belonging to the table.
00125   // The group type determines if it stored as a region or mask.
00126   // If overwrite=False, an exception will be thrown if the region
00127   // already exists in the "regions" or "masks" keyword.
00128   // Otherwise the region will be removed first.
00129   // <br>A False status is returned if the table is not writable
00130   virtual Bool defineRegion (const String& name,
00131                              const ImageRegion& region,
00132                              RegionHandler::GroupType,
00133                              Bool overwrite = False);
00134 
00135   // Does the table have a region with the given name?
00136   virtual Bool hasRegion (const String& name,
00137                           RegionHandler::GroupType = RegionHandler::Any) const;
00138   
00139   // Get a region belonging to the table.
00140   // A zero pointer is returned if the region does not exist.
00141   // The caller has to delete the <src>ImageRegion</src> object created.
00142   // <br>No exception is thrown if the region does not exist.
00143   virtual ImageRegion* getRegion (const String& name,
00144                                   RegionHandler::GroupType = Any,
00145                                   Bool throwIfUnknown = True) const;
00146 
00147   // Rename a region.
00148   // If a region with the new name already exists, it is deleted or
00149   // an exception is thrown (depending on <src>overwrite</src>).
00150   // The region name is looked up in the given group(s).
00151   // <br>An exception is thrown if the old region name does not exist.
00152   virtual Bool renameRegion (const String& newName,
00153                              const String& oldName,
00154                              RegionHandler::GroupType = Any,
00155                              Bool overwrite = False);
00156 
00157   // Remove a region belonging to the table.
00158   // <br>Optionally an exception is thrown if the region does not exist.
00159   // <br>A False status is returned if the table is not writable
00160   virtual Bool removeRegion (const String& name,
00161                              RegionHandler::GroupType = Any,
00162                              Bool throwIfUnknown = True);
00163 
00164   // Get the names of all regions/masks.
00165   virtual Vector<String> regionNames (RegionHandler::GroupType = Any) const;
00166 
00167   // Make a mask (an LCPagedMask) for a stored lattice (a PagedImage).
00168   // It creates it with the shape and tile shape of the lattice.
00169   virtual ImageRegion makeMask (const LatticeBase& lattice,
00170                                 const String& name);
00171 
00172 private:
00173   // Get the table object.
00174   // <group>
00175   Table& rwTable()
00176     { return itsCallback (itsObjectPtr, True); }
00177   const Table& table() const
00178     { return itsCallback (const_cast<RegionHandlerTable*>(this)->itsObjectPtr,
00179                           False); }
00180   // </group>
00181 
00182   // Find field number of the region group to which a region belongs
00183   // (i.e. the field number of the "regions" or "masks" field).
00184   // <0 is returned if the region does not exist.
00185   // <br>Optionally an exception is thrown if the region does not exist.
00186   virtual Int findRegionGroup (const String& regionName,
00187                                RegionHandler::GroupType = Any,
00188                                Bool throwIfUnknown = True) const;
00189 
00190 
00191   GetCallback* itsCallback;
00192   void*        itsObjectPtr;
00193 };
00194 
00195 
00196 
00197 
00198 } //# NAMESPACE CASA - END
00199 
00200 #endif