LCOV - code coverage report
Current view: top level - imageanalysis/ImageAnalysis - ImageInputProcessor2.tcc (source / functions) Hit Total Coverage
Test: casa_coverage.info Lines: 0 23 0.0 %
Date: 2023-10-25 08:47:59 Functions: 0 2 0.0 %

          Line data    Source code
       1             : 
       2             : //# Copyright (C) 1998,1999,2000,2001,2003
       3             : //# Associated Universities, Inc. Washington DC, USA.
       4             : //#
       5             : //# This program is free software; you can redistribute it and/or modify it
       6             : //# under the terms of the GNU General Public License as published by the Free
       7             : //# Software Foundation; either version 2 of the License, or (at your option)
       8             : //# any later version.
       9             : //#
      10             : //# This program is distributed in the hope that it will be useful, but WITHOUT
      11             : //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
      12             : //# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
      13             : //# more details.
      14             : //#
      15             : //# You should have received a copy of the GNU General Public License along
      16             : //# with this program; if not, write to the Free Software Foundation, Inc.,
      17             : //# 675 Massachusetts Ave, Cambridge, MA 02139, USA.
      18             : //#
      19             : //# Correspondence concerning AIPS++ should be addressed as follows:
      20             : //#        Internet email: aips2-request@nrao.edu.
      21             : //#        Postal address: AIPS++ Project Office
      22             : //#                        National Radio Astronomy Observatory
      23             : //#                        520 Edgemont Road
      24             : //#                        Charlottesville, VA 22903-2475 USA
      25             : //#
      26             : 
      27             : #include <imageanalysis/ImageAnalysis/ImageInputProcessor.h>
      28             : 
      29             : #include <casacore/casa/Utilities/Sort.h>
      30             : #include <iostream>
      31             : 
      32             : #include <casacore/images/Images/FITSImage.h>
      33             : #include <casacore/images/Images/MIRIADImage.h>
      34             : #include <casacore/images/Regions/WCBox.h>
      35             : #include <imageanalysis/ImageAnalysis/ImageMetaData.h>
      36             : 
      37             : #include <casacore/measures/Measures/Stokes.h>
      38             : 
      39             : namespace casa {
      40             : 
      41           0 : template<class T> void ImageInputProcessor::process(
      42             :         casacore::Record& regionRecord, casacore::String& diagnostics,
      43             :         std::vector<OutputDestinationChecker::OutputStruct> * const outputStruct, casacore::String& stokes,
      44             :         SPCIIT image,
      45             :         const casacore::Record* regionPtr, const casacore::String& regionName,
      46             :         const casacore::String& box, const casacore::String& chans,
      47             :         const CasacRegionManager::StokesControl& stokesControl, const casacore::Bool& allowMultipleBoxes,
      48             :         const std::vector<casacore::Coordinate::Type> *const &requiredCoordinateTypes, casacore::Bool verbose
      49             : ) {
      50           0 :         _process(
      51             :                 regionRecord, diagnostics, outputStruct, stokes,
      52             :                 image, regionPtr, regionName, box, chans, stokesControl,
      53             :                 allowMultipleBoxes, requiredCoordinateTypes, verbose
      54             :         );
      55           0 : }
      56             : 
      57           0 : template<class T> void ImageInputProcessor::_process(
      58             :     casacore::Record& regionRecord,
      59             :     casacore::String& diagnostics,
      60             :     std::vector<OutputDestinationChecker::OutputStruct> * const outputStruct,
      61             :     casacore::String& stokes, SPCIIT image,
      62             :     const casacore::Record *const &regionPtr,
      63             :     const casacore::String& regionName, const casacore::String& box,
      64             :     const casacore::String& chans, const CasacRegionManager::StokesControl& stokesControl,
      65             :     const casacore::Bool& allowMultipleBoxes,
      66             :     const std::vector<casacore::Coordinate::Type> *const &requiredCoordinateTypes,
      67             :     casacore::Bool verbose
      68             : ) {
      69           0 :         casacore::LogOrigin origin("ImageInputProcessor", __func__);
      70           0 :     *_log << origin;
      71           0 :     if (outputStruct != 0) {
      72           0 :         OutputDestinationChecker::checkOutputs(outputStruct, *_log);
      73             : 
      74             :     }
      75           0 :     *_log << origin;
      76           0 :     if (requiredCoordinateTypes) {
      77           0 :         for (
      78           0 :                 vector<casacore::Coordinate::Type>::const_iterator iter = requiredCoordinateTypes->begin();
      79           0 :                 iter != requiredCoordinateTypes->end(); iter++
      80             :         ) {
      81           0 :                 ThrowIf(
      82             :                         image->coordinates().findCoordinate(*iter) < 0,
      83             :                         "Image " + image->name() + " does not have required coordinate "
      84             :                                 + casacore::Coordinate::typeToString(*iter)
      85             :                 );
      86             :         }
      87             :     }
      88           0 :         ImageMetaData<T> md(image);
      89           0 :         _nSelectedChannels = md.nChannels();
      90           0 :         CasacRegionManager regionMgr(image->coordinates());
      91           0 :         regionRecord = regionMgr.fromBCS(
      92           0 :                 diagnostics, _nSelectedChannels, stokes,
      93             :                 regionPtr, regionName, chans,
      94           0 :                 stokesControl, box, image->shape(), image->name(),
      95             :                 verbose
      96             :         );
      97             :         // FIXME an exception can be incorrectly thrown for a union of two regions
      98             :         // in which one defines a single region in direction space and the
      99             :         // defines spectral extent
     100           0 :     ThrowIf(
     101             :         ! allowMultipleBoxes && regionRecord.isDefined("regions"),
     102             :         "Only a single n-dimensional rectangular region is supported"
     103             :     );
     104           0 :     _processHasRun = true;
     105           0 : }
     106             : 
     107             : template<class T> void ImageInputProcessor::_setRegion(
     108             :         casacore::Record& regionRecord, casacore::String& diagnostics,
     109             :         const casacore::ImageInterface<T> *image, const casacore::String& regionName
     110             : ) const {
     111             :         // region name provided
     112             :         casacore::File myFile(regionName);
     113             :         if (myFile.exists()) {
     114             :                 casacore::Record *rec = casacore::RegionManager::readImageFile(regionName, "");
     115             :                 regionRecord = *rec;
     116             :                 delete rec;
     117             :                 diagnostics = "Region read from file " + regionName;
     118             :         }
     119             :         else {
     120             : 
     121             :                 casacore::ImageRegion imRegion;
     122             :                 casacore::Regex otherImage("(.*)+:(.*)+");
     123             :                 try {
     124             :                         casacore::String imagename;
     125             :                         if (regionName.matches(otherImage)) {
     126             :                                 casacore::String res[2];
     127             :                                 casacore::split(regionName, res, 2, ":");
     128             :                                 imagename = res[0];
     129             :                                 casacore::PagedImage<casacore::Float> other(imagename);
     130             :                                 imRegion = other.getRegion(res[1]);
     131             :                         }
     132             :                         else {
     133             :                                 imRegion = image->getRegion(regionName);
     134             :                                 imagename = image->name();
     135             :                         }
     136             :                     regionRecord = casacore::Record(imRegion.toRecord(""));
     137             :                     diagnostics = "Used region " + regionName + " from image "
     138             :                                 + imagename + " table description";
     139             :                 }
     140             :                 catch (const casacore::AipsError& x) {
     141             :                         ThrowCc(
     142             :                                 "Unable to open region file or region table description "
     143             :                                 + regionName
     144             :                         );
     145             :                 }
     146             :         }
     147             : }
     148             : }
     149             :  

Generated by: LCOV version 1.16