import scenes in a separate thread
parent
f231d57b7a
commit
1d2dfda4c8
|
@ -20,13 +20,6 @@ public:
|
|||
|
||||
m_kd = props.getFloat("diffuseReflectance", 0.5f);
|
||||
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);
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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_type = new unsigned int[m_componentCount];
|
||||
m_type[0] = EDiffuseReflection;
|
||||
|
|
|
@ -149,4 +149,14 @@ struct SceneContext {
|
|||
~SceneContext();
|
||||
};
|
||||
|
||||
class NonClosableDialog : public QDialog {
|
||||
public:
|
||||
NonClosableDialog(QWidget *parent) : QDialog(parent) {
|
||||
}
|
||||
|
||||
void closeEvent(QCloseEvent *e) {
|
||||
e->ignore();
|
||||
}
|
||||
};
|
||||
|
||||
#endif // QTGUI_COMMON_H
|
||||
|
|
|
@ -1,30 +1,11 @@
|
|||
#include "ui_importdlg.h"
|
||||
#include "importdlg.h"
|
||||
#include "acknowledgmentdlg.h"
|
||||
#include "../converter/converter.h"
|
||||
#include "mainwindow.h"
|
||||
#include "locateresourcedlg.h"
|
||||
#include "sceneimporter.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;
|
||||
};
|
||||
|
||||
ImportDialog::ImportDialog(QWidget *parent) :
|
||||
QDialog(parent, Qt::Sheet),
|
||||
ui(new Ui::ImportDialog) {
|
||||
ImportDialog::ImportDialog(QWidget *parent, FileResolver *resolver) :
|
||||
QDialog(parent, Qt::Sheet), ui(new Ui::ImportDialog), m_resolver(resolver) {
|
||||
ui->setupUi(this);
|
||||
connect(ui->sceneEdit, SIGNAL(textChanged(const QString &)),
|
||||
this, SLOT(refresh()));
|
||||
|
@ -102,13 +83,13 @@ void ImportDialog::refresh() {
|
|||
|
||||
void ImportDialog::accept() {
|
||||
QDialog::accept();
|
||||
|
||||
QString sourceFile = ui->inputEdit->text();
|
||||
|
||||
QString directory = ui->directoryEdit->text();
|
||||
QString targetScene = ui->sceneEdit->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->setWindowTitle("Converting ..");
|
||||
QVBoxLayout *layout = new QVBoxLayout(dialog);
|
||||
|
@ -121,24 +102,29 @@ void ImportDialog::accept() {
|
|||
dialog->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();
|
||||
importingThread->wait(20);
|
||||
}
|
||||
importingThread->join();
|
||||
|
||||
GUIGeometryConverter cvt(this);
|
||||
cvt.setSRGB(ui->sRGBButton->isChecked());
|
||||
|
||||
try {
|
||||
cvt.convert(sourceFile.toStdString(), directory.toStdString(),
|
||||
targetScene.toStdString(), adjustmentFile.toStdString());
|
||||
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());
|
||||
dialog->hide();
|
||||
delete dialog;
|
||||
|
||||
if (importingThread->getResult().length() > 0)
|
||||
((MainWindow *) parent())->loadFile(QString(importingThread->getResult().c_str()));
|
||||
else
|
||||
QMessageBox::critical(this, tr("Scene Import"),
|
||||
tr("Conversion failed -- please see the log for details."),
|
||||
QMessageBox::Ok);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,7 +10,7 @@ namespace Ui {
|
|||
class ImportDialog : public QDialog {
|
||||
Q_OBJECT
|
||||
public:
|
||||
ImportDialog(QWidget *parent);
|
||||
ImportDialog(QWidget *parent, FileResolver *resolver);
|
||||
~ImportDialog();
|
||||
public slots:
|
||||
void accept();
|
||||
|
@ -23,6 +23,7 @@ protected:
|
|||
void changeEvent(QEvent *e);
|
||||
private:
|
||||
Ui::ImportDialog *ui;
|
||||
ref<FileResolver> m_resolver;
|
||||
};
|
||||
|
||||
#endif // __IMPORTDLG_H
|
||||
|
|
|
@ -27,16 +27,6 @@
|
|||
#include "previewsettingsdlg.h"
|
||||
#endif
|
||||
|
||||
class NonClosableDialog : public QDialog {
|
||||
public:
|
||||
NonClosableDialog(QWidget *parent) : QDialog(parent) {
|
||||
}
|
||||
|
||||
void closeEvent(QCloseEvent *e) {
|
||||
e->ignore();
|
||||
}
|
||||
};
|
||||
|
||||
class ProgramVersion {
|
||||
public:
|
||||
ProgramVersion(const QString &versionString) {
|
||||
|
@ -431,7 +421,12 @@ void MainWindow::onBugReportSubmitted() {
|
|||
}
|
||||
|
||||
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);
|
||||
connect(dialog, SIGNAL(finished(int)), this, SLOT(onImportDialogClose(int)));
|
||||
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