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// <summary>
38// Class for keeping regions in an HDF5 file.
39// </summary>
40
41// <use visibility=local>
42
43// <reviewed reviewer="" date="" tests="tHDF5Image2.cc" demos="">
44// </reviewed>
45
46// <prerequisite>
47// <li> <linkto class=HDF5Image>HDF5Image</linkto>
48// <li> <linkto class=ImageRegion>ImageRegion</linkto>
49// </prerequisite>
50
51// <synopsis>
52// Persistent regions are stored as subrecords of the table keywords
53// "regions" and "masks". The user can choose one of both keywords.
54// Keyword "masks" is meant for true image masks, i.e. telling for
55// each pixel if it is good or bad. Keyword "regions" is meant for
56// true regions in an image.
57// <p>
58// This class handles defining, getting and removing such regions.
59// It is used by class <linkto class=PagedImage</linkto>, but it can also
60// be used by other code to handle regions in other tables.
61// <p>
62// Another function performed by this class for PagedImage is the
63// definition of the default region to be used with an image.
64// </synopsis>
65
66// <example>
67// </example>
68
69// <motivation>
70// This class has 2 purposes:
71// <ol>
72// <li> This untemplated code can be factored out from the templated
73// Image classes.
74// <li> The functions can easily be used by other code.
75// </ol>
76// </motivation>
77
78// # <todo asof="1999/02/16">
79// # <li>
80// # </todo>
81
83 public:
84 // The HDF5File object needed for the region operations.
85 typedef const std::shared_ptr<HDF5File>& GetCallback(void* objectPtr);
86
87 RegionHandlerHDF5(GetCallback* callback, void* objectPtr);
88
89 // Copy constructor (copy semantics).
91
93
94 // Assignment (copy semantics).
96
97 // Make a copy of the object.
98 virtual RegionHandlerHDF5* clone() const;
99
100 // Set the object pointer for callback function.
101 virtual void setObjectPtr(void* objectPtr);
102
103 // This class can define and handle regions.
104 virtual Bool canDefineRegion() const;
105
106 // Set the default mask to the mask with the given name.
107 // It constructs a ImageRegion object for the new default mask.
108 // If the table is writable, the setting is persistent by writing
109 // the name as a keyword.
110 // If the given maskName is the empty string, the default mask is unset.
111 virtual void setDefaultMask(const String& maskName);
112
113 // Get the name of the default mask.
114 // An empty string is returned if no default mask.
115 virtual String getDefaultMask() const;
116
117 // Define a region belonging to the table.
118 // The group type determines if it stored as a region or mask.
119 // If overwrite=False, an exception will be thrown if the region
120 // already exists in the "regions" or "masks" keyword.
121 // Otherwise the region will be removed first.
122 // <br>A False status is returned if the table is not writable
124 Bool overwrite = False);
125
126 // Does the table have a region with the given name?
128
129 // Get a region belonging to the table.
130 // A zero pointer is returned if the region does not exist.
131 // The caller has to delete the <src>ImageRegion</src> object created.
132 // <br>No exception is thrown if the region does not exist.
134 Bool throwIfUnknown = True) const;
135
136 // Rename a region.
137 // If a region with the new name already exists, it is deleted or
138 // an exception is thrown (depending on <src>overwrite</src>).
139 // The region name is looked up in the given group(s).
140 // <br>An exception is thrown if the old region name does not exist.
141 virtual Bool renameRegion(const String& newName, const String& oldName,
142 RegionHandler::GroupType = Any, Bool overwrite = False);
143
144 // Remove a region belonging to the table.
145 // <br>Optionally an exception is thrown if the region does not exist.
146 // <br>A False status is returned if the table is not writable
148 Bool throwIfUnknown = True);
149
150 // Get the names of all regions/masks.
152
153 // Make a mask (an LCPagedMask) for a stored lattice (a PagedImage).
154 // It creates it with the shape and tile shape of the lattice.
155 virtual ImageRegion makeMask(const LatticeBase& lattice, const String& name);
156
157 // Save the record containing the masking info in the HDF5 file.
158 // It is only saved if changed or if always is true.
159 void save(Bool always = False);
160
161 // Restore the record containing the masking info from the HDF5 file.
162 void restore();
163
164 private:
165 // Get the file object.
166 const std::shared_ptr<HDF5File>& file() const { return itsCallback(itsObjectPtr); }
167
168 // Find field number of the region group to which a region belongs
169 // (i.e. the field number of the "regions" or "masks" field).
170 // <0 is returned if the region does not exist.
171 // <br>Optionally an exception is thrown if the region does not exist.
173 Bool throwIfUnknown = True) const;
174
176 Bool itsChanged; // # Has the record changed?
179};
180
181} // namespace casacore
182
183#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?
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:355
For temporary backward namespace compatibility, use casa as alias for casacore.
Definition mainpage.dox:28
const Bool False
Definition aipstype.h:42
String name() const
Return the name of the field.
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