Mercurial > hg > orthanc-stone
comparison OrthancStone/Sources/Volumes/VolumeSceneLayerSource.cpp @ 1512:244ad1e4e76a
reorganization of folders
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 07 Jul 2020 16:21:02 +0200 |
parents | Framework/Volumes/VolumeSceneLayerSource.cpp@30deba7bc8e2 |
children | 314b6dc507d9 |
comparison
equal
deleted
inserted
replaced
1511:9dfeee74c1e6 | 1512:244ad1e4e76a |
---|---|
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-2020 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 "VolumeSceneLayerSource.h" | |
23 | |
24 #include "../Scene2D/NullLayer.h" | |
25 #include "../Viewport/IViewport.h" | |
26 #include "../StoneException.h" | |
27 | |
28 #include <OrthancException.h> | |
29 | |
30 namespace OrthancStone | |
31 { | |
32 static bool IsSameCuttingPlane(const CoordinateSystem3D& a, | |
33 const CoordinateSystem3D& b) | |
34 { | |
35 // TODO - What if the normal is reversed? | |
36 double distance; | |
37 return (CoordinateSystem3D::ComputeDistance(distance, a, b) && | |
38 LinearAlgebra::IsCloseToZero(distance)); | |
39 } | |
40 | |
41 | |
42 void VolumeSceneLayerSource::ClearLayer() | |
43 { | |
44 { | |
45 std::unique_ptr<IViewport::ILock> lock(viewport_->Lock()); | |
46 ViewportController& controller = lock->GetController(); | |
47 Scene2D& scene = controller.GetScene(); | |
48 scene.DeleteLayer(layerDepth_); | |
49 } | |
50 lastPlane_.reset(NULL); | |
51 } | |
52 | |
53 VolumeSceneLayerSource::VolumeSceneLayerSource( | |
54 boost::shared_ptr<OrthancStone::IViewport> viewport, | |
55 int layerDepth, | |
56 const boost::shared_ptr<IVolumeSlicer>& slicer) | |
57 : viewport_(viewport) | |
58 , layerDepth_(layerDepth) | |
59 , slicer_(slicer) | |
60 { | |
61 if (slicer == NULL) | |
62 { | |
63 throw Orthanc::OrthancException(Orthanc::ErrorCode_NullPointer); | |
64 } | |
65 | |
66 { | |
67 std::unique_ptr<IViewport::ILock> lock(viewport_->Lock()); | |
68 ViewportController& controller = lock->GetController(); | |
69 Scene2D& scene = controller.GetScene(); | |
70 ORTHANC_ASSERT(!scene.HasLayer(layerDepth_)); | |
71 | |
72 // we need to book the scene layer depth by adding a dummy layer | |
73 std::unique_ptr<NullLayer> nullLayer(new NullLayer); | |
74 scene.SetLayer(layerDepth_,nullLayer.release()); | |
75 } | |
76 } | |
77 | |
78 VolumeSceneLayerSource::~VolumeSceneLayerSource() | |
79 { | |
80 ClearLayer(); | |
81 } | |
82 | |
83 void VolumeSceneLayerSource::RemoveConfigurator() | |
84 { | |
85 configurator_.reset(); | |
86 lastPlane_.reset(); | |
87 } | |
88 | |
89 | |
90 void VolumeSceneLayerSource::SetConfigurator(ILayerStyleConfigurator* configurator) // Takes ownership | |
91 { | |
92 if (configurator == NULL) | |
93 { | |
94 throw Orthanc::OrthancException(Orthanc::ErrorCode_NullPointer); | |
95 } | |
96 | |
97 configurator_.reset(configurator); | |
98 | |
99 // Invalidate the layer | |
100 lastPlane_.reset(NULL); | |
101 } | |
102 | |
103 | |
104 ILayerStyleConfigurator& VolumeSceneLayerSource::GetConfigurator() const | |
105 { | |
106 if (configurator_.get() == NULL) | |
107 { | |
108 LOG(ERROR) << "VolumeSceneLayerSource::GetConfigurator(): (configurator_.get() == NULL)"; | |
109 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); | |
110 } | |
111 | |
112 return *configurator_; | |
113 } | |
114 | |
115 | |
116 void VolumeSceneLayerSource::Update(const CoordinateSystem3D& plane) | |
117 { | |
118 std::unique_ptr<IViewport::ILock> lock(viewport_->Lock()); | |
119 ViewportController& controller = lock->GetController(); | |
120 Scene2D& scene = controller.GetScene(); | |
121 | |
122 assert(slicer_.get() != NULL); | |
123 std::unique_ptr<IVolumeSlicer::IExtractedSlice> slice(slicer_->ExtractSlice(plane)); | |
124 | |
125 if (slice.get() == NULL) | |
126 { | |
127 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); | |
128 } | |
129 | |
130 if (!slice->IsValid()) | |
131 { | |
132 // The slicer cannot handle this cutting plane: Clear the layer | |
133 ClearLayer(); | |
134 } | |
135 else if (lastPlane_.get() != NULL && | |
136 IsSameCuttingPlane(*lastPlane_, plane) && | |
137 lastRevision_ == slice->GetRevision()) | |
138 { | |
139 // The content of the slice has not changed: Don't update the | |
140 // layer content, but possibly update its style | |
141 | |
142 if (configurator_.get() != NULL && | |
143 configurator_->GetRevision() != lastConfiguratorRevision_ && | |
144 scene.HasLayer(layerDepth_)) | |
145 { | |
146 configurator_->ApplyStyle(scene.GetLayer(layerDepth_)); | |
147 } | |
148 } | |
149 else | |
150 { | |
151 LOG(TRACE) << "VolumeSceneLayerSource::Update -- Content has changed: An update is needed"; | |
152 // Content has changed: An update is needed | |
153 lastPlane_.reset(new CoordinateSystem3D(plane)); | |
154 lastRevision_ = slice->GetRevision(); | |
155 | |
156 std::unique_ptr<ISceneLayer> layer(slice->CreateSceneLayer(configurator_.get(), plane)); | |
157 if (layer.get() == NULL) | |
158 { | |
159 LOG(TRACE) << "VolumeSceneLayerSource::Update -- (layer.get() == NULL)"; | |
160 ClearLayer(); | |
161 } | |
162 else | |
163 { | |
164 LOG(TRACE) << "VolumeSceneLayerSource::Update -- (layer.get() != NULL)"; | |
165 if (configurator_.get() != NULL) | |
166 { | |
167 lastConfiguratorRevision_ = configurator_->GetRevision(); | |
168 configurator_->ApplyStyle(*layer); | |
169 } | |
170 | |
171 scene.SetLayer(layerDepth_, layer.release()); | |
172 } | |
173 } | |
174 } | |
175 } |