Mercurial > hg > orthanc-stl
comparison Sources/STLToolbox.cpp @ 33:2460b376d3f7
reorganization
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 04 Apr 2024 18:50:11 +0200 |
parents | Sources/Toolbox.cpp@976da5476810 |
children |
comparison
equal
deleted
inserted
replaced
32:976da5476810 | 33:2460b376d3f7 |
---|---|
1 /** | |
2 * SPDX-FileCopyrightText: 2023-2024 Sebastien Jodogne, UCLouvain, Belgium | |
3 * SPDX-License-Identifier: GPL-3.0-or-later | |
4 */ | |
5 | |
6 /** | |
7 * STL plugin for Orthanc | |
8 * Copyright (C) 2023-2024 Sebastien Jodogne, UCLouvain, Belgium | |
9 * | |
10 * This program is free software: you can redistribute it and/or | |
11 * modify it under the terms of the GNU General Public License as | |
12 * published by the Free Software Foundation, either version 3 of the | |
13 * License, or (at your option) any later version. | |
14 * | |
15 * This program is distributed in the hope that it will be useful, but | |
16 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
18 * General Public License for more details. | |
19 * | |
20 * You should have received a copy of the GNU General Public License | |
21 * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
22 **/ | |
23 | |
24 | |
25 #include "STLToolbox.h" | |
26 | |
27 #include <OrthancException.h> | |
28 #include <Toolbox.h> | |
29 | |
30 #include <algorithm> | |
31 #include <cmath> | |
32 | |
33 | |
34 namespace STLToolbox | |
35 { | |
36 bool IsNear(double a, | |
37 double b) | |
38 { | |
39 return std::abs(a - b) < 10.0 * std::numeric_limits<double>::epsilon(); | |
40 } | |
41 | |
42 | |
43 bool MyParseDouble(double& value, | |
44 const std::string& s) | |
45 { | |
46 #if 1 | |
47 char* end = NULL; | |
48 value = strtod(s.c_str(), &end); | |
49 return (end == s.c_str() + s.size()); | |
50 #else | |
51 return Orthanc::SerializationToolbox::ParseDouble(value, s); | |
52 #endif | |
53 } | |
54 | |
55 | |
56 namespace | |
57 { | |
58 struct IsNearPredicate | |
59 { | |
60 bool operator() (const double& a, | |
61 const double& b) | |
62 { | |
63 return IsNear(a, b); | |
64 } | |
65 }; | |
66 } | |
67 | |
68 | |
69 void RemoveDuplicateValues(std::vector<double>& v) | |
70 { | |
71 IsNearPredicate predicate; | |
72 std::vector<double>::iterator last = std::unique(v.begin(), v.end(), predicate); | |
73 v.erase(last, v.end()); | |
74 } | |
75 | |
76 | |
77 std::string GetStringValue(DcmItem& item, | |
78 const DcmTagKey& key) | |
79 { | |
80 const char* s = NULL; | |
81 if (!item.findAndGetString(key, s).good() || | |
82 s == NULL) | |
83 { | |
84 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat); | |
85 } | |
86 else | |
87 { | |
88 return Orthanc::Toolbox::StripSpaces(s); | |
89 } | |
90 } | |
91 } |