Skip to content

Commit 75b7aaa

Browse files
committed
replaced custom Vector3f implementation with Eigen.
1 parent e2a753e commit 75b7aaa

35 files changed

+184
-132
lines changed

relight-cli/rtibuilder.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,10 @@
2727

2828
#include <set>
2929
#include <iostream>
30-
3130
#include <math.h>
31+
3232
using namespace std;
33+
using namespace Eigen;
3334

3435
/* reampling model:
3536
*

relight-cli/rtibuilder.h

+7-6
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include "../src/rti.h"
77
#include "../src/imageset.h"
88
#include "../src/material.h"
9+
#include "../src/relight_vector.h"
910

1011
#include <Eigen/Core>
1112

@@ -65,17 +66,17 @@ class RtiBuilder: public Rti {
6566

6667
//TODO this should go inimageset!
6768
//compute the 3d lights relative to the pixel x, y
68-
std::vector<Vector3f> relativeNormalizedLights(int x, int y);
69+
std::vector<Eigen::Vector3f> relativeNormalizedLights(int x, int y);
6970

7071
void resamplePixel(Pixel &sample, Pixel &pixel);
7172

72-
void buildResampleMap(std::vector<Vector3f> &lights, std::vector<std::vector<std::pair<int, float> > > &remap);
73+
void buildResampleMap(std::vector<Eigen::Vector3f> &lights, std::vector<std::vector<std::pair<int, float> > > &remap);
7374
void buildResampleMaps();
7475
void remapPixel(Pixel &sample, Pixel &pixel, Resamplemap &resamplemap, float weight);
7576

7677

7778

78-
MaterialBuilder pickBase(PixelArray &sample, std::vector<Vector3f> &lights);
79+
MaterialBuilder pickBase(PixelArray &sample, std::vector<Eigen::Vector3f> &lights);
7980
//use for 3d lights
8081
void pickBases(PixelArray &sample);
8182
//PTM or HSH + bad light sampling could overestimate, here histogram is renormalized.
@@ -92,10 +93,10 @@ class RtiBuilder: public Rti {
9293
void getPixelBestMaterial(PixelArray &pixels, std::vector<size_t> &indices);
9394

9495
MaterialBuilder pickBasePCA(PixelArray &sample);
95-
MaterialBuilder pickBasePTM(std::vector<Vector3f> &lights);
96-
MaterialBuilder pickBaseHSH(std::vector<Vector3f> &lights, Type base = HSH);
96+
MaterialBuilder pickBasePTM(std::vector<Eigen::Vector3f> &lights);
97+
MaterialBuilder pickBaseHSH(std::vector<Eigen::Vector3f> &lights, Type base = HSH);
9798

98-
Vector3f getNormalThreeLights(std::vector<float> &pri); //use 3 virtual lights at 45 degs.
99+
Eigen::Vector3f getNormalThreeLights(std::vector<float> &pri); //use 3 virtual lights at 45 degs.
99100

100101
//DEBUG
101102

relight-merge/relight-merge.pro

+5-3
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,14 @@ DEFINES += QT_DEPRECATED_WARNINGS
1313
# You can also select to disable deprecated APIs only up to a certain version of Qt.
1414
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
1515

16+
win32:INCLUDEPATH += ../external/libjpeg-turbo-2.0.6/include \
17+
../external/eigen-3.3.9/ \
18+
../src/
19+
win32:LIBS += ../external/libjpeg-turbo-2.0.6/lib/jpeg-static.lib
1620

17-
win32:INCLUDEPATH += ../libjpeg/include
18-
win32:LIBS += ../libjpeg/lib/jpeg.lib
1921

2022
unix:INCLUDEPATH += /usr/include/eigen3 /usr/include/python3.6m
21-
#unix:LIBS += -ljpeg -liomp5
23+
unix:LIBS += -ljpeg -liomp5
2224
#unix:QMAKE_CXXFLAGS += -fopenmp
2325

2426
mac:INCLUDEPATH += /opt/homebrew/opt/jpeg-turbo/include \

relight/history.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
#include "history.h"
22

3-
void History::push(const Action &action) {
3+
void History::push(const Event &action) {
44
current_action++;
55
resize(current_action);
66
push_back(action);
77
}
88

9-
Action History::undo() {
9+
Event History::undo() {
1010
if(current_action == -1)
11-
return Action();
11+
return Event();
1212
return (*this)[current_action--];
1313
}
1414

15-
Action History::redo() {
15+
Event History::redo() {
1616
if(current_action >= (int)size())
17-
return Action();
17+
return Event();
1818
return (*this)[current_action++];
1919
}

relight/history.h

+9-7
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,25 @@
66

77
#include "../src/sphere.h"
88

9-
class Action {
9+
10+
class Event {
1011
public:
1112
enum Type { NO_ACTION, ADD_SPHERE, REMOVE_SPHERE, ADD_BORDER, REMOVE_BORDER, MOVE_BORDER, ENABLE_IMAGE, DISABLE_IMAGE};
1213
Type type = NO_ACTION;
1314
int sphere_id = -1; //which sphere was removed
1415
Sphere sphere; //when a sphere is modified or removed.
1516

16-
Action() {}
17-
Action(Type t, int id, Sphere &sp): type(t), sphere_id(id), sphere(sp) {}
17+
Event() {}
18+
Event(Type t, int id, Sphere &sp): type(t), sphere_id(id), sphere(sp) {}
1819
};
1920

20-
class History: std::vector<Action> {
21+
22+
class History: std::vector<Event> {
2123
public:
2224
int current_action = -1;
23-
void push(const Action &action);
24-
Action undo();
25-
Action redo();
25+
void push(const Event &event);
26+
Event undo();
27+
Event redo();
2628
};
2729

2830
#endif // HISTORY_H

relight/mainwindow.cpp

+12-8
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@
3434
#include <set>
3535
#include <iostream>
3636
#include <assert.h>
37+
3738
using namespace std;
39+
using namespace Eigen;
3840

3941
MainWindow::MainWindow(QWidget *parent) :
4042
QMainWindow(parent),
@@ -310,10 +312,10 @@ void MainWindow::esc() {
310312
}
311313

312314
void MainWindow::undo(){
313-
Action action = history.undo();
315+
Event action = history.undo();
314316
switch(action.type) {
315-
case Action::NO_ACTION: return;
316-
case Action::ADD_SPHERE: { //a sphere was added: remove it.
317+
case Event::NO_ACTION: return;
318+
case Event::ADD_SPHERE: { //a sphere was added: remove it.
317319
assert(action.sphere_id >= 0 && action.sphere_id < (int)project.spheres.size());
318320
Sphere *sphere = project.spheres[action.sphere_id];
319321
auto markers = ui->markerList->getItems();
@@ -329,12 +331,14 @@ void MainWindow::undo(){
329331
delete sphere;
330332
}
331333
break;
334+
default:
335+
break;
332336
}
333337
}
334338

335339
void MainWindow::redo() {
336-
Action action = history.redo();
337-
if(action.type == Action::NO_ACTION)
340+
Event action = history.redo();
341+
if(action.type == Event::NO_ACTION)
338342
return;
339343

340344
}
@@ -564,7 +568,7 @@ void MainWindow::updateBorderPoints(QGraphicsEllipseItem *point) {
564568
m->fit();
565569
int sphere_id = project.indexOf(m->sphere);
566570
assert(sphere_id != -1);
567-
history.push(Action(Action::MOVE_BORDER, sphere_id, *(m->sphere)));
571+
history.push(Event(Event::MOVE_BORDER, sphere_id, *(m->sphere)));
568572
}
569573
}
570574

@@ -598,7 +602,7 @@ void MainWindow::newSphere() {
598602
ui->markerList->setSelected(marker);
599603
connect(marker, SIGNAL(removed()), this, SLOT(removeSphere()));
600604
marker->setEditing(true);
601-
history.push(Action(Action::ADD_SPHERE, project.indexOf(sphere), *sphere));
605+
history.push(Event(Event::ADD_SPHERE, project.indexOf(sphere), *sphere));
602606
}
603607

604608

@@ -640,7 +644,7 @@ void MainWindow::newWhite() {
640644
void MainWindow::removeSphere() {
641645
auto marker = dynamic_cast<SphereMarker *>(QObject::sender());
642646
int sphere_id = project.indexOf(marker->sphere);
643-
history.push(Action(Action::REMOVE_SPHERE, sphere_id, *(marker->sphere)));
647+
history.push(Event(Event::REMOVE_SPHERE, sphere_id, *(marker->sphere)));
644648
project.spheres.erase(std::remove(project.spheres.begin(), project.spheres.end(), marker->sphere), project.spheres.end());
645649
delete marker;
646650
}

relight/normalstask.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include <time.h>
2020

2121
using namespace std;
22+
using namespace Eigen;
2223

2324
//////////////////////////////////////////////////////// NORMALS TASK //////////////////////////////////////////////////////////
2425
/// \brief NormalsTask: Takes care of creating the normals from the images given in a folder (inputFolder) and saves the file

relight/normalstask.h

+8-5
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,20 @@
33

44
#endif // NORMALSTASK_H
55

6+
#include "task.h"
7+
#include "../src/imageset.h"
8+
#include "../src/project.h"
9+
610

7-
#include <string>
811
#include <QJsonObject>
912
#include <QMutex>
1013
#include <QRect>
11-
#include "../src/relight_vector.h"
12-
#include "../src/imageset.h"
13-
#include "../src/project.h"
14-
#include "task.h"
1514
#include <QRunnable>
1615

16+
#include <string>
17+
18+
#include <Eigen/Core>
19+
1720
enum NormalSolver { NORMALS_L2, NORMALS_SBL, NORMALS_RPCA };
1821
enum FlatMethod { NONE, RADIAL, FOURIER };
1922

relight/rtiexport.h

+8-5
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
#ifndef RTIEXPORT_H
22
#define RTIEXPORT_H
33

4-
#include <QDialog>
5-
#include <map>
6-
#include <QFutureWatcher>
7-
84
#include "httpserver.h"
95
#include "../src/relight_vector.h"
106
#include "../src/project.h"
117

8+
#include <QDialog>
9+
#include <QFutureWatcher>
10+
11+
#include <Eigen/Core>
12+
#include <map>
13+
14+
1215
namespace Ui {
1316
class RtiExport;
1417
}
@@ -25,7 +28,7 @@ class RtiExport : public QDialog
2528

2629
Project *project = nullptr;
2730
QStringList images;
28-
std::vector<Vector3f> lights;
31+
std::vector<Eigen::Vector3f> lights;
2932
bool light3d = false;
3033
float pixelSize = 0;
3134
QRect crop;

relight/rtitask.cpp

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
#include "rtitask.h"
2+
#include "zoom.h"
3+
#include "dstretch.h"
4+
#include "../src/rti.h"
5+
#include "../relight-cli/rtibuilder.h"
6+
17
#include <QDebug>
28
#include <QFileInfo>
39
#include <QFile>
@@ -7,15 +13,9 @@
713
#include <QRect>
814
#include <QTemporaryDir>
915

10-
#include "rtitask.h"
11-
#include "zoom.h"
12-
#include "dstretch.h"
13-
#include "../src/rti.h"
14-
#include "../relight-cli/rtibuilder.h"
15-
16-
1716
#include <iostream>
1817
using namespace std;
18+
using namespace Eigen;
1919

2020
int convertToRTI(const char *filename, const char *output);
2121
int convertRTI(const char *file, const char *output, int quality);

relight/scripts.cpp

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#include "scripts.h"
2+
13
#include <QFile>
24
#include <QFileDialog>
35
#include <QSettings>
@@ -8,10 +10,12 @@
810
#include <QJsonObject>
911

1012
#include <iostream>
13+
1114
using namespace std;
15+
using namespace Eigen;
16+
1217

1318

14-
#include "scripts.h"
1519

1620
Scripts::Scripts() {}
1721

relight/scripts.h

+3-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
#include <QStringList>
55
#include <QRect>
66
#include <vector>
7-
#include "../src/relight_vector.h"
7+
8+
#include <Eigen/Core>
89

910
namespace pybind11 {
1011
class object;
@@ -15,7 +16,7 @@ class Scripts {
1516
Scripts();
1617
static void deepzoom(QString plane, int quality = 98); //expects "path/plane_1"
1718
static void tarzoom(QString plane); //expects "path/plane_1"
18-
static void normals(QString output, QStringList images, const std::vector<Vector3f> &lights, int method, QRect &crop);
19+
static void normals(QString output, QStringList images, const std::vector<Eigen::Vector3f> &lights, int method, QRect &crop);
1920

2021
static bool checkModule(QString module);
2122
private:

relightlab/directionsview.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
#include <QGraphicsEllipseItem>
55
#include <QDebug>
66

7+
using namespace Eigen;
8+
79
DirectionsView::DirectionsView(QWidget *parent): QGraphicsView(parent) {
810
setScene(&scene);
911
}

relightlab/imageview.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ void ImageView::clear() {
2121

2222
void ImageView::showImage(int id) {
2323
Project &project = qRelightApp->project();
24-
if(project.images.size() <= id)
24+
if(project.images.size() <= size_t(id))
2525
return;
2626

2727
QString filename = project.images[id].filename;
@@ -64,7 +64,7 @@ void ImageView::one() {
6464
}
6565

6666
void ImageView::next() {
67-
if(current_image < qRelightApp->project().images.size()-1)
67+
if(size_t(current_image+1) < qRelightApp->project().images.size())
6868
showImage(current_image+1);
6969
}
7070

0 commit comments

Comments
 (0)