-
Notifications
You must be signed in to change notification settings - Fork 0
simpleExample
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.
For more examples using different Representers and ModelBuilders see the Example Folder.