]> Creatis software - clitk.git/blob - tools/clitkImageStatisticsGenericFilter.cxx
GateAsciiImageIO is now cross-platform using itksys::RegularExpression
[clitk.git] / tools / clitkImageStatisticsGenericFilter.cxx
1 /*=========================================================================
2   Program:   vv                     http://www.creatis.insa-lyon.fr/rio/vv
3
4   Authors belong to: 
5   - University of LYON              http://www.universite-lyon.fr/
6   - Léon Bérard cancer center       http://www.centreleonberard.fr
7   - CREATIS CNRS laboratory         http://www.creatis.insa-lyon.fr
8
9   This software is distributed WITHOUT ANY WARRANTY; without even
10   the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
11   PURPOSE.  See the copyright notices for more information.
12
13   It is distributed under dual licence
14
15   - BSD        See included LICENSE.txt file
16   - CeCILL-B   http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
17 ===========================================================================**/
18 #ifndef clitkImageStatisticsGenericFilter_cxx
19 #define clitkImageStatisticsGenericFilter_cxx
20
21 /* =================================================
22  * @file   clitkImageStatisticsGenericFilter.cxx
23  * @author 
24  * @date   
25  * 
26  * @brief 
27  * 
28  ===================================================*/
29
30 #include "clitkImageStatisticsGenericFilter.h"
31
32
33 namespace clitk
34 {
35
36
37   //-----------------------------------------------------------
38   // Constructor
39   //-----------------------------------------------------------
40   ImageStatisticsGenericFilter::ImageStatisticsGenericFilter()
41   {
42     m_Verbose=false;
43     m_InputFileName="";
44   }
45
46
47   //-----------------------------------------------------------
48   // Update
49   //-----------------------------------------------------------
50   void ImageStatisticsGenericFilter::Update()
51   {
52     // Read the Dimension and PixelType
53     int Dimension, Components;
54     std::string PixelType;
55     ReadImageDimensionAndPixelType(m_InputFileName, Dimension, PixelType, Components);
56     
57     if (m_ArgsInfo.channel_arg < -1 || m_ArgsInfo.channel_arg >= Components) {
58       std::cout << "Invalid image channel" << std::endl;
59       return;
60     }
61     
62     if (m_ArgsInfo.mask_given) {
63       int maskDimension, maskComponents;
64       std::string maskPixelType;
65       ReadImageDimensionAndPixelType(m_ArgsInfo.mask_arg, maskDimension, maskPixelType, maskComponents);
66       if (!(maskDimension == Dimension || maskDimension == (Dimension - 1))) {
67         std::cout << "Dimension of label mask must be equal to the (d)imension of the input image or d-1." << std::endl;
68         return;
69       }
70     }
71
72     
73     // Call UpdateWithDim
74     if (Dimension==2) {
75       switch (Components) {
76         case 1: 
77           UpdateWithDim<2,1>(PixelType);
78           break;
79         case 2: 
80           UpdateWithDim<2,2>(PixelType);
81           break;
82         case 3: 
83           UpdateWithDim<2,3>(PixelType);
84           break;
85         default:
86           std::cout << "Unsupported number of channels" << std::endl;
87           break;
88       }
89     }
90     else if (Dimension==3) {
91       switch (Components) {
92         case 1: 
93           UpdateWithDim<3,1>(PixelType);
94           break;
95         case 2: 
96           UpdateWithDim<3,2>(PixelType);
97           break;
98         case 3: 
99           UpdateWithDim<3,3>(PixelType);
100           break;
101         default:
102           std::cout << "Unsupported number of channels" << std::endl;
103           break;
104       }
105     }
106     else if (Dimension==4) {
107       switch (Components) {
108         case 1: 
109           UpdateWithDim<4,1>(PixelType);
110           break;
111         case 2: 
112           UpdateWithDim<4,2>(PixelType);
113           break;
114         case 3: 
115           UpdateWithDim<4,3>(PixelType);
116           break;
117         default:
118           std::cout << "Unsupported number of channels" << std::endl;
119           break;
120       }
121     }
122     else {
123       std::cout<<"Error, Only for 2 or 3  Dimensions!!!"<<std::endl ;
124       return;
125     }
126   }
127
128
129 } //end clitk
130
131 #endif  //#define clitkImageStatisticsGenericFilter_cxx