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$ 00028 00029 #ifndef IMAGES_IMAGEOPENER_H 00030 #define IMAGES_IMAGEOPENER_H 00031 00032 00033 #include <casacore/casa/aips.h> 00034 #include <casacore/images/Images/MaskSpecifier.h> 00035 #include <casacore/casa/Containers/SimOrdMap.h> 00036 00037 namespace casacore { //# NAMESPACE CASACORE - BEGIN 00038 00039 //# Forward Declarations 00040 class LatticeBase; 00041 class LatticeExprNode; 00042 00043 // <summary> 00044 // Definition of image types and handlers 00045 // </summary> 00046 // 00047 // <use visibility=local> 00048 // 00049 // <reviewed reviewer="" date="yyyy/mm/dd" tests="" demos=""> 00050 // </reviewed> 00051 // 00052 // <synopsis> 00053 // The class contains defines the possible image types. 00054 // It contains a registry containing functions to construct an image 00055 // based on its type. In this way any image can be used in the image package 00056 // without the need that the code must reside in the images package. 00057 // </synopsis> 00058 // 00059 // <motivation> 00060 // FITS and MIRIAD needed to be moved out of the images package. 00061 // </motivation> 00062 00063 00064 class ImageOpener 00065 { 00066 public: 00067 // Define the possible image types. 00068 enum ImageTypes { 00069 // Casacore (former AIPS++) 00070 AIPSPP, 00071 // FITS 00072 FITS, 00073 // Miriad 00074 MIRIAD, 00075 // Gipsy 00076 GIPSY, 00077 // Classic AIPS 00078 CAIPS, 00079 // Newstar 00080 NEWSTAR, 00081 // HDF5 00082 HDF5, 00083 // ImageConcat 00084 IMAGECONCAT, 00085 // ImageExpr 00086 IMAGEEXPR, 00087 // Unknown 00088 UNKNOWN 00089 }; 00090 00091 // Return the type of an image with the given name. Will throw an 00092 // exception if file does not exist. 00093 static ImageTypes imageType (const String& fileName); 00094 00095 // Define the signature of a function opening an image. 00096 // Each basic image class (like FITSImage) must have a static open function 00097 // with this signature. 00098 // They can be registered using registerOpenImageFunction. 00099 // In this way a function like openImage can create any image object 00100 // without the need that all image classes are in the images package. 00101 // The LogIO object can be used for possible error reporting or logging. 00102 typedef LatticeBase* OpenImageFunction (const String& fileName, 00103 const MaskSpecifier&); 00104 00105 // Register an openImageFunction. 00106 static void registerOpenImageFunction (ImageTypes, OpenImageFunction*); 00107 00108 // Open an image in the file/table with the given name. 00109 // The specified mask will be applied (default is default mask). 00110 // A null pointer is returned for an unknown image type. 00111 // Non-Casacore image types must have been registered to be known. 00112 // Note that class ImageProxy has a function to open an image from a file 00113 // or from an image expression. 00114 static LatticeBase* openImage (const String& fileName, 00115 const MaskSpecifier& = MaskSpecifier()); 00116 00117 // Open a Casacore paged image of any data type. 00118 static LatticeBase* openPagedImage (const String& fileName, 00119 const MaskSpecifier& = MaskSpecifier()); 00120 00121 // Open an HDF5 paged image of any data type. 00122 static LatticeBase* openHDF5Image (const String& fileName, 00123 const MaskSpecifier& = MaskSpecifier()); 00124 00125 // Open a persistent image concatenation of any type. 00126 static LatticeBase* openImageConcat (const String& fileName); 00127 00128 // Open a persistent image expression of any type. 00129 // It reads the file written by ImageExpr::save. 00130 static LatticeBase* openImageExpr (const String& fileName); 00131 00132 // Parse an image expression and return the ImageExpr<T> object for it. 00133 // The block of nodes represents optional $i arguments in the expression. 00134 static LatticeBase* openExpr (const String& expr, 00135 const Block<LatticeExprNode>& nodes, 00136 const String& fileName = String()); 00137 00138 private: 00139 // The default openImage function for an unknown image type. 00140 // It returns a null pointer. 00141 static LatticeBase* unknownImageOpen (const String& name, 00142 const MaskSpecifier&); 00143 00144 // Mapping of the image type to an openImage function. 00145 static SimpleOrderedMap<ImageTypes,OpenImageFunction*> theirOpenFuncMap; 00146 }; 00147 00148 00149 } //# NAMESPACE CASACORE - END 00150 00151 #endif