Mercurial > hg > orthanc-stone
annotate OrthancStone/Sources/Toolbox/OrthancDatasets/DicomDatasetReader.cpp @ 1894:438071a29f77
xor polygon filler for holes in rt-struct
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 19 Jan 2022 14:25:59 +0100 |
parents | 7053b8a0aaec |
children | 07964689cb0b |
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 | |
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 | 7 * |
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 | 10 * as published by the Free Software Foundation, either version 3 of |
11 * the License, or (at your option) any later version. | |
12 * | |
13 * This program is distributed in the hope that it will be useful, but | |
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 | 21 **/ |
22 | |
23 | |
24 #include "DicomDatasetReader.h" | |
25 | |
26 #include <OrthancException.h> | |
27 #include <Toolbox.h> | |
28 | |
29 #include <boost/lexical_cast.hpp> | |
30 | |
31 namespace OrthancStone | |
32 { | |
33 DicomDatasetReader::DicomDatasetReader(const IDicomDataset& dataset) : | |
34 dataset_(dataset) | |
35 { | |
36 } | |
37 | |
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 | 40 const std::string& defaultValue) const |
41 { | |
42 std::string s; | |
43 if (dataset_.GetStringValue(s, path)) | |
44 { | |
45 return s; | |
46 } | |
47 else | |
48 { | |
49 return defaultValue; | |
50 } | |
51 } | |
52 | |
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 | 55 { |
56 std::string s; | |
57 if (dataset_.GetStringValue(s, path)) | |
58 { | |
59 return s; | |
60 } | |
61 else | |
62 { | |
63 throw Orthanc::OrthancException(Orthanc::ErrorCode_InexistentTag); | |
64 } | |
65 } | |
66 | |
67 | |
68 template <typename T> | |
69 static bool GetValueInternal(T& target, | |
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 | 72 { |
73 try | |
74 { | |
75 std::string s; | |
76 | |
77 if (dataset.GetStringValue(s, path)) | |
78 { | |
79 target = boost::lexical_cast<T>(Orthanc::Toolbox::StripSpaces(s)); | |
80 return true; | |
81 } | |
82 else | |
83 { | |
84 return false; | |
85 } | |
86 } | |
87 catch (boost::bad_lexical_cast&) | |
88 { | |
89 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat); | |
90 } | |
91 } | |
92 | |
93 | |
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 | 96 { |
97 return GetValueInternal<int>(target, dataset_, path); | |
98 } | |
99 | |
100 | |
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 | 103 { |
104 int value; | |
105 | |
106 if (!GetIntegerValue(value, path)) | |
107 { | |
108 return false; | |
109 } | |
110 else if (value >= 0) | |
111 { | |
112 target = static_cast<unsigned int>(value); | |
113 return true; | |
114 } | |
115 else | |
116 { | |
117 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); | |
118 } | |
119 } | |
120 | |
121 | |
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 | 124 { |
125 return GetValueInternal<float>(target, dataset_, path); | |
126 } | |
127 | |
128 | |
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 | 131 { |
132 return GetValueInternal<double>(target, dataset_, path); | |
133 } | |
134 } |