SourceXtractorPlusPlus  0.16
Please provide a description of the project.
MeasurementFrameRectangleTask.cpp
Go to the documentation of this file.
1 
17 /*
18  * MeasurementFrameRectangleTask.cpp
19  *
20  * Created on: Sep 24, 2018
21  * Author: Alejandro Alvarez Ayllon
22  */
23 
28 
31 
32 namespace SourceXtractor {
33 
35  auto& detection_group_stamp = source.getProperty<PixelBoundaries>();
36  auto measurement_frame_coordinates = source.getProperty<MeasurementFrameCoordinates>(m_instance).getCoordinateSystem();
37  auto detection_frame_coordinates = source.getProperty<DetectionFrameCoordinates>().getCoordinateSystem();
38 
39  const auto& measurement_frame_info = source.getProperty<MeasurementFrameInfo>(m_instance);
40 
41  // Get the coordinates of the detection frame group stamp
42  auto stamp_top_left = detection_group_stamp.getMin();
43  auto width = detection_group_stamp.getWidth();
44  auto height = detection_group_stamp.getHeight();
45 
46  // Transform the 4 corner coordinates from detection image
47  ImageCoordinate coord1, coord2, coord3, coord4;
48  bool bad_coordinates = false;
49  try {
50  coord1 = measurement_frame_coordinates->worldToImage(
51  detection_frame_coordinates->imageToWorld(ImageCoordinate(stamp_top_left.m_x, stamp_top_left.m_y)));
52  coord2 = measurement_frame_coordinates->worldToImage(
53  detection_frame_coordinates->imageToWorld(ImageCoordinate(stamp_top_left.m_x + width, stamp_top_left.m_y)));
54  coord3 = measurement_frame_coordinates->worldToImage(
55  detection_frame_coordinates->imageToWorld(ImageCoordinate(stamp_top_left.m_x + width, stamp_top_left.m_y + height)));
56  coord4 = measurement_frame_coordinates->worldToImage(
57  detection_frame_coordinates->imageToWorld(ImageCoordinate(stamp_top_left.m_x, stamp_top_left.m_y + height)));
58  }
59  catch (const InvalidCoordinatesException&) {
60  bad_coordinates = true;
61  }
62 
63  // Determine the min/max coordinates
64  auto min_x = std::min(coord1.m_x, std::min(coord2.m_x, std::min(coord3.m_x, coord4.m_x)));
65  auto min_y = std::min(coord1.m_y, std::min(coord2.m_y, std::min(coord3.m_y, coord4.m_y)));
66  auto max_x = std::max(coord1.m_x, std::max(coord2.m_x, std::max(coord3.m_x, coord4.m_x)));
67  auto max_y = std::max(coord1.m_y, std::max(coord2.m_y, std::max(coord3.m_y, coord4.m_y)));
68 
69  PixelCoordinate min_coord, max_coord;
70  min_coord.m_x = int(min_x);
71  min_coord.m_y = int(min_y);
72  max_coord.m_x = int(max_x) + 1;
73  max_coord.m_y = int(max_y) + 1;
74 
75  // The full boundaries may lie outside of the frame
76  if (bad_coordinates || max_coord.m_x < 0 || max_coord.m_y < 0 ||
77  min_coord.m_x >= measurement_frame_info.getWidth() || min_coord.m_y >= measurement_frame_info.getHeight()) {
79  }
80  // Clip the coordinates to fit the available image
81  else {
82  min_coord.m_x = std::max(0, min_coord.m_x);
83  min_coord.m_y = std::max(0, min_coord.m_y);
84  max_coord.m_x = std::min(measurement_frame_info.getWidth() - 1, max_coord.m_x);
85  max_coord.m_y = std::min(measurement_frame_info.getHeight() - 1, max_coord.m_y);
86 
87  source.setIndexedProperty<MeasurementFrameRectangle>(m_instance, min_coord, max_coord);
88  }
89 }
90 
91 } // SEImplementation namespace
92 
virtual void computeProperties(SourceInterface &source) const override
Computes one or more properties for the Source.
The bounding box of all the pixels in the source. Both min and max coordinate are inclusive.
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.