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