]> Creatis software - clitk.git/blobdiff - tools/clitkMedianTemporalDimensionGenericFilter.txx
Remove sonarQube
[clitk.git] / tools / clitkMedianTemporalDimensionGenericFilter.txx
index 15d6ec212b06addf1d574a24334df2e21621f80f..f23e2771ff5fe2d4821f63aafee59b6c747dcc01 100644 (file)
@@ -3,7 +3,7 @@
 
   Authors belong to:
   - University of LYON              http://www.universite-lyon.fr/
-  - Léon Bérard cancer center       http://oncora1.lyon.fnclcc.fr
+  - Léon Bérard cancer center       http://www.centreleonberard.fr
   - CREATIS CNRS laboratory         http://www.creatis.insa-lyon.fr
 
   This software is distributed WITHOUT ANY WARRANTY; without even
@@ -14,7 +14,7 @@
 
   - BSD        See included LICENSE.txt file
   - CeCILL-B   http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
-======================================================================-====*/
+===========================================================================**/
 #ifndef clitkMedianTemporalDimensionGenericFilter_txx
 #define clitkMedianTemporalDimensionGenericFilter_txx
 
@@ -184,24 +184,24 @@ namespace clitk
 
       // Take the median
       double value;
+      typename InputImageType::IndexValueType temporal_dimension = size4D[Dimension-1];
+      std::vector<PixelType> temp(temporal_dimension);
       while (!(iterators[0]).IsAtEnd()) {
         value=0.;
-        std::vector<PixelType> temp;
-        for (unsigned int i=0; i<size4D[Dimension-1]; i++) {
-          temp.push_back(iterators[i].Get());
+        for (unsigned int i=0; i<temporal_dimension; i++) {
+          temp[i] = iterators[i].Get();
           ++(iterators[i]);
         }
-        if (temp.size() % 2) {
-          nth_element(temp.begin(),temp.begin()+((temp.size()-1)/2+1),temp.end());
-          value=temp[(temp.size()-1)/2];
+        if (temporal_dimension & 1) {
+          nth_element(temp.begin(), temp.begin() + temporal_dimension/2,temp.end());
+          value = temp[temporal_dimension/2];
         } else {
-          nth_element(temp.begin(),temp.begin()+(temp.size())/2,temp.end());
-          value=temp[temp.size()/2];
-          nth_element(temp.begin(),temp.begin()+ (temp.size()/2+1),temp.end());
-          value+=temp[temp.size()/2+1];
-          value/=2;
+          nth_element(temp.begin(), temp.begin() + temporal_dimension/2 - 1, temp.end());
+          value = temp[temporal_dimension/2 - 1];
+          nth_element(temp.begin(), temp.begin() + temporal_dimension/2, temp.end());
+          value += temp[temporal_dimension/2];
+          value /= 2;
         }
-        value/=size4D[Dimension-1];
         avIt.Set(value);
         ++avIt;
       }