casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
LatticeUtilities.h
Go to the documentation of this file.
00001 //# LatticeUtilities.h: useful global functions for Lattices
00002 //# Copyright (C) 1995,1996,1997,1999,2000,2001,2002,2004
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: LatticeUtilities.h 20229 2008-01-29 15:19:06Z gervandiepen $
00027 
00028 #ifndef LATTICES_LATTICEUTILITIES_H
00029 #define LATTICES_LATTICEUTILITIES_H
00030 
00031 #include <lattices/Lattices/LatticeStatsBase.h>
00032 
00033 #include <casa/aips.h>
00034 
00035 namespace casa { //# NAMESPACE CASA - BEGIN
00036 
00037 template <class T> class Array;
00038 template <class T> class Lattice;
00039 template <class T> class MaskedLattice;
00040 template <class T> class MaskedArray;
00041 class IPosition;
00042 class LogIO;
00043 class Slicer;
00044 
00045 // <summary>Static functions for Lattices</summary>
00046 // <use visibility=export>
00047 
00048 // <reviewed reviewer="" date="yyyy/mm/dd" tests="tLatticeUtilities.cc" demos="">
00049 // </reviewed>
00050 //
00051 // <prerequisite>
00052 //   <li> <linkto class="Lattice">Lattice</linkto>
00053 // </prerequisite>
00054 //
00055 // <synopsis>
00056 // Some static helper functions for Lattices
00057 // </synopsis>
00058 //
00059 // <motivation>
00060 // Common functionality not appropriate for Lattice member functions
00061 // </motivation>
00062 //
00063 // <todo asof="2001/08/27">
00064 //   <li> nothing I know of
00065 // </todo>
00066 //
00067 
00068 
00069 class LatticeUtilities 
00070 {
00071    public:
00072 
00073 // Collapse the specified axes by averaging and recover the
00074 // pixel values.  If axes is empty, then the data just contains
00075 // all of the lattice (i.e. no collapse), 
00076 // but dropDegenerateAxes is stil honoured
00077    template <class T>
00078    static void collapse (Array<T>& data, const IPosition& axes,
00079                          const MaskedLattice<T>& in,
00080                          Bool dropDegenerateAxes);
00081 //
00082 // Collapse the specified axes by averaging and recover either/and
00083 // the pixel values and mask. If axes is empty, then the data and mask just contains
00084 // all of the lattice (i.e. no collapse)
00085 // but dropDegenerateAxes is stil honoured
00086    template <class T>
00087    static void collapse (
00088         Array<T>& data, Array<Bool>& mask,
00089     const IPosition& axes,
00090     const MaskedLattice<T>& lat,
00091     Bool dropDegenerateAxes,
00092     Bool getPixels=True, Bool getMask=True,
00093     const LatticeStatsBase::StatisticsTypes stat=LatticeStatsBase::MEAN
00094    );
00095 
00096 // Copy data and mask from input to output.  If the input has no mask,
00097 // that means all True (good), and these values will be transferred
00098 // to the output.   Mask transfer only  occurs if the output has
00099 // a writeable mask.
00100    template <class T>
00101    static void copyDataAndMask (LogIO& os, MaskedLattice<T>& out,
00102                                 const MaskedLattice<T>& in, Bool zeroMasked=False);
00103 
00104 // Replicate array through lattice in the specified region.
00105 // The shape of <src>pixels</src> has to fit exactly into the shape of
00106 // the selected region for each axis of <src>pixels</src>. Otherwise
00107 // and exception will be thrown. For example,
00108 // if the shape of the region is [10,20], the shape of pixels could
00109 // be [10] and it will be replicated 20 times.  Another example would
00110 // be that the shape of pixels could be [5,10] and it would be
00111 // replicated 4 times fitting into the Lattice
00112    template <class T>
00113    static void replicate (Lattice<T>& lat,
00114                           const Slicer& region,
00115                           const Array<T>& pixels);
00116 
00117 // Bin up one axis of MaskedArray (uses Lattices in implementation)
00118    template <class T>
00119    static void bin (MaskedArray<T>& out, const MaskedArray<T>& in, uInt axis, uInt bin);
00120 
00121 // Add degenerate axes to the lattice if needed (nDim is the desired number of dimensions
00122 // for the output lattice).  If the shapes are the same, the returned
00123 // pointer holds a SubLattice.  If a reshape was necessary, the pointer
00124 // holds an ExtendLattice.  The pointer is the callers responsibility to delete.
00125    template <class T>
00126    static void addDegenerateAxes (Lattice<T>*& pLatOut, const Lattice<T>& latIn, uInt nDim);
00127 };
00128 
00129 // <summary>Global functions on Lattices</summary>
00130 // <use visibility=export>
00131 
00132 // <reviewed reviewer="" date="yyyy/mm/dd" tests="tLatticeUtilities.cc" demos="">
00133 // </reviewed>
00134 //
00135 // <prerequisite>
00136 //   <li> <linkto class="Lattice">Lattice</linkto>
00137 // </prerequisite>
00138 //
00139 // <synopsis>
00140 // Global functions using Lattices
00141 // </synopsis>
00142 //
00143 // <example>
00144 // <h4>Example 1:</h4>
00145 // Copy the lattice-type data between two Images.// <srcblock>
00146 //
00147 // PagedImage<Float> myImg ("myimagefile");
00148 // Float lmin;
00149 // Float lmax;
00150 // IPosition posMin = myImg.shape();
00151 // IPosition posMax = myImg.shape();
00152 // minMax( lmin, lmax, posMin, posMax, myImg );
00153 //
00154 // </srcblock>
00155 // </example>
00156 //
00157 //
00158 // <motivation>
00159 // Algorithms like CLEAN need to know the position of the MIN and MAX
00160 // of an image, but easy things like LEL's min and max don't tell you
00161 // the location of the min and max.  It seems there may be other global
00162 // functions involving lattices.
00163 // </motivation>
00164 //
00165 // <todo asof="1999/10/27">
00166 //   <li> nothing I know of
00167 // </todo>
00168 //
00169 // <group name=LatticeUtilities>
00170 
00171 // This global function finds the max of a Lattice, and also
00172 // the IPositions of the max.  (LEL does not get you the IPositions of the
00173 // min and max)
00174 
00175    template <class T>
00176    void minMax(T & min, T & max, 
00177                IPosition & posMin, IPosition & posMax, 
00178                const Lattice<T>& lat);
00179 
00180 // </group>
00181 
00182 
00183 } //# NAMESPACE CASA - END
00184 
00185 #ifndef CASACORE_NO_AUTO_TEMPLATES
00186 #include <lattices/Lattices/LatticeUtilities.tcc>
00187 #endif //# CASACORE_NO_AUTO_TEMPLATES
00188 #endif
00189 
00190