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