Statismo  0.10.1
 All Classes Namespaces Functions Typedefs
itkDataManagerWithSurrogates.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_DATAMANAGER_WITH_SURROGATES_H_
40 #define ITK_DATAMANAGER_WITH_SURROGATES_H_
41 
42 #include <boost/bind.hpp>
43 #include <boost/utility/result_of.hpp>
44 
45 #include <itkObject.h>
46 #include <itkObjectFactory.h>
47 
48 #include "DataManagerWithSurrogates.h"
49 #include "statismoITKConfig.h"
50 
51 namespace itk {
52 
53 
58 template <class Representer>
59 class DataManagerWithSurrogates : public statismo::DataManager<Representer> {
60  public:
61 
62 
65  typedef SmartPointer<Self> Pointer;
66  typedef SmartPointer<const Self> ConstPointer;
67 
68  itkNewMacro( Self );
69  itkTypeMacro( DataManagerWithSurrogates, Object );
70 
71 
73 
74  template <class F>
75  typename boost::result_of<F()>::type callstatismoImpl(F f) const {
76  if (m_impl == 0) {
77  itkExceptionMacro(<< "Model not properly initialized. Maybe you forgot to call SetParameters");
78  }
79  try {
80  return f();
82  itkExceptionMacro(<< s.what());
83  }
84  }
85 
86 
87  DataManagerWithSurrogates() : m_impl(0) {}
88 
89  virtual ~DataManagerWithSurrogates() {
90  if (m_impl) {
91  delete m_impl;
92  m_impl = 0;
93  }
94  }
95 
96 
97  void SetstatismoImplObj(ImplType* impl) {
98  if (m_impl) {
99  delete m_impl;
100  }
101  m_impl = impl;
102  }
103 
104  void SetRepresenterAndSurrogateFilename(const Representer* representer, const char* surrogTypeFilename) {
105  SetstatismoImplObj(ImplType::Create(representer, surrogTypeFilename));
106  }
107 
108  void SetRepresenter(const Representer* representer) {
109  itkExceptionMacro(<< "Please call SetRepresenterAndSurrogateFilename to initialize the object");
110  }
111 
112 
113 
114  void AddDatasetWithSurrogates(typename Representer::DatasetConstPointerType ds,
115  const char* datasetURI,
116  const char* surrogateFilename) {
117  callstatismoImpl(boost::bind(&ImplType::AddDatasetWithSurrogates, this->m_impl, ds, datasetURI, surrogateFilename));
118  }
119 
120 
121  private:
122 
125 
126  ImplType* m_impl;
127 };
128 
129 
130 }
131 
132 #endif /* ITK_DATAMANAGER_WITH_SURROGATES_H_ */
Manages Training and Test Data for building Statistical Models and provides functionality for Crossva...
Definition: DataManager.h:114
Manages Training and Test Data for building Statistical Models and provides functionality for Crossva...
Definition: DataManagerWithSurrogates.h:56
static DataManagerWithSurrogates< T > * Create(const RepresenterType *representer, const std::string &surrogTypeFilename)
Definition: DataManagerWithSurrogates.h:86
Generic Exception class for the statismo Library.
Definition: Exceptions.h:68
ITK Wrapper for the statismo::DataManager class.
Definition: itkDataManagerWithSurrogates.h:59
void AddDatasetWithSurrogates(DatasetConstPointerType ds, const std::string &datasetURI, const std::string &surrogateFilename)
Definition: DataManagerWithSurrogates.hxx:79