Mercurial > hg > orthanc-stone
annotate Framework/Toolbox/Slice.cpp @ 113:2eca030792aa wasm
using the Orthanc Framework
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 20 Sep 2017 15:32:32 +0200 |
parents | 53025eecbc95 |
children | 42c05a3baee3 |
rev | line source |
---|---|
73 | 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 | |
113
2eca030792aa
using the Orthanc Framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
110
diff
changeset
|
24 #include <Core/OrthancException.h> |
73 | 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 { | |
110
53025eecbc95
renamed SliceGeometry as CoordinateSystem3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
102
diff
changeset
|
56 geometry_ = CoordinateSystem3D(position, orientation); |
73 | 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 | |
110
53025eecbc95
renamed SliceGeometry as CoordinateSystem3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
102
diff
changeset
|
98 const CoordinateSystem3D& Slice::GetGeometry() const |
73 | 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 } | |
89
f244018a4e4b
BUGGY- trying to remove IVolumeSlicesObserver
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
73
diff
changeset
|
173 |
f244018a4e4b
BUGGY- trying to remove IVolumeSlicesObserver
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
73
diff
changeset
|
174 |
110
53025eecbc95
renamed SliceGeometry as CoordinateSystem3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
102
diff
changeset
|
175 bool Slice::ContainsPlane(const CoordinateSystem3D& plane) const |
89
f244018a4e4b
BUGGY- trying to remove IVolumeSlicesObserver
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
73
diff
changeset
|
176 { |
f244018a4e4b
BUGGY- trying to remove IVolumeSlicesObserver
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
73
diff
changeset
|
177 if (type_ == Type_Invalid) |
f244018a4e4b
BUGGY- trying to remove IVolumeSlicesObserver
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
73
diff
changeset
|
178 { |
f244018a4e4b
BUGGY- trying to remove IVolumeSlicesObserver
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
73
diff
changeset
|
179 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); |
f244018a4e4b
BUGGY- trying to remove IVolumeSlicesObserver
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
73
diff
changeset
|
180 } |
101
af312ce4fe59
support of 3D swapping of the normal
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
89
diff
changeset
|
181 |
af312ce4fe59
support of 3D swapping of the normal
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
89
diff
changeset
|
182 bool opposite; |
af312ce4fe59
support of 3D swapping of the normal
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
89
diff
changeset
|
183 return (GeometryToolbox::IsParallelOrOpposite(opposite, |
af312ce4fe59
support of 3D swapping of the normal
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
89
diff
changeset
|
184 GetGeometry().GetNormal(), |
af312ce4fe59
support of 3D swapping of the normal
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
89
diff
changeset
|
185 plane.GetNormal()) && |
89
f244018a4e4b
BUGGY- trying to remove IVolumeSlicesObserver
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
73
diff
changeset
|
186 GeometryToolbox::IsNear(GetGeometry().ProjectAlongNormal(GetGeometry().GetOrigin()), |
f244018a4e4b
BUGGY- trying to remove IVolumeSlicesObserver
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
73
diff
changeset
|
187 GetGeometry().ProjectAlongNormal(plane.GetOrigin()), |
f244018a4e4b
BUGGY- trying to remove IVolumeSlicesObserver
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
73
diff
changeset
|
188 thickness_ / 2.0)); |
f244018a4e4b
BUGGY- trying to remove IVolumeSlicesObserver
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
73
diff
changeset
|
189 } |
102 | 190 |
191 | |
192 void Slice::GetExtent(std::vector<Vector>& points) const | |
193 { | |
194 double sx = GetPixelSpacingX(); | |
195 double sy = GetPixelSpacingY(); | |
196 double w = static_cast<double>(GetWidth()); | |
197 double h = static_cast<double>(GetHeight()); | |
198 | |
199 points.clear(); | |
200 points.push_back(GetGeometry().MapSliceToWorldCoordinates(-0.5 * sx, -0.5 * sy)); | |
201 points.push_back(GetGeometry().MapSliceToWorldCoordinates((w - 0.5) * sx, -0.5 * sy)); | |
202 points.push_back(GetGeometry().MapSliceToWorldCoordinates(-0.5 * sx, (h - 0.5) * sy)); | |
203 points.push_back(GetGeometry().MapSliceToWorldCoordinates((w - 0.5) * sx, (h - 0.5) * sy)); | |
204 } | |
73 | 205 } |