SourceXtractorPlusPlus 1.0.3
SourceXtractor++, the next generation SExtractor
Loading...
Searching...
No Matches
CircularAperture.cpp
Go to the documentation of this file.
1
17/*
18 * CircularAperture.cpp
19 *
20 * Created on: Oct 08, 2018
21 * Author: Alejandro Alvarez
22 */
23#include <iostream>
25
26namespace SourceXtractor {
27
28// enhancing from 5 to 10 smoothens the photometry
29const int SUPERSAMPLE_NB = 10;
30
31SeFloat CircularAperture::getArea(SeFloat center_x, SeFloat center_y, SeFloat pixel_x, SeFloat pixel_y) const {
32 auto dx = pixel_x - center_x;
33 auto dy = pixel_y - center_y;
34 SeFloat min_supersampled_radius_squared = m_radius > .75 ? (m_radius - .75) * (m_radius - .75) : 0;
35 SeFloat max_supersampled_radius_squared = (m_radius + .75) * (m_radius + .75);
36
37 auto distance_squared = dx * dx + dy * dy;
38 SeFloat area = 0.0;
39 if (distance_squared < min_supersampled_radius_squared) {
40 area = 1.0;
41 }
42 else if (distance_squared <= max_supersampled_radius_squared) {
43 for (int sub_y = 0; sub_y < SUPERSAMPLE_NB; sub_y++) {
44 for (int sub_x = 0; sub_x < SUPERSAMPLE_NB; sub_x++) {
45 auto dx2 = dx + SeFloat(sub_x - SUPERSAMPLE_NB / 2) / SUPERSAMPLE_NB;
46 auto dy2 = dy + SeFloat(sub_y - SUPERSAMPLE_NB / 2) / SUPERSAMPLE_NB;
47 auto supersampled_distance_squared = dx2 * dx2 + dy2 * dy2;
48 if (supersampled_distance_squared <= m_radius * m_radius) {
49 area += 1.0 / (SUPERSAMPLE_NB * SUPERSAMPLE_NB);
50 }
51 }
52 }
53 }
54 return area;
55}
56
57SeFloat CircularAperture::drawArea(SeFloat center_x, SeFloat center_y, SeFloat pixel_x, SeFloat pixel_y) const {
58 SeFloat thickness = 0.5;
59
60 // define an inner and an outer radius
61 SeFloat min_radius_squared = m_radius > thickness ? (m_radius - thickness) * (m_radius - thickness) : 0;
62 SeFloat max_radius_squared = (m_radius + thickness) * (m_radius + thickness);
63
64 // compare the actual radius against the inner and outer radius
65 auto distance_squared = getRadiusSquared(center_x, center_y, pixel_x, pixel_y);
66 if (min_radius_squared < distance_squared && distance_squared <= max_radius_squared) {
67 return 1.0;
68 }
69 return 0.0;
70}
71
72SeFloat CircularAperture::getRadiusSquared(SeFloat center_x, SeFloat center_y, SeFloat pixel_x, SeFloat pixel_y) const {
73 auto dist_x = SeFloat(pixel_x) - center_x;
74 auto dist_y = SeFloat(pixel_y) - center_y;
75
76 return dist_x * dist_x + dist_y * dist_y;
77}
78
80 return PixelCoordinate(centroid_x - m_radius, centroid_y - m_radius);
81}
82
84 return PixelCoordinate(std::ceil(centroid_x + m_radius), std::ceil(centroid_y + m_radius));
85}
86
87} // end SourceXtractor
T ceil(T... args)
PixelCoordinate getMinPixel(SeFloat centroid_x, SeFloat centroid_y) const override
SeFloat drawArea(SeFloat center_x, SeFloat center_y, SeFloat pixel_x, SeFloat pixel_y) const override
SeFloat getRadiusSquared(SeFloat center_x, SeFloat center_y, SeFloat pixel_x, SeFloat pixel_y) const override
PixelCoordinate getMaxPixel(SeFloat centroid_x, SeFloat centroid_y) const override
SeFloat getArea(SeFloat center_x, SeFloat center_y, SeFloat pixel_x, SeFloat pixel_y) const override
SeFloat32 SeFloat
Definition Types.h:32
A pixel coordinate made of two integers m_x and m_y.