Mercurial > hg > orthanc-stone
annotate OrthancStone/Sources/Toolbox/OrthancDatasets/DicomDatasetReader.cpp @ 1652:fa9e6bf84958
integrating pdf.js into Stone Web viewer
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Mon, 16 Nov 2020 20:47:53 +0100 |
parents | 8563ea5d8ae4 |
children | 9ac2a65d4172 |
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 | |
5 * Copyright (C) 2017-2020 Osimis S.A., Belgium | |
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 | |
38 std::string DicomDatasetReader::GetStringValue(const DicomPath& path, | |
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 | |
53 std::string DicomDatasetReader::GetMandatoryStringValue(const DicomPath& path) const | |
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, | |
70 const DicomPath& path) | |
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, | |
94 const DicomPath& path) const | |
95 { | |
96 return GetValueInternal<int>(target, dataset_, path); | |
97 } | |
98 | |
99 | |
100 bool DicomDatasetReader::GetUnsignedIntegerValue(unsigned int& target, | |
101 const DicomPath& path) const | |
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, | |
122 const DicomPath& path) const | |
123 { | |
124 return GetValueInternal<float>(target, dataset_, path); | |
125 } | |
126 | |
127 | |
128 bool DicomDatasetReader::GetDoubleValue(double& target, | |
129 const DicomPath& path) const | |
130 { | |
131 return GetValueInternal<double>(target, dataset_, path); | |
132 } | |
133 } |