annotate OrthancStone/Sources/Toolbox/OrthancDatasets/DicomDatasetReader.cpp @ 1993:317a53d4fdc6

added magnifying glass
author Sebastien Jodogne <s.jodogne@gmail.com>
date Mon, 31 Oct 2022 22:19:57 +0100
parents 7053b8a0aaec
children 07964689cb0b
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
1871
7053b8a0aaec upgrade to year 2022
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1870
diff changeset
5 * Copyright (C) 2017-2022 Osimis S.A., Belgium
7053b8a0aaec upgrade to year 2022
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1870
diff changeset
6 * Copyright (C) 2021-2022 Sebastien Jodogne, ICTEAM UCLouvain, Belgium
1504
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 *
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 * 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
9 * modify it under the terms of the GNU Lesser General Public License
1504
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 * as published by the Free Software Foundation, either version 3 of
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 * the License, or (at your option) any later version.
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 *
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 * This program is distributed in the hope that it will be useful, but
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 * 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
15 * 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
16 * Lesser General Public License for more details.
1596
4fb8fdf03314 removed annoying whitespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1512
diff changeset
17 *
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
18 * 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
19 * 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
20 * <http://www.gnu.org/licenses/>.
1504
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
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24 #include "DicomDatasetReader.h"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26 #include <OrthancException.h>
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27 #include <Toolbox.h>
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29 #include <boost/lexical_cast.hpp>
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31 namespace OrthancStone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
33 DicomDatasetReader::DicomDatasetReader(const IDicomDataset& dataset) :
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34 dataset_(dataset)
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
1834
126522623e20 replaced OrthancStone::DicomPath by new class Orthanc::DicomPath from orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
39 std::string DicomDatasetReader::GetStringValue(const Orthanc::DicomPath& path,
1504
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
40 const std::string& defaultValue) const
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
41 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
42 std::string s;
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
43 if (dataset_.GetStringValue(s, path))
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
44 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
45 return s;
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
46 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
47 else
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
48 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
49 return defaultValue;
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
1834
126522623e20 replaced OrthancStone::DicomPath by new class Orthanc::DicomPath from orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
54 std::string DicomDatasetReader::GetMandatoryStringValue(const Orthanc::DicomPath& path) const
1504
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
55 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
56 std::string s;
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
57 if (dataset_.GetStringValue(s, path))
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
58 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
59 return s;
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
60 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
61 else
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
62 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
63 throw Orthanc::OrthancException(Orthanc::ErrorCode_InexistentTag);
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
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
68 template <typename T>
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
69 static bool GetValueInternal(T& target,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
70 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
71 const Orthanc::DicomPath& path)
1504
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
72 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
73 try
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
74 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
75 std::string s;
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
76
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
77 if (dataset.GetStringValue(s, path))
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
78 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
79 target = boost::lexical_cast<T>(Orthanc::Toolbox::StripSpaces(s));
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
80 return true;
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
81 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
82 else
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
83 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
84 return false;
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
85 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
86 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
87 catch (boost::bad_lexical_cast&)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
88 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
89 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat);
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
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
94 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
95 const Orthanc::DicomPath& path) const
1504
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
96 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
97 return GetValueInternal<int>(target, dataset_, path);
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
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
101 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
102 const Orthanc::DicomPath& path) const
1504
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
103 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
104 int value;
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
105
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
106 if (!GetIntegerValue(value, path))
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
107 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
108 return false;
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
109 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
110 else if (value >= 0)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
111 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
112 target = static_cast<unsigned int>(value);
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
113 return true;
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
114 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
115 else
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
116 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
117 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange);
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
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
122 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
123 const Orthanc::DicomPath& path) const
1504
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
124 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
125 return GetValueInternal<float>(target, dataset_, path);
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
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
129 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
130 const Orthanc::DicomPath& path) const
1504
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
131 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
132 return GetValueInternal<double>(target, dataset_, path);
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
133 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
134 }