comparison Framework/Toolbox/LinearAlgebra.cpp @ 804:61ba4b504e9a

PolylineSceneLayer now has one color per chain
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 28 May 2019 15:58:21 +0200
parents 9f68155c75b0
children 32eaf4929b08
comparison
equal deleted inserted replaced
802:f38c1fc08655 804:61ba4b504e9a
24 #include <Core/Logging.h> 24 #include <Core/Logging.h>
25 #include <Core/OrthancException.h> 25 #include <Core/OrthancException.h>
26 #include <Core/Toolbox.h> 26 #include <Core/Toolbox.h>
27 27
28 #include <stdio.h> 28 #include <stdio.h>
29 #include <boost/lexical_cast.hpp>
29 #include <boost/numeric/ublas/lu.hpp> 30 #include <boost/numeric/ublas/lu.hpp>
30 31
31 namespace OrthancStone 32 namespace OrthancStone
32 { 33 {
33 namespace LinearAlgebra 34 namespace LinearAlgebra
66 67
67 target.resize(items.size()); 68 target.resize(items.size());
68 69
69 for (size_t i = 0; i < items.size(); i++) 70 for (size_t i = 0; i < items.size(); i++)
70 { 71 {
72 /**
73 * We try and avoid the use of "boost::lexical_cast<>" here,
74 * as it is very slow. As we are parsing many doubles, we
75 * prefer to use the standard "std::stod" function if
76 * available: http://www.cplusplus.com/reference/string/stod/
77 **/
78
79 #if __cplusplus >= 201103L // Is C++11 enabled?
71 try 80 try
72 { 81 {
73 /**
74 * We don't use "boost::lexical_cast<>" here, as it is very
75 * slow. As we are parsing many doubles, we prefer to use
76 * the standard "std::stod" function:
77 * http://www.cplusplus.com/reference/string/stod/
78 **/
79
80 target[i] = std::stod(items[i]); 82 target[i] = std::stod(items[i]);
81 } 83 }
82 catch (std::exception&) 84 catch (std::exception&)
83 { 85 {
84 target.clear(); 86 target.clear();
85 return false; 87 return false;
86 } 88 }
89 #else // Fallback implementation using Boost
90 try
91 {
92 target[i] = boost::lexical_cast<double>(items[i]);
93 }
94 catch (boost::bad_lexical_cast&)
95 {
96 target.clear();
97 return false;
98 }
99 #endif
87 } 100 }
88 101
89 return true; 102 return true;
90 } 103 }
91 104