Statismo  0.10.1
 All Classes Namespaces Functions Typedefs
Representer.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 #ifndef REPRESENTER_H_
38 #define REPRESENTER_H_
39 
40 #include <string>
41 #include <H5Cpp.h>
42 
43 #include "CommonTypes.h"
44 #include "Domain.h"
45 
60 //RB: would it be possible to make all representers inherit from it, so as to strictly enforce the interface?
61 namespace statismo {
62 
63 template<class T>
64 class RepresenterTraits {
65 };
66 
67 template<class T>
68 class Representer {
69 
70  public:
71 
72  enum RepresenterDataType {
73  UNKNOWN = 0,
74  POINT_SET = 1,
75  POLYGON_MESH = 2,
76  VOLUME_MESH = 3,
77  IMAGE = 4,
78  VECTOR = 5,
79  CUSTOM = 99
80  };
81 
82  static RepresenterDataType TypeFromString(const std::string& s) {
83  if (s == "POINT_SET")
84  return POINT_SET;
85  else if (s == "POLYGON_MESH")
86  return POLYGON_MESH;
87  else if (s == "VOLUME_MESH")
88  return VOLUME_MESH;
89  else if (s == "IMAGE")
90  return IMAGE;
91  else if (s == "VECTOR")
92  return VECTOR;
93  else if (s == "CUSTOM")
94  return CUSTOM;
95  else
96  return UNKNOWN;
97  }
98 
99  static std::string TypeToString(const RepresenterDataType& type) {
100  switch (type) {
101  case POINT_SET: {
102  return "POINT_SET";
103  break;
104  }
105  case POLYGON_MESH: {
106  return "POLYGON_MESH";
107  break;
108  }
109  case VOLUME_MESH: {
110  return "VOLUME_MESH";
111  break;
112  }
113  case IMAGE: {
114  return "IMAGE";
115  break;
116  }
117  case VECTOR: {
118  return "VECTOR";
119  break;
120  }
121  case CUSTOM: {
122  return "CUSTOM";
123  break;
124  }
125  default: {
126  return "UNKNOWN";
127  }
128  }
129  }
130 
134  typedef typename RepresenterTraits<T>::DatasetPointerType DatasetPointerType;
138 
140  typedef typename RepresenterTraits<T>::DatasetConstPointerType DatasetConstPointerType;
141 
143  typedef typename RepresenterTraits<T>::PointType PointType;
144 
147  typedef typename RepresenterTraits<T>::ValueType ValueType;
148 
149  typedef T DatasetType;
150 
151  typedef Domain<PointType> DomainType;
152 
153  virtual ~Representer() {
154  }
155 
157  virtual std::string GetName() const = 0;
158 
159  virtual RepresenterDataType GetType() const = 0;
160 
163  virtual unsigned GetDimensions() const = 0;
165 
166  virtual std::string GetVersion() const = 0;
167 
171 
176  virtual void Load(const H5::Group& fg) = 0;
177 
179  virtual Representer* Clone() const = 0;
180 
182  virtual void Delete() const = 0;
183 
185 
189  virtual void DeleteDataset(DatasetPointerType d) const = 0;
190  virtual DatasetPointerType CloneDataset(DatasetConstPointerType d) const = 0;
192 
193 
194 
195 
196 
200 
206  virtual const statismo::Domain<PointType>& GetDomain() const = 0;
207 
208 
209  virtual DatasetConstPointerType GetReference() const = 0;
210 
214  virtual VectorType PointToVector(const PointType& pt) const = 0;
215 
219  virtual VectorType SampleToSampleVector(
220  DatasetConstPointerType sample) const = 0;
221 
226  virtual DatasetPointerType SampleVectorToSample(
227  const VectorType& sample) const = 0;
228 
232  virtual ValueType PointSampleFromSample(DatasetConstPointerType sample,
233  unsigned ptid) const = 0;
234 
242  virtual ValueType PointSampleVectorToPointSample(
243  const VectorType& v) const = 0;
244 
249  virtual VectorType PointSampleToPointSampleVector(
250  const ValueType& pointSample) const = 0;
251 
260  virtual unsigned MapPointIdToInternalIdx(unsigned ptId,
261  unsigned componentInd) const {
262  return ptId * GetDimensions() + componentInd;
263  }
264 
268  virtual unsigned GetPointIdForPoint(const PointType& point) const = 0;
269 
271 
275 
280  virtual void Save(const H5::Group& fg) const = 0;
281 
283 };
284 
285 }
286 
287 #endif /* REPRESENTER_H_ */
288 
Definition: Domain.h:51