SourceXtractorPlusPlus
0.21
SourceXtractor++, the next generation SExtractor
Loading...
Searching...
No Matches
SEImplementation
src
lib
Plugin
MeasurementFrameGroupRectangle
MeasurementFrameGroupRectangleTask.cpp
Go to the documentation of this file.
1
17
/*
18
* MeasurementFrameGroupRectangleTask.cpp
19
*
20
* Created on: Sep 5, 2018
21
* Author: Alejandro Alvarez Ayllon
22
*/
23
24
#include "
SEImplementation/Plugin/MeasurementFrameCoordinates/MeasurementFrameCoordinates.h
"
25
#include "
SEImplementation/Plugin/MeasurementFrameInfo/MeasurementFrameInfo.h
"
26
#include <
SEImplementation/Plugin/DetectionFrameGroupStamp/DetectionFrameGroupStamp.h
>
27
#include "
SEImplementation/Plugin/DetectionFrameCoordinates/DetectionFrameCoordinates.h
"
28
29
#include <
SEImplementation/Plugin/MeasurementFrameGroupRectangle/MeasurementFrameGroupRectangle.h
>
30
#include <
SEImplementation/Plugin/MeasurementFrameGroupRectangle/MeasurementFrameGroupRectangleTask.h
>
31
32
namespace
SourceXtractor
{
33
34
void
MeasurementFrameGroupRectangleTask::computeProperties
(
SourceGroupInterface
&
group
)
const
{
35
auto
&
detection_group_stamp
=
group
.getProperty<
DetectionFrameGroupStamp
>();
36
auto
detection_frame_coordinates
=
group
.begin()->getProperty<
DetectionFrameCoordinates
>().getCoordinateSystem();
37
auto
measurement_frame_coordinates
=
group
.begin()->getProperty<
MeasurementFrameCoordinates
>(
m_instance
).getCoordinateSystem();
38
39
const
auto
&
measurement_frame_info
=
group
.begin()->getProperty<
MeasurementFrameInfo
>(
m_instance
);
40
41
// Get the coordinates of the detection frame group stamp
42
auto
stamp_top_left
=
detection_group_stamp
.getTopLeft();
43
auto
width =
detection_group_stamp
.getStamp().getWidth();
44
auto
height =
detection_group_stamp
.getStamp().getHeight();
45
46
// Transform the 4 corner coordinates from detection image
47
ImageCoordinate
coord1
,
coord2
,
coord3
,
coord4
;
48
bool
bad_coordinates
=
false
;
49
50
try
{
51
coord1
=
measurement_frame_coordinates
->worldToImage(
52
detection_frame_coordinates
->imageToWorld(
ImageCoordinate
(
stamp_top_left
.m_x,
stamp_top_left
.m_y)));
53
coord2
=
measurement_frame_coordinates
->worldToImage(
54
detection_frame_coordinates
->imageToWorld(
ImageCoordinate
(
stamp_top_left
.m_x + width,
stamp_top_left
.m_y)));
55
coord3
=
measurement_frame_coordinates
->worldToImage(
56
detection_frame_coordinates
->imageToWorld(
ImageCoordinate
(
stamp_top_left
.m_x + width,
stamp_top_left
.m_y + height)));
57
coord4
=
measurement_frame_coordinates
->worldToImage(
58
detection_frame_coordinates
->imageToWorld(
ImageCoordinate
(
stamp_top_left
.m_x,
stamp_top_left
.m_y + height)));
59
}
60
catch
(
const
InvalidCoordinatesException
&) {
61
bad_coordinates
=
true
;
62
}
63
64
// Determine the min/max coordinates
65
auto
min_x
=
std::min
(
coord1
.m_x,
std::min
(
coord2
.m_x,
std::min
(
coord3
.m_x,
coord4
.m_x)));
66
auto
min_y
=
std::min
(
coord1
.m_y,
std::min
(
coord2
.m_y,
std::min
(
coord3
.m_y,
coord4
.m_y)));
67
auto
max_x
=
std::max
(
coord1
.m_x,
std::max
(
coord2
.m_x,
std::max
(
coord3
.m_x,
coord4
.m_x)));
68
auto
max_y
=
std::max
(
coord1
.m_y,
std::max
(
coord2
.m_y,
std::max
(
coord3
.m_y,
coord4
.m_y)));
69
70
PixelCoordinate
min_coord
,
max_coord
;
71
min_coord
.m_x =
int
(
min_x
);
72
min_coord
.m_y =
int
(
min_y
);
73
max_coord
.m_x =
int
(
max_x
) + 1;
74
max_coord
.m_y =
int
(
max_y
) + 1;
75
76
// The full boundaries may lie outside of the frame
77
// Or maybe there was a projection issue, so skip the frame for that source
78
if
(
bad_coordinates
||
max_coord
.m_x < 0 ||
max_coord
.m_y < 0 ||
min_coord
.m_x >=
measurement_frame_info
.getWidth() ||
79
min_coord
.m_y >=
measurement_frame_info
.getHeight()) {
80
group
.setIndexedProperty<
MeasurementFrameGroupRectangle
>(
m_instance
,
bad_coordinates
);
81
}
82
// Clip the coordinates to fit the available image
83
else
{
84
min_coord
.m_x =
std::max
(0,
min_coord
.m_x);
85
min_coord
.m_y =
std::max
(0,
min_coord
.m_y);
86
max_coord
.m_x =
std::min
(
measurement_frame_info
.getWidth() - 1,
max_coord
.m_x);
87
max_coord
.m_y =
std::min
(
measurement_frame_info
.getHeight() - 1,
max_coord
.m_y);
88
89
group
.setIndexedProperty<
MeasurementFrameGroupRectangle
>(
m_instance
,
min_coord
,
max_coord
);
90
}
91
}
92
93
}
// SEImplementation namespace
94
DetectionFrameCoordinates.h
DetectionFrameGroupStamp.h
MeasurementFrameCoordinates.h
MeasurementFrameGroupRectangleTask.h
MeasurementFrameGroupRectangle.h
MeasurementFrameInfo.h
SourceXtractor::DetectionFrameCoordinates
Definition
DetectionFrameCoordinates.h:26
SourceXtractor::DetectionFrameGroupStamp
Definition
DetectionFrameGroupStamp.h:33
SourceXtractor::InvalidCoordinatesException
Definition
CoordinateSystem.h:62
SourceXtractor::MeasurementFrameCoordinates
Definition
MeasurementFrameCoordinates.h:26
SourceXtractor::MeasurementFrameGroupRectangleTask::computeProperties
void computeProperties(SourceGroupInterface &group) const override
Computes one or more properties for the SourceGroup and/or the Sources it contains.
Definition
MeasurementFrameGroupRectangleTask.cpp:34
SourceXtractor::MeasurementFrameGroupRectangleTask::m_instance
unsigned m_instance
Definition
MeasurementFrameGroupRectangleTask.h:42
SourceXtractor::MeasurementFrameGroupRectangle
Definition
MeasurementFrameGroupRectangle.h:33
SourceXtractor::MeasurementFrameInfo
Definition
MeasurementFrameInfo.h:28
SourceXtractor::SourceGroupInterface
Defines the interface used to group sources.
Definition
SourceGroupInterface.h:38
std::function
std::max
T max(T... args)
std::min
T min(T... args)
SourceXtractor
Definition
Aperture.h:30
SourceXtractor::ImageCoordinate
Definition
CoordinateSystem.h:43
SourceXtractor::PixelCoordinate
A pixel coordinate made of two integers m_x and m_y.
Definition
PixelCoordinate.h:37
Generated by
1.10.0