mtsgui: handle the -o parameter

metadata
Wenzel Jakob 2014-10-18 22:38:04 +02:00
parent d5208828de
commit 84685dfc8d
5 changed files with 24 additions and 14 deletions

View File

@ -48,8 +48,8 @@
#if defined(__WINDOWS__) #if defined(__WINDOWS__)
// Always use the High Performance GPU on machines using NVIDIA Optimus // Always use the High Performance GPU on machines using NVIDIA Optimus
// http://stackoverflow.com/questions/10535950/forcing-nvidia-gpu-programmatically-in-optimus-laptops [January 2014] // http://stackoverflow.com/questions/10535950/forcing-nvidia-gpu-programmatically-in-optimus-laptops [January 2014]
extern "C" { extern "C" {
_declspec(dllexport) DWORD NvOptimusEnablement = 0x00000001; _declspec(dllexport) DWORD NvOptimusEnablement = 0x00000001;
} }
#endif #endif

View File

@ -264,9 +264,11 @@ MainWindow::~MainWindow() {
bool MainWindow::initWorkersProcessArgv() { bool MainWindow::initWorkersProcessArgv() {
QSettings settings; QSettings settings;
QStringList args = qApp->arguments(), toBeLoaded; QStringList args = qApp->arguments();
std::vector<std::pair<QString, QString> > toBeLoaded;
int localWorkerCount = settings.value("localWorkers", getCoreCount()).toInt(); int localWorkerCount = settings.value("localWorkers", getCoreCount()).toInt();
ref<Scheduler> scheduler = Scheduler::getInstance(); ref<Scheduler> scheduler = Scheduler::getInstance();
QString outputFile("");
for (int i=1; i<args.count(); ++i) { for (int i=1; i<args.count(); ++i) {
if (args[i].startsWith("-D")) { if (args[i].startsWith("-D")) {
@ -282,6 +284,10 @@ bool MainWindow::initWorkersProcessArgv() {
if (value.length() == 0 && i+1<args.count()) if (value.length() == 0 && i+1<args.count())
value = args[++i]; value = args[++i];
resolver->appendPath(value.toStdString()); resolver->appendPath(value.toStdString());
} else if (args[i].startsWith("-o")) {
outputFile = args[i].mid(2);
if (outputFile.length() == 0 && i+1<args.count())
outputFile = args[++i];
} else if (args[i].startsWith("-p")) { } else if (args[i].startsWith("-p")) {
QString value = args[i].mid(2); QString value = args[i].mid(2);
if (value.length() == 0 && i+1<args.count()) if (value.length() == 0 && i+1<args.count())
@ -297,6 +303,7 @@ bool MainWindow::initWorkersProcessArgv() {
cout << "Options/Arguments:" << endl; cout << "Options/Arguments:" << endl;
cout << " -h Display this help text" << endl << endl; cout << " -h Display this help text" << endl << endl;
cout << " -D key=val Define a constant, which can referenced as \"$key\" in the scene" << endl << endl; cout << " -D key=val Define a constant, which can referenced as \"$key\" in the scene" << endl << endl;
cout << " -o fname Write the output image to the file denoted by \"fname\"" << endl << endl;
cout << " -a p1;p2;.. Add one or more entries to the resource search path" << endl << endl; cout << " -a p1;p2;.. Add one or more entries to the resource search path" << endl << endl;
cout << " -p count Override the detected number of processors." << endl << endl; cout << " -p count Override the detected number of processors." << endl << endl;
cout << " For documentation, please refer to http://www.mitsuba-renderer.org/docs.html" << endl; cout << " For documentation, please refer to http://www.mitsuba-renderer.org/docs.html" << endl;
@ -304,7 +311,8 @@ bool MainWindow::initWorkersProcessArgv() {
} else if (args[i].startsWith("-")) { } else if (args[i].startsWith("-")) {
cerr << "Unknown option \"" << args[i].toStdString() << "\"" << endl; cerr << "Unknown option \"" << args[i].toStdString() << "\"" << endl;
} else { } else {
toBeLoaded.append(args[i]); toBeLoaded.push_back(std::make_pair(args[i], outputFile));
outputFile = QString("");
} }
} }
@ -365,7 +373,7 @@ bool MainWindow::initWorkersProcessArgv() {
} }
for (int i=0; i<toBeLoaded.size(); ++i) for (int i=0; i<toBeLoaded.size(); ++i)
loadFile(toBeLoaded[i]); loadFile(toBeLoaded[i].first, toBeLoaded[i].second);
scheduler->start(); scheduler->start();
raise(); raise();
@ -657,7 +665,7 @@ void MainWindow::onClearRecent() {
settings.setValue("recentFileList", QStringList()); settings.setValue("recentFileList", QStringList());
} }
SceneContext *MainWindow::loadScene(const QString &qFileName) { SceneContext *MainWindow::loadScene(const QString &qFileName, const QString &destFile) {
ref<FileResolver> resolver = Thread::getThread()->getFileResolver(); ref<FileResolver> resolver = Thread::getThread()->getFileResolver();
fs::path filename = resolver->resolve(toFsPath(qFileName)); fs::path filename = resolver->resolve(toFsPath(qFileName));
fs::path filePath = fs::absolute(filename).parent_path(); fs::path filePath = fs::absolute(filename).parent_path();
@ -674,7 +682,7 @@ SceneContext *MainWindow::loadScene(const QString &qFileName) {
loaddlg->show(); loaddlg->show();
retry: retry:
loadingThread = new SceneLoader(newResolver, filename, m_parameters); loadingThread = new SceneLoader(newResolver, filename, toFsPath(destFile), m_parameters);
loadingThread->start(); loadingThread->start();
while (loadingThread->isRunning()) { while (loadingThread->isRunning()) {
@ -735,11 +743,11 @@ retry:
return result; return result;
} }
void MainWindow::loadFile(QString filename) { void MainWindow::loadFile(QString filename, const QString &destFile) {
QFileInfo fInfo(filename); QFileInfo fInfo(filename);
fInfo.makeAbsolute(); fInfo.makeAbsolute();
SceneContext *context = loadScene(filename); SceneContext *context = loadScene(filename, destFile);
if (context == NULL) if (context == NULL)
return; return;
m_contextMutex.lock(); m_contextMutex.lock();

View File

@ -117,13 +117,13 @@ class MainWindow : public QMainWindow {
public: public:
MainWindow(QWidget *parent = 0); MainWindow(QWidget *parent = 0);
~MainWindow(); ~MainWindow();
void loadFile(QString filename); void loadFile(QString filename, const QString &destFile = "");
void adjustSize(); void adjustSize();
bool isActive(); bool isActive();
bool initWorkersProcessArgv(); bool initWorkersProcessArgv();
protected: protected:
SceneContext *loadScene(const QString &filename); SceneContext *loadScene(const QString &filename, const QString &destFile = "");
void resizeEvent(QResizeEvent *event); void resizeEvent(QResizeEvent *event);
void changeEvent(QEvent *e); void changeEvent(QEvent *e);
void updateRecentFileActions(); void updateRecentFileActions();

View File

@ -32,8 +32,8 @@
XERCES_CPP_NAMESPACE_USE XERCES_CPP_NAMESPACE_USE
SceneLoader::SceneLoader(FileResolver *resolver, const fs::path &filename, SceneLoader::SceneLoader(FileResolver *resolver, const fs::path &filename,
const std::map<std::string, std::string, SimpleStringOrdering> &parameters) const fs::path &destFile, const std::map<std::string, std::string, SimpleStringOrdering> &parameters)
: Thread("load"), m_resolver(resolver), m_filename(fromFsPath(filename)), : Thread("load"), m_resolver(resolver), m_filename(fromFsPath(filename)), m_destFile(destFile),
m_parameters(parameters) { m_parameters(parameters) {
m_wait = new WaitFlag(); m_wait = new WaitFlag();
m_versionError = false; m_versionError = false;
@ -115,7 +115,7 @@ void SceneLoader::run() {
ref<Scene> scene = handler->getScene(); ref<Scene> scene = handler->getScene();
scene->setSourceFile(filename); scene->setSourceFile(filename);
scene->setDestinationFile(filePath / baseName); scene->setDestinationFile(m_destFile.empty() ? (filePath / baseName) : m_destFile);
scene->initialize(); scene->initialize();
if (scene->getIntegrator() == NULL) if (scene->getIntegrator() == NULL)

View File

@ -30,6 +30,7 @@ class SceneLoader : public Thread {
public: public:
SceneLoader(FileResolver *resolver, SceneLoader(FileResolver *resolver,
const fs::path &filename, const fs::path &filename,
const fs::path &destFile,
const std::map<std::string, std::string, SimpleStringOrdering> &parameters); const std::map<std::string, std::string, SimpleStringOrdering> &parameters);
void run(); void run();
@ -47,6 +48,7 @@ private:
SceneContext *m_result; SceneContext *m_result;
std::string m_error; std::string m_error;
const QString m_filename; const QString m_filename;
fs::path m_destFile;
bool m_versionError; bool m_versionError;
Version m_version; Version m_version;
const std::map<std::string, std::string, SimpleStringOrdering> &m_parameters; const std::map<std::string, std::string, SimpleStringOrdering> &m_parameters;