39 #ifndef __ITK_TYPE_CONVERSION_TRAIT
40 #define __ITK_TYPE_CONVERSION_TRAIT
42 #include <itkVector.h>
44 #include "Exceptions.h"
45 #include "CommonTypes.h"
52 template <
typename T>
struct PixelConversionTrait {
53 static statismo::VectorType ToVector(
const T& pixel) {
56 static T FromVector(
const statismo::VectorType& v) {
59 static unsigned GetDataType() {
62 static unsigned GetPixelDimension() {
67 template <>
struct PixelConversionTrait<double> {
68 static statismo::VectorType ToVector(
const double& pixel) {
69 statismo::VectorType v(1);
73 static double FromVector(
const statismo::VectorType& v) {
74 assert(v.size() == 1);
77 static unsigned GetDataType() {
78 return statismo::DOUBLE;
80 static unsigned GetPixelDimension() {
84 template <>
struct PixelConversionTrait<float> {
85 static statismo::VectorType ToVector(
const float& pixel) {
86 statismo::VectorType v(1);
90 static float FromVector(
const statismo::VectorType& v) {
91 assert(v.size() == 1);
94 static unsigned GetDataType() {
95 return statismo::FLOAT;
97 static unsigned GetPixelDimension() {
101 template <>
struct PixelConversionTrait<short> {
102 static statismo::VectorType ToVector(
const short& pixel) {
103 statismo::VectorType v(1);
107 static short FromVector(
const statismo::VectorType& v) {
108 assert(v.size() == 1);
111 static unsigned GetDataType() {
112 return statismo::SIGNED_SHORT;
114 static unsigned GetPixelDimension() {
118 template <>
struct PixelConversionTrait<unsigned short> {
119 static statismo::VectorType ToVector(
const unsigned short& pixel) {
120 statismo::VectorType v(1);
124 static unsigned short FromVector(
const statismo::VectorType& v) {
125 assert(v.size() == 1);
128 static unsigned GetDataType() {
129 return statismo::UNSIGNED_SHORT;
131 static unsigned GetPixelDimension() {
135 template <>
struct PixelConversionTrait<int> {
136 static statismo::VectorType ToVector(
const int& pixel) {
137 statismo::VectorType v(1);
141 static int FromVector(
const statismo::VectorType& v) {
142 assert(v.size() == 1);
145 static unsigned GetDataType() {
146 return statismo::SIGNED_INT;
148 static unsigned GetPixelDimension() {
152 template <>
struct PixelConversionTrait<unsigned int> {
153 static statismo::VectorType ToVector(
const unsigned int& pixel) {
154 statismo::VectorType v(1);
158 static unsigned int FromVector(
const statismo::VectorType& v) {
159 assert(v.size() == 1);
162 static unsigned GetDataType() {
163 return statismo::UNSIGNED_SHORT;
165 static unsigned GetPixelDimension() {
169 template <>
struct PixelConversionTrait<char> {
170 static statismo::VectorType ToVector(
const char& pixel) {
171 statismo::VectorType v(1);
175 static char FromVector(
const statismo::VectorType& v) {
176 assert(v.size() == 1);
179 static unsigned GetDataType() {
180 return statismo::SIGNED_CHAR;
182 static unsigned GetPixelDimension() {
186 template <>
struct PixelConversionTrait<unsigned char> {
187 static statismo::VectorType ToVector(
const unsigned char& pixel) {
188 statismo::VectorType v(1);
192 static unsigned char FromVector(
const statismo::VectorType& v) {
193 assert(v.size() == 1);
196 static unsigned GetDataType() {
197 return statismo::UNSIGNED_CHAR;
199 static unsigned GetPixelDimension() {
204 template <>
struct PixelConversionTrait<long> {
205 static statismo::VectorType ToVector(
const long& pixel) {
206 statismo::VectorType v(1);
210 static long FromVector(
const statismo::VectorType& v) {
211 assert(v.size() == 1);
214 static unsigned GetDataType() {
215 return statismo::SIGNED_LONG;
217 static unsigned GetPixelDimension() {
221 template <>
struct PixelConversionTrait<unsigned long> {
222 static statismo::VectorType ToVector(
const unsigned long& pixel) {
223 statismo::VectorType v(1);
227 static unsigned long FromVector(
const statismo::VectorType& v) {
228 assert(v.size() == 1);
231 static unsigned GetDataType() {
232 return statismo::UNSIGNED_LONG;
234 static unsigned GetPixelDimension() {
239 template <>
struct PixelConversionTrait<itk::Vector<float, 2> > {
240 static statismo::VectorType ToVector(
const itk::Vector<float, 2>& pixel) {
241 statismo::VectorType v(2);
242 v << pixel[0] , pixel[1];
245 static itk::Vector<float, 2> FromVector(
const statismo::VectorType& v) {
246 assert(v.size() == 2);
247 itk::Vector<double, 2> itkVec;
252 static unsigned GetDataType() {
253 return statismo::FLOAT;
255 static unsigned GetPixelDimension() {
260 template <>
struct PixelConversionTrait<itk::Vector<float, 3> > {
261 static statismo::VectorType ToVector(
const itk::Vector<float, 3>& pixel) {
262 statismo::VectorType v(3);
263 v << pixel[0] , pixel[1], pixel[2];
266 static itk::Vector<float, 3> FromVector(
const statismo::VectorType& v) {
267 assert(v.size() == 3);
268 itk::Vector<double, 3> itkVec;
274 static unsigned GetDataType() {
275 return statismo::FLOAT;
277 static unsigned GetPixelDimension() {
Generic Exception class for the statismo Library.
Definition: Exceptions.h:68