Mercurial > hg > orthanc-stone
annotate OrthancStone/Sources/Toolbox/OrthancDatasets/DicomDatasetReader.cpp @ 1835:6c252e51008d
no more need of "-DORTHANC_FRAMEWORK_ADDITIONAL_LIBRARIES" to dynamically link against system-wide orthanc framework
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Sat, 12 Jun 2021 09:01:40 +0200 |
parents | 126522623e20 |
children | 3889ae96d2e9 |
rev | line source |
---|---|
1504 | 1 /** |
2 * Stone of Orthanc | |
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics | |
4 * Department, University Hospital of Liege, Belgium | |
1739
9ac2a65d4172
upgrade to year 2021
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1598
diff
changeset
|
5 * Copyright (C) 2017-2021 Osimis S.A., Belgium |
1504 | 6 * |
7 * This program is free software: you can redistribute it and/or | |
1598
8563ea5d8ae4
relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1596
diff
changeset
|
8 * modify it under the terms of the GNU Lesser General Public License |
1504 | 9 * as published by the Free Software Foundation, either version 3 of |
10 * the License, or (at your option) any later version. | |
11 * | |
12 * This program is distributed in the hope that it will be useful, but | |
13 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
1598
8563ea5d8ae4
relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1596
diff
changeset
|
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
8563ea5d8ae4
relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1596
diff
changeset
|
15 * Lesser General Public License for more details. |
1596
4fb8fdf03314
removed annoying whitespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1512
diff
changeset
|
16 * |
1598
8563ea5d8ae4
relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1596
diff
changeset
|
17 * You should have received a copy of the GNU Lesser General Public |
8563ea5d8ae4
relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1596
diff
changeset
|
18 * License along with this program. If not, see |
8563ea5d8ae4
relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1596
diff
changeset
|
19 * <http://www.gnu.org/licenses/>. |
1504 | 20 **/ |
21 | |
22 | |
23 #include "DicomDatasetReader.h" | |
24 | |
25 #include <OrthancException.h> | |
26 #include <Toolbox.h> | |
27 | |
28 #include <boost/lexical_cast.hpp> | |
29 | |
30 namespace OrthancStone | |
31 { | |
32 DicomDatasetReader::DicomDatasetReader(const IDicomDataset& dataset) : | |
33 dataset_(dataset) | |
34 { | |
35 } | |
36 | |
37 | |
1834
126522623e20
replaced OrthancStone::DicomPath by new class Orthanc::DicomPath from orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
38 std::string DicomDatasetReader::GetStringValue(const Orthanc::DicomPath& path, |
1504 | 39 const std::string& defaultValue) const |
40 { | |
41 std::string s; | |
42 if (dataset_.GetStringValue(s, path)) | |
43 { | |
44 return s; | |
45 } | |
46 else | |
47 { | |
48 return defaultValue; | |
49 } | |
50 } | |
51 | |
52 | |
1834
126522623e20
replaced OrthancStone::DicomPath by new class Orthanc::DicomPath from orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
53 std::string DicomDatasetReader::GetMandatoryStringValue(const Orthanc::DicomPath& path) const |
1504 | 54 { |
55 std::string s; | |
56 if (dataset_.GetStringValue(s, path)) | |
57 { | |
58 return s; | |
59 } | |
60 else | |
61 { | |
62 throw Orthanc::OrthancException(Orthanc::ErrorCode_InexistentTag); | |
63 } | |
64 } | |
65 | |
66 | |
67 template <typename T> | |
68 static bool GetValueInternal(T& target, | |
69 const IDicomDataset& dataset, | |
1834
126522623e20
replaced OrthancStone::DicomPath by new class Orthanc::DicomPath from orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
70 const Orthanc::DicomPath& path) |
1504 | 71 { |
72 try | |
73 { | |
74 std::string s; | |
75 | |
76 if (dataset.GetStringValue(s, path)) | |
77 { | |
78 target = boost::lexical_cast<T>(Orthanc::Toolbox::StripSpaces(s)); | |
79 return true; | |
80 } | |
81 else | |
82 { | |
83 return false; | |
84 } | |
85 } | |
86 catch (boost::bad_lexical_cast&) | |
87 { | |
88 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat); | |
89 } | |
90 } | |
91 | |
92 | |
93 bool DicomDatasetReader::GetIntegerValue(int& target, | |
1834
126522623e20
replaced OrthancStone::DicomPath by new class Orthanc::DicomPath from orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
94 const Orthanc::DicomPath& path) const |
1504 | 95 { |
96 return GetValueInternal<int>(target, dataset_, path); | |
97 } | |
98 | |
99 | |
100 bool DicomDatasetReader::GetUnsignedIntegerValue(unsigned int& target, | |
1834
126522623e20
replaced OrthancStone::DicomPath by new class Orthanc::DicomPath from orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
101 const Orthanc::DicomPath& path) const |
1504 | 102 { |
103 int value; | |
104 | |
105 if (!GetIntegerValue(value, path)) | |
106 { | |
107 return false; | |
108 } | |
109 else if (value >= 0) | |
110 { | |
111 target = static_cast<unsigned int>(value); | |
112 return true; | |
113 } | |
114 else | |
115 { | |
116 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); | |
117 } | |
118 } | |
119 | |
120 | |
121 bool DicomDatasetReader::GetFloatValue(float& target, | |
1834
126522623e20
replaced OrthancStone::DicomPath by new class Orthanc::DicomPath from orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
122 const Orthanc::DicomPath& path) const |
1504 | 123 { |
124 return GetValueInternal<float>(target, dataset_, path); | |
125 } | |
126 | |
127 | |
128 bool DicomDatasetReader::GetDoubleValue(double& target, | |
1834
126522623e20
replaced OrthancStone::DicomPath by new class Orthanc::DicomPath from orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
129 const Orthanc::DicomPath& path) const |
1504 | 130 { |
131 return GetValueInternal<double>(target, dataset_, path); | |
132 } | |
133 } |