30 std::map<int, int> parents;
41 auto vert = q.front();
44 for (
auto&& pair : edges)
47 if (pair.first == vert) next = pair.second;
48 if (pair.second == vert) next = pair.first;
49 if (next >= 0 && parents[next] == -1)
57 std::vector<int>
path;
60 if (parents[to] != -1)
81 if (
state.points.size() >= 2 && !shift)
85 state.polygons.clear();
88 int last = int(
state.points.size());
92 state.points.push_back(p);
103 if (
state.edges.size())
110 std::vector<float3> poly;
118 if (
state.points.size() >= 2)
121 state.edges.push_back(std::make_pair(last, prev));
133 return to_string() << std::setprecision(2) << area <<
" m";
141 if (distance < 0.01
f)
143 label =
to_string() << std::setprecision(3) << distance * 1000.f <<
" mm";
144 }
else if (distance < 1.
f) {
145 label =
to_string() << std::setprecision(3) << distance * 100.f <<
" cm";
147 label =
to_string() << std::setprecision(3) << distance <<
" m";
151 if (distance < 0.0254
f)
153 label =
to_string() << std::setprecision(3) << distance * 1000.f <<
" mm";
154 }
else if (distance < 0.3048
f) {
155 label =
to_string() << std::setprecision(3) << distance / 0.0254 <<
" in";
156 }
else if (distance < 0.9144) {
157 label =
to_string() << std::setprecision(3) << distance / 0.3048f <<
" ft";
159 label =
to_string() << std::setprecision(3) << distance / 0.9144 <<
" yd";
167 if (poly.size() < 3)
return 0.
f;
169 float3 total{ 0.f, 0.f, 0.f };
171 for (
int i = 0;
i < poly.size();
i++)
174 auto v2 = poly[(
i+1) % poly.size()];
176 total = total + prod;
179 auto a = poly[1] - poly[0];
180 auto b = poly[2] - poly[0];
182 return abs(total *
n.normalize()) / 2;
187 for(
int i = 0;
i <= lats;
i++)
189 float lat0 = float(M_PI) * (-0.5f + (float) (
i - 1) / lats);
190 float z0 = sin(lat0);
191 float zr0 = cos(lat0);
193 float lat1 = float(M_PI) * (-0.5f + (float)
i / lats);
194 float z1 = sin(lat1);
195 float zr1 = cos(lat1);
198 for(
int j = 0;
j <= longs;
j++)
200 float lng = 2.f * float(M_PI) * (float) (
j - 1) / longs;
205 glVertex3f(pos.
x + r * x * zr0, pos.
y + r * y * zr0, pos.
z + r * z0);
207 glVertex3f(pos.
x + r * x * zr1, pos.
y + r * y * zr1, pos.
z + r * z1);
274 std::vector<float3> parts;
275 parts.push_back(from);
276 auto dir = to - from;
277 auto l =
dir.length();
280 auto parts_num = l /
unit;
281 for (
int i = 0;
i < parts_num;
i++)
283 auto t =
i / (float)parts_num;
284 parts.push_back(from +
dir *
t);
290 for (
int i = 1;
i < parts.size();
i++)
292 auto alpha = selected == 0 ? 0.4f : 0.9f;
296 auto from = parts[
i-1];
306 float3 ctr = from + (to - from) / 2;
337 auto rect_copy = viewer_rect;
363 for (
int i = 0;
i <
state.points.size();
i++)
379 const float l2 =
dot(b - a, b - a);
380 if (l2 == 0.0)
return (p - a).length();
381 const float t =
clamp(
dot(p - a, b - a) / l2, 0.
f, 1.
f);
382 return (
lerp(a, b, t) - p).length();
387 for (
int i = 0;
i <
state.edges.size();
i++)
417 auto new_state =
state;
458 auto faxis1 =
float3 { axis1.
x, axis1.y, axis1.z };
461 auto faxis2 =
float3 { axis2.
x, axis2.y, axis2.z };
465 basis(0, 0) = faxis1.x;
466 basis(0, 1) = faxis1.y;
467 basis(0, 2) = faxis1.z;
469 basis(1, 0) = faxis2.x;
470 basis(1, 1) = faxis2.y;
471 basis(1, 2) = faxis2.z;
480 auto t1 = 2.f * float(M_PI) * ((float)
i / segments);
481 auto t2 = 2.f * float(M_PI) * ((float)(
i+1) /
segments);
485 float4 xy2 { cosf(
t1) * size * 0.5f, sinf(
t1) * size * 0.5f, 0.f, 1.f };
488 float4 xy3 { cosf(
t2) * size * 0.5f, sinf(
t2) * size * 0.5f, 0.f, 1.f };
511 if (
state.points.size() == 1 || (shift &&
state.points.size()))
527 for (
auto&& poly :
state.polygons)
529 auto ancor =
state.points[poly.front()];
531 std::vector<float3>
points;
532 points.push_back(ancor.pos);
534 auto mid = ancor.pos;
540 for (
int i = 0;
i < poly.size() - 1;
i++)
542 auto b =
state.points[poly[
i]];
543 auto c =
state.points[poly[
i+1]];
548 points.push_back(
c.pos);
554 mid = mid * (1.f / poly.size());
561 for (
int i = 0;
i <
state.edges.size();
i++)
563 auto&& pair =
state.edges[
i];
574 state.points.clear();
576 state.polygons.clear();
589 if (hovered_point >= 0)
626 for (
auto&&
e :
state.edges)
639 std::vector<float3> poly;
float3 cross(const float3 &a, const float3 &b)
IMGUI_API void PushStyleVar(ImGuiStyleVar idx, float val)
static const ImVec4 transparent
float lerp(float a, float b, float t)
static const ImVec4 white
std::vector< int > find_path(int from, int to)
IMGUI_API float GetCursorPosX()
IMGUI_API bool IsKeyPressed(int key_index, bool repeat=true)
GLboolean GLboolean GLboolean b
std::string length_to_string(float distance)
static matrix4 identity()
static const char * is_measuring
IMGUI_API void SetTooltip(const char *fmt,...) IM_PRINTFARGS(1)
static const ImVec4 almost_white_bg
std::deque< measurement_state > state_history
static config_file & instance()
static const ImVec4 light_blue
GLsizei const GLchar *const * path
IMGUI_API void SetNextWindowPos(const ImVec2 &pos, ImGuiSetCond cond=0)
void update_input(ux_window &win, const rs2::rect &viewer_rect)
GLuint GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat t1
#define GLFW_KEY_LEFT_SHIFT
GLsizei const GLchar *const * string
std::function< bool()> is_metric
void draw_sphere(const float3 &pos, float r, int lats, int longs)
bool measurement_point_hovered
void add_point(interest_point p)
float distance_to_line(rs2::float2 a, rs2::float2 b, rs2::float2 p)
GLsizei GLsizei GLfloat distance
bool manipulating() const
float calculate_area(std::vector< float3 > points)
GLboolean GLboolean GLboolean GLboolean a
int current_hovered_point
IMGUI_API void SameLine(float pos_x=0.0f, float spacing_w=-1.0f)
temporal_event mouse_picked_event
GLfloat GLfloat GLfloat alpha
IMGUI_API bool Begin(const char *name, bool *p_open=NULL, ImGuiWindowFlags flags=0)
IMGUI_API void PopStyleVar(int count=1)
IMGUI_API ImVec2 CalcTextSize(const char *text, const char *text_end=NULL, bool hide_text_after_double_hash=false, float wrap_width=-1.0f)
static const ImVec4 regular_blue
void draw_ruler(ux_window &win, float3 from, float3 to, float height, int selected)
#define GL_PROJECTION_MATRIX
void draw_label(ux_window &win, float3 pos, float distance, int height, bool is_area=false)
GLint GLsizei GLsizei height
float single_wave(float x)
IMGUI_API void SetNextWindowSize(const ImVec2 &size, ImGuiSetCond cond=0)
float dot(const rs2::float2 &a, const rs2::float2 &b)
int point_hovered(ux_window &win)
IMGUI_API void SetCursorPosX(float x)
void mouse_pick(ux_window &win, float3 picked, float3 normal)
IMGUI_API void Text(const char *fmt,...) IM_PRINTFARGS(1)
const base::type::char_t * unit
int edge_hovered(ux_window &win)
ImVec4 alpha(const ImVec4 &v, float a)
bool dragging_measurement_point
#define GL_ONE_MINUS_SRC_ALPHA
IMGUI_API void PushStyleColor(ImGuiCol idx, const ImVec4 &col)
rs2::float2 project_to_2d(rs2::float3 pos)
IMGUI_API void PushFont(ImFont *font)
float framebuf_height() const
GLdouble GLdouble GLint GLint GLdouble v1
void next(auto_any_t cur, type2type< T, C > *)
std::string area_to_string(float area)
GLdouble GLdouble GLdouble q
void set(const char *key, const char *value)
std::function< void(std::string)> log_function
bool display_mouse_picked_tooltip() const
void draw(ux_window &win)
GLuint GLsizei const GLchar * label
float clamp(float x, float min, float max)
#define GL_MODELVIEW_MATRIX
GLenum GLuint GLenum GLsizei length
float2 translate_3d_to_2d(float3 point, matrix4 p, matrix4 v, matrix4 f, int32_t vp[4])
IMGUI_API bool IsKeyDown(int key_index)
ImFont * get_large_font() const
#define GLFW_KEY_RIGHT_SHIFT
void show_tooltip(ux_window &win)
GLdouble GLdouble GLint GLint const GLdouble * points
IMGUI_API void PopStyleColor(int count=1)
rs2::mouse_info & get_mouse()
std::string to_string(T value)