void playback_sensor::register_sensor_options(const device_serializer::sensor_snapshot& sensor_snapshot)
{
    auto options_snapshot = sensor_snapshot.get_sensor_extensions_snapshots().find(RS2_EXTENSION_OPTIONS);
    if (options_snapshot == nullptr)
    {
        LOG_WARNING("Recorded file does not contain sensor options");
        return;
    }
    auto options_api = As<options_interface>(options_snapshot);
    if (options_api == nullptr)
    {
        throw invalid_value_exception("Failed to get options interface from sensor snapshots");
    }

    for (int i = 0; i < static_cast<int>(RS2_OPTION_COUNT); i++)
    {
        auto option_id = static_cast<rs2_option>(i);
        try
        {
            if (options_api->supports_option(option_id))
            {
                auto&& option = options_api->get_option(option_id);
                float value = option.query();
                register_option(option_id, std::make_shared<const_value_option>(option.get_description(), option.query()));
                LOG_DEBUG("Registered " << rs2_option_to_string(option_id) << " for sensor " << m_sensor_id << " with value: " << option.query());
            }
        }
        catch (std::exception& e)
        {
            LOG_WARNING("Failed to register option " << option_id << ". Exception: " << e.what());
        }
    }
}
 bool software_sensor::extend_to(rs2_extension extension_type, void ** ptr)
 {
     if (extension_type == RS2_EXTENSION_DEPTH_SENSOR)
     {
         if (supports_option(RS2_OPTION_DEPTH_UNITS))
         {
             *ptr = &(*_stereo_extension);
             return true;
         }
     }
     else if (extension_type == RS2_EXTENSION_DEPTH_STEREO_SENSOR)
     {
         if (supports_option(RS2_OPTION_DEPTH_UNITS) && 
             supports_option(RS2_OPTION_STEREO_BASELINE))
         {
             *ptr = &(*_stereo_extension);
             return true;
         }
     }
     return false;
 }
Example #3
0
int rs_device_supports_option(const rs_device * device, rs_option option, rs_error ** error) try
{
    VALIDATE_NOT_NULL(device);
    VALIDATE_ENUM(option);
    return device->supports_option(option);
}
Example #4
0
int main(int argc, char * argv[]) try
{
    rs::log_to_console(rs::log_severity::warn);
    //rs::log_to_file(rs::log_severity::debug, "librealsense.log");

    rs::context ctx;
    if(ctx.get_device_count() == 0) throw std::runtime_error("No device detected. Is it plugged in?");
    rs::device & dev = *ctx.get_device(0);

    dev.enable_stream(rs::stream::depth, rs::preset::best_quality);
    dev.enable_stream(rs::stream::color, rs::preset::best_quality);
    dev.enable_stream(rs::stream::infrared, rs::preset::best_quality);
    try {
        dev.enable_stream(rs::stream::infrared2, 0, 0, rs::format::any, 0);
    }
    catch(...) {}

    // Compute field of view for each enabled stream
    for(int i = 0; i < 4; ++i)
    {
        auto stream = rs::stream(i);
        if(!dev.is_stream_enabled(stream)) continue;
        auto intrin = dev.get_stream_intrinsics(stream);
        std::cout << "Capturing " << stream << " at " << intrin.width << " x " << intrin.height;
        std::cout << std::setprecision(1) << std::fixed << ", fov = " << intrin.hfov() << " x " << intrin.vfov() << ", distortion = " << intrin.model() << std::endl;
    }

    // Start our device
    dev.start();

    // For the libuvc backend, this sleep is required before touching any of the camera
    // options after a device has been .start()'d
    std::this_thread::sleep_for(std::chrono::milliseconds(1000));

    // Report the status of each supported option
    /*for(int i = 0; i < RS_OPTION_COUNT; ++i)
    {
        auto option = rs::option(i);
        if(dev.supports_option(option))
        {
            std::cout << "Option " << option << ": ";
            try { std::cout << dev.get_option(option) << std::endl; }
            catch(const std::exception & e) { std::cout << e.what() << std::endl; }
        }
    }*/

    // Open a GLFW window
    glfwInit();
    std::ostringstream ss;
    ss << "CPP Capture Example (" << dev.get_name() << ")";
    GLFWwindow * win = glfwCreateWindow(1280, 960, ss.str().c_str(), 0, 0);
    glfwSetWindowUserPointer(win, &dev);
    glfwSetKeyCallback(win, [](GLFWwindow * win, int key, int scancode, int action, int mods)
    {
        auto dev = reinterpret_cast<rs::device *>(glfwGetWindowUserPointer(win));
        if(action != GLFW_RELEASE) switch(key)
            {
            case GLFW_KEY_R:
                color_rectification_enabled = !color_rectification_enabled;
                break;
            case GLFW_KEY_C:
                align_color_to_depth = !align_color_to_depth;
                break;
            case GLFW_KEY_D:
                align_depth_to_color = !align_depth_to_color;
                break;
            case GLFW_KEY_E:
                if(dev->supports_option(rs::option::r200_emitter_enabled))
                {
                    int value = !dev->get_option(rs::option::r200_emitter_enabled);
                    std::cout << "Setting emitter to " << value << std::endl;
                    dev->set_option(rs::option::r200_emitter_enabled, value);
                }
                break;
            case GLFW_KEY_A:
                if(dev->supports_option(rs::option::r200_lr_auto_exposure_enabled))
                {
                    int value = !dev->get_option(rs::option::r200_lr_auto_exposure_enabled);
                    std::cout << "Setting auto exposure to " << value << std::endl;
                    dev->set_option(rs::option::r200_lr_auto_exposure_enabled, value);
                }
                break;
            }
    });
    glfwMakeContextCurrent(win);

    while (!glfwWindowShouldClose(win))
    {
        // Wait for new images
        glfwPollEvents();
        dev.wait_for_frames();

        // Clear the framebuffer
        int w,h;
        glfwGetFramebufferSize(win, &w, &h);
        glViewport(0, 0, w, h);
        glClear(GL_COLOR_BUFFER_BIT);

        // Draw the images
        glPushMatrix();
        glfwGetWindowSize(win, &w, &h);
        glOrtho(0, w, h, 0, -1, +1);
        buffers[0].show(dev, align_color_to_depth ? rs::stream::color_aligned_to_depth : (color_rectification_enabled ? rs::stream::rectified_color : rs::stream::color), 0, 0, w/2, h/2);
        buffers[1].show(dev, align_depth_to_color ? (color_rectification_enabled ? rs::stream::depth_aligned_to_rectified_color : rs::stream::depth_aligned_to_color) : rs::stream::depth, w/2, 0, w-w/2, h/2);
        buffers[2].show(dev, rs::stream::infrared, 0, h/2, w/2, h-h/2);
        buffers[3].show(dev, rs::stream::infrared2, w/2, h/2, w-w/2, h-h/2);
        glPopMatrix();
        glfwSwapBuffers(win);
    }

    glfwDestroyWindow(win);
    glfwTerminate();
    return EXIT_SUCCESS;
}
catch(const rs::error & e)
{
    std::cerr << "RealSense error calling " << e.get_failed_function() << "(" << e.get_failed_args() << "):\n    " << e.what() << std::endl;
    return EXIT_FAILURE;
}
catch(const std::exception & e)
{
    std::cerr << e.what() << std::endl;
    return EXIT_FAILURE;
}