Displacement fields in mesheR
29 Feb 2016Inspired by the awesome Shape Modelling MOOC, organized by the University of Basel, I decided to add interpolation of displacement fields in mesheR as well. The interpolation is calculated by using the displacement vectors of the k-closest domain points and applying a Gaussian smoothing based on the distances to the domain points (a lot of useful stuff was already there from gaussMatch
)
The functions added are:
createDisplacementField
– creates a discrete displacement fieldinterpolateDisplacementField
– interpolate discrete displacement field at any point(s)applyDisplacementField
– apply (and optionally interpolate) a deformation defined by a displacement field to coordinates/meshplotDisplacementField
– visualize a displacement field
Here is some code to play with. Happy 29th February.
Example 1
We are going create a displacement field from a GP-model instance and its mean and apply it to a second random instance.
require(Rvcg);require(mesheR);require(rgl)
require(RvtkStatismo)
data(humface)
## create a GP model of a human face
mymod <- statismoModelFromRepresenter(humface,kernel=list(c(50,30)))
## sample two instances from the model
sample1 <- DrawSample(mymod)
sample2 <- DrawSample(mymod)
dispfield <- createDisplacementField(DrawMean(mymod),sample1)
dispfieldNew <- interpolateDisplacementField(dispfield,sample2)
sample2displaced <- applyDisplacementField(dispfieldNew,sample2)
##visualize the displacement field
plotDisplacementField(dispfieldNew,lwd=2)
wire3d(sample2)
Example 2
Here we use a discrete displacement field generated from a coarse mesh (Example 1) and apply the resulting deformation to a high resolution version of the reference mesh (you will need the latest master snapshot of Rvcg to create a high resolution mesh). The result and the differences to the target mesh that was used to calculate the discrete displacment field can be seen in Figure 2.
## create a finer mesh of the mean using subdivison algorithm
highres <- vcgSubdivide(DrawMean(mymod),type="loop",threshold=1.5)
dispfieldHighres <- interpolateDisplacementField(dispfield,highres)
highresDisplaced <- applyDisplacementField(dispfieldHighres,highres)
## visualize the result, also displaying the errors between the
## deformed highres mean and the target surface
Morpho::meshDist(highresDisplaced,sample1,tol=0.1)