LCOV - code coverage report
Current view: top level - imageanalysis/Annotations - AnnCircle.cc (source / functions) Hit Total Coverage
Test: casacpp_coverage.info Lines: 26 53 49.1 %
Date: 2024-11-06 17:42:47 Functions: 3 7 42.9 %

          Line data    Source code
       1             : //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
       2             : //# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
       3             : //# License for more details.
       4             : //#
       5             : //# You should have received a copy of the GNU Library General Public License
       6             : //# along with this library; if not, write to the Free Software Foundation,
       7             : //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
       8             : //#
       9             : //# Correspondence concerning AIPS++ should be addressed as follows:
      10             : //#        Internet email: casa-feedback@nrao.edu.
      11             : //#        Postal address: AIPS++ Project Office
      12             : //#                        National Radio Astronomy Observatory
      13             : //#                        520 Edgemont Road
      14             : //#                        Charlottesville, VA 22903-2475 USA
      15             : //#
      16             : 
      17             : 
      18             : #include <imageanalysis/Annotations/AnnCircle.h>
      19             : 
      20             : #include <casacore/coordinates/Coordinates/DirectionCoordinate.h>
      21             : #include <casacore/images/Regions/WCEllipsoid.h>
      22             : 
      23             : 
      24             : using namespace casacore;
      25             : namespace casa {
      26             : 
      27          26 : AnnCircle::AnnCircle(
      28             :         const Quantity& xcenter,
      29             :         const Quantity& ycenter,
      30             :         const Quantity& radius,
      31             :         const String& dirRefFrameString,
      32             :         const CoordinateSystem& csys,
      33             :         const IPosition& imShape,
      34             :         const Quantity& beginFreq,
      35             :         const Quantity& endFreq,
      36             :         const String& freqRefFrameString,
      37             :         const String& dopplerString,
      38             :         const Quantity& restfreq,
      39             :         const Vector<Stokes::StokesTypes> stokes,
      40             :         const Bool annotationOnly,
      41             :         const Bool requireImageRegion
      42          26 : ) : AnnRegion(
      43             :                 CIRCLE, dirRefFrameString, csys, imShape, beginFreq,
      44             :                 endFreq, freqRefFrameString, dopplerString,
      45             :                 restfreq, stokes, annotationOnly, requireImageRegion
      46          26 : ), _inputCenter(AnnotationBase::Direction(1)), _inputRadius(radius) {
      47          26 :         _init(xcenter, ycenter);
      48          26 : }
      49             : 
      50           1 : AnnCircle::AnnCircle(
      51             :         const Quantity& xcenter,
      52             :         const Quantity& ycenter,
      53             :         const Quantity& radius,
      54             :         const CoordinateSystem& csys,
      55             :         const IPosition& imShape,
      56             :         const Vector<Stokes::StokesTypes>& stokes,
      57             :         const Bool requireImageRegion
      58           1 : ) : AnnRegion(CIRCLE, csys, imShape, stokes, requireImageRegion),
      59           1 :         _inputCenter(AnnotationBase::Direction(1)), _inputRadius(radius) {
      60           1 :         _init(xcenter, ycenter);
      61           1 : }
      62             : 
      63           0 : AnnCircle& AnnCircle::operator= (
      64             :         const AnnCircle& other
      65             : ) {
      66           0 :         if (this == &other) {
      67           0 :                 return *this;
      68             :         }
      69           0 :         AnnRegion::operator=(other);
      70           0 :         _inputCenter.resize(other._inputCenter.nelements());
      71           0 :         _inputCenter = other._inputCenter;
      72           0 :         _inputRadius = other._inputRadius;
      73           0 :         _convertedRadius = other._convertedRadius;
      74           0 :         return *this;
      75             : }
      76             : 
      77             : 
      78           0 : MDirection AnnCircle::getCenter() const {
      79           0 :         return getConvertedDirections()[0];
      80             : }
      81             : 
      82           0 : Quantity AnnCircle::getRadius() const {
      83           0 :         return _convertedRadius;
      84             : }
      85             : 
      86           0 : ostream& AnnCircle::print(ostream &os) const {
      87           0 :         _printPrefix(os);
      88           0 :         os << "circle [["
      89           0 :                 << _printDirection(_inputCenter[0].first, _inputCenter[0].second)
      90           0 :                 << "], " << _toArcsec(_inputRadius) << "]";
      91           0 :         _printPairs(os);
      92           0 :         return os;
      93             : }
      94             : 
      95          27 : void AnnCircle::_init(const Quantity& xcenter, const Quantity& ycenter) {
      96          27 :         ThrowIf(
      97             :                 _inputRadius.getUnit() == "pix"
      98             :                         && ! getCsys().directionCoordinate().hasSquarePixels(),
      99             :                 "AnnCircle should not be used when radius is "
     100             :                         "in pixels and pixels are not square. Use AnnEllipse instead."
     101             :         );
     102          27 :         _convertedRadius = _lengthToAngle(_inputRadius, _getDirectionAxes()[0]);
     103          27 :         _inputCenter[0].first = xcenter;
     104          27 :         _inputCenter[0].second = ycenter;
     105             : 
     106          27 :         _checkAndConvertDirections(String(__FUNCTION__), _inputCenter);
     107             : 
     108          54 :         Vector<Double> coords = getConvertedDirections()[0].getAngle("rad").getValue();
     109             : 
     110          27 :         Vector<Quantity> center(2);
     111             : 
     112          27 :         center[0] = Quantity(coords[0], "rad");
     113          27 :         center[1] = Quantity(coords[1], "rad");
     114             : 
     115             :         try {
     116             :                 WCEllipsoid circle(
     117          27 :                         center, _convertedRadius, _getDirectionAxes(),
     118             :                         getCsys(), RegionType::Abs
     119          27 :                 );
     120          27 :                 _setDirectionRegion(circle);
     121          27 :                 _extend();
     122          27 :         } catch (const ToLCRegionConversionError& err) {
     123           0 :                 if (_requireImageRegion) {
     124           0 :                         throw(err);
     125             :                 } else {
     126           0 :                         ImageRegion defaultRegion;
     127           0 :                         _setDirectionRegion(defaultRegion);
     128           0 :                         _imageRegion = _directionRegion;
     129           0 :                 }
     130           0 :         }
     131          27 : }
     132             : 
     133             : }

Generated by: LCOV version 1.16