]> Creatis software - clitk.git/blob - common/clitkListOfPair.cxx
The lower and upper options can be tuned for all type of region growing algorithm
[clitk.git] / common / clitkListOfPair.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 CLITKLISTOFPAIR_CXX
19 #define CLITKLISTOFPAIR_CXX
20 /**
21    ------------------------------------------------=
22    * @file   clitkListOfPair.cxx
23    * @author David Sarrut <david.sarrut@creatis.insa-lyon.fr>
24    * @date   27 Feb 2007 09:55:56
25    *
26    * @brief
27    *
28    *
29    ------------------------------------------------=*/
30
31 #include "clitkListOfPair.h"
32
33 //--------------------------------------------------------------------
34 double clitk::convertValue(double v,
35                            const std::multimap<double, double> & conversionTable,
36                            bool linear)
37 {
38   std::multimap<double, double>::const_iterator i;
39   i = conversionTable.lower_bound(v);
40   if (i == conversionTable.end()) {
41     std::cerr << "The value " << v << " is out of the table" << std::endl;
42     exit(0);
43   }
44
45   double v2 = i->first;
46   double p2 = i->second;
47   if (i != conversionTable.begin()) i--;
48   double v1 = i->first;
49   double p1 = i->second;
50
51   // interpol
52   if (!linear) {
53     if ((v-v1) > (v2-v)) return p2;
54     else return p1;
55   } else {
56     double w = (v-v1)/(v2-v1);
57     return p1*(1.0-w)+w*p2;
58   }
59 }
60 //--------------------------------------------------------------------
61
62 #endif /* end #define CLITKLISTOFPAIR_CXX */
63