Utils.h
Go to the documentation of this file.
1 /*
2  * Medical Image Registration ToolKit (MIRTK)
3  *
4  * Copyright 2013-2015 Imperial College London
5  * Copyright 2013-2015 Andreas Schuh
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */
19 
20 /**
21  * \file mirtk/Utils.h
22  * \brief Collection of a few very basic functions.
23  */
24 
25 #ifndef MIRTK_Utils_H
26 #define MIRTK_Utils_H
27 
28 #include "mirtk/OrderedSet.h"
29 
30 
31 namespace mirtk {
32 
33 
34 // -----------------------------------------------------------------------------
35 /// Get average interval between consecutive values of an ordered set
36 inline double AverageInterval(const OrderedSet<double> &values)
37 {
38  double avg = .0;
39  if (values.size() > 1) {
40  OrderedSet<double>::const_iterator j = values.begin();
41  OrderedSet<double>::const_iterator i = j++;
42  for (; j != values.end(); ++i, ++j) avg += (*j) - (*i);
43  avg /= (values.size() - 1);
44  }
45  return avg;
46 }
47 
48 
49 } // namespace mirtk
50 
51 #endif // MIRTK_Utils_H
Definition: IOConfig.h:41
double AverageInterval(const OrderedSet< double > &values)
Get average interval between consecutive values of an ordered set.
Definition: Utils.h:36