casa  5.7.0-16
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ImageFactory.h
Go to the documentation of this file.
1 //# tSubImage.cc: Test program for class SubImage
2 //# Copyright (C) 1998,1999,2000,2001,2003
3 //# Associated Universities, Inc. Washington DC, USA.
4 //#
5 //# This program is free software; you can redistribute it and/or modify it
6 //# under the terms of the GNU General Public License as published by the Free
7 //# Software Foundation; either version 2 of the License, or (at your option)
8 //# any later version.
9 //#
10 //# This program 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 General Public License for
13 //# more details.
14 //#
15 //# You should have received a copy of the GNU General Public License along
16 //# with this program; if not, write to the Free Software Foundation, Inc.,
17 //# 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: tSubImage.cc 20567 2009-04-09 23:12:39Z gervandiepen $
27 
28 #ifndef IMAGEANALYSIS_IMAGEFACTORY_H
29 #define IMAGEANALYSIS_IMAGEFACTORY_H
30 
32 
34 
41 #include <utility>
42 #include <vector>
43 
44 namespace casacore{
45 
46 class CoordinateSystem;
47 class IPosition;
48 class Record;
49 template <class T> class TempImage;
50 template <class T> class Vector;
51 }
52 
53 namespace casa {
54 
55 class ImageFactory {
56  // <summary>
57  // Static methods for creating images
58  // </summary>
59 
60  // <reviewed reviewer="" date="" tests="" demos="">
61  // </reviewed>
62 
63  // <prerequisite>
64  // </prerequisite>
65 
66  // <etymology>
67  // </etymology>
68 
69  // <synopsis>
70  // </synopsis>
71 
72 public:
73 
77  };
78 
79  ImageFactory() = delete;
80 
82 
83  // Create a casacore::TempImage if outfile is empty, otherwise a PagedImage.
84  // If log is true, log useful messages, quiet if false. Created image
85  // has all pixel values set to zero and is unmasked.
86  template <class T> static SPIIT createImage(
87  const casacore::String& outfile,
90  const std::vector<std::pair<casacore::LogOrigin, casacore::String> > *const &msgs
91  );
92 
93  // create a ComponentListImage
94  static std::shared_ptr<ComponentListImage> createComponentListImage(
95  const casacore::String& outfile, const casacore::Record& cl,
97  const casacore::Record& csys, casacore::Bool overwrite,
99  );
100 
102  static const casacore::String s = "ImageFactory"; return s;
103  }
104 
105  // create an image with the specified shape and specified coordinate system.
106  // If outfile is blank, the returned object is a casacore::TempImage, casacore::PagedImage otherwise.
107  // If csys is empty,
108  // a default coordiante system is attached to the image, and if linear
109  // is true, it has linear coordinates in place of the direction coordinate.
110 
111  static SPIIF floatImageFromShape(
112  const casacore::String& outfile,
114  const casacore::Record& csys, casacore::Bool linear=true,
115  casacore::Bool overwrite=false, casacore::Bool verbose=true,
116  const std::vector<
117  std::pair<casacore::LogOrigin, casacore::String>
118  > *const &msgs=nullptr
119  );
120 
122  const casacore::String& outfile,
124  const casacore::Record& csys, casacore::Bool linear=true,
125  casacore::Bool overwrite=false, casacore::Bool verbose=true,
126  const std::vector<
127  std::pair<casacore::LogOrigin, casacore::String>
128  > *const &msgs=nullptr
129  );
130 
132  const casacore::String& outfile,
134  const casacore::Record& csys, casacore::Bool linear=true,
135  casacore::Bool overwrite=false, casacore::Bool verbose=true,
136  const std::vector<
137  std::pair<casacore::LogOrigin, casacore::String>
138  > *const &msgs=nullptr
139  );
140 
143  const casacore::Record& csys, casacore::Bool linear=true,
144  casacore::Bool overwrite=false, casacore::Bool verbose=true,
145  const std::vector<
146  std::pair<casacore::LogOrigin, casacore::String>
147  > *const &msgs=nullptr
148  );
149 
150  // only the pointer of the correct data type will be valid, the other
151  // will be null.
152  static ITUPLE fromImage(
153  const casacore::String& outfile, const casacore::String& infile,
154  const casacore::Record& region, const casacore::String& mask,
155  casacore::Bool dropdeg=false,
156  casacore::Bool overwrite=false
157  );
158 
159  template <class T> static SPIIT imageFromArray(
160  const casacore::String& outfile, const casacore::Array<T>& pixels,
161  const casacore::Record& csys, casacore::Bool linear=false,
162  casacore::Bool overwrite=false, casacore::Bool verbose=true,
163  const std::vector<
164  std::pair<casacore::LogOrigin, casacore::String>
165  > *const &msgs=nullptr
166  );
167 
168  static SPIIF fromASCII(
169  const casacore::String& outfile, const casacore::String& infile,
170  const casacore::IPosition& shape, const casacore::String& sep,
171  const casacore::Record& csys, const casacore::Bool linear,
172  const casacore::Bool overwrite
173  );
174 
175  template <class T> static SPIIT fromShape(
176  const casacore::String& outfile,
178  const casacore::Record& csys, casacore::Bool linear=false,
179  casacore::Bool overwrite=false, casacore::Bool verbose=false,
180  const std::vector<
181  std::pair<casacore::LogOrigin, casacore::String>
182  > *const &msgs=nullptr
183  );
184 
185  // Create a float-valued image from a complex-valued image. All metadata is
186  // copied and pixel values are initialized according to <src>func</src>.
187  template<class T>
188  static std::shared_ptr<casacore::TempImage<T>> floatFromComplex(
189  std::shared_ptr<
190  const casacore::ImageInterface<std::complex<T>>
191  > complexImage, ComplexToFloatFunction func
192  );
193 
194  // Create a complex-valued image from two real valued images. All metadata
195  // is copied from the real image and pixel values are initialized to
196  // realPart + i*complexPart
197  template<class T>
198  static std::shared_ptr<casacore::TempImage<std::complex<T>>> makeComplexImage(
199  SPCIIT realPart, SPCIIT imagPart
200  );
201 
202  // Create a complex-valued image from two real-valued images. All metadata
203  // is copied from the real image and pixel values are initialized to
204  // realPart + i*complexPart
205  template<class T>
206  static std::shared_ptr<casacore::ImageInterface<std::complex<T>>> makeComplex(
207  SPCIIT realPart, SPCIIT imagPart, const casacore::String& outfile,
208  const casacore::Record& region, casacore::Bool overwrite = false
209  );
210 
211  // exactly one of the pointers will not be null, indicating the
212  // pixel data type. Cache is only used if the image is a CompoenentListImage
213  static ITUPLE fromFile(
214  const casacore::String& filename, casacore::Bool cache=casacore::True
215  );
216 
217  // for specific types
218  static SPIIF fromFile(
220  );
221 
222  static SPIID fromFile(
224  );
225 
226  static SPIIC fromFile(
228  );
229 
230  static SPIIDC fromFile(
232  );
233 
234  static SPIIF fromFITS(
235  const casacore::String& outfile, const casacore::String& fitsfile,
236  const casacore::Int whichrep, const casacore::Int whichhdu,
237  const casacore::Bool zeroBlanks, const casacore::Bool overwrite
238  );
239 
240  static std::pair<SPIIF, SPIIC> fromRecord(
241  const casacore::RecordInterface& rec, const casacore::String& imagename=""
242  );
243 
244  template <class T> static void remove(SPIIT& image, casacore::Bool verbose);
245 
246  // if successful, image will be reset to point to new image upon return
247  static void rename(
248  SPIIF& image, const casacore::String& name, const casacore::Bool overwrite
249  );
250 
251  static void rename(
252  SPIIC& image, const casacore::String& name, const casacore::Bool overwrite
253  );
254 
255  // open a canonical image
256  static SPIIF testImage(
257  const casacore::String& outfile, const casacore::Bool overwrite,
258  const casacore::String& imagetype="2d"
259  );
260 
261  static void toASCII(
262  SPCIIF image,
263  const casacore::String& outfile, casacore::Record& region, const casacore::String& mask,
264  const casacore::String& sep=" ", const casacore::String& format="%e",
265  casacore::Double maskvalue=-999, casacore::Bool overwrite=false,
266  casacore::Bool extendMask=false
267  );
268 
269  static void toFITS(
270  SPCIIF image, const casacore::String& outfile, casacore::Bool velocity,
271  casacore::Bool optical, casacore::Int bitpix, casacore::Double minpix, casacore::Double maxpix,
272  const casacore::Record& region, const casacore::String& mask,
273  casacore::Bool overwrite=false, casacore::Bool dropdeg=false, casacore::Bool deglast=false,
274  casacore::Bool dropstokes=false, casacore::Bool stokeslast=false,
275  casacore::Bool wavelength=false, casacore::Bool airWavelength=false,
276  const casacore::String& origin="", casacore::Bool stretch=false, casacore::Bool history=true
277  );
278 
279 private:
280 
281  template <class T> static SPIIT _fromRecord(
283  );
284 
285  static void _centerRefPix(
287  );
288 
289  static void _checkInfile(const casacore::String& infile);
290 
291  // Convert a casacore::Record to a CoordinateSystem
293  const casacore::Record& cSys,
295  );
296 
297  static void _checkOutfile(const casacore::String& outfile, casacore::Bool overwrite);
298 
299  static ITUPLE _fromLatticeBase(
300  std::unique_ptr<casacore::LatticeBase>& latt
301  );
302 
304  const casacore::String& outfile, const ITUPLE& imagePtrs
305  );
306 
308  const casacore::String& outfile, const casacore::IPosition& shape,
309  casacore::DataType dataType
310  );
311 
312  // if successful, image will point to the newly named image
313  // upone return
314  template <class T> static ITUPLE _rename(
315  SPIIT& image, const casacore::String& name,
316  const casacore::Bool overwrite
317  );
318 
319 };
320 }
321 
322 #ifndef AIPS_NO_TEMPLATE_SRC
323 #include <imageanalysis/ImageAnalysis/ImageFactory.tcc>
324 #endif
325 
326 #endif
A Vector of integers, for indexing into Array&lt;T&gt; objects.
Definition: IPosition.h:119
A 1-D Specialization of the Array class.
int Int
Definition: aipstype.h:50
static SPIIT imageFromArray(const casacore::String &outfile, const casacore::Array< T > &pixels, const casacore::Record &csys, casacore::Bool linear=false, casacore::Bool overwrite=false, casacore::Bool verbose=true, const std::vector< std::pair< casacore::LogOrigin, casacore::String > > *const &msgs=nullptr)
LatticeExprNode log(const LatticeExprNode &expr)
static void _checkOutfile(const casacore::String &outfile, casacore::Bool overwrite)
static SPIIT fromShape(const casacore::String &outfile, const casacore::Vector< casacore::Int > &shape, const casacore::Record &csys, casacore::Bool linear=false, casacore::Bool overwrite=false, casacore::Bool verbose=false, const std::vector< std::pair< casacore::LogOrigin, casacore::String > > *const &msgs=nullptr)
Temporary astronomical images.
static SPIIF testImage(const casacore::String &outfile, const casacore::Bool overwrite, const casacore::String &imagetype="2d")
open a canonical image
LatticeExprNode mask(const LatticeExprNode &expr)
This function returns the mask of the given expression.
static void toFITS(SPCIIF image, const casacore::String &outfile, casacore::Bool velocity, casacore::Bool optical, casacore::Int bitpix, casacore::Double minpix, casacore::Double maxpix, const casacore::Record &region, const casacore::String &mask, casacore::Bool overwrite=false, casacore::Bool dropdeg=false, casacore::Bool deglast=false, casacore::Bool dropstokes=false, casacore::Bool stokeslast=false, casacore::Bool wavelength=false, casacore::Bool airWavelength=false, const casacore::String &origin="", casacore::Bool stretch=false, casacore::Bool history=true)
static std::shared_ptr< casacore::ImageInterface< std::complex< T > > > makeComplex(SPCIIT realPart, SPCIIT imagPart, const casacore::String &outfile, const casacore::Record &region, casacore::Bool overwrite=false)
Create a complex-valued image from two real-valued images.
std::tuple< SPIIF, SPIIC, SPIID, SPIIDC > ITUPLE
Definition: ImageTypedefs.h:58
static SPIIF floatImageFromShape(const casacore::String &outfile, const casacore::Vector< casacore::Int > &shape, const casacore::Record &csys, casacore::Bool linear=true, casacore::Bool overwrite=false, casacore::Bool verbose=true, const std::vector< std::pair< casacore::LogOrigin, casacore::String > > *const &msgs=nullptr)
create an image with the specified shape and specified coordinate system.
static SPIIC complexImageFromShape(const casacore::String &outfile, const casacore::Vector< casacore::Int > &shape, const casacore::Record &csys, casacore::Bool linear=true, casacore::Bool overwrite=false, casacore::Bool verbose=true, const std::vector< std::pair< casacore::LogOrigin, casacore::String > > *const &msgs=nullptr)
static SPIIF fromFITS(const casacore::String &outfile, const casacore::String &fitsfile, const casacore::Int whichrep, const casacore::Int whichhdu, const casacore::Bool zeroBlanks, const casacore::Bool overwrite)
static ITUPLE _rename(SPIIT &image, const casacore::String &name, const casacore::Bool overwrite)
if successful, image will point to the newly named image upone return
static std::shared_ptr< casacore::TempImage< T > > floatFromComplex(std::shared_ptr< const casacore::ImageInterface< std::complex< T >> > complexImage, ComplexToFloatFunction func)
Create a float-valued image from a complex-valued image.
static std::shared_ptr< ComponentListImage > createComponentListImage(const casacore::String &outfile, const casacore::Record &cl, const casacore::Vector< casacore::Int > &shape, const casacore::Record &csys, casacore::Bool overwrite, casacore::Bool log, casacore::Bool cache)
create a ComponentListImage
std::shared_ptr< casacore::ImageInterface< casacore::Complex > > SPIIC
Definition: ImageTypedefs.h:53
ABSTRACT CLASSES Abstract class for colors Any implementation of color should be able to provide a hexadecimal form of the if a human readable name(i.e."black").In many places throughout the plotter
static void rename(SPIIF &image, const casacore::String &name, const casacore::Bool overwrite)
if successful, image will be reset to point to new image upon return
static void _centerRefPix(casacore::CoordinateSystem &csys, const casacore::IPosition &shape)
std::shared_ptr< casacore::ImageInterface< casacore::DComplex > > SPIIDC
Definition: ImageTypedefs.h:57
static ITUPLE fromImage(const casacore::String &outfile, const casacore::String &infile, const casacore::Record &region, const casacore::String &mask, casacore::Bool dropdeg=false, casacore::Bool overwrite=false)
only the pointer of the correct data type will be valid, the other will be null.
static ITUPLE fromFile(const casacore::String &filename, casacore::Bool cache=casacore::True)
exactly one of the pointers will not be null, indicating the pixel data type.
static std::pair< SPIIF, SPIIC > fromRecord(const casacore::RecordInterface &rec, const casacore::String &imagename="")
A base class for astronomical images.
#define SPIIT
Definition: ImageTypedefs.h:34
static ITUPLE _fromLatticeBase(std::unique_ptr< casacore::LatticeBase > &latt)
static casacore::String _imageCreationMessage(const casacore::String &outfile, const ITUPLE &imagePtrs)
double Double
Definition: aipstype.h:55
ComplexToFloatFunction
Static methods for creating images.
Definition: ImageFactory.h:74
std::shared_ptr< const casacore::ImageInterface< casacore::Float > > SPCIIF
Definition: ImageTypedefs.h:50
std::shared_ptr< casacore::ImageInterface< casacore::Double > > SPIID
Definition: ImageTypedefs.h:55
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
float Float
Definition: aipstype.h:54
static void toASCII(SPCIIF image, const casacore::String &outfile, casacore::Record &region, const casacore::String &mask, const casacore::String &sep=" ", const casacore::String &format="%e", casacore::Double maskvalue=-999, casacore::Bool overwrite=false, casacore::Bool extendMask=false)
static SPIIT createImage(const casacore::String &outfile, const casacore::CoordinateSystem &cSys, const casacore::IPosition &shape, casacore::Bool log, casacore::Bool overwrite, const std::vector< std::pair< casacore::LogOrigin, casacore::String > > *const &msgs)
Create a casacore::TempImage if outfile is empty, otherwise a PagedImage.
#define SPCIIT
Definition: ImageTypedefs.h:35
TableExprNode shape(const TableExprNode &array)
Function operating on any scalar or array resulting in a Double array containing the shape...
Definition: ExprNode.h:1944
template &lt;class T, class U&gt; class vector;
Definition: MSFlagger.h:37
virtual Origin origin() const =0
ABSTRACT METHODS //.
static casacore::String className()
Definition: ImageFactory.h:101
static SPIIT _fromRecord(const casacore::RecordInterface &rec, const casacore::String &name)
std::shared_ptr< casacore::ImageInterface< casacore::Float > > SPIIF
Definition: ImageTypedefs.h:51
static SPIID doubleImageFromShape(const casacore::String &outfile, const casacore::Vector< casacore::Int > &shape, const casacore::Record &csys, casacore::Bool linear=true, casacore::Bool overwrite=false, casacore::Bool verbose=true, const std::vector< std::pair< casacore::LogOrigin, casacore::String > > *const &msgs=nullptr)
static void _checkInfile(const casacore::String &infile)
static casacore::CoordinateSystem * _makeCoordinateSystem(const casacore::Record &cSys, const casacore::IPosition &shape)
Convert a casacore::Record to a CoordinateSystem.
static SPIIF fromASCII(const casacore::String &outfile, const casacore::String &infile, const casacore::IPosition &shape, const casacore::String &sep, const casacore::Record &csys, const casacore::Bool linear, const casacore::Bool overwrite)
String: the storage and methods of handling collections of characters.
Definition: String.h:223
static std::shared_ptr< casacore::TempImage< std::complex< T > > > makeComplexImage(SPCIIT realPart, SPCIIT imagPart)
Create a complex-valued image from two real valued images.
Abstract base class for Record classes.
static SPIIDC complexDoubleImageFromShape(const casacore::String &outfile, const casacore::Vector< casacore::Int > &shape, const casacore::Record &csys, casacore::Bool linear=true, casacore::Bool overwrite=false, casacore::Bool verbose=true, const std::vector< std::pair< casacore::LogOrigin, casacore::String > > *const &msgs=nullptr)
const Bool True
Definition: aipstype.h:43
Interconvert pixel and world coordinates.
#define casacore
&lt;X11/Intrinsic.h&gt; #defines true, false, casacore::Bool, and String.
Definition: X11Intrinsic.h:42