Skip to content

Fix underflow issue when computing normalization#1344

Merged
alecjacobson merged 1 commit intodevfrom
alecjacobson-patch-1
Nov 8, 2019
Merged

Fix underflow issue when computing normalization#1344
alecjacobson merged 1 commit intodevfrom
alecjacobson-patch-1

Conversation

@alecjacobson
Copy link
Copy Markdown
Contributor

Heat Geodesics first computes a scalar potential field. Values far from the source will be extremely small, approaching the limits of floating point numbers. Then the method takes the per triangle gradient and normalizes this vector (divides the vector by the norm).
The gradient vector will have tiny values. (e.g., [1e-300 2e-300 3e-300]). Computing the vector norm in the obvious way will fail. It's more robust to first divide by the coordinate with the max absolute and then take the norm.

if(norm == 0)
norm = ma*sqrt(norm);
// These are probably over kill; ma==0 should be enough
if(ma == 0 || norm == 0 || norm!=norm)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe use std::isnan() or std::isfinite() instead of checking if norm != norm?

@jdumas
Copy link
Copy Markdown
Collaborator

jdumas commented Nov 8, 2019

Could this be written as a one-liner using a combination of Eigen::Map and rowwise().stableNorm()?

@alecjacobson alecjacobson merged commit 7ab7dc7 into dev Nov 8, 2019
@alecjacobson
Copy link
Copy Markdown
Contributor Author

yes, it could.

@jdumas jdumas deleted the alecjacobson-patch-1 branch November 11, 2019 00:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants