Skip to content

Commit 130fb8d

Browse files
committed
fourier padding, some exception cleanup, recent project filtered
1 parent 9776163 commit 130fb8d

18 files changed

+113
-26
lines changed

relight-cli/convert_rti.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ int convertRTI(const char *file, const char *output, int quality) {
2626
rti.chromasubsampling = lrti.chromasubsampled;
2727
switch(lrti.type) {
2828
case LRti::UNKNOWN:
29-
throw "Unknown RTI type!\n";
29+
throw QString("Unknown RTI type!\n");
3030
return 1;
3131
case LRti::PTM_LRGB:
3232
rti.type = Rti::PTM;
@@ -76,7 +76,7 @@ int convertRTI(const char *file, const char *output, int quality) {
7676
if(!dir.exists()) {
7777
QDir here("./");
7878
if(!here.mkdir(output))
79-
throw "Could not create output dir!\n";
79+
throw QString("Could not create output dir!\n");
8080
}
8181

8282
rti.saveJSON(dir, quality);

relight-cli/rtibuilder.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ MaterialBuilder RtiBuilder::pickBasePCA(PixelArray &sample) {
231231

232232
if(callback)
233233
if(!(*callback)("Computing PCA:", 0))
234-
throw std::string("Cancelled.");
234+
throw QString("Cancelled.");
235235

236236
if(colorspace == MRGB) {
237237
uint32_t dim = sample.components()*3;
@@ -255,7 +255,7 @@ MaterialBuilder RtiBuilder::pickBasePCA(PixelArray &sample) {
255255
d /= nsamples;
256256

257257
if(callback && !(*callback)("Computing PCA:", 5))
258-
throw std::string("Cancelled.");
258+
throw QString("Cancelled.");
259259

260260
for(uint32_t i = 0; i < sample.size(); i++) {
261261
Pixel &pixel = sample[i];
@@ -269,7 +269,7 @@ MaterialBuilder RtiBuilder::pickBasePCA(PixelArray &sample) {
269269
}
270270

271271
if(callback && !(*callback)("Computing PCA:", 10))
272-
throw std::string("Cancelled.");
272+
throw QString("Cancelled.");
273273

274274
pca.solve(nplanes);
275275

@@ -349,7 +349,7 @@ MaterialBuilder RtiBuilder::pickBasePCA(PixelArray &sample) {
349349

350350

351351
if(callback && !(*callback)("Computing PCA:", 100*component/3))
352-
throw std::string("Cancelled.");
352+
throw QString("Cancelled.");
353353
}
354354
}
355355
//normalize coeffs
@@ -366,7 +366,7 @@ MaterialBuilder RtiBuilder::pickBasePCA(PixelArray &sample) {
366366
}
367367

368368
if(callback && !(*callback)("Computing PCA:", 100))
369-
throw std::string("Cancelled.");
369+
throw QString("Cancelled.");
370370
return mat;
371371
}
372372

relight/mainwindow.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -234,8 +234,9 @@ void MainWindow::openProject() {
234234
project.clear();
235235
try {
236236
project.load(filename);
237-
} catch(QString e) {
238-
QMessageBox::critical(this, "Could not load the project: " + filename, "Error: " + e);
237+
} catch(Error err) {
238+
//TODO replace with something that can display help
239+
QMessageBox::critical(this, err.title, err.text);
239240
return;
240241
}
241242
project_filename = filename; //project.dir.relativeFilePath(filename);

relight/relight.pro

+4-2
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,8 @@ SOURCES += main.cpp \
8181
convertdialog.cpp \
8282
aligndialog.cpp \
8383
zoomdialog.cpp \
84-
zoomtask.cpp
84+
zoomtask.cpp \
85+
error.cpp
8586

8687

8788

@@ -141,7 +142,8 @@ HEADERS += \
141142
zoom.h \
142143
zoomdialog.h \
143144
zoomtask.h \
144-
../src/deepzoom.h
145+
../src/deepzoom.h \
146+
error.h
145147

146148
FORMS += \
147149
dstretchdialog.ui \

relightlab/cropframe.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ void CropFrame::init() {
125125
int count = 0;
126126
while(project.images[count].skip == true) {
127127
count++;
128-
if(count >= project.images.size())
128+
if(size_t(count) >= project.images.size())
129129
break;
130130
filename = project.images[count].filename;
131131
}

relightlab/homeframe.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ HomeFrame::HomeFrame() {
4444
leftColumnLayout->addSpacing(20);
4545
leftColumnLayout->addWidget(recentLabel);
4646

47-
47+
cleanRecentProjects();
4848
for(QString path: recentProjects()) {
4949
QFileInfo fileInfo(path);
5050
QString filename = fileInfo.fileName();

relightlab/imagelist.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ void ImageList::verifyItem(QListWidgetItem *item) {
2525
bool skip = item->checkState() != Qt::Checked;
2626

2727
Project &project = qRelightApp->project();
28-
assert(img_number >= 0 && img_number < project.images.size());
28+
assert(img_number >= 0 && size_t(img_number) < project.images.size());
2929

3030
project.images[img_number].skip = skip;
3131

relightlab/normalstask.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,8 @@ void NormalsTask::run() {
199199
assm(filename, normals, parameters.assm_error);
200200

201201
} else if(parameters.surface_integration == SURFACE_BNI || parameters.surface_integration == SURFACE_FFT) {
202-
bool proceed = progressed("Bilateral normal integration...", 0);
202+
QString type = parameters.surface_integration == SURFACE_BNI ? "Bilateral" : "Fourier";
203+
bool proceed = progressed(type + " normal integration...", 0);
203204
if(!proceed)
204205
return;
205206

relightlab/normalstask.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class NormalsParameters {
2323
NormalSolver solver = NORMALS_L2;
2424

2525
FlatMethod flatMethod = FLAT_NONE;
26-
double flatPercentage = 50;
26+
double flatPercentage = 20;
2727

2828

2929
SurfaceIntegration surface_integration = SURFACE_NONE;

relightlab/recentprojects.cpp

+22
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#include <QVariant>
33
#include <QMap>
44
#include <QList>
5+
#include <QFileInfo>
56
#include "recentprojects.h"
67

78
QStringList recentProjects() {
@@ -23,3 +24,24 @@ void clearRecentProjects() {
2324
}
2425

2526

27+
void removeRecentProject(const QString &filename) {
28+
QStringList recents = recentProjects();
29+
int index = recents.indexOf(filename);
30+
if (index != -1) { // String found in the list
31+
recents.removeAt(index); // Remove the string from its current position
32+
}
33+
QSettings().setValue("recent-projects", recents);
34+
}
35+
36+
void cleanRecentProjects() {
37+
QStringList recents = recentProjects();
38+
QStringList valid;
39+
for(QString path: recents) {
40+
QFileInfo info(path);
41+
if(info.exists())
42+
valid.push_back(path);
43+
}
44+
if(recents.size() != valid.size())
45+
QSettings().setValue("recent-projects", valid);
46+
}
47+

relightlab/recentprojects.h

+2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

66
QStringList recentProjects();
77
void addRecentProject(const QString &filename);
8+
void removeRecentProject(const QString &filename);
9+
void cleanRecentProjects(); //removes missing projects
810
void clearRecentProjects();
911

1012
#endif // RECENTPROJECTS_H

relightlab/relightapp.cpp

+7-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include "recentprojects.h"
55
#include "mainwindow.h"
66
#include "preferences.h"
7+
#include "../src/error.h"
78

89
#include <QMessageBox>
910
#include <QFileDialog>
@@ -228,7 +229,7 @@ void RelightApp::openProject(const QString &filename) {
228229
try {
229230
project.load(filename);
230231
} catch(QString e) {
231-
QMessageBox::critical(mainwindow, "Could not load the project: " + filename, "Error: " + e);
232+
QMessageBox::critical(mainwindow, "Could not load project", e);
232233
return;
233234
}
234235

@@ -325,9 +326,13 @@ void RelightApp::loadThumbnails() {
325326
Image &image = m_project.images[i];
326327
if(i == 0) {
327328
QImage img(image.filename);
329+
if(img.isNull()) {
330+
img = QImage(256, 256, QImage::Format_ARGB32);
331+
img.fill(Qt::black);
332+
}
328333
m_thumbnails[i] = img.scaledToHeight(256);
329334
} else {
330-
QImage img(m_thumbnails[0].size().scaled(2560, 256, Qt::KeepAspectRatio), QImage::Format_ARGB32);
335+
QImage img(m_thumbnails[0].size().scaled(256, 256, Qt::KeepAspectRatio), QImage::Format_ARGB32);
331336
img.fill(Qt::black);
332337
m_thumbnails[i] = img;
333338
paths.push_back(image.filename);

relightlab/sphererow.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ void SphereRow::remove() {
101101
emit removeme(this);
102102
}
103103

104-
void SphereRow::updateStatus(QString msg, int percent) {
104+
void SphereRow::updateStatus(QString /*msg*/, int percent) {
105105
// status->setText(msg);
106106
progress->setValue(percent);
107107
reflections->update();

src/error.cpp

Whitespace-only changes.

src/error.h

Whitespace-only changes.

src/fft_normal_integration.cpp

+55
Original file line numberDiff line numberDiff line change
@@ -103,10 +103,63 @@ void ifft2(const ComplexMatrix& input, MatrixXd& output) {
103103
}
104104
}
105105

106+
void pad(int &w, int &h, std::vector<float> &normals, int padding) {
107+
int W = w + padding;
108+
int H = h + padding;
109+
std::vector<float> n(W*H*3);
110+
for(int y = 0; y < H; y++) {
111+
for(int x = 0; x < W; x++) {
112+
int X = x - padding;
113+
int Y = y - padding;
114+
if(x < padding) {
115+
X = padding -x;
116+
}
117+
118+
if(x >= w + padding) {
119+
X = 2*w + padding - 1 - x;
120+
}
121+
122+
if(y < padding) {
123+
Y = padding - y;
124+
}
125+
126+
if(y >= h + padding) {
127+
Y = 2*h + padding - 1 - y;
128+
Y = H - padding + h - 1 -y;
129+
}
130+
for(int k = 0; k < 3; k++)
131+
n[3*(x + y*W) + k] = normals[3*(X + Y*w) + k];
132+
assert(!isnan(n[x + y*W]));
133+
}
134+
}
135+
w = W;
136+
h = H;
137+
swap(normals, n);
138+
}
139+
140+
void depad(int &w, int &h, std::vector<float> &heights, int padding) {
141+
142+
int W = w;
143+
int H = h;
144+
w -= padding;
145+
h -= padding;
146+
std::vector<float> elev(w*h);
147+
for(int y = 0; y < h; y++) {
148+
for(int x = 0; x < w; x++) {
149+
elev[x + w*y] = heights[x + padding + (y + padding)*W];
150+
}
151+
}
152+
swap(elev, heights);
153+
}
154+
106155
void fft_integrate(std::function<bool(QString s, int n)> progressed,
107156
int cols, int rows, std::vector<float> &normals, std::vector<float> &heights) {
108157

109158

159+
int minsize = std::min(cols, rows);
160+
int padding = minsize/4;
161+
pad(cols, rows, normals, padding);
162+
110163

111164
MatrixXd dzdx(rows, cols);
112165
MatrixXd dzdy(rows, cols);
@@ -152,6 +205,8 @@ void fft_integrate(std::function<bool(QString s, int n)> progressed,
152205
}
153206
}
154207

208+
depad(cols, rows, heights, padding);
209+
155210
/*
156211
[wx, wy] = meshgrid(([1:cols]-(fix(cols/2)+1))/(cols-mod(cols,2)), ...
157212
([1:rows]-(fix(rows/2)+1))/(rows-mod(rows,2)));

src/project.cpp

+4-5
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ void Project::rotateImages() {
275275
void Project::load(QString filename) {
276276
QFile file(filename);
277277
if(!file.open(QFile::ReadOnly))
278-
throw QString("Failed opening: " + filename);
278+
throw QString("The project file could not be opened.\nThe path might be wrong, or the file missing.");
279279

280280
QJsonDocument doc = QJsonDocument::fromJson(file.readAll());
281281
QJsonObject obj = doc.object();
@@ -293,14 +293,14 @@ void Project::load(QString filename) {
293293
imgsize.setWidth(obj["width"].toInt());
294294
imgsize.setHeight(obj["height"].toInt());
295295
if(!imgsize.isValid())
296-
throw "Missing or invalid width and/or height.";
296+
throw QString("Missing or invalid width and/or height in project.");
297297

298298
QFileInfo info(filename);
299299
QDir folder = info.dir();
300300
folder.cd(obj["folder"].toString());
301301

302302
if(!setDir(folder))
303-
throw(QString("Can't load a project without a valid folder"));
303+
throw QString("The folder " + obj["folder"].toString() + " does not exists.");
304304

305305
lens.fromJson(obj["lens"].toObject());
306306
lens.width = imgsize.width();
@@ -365,8 +365,7 @@ void Project::checkMissingImages() {
365365
QFileInfo imginfo(image.filename);
366366
if(!imginfo.exists()) {
367367
missing.push_back(int(i));
368-
//throw QString("Could not find the image: " + image.filename) + " in folder: " + dir.absolutePath();
369-
continue;
368+
throw "Could not find the image:\n" + image.filename + " in folder: " + dir.absolutePath();
370369
}
371370
}
372371
}

src/project.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ class Project {
5858

5959
void clear();
6060
void load(QString filename);
61-
void save(QString filename); //throws QString on error
62-
void saveLP(QString filename, std::vector<Eigen::Vector3f> &directions); //throws QString on error
61+
void save(QString filename);
62+
void saveLP(QString filename, std::vector<Eigen::Vector3f> &directions);
6363
void loadLP(QString filename);
6464
void computeDirections();
6565
void computePixelSize();

0 commit comments

Comments
 (0)