]> Creatis software - clitk.git/blob - tools/clitkImageStatisticsGenericFilter.cxx
Remove sonarQube
[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 #include "clitkImageStatisticsGenericFilter.h"
22
23 namespace clitk
24 {
25
26
27   //-----------------------------------------------------------
28   // Constructor
29   //-----------------------------------------------------------
30   ImageStatisticsGenericFilter::ImageStatisticsGenericFilter()
31   {
32     m_Verbose=false;
33     m_InputFileName="";
34   }
35   //-----------------------------------------------------------
36
37
38   //-----------------------------------------------------------
39   // Update
40   //-----------------------------------------------------------
41   void ImageStatisticsGenericFilter::Update()
42   {
43     // Read the Dimension and PixelType
44     int Dimension, Components;
45     std::string PixelType;
46     ReadImageDimensionAndPixelType(m_InputFileName, Dimension, PixelType, Components);
47
48     if (m_ArgsInfo.channel_arg < -1 || m_ArgsInfo.channel_arg >= Components) {
49       std::cout << "Invalid image channel" << std::endl;
50       return;
51     }
52
53     if (m_ArgsInfo.mask_given) {
54       int maskDimension, maskComponents;
55       std::string maskPixelType;
56       ReadImageDimensionAndPixelType(m_ArgsInfo.mask_arg, maskDimension, maskPixelType, maskComponents);
57       if (!(maskDimension == Dimension || maskDimension == (Dimension - 1))) {
58         std::cout << "Dimension of label mask must be equal to the (d)imension of the input image or d-1." << std::endl;
59         return;
60       }
61     }
62
63
64     // Call UpdateWithDim
65     if (Dimension==2) {
66       switch (Components) {
67         case 1:
68           UpdateWithDim<2,1>(PixelType);
69           break;
70         case 2:
71           UpdateWithDim<2,2>(PixelType);
72           break;
73         case 3:
74           UpdateWithDim<2,3>(PixelType);
75           break;
76         default:
77           std::cout << "Unsupported number of channels" << std::endl;
78           break;
79       }
80     }
81     else if (Dimension==3) {
82       switch (Components) {
83         case 1:
84           UpdateWithDim<3,1>(PixelType);
85           break;
86         case 2:
87           UpdateWithDim<3,2>(PixelType);
88           break;
89         case 3:
90           UpdateWithDim<3,3>(PixelType);
91           break;
92         default:
93           std::cout << "Unsupported number of channels" << std::endl;
94           break;
95       }
96     }
97     else if (Dimension==4) {
98       switch (Components) {
99         case 1:
100           UpdateWithDim<4,1>(PixelType);
101           break;
102         case 2:
103           UpdateWithDim<4,2>(PixelType);
104           break;
105         case 3:
106           UpdateWithDim<4,3>(PixelType);
107           break;
108         default:
109           std::cout << "Unsupported number of channels" << std::endl;
110           break;
111       }
112     }
113     else {
114       std::cout<<"Error, Only for 2 or 3  Dimensions!!!"<<std::endl ;
115       return;
116     }
117   }
118
119
120 } //end clitk
121
122 #endif  //#define clitkImageStatisticsGenericFilter_cxx