Compute Geodesic Path and Distance in RvtkStatismo
27 Oct 2016The development branch of RvtkStatismo now contains an implementation of vtkDijkstraGraphGeodesicPath
. The R-functions vtkGeodesicPath
and vtkGeodesicPathForPointPair
allow to compute the (pseudo-) geodesic path by tracking the shortest route along connected vertices - this means the higher the mesh resolution, the smoother the resulting path will be. vtkGeodesicPath
needs a mesh and two vertex indices (defining start and end positions of the path) as input. vtkGeodesicPathForPointPair
requires a mesh and two vectors containing points on the surface. For the latter the search will start and and at the vertices closest to those coordinates.
Example 1: vtkGeodesicPath
(Figure 1)
require(Rvcg)
data(humface)
gp <- vtkGeodesicPath(humface,1,1000)
gp$distance
## The distance is 98.36738 mm
## render it
require(rgl);require(Morpho)
points3d(vert2points(humface)[gp$index,])
lines3d(vert2points(humface)[gp$index,],col="blue",lwd=4)
spheres3d(vert2points(humface)[c(1,1000),],col=2)
shade3d(humface,col="white")
Example 2: vtkGeodesicPathForPointPair
(Figure 2)
require(Rvcg)
data(humface)
gp <- vtkGeodesicPathForPointPair(humface,humface.lm[1,],humface.lm[2,])
gp$distance
## The distance is 30.98827 mm
## render it
require(rgl);require(Morpho)
points3d(vert2points(humface)[gp$index,])
lines3d(vert2points(humface)[gp$index,],col="blue",lwd=4)
spheres3d(humface.lm[1:2,],col=2)
shade3d(humface,col="white")
The paths are quite crooked because of the mesh’s low resolution. To obtain a smoother path, we can e.g. apply a triangle subdivision first (Figure 3):
Example 3: vtkGeodesicPathForPointPair
on a high resolution mesh (Figure 3)
humface <- vcgSubdivide(humface,threshold = 0.5,looptype = "cont",iterations=5)
gp <- vtkGeodesicPathForPointPair(humface,humface.lm[1,],humface.lm[2,])
## render it
require(rgl);require(Morpho)
points3d(vert2points(humface)[gp$index,])
lines3d(vert2points(humface)[gp$index,],col="blue",lwd=4)
spheres3d(humface.lm[1:2,],col=2)
shade3d(humface,col="white")