# Point Distribution Models in Scalismo 0.90

#### Marcel Lüthi

Lecturer, Department of Mathematics and Computer Science, University of Basel### Introduction

The recently released version of Scalismo - version 0.90 - comes with a number of important changes in its
core classes. In this blog post we will look at the class `PointDistributionModel`

, which replaces and
generalizes `StatisticalMeshModel`

.

We start by discussing the differences to the previous implementation. We then show how to create Point Distribution Models. In the last part we will discuss how we can change the domain over which the Point Distribution Model is defined. This allows us to change the resolution of the model, restrict the model to a subset of the original domain, or even to change the type of domain over which the model is defined.

### From StatisticalMeshModel to PointDistributionModel

Recall that shape variations are modelled using Gaussian processes in Scalismo. More precisely, we use a low-rank approximation of a Gaussian process, which models a probability distribution over deformation fields,

The type signature indicates that the Gaussian process is defined in 3D space and it represents a collection of random variables over 3D vectors in Euclidean space.

A `StatisticalMeshModel`

is the restriction of this continuously defined Gaussian Process to
a discrete and finite set of points. This set of points is defined to be the vertices of a triangle mesh,
which is called the reference mesh.
Thus, a `StatisticalMeshModel`

is just an aggregate of a mesh and a corresponding Gaussian process,
restricted to the points of the reference mesh. This is reflected in the definition in Scalismo:

When we draw a sample from this model, we actually draw a sample from the Gaussian process and apply the sampled deformation field to the points of the reference mesh. The resulting sample is the deformed version of the reference mesh.

From this description it becomes obvious how we can generalize this to other types of datasets.
As we only use the points of the mesh, we can relax the restriction that the reference has to be a triangle mesh.
Instead, we assume that the dataset is defined on a finite set of points. In Scalismo, a dataset which is defined on
a finite set of points is modelled as a subtype of the class `DiscreteDomain`

. This is the basis of the definition of
a `PointDistributionModel`

:

Here we replaced `TriangleMesh`

by the generic type `DDomain`

, which can be any subtype
of a `DiscreteDomain`

. The implicit argument `warper`

restricts the domains further to domains
that can be deformed. In Scalismo these are currently the classes `TriangleMesh`

,
`TetrahedralMesh`

, `LineMesh`

and `UnstructuredPointsDomain`

.^{1}

In the actual Scalismo implementation, the definition of the class `PointDistributionModel`

is even a bit simpler.
The reference is assumed to coincide with the domain over which the (discrete) Gaussian process is defined. Therefore,
we do not even need to explicitly represent it as part of the class `PointDistributionModel`

.

### Creating and working with Point Distribution Models

Now that we know what a Point Distribution Model is, we will show how we work with them in Scalismo.
Our first example illustrates how to learn a Point Distribution Model of tetrahedral meshes from given example meshes.
This is simple: We create a data collection, where we provide a sequence of tetrahedral meshes and use the method `createUsingPCA`

to create the model:

As expected, samples from this model are valid tetrahedral meshes.

Creating models of other types of data sets works exactly in the same way. We simply change the corresponding type of the reference and the data collection.

A second way to create a PDMs is to specify a low rank Gaussian process as well as a reference mesh on which the Gp will be discretized:

Again, samples from the model will have the correct type:

### Changing the domain

The new implementation opens an interesting new possibility: We can
change the domain over which the point distribution model is defined.
To achieve this, we call the methods `newReference`

and provide as an argument the new reference mesh
and an interpolator. Internally, the interpolator is used to obtain a continuously defined `LowRankGaussianProcess`

from the `DiscreteLowRankGaussianProcess`

. From above discussion we already know how to create a PDM from a `reference`

and
a `LowRankGaussianProcess`

. This is exactly what is done behind the scenes when we call `newReference`

.

In the following example we show how we can use this method to obtain a PDM of a triangle mesh from a model defined over tetrahedral meshes. As the new reference we use the outer surface of the tetrahedral mesh over which the original PDM is defined

Another common use case for this method is to restrict the model to a subset of the vertices on which the PDM is defined. This can either be used for restricting the model to a part of the domain, or to change the resolution of the domain. This latter use case is illustrated in the following code:

Having an easily accessible method to change the points on which the PDM is defined, makes it possible to choose the appropriate mesh resolution for each task. We might for example want to start with a high resolution model, which result in visually pleasing samples when rendered, but reduce the mesh resolution when fitting the model, in order to save computation time.

### Summary

We have seen that the new PDM class generalizes the concept of `StatisticalMeshModel`

from previous versions of Scalismo.
The newly introduced class `PointDistributionModel`

can be defined over any subtype of `DiscreteDomain`

, which supports a warping operation.
Besides triangle and tetrahedral meshes, this includes line meshes and unstructured point domains.
Another notable feature of Point Distribution Model is that it provides a method to change the
domain over which the PDM is defined. This makes it possible to restrict a Gaussian process model to a part of the domain,
change the type of the domain or to change its resolution.

#### Footnotes1: An example for a discrete domain, which cannot be used as a basis for a PDM is a

`DiscreteImage`

. The reason is that an image is defined on a regular grid, but once we warp the grid
it is not regular anymore and hence not an image.