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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1504
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 /**
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2 * Stone of Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
4 * Department, University Hospital of Liege, Belgium
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
5 * Copyright (C) 2017-2020 Osimis S.A., Belgium
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
6 *
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
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
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 * as published by the Free Software Foundation, either version 3 of
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 * the License, or (at your option) any later version.
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 *
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 * This program is distributed in the hope that it will be useful, but
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
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
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20 **/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23 #include "DicomDatasetReader.h"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25 #include <OrthancException.h>
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26 #include <Toolbox.h>
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28 #include <boost/lexical_cast.hpp>
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30 namespace OrthancStone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32 DicomDatasetReader::DicomDatasetReader(const IDicomDataset& dataset) :
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
33 dataset_(dataset)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
36
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
37
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
38 std::string DicomDatasetReader::GetStringValue(const DicomPath& path,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
39 const std::string& defaultValue) const
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
40 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
41 std::string s;
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
42 if (dataset_.GetStringValue(s, path))
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
43 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
44 return s;
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
45 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
46 else
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
47 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
48 return defaultValue;
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
49 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
50 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
51
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
52
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
53 std::string DicomDatasetReader::GetMandatoryStringValue(const DicomPath& path) const
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
54 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
55 std::string s;
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
56 if (dataset_.GetStringValue(s, path))
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
57 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
58 return s;
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
59 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
60 else
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
61 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
62 throw Orthanc::OrthancException(Orthanc::ErrorCode_InexistentTag);
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
63 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
64 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
65
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
66
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
67 template <typename T>
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
68 static bool GetValueInternal(T& target,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
69 const IDicomDataset& dataset,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
70 const DicomPath& path)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
71 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
72 try
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
73 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
74 std::string s;
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
75
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
76 if (dataset.GetStringValue(s, path))
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
77 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
78 target = boost::lexical_cast<T>(Orthanc::Toolbox::StripSpaces(s));
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
79 return true;
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
80 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
81 else
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
82 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
83 return false;
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
84 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
85 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
86 catch (boost::bad_lexical_cast&)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
87 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
88 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat);
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
89 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
90 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
91
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
92
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
93 bool DicomDatasetReader::GetIntegerValue(int& target,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
94 const DicomPath& path) const
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
95 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
96 return GetValueInternal<int>(target, dataset_, path);
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
97 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
98
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
99
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
100 bool DicomDatasetReader::GetUnsignedIntegerValue(unsigned int& target,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
101 const DicomPath& path) const
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
102 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
103 int value;
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
104
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
105 if (!GetIntegerValue(value, path))
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
106 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
107 return false;
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
108 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
109 else if (value >= 0)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
110 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
111 target = static_cast<unsigned int>(value);
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
112 return true;
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
113 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
114 else
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
115 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
116 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange);
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
117 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
118 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
119
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
120
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
121 bool DicomDatasetReader::GetFloatValue(float& target,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
122 const DicomPath& path) const
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
123 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
124 return GetValueInternal<float>(target, dataset_, path);
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
125 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
126
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
127
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
128 bool DicomDatasetReader::GetDoubleValue(double& target,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
129 const DicomPath& path) const
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
130 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
131 return GetValueInternal<double>(target, dataset_, path);
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
132 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
133 }