00001 //# FITSMask.h: A Lattice that can be used for temporary storage 00002 //# Copyright (C) 1997,1998,1999,2000,2001,2002 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 LATTICES_FITSMASK_H 00030 #define LATTICES_FITSMASK_H 00031 00032 //# Includes 00033 #include <casacore/casa/aips.h> 00034 #include <casacore/casa/Arrays/Array.h> 00035 #include <casacore/lattices/Lattices/Lattice.h> 00036 00037 namespace casacore { //# NAMESPACE CASACORE - BEGIN 00038 00039 //# Forward Declarations 00040 class TiledFileAccess; 00041 00042 00043 // <summary> 00044 // Provides an on-the-fly mask for FITS images 00045 // </summary> 00046 00047 // <use visibility=export> 00048 00049 // <reviewed reviewer="" date="" tests="" demos=""> 00050 // </reviewed> 00051 00052 // <prerequisite> 00053 // <li> <linkto class="Lattice">Lattice</linkto> 00054 // <li> <linkto class="FITSImage">FITSImage</linkto> 00055 // </prerequisite> 00056 00057 // <etymology> 00058 // This class provides a pixel mask for the FITSImage class. 00059 // </etymology> 00060 00061 // <synopsis> 00062 // Masked values are indicated in FITS images via magic 00063 // value blanking. This class provides an on-the-fly mask. 00064 // The doGetSlice function reads the data values and returns 00065 // an Array<Bool> which is True (good) or False (bad - blanked) 00066 // 00067 // Because FITSMask inherits from Lattice<Bool> it can be 00068 // used as the private pixel mask data member for FITSImage 00069 // returned by the MaskedLattice::pixelMask() functions 00070 // 00071 // The FITSMask object is constructed from a TiledFileAccess 00072 // object. This must be the same one that the FITSImage 00073 // object constructs internally. It is shared by both 00074 // FITSImage and FITSMask. 00075 // 00076 // </synopsis> 00077 // 00078 // <example> 00079 // <srcblock> 00080 // </srcblock> 00081 // </example> 00082 00083 // <motivation> 00084 // FITSImage provides native access to FITS image files 00085 // and needede an efficient way to handle the pixel mask 00086 // other than iterating all the way through the image 00087 // first to set a mask. 00088 // </motivation> 00089 00090 //# <todo asof="yyyy/mm/dd"> 00091 //# <li> add this feature 00092 //# <li> fix this bug 00093 //# <li> start discussion of this possible extension 00094 //# </todo> 00095 00096 00097 class FITSMask : public Lattice<Bool> 00098 { 00099 public: 00100 00101 // Constructor (for 32 bit floating point). The pointer is not cloned, 00102 // just copied. 00103 FITSMask (TiledFileAccess* tiledFileAccess); 00104 00105 // Constructor (for 8 bit integers). The pointer is not cloned, just copied 00106 // The scale, offset, magic blanking values must come from 00107 // the FITS header ('bscale', 'bzero', 'blank') 00108 FITSMask (TiledFileAccess* tiledFileAccess, Float scale, Float offset, 00109 uChar magic, Bool hasBlanks); 00110 00111 // Constructor (for 16 bit integers). The pointer is not cloned, just copied 00112 // The scale, offset, magic blanking values must come from 00113 // the FITS header ('bscale', 'bzero', 'blank') 00114 FITSMask (TiledFileAccess* tiledFileAccess, Float scale, Float offset, 00115 Short magic, Bool hasBlanks); 00116 00117 // Constructor (for 32 bit integers). The pointer is not cloned, just copied 00118 // The scale, offset, magic blanking values must come from 00119 // the FITS header ('bscale', 'bzero', 'blank') 00120 FITSMask (TiledFileAccess* tiledFileAccess, Float scale, Float offset, 00121 Int magic, Bool hasBlanks); 00122 00123 // Copy constructor (reference semantics). The TiledFileAccess pointer 00124 // is just copied. 00125 FITSMask (const FITSMask& other) ; 00126 00127 // Destructor 00128 virtual ~FITSMask(); 00129 00130 // The assignment operator with reference semantics. 00131 // The TiledFileAccess pointer is just copied. 00132 FITSMask& operator= (const FITSMask& other); 00133 00134 // Make a copy of the object (reference semantics). 00135 virtual Lattice<Bool>* clone() const; 00136 00137 // Is the FITSMask writable? Returns False. Although it is not hard 00138 // to implement writing of the mask, data values would be lost 00139 // because of magic blanking. 00140 virtual Bool isWritable() const; 00141 00142 // Return the shape of the Lattice including all degenerate 00143 // axes (ie. axes with a length of one) 00144 IPosition shape() const; 00145 00146 // Do the actual getting of an array of values. 00147 virtual Bool doGetSlice (Array<Bool>& buffer, const Slicer& section); 00148 00149 // Do the actual getting of an array of values. Throws an exception. 00150 virtual void doPutSlice (const Array<Bool>& sourceBuffer, 00151 const IPosition& where, 00152 const IPosition& stride); 00153 00154 // Set the switch for also filtering 0.0 (besides NaNs). 00155 virtual void setFilterZero (Bool filterZero); 00156 00157 private: 00158 00159 // Mask out ONLY NaN's 00160 void filterNaN (Bool* pMask, const float* pData, uInt nelems); 00161 00162 // Mask out NaN's and values 0.0 00163 void filterZeroNaN (Bool* pMask, const Float* pData, uInt nelems); 00164 00165 // 00166 TiledFileAccess* itsTiledFilePtr; 00167 Array<Float> itsBuffer; 00168 Float itsScale, itsOffset; 00169 Short itsUCharMagic; 00170 Short itsShortMagic; 00171 Int itsLongMagic; 00172 Bool itsHasIntBlanks; 00173 Bool itsFilterZero; 00174 }; 00175 00176 00177 00178 } //# NAMESPACE CASACORE - END 00179 00180 #endif