LCOV - code coverage report
Current view: top level - imageanalysis/ImageAnalysis - ImageHistograms.tcc (source / functions) Hit Total Coverage
Test: casacpp_coverage.info Lines: 25 58 43.1 %
Date: 2024-10-29 13:38:20 Functions: 5 8 62.5 %

          Line data    Source code
       1             : //# ImageHistograms.cc: generate histograms from an image
       2             : //# Copyright (C) 1996,1997,1998,1999,2000,2001,2003
       3             : //# Associated Universities, Inc. Washington DC, USA.
       4             : //#
       5             : //# This library is free software; you can redistribute it and/or modify it
       6             : //# under the terms of the GNU Library General Public License as published by
       7             : //# the Free Software Foundation; either version 2 of the License, or (at your
       8             : //# option) any later version.
       9             : //#
      10             : //# This library 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 Library General Public
      13             : //# License for more details.
      14             : //#
      15             : //# You should have received a copy of the GNU Library General Public License
      16             : //# along with this library; if not, write to the Free Software Foundation,
      17             : //# Inc., 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: ImageHistograms.tcc 19941 2007-02-27 05:36:58Z Malte.Marquarding $
      27             : 
      28             : #include <imageanalysis/ImageAnalysis/ImageHistograms.h>
      29             : 
      30             : #include <casacore/casa/aips.h>
      31             : #include <casacore/images/Images/ImageInterface.h>
      32             : #include <casacore/images/Images/ImageUtilities.h>
      33             : #include <casacore/lattices/LatticeMath/LatticeHistograms.h>
      34             : #include <casacore/casa/IO/ArrayIO.h>
      35             : #include <casacore/casa/Logging/LogIO.h>
      36             : #include <casacore/casa/BasicSL/String.h>
      37             : 
      38             : #include <sstream>
      39             : 
      40             : using namespace casacore;
      41             : 
      42             : namespace casa { //# NAMESPACE CASA - BEGIN
      43             : 
      44             : // Public functions
      45             : 
      46             : template <class T>
      47           1 : ImageHistograms<T>::ImageHistograms (const casacore::ImageInterface<T>& image, 
      48             :                                      casacore::LogIO &os,
      49             :                                      casacore::Bool showProgress,
      50             :                                      casacore::Bool forceDisk)
      51             : : casacore::LatticeHistograms<T>(image, os, showProgress, forceDisk),
      52           1 :   pInImage_p(0)
      53             : {
      54           1 :    if (!this->setNewImage(image)) {
      55           0 :       os_p << error_p << casacore::LogIO::EXCEPTION;
      56             :    }
      57           1 : }
      58             : 
      59             : 
      60             : template <class T>
      61           0 : ImageHistograms<T>::ImageHistograms (const casacore::ImageInterface<T>& image, 
      62             :                                      casacore::Bool showProgress,
      63             :                                      casacore::Bool forceDisk)
      64             : : casacore::LatticeHistograms<T>(image, showProgress, forceDisk),
      65           0 :   pInImage_p(0)
      66             : {
      67           0 :    if (!this->setNewImage(image)) {
      68           0 :       os_p << error_p << casacore::LogIO::EXCEPTION;
      69             :    }
      70           0 : }
      71             : 
      72             :  
      73             : template <class T>
      74           1 : ImageHistograms<T>::ImageHistograms(const ImageHistograms<T> &other)
      75             : : casacore::LatticeHistograms<T>(other),
      76           1 :   pInImage_p(0)
      77             : {
      78           1 :    if (pInImage_p!=0) delete pInImage_p;
      79           1 :    pInImage_p = other.pInImage_p->cloneII();
      80           1 : }      
      81             : 
      82             : 
      83             : template <class T>
      84           1 : ImageHistograms<T> &ImageHistograms<T>::operator=(const ImageHistograms<T> &other)
      85             : {
      86           1 :    if (this != &other) {
      87           1 :       casacore::LatticeHistograms<T>::operator=(other);
      88             : //
      89           1 :       if (pInImage_p!=0) delete pInImage_p;
      90           1 :       pInImage_p = other.pInImage_p->cloneII();
      91             :    }
      92           1 :    return *this;
      93             : }
      94             : 
      95             :  
      96             : 
      97             : template <class T>
      98           2 : ImageHistograms<T>::~ImageHistograms()
      99             : {
     100           2 :    delete pInImage_p;
     101           2 :    pInImage_p = 0;
     102           4 : }
     103             : 
     104             : template <class T>
     105           2 : Bool ImageHistograms<T>::setNewImage(const casacore::ImageInterface<T>& image)
     106             : {
     107           2 :    if (!goodParameterStatus_p) {
     108           0 :       return false;
     109             :    }
     110             :       
     111             : // Make a clone of the image
     112             :       
     113           2 :    if (pInImage_p!=0) delete pInImage_p;
     114           2 :    pInImage_p = image.cloneII();
     115             :       
     116             :       
     117             : // Pass it on to LatticeHistograms
     118             :    
     119           2 :    goodParameterStatus_p = this->setNewLattice(image);
     120             : //  
     121           2 :    return goodParameterStatus_p;
     122             : }
     123             : 
     124             : template <class T>
     125           0 : String ImageHistograms<T>::writeCoordinates(const casacore::IPosition& histPos) const
     126             : {
     127           0 :    ostringstream oss;
     128           0 :    const casacore::Int nDisplayAxes = displayAxes_p.nelements();
     129           0 :    if (nDisplayAxes > 0) {
     130           0 :       casacore::Vector<casacore::String> sWorld(1);
     131           0 :       casacore::Vector<casacore::Double> pixels(1);
     132           0 :       casacore::IPosition blc(pInImage_p->ndim(),0);
     133           0 :       casacore::IPosition trc(pInImage_p->shape()-1);
     134             : //
     135           0 :       casacore::CoordinateSystem cSys = pInImage_p->coordinates();
     136           0 :       for (casacore::Int j=0; j<nDisplayAxes; j++) {
     137           0 :          const casacore::Int worldAxis =cSys.pixelAxisToWorldAxis(displayAxes_p(j));
     138           0 :          const casacore::String name = cSys.worldAxisNames()(worldAxis);
     139             : 
     140             : // Get pixel coordinate relative to current lattice
     141             : 
     142           0 :          pixels(0) = casacore::Double(locHistInLattice(histPos,false)(j+1));
     143             : //
     144           0 :          if (casacore::ImageUtilities::pixToWorld (sWorld, cSys,
     145           0 :                                          displayAxes_p(j), cursorAxes_p,
     146           0 :                                          blc, trc, pixels, -1)) {
     147           0 :             oss <<  casacore::ImageUtilities::shortAxisName(name)
     148           0 :                 << "=" << locHistInLattice(histPos,true)+1 
     149           0 :                 << " (" << sWorld(0) << ")";
     150           0 :             if (j < nDisplayAxes-1) oss << ", ";
     151             :          } else {
     152           0 :             oss << "Axis " << displayAxes_p(j) + 1 
     153           0 :                 << "=" << locHistInLattice(histPos,true)+1;
     154           0 :             if (j < nDisplayAxes-1) oss << ", ";
     155             :          }
     156             :       }
     157           0 :    }
     158             : //
     159           0 :    return casacore::String(oss);
     160           0 : }
     161             : 
     162             : 
     163             : 
     164             : } //# NAMESPACE CASA - END
     165             : 

Generated by: LCOV version 1.16