Statismo  0.10.1
 All Classes Namespaces Functions Typedefs
itkPosteriorModelBuilder.h
1 /*
2  * This file is part of the statismo library.
3  *
4  * Author: Marcel Luethi (marcel.luethi@unibas.ch)
5  *
6  * Copyright (c) 2011 University of Basel
7  * All rights reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  *
13  * Redistributions of source code must retain the above copyright notice,
14  * this list of conditions and the following disclaimer.
15  *
16  * Redistributions in binary form must reproduce the above copyright
17  * notice, this list of conditions and the following disclaimer in the
18  * documentation and/or other materials provided with the distribution.
19  *
20  * Neither the name of the project's author nor the names of its
21  * contributors may be used to endorse or promote products derived from
22  * this software without specific prior written permission.
23  *
24  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
27  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
28  * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
29  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
30  * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
31  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
32  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
33  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
34  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35  *
36  */
37 
38 
39 #ifndef ITK_POSTERIOR_MODELBUILDER_H_
40 #define ITK_POSTERIOR_MODELBUILDER_H_
41 
42 #include <itkObject.h>
43 
44 #include "itkDataManager.h"
45 #include "itkStatisticalModel.h"
46 
47 #include "PosteriorModelBuilder.h"
48 #include "statismoITKConfig.h"
49 
50 namespace itk {
51 
56 template <class T>
57 class PosteriorModelBuilder : public Object {
58  public:
59 
61  typedef Object Superclass;
62  typedef SmartPointer<Self> Pointer;
63  typedef SmartPointer<const Self> ConstPointer;
64 
65  itkNewMacro( Self );
66  itkTypeMacro( PosteriorModelBuilder, Object );
67 
70  typedef typename DataManagerType::DataItemListType DataItemListType;
71 
72 
73 
74  template <class F>
75  typename boost::result_of<F()>::type callstatismoImpl(F f) const {
76  try {
77  return f();
79  itkExceptionMacro(<< s.what());
80  }
81  }
82 
83 
85 
86  virtual ~PosteriorModelBuilder() {
87  if (m_impl) {
88  delete m_impl;
89  m_impl = 0;
90  }
91  }
92 
93 
94  // create statismo stuff
95  typedef statismo::Representer<T> RepresenterType;
96  typedef typename RepresenterType::ValueType ValueType;
97  typedef typename RepresenterType::PointType PointType;
98  typedef typename statismo::PosteriorModelBuilder<T>::PointValueListType PointValueListType;
99  typedef typename statismo::PosteriorModelBuilder<T>::PointValueWithCovariancePairType PointValueWithCovariancePairType;
100  typedef typename statismo::PosteriorModelBuilder<T>::PointValueWithCovarianceListType PointValueWithCovarianceListType;
103 
104  typename StatisticalModelType::Pointer BuildNewModelFromModel(const StatisticalModelType* model, const PointValueListType& pointValues, double pointValuesNoiseVariance, bool computeScores=true) {
105  StatismoStatisticalModelType* model_statismo = model->GetstatismoImplObj();
106  StatismoStatisticalModelType* new_model_statismo = callstatismoImpl(boost::bind(
107  static_cast<StatismoStatisticalModelType* (ImplType::*) (const StatismoStatisticalModelType* model, const PointValueListType& pointValues, double pointValuesNoiseVariance, bool computeScores) const > (&ImplType::BuildNewModelFromModel),
108  this->m_impl, model_statismo, pointValues, pointValuesNoiseVariance, computeScores));
109  typename StatisticalModelType::Pointer model_itk = StatisticalModelType::New();
110  model_itk->SetstatismoImplObj(new_model_statismo);
111  return model_itk;
112  }
113 
114  typename StatisticalModelType::Pointer BuildNewModel(DataItemListType DataItemList, const PointValueListType& pointValues, double pointValuesNoiseVariance, double noiseVariance) {
115  StatismoStatisticalModelType* model_statismo = callstatismoImpl(boost::bind(&ImplType::BuildNewModel, this->m_impl, DataItemList ,pointValues, pointValuesNoiseVariance, noiseVariance));
116  typename StatisticalModelType::Pointer model_itk = StatisticalModelType::New();
117  model_itk->SetstatismoImplObj(model_statismo);
118  return model_itk;
119  }
120 
121  typename StatisticalModelType::Pointer BuildNewModelFromModel(const StatisticalModelType* model, const PointValueWithCovarianceListType& pointValuesWithCovariance, bool computeScores=true) {
122  StatismoStatisticalModelType* model_statismo = model->GetstatismoImplObj();
123  StatismoStatisticalModelType* new_model_statismo = callstatismoImpl(boost::bind(
124  static_cast<StatismoStatisticalModelType* (ImplType::*) (const StatismoStatisticalModelType* model, const PointValueWithCovarianceListType& pointValuesWithCovariance, bool computeScores) const > (&ImplType::BuildNewModelFromModel),
125  this->m_impl, model_statismo, pointValuesWithCovariance, computeScores));
126  typename StatisticalModelType::Pointer model_itk = StatisticalModelType::New();
127  model_itk->SetstatismoImplObj(new_model_statismo);
128  return model_itk;
129  }
130 
131  typename StatisticalModelType::Pointer BuildNewModel(const DataItemListType& DataItemList, const PointValueWithCovarianceListType& pointValuesWithCovariance, double noiseVariance) {
132  StatismoStatisticalModelType* model_statismo = callstatismoImpl(boost::bind(&ImplType::BuildNewModel, this->m_impl, DataItemList, pointValuesWithCovariance, noiseVariance));
133  typename StatisticalModelType::Pointer model_itk = StatisticalModelType::New();
134  model_itk->SetstatismoImplObj(model_statismo);
135  return model_itk;
136  }
137 
138  private:
140  PosteriorModelBuilder& operator=(const PosteriorModelBuilder& rhs);
141 
142  ImplType* m_impl;
143 };
144 
145 
146 }
147 
148 #endif /* ITK_POSTERIOR_MODEL_BUILDER */
Manages Training and Test Data for building Statistical Models and provides functionality for Crossva...
Definition: DataManager.h:114
static PosteriorModelBuilder * Create()
Definition: PosteriorModelBuilder.h:94
ITK Wrapper for the statismo::PosteriorModelBuilder class.
Definition: itkPosteriorModelBuilder.h:57
StatisticalModelType * BuildNewModel(const DataItemListType &dataItemList, const PointValueListType &pointValues, double pointValueNoiseVariance, double noiseVariance) const
Definition: PosteriorModelBuilder.hxx:65
Generic Exception class for the statismo Library.
Definition: Exceptions.h:68
StatisticalModelType * BuildNewModelFromModel(const StatisticalModelType *model, const PointValueListType &pointValues, double pointValueNoiseVariance, bool computeScores=true) const
Definition: PosteriorModelBuilder.hxx:76
A Point/Value pair that is used to specify a value at a given point.
Definition: StatisticalModel.h:100
Given a statistical model (prior) and a set of point constraints (likelihood), generate a new PCA mod...
Definition: PosteriorModelBuilder.h:71
ITK Wrapper for the statismo::StatisticalModel class.
Definition: itkStatisticalModel.h:62