Mercurial > hg > orthanc-stone
annotate OrthancStone/Sources/Volumes/VolumeSceneLayerSource.cpp @ 1571:85e117739eca
cppcheck
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Mon, 21 Sep 2020 17:46:39 +0200 |
parents | 314b6dc507d9 |
children | 4fb8fdf03314 |
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 | |
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 | |
1324
4d8d642f7036
Added a NullLayer scene layer type that allows
Benjamin Golinvaux <bgo@osimis.io>
parents:
1322
diff
changeset
|
24 #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
|
25 #include "../Viewport/IViewport.h" |
1324
4d8d642f7036
Added a NullLayer scene layer type that allows
Benjamin Golinvaux <bgo@osimis.io>
parents:
1322
diff
changeset
|
26 #include "../StoneException.h" |
1558 | 27 #include "../Scene2DViewport/ViewportController.h" |
1324
4d8d642f7036
Added a NullLayer scene layer type that allows
Benjamin Golinvaux <bgo@osimis.io>
parents:
1322
diff
changeset
|
28 |
1455
30deba7bc8e2
simplifying include_directories
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1433
diff
changeset
|
29 #include <OrthancException.h> |
815 | 30 |
31 namespace OrthancStone | |
32 { | |
33 static bool IsSameCuttingPlane(const CoordinateSystem3D& a, | |
34 const CoordinateSystem3D& b) | |
35 { | |
36 // TODO - What if the normal is reversed? | |
37 double distance; | |
38 return (CoordinateSystem3D::ComputeDistance(distance, a, b) && | |
39 LinearAlgebra::IsCloseToZero(distance)); | |
40 } | |
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 { |
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
|
46 std::unique_ptr<IViewport::ILock> lock(viewport_->Lock()); |
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 | |
1322
0da659f8579c
Object reference 1st commit + indent change
Benjamin Golinvaux <bgo@osimis.io>
parents:
1298
diff
changeset
|
54 VolumeSceneLayerSource::VolumeSceneLayerSource( |
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
|
55 boost::shared_ptr<OrthancStone::IViewport> viewport, |
1322
0da659f8579c
Object reference 1st commit + indent change
Benjamin Golinvaux <bgo@osimis.io>
parents:
1298
diff
changeset
|
56 int layerDepth, |
1571 | 57 const boost::shared_ptr<IVolumeSlicer>& slicer) : |
58 viewport_(viewport), | |
59 layerDepth_(layerDepth), | |
60 slicer_(slicer), | |
61 lastRevision_(0), | |
62 lastConfiguratorRevision_(0) | |
815 | 63 { |
64 if (slicer == NULL) | |
65 { | |
66 throw Orthanc::OrthancException(Orthanc::ErrorCode_NullPointer); | |
67 } | |
1324
4d8d642f7036
Added a NullLayer scene layer type that allows
Benjamin Golinvaux <bgo@osimis.io>
parents:
1322
diff
changeset
|
68 |
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
|
69 { |
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
|
70 std::unique_ptr<IViewport::ILock> lock(viewport_->Lock()); |
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
|
71 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
|
72 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
|
73 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
|
74 |
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
|
75 // 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
|
76 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
|
77 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
|
78 } |
815 | 79 } |
80 | |
934
094d10ed7ec2
VolumeSceneLayerSource dtor now clears the layer
Benjamin Golinvaux <bgo@osimis.io>
parents:
921
diff
changeset
|
81 VolumeSceneLayerSource::~VolumeSceneLayerSource() |
094d10ed7ec2
VolumeSceneLayerSource dtor now clears the layer
Benjamin Golinvaux <bgo@osimis.io>
parents:
921
diff
changeset
|
82 { |
094d10ed7ec2
VolumeSceneLayerSource dtor now clears the layer
Benjamin Golinvaux <bgo@osimis.io>
parents:
921
diff
changeset
|
83 ClearLayer(); |
094d10ed7ec2
VolumeSceneLayerSource dtor now clears the layer
Benjamin Golinvaux <bgo@osimis.io>
parents:
921
diff
changeset
|
84 } |
815 | 85 |
86 void VolumeSceneLayerSource::RemoveConfigurator() | |
87 { | |
88 configurator_.reset(); | |
89 lastPlane_.reset(); | |
90 } | |
91 | |
92 | |
93 void VolumeSceneLayerSource::SetConfigurator(ILayerStyleConfigurator* configurator) // Takes ownership | |
94 { | |
95 if (configurator == NULL) | |
96 { | |
97 throw Orthanc::OrthancException(Orthanc::ErrorCode_NullPointer); | |
98 } | |
99 | |
100 configurator_.reset(configurator); | |
101 | |
102 // Invalidate the layer | |
103 lastPlane_.reset(NULL); | |
104 } | |
105 | |
106 | |
107 ILayerStyleConfigurator& VolumeSceneLayerSource::GetConfigurator() const | |
108 { | |
109 if (configurator_.get() == NULL) | |
110 { | |
956
a7351ad54960
Made IsContextLost automatically set the flag by checking with the emscripten
Benjamin Golinvaux <bgo@osimis.io>
parents:
934
diff
changeset
|
111 LOG(ERROR) << "VolumeSceneLayerSource::GetConfigurator(): (configurator_.get() == NULL)"; |
815 | 112 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); |
113 } | |
114 | |
115 return *configurator_; | |
116 } | |
117 | |
118 | |
1345
0d6a01ffa1dd
Clean version of the hack commited in
Benjamin Golinvaux <bgo@osimis.io>
parents:
1344
diff
changeset
|
119 void VolumeSceneLayerSource::Update(const CoordinateSystem3D& plane) |
815 | 120 { |
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
|
121 std::unique_ptr<IViewport::ILock> lock(viewport_->Lock()); |
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
|
122 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
|
123 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
|
124 |
815 | 125 assert(slicer_.get() != NULL); |
1298
8a0a62189f46
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1270
diff
changeset
|
126 std::unique_ptr<IVolumeSlicer::IExtractedSlice> slice(slicer_->ExtractSlice(plane)); |
815 | 127 |
128 if (slice.get() == NULL) | |
129 { | |
130 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); | |
131 } | |
132 | |
133 if (!slice->IsValid()) | |
134 { | |
135 // The slicer cannot handle this cutting plane: Clear the layer | |
136 ClearLayer(); | |
137 } | |
1345
0d6a01ffa1dd
Clean version of the hack commited in
Benjamin Golinvaux <bgo@osimis.io>
parents:
1344
diff
changeset
|
138 else if (lastPlane_.get() != NULL && |
815 | 139 IsSameCuttingPlane(*lastPlane_, plane) && |
140 lastRevision_ == slice->GetRevision()) | |
141 { | |
142 // The content of the slice has not changed: Don't update the | |
143 // layer content, but possibly update its style | |
144 | |
145 if (configurator_.get() != NULL && | |
146 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
|
147 scene.HasLayer(layerDepth_)) |
815 | 148 { |
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
|
149 configurator_->ApplyStyle(scene.GetLayer(layerDepth_)); |
815 | 150 } |
151 } | |
152 else | |
153 { | |
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
|
154 LOG(TRACE) << "VolumeSceneLayerSource::Update -- Content has changed: An update is needed"; |
815 | 155 // Content has changed: An update is needed |
156 lastPlane_.reset(new CoordinateSystem3D(plane)); | |
157 lastRevision_ = slice->GetRevision(); | |
158 | |
1298
8a0a62189f46
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1270
diff
changeset
|
159 std::unique_ptr<ISceneLayer> layer(slice->CreateSceneLayer(configurator_.get(), plane)); |
815 | 160 if (layer.get() == NULL) |
161 { | |
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
|
162 LOG(TRACE) << "VolumeSceneLayerSource::Update -- (layer.get() == NULL)"; |
815 | 163 ClearLayer(); |
164 } | |
165 else | |
166 { | |
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
|
167 LOG(TRACE) << "VolumeSceneLayerSource::Update -- (layer.get() != NULL)"; |
815 | 168 if (configurator_.get() != NULL) |
169 { | |
170 lastConfiguratorRevision_ = configurator_->GetRevision(); | |
171 configurator_->ApplyStyle(*layer); | |
172 } | |
173 | |
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
|
174 scene.SetLayer(layerDepth_, layer.release()); |
815 | 175 } |
176 } | |
177 } | |
178 } |