Skip to content

Commit 52178fd

Browse files
committed
refactored ritframe
1 parent b982157 commit 52178fd

File tree

4 files changed

+234
-227
lines changed

4 files changed

+234
-227
lines changed

relightlab/rtiframe.cpp

+127-92
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,10 @@
11
#include "rtiframe.h"
2+
#include "rtiplan.h"
23
#include "helpbutton.h"
34
#include "relightapp.h"
4-
#include "rticard.h"
5-
#include "flowlayout.h"
6-
#include "rtiplan.h"
7-
#include "rtirow.h"
85
#include "rtirecents.h"
9-
#include "rtiframe.h"
106
#include "qlabelbutton.h"
11-
#include "rtitask.h"
7+
128

139
#include "processqueue.h"
1410

@@ -25,7 +21,7 @@
2521
#include <QScrollArea>
2622
#include <QFileDialog>
2723

28-
#include "rtiplan.h"
24+
2925

3026

3127
RtiFrame::RtiFrame(QWidget *parent): QFrame(parent) {
@@ -36,118 +32,81 @@ RtiFrame::RtiFrame(QWidget *parent): QFrame(parent) {
3632

3733
content->addWidget(recents = new RtiRecents);
3834

39-
content->addWidget(rti_plan = new RtiPlan, 1);
40-
connect(rti_plan, SIGNAL(exportRti()), this, SLOT(exportRti()));
41-
return;
35+
basis_row = new RtiBasisRow(parameters, this);
36+
colorspace_row = new RtiColorSpaceRow(parameters, this);
37+
planes_row = new RtiPlanesRow(parameters, this);
38+
format_row = new RtiFormatRow(parameters, this);
39+
quality_row = new RtiQualityRow(parameters, this);
40+
layout_row = new RtiWebLayoutRow(parameters, this);
41+
export_row = new RtiExportRow(parameters, this);
4242

43-
QScrollArea *area = new QScrollArea;
44-
area->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
45-
area->setWidgetResizable(true);
46-
content->addWidget(area, 1);
4743

48-
QWidget *widget = new QWidget;
49-
area->setWidget(widget);
44+
content->addWidget(basis_row);
45+
content->addWidget(colorspace_row);
46+
content->addWidget(planes_row);
47+
content->addWidget(format_row);
48+
content->addWidget(quality_row);
49+
content->addWidget(layout_row);
50+
content->addWidget(export_row);
5051

5152

52-
FlowLayout *sample_layout = new FlowLayout(area->widget());
53-
54-
sample_layout->addWidget(new RtiCard(Rti::PTM, Rti::LRGB, 9, 0));
55-
sample_layout->addWidget(new RtiCard(Rti::PTM, Rti::RGB, 18, 0));
56-
sample_layout->addWidget(new RtiCard(Rti::HSH, Rti::RGB, 27, 0));
5753

54+
connect(basis_row, &RtiBasisRow::basisChanged, this, &RtiFrame::basisChanged);
55+
connect(colorspace_row, &RtiColorSpaceRow::colorspaceChanged, this, &RtiFrame::colorspaceChanged);
56+
connect(planes_row, &RtiPlanesRow::nplanesChanged, this, &RtiFrame::nplanesChanged);
57+
connect(format_row, &RtiFormatRow::formatChanged, this, &RtiFrame::formatChanged);
58+
connect(layout_row, &RtiWebLayoutRow::layoutChanged, this, &RtiFrame::layoutChanged);
59+
connect(quality_row, &RtiQualityRow::qualityChanged, this, &RtiFrame::qualityChanged);
5860

59-
sample_layout->addWidget(new RtiCard(Rti::RBF, Rti::MRGB, 18, 0));
60-
sample_layout->addWidget(new RtiCard(Rti::BILINEAR, Rti::MRGB, 18, 0));
61+
{
62+
QHBoxLayout *save_row = new QHBoxLayout;
6163

64+
{
65+
QLabel *label = new QLabel("");
66+
label->setFixedWidth(200);
67+
save_row->addWidget(label, 0, Qt::AlignLeft);
68+
}
69+
save_row->addStretch(1);
6270

71+
{
72+
QFrame *buttons_frame = new QFrame;
73+
buttons_frame->setMinimumWidth(860);
6374

64-
/*
65-
QGroupBox *model = new QGroupBox("Model");
66-
content->addWidget(model);
67-
QVBoxLayout *model_layout = new QVBoxLayout(model);
68-
model_layout->addWidget(new HelpRadio("Polynomial Texture Maps (PTM)", "rti/ptm"));
69-
model_layout->addWidget(new HelpRadio("HemiSpherical Harmonics (HSH)", "rti/hsh"));
70-
model_layout->addWidget(new HelpRadio("Radial Basis Functions (RBF)", "rti/rbf"));
71-
model_layout->addWidget(new HelpRadio("Bilinear sampling (BNL)", "rti/bln"));
72-
model_layout->addWidget(new HelpRadio("Neural network", "rti/neural"));
73-
74-
QGroupBox *colorspace= new QGroupBox("Colorspace");
75-
content->addWidget(colorspace);
76-
QVBoxLayout *colorspace_layout = new QVBoxLayout(colorspace);
77-
colorspace_layout->addWidget(new HelpRadio("RGB", "rti/rgb"));
78-
colorspace_layout->addWidget(new HelpRadio("LRGB", "rti/lrgb"));
79-
colorspace_layout->addWidget(new HelpRadio("MRGB", "rti/mrgb"));
80-
colorspace_layout->addWidget(new HelpRadio("YCC", "rti/ycc"));
81-
82-
QGroupBox *planes = new QGroupBox("Planes");
83-
content->addWidget(planes);
84-
85-
QGridLayout *planes_layout = new QGridLayout(planes);
86-
planes_layout->addWidget(new HelpLabel("Total number of planes:", "rti/planes"), 0, 0);
87-
88-
QSpinBox *total_planes = new QSpinBox;
89-
planes_layout->addWidget(total_planes, 0, 1);
75+
{
76+
QHBoxLayout *buttons_layout = new QHBoxLayout(buttons_frame);
9077

91-
planes_layout->addWidget(new HelpLabel("Number of luminance planes:", "rti/luminance"), 1, 0);
78+
buttons_layout->addStretch(1);
79+
QPushButton *save = new QPushButton("Export", this);
80+
save->setIcon(QIcon::fromTheme("save"));
81+
save->setProperty("class", "large");
82+
save->setMinimumWidth(200);
83+
connect(save, &QPushButton::clicked, [this]() { emit exportRti(); });
9284

93-
QSpinBox *luminance_planes = new QSpinBox;
94-
planes_layout->addWidget(luminance_planes, 1, 1);
95-
*/
96-
/*
97-
QGroupBox *legacy = new QGroupBox("Export .rti for RtiViewer");
98-
content->addWidget(legacy);
85+
buttons_layout->addWidget(save);
86+
}
9987

100-
QGridLayout *legacy_layout = new QGridLayout(legacy);
101-
102-
legacy_layout->addWidget(new HelpRadio("Lossless (heavy!)", "rti/legacy"), 0, 0);
88+
save_row->addWidget(buttons_frame);
89+
}
90+
save_row->addStretch(1);
10391

104-
legacy_layout->addWidget(new HelpRadio("JPEG", "rti/legacy"), 1, 0);
105-
legacy_layout->addWidget(new HelpLabel("Quality:", "rti/legacy"), 1, 1);
106-
QSpinBox *quality = new QSpinBox;
107-
legacy_layout->addWidget(quality, 1, 2);
10892

109-
legacy_layout->addWidget(new QLabel("Filename:"), 2, 0);
110-
legacy_layout->addWidget(new QLineEdit(), 2, 1);
111-
legacy_layout->addWidget(new QPushButton("..."), 2, 2);
93+
content->addLayout(save_row);
11294

113-
legacy_layout->addWidget(new QPushButton("Export"), 3, 2); */
95+
}
11496

11597
content->addStretch();
98+
11699
}
117100

118101
void RtiFrame::exportRti() {
119102

120103
//check for lights
121104
if(qRelightApp->project().dome.directions.size() == 0) {
122105
QMessageBox::warning(this, "Missing light directions.", "You need light directions for this dataset to build an RTI.\n"
123-
"You can either load a dome or .lp file or mark a reflective sphere in the 'Lights' tab.");
106+
"You can either load a dome or .lp file or mark a reflective sphere in the 'Lights' tab.");
124107
return;
125108
}
126-
RtiParameters &parameters = rti_plan->parameters;
127-
//get folder if not legacy.
128-
QString output;
129-
if(parameters.format == RtiParameters::RTI) {
130-
QString extension;
131-
QString label;
132-
133-
if(parameters.basis == Rti::HSH) {
134-
extension = ".rti";
135-
label = "RTI file (*.rti)";
136-
} else if(parameters.basis == Rti::PTM) {
137-
extension = ".ptm";
138-
label = "PTM file (*.ptm)";
139-
}
140-
output = QFileDialog::getSaveFileName(this, "Select a file name", QString(), label);
141-
if(output.isNull()) return;
142109

143-
if(!output.endsWith(extension))
144-
output += extension;
145-
146-
} else {
147-
output = QFileDialog::getSaveFileName(this, "Select an output folder", QString());
148-
if(output.isNull()) return;
149-
}
150-
parameters.path = output;
151110

152111
RtiTask *rti_task = new RtiTask(qRelightApp->project());
153112
rti_task->parameters = parameters;
@@ -159,3 +118,79 @@ void RtiFrame::exportRti() {
159118
}
160119

161120

121+
void RtiFrame::basisChanged() {
122+
//when basis is changed we try to change the other values as little as possible.
123+
//if the new basis is not compatible with the current color space we change it to the default one
124+
//colorspace:
125+
auto &basis = parameters.basis;
126+
bool pca = basis == Rti::RBF || basis == Rti::BILINEAR;
127+
128+
// COLORSPACE
129+
130+
auto &colorspace = parameters.colorspace;
131+
if(!pca) {
132+
if(colorspace != Rti::RGB && colorspace != Rti::LRGB)
133+
colorspace = Rti::RGB;
134+
135+
} else {
136+
if(colorspace != Rti::MRGB && colorspace != Rti::YCC)
137+
colorspace = Rti::MRGB;
138+
}
139+
colorspace_row->setColorspace(colorspace);
140+
141+
// PLANES
142+
143+
auto &nplanes = parameters.nplanes;
144+
auto &nchroma = parameters.nchroma;
145+
146+
switch(basis) {
147+
case Rti::PTM: nplanes = 18; nchroma = 0; break;
148+
case Rti::HSH: if(nplanes != 12 && nplanes != 27) nplanes = 27; nchroma = 0; break;
149+
case Rti::RBF:
150+
case Rti::BILINEAR:
151+
if(colorspace != Rti::YCC) nchroma = 0;
152+
}
153+
154+
planes_row->setNPlanes(nplanes);
155+
planes_row->setNChroma(nchroma);
156+
157+
//FORMAT
158+
format_row->allowLegacy(!pca);
159+
160+
if(pca && parameters.format == RtiParameters::RTI) {
161+
format_row->setFormat(RtiParameters::WEB); //emit and cascade update other rows.
162+
}
163+
export_row->suggestPath();
164+
}
165+
166+
void RtiFrame::colorspaceChanged() {
167+
planes_row->setNChroma(parameters.nchroma);
168+
169+
bool pca = parameters.basis == Rti::RBF || parameters.basis == Rti::BILINEAR;
170+
if(pca && parameters.format == RtiParameters::RTI) {
171+
format_row->setFormat(RtiParameters::WEB);
172+
}
173+
export_row->suggestPath();
174+
175+
}
176+
177+
void RtiFrame::nplanesChanged() {
178+
export_row->suggestPath();
179+
}
180+
181+
void RtiFrame::formatChanged() {
182+
bool legacy = quality_row->parameters.format == RtiParameters::RTI;
183+
//only RTI allows for lossless.
184+
quality_row->allowLossless(legacy);
185+
layout_row->setEnabled(quality_row->parameters.format == RtiParameters::WEB);
186+
export_row->suggestPath();
187+
}
188+
189+
void RtiFrame::qualityChanged() {
190+
}
191+
192+
void RtiFrame::layoutChanged() {
193+
194+
}
195+
196+

relightlab/rtiframe.h

+28-5
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,51 @@
44
#include <QFrame>
55
//TODO we should separate RTI definitions from actual implementation (materials etc).
66
#include "../src/rti.h"
7+
#include "rtitask.h"
78

8-
class RtiPlan;
9-
class RtiCard;
109
class RtiRecents;
1110
class RtiParameters;
1211

12+
class RtiBasisRow;
13+
class RtiColorSpaceRow;
14+
class RtiPlanesRow;
15+
class RtiFormatRow;
16+
class RtiQualityRow;
17+
class RtiWebLayoutRow;
18+
class RtiExportRow;
19+
1320
class RtiFrame: public QFrame {
1421
Q_OBJECT
15-
1622
public:
1723
RtiFrame(QWidget *parent = nullptr);
18-
void init();
24+
25+
RtiParameters parameters;
1926

2027
public slots:
2128
void exportRti();
2229

30+
void basisChanged();
31+
void colorspaceChanged();
32+
void nplanesChanged();
33+
void formatChanged();
34+
void qualityChanged();
35+
void layoutChanged();
36+
2337
signals:
2438
void processStarted();
2539

40+
2641
private:
2742
RtiRecents *recents;
28-
RtiPlan *rti_plan;
43+
44+
RtiBasisRow *basis_row = nullptr;
45+
RtiColorSpaceRow *colorspace_row = nullptr;
46+
RtiPlanesRow *planes_row = nullptr;
47+
RtiFormatRow *format_row = nullptr;
48+
RtiQualityRow *quality_row = nullptr;
49+
RtiWebLayoutRow *layout_row = nullptr;
50+
RtiExportRow *export_row = nullptr;
2951
};
3052

53+
3154
#endif // RTIFRAME_H

0 commit comments

Comments
 (0)