import scenes in a separate thread
parent
f231d57b7a
commit
1d2dfda4c8
|
@ -20,13 +20,6 @@ public:
|
||||||
|
|
||||||
m_kd = props.getFloat("diffuseReflectance", 0.5f);
|
m_kd = props.getFloat("diffuseReflectance", 0.5f);
|
||||||
m_ks = props.getFloat("specularReflectance", 0.2f);
|
m_ks = props.getFloat("specularReflectance", 0.2f);
|
||||||
|
|
||||||
Float avgDiffReflectance = m_diffuseColor->getAverage().average() * m_kd;
|
|
||||||
Float avgSpecularReflectance = m_specularColor->getAverage().average() * m_ks;
|
|
||||||
|
|
||||||
m_specularSamplingWeight = props.getFloat("specularSamplingWeight",
|
|
||||||
avgSpecularReflectance / (avgDiffReflectance + avgSpecularReflectance));
|
|
||||||
m_diffuseSamplingWeight = 1.0f - m_specularSamplingWeight;
|
|
||||||
m_exponent = props.getFloat("exponent", 10.0f);
|
m_exponent = props.getFloat("exponent", 10.0f);
|
||||||
|
|
||||||
if (m_kd * m_diffuseColor->getMaximum().max() + m_ks * m_specularColor->getMaximum().max() > 1.0f) {
|
if (m_kd * m_diffuseColor->getMaximum().max() + m_ks * m_specularColor->getMaximum().max() > 1.0f) {
|
||||||
|
@ -38,6 +31,13 @@ public:
|
||||||
m_kd *= normalization; m_ks *= normalization;
|
m_kd *= normalization; m_ks *= normalization;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Float avgDiffReflectance = m_diffuseColor->getAverage().average() * m_kd;
|
||||||
|
Float avgSpecularReflectance = m_specularColor->getAverage().average() * m_ks;
|
||||||
|
|
||||||
|
m_specularSamplingWeight = props.getFloat("specularSamplingWeight",
|
||||||
|
avgSpecularReflectance / (avgDiffReflectance + avgSpecularReflectance));
|
||||||
|
m_diffuseSamplingWeight = 1.0f - m_specularSamplingWeight;
|
||||||
|
|
||||||
m_componentCount = 2;
|
m_componentCount = 2;
|
||||||
m_type = new unsigned int[m_componentCount];
|
m_type = new unsigned int[m_componentCount];
|
||||||
m_type[0] = EDiffuseReflection;
|
m_type[0] = EDiffuseReflection;
|
||||||
|
|
|
@ -149,4 +149,14 @@ struct SceneContext {
|
||||||
~SceneContext();
|
~SceneContext();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class NonClosableDialog : public QDialog {
|
||||||
|
public:
|
||||||
|
NonClosableDialog(QWidget *parent) : QDialog(parent) {
|
||||||
|
}
|
||||||
|
|
||||||
|
void closeEvent(QCloseEvent *e) {
|
||||||
|
e->ignore();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
#endif // QTGUI_COMMON_H
|
#endif // QTGUI_COMMON_H
|
||||||
|
|
|
@ -1,30 +1,11 @@
|
||||||
#include "ui_importdlg.h"
|
#include "ui_importdlg.h"
|
||||||
#include "importdlg.h"
|
#include "importdlg.h"
|
||||||
#include "acknowledgmentdlg.h"
|
#include "acknowledgmentdlg.h"
|
||||||
#include "../converter/converter.h"
|
|
||||||
#include "mainwindow.h"
|
#include "mainwindow.h"
|
||||||
#include "locateresourcedlg.h"
|
#include "sceneimporter.h"
|
||||||
|
|
||||||
class GUIGeometryConverter : public GeometryConverter {
|
ImportDialog::ImportDialog(QWidget *parent, FileResolver *resolver) :
|
||||||
public:
|
QDialog(parent, Qt::Sheet), ui(new Ui::ImportDialog), m_resolver(resolver) {
|
||||||
inline GUIGeometryConverter(QWidget *parent) : m_parent(parent) {
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string locateResource(const std::string &resource) {
|
|
||||||
LocateResourceDialog locateResource(m_parent, resource.c_str());
|
|
||||||
locateResource.setWindowModality(Qt::ApplicationModal);
|
|
||||||
if (locateResource.exec())
|
|
||||||
return locateResource.getFilename().toStdString();
|
|
||||||
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
private:
|
|
||||||
QWidget *m_parent;
|
|
||||||
};
|
|
||||||
|
|
||||||
ImportDialog::ImportDialog(QWidget *parent) :
|
|
||||||
QDialog(parent, Qt::Sheet),
|
|
||||||
ui(new Ui::ImportDialog) {
|
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
connect(ui->sceneEdit, SIGNAL(textChanged(const QString &)),
|
connect(ui->sceneEdit, SIGNAL(textChanged(const QString &)),
|
||||||
this, SLOT(refresh()));
|
this, SLOT(refresh()));
|
||||||
|
@ -102,13 +83,13 @@ void ImportDialog::refresh() {
|
||||||
|
|
||||||
void ImportDialog::accept() {
|
void ImportDialog::accept() {
|
||||||
QDialog::accept();
|
QDialog::accept();
|
||||||
|
|
||||||
QString sourceFile = ui->inputEdit->text();
|
QString sourceFile = ui->inputEdit->text();
|
||||||
|
|
||||||
QString directory = ui->directoryEdit->text();
|
QString directory = ui->directoryEdit->text();
|
||||||
QString targetScene = ui->sceneEdit->text();
|
QString targetScene = ui->sceneEdit->text();
|
||||||
QString adjustmentFile = ui->adjustmentEdit->text();
|
QString adjustmentFile = ui->adjustmentEdit->text();
|
||||||
|
|
||||||
QDialog *dialog = new QDialog(static_cast<QWidget *>(parent()));
|
NonClosableDialog *dialog = new NonClosableDialog(static_cast<QWidget *>(parent()));
|
||||||
dialog->setWindowModality(Qt::WindowModal);
|
dialog->setWindowModality(Qt::WindowModal);
|
||||||
dialog->setWindowTitle("Converting ..");
|
dialog->setWindowTitle("Converting ..");
|
||||||
QVBoxLayout *layout = new QVBoxLayout(dialog);
|
QVBoxLayout *layout = new QVBoxLayout(dialog);
|
||||||
|
@ -121,24 +102,29 @@ void ImportDialog::accept() {
|
||||||
dialog->show();
|
dialog->show();
|
||||||
progressBar->show();
|
progressBar->show();
|
||||||
|
|
||||||
for (int i=0; i<10; ++i)
|
std::string filePath = m_resolver->pathFromFile(sourceFile.toStdString());
|
||||||
|
if (!m_resolver->contains(filePath))
|
||||||
|
m_resolver->addPath(filePath);
|
||||||
|
|
||||||
|
ref<SceneImporter> importingThread = new SceneImporter(this,
|
||||||
|
m_resolver, sourceFile.toStdString(), directory.toStdString(),
|
||||||
|
targetScene.toStdString(), adjustmentFile.toStdString(),
|
||||||
|
ui->sRGBButton->isChecked());
|
||||||
|
importingThread->start();
|
||||||
|
|
||||||
|
while (importingThread->isRunning()) {
|
||||||
QCoreApplication::processEvents();
|
QCoreApplication::processEvents();
|
||||||
|
importingThread->wait(20);
|
||||||
|
}
|
||||||
|
importingThread->join();
|
||||||
|
|
||||||
GUIGeometryConverter cvt(this);
|
dialog->hide();
|
||||||
cvt.setSRGB(ui->sRGBButton->isChecked());
|
delete dialog;
|
||||||
|
|
||||||
try {
|
if (importingThread->getResult().length() > 0)
|
||||||
cvt.convert(sourceFile.toStdString(), directory.toStdString(),
|
((MainWindow *) parent())->loadFile(QString(importingThread->getResult().c_str()));
|
||||||
targetScene.toStdString(), adjustmentFile.toStdString());
|
else
|
||||||
dialog->hide();
|
|
||||||
delete dialog;
|
|
||||||
((MainWindow *) parent())->loadFile(QString(cvt.getFilename().c_str()));
|
|
||||||
} catch (const std::exception &ex) {
|
|
||||||
dialog->hide();
|
|
||||||
delete dialog;
|
|
||||||
SLog(EWarn, "Conversion failed: %s", ex.what());
|
|
||||||
QMessageBox::critical(this, tr("Scene Import"),
|
QMessageBox::critical(this, tr("Scene Import"),
|
||||||
tr("Conversion failed -- please see the log for details."),
|
tr("Conversion failed -- please see the log for details."),
|
||||||
QMessageBox::Ok);
|
QMessageBox::Ok);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,7 +10,7 @@ namespace Ui {
|
||||||
class ImportDialog : public QDialog {
|
class ImportDialog : public QDialog {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
ImportDialog(QWidget *parent);
|
ImportDialog(QWidget *parent, FileResolver *resolver);
|
||||||
~ImportDialog();
|
~ImportDialog();
|
||||||
public slots:
|
public slots:
|
||||||
void accept();
|
void accept();
|
||||||
|
@ -23,6 +23,7 @@ protected:
|
||||||
void changeEvent(QEvent *e);
|
void changeEvent(QEvent *e);
|
||||||
private:
|
private:
|
||||||
Ui::ImportDialog *ui;
|
Ui::ImportDialog *ui;
|
||||||
|
ref<FileResolver> m_resolver;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // __IMPORTDLG_H
|
#endif // __IMPORTDLG_H
|
||||||
|
|
|
@ -27,16 +27,6 @@
|
||||||
#include "previewsettingsdlg.h"
|
#include "previewsettingsdlg.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
class NonClosableDialog : public QDialog {
|
|
||||||
public:
|
|
||||||
NonClosableDialog(QWidget *parent) : QDialog(parent) {
|
|
||||||
}
|
|
||||||
|
|
||||||
void closeEvent(QCloseEvent *e) {
|
|
||||||
e->ignore();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
class ProgramVersion {
|
class ProgramVersion {
|
||||||
public:
|
public:
|
||||||
ProgramVersion(const QString &versionString) {
|
ProgramVersion(const QString &versionString) {
|
||||||
|
@ -431,7 +421,12 @@ void MainWindow::onBugReportSubmitted() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::on_actionImport_triggered() {
|
void MainWindow::on_actionImport_triggered() {
|
||||||
ImportDialog *dialog = new ImportDialog(this);
|
ref<FileResolver> resolver = FileResolver::getInstance();
|
||||||
|
ref<FileResolver> newResolver = resolver->clone();
|
||||||
|
for (int i=0; i<m_searchPaths.size(); ++i)
|
||||||
|
newResolver->addPath(m_searchPaths[i].toStdString());
|
||||||
|
|
||||||
|
ImportDialog *dialog = new ImportDialog(this, newResolver);
|
||||||
dialog->setAttribute(Qt::WA_DeleteOnClose);
|
dialog->setAttribute(Qt::WA_DeleteOnClose);
|
||||||
connect(dialog, SIGNAL(finished(int)), this, SLOT(onImportDialogClose(int)));
|
connect(dialog, SIGNAL(finished(int)), this, SLOT(onImportDialogClose(int)));
|
||||||
m_currentChild = dialog;
|
m_currentChild = dialog;
|
||||||
|
|
|
@ -0,0 +1,49 @@
|
||||||
|
#include "sceneimporter.h"
|
||||||
|
#include "../converter/converter.h"
|
||||||
|
#include "locateresourcedlg.h"
|
||||||
|
|
||||||
|
class GUIGeometryConverter : public GeometryConverter {
|
||||||
|
public:
|
||||||
|
inline GUIGeometryConverter(QWidget *parent) : m_parent(parent) {
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string locateResource(const std::string &resource) {
|
||||||
|
LocateResourceDialog locateResource(m_parent, resource.c_str());
|
||||||
|
locateResource.setWindowModality(Qt::ApplicationModal);
|
||||||
|
if (locateResource.exec())
|
||||||
|
return locateResource.getFilename().toStdString();
|
||||||
|
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
private:
|
||||||
|
QWidget *m_parent;
|
||||||
|
};
|
||||||
|
|
||||||
|
SceneImporter::SceneImporter(QWidget *parent, FileResolver *resolver,
|
||||||
|
const std::string &sourceFile, const std::string &directory,
|
||||||
|
const std::string &targetScene, const std::string &adjustmentFile,
|
||||||
|
bool sRGB)
|
||||||
|
: Thread("impt"), m_parent(parent), m_resolver(resolver),
|
||||||
|
m_sourceFile(sourceFile), m_directory(directory),
|
||||||
|
m_targetScene(targetScene), m_adjustmentFile(adjustmentFile), m_srgb(sRGB) {
|
||||||
|
m_wait = new WaitFlag();
|
||||||
|
}
|
||||||
|
|
||||||
|
SceneImporter::~SceneImporter() {
|
||||||
|
}
|
||||||
|
|
||||||
|
void SceneImporter::run() {
|
||||||
|
FileResolver::setInstance(m_resolver);
|
||||||
|
try {
|
||||||
|
GUIGeometryConverter cvt(m_parent);
|
||||||
|
cvt.setSRGB(m_srgb);
|
||||||
|
cvt.convert(m_sourceFile, m_directory, m_targetScene, m_adjustmentFile);
|
||||||
|
m_result = cvt.getFilename();
|
||||||
|
} catch (const std::exception &ex) {
|
||||||
|
SLog(EWarn, "Conversion failed: %s", ex.what());
|
||||||
|
} catch (...) {
|
||||||
|
SLog(EWarn, "An unknown type of error occurred!");
|
||||||
|
}
|
||||||
|
m_wait->set(true);
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,37 @@
|
||||||
|
#if !defined(__SCENELOADER_H)
|
||||||
|
#define __SCENELOADER_H
|
||||||
|
|
||||||
|
#include <QtGui>
|
||||||
|
#include <mitsuba/core/fresolver.h>
|
||||||
|
#include <mitsuba/core/lock.h>
|
||||||
|
|
||||||
|
using namespace mitsuba;
|
||||||
|
|
||||||
|
class SceneImporter : public Thread {
|
||||||
|
public:
|
||||||
|
SceneImporter(QWidget *parent, FileResolver *resolver,
|
||||||
|
const std::string &sourceFile, const std::string &directory,
|
||||||
|
const std::string &targetScene, const std::string &adjustmentFile,
|
||||||
|
bool sRGB);
|
||||||
|
|
||||||
|
void run();
|
||||||
|
|
||||||
|
inline void wait(int ms) { m_wait->wait(ms); }
|
||||||
|
|
||||||
|
inline const std::string &getResult() const { return m_result; }
|
||||||
|
protected:
|
||||||
|
virtual ~SceneImporter();
|
||||||
|
private:
|
||||||
|
QWidget *m_parent;
|
||||||
|
ref<FileResolver> m_resolver;
|
||||||
|
ref<WaitFlag> m_wait;
|
||||||
|
std::string m_sourceFile;
|
||||||
|
std::string m_directory;
|
||||||
|
std::string m_targetScene;
|
||||||
|
std::string m_adjustmentFile;
|
||||||
|
std::string m_result;
|
||||||
|
bool m_srgb;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // __SCENELOADER_H
|
||||||
|
|
Loading…
Reference in New Issue