]> Creatis software - clitk.git/blob - common/clitkListOfPair.cxx
defbe60101c4d80dbedef4eb5d4cacb41b2f96ac
[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://oncora1.lyon.fnclcc.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   std::multimap<double, double>::const_iterator i;
38   i = conversionTable.lower_bound(v);  
39   if (i == conversionTable.end()) {
40     std::cerr << "The value " << v << " is out of the table" << std::endl;
41     exit(0);
42   }
43   
44   double v2 = i->first;
45   double p2 = i->second;
46   if (i != conversionTable.begin()) i--;
47   double v1 = i->first;
48   double p1 = i->second;
49
50   // interpol
51   if (!linear) {
52     if ((v-v1) > (v2-v)) return p2;
53     else return p1;
54   }
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