comparison Framework/Deprecated/Layers/DicomSeriesVolumeSlicer.cpp @ 732:c35e98d22764

move Deprecated classes to a separate folder
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 21 May 2019 14:27:35 +0200
parents Framework/Layers/DicomSeriesVolumeSlicer.cpp@4f2416d519b4
children be9c1530d40a
comparison
equal deleted inserted replaced
729:529189f399ec 732:c35e98d22764
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-2019 Osimis S.A., 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 "DicomSeriesVolumeSlicer.h"
23
24 #include "FrameRenderer.h"
25 #include "../Toolbox/DicomFrameConverter.h"
26
27 #include <Core/Logging.h>
28 #include <Core/OrthancException.h>
29
30 #include <boost/lexical_cast.hpp>
31
32 namespace Deprecated
33 {
34
35 void DicomSeriesVolumeSlicer::OnSliceGeometryReady(const OrthancSlicesLoader::SliceGeometryReadyMessage& message)
36 {
37 if (message.GetOrigin().GetSlicesCount() > 0)
38 {
39 BroadcastMessage(IVolumeSlicer::GeometryReadyMessage(*this));
40 }
41 else
42 {
43 BroadcastMessage(IVolumeSlicer::GeometryErrorMessage(*this));
44 }
45 }
46
47 void DicomSeriesVolumeSlicer::OnSliceGeometryError(const OrthancSlicesLoader::SliceGeometryErrorMessage& message)
48 {
49 BroadcastMessage(IVolumeSlicer::GeometryErrorMessage(*this));
50 }
51
52
53 class DicomSeriesVolumeSlicer::RendererFactory : public LayerReadyMessage::IRendererFactory
54 {
55 private:
56 const OrthancSlicesLoader::SliceImageReadyMessage& message_;
57
58 public:
59 RendererFactory(const OrthancSlicesLoader::SliceImageReadyMessage& message) :
60 message_(message)
61 {
62 }
63
64 virtual ILayerRenderer* CreateRenderer() const
65 {
66 bool isFull = (message_.GetEffectiveQuality() == OrthancStone::SliceImageQuality_FullPng ||
67 message_.GetEffectiveQuality() == OrthancStone::SliceImageQuality_FullPam);
68
69 return FrameRenderer::CreateRenderer(message_.GetImage(), message_.GetSlice(), isFull);
70 }
71 };
72
73 void DicomSeriesVolumeSlicer::OnSliceImageReady(const OrthancSlicesLoader::SliceImageReadyMessage& message)
74 {
75 // first notify that the pixel data of the frame is ready (targeted to, i.e: an image cache)
76 BroadcastMessage(FrameReadyMessage(*this, message.GetImage(),
77 message.GetEffectiveQuality(), message.GetSlice()));
78
79 // then notify that the layer is ready for rendering
80 RendererFactory factory(message);
81 BroadcastMessage(IVolumeSlicer::LayerReadyMessage(*this, factory, message.GetSlice().GetGeometry()));
82 }
83
84 void DicomSeriesVolumeSlicer::OnSliceImageError(const OrthancSlicesLoader::SliceImageErrorMessage& message)
85 {
86 BroadcastMessage(IVolumeSlicer::LayerErrorMessage(*this, message.GetSlice().GetGeometry()));
87 }
88
89
90 DicomSeriesVolumeSlicer::DicomSeriesVolumeSlicer(OrthancStone::MessageBroker& broker,
91 OrthancApiClient& orthanc) :
92 IVolumeSlicer(broker),
93 IObserver(broker),
94 loader_(broker, orthanc),
95 quality_(OrthancStone::SliceImageQuality_FullPng)
96 {
97 loader_.RegisterObserverCallback(
98 new OrthancStone::Callable<DicomSeriesVolumeSlicer, OrthancSlicesLoader::SliceGeometryReadyMessage>
99 (*this, &DicomSeriesVolumeSlicer::OnSliceGeometryReady));
100
101 loader_.RegisterObserverCallback(
102 new OrthancStone::Callable<DicomSeriesVolumeSlicer, OrthancSlicesLoader::SliceGeometryErrorMessage>
103 (*this, &DicomSeriesVolumeSlicer::OnSliceGeometryError));
104
105 loader_.RegisterObserverCallback(
106 new OrthancStone::Callable<DicomSeriesVolumeSlicer, OrthancSlicesLoader::SliceImageReadyMessage>
107 (*this, &DicomSeriesVolumeSlicer::OnSliceImageReady));
108
109 loader_.RegisterObserverCallback(
110 new OrthancStone::Callable<DicomSeriesVolumeSlicer, OrthancSlicesLoader::SliceImageErrorMessage>
111 (*this, &DicomSeriesVolumeSlicer::OnSliceImageError));
112 }
113
114
115 void DicomSeriesVolumeSlicer::LoadSeries(const std::string& seriesId)
116 {
117 loader_.ScheduleLoadSeries(seriesId);
118 }
119
120
121 void DicomSeriesVolumeSlicer::LoadInstance(const std::string& instanceId)
122 {
123 loader_.ScheduleLoadInstance(instanceId);
124 }
125
126
127 void DicomSeriesVolumeSlicer::LoadFrame(const std::string& instanceId,
128 unsigned int frame)
129 {
130 loader_.ScheduleLoadFrame(instanceId, frame);
131 }
132
133
134 bool DicomSeriesVolumeSlicer::GetExtent(std::vector<OrthancStone::Vector>& points,
135 const OrthancStone::CoordinateSystem3D& viewportSlice)
136 {
137 size_t index;
138
139 if (loader_.IsGeometryReady() &&
140 loader_.LookupSlice(index, viewportSlice))
141 {
142 loader_.GetSlice(index).GetExtent(points);
143 return true;
144 }
145 else
146 {
147 return false;
148 }
149 }
150
151
152 void DicomSeriesVolumeSlicer::ScheduleLayerCreation(const OrthancStone::CoordinateSystem3D& viewportSlice)
153 {
154 size_t index;
155
156 if (loader_.IsGeometryReady() &&
157 loader_.LookupSlice(index, viewportSlice))
158 {
159 loader_.ScheduleLoadSliceImage(index, quality_);
160 }
161 }
162 }