zarquon42b / Rvcg

R-package providing mesh manipulation routines from VCGLIB
Other
25 stars 10 forks source link

Geodesic distances #17

Closed dfsp-spirit closed 3 years ago

dfsp-spirit commented 3 years ago

Thanks for making Rvcg! I wanted to ask whether you could consider adding geodesic distance computation.

A vcglib example from the official docs is here and here.

I tried to do it myself and submit a PR, but my knowledge on C++ template programming and Rcpp is very limited and I could not get it to work.

I asked you about this a while ago in an RvtkStatismo issue and got it to work, but the installation required quite some effort and I cannot make RvtkStatismo a dependency of my package that is on CRAN.

zarquon42b commented 3 years ago

Hi @dfsp-spirit , here you go. This is an implementation of the Dijkstra-algorithm. It gives you the shorted geodesic distance to a point for each vertex. Please test and report back.

zarquon42b commented 3 years ago

Update: I just pushed a wrapper function vcgGeodist to explicitly compute the geodesic distances between two 3D coordinates (projected) on a triangular surface mesh.

dfsp-spirit commented 3 years ago

Oh wow, that was fast. Thanks heaps, I'm off to test it...

zarquon42b commented 3 years ago

If you encounter me in procrastination mode, things can be fast ;)

dfsp-spirit commented 3 years ago

This looks great so far, I am testing it here.

I'll post a visualization soon and compare the results to those from a Python and C implementation of geodesic distances.

Here is a visualization of the 3 points tested in the script (in Test 1 and Test 2), near motor cortex: geodesics_points_rgb

zarquon42b commented 3 years ago

Nice, keep me posted. BTW it gives the exact same results as the VTK implementation.

zarquon42b commented 3 years ago

Here is another CAVEAT: this is actually not the geodesic path between the points but the pseudo-geodesic path (following the edges) between the two vertices closest to these points.

dfsp-spirit commented 3 years ago

Yes I know, I have read quite a bit about geodesic distances and seen various implementations and aproximative algorithms. That is fine with me.

I also computed the one-to-all vertices geodesic path length map for a larger mesh (160k verts, Test 3 in the script above), here is the plot:

fsbrain_arranged

zarquon42b commented 3 years ago

I just also tested it and it takes 0.29 secs for a mesh with ~850.000 vertices.

dfsp-spirit commented 3 years ago

Yes, it is very fast.

dfsp-spirit commented 3 years ago

@zarquon42b This is amazing, thanks a lot.

I'll cite the Morpho/Rvcg paper given incitation("Rvcg") when I use it. Anything else (except for VCGLIB, of course)?

zarquon42b commented 3 years ago

I am glad that it works for you. Cool images ;)