SourceXtractorPlusPlus 1.0.3
SourceXtractor++, the next generation SExtractor
Loading...
Searching...
No Matches
MeasurementFrameRectangleTaskNoDetect.cpp
Go to the documentation of this file.
1
17
18#include <iostream>
19
26
29
30namespace SourceXtractor {
31
33 auto measurement_frame_coordinates = source.getProperty<MeasurementFrameCoordinates>(m_instance).getCoordinateSystem();
34 const auto& measurement_frame_info = source.getProperty<MeasurementFrameInfo>(m_instance);
35 const auto& world_centroid = source.getProperty<WorldCentroid>();
36 const auto& assoc_mode = source.getProperty<AssocMode>();
37
38 auto coord = world_centroid.getCentroid();
39
40 bool bad_coordinates = false;
41 ImageCoordinate coord1, coord2, coord3, coord4;
42 try {
43 int w = assoc_mode.getRefFramePixelWidth();
44 int h = assoc_mode.getRefFramePixelHeight();
45
46 auto c = measurement_frame_coordinates->worldToImage(coord);
47 coord1 = ImageCoordinate(c.m_x - w, c.m_y - h);
48 coord2 = ImageCoordinate(c.m_x + w, c.m_y - h);
49 coord3 = ImageCoordinate(c.m_x - w, c.m_y + h);
50 coord4 = ImageCoordinate(c.m_x + w, c.m_y + h);
51 }
52 catch (const InvalidCoordinatesException&) {
53 bad_coordinates = true;
54 }
55
56 // Determine the min/max coordinates
57 auto min_x = std::min(coord1.m_x, std::min(coord2.m_x, std::min(coord3.m_x, coord4.m_x)));
58 auto min_y = std::min(coord1.m_y, std::min(coord2.m_y, std::min(coord3.m_y, coord4.m_y)));
59 auto max_x = std::max(coord1.m_x, std::max(coord2.m_x, std::max(coord3.m_x, coord4.m_x)));
60 auto max_y = std::max(coord1.m_y, std::max(coord2.m_y, std::max(coord3.m_y, coord4.m_y)));
61
62 PixelCoordinate min_coord, max_coord;
63 min_coord.m_x = int(min_x);
64 min_coord.m_y = int(min_y);
65 max_coord.m_x = int(max_x) + 1;
66 max_coord.m_y = int(max_y) + 1;
67
68 // The full boundaries may lie outside of the frame
69 if (bad_coordinates || max_coord.m_x < 0 || max_coord.m_y < 0 ||
70 min_coord.m_x >= measurement_frame_info.getWidth() || min_coord.m_y >= measurement_frame_info.getHeight()) {
72 }
73 // Clip the coordinates to fit the available image
74 else {
75 min_coord.m_x = std::max(0, min_coord.m_x);
76 min_coord.m_y = std::max(0, min_coord.m_y);
77 max_coord.m_x = std::min(measurement_frame_info.getWidth() - 1, max_coord.m_x);
78 max_coord.m_y = std::min(measurement_frame_info.getHeight() - 1, max_coord.m_y);
79
80 source.setIndexedProperty<MeasurementFrameRectangle>(m_instance, min_coord, max_coord);
81 }
82}
83
84} // SEImplementation namespace
85
void computeProperties(SourceInterface &source) const override
Computes one or more properties for the Source.
The SourceInterface is an abstract "source" that has properties attached to it.
void setIndexedProperty(std::size_t index, Args... args)
Convenience template method to call setProperty() with a more user-friendly syntax.
const PropertyType & getProperty(unsigned int index=0) const
Convenience template method to call getProperty() with a more user-friendly syntax.
T max(T... args)
T min(T... args)
A pixel coordinate made of two integers m_x and m_y.