Mercurial > hg > orthanc-stone
comparison OrthancStone/Sources/Volumes/VolumeSceneLayerSource.cpp @ 1685:7896aac14587
Protected against usage of dying viewport
author | Benjamin Golinvaux <bgo@osimis.io> |
---|---|
date | Wed, 25 Nov 2020 12:16:53 +0100 |
parents | 52b8b96cb55f |
children | 9ac2a65d4172 |
comparison
equal
deleted
inserted
replaced
1684:fb62c1522193 | 1685:7896aac14587 |
---|---|
135 | 135 |
136 | 136 |
137 void VolumeSceneLayerSource::Update(const CoordinateSystem3D& plane) | 137 void VolumeSceneLayerSource::Update(const CoordinateSystem3D& plane) |
138 { | 138 { |
139 std::unique_ptr<IViewport::ILock> lock(GetViewportLock()); | 139 std::unique_ptr<IViewport::ILock> lock(GetViewportLock()); |
140 ViewportController& controller = lock->GetController(); | 140 if(lock) |
141 Scene2D& scene = controller.GetScene(); | 141 { |
142 ViewportController& controller = lock->GetController(); | |
143 Scene2D& scene = controller.GetScene(); | |
142 | 144 |
143 assert(slicer_.get() != NULL); | 145 assert(slicer_.get() != NULL); |
144 std::unique_ptr<IVolumeSlicer::IExtractedSlice> slice(slicer_->ExtractSlice(plane)); | 146 std::unique_ptr<IVolumeSlicer::IExtractedSlice> slice(slicer_->ExtractSlice(plane)); |
145 | 147 |
146 if (slice.get() == NULL) | 148 if (slice.get() == NULL) |
147 { | 149 { |
148 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); | 150 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); |
149 } | 151 } |
150 | 152 |
151 if (!slice->IsValid()) | 153 if (!slice->IsValid()) |
152 { | 154 { |
153 // The slicer cannot handle this cutting plane: Clear the layer | 155 // The slicer cannot handle this cutting plane: Clear the layer |
154 ClearLayer(); | 156 ClearLayer(); |
155 } | 157 } |
156 else if (lastPlane_.get() != NULL && | 158 else if (lastPlane_.get() != NULL && |
157 IsSameCuttingPlane(*lastPlane_, plane) && | 159 IsSameCuttingPlane(*lastPlane_, plane) && |
158 lastRevision_ == slice->GetRevision()) | 160 lastRevision_ == slice->GetRevision()) |
159 { | 161 { |
160 // The content of the slice has not changed: Don't update the | 162 // The content of the slice has not changed: Don't update the |
161 // layer content, but possibly update its style | 163 // layer content, but possibly update its style |
162 | 164 |
163 if (configurator_.get() != NULL && | 165 if (configurator_.get() != NULL && |
164 configurator_->GetRevision() != lastConfiguratorRevision_ && | 166 configurator_->GetRevision() != lastConfiguratorRevision_ && |
165 scene.HasLayer(layerDepth_)) | 167 scene.HasLayer(layerDepth_)) |
166 { | 168 { |
167 configurator_->ApplyStyle(scene.GetLayer(layerDepth_)); | 169 configurator_->ApplyStyle(scene.GetLayer(layerDepth_)); |
168 } | 170 } |
169 } | |
170 else | |
171 { | |
172 LOG(TRACE) << "VolumeSceneLayerSource::Update -- Content has changed: An update is needed"; | |
173 // Content has changed: An update is needed | |
174 lastPlane_.reset(new CoordinateSystem3D(plane)); | |
175 lastRevision_ = slice->GetRevision(); | |
176 | |
177 std::unique_ptr<ISceneLayer> layer(slice->CreateSceneLayer(configurator_.get(), plane)); | |
178 if (layer.get() == NULL) | |
179 { | |
180 LOG(TRACE) << "VolumeSceneLayerSource::Update -- (layer.get() == NULL)"; | |
181 ClearLayer(); | |
182 } | 171 } |
183 else | 172 else |
184 { | 173 { |
185 LOG(TRACE) << "VolumeSceneLayerSource::Update -- (layer.get() != NULL)"; | 174 LOG(TRACE) << "VolumeSceneLayerSource::Update -- Content has changed: An update is needed"; |
186 if (configurator_.get() != NULL) | 175 // Content has changed: An update is needed |
176 lastPlane_.reset(new CoordinateSystem3D(plane)); | |
177 lastRevision_ = slice->GetRevision(); | |
178 | |
179 std::unique_ptr<ISceneLayer> layer(slice->CreateSceneLayer(configurator_.get(), plane)); | |
180 if (layer.get() == NULL) | |
187 { | 181 { |
188 lastConfiguratorRevision_ = configurator_->GetRevision(); | 182 LOG(TRACE) << "VolumeSceneLayerSource::Update -- (layer.get() == NULL)"; |
189 configurator_->ApplyStyle(*layer); | 183 ClearLayer(); |
190 } | 184 } |
185 else | |
186 { | |
187 LOG(TRACE) << "VolumeSceneLayerSource::Update -- (layer.get() != NULL)"; | |
188 if (configurator_.get() != NULL) | |
189 { | |
190 lastConfiguratorRevision_ = configurator_->GetRevision(); | |
191 configurator_->ApplyStyle(*layer); | |
192 } | |
191 | 193 |
192 scene.SetLayer(layerDepth_, layer.release()); | 194 scene.SetLayer(layerDepth_, layer.release()); |
195 } | |
193 } | 196 } |
194 } | 197 } |
195 } | 198 } |
196 } | 199 } |