ImageFactory.h

Go to the documentation of this file.
00001 //# tSubImage.cc: Test program for class SubImage
00002 //# Copyright (C) 1998,1999,2000,2001,2003
00003 //# Associated Universities, Inc. Washington DC, USA.
00004 //#
00005 //# This program is free software; you can redistribute it and/or modify it
00006 //# under the terms of the GNU General Public License as published by the Free
00007 //# Software Foundation; either version 2 of the License, or (at your option)
00008 //# any later version.
00009 //#
00010 //# This program 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 General Public License for
00013 //# more details.
00014 //#
00015 //# You should have received a copy of the GNU General Public License along
00016 //# with this program; if not, write to the Free Software Foundation, Inc.,
00017 //# 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: tSubImage.cc 20567 2009-04-09 23:12:39Z gervandiepen $
00027 
00028 #ifndef IMAGEANALYSIS_IMAGEFACTORY_H
00029 #define IMAGEANALYSIS_IMAGEFACTORY_H
00030 
00031 #include <imageanalysis/ImageTypedefs.h>
00032 
00033 #include <casa/Arrays/Array.h>
00034 #include <casa/BasicSL/String.h>
00035 #include <casa/Containers/Record.h>
00036 #include <casa/Logging/LogOrigin.h>
00037 #include <casa/namespace.h>
00038 #include <lattices/Lattices/LatticeBase.h>
00039 #include <utility>
00040 #include <vector>
00041 
00042 namespace casa {
00043 
00044 class CoordinateSystem;
00045 class IPosition;
00046 class Record;
00047 template <class T> class TempImage;
00048 template <class T> class Vector;
00049 
00050 class ImageFactory {
00051         // <summary>
00052         // Static methods for creating images 
00053         // </summary>
00054 
00055         // <reviewed reviewer="" date="" tests="" demos="">
00056         // </reviewed>
00057 
00058         // <prerequisite>
00059         // </prerequisite>
00060 
00061         // <etymology>
00062         // </etymology>
00063 
00064         // <synopsis>
00065         // </synopsis>
00066 
00067 public:
00068 
00069         enum ComplexToFloatFunction {
00070                 REAL,
00071                 IMAG
00072         };
00073 
00074         ImageFactory() = delete;
00075 
00076     ~ImageFactory() {};
00077 
00078     // Create a TempImage if outfile is empty, otherwise a PagedImage.
00079     // If log is True, log useful messages, quiet if False. Created image
00080     // has all pixel values set to zero and is unmasked.
00081     template <class T> static SPIIT createImage(
00082         const String& outfile,
00083         const CoordinateSystem& cSys, const IPosition& shape,
00084         Bool log, Bool overwrite,
00085         const std::vector<std::pair<LogOrigin, String> > *const &msgs
00086     );
00087 
00088     static String className() { static const String s = "ImageFactory"; return s; }
00089 
00090     // create an image with the specified shape and specified coordinate system.
00091     // If outfile is blank, the returned object is a TempImage, PagedImage otherwise.
00092     // If csys is empty,
00093     // a default coordiante system is attached to the image, and if linear
00094     // is True, it has linear coordinates in place of the direction coordinate.
00095 
00096     static SPIIF floatImageFromShape(
00097         const String& outfile, const Vector<Int>& shape,
00098         const Record& csys, Bool linear=True,
00099         Bool overwrite=False, Bool verbose=True,
00100         const std::vector<std::pair<LogOrigin, String> > *const &msgs=0
00101     );
00102 
00103     static SPIIC complexImageFromShape(
00104         const String& outfile, const Vector<Int>& shape,
00105         const Record& csys, Bool linear=True,
00106         Bool overwrite=False, Bool verbose=True,
00107         const std::vector<std::pair<LogOrigin, String> > *const &msgs=0
00108     );
00109 
00110     // only the pointer of the correct data type will be valid, the other
00111     // will be null.
00112     static std::pair<SPIIF, SPIIC> fromImage(
00113         const String& outfile, const String& infile,
00114         const Record& region, const String& mask,
00115         Bool dropdeg=False,
00116         Bool overwrite=False
00117     );
00118 
00119     template <class T> static SPIIT imageFromArray(
00120         const String& outfile, const Array<T>& pixels,
00121         const Record& csys, Bool linear=False,
00122         Bool overwrite=False, Bool verbose=True,
00123         const vector<std::pair<LogOrigin, String> > *const &msgs=0
00124     );
00125 
00126     static SPIIF fromASCII(
00127         const String& outfile, const String& infile,
00128         const IPosition& shape, const String& sep, const Record& csys,
00129         const Bool linear, const Bool overwrite
00130     );
00131 
00132     // Create a float-valued image from a complex-valued image. All metadata is copied
00133     // and pixel values are initialized according to <src>func</src>.
00134     static SHARED_PTR<TempImage<Float> > floatFromComplex(
00135         SPCIIC complexImage, ComplexToFloatFunction func
00136     );
00137 
00138     // Create a complex-valued image from a float-valued image (real part)
00139     // and float-valued array (imaginary part). All metadata is copied from the
00140     // real image and pixel values are initialized to realPart + i*complexPart
00141     static SHARED_PTR<TempImage<Complex> > complexFromFloat(
00142         SPCIIF realPart, const Array<Float>& imagPart
00143     );
00144 
00145     // Create a complex-valued image from a float-valued image (real part)
00146     // and float-valued array (imaginary part). All metadata is copied from the
00147     // real image and pixel values are initialized to realPart + i*complexPart
00148     static SPIIC makeComplex(
00149         SPCIIF realPart, SPCIIF imagPart, const String& outfile,
00150                 const Record& region, Bool overwrite = False
00151     );
00152 
00153     // exactly one of the pointers will not be null, indicating the
00154     // pixel data type
00155     static std::pair<SPIIF, SPIIC> fromFile(const String& filename);
00156 
00157     static SPIIF fromFITS(
00158         const String& outfile, const String& fitsfile,
00159         const Int whichrep, const Int whichhdu,
00160         const Bool zeroBlanks, const Bool overwrite
00161     );
00162 
00163     static std::pair<SPIIF, SPIIC> fromRecord(
00164         const RecordInterface& rec, const String& imagename=""
00165     );
00166 
00167     template <class T> static void remove(SPIIT& image, Bool verbose);
00168 
00169     // if successful, image will be reset to point to new image upon return
00170     static void rename(
00171         SPIIF& image, const String& name, const Bool overwrite
00172     );
00173 
00174     static void rename(
00175         SPIIC& image, const String& name, const Bool overwrite
00176     );
00177 
00178     // open a canonical image
00179     static SPIIF testImage(
00180         const String& outfile, const Bool overwrite,
00181         const String& imagetype="2d"
00182     );
00183 
00184     static void toASCII(
00185         SPCIIF image,
00186         const String& outfile, Record& region, const String& mask,
00187         const String& sep=" ", const String& format="%e",
00188         Double maskvalue=-999, Bool overwrite=False,
00189         Bool extendMask=False
00190     );
00191 
00192     static void toFITS(
00193         SPCIIF image, const String& outfile, Bool velocity,
00194                 Bool optical, Int bitpix, Double minpix, Double maxpix,
00195                 const Record& region, const String& mask,
00196                 Bool overwrite=False, Bool dropdeg=False, Bool deglast=False,
00197                 Bool dropstokes=False, Bool stokeslast=False,
00198                 Bool wavelength=False, Bool airWavelength=False,
00199                 const String& origin="", Bool stretch=False, Bool history=True
00200     );
00201 
00202 private:
00203 
00204         template <class T> static SPIIT _fromShape(
00205                 const String& outfile, const Vector<Int>& shape,
00206                 const Record& csys, Bool linear,
00207                 Bool overwrite, Bool verbose,
00208         const std::vector<std::pair<LogOrigin, String> > *const &msgs
00209         );
00210 
00211         template <class T> static SPIIT _fromRecord(
00212             const RecordInterface& rec, const String& name
00213         );
00214 
00215         static void _centerRefPix(
00216                 CoordinateSystem& csys, const IPosition& shape
00217         );
00218 
00219         static void _checkInfile(const String& infile);
00220 
00221     // Convert a Record to a CoordinateSystem
00222     static CoordinateSystem* _makeCoordinateSystem(
00223         const casa::Record& cSys,
00224         const casa::IPosition& shape
00225     );
00226 
00227     static void _checkOutfile(const String& outfile, Bool overwrite);
00228 
00229     static std::pair<SPIIF, SPIIC> _fromLatticeBase(std::unique_ptr<LatticeBase>& latt);
00230 
00231     // if successful, image will point to the newly named image
00232     // upone return
00233     template <class T> static std::pair<SPIIF, SPIIC> _rename(
00234         SPIIT& image, const String& name, const Bool overwrite
00235     );
00236 
00237 };
00238 }
00239 
00240 #ifndef AIPS_NO_TEMPLATE_SRC
00241 #include <imageanalysis/ImageAnalysis/ImageFactory.tcc>
00242 #endif
00243 
00244 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on 31 Aug 2016 for casa by  doxygen 1.6.1