From d3f0b42b16f1350dfaf5a3a794417fd56b466b87 Mon Sep 17 00:00:00 2001 From: Noha Yassin <37175819+nohayassin@users.noreply.github.com> Date: Sun, 1 Nov 2020 16:18:07 +0200 Subject: [PATCH 1/4] DSO-8689 fix : division by 0 --- src/proc/colorizer.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/proc/colorizer.cpp b/src/proc/colorizer.cpp index 13f134aa53..fd3b72c760 100644 --- a/src/proc/colorizer.cpp +++ b/src/proc/colorizer.cpp @@ -296,6 +296,7 @@ namespace librealsense auto min = _min; auto max = _max; auto coloring_function = [&, this](float data) { + if (max == min) return data * _depth_units; return (data * _depth_units - min) / (max - min); }; make_rgb_data(depth_data, rgb_data, w, h, coloring_function); From 34e83739592cf5deb76a39bd80c59cd8e4f13a66 Mon Sep 17 00:00:00 2001 From: Noha Yassin <37175819+nohayassin@users.noreply.github.com> Date: Mon, 2 Nov 2020 13:23:19 +0200 Subject: [PATCH 2/4] Colorizer - fix division by zero --- src/proc/colorizer.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/proc/colorizer.cpp b/src/proc/colorizer.cpp index fd3b72c760..0533de7bf4 100644 --- a/src/proc/colorizer.cpp +++ b/src/proc/colorizer.cpp @@ -286,6 +286,7 @@ namespace librealsense auto max = (_d2d_convert_factor / (__min)) * _depth_units + .5f; auto min = (_d2d_convert_factor / (_max)) * _depth_units + .5f; auto coloring_function = [&, this](float data) { + if (max == min) return data; return (data - min) / (max - min); }; make_rgb_data(depth_data, rgb_data, w, h, coloring_function); From 737e2a48b9b6806fd616999968803953c10142de Mon Sep 17 00:00:00 2001 From: Noha Yassin <37175819+nohayassin@users.noreply.github.com> Date: Mon, 2 Nov 2020 14:04:41 +0200 Subject: [PATCH 3/4] Colorizer - fix division by zero --- common/rendering.h | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/common/rendering.h b/common/rendering.h index feee0efd4c..cb5a0e9bb2 100644 --- a/common/rendering.h +++ b/common/rendering.h @@ -107,7 +107,15 @@ namespace rs2 inline float smoothstep(float x, float min, float max) { - x = clamp((x - min) / (max - min), 0.0, 1.0); + if (max == min) + { + x = clamp((x - min) , 0.0, 1.0); + } + else + { + x = clamp((x - min) / (max - min), 0.0, 1.0); + } + return x*x*(3 - 2 * x); } @@ -475,6 +483,7 @@ namespace rs2 template T normalizeT(const T& in_val, const T& min, const T& max) { + if(min == max) return in_val; return ((in_val - min)/(max - min)); } From 9409bac5db323ce7f52f3d9ca651751c65692b30 Mon Sep 17 00:00:00 2001 From: Noha Yassin <37175819+nohayassin@users.noreply.github.com> Date: Tue, 3 Nov 2020 10:04:44 +0200 Subject: [PATCH 4/4] Colorizer - fix division by zero --- common/rendering.h | 2 +- src/proc/colorizer.cpp | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/common/rendering.h b/common/rendering.h index cb5a0e9bb2..b1c6ee2de8 100644 --- a/common/rendering.h +++ b/common/rendering.h @@ -483,7 +483,7 @@ namespace rs2 template T normalizeT(const T& in_val, const T& min, const T& max) { - if(min == max) return in_val; + if (min >= max) return 0; return ((in_val - min)/(max - min)); } diff --git a/src/proc/colorizer.cpp b/src/proc/colorizer.cpp index 0533de7bf4..af410bf00d 100644 --- a/src/proc/colorizer.cpp +++ b/src/proc/colorizer.cpp @@ -286,7 +286,6 @@ namespace librealsense auto max = (_d2d_convert_factor / (__min)) * _depth_units + .5f; auto min = (_d2d_convert_factor / (_max)) * _depth_units + .5f; auto coloring_function = [&, this](float data) { - if (max == min) return data; return (data - min) / (max - min); }; make_rgb_data(depth_data, rgb_data, w, h, coloring_function); @@ -297,7 +296,7 @@ namespace librealsense auto min = _min; auto max = _max; auto coloring_function = [&, this](float data) { - if (max == min) return data * _depth_units; + if (min >= max) return 0.f; return (data * _depth_units - min) / (max - min); }; make_rgb_data(depth_data, rgb_data, w, h, coloring_function);