Statismo  0.10.1
 All Classes Namespaces Functions Typedefs
CommonTypes.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 __COMMON_TYPES_H
39 #define __COMMON_TYPES_H
40 
41 #include <exception>
42 #include <iostream>
43 #include <list>
44 #include <string>
45 #include <vector>
46 
47 #include <boost/functional/hash.hpp>
48 
49 #include <Eigen/Dense>
50 
51 #include "Config.h"
52 #include "Domain.h"
53 #include "Exceptions.h"
54 
55 namespace statismo {
56 
57 const double PI = 3.14159265358979323846;
58 
60 typedef float ScalarType;
61 
62 // wrapper struct that allows us to easily select matrix and vectors of an arbitrary
63 // type, wich has the same traits as the standard matrix / vector traits
64 template <typename TScalar> struct GenericEigenType {
65  typedef Eigen::Matrix<TScalar, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor> MatrixType;
66  typedef Eigen::DiagonalMatrix<TScalar, Eigen::Dynamic> DiagMatrixType;
67  typedef Eigen::Matrix<TScalar, Eigen::Dynamic, 1> VectorType;
68  typedef Eigen::Matrix<TScalar, 1 , Eigen::Dynamic> RowVectorType;
69 
70 };
71 typedef GenericEigenType<ScalarType>::MatrixType MatrixType;
72 typedef GenericEigenType<double>::MatrixType MatrixTypeDoublePrecision;
73 typedef GenericEigenType<ScalarType>::DiagMatrixType DiagMatrixType;
74 typedef GenericEigenType<ScalarType>::VectorType VectorType;
75 typedef GenericEigenType<double>::VectorType VectorTypeDoublePrecision;
76 typedef GenericEigenType<ScalarType>::RowVectorType RowVectorType;
77 
78 // type definitions used in the standard file format.
79 // Note that these are the same as used by VTK
80 const static unsigned Void = 0; // not capitalized, as windows defines: #define VOID void, which causes trouble
81 const static unsigned SIGNED_CHAR = 2;
82 const static unsigned UNSIGNED_CHAR = 3;
83 const static unsigned SIGNED_SHORT = 4;
84 const static unsigned UNSIGNED_SHORT = 5;
85 const static unsigned SIGNED_INT = 6;
86 const static unsigned UNSIGNED_INT = 7;
87 const static unsigned SIGNED_LONG = 8;
88 const static unsigned UNSIGNED_LONG = 9;
89 const static unsigned FLOAT = 10;
90 const static unsigned DOUBLE = 11;
91 
92 template <class T> unsigned GetDataTypeId() {
93  throw StatisticalModelException("The datatype that was provided is not a valid statismo data type ");
94 }
95 template <> inline unsigned GetDataTypeId<signed char>() {
96  return SIGNED_CHAR;
97 }
98 template <> inline unsigned GetDataTypeId<unsigned char>() {
99  return UNSIGNED_CHAR;
100 }
101 template <> inline unsigned GetDataTypeId<signed short>() {
102  return SIGNED_SHORT;
103 }
104 template <> inline unsigned GetDataTypeId<unsigned short>() {
105  return UNSIGNED_SHORT;
106 }
107 template <> inline unsigned GetDataTypeId<signed int>() {
108  return SIGNED_INT;
109 }
110 template <> inline unsigned GetDataTypeId<unsigned int>() {
111  return UNSIGNED_INT;
112 }
113 template <> inline unsigned GetDataTypeId<signed long>() {
114  return SIGNED_LONG;
115 }
116 template <> inline unsigned GetDataTypeId<unsigned long>() {
117  return UNSIGNED_LONG;
118 }
119 template <> inline unsigned GetDataTypeId<float>() {
120  return FLOAT;
121 }
122 template <> inline unsigned GetDataTypeId<double>() {
123  return DOUBLE;
124 }
125 
126 
127 
128 } //namespace statismo
129 
130 // If we want to store a vector in a boost map, boost requires this function to be present.
131 // We define it here once and for all.
132 // Because of the way boost looksup the values, it needs to be defined in the namespace Eigen
133 namespace Eigen {
134 inline size_t hash_value(const statismo::VectorType& v) {
135 
136  size_t value = 0;
137  for (unsigned i = 0; i < v.size(); i++) {
138  boost::hash_combine(value, v(i));
139  }
140  return value;
141 }
142 }
143 
144 #endif
145 
float ScalarType
the type that is used for all vector and matrices throughout the library.
Definition: CommonTypes.h:60