Skip to content

Commit db29bfd

Browse files
committed
align verify dialog
1 parent 77bcabb commit db29bfd

9 files changed

+153
-34
lines changed

relightlab/alignrow.cpp

+8-8
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ void FindAlignment::run() {
3434
align->readThumb(img, i);
3535

3636
int progress = std::min(99, (int)(100*(i+1) / project.images.size()));
37-
progressed(QString("Detecting highlights"), progress);
37+
progressed(QString("Collecting patches"), progress);
3838
}
3939
progressed(QString("Done"), 100);
4040
mutex.lock();
@@ -70,14 +70,15 @@ AlignRow::AlignRow(Align *_align, QWidget *parent): QWidget(parent) {
7070

7171
QPushButton *edit = new QPushButton(QIcon::fromTheme("edit"), "Edit...");
7272
columns->addWidget(edit, 1);
73-
QPushButton *verify = new QPushButton(QIcon::fromTheme("check"), "Verify...");
74-
columns->addWidget(verify, 1);
73+
verify_button = new QPushButton(QIcon::fromTheme("check"), "Verify...");
74+
verify_button->setEnabled(false);
75+
columns->addWidget(verify_button, 1);
7576
QPushButton *remove = new QPushButton(QIcon::fromTheme("trash-2"), "Delete");
7677
columns->addWidget(remove, 1);
7778

7879
connect(edit, SIGNAL(clicked()), this, SLOT(edit()));
7980
connect(remove, SIGNAL(clicked()), this, SLOT(remove()));
80-
connect(verify, SIGNAL(clicked()), this, SLOT(verify()));
81+
connect(verify_button, SIGNAL(clicked()), this, SLOT(verify()));
8182

8283

8384
}
@@ -94,10 +95,7 @@ void AlignRow::edit() {
9495
}
9596

9697
void AlignRow::verify() {
97-
std::vector<QPointF> centers;
98-
std::vector<QImage> thumbs;
99-
// assert(0); //todo needs to initialize those vaules and update align.
100-
VerifyDialog *verify_dialog = new VerifyDialog(thumbs, centers, this);
98+
VerifyDialog *verify_dialog = new VerifyDialog(align->thumbs, align->offsets, VerifyDialog::ALIGN, this);
10199
verify_dialog->exec();
102100
}
103101

@@ -111,10 +109,12 @@ void AlignRow::updateStatus(QString msg, int percent) {
111109
//reflections->update();
112110
if(percent == 100) {
113111
emit updated();
112+
verify_button->setEnabled(true);
114113
}
115114
}
116115

117116
void AlignRow::findAlignment(bool update) {
117+
verify_button->setEnabled(false);
118118
if(!find_alignment) {
119119
find_alignment = new FindAlignment(align, update);
120120
connect(find_alignment, &FindAlignment::progress, this, &AlignRow::updateStatus); //, Qt::QueuedConnection);

relightlab/alignrow.h

+2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
class Align;
1111
class QLabel;
1212
class QProgressBar;
13+
class QPushButton;
1314
class AlignOverview;
1415
class QGraphicsPixmapItem;
1516

@@ -32,6 +33,7 @@ class AlignRow: public QWidget {
3233
AlignOverview *position = nullptr;
3334
QLabel *status = nullptr;
3435
QProgressBar *progress = nullptr;
36+
QPushButton *verify_button = nullptr;
3537
FindAlignment *find_alignment = nullptr;
3638

3739
AlignRow(Align *align, QWidget *parent = nullptr);

relightlab/sphererow.cpp

+10-5
Original file line numberDiff line numberDiff line change
@@ -64,14 +64,15 @@ SphereRow::SphereRow(Sphere *_sphere, QWidget *parent): QWidget(parent) {
6464

6565
QPushButton *edit = new QPushButton(QIcon::fromTheme("edit"), "Edit...");
6666
columns->addWidget(edit, 1);
67-
QPushButton *verify = new QPushButton(QIcon::fromTheme("check"), "Verify...");
68-
columns->addWidget(verify, 1);
67+
verify_button = new QPushButton(QIcon::fromTheme("check"), "Verify...");
68+
verify_button->setEnabled(false);
69+
columns->addWidget(verify_button, 1);
6970
QPushButton *remove = new QPushButton(QIcon::fromTheme("trash-2"), "Delete");
7071
columns->addWidget(remove, 1);
7172

7273
connect(edit, SIGNAL(clicked()), this, SLOT(edit()));
7374
connect(remove, SIGNAL(clicked()), this, SLOT(remove()));
74-
connect(verify, SIGNAL(clicked()), this, SLOT(verify()));
75+
connect(verify_button, SIGNAL(clicked()), this, SLOT(verify()));
7576

7677
}
7778
void SphereRow::edit() {
@@ -92,8 +93,7 @@ void SphereRow::verify() {
9293
std::vector<QPointF> &positions = sphere->lights;
9394
for(QPointF &pos: positions)
9495
pos -= sphere->inner.topLeft();
95-
96-
VerifyDialog *verify_dialog = new VerifyDialog(sphere->thumbs, positions, this);
96+
VerifyDialog *verify_dialog = new VerifyDialog(sphere->thumbs, positions, VerifyDialog::REFLECTION, this);
9797
verify_dialog->exec();
9898

9999
for(QPointF &pos: positions)
@@ -110,14 +110,18 @@ void SphereRow::updateStatus(QString /*msg*/, int percent) {
110110
reflections->update();
111111
if(percent == 100) {
112112
emit updated();
113+
verify_button->setEnabled(true);
113114
}
114115
}
115116

116117
void SphereRow::detectHighlights(bool update) {
118+
119+
117120
if(sphere->center.isNull()) {
118121
// status->setText("Needs at least 3 points.");
119122
return;
120123
}
124+
verify_button->setEnabled(false);
121125
if(!detect_highlights) {
122126
detect_highlights = new DetectHighlights(sphere, update);
123127
connect(detect_highlights, &DetectHighlights::progress, this, &SphereRow::updateStatus); //, Qt::QueuedConnection);
@@ -137,5 +141,6 @@ void SphereRow::stopDetecting() {
137141
detect_highlights->wait();
138142
}
139143
detect_highlights->deleteLater();
144+
verify_button->setEnabled(true);
140145
}
141146
}

relightlab/sphererow.h

+2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
class Sphere;
1010
class QLabel;
1111
class QProgressBar;
12+
class QPushButton;
1213
class ReflectionOverview;
1314
class SphereOverview;
1415

@@ -31,6 +32,7 @@ class SphereRow: public QWidget {
3132
ReflectionOverview *reflections = nullptr;
3233
QLabel *status = nullptr;
3334
QProgressBar *progress = nullptr;
35+
QPushButton *verify_button = nullptr;
3436
DetectHighlights *detect_highlights = nullptr;
3537

3638
SphereRow(Sphere *sphere, QWidget *parent = nullptr);

relightlab/verifydialog.cpp

+12-3
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@
1111
#include <QDialogButtonBox>
1212
#include "assert.h"
1313

14+
#include <iostream>
15+
using namespace std;
1416

15-
VerifyDialog::VerifyDialog(std::vector<QImage> &_thumbs, std::vector<QPointF> &_positions, QWidget *parent):
17+
VerifyDialog::VerifyDialog(std::vector<QImage> &_thumbs, std::vector<QPointF> &_positions, Markers marker, QWidget *parent):
1618
QDialog(parent), thumbs(_thumbs), positions(_positions) {
1719
setModal(true);
1820

@@ -28,9 +30,16 @@ VerifyDialog::VerifyDialog(std::vector<QImage> &_thumbs, std::vector<QPointF> &_
2830

2931
area->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
3032

33+
cout << "Thumbs.size: " << thumbs.size() << endl;
3134
for(size_t i = 0; i < thumbs.size(); i++) {
32-
VerifyView *thumb = new VerifyView(thumbs[i], positions[i], 192);
33-
flowlayout->addWidget(thumb);
35+
assert(!thumbs[i].isNull());
36+
if(marker == REFLECTION ) {
37+
ReflectionVerify *thumb = new ReflectionVerify(thumbs[i], 192, positions[i]);
38+
flowlayout->addWidget(thumb);
39+
} else {
40+
AlignVerify *thumb = new AlignVerify(thumbs[i], 192, positions[i]);
41+
flowlayout->addWidget(thumb);
42+
}
3443
}
3544

3645
QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok);

relightlab/verifydialog.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ class Sphere;
99

1010
class VerifyDialog: public QDialog {
1111
public:
12-
VerifyDialog(std::vector<QImage> &thumbs, std::vector<QPointF> &positions, QWidget *parent = nullptr);
12+
enum Markers { REFLECTION, ALIGN };
13+
VerifyDialog(std::vector<QImage> &thumbs, std::vector<QPointF> &positions, Markers marker, QWidget *parent = nullptr);
1314

1415
private:
1516
FlowLayout *flowlayout = nullptr;

relightlab/verifyview.cpp

+76-8
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,13 @@
55
#include "../src/sphere.h"
66

77
#include <QGraphicsPixmapItem>
8+
#include <QGraphicsPathItem>
89
#include <QRectF>
910
#include <QDebug>
1011
#include <assert.h>
1112

12-
ReflectionPoint::ReflectionPoint(VerifyView *_view, qreal x, qreal y, qreal w, qreal h, QGraphicsItem *parent):
13-
QGraphicsEllipseItem(x, y, w, h, parent), view(_view) {
14-
init();
15-
}
1613
ReflectionPoint::ReflectionPoint(VerifyView *_view, QRectF rect, QGraphicsItem *parent):
1714
QGraphicsEllipseItem(rect, parent), view(_view) {
18-
1915
init();
2016
}
2117

@@ -26,6 +22,25 @@ void ReflectionPoint::init() {
2622
setFlag(QGraphicsItem::ItemSendsScenePositionChanges);
2723
}
2824

25+
26+
AlignPoint::AlignPoint(VerifyView *_view, QGraphicsItem *parent):
27+
QGraphicsPathItem(parent), view(_view) {
28+
QPainterPath path;
29+
path.moveTo(-2, 0);
30+
path.lineTo(2, 0);
31+
path.moveTo(0, -2);
32+
path.lineTo(0, 2);
33+
setPath(path);
34+
init();
35+
}
36+
37+
void AlignPoint::init() {
38+
setCursor(Qt::CrossCursor);
39+
setFlag(QGraphicsItem::ItemIsMovable);
40+
setFlag(QGraphicsItem::ItemIsSelectable);
41+
setFlag(QGraphicsItem::ItemSendsScenePositionChanges);
42+
}
43+
2944
QVariant ReflectionPoint::itemChange(GraphicsItemChange change, const QVariant &value) {
3045
if ((change == ItemPositionChange && scene()) ) {
3146

@@ -40,12 +55,31 @@ QVariant ReflectionPoint::itemChange(GraphicsItemChange change, const QVariant &
4055
}
4156

4257
if(change == ItemScenePositionHasChanged) {
43-
view->updateReflection();
58+
view->update();
59+
}
60+
return QGraphicsItem::itemChange(change, value);
61+
}
62+
63+
QVariant AlignPoint::itemChange(GraphicsItemChange change, const QVariant &value) {
64+
if ((change == ItemPositionChange && scene()) ) {
65+
66+
QPointF newPos = value.toPointF();
67+
QRectF rect = scene()->sceneRect();
68+
if (!rect.contains(newPos)) {
69+
// Keep the item inside the scene rect.
70+
newPos.setX(qMin(rect.right(), qMax(newPos.x(), rect.left())));
71+
newPos.setY(qMin(rect.bottom(), qMax(newPos.y(), rect.top())));
72+
}
73+
return newPos;
74+
}
75+
76+
if(change == ItemScenePositionHasChanged) {
77+
view->update();
4478
}
4579
return QGraphicsItem::itemChange(change, value);
4680
}
4781

48-
VerifyView:: VerifyView(QImage &_image, QPointF &_pos, int _height, QWidget *parent):
82+
VerifyView:: VerifyView(QImage &_image, int _height, QPointF &_pos, QWidget *parent):
4983
QGraphicsView(parent), image(_image), pos(_pos) {
5084
height = _height;
5185
setScene(&scene);
@@ -57,7 +91,11 @@ VerifyView:: VerifyView(QImage &_image, QPointF &_pos, int _height, QWidget *par
5791
img_item = scene.addPixmap(pix);
5892
double scale = height/(double)pix.height();
5993
setFixedSize(pix.width()*scale, height);
94+
}
6095

96+
ReflectionVerify::ReflectionVerify(QImage&_image, int _height, QPointF &_pos, QWidget *parent):
97+
VerifyView(_image, _height, _pos, parent) {
98+
double scale = height/double(image.height());
6199
int r = 8*scale;
62100
reflection = new ReflectionPoint(this, QRectF(QPointF(-r, -r), QSize(2*r, 2*r)));
63101
if(pos.isNull()) {
@@ -71,7 +109,23 @@ VerifyView:: VerifyView(QImage &_image, QPointF &_pos, int _height, QWidget *par
71109
scene.addItem(reflection);
72110
}
73111

74-
void VerifyView::updateReflection() {
112+
AlignVerify::AlignVerify(QImage&_image, int _height, QPointF &_pos, QWidget *parent):
113+
VerifyView(_image, _height, _pos, parent) {
114+
115+
align = new AlignPoint(this);
116+
if(pos.isNull()) {
117+
align->setPos(image.width()/2, image.height()/2);
118+
align->setPen(QPen(Qt::red, 0.2));
119+
120+
} else {
121+
align->setPos(pos);
122+
align->setPen(QPen(Qt::green, 0.2));
123+
}
124+
scene.addItem(align);
125+
}
126+
127+
128+
void ReflectionVerify::update() {
75129
QPointF p = reflection->pos();
76130
if(!img_item->boundingRect().contains(p)) {
77131
reflection->setPos(image.width()/2, image.height()/2);
@@ -85,6 +139,20 @@ void VerifyView::updateReflection() {
85139
}
86140

87141

142+
void AlignVerify::update() {
143+
QPointF p = align->pos();
144+
if(!img_item->boundingRect().contains(p)) {
145+
align->setPos(image.width()/2, image.height()/2);
146+
align->setPen(QPen(Qt::red, 0.2));
147+
pos = QPointF(0, 0); //order is important: setPos triggers again.
148+
149+
} else {
150+
pos = p;
151+
align->setPen(QPen(Qt::green, 0.2));
152+
}
153+
}
154+
155+
88156
void VerifyView::resizeEvent(QResizeEvent *) {
89157
fitInView(img_item->boundingRect()); //.sceneRect()); //img_item);
90158
}

relightlab/verifyview.h

+40-9
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@
88
class Sphere;
99
class VerifyView;
1010

11+
1112
class ReflectionPoint: public QGraphicsEllipseItem {
1213
public:
1314
ReflectionPoint(VerifyView *_view, QRectF rect, QGraphicsItem *parent = Q_NULLPTR);
14-
ReflectionPoint(VerifyView *_view, qreal x, qreal y, qreal w, qreal h, QGraphicsItem *parent = Q_NULLPTR);
1515
void init();
1616
virtual ~ReflectionPoint() {}
1717

@@ -20,27 +20,58 @@ class ReflectionPoint: public QGraphicsEllipseItem {
2020
QVariant itemChange(GraphicsItemChange change, const QVariant &value);
2121
};
2222

23+
class AlignPoint: public QGraphicsPathItem {
24+
public:
25+
AlignPoint(VerifyView *_view, QGraphicsItem *parent = Q_NULLPTR);
26+
AlignPoint(VerifyView *_view, qreal x, qreal y, QGraphicsItem *parent = Q_NULLPTR);
27+
void init();
28+
virtual ~AlignPoint() {}
29+
30+
protected:
31+
VerifyView *view;
32+
QVariant itemChange(GraphicsItemChange change, const QVariant &value);
33+
};
34+
2335

2436
class VerifyView: public QGraphicsView {
2537
Q_OBJECT
2638
public:
27-
double lightSize = 10.0;
28-
//id is just image number
29-
VerifyView(QImage &image, QPointF &pos, int height, QWidget *parent = nullptr);
30-
31-
public slots:
32-
void updateReflection();
39+
VerifyView(QImage &image, int height, QPointF &pos, QWidget *parent = nullptr);
40+
virtual void update() = 0;
3341

3442
protected:
3543
void resizeEvent(QResizeEvent *event);
3644

37-
private:
45+
protected:
3846
QGraphicsPixmapItem *img_item;
39-
ReflectionPoint *reflection;
4047
QGraphicsScene scene;
4148
QImage &image;
4249
QPointF &pos;
4350
int id;
4451
int height;
4552
};
53+
54+
class ReflectionVerify: public VerifyView {
55+
Q_OBJECT
56+
public:
57+
double lightSize = 10.0;
58+
59+
ReflectionVerify(QImage &image,int height, QPointF &pos, QWidget *parent = nullptr);
60+
virtual void update();
61+
62+
private:
63+
ReflectionPoint *reflection;
64+
65+
};
66+
67+
class AlignVerify: public VerifyView {
68+
Q_OBJECT
69+
public:
70+
AlignVerify(QImage &image,int height, QPointF &pos, QWidget *parent = nullptr);
71+
virtual void update();
72+
73+
private:
74+
AlignPoint *align;
75+
};
76+
4677
#endif // VERIFYVIEW_H

0 commit comments

Comments
 (0)