casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
ImageInputProcessor.h
Go to the documentation of this file.
00001 //# Copyright (C) 1998,1999,2000,2001,2003
00002 //# Associated Universities, Inc. Washington DC, USA.
00003 //#
00004 //# This program is free software; you can redistribute it and/or modify it
00005 //# under the terms of the GNU General Public License as published by the Free
00006 //# Software Foundation; either version 2 of the License, or (at your option)
00007 //# any later version.
00008 //#
00009 //# This program is distributed in the hope that it will be useful, but WITHOUT
00010 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00011 //# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
00012 //# more details.
00013 //#
00014 //# You should have received a copy of the GNU General Public License along
00015 //# with this program; if not, write to the Free Software Foundation, Inc.,
00016 //# 675 Massachusetts Ave, Cambridge, MA 02139, USA.
00017 //#
00018 //# Correspondence concerning AIPS++ should be addressed as follows:
00019 //#        Internet email: aips2-request@nrao.edu.
00020 //#        Postal address: AIPS++ Project Office
00021 //#                        National Radio Astronomy Observatory
00022 //#                        520 Edgemont Road
00023 //#                        Charlottesville, VA 22903-2475 USA
00024 //#
00025 
00026 #ifndef IMAGES_IMAGEINPUTPROCESSOR_H
00027 #define IMAGES_IMAGEINPUTPROCESSOR_H
00028 
00029 #include <images/Images/ImageInterface.h>
00030 
00031 #include <imageanalysis/Regions/CasacRegionManager.h>
00032 
00033 #include <casa/namespace.h>
00034 
00035 namespace casa {
00036 
00037 class ImageInputProcessor {
00038         // <summary>
00039         // Collection of methods for processing inputs to image analysis applications
00040         // </summary>
00041 
00042         // <reviewed reviewer="" date="" tests="" demos="">
00043         // </reviewed>
00044 
00045         // <prerequisite>
00046         // </prerequisite>
00047 
00048         // <etymology>
00049         // Processes inputs to image analysis apps.
00050         // </etymology>
00051 
00052         // <synopsis>
00053         // Collection of methods for processing inputs to image analysis applications
00054         // </synopsis>
00055 
00056 public:
00057 
00058         // struct for checking output file writability
00059         struct OutputStruct {
00060                 // label used for messages, eg "residual image", "estmates file"
00061                 String label;
00062                 // pointer to the output name
00063                 String *outputFile;
00064                 // is this file required to be written, or can the task continue if it cannot be?
00065                 Bool required;
00066                 // If a file by the same name already exists, will the task allow it to be overwritten?
00067                 Bool replaceable;
00068         };
00069 
00070         //constructor
00071         ImageInputProcessor();
00072 
00073         //Destructor
00074         ~ImageInputProcessor();
00075 
00076         // Process the inputs. Output parameters are the pointer to the
00077         // opened <src>image</src>, the specified region as a record (<src>
00078         // regionRecord</src>, and a <src>diagnostics</src> String describing
00079         // how the region was chosen. If provided, <src>regionPtr</src> should
00080         // be a pointer to a record created by a RegionManager method.
00081         // <src>stokesControl</src> indicates default
00082         // stokes range to use if <src>stokes</src> is blank. In this case <src>stokes</src>
00083         // will be set the the value of stokes that will be used. If
00084         // <src>allowMultipleBoxes</src> is False, an exception will be thrown if
00085         // the inputs specify multiple n-dimensional rectangles. This should usually
00086         // be set to false if the caller can only deal with a single n-dimensional
00087         // rectangular region.
00088     void process(
00089         ImageInterface<Float>*& image, Record& regionRecord,
00090         String& diagnostics,
00091         std::vector<OutputStruct> *const outputStruct,
00092         String& stokes, const String& imagename,
00093         const Record* regionPtr, const String& regionName,
00094         const String& box, const String& chans,
00095         const CasacRegionManager::StokesControl& stokesControl,
00096         const Bool& allowMultipleBoxes,
00097         const std::vector<Coordinate::Type> *const &requiredCoordinateTypes,
00098         Bool verbose=True
00099     );
00100 
00101         // Process the inputs. Use this version if the associated image already exists.
00102     // Output parameters the specified region as a record (<src>
00103         // regionRecord</src>, and a <src>diagnostics</src> String describing
00104         // how the region was chosen. If provided, <src>regionPtr</src> should
00105         // be a pointer to a record created by a RegionManager method.
00106     // <src>stokesControl</src> indicates default
00107         // stokes range to use if <src>stokes</src> is blank. In this case <src>stokes</src>
00108         // will be set the the value of stokes that will be used. If
00109         // <src>allowMultipleBoxes</src> is False, an exception will be thrown if
00110         // the inputs specify multiple n-dimensional rectangles. This should usually
00111         // be set to false if the caller can only deal with a single n-dimensional
00112         // rectangular region.
00113     void process(
00114         Record& regionRecord,
00115         String& diagnostics, std::vector<OutputStruct> *const outputStruct,
00116         String& stokes,
00117         const ImageInterface<Float> *const &image,
00118         const Record* regionPtr,
00119         const String& regionName, const String& box,
00120         const String& chans,
00121         const CasacRegionManager::StokesControl& stokesControl,
00122         const Bool& allowMultipleBoxes,
00123         const std::vector<Coordinate::Type> *const &requiredCoordinateTypes,
00124         Bool verbose=True
00125     );
00126 
00127     static void checkOutputs(std::vector<OutputStruct> *const output, LogIO& log);
00128 
00129     static void checkOutput(OutputStruct& output, LogIO& log);
00130 
00131     // Get the number of channels that have been selected. The process() method must
00132     // be called prior to calling this method or an exception is thrown.
00133     uInt nSelectedChannels() const;
00134 
00135 private:
00136     LogIO *_log;
00137     Bool _processHasRun;
00138     uInt _nSelectedChannels;
00139 
00140     void _process(
00141         Record& regionRecord, String& diagnostics,
00142         std::vector<OutputStruct>* outputStruct,
00143         String& stokes, const ImageInterface<Float> *const &image,
00144         const Record *const &regionPtr,
00145         const String& regionName, const String& box,
00146         const String& chans, const CasacRegionManager::StokesControl& stokesControl,
00147         const Bool& allowMultipleBoxes,
00148         const std::vector<Coordinate::Type> *const &requiredCoordinateTypes, Bool verbose
00149     );
00150 
00151     // set region given a pointer to a region record.
00152     void _setRegion(
00153         Record& regionRecord, String& diagnostics,
00154         const Record *const regionPtr
00155     ) const;
00156 
00157     void _setRegion(Record& regionRecord, String& diagnostics,
00158         const ImageInterface<Float> *const image, const String& regionName
00159     ) const;
00160 
00161     String _stokesFromRecord(
00162         const Record& region, const CoordinateSystem& csys
00163     ) const;
00164 
00165     String _pairsToString(const std::vector<uInt>& pairs) const;
00166 
00167 };
00168 
00169 }
00170 
00171 #endif /* IMAGES_IMAGEINPUTPROCESSOR_H */