annotate OrthancStone/Sources/Volumes/VolumeSceneLayerSource.cpp @ 1763:29c85a2c6df0

fix segfault in sample rt viewer on sdl
author Sebastien Jodogne <s.jodogne@gmail.com>
date Mon, 10 May 2021 14:18:24 +0200
parents 9ac2a65d4172
children 3889ae96d2e9
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
815
df442f1ba0c6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 /**
df442f1ba0c6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2 * Stone of Orthanc
df442f1ba0c6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
df442f1ba0c6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
4 * Department, University Hospital of Liege, Belgium
1739
9ac2a65d4172 upgrade to year 2021
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1685
diff changeset
5 * Copyright (C) 2017-2021 Osimis S.A., Belgium
815
df442f1ba0c6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
6 *
df442f1ba0c6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 * This program is free software: you can redistribute it and/or
1598
8563ea5d8ae4 relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1596
diff changeset
8 * modify it under the terms of the GNU Lesser General Public License
815
df442f1ba0c6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 * as published by the Free Software Foundation, either version 3 of
df442f1ba0c6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 * the License, or (at your option) any later version.
df442f1ba0c6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 *
df442f1ba0c6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 * This program is distributed in the hope that it will be useful, but
df442f1ba0c6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
1598
8563ea5d8ae4 relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1596
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
8563ea5d8ae4 relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1596
diff changeset
15 * Lesser General Public License for more details.
1596
4fb8fdf03314 removed annoying whitespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1571
diff changeset
16 *
1598
8563ea5d8ae4 relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1596
diff changeset
17 * You should have received a copy of the GNU Lesser General Public
8563ea5d8ae4 relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1596
diff changeset
18 * License along with this program. If not, see
8563ea5d8ae4 relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1596
diff changeset
19 * <http://www.gnu.org/licenses/>.
815
df442f1ba0c6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20 **/
df442f1ba0c6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21
df442f1ba0c6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22
df442f1ba0c6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23 #include "VolumeSceneLayerSource.h"
df442f1ba0c6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24
1324
4d8d642f7036 Added a NullLayer scene layer type that allows
Benjamin Golinvaux <bgo@osimis.io>
parents: 1322
diff changeset
25 #include "../Scene2D/NullLayer.h"
1433
8635b333fa5b [BREAKING] VolumeSceneLayerSource now locks the viewport properly before using the scene. The ctor now accepts the viewport instead of a ref. to the scene. RtViewer sample has been adapted accordingly.
Benjamin Golinvaux <bgo@osimis.io>
parents: 1345
diff changeset
26 #include "../Viewport/IViewport.h"
1324
4d8d642f7036 Added a NullLayer scene layer type that allows
Benjamin Golinvaux <bgo@osimis.io>
parents: 1322
diff changeset
27 #include "../StoneException.h"
1558
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1512
diff changeset
28 #include "../Scene2DViewport/ViewportController.h"
1324
4d8d642f7036 Added a NullLayer scene layer type that allows
Benjamin Golinvaux <bgo@osimis.io>
parents: 1322
diff changeset
29
1455
30deba7bc8e2 simplifying include_directories
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1433
diff changeset
30 #include <OrthancException.h>
815
df442f1ba0c6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31
df442f1ba0c6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32 namespace OrthancStone
df442f1ba0c6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
33 {
df442f1ba0c6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34 static bool IsSameCuttingPlane(const CoordinateSystem3D& a,
df442f1ba0c6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35 const CoordinateSystem3D& b)
df442f1ba0c6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
36 {
df442f1ba0c6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
37 // TODO - What if the normal is reversed?
df442f1ba0c6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
38 double distance;
df442f1ba0c6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
39 return (CoordinateSystem3D::ComputeDistance(distance, a, b) &&
df442f1ba0c6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
40 LinearAlgebra::IsCloseToZero(distance));
df442f1ba0c6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
41 }
df442f1ba0c6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
42
df442f1ba0c6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
43 void VolumeSceneLayerSource::ClearLayer()
df442f1ba0c6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
44 {
1433
8635b333fa5b [BREAKING] VolumeSceneLayerSource now locks the viewport properly before using the scene. The ctor now accepts the viewport instead of a ref. to the scene. RtViewer sample has been adapted accordingly.
Benjamin Golinvaux <bgo@osimis.io>
parents: 1345
diff changeset
45 {
1606
874e178f34e9 - ViewportController now has weak ptr to Viewport
Benjamin Golinvaux <bgo@osimis.io>
parents: 1598
diff changeset
46 std::unique_ptr<IViewport::ILock> lock(GetViewportLock());
1763
29c85a2c6df0 fix segfault in sample rt viewer on sdl
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
47 if (lock.get())
29c85a2c6df0 fix segfault in sample rt viewer on sdl
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
48 {
29c85a2c6df0 fix segfault in sample rt viewer on sdl
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
49 ViewportController& controller = lock->GetController();
29c85a2c6df0 fix segfault in sample rt viewer on sdl
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
50 Scene2D& scene = controller.GetScene();
29c85a2c6df0 fix segfault in sample rt viewer on sdl
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
51 scene.DeleteLayer(layerDepth_);
29c85a2c6df0 fix segfault in sample rt viewer on sdl
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
52 }
1433
8635b333fa5b [BREAKING] VolumeSceneLayerSource now locks the viewport properly before using the scene. The ctor now accepts the viewport instead of a ref. to the scene. RtViewer sample has been adapted accordingly.
Benjamin Golinvaux <bgo@osimis.io>
parents: 1345
diff changeset
53 }
815
df442f1ba0c6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
54 lastPlane_.reset(NULL);
df442f1ba0c6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
55 }
df442f1ba0c6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
56
1606
874e178f34e9 - ViewportController now has weak ptr to Viewport
Benjamin Golinvaux <bgo@osimis.io>
parents: 1598
diff changeset
57 IViewport::ILock* VolumeSceneLayerSource::GetViewportLock()
874e178f34e9 - ViewportController now has weak ptr to Viewport
Benjamin Golinvaux <bgo@osimis.io>
parents: 1598
diff changeset
58 {
874e178f34e9 - ViewportController now has weak ptr to Viewport
Benjamin Golinvaux <bgo@osimis.io>
parents: 1598
diff changeset
59 boost::shared_ptr<IViewport> viewport = viewport_.lock();
874e178f34e9 - ViewportController now has weak ptr to Viewport
Benjamin Golinvaux <bgo@osimis.io>
parents: 1598
diff changeset
60 if (viewport)
874e178f34e9 - ViewportController now has weak ptr to Viewport
Benjamin Golinvaux <bgo@osimis.io>
parents: 1598
diff changeset
61 return viewport->Lock();
874e178f34e9 - ViewportController now has weak ptr to Viewport
Benjamin Golinvaux <bgo@osimis.io>
parents: 1598
diff changeset
62 else
1608
646e581e115b replacing nullptr by NULL for VS2008 compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1606
diff changeset
63 return NULL;
1606
874e178f34e9 - ViewportController now has weak ptr to Viewport
Benjamin Golinvaux <bgo@osimis.io>
parents: 1598
diff changeset
64 }
874e178f34e9 - ViewportController now has weak ptr to Viewport
Benjamin Golinvaux <bgo@osimis.io>
parents: 1598
diff changeset
65
874e178f34e9 - ViewportController now has weak ptr to Viewport
Benjamin Golinvaux <bgo@osimis.io>
parents: 1598
diff changeset
66 IViewport::ILock* VolumeSceneLayerSource::GetViewportLock() const
874e178f34e9 - ViewportController now has weak ptr to Viewport
Benjamin Golinvaux <bgo@osimis.io>
parents: 1598
diff changeset
67 {
874e178f34e9 - ViewportController now has weak ptr to Viewport
Benjamin Golinvaux <bgo@osimis.io>
parents: 1598
diff changeset
68 boost::shared_ptr<IViewport> viewport = viewport_.lock();
874e178f34e9 - ViewportController now has weak ptr to Viewport
Benjamin Golinvaux <bgo@osimis.io>
parents: 1598
diff changeset
69 if (viewport)
874e178f34e9 - ViewportController now has weak ptr to Viewport
Benjamin Golinvaux <bgo@osimis.io>
parents: 1598
diff changeset
70 return viewport->Lock();
874e178f34e9 - ViewportController now has weak ptr to Viewport
Benjamin Golinvaux <bgo@osimis.io>
parents: 1598
diff changeset
71 else
1608
646e581e115b replacing nullptr by NULL for VS2008 compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1606
diff changeset
72 return NULL;
1606
874e178f34e9 - ViewportController now has weak ptr to Viewport
Benjamin Golinvaux <bgo@osimis.io>
parents: 1598
diff changeset
73 }
874e178f34e9 - ViewportController now has weak ptr to Viewport
Benjamin Golinvaux <bgo@osimis.io>
parents: 1598
diff changeset
74
874e178f34e9 - ViewportController now has weak ptr to Viewport
Benjamin Golinvaux <bgo@osimis.io>
parents: 1598
diff changeset
75
1640
52b8b96cb55f cleaning namespaces
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1608
diff changeset
76 VolumeSceneLayerSource::VolumeSceneLayerSource(boost::weak_ptr<IViewport> viewport,
52b8b96cb55f cleaning namespaces
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1608
diff changeset
77 int layerDepth,
52b8b96cb55f cleaning namespaces
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1608
diff changeset
78 const boost::shared_ptr<IVolumeSlicer>& slicer) :
1571
85e117739eca cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1558
diff changeset
79 viewport_(viewport),
85e117739eca cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1558
diff changeset
80 layerDepth_(layerDepth),
85e117739eca cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1558
diff changeset
81 slicer_(slicer),
85e117739eca cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1558
diff changeset
82 lastRevision_(0),
85e117739eca cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1558
diff changeset
83 lastConfiguratorRevision_(0)
815
df442f1ba0c6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
84 {
df442f1ba0c6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
85 if (slicer == NULL)
df442f1ba0c6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
86 {
df442f1ba0c6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
87 throw Orthanc::OrthancException(Orthanc::ErrorCode_NullPointer);
df442f1ba0c6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
88 }
1324
4d8d642f7036 Added a NullLayer scene layer type that allows
Benjamin Golinvaux <bgo@osimis.io>
parents: 1322
diff changeset
89
1433
8635b333fa5b [BREAKING] VolumeSceneLayerSource now locks the viewport properly before using the scene. The ctor now accepts the viewport instead of a ref. to the scene. RtViewer sample has been adapted accordingly.
Benjamin Golinvaux <bgo@osimis.io>
parents: 1345
diff changeset
90 {
1606
874e178f34e9 - ViewportController now has weak ptr to Viewport
Benjamin Golinvaux <bgo@osimis.io>
parents: 1598
diff changeset
91 std::unique_ptr<IViewport::ILock> lock(GetViewportLock());
1433
8635b333fa5b [BREAKING] VolumeSceneLayerSource now locks the viewport properly before using the scene. The ctor now accepts the viewport instead of a ref. to the scene. RtViewer sample has been adapted accordingly.
Benjamin Golinvaux <bgo@osimis.io>
parents: 1345
diff changeset
92 ViewportController& controller = lock->GetController();
8635b333fa5b [BREAKING] VolumeSceneLayerSource now locks the viewport properly before using the scene. The ctor now accepts the viewport instead of a ref. to the scene. RtViewer sample has been adapted accordingly.
Benjamin Golinvaux <bgo@osimis.io>
parents: 1345
diff changeset
93 Scene2D& scene = controller.GetScene();
8635b333fa5b [BREAKING] VolumeSceneLayerSource now locks the viewport properly before using the scene. The ctor now accepts the viewport instead of a ref. to the scene. RtViewer sample has been adapted accordingly.
Benjamin Golinvaux <bgo@osimis.io>
parents: 1345
diff changeset
94 ORTHANC_ASSERT(!scene.HasLayer(layerDepth_));
8635b333fa5b [BREAKING] VolumeSceneLayerSource now locks the viewport properly before using the scene. The ctor now accepts the viewport instead of a ref. to the scene. RtViewer sample has been adapted accordingly.
Benjamin Golinvaux <bgo@osimis.io>
parents: 1345
diff changeset
95
8635b333fa5b [BREAKING] VolumeSceneLayerSource now locks the viewport properly before using the scene. The ctor now accepts the viewport instead of a ref. to the scene. RtViewer sample has been adapted accordingly.
Benjamin Golinvaux <bgo@osimis.io>
parents: 1345
diff changeset
96 // we need to book the scene layer depth by adding a dummy layer
8635b333fa5b [BREAKING] VolumeSceneLayerSource now locks the viewport properly before using the scene. The ctor now accepts the viewport instead of a ref. to the scene. RtViewer sample has been adapted accordingly.
Benjamin Golinvaux <bgo@osimis.io>
parents: 1345
diff changeset
97 std::unique_ptr<NullLayer> nullLayer(new NullLayer);
8635b333fa5b [BREAKING] VolumeSceneLayerSource now locks the viewport properly before using the scene. The ctor now accepts the viewport instead of a ref. to the scene. RtViewer sample has been adapted accordingly.
Benjamin Golinvaux <bgo@osimis.io>
parents: 1345
diff changeset
98 scene.SetLayer(layerDepth_,nullLayer.release());
8635b333fa5b [BREAKING] VolumeSceneLayerSource now locks the viewport properly before using the scene. The ctor now accepts the viewport instead of a ref. to the scene. RtViewer sample has been adapted accordingly.
Benjamin Golinvaux <bgo@osimis.io>
parents: 1345
diff changeset
99 }
815
df442f1ba0c6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
100 }
df442f1ba0c6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
101
934
094d10ed7ec2 VolumeSceneLayerSource dtor now clears the layer
Benjamin Golinvaux <bgo@osimis.io>
parents: 921
diff changeset
102 VolumeSceneLayerSource::~VolumeSceneLayerSource()
094d10ed7ec2 VolumeSceneLayerSource dtor now clears the layer
Benjamin Golinvaux <bgo@osimis.io>
parents: 921
diff changeset
103 {
094d10ed7ec2 VolumeSceneLayerSource dtor now clears the layer
Benjamin Golinvaux <bgo@osimis.io>
parents: 921
diff changeset
104 ClearLayer();
094d10ed7ec2 VolumeSceneLayerSource dtor now clears the layer
Benjamin Golinvaux <bgo@osimis.io>
parents: 921
diff changeset
105 }
815
df442f1ba0c6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
106
df442f1ba0c6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
107 void VolumeSceneLayerSource::RemoveConfigurator()
df442f1ba0c6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
108 {
df442f1ba0c6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
109 configurator_.reset();
df442f1ba0c6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
110 lastPlane_.reset();
df442f1ba0c6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
111 }
df442f1ba0c6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
112
df442f1ba0c6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
113
df442f1ba0c6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
114 void VolumeSceneLayerSource::SetConfigurator(ILayerStyleConfigurator* configurator) // Takes ownership
df442f1ba0c6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
115 {
df442f1ba0c6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
116 if (configurator == NULL)
df442f1ba0c6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
117 {
df442f1ba0c6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
118 throw Orthanc::OrthancException(Orthanc::ErrorCode_NullPointer);
df442f1ba0c6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
119 }
df442f1ba0c6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
120
df442f1ba0c6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
121 configurator_.reset(configurator);
df442f1ba0c6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
122
df442f1ba0c6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
123 // Invalidate the layer
df442f1ba0c6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
124 lastPlane_.reset(NULL);
df442f1ba0c6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
125 }
df442f1ba0c6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
126
df442f1ba0c6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
127
df442f1ba0c6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
128 ILayerStyleConfigurator& VolumeSceneLayerSource::GetConfigurator() const
df442f1ba0c6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
129 {
df442f1ba0c6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
130 if (configurator_.get() == NULL)
df442f1ba0c6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
131 {
956
a7351ad54960 Made IsContextLost automatically set the flag by checking with the emscripten
Benjamin Golinvaux <bgo@osimis.io>
parents: 934
diff changeset
132 LOG(ERROR) << "VolumeSceneLayerSource::GetConfigurator(): (configurator_.get() == NULL)";
815
df442f1ba0c6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
133 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls);
df442f1ba0c6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
134 }
df442f1ba0c6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
135
df442f1ba0c6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
136 return *configurator_;
df442f1ba0c6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
137 }
df442f1ba0c6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
138
df442f1ba0c6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
139
1345
0d6a01ffa1dd Clean version of the hack commited in
Benjamin Golinvaux <bgo@osimis.io>
parents: 1344
diff changeset
140 void VolumeSceneLayerSource::Update(const CoordinateSystem3D& plane)
815
df442f1ba0c6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
141 {
1606
874e178f34e9 - ViewportController now has weak ptr to Viewport
Benjamin Golinvaux <bgo@osimis.io>
parents: 1598
diff changeset
142 std::unique_ptr<IViewport::ILock> lock(GetViewportLock());
1685
7896aac14587 Protected against usage of dying viewport
Benjamin Golinvaux <bgo@osimis.io>
parents: 1640
diff changeset
143 if(lock)
815
df442f1ba0c6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
144 {
1685
7896aac14587 Protected against usage of dying viewport
Benjamin Golinvaux <bgo@osimis.io>
parents: 1640
diff changeset
145 ViewportController& controller = lock->GetController();
7896aac14587 Protected against usage of dying viewport
Benjamin Golinvaux <bgo@osimis.io>
parents: 1640
diff changeset
146 Scene2D& scene = controller.GetScene();
815
df442f1ba0c6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
147
1685
7896aac14587 Protected against usage of dying viewport
Benjamin Golinvaux <bgo@osimis.io>
parents: 1640
diff changeset
148 assert(slicer_.get() != NULL);
7896aac14587 Protected against usage of dying viewport
Benjamin Golinvaux <bgo@osimis.io>
parents: 1640
diff changeset
149 std::unique_ptr<IVolumeSlicer::IExtractedSlice> slice(slicer_->ExtractSlice(plane));
7896aac14587 Protected against usage of dying viewport
Benjamin Golinvaux <bgo@osimis.io>
parents: 1640
diff changeset
150
7896aac14587 Protected against usage of dying viewport
Benjamin Golinvaux <bgo@osimis.io>
parents: 1640
diff changeset
151 if (slice.get() == NULL)
815
df442f1ba0c6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
152 {
1685
7896aac14587 Protected against usage of dying viewport
Benjamin Golinvaux <bgo@osimis.io>
parents: 1640
diff changeset
153 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError);
815
df442f1ba0c6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
154 }
df442f1ba0c6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
155
1685
7896aac14587 Protected against usage of dying viewport
Benjamin Golinvaux <bgo@osimis.io>
parents: 1640
diff changeset
156 if (!slice->IsValid())
7896aac14587 Protected against usage of dying viewport
Benjamin Golinvaux <bgo@osimis.io>
parents: 1640
diff changeset
157 {
7896aac14587 Protected against usage of dying viewport
Benjamin Golinvaux <bgo@osimis.io>
parents: 1640
diff changeset
158 // The slicer cannot handle this cutting plane: Clear the layer
7896aac14587 Protected against usage of dying viewport
Benjamin Golinvaux <bgo@osimis.io>
parents: 1640
diff changeset
159 ClearLayer();
7896aac14587 Protected against usage of dying viewport
Benjamin Golinvaux <bgo@osimis.io>
parents: 1640
diff changeset
160 }
7896aac14587 Protected against usage of dying viewport
Benjamin Golinvaux <bgo@osimis.io>
parents: 1640
diff changeset
161 else if (lastPlane_.get() != NULL &&
7896aac14587 Protected against usage of dying viewport
Benjamin Golinvaux <bgo@osimis.io>
parents: 1640
diff changeset
162 IsSameCuttingPlane(*lastPlane_, plane) &&
7896aac14587 Protected against usage of dying viewport
Benjamin Golinvaux <bgo@osimis.io>
parents: 1640
diff changeset
163 lastRevision_ == slice->GetRevision())
815
df442f1ba0c6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
164 {
1685
7896aac14587 Protected against usage of dying viewport
Benjamin Golinvaux <bgo@osimis.io>
parents: 1640
diff changeset
165 // The content of the slice has not changed: Don't update the
7896aac14587 Protected against usage of dying viewport
Benjamin Golinvaux <bgo@osimis.io>
parents: 1640
diff changeset
166 // layer content, but possibly update its style
7896aac14587 Protected against usage of dying viewport
Benjamin Golinvaux <bgo@osimis.io>
parents: 1640
diff changeset
167
7896aac14587 Protected against usage of dying viewport
Benjamin Golinvaux <bgo@osimis.io>
parents: 1640
diff changeset
168 if (configurator_.get() != NULL &&
7896aac14587 Protected against usage of dying viewport
Benjamin Golinvaux <bgo@osimis.io>
parents: 1640
diff changeset
169 configurator_->GetRevision() != lastConfiguratorRevision_ &&
7896aac14587 Protected against usage of dying viewport
Benjamin Golinvaux <bgo@osimis.io>
parents: 1640
diff changeset
170 scene.HasLayer(layerDepth_))
7896aac14587 Protected against usage of dying viewport
Benjamin Golinvaux <bgo@osimis.io>
parents: 1640
diff changeset
171 {
7896aac14587 Protected against usage of dying viewport
Benjamin Golinvaux <bgo@osimis.io>
parents: 1640
diff changeset
172 configurator_->ApplyStyle(scene.GetLayer(layerDepth_));
7896aac14587 Protected against usage of dying viewport
Benjamin Golinvaux <bgo@osimis.io>
parents: 1640
diff changeset
173 }
815
df442f1ba0c6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
174 }
df442f1ba0c6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
175 else
df442f1ba0c6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
176 {
1685
7896aac14587 Protected against usage of dying viewport
Benjamin Golinvaux <bgo@osimis.io>
parents: 1640
diff changeset
177 LOG(TRACE) << "VolumeSceneLayerSource::Update -- Content has changed: An update is needed";
7896aac14587 Protected against usage of dying viewport
Benjamin Golinvaux <bgo@osimis.io>
parents: 1640
diff changeset
178 // Content has changed: An update is needed
7896aac14587 Protected against usage of dying viewport
Benjamin Golinvaux <bgo@osimis.io>
parents: 1640
diff changeset
179 lastPlane_.reset(new CoordinateSystem3D(plane));
7896aac14587 Protected against usage of dying viewport
Benjamin Golinvaux <bgo@osimis.io>
parents: 1640
diff changeset
180 lastRevision_ = slice->GetRevision();
7896aac14587 Protected against usage of dying viewport
Benjamin Golinvaux <bgo@osimis.io>
parents: 1640
diff changeset
181
7896aac14587 Protected against usage of dying viewport
Benjamin Golinvaux <bgo@osimis.io>
parents: 1640
diff changeset
182 std::unique_ptr<ISceneLayer> layer(slice->CreateSceneLayer(configurator_.get(), plane));
7896aac14587 Protected against usage of dying viewport
Benjamin Golinvaux <bgo@osimis.io>
parents: 1640
diff changeset
183 if (layer.get() == NULL)
815
df442f1ba0c6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
184 {
1685
7896aac14587 Protected against usage of dying viewport
Benjamin Golinvaux <bgo@osimis.io>
parents: 1640
diff changeset
185 LOG(TRACE) << "VolumeSceneLayerSource::Update -- (layer.get() == NULL)";
7896aac14587 Protected against usage of dying viewport
Benjamin Golinvaux <bgo@osimis.io>
parents: 1640
diff changeset
186 ClearLayer();
815
df442f1ba0c6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
187 }
1685
7896aac14587 Protected against usage of dying viewport
Benjamin Golinvaux <bgo@osimis.io>
parents: 1640
diff changeset
188 else
7896aac14587 Protected against usage of dying viewport
Benjamin Golinvaux <bgo@osimis.io>
parents: 1640
diff changeset
189 {
7896aac14587 Protected against usage of dying viewport
Benjamin Golinvaux <bgo@osimis.io>
parents: 1640
diff changeset
190 LOG(TRACE) << "VolumeSceneLayerSource::Update -- (layer.get() != NULL)";
7896aac14587 Protected against usage of dying viewport
Benjamin Golinvaux <bgo@osimis.io>
parents: 1640
diff changeset
191 if (configurator_.get() != NULL)
7896aac14587 Protected against usage of dying viewport
Benjamin Golinvaux <bgo@osimis.io>
parents: 1640
diff changeset
192 {
7896aac14587 Protected against usage of dying viewport
Benjamin Golinvaux <bgo@osimis.io>
parents: 1640
diff changeset
193 lastConfiguratorRevision_ = configurator_->GetRevision();
7896aac14587 Protected against usage of dying viewport
Benjamin Golinvaux <bgo@osimis.io>
parents: 1640
diff changeset
194 configurator_->ApplyStyle(*layer);
7896aac14587 Protected against usage of dying viewport
Benjamin Golinvaux <bgo@osimis.io>
parents: 1640
diff changeset
195 }
815
df442f1ba0c6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
196
1685
7896aac14587 Protected against usage of dying viewport
Benjamin Golinvaux <bgo@osimis.io>
parents: 1640
diff changeset
197 scene.SetLayer(layerDepth_, layer.release());
7896aac14587 Protected against usage of dying viewport
Benjamin Golinvaux <bgo@osimis.io>
parents: 1640
diff changeset
198 }
815
df442f1ba0c6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
199 }
df442f1ba0c6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
200 }
df442f1ba0c6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
201 }
df442f1ba0c6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
202 }