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