Mercurial > hg > orthanc-stone
annotate Framework/Layers/SeriesFrameRendererFactory.cpp @ 550:01c4b4583cc1 ct-pet-dose-struct
Close branch ct-pet-dose-struct
author | Benjamin Golinvaux <bgo@osimis.io> |
---|---|
date | Tue, 02 Apr 2019 14:02:12 +0000 |
parents | b70e9be013e4 |
children | 4f2416d519b4 |
rev | line source |
---|---|
0 | 1 /** |
2 * Stone of Orthanc | |
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics | |
4 * Department, University Hospital of Liege, Belgium | |
439 | 5 * Copyright (C) 2017-2019 Osimis S.A., Belgium |
0 | 6 * |
7 * This program is free software: you can redistribute it and/or | |
47 | 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. | |
0 | 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 | |
47 | 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 | |
0 | 18 * along with this program. If not, see <http://www.gnu.org/licenses/>. |
19 **/ | |
20 | |
21 | |
22 #include "SeriesFrameRendererFactory.h" | |
23 | |
24 #include "FrameRenderer.h" | |
113
2eca030792aa
using the Orthanc Framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
25 |
212
5412adf19980
resort to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
201
diff
changeset
|
26 #include <OrthancException.h> |
5412adf19980
resort to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
201
diff
changeset
|
27 #include <Logging.h> |
5412adf19980
resort to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
201
diff
changeset
|
28 #include <Toolbox.h> |
113
2eca030792aa
using the Orthanc Framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
29 #include <Plugins/Samples/Common/OrthancPluginException.h> |
2eca030792aa
using the Orthanc Framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
30 #include <Plugins/Samples/Common/DicomDatasetReader.h> |
32 | 31 |
0 | 32 |
33 namespace OrthancStone | |
34 { | |
35 void SeriesFrameRendererFactory::ReadCurrentFrameDataset(size_t frame) | |
36 { | |
37 if (currentDataset_.get() != NULL && | |
38 (fast_ || currentFrame_ == frame)) | |
39 { | |
40 // The frame has not changed since the previous call, no need to | |
41 // update the DICOM dataset | |
42 return; | |
43 } | |
44 | |
45 currentDataset_.reset(loader_->DownloadDicom(frame)); | |
46 currentFrame_ = frame; | |
47 | |
48 if (currentDataset_.get() == NULL) | |
49 { | |
50 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); | |
51 } | |
52 } | |
53 | |
54 | |
55 void SeriesFrameRendererFactory::GetCurrentPixelSpacing(double& spacingX, | |
56 double& spacingY) const | |
57 { | |
58 if (currentDataset_.get() == NULL) | |
59 { | |
60 // There was no previous call "ReadCurrentFrameDataset()" | |
61 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); | |
62 } | |
63 | |
32 | 64 GeometryToolbox::GetPixelSpacing(spacingX, spacingY, *currentDataset_); |
0 | 65 } |
66 | |
67 | |
68 double SeriesFrameRendererFactory::GetCurrentSliceThickness() const | |
69 { | |
70 if (currentDataset_.get() == NULL) | |
71 { | |
72 // There was no previous call "ReadCurrentFrameDataset()" | |
73 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); | |
74 } | |
32 | 75 |
76 try | |
0 | 77 { |
32 | 78 OrthancPlugins::DicomDatasetReader reader(*currentDataset_); |
79 | |
80 double thickness; | |
81 if (reader.GetDoubleValue(thickness, OrthancPlugins::DICOM_TAG_SLICE_THICKNESS)) | |
82 { | |
83 return thickness; | |
84 } | |
0 | 85 } |
32 | 86 catch (ORTHANC_PLUGINS_EXCEPTION_CLASS& e) |
0 | 87 { |
88 } | |
32 | 89 |
90 // Some arbitrary large slice thickness | |
91 return std::numeric_limits<double>::infinity(); | |
0 | 92 } |
93 | |
94 | |
95 SeriesFrameRendererFactory::SeriesFrameRendererFactory(ISeriesLoader* loader, // Takes ownership | |
96 bool fast) : | |
97 loader_(loader), | |
98 currentFrame_(0), | |
99 fast_(fast) | |
100 { | |
101 if (loader == NULL) | |
102 { | |
103 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); | |
104 } | |
105 } | |
106 | |
107 | |
108 bool SeriesFrameRendererFactory::GetExtent(double& x1, | |
109 double& y1, | |
110 double& x2, | |
111 double& y2, | |
112 const SliceGeometry& viewportSlice) | |
113 { | |
114 if (currentDataset_.get() == NULL) | |
115 { | |
116 // There has been no previous call to | |
117 // "CreateLayerRenderer". Read some arbitrary DICOM frame, the | |
118 // one at the middle of the series. | |
119 unsigned int depth = loader_->GetGeometry().GetSliceCount(); | |
120 ReadCurrentFrameDataset(depth / 2); | |
121 } | |
122 | |
123 double spacingX, spacingY; | |
124 GetCurrentPixelSpacing(spacingX, spacingY); | |
125 | |
126 return FrameRenderer::ComputeFrameExtent(x1, y1, x2, y2, | |
127 viewportSlice, | |
128 loader_->GetGeometry().GetSlice(0), | |
129 loader_->GetWidth(), | |
130 loader_->GetHeight(), | |
131 spacingX, spacingY); | |
132 } | |
133 | |
134 | |
135 ILayerRenderer* SeriesFrameRendererFactory::CreateLayerRenderer(const SliceGeometry& viewportSlice) | |
136 { | |
137 size_t closest; | |
138 double distance; | |
139 | |
140 bool isOpposite; | |
141 if (!GeometryToolbox::IsParallelOrOpposite(isOpposite, loader_->GetGeometry().GetNormal(), viewportSlice.GetNormal()) || | |
142 !loader_->GetGeometry().ComputeClosestSlice(closest, distance, viewportSlice.GetOrigin())) | |
143 { | |
144 // Unable to compute the slice in the series that is the | |
145 // closest to the slice displayed by the viewport | |
146 return NULL; | |
147 } | |
148 | |
149 ReadCurrentFrameDataset(closest); | |
150 assert(currentDataset_.get() != NULL); | |
151 | |
152 double spacingX, spacingY; | |
153 GetCurrentPixelSpacing(spacingX, spacingY); | |
154 | |
155 if (distance <= GetCurrentSliceThickness() / 2.0) | |
156 { | |
157 SliceGeometry frameSlice(*currentDataset_); | |
158 return FrameRenderer::CreateRenderer(loader_->DownloadFrame(closest), | |
159 frameSlice, | |
160 *currentDataset_, | |
161 spacingX, spacingY, | |
162 true); | |
163 } | |
164 else | |
165 { | |
166 // The closest slice of the series is too far away from the | |
167 // slice displayed by the viewport | |
168 return NULL; | |
169 } | |
170 } | |
171 | |
172 | |
173 ISliceableVolume& SeriesFrameRendererFactory::GetSourceVolume() const | |
174 { | |
175 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); | |
176 } | |
177 } |