9 #define _USE_MATH_DEFINES 12 #include <unordered_set> 18 using pixel = std::pair<int, int>;
72 return static_cast<float>(pow(
x - other.
x, 2) + pow(
y - other.
y, 2));
83 bool mouse_down =
false;
100 int main(
int argc,
char * argv[])
try 158 app_state.ruler_end = { 0.55f, 0.5f };
165 std::atomic_bool alive{
true };
171 std::thread video_processing_thread([&]() {
202 postprocessed_frames.
enqueue(data);
213 if (current_frameset)
215 auto depth = current_frameset.get_depth_frame();
216 auto color = current_frameset.get_color_frame();
224 depth_image.
render(colorized_depth, { 0, 0, app.width(), app.height() });
228 color_image.
render(
color, { 0, 0, app.width(), app.height() });
234 app_state.ruler_start.render(app);
235 app_state.ruler_end.render(app);
244 video_processing_thread.join();
253 catch (
const std::exception& e)
268 upixel[0] =
static_cast<float>(u.first);
269 upixel[1] =
static_cast<float>(u.second);
270 vpixel[0] =
static_cast<float>(v.first);
271 vpixel[1] =
static_cast<float>(v.second);
278 auto udist = frame.
get_distance(static_cast<int>(upixel[0]), static_cast<int>(upixel[1]));
279 auto vdist = frame.
get_distance(static_cast<int>(vpixel[0]), static_cast<int>(vpixel[1]));
287 return sqrt(pow(upoint[0] - vpoint[0], 2.
f) +
288 pow(upoint[1] - vpoint[1], 2.
f) +
289 pow(upoint[2] - vpoint[2], 2.
f));
331 float air_dist =
dist_3d(depth, from_pixel, to_pixel);
333 center.first = (from_pixel.first + to_pixel.first) / 2;
334 center.second = (from_pixel.second + to_pixel.second) / 2;
336 std::stringstream ss;
337 ss << int(air_dist * 100) <<
" cm";
371 std::vector<toggle*> toggles{
377 toggle* best = toggles.front();
378 for (
auto&&
t : toggles)
380 if (
t->dist_2d(cursor) < best->
dist_2d(cursor))
389 for (
auto&&
t : toggles)
t->selected =
false;
392 for (
auto&&
t : toggles)
394 if (
t->selected) *
t = cursor;
float dist_3d(const rs2::depth_frame &frame, pixel u, pixel v)
frame apply_filter(filter_interface &filter)
std::function< void(bool)> on_left_mouse
void render(const rs2::frame &frame, const rect &rect, float alpha=1.f)
void render_circle(const window &app, float r)
#define GL_TRIANGLE_STRIP
std::enable_if< std::is_base_of< rs2::frame, T >::value, bool >::type poll_for_frame(T *output) const
stream_profile get_profile() const
void enqueue(frame f) const
GLint GLint GLsizei GLsizei GLsizei depth
pixel get_pixel(rs2::depth_frame frm) const
void draw_line(float x0, float y0, float x1, float y1, int width)
GLdouble GLdouble GLdouble w
const std::string & get_failed_args() const
bool poll_for_frames(frameset *f) const
static void rs2_deproject_pixel_to_point(float point[3], const struct rs2_intrinsics *intrin, const float pixel[2], float depth)
void render(const window &app)
void register_glfw_callbacks(window &app, state &app_state)
float dist_2d(const toggle &other) const
void enable_stream(rs2_stream stream_type, int stream_index, int width, int height, rs2_format format=RS2_FORMAT_ANY, int framerate=0)
#define GL_ONE_MINUS_SRC_ALPHA
GLuint GLfloat GLfloat GLfloat x1
float get_distance(int x, int y) const
static int stb_easy_font_width(char *text)
void draw_text(int x, int y, const char *text)
GLuint GLfloat GLfloat y0
int main(int argc, char *argv[])
toggle(float xl, float yl)
std::function< void(double, double)> on_mouse_move
void set_option(rs2_option option, float value) const
const std::string & get_failed_function() const
void render_simple_distance(const rs2::depth_frame &depth, const state &s, const window &app)