rs-pointcloud.cpp
Go to the documentation of this file.
1 // License: Apache 2.0. See LICENSE file in root directory.
2 // Copyright(c) 2015-2017 Intel Corporation. All Rights Reserved.
3 
4 #include <librealsense2/rs.hpp> // Include RealSense Cross Platform API
5 #include "example.hpp" // Include short list of convenience functions for rendering
6 
7 #include <algorithm> // std::min, std::max
8 
9 // Helper functions
10 void register_glfw_callbacks(window& app, glfw_state& app_state);
11 
12 int main(int argc, char * argv[]) try
13 {
14  // Create a simple OpenGL window for rendering:
15  window app(1280, 720, "RealSense Pointcloud Example");
16  // Construct an object to manage view state
17  glfw_state app_state;
18  // register callbacks to allow manipulation of the pointcloud
19  register_glfw_callbacks(app, app_state);
20 
21  // Declare pointcloud object, for calculating pointclouds and texture mappings
23  // We want the points object to be persistent so we can display the last cloud when a frame drops
25 
26  // Declare RealSense pipeline, encapsulating the actual device and sensors
28  // Start streaming with default recommended configuration
29  pipe.start();
30 
31  while (app) // Application still alive?
32  {
33  // Wait for the next set of frames from the camera
34  auto frames = pipe.wait_for_frames();
35 
36  auto color = frames.get_color_frame();
37 
38  // For cameras that don't have RGB sensor, we'll map the pointcloud to infrared instead of color
39  if (!color)
40  color = frames.get_infrared_frame();
41 
42  // Tell pointcloud object to map to this color frame
43  pc.map_to(color);
44 
45  auto depth = frames.get_depth_frame();
46 
47  // Generate the pointcloud and texture mappings
48  points = pc.calculate(depth);
49 
50  // Upload the color frame to OpenGL
51  app_state.tex.upload(color);
52 
53  // Draw the pointcloud
54  draw_pointcloud(app.width(), app.height(), app_state, points);
55  }
56 
57  return EXIT_SUCCESS;
58 }
59 catch (const rs2::error & e)
60 {
61  std::cerr << "RealSense error calling " << e.get_failed_function() << "(" << e.get_failed_args() << "):\n " << e.what() << std::endl;
62  return EXIT_FAILURE;
63 }
64 catch (const std::exception & e)
65 {
66  std::cerr << e.what() << std::endl;
67  return EXIT_FAILURE;
68 }
frameset wait_for_frames(unsigned int timeout_ms=RS2_DEFAULT_TIMEOUT) const
GLuint color
GLint GLint GLsizei GLsizei GLsizei depth
void map_to(frame mapped)
e
Definition: rmse.py:177
const std::string & get_failed_args() const
Definition: rs_types.hpp:117
float width() const
Definition: example.hpp:627
void upload(const rs2::video_frame &frame)
Definition: example.hpp:406
points calculate(frame depth) const
int main(int argc, char *argv[])
float height() const
Definition: example.hpp:628
void draw_pointcloud(float width, float height, glfw_state &app_state, rs2::points &points)
Definition: example.hpp:886
void register_glfw_callbacks(window &app, glfw_state &app_state)
Definition: example.hpp:1037
std::ostream & cerr()
pipeline_profile start()
texture tex
Definition: example.hpp:882
const std::string & get_failed_function() const
Definition: rs_types.hpp:112
GLdouble GLdouble GLint GLint const GLdouble * points


librealsense2
Author(s): Sergey Dorodnicov , Doron Hirshberg , Mark Horn , Reagan Lopez , Itay Carpis
autogenerated on Mon May 3 2021 02:47:40