Exemple #1
0
int main(int argc, char** argv) {
    int ret = -1;
    {
        // scope for ivw app
        inviwo::LogCentral::init();
        inviwo::LogCentral::getPtr()->registerLogger(new inviwo::ConsoleLogger());

        // Search for directory containing data folder to find application basepath.
        // Working directory will be used if data folder is not found in parent directories.
        std::string basePath = inviwo::filesystem::findBasePath();
        InviwoApplication app(argc, argv, "unittest " + IVW_VERSION, basePath);

        if (!glfwInit()) {
            LogErrorCustom("Inviwo Unit Tests Application", "GLFW could not be initialized.");
            return 0;
        }

        // Initialize all modules
        app.initialize(&inviwo::registerAllModules);

        // Continue initialization of default context
        CanvasGLFW* sharedCanvas = static_cast<CanvasGLFW*>(RenderContext::getPtr()->getDefaultRenderContext());
        sharedCanvas->initialize();
        sharedCanvas->activate();

        ret = inviwo::UnitTestsModule::runAllTests();

        app.getProcessorNetwork()->clear();
        sharedCanvas->deinitialize();
        app.closeInviwoApplication();
        glfwTerminate();
    }

    return ret;
}
Exemple #2
0
int main(int argc, char** argv) {
    LogCentral::init();
    LogCentral::getPtr()->registerLogger(new ConsoleLogger());

    InviwoApplication inviwoApp(argc, argv, "Inviwo v" + IVW_VERSION + " - GLFWApp",
                                inviwo::filesystem::findBasePath());
    inviwoApp.setPostEnqueueFront([]() { glfwPostEmptyEvent(); });

    CanvasGLFW::setAlwaysOnTopByDefault(false);

    // Initialize all modules
    inviwoApp.initialize(&inviwo::registerAllModules);

    // Continue initialization of default context
    CanvasGLFW* sharedCanvas =
        static_cast<CanvasGLFW*>(RenderContext::getPtr()->getDefaultRenderContext());
    sharedCanvas->initialize();
    sharedCanvas->activate();

    // Load simple scene
    inviwoApp.getProcessorNetwork()->lock();
    const CommandLineParser* cmdparser = inviwoApp.getCommandLineParser();
    const std::string workspace =
        cmdparser->getLoadWorkspaceFromArg()
            ? cmdparser->getWorkspacePath()
            : inviwoApp.getPath(InviwoApplication::PATH_WORKSPACES, "/boron.inv");

    std::vector<std::unique_ptr<ProcessorWidget>> widgets;
    try {
        if (!workspace.empty()) {
            Deserializer xmlDeserializer(workspace);
            inviwoApp.getProcessorNetwork()->deserialize(xmlDeserializer);
            std::vector<Processor*> processors = inviwoApp.getProcessorNetwork()->getProcessors();

            for (auto processor : processors) {
                processor->invalidate(InvalidationLevel::InvalidResources);
                if (auto processorWidget = ProcessorWidgetFactory::getPtr()->create(processor)) {
                    processorWidget->setProcessor(processor);
                    processorWidget->initialize();
                    processorWidget->setVisible(processorWidget->ProcessorWidget::isVisible());
                    processor->setProcessorWidget(processorWidget.get());
                    widgets.push_back(std::move(processorWidget));
                }
            }
        }
    } catch (const AbortException& exception) {
        util::log(exception.getContext(),
                  "Unable to load network " + workspace + " due to " + exception.getMessage(),
                  LogLevel::Error);
        return 1;
    } catch (const IgnoreException& exception) {
        util::log(exception.getContext(),
                  "Incomplete network loading " + workspace + " due to " + exception.getMessage(),
                  LogLevel::Error);
        return 1;
    } catch (const ticpp::Exception& exception) {
        LogErrorCustom("glfwminimum", "Unable to load network " + workspace +
                                          " due to deserialization error: " + exception.what());
        return 1;
    }

    inviwoApp.getProcessorNetwork()->setModified(true);
    inviwoApp.getProcessorNetwork()->unlock();

    if (cmdparser->getCaptureAfterStartup()) {
        std::string path = cmdparser->getOutputPath();
        if (path.empty()) path = inviwoApp.getPath(InviwoApplication::PATH_IMAGES);

        util::saveAllCanvases(inviwoApp.getProcessorNetwork(), path, cmdparser->getSnapshotName());
    }

    if (cmdparser->getQuitApplicationAfterStartup()) {
        glfwTerminate();
        return 0;
    }

    while (CanvasGLFW::getWindowCount() > 0) {
        glfwWaitEvents();
        inviwoApp.processFront();
    }

    inviwoApp.deinitialize();

    return 0;
}