Statismo  0.10.1
 All Classes Namespaces Functions Typedefs
itkLowRankGPModelBuilder.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 #ifndef ITKLOWRANKMODELBUILDER_H_
39 #define ITKLOWRANKMODELBUILDER_H_
40 
41 #include <itkObject.h>
42 #include <itkObjectFactory.h>
43 
44 #include "itkStatisticalModel.h"
45 
46 #include "Kernels.h"
47 #include "LowRankGPModelBuilder.h"
48 #include "Representer.h"
49 #include "statismoITKConfig.h"
50 
51 namespace itk {
52 
58 template<class T>
59 class LowRankGPModelBuilder: public Object {
60  public:
61 
63  typedef statismo::Representer<T> RepresenterType;
64  typedef Object Superclass;
65  typedef SmartPointer<Self> Pointer;
66  typedef SmartPointer<const Self> ConstPointer;
67 
68  itkNewMacro (Self);
69  itkTypeMacro( LowRankGPModelBuilder, Object );
70 
74 
76  m_impl(0) {
77  }
78 
79 
80  void SetstatismoImplObj(ImplType* impl) {
81  if (m_impl) {
82  delete m_impl;
83  }
84  m_impl = impl;
85  }
86 
87 
88  void SetRepresenter(const RepresenterType* representer) {
89  SetstatismoImplObj(ImplType::Create(representer));
90  }
91 
92  virtual ~LowRankGPModelBuilder() {
93  if (m_impl) {
94  delete m_impl;
95  m_impl = 0;
96  }
97  }
98 
99  typename StatisticalModelType::Pointer BuildNewZeroMeanModel(
100  const MatrixValuedKernelType& kernel, unsigned numComponents,
101  unsigned numPointsForNystrom = 500) const {
102  if (m_impl == 0) {
103  itkExceptionMacro(<< "Model not properly initialized. Maybe you forgot to call SetRepresenter");
104  }
105 
106 
107  statismo::StatisticalModel<T>* model_statismo = 0;
108  try {
109  model_statismo = this->m_impl->BuildNewZeroMeanModel(kernel, numComponents, numPointsForNystrom);
110 
112  itkExceptionMacro(<< s.what());
113  }
114 
115  typename StatisticalModel<T>::Pointer model_itk = StatisticalModel<T>::New();
116  model_itk->SetstatismoImplObj(model_statismo);
117  return model_itk;
118 
119  }
120 
121  typename StatisticalModelType::Pointer BuildNewModel(typename RepresenterType::DatasetType* mean, const MatrixValuedKernelType& kernel, unsigned numComponents, unsigned numPointsForNystrom = 500) {
122  if (m_impl == 0) {
123  itkExceptionMacro(<< "Model not properly initialized. Maybe you forgot to call SetRepresenter");
124  }
125 
126  statismo::StatisticalModel<T>* model_statismo = 0;
127  try {
128  model_statismo = this->m_impl->BuildNewModel(mean, kernel, numComponents, numPointsForNystrom);
129 
131  itkExceptionMacro(<< s.what());
132  }
133 
134 
135  typename StatisticalModel<T>::Pointer model_itk = StatisticalModel<T>::New();
136  model_itk->SetstatismoImplObj(model_statismo);
137  return model_itk;
138 
139  }
140 
141  private:
143  LowRankGPModelBuilder& operator=(const LowRankGPModelBuilder& rhs);
144 
145  ImplType* m_impl;
146 };
147 
148 }
149 
150 #endif /* ITKLOWRANKMODELBUILDER_H_ */
StatisticalModelType * BuildNewZeroMeanModel(const MatrixValuedKernelType &kernel, unsigned numComponents, unsigned numPointsForNystrom=500) const
Definition: LowRankGPModelBuilder.h:138
StatisticalModelType * BuildNewModel(typename RepresenterType::DatasetConstPointerType mean, const MatrixValuedKernelType &kernel, unsigned numComponents, unsigned numPointsForNystrom=500) const
Definition: LowRankGPModelBuilder.h:162
Definition: Kernels.h:63
static LowRankGPModelBuilder * Create(const RepresenterType *representer)
Definition: LowRankGPModelBuilder.h:110
Generic Exception class for the statismo Library.
Definition: Exceptions.h:68
Definition: LowRankGPModelBuilder.h:92
ITK Wrapper for the statismo::LowRankGPModelBuilder class.
Definition: itkLowRankGPModelBuilder.h: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