KWStyle - itkPixelTraits.h
 
Matrix View
Description

1 /*=========================================================================
2
3   Program:   Insight Segmentation & Registration Toolkit
4   Module:    $RCSfile: itkPixelTraits.h.html,v $
5   Language:  C++
6   Date:      $Date: 2006/01/17 19:15:43 $
7   Version:   $Revision: 1.4 $
8
9   Copyright (c) Insight Software Consortium. All rights reserved.
10   See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
11
12   Portions of this code are covered under the VTK copyright.
13   See VTKCopyright.txt or http://www.kitware.com/VTKCopyright.htm for details.
14
15      This software is distributed WITHOUT ANY WARRANTY; without even 
16      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
17 IND *****PURPOSE.  See the above copyright notices for more information.
18
19 =========================================================================*/
20 #ifndef __itkPixelTraits_h
21 #define __itkPixelTraits_h
22
23 namespace itk
24 {
25
26 /** \class PixelTraits
27  * \brief Traits for a pixel that define the dimension and component type.
28  *
29  * PixelTraits determines the dimension and the component type
30  * of a pixel.  The default implementation is suitable for all subclasses
31  * of itk::Array. This (will) include RGBPixel and RGBAPixel. Specialized
32  * versions of PixelTraits are defined for the standard scalar types.
33  */
34 template<class TPixelType>
35 class PixelTraits
36 {
37 public:
38   /** Dimension of the pixel (range). */
39   itkStaticConstMacro(Dimension, unsigned int, TPixelType::Length);
40   
41   /** Type of a single component of a pixel. */
42   typedef typename TPixelType::ValueType ValueType;
43 };
44
45 /** Specialization of PixelTraitss for scalar images. */
46 template <>
47 class PixelTraits<bool>
48 MCM {
49 public:
50   itkStaticConstMacro(Dimension, unsigned int, 1);
51   typedef bool ValueType;
52 };
53
54 template <>
55 class PixelTraits<char>
56 {
57 public:
58   itkStaticConstMacro(Dimension, unsigned int, 1);
59   typedef char ValueType;
60 };
61
62 template <>
63 class PixelTraits<signed char>
64 {
65 public:
66   itkStaticConstMacro(Dimension, unsigned int, 1);
67   typedef char ValueType;
68 };
69
70 template <>
71 class PixelTraits<unsigned char>
72 {
73 public:
74   itkStaticConstMacro(Dimension, unsigned int, 1);
75   typedef unsigned char ValueType;
76 };
77
78 template <>
79 class PixelTraits<short>
80 {
81 public:
82   itkStaticConstMacro(Dimension, unsigned int, 1);
83   typedef short ValueType;
84 };
85
86 template <>
87 class PixelTraits<unsigned short>
88 {
89 public:
90   itkStaticConstMacro(Dimension, unsigned int, 1);
91   typedef unsigned short ValueType;
92 };
93
94 template <>
95 class PixelTraits<int>
96 {
97 public:
98   itkStaticConstMacro(Dimension, unsigned int, 1);
99   typedef int ValueType;
100 };
101
102 template <>
103 class PixelTraits<unsigned int>
104 {
105 public:
106   itkStaticConstMacro(Dimension, unsigned int, 1);
107   typedef unsigned int ValueType;
108 };
109
110 template <>
111 class PixelTraits<long>
112 {
113 public:
114   itkStaticConstMacro(Dimension, unsigned int, 1);
115   typedef long ValueType;
116 };
117
118 template <>
119 class PixelTraits<unsigned long>
120 {
121 public:
122   itkStaticConstMacro(Dimension, unsigned int, 1);
123   typedef unsigned long ValueType;
124 };
125
126 template <>
127 class PixelTraits<float>
128 {
129 public:
130   itkStaticConstMacro(Dimension, unsigned int, 1);
131   typedef float ValueType;
132 };
133
134 template <>
135 class PixelTraits<double>
136 {
137 public:
138   itkStaticConstMacro(Dimension, unsigned int, 1);
139   typedef double ValueType;
140 };
141
142 /** \class JoinTraits
143  * \brief Trait to determine what datatype is needed if the specified 
144  * pixel types are "joined" into a single vector.
145  *
146  * JoinTraits defines the value type needed to combine the specified
147  * pixel types into a single vector.  The data type selected is the
148  * smallest data type that can represent the dynamic range of both
149  * input pixel types.  For example, if a char and unsigned short are
150  * "joined", the resulting data type must be a vector of int.  In
151  * some cases, like joining a unsigned int and a char, the join
152  * value type is promoted all the way to a float.  This provides
153  * consistent behavior on both 32 and 64 bit systems (on 64 bit
154  * systems, we could have promoted to a long which is distinct from
155  * an int but this is not the case for 32 bit systems, so we promote
156  * to float). There are several combinations similar to this.  Most
157  * of the JoinTraits are specializations of the base template.
158  */
159 template <class TValueType1, class TValueType2>
160 class JoinTraits
161 {
162 public:
163   typedef TValueType1 ValueType;
164 };
165
166 /** Specializations for bool. */
167 template<>
168 class JoinTraits<bool, bool>
169 MCM {
170 public:
171   typedef bool ValueType;
172 };
173
174 template<>
175 class JoinTraits<bool, char>
176 {
177 public:
178   typedef char ValueType;
179 };
180
181 template<>
182 class JoinTraits<bool, unsigned char>
183 {
184 public:
185   typedef unsigned char ValueType;
186 };
187
188 template<>
189 class JoinTraits<bool, short>
190 {
191 public:
192   typedef short ValueType;
193 };
194
195 template<>
196 class JoinTraits<bool, unsigned short>
197 {
198 public:
199   typedef unsigned short ValueType;
200 };
201
202 template<>
203 class JoinTraits<bool, int>
204 {
205 public:
206   typedef int ValueType;
207 };
208
209 template<>
210 class JoinTraits<bool, unsigned int>
211 {
212 public:
213   typedef unsigned int ValueType;
214 };
215
216 template<>
217 class JoinTraits<bool, long>
218 {
219 public:
220   typedef long ValueType;
221 };
222
223 template<>
224 class JoinTraits<bool, unsigned long>
225 {
226 public:
227   typedef unsigned long ValueType;
228 };
229
230 template<>
231 class JoinTraits<bool, float>
232 {
233 public:
234   typedef float ValueType;
235 };
236
237 template<>
238 class JoinTraits<bool, double>
239 {
240 public:
241   typedef double ValueType;
242 };
243
244 /** Specializations for char. */
245 template<>
246 class JoinTraits<char, bool>
247 MCM {
248 public:
249   typedef char ValueType;
250 };
251
252 template<>
253 class JoinTraits<char, char>
254 {
255 public:
256   typedef char ValueType;
257 };
258
259 template<>
260 class JoinTraits<char, unsigned char>
261 {
262 public:
263   typedef short ValueType;
264 };
265
266 template<>
267 class JoinTraits<char, short>
268 {
269 public:
270   typedef short ValueType;
271 };
272
273 template<>
274 class JoinTraits<char, unsigned short>
275 {
276 public:
277   typedef int ValueType;
278 };
279
280 template<>
281 class JoinTraits<char, int>
282 {
283 public:
284   typedef int ValueType;
285 };
286
287 template<>
288 class JoinTraits<char, unsigned int>
289 {
290 public:
291   // unsigned int & unsigned long may be the same size, so promote to float
292   typedef float ValueType;
293 };
294
295 template<>
296 class JoinTraits<char, long>
297 {
298 public:
299   typedef long ValueType;
300 };
301
302 template<>
303 class JoinTraits<char, unsigned long>
304 {
305 public:
306   typedef float ValueType;
307 };
308
309 template<>
310 class JoinTraits<char, float>
311 {
312 public:
313   typedef float ValueType;
314 };
315
316 template<>
317 class JoinTraits<char, double>
318 {
319 public:
320   typedef double ValueType;
321 };
322
323 /** Specializations for unsigned char. */
324 template<>
325 class JoinTraits<unsigned char, bool>
326 MCM {
327 public:
328   typedef unsigned char ValueType;
329 };
330
331 template<>
332 class JoinTraits<unsigned char, char>
333 {
334 public:
335   typedef short ValueType;
336 };
337
338 template<>
339 class JoinTraits<unsigned char, unsigned char>
340 {
341 public:
342   typedef unsigned char ValueType;
343 };
344
345 template<>
346 class JoinTraits<unsigned char, short>
347 {
348 public:
349   typedef short ValueType;
350 };
351
352 template<>
353 class JoinTraits<unsigned char, unsigned short>
354 {
355 public:
356   typedef unsigned short ValueType;
357 };
358
359 template<>
360 class JoinTraits<unsigned char, int>
361 {
362 public:
363   typedef int ValueType;
364 };
365
366 template<>
367 class JoinTraits<unsigned char, unsigned int>
368 {
369 public:
370   typedef unsigned int ValueType;
371 };
372
373 template<>
374 class JoinTraits<unsigned char, long>
375 {
376 public:
377   typedef long ValueType;
378 };
379
380 template<>
381 class JoinTraits<unsigned char, unsigned long>
382 {
383 public:
384   typedef unsigned long ValueType;
385 };
386
387 template<>
388 class JoinTraits<unsigned char, float>
389 {
390 public:
391   typedef float ValueType;
392 };
393
394 template<>
395 class JoinTraits<unsigned char, double>
396 {
397 public:
398   typedef double ValueType;
399 };
400   
401 /** Specializations for short. */
402 template<>
403 class JoinTraits<short, bool>
404 MCM {
405 public:
406   typedef short ValueType;
407 };
408
409 template<>
410 class JoinTraits<short, char>
411 {
412 public:
413   typedef short ValueType;
414 };
415
416 template<>
417 class JoinTraits<short, unsigned char>
418 {
419 public:
420   typedef short ValueType;
421 };
422
423 template<>
424 class JoinTraits<short, short>
425 {
426 public:
427   typedef short ValueType;
428 };
429
430 template<>
431 class JoinTraits<short, unsigned short>
432 {
433 public:
434   typedef int ValueType;
435 };
436
437 template<>
438 class JoinTraits<short, int>
439 {
440 public:
441   typedef int ValueType;
442 };
443
444 template<>
445 class JoinTraits<short, unsigned int>
446 {
447 public:
448   // unsigned int & unsigned long may be the same size, so promote to float
449   typedef float ValueType;
450 };
451
452 template<>
453 class JoinTraits<short, long>
454 {
455 public:
456   typedef long ValueType;
457 };
458
459 template<>
460 class JoinTraits<short, unsigned long>
461 {
462 public:
463   typedef float ValueType;
464 };
465
466 template<>
467 class JoinTraits<short, float>
468 {
469 public:
470   typedef float ValueType;
471 };
472
473 template<>
474 class JoinTraits<short, double>
475 {
476 public:
477   typedef double ValueType;
478 };
479   
480 /** Specializations for unsigned short. */
481 template<>
482 class JoinTraits<unsigned short, bool>
483 MCM {
484 public:
485   typedef unsigned short ValueType;
486 };
487
488 template<>
489 class JoinTraits<unsigned short, char>
490 {
491 public:
492   typedef int ValueType;
493 };
494
495 template<>
496 class JoinTraits<unsigned short, unsigned char>
497 {
498 public:
499   typedef unsigned short ValueType;
500 };
501
502 template<>
503 class JoinTraits<unsigned short, short>
504 {
505 public:
506   typedef int ValueType;
507 };
508
509 template<>
510 class JoinTraits<unsigned short, unsigned short>
511 {
512 public:
513   typedef unsigned short ValueType;
514 };
515
516 template<>
517 class JoinTraits<unsigned short, int>
518 {
519 public:
520   typedef int ValueType;
521 };
522
523 template<>
524 class JoinTraits<unsigned short, unsigned int>
525 {
526 public:
527   typedef unsigned int ValueType;
528 };
529
530 template<>
531 class JoinTraits<unsigned short, long>
532 {
533 public:
534   typedef long ValueType;
535 };
536
537 template<>
538 class JoinTraits<unsigned short, unsigned long>
539 {
540 public:
541   typedef unsigned long ValueType;
542 };
543
544 template<>
545 class JoinTraits<unsigned short, float>
546 {
547 public:
548   typedef float ValueType;
549 };
550
551 template<>
552 class JoinTraits<unsigned short, double>
553 {
554 public:
555   typedef double ValueType;
556 };
557   
558 /** Specializations for int. */
559 template<>
560 class JoinTraits<int, bool>
561 MCM {
562 public:
563   typedef int ValueType;
564 };
565
566 template<>
567 class JoinTraits<int, char>
568 {
569 public:
570   typedef int ValueType;
571 };
572
573 template<>
574 class JoinTraits<int, unsigned char>
575 {
576 public:
577   typedef int ValueType;
578 };
579
580 template<>
581 class JoinTraits<int, short>
582 {
583 public:
584   typedef int ValueType;
585 };
586
587 template<>
588 class JoinTraits<int, unsigned short>
589 {
590 public:
591   typedef int ValueType;
592 };
593
594 template<>
595 class JoinTraits<int, int>
596 {
597 public:
598   typedef int ValueType;
599 };
600
601 template<>
602 class JoinTraits<int, unsigned int>
603 {
604 public:
605   // unsigned int & unsigned long may be the same size, so promote to float
606   typedef float ValueType;
607 };
608
609 template<>
610 class JoinTraits<int, long>
611 {
612 public:
613   typedef long ValueType;
614 };
615
616 template<>
617 class JoinTraits<int, unsigned long>
618 {
619 public:
620   typedef float ValueType;
621 };
622
623 template<>
624 class JoinTraits<int, float>
625 {
626 public:
627   typedef float ValueType;
628 };
629
630 template<>
631 class JoinTraits<int, double>
632 {
633 public:
634   typedef double ValueType;
635 };
636   
637 /** Specializations for unsigned int. */
638 template<>
639 class JoinTraits<unsigned int, bool>
640 MCM {
641 public:
642   typedef unsigned int ValueType;
643 };
644
645 template<>
646 class JoinTraits<unsigned int, char>
647 {
648 public:
649   // unsigned int & unsigned long may be the same size, so promote to float
650   typedef float ValueType;
651 };
652
653 template<>
654 class JoinTraits<unsigned int, unsigned char>
655 {
656 public:
657   typedef unsigned int ValueType;
658 };
659
660 template<>
661 class JoinTraits<unsigned int, short>
662 {
663 public:
664   // unsigned int & unsigned long may be the same size, so promote to float
665   typedef float ValueType;
666 };
667
668 template<>
669 class JoinTraits<unsigned int, unsigned short>
670 {
671 public:
672   typedef unsigned int ValueType;
673 };
674
675 template<>
676 class JoinTraits<unsigned int, int>
677 {
678 public:
679   // unsigned int & unsigned long may be the same size, so promote to float
680   typedef float ValueType;
681 };
682
683 template<>
684 class JoinTraits<unsigned int, unsigned int>
685 {
686 public:
687   typedef unsigned int ValueType;
688 };
689
690 template<>
691 class JoinTraits<unsigned int, long>
692 {
693 public:
694   typedef float ValueType;
695 };
696
697 template<>
698 class JoinTraits<unsigned int, unsigned long>
699 {
700 public:
701   typedef unsigned long ValueType;
702 };
703
704 template<>
705 class JoinTraits<unsigned int, float>
706 {
707 public:
708   typedef float ValueType;
709 };
710
711 template<>
712 class JoinTraits<unsigned int, double>
713 {
714 public:
715   typedef double ValueType;
716 };
717   
718 /** Specializations for long. */
719 template<>
720 class JoinTraits<long, bool>
721 MCM {
722 public:
723   typedef long ValueType;
724 };
725
726 template<>
727 class JoinTraits<long, char>
728 {
729 public:
730   typedef long ValueType;
731 };
732
733 template<>
734 class JoinTraits<long, unsigned char>
735 {
736 public:
737   typedef long ValueType;
738 };
739
740 template<>
741 class JoinTraits<long, short>
742 {
743 public:
744   typedef long ValueType;
745 };
746
747 template<>
748 class JoinTraits<long, unsigned short>
749 {
750 public:
751   typedef long ValueType;
752 };
753
754 template<>
755 class JoinTraits<long, int>
756 {
757 public:
758   typedef long ValueType;
759 };
760
761 template<>
762 class JoinTraits<long, unsigned int>
763 {
764 public:
765   typedef float ValueType;
766 };
767
768 template<>
769 class JoinTraits<long, long>
770 {
771 public:
772   typedef long ValueType;
773 };
774
775 template<>
776 class JoinTraits<long, unsigned long>
777 {
778 public:
779   typedef float ValueType;
780 };
781
782 template<>
783 class JoinTraits<long, float>
784 {
785 public:
786   typedef float ValueType;
787 };
788
789 template<>
790 class JoinTraits<long, double>
791 {
792 public:
793   typedef double ValueType;
794 };
795   
796 /** Specializations for unsigned long. */
797 template<>
798 class JoinTraits<unsigned long, bool>
799 MCM {
800 public:
801   typedef unsigned long ValueType;
802 };
803
804 template<>
805 class JoinTraits<unsigned long, char>
806 {
807 public:
808   typedef float ValueType;
809 };
810
811 template<>
812 class JoinTraits<unsigned long, unsigned char>
813 {
814 public:
815   typedef unsigned long ValueType;
816 };
817
818 template<>
819 class JoinTraits<unsigned long, short>
820 {
821 public:
822   typedef float ValueType;
823 };
824
825 template<>
826 class JoinTraits<unsigned long, unsigned short>
827 {
828 public:
829   typedef unsigned long ValueType;
830 };
831
832 template<>
833 class JoinTraits<unsigned long, int>
834 {
835 public:
836   typedef float ValueType;
837 };
838
839 template<>
840 class JoinTraits<unsigned long, unsigned int>
841 {
842 public:
843   typedef unsigned long ValueType;
844 };
845
846 template<>
847 class JoinTraits<unsigned long, long>
848 {
849 public:
850   typedef float ValueType;
851 };
852
853 template<>
854 class JoinTraits<unsigned long, unsigned long>
855 {
856 public:
857   typedef unsigned long ValueType;
858 };
859
860 template<>
861 class JoinTraits<unsigned long, float>
862 {
863 public:
864   typedef float ValueType;
865 };
866
867 template<>
868 class JoinTraits<unsigned long, double>
869 {
870 public:
871   typedef double ValueType;
872 };
873   
874 /** Specializations for float. */
875 template<>
876 class JoinTraits<float, bool>
877 MCM {
878 public:
879   typedef float ValueType;
880 };
881
882 template<>
883 class JoinTraits<float, char>
884 {
885 public:
886   typedef float ValueType;
887 };
888
889 template<>
890 class JoinTraits<float, unsigned char>
891 {
892 public:
893   typedef float ValueType;
894 };
895
896 template<>
897 class JoinTraits<float, short>
898 {
899 public:
900   typedef float ValueType;
901 };
902
903 template<>
904 class JoinTraits<float, unsigned short>
905 {
906 public:
907   typedef float ValueType;
908 };
909
910 template<>
911 class JoinTraits<float, int>
912 {
913 public:
914   typedef float ValueType;
915 };
916
917 template<>
918 class JoinTraits<float, unsigned int>
919 {
920 public:
921   typedef float ValueType;
922 };
923
924 template<>
925 class JoinTraits<float, long>
926 {
927 public:
928   typedef float ValueType;
929 };
930
931 template<>
932 class JoinTraits<float, unsigned long>
933 {
934 public:
935   typedef float ValueType;
936 };
937
938 template<>
939 class JoinTraits<float, float>
940 {
941 public:
942   typedef float ValueType;
943 };
944
945 template<>
946 class JoinTraits<float, double>
947 {
948 public:
949   typedef double ValueType;
950 };
951   
952 /** Specializations for double. */
953 template<>
954 class JoinTraits<double, bool>
955 MCM {
956 public:
957   typedef double ValueType;
958 };
959
960 template<>
961 class JoinTraits<double, char>
962 {
963 public:
964   typedef double ValueType;
965 };
966
967 template<>
968 class JoinTraits<double, unsigned char>
969 {
970 public:
971   typedef double ValueType;
972 };
973
974 template<>
975 class JoinTraits<double, short>
976 {
977 public:
978   typedef double ValueType;
979 };
980
981 template<>
982 class JoinTraits<double, unsigned short>
983 {
984 public:
985   typedef double ValueType;
986 };
987
988 template<>
989 class JoinTraits<double, int>
990 {
991 public:
992   typedef double ValueType;
993 };
994
995 template<>
996 class JoinTraits<double, unsigned int>
997 {
998 public:
999   typedef double ValueType;
1000 };
1001
1002 template<>
1003 class JoinTraits<double, long>
1004 {
1005 public:
1006   typedef double ValueType;
1007 };
1008
1009 template<>
1010 class JoinTraits<double, unsigned long>
1011 {
1012 public:
1013   typedef double ValueType;
1014 };
1015
1016 template<>
1017 class JoinTraits<double, float>
1018 {
1019 public:
1020   typedef double ValueType;
1021 };
1022
1023 template<>
1024 class JoinTraits<double, double>
1025 {
1026 public:
1027   typedef double ValueType;
1028 };
1029   
1030 // end namespace itk
1031
1032 #endif // __itkPixelTraits_h
1033

Generated by KWStyle 1.0b on Tuesday January,17 at 02:14:39PM
© Kitware Inc.