-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
476 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,91 @@ | ||
#include "alignframe.h" | ||
#include "imageview.h" | ||
#include "flowlayout.h" | ||
#include "relightapp.h" | ||
#include "markerdialog.h" | ||
#include "alignrow.h" | ||
#include "../src/align.h" | ||
|
||
#include <QVBoxLayout> | ||
#include <QHBoxLayout> | ||
#include <QGraphicsRectItem> | ||
#include <QPushButton> | ||
|
||
AlignFrame::AlignFrame(QWidget *parent): QFrame(parent) { | ||
//TODO: make a function for this to use in all frames. (inheritance?) | ||
setFrameStyle(QFrame::NoFrame); | ||
QVBoxLayout *content = new QVBoxLayout(this); | ||
|
||
QVBoxLayout *content = new QVBoxLayout(this); | ||
content->addSpacing(10); | ||
QPushButton *new_align = new QPushButton("New align..."); | ||
new_align->setProperty("class", "large"); | ||
content->addWidget(new_align); | ||
new_align->setMinimumWidth(200); | ||
new_align->setMaximumWidth(300); | ||
|
||
content->addWidget(image_viewer = new ImageViewer()); | ||
QFrame *aligns_frame = new QFrame; | ||
content->addWidget(aligns_frame); | ||
aligns = new QVBoxLayout(aligns_frame); | ||
|
||
//content->addWidget(new FlowLayout()); | ||
//content->addStretch(); | ||
connect(new_align, SIGNAL(clicked()), this, SLOT(newAlign())); | ||
} | ||
|
||
void AlignFrame::clear() { | ||
while(aligns->count() > 0) { | ||
QLayoutItem *item = aligns->takeAt(0); | ||
AlignRow *row = dynamic_cast<AlignRow *>(item->widget()); | ||
//row->stopDetecting(); | ||
delete row; | ||
} | ||
} | ||
|
||
connect(image_viewer->view, SIGNAL(clicked(QPoint)), this, SLOT(click(QPoint))); | ||
void AlignFrame::init() { | ||
for(Align *align: qRelightApp->project().aligns) { | ||
AlignRow * row = addAlign(align); | ||
// row->detectHighlights(false); | ||
} | ||
} | ||
|
||
void AlignFrame::click(QPoint p) { | ||
QPointF pos = image_viewer->view->mapToScene(p); | ||
/* on user button press */ | ||
void AlignFrame::newAlign() { | ||
if(!marker_dialog) | ||
marker_dialog = new MarkerDialog(MarkerDialog::ALIGN, this); | ||
|
||
//min distance between border points in pixels. | ||
double minBorderDist = 20; | ||
if( sqrt(pow(p.x() - pos.x(), 2) + pow(p.y() - pos.y(), 2)) < minBorderDist) { | ||
return; | ||
//TODO ACTUALLY images might be skipped! | ||
Align *align = new Align(qRelightApp->project().images.size()); | ||
marker_dialog->setAlign(align); | ||
int answer = marker_dialog->exec(); | ||
if(answer == QDialog::Rejected) { | ||
delete align; | ||
return; | ||
} | ||
float side = 32; | ||
QGraphicsRectItem *rect = new QGraphicsRectItem(pos.x() - side, pos.y() - side, side*2, side*2); | ||
image_viewer->scene().addItem(rect); | ||
qRelightApp->project().aligns.push_back(align); | ||
AlignRow *row = addAlign(align); | ||
//row->detectHighlights(); | ||
} | ||
|
||
AlignRow *AlignFrame::addAlign(Align *align) { | ||
AlignRow *row = new AlignRow(align); | ||
aligns->addWidget(row); | ||
|
||
|
||
connect(row, SIGNAL(removeme(AlignRow *)), this, SLOT(removeAlign(AlignRow *))); | ||
connect(row, SIGNAL(updated()), this, SIGNAL(updated())); | ||
return row; | ||
} | ||
|
||
void AlignFrame::removeAlign(AlignRow *row) { | ||
layout()->removeWidget(row); | ||
|
||
// row->stopDetecting(); | ||
|
||
Align *align = row->align; | ||
auto &aligns = qRelightApp->project().aligns; | ||
|
||
auto it = std::find(aligns.begin(), aligns.end(), align); | ||
|
||
assert(it != aligns.end()); | ||
|
||
delete align; | ||
aligns.erase(it); | ||
delete row; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
#include "alignpicking.h" | ||
#include "canvas.h" | ||
#include "../src/align.h" | ||
#include "relightapp.h" | ||
|
||
#include <QGraphicsRectItem> | ||
#include <QPen> | ||
#include <QKeyEvent> | ||
|
||
AlignPicking::AlignPicking(QWidget *parent): ImageViewer(parent) { | ||
|
||
marker_side = 40; | ||
|
||
connect(view, SIGNAL(clicked(QPoint)), this, SLOT(click(QPoint))); | ||
} | ||
|
||
|
||
void AlignPicking::clear() { | ||
scene().clear(); | ||
rect = nullptr; | ||
} | ||
|
||
void AlignPicking::setAlign(Align *a) { | ||
clear(); | ||
align = a; | ||
|
||
rect = scene().addRect(a->rect, QPen(Qt::yellow), Qt::red); | ||
|
||
showImage(0); | ||
fit(); | ||
} | ||
|
||
|
||
|
||
void AlignPicking::click(QPoint p) { | ||
clear(); | ||
|
||
QSize imgsize = qRelightApp->project().imgsize; | ||
QPointF pos = view->mapToScene(p); | ||
|
||
//ensure that the marker is inside the image | ||
pos.setX(std::max(marker_side/2.0, pos.x())); | ||
pos.setY(std::max(marker_side/2.0, pos.y())); | ||
|
||
|
||
pos.setX(std::min(imgsize.width()-marker_side/2.0, pos.x())); | ||
pos.setY(std::min(imgsize.height()-marker_side/2.0, pos.y())); | ||
|
||
align->rect = QRect(pos.x()-marker_side/2.0, pos.y()-marker_side/2.0, marker_side, marker_side); | ||
rect = scene().addRect(align->rect, QPen(Qt::yellow), Qt::red); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#ifndef ALIGN_PICKING_H | ||
#define ALIGN_PICKING_H | ||
|
||
#include "imageview.h" | ||
|
||
class QGraphicsRectItem; | ||
class Canvas; | ||
class Align; | ||
|
||
|
||
class AlignPicking: public ImageViewer { | ||
Q_OBJECT | ||
public: | ||
int marker_side = 40; | ||
Align *align = nullptr; | ||
|
||
QGraphicsRectItem *rect = nullptr; | ||
|
||
|
||
AlignPicking(QWidget *parent = nullptr); | ||
void setAlign(Align *sphere); | ||
void updateAlign(); | ||
void clear(); | ||
|
||
public slots: | ||
void click(QPoint); | ||
|
||
}; | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
#include "alignrow.h" | ||
#include "markerdialog.h" | ||
#include "relightapp.h" | ||
#include "verifydialog.h" | ||
#include "reflectionview.h" | ||
#include "../src/project.h" | ||
#include "../src/sphere.h" | ||
#include "../relight/processqueue.h" | ||
|
||
#include <QHBoxLayout> | ||
#include <QLabel> | ||
#include <QProgressBar> | ||
#include <QPushButton> | ||
#include <QDebug> | ||
|
||
FindAlignment::FindAlignment(Align *_align, bool update) { | ||
align = _align; | ||
update_positions = update; | ||
} | ||
|
||
void FindAlignment::run() { | ||
mutex.lock(); | ||
status = RUNNING; | ||
mutex.unlock(); | ||
/* | ||
Project &project = qRelightApp->project(); | ||
for(size_t i = 0; i < project.images.size(); i++) { | ||
Image &image = project.images[i]; | ||
if(image.skip) continue; | ||
QImage img(image.filename); | ||
sphere->findHighlight(img, i, update_positions); | ||
int progress = std::min(99, (int)(100*(i+1) / project.images.size())); | ||
progressed(QString("Detecting highlights"), progress); | ||
} */ | ||
progressed(QString("Done"), 100); | ||
mutex.lock(); | ||
status = DONE; | ||
mutex.unlock(); | ||
} | ||
|
||
|
||
AlignRow::AlignRow(Align *_align, QWidget *parent): QWidget(parent) { | ||
align = _align; | ||
QHBoxLayout *columns = new QHBoxLayout(this); | ||
columns->setSpacing(20); | ||
|
||
columns->addWidget(thumb = new QLabel()); | ||
/* position = new PositionView(sphere, rowHeight); | ||
position->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); | ||
columns->addWidget(position); | ||
reflections = new ReflectionView(sphere, rowHeight); | ||
reflections->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); | ||
columns->addWidget(reflections); */ | ||
|
||
QVBoxLayout *status_layout = new QVBoxLayout; | ||
columns->addLayout(status_layout, 2); | ||
status_layout->addStretch(); | ||
status = new QLabel("Locating highlights..."); | ||
status_layout->addWidget(status); | ||
progress = new QProgressBar; | ||
progress->setValue(0); | ||
status_layout->addWidget(progress); | ||
status_layout->addStretch(); | ||
|
||
QPushButton *edit = new QPushButton(QIcon::fromTheme("edit"), "Edit..."); | ||
columns->addWidget(edit, 1); | ||
QPushButton *verify = new QPushButton(QIcon::fromTheme("check"), "Verify..."); | ||
columns->addWidget(verify, 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())); | ||
|
||
} | ||
void AlignRow::edit() { | ||
MarkerDialog *marker_dialog = new MarkerDialog(MarkerDialog::ALIGN, this); | ||
marker_dialog->setAlign(align); | ||
int answer = marker_dialog->exec(); | ||
if(answer == QDialog::Accepted) { | ||
//position->update(); | ||
//reflections->init(); | ||
//detectHighlights(); | ||
} | ||
} | ||
|
||
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); | ||
verify_dialog->exec(); | ||
} | ||
|
||
void AlignRow::remove() { | ||
emit removeme(this); | ||
} | ||
|
||
void AlignRow::updateStatus(QString msg, int percent) { | ||
status->setText(msg); | ||
progress->setValue(percent); | ||
reflections->update(); | ||
if(percent == 100) { | ||
emit updated(); | ||
} | ||
} | ||
|
||
void AlignRow::findAlignment(bool update) { | ||
/* if(sphere->center.isNull()) { | ||
status->setText("Needs at least 3 points."); | ||
return; | ||
} | ||
if(!detect_highlights) { | ||
detect_highlights = new DetectHighlights(sphere, update); | ||
connect(detect_highlights, &DetectHighlights::progress, this, &SphereRow::updateStatus); //, Qt::QueuedConnection); | ||
} | ||
detect_highlights->stop(); | ||
ProcessQueue &queue = ProcessQueue::instance(); | ||
queue.removeTask(detect_highlights); | ||
queue.addTask(detect_highlights); | ||
queue.start(); */ | ||
} | ||
|
||
void AlignRow::stopFinding() { | ||
/* | ||
if(detect_highlights) { | ||
if(detect_highlights->isRunning()) { | ||
detect_highlights->stop(); | ||
detect_highlights->wait(); | ||
} | ||
detect_highlights->deleteLater(); | ||
} */ | ||
} |
Oops, something went wrong.