예제 #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;
}
예제 #2
0
void CanvasGLFW::keyboard(GLFWwindow* window, int key, int scancode, int action, int mods) {
    if (key == GLFW_KEY_ESCAPE && action == GLFW_PRESS) {
        // glfwSetWindowShouldClose(window, GL_TRUE);
        glfwTerminate();
        exit(0);
        return;
    }

    CanvasGLFW* thisCanvas = getCanvasGLFW(window);

    KeyboardEvent keyEvent(toupper(key), KeyboardEvent::MODIFIER_NONE,
                           KeyboardEvent::KEY_STATE_PRESS);

    thisCanvas->keyPressEvent(&keyEvent);
}
예제 #3
0
void CanvasGLFW::scroll(GLFWwindow* window, double xoffset, double yoffset) {
    CanvasGLFW* thisCanvas = getCanvasGLFW(window);
    thisCanvas->mouseButton_ = MouseEvent::MOUSE_BUTTON_MIDDLE;
    thisCanvas->mouseState_ = MouseEvent::MOUSE_STATE_WHEEL;
    thisCanvas->mouseModifiers_ = KeyboardEvent::MODIFIER_NONE;
    double x;
    double y;
    glfwGetCursorPos(window, &x, &y);
    ivec2 screenPos(floor(x), floor(y));
    ivec2 screenPosInvY(screenPos.x,
                        static_cast<int>(thisCanvas->getScreenDimensions().y) - 1 - screenPos.y);
    int delta = static_cast<int>(yoffset < 0.0 ? floor(yoffset) : ceil(yoffset));

    MouseEvent mouseEvent(screenPos, delta, thisCanvas->mouseButton_, thisCanvas->mouseState_,
                          MouseEvent::MOUSE_WHEEL_VERTICAL, thisCanvas->mouseModifiers_,
                          thisCanvas->getScreenDimensions(),
                          thisCanvas->getDepthValueAtCoord(screenPosInvY));

    thisCanvas->mouseWheelEvent(&mouseEvent);
}
예제 #4
0
void CanvasGLFW::mouseMotion(GLFWwindow* window, double x, double y) {
    CanvasGLFW* thisCanvas = getCanvasGLFW(window);
    ivec2 screenPos(floor(x), floor(y));
    ivec2 screenPosInvY(screenPos.x,
                        static_cast<int>(thisCanvas->getScreenDimensions().y) - 1 - screenPos.y);

    MouseEvent::MouseState state =
        (thisCanvas->mouseState_ == MouseEvent::MOUSE_STATE_PRESS ? MouseEvent::MOUSE_STATE_MOVE
                                                                  : thisCanvas->mouseState_);
    MouseEvent mouseEvent(screenPos, thisCanvas->mouseButton_, state, thisCanvas->mouseModifiers_,
                          thisCanvas->getScreenDimensions(),
                          thisCanvas->getDepthValueAtCoord(screenPosInvY));

    if (state == MouseEvent::MOUSE_STATE_MOVE)
        thisCanvas->mouseMoveEvent(&mouseEvent);
    else if (state == MouseEvent::MOUSE_STATE_RELEASE)
        thisCanvas->mouseReleaseEvent(&mouseEvent);
}
예제 #5
0
void CanvasGLFW::mouseButton(GLFWwindow* window, int button, int action, int mods) {
    CanvasGLFW* thisCanvas = getCanvasGLFW(window);
    thisCanvas->mouseButton_ = mapMouseButton(button);
    thisCanvas->mouseState_ = mapMouseState(action);
    thisCanvas->mouseModifiers_ = mapModifiers(mods);
    double x;
    double y;
    glfwGetCursorPos(window, &x, &y);
    ivec2 screenPos(floor(x), floor(y));
    ivec2 screenPosInvY(screenPos.x,
                        static_cast<int>(thisCanvas->getScreenDimensions().y) - 1 - screenPos.y);
    MouseEvent mouseEvent(screenPos, thisCanvas->mouseButton_, thisCanvas->mouseState_,
                          thisCanvas->mouseModifiers_, thisCanvas->getScreenDimensions(),
                          thisCanvas->getDepthValueAtCoord(screenPosInvY));

    if (thisCanvas->mouseState_ == MouseEvent::MOUSE_STATE_PRESS)
        thisCanvas->mousePressEvent(&mouseEvent);
    else if (thisCanvas->mouseState_ == MouseEvent::MOUSE_STATE_RELEASE)
        thisCanvas->mouseReleaseEvent(&mouseEvent);
}
예제 #6
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;
}