Skip to content

Commit

Permalink
align verify dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
ponchio committed Jan 23, 2025
1 parent 77bcabb commit db29bfd
Show file tree
Hide file tree
Showing 9 changed files with 153 additions and 34 deletions.
16 changes: 8 additions & 8 deletions relightlab/alignrow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ void FindAlignment::run() {
align->readThumb(img, i);

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

QPushButton *edit = new QPushButton(QIcon::fromTheme("edit"), "Edit...");
columns->addWidget(edit, 1);
QPushButton *verify = new QPushButton(QIcon::fromTheme("check"), "Verify...");
columns->addWidget(verify, 1);
verify_button = new QPushButton(QIcon::fromTheme("check"), "Verify...");
verify_button->setEnabled(false);
columns->addWidget(verify_button, 1);
QPushButton *remove = new QPushButton(QIcon::fromTheme("trash-2"), "Delete");
columns->addWidget(remove, 1);

connect(edit, SIGNAL(clicked()), this, SLOT(edit()));
connect(remove, SIGNAL(clicked()), this, SLOT(remove()));
connect(verify, SIGNAL(clicked()), this, SLOT(verify()));
connect(verify_button, SIGNAL(clicked()), this, SLOT(verify()));


}
Expand All @@ -94,10 +95,7 @@ void AlignRow::edit() {
}

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

Expand All @@ -111,10 +109,12 @@ void AlignRow::updateStatus(QString msg, int percent) {
//reflections->update();
if(percent == 100) {
emit updated();
verify_button->setEnabled(true);
}
}

void AlignRow::findAlignment(bool update) {
verify_button->setEnabled(false);
if(!find_alignment) {
find_alignment = new FindAlignment(align, update);
connect(find_alignment, &FindAlignment::progress, this, &AlignRow::updateStatus); //, Qt::QueuedConnection);
Expand Down
2 changes: 2 additions & 0 deletions relightlab/alignrow.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
class Align;
class QLabel;
class QProgressBar;
class QPushButton;
class AlignOverview;
class QGraphicsPixmapItem;

Expand All @@ -32,6 +33,7 @@ class AlignRow: public QWidget {
AlignOverview *position = nullptr;
QLabel *status = nullptr;
QProgressBar *progress = nullptr;
QPushButton *verify_button = nullptr;
FindAlignment *find_alignment = nullptr;

AlignRow(Align *align, QWidget *parent = nullptr);
Expand Down
15 changes: 10 additions & 5 deletions relightlab/sphererow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,15 @@ SphereRow::SphereRow(Sphere *_sphere, QWidget *parent): QWidget(parent) {

QPushButton *edit = new QPushButton(QIcon::fromTheme("edit"), "Edit...");
columns->addWidget(edit, 1);
QPushButton *verify = new QPushButton(QIcon::fromTheme("check"), "Verify...");
columns->addWidget(verify, 1);
verify_button = new QPushButton(QIcon::fromTheme("check"), "Verify...");
verify_button->setEnabled(false);
columns->addWidget(verify_button, 1);
QPushButton *remove = new QPushButton(QIcon::fromTheme("trash-2"), "Delete");
columns->addWidget(remove, 1);

connect(edit, SIGNAL(clicked()), this, SLOT(edit()));
connect(remove, SIGNAL(clicked()), this, SLOT(remove()));
connect(verify, SIGNAL(clicked()), this, SLOT(verify()));
connect(verify_button, SIGNAL(clicked()), this, SLOT(verify()));

}
void SphereRow::edit() {
Expand All @@ -92,8 +93,7 @@ void SphereRow::verify() {
std::vector<QPointF> &positions = sphere->lights;
for(QPointF &pos: positions)
pos -= sphere->inner.topLeft();

VerifyDialog *verify_dialog = new VerifyDialog(sphere->thumbs, positions, this);
VerifyDialog *verify_dialog = new VerifyDialog(sphere->thumbs, positions, VerifyDialog::REFLECTION, this);
verify_dialog->exec();

for(QPointF &pos: positions)
Expand All @@ -110,14 +110,18 @@ void SphereRow::updateStatus(QString /*msg*/, int percent) {
reflections->update();
if(percent == 100) {
emit updated();
verify_button->setEnabled(true);
}
}

void SphereRow::detectHighlights(bool update) {


if(sphere->center.isNull()) {
// status->setText("Needs at least 3 points.");
return;
}
verify_button->setEnabled(false);
if(!detect_highlights) {
detect_highlights = new DetectHighlights(sphere, update);
connect(detect_highlights, &DetectHighlights::progress, this, &SphereRow::updateStatus); //, Qt::QueuedConnection);
Expand All @@ -137,5 +141,6 @@ void SphereRow::stopDetecting() {
detect_highlights->wait();
}
detect_highlights->deleteLater();
verify_button->setEnabled(true);
}
}
2 changes: 2 additions & 0 deletions relightlab/sphererow.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
class Sphere;
class QLabel;
class QProgressBar;
class QPushButton;
class ReflectionOverview;
class SphereOverview;

Expand All @@ -31,6 +32,7 @@ class SphereRow: public QWidget {
ReflectionOverview *reflections = nullptr;
QLabel *status = nullptr;
QProgressBar *progress = nullptr;
QPushButton *verify_button = nullptr;
DetectHighlights *detect_highlights = nullptr;

SphereRow(Sphere *sphere, QWidget *parent = nullptr);
Expand Down
15 changes: 12 additions & 3 deletions relightlab/verifydialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@
#include <QDialogButtonBox>
#include "assert.h"

#include <iostream>
using namespace std;

VerifyDialog::VerifyDialog(std::vector<QImage> &_thumbs, std::vector<QPointF> &_positions, QWidget *parent):
VerifyDialog::VerifyDialog(std::vector<QImage> &_thumbs, std::vector<QPointF> &_positions, Markers marker, QWidget *parent):
QDialog(parent), thumbs(_thumbs), positions(_positions) {
setModal(true);

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

area->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);

cout << "Thumbs.size: " << thumbs.size() << endl;
for(size_t i = 0; i < thumbs.size(); i++) {
VerifyView *thumb = new VerifyView(thumbs[i], positions[i], 192);
flowlayout->addWidget(thumb);
assert(!thumbs[i].isNull());
if(marker == REFLECTION ) {
ReflectionVerify *thumb = new ReflectionVerify(thumbs[i], 192, positions[i]);
flowlayout->addWidget(thumb);
} else {
AlignVerify *thumb = new AlignVerify(thumbs[i], 192, positions[i]);
flowlayout->addWidget(thumb);
}
}

QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok);
Expand Down
3 changes: 2 additions & 1 deletion relightlab/verifydialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ class Sphere;

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

private:
FlowLayout *flowlayout = nullptr;
Expand Down
84 changes: 76 additions & 8 deletions relightlab/verifyview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,13 @@
#include "../src/sphere.h"

#include <QGraphicsPixmapItem>
#include <QGraphicsPathItem>
#include <QRectF>
#include <QDebug>
#include <assert.h>

ReflectionPoint::ReflectionPoint(VerifyView *_view, qreal x, qreal y, qreal w, qreal h, QGraphicsItem *parent):
QGraphicsEllipseItem(x, y, w, h, parent), view(_view) {
init();
}
ReflectionPoint::ReflectionPoint(VerifyView *_view, QRectF rect, QGraphicsItem *parent):
QGraphicsEllipseItem(rect, parent), view(_view) {

init();
}

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


AlignPoint::AlignPoint(VerifyView *_view, QGraphicsItem *parent):
QGraphicsPathItem(parent), view(_view) {
QPainterPath path;
path.moveTo(-2, 0);
path.lineTo(2, 0);
path.moveTo(0, -2);
path.lineTo(0, 2);
setPath(path);
init();
}

void AlignPoint::init() {
setCursor(Qt::CrossCursor);
setFlag(QGraphicsItem::ItemIsMovable);
setFlag(QGraphicsItem::ItemIsSelectable);
setFlag(QGraphicsItem::ItemSendsScenePositionChanges);
}

QVariant ReflectionPoint::itemChange(GraphicsItemChange change, const QVariant &value) {
if ((change == ItemPositionChange && scene()) ) {

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

if(change == ItemScenePositionHasChanged) {
view->updateReflection();
view->update();
}
return QGraphicsItem::itemChange(change, value);
}

QVariant AlignPoint::itemChange(GraphicsItemChange change, const QVariant &value) {
if ((change == ItemPositionChange && scene()) ) {

QPointF newPos = value.toPointF();
QRectF rect = scene()->sceneRect();
if (!rect.contains(newPos)) {
// Keep the item inside the scene rect.
newPos.setX(qMin(rect.right(), qMax(newPos.x(), rect.left())));
newPos.setY(qMin(rect.bottom(), qMax(newPos.y(), rect.top())));
}
return newPos;
}

if(change == ItemScenePositionHasChanged) {
view->update();
}
return QGraphicsItem::itemChange(change, value);
}

VerifyView:: VerifyView(QImage &_image, QPointF &_pos, int _height, QWidget *parent):
VerifyView:: VerifyView(QImage &_image, int _height, QPointF &_pos, QWidget *parent):
QGraphicsView(parent), image(_image), pos(_pos) {
height = _height;
setScene(&scene);
Expand All @@ -57,7 +91,11 @@ VerifyView:: VerifyView(QImage &_image, QPointF &_pos, int _height, QWidget *par
img_item = scene.addPixmap(pix);
double scale = height/(double)pix.height();
setFixedSize(pix.width()*scale, height);
}

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

void VerifyView::updateReflection() {
AlignVerify::AlignVerify(QImage&_image, int _height, QPointF &_pos, QWidget *parent):
VerifyView(_image, _height, _pos, parent) {

align = new AlignPoint(this);
if(pos.isNull()) {
align->setPos(image.width()/2, image.height()/2);
align->setPen(QPen(Qt::red, 0.2));

} else {
align->setPos(pos);
align->setPen(QPen(Qt::green, 0.2));
}
scene.addItem(align);
}


void ReflectionVerify::update() {
QPointF p = reflection->pos();
if(!img_item->boundingRect().contains(p)) {
reflection->setPos(image.width()/2, image.height()/2);
Expand All @@ -85,6 +139,20 @@ void VerifyView::updateReflection() {
}


void AlignVerify::update() {
QPointF p = align->pos();
if(!img_item->boundingRect().contains(p)) {
align->setPos(image.width()/2, image.height()/2);
align->setPen(QPen(Qt::red, 0.2));
pos = QPointF(0, 0); //order is important: setPos triggers again.

} else {
pos = p;
align->setPen(QPen(Qt::green, 0.2));
}
}


void VerifyView::resizeEvent(QResizeEvent *) {
fitInView(img_item->boundingRect()); //.sceneRect()); //img_item);
}
Expand Down
49 changes: 40 additions & 9 deletions relightlab/verifyview.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
class Sphere;
class VerifyView;


class ReflectionPoint: public QGraphicsEllipseItem {
public:
ReflectionPoint(VerifyView *_view, QRectF rect, QGraphicsItem *parent = Q_NULLPTR);
ReflectionPoint(VerifyView *_view, qreal x, qreal y, qreal w, qreal h, QGraphicsItem *parent = Q_NULLPTR);
void init();
virtual ~ReflectionPoint() {}

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

class AlignPoint: public QGraphicsPathItem {
public:
AlignPoint(VerifyView *_view, QGraphicsItem *parent = Q_NULLPTR);
AlignPoint(VerifyView *_view, qreal x, qreal y, QGraphicsItem *parent = Q_NULLPTR);
void init();
virtual ~AlignPoint() {}

protected:
VerifyView *view;
QVariant itemChange(GraphicsItemChange change, const QVariant &value);
};


class VerifyView: public QGraphicsView {
Q_OBJECT
public:
double lightSize = 10.0;
//id is just image number
VerifyView(QImage &image, QPointF &pos, int height, QWidget *parent = nullptr);

public slots:
void updateReflection();
VerifyView(QImage &image, int height, QPointF &pos, QWidget *parent = nullptr);
virtual void update() = 0;

protected:
void resizeEvent(QResizeEvent *event);

private:
protected:
QGraphicsPixmapItem *img_item;
ReflectionPoint *reflection;
QGraphicsScene scene;
QImage &image;
QPointF &pos;
int id;
int height;
};

class ReflectionVerify: public VerifyView {
Q_OBJECT
public:
double lightSize = 10.0;

ReflectionVerify(QImage &image,int height, QPointF &pos, QWidget *parent = nullptr);
virtual void update();

private:
ReflectionPoint *reflection;

};

class AlignVerify: public VerifyView {
Q_OBJECT
public:
AlignVerify(QImage &image,int height, QPointF &pos, QWidget *parent = nullptr);
virtual void update();

private:
AlignPoint *align;
};

#endif // VERIFYVIEW_H
Loading

0 comments on commit db29bfd

Please sign in to comment.