Statismo  0.10.1
 All Classes Namespaces Functions Typedefs
itkReducedVarianceModelBuilder.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_PARTIALLY_FIXED_MODELBUILDER_H_
40 #define ITK_PARTIALLY_FIXED_MODELBUILDER_H_
41 
42 #include <itkObject.h>
43 
44 #include "itkDataManager.h"
45 #include "itkStatisticalModel.h"
46 
47 #include "ReducedVarianceModelBuilder.h"
48 #include "statismoITKConfig.h"
49 #include "StatismoUtils.h"
50 
51 namespace itk {
52 
57 template <class Representer>
58 class ReducedVarianceModelBuilder : public Object {
59  public:
60 
62  typedef Object Superclass;
63  typedef SmartPointer<Self> Pointer;
64  typedef SmartPointer<const Self> ConstPointer;
65 
66  itkNewMacro( Self );
67  itkTypeMacro( ReducedVarianceModelBuilder, Object );
68 
70 
71 
72  template <class F>
73  typename boost::result_of<F()>::type callstatismoImpl(F f) const {
74  try {
75  return f();
77  itkExceptionMacro(<< s.what());
78  }
79  }
80 
81 
83 
84  virtual ~ReducedVarianceModelBuilder() {
85  if (m_impl) {
86  delete m_impl;
87  m_impl = 0;
88  }
89  }
90 
91 
92 
93  typename StatisticalModel<Representer>::Pointer BuildNewModelWithLeadingComponents(const StatisticalModel<Representer>* model, unsigned numberOfPrincipalComponents) {
94  statismo::StatisticalModel<Representer>* model_statismo = model->GetstatismoImplObj();
95  statismo::StatisticalModel<Representer>* new_model_statismo = callstatismoImpl(boost::bind(&ImplType::BuildNewModelWithLeadingComponents, this->m_impl, model_statismo, numberOfPrincipalComponents));
96  typename StatisticalModel<Representer>::Pointer model_itk = StatisticalModel<Representer>::New();
97  model_itk->SetstatismoImplObj(new_model_statismo);
98  return model_itk;
99  }
100 
101  typename StatisticalModel<Representer>::Pointer BuildNewModelWithVariance(const StatisticalModel<Representer>* model, double totalVariance) {
102  statismo::StatisticalModel<Representer>* model_statismo = model->GetstatismoImplObj();
103  statismo::StatisticalModel<Representer>* new_model_statismo = callstatismoImpl(boost::bind(&ImplType::BuildNewModelWithVariance, this->m_impl, model_statismo, totalVariance));
104  typename StatisticalModel<Representer>::Pointer model_itk = StatisticalModel<Representer>::New();
105  model_itk->SetstatismoImplObj(new_model_statismo);
106  return model_itk;
107  }
108 
109  is_deprecated typename StatisticalModel<Representer>::Pointer BuildNewModelFromModel(const StatisticalModel<Representer>* model, double totalVariance) {
110  statismo::StatisticalModel<Representer>* model_statismo = model->GetstatismoImplObj();
111  statismo::StatisticalModel<Representer>* new_model_statismo = callstatismoImpl(boost::bind(&ImplType::BuildNewModelFromModel, this->m_impl, model_statismo, totalVariance));
112  typename StatisticalModel<Representer>::Pointer model_itk = StatisticalModel<Representer>::New();
113  model_itk->SetstatismoImplObj(new_model_statismo);
114  return model_itk;
115  }
116 
117 
118  private:
121 
122  ImplType* m_impl;
123 };
124 
125 
126 }
127 
128 #endif /* ITK_PARTIALLY_FIXED_MODEL_BUILDER */
static ReducedVarianceModelBuilder * Create()
Definition: ReducedVarianceModelBuilder.h:71
ITK Wrapper for the statismo::ReducedVarianceModelBuilder class.
Definition: itkReducedVarianceModelBuilder.h:58
StatisticalModelType * BuildNewModelWithVariance(const StatisticalModelType *model, double totalVariance) const
Definition: ReducedVarianceModelBuilder.hxx:97
Builds a new model which retains only the specified total variance.
Definition: ReducedVarianceModelBuilder.h:60
Generic Exception class for the statismo Library.
Definition: Exceptions.h:68
StatisticalModelType * BuildNewModelWithLeadingComponents(const StatisticalModelType *model, unsigned numberOfPrincipalComponents) const
Definition: ReducedVarianceModelBuilder.hxx:59
A Point/Value pair that is used to specify a value at a given point.
Definition: StatisticalModel.h:100
ITK Wrapper for the statismo::StatisticalModel class.
Definition: itkStatisticalModel.h:62