LCOV - code coverage report
Current view: top level - components/ComponentModels - PointShape.cc (source / functions) Hit Total Coverage
Test: casacpp_coverage.info Lines: 108 131 82.4 %
Date: 2024-12-11 20:54:31 Functions: 21 28 75.0 %

          Line data    Source code
       1             : //# PointShape.cc:
       2             : //# Copyright (C) 1998,1999,2000
       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: PointShape.cc 21130 2011-10-18 07:39:05Z gervandiepen $
      27             : 
      28             : #include <components/ComponentModels/PointShape.h>
      29             : #include <components/ComponentModels/Flux.h>
      30             : #include <casacore/casa/Arrays/Vector.h>
      31             : #include <casacore/casa/Containers/RecordFieldId.h>
      32             : #include <casacore/casa/Containers/RecordInterface.h>
      33             : #include <casacore/casa/Exceptions/Error.h>
      34             : #include <casacore/casa/BasicSL/Complex.h>
      35             : #include <casacore/casa/BasicMath/Math.h>
      36             : #include <casacore/measures/Measures/MCDirection.h>
      37             : #include <casacore/measures/Measures/MeasConvert.h>
      38             : #include <casacore/casa/Quanta/MVAngle.h>
      39             : #include <casacore/casa/Quanta/QMath.h>
      40             : #include <casacore/casa/Quanta/Quantum.h>
      41             : #include <casacore/casa/Utilities/Assert.h>
      42             : #include <casacore/casa/BasicSL/String.h>
      43             : 
      44             : using namespace casacore;
      45             : namespace casa { //# NAMESPACE CASA - BEGIN
      46             : 
      47      113357 : PointShape::PointShape() 
      48      113357 :   :ComponentShape()
      49             : {
      50      113357 :   DebugAssert(ok(), AipsError);
      51      113357 : }
      52             : 
      53        2522 : PointShape::PointShape(const MDirection& direction)
      54        2522 :   :ComponentShape(direction)
      55             : {
      56        2522 :   DebugAssert(ok(), AipsError);
      57        2522 : }
      58             : 
      59       11458 : PointShape::PointShape(const PointShape& other)
      60       11458 :   :ComponentShape(other)
      61             : {
      62       11458 :   DebugAssert(ok(), AipsError);
      63       11458 : }
      64             : 
      65      252150 : PointShape::~PointShape() {
      66      127336 :   DebugAssert(ok(), AipsError);
      67      252150 : }
      68             : 
      69           0 : PointShape& PointShape::operator=(const PointShape& other) {
      70           0 :   ComponentShape::operator=(other);
      71           0 :   DebugAssert(ok(), AipsError);
      72           0 :   return *this;
      73             : }
      74             : 
      75      115769 : ComponentType::Shape PointShape::type() const {
      76      115769 :   DebugAssert(ok(), AipsError);
      77      115769 :   return ComponentType::POINT;
      78             : }
      79             : 
      80        2491 : Double PointShape::sample(const MDirection& direction, 
      81             :                           const MVAngle& pixelLatSize,
      82             :                           const MVAngle& pixelLongSize) const {
      83        2491 :   DebugAssert(ok(), AipsError);
      84        2491 :   const MDirection& compDir(refDirection());
      85        2491 :   const MDirection::Ref& compDirFrame(compDir.getRef());
      86        2491 :   const MDirection::MVType* compDirValue = &(compDir.getValue());
      87        2491 :   Bool deleteValue = false;
      88             :   // Convert direction to the same frame as the reference direction
      89        2491 :   if (ComponentShape::differentRefs(direction.getRef(), compDirFrame)) {
      90        2410 :     compDirValue = new MDirection::MVType
      91        2410 :       (MDirection::Convert(compDir, direction.getRef())().getValue());
      92        2410 :     deleteValue = true;
      93             :   }
      94             : //
      95        2491 :   const Double latSize = abs(pixelLatSize.radian());
      96        2491 :   const Double longSize = abs(pixelLongSize.radian());
      97        2491 :   const Double nearSize = max(latSize, longSize);
      98             : //
      99        2491 :   const MDirection::MVType& dirValue = direction.getValue();
     100             : //
     101        2491 :   Double retVal = dirIsInPixel (longSize, latSize, nearSize, dirValue, compDirValue);
     102             : //
     103        2491 :   if (deleteValue) delete compDirValue;
     104        2491 :   return retVal;
     105        2491 : }
     106             : 
     107             : 
     108           1 : void PointShape::sample(Vector<Double>& scale, 
     109             :                         const Vector<MDirection::MVType>& directions, 
     110             :                         const MDirection::Ref& refFrame, 
     111             :                         const MVAngle& pixelLatSize,
     112             :                         const MVAngle& pixelLongSize) const 
     113             : {
     114           1 :   DebugAssert(ok(), AipsError);
     115           1 :   const uInt nSamples = directions.nelements();
     116           1 :   DebugAssert(scale.nelements() == nSamples, AipsError);
     117             :   
     118           1 :   const MDirection& compDir(refDirection());
     119           1 :   const MDirection::Ref& compDirFrame(compDir.getRef());
     120           1 :   const MDirection::MVType* compDirValue = &(compDir.getValue());
     121           1 :   Bool deleteValue = false;
     122             :   // Convert direction to the same frame as the reference direction
     123           1 :   if (refFrame != compDirFrame) {
     124           1 :     compDirValue = new MDirection::MVType
     125           1 :       (MDirection::Convert(compDir, refFrame)().getValue());
     126           1 :     deleteValue = true;
     127             :   }
     128             : //
     129           1 :   const Double longSize = abs(pixelLongSize.radian());
     130           1 :   const Double latSize = abs(pixelLatSize.radian());
     131           1 :   const Double nearSize = max(latSize, longSize);
     132           1 :   scale = 0.0;
     133             : //
     134           2 :   for (uInt i = 0; i < nSamples; i++) {
     135           1 :     const MDirection::MVType& dirValue = directions(i);
     136           1 :     scale(i) = dirIsInPixel (longSize, latSize, nearSize, dirValue, compDirValue);
     137             :   }
     138           1 :   if (deleteValue) delete compDirValue;
     139           1 : }
     140             : 
     141     1994155 : DComplex PointShape::visibility(const Vector<Double>&,
     142             :                                 const Double&) const {
     143     1994155 :   DebugAssert(ok(), AipsError);
     144     1994155 :   return DComplex(1.0, 0.0);
     145             : }
     146             : 
     147           0 : void PointShape::visibility(Vector<DComplex>& scale, 
     148             :                             const Matrix<Double>&,
     149             :                             const Double&) const {
     150           0 :   DebugAssert(ok(), AipsError);
     151           0 :   scale = DComplex(1.0, 0.0);
     152           0 : }
     153             : 
     154       61975 : void PointShape::visibility(Matrix<DComplex>& scale, const Matrix<Double>& uvw,
     155             :                             const Vector<Double> & freq) const {
     156       61975 :   DebugAssert(ok(), AipsError);
     157       61975 :   scale.resize(uvw.ncolumn(), freq.nelements());
     158       61975 :   scale = DComplex(1.0, 0.0);
     159       61975 : }
     160             : 
     161           0 : Bool PointShape::isSymmetric() const {
     162           0 :   DebugAssert(ok(), AipsError);
     163           0 :   return true;
     164             : }
     165             : 
     166       11458 : ComponentShape* PointShape::clone() const {
     167       11458 :   DebugAssert(ok(), AipsError);
     168       11458 :   ComponentShape* tmpPtr = new PointShape(*this);
     169       11458 :   AlwaysAssert(tmpPtr != 0, AipsError);
     170       11458 :   return tmpPtr;
     171             : }
     172             : 
     173        2710 : uInt PointShape::nParameters() const {
     174        2710 :   DebugAssert(ok(), AipsError);
     175        2710 :   return 0;
     176             : }
     177             : 
     178        1217 : void PointShape::setParameters(const Vector<Double>& newParms) {
     179        1217 :   DebugAssert(newParms.nelements() == nParameters(), AipsError);
     180        1217 :   DebugAssert(ok(), AipsError);
     181             :   // Suppress compiler warning about unused variable
     182        1217 :   if (newParms.empty()) {}; 
     183        1217 : }
     184             : 
     185        2403 : Vector<Double> PointShape::parameters() const {
     186        2403 :   DebugAssert(ok(), AipsError);
     187        2403 :   return Vector<Double>(0);
     188             : }
     189             : 
     190        1217 : void PointShape::setErrors(const Vector<Double>& newErrors) {
     191        1217 :   DebugAssert(newErrors.nelements() == nParameters(), AipsError);
     192        1217 :   DebugAssert(ok(), AipsError);
     193             :   // Suppress compiler warning about unused variable
     194        1217 :   if (newErrors.empty()) {}; 
     195        1217 : }
     196             : 
     197        2403 : Vector<Double> PointShape::errors() const {
     198        2403 :   DebugAssert(ok(), AipsError);
     199        2403 :   return Vector<Double>(0);
     200             : }
     201             : 
     202           0 : Vector<Double> PointShape::optParameters() const {
     203           0 :   DebugAssert(ok(), AipsError);
     204           0 :   return Vector<Double>(0);
     205             : }
     206             : 
     207           0 : void PointShape::setOptParameters(const Vector<Double>& newOptParms) {
     208           0 :   DebugAssert(ok(), AipsError);
     209             :   // squash compiler warning, maybe just get rid of DebugAssert statements
     210           0 :   if (newOptParms.empty()) {};
     211           0 : }
     212             : 
     213       63158 : Bool PointShape::fromRecord(String& errorMessage,
     214             :                             const RecordInterface& record) {
     215       63158 :   DebugAssert(ok(), AipsError);
     216       63158 :   return ComponentShape::fromRecord(errorMessage, record);
     217             : }
     218             : 
     219        5570 : Bool PointShape::toRecord(String& errorMessage,
     220             :                           RecordInterface& record) const {
     221        5570 :   DebugAssert(ok(), AipsError);
     222        5570 :   return ComponentShape::toRecord(errorMessage, record);
     223             : }
     224             : 
     225           0 : Bool PointShape::convertUnit(String&, const RecordInterface&) {
     226           0 :   DebugAssert(ok(), AipsError);
     227           0 :   return true;
     228             : }
     229             : 
     230     2641506 : Bool PointShape::ok() const {
     231     2641506 :   return ComponentShape::ok();
     232             : }
     233             : 
     234           5 : const ComponentShape* PointShape::getPtr() const {
     235           5 :     return this;
     236             : }
     237             : 
     238             : 
     239        2492 : Double PointShape::dirIsInPixel (Double longSize, Double latSize, Double nearSize,
     240             :                                  const MDirection::MVType& dirValue,
     241             :                                  const MDirection::MVType* compDirValue) const
     242             : {                                 
     243        2492 :   Double retVal = 0.0;
     244             : //
     245        2492 :   const Double separation = abs(compDirValue->separation(dirValue));
     246        2492 :   if (separation <= nearSize) {
     247        2492 :      const Double pa = compDirValue->positionAngle(dirValue);
     248             : //
     249        4984 :      if (abs(separation*sin(pa)) <= longSize/2.0 &&
     250        2492 :          abs(separation*cos(pa)) <= latSize/2.0) {
     251        2492 :        retVal = 1.0;
     252             :      }
     253             :   }
     254        2492 :   return retVal;
     255             : }
     256             : 
     257           0 : String PointShape::sizeToString() const {
     258           0 :         return "Point";
     259             : }
     260             : 
     261             : 
     262             : 
     263             : // Local Variables: 
     264             : // compile-command: "gmake PointShape"
     265             : // End: 
     266             : 
     267             : } //# NAMESPACE CASA - END
     268             : 

Generated by: LCOV version 1.16