Commit f3cdb72c3b56ee5dc5019cdb9eef7fa91d6d6146
1 parent
68928c4a
initial version
Showing
2 changed files
with
122 additions
and
0 deletions
inst/cta/src/GCTASupport.cpp
0 → 100644
| 1 | +/*************************************************************************** | |
| 2 | + * GCTASupport.cpp - CTA support functions * | |
| 3 | + * ----------------------------------------------------------------------- * | |
| 4 | + * copyright (C) 2011 by Jurgen Knodlseder * | |
| 5 | + * ----------------------------------------------------------------------- * | |
| 6 | + * * | |
| 7 | + * This program is free software; you can redistribute it and/or modify * | |
| 8 | + * it under the terms of the GNU General Public License as published by * | |
| 9 | + * the Free Software Foundation; either version 2 of the License, or * | |
| 10 | + * (at your option) any later version. * | |
| 11 | + * * | |
| 12 | + ***************************************************************************/ | |
| 13 | +/** | |
| 14 | + * @file GCTASupport.cpp | |
| 15 | + * @brief Implementation of support function used by CTA classes | |
| 16 | + * @author J. Knodlseder | |
| 17 | + */ | |
| 18 | + | |
| 19 | +/* __ Includes ___________________________________________________________ */ | |
| 20 | +#ifdef HAVE_CONFIG_H | |
| 21 | +#include <config.h> | |
| 22 | +#endif | |
| 23 | +#include "GCTASupport.hpp" | |
| 24 | +#include "GTools.hpp" | |
| 25 | + | |
| 26 | +/* __ Coding definitions _________________________________________________ */ | |
| 27 | + | |
| 28 | + | |
| 29 | +/***********************************************************************//** | |
| 30 | + * @brief Returns length of circular arc within circular ROI | |
| 31 | + * | |
| 32 | + * @param[in] rad Circle radius in radians (<pi). | |
| 33 | + * @param[in] dist Circle centre distance to ROI centre (<pi). | |
| 34 | + * @param[in] cospsf Cosine of circle centre distance to ROI centre. | |
| 35 | + * @param[in] sindist Sinus of circle centre distance to ROI centre. | |
| 36 | + * @param[in] roi Radius of ROI in radians. | |
| 37 | + * @param[in] cosroi Cosine of ROI radius. | |
| 38 | + * | |
| 39 | + * This method returns the arclength in radians of a circle of radius 'rad' | |
| 40 | + * with a centre that is offset by 'dist' from the ROI centre, where the ROI | |
| 41 | + * radius is given by 'roi'. To speed-up computations, the cosines and sinus | |
| 42 | + * of 'roi' and 'psf' should be calculated by the client and be passed to | |
| 43 | + * the method. | |
| 44 | + ***************************************************************************/ | |
| 45 | +double cta_roi_arclength(const double& rad, const double& dist, | |
| 46 | + const double& cosdist, const double& sindist, | |
| 47 | + const double& roi, const double& cosroi) | |
| 48 | +{ | |
| 49 | + // Declare arclength | |
| 50 | + double arclength; | |
| 51 | + | |
| 52 | + // Handle special case that circle centre matches ROI centre | |
| 53 | + if (dist == 0.0) { | |
| 54 | + if (rad > roi) arclength = 0.0; // Circle outside ROI | |
| 55 | + else arclength = twopi; // Circle inside ROI | |
| 56 | + } | |
| 57 | + | |
| 58 | + // ... otherwise circle and ROI centres are not identical | |
| 59 | + else { | |
| 60 | + | |
| 61 | + // Handle special case that we evaluate exactly at the circle | |
| 62 | + // centre. In this case we have in fact a point, and if this point | |
| 63 | + // falls within the ROI it has a formal arclength of 2pi. | |
| 64 | + // | |
| 65 | + if (rad == 0.0) { | |
| 66 | + if (dist > roi) arclength = 0.0; // Circle centre outside ROI | |
| 67 | + else arclength = twopi; // Circle centre inside ROI | |
| 68 | + } | |
| 69 | + | |
| 70 | + // ... otherwise we have to handle the general case | |
| 71 | + else { | |
| 72 | + double dist = roi - dist; | |
| 73 | + if (-rad >= dist) | |
| 74 | + arclength = 0.0; | |
| 75 | + else if (rad <= dist) | |
| 76 | + arclength = twopi; | |
| 77 | + else { | |
| 78 | + double cosrad = cos(rad); | |
| 79 | + double sinrad = sin(rad); | |
| 80 | + double cosang = (cosroi - cosdist*cosrad) / (sindist*sinrad); | |
| 81 | + arclength = acos(cosang); | |
| 82 | + } | |
| 83 | + } | |
| 84 | + | |
| 85 | + } // endelse: Circle and ROI centres were not identical | |
| 86 | + | |
| 87 | + // Return arclength | |
| 88 | + return arclength; | |
| 89 | +} | ... | ... |
inst/cta/src/GCTASupport.hpp
0 → 100644
| 1 | +/*************************************************************************** | |
| 2 | + * GCTASupport.hpp - CTA support functions * | |
| 3 | + * ----------------------------------------------------------------------- * | |
| 4 | + * copyright (C) 2011 by Jurgen Knodlseder * | |
| 5 | + * ----------------------------------------------------------------------- * | |
| 6 | + * * | |
| 7 | + * This program is free software; you can redistribute it and/or modify * | |
| 8 | + * it under the terms of the GNU General Public License as published by * | |
| 9 | + * the Free Software Foundation; either version 2 of the License, or * | |
| 10 | + * (at your option) any later version. * | |
| 11 | + * * | |
| 12 | + ***************************************************************************/ | |
| 13 | +/** | |
| 14 | + * @file GCTASupport.hpp | |
| 15 | + * @brief Definition of support function used by CTA classes | |
| 16 | + * @author J. Knodlseder | |
| 17 | + */ | |
| 18 | + | |
| 19 | +#ifndef GCTASUPPORT_HPP | |
| 20 | +#define GCTASUPPORT_HPP | |
| 21 | + | |
| 22 | +/* __ Includes ___________________________________________________________ */ | |
| 23 | + | |
| 24 | +/* __ Namespaces _________________________________________________________ */ | |
| 25 | + | |
| 26 | +/* __ Constants __________________________________________________________ */ | |
| 27 | + | |
| 28 | +/* __ Prototypes _________________________________________________________ */ | |
| 29 | +double cta_roi_arclength(const double& rad, const double& dist, | |
| 30 | + const double& cosdist, const double& sindist, | |
| 31 | + const double& roi, const double& cosroi); | |
| 32 | + | |
| 33 | +#endif /* GCTASUPPORT_HPP */ | ... | ... |