SourceXtractorPlusPlus  0.10
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 
24 #include <iostream>
25 #include <mutex>
31 
32 
33 namespace SourceXtractor {
34 
36  auto frame = source.getProperty<MeasurementFrame>(m_instance).getFrame();
37  auto frame_coordinates = frame->getCoordinateSystem();
38  auto& detection_group_stamp = source.getProperty<PixelBoundaries>();
39  auto detection_frame_coordinates = source.getProperty<DetectionFrame>().getFrame()->getCoordinateSystem();
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  auto coord1 = frame_coordinates->worldToImage(detection_frame_coordinates->imageToWorld(ImageCoordinate(
48  stamp_top_left.m_x, stamp_top_left.m_y)));
49  auto coord2 = frame_coordinates->worldToImage(detection_frame_coordinates->imageToWorld(ImageCoordinate(
50  stamp_top_left.m_x + width, stamp_top_left.m_y)));
51  auto coord3 = frame_coordinates->worldToImage(detection_frame_coordinates->imageToWorld(ImageCoordinate(
52  stamp_top_left.m_x + width, stamp_top_left.m_y + height)));
53  auto coord4 = frame_coordinates->worldToImage(detection_frame_coordinates->imageToWorld(ImageCoordinate(
54  stamp_top_left.m_x, stamp_top_left.m_y + height)));
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  auto frame_image = frame->getSubtractedImage();
69 
70  // The full boundaries may lie outside of the frame
71  if (max_coord.m_x < 0 || max_coord.m_y < 0 || min_coord.m_x >= frame_image->getWidth() || min_coord.m_y >= frame_image->getHeight()) {
73  }
74  // Clip the coordinates to fit the available image
75  else {
76  min_coord.m_x = std::max(0, min_coord.m_x);
77  min_coord.m_y = std::max(0, min_coord.m_y);
78  max_coord.m_x = std::min(frame_image->getWidth() - 1, max_coord.m_x);
79  max_coord.m_y = std::min(frame_image->getHeight() - 1, max_coord.m_y);
80 
81  source.setIndexedProperty<MeasurementFrameRectangle>(m_instance, min_coord, max_coord);
82  }
83 }
84 
85 } // SEImplementation namespace
86 
SourceXtractor::PixelBoundaries
The bounding box of all the pixels in the source. Both min and max coordinate are inclusive.
Definition: PixelBoundaries.h:37
MeasurementFrame.h
SourceXtractor::PixelCoordinate
A pixel coordinate made of two integers m_x and m_y.
Definition: PixelCoordinate.h:37
PixelBoundaries.h
SourceXtractor::MeasurementFrameRectangle
Definition: MeasurementFrameRectangle.h:33
DetectionFrame.h
SourceXtractor
Definition: Aperture.h:30
SourceXtractor::PixelCoordinate::m_x
int m_x
Definition: PixelCoordinate.h:38
SourceXtractor::PixelCoordinate::m_y
int m_y
Definition: PixelCoordinate.h:38
SourceXtractor::SourceInterface::setIndexedProperty
void setIndexedProperty(std::size_t index, Args... args)
Convenience template method to call setProperty() with a more user-friendly syntax.
Definition: SourceInterface.h:64
SourceXtractor::DetectionFrame
Definition: DetectionFrame.h:33
SourceXtractor::MeasurementFrameRectangleTask::computeProperties
virtual void computeProperties(SourceInterface &source) const override
Computes one or more properties for the Source.
Definition: MeasurementFrameRectangleTask.cpp:35
SourceXtractor::MeasurementFrame
Definition: MeasurementFrame.h:36
SourceXtractor::ImageCoordinate
Definition: CoordinateSystem.h:42
SourceXtractor::MeasurementFrameRectangleTask::m_instance
unsigned m_instance
Definition: MeasurementFrameRectangleTask.h:42
std::min
T min(T... args)
MeasurementFrameRectangleTask.h
SourceXtractor::SourceInterface::getProperty
const PropertyType & getProperty(unsigned int index=0) const
Convenience template method to call getProperty() with a more user-friendly syntax.
Definition: SourceInterface.h:57
SourceXtractor::SourceInterface
The SourceInterface is an abstract "source" that has properties attached to it.
Definition: SourceInterface.h:46
std::max
T max(T... args)
MeasurementFrameRectangle.h