casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
ImageOpener.h
Go to the documentation of this file.
00001 //# ImageOpener.h: A class with static functions to open an image of any type
00002 //# Copyright (C) 2005
00003 //# Associated Universities, Inc. Washington DC, USA.
00004 //#
00005 //# This library is free software; you can redistribute it and/or modify it
00006 //# under the terms of the GNU Library General Public License as published by
00007 //# the Free Software Foundation; either version 2 of the License, or (at your
00008 //# option) any later version.
00009 //#
00010 //# This library 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 Library General Public
00013 //# License for more details.
00014 //#
00015 //# You should have received a copy of the GNU Library General Public License
00016 //# along with this library; if not, write to the Free Software Foundation,
00017 //# Inc., 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 //#
00027 //# $Id: ImageOpener.h 20410 2008-10-20 09:00:06Z gervandiepen $
00028 
00029 #ifndef IMAGES_IMAGEOPENER_H
00030 #define IMAGES_IMAGEOPENER_H
00031 
00032 
00033 #include <casa/aips.h>
00034 #include <images/Images/MaskSpecifier.h>
00035 #include <casa/Containers/SimOrdMap.h>
00036 
00037 namespace casa { //# NAMESPACE CASA - BEGIN
00038 
00039 //# Forward Declarations
00040 class LatticeBase;
00041 
00042 // <summary>
00043 // Definition of image types and handlers
00044 // </summary>
00045 //
00046 // <use visibility=local>
00047 //
00048 // <reviewed reviewer="" date="yyyy/mm/dd" tests="" demos="">
00049 // </reviewed>
00050 // 
00051 // <synopsis>
00052 // The class contains defines the possible image types.
00053 // It contains a registry containing functions to construct an image
00054 // based on its type. In this way any image can be used in the image package
00055 // without the need that the code must reside in the images package.
00056 // </synopsis>
00057 //
00058 // <motivation>
00059 // FITS and MIRIAD needed to be moved out of the images package.
00060 // </motivation>
00061 
00062 
00063 class ImageOpener
00064 {
00065 public:
00066 // Define the possible image types.
00067   enum ImageTypes {
00068     // AIPS++
00069     AIPSPP,
00070     // FITS
00071     FITS,
00072     // Miriad
00073     MIRIAD,
00074     // Gipsy
00075     GIPSY,
00076     // Classic AIPS
00077     CAIPS,
00078     // Newstar
00079     NEWSTAR,
00080     // HDF5
00081     HDF5,
00082     // Unknown
00083     UNKNOWN
00084    };
00085 
00086   // Return the type of an image with the given name.  Will throw an
00087   // exception if file does not exist.
00088   static ImageTypes imageType (const String& fileName);
00089 
00090   // Define the signature of a function opening an image.
00091   // Each basic image class (like FITSImage) must have a static open function
00092   // with this signature.
00093   // They can be registered using registerOpenImageFunction.
00094   // In this way a function like openImage can create any image object
00095   // without the need that all image classes are in the images package.
00096   // The LogIO object can be used for possible error reporting or logging.
00097   typedef LatticeBase* OpenImageFunction (const String& fileName,
00098                                           const MaskSpecifier&);
00099 
00100   // Register an openImageFunction.
00101   static void registerOpenImageFunction (ImageTypes, OpenImageFunction*);
00102 
00103   // Open an image in the file/table with the given name.
00104   // The specified mask will be applied (default is default mask).
00105   // A null pointer is returned for an unknown image type.
00106   // Non-AIPS++ image types must have been registered to be known.
00107   // Note that class ImageProxy has a function to open an image from a file
00108   // or from an image expression.
00109   static LatticeBase* openImage (const String& fileName,
00110                                  const MaskSpecifier& = MaskSpecifier());
00111 
00112   // Open an AIPS++ paged image of any data type.
00113   static LatticeBase* openPagedImage (const String& fileName,
00114                                       const MaskSpecifier& = MaskSpecifier());
00115 
00116   // Open an HDF5 paged image of any data type.
00117   static LatticeBase* openHDF5Image (const String& fileName,
00118                                      const MaskSpecifier& = MaskSpecifier());
00119 
00120 private:
00121   // The default openImage function for an unknown image type.
00122   // It returns a null pointer.
00123   static LatticeBase* unknownImageOpen (const String& name,
00124                                         const MaskSpecifier&);
00125 
00126   // Mapping of the image type to an openImage function.
00127   static SimpleOrderedMap<ImageTypes,OpenImageFunction*> theirOpenFuncMap;
00128 };
00129 
00130 
00131 } //# NAMESPACE CASA - END
00132 
00133 #endif