casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
ImageCollapser.h
Go to the documentation of this file.
00001 //# tSubImage.cc: Test program for class SubImage
00002 //# Copyright (C) 1998,1999,2000,2001,2003
00003 //# Associated Universities, Inc. Washington DC, USA.
00004 //#
00005 //# This program is free software; you can redistribute it and/or modify it
00006 //# under the terms of the GNU General Public License as published by the Free
00007 //# Software Foundation; either version 2 of the License, or (at your option)
00008 //# any later version.
00009 //#
00010 //# This program 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 General Public License for
00013 //# more details.
00014 //#
00015 //# You should have received a copy of the GNU General Public License along
00016 //# with this program; if not, write to the Free Software Foundation, Inc.,
00017 //# 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: tSubImage.cc 20567 2009-04-09 23:12:39Z gervandiepen $
00027 
00028 #ifndef IMAGES_IMAGECOLLAPSER_H
00029 #define IMAGES_IMAGECOLLAPSER_H
00030 
00031 #include <imageanalysis/ImageAnalysis/ImageTask.h>
00032 #include <images/Images/SubImage.h>
00033 
00034 #include <casa/namespace.h>
00035 
00036 namespace casa {
00037 
00038 class ImageCollapser : public ImageTask {
00039         // <summary>
00040         // Top level interface which allows collapsing of images along a single axis. An aggregate method
00041         // (average, sum, etc) is applied to the collapsed pixels.
00042         // </summary>
00043 
00044         // <reviewed reviewer="" date="" tests="" demos="">
00045         // </reviewed>
00046 
00047         // <prerequisite>
00048         // </prerequisite>
00049 
00050         // <etymology>
00051         // Collapses image.
00052         // </etymology>
00053 
00054         // <synopsis>
00055         // High level interface for collapsing an image along a single axis.
00056         // </synopsis>
00057 
00058         // <example>
00059         // <srcblock>
00060         // ImageCollapser collapser();
00061         // collapser.collapse();
00062         // </srcblock>
00063         // </example>
00064 
00065 public:
00066 
00067         enum AggregateType {
00068                 //AVDEV,
00069                 MAX,
00070                 MEAN,
00071                 MEDIAN,
00072                 MIN,
00073                 RMS,
00074                 STDDEV,
00075                 SUM,
00076                 VARIANCE,
00077                 // set all pixels in output image to 0
00078                 ZERO,
00079                 UNKNOWN
00080         };
00081 
00082         // if <src>outname</src> is empty, no image will be written
00083         // if <src>overwrite</src> is True, if image already exists it will be removed
00084         // if <src>overwrite</src> is False, if image already exists exception will be thrown
00085         //
00086         // <group>
00087 
00088         ImageCollapser(
00089                 String aggString, const ImageInterface<Float> *const image,
00090                 const String& region, const Record *const regionRec,
00091                 const String& box,
00092                 const String& chanInp, const String& stokes,
00093                 const String& maskInp, const IPosition& axes,
00094                 const String& outname, const Bool overwrite
00095         );
00096 
00097         ImageCollapser(
00098                 const ImageInterface<Float> * const image,
00099                 const IPosition& axes, const Bool invertAxesSelection,
00100                 const AggregateType aggregateType,
00101                 const String& outname, const Bool overwrite
00102         );
00103         // </group>
00104 
00105         // destructor
00106         ~ImageCollapser();
00107 
00108         // perform the collapse. If <src>wantReturn</src> is True, return a pointer to the
00109         // collapsed image. The returned pointer is created via new(); it is the caller's
00110         // responsibility to delete the returned pointer. If <src>wantReturn</src> is False,
00111         // a NULL pointer is returned and pointer deletion is performed internally.
00112         ImageInterface<Float>* collapse(const Bool wantReturn) const;
00113 
00114         static ImageCollapser::AggregateType aggregateType(String& aggString);
00115 
00116         static const map<uInt, Float (*)(const Array<Float>&)>* funcMap();
00117         static const map<uInt, String>* funcNameMap();
00118         static const map<uInt, String>* minMatchMap();
00119 
00120         inline String getClass() const { return _class; }
00121 
00122 protected:
00123         inline  CasacRegionManager::StokesControl _getStokesControl() const {
00124                 return CasacRegionManager::USE_ALL_STOKES;
00125         }
00126 
00127         inline vector<Coordinate::Type> _getNecessaryCoordinates() const {
00128                 return vector<Coordinate::Type>(0);
00129         }
00130 
00131 private:
00132         Bool _invertAxesSelection;
00133         IPosition _axes;
00134         AggregateType _aggType;
00135         static const String _class;
00136 
00137         static map<uInt, Float (*)(const Array<Float>&)> _funcMap;
00138         static map<uInt, String> *_funcNameMap, *_minMatchMap;
00139 
00140         // disallow default constructor
00141         ImageCollapser();
00142 
00143         void _invert();
00144 
00145         //std::vector<ImageInputProcessor::OutputStruct> _getOutputStruct();
00146 
00147         void _finishConstruction();
00148 
00149         // necessary to improve performance
00150         void _doMedian(
00151                 const SubImage<Float>& subImage,
00152                 const std::auto_ptr<ImageInterface<Float> >& outImage
00153         ) const;
00154 
00155         void _attachOutputMask(
00156                 const std::auto_ptr<ImageInterface<Float> >& outImage,
00157                 const Array<Bool>& outMask
00158         ) const;
00159 
00160         static const map<uInt, Float (*)(const Array<Float>&)>& _getFuncMap();
00161 
00162 
00163 };
00164 }
00165 
00166 #endif