Skip to content

Commit 97528f8

Browse files
authored
Merge pull request #621 from astrorama/fix/assoc_pixel_size_as_double
Changed fitting window calculation to use doubles
2 parents a497f42 + 0bbbf71 commit 97528f8

File tree

5 files changed

+65
-22
lines changed

5 files changed

+65
-22
lines changed

SEFramework/SEFramework/CoordinateSystem/CoordinateSystem.h

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,30 @@ struct ImageCoordinate {
4545

4646
ImageCoordinate() : m_x(0), m_y(0) {}
4747
ImageCoordinate(double x, double y) : m_x(x), m_y(y) {}
48+
49+
ImageCoordinate operator*(double scalar) const {
50+
return ImageCoordinate(m_x * scalar, m_y * scalar);
51+
}
52+
53+
ImageCoordinate operator+(const ImageCoordinate& other) const {
54+
return ImageCoordinate(m_x + other.m_x, m_y + other.m_y);
55+
}
56+
57+
ImageCoordinate& operator+=(const ImageCoordinate& other) {
58+
m_x += other.m_x;
59+
m_y += other.m_y;
60+
return *this;
61+
}
62+
63+
ImageCoordinate operator-(const ImageCoordinate& other) const {
64+
return ImageCoordinate(m_x - other.m_x, m_y - other.m_y);
65+
}
66+
67+
ImageCoordinate& operator-=(const ImageCoordinate& other) {
68+
m_x -= other.m_x;
69+
m_y -= other.m_y;
70+
return *this;
71+
}
4872
};
4973

5074
class CoordinateSystem {

SEImplementation/SEImplementation/Plugin/MeasurementFrameRectangle/MeasurementFrameRectangle.h

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,10 @@
2424
#ifndef _SEIMPLEMENTATION_PLUGIN_MEASUREMENTFRAMERECTANGLE_MEASUREMENTFRAMERECTANGLE_H_
2525
#define _SEIMPLEMENTATION_PLUGIN_MEASUREMENTFRAMERECTANGLE_MEASUREMENTFRAMERECTANGLE_H_
2626

27+
#include <tuple>
28+
2729
#include "SEUtils/PixelRectangle.h"
30+
#include "SEFramework/CoordinateSystem/CoordinateSystem.h"
2831

2932
#include "SEFramework/Property/Property.h"
3033
#include "SEFramework/Image/Image.h"
@@ -36,11 +39,15 @@ class MeasurementFrameRectangle: public Property {
3639
virtual ~MeasurementFrameRectangle() = default;
3740

3841
explicit MeasurementFrameRectangle(bool bad_projection):
39-
m_min_coord{-1, -1}, m_max_coord{-1, -1}, m_bad_projection{bad_projection}{}
42+
m_min_coord{-1, -1}, m_max_coord{-1, -1}, m_min_coord_image{-1, -1},
43+
m_max_coord_image{-1, -1}, m_bad_projection{bad_projection} {}
4044

41-
MeasurementFrameRectangle(PixelCoordinate min_coord, PixelCoordinate max_coord):
42-
m_min_coord{min_coord}, m_max_coord{max_coord}, m_bad_projection{false} {
45+
MeasurementFrameRectangle(PixelCoordinate min_coord, PixelCoordinate max_coord,
46+
ImageCoordinate min_coord_image, ImageCoordinate max_coord_image):
47+
m_min_coord(min_coord), m_max_coord(max_coord),
48+
m_min_coord_image(min_coord_image), m_max_coord_image(max_coord_image), m_bad_projection{false} {
4349
assert(min_coord.m_x <= max_coord.m_x && min_coord.m_y <= max_coord.m_y);
50+
assert(min_coord_image.m_x <= max_coord_image.m_x && min_coord_image.m_y <= max_coord_image.m_y);
4451
}
4552

4653
PixelCoordinate getTopLeft() const {
@@ -65,8 +72,8 @@ class MeasurementFrameRectangle: public Property {
6572
return m_max_coord.m_y - m_min_coord.m_y + 1;
6673
}
6774

68-
PixelRectangle getRect() const {
69-
return PixelRectangle(m_min_coord, m_max_coord);
75+
std::tuple<ImageCoordinate, ImageCoordinate> getImageRect() const {
76+
return std::make_tuple(m_min_coord_image, m_max_coord_image);
7077
}
7178

7279
bool badProjection() const {
@@ -75,6 +82,7 @@ class MeasurementFrameRectangle: public Property {
7582

7683
private:
7784
PixelCoordinate m_min_coord, m_max_coord;
85+
ImageCoordinate m_min_coord_image, m_max_coord_image;
7886
bool m_bad_projection;
7987
};
8088

SEImplementation/src/lib/Plugin/FlexibleModelFitting/FlexibleModelFittingIterativeTask.cpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,8 @@ FlexibleModelFittingIterativeTask::~FlexibleModelFittingIterativeTask() {
7474
}
7575

7676
PixelRectangle FlexibleModelFittingIterativeTask::getUnclippedFittingRect(SourceInterface& source, int frame_index) const {
77-
auto fitting_rect = source.getProperty<MeasurementFrameRectangle>(frame_index).getRect();
77+
ImageCoordinate min_coord, max_coord;
78+
std::tie(min_coord, max_coord) = source.getProperty<MeasurementFrameRectangle>(frame_index).getImageRect();
7879

7980
if (m_window_type == WindowType::ROTATED_ELLIPSE) {
8081
auto ellipse = getFittingEllipse(source, frame_index);
@@ -84,14 +85,14 @@ PixelRectangle FlexibleModelFittingIterativeTask::getUnclippedFittingRect(Source
8485
return getEllipseRect(ellipse);
8586
}
8687

87-
if (fitting_rect.getWidth() <= 0 || fitting_rect.getHeight() <= 0) {
88+
if (max_coord.m_x - min_coord.m_x <= 0 || max_coord.m_y - min_coord.m_y <= 0) {
8889
return PixelRectangle();
8990
} else {
90-
auto min = fitting_rect.getTopLeft();
91-
auto max = fitting_rect.getBottomRight();
91+
auto min = min_coord;
92+
auto max = max_coord;
9293

9394
// FIXME temporary, for now just enlarge the area by a fixed amount of pixels
94-
PixelCoordinate border = (max - min) * .8 + PixelCoordinate(2, 2);
95+
ImageCoordinate border = (max - min) * .8 + ImageCoordinate(2.0, 2.0);
9596

9697
min -= border;
9798
max += border;
@@ -125,7 +126,10 @@ PixelRectangle FlexibleModelFittingIterativeTask::getUnclippedFittingRect(Source
125126
max.m_y = min.m_y + size;
126127
}
127128

128-
return PixelRectangle(min, max);
129+
auto min_pc = PixelCoordinate(static_cast<int>(min.m_x + 0.5), static_cast<int>(min.m_y + 0.5));
130+
auto max_pc = PixelCoordinate(static_cast<int>(max.m_x + 0.5), static_cast<int>(max.m_y + 0.5));
131+
132+
return PixelRectangle(min_pc, max_pc);
129133
}
130134
}
131135

SEImplementation/src/lib/Plugin/MeasurementFrameRectangle/MeasurementFrameRectangleTask.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,8 @@ void MeasurementFrameRectangleTask::computeProperties(SourceInterface& source) c
8585
max_coord.m_x = std::min(measurement_frame_info.getWidth() - 1, max_coord.m_x);
8686
max_coord.m_y = std::min(measurement_frame_info.getHeight() - 1, max_coord.m_y);
8787

88-
source.setIndexedProperty<MeasurementFrameRectangle>(m_instance, min_coord, max_coord);
88+
source.setIndexedProperty<MeasurementFrameRectangle>(
89+
m_instance, min_coord, max_coord, ImageCoordinate(min_x, min_y), ImageCoordinate(max_x, max_y));
8990
}
9091
}
9192

SEImplementation/src/lib/Plugin/MeasurementFrameRectangle/MeasurementFrameRectangleTaskNoDetect.cpp

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include "SEImplementation/Plugin/DetectionFrameCoordinates/DetectionFrameCoordinates.h"
2424
#include <SEImplementation/Plugin/WorldCentroid/WorldCentroid.h>
2525
#include <SEImplementation/Plugin/AssocMode/AssocMode.h>
26+
#include <SEImplementation/Plugin/ReferenceCoordinates/ReferenceCoordinates.h>
2627

2728
#include <SEImplementation/Plugin/MeasurementFrameRectangle/MeasurementFrameRectangle.h>
2829
#include <SEImplementation/Plugin/MeasurementFrameRectangle/MeasurementFrameRectangleTaskNoDetect.h>
@@ -31,23 +32,27 @@ namespace SourceXtractor {
3132

3233
void MeasurementFrameRectangleTaskNoDetect::computeProperties(SourceInterface& source) const {
3334
auto measurement_frame_coordinates = source.getProperty<MeasurementFrameCoordinates>(m_instance).getCoordinateSystem();
35+
auto reference_frame_coordinates = source.getProperty<ReferenceCoordinates>().getCoordinateSystem();
36+
3437
const auto& measurement_frame_info = source.getProperty<MeasurementFrameInfo>(m_instance);
3538
const auto& world_centroid = source.getProperty<WorldCentroid>();
3639
const auto& assoc_mode = source.getProperty<AssocMode>();
3740

38-
auto coord = world_centroid.getCentroid();
39-
4041
bool bad_coordinates = false;
4142
ImageCoordinate coord1, coord2, coord3, coord4;
4243
try {
43-
int w = assoc_mode.getRefFramePixelWidth();
44-
int h = assoc_mode.getRefFramePixelHeight();
44+
auto w = assoc_mode.getRefFramePixelWidth();
45+
auto h = assoc_mode.getRefFramePixelHeight();
4546

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);
47+
auto c = reference_frame_coordinates->worldToImage(world_centroid.getCentroid());
48+
coord1 = measurement_frame_coordinates->worldToImage(
49+
reference_frame_coordinates->imageToWorld(ImageCoordinate(c.m_x - w, c.m_y - h)));
50+
coord2 = measurement_frame_coordinates->worldToImage(
51+
reference_frame_coordinates->imageToWorld(ImageCoordinate(c.m_x + w, c.m_y - h)));
52+
coord3 = measurement_frame_coordinates->worldToImage(
53+
reference_frame_coordinates->imageToWorld(ImageCoordinate(c.m_x - w, c.m_y + h)));
54+
coord4 = measurement_frame_coordinates->worldToImage(
55+
reference_frame_coordinates->imageToWorld(ImageCoordinate(c.m_x + w, c.m_y + h)));
5156
}
5257
catch (const InvalidCoordinatesException&) {
5358
bad_coordinates = true;
@@ -77,7 +82,8 @@ void MeasurementFrameRectangleTaskNoDetect::computeProperties(SourceInterface& s
7782
max_coord.m_x = std::min(measurement_frame_info.getWidth() - 1, max_coord.m_x);
7883
max_coord.m_y = std::min(measurement_frame_info.getHeight() - 1, max_coord.m_y);
7984

80-
source.setIndexedProperty<MeasurementFrameRectangle>(m_instance, min_coord, max_coord);
85+
source.setIndexedProperty<MeasurementFrameRectangle>(
86+
m_instance, min_coord, max_coord, ImageCoordinate(min_x, min_y), ImageCoordinate(max_x, max_y));
8187
}
8288
}
8389

0 commit comments

Comments
 (0)