16 float x()
const {
return f[0]; }
17 float y()
const {
return f[1]; }
18 float z()
const {
return f[2]; }
26 float x()
const {
return f[0]; }
27 float y()
const {
return f[1]; }
31 typedef std::array<point3d, 4>
object;
47 static void render_line(
const std::vector<pixel>&
line,
int color_code);
50 int main(
int argc,
char * argv[])
try 52 std::cout <<
"Waiting for device..." << std::endl;
66 const int fisheye_sensor_idx = 1;
74 std::cout <<
"Device got. Streaming data" << std::endl;
77 window app(intrinsics.
width, intrinsics.
height,
"Intel RealSense T265 Augmented Reality Example");
84 const float length = 0.20f;
85 const object virtual_object = {{
95 bool object_pose_in_world_initialized =
false;
119 if (!object_pose_in_world_initialized)
122 object_pose_in_world_initialized =
true;
133 object object_in_sensor;
134 for (
size_t i = 0;
i < object_in_device.size(); ++
i)
139 for (
size_t i = 1;
i < object_in_sensor.size(); ++
i)
142 std::vector<point3d> points_in_sensor =
raster_line(object_in_sensor[0], object_in_sensor[
i], 0.01
f);
143 std::vector<pixel> projected_line;
144 projected_line.reserve(points_in_sensor.size());
145 for (
auto&
point : points_in_sensor)
151 projected_line.emplace_back();
160 render_text(static_cast<int>(app.
height()),
"Press spacebar to reset the pose of the virtual object. Press ESC to exit");
168 std::cout <<
"Setting new pose for virtual object: " << object_pose_in_world.
translation << std::endl;
184 catch (
const std::exception& e)
219 return object_pose_in_world;
246 a.
x * b.
w + a.
w * b.
x - a.
z * b.
y + a.
y * b.
z,
247 a.
y * b.
w + a.
z * b.
x + a.
w * b.
y - a.
x * b.
z,
248 a.
z * b.
w - a.
y * b.
x + a.
x * b.
y + a.
w * b.
z,
249 a.
w * b.
w - a.
x * b.
x - a.
y * b.
y - a.
z * b.
z,
277 object transformed_obj;
278 for (
size_t i = 0;
i < obj.size(); ++
i) {
281 transformed_obj[
i].f[0] =
v.x;
282 transformed_obj[
i].f[1] =
v.y;
283 transformed_obj[
i].f[2] =
v.z;
285 return transformed_obj;
291 float distance = std::sqrt(direction.
x*direction.
x + direction.
y*direction.
y + direction.
z*direction.
z);
292 int npoints =
static_cast<int>(distance / step + 1);
294 std::vector<point3d>
points;
301 points.reserve(npoints);
302 points.emplace_back(a);
303 for (
int i = 1;
i < npoints; ++
i)
305 points.emplace_back(a.
x() + direction.
x *
i,
306 a.
y() + direction.
y *
i,
307 a.
z() + direction.
z *
i);
322 color_code == 2 ? 1.f : 0.f,
323 color_code == 3 ? 1.f : 0.f);
326 for (
auto&
pixel : line)
342 draw_text(15, (win_height - 10) / 2, text.c_str());
frameset wait_for_frames(unsigned int timeout_ms=RS2_DEFAULT_TIMEOUT) const
static void render_text(int win_height, const std::string &text)
static rs2_pose identity_pose()
static void rs2_transform_point_to_point(float to_point[3], const struct rs2_extrinsics *extrin, const float from_point[3])
GLboolean GLboolean GLboolean b
void render(const rs2::frame &frame, const rect &rect, float alpha=1.f)
point3d(float x, float y, float z)
static rs2_vector quaternion_rotate_vector(const rs2_quaternion &q, const rs2_vector &v)
int main(int argc, char *argv[])
static object convert_object_coordinates(const object &obj, const rs2_pose &object_pose)
static rs2_pose pose_multiply(const rs2_pose &ref2_in_ref1, const rs2_pose &ref3_in_ref2)
rs2_extrinsics get_extrinsics_to(const stream_profile &to) const
GLsizei const GLchar *const * string
GLsizei GLsizei GLfloat distance
rs2_pose get_pose_data() const
::realsense_legacy_msgs::pose_< std::allocator< void > > pose
GLboolean GLboolean GLboolean GLboolean a
Quaternion used to represent rotation.
const std::string & get_failed_args() const
static rs2_vector vector_addition(const rs2_vector &a, const rs2_vector &b)
stream_profile get_stream(rs2_stream stream_type, int stream_index=-1) const
static void render_line(const std::vector< pixel > &line, int color_code)
static std::vector< point3d > raster_line(const point3d &a, const point3d &b, float step)
void enable_stream(rs2_stream stream_type, int stream_index, int width, int height, rs2_format format=RS2_FORMAT_ANY, int framerate=0)
std::array< point3d, 4 > object
static rs2_pose reset_object_pose(const rs2_pose &device_pose_in_world=identity_pose())
Cross-stream extrinsics: encodes the topology describing how the different devices are oriented...
3D vector in Euclidean coordinate space
static void rs2_project_point_to_pixel(float pixel[2], const struct rs2_intrinsics *intrin, const float point[3])
GLdouble GLdouble GLdouble q
static rs2_vector vector_negate(const rs2_vector &v)
void draw_text(int x, int y, const char *text)
static rs2_quaternion quaternion_conjugate(const rs2_quaternion &q)
GLenum GLuint GLenum GLsizei length
static rs2_pose pose_inverse(const rs2_pose &p)
static rs2_quaternion quaternion_multiply(const rs2_quaternion &a, const rs2_quaternion &b)
const std::string & get_failed_function() const
GLdouble GLdouble GLint GLint const GLdouble * points
static rs2_vector pose_transform_point(const rs2_pose &pose, const rs2_vector &p)