comparison Framework/Toolbox/Slice.cpp @ 73:ffa6dded91bd wasm

reorganization
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 24 May 2017 11:59:24 +0200
parents
children f244018a4e4b
comparison
equal deleted inserted replaced
72:c1cc3bdba18c 73:ffa6dded91bd
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 Osimis, Belgium
6 *
7 * This program is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU Affero General Public License
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
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Affero General Public License for more details.
16 *
17 * You should have received a copy of the GNU Affero General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 **/
20
21
22 #include "Slice.h"
23
24 #include "../../Resources/Orthanc/Core/OrthancException.h"
25
26 namespace OrthancStone
27 {
28 bool Slice::ParseOrthancFrame(const OrthancPlugins::IDicomDataset& dataset,
29 const std::string& instanceId,
30 unsigned int frame)
31 {
32 OrthancPlugins::DicomDatasetReader reader(dataset);
33
34 unsigned int frameCount;
35 if (!reader.GetUnsignedIntegerValue(frameCount, OrthancPlugins::DICOM_TAG_NUMBER_OF_FRAMES))
36 {
37 frameCount = 1; // Assume instance with one frame
38 }
39
40 if (frame >= frameCount)
41 {
42 return false;
43 }
44
45 if (!reader.GetDoubleValue(thickness_, OrthancPlugins::DICOM_TAG_SLICE_THICKNESS))
46 {
47 thickness_ = 100.0 * std::numeric_limits<double>::epsilon();
48 }
49
50 GeometryToolbox::GetPixelSpacing(pixelSpacingX_, pixelSpacingY_, dataset);
51
52 std::string position, orientation;
53 if (dataset.GetStringValue(position, OrthancPlugins::DICOM_TAG_IMAGE_POSITION_PATIENT) &&
54 dataset.GetStringValue(orientation, OrthancPlugins::DICOM_TAG_IMAGE_ORIENTATION_PATIENT))
55 {
56 geometry_ = SliceGeometry(position, orientation);
57 }
58
59 if (reader.GetUnsignedIntegerValue(width_, OrthancPlugins::DICOM_TAG_COLUMNS) &&
60 reader.GetUnsignedIntegerValue(height_, OrthancPlugins::DICOM_TAG_ROWS))
61 {
62 orthancInstanceId_ = instanceId;
63 frame_ = frame;
64 converter_.ReadParameters(dataset);
65
66 type_ = Type_OrthancInstance;
67 return true;
68 }
69 else
70 {
71 return false;
72 }
73 }
74
75
76 const std::string Slice::GetOrthancInstanceId() const
77 {
78 if (type_ != Type_OrthancInstance)
79 {
80 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls);
81 }
82
83 return orthancInstanceId_;
84 }
85
86
87 unsigned int Slice::GetFrame() const
88 {
89 if (type_ == Type_Invalid)
90 {
91 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls);
92 }
93
94 return frame_;
95 }
96
97
98 const SliceGeometry& Slice::GetGeometry() const
99 {
100 if (type_ == Type_Invalid)
101 {
102 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls);
103 }
104
105 return geometry_;
106 }
107
108
109 double Slice::GetThickness() const
110 {
111 if (type_ == Type_Invalid)
112 {
113 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls);
114 }
115
116 return thickness_;
117 }
118
119
120 double Slice::GetPixelSpacingX() const
121 {
122 if (type_ == Type_Invalid)
123 {
124 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls);
125 }
126
127 return pixelSpacingX_;
128 }
129
130
131 double Slice::GetPixelSpacingY() const
132 {
133 if (type_ == Type_Invalid)
134 {
135 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls);
136 }
137
138 return pixelSpacingY_;
139 }
140
141
142 unsigned int Slice::GetWidth() const
143 {
144 if (type_ == Type_Invalid)
145 {
146 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls);
147 }
148
149 return width_;
150 }
151
152
153 unsigned int Slice::GetHeight() const
154 {
155 if (type_ == Type_Invalid)
156 {
157 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls);
158 }
159
160 return height_;
161 }
162
163
164 const DicomFrameConverter& Slice::GetConverter() const
165 {
166 if (type_ == Type_Invalid)
167 {
168 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls);
169 }
170
171 return converter_;
172 }
173 }