Skip to content

Commit 022cc2f

Browse files
committed
moved light number and images number checks to a safer place
image list selection adjusted
1 parent 9c63e1d commit 022cc2f

9 files changed

+75
-51
lines changed

relightlab/imageframe.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ void ImageFrame::init() {
9999

100100
if(qRelightApp->project().images.size()) {
101101
showImage(0);
102+
image_list->setCurrentRow(0);
102103
image_view->fit();
103104
}
104105
listMode(); //TODO actually use last used mode used by the user but only in imageframe
@@ -113,7 +114,7 @@ void ImageFrame::showImage(int id) {
113114

114115
Project &project = qRelightApp->project();
115116

116-
image_list->setCurrentRow(id);
117+
//image_list->setCurrentRow(id);
117118
qRelightApp->action("previous_image")->setEnabled(id != 0);
118119
qRelightApp->action("next_image")->setEnabled(id != (int)project.images.size()-1);
119120

relightlab/imagelist.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
#include <assert.h>
66

77
void ImageList::init() {
8+
setSelectionMode(QAbstractItemView::ExtendedSelection);
9+
810
Project &project = qRelightApp->project();
911
clear();
1012
int count =0;
@@ -31,7 +33,6 @@ void ImageList::verifyItem(QListWidgetItem *item) {
3133
project.images[img_number].skip = skip;
3234

3335
emit skipChanged(img_number, skip);
34-
3536
}
3637

3738
void ImageList::setSkipped(int img_number, bool skip) {

relightlab/normalsframe.cpp

+12-4
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,18 @@ void NormalsFrame::save() {
9393
}
9494
}
9595
NormalsTask *task = new NormalsTask();
96-
task->setParameters(parameters);
97-
task->output = parameters.path;
98-
if(parameters.compute)
99-
task->initFromProject(qRelightApp->project());
96+
try {
97+
98+
task->setParameters(parameters);
99+
task->output = parameters.path;
100+
if(parameters.compute)
101+
task->initFromProject(qRelightApp->project());
102+
103+
} catch(QString error) {
104+
QMessageBox::critical(this, "Something went wrong", error);
105+
delete task;
106+
return;
107+
}
100108

101109
ProcessQueue &queue = ProcessQueue::instance();
102110
queue.addTask(task);

relightlab/rtiframe.cpp

+12-4
Original file line numberDiff line numberDiff line change
@@ -116,10 +116,18 @@ void RtiFrame::exportRti() {
116116
QMessageBox::warning(this, "Destination path is missing.", "Fill in the output folder or the filename for the RTI.");
117117
return;
118118
}
119-
RtiTask *rti_task = new RtiTask(project);
120-
rti_task->setParameters(parameters);
121-
rti_task->output = parameters.path;
122-
rti_task->crop = project.crop;
119+
RtiTask *rti_task = new RtiTask();
120+
try {
121+
rti_task->setProject(project);
122+
rti_task->setParameters(parameters);
123+
rti_task->output = parameters.path;
124+
rti_task->crop = project.crop;
125+
126+
} catch(QString error) {
127+
QMessageBox::critical(this, "Something went wrong", error);
128+
delete rti_task;
129+
return;
130+
}
123131

124132
ProcessQueue &queue = ProcessQueue::instance();
125133
queue.addTask(rti_task);

relightlab/rtitask.cpp

+35-31
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,37 @@ QString RtiParameters::summary() {
4242
return txt;
4343
}
4444

45-
RtiTask::RtiTask(const Project &_project): Task(), project(_project) {}
45+
RtiTask::RtiTask(): Task() {
46+
builder = new RtiBuilder;
47+
}
48+
49+
void RtiTask::setProject(Project &project) {
50+
builder->imageset.pixel_size = project.pixelSize;
51+
52+
builder->nworkers = QSettings().value("nworkers", 8).toInt();
53+
builder->samplingram = QSettings().value("ram", 512).toInt();
54+
55+
56+
ImageSet &imageset = builder->imageset;
57+
58+
imageset.images = project.getImages();
59+
imageset.initImages(project.dir.absolutePath().toStdString().c_str());
60+
61+
imageset.initFromDome(project.dome); //lights after images
62+
imageset.setCrop(crop, project.offsets);
63+
imageset.pixel_size = project.pixelSize;
64+
65+
//TODO too many crop locations!
66+
if(!crop.isNull()) {
67+
builder->crop[0] = imageset.left;
68+
builder->crop[1] = imageset.top;
69+
builder->crop[2] = imageset.width;
70+
builder->crop[3] = imageset.height;
71+
}
72+
73+
builder->width = imageset.width;
74+
builder->height = imageset.height;
75+
}
4676

4777
RtiTask::~RtiTask() {
4878
if(builder)
@@ -52,20 +82,6 @@ RtiTask::~RtiTask() {
5282
void RtiTask::setParameters(RtiParameters &p) {
5383
parameters = p;
5484
label = parameters.summary();
55-
}
56-
57-
void RtiTask::run() {
58-
label = parameters.summary();
59-
60-
status = RUNNING;
61-
std::function<bool(QString s, int d)> callback = [this](QString s, int n)->bool { return this->progressed(s, n); };
62-
63-
//TODO mnove all this to the constructor (except what parameters can set.
64-
builder = new RtiBuilder;
65-
builder->imageset.pixel_size = project.pixelSize;
66-
67-
builder->nworkers = QSettings().value("nworkers", 8).toInt();
68-
builder->samplingram = QSettings().value("ram", 512).toInt();
6985

7086
builder->type = parameters.basis;
7187
builder->colorspace = parameters.colorspace;
@@ -81,24 +97,12 @@ void RtiTask::run() {
8197
if(parameters.format == RtiParameters::RTI)
8298
builder->commonMinMax = true;
8399

84-
ImageSet &imageset = builder->imageset;
85-
imageset.images = project.getImages();
86-
imageset.pixel_size = project.pixelSize;
87-
imageset.initImages(input_folder.toStdString().c_str());
88-
89-
imageset.initFromDome(project.dome); //lights after images
90-
imageset.setCrop(crop, project.offsets);
100+
}
91101

92-
//TODO too many crop locations!
93-
if(!crop.isNull()) {
94-
builder->crop[0] = imageset.left;
95-
builder->crop[1] = imageset.top;
96-
builder->crop[2] = imageset.width;
97-
builder->crop[3] = imageset.height;
98-
}
102+
void RtiTask::run() {
99103

100-
builder->width = imageset.width;
101-
builder->height = imageset.height;
104+
status = RUNNING;
105+
std::function<bool(QString s, int d)> callback = [this](QString s, int n)->bool { return this->progressed(s, n); };
102106

103107
QString output = parameters.path; //masking Task::output.
104108
try {

relightlab/rtitask.h

+5-3
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,16 @@ class RtiParameters {
3636
class RtiTask: public Task {
3737
Q_OBJECT
3838
public:
39-
Project project;
4039
RtiParameters parameters;
4140
QRect crop;
4241

43-
RtiTask(const Project &_project);
42+
RtiTask();
4443
virtual ~RtiTask();
45-
virtual void run() override;
44+
45+
void setProject(Project &_project);
4646
void setParameters(RtiParameters &p);
47+
virtual void run() override;
48+
4749

4850
public slots:
4951

src/imageset.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ void ImageSet::initFromDome(Dome &dome) {
105105
}
106106
}
107107

108-
void ImageSet::setLights(std::vector<Eigen::Vector3f> &lights, Dome::LightConfiguration configuration) {
108+
void ImageSet::setLights(const std::vector<Eigen::Vector3f> &lights, const Dome::LightConfiguration configuration) {
109109
lights1 = lights;
110110
light3d = (configuration != Dome::DIRECTIONAL);
111111
if(light3d) {
@@ -388,9 +388,9 @@ void ImageSet::restart() {
388388
current_line = 0;
389389
}
390390

391-
void ImageSet::setCrop(QRect &_crop, std::vector<QPointF> &_offsets) {
391+
void ImageSet::setCrop(QRect &_crop, const std::vector<QPointF> &_offsets) {
392392
std::vector<QPoint> int_offsets;
393-
for(QPointF &p: _offsets)
393+
for(const QPointF &p: _offsets)
394394
int_offsets.push_back(p.toPoint());
395395

396396
//find min and max of offsets to adjust the maxCrop;

src/imageset.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,10 @@ class ImageSet {
5454
//open images and starts the decoders
5555
bool initImages(const char *path); //path points to the dir of the images.
5656

57-
void setCrop(QRect &crop, std::vector<QPointF> &offsets);
57+
void setCrop(QRect &crop, const std::vector<QPointF> &offsets);
5858

5959

60-
void setLights(std::vector<Eigen::Vector3f> &lights, Dome::LightConfiguration configuration);
60+
void setLights(const std::vector<Eigen::Vector3f> &lights, const Dome::LightConfiguration configuration);
6161
std::vector<Eigen::Vector3f> &lights() { return lights1; }
6262

6363
size_t size() { return size_t(images.size()); }

src/project.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,9 @@ class Project {
8282
}
8383
size_t size() { return images.size(); }
8484

85-
QStringList getImages() {
85+
QStringList getImages() const {
8686
QStringList imgs;
87-
for(Image &img: images)
87+
for(Image img: images)
8888
if(!img.skip)
8989
imgs.push_back(img.filename);
9090
return imgs;

0 commit comments

Comments
 (0)