casacore
Loading...
Searching...
No Matches
RegionHandlerHDF5.h
Go to the documentation of this file.
1//# RegionHandlerHDF5.h: Class for keeping regions in an HDF5 file
2//# Copyright (C) 2008
3//# Associated Universities, Inc. Washington DC, USA.
4//#
5//# This library is free software; you can redistribute it and/or modify it
6//# under the terms of the GNU Library General Public License as published by
7//# the Free Software Foundation; either version 2 of the License, or (at your
8//# option) any later version.
9//#
10//# This library is distributed in the hope that it will be useful, but WITHOUT
11//# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12//# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
13//# License for more details.
14//#
15//# You should have received a copy of the GNU Library General Public License
16//# along with this library; if not, write to the Free Software Foundation,
17//# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
18//#
19//# Correspondence concerning AIPS++ should be addressed as follows:
20//# Internet email: casa-feedback@nrao.edu.
21//# Postal address: AIPS++ Project Office
22//# National Radio Astronomy Observatory
23//# 520 Edgemont Road
24//# Charlottesville, VA 22903-2475 USA
25
26#ifndef IMAGES_REGIONHANDLERHDF5_H
27#define IMAGES_REGIONHANDLERHDF5_H
28
29//# Includes
30#include <casacore/casa/aips.h>
31#include <casacore/images/Regions/RegionHandler.h>
32#include <casacore/casa/HDF5/HDF5File.h>
33#include <casacore/tables/Tables/TableRecord.h>
34
35namespace casacore { //# NAMESPACE CASACORE - BEGIN
36
37
38// <summary>
39// Class for keeping regions in an HDF5 file.
40// </summary>
41
42// <use visibility=local>
43
44// <reviewed reviewer="" date="" tests="tHDF5Image2.cc" demos="">
45// </reviewed>
46
47// <prerequisite>
48// <li> <linkto class=HDF5Image>HDF5Image</linkto>
49// <li> <linkto class=ImageRegion>ImageRegion</linkto>
50// </prerequisite>
51
52// <synopsis>
53// Persistent regions are stored as subrecords of the table keywords
54// "regions" and "masks". The user can choose one of both keywords.
55// Keyword "masks" is meant for true image masks, i.e. telling for
56// each pixel if it is good or bad. Keyword "regions" is meant for
57// true regions in an image.
58// <p>
59// This class handles defining, getting and removing such regions.
60// It is used by class <linkto class=PagedImage</linkto>, but it can also
61// be used by other code to handle regions in other tables.
62// <p>
63// Another function performed by this class for PagedImage is the
64// definition of the default region to be used with an image.
65// </synopsis>
66
67// <example>
68// </example>
69
70// <motivation>
71// This class has 2 purposes:
72// <ol>
73// <li> This untemplated code can be factored out from the templated
74// Image classes.
75// <li> The functions can easily be used by other code.
76// </ol>
77// </motivation>
78
79//# <todo asof="1999/02/16">
80//# <li>
81//# </todo>
82
83
85{
86public:
87 // The HDF5File object needed for the region operations.
88 typedef const std::shared_ptr<HDF5File>& GetCallback (void* objectPtr);
89
90 RegionHandlerHDF5 (GetCallback* callback, void* objectPtr);
91
92 // Copy constructor (copy semantics).
94
96
97 // Assignment (copy semantics).
99
100 // Make a copy of the object.
101 virtual RegionHandlerHDF5* clone() const;
102
103 // Set the object pointer for callback function.
104 virtual void setObjectPtr (void* objectPtr);
105
106 // This class can define and handle regions.
107 virtual Bool canDefineRegion() const;
108
109 // Set the default mask to the mask with the given name.
110 // It constructs a ImageRegion object for the new default mask.
111 // If the table is writable, the setting is persistent by writing
112 // the name as a keyword.
113 // If the given maskName is the empty string, the default mask is unset.
114 virtual void setDefaultMask (const String& maskName);
115
116 // Get the name of the default mask.
117 // An empty string is returned if no default mask.
118 virtual String getDefaultMask() const;
119
120 // Define a region belonging to the table.
121 // The group type determines if it stored as a region or mask.
122 // If overwrite=False, an exception will be thrown if the region
123 // already exists in the "regions" or "masks" keyword.
124 // Otherwise the region will be removed first.
125 // <br>A False status is returned if the table is not writable
126 virtual Bool defineRegion (const String& name,
127 const ImageRegion& region,
129 Bool overwrite = False);
130
131 // Does the table have a region with the given name?
132 virtual Bool hasRegion (const String& name,
134
135 // Get a region belonging to the table.
136 // A zero pointer is returned if the region does not exist.
137 // The caller has to delete the <src>ImageRegion</src> object created.
138 // <br>No exception is thrown if the region does not exist.
139 virtual ImageRegion* getRegion (const String& name,
141 Bool throwIfUnknown = True) const;
142
143 // Rename a region.
144 // If a region with the new name already exists, it is deleted or
145 // an exception is thrown (depending on <src>overwrite</src>).
146 // The region name is looked up in the given group(s).
147 // <br>An exception is thrown if the old region name does not exist.
148 virtual Bool renameRegion (const String& newName,
149 const String& oldName,
151 Bool overwrite = False);
152
153 // Remove a region belonging to the table.
154 // <br>Optionally an exception is thrown if the region does not exist.
155 // <br>A False status is returned if the table is not writable
156 virtual Bool removeRegion (const String& name,
158 Bool throwIfUnknown = True);
159
160 // Get the names of all regions/masks.
162
163 // Make a mask (an LCPagedMask) for a stored lattice (a PagedImage).
164 // It creates it with the shape and tile shape of the lattice.
165 virtual ImageRegion makeMask (const LatticeBase& lattice,
166 const String& name);
167
168 // Save the record containing the masking info in the HDF5 file.
169 // It is only saved if changed or if always is true.
170 void save (Bool always=False);
171
172 // Restore the record containing the masking info from the HDF5 file.
173 void restore();
174
175private:
176 // Get the file object.
177 const std::shared_ptr<HDF5File>& file() const
178 { return itsCallback (itsObjectPtr); }
179
180 // Find field number of the region group to which a region belongs
181 // (i.e. the field number of the "regions" or "masks" field).
182 // <0 is returned if the region does not exist.
183 // <br>Optionally an exception is thrown if the region does not exist.
184 virtual Int findRegionGroup (const String& regionName,
186 Bool throwIfUnknown = True) const;
187
188
190 Bool itsChanged; //# Has the record changed?
193};
194
195
196} //# NAMESPACE CASACORE - END
197
198#endif
RegionHandlerHDF5(GetCallback *callback, void *objectPtr)
virtual Bool removeRegion(const String &name, RegionHandler::GroupType=Any, Bool throwIfUnknown=True)
Remove a region belonging to the table.
virtual Bool defineRegion(const String &name, const ImageRegion &region, RegionHandler::GroupType, Bool overwrite=False)
Define a region belonging to the table.
virtual ImageRegion makeMask(const LatticeBase &lattice, const String &name)
Make a mask for a lattice (e.g.
void save(Bool always=False)
virtual Bool canDefineRegion() const
Can the class indeed define and handle regions? The default implementation returns False.
virtual RegionHandlerHDF5 * clone() const
Make a copy of the object.
virtual Int findRegionGroup(const String &regionName, RegionHandler::GroupType=Any, Bool throwIfUnknown=True) const
RegionHandlerHDF5 & operator=(const RegionHandlerHDF5 &)
const std::shared_ptr< HDF5File > & file() const
virtual Bool hasRegion(const String &name, RegionHandler::GroupType=RegionHandler::Any) const
Does the table have a region with the given name?
const std::shared_ptr< HDF5File > & GetCallback(void *objectPtr)
virtual String getDefaultMask() const
Get the name of the default mask.
virtual ImageRegion * getRegion(const String &name, RegionHandler::GroupType=Any, Bool throwIfUnknown=True) const
Get a region belonging to the table.
virtual Bool renameRegion(const String &newName, const String &oldName, RegionHandler::GroupType=Any, Bool overwrite=False)
Rename a region.
virtual Vector< String > regionNames(RegionHandler::GroupType=Any) const
Get the names of all regions/masks.
virtual void setDefaultMask(const String &maskName)
Set the default mask to the mask with the given name.
RegionHandlerHDF5(const RegionHandlerHDF5 &)
virtual void setObjectPtr(void *objectPtr)
Set the object pointer (for RegionHandlerTable's callback).
GroupType
Define the possible group types (regions or masks).
String: the storage and methods of handling collections of characters.
Definition String.h:223
this file contains all the compiler specific defines
Definition mainpage.dox:28
const Bool False
Definition aipstype.h:42
int Int
Definition aipstype.h:48
bool Bool
Define the standard types used by Casacore.
Definition aipstype.h:40
const Bool True
Definition aipstype.h:41