Skip to content

Commit e3f87fd

Browse files
committed
added some checks.
1 parent 3e282c1 commit e3f87fd

9 files changed

+52
-34
lines changed

relightlab/alignrow.cpp

+7
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,13 @@ void FindAlignment::run() {
3131
if(image.skip) continue;
3232

3333
QImage img(image.filename);
34+
if(img.isNull()) {
35+
mutex.lock();
36+
status = FAILED;
37+
mutex.unlock();
38+
progressed(QString("Failed loading image: %1").arg(image.filename), 100);
39+
return;
40+
}
3441
align->readThumb(img, i);
3542

3643
int progress = std::min(99, (int)(100*(i+1) / project.images.size()));

relightlab/imageview.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ void ImageView::showImage(int id) {
2626

2727
QString filename = project.images[id].filename;
2828

29-
QImage img(project.dir.filePath(filename));
29+
QImage img(filename);
3030
if(img.isNull()) {
3131
QMessageBox::critical(this, "Houston we have a problem!", "Could not load image " + filename);
3232
return;

relightlab/main.cpp

+5-2
Original file line numberDiff line numberDiff line change
@@ -10,24 +10,27 @@
1010

1111
#include <locale.h>
1212

13+
#include <iostream>
14+
using namespace std;
15+
1316
#define RELIGHT_STRINGIFY0(v) #v
1417
#define RELIGHT_STRINGIFY(v) RELIGHT_STRINGIFY0(v)
1518

1619
Project project;
1720

1821
int main(int argc, char *argv[]) {
1922

23+
2024
RelightApp app(argc, argv);
2125

2226
QApplication::setAttribute(Qt::AA_MacDontSwapCtrlAndMeta);
2327
setlocale(LC_ALL, "en_US.UTF8"); //needs to be called AFTER QApplication creation.
2428

2529
#if QT_VERSION >= 0x060000
2630
//large images wont load because of this limit!
27-
QImageReader::setAllocationLimit(uint64_t(1)<<31);
31+
QImageReader::setAllocationLimit(0);
2832
#endif
2933

30-
3134
QCoreApplication::setOrganizationName("VCG");
3235
QCoreApplication::setOrganizationDomain("vcg.isti.cnr.it");
3336
QCoreApplication::setApplicationName("RelightLab");

relightlab/relightapp.cpp

+22-25
Original file line numberDiff line numberDiff line change
@@ -227,55 +227,52 @@ void RelightApp::openProject() {
227227
}
228228

229229
void RelightApp::openProject(const QString &filename) {
230+
231+
QString current = QDir::currentPath();
232+
230233
Project *project = new Project;
231234
try {
232235
project->load(filename);
233236
} catch(QString e) {
234237
QMessageBox::critical(mainwindow, "Could not load project", e);
238+
QDir::setCurrent(current);
235239
return;
236240
}
237241

238-
QFileInfo info(filename);
239-
QDir::setCurrent(info.canonicalPath());
240-
241242
while(project->missing.size() != 0) {
242-
243-
QString msg = "Could not find this images:\n";
243+
QString msg = "Could not find these images:\n";
244244
for(int i: project->missing)
245245
msg += "\t" + project->images[i].filename + "\n";
246246

247+
if(msg.size() > 300)
248+
msg = msg.left(297) + "...";
249+
247250
QMessageBox box(mainwindow);
248251
box.setText(msg);
249252
box.setWindowTitle("Missing images");
250-
box.addButton("Ignore missing images", QMessageBox::AcceptRole);
251253
box.addButton("Select a different folder...", QMessageBox::ActionRole);
252254
box.addButton("Cancel", QMessageBox::RejectRole);
253255
int ret = box.exec();
254256

255-
switch(ret) {
256-
case 1: {
257-
QString imagefolder = QFileDialog::getExistingDirectory(mainwindow, "Could not find the images, please select the image folder:", project->dir.absolutePath());
258-
if(imagefolder.isNull()) {
259-
QMessageBox::critical(mainwindow, "No folder selected", "No folder selected.");
260-
return;
261-
}
262-
project->dir.setPath(imagefolder);
263-
QDir::setCurrent(imagefolder);
264-
project->checkMissingImages();
265-
project->checkImages();
266-
}
267-
break;
268-
case 2: //cancel
257+
if(ret == 2) {
258+
QDir::setCurrent(current);
269259
return;
270-
case 3: //ignore
271-
project->missing.clear();
272-
break;
273260
}
274-
}
275261

262+
QString imagefolder = QFileDialog::getExistingDirectory(mainwindow, "Could not find the images, please select the image folder:", project->dir.absolutePath());
263+
if(imagefolder.isNull()) {
264+
QMessageBox::critical(mainwindow, "No folder selected", "No folder selected.");
265+
QDir::setCurrent(current);
266+
return;
267+
}
268+
project->dir.setPath(imagefolder);
269+
QDir::setCurrent(imagefolder);
270+
project->checkMissingImages();
271+
project->checkImages();
272+
}
276273
qRelightApp->setProject(project);
277274

278-
project_filename = filename; //project.dir.relativeFilePath(filename);
275+
project_filename = filename;
279276
addRecentProject(filename);
280277
mainwindow->updateRecentProjectsMenu();
281278
}

relightlab/rtiframe.cpp

+9
Original file line numberDiff line numberDiff line change
@@ -123,12 +123,21 @@ void RtiFrame::exportRti() {
123123
if(answer == QMessageBox::No)
124124
return;
125125
}
126+
Dome::LightConfiguration previous = project.dome.lightConfiguration;
127+
128+
if(parameters.basis == Rti::RBF && project.dome.lightConfiguration == Dome::SPHERICAL) {
129+
QMessageBox::warning(this, "RBF limitations",
130+
"RBF basis do not support positional lights. (BLN does)\n"
131+
"Using directiona lights instead.");
132+
project.dome.lightConfiguration = Dome::DIRECTIONAL;
133+
}
126134

127135
RtiTask *rti_task = new RtiTask();
128136
try {
129137
rti_task->setProject(project);
130138
rti_task->setParameters(parameters);
131139
rti_task->output = parameters.path;
140+
project.dome.lightConfiguration = previous;
132141

133142
} catch(QString error) {
134143
QMessageBox::critical(this, "Something went wrong", error);

relightlab/sphererow.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ void DetectHighlights::run() {
3434

3535
Image &image = project.images[i];
3636

37-
QImage img(project.dir.filePath(image.filename));
37+
QImage img(image.filename);
3838
if(img.isNull()) {
3939
mutex.lock();
4040
status = FAILED;

src/imageset.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,12 @@ bool ImageSet::initFromProject(Project &project) {
6565
throw QString("Number of lights in dome needs to be equal to the number of images");
6666
}
6767
int count = 0;
68-
for(int i = 0; i < lights1.size(); i++) {
68+
for(size_t i = 0; i < lights1.size(); i++) {
6969
if(visibles[i])
7070
lights1[count++] = lights1[i];
7171
}
7272
lights1.resize(count);
73+
return true;
7374
}
7475

7576
bool ImageSet::initFromProject(QJsonObject &obj, const QString &filename) {

src/project.cpp

+4-2
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,7 @@ void Project::load(QString filename) {
254254
if(!file.open(QFile::ReadOnly))
255255
throw QString("The project file could not be opened.\nThe path might be wrong, or the file missing.");
256256

257+
257258
QJsonDocument doc = QJsonDocument::fromJson(file.readAll());
258259
QJsonObject obj = doc.object();
259260

@@ -340,16 +341,17 @@ void Project::checkMissingImages() {
340341
missing.clear();
341342
for(size_t i = 0; i < images.size(); i++) {
342343
Image &image = images[i];
343-
QFileInfo imginfo(image.filename);
344+
QFileInfo imginfo(dir.filePath(image.filename));
344345
if(!imginfo.exists()) {
345346
missing.push_back(int(i));
346-
throw "Could not find the image:\n" + image.filename + " in folder: " + dir.absolutePath();
347347
}
348348
}
349349
}
350350
void Project::checkImages() {
351351
for(Image &image:images) {
352352
QImageReader reader(image.filename);
353+
if(!reader.canRead())
354+
continue;
353355
QSize size = reader.size();
354356
image.valid = (size == imgsize);
355357
if(!image.valid) image.skip = true;

src/sphere.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,7 @@ bool inEllipse(double x, double y, double a, double b, double theta) {
196196
void Sphere::findHighlight(QImage img, int n, bool skip, bool update_positions) {
197197
if(sphereImg.isNull()) {
198198
sphereImg = QImage(inner.width(), inner.height(), QImage::Format_ARGB32);
199+
sphereImg.fill(0);
199200
}
200201

201202

@@ -230,8 +231,6 @@ void Sphere::findHighlight(QImage img, int n, bool skip, bool update_positions)
230231
float d = sqrt(cx*cx + cy*cy);
231232
if(d > smallradius) continue;
232233
}
233-
assert(x < img.width());
234-
assert(y < img.height());
235234
QRgb c = img.pixel(x, y);
236235
int g = qGray(c);
237236

0 commit comments

Comments
 (0)