casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
RegionHandlerMemory.h
Go to the documentation of this file.
00001 //# RegionHandlerMemory.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: RegionHandlerMemory.h 20615 2009-06-09 02:16:01Z Malte.Marquarding $
00027 
00028 #ifndef IMAGES_REGIONHANDLERMEMORY_H
00029 #define IMAGES_REGIONHANDLERMEMORY_H
00030 
00031 
00032 //# Includes
00033 #include <images/Regions/RegionHandler.h>
00034 #include <casa/BasicSL/String.h>
00035 #include <casa/Containers/SimOrdMap.h>
00036 
00037 namespace casa { //# NAMESPACE CASA - BEGIN
00038 
00039 // <summary>
00040 // Class for keeping regions in memory.
00041 // </summary>
00042 
00043 // <use visibility=local>
00044 
00045 // <reviewed reviewer="" date="" tests="tPagedImage2.cc" demos="">
00046 // </reviewed>
00047 
00048 // <prerequisite>
00049 //   <li> <linkto class=PagedImage>PagedImage</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 // <p>
00067 // The class consists of static functions only.
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 RegionHandlerMemory: public RegionHandler
00088 {
00089 public: 
00090   RegionHandlerMemory();
00091 
00092   // Copy constructor (copy semantics).
00093   RegionHandlerMemory (const RegionHandlerMemory&);
00094 
00095   virtual ~RegionHandlerMemory();
00096 
00097   // Assignment (copy semantics).
00098   RegionHandlerMemory& operator= (const RegionHandlerMemory&);
00099 
00100   // Make a copy of the object.
00101   virtual RegionHandlerMemory* clone() const;
00102 
00103   // This class can define and handle regions.
00104   virtual Bool canDefineRegion() const;
00105 
00106   // Set the default mask to the mask with the given name.
00107   // If the given maskName is the empty string, the default mask is unset.
00108   virtual void setDefaultMask (const String& maskName);
00109 
00110   // Get the name of the default mask.
00111   // An empty string is returned if no default mask.
00112   virtual String getDefaultMask() const;
00113 
00114   // Define a region.
00115   // The group type determines if it is kept as a region or a mask.
00116   // If overwrite=False, an exception will be thrown if the region
00117   // already exists in the "regions" or "masks" group.
00118   // Otherwise the region will be removed first.
00119   // <br>It always returns a True status.
00120   virtual Bool defineRegion (const String& name,
00121                              const ImageRegion& region,
00122                              RegionHandler::GroupType,
00123                              Bool overwrite = False);
00124 
00125   // Is there a region with the given name?
00126   virtual Bool hasRegion (const String& name,
00127                           RegionHandler::GroupType = RegionHandler::Any) const;
00128   
00129   // Get a region with the given name from the given group.
00130   // A zero pointer is returned if the region does not exist.
00131   // The caller has to delete the <src>ImageRegion</src> object created.
00132   // <br>No exception is thrown if the region does not exist.
00133   virtual ImageRegion* getRegion (const String& name,
00134                                   RegionHandler::GroupType = Any,
00135                                   Bool throwIfUnknown = True) const;
00136 
00137   // Rename a region.
00138   // If a region with the new name already exists, it is deleted or
00139   // an exception is thrown (depending on <src>overwrite</src>).
00140   // The region name is looked up in the given group(s).
00141   // <br>An exception is thrown if the old region name does not exist.
00142   // <br>It always returns a True status.
00143   virtual Bool renameRegion (const String& newName,
00144                              const String& oldName,
00145                              RegionHandler::GroupType = Any,
00146                              Bool overwrite = False);
00147 
00148   // Remove a region from the given group.
00149   // <br>Optionally an exception is thrown if the region does not exist.
00150   // <br>It always returns a True status.
00151   virtual Bool removeRegion (const String& name,
00152                              RegionHandler::GroupType = Any,
00153                              Bool throwIfUnknown = True);
00154 
00155   // Get the names of all regions/masks.
00156   virtual Vector<String> regionNames (RegionHandler::GroupType = Any) const;
00157 
00158   // Make a mask (an LCMask) for a temporary lattice (a TempImage).
00159   // It creates it with the shape and tile shape of the lattice.
00160   virtual ImageRegion makeMask (const LatticeBase& lattice,
00161                                 const String& name);
00162 
00163 private:
00164   // Find group number of the region group to which a region belongs
00165   // (i.e. the field number of the "regions" or "masks" field).
00166   // -1 is returned if the region does not exist.
00167   // <br>Optionally an exception is thrown if the region does not exist.
00168   Int findRegionGroup (const String& regionName,
00169                        RegionHandler::GroupType = Any,
00170                        Bool throwIfUnknown = True) const;
00171 
00172   // Find a region..
00173   // It is used by getRegion (which makes a clone of the object).
00174   // A zero pointer is returned if the region does not exist.
00175   virtual ImageRegion* findRegion (const String& name,
00176                                    RegionHandler::GroupType = Any,
00177                                    Bool throwIfUnknown = True) const;
00178 
00179   // Remove all regions from the maps.
00180   void clear();
00181 
00182 
00183   String itsDefaultName;
00184   SimpleOrderedMap<String, void*>* itsMaps[2];
00185 };
00186 
00187 
00188 
00189 
00190 } //# NAMESPACE CASA - END
00191 
00192 #endif