cpp-alignimages.cpp
Go to the documentation of this file.
1 // License: Apache 2.0. See LICENSE file in root directory.
2 // Copyright(c) 2015 Intel Corporation. All Rights Reserved.
3 
4 #include <librealsense/rs.hpp>
5 #include "example.hpp"
6 
7 #include <sstream>
8 #include <iostream>
9 #include <iomanip>
10 #include <thread>
11 
13 
14 #pragma pack(push, 1)
15 struct rgb_pixel
16 {
17  uint8_t r,g,b;
18 };
19 #pragma pack(pop)
20 
21 int main(int argc, char * argv[]) try
22 {
24  //rs::log_to_file(rs::log_severity::debug, "librealsense.log");
25 
27  if(ctx.get_device_count() == 0) throw std::runtime_error("No device detected. Is it plugged in?");
28  rs::device & dev = *ctx.get_device(0);
29 
33  dev.start();
34 
35  // Open a GLFW window
36  glfwInit();
37  std::ostringstream ss; ss << "CPP Image Alignment Example (" << dev.get_name() << ")";
38  GLFWwindow * win = glfwCreateWindow(dev.is_stream_enabled(rs::stream::infrared2) ? 1920 : 1280, 960, ss.str().c_str(), 0, 0);
40 
41  while (!glfwWindowShouldClose(win))
42  {
43  // Wait for new images
45  dev.wait_for_frames();
46 
47  // Clear the framebuffer
48  int w,h;
49  glfwGetFramebufferSize(win, &w, &h);
50  glViewport(0, 0, w, h);
51  glClear(GL_COLOR_BUFFER_BIT);
52 
53  // Draw the images
54  glPushMatrix();
55  glfwGetWindowSize(win, &w, &h);
56  glOrtho(0, w, h, 0, -1, +1);
57  int s = w / (dev.is_stream_enabled(rs::stream::infrared2) ? 3 : 2);
58  buffers[0].show(dev, rs::stream::color, 0, 0, s, h-h/2);
59  buffers[1].show(dev, rs::stream::color_aligned_to_depth, s, 0, s, h-h/2);
60  buffers[2].show(dev, rs::stream::depth_aligned_to_color, 0, h/2, s, h-h/2);
61  buffers[3].show(dev, rs::stream::depth, s, h/2, s, h-h/2);
63  {
64  buffers[4].show(dev, rs::stream::infrared2_aligned_to_depth, 2*s, 0, s, h-h/2);
65  buffers[5].show(dev, rs::stream::depth_aligned_to_infrared2, 2*s, h/2, s, h-h/2);
66  }
67  glPopMatrix();
68  glfwSwapBuffers(win);
69  }
70 
71  glfwDestroyWindow(win);
72  glfwTerminate();
73  return EXIT_SUCCESS;
74 }
75 catch(const rs::error & e)
76 {
77  std::cerr << "RealSense error calling " << e.get_failed_function() << "(" << e.get_failed_args() << "):\n " << e.what() << std::endl;
78  return EXIT_FAILURE;
79 }
80 catch(const std::exception & e)
81 {
82  std::cerr << e.what() << std::endl;
83  return EXIT_FAILURE;
84 }
void log_to_console(log_severity min_severity)
Definition: rs.hpp:1104
Provides convenience methods relating to devices.
Definition: rs.hpp:567
void enable_stream(stream stream, int width, int height, format format, int framerate, output_buffer_format output_buffer_type=output_buffer_format::continous)
Enables specific stream and requests specific properties.
Definition: rs.hpp:704
GLFWAPI void glfwGetWindowSize(GLFWwindow *window, int *width, int *height)
Retrieves the size of the client area of the specified window.
Definition: window.c:456
const std::string & get_failed_args() const
Definition: rs.hpp:315
rs_error * e
const GLuint * buffers
Definition: glext.h:529
Exposes librealsense functionality for C++ compilers.
GLfloat GLfloat GLfloat GLfloat h
Definition: glext.h:1944
struct GLFWwindow GLFWwindow
Opaque window object.
Definition: glfw3.h:722
GLFWAPI int glfwInit(void)
Initializes the GLFW library.
void show(float rx, float ry, float rw, float rh) const
Definition: example.hpp:189
bool is_stream_enabled(stream stream) const
Determines if specific stream is enabled.
Definition: rs.hpp:733
Context.
Definition: rs.hpp:319
const char * get_name() const
Retrieves human-readable device model string.
Definition: rs.hpp:578
void start(rs::source source=rs::source::video)
Begins streaming on all enabled streams for this device.
Definition: rs.hpp:879
GLFWAPI void glfwSwapBuffers(GLFWwindow *window)
Swaps the front and back buffers of the specified window.
Definition: context.c:544
GLFWAPI void glfwMakeContextCurrent(GLFWwindow *window)
Makes the context of the specified window current for the calling thread.
Definition: context.c:531
auto ctx
GLFWAPI GLFWwindow * glfwCreateWindow(int width, int height, const char *title, GLFWmonitor *monitor, GLFWwindow *share)
Creates a window and its associated context.
Definition: window.c:116
int main(int argc, char *argv[])
GLdouble s
Definition: glext.h:231
rs_device * dev
GLFWAPI void glfwDestroyWindow(GLFWwindow *window)
Destroys the specified window and its context.
Definition: window.c:369
GLFWAPI void glfwGetFramebufferSize(GLFWwindow *window, int *width, int *height)
Retrieves the size of the framebuffer of the specified window.
Definition: window.c:484
GLFWAPI void glfwTerminate(void)
Terminates the GLFW library.
GLFWAPI void glfwPollEvents(void)
Processes all pending events.
Definition: window.c:682
device * get_device(int index)
Definition: rs.hpp:354
const std::string & get_failed_function() const
Definition: rs.hpp:314
GLubyte GLubyte GLubyte GLubyte w
Definition: glext.h:726
void wait_for_frames()
Blocks until new frames are available.
Definition: rs.hpp:985
int get_device_count() const
Definition: rs.hpp:343
GLFWAPI int glfwWindowShouldClose(GLFWwindow *window)
Checks the close flag of the specified window.
Definition: window.c:406


librealsense
Author(s): Sergey Dorodnicov , Mark Horn , Reagan Lopez
autogenerated on Fri Mar 13 2020 03:16:16