Skip to content
Andreas-Forster edited this page Sep 25, 2014 · 3 revisions

Installation

As a first step you need to download and compile statismo. You can either clone the code using

git clone https://github.com/statismo/statismo.git

or download the latest release (0.81), as a zip archive.

Compilation is done using a standard CMake workflow. On Unix systems, you would write

mkdir builddir
cd builddir
ccmake .
make install

to build and install statismo.

For the following example, we also assume that you have a working version of VTK installed.

A simple example

Here we give a simple example how Statismo can be used to build a simple shape model using VTK.

The first step when using Statismo is to decide which representer to choose: (For more about Representers see Representer). In VTK, shapes are most conveniently represented using vtkPolyData. We therefore choose the VTKPolyDataRepresenter. All the classes that we are later going to use are parametrized with that representer.

typedef vtkPolyDataRepresenter RepresenterType;
typedef statismo::DataManager<RepresenterType> DataManagerType;
typedef statismo::PCAModelBuilder<RepresenterType> ModelBuilderType;
typedef statismo::StatisticalModel<RepresenterType> StatisticalModelType;    

We create a representer and provide it with a reference dataset

RepresenterType* representer = RepresenterType::Create(loadVTKPolydata("reference.vtk"));

In a second step we create a data manager, which holds the datasets we would like to use for building the model. We provide the representer object to the datamanager, to tell it that it how the data need to be converted and interpreted. Then we add our data to the datamanager using the AddDataset method (It is assumed here that all the datasets are already in correspondence). The filename, which we provide as a second argument, will be stored as metadata together with the model.

DataManagerType* datamanager = DataManagerType::Create(representer);
datamanager->AddDataset(loadVTKPolydata("dataset1.vtk"), "dataset1.vtk");
datamanager->AddDataset(loadVTKPolydata("dataset2.vtk"), "dataset2.vtk");
datamanager->AddDataset(loadVTKPolydata("dataset3.vtk"), "dataset3.vtk");

To build a standard PCA model, we use the PCAModelBuilder. The first parameters is a list of samples, which we obtain from the DataManager. The second parameter is the variance of a Gaussian noise term. It specifies how noisy we think the data is.

ModelBuilderType* modelBuilder = ModelBuilderType::Create();
StatisticalModelType* model = modelBuilder->BuildNewModel(datamanager->GetSampleData(), 0.1);

The model is now built and ready to use. For example, we can explore the model by drawing samples from it.

vtkPolyData* aSample = model->DrawSample();

Most often, however, we simply want to save the model after it has been built, to use it later from another application. This is done by calling:

model->Save("filename.h5")

This stores all the information that is needed to restore the model in a single HDF5 file.

To later load a model to use it from an application, we simply call:

StatisticalModelType* newModel = StatisticalModelType::Load("filename.h5")

See the API Documentation for a detailed description of the individual functions the StatisticalModel class offers.

Compiling the example program

We assume that you saved the code above in a file names (BuildShapeModelExample.cxx). To compile the example, you need to create a file CMakeLists.txt that contains the following instructions:

CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
PROJECT(example)

FIND_PACKAGE(STATISMO REQUIRED)

FIND_PACKAGE(VTK REQUIRED)
include (${VTK_USE_FILE})

FILE(GLOB INCLUDE_FILES *.h)
FILE(GLOB SOURCE_FILES  *.txx *.cpp)

include_directories(${STATISMO_INCLUDE_DIRS} ${VTK_INCLUDE_DIR})
link_directories(${STATISMO_LIBRARY_DIR} ${VTK_LIBRARY_DIR})
 
add_executable (BuildShapeModelExample BuildShapeModelExample.cxx) 
target_link_libraries (BuildShapeModelExample ${STATISMO_LIBRARIES} ${VTK_LIBRARIES})

You can run CMake again to compile the program.

More examples

For more examples using different Representers and ModelBuilders see the ITK-Example Folder or VTK-Example Folder.