LCOV - code coverage report
Current view: top level - imageanalysis/ImageAnalysis - ImagePadder.cc (source / functions) Hit Total Coverage
Test: casacpp_coverage.info Lines: 48 49 98.0 %
Date: 2024-11-06 17:42:47 Functions: 5 6 83.3 %

          Line data    Source code
       1             : //# tSubImage.cc: Test program for class SubImage
       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: casa-feedback@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             : //# $Id: $
      27             : 
      28             : #include <imageanalysis/ImageAnalysis/ImagePadder.h>
      29             : 
      30             : #include <imageanalysis/ImageAnalysis/SubImageFactory.h>
      31             : #include <casacore/images/Images/TempImage.h>
      32             : #include <casacore/images/Images/ImageUtilities.h>
      33             : 
      34             : using namespace casacore;
      35             : namespace casa {
      36             : 
      37             : const String ImagePadder::_class = "ImagePadder";
      38             : 
      39         127 : ImagePadder::ImagePadder(
      40             :         const SPCIIF image,
      41             :     const Record *const regionRec,
      42             :     const String& box,
      43             :     const String& chanInp, const String& stokes,
      44             :     const String& maskInp, const String& outname,
      45             :     const Bool overwrite
      46         127 : ) : ImageTask<Float>(
      47             :         image, "", regionRec, box, chanInp, stokes,
      48             :         maskInp, outname, overwrite
      49         127 :     ), _nPixels(0), _value(0), _good(False) {
      50         127 :     _construct();
      51         127 : }
      52             : 
      53         127 : ImagePadder::~ImagePadder() {}
      54             : 
      55         127 : void ImagePadder::setPaddingPixels(
      56             :     const uInt nPixels, const Float value,
      57             :     const Bool good
      58             : ) {
      59         127 :     _nPixels = nPixels;
      60         127 :     _value = value;
      61         127 :     _good = good;
      62         127 : }
      63             : 
      64         127 : SPIIF ImagePadder::pad(const Bool wantReturn) const {
      65         127 :     *_getLog() << LogOrigin(_class, __FUNCTION__, WHERE);
      66             :     std::shared_ptr<const SubImage<Float> > subImage = SubImageFactory<Float>::createSubImageRO(
      67         127 :         *this->_getImage(), *_getRegion(), _getMask(),
      68         381 :         _getLog().get(), AxesSpecifier(), _getStretch()
      69         381 :     );
      70         127 :     Vector<Int> dirAxes = subImage->coordinates().directionAxesNumbers();
      71         127 :     IPosition outShape = subImage->shape();
      72         127 :     outShape[dirAxes[0]] += 2*_nPixels;
      73         127 :     outShape[dirAxes[1]] += 2*_nPixels;
      74         127 :     CoordinateSystem newCoords = subImage->coordinates();
      75         127 :     Vector<Double> refpix = newCoords.referencePixel();
      76         127 :     refpix[dirAxes[0]] += _nPixels;
      77         127 :     refpix[dirAxes[1]] += _nPixels;
      78         127 :     newCoords.setReferencePixel(refpix);
      79         127 :     ArrayLattice<Bool> mask(outShape);
      80         127 :     mask.set(_good);
      81         127 :     IPosition blc(subImage->ndim(), 0);
      82         127 :     blc[dirAxes[0]] = _nPixels;
      83         127 :     blc[dirAxes[1]] = _nPixels;
      84         127 :     if (subImage->isMasked() || ! _good) {
      85         127 :         IPosition end = subImage->shape();
      86         127 :         Slicer slice(blc, end, Slicer::endIsLength);
      87         127 :         SubLattice<Bool> subLatt(mask, slice, True);
      88         127 :         ImageTask<Float>::_copyMask(subLatt, *subImage);
      89         127 :     }
      90         127 :     Array<Float> valArray(outShape, _value);
      91         127 :     ArrayLattice<Float> values(valArray);
      92         127 :     values.putSlice(subImage->get(), blc);
      93         127 :     const Array<Float>& vals = values.get();
      94         127 :     this->_reportOldNewImageShapes(outShape);
      95             :     SPIIF outImage = _prepareOutputImage(
      96         127 :         *subImage, &vals, &mask, &outShape, &newCoords
      97         127 :     );
      98         127 :     if (! wantReturn) {
      99           0 :         outImage.reset();
     100             :     }
     101         254 :     return outImage;
     102         127 : }
     103             : 
     104         127 : String ImagePadder::getClass() const {
     105         127 :     return _class;
     106             : }
     107             : 
     108             : }
     109             : 
     110             : 

Generated by: LCOV version 1.16