Skip to content

Commit 9776163

Browse files
committed
fixed flattening exponential bug (for normals exactly (0, 0, 1)).
1 parent 3f7d600 commit 9776163

8 files changed

+47
-36
lines changed

relightlab/normalsplan.cpp

+5-4
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,9 @@ NormalsFlattenRow::NormalsFlattenRow(NormalsParameters &_parameters, QFrame *par
100100
QHBoxLayout *loader_layout = new QHBoxLayout;
101101
loader_layout->addWidget(new QLabel("Fourier low pass frequency."));
102102
loader_layout->addWidget(max_frequency = new QDoubleSpinBox);
103-
max_frequency->setRange(0.0001, 1);
103+
max_frequency->setRange(0, 100);
104104
max_frequency->setDecimals(4);
105+
max_frequency->setValue(parameters.flatPercentage);
105106

106107
button_layout->addLayout(loader_layout);
107108

@@ -113,9 +114,9 @@ NormalsFlattenRow::NormalsFlattenRow(NormalsParameters &_parameters, QFrame *par
113114
connect(fourier, &QAbstractButton::clicked, this, [this](){ setFlattenMethod(FLAT_FOURIER); });
114115

115116
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
116-
connect(max_frequency, static_cast<void (QDoubleSpinBox::*)(double)>(&QDoubleSpinBox::valueChanged), this, [this](double v) { parameters.m_FlatRadius = v; });
117+
connect(max_frequency, static_cast<void (QDoubleSpinBox::*)(double)>(&QDoubleSpinBox::valueChanged), this, [this](double v) { parameters.flatPercentage = v; });
117118
#else
118-
connect(max_frequency, qOverload<double>(&QDoubleSpinBox::valueChanged), this, [this](double v) { parameters.m_FlatRadius = v; });
119+
connect(max_frequency, qOverload<double>(&QDoubleSpinBox::valueChanged), this, [this](double v) { parameters.flatPercentage = v; });
119120
#endif
120121

121122

@@ -136,7 +137,7 @@ void NormalsFlattenRow::setFlattenMethod(FlatMethod method) {
136137
}
137138

138139
void NormalsFlattenRow::setFourierFrequency(double f) {
139-
parameters.m_FlatRadius = f;
140+
parameters.flatPercentage = f;
140141
max_frequency->setValue(f);
141142
}
142143

relightlab/normalstask.cpp

+5-1
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,11 @@ void NormalsTask::run() {
153153
ni.flattenRadial();
154154
break;
155155
case FLAT_FOURIER:
156+
//0 remove all details.
157+
//1 remove detail on the scale of the image only.
158+
//from 0 to width;
156159
//convert radius to frequencies
157-
double sigma = 100*parameters.m_FlatRadius;
160+
double sigma = width*parameters.flatPercentage/100;
158161
ni.flattenFourier(width/10, sigma);
159162
break;
160163
}
@@ -218,6 +221,7 @@ void NormalsTask::run() {
218221
savePly(filename, width, height, z);
219222
}
220223
progressed("Done", 100);
224+
status = DONE;
221225
}
222226

223227
bool savePly(const char *filename, pmp::SurfaceMesh &mesh) {

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 m_FlatRadius = 0.5;
26+
double flatPercentage = 50;
2727

2828

2929
SurfaceIntegration surface_integration = SURFACE_NONE;

relightlab/processqueue.cpp

+4-1
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,11 @@ void ProcessQueue::startNewProcess() {
6262
task = queue.front();
6363
queue.pop_front();
6464

65-
task->start();
65+
//task->mutex.lock();
6666
task->status = Task::RUNNING;
67+
//task->mutex.unlock();
68+
69+
task->start();
6770
emit update();
6871
}
6972

relightlab/queueitem.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,6 @@ void QueueItem::update() {
9090
break;
9191
case Task::RUNNING:
9292
status->setText("Starting...");
93-
9493
break;
9594
case Task::DONE:
9695
status->setText("Done");

relightlab/spherepanel.cpp

+16-17
Original file line numberDiff line numberDiff line change
@@ -18,25 +18,24 @@ SpherePanel::SpherePanel(QWidget *parent): QGroupBox("Reflective spheres", paren
1818

1919
content->addSpacing(10);
2020

21-
QFrame *spheres_frame = new QFrame;
22-
23-
QPushButton *sphere = new QPushButton(QIcon::fromTheme("folder"), "New reflective sphere...");
24-
sphere->setProperty("class", "large");
25-
sphere->setMinimumWidth(200);
26-
sphere->setMaximumWidth(300);
27-
connect(sphere, SIGNAL(clicked()), this, SLOT(newSphere()));
28-
content->addWidget(sphere, 0, Qt::AlignTop);
29-
30-
content->addWidget(spheres_frame);
31-
32-
spheres = new QVBoxLayout(spheres_frame);
33-
34-
QHBoxLayout *buttons = new QHBoxLayout;
35-
content->addLayout(buttons);
21+
{
22+
QPushButton *sphere = new QPushButton(QIcon::fromTheme("folder"), "New reflective sphere...");
23+
sphere->setProperty("class", "large");
24+
sphere->setMinimumWidth(200);
25+
sphere->setMaximumWidth(300);
26+
connect(sphere, SIGNAL(clicked()), this, SLOT(newSphere()));
27+
content->addWidget(sphere, 0, Qt::AlignTop);
28+
}
29+
{
30+
QFrame *spheres_frame = new QFrame;
31+
spheres = new QVBoxLayout;
32+
spheres_frame->setLayout(spheres);
33+
content->addWidget(spheres_frame);
34+
}
3635
}
3736

3837
void SpherePanel::clear() {
39-
setVisible(false);
38+
//setVisible(false);
4039
while(spheres->count() > 0) {
4140
QLayoutItem *item = spheres->takeAt(0);
4241
SphereRow *row = dynamic_cast<SphereRow *>(item->widget());
@@ -47,7 +46,7 @@ void SpherePanel::clear() {
4746

4847
void SpherePanel::init() {
4948
auto &project_spheres = qRelightApp->project().spheres;
50-
setVisible(project_spheres.size() > 0);
49+
//setVisible(project_spheres.size() > 0);
5150
for(Sphere *sphere: project_spheres) {
5251
sphere->fit();
5352
SphereRow * row = addSphere(sphere);

relightlab/sphererow.cpp

-7
Original file line numberDiff line numberDiff line change
@@ -58,15 +58,8 @@ SphereRow::SphereRow(Sphere *_sphere, QWidget *parent): QWidget(parent) {
5858
reflections->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
5959
columns->addWidget(reflections);
6060

61-
//QVBoxLayout *status_layout = new QVBoxLayout;
62-
//columns->addLayout(status_layout, 2);
63-
//status_layout->addStretch();
64-
//status = new QLabel("Locating highlights...");
65-
//status_layout->addWidget(status);
6661
progress = new QProgressBar;
6762
progress->setValue(0);
68-
//status_layout->addWidget(progress);
69-
//status_layout->addStretch();
7063
columns->addWidget(progress, 2);
7164

7265
QPushButton *edit = new QPushButton(QIcon::fromTheme("edit"), "Edit...");

src/flatnormals.cpp

+16-4
Original file line numberDiff line numberDiff line change
@@ -188,12 +188,20 @@ void NormalsImage::flattenFourier(int padding, double sigma) {
188188
n[1] = normals[3*(x + y*w)+1];
189189
n[2] = normals[3*(x + y*w)+2];
190190

191+
191192
if(exponential) {
192193
double t = acos(n[2]);
193-
n[0] = n[0]*t/sin(t);
194-
n[1] = n[1]*t/sin(t);
194+
if(t > 0) {
195+
n[0] = n[0]*t/sin(t);
196+
n[1] = n[1]*t/sin(t);
197+
}
195198
}
196199

200+
assert(!isnan(n[0]));
201+
assert(!isnan(n[1]));
202+
assert(!isnan(n[2]));
203+
204+
197205
int X = x + padding_amount;
198206
int Y = y + padding_amount;
199207
datax[X + Y*W].real(n[0]);
@@ -241,6 +249,8 @@ void NormalsImage::flattenFourier(int padding, double sigma) {
241249
* double g = 1.0;
242250
if(r2 < sigma*sigma/4)
243251
g = 1.0 - pow(cos(M_PI*r2/sigma), 2); */
252+
assert(!isnan(datax[x + y*W].real()));
253+
assert(!isnan(datay[x + y*W].imag()));
244254

245255
datax[x + y*W] *= g;
246256
datay[x + y*W] *= g;
@@ -259,8 +269,10 @@ void NormalsImage::flattenFourier(int padding, double sigma) {
259269
double g = datay[X + Y*W].real();
260270
double d = sqrt(r*r + g*g);
261271
if(exponential) {
262-
r = r*sin(d)/d;
263-
g = g*sin(d)/d;
272+
if(d > 0) {
273+
r = r*sin(d)/d;
274+
g = g*sin(d)/d;
275+
}
264276
}
265277

266278
double b = sqrt(1 - r*r - g*g);

0 commit comments

Comments
 (0)