Skip to content

Commit 6d6f8ad

Browse files
committed
Cache for align and sphere patches.
1 parent 66c89ad commit 6d6f8ad

23 files changed

+264
-104
lines changed

relightlab/alignframe.cpp

+5-16
Original file line numberDiff line numberDiff line change
@@ -74,13 +74,14 @@ void AlignFrame::okMarker() {
7474

7575
AlignRow *row = findRow(provisional_align);
7676

77-
provisional_align->rect = marker_dialog->getAlign();
77+
provisional_align->rect = marker_dialog->getAlign().toRect();
7878
if(!row) { //new align
7979
qRelightApp->project().aligns.push_back(provisional_align);
8080
row = addAlign(provisional_align);
8181
} else {
8282
row->setRect(provisional_align->rect);
8383
}
84+
qRelightApp->project().cleanAlignCache();
8485
row->findAlignment();
8586

8687
provisional_align = nullptr;
@@ -98,8 +99,6 @@ void AlignFrame::cancelMarker() {
9899
stack->setCurrentIndex(0);
99100
}
100101

101-
102-
/* on user button press */
103102
void AlignFrame::newAlign() {
104103
stack->setCurrentIndex(1);
105104
provisional_align = new Align(qRelightApp->project().images.size());
@@ -122,27 +121,17 @@ AlignRow *AlignFrame::addAlign(Align *align) {
122121
AlignRow *row = new AlignRow(align);
123122
aligns->addWidget(row);
124123

125-
connect(row, SIGNAL(edit(AlignRow *)), this, SLOT(editAlign(AlignRow *)));
124+
connect(row, SIGNAL(editme(AlignRow *)), this, SLOT(editAlign(AlignRow *)));
126125
connect(row, SIGNAL(removeme(AlignRow *)), this, SLOT(removeAlign(AlignRow *)));
127-
connect(row, SIGNAL(updated()), this, SLOT(projectUpdate()));
126+
connect(row, SIGNAL(updated()), this, SLOT(projectUpdate()));
128127
return row;
129128
}
130129

131130
void AlignFrame::removeAlign(AlignRow *row) {
132-
row->stopFinding();
133131

134132
layout()->removeWidget(row);
135-
136-
Align *align = row->align;
137-
auto &aligns = qRelightApp->project().aligns;
138-
139-
auto it = std::find(aligns.begin(), aligns.end(), align);
140-
141-
assert(it != aligns.end());
142-
143-
delete align;
144-
aligns.erase(it);
145133
delete row;
134+
146135
projectUpdate();
147136
}
148137

relightlab/alignrow.cpp

+43-14
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,34 @@
1212
#include <QLabel>
1313
#include <QProgressBar>
1414
#include <QPushButton>
15+
#include <QMessageBox>
1516

1617
FindAlignment::FindAlignment(Align *_align, bool update) {
1718
align = _align;
1819
update_positions = update;
1920
visible = false;
21+
owned = true;
2022
}
2123

2224
void FindAlignment::run() {
2325
setStatus(RUNNING);
2426

27+
QRect inner = align->rect;
28+
QString cache_filename = QString("resources/align_%1x%2+%3+%4.jpg")
29+
.arg(inner.width())
30+
.arg(inner.height())
31+
.arg(inner.left())
32+
.arg(inner.top());
33+
34+
QImage img(cache_filename);
35+
if(!img.isNull()) {
36+
align->readCacheThumbs(img);
37+
progressed(QString("Done."), 100);
38+
setStatus(DONE);
39+
return;
40+
}
41+
42+
2543
Project &project = qRelightApp->project();
2644
for(size_t i = 0; i < project.images.size(); i++) {
2745

@@ -40,6 +58,7 @@ void FindAlignment::run() {
4058
if(!progressed(QString("Collecting patches"), progress))
4159
return;
4260
}
61+
align->saveCacheThumbs(cache_filename);
4362
progressed(QString("Done"), 100);
4463
setStatus(DONE);
4564
}
@@ -90,8 +109,8 @@ AlignRow::AlignRow(Align *_align, QWidget *parent): QWidget(parent) {
90109

91110
edit_layout->setRowStretch(3,1);
92111

93-
connect(edit_button, &QPushButton::clicked, [this]() { emit edit(this); });
94-
connect(remove_button, &QPushButton::clicked, [this]() { emit removeme(this); });
112+
connect(edit_button, &QPushButton::clicked, [this]() { emit editme(this); });
113+
connect(remove_button, SIGNAL(clicked()), this, SLOT(remove()));
95114
connect(verify_button, SIGNAL(clicked()), this, SLOT(verify()));
96115
}
97116

@@ -101,24 +120,27 @@ AlignRow::~AlignRow() {
101120
}
102121
delete find_alignment;
103122
}
104-
/*
105-
void AlignRow::edit() {
106-
MarkerDialog *marker_dialog = new MarkerDialog(MarkerDialog::ALIGN, this);
107-
marker_dialog->setAlign(align);
108-
int answer = marker_dialog->exec();
109-
if(answer == QDialog::Accepted) {
110-
position->rect = align->rect;
111-
position->update();
112-
updateRegion();
113-
findAlignment();
114-
}
115-
}*/
116123

117124
void AlignRow::verify() {
118125
VerifyDialog *verify_dialog = new VerifyDialog(align->thumbs, align->offsets, VerifyDialog::ALIGN, this);
119126
verify_dialog->exec();
127+
128+
emit updated();
120129
}
121130

131+
void AlignRow::remove() {
132+
stopFinding();
133+
auto &aligns = qRelightApp->project().aligns;
134+
auto it = std::find(aligns.begin(), aligns.end(), align);
135+
assert(it != aligns.end());
136+
137+
delete align;
138+
aligns.erase(it);
139+
140+
qRelightApp->project().cleanAlignCache();
141+
142+
emit removeme(this);
143+
}
122144

123145
void AlignRow::updateRegion() {
124146
QRectF r = align->rect;
@@ -133,6 +155,12 @@ void AlignRow::setRect(QRectF rect) {
133155
}
134156

135157
void AlignRow::updateStatus(QString msg, int percent) {
158+
if(find_alignment->status == Task::FAILED) {
159+
QMessageBox::critical(this, "Could not load patches!", msg);
160+
progress->setValue(0);
161+
return;
162+
}
163+
136164
status->setText(msg);
137165
progress->setValue(percent);
138166
//reflections->update();
@@ -164,6 +192,7 @@ void AlignRow::stopFinding() {
164192
find_alignment->stop();
165193
find_alignment->wait();
166194
}
195+
verify_button->setEnabled(true);
167196
ProcessQueue &queue = ProcessQueue::instance();
168197
queue.removeTask(find_alignment);
169198
}

relightlab/alignrow.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,12 @@ class AlignRow: public QWidget {
4646
void setRect(QRectF rect);
4747

4848
signals:
49-
void edit(AlignRow *row);
49+
void editme(AlignRow *row);
5050
void removeme(AlignRow *row);
5151
void updated(); //emit when status changes
5252

5353
public slots:
54+
void remove();
5455
void verify();
5556
void updateStatus(QString msg, int percent);
5657
};

relightlab/imageframe.cpp

+6-6
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,12 @@ ImageFrame::ImageFrame(QWidget *parent): QFrame(parent) {
6060

6161
content->addWidget(image_view = new ImageView, 1);
6262

63-
connect(image_list, SIGNAL(skipChanged(int,bool)), image_grid, SLOT(setSkipped(int,bool)));
64-
connect(image_list, SIGNAL(skipChanged(int,bool)), image_view, SLOT(setSkipped(int,bool)));
65-
connect(image_grid, SIGNAL(skipChanged(int,bool)), image_list, SLOT(setSkipped(int,bool)));
66-
connect(image_grid, SIGNAL(skipChanged(int,bool)), image_view, SLOT(setSkipped(int,bool)));
67-
connect(image_view, SIGNAL(skipChanged(int,bool)), image_grid, SLOT(setSkipped(int,bool)));
68-
connect(image_view, SIGNAL(skipChanged(int,bool)), image_list, SLOT(setSkipped(int,bool)));
63+
connect(image_list, SIGNAL(skipChanged(int)), image_grid, SLOT(setSkipped(int)));
64+
connect(image_list, SIGNAL(skipChanged(int)), image_view, SLOT(setSkipped(int)));
65+
connect(image_grid, SIGNAL(skipChanged(int)), image_list, SLOT(setSkipped(int)));
66+
connect(image_grid, SIGNAL(skipChanged(int)), image_view, SLOT(setSkipped(int)));
67+
connect(image_view, SIGNAL(skipChanged(int)), image_grid, SLOT(setSkipped(int)));
68+
connect(image_view, SIGNAL(skipChanged(int)), image_list, SLOT(setSkipped(int)));
6969

7070
connect(qRelightApp->action("rotate_left"), SIGNAL(triggered(bool)), this, SLOT(rotateLeft()));
7171
connect(qRelightApp->action("rotate_right"), SIGNAL(triggered(bool)), this, SLOT(rotateRight()));

relightlab/imagegrid.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -79,13 +79,13 @@ void ImageGrid::init() {
7979
ImageThumb *thumb = new ImageThumb(thumbnail, info.fileName(), image.skip, image.visible);
8080
connect(thumb, &ImageThumb::skipChanged, [this, i, &image](int state){
8181
image.skip = (state==0);
82-
this->emit skipChanged(i, image.skip);
82+
this->emit skipChanged(i);
8383
});
8484
flowlayout->addWidget(thumb);
8585
}
8686
}
8787

88-
void ImageGrid::setSkipped(int img_number, bool skip) {
88+
void ImageGrid::setSkipped(int img_number) {
8989
auto &images = qRelightApp->project().images;
9090
assert(img_number >= 0 && img_number < images.size());
9191
Image &img = images[img_number];

relightlab/imagegrid.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,11 @@ class ImageGrid: public QScrollArea {
3434
void init();
3535

3636
public slots:
37-
void setSkipped(int image, bool skip);
37+
void setSkipped(int image);
3838
void updateThumbnail(int pos);
3939

4040
signals:
41-
void skipChanged(int image, bool skip);
41+
void skipChanged(int image);
4242

4343
private:
4444
FlowLayout *flowlayout = nullptr;

relightlab/imagelist.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,10 @@ void ImageList::verifyItem(QListWidgetItem *item) {
5050

5151
project.images[img_number].skip = skip;
5252

53-
emit skipChanged(img_number, skip);
53+
emit skipChanged(img_number);
5454
}
5555

56-
void ImageList::setSkipped(int img_number, bool skip) {
56+
void ImageList::setSkipped(int img_number) {
5757
QListWidgetItem *item = this->item(img_number);
5858
auto &images = qRelightApp->project().images;
5959
assert(img_number >= 0 && img_number < images.size());
@@ -93,7 +93,7 @@ void ImageList::mousePressEvent(QMouseEvent *event) {
9393
img.visible = !img.visible;
9494

9595
item->setIcon(QIcon::fromTheme(img.visible ? "eye" : "eye-off"));
96-
emit skipChanged(img_number, img.skip);
96+
emit skipChanged(img_number);
9797
}
9898
}
9999
QListWidget::mousePressEvent(event);

relightlab/imagelist.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ class ImageList: public QListWidget {
1212
void init();
1313

1414
public slots:
15-
void setSkipped(int image, bool skip);
15+
void setSkipped(int image);
1616
void verifyItem(QListWidgetItem *item);
1717

1818
signals:
19-
void skipChanged(int image, bool skip);
19+
void skipChanged(int image);
2020

2121
protected:
2222
void mousePressEvent(QMouseEvent *event) override ;

relightlab/imageview.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ void ImageView::showImage(int id) {
4848
current_image = id;
4949
}
5050

51-
void ImageView::setSkipped(int image, bool skip) {
51+
void ImageView::setSkipped(int image) {
5252
if(image != current_image)
5353
return;
5454
}

relightlab/imageview.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,15 @@ class ImageView: public Canvas {
2222

2323
public slots:
2424
void showImage(int id);
25-
void setSkipped(int image, bool skip);
25+
void setSkipped(int image);
2626

2727
void fit(); //fit image on screen
2828
void one(); //scale to 1:1 zoom
2929
void next(); //show next image
3030
void prev(); //show previous image
3131

3232
signals:
33-
void skipChanged(int image, bool skip);
33+
void skipChanged(int image);
3434

3535
protected:
3636
QGraphicsPixmapItem *imagePixmap = nullptr;

relightlab/processqueue.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,8 @@ void ProcessQueue::removeTask(int id) {
118118

119119
queue.takeAt(index);
120120
//processqueue is never the owner!
121-
//delete task;
121+
if(!task->owned)
122+
delete task;
122123
}
123124
emit update();
124125
}

relightlab/sphereframe.cpp

+3-14
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ SphereFrame::SphereFrame(QWidget *parent): QGroupBox("Reflective spheres", paren
5151
}
5252

5353
void SphereFrame::clear() {
54-
//setVisible(false);
5554
while(spheres->count() > 0) {
5655
QLayoutItem *item = spheres->takeAt(0);
5756
SphereRow *row = dynamic_cast<SphereRow *>(item->widget());
@@ -79,6 +78,7 @@ void SphereFrame::okMarker() {
7978
qRelightApp->project().spheres.push_back(provisional_sphere);
8079
row = addSphere(provisional_sphere);
8180
}
81+
qRelightApp->project().cleanSphereCache();
8282
row->detectHighlights();
8383

8484
provisional_sphere = nullptr;
@@ -115,29 +115,18 @@ SphereRow *SphereFrame::addSphere(Sphere *sphere) {
115115
SphereRow *row = new SphereRow(sphere);
116116
spheres->addWidget(row);
117117

118-
connect(row, SIGNAL(edit(SphereRow *)), this, SLOT(editSphere(SphereRow *)));
118+
connect(row, SIGNAL(editme(SphereRow *)), this, SLOT(editSphere(SphereRow *)));
119119
connect(row, SIGNAL(removeme(SphereRow *)), this, SLOT(removeSphere(SphereRow *)));
120120
connect(row, SIGNAL(updated()), this, SIGNAL(updated()));
121121
return row;
122122
}
123123

124124
void SphereFrame::removeSphere(SphereRow *row) {
125-
row->stopDetecting();
126125

127126
layout()->removeWidget(row);
128-
129-
Sphere *sphere = row->sphere;
130-
auto &spheres = qRelightApp->project().spheres;
131-
132-
133-
auto it = std::find(spheres.begin(), spheres.end(), sphere);
134-
135-
assert(it != spheres.end());
136-
137-
delete sphere;
138127
delete row;
139128

140-
spheres.erase(it);
129+
141130
}
142131

143132
SphereRow *SphereFrame::findRow(Sphere *sphere) {

0 commit comments

Comments
 (0)