00001 //# SubImage.h: A (masked) subset of an ImageInterface object 00002 //# Copyright (C) 1998,1999,2000,2001,2003 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 //# $Id: SubImage.h 20739 2009-09-29 01:15:15Z Malte.Marquarding $ 00027 00028 #ifndef IMAGESANALYSIS_SUBIMAGEFACTORY_H 00029 #define IMAGESANALYSIS_SUBIMAGEFACTORY_H 00030 00031 #include <images/Images/SubImage.h> 00032 00033 #include <imageanalysis/ImageTypedefs.h> 00034 00035 namespace casa { //# NAMESPACE CASA - BEGIN 00036 00037 // <summary> 00038 // Static methods for subimage creation 00039 // </summary> 00040 // 00041 // <use visibility=export> 00042 // 00043 // <reviewed reviewer="" date="" tests="tSubImageFactory.cc"> 00044 // </reviewed> 00045 // 00046 // <prerequisite> 00047 // <li> <linkto class=ImageInterface>SubImage</linkto> 00048 // </prerequisite> 00049 // 00050 // <synopsis> 00051 // Factory methods for creating subimages 00052 // <srcblock> 00053 // </srcblock> 00054 // </example> 00055 // 00056 // <motivation> 00057 // </motivation> 00058 // 00059 // <todo asof="2013/02/24"> 00060 // </todo> 00061 00062 00063 template <class T> class SubImageFactory { 00064 public: 00065 00066 SubImageFactory() = delete; 00067 00068 // Factory method to create a SubImage from a region and a WCLELMask string. 00069 // Moved from ImageAnalysis 00070 // <src>outRegion</src> Pointer to the corresponding region. Pointer is 00071 // created internally by new(); it is the caller's responsibility to delete it. 00072 // <src>outMask</src> Pointer to corresponding mask. Pointer is created 00073 // internally via new(); it is the caller's responsibility to delete it. 00074 // <src>inImage</src> input image for which a subimage is desired. 00075 // <src>region</src> Input region record from which to make the subimage. 00076 // <src>mask</src> LEL mask description. 00077 // <src>os</src> Pointer to logger to which to log messages. If null, no logging (except exceptions). 00078 // <src>writableIfPossible</src> make the subimage writable. If input image is not writable, this 00079 // will always be False. 00080 // <src>axesSpecifier</src> Specifier for output axes. 00081 // <src>extendMask</src> If the mask has one 00082 // or more of degenerate axes whereas the corresponding axes of <src>inImage</src> are 00083 // not, extend the mask to match the shape of the input image. 00084 // <src>preserveAxesOrder</src>. Only used when dropping degenerate axes and coordinate order 00085 // and axes order are not the same. In that case, if False, the pixel/world axes order of the 00086 // returned image will be different from the input, if True it will be the same. If not 00087 // dropping degenerate axes or if coordinate order and axes order are the same in the input 00088 // image's coordinate system, the output axex order will always be preserved. 00089 00090 static SHARED_PTR<SubImage<T> > createSubImageRW( 00091 CountedPtr<ImageRegion>& outRegion, CountedPtr<ImageRegion>& outMask, 00092 ImageInterface<T>& inImage, const Record& region, 00093 const String& mask, LogIO *const &os, 00094 const AxesSpecifier& axesSpecifier=AxesSpecifier(), 00095 Bool extendMask=False, Bool preserveAxesOrder=False 00096 ); 00097 00098 // variant on previous method where caller doesn't have to worry 00099 // about creating pointers it does not need returned. 00100 static SHARED_PTR<SubImage<T> > createSubImageRW( 00101 ImageInterface<T>& inImage, const Record& region, 00102 const String& mask, LogIO *const &os, 00103 const AxesSpecifier& axesSpecifier=AxesSpecifier(), 00104 Bool extendMask=False, Bool preserveAxesOrder=False 00105 ); 00106 00107 // The const ImageInterface versions where the resulting SubImage is not 00108 // writable. 00109 static SHARED_PTR<const SubImage<T> > createSubImageRO( 00110 CountedPtr<ImageRegion>& outRegion, CountedPtr<ImageRegion>& outMask, 00111 const ImageInterface<T>& inImage, const Record& region, 00112 const String& mask, LogIO *const &os, 00113 const AxesSpecifier& axesSpecifier=AxesSpecifier(), 00114 Bool extendMask=False, Bool preserveAxesOrder=False 00115 ); 00116 00117 // variant on previous method where caller doesn't have to worry 00118 // about creating pointers it does not need returned. 00119 static SHARED_PTR<const SubImage<T> > createSubImageRO( 00120 const ImageInterface<T>& inImage, const Record& region, 00121 const String& mask, LogIO *const &os, 00122 const AxesSpecifier& axesSpecifier=AxesSpecifier(), 00123 Bool extendMask=False, Bool preserveAxesOrder=False 00124 ); 00125 00126 // <group> 00127 // return a true copy (ie underlying data is a copy of the original, not 00128 // a reference) of the subimage selected in the given region. 00129 // A PagedImage is returned if outfile is not blank or a TempImage 00130 // is returned if it is. 00131 // If <src>attachMask</src> is True, attach a pixel mask to the newly created image 00132 // if it otherwise wouldn't have a pixel mask. All the values in this mask will be 00133 // True. If specified, data values will be copied from the <src>data</src> lattice. 00134 // Note that data values only are copied from this lattice if it is specified; 00135 // the mask values are still copied from the input image. The data lattice must 00136 // be the same shape as the output image. 00137 static SPIIT createImage( 00138 const ImageInterface<T>& image, 00139 const String& outfile, const Record& region, 00140 const String& mask, Bool dropDegenerateAxes, 00141 Bool overwrite, Bool list, Bool extendMask, 00142 Bool attachMask=False, const Lattice<T> *const data=nullptr 00143 ); 00144 00145 static SPIIT createImage( 00146 const ImageInterface<T>& image, 00147 const String& outfile, const Record& region, 00148 const String& mask, const AxesSpecifier& axesSpec, 00149 Bool overwrite, Bool list, Bool extendMask, 00150 Bool attachMask=False, const Lattice<T> *const data=nullptr 00151 ); 00152 // </group> 00153 00154 private: 00155 00156 static void _getMask( 00157 CountedPtr<ImageRegion>& outMask, const String& mask, 00158 Bool extendMask, const IPosition& imageShape, 00159 const CoordinateSystem& csys 00160 ); 00161 }; 00162 00163 00164 00165 } //# NAMESPACE CASA - END 00166 00167 #ifndef CASACORE_NO_AUTO_TEMPLATES 00168 #include <imageanalysis/ImageAnalysis/SubImageFactory.tcc> 00169 #endif //# CASACORE_NO_AUTO_TEMPLATES 00170 #endif