summaryrefslogtreecommitdiffhomepage
path: root/pose-widget
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2016-05-13 23:59:07 +0200
committerStanislaw Halik <sthalik@misaki.pl>2016-05-13 23:59:07 +0200
commitee18bc05ae54bd4b9a959ef544181dd8f597d955 (patch)
treeda5045cbd013f7411b1aac0b31a6cf6dcb26b34e /pose-widget
parentc772987dde5c42aa7f236ac7708f6e7d063d4aa7 (diff)
pose-widget: avoid too small denominator in perpendicular alignment
With a very small denominator in barycentric coords formula we get a dissociated octopus that took PCP and LSD in one sitting. A dead Octopus is just a bunch of blue spheres. IOW, in division with too small a denominator operand the results are numerically unstable. This is done in the constructor in a convoluted way as to avoid branching during calculating for each pixel. Issue: #356 Reported-by: @MathijsG
Diffstat (limited to 'pose-widget')
-rw-r--r--pose-widget/glwidget.cpp13
1 files changed, 11 insertions, 2 deletions
diff --git a/pose-widget/glwidget.cpp b/pose-widget/glwidget.cpp
index a2ed422e..f85e2ae1 100644
--- a/pose-widget/glwidget.cpp
+++ b/pose-widget/glwidget.cpp
@@ -11,7 +11,6 @@
#include <QPainter>
#include <QPaintEvent>
-//#include <QDebug>
GLWidget::GLWidget(QWidget *parent) : QWidget(parent)
{
@@ -68,7 +67,17 @@ public:
dot00 = v0.dot(v0);
dot01 = v0.dot(v1);
dot11 = v1.dot(v1);
- invDenom = 1 / (dot00 * dot11 - dot01 * dot01);
+ const num denom = dot00 * dot11 - dot01 * dot01;
+ if (std::fabs(denom) < 1e-1f)
+ {
+ // for perpendicular plane, ensure u and v don't come out right
+ // this is done here to avoid branching below, in a hot loop
+ invDenom = -1;
+ dot00 = dot01 = dot11 = 1;
+ v0 = v1 = vec2(1, 1);
+ }
+ else
+ invDenom = 1 / denom;
}
bool barycentric_coords(const vec2& px, vec2& uv) const
{