Skip to content

Commit 24c5da1

Browse files
committed
dealing with disabled images
1 parent 4e2d11f commit 24c5da1

12 files changed

+98
-102
lines changed

relightlab/lightgeometry.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ void LightsGeometry::setFromSpheres() {
139139
//call appropriate compute directions/positions
140140
Dome &dome = project.dome;
141141
dome.label = "";
142-
dome.fromSpheres(project.spheres, project.lens);
142+
dome.fromSpheres(project.images, project.spheres, project.lens);
143143

144144
init();
145145
}

relightlab/relightapp.cpp

+31-28
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ RelightApp::RelightApp(int &argc, char **argv): QApplication(argc, argv) {
118118
systemTray->setVisible(false);
119119
}
120120

121+
m_project = new Project;
121122

122123
}
123124
void RelightApp::notify(const QString &title, const QString &msg, int ms) {
@@ -148,16 +149,18 @@ void RelightApp::setDarkTheme(bool dark) {
148149
QSettings().setValue("dark", dark);
149150
}
150151

151-
void RelightApp::setProject(const Project &_project) {
152+
void RelightApp::setProject(Project *_project) {
152153
//cleanup interface and stop (and remove) project related tasks.
153154
mainwindow->clear();
154155

156+
delete m_project;
157+
155158
m_project = _project;
156159
loadThumbnails();
157160

158161
mainwindow->init();
159162
mainwindow->setTabIndex(1);
160-
qRelightApp->setLastProjectDir(m_project.dir.path());
163+
qRelightApp->setLastProjectDir(m_project->dir.path());
161164
qRelightApp->clearLastOutputDir();
162165
}
163166

@@ -169,28 +172,28 @@ void RelightApp::newProject() {
169172
if(dir.isNull()) return;
170173

171174

172-
Project project;
173-
project.setDir(QDir(dir));
174-
bool ok = project.scanDir();
175-
if(!project.size()) {
176-
QMessageBox::critical(mainwindow, "Houston we have a problem!", "Could not find images in directory: " + project.dir.path());
175+
Project *project = new Project;
176+
project->setDir(QDir(dir));
177+
bool ok = project->scanDir();
178+
if(!project->size()) {
179+
QMessageBox::critical(mainwindow, "Houston we have a problem!", "Could not find images in directory: " + project->dir.path());
177180
return;
178181
}
179182

180183
if(!ok) {
181184
//check if we can rotate a few images.
182185
bool canrotate = false;
183-
for(Image &image: project.images) {
184-
if(image.size == project.imgsize)
186+
for(Image &image: project->images) {
187+
if(image.size == project->imgsize)
185188
continue;
186189

187-
if(image.isRotated(project.imgsize))
190+
if(image.isRotated(project->imgsize))
188191
canrotate = true;
189192
}
190193
if(canrotate) {
191194
int answer = QMessageBox::question(mainwindow, "Some images are rotated.", "Do you wish to uniform image rotation?", QMessageBox::Yes, QMessageBox::No);
192195
if(answer != QMessageBox::No)
193-
project.rotateImages();
196+
project->rotateImages();
194197
} else
195198
QMessageBox::critical(mainwindow, "Resolution problem", "Not all of the images in the folder have the same resolution,\nyou might need to fix this problem manually.");
196199
}
@@ -206,7 +209,7 @@ void RelightApp::newProject() {
206209
int answer = QMessageBox::question(mainwindow, "Found an .lp file: " + lps[0], "Do you wish to load " + lps[0] + "?", QMessageBox::Yes, QMessageBox::No);
207210
if(answer != QMessageBox::No) {
208211
try {
209-
m_project.loadLP(lps[0]);
212+
m_project->loadLP(lps[0]);
210213
} catch(QString error) {
211214
QMessageBox::critical(mainwindow, "Could not load the .lp file", error);
212215
}
@@ -224,9 +227,9 @@ void RelightApp::openProject() {
224227
}
225228

226229
void RelightApp::openProject(const QString &filename) {
227-
Project project;
230+
Project *project = new Project;
228231
try {
229-
project.load(filename);
232+
project->load(filename);
230233
} catch(QString e) {
231234
QMessageBox::critical(mainwindow, "Could not load project", e);
232235
return;
@@ -235,11 +238,11 @@ void RelightApp::openProject(const QString &filename) {
235238
QFileInfo info(filename);
236239
QDir::setCurrent(info.canonicalPath());
237240

238-
while(project.missing.size() != 0) {
241+
while(project->missing.size() != 0) {
239242

240243
QString msg = "Could not find this images:\n";
241-
for(int i: project.missing)
242-
msg += "\t" + project.images[i].filename + "\n";
244+
for(int i: project->missing)
245+
msg += "\t" + project->images[i].filename + "\n";
243246

244247
QMessageBox box(mainwindow);
245248
box.setText(msg);
@@ -251,21 +254,21 @@ void RelightApp::openProject(const QString &filename) {
251254

252255
switch(ret) {
253256
case 1: {
254-
QString imagefolder = QFileDialog::getExistingDirectory(mainwindow, "Could not find the images, please select the image folder:", project.dir.absolutePath());
257+
QString imagefolder = QFileDialog::getExistingDirectory(mainwindow, "Could not find the images, please select the image folder:", project->dir.absolutePath());
255258
if(imagefolder.isNull()) {
256259
QMessageBox::critical(mainwindow, "No folder selected", "No folder selected.");
257260
return;
258261
}
259-
project.dir.setPath(imagefolder);
262+
project->dir.setPath(imagefolder);
260263
QDir::setCurrent(imagefolder);
261-
project.checkMissingImages();
262-
project.checkImages();
264+
project->checkMissingImages();
265+
project->checkImages();
263266
}
264267
break;
265268
case 2: //cancel
266269
return;
267270
case 3: //ignore
268-
project.missing.clear();
271+
project->missing.clear();
269272
break;
270273
}
271274
}
@@ -288,7 +291,7 @@ void RelightApp::saveProject() {
288291
project_filename = filename;
289292
}
290293

291-
m_project.save(project_filename);
294+
m_project->save(project_filename);
292295

293296
QFileInfo info(project_filename);
294297
mainwindow->setWindowTitle("Relight - " + info.fileName());
@@ -304,7 +307,7 @@ void RelightApp::saveProjectAs() {
304307
filename += ".relight";
305308
project_filename = filename;
306309

307-
m_project.save(project_filename);
310+
m_project->save(project_filename);
308311
QFileInfo info(project_filename);
309312
mainwindow->setWindowTitle("Relight - " + info.fileName());
310313
addRecentProject(project_filename);
@@ -319,10 +322,10 @@ void RelightApp::loadThumbnails() {
319322
delete loader;
320323
loader = nullptr;
321324
}
322-
m_thumbnails.resize(m_project.images.size());
325+
m_thumbnails.resize(m_project->images.size());
323326
QStringList paths;
324-
for(size_t i = 0; i < m_project.images.size(); i++) {
325-
Image &image = m_project.images[i];
327+
for(size_t i = 0; i < m_project->images.size(); i++) {
328+
Image &image = m_project->images[i];
326329
if(i == 0) {
327330
QImage img(image.filename);
328331
if(img.isNull()) {
@@ -399,7 +402,7 @@ void RelightApp::close() {
399402

400403

401404
bool RelightApp::needsSavingProceed() {
402-
if(!m_project.needs_saving)
405+
if(!m_project->needs_saving)
403406
return true;
404407
auto answer = QMessageBox::question(mainwindow, "Current project is unsaved", "Do you want to proceed without saving?");
405408
return answer == QMessageBox::Yes;

relightlab/relightapp.h

+5-5
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ class ThumbailLoader: public QThread {
5353
class RelightApp: public QApplication {
5454
Q_OBJECT
5555
public:
56-
Project m_project;
56+
Project *m_project = nullptr;
5757
std::vector<QImage> m_thumbnails;
5858

5959
QMap<QString, QAction *> actions;
@@ -62,7 +62,7 @@ class RelightApp: public QApplication {
6262
QSystemTrayIcon *systemTray = nullptr;
6363

6464
RelightApp(int &argc, char **argv);
65-
virtual ~RelightApp() {}
65+
virtual ~RelightApp() { delete m_project; }
6666
void run();
6767

6868
public slots:
@@ -81,8 +81,8 @@ public slots:
8181
void updateThumbnail(int pos);
8282

8383
public:
84-
void setProject(const Project &project);
85-
Project &project() { return m_project; }
84+
void setProject(Project *project);
85+
Project &project() { return *m_project; }
8686

8787
QMutex thumbails_lock;
8888
std::vector<QImage> &thumbnails() { return m_thumbnails; }
@@ -99,7 +99,7 @@ public slots:
9999
QString lastOutputDir() {
100100
if(!last_output_dir.isEmpty())
101101
return last_output_dir;
102-
QDir out = m_project.dir;
102+
QDir out = m_project->dir;
103103
out.cdUp();
104104
return out.absolutePath();
105105
}

relightlab/spherepanel.cpp

-2
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ void SpherePanel::clear() {
4545

4646
void SpherePanel::init() {
4747
auto &project_spheres = qRelightApp->project().spheres;
48-
//setVisible(project_spheres.size() > 0);
4948
for(Sphere *sphere: project_spheres) {
5049
sphere->fit();
5150
SphereRow * row = addSphere(sphere);
@@ -58,7 +57,6 @@ void SpherePanel::newSphere() {
5857
if(!sphere_dialog)
5958
sphere_dialog = new SphereDialog(this);
6059

61-
//TODO ACTUALLY images might be skipped!
6260
Sphere *sphere = new Sphere(qRelightApp->project().images.size());
6361
sphere_dialog->setSphere(sphere);
6462
int answer = sphere_dialog->exec();

relightlab/sphererow.cpp

+5-4
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,16 @@ void DetectHighlights::run() {
2424
status = RUNNING;
2525
mutex.unlock();
2626

27+
sphere->sphereImg.fill(0);
28+
sphere->thumbs.clear();
29+
2730
Project &project = qRelightApp->project();
2831
for(size_t i = 0; i < project.images.size(); i++) {
2932

3033
Image &image = project.images[i];
31-
if(image.skip) continue;
3234

3335
QImage img(image.filename);
34-
sphere->findHighlight(img, i, update_positions);
36+
sphere->findHighlight(img, i, image.skip, update_positions);
3537

3638
int progress = std::min(99, (int)(100*(i+1) / project.images.size()));
3739
progressed(QString("Detecting highlights"), progress);
@@ -128,11 +130,10 @@ void SphereRow::updateStatus(QString /*msg*/, int percent) {
128130

129131
void SphereRow::detectHighlights(bool update) {
130132

131-
132133
if(sphere->center.isNull()) {
133-
// status->setText("Needs at least 3 points.");
134134
return;
135135
}
136+
//look for cached data.
136137
verify_button->setEnabled(false);
137138
if(!detect_highlights) {
138139
detect_highlights = new DetectHighlights(sphere, update);

relightlab/sphererow.h

+1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ class SphereRow: public QWidget {
3535
QPushButton *verify_button = nullptr;
3636
DetectHighlights *detect_highlights = nullptr;
3737

38+
3839
SphereRow(Sphere *sphere, QWidget *parent = nullptr);
3940
virtual ~SphereRow();
4041
void detectHighlights(bool update = true);

src/dome.cpp

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include "dome.h"
2+
#include "image.h"
23
#include "sphere.h"
34
#include "lens.h"
45
#include "lp.h"
@@ -56,17 +57,17 @@ void Dome::updateSphereDirections() {
5657
positions3d = positionsSphere;
5758
}
5859

59-
void Dome::fromSpheres(std::vector<Sphere *> &spheres, Lens &lens) {
60+
void Dome::fromSpheres(std::vector<Image> &images, std::vector<Sphere *> &spheres, Lens &lens) {
6061
switch(lightConfiguration) {
6162
case Dome::DIRECTIONAL:
62-
computeDirections(spheres, lens, directions);
63+
computeDirections(images, spheres, lens, directions);
6364
break;
6465
case Dome::SPHERICAL:
65-
computeDirections(spheres, lens, directions);
66+
computeDirections(images, spheres, lens, directions);
6667
updateSphereDirections();
6768
break;
6869
case Dome::LIGHTS3D:
69-
computeParallaxPositions(spheres, lens, positions3d);
70+
computeParallaxPositions(images, spheres, lens, positions3d);
7071
directions = positions3d;
7172
for(size_t i = 0; i < directions.size(); i++) {
7273
float len = directions[i].norm();

src/dome.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include <QString>
99

1010
class QJsonObject;
11+
class Image;
1112
class Lens;
1213
class Sphere;
1314

@@ -46,7 +47,7 @@ class Dome {
4647

4748
Dome();
4849
Dome(const QString &filename) { load(filename); }
49-
void fromSpheres(std::vector<Sphere *> &spheres, Lens &lens);
50+
void fromSpheres(std::vector<Image> &images, std::vector<Sphere *> &spheres, Lens &lens);
5051
void updateSphereDirections();
5152
void parseLP(const QString &lp_path);
5253
//TODO: move savelp here from project

0 commit comments

Comments
 (0)