Mercurial > hg > orthanc-stone
annotate OrthancStone/Sources/Volumes/VolumeSceneLayerSource.cpp @ 1609:5f5c549499ff
new class MacroSceneLayer
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 29 Oct 2020 17:01:29 +0100 |
parents | 646e581e115b |
children | 52b8b96cb55f |
rev | line source |
---|---|
815 | 1 /** |
2 * Stone of Orthanc | |
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics | |
4 * Department, University Hospital of Liege, Belgium | |
1270
2d8ab34c8c91
upgrade to year 2020
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
956
diff
changeset
|
5 * Copyright (C) 2017-2020 Osimis S.A., Belgium |
815 | 6 * |
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 | 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 | |
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 | 20 **/ |
21 | |
22 | |
23 #include "VolumeSceneLayerSource.h" | |
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 | 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 | 31 |
32 namespace OrthancStone | |
33 { | |
34 static bool IsSameCuttingPlane(const CoordinateSystem3D& a, | |
35 const CoordinateSystem3D& b) | |
36 { | |
37 // TODO - What if the normal is reversed? | |
38 double distance; | |
39 return (CoordinateSystem3D::ComputeDistance(distance, a, b) && | |
40 LinearAlgebra::IsCloseToZero(distance)); | |
41 } | |
42 | |
43 void VolumeSceneLayerSource::ClearLayer() | |
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()); |
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
|
47 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
|
48 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
|
49 scene.DeleteLayer(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
|
50 } |
815 | 51 lastPlane_.reset(NULL); |
52 } | |
53 | |
1606
874e178f34e9
- ViewportController now has weak ptr to Viewport
Benjamin Golinvaux <bgo@osimis.io>
parents:
1598
diff
changeset
|
54 IViewport::ILock* VolumeSceneLayerSource::GetViewportLock() |
874e178f34e9
- ViewportController now has weak ptr to Viewport
Benjamin Golinvaux <bgo@osimis.io>
parents:
1598
diff
changeset
|
55 { |
874e178f34e9
- ViewportController now has weak ptr to Viewport
Benjamin Golinvaux <bgo@osimis.io>
parents:
1598
diff
changeset
|
56 boost::shared_ptr<IViewport> viewport = viewport_.lock(); |
874e178f34e9
- ViewportController now has weak ptr to Viewport
Benjamin Golinvaux <bgo@osimis.io>
parents:
1598
diff
changeset
|
57 if (viewport) |
874e178f34e9
- ViewportController now has weak ptr to Viewport
Benjamin Golinvaux <bgo@osimis.io>
parents:
1598
diff
changeset
|
58 return viewport->Lock(); |
874e178f34e9
- ViewportController now has weak ptr to Viewport
Benjamin Golinvaux <bgo@osimis.io>
parents:
1598
diff
changeset
|
59 else |
1608
646e581e115b
replacing nullptr by NULL for VS2008 compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1606
diff
changeset
|
60 return NULL; |
1606
874e178f34e9
- ViewportController now has weak ptr to Viewport
Benjamin Golinvaux <bgo@osimis.io>
parents:
1598
diff
changeset
|
61 } |
874e178f34e9
- ViewportController now has weak ptr to Viewport
Benjamin Golinvaux <bgo@osimis.io>
parents:
1598
diff
changeset
|
62 |
874e178f34e9
- ViewportController now has weak ptr to Viewport
Benjamin Golinvaux <bgo@osimis.io>
parents:
1598
diff
changeset
|
63 IViewport::ILock* VolumeSceneLayerSource::GetViewportLock() const |
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 boost::shared_ptr<IViewport> viewport = viewport_.lock(); |
874e178f34e9
- ViewportController now has weak ptr to Viewport
Benjamin Golinvaux <bgo@osimis.io>
parents:
1598
diff
changeset
|
66 if (viewport) |
874e178f34e9
- ViewportController now has weak ptr to Viewport
Benjamin Golinvaux <bgo@osimis.io>
parents:
1598
diff
changeset
|
67 return viewport->Lock(); |
874e178f34e9
- ViewportController now has weak ptr to Viewport
Benjamin Golinvaux <bgo@osimis.io>
parents:
1598
diff
changeset
|
68 else |
1608
646e581e115b
replacing nullptr by NULL for VS2008 compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1606
diff
changeset
|
69 return NULL; |
1606
874e178f34e9
- ViewportController now has weak ptr to Viewport
Benjamin Golinvaux <bgo@osimis.io>
parents:
1598
diff
changeset
|
70 } |
874e178f34e9
- ViewportController now has weak ptr to Viewport
Benjamin Golinvaux <bgo@osimis.io>
parents:
1598
diff
changeset
|
71 |
874e178f34e9
- ViewportController now has weak ptr to Viewport
Benjamin Golinvaux <bgo@osimis.io>
parents:
1598
diff
changeset
|
72 |
1322
0da659f8579c
Object reference 1st commit + indent change
Benjamin Golinvaux <bgo@osimis.io>
parents:
1298
diff
changeset
|
73 VolumeSceneLayerSource::VolumeSceneLayerSource( |
1606
874e178f34e9
- ViewportController now has weak ptr to Viewport
Benjamin Golinvaux <bgo@osimis.io>
parents:
1598
diff
changeset
|
74 boost::weak_ptr<OrthancStone::IViewport> viewport, |
1322
0da659f8579c
Object reference 1st commit + indent change
Benjamin Golinvaux <bgo@osimis.io>
parents:
1298
diff
changeset
|
75 int layerDepth, |
1571 | 76 const boost::shared_ptr<IVolumeSlicer>& slicer) : |
77 viewport_(viewport), | |
78 layerDepth_(layerDepth), | |
79 slicer_(slicer), | |
80 lastRevision_(0), | |
81 lastConfiguratorRevision_(0) | |
815 | 82 { |
83 if (slicer == NULL) | |
84 { | |
85 throw Orthanc::OrthancException(Orthanc::ErrorCode_NullPointer); | |
86 } | |
1324
4d8d642f7036
Added a NullLayer scene layer type that allows
Benjamin Golinvaux <bgo@osimis.io>
parents:
1322
diff
changeset
|
87 |
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
|
88 { |
1606
874e178f34e9
- ViewportController now has weak ptr to Viewport
Benjamin Golinvaux <bgo@osimis.io>
parents:
1598
diff
changeset
|
89 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
|
90 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
|
91 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
|
92 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
|
93 |
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 // 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
|
95 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
|
96 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
|
97 } |
815 | 98 } |
99 | |
934
094d10ed7ec2
VolumeSceneLayerSource dtor now clears the layer
Benjamin Golinvaux <bgo@osimis.io>
parents:
921
diff
changeset
|
100 VolumeSceneLayerSource::~VolumeSceneLayerSource() |
094d10ed7ec2
VolumeSceneLayerSource dtor now clears the layer
Benjamin Golinvaux <bgo@osimis.io>
parents:
921
diff
changeset
|
101 { |
094d10ed7ec2
VolumeSceneLayerSource dtor now clears the layer
Benjamin Golinvaux <bgo@osimis.io>
parents:
921
diff
changeset
|
102 ClearLayer(); |
094d10ed7ec2
VolumeSceneLayerSource dtor now clears the layer
Benjamin Golinvaux <bgo@osimis.io>
parents:
921
diff
changeset
|
103 } |
815 | 104 |
105 void VolumeSceneLayerSource::RemoveConfigurator() | |
106 { | |
107 configurator_.reset(); | |
108 lastPlane_.reset(); | |
109 } | |
110 | |
111 | |
112 void VolumeSceneLayerSource::SetConfigurator(ILayerStyleConfigurator* configurator) // Takes ownership | |
113 { | |
114 if (configurator == NULL) | |
115 { | |
116 throw Orthanc::OrthancException(Orthanc::ErrorCode_NullPointer); | |
117 } | |
118 | |
119 configurator_.reset(configurator); | |
120 | |
121 // Invalidate the layer | |
122 lastPlane_.reset(NULL); | |
123 } | |
124 | |
125 | |
126 ILayerStyleConfigurator& VolumeSceneLayerSource::GetConfigurator() const | |
127 { | |
128 if (configurator_.get() == NULL) | |
129 { | |
956
a7351ad54960
Made IsContextLost automatically set the flag by checking with the emscripten
Benjamin Golinvaux <bgo@osimis.io>
parents:
934
diff
changeset
|
130 LOG(ERROR) << "VolumeSceneLayerSource::GetConfigurator(): (configurator_.get() == NULL)"; |
815 | 131 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); |
132 } | |
133 | |
134 return *configurator_; | |
135 } | |
136 | |
137 | |
1345
0d6a01ffa1dd
Clean version of the hack commited in
Benjamin Golinvaux <bgo@osimis.io>
parents:
1344
diff
changeset
|
138 void VolumeSceneLayerSource::Update(const CoordinateSystem3D& plane) |
815 | 139 { |
1606
874e178f34e9
- ViewportController now has weak ptr to Viewport
Benjamin Golinvaux <bgo@osimis.io>
parents:
1598
diff
changeset
|
140 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
|
141 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
|
142 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
|
143 |
815 | 144 assert(slicer_.get() != NULL); |
1298
8a0a62189f46
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1270
diff
changeset
|
145 std::unique_ptr<IVolumeSlicer::IExtractedSlice> slice(slicer_->ExtractSlice(plane)); |
815 | 146 |
147 if (slice.get() == NULL) | |
148 { | |
149 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); | |
150 } | |
151 | |
152 if (!slice->IsValid()) | |
153 { | |
154 // The slicer cannot handle this cutting plane: Clear the layer | |
155 ClearLayer(); | |
156 } | |
1345
0d6a01ffa1dd
Clean version of the hack commited in
Benjamin Golinvaux <bgo@osimis.io>
parents:
1344
diff
changeset
|
157 else if (lastPlane_.get() != NULL && |
815 | 158 IsSameCuttingPlane(*lastPlane_, plane) && |
159 lastRevision_ == slice->GetRevision()) | |
160 { | |
161 // The content of the slice has not changed: Don't update the | |
162 // layer content, but possibly update its style | |
163 | |
164 if (configurator_.get() != NULL && | |
165 configurator_->GetRevision() != lastConfiguratorRevision_ && | |
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
|
166 scene.HasLayer(layerDepth_)) |
815 | 167 { |
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
|
168 configurator_->ApplyStyle(scene.GetLayer(layerDepth_)); |
815 | 169 } |
170 } | |
171 else | |
172 { | |
921
81d30cd93b65
Ability to ask the loader for the geometry in PULL mode (when subscribing to the messages is not possible) + small changes (removed const/ref qualifiers for boost::shared_ptr param, added traces, doc change)
Benjamin Golinvaux <bgo@osimis.io>
parents:
815
diff
changeset
|
173 LOG(TRACE) << "VolumeSceneLayerSource::Update -- Content has changed: An update is needed"; |
815 | 174 // Content has changed: An update is needed |
175 lastPlane_.reset(new CoordinateSystem3D(plane)); | |
176 lastRevision_ = slice->GetRevision(); | |
177 | |
1298
8a0a62189f46
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1270
diff
changeset
|
178 std::unique_ptr<ISceneLayer> layer(slice->CreateSceneLayer(configurator_.get(), plane)); |
815 | 179 if (layer.get() == NULL) |
180 { | |
921
81d30cd93b65
Ability to ask the loader for the geometry in PULL mode (when subscribing to the messages is not possible) + small changes (removed const/ref qualifiers for boost::shared_ptr param, added traces, doc change)
Benjamin Golinvaux <bgo@osimis.io>
parents:
815
diff
changeset
|
181 LOG(TRACE) << "VolumeSceneLayerSource::Update -- (layer.get() == NULL)"; |
815 | 182 ClearLayer(); |
183 } | |
184 else | |
185 { | |
921
81d30cd93b65
Ability to ask the loader for the geometry in PULL mode (when subscribing to the messages is not possible) + small changes (removed const/ref qualifiers for boost::shared_ptr param, added traces, doc change)
Benjamin Golinvaux <bgo@osimis.io>
parents:
815
diff
changeset
|
186 LOG(TRACE) << "VolumeSceneLayerSource::Update -- (layer.get() != NULL)"; |
815 | 187 if (configurator_.get() != NULL) |
188 { | |
189 lastConfiguratorRevision_ = configurator_->GetRevision(); | |
190 configurator_->ApplyStyle(*layer); | |
191 } | |
192 | |
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
|
193 scene.SetLayer(layerDepth_, layer.release()); |
815 | 194 } |
195 } | |
196 } | |
197 } |