aardvark-platform / aardvark.algodat

Aardvark.Algodat contains advanced geometric and photometric data structures and algorithms. It is part of the open-source Aardvark Platform for visual computing, real-time graphics, and visualization.
https://aardvarkians.com/
GNU Affero General Public License v3.0
34 stars 6 forks source link

EstimateNormals with fallback #20

Open luithefirst opened 2 years ago

luithefirst commented 2 years ago

I'm using EstimateNormals to calculate orientations of user-generated calculation grids. While the points typically are on a plane or a slope there are other cases where the points have a linear dependency where I simply want to fallback to a default orientation. With k=5 I get inconsistent (almost random appearing) orientations in this case (maybe not all points are perfectly linear): EstimateNormals_Fallback

One possibility would to implement a version of EstimateNormals where a default normal can be specified in case the calculation is degenerated (count < 3 or any group of neighboring points have a linear dependency) and some kind of threshold: V3f[] EstimateNormals(this V3d[] points, int k, V3f fallback, double epsilon)

An alternative would be to only add an epsilon parameter and return V3f.Zero (like in one case already), so degenerated normals can be identified on the user side: V3f[] EstimateNormals(this V3d[] points, int k, double epsilon) The additional pass should not be that expensive compared to the method and the API change would be minimal. It would actually be even more useful than with a directly specified fallback because it can be distinguished between the degenerated case and a point where the normal is calculated as the fallback.

I could start with a local copy of EstimateNormals, but it would be great to have it in this library.

The one thing I'm not sure yet is how the epsilon parameter should be interpreted. I guess since the smallest eigenvalue is the normal, in case there is a second very small value the points are degenerated? Do you have a suggestion on how this check should actually look like?

krauthaufen commented 2 years ago

We could also return the "quality" of the normal encoded into its length which would allow to filter these things and offload the task of finding a proper epsilon to the user