casa  5.7.0-16
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
SubImageFactory.h
Go to the documentation of this file.
1 //# SubImage.h: A (masked) subset of an casacore::ImageInterface object
2 //# Copyright (C) 1998,1999,2000,2001,2003
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: aips2-request@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 //# $Id: SubImage.h 20739 2009-09-29 01:15:15Z Malte.Marquarding $
27 
28 #ifndef IMAGESANALYSIS_SUBIMAGEFACTORY_H
29 #define IMAGESANALYSIS_SUBIMAGEFACTORY_H
30 
31 #include <images/Images/SubImage.h>
32 
34 
35 namespace casa { //# NAMESPACE CASA - BEGIN
36 
37 // <summary>
38 // Static methods for subimage creation
39 // </summary>
40 //
41 // <use visibility=export>
42 //
43 // <reviewed reviewer="" date="" tests="tSubImageFactory.cc">
44 // </reviewed>
45 //
46 // <prerequisite>
47 // <li> <linkto class=casacore::ImageInterface>casacore::SubImage</linkto>
48 // </prerequisite>
49 //
50 // <synopsis>
51 // Factory methods for creating subimages
52 // <srcblock>
53 // </srcblock>
54 // </example>
55 //
56 // <motivation>
57 // </motivation>
58 //
59 // <todo asof="2013/02/24">
60 // </todo>
61 
62 
63 template <class T> class SubImageFactory {
64 public:
65 
66  SubImageFactory() = delete;
67 
68  // Factory method to create a casacore::SubImage from a region and a casacore::WCLELMask string.
69  // Moved from ImageAnalysis
70  // <src>outRegion</src> Pointer to the corresponding region. Pointer is
71  // created internally by new(); it is the caller's responsibility to delete it.
72  // <src>outMask</src> Pointer to corresponding mask. Pointer is created
73  // internally via new(); it is the caller's responsibility to delete it.
74  // <src>inImage</src> input image for which a subimage is desired.
75  // <src>region</src> casacore::Input region record from which to make the subimage.
76  // <src>mask</src> LEL mask description.
77  // <src>os</src> Pointer to logger to which to log messages. If null, no logging (except exceptions).
78  // <src>writableIfPossible</src> make the subimage writable. If input image is not writable, this
79  // will always be false.
80  // <src>axesSpecifier</src> Specifier for output axes.
81  // <src>extendMask</src> If the mask has one
82  // or more of degenerate axes whereas the corresponding axes of <src>inImage</src> are
83  // not, extend the mask to match the shape of the input image.
84  // <src>preserveAxesOrder</src>. Only used when dropping degenerate axes and coordinate order
85  // and axes order are not the same. In that case, if false, the pixel/world axes order of the
86  // returned image will be different from the input, if true it will be the same. If not
87  // dropping degenerate axes or if coordinate order and axes order are the same in the input
88  // image's coordinate system, the output axex order will always be preserved.
89 
90  static std::shared_ptr<casacore::SubImage<T> > createSubImageRW(
92  casacore::ImageInterface<T>& inImage, const casacore::Record& region,
93  const casacore::String& mask, casacore::LogIO *const &os,
94  const casacore::AxesSpecifier& axesSpecifier=casacore::AxesSpecifier(),
95  casacore::Bool extendMask=false, casacore::Bool preserveAxesOrder=false
96  );
97 
98  // variant on previous method where caller doesn't have to worry
99  // about creating pointers it does not need returned.
100  static std::shared_ptr<casacore::SubImage<T> > createSubImageRW(
101  casacore::ImageInterface<T>& inImage, const casacore::Record& region,
102  const casacore::String& mask, casacore::LogIO *const &os,
103  const casacore::AxesSpecifier& axesSpecifier=casacore::AxesSpecifier(),
104  casacore::Bool extendMask=false, casacore::Bool preserveAxesOrder=false
105  );
106 
107  // The const casacore::ImageInterface versions where the resulting casacore::SubImage is not
108  // writable.
109  static std::shared_ptr<const casacore::SubImage<T> > createSubImageRO(
111  const casacore::ImageInterface<T>& inImage, const casacore::Record& region,
112  const casacore::String& mask, casacore::LogIO *const &os,
113  const casacore::AxesSpecifier& axesSpecifier=casacore::AxesSpecifier(),
114  casacore::Bool extendMask=false, casacore::Bool preserveAxesOrder=false
115  );
116 
117  // variant on previous method where caller doesn't have to worry
118  // about creating pointers it does not need returned.
119  static std::shared_ptr<const casacore::SubImage<T> > createSubImageRO(
120  const casacore::ImageInterface<T>& inImage, const casacore::Record& region,
121  const casacore::String& mask, casacore::LogIO *const &os,
122  const casacore::AxesSpecifier& axesSpecifier=casacore::AxesSpecifier(),
123  casacore::Bool extendMask=false, casacore::Bool preserveAxesOrder=false
124  );
125 
126  // <group>
127  // return a true copy (ie underlying data is a copy of the original, not
128  // a reference) of the subimage selected in the given region.
129  // A casacore::PagedImage is returned if outfile is not blank or a TempImage
130  // is returned if it is.
131  // If <src>attachMask</src> is true, attach a pixel mask to the newly created image
132  // if it otherwise wouldn't have a pixel mask. All the values in this mask will be
133  // true. If specified, data values will be copied from the <src>data</src> lattice.
134  // Note that data values only are copied from this lattice if it is specified;
135  // the mask values are still copied from the input image. The data lattice must
136  // be the same shape as the output image.
137  static SPIIT createImage(
138  const casacore::ImageInterface<T>& image,
139  const casacore::String& outfile, const casacore::Record& region,
140  const casacore::String& mask, casacore::Bool dropDegenerateAxes,
141  casacore::Bool overwrite, casacore::Bool list, casacore::Bool extendMask,
142  casacore::Bool attachMask=false, const casacore::Lattice<T> *const data=nullptr
143  );
144 
145  static SPIIT createImage(
146  const casacore::ImageInterface<T>& image,
147  const casacore::String& outfile, const casacore::Record& region,
148  const casacore::String& mask, const casacore::AxesSpecifier& axesSpec,
149  casacore::Bool overwrite, casacore::Bool list, casacore::Bool extendMask,
150  casacore::Bool attachMask=false, const casacore::Lattice<T> *const data=nullptr
151  );
152  // </group>
153 
154 private:
155 
156  static void _getMask(
158  casacore::Bool extendMask, const casacore::IPosition& imageShape,
159  const casacore::CoordinateSystem& csys
160  );
161 };
162 
163 
164 
165 } //# NAMESPACE CASA - END
166 
167 #ifndef CASACORE_NO_AUTO_TEMPLATES
168 #include <imageanalysis/ImageAnalysis/SubImageFactory.tcc>
169 #endif //# CASACORE_NO_AUTO_TEMPLATES
170 #endif
static std::shared_ptr< const casacore::SubImage< T > > createSubImageRO(casacore::CountedPtr< casacore::ImageRegion > &outRegion, casacore::CountedPtr< casacore::ImageRegion > &outMask, const casacore::ImageInterface< T > &inImage, const casacore::Record &region, const casacore::String &mask, casacore::LogIO *const &os, const casacore::AxesSpecifier &axesSpecifier=casacore::AxesSpecifier(), casacore::Bool extendMask=false, casacore::Bool preserveAxesOrder=false)
The const casacore::ImageInterface versions where the resulting casacore::SubImage is not writable...
A Vector of integers, for indexing into Array&lt;T&gt; objects.
Definition: IPosition.h:119
LatticeExprNode mask(const LatticeExprNode &expr)
This function returns the mask of the given expression.
ostream-like interface to creating log messages.
Definition: LogIO.h:167
Specification of axes to keep or remove.
ABSTRACT CLASSES Deliberately vague to be general enough to allow for many different types of data
Definition: PlotData.h:48
A templated, abstract base class for array-like objects.
Referenced counted pointer for constant data.
Definition: VisModelData.h:42
A base class for astronomical images.
#define SPIIT
Definition: ImageTypedefs.h:34
A hierarchical collection of named fields of various types.
Definition: Record.h:180
bool Bool
Define the standard types used by Casacore.
Definition: aipstype.h:42
static std::shared_ptr< casacore::SubImage< T > > createSubImageRW(casacore::CountedPtr< casacore::ImageRegion > &outRegion, casacore::CountedPtr< casacore::ImageRegion > &outMask, casacore::ImageInterface< T > &inImage, const casacore::Record &region, const casacore::String &mask, casacore::LogIO *const &os, const casacore::AxesSpecifier &axesSpecifier=casacore::AxesSpecifier(), casacore::Bool extendMask=false, casacore::Bool preserveAxesOrder=false)
Factory method to create a casacore::SubImage from a region and a casacore::WCLELMask string...
static SPIIT createImage(const casacore::ImageInterface< T > &image, const casacore::String &outfile, const casacore::Record &region, const casacore::String &mask, casacore::Bool dropDegenerateAxes, casacore::Bool overwrite, casacore::Bool list, casacore::Bool extendMask, casacore::Bool attachMask=false, const casacore::Lattice< T > *const data=nullptr)
return a true copy (ie underlying data is a copy of the original, not a reference) of the subimage se...
Static methods for subimage creation.
static void _getMask(casacore::CountedPtr< casacore::ImageRegion > &outMask, const casacore::String &mask, casacore::Bool extendMask, const casacore::IPosition &imageShape, const casacore::CoordinateSystem &csys)
String: the storage and methods of handling collections of characters.
Definition: String.h:223
Interconvert pixel and world coordinates.