24 #include "mirtk/Math.h" 25 #include "mirtk/Vector3D.h" 26 #include "mirtk/Vector4D.h" 27 #include "mirtk/VectorND.h" 28 #include "mirtk/String.h" 46 MIRTK_VOXEL_UNSIGNED_CHAR,
48 MIRTK_VOXEL_UNSIGNED_SHORT,
50 MIRTK_VOXEL_UNSIGNED_INT,
69 MIRTK_VOXEL_DOUBLE1x1,
70 MIRTK_VOXEL_DOUBLE2x2,
71 MIRTK_VOXEL_DOUBLE3x3,
72 MIRTK_VOXEL_DOUBLE3x4,
73 MIRTK_VOXEL_DOUBLE4x4,
77 MIRTK_VOXEL_BINARY = MIRTK_VOXEL_UNSIGNED_CHAR,
78 MIRTK_VOXEL_BYTE = MIRTK_VOXEL_UNSIGNED_CHAR,
79 MIRTK_VOXEL_GREY = MIRTK_VOXEL_SHORT,
80 #if MIRTK_USE_FLOAT_BY_DEFAULT 81 MIRTK_VOXEL_REAL = MIRTK_VOXEL_FLOAT,
82 MIRTK_VOXEL_REAL1 = MIRTK_VOXEL_FLOAT1,
83 MIRTK_VOXEL_REAL2 = MIRTK_VOXEL_FLOAT2,
84 MIRTK_VOXEL_REAL3 = MIRTK_VOXEL_FLOAT3,
85 MIRTK_VOXEL_REAL4 = MIRTK_VOXEL_FLOAT4,
86 MIRTK_VOXEL_REAL9 = MIRTK_VOXEL_FLOAT9,
87 MIRTK_VOXEL_REAL1x1 = MIRTK_VOXEL_FLOAT1x1,
88 MIRTK_VOXEL_REAL2x2 = MIRTK_VOXEL_FLOAT2x2,
89 MIRTK_VOXEL_REAL3x3 = MIRTK_VOXEL_FLOAT3x3,
90 MIRTK_VOXEL_REAL3x4 = MIRTK_VOXEL_FLOAT3x4,
91 MIRTK_VOXEL_REAL4x4 = MIRTK_VOXEL_FLOAT4x4
92 #else // MIRTK_USE_FLOAT_BY_DEFAULT 93 MIRTK_VOXEL_REAL = MIRTK_VOXEL_DOUBLE,
94 MIRTK_VOXEL_REAL1 = MIRTK_VOXEL_DOUBLE1,
95 MIRTK_VOXEL_REAL2 = MIRTK_VOXEL_DOUBLE2,
96 MIRTK_VOXEL_REAL3 = MIRTK_VOXEL_DOUBLE3,
97 MIRTK_VOXEL_REAL4 = MIRTK_VOXEL_DOUBLE4,
98 MIRTK_VOXEL_REAL9 = MIRTK_VOXEL_DOUBLE9,
99 MIRTK_VOXEL_REAL1x1 = MIRTK_VOXEL_DOUBLE1x1,
100 MIRTK_VOXEL_REAL2x2 = MIRTK_VOXEL_DOUBLE2x2,
101 MIRTK_VOXEL_REAL3x3 = MIRTK_VOXEL_DOUBLE3x3,
102 MIRTK_VOXEL_REAL3x4 = MIRTK_VOXEL_DOUBLE3x4,
103 MIRTK_VOXEL_REAL4x4 = MIRTK_VOXEL_DOUBLE4x4
104 #endif // MIRTK_USE_FLOAT_BY_DEFAULT 120 inline int ToVTKDataType(
int type)
123 case MIRTK_VOXEL_CHAR:
return VTK_CHAR;
124 case MIRTK_VOXEL_UNSIGNED_CHAR:
return VTK_UNSIGNED_CHAR;
125 case MIRTK_VOXEL_SHORT:
return VTK_SHORT;
126 case MIRTK_VOXEL_UNSIGNED_SHORT:
return VTK_UNSIGNED_SHORT;
127 case MIRTK_VOXEL_INT:
return VTK_INT;
128 case MIRTK_VOXEL_UNSIGNED_INT:
return VTK_UNSIGNED_INT;
129 case MIRTK_VOXEL_FLOAT:
return VTK_FLOAT;
130 case MIRTK_VOXEL_DOUBLE:
return VTK_DOUBLE;
131 default:
return VTK_VOID;
137 inline int FromVTKDataType(
int type)
140 case VTK_CHAR:
return MIRTK_VOXEL_CHAR;
141 case VTK_UNSIGNED_CHAR:
return MIRTK_VOXEL_UNSIGNED_CHAR;
142 case VTK_SHORT:
return MIRTK_VOXEL_SHORT;
143 case VTK_UNSIGNED_SHORT:
return MIRTK_VOXEL_UNSIGNED_SHORT;
144 case VTK_INT:
return MIRTK_VOXEL_INT;
145 case VTK_UNSIGNED_INT:
return MIRTK_VOXEL_UNSIGNED_INT;
146 case VTK_FLOAT:
return MIRTK_VOXEL_FLOAT;
147 case VTK_DOUBLE:
return MIRTK_VOXEL_DOUBLE;
148 default:
return MIRTK_VOXEL_UNKNOWN;
157 typedef unsigned char BinaryPixel;
158 typedef unsigned char BytePixel;
159 typedef short GreyPixel;
160 typedef realt RealPixel;
173 const GreyPixel MIN_GREY = numeric_limits<GreyPixel>::min();
174 const GreyPixel MAX_GREY = numeric_limits<GreyPixel>::max();
183 static double min()
throw();
187 static double max()
throw();
189 static T min_value()
throw();
191 static T max_value()
throw();
195 template <>
struct voxel_limits<char>
197 static char min_value()
throw() {
return numeric_limits<char>::lowest(); }
198 static char max_value()
throw() {
return numeric_limits<char>::max(); }
199 static double min()
throw() {
return static_cast<double>(min_value()); }
200 static double max()
throw() {
return static_cast<double>(max_value()); }
204 template <>
struct voxel_limits<unsigned char>
206 static unsigned char min_value()
throw() {
return numeric_limits<unsigned char>::lowest(); }
207 static unsigned char max_value()
throw() {
return numeric_limits<unsigned char>::max(); }
208 static double min()
throw() {
return static_cast<double>(min_value()); }
209 static double max()
throw() {
return static_cast<double>(max_value()); }
213 template <>
struct voxel_limits<short>
215 static short min_value()
throw() {
return numeric_limits<short>::lowest(); }
216 static short max_value()
throw() {
return numeric_limits<short>::max(); }
217 static double min()
throw() {
return static_cast<double>(min_value()); }
218 static double max()
throw() {
return static_cast<double>(max_value()); }
222 template <>
struct voxel_limits<unsigned short>
224 static unsigned short min_value()
throw() {
return numeric_limits<unsigned short>::lowest(); }
225 static unsigned short max_value()
throw() {
return numeric_limits<unsigned short>::max(); }
226 static double min()
throw() {
return static_cast<double>(min_value()); }
227 static double max()
throw() {
return static_cast<double>(max_value()); }
231 template <>
struct voxel_limits<int> {
232 static int min_value()
throw() {
return numeric_limits<int>::lowest(); }
233 static int max_value()
throw() {
return numeric_limits<int>::max(); }
234 static double min()
throw() {
return static_cast<double>(min_value()); }
235 static double max()
throw() {
return static_cast<double>(max_value()); }
239 template <>
struct voxel_limits<unsigned int>
241 static unsigned int min_value()
throw() {
return numeric_limits<unsigned int>::lowest(); }
242 static unsigned int max_value()
throw() {
return numeric_limits<unsigned int>::max(); }
243 static double min()
throw() {
return static_cast<double >(min_value()); }
244 static double max()
throw() {
return static_cast<double >(max_value()); }
248 template <>
struct voxel_limits<float>
250 static float min_value()
throw() {
return numeric_limits<float>::lowest(); }
251 static float max_value()
throw() {
return numeric_limits<float>::max(); }
252 static double min()
throw() {
return static_cast<double>(min_value()); }
253 static double max()
throw() {
return static_cast<double>(max_value()); }
257 template <>
struct voxel_limits<double>
259 static double min_value()
throw() {
return numeric_limits<double>::lowest(); }
260 static double max_value()
throw() {
return numeric_limits<double>::max(); }
261 static double min()
throw() {
return static_cast<double>(min_value()); }
262 static double max()
throw() {
return static_cast<double>(max_value()); }
266 template <>
struct voxel_limits<float1>
268 static float1 min_value()
throw() {
return make_float1(voxel_limits<float>::min_value()); }
269 static float1 max_value()
throw() {
return make_float1(voxel_limits<float>::max_value()); }
270 static double min()
throw() {
return voxel_limits<float>::min(); }
271 static double max()
throw() {
return voxel_limits<float>::max(); }
275 template <>
struct voxel_limits<float2>
277 static float2 min_value()
throw() {
return make_float2(voxel_limits<float>::min_value()); }
278 static float2 max_value()
throw() {
return make_float2(voxel_limits<float>::max_value()); }
279 static double min()
throw() {
return voxel_limits<float>::min(); }
280 static double max()
throw() {
return voxel_limits<float>::max(); }
284 template <>
struct voxel_limits<float3>
286 static float3 min_value()
throw() {
return make_float3(voxel_limits<float>::min_value()); }
287 static float3 max_value()
throw() {
return make_float3(voxel_limits<float>::max_value()); }
288 static double min()
throw() {
return voxel_limits<float>::min(); }
289 static double max()
throw() {
return voxel_limits<float>::max(); }
293 template <>
struct voxel_limits<float4>
295 static float4 min_value()
throw() {
return make_float4(voxel_limits<float>::min_value()); }
296 static float4 max_value()
throw() {
return make_float4(voxel_limits<float>::max_value()); }
297 static double min()
throw() {
return voxel_limits<float>::min(); }
298 static double max()
throw() {
return voxel_limits<float>::max(); }
302 template <>
struct voxel_limits<float3x3>
304 static float3x3 min_value()
throw() {
return make_float3x3(voxel_limits<float>::min_value()); }
305 static float3x3 max_value()
throw() {
return make_float3x3(voxel_limits<float>::max_value()); }
306 static double min()
throw() {
return voxel_limits<float>::min(); }
307 static double max()
throw() {
return voxel_limits<float>::max(); }
311 template <>
struct voxel_limits<double1>
313 static double1 min_value()
throw() {
return make_double1(voxel_limits<double>::min_value()); }
314 static double1 max_value()
throw() {
return make_double1(voxel_limits<double>::max_value()); }
315 static double min()
throw() {
return voxel_limits<double>::min(); }
316 static double max()
throw() {
return voxel_limits<double>::max(); }
320 template <>
struct voxel_limits<double2>
322 static double2 min_value()
throw() {
return make_double2(voxel_limits<double>::min_value()); }
323 static double2 max_value()
throw() {
return make_double2(voxel_limits<double>::max_value()); }
324 static double min()
throw() {
return voxel_limits<double>::min(); }
325 static double max()
throw() {
return voxel_limits<double>::max(); }
329 template <>
struct voxel_limits<double3>
331 static double3 min_value()
throw() {
return make_double3(voxel_limits<double>::min_value()); }
332 static double3 max_value()
throw() {
return make_double3(voxel_limits<double>::max_value()); }
333 static double min()
throw() {
return voxel_limits<double>::min(); }
334 static double max()
throw() {
return voxel_limits<double>::max(); }
338 template <>
struct voxel_limits<double4>
340 static double4 min_value()
throw() {
return make_double4(voxel_limits<double>::min_value()); }
341 static double4 max_value()
throw() {
return make_double4(voxel_limits<double>::max_value()); }
342 static double min()
throw() {
return voxel_limits<double>::min(); }
343 static double max()
throw() {
return voxel_limits<double>::max(); }
347 template <>
struct voxel_limits<double3x3>
349 static double3x3 min_value()
throw() {
return make_double3x3(voxel_limits<double>::min_value()); }
350 static double3x3 max_value()
throw() {
return make_double3x3(voxel_limits<double>::max_value()); }
351 static double min()
throw() {
return voxel_limits<double>::min(); }
352 static double max()
throw() {
return voxel_limits<double>::max(); }
356 template <>
struct voxel_limits<Float3>
358 static Float3 min_value()
throw()
359 {
return Float3(voxel_limits<float>::min_value()); }
360 static Float3 max_value()
throw()
361 {
return Float3(voxel_limits<float>::max_value()); }
362 static double min()
throw() {
return voxel_limits<float>::min(); }
363 static double max()
throw() {
return voxel_limits<float>::max(); }
367 template <>
struct voxel_limits<Double3>
369 static Double3 min_value()
throw()
370 {
return Double3(voxel_limits<double>::min_value()); }
371 static Double3 max_value()
throw()
372 {
return Double3(voxel_limits<double>::max_value()); }
373 static double min()
throw() {
return voxel_limits<double>::min(); }
374 static double max()
throw() {
return voxel_limits<double>::max(); }
378 template <>
struct voxel_limits<Float4>
380 static Float4 min_value()
throw()
381 {
return Float4(voxel_limits<float>::min_value()); }
382 static Float4 max_value()
throw()
383 {
return Float4(voxel_limits<float>::max_value()); }
384 static double min()
throw() {
return voxel_limits<float>::min(); }
385 static double max()
throw() {
return voxel_limits<float>::max(); }
389 template <>
struct voxel_limits<Double4>
391 static Double4 min_value()
throw()
392 {
return Double4(voxel_limits<double>::min_value()); }
393 static Double4 max_value()
throw()
394 {
return Double4(voxel_limits<double>::max_value()); }
395 static double min()
throw() {
return voxel_limits<double>::min(); }
396 static double max()
throw() {
return voxel_limits<double>::max(); }
400 template <>
struct voxel_limits<Float9>
402 static Float9 min_value()
throw()
403 {
return Float9(voxel_limits<float>::min_value()); }
404 static Float9 max_value()
throw()
405 {
return Float9(voxel_limits<float>::max_value()); }
406 static double min()
throw() {
return voxel_limits<float>::min(); }
407 static double max()
throw() {
return voxel_limits<float>::max(); }
411 template <>
struct voxel_limits<Double9>
413 static Double9 min_value()
throw()
414 {
return Double9(voxel_limits<double>::min_value()); }
415 static Double9 max_value()
throw()
416 {
return Double9(voxel_limits<double>::max_value()); }
417 static double min()
throw() {
return voxel_limits<double>::min(); }
418 static double max()
throw() {
return voxel_limits<double>::max(); }
425 template <>
struct voxel_limits<Vector>
427 static Vector min_value()
throw() {
return Vector(1, min()); }
428 static Vector max_value()
throw() {
return Vector(1, max()); }
429 static double min()
throw() {
return numeric_limits<double>::lowest(); }
430 static double max()
throw() {
return numeric_limits<double>::max(); }
438 int DataTypeSize(
int);
441 inline string DataTypeName(
int type)
443 return ToString(static_cast<ImageDataType>(type));
447 inline int ToDataType(
const char *str)
451 return MIRTK_VOXEL_UNKNOWN;
455 inline int ToDataType(
const string &str)
457 return ToDataType(str.c_str());
462 struct voxel_info :
public voxel_limits<T>
465 typedef T ScalarType;
467 typedef RealPixel RealType;
469 static int vector_size()
throw();
471 static int element_type()
throw();
473 static int type()
throw();
477 using voxel_limits<T>::min;
481 using voxel_limits<T>::max;
483 using voxel_limits<T>::min_value;
485 using voxel_limits<T>::max_value;
489 template <>
struct voxel_info<char>
491 typedef char ScalarType;
492 typedef RealPixel RealType;
493 static int vector_size()
throw() {
return 1; }
494 static int element_type()
throw() {
return MIRTK_VOXEL_CHAR; }
495 static int type()
throw() {
return MIRTK_VOXEL_CHAR; }
499 template <>
struct voxel_info<unsigned char>
501 typedef unsigned char ScalarType;
502 typedef RealPixel RealType;
503 static int vector_size()
throw() {
return 1; }
504 static int element_type()
throw() {
return MIRTK_VOXEL_UNSIGNED_CHAR; }
505 static int type()
throw() {
return MIRTK_VOXEL_UNSIGNED_CHAR; }
509 template <>
struct voxel_info<short>
511 typedef short ScalarType;
512 typedef RealPixel RealType;
513 static int vector_size()
throw() {
return 1; }
514 static int element_type()
throw() {
return MIRTK_VOXEL_SHORT; }
515 static int type()
throw() {
return MIRTK_VOXEL_SHORT; }
519 template <>
struct voxel_info<unsigned short>
521 typedef unsigned short ScalarType;
522 typedef RealPixel RealType;
523 static int vector_size()
throw() {
return 1; }
524 static int element_type()
throw() {
return MIRTK_VOXEL_UNSIGNED_SHORT; }
525 static int type()
throw() {
return MIRTK_VOXEL_UNSIGNED_SHORT; }
529 template <>
struct voxel_info<int>
531 typedef int ScalarType;
532 typedef RealPixel RealType;
533 static int vector_size()
throw() {
return 1; }
534 static int element_type()
throw() {
return MIRTK_VOXEL_INT; }
535 static int type()
throw() {
return MIRTK_VOXEL_INT; }
539 template <>
struct voxel_info<unsigned int>
541 typedef unsigned int ScalarType;
542 typedef RealPixel RealType;
543 static int vector_size()
throw() {
return 1; }
544 static int element_type()
throw() {
return MIRTK_VOXEL_UNSIGNED_INT; }
545 static int type()
throw() {
return MIRTK_VOXEL_UNSIGNED_INT; }
549 template <>
struct voxel_info<float>
551 typedef float1 Type1;
552 typedef float2 Type2;
553 typedef float3 Type3;
554 typedef float4 Type4;
556 typedef float3x3 Type3x3;
559 typedef float ScalarType;
560 typedef float RealType;
561 static int vector_size()
throw() {
return 1; }
562 static int element_type()
throw() {
return MIRTK_VOXEL_FLOAT; }
563 static int type()
throw() {
return MIRTK_VOXEL_FLOAT; }
567 template <>
struct voxel_info<float1>
569 typedef float ScalarType;
570 typedef float1 RealType;
571 static int vector_size()
throw() {
return 1; }
572 static int element_type()
throw() {
return MIRTK_VOXEL_FLOAT; }
573 static int type()
throw() {
return MIRTK_VOXEL_FLOAT1; }
577 template <>
struct voxel_info<float2>
579 typedef float ScalarType;
580 typedef float2 RealType;
581 static int vector_size()
throw() {
return 2; }
582 static int element_type()
throw() {
return MIRTK_VOXEL_FLOAT; }
583 static int type()
throw() {
return MIRTK_VOXEL_FLOAT2; }
587 template <>
struct voxel_info<float3>
589 typedef float ScalarType;
590 typedef float3 RealType;
591 static int vector_size()
throw() {
return 3; }
592 static int element_type()
throw() {
return MIRTK_VOXEL_FLOAT; }
593 static int type()
throw() {
return MIRTK_VOXEL_FLOAT3; }
597 template <>
struct voxel_info<float4>
599 typedef float ScalarType;
600 typedef float4 RealType;
601 static int vector_size()
throw() {
return 4; }
602 static int element_type()
throw() {
return MIRTK_VOXEL_FLOAT; }
603 static int type()
throw() {
return MIRTK_VOXEL_FLOAT4; }
607 template <>
struct voxel_info<float3x3>
609 typedef float ScalarType;
610 typedef float3x3 RealType;
611 static int vector_size()
throw() {
return 9; }
612 static int element_type()
throw() {
return MIRTK_VOXEL_FLOAT; }
613 static int type()
throw() {
return MIRTK_VOXEL_FLOAT3x3; }
617 template <>
struct voxel_info<double>
619 typedef double1 Type1;
620 typedef double2 Type2;
621 typedef double3 Type3;
622 typedef double4 Type4;
624 typedef double3x3 Type3x3;
627 typedef double ScalarType;
628 typedef double RealType;
629 static int vector_size()
throw() {
return 1; }
630 static int element_type()
throw() {
return MIRTK_VOXEL_DOUBLE; }
631 static int type()
throw() {
return MIRTK_VOXEL_DOUBLE; }
635 template <>
struct voxel_info<double1>
637 typedef double ScalarType;
638 typedef double1 RealType;
639 static int vector_size()
throw() {
return 1; }
640 static int element_type()
throw() {
return MIRTK_VOXEL_DOUBLE; }
641 static int type()
throw() {
return MIRTK_VOXEL_DOUBLE1; }
645 template <>
struct voxel_info<double2>
647 typedef double ScalarType;
648 typedef double2 RealType;
649 static int vector_size()
throw() {
return 2; }
650 static int element_type()
throw() {
return MIRTK_VOXEL_DOUBLE; }
651 static int type()
throw() {
return MIRTK_VOXEL_DOUBLE2; }
655 template <>
struct voxel_info<double3>
657 typedef double ScalarType;
658 typedef double3 RealType;
659 static int vector_size()
throw() {
return 3; }
660 static int element_type()
throw() {
return MIRTK_VOXEL_DOUBLE; }
661 static int type()
throw() {
return MIRTK_VOXEL_DOUBLE3; }
665 template <>
struct voxel_info<double4>
667 typedef double ScalarType;
668 typedef double4 RealType;
669 static int vector_size()
throw() {
return 4; }
670 static int element_type()
throw() {
return MIRTK_VOXEL_DOUBLE; }
671 static int type()
throw() {
return MIRTK_VOXEL_DOUBLE4; }
675 template <>
struct voxel_info<double3x3>
677 typedef double ScalarType;
678 typedef double3x3 RealType;
679 static int vector_size()
throw() {
return 9; }
680 static int element_type()
throw() {
return MIRTK_VOXEL_DOUBLE; }
681 static int type()
throw() {
return MIRTK_VOXEL_DOUBLE3x3; }
688 template <>
struct voxel_info<Vector>
690 typedef double ScalarType;
691 typedef double RealType;
692 static int vector_size()
throw() {
return 1; }
693 static int element_type()
throw() {
return MIRTK_VOXEL_DOUBLE; }
694 static int type()
throw() {
return MIRTK_VOXEL_DOUBLE; }
698 template <>
struct voxel_info<Float3>
700 typedef float ScalarType;
701 typedef Float3 RealType;
702 static int vector_size()
throw() {
return 3; }
703 static int element_type()
throw() {
return MIRTK_VOXEL_FLOAT; }
704 static int type()
throw() {
return MIRTK_VOXEL_FLOAT3; }
708 template <>
struct voxel_info<Double3>
710 typedef double ScalarType;
711 typedef Double3 RealType;
712 static int vector_size()
throw() {
return 3; }
713 static int element_type()
throw() {
return MIRTK_VOXEL_DOUBLE; }
714 static int type()
throw() {
return MIRTK_VOXEL_DOUBLE3; }
718 template <>
struct voxel_info<Float4>
720 typedef float ScalarType;
721 typedef Float4 RealType;
722 static int vector_size()
throw() {
return 4; }
723 static int element_type()
throw() {
return MIRTK_VOXEL_FLOAT; }
724 static int type()
throw() {
return MIRTK_VOXEL_FLOAT4; }
728 template <>
struct voxel_info<Double4>
730 typedef double ScalarType;
731 typedef Double4 RealType;
732 static int vector_size()
throw() {
return 4; }
733 static int element_type()
throw() {
return MIRTK_VOXEL_DOUBLE; }
734 static int type()
throw() {
return MIRTK_VOXEL_DOUBLE4; }
738 template <>
struct voxel_info<Float9>
740 typedef float ScalarType;
741 typedef Float9 RealType;
742 static int vector_size()
throw() {
return 9; }
743 static int element_type()
throw() {
return MIRTK_VOXEL_FLOAT; }
744 static int type()
throw() {
return MIRTK_VOXEL_FLOAT4; }
748 template <>
struct voxel_info<Double9>
750 typedef double ScalarType;
751 typedef Double9 RealType;
752 static int vector_size()
throw() {
return 9; }
753 static int element_type()
throw() {
return MIRTK_VOXEL_DOUBLE; }
754 static int type()
throw() {
return MIRTK_VOXEL_DOUBLE4; }
760 #endif // MIRTK_Voxel_H 2x2 single-precision matrix
3x4 single-precision coordinate transformation matrix
4x4 single-precision matrix
ImageDataType
Enumeration of voxel data types.
3x4 double-precision coordinate transformation matrix
4x4 double-precision matrix
2x2 double-precision matrix
string ToString(const EnergyMeasure &value, int w, char c, bool left)
Convert energy measure enumeration value to string.
bool FromString(const char *str, EnergyMeasure &value)
Convert energy measure string to enumeration value.