38 #ifndef ITKSTATISTICALMODEL_H_
39 #define ITKSTATISTICALMODEL_H_
41 #include <boost/bind.hpp>
42 #include <boost/utility/result_of.hpp>
44 #include <itkObject.h>
45 #include <itkObjectFactory.h>
47 #include <vnl/vnl_matrix.h>
48 #include <vnl/vnl_vector.h>
50 #include "ModelInfo.h"
51 #include "Representer.h"
52 #include "StatisticalModel.h"
53 #include "statismoITKConfig.h"
66 typedef Object Superclass;
67 typedef SmartPointer<Self> Pointer;
68 typedef SmartPointer<const Self> ConstPointer;
73 typedef statismo::Representer<T> RepresenterType;
78 typedef typename statismo::DataManager<T>::DataItemType DataItemType;
80 typedef vnl_matrix<statismo::ScalarType> MatrixType;
81 typedef vnl_vector<statismo::ScalarType> VectorType;
85 typename boost::result_of<F()>::type callstatismoImpl(F f)
const {
89 itkExceptionMacro(<< s.what());
93 void SetstatismoImplObj(
ImplType* impl) {
100 ImplType* GetstatismoImplObj()
const {
113 typedef typename RepresenterType::DatasetPointerType DatasetPointerType;
114 typedef typename RepresenterType::DatasetConstPointerType DatasetConstPointerType;
116 typedef typename RepresenterType::ValueType ValueType;
117 typedef typename RepresenterType::PointType PointType;
119 typedef typename statismo::StatisticalModel<T>::PointValuePairType PointValuePairType;
120 typedef typename statismo::StatisticalModel<T>::PointValueListType PointValueListType;
125 void Load(RepresenterType* representer,
const char* filename) {
129 itkExceptionMacro(<< s.what());
134 void Load(RepresenterType* representer,
const H5::Group& modelRoot) {
138 itkExceptionMacro(<< s.what());
144 const RepresenterType* GetRepresenter()
const {
152 DatasetPointerType DrawMean()
const {
156 ValueType DrawMeanAtPoint(
const PointType& pt)
const {
157 typedef ValueType (
ImplType::*functype)(
const PointType&)
const;
161 ValueType DrawMeanAtPoint(
unsigned ptid)
const {
162 typedef ValueType (
ImplType::*functype)(unsigned)
const;
166 DatasetPointerType DrawSample(
const VectorType& coeffs,
bool addNoise =
false)
const {
167 typedef DatasetPointerType (
ImplType::*functype)(
const statismo::VectorType&, bool)
const;
168 return callstatismoImpl(boost::bind(static_cast<functype>(&
ImplType::DrawSample), this->m_impl, fromVnlVector(coeffs), addNoise));
171 DatasetPointerType DrawSample(
bool addNoise =
false)
const {
172 typedef DatasetPointerType (
ImplType::*functype)(bool)
const;
173 return callstatismoImpl(boost::bind(static_cast<functype>(&
ImplType::DrawSample), this->m_impl, addNoise));
176 DatasetPointerType DrawPCABasisSample(
unsigned componentNumber)
const {
177 typedef DatasetPointerType (
ImplType::*functype)(unsigned)
const;
181 ValueType DrawSampleAtPoint(
const VectorType& coeffs,
const PointType& pt,
bool addNoise =
false)
const {
182 typedef ValueType (
ImplType::*functype)(
const statismo::VectorType&,
const PointType&, bool)
const;
183 return callstatismoImpl(boost::bind(static_cast<functype>(&
ImplType::DrawSampleAtPoint), this->m_impl, fromVnlVector(coeffs), pt, addNoise));
186 ValueType DrawSampleAtPoint(
const VectorType& coeffs,
unsigned ptid,
bool addNoise =
false)
const {
187 typedef ValueType (
ImplType::*functype)(
const statismo::VectorType&, unsigned, bool)
const;
188 return callstatismoImpl(boost::bind(static_cast<functype>(&
ImplType::DrawSampleAtPoint), this->m_impl, fromVnlVector(coeffs), ptid, addNoise));
192 VectorType ComputeCoefficientsForDataset(DatasetConstPointerType ds)
const {
196 VectorType ComputeCoefficientsForSample(DatasetConstPointerType ds)
const {
200 VectorType ComputeCoefficientsForDataSample(
const DataItemType* sample)
const {
201 return toVnlVector(callstatismoImpl(boost::bind(&ImplType::ComputeCoefficientsForDataSample, this->m_impl, sample)));
204 double ComputeLogProbabilityOfDataset(DatasetConstPointerType ds)
const {
208 double ComputeProbabilityOfDataset(DatasetConstPointerType ds)
const {
212 double ComputeLogProbabilityOfCoefficients(
const VectorType& coeffs)
const {
216 double ComputeProbabilityOfCoefficients(
const VectorType& coeffs)
const {
220 double ComputeMahalanobisDistanceForDataset(DatasetConstPointerType ds)
const {
224 VectorType ComputeCoefficientsForPointValues(
const PointValueListType& pvlist,
double variance)
const {
225 typedef statismo::VectorType (
ImplType::*functype)(
const PointValueListType&, double)
const;
230 DatasetPointerType DatasetToSample(DatasetConstPointerType ds)
const {
234 unsigned GetNumberOfPrincipalComponents()
const {
238 void Save(
const char* modelname) {
239 typedef void (
ImplType::*functype)(
const std::string&)
const;
240 callstatismoImpl(boost::bind(static_cast<functype>(&
ImplType::Save), this->m_impl, modelname));
243 void Save(
const H5::Group& modelRoot) {
244 typedef void (
ImplType::*functype)(
const H5::Group&)
const;
245 callstatismoImpl(boost::bind(static_cast<functype>(&
ImplType::Save), this->m_impl, modelRoot));
248 float GetNoiseVariance()
const {
252 MatrixType GetCovarianceAtPoint(
const PointType& pt1,
const PointType& pt2)
const {
253 typedef statismo::MatrixType (
ImplType::*functype)(
const PointType&,
const PointType&)
const;
257 MatrixType GetCovarianceAtPoint(
unsigned ptid1,
unsigned ptid2)
const {
258 typedef statismo::MatrixType (
ImplType::*functype)(unsigned, unsigned )
const;
262 MatrixType GetJacobian(
const PointType& pt)
const {
266 MatrixType GetPCABasisMatrix()
const {
270 MatrixType GetOrthonormalPCABasisMatrix()
const {
274 VectorType GetPCAVarianceVector()
const {
278 VectorType GetMeanVector()
const {
288 static MatrixType toVnlMatrix(
const statismo::MatrixType& M) {
289 return MatrixType(M.data(), M.rows(), M.cols());
293 static VectorType toVnlVector(
const statismo::VectorType& v) {
294 return VectorType(v.data(), v.rows());
298 static statismo::VectorType fromVnlVector(
const VectorType& v) {
299 return Eigen::Map<const statismo::VectorType>(v.data_block(), v.size());
static StatisticalModel * Load(Representer< T > *representer, const std::string &filename, unsigned maxNumberOfPCAComponents=std::numeric_limits< unsigned >::max())
Definition: StatisticalModel.hxx:526
ValueType DrawSampleAtPoint(const VectorType &coefficients, const PointType &point, bool addNoise=false) const
Definition: StatisticalModel.hxx:191
double ComputeMahalanobisDistanceForDataset(DatasetConstPointerType dataset) const
Definition: StatisticalModel.hxx:371
const ModelInfo & GetModelInfo() const
Definition: StatisticalModel.hxx:493
MatrixType GetOrthonormalPCABasisMatrix() const
Definition: StatisticalModel.hxx:473
VectorType ComputeCoefficientsForSample(DatasetConstPointerType sample) const
Definition: StatisticalModel.hxx:277
float GetNoiseVariance() const
Definition: StatisticalModel.hxx:447
DatasetPointerType DrawPCABasisSample(unsigned componentNumber) const
Definition: StatisticalModel.hxx:157
Generic Exception class for the statismo Library.
Definition: Exceptions.h:68
const VectorType & GetPCAVarianceVector() const
Definition: StatisticalModel.hxx:460
const MatrixType & GetPCABasisMatrix() const
Definition: StatisticalModel.hxx:467
ValueType DrawMeanAtPoint(const PointType &point) const
Definition: StatisticalModel.hxx:120
stores meta information about the model, such as e.g. the name (uri) of the datasets used to build th...
Definition: ModelInfo.h:61
const RepresenterType * GetRepresenter() const
Definition: StatisticalModel.h:564
DatasetPointerType DatasetToSample(DatasetConstPointerType dataset) const
Definition: StatisticalModel.hxx:88
DatasetPointerType DrawMean() const
Definition: StatisticalModel.hxx:112
double ComputeProbabilityOfCoefficients(const VectorType &coefficients) const
Definition: StatisticalModel.hxx:364
MatrixType GetJacobian(const PointType &pt) const
Definition: StatisticalModel.hxx:507
const DomainType & GetDomain() const
Definition: StatisticalModel.h:572
double ComputeProbabilityOfDataset(DatasetConstPointerType dataset) const
Definition: StatisticalModel.hxx:350
unsigned int GetNumberOfPrincipalComponents() const
Definition: StatisticalModel.hxx:501
VectorType ComputeCoefficientsForDataset(DatasetConstPointerType dataset) const
Definition: StatisticalModel.hxx:267
double ComputeLogProbabilityOfDataset(DatasetConstPointerType dataset) const
Definition: StatisticalModel.hxx:343
MatrixType GetCovarianceAtPoint(const PointType &pt1, const PointType &pt2) const
Definition: StatisticalModel.hxx:230
const VectorType & GetMeanVector() const
Definition: StatisticalModel.hxx:454
DatasetPointerType DrawSample(const VectorType &coefficients, bool addNoise=false) const
Definition: StatisticalModel.hxx:150
A Point/Value pair that is used to specify a value at a given point.
Definition: StatisticalModel.h:100
void Save(const std::string &filename) const
Definition: StatisticalModel.hxx:620
double ComputeLogProbabilityOfCoefficients(const VectorType &coefficients) const
Definition: StatisticalModel.hxx:358
ITK Wrapper for the statismo::StatisticalModel class.
Definition: itkStatisticalModel.h:62
VectorType ComputeCoefficientsForPointValues(const PointValueListType &pointValues, double pointValueNoiseVariance=0.0) const
Definition: StatisticalModel.hxx:297