SourceXtractorPlusPlus  0.11
Please provide a description of the project.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
TransformedAperture.cpp
Go to the documentation of this file.
1 
17 /*
18  * TransformedAperture.cpp
19  *
20  * Created on: Oct 08, 2018
21  * Author: Alejandro Alvarez
22  */
23 
25 #include <algorithm>
26 
27 namespace SourceXtractor {
28 
31  : m_decorated{decorated} {
32 
33  m_transform[0] = std::get<0>(jacobian);
34  m_transform[1] = std::get<1>(jacobian);
35  m_transform[2] = std::get<2>(jacobian);
36  m_transform[3] = std::get<3>(jacobian);
37 
38  double inv_det = 1. / (m_transform[0] * m_transform[3] - m_transform[2] * m_transform[1]);
39 
40  m_inv_transform[0] = m_transform[3] * inv_det;
41  m_inv_transform[1] = -m_transform[1] * inv_det;
42  m_inv_transform[2] = -m_transform[2] * inv_det;
43  m_inv_transform[3] = m_transform[0] * inv_det;
44 }
45 
47  return {
48  x * t[0] + y * t[2],
49  x * t[1] + y * t[3]
50  };
51 }
52 
54  auto min = m_decorated->getMinPixel(0, 0);
55  auto max = m_decorated->getMaxPixel(0, 0);
56 
57  auto a = transform(min.m_x, min.m_y, m_transform);
58  auto b = transform(max.m_x, min.m_y, m_transform);
59  auto c = transform(min.m_x, max.m_y, m_transform);
60  auto d = transform(max.m_x, max.m_y, m_transform);
61 
62  auto min_x = std::min({a.first, b.first, c.first, d.first});
63  auto min_y = std::min({a.second, b.second, c.second, d.second});
64 
65  return PixelCoordinate(x + min_x, y + min_y);
66 }
67 
69  auto min = m_decorated->getMinPixel(0, 0);
70  auto max = m_decorated->getMaxPixel(0, 0);
71 
72  auto a = transform(min.m_x, min.m_y, m_transform);
73  auto b = transform(max.m_x, min.m_y, m_transform);
74  auto c = transform(min.m_x, max.m_y, m_transform);
75  auto d = transform(max.m_x, max.m_y, m_transform);
76 
77  auto min_x = std::max({a.first, b.first, c.first, d.first});
78  auto min_y = std::max({a.second, b.second, c.second, d.second});
79 
80  return PixelCoordinate(x + min_x, y + min_y);
81 }
82 
83 SeFloat TransformedAperture::getArea(SeFloat center_x, SeFloat center_y, SeFloat pixel_x, SeFloat pixel_y) const {
84  auto diff_x = pixel_x - center_x;
85  auto diff_y = pixel_y - center_y;
86 
87  SeFloat new_diff_x = diff_x * m_inv_transform[0] + diff_y * m_inv_transform[2];
88  SeFloat new_diff_y = diff_x * m_inv_transform[1] + diff_y * m_inv_transform[3];
89 
90  return m_decorated->getArea(0, 0, new_diff_x, new_diff_y);
91 }
92 
93 SeFloat TransformedAperture::getRadiusSquared(SeFloat center_x, SeFloat center_y, SeFloat pixel_x, SeFloat pixel_y) const {
94  auto diff_x = pixel_x - center_x;
95  auto diff_y = pixel_y - center_y;
96 
97  SeFloat new_diff_x = diff_x * m_inv_transform[0] + diff_y * m_inv_transform[2];
98  SeFloat new_diff_y = diff_x * m_inv_transform[1] + diff_y * m_inv_transform[3];
99 
100  return m_decorated->getRadiusSquared(0, 0, new_diff_x, new_diff_y);
101 }
102 
103 } // end SourceXtractor
TransformedAperture(std::shared_ptr< Aperture > decorated, const std::tuple< double, double, double, double > &jacobian)
std::shared_ptr< DependentParameter< std::shared_ptr< EngineParameter > > > x
SeFloat getArea(SeFloat center_x, SeFloat center_y, SeFloat pixel_x, SeFloat pixel_y) const override
SeFloat32 SeFloat
Definition: Types.h:32
std::shared_ptr< Aperture > m_decorated
std::array< double, 4 > m_inv_transform
std::shared_ptr< DependentParameter< std::shared_ptr< EngineParameter > > > y
T min(T...args)
PixelCoordinate getMaxPixel(SeFloat centroid_x, SeFloat centroid_y) const override
SeFloat getRadiusSquared(SeFloat center_x, SeFloat center_y, SeFloat pixel_x, SeFloat pixel_y) const override
T max(T...args)
A pixel coordinate made of two integers m_x and m_y.
PixelCoordinate getMinPixel(SeFloat centroid_x, SeFloat centroid_y) const override
std::pair< double, double > transform(int x, int y, const std::array< double, 4 > &t)