]> Creatis software - clitk.git/blob - registration/clitkDeformationListStatisticsFilter.txx
Debug RTStruct conversion with empty struc
[clitk.git] / registration / clitkDeformationListStatisticsFilter.txx
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 __clitkDeformationFieldStatisticsFilter_txx
19 #define __clitkDeformationFieldStatisticsFilter_txx
20 #include "clitkDeformationListStatisticsFilter.h"
21
22
23 namespace clitk
24 {
25
26   //------------------------------------------------------
27   //Magnitude
28   //------------------------------------------------------
29   template <class ListItemType> 
30   void 
31   DeformationListStatisticsFilter<ListItemType>::GetStatistics(const ListType& list, ValueType & mean,  ValueType & sd,  ValueType & max)
32   {
33     // Initialize
34     ValueType norm;
35     mean=0;
36     sd=0;
37     max=0;
38
39     // loop over the list of displacements
40     for (unsigned int i=0;i<list.size();i++)
41       {
42         norm=list[i].GetNorm();
43         mean+=norm;
44         sd+=norm*norm;
45         if (max<norm)max=norm;
46       }
47         
48     // Normalize
49     mean/=list.size();
50     sd/=list.size();
51     sd-=mean*mean;
52     sd=sqrt(sd);
53     
54   }
55
56
57
58   //------------------------------------------------------
59   // For multiple lists 
60   //------------------------------------------------------
61   template <class ListItemType> 
62   void 
63   DeformationListStatisticsFilter<ListItemType>::GetStatistics(const ListsType& list, ValueListType & mean,  ValueListType & sd,  ValueListType & max)
64   {
65
66     mean.resize(list.size());
67     sd.resize(list.size());
68     max.resize(list.size());
69
70     for (unsigned int i=0;i<list.size();i++)
71       {
72         // call function per list
73         GetStatistics(list[i], mean[i], sd[i], max[i]);
74       }
75   }
76
77
78   //------------------------------------------------------
79   // Magnitude AND General statistics for magnitude     
80   //------------------------------------------------------
81   template <class ListItemType> 
82   void 
83   DeformationListStatisticsFilter<ListItemType>::GetStatistics(const ListsType& list, ValueType&  mean, ValueType &sd, ValueType & max,  ValueListType & meanList, ValueListType & sdList,  ValueListType & maxList)
84   {
85     // Calculate statistics per list
86     GetStatistics(list, meanList, sdList, maxList);
87
88     // Initialize
89     mean=0;
90     sd=0;
91     max=0;
92     
93     // Loop
94     for (unsigned int i=0;i<list.size();i++)
95       {
96         mean+=meanList[i];
97         sd+=sdList[i]*sdList[i];
98         if(max<maxList[i])max=maxList[i];
99       }
100
101     // Normalize
102     mean/=list.size();
103     sd/=list.size();
104     sd=sqrt(sd);
105   }
106
107
108   //------------------------------------------------------
109   // Per component      
110   //------------------------------------------------------
111   template <class ListItemType> 
112   void 
113   DeformationListStatisticsFilter<ListItemType>::GetStatistics(const ListType& list, ListItemType & mean,  ListItemType & sd,  ListItemType & max)
114   {
115     // Initialize
116     ListItemType displacement;
117     mean.Fill(itk::NumericTraits<ValueType>::Zero);
118     sd.Fill(itk::NumericTraits<ValueType>::Zero);
119     max.Fill(itk::NumericTraits<ValueType>::Zero);
120
121     // Loop over the list of displacements
122     for (unsigned int i=0;i<list.size();i++)
123       {
124         displacement=list[i];
125         mean+=displacement;
126         for (unsigned int dim=0; dim<list[0].Size(); dim++)
127           {
128             sd[dim]+=displacement[dim]*displacement[dim];
129             if (fabs(max[dim])<fabs(displacement[dim])) max[dim]=displacement[dim];
130           }
131       }
132         
133     // Normalize
134     for (unsigned int dim=0; dim<list[0].Size(); dim++)
135       {
136         mean[dim]/=list.size();
137         sd[dim]/=list.size();
138         sd[dim]-=mean[dim]*mean[dim];
139         sd[dim]=sqrt(sd[dim]);
140       }
141   }
142
143   //------------------------------------------------------
144   // For multiple lists 
145   //------------------------------------------------------
146   template <class ListItemType> 
147   void 
148   DeformationListStatisticsFilter<ListItemType>::GetStatistics(const ListsType& list, ListType & mean,  ListType & sd,  ListType & max)
149   {
150     mean.resize(list.size());
151     sd.resize(list.size());
152     max.resize(list.size());
153
154     for (unsigned int i=0;i<list.size();i++)
155       {
156         // call function per list
157         GetStatistics(list[i], mean[i], sd[i], max[i]);
158       }
159   }
160
161
162
163   //------------------------------------------------------
164   // Magnitude AND General statistics per component     
165   //------------------------------------------------------
166   template <class ListItemType> 
167   void 
168   DeformationListStatisticsFilter<ListItemType>::GetStatistics(const ListsType& list, ListItemType&  mean, ListItemType &sd, ListItemType & max,  ListType & meanList, ListType & sdList,  ListType & maxList)
169   {
170     // Calculate statistics par list
171     GetStatistics(list, meanList, sdList, maxList);
172
173     // Initialize
174     mean.Fill(itk::NumericTraits<ValueType>::Zero);
175     sd.Fill(itk::NumericTraits<ValueType>::Zero);
176     max.Fill(itk::NumericTraits<ValueType>::Zero);
177     ListItemType displacement;
178
179     // Loop
180     for (unsigned int i=0;i<list.size();i++)
181       {
182
183         mean +=meanList[i];
184         
185         for (unsigned int dim=0; dim<mean.Size(); dim++)
186           {
187              sd[dim]+=sdList[i][dim]*sdList[i][dim];
188              if (fabs(max[dim])<fabs(maxList[i][dim])) max[dim]=maxList[i][dim];
189           }
190       }
191
192     // Normalize
193     for (unsigned int dim=0; dim<mean.Size(); dim++)
194       {
195         mean[dim]/=list.size();
196         sd[dim]/=list.size();
197         //sd[dim]-=mean[dim]*mean[dim];
198         sd[dim]=sqrt(sd[dim]);
199       }
200   }
201
202
203 }
204
205 #endif