annotate Framework/Widgets/LayerWidget.cpp @ 284:38b0ac8055b9 am-2

Qt: catch and forward keyboard events
author am@osimis.io
date Tue, 28 Aug 2018 11:09:37 +0200
parents 8a86695fcbc3
children 3897f9f28cfa
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
66
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 /**
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2 * Stone of Orthanc
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
4 * Department, University Hospital of Liege, Belgium
135
e2fe9352f240 upgrade to year 2018
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
5 * Copyright (C) 2017-2018 Osimis S.A., Belgium
66
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
6 *
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 * This program is free software: you can redistribute it and/or
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 * modify it under the terms of the GNU Affero General Public License
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 * as published by the Free Software Foundation, either version 3 of
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 * the License, or (at your option) any later version.
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 *
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 * This program is distributed in the hope that it will be useful, but
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 * Affero General Public License for more details.
251
192e6e349e69 first usage of new message system (in SDL only)
am@osimis.io
parents: 219
diff changeset
16 *
66
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
17 * You should have received a copy of the GNU Affero General Public License
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
19 **/
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22 #include "LayerWidget.h"
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23
99
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 97
diff changeset
24 #include "../Layers/SliceOutlineRenderer.h"
159
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 135
diff changeset
25 #include "../Toolbox/GeometryToolbox.h"
85
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 83
diff changeset
26
212
5412adf19980 resort to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 201
diff changeset
27 #include <Core/Logging.h>
113
2eca030792aa using the Orthanc Framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 111
diff changeset
28
85
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 83
diff changeset
29 static const double THIN_SLICE_THICKNESS = 100.0 * std::numeric_limits<double>::epsilon();
66
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31 namespace OrthancStone
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32 {
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
33 class LayerWidget::Scene : public boost::noncopyable
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34 {
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35 private:
110
53025eecbc95 renamed SliceGeometry as CoordinateSystem3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 109
diff changeset
36 CoordinateSystem3D slice_;
121
e66b2c757790 displaying rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 119
diff changeset
37 double thickness_;
66
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
38 size_t countMissing_;
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
39 std::vector<ILayerRenderer*> renderers_;
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
40
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
41 void DeleteLayer(size_t index)
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
42 {
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
43 if (index >= renderers_.size())
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
44 {
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
45 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange);
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
46 }
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
47
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
48 assert(countMissing_ <= renderers_.size());
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
49
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
50 if (renderers_[index] != NULL)
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
51 {
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
52 assert(countMissing_ < renderers_.size());
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
53 delete renderers_[index];
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
54 renderers_[index] = NULL;
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
55 countMissing_++;
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
56 }
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
57 }
251
192e6e349e69 first usage of new message system (in SDL only)
am@osimis.io
parents: 219
diff changeset
58
66
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
59 public:
110
53025eecbc95 renamed SliceGeometry as CoordinateSystem3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 109
diff changeset
60 Scene(const CoordinateSystem3D& slice,
121
e66b2c757790 displaying rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 119
diff changeset
61 double thickness,
66
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
62 size_t countLayers) :
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
63 slice_(slice),
121
e66b2c757790 displaying rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 119
diff changeset
64 thickness_(thickness),
66
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
65 countMissing_(countLayers),
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
66 renderers_(countLayers, NULL)
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
67 {
121
e66b2c757790 displaying rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 119
diff changeset
68 if (thickness <= 0)
e66b2c757790 displaying rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 119
diff changeset
69 {
e66b2c757790 displaying rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 119
diff changeset
70 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange);
e66b2c757790 displaying rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 119
diff changeset
71 }
66
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
72 }
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
73
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
74 ~Scene()
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
75 {
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
76 for (size_t i = 0; i < renderers_.size(); i++)
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
77 {
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
78 DeleteLayer(i);
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
79 }
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
80 }
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
81
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
82 void SetLayer(size_t index,
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
83 ILayerRenderer* renderer) // Takes ownership
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
84 {
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
85 if (renderer == NULL)
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
86 {
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
87 throw Orthanc::OrthancException(Orthanc::ErrorCode_NullPointer);
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
88 }
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
89
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
90 DeleteLayer(index);
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
91
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
92 renderers_[index] = renderer;
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
93 countMissing_--;
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
94 }
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
95
110
53025eecbc95 renamed SliceGeometry as CoordinateSystem3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 109
diff changeset
96 const CoordinateSystem3D& GetSlice() const
66
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
97 {
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
98 return slice_;
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
99 }
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
100
93
5945e81734a3 decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 92
diff changeset
101 bool HasRenderer(size_t index)
5945e81734a3 decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 92
diff changeset
102 {
5945e81734a3 decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 92
diff changeset
103 return renderers_[index] != NULL;
5945e81734a3 decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 92
diff changeset
104 }
5945e81734a3 decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 92
diff changeset
105
66
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
106 bool IsComplete() const
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
107 {
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
108 return countMissing_ == 0;
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
109 }
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
110
89
f244018a4e4b BUGGY- trying to remove IVolumeSlicesObserver
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 87
diff changeset
111 unsigned int GetCountMissing() const
f244018a4e4b BUGGY- trying to remove IVolumeSlicesObserver
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 87
diff changeset
112 {
f244018a4e4b BUGGY- trying to remove IVolumeSlicesObserver
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 87
diff changeset
113 return countMissing_;
f244018a4e4b BUGGY- trying to remove IVolumeSlicesObserver
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 87
diff changeset
114 }
f244018a4e4b BUGGY- trying to remove IVolumeSlicesObserver
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 87
diff changeset
115
66
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
116 bool RenderScene(CairoContext& context,
97
d18dcc963930 separation of the renderers vs. viewport slice
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 96
diff changeset
117 const ViewportGeometry& view,
110
53025eecbc95 renamed SliceGeometry as CoordinateSystem3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 109
diff changeset
118 const CoordinateSystem3D& viewportSlice)
66
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
119 {
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
120 bool fullQuality = true;
97
d18dcc963930 separation of the renderers vs. viewport slice
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 96
diff changeset
121 cairo_t *cr = context.GetObject();
66
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
122
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
123 for (size_t i = 0; i < renderers_.size(); i++)
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
124 {
97
d18dcc963930 separation of the renderers vs. viewport slice
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 96
diff changeset
125 if (renderers_[i] != NULL)
66
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
126 {
110
53025eecbc95 renamed SliceGeometry as CoordinateSystem3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 109
diff changeset
127 const CoordinateSystem3D& frameSlice = renderers_[i]->GetLayerSlice();
97
d18dcc963930 separation of the renderers vs. viewport slice
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 96
diff changeset
128
d18dcc963930 separation of the renderers vs. viewport slice
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 96
diff changeset
129 double x0, y0, x1, y1, x2, y2;
d18dcc963930 separation of the renderers vs. viewport slice
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 96
diff changeset
130 viewportSlice.ProjectPoint(x0, y0, frameSlice.GetOrigin());
d18dcc963930 separation of the renderers vs. viewport slice
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 96
diff changeset
131 viewportSlice.ProjectPoint(x1, y1, frameSlice.GetOrigin() + frameSlice.GetAxisX());
d18dcc963930 separation of the renderers vs. viewport slice
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 96
diff changeset
132 viewportSlice.ProjectPoint(x2, y2, frameSlice.GetOrigin() + frameSlice.GetAxisY());
d18dcc963930 separation of the renderers vs. viewport slice
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 96
diff changeset
133
d18dcc963930 separation of the renderers vs. viewport slice
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 96
diff changeset
134 /**
d18dcc963930 separation of the renderers vs. viewport slice
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 96
diff changeset
135 * Now we solve the system of linear equations Ax + b = x', given:
d18dcc963930 separation of the renderers vs. viewport slice
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 96
diff changeset
136 * A [0 ; 0] + b = [x0 ; y0]
d18dcc963930 separation of the renderers vs. viewport slice
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 96
diff changeset
137 * A [1 ; 0] + b = [x1 ; y1]
d18dcc963930 separation of the renderers vs. viewport slice
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 96
diff changeset
138 * A [0 ; 1] + b = [x2 ; y2]
d18dcc963930 separation of the renderers vs. viewport slice
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 96
diff changeset
139 * <=>
d18dcc963930 separation of the renderers vs. viewport slice
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 96
diff changeset
140 * b = [x0 ; y0]
d18dcc963930 separation of the renderers vs. viewport slice
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 96
diff changeset
141 * A [1 ; 0] = [x1 ; y1] - b = [x1 - x0 ; y1 - y0]
d18dcc963930 separation of the renderers vs. viewport slice
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 96
diff changeset
142 * A [0 ; 1] = [x2 ; y2] - b = [x2 - x0 ; y2 - y0]
d18dcc963930 separation of the renderers vs. viewport slice
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 96
diff changeset
143 * <=>
d18dcc963930 separation of the renderers vs. viewport slice
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 96
diff changeset
144 * b = [x0 ; y0]
d18dcc963930 separation of the renderers vs. viewport slice
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 96
diff changeset
145 * [a11 ; a21] = [x1 - x0 ; y1 - y0]
d18dcc963930 separation of the renderers vs. viewport slice
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 96
diff changeset
146 * [a12 ; a22] = [x2 - x0 ; y2 - y0]
d18dcc963930 separation of the renderers vs. viewport slice
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 96
diff changeset
147 **/
d18dcc963930 separation of the renderers vs. viewport slice
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 96
diff changeset
148
d18dcc963930 separation of the renderers vs. viewport slice
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 96
diff changeset
149 cairo_matrix_t transform;
d18dcc963930 separation of the renderers vs. viewport slice
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 96
diff changeset
150 cairo_matrix_init(&transform, x1 - x0, y1 - y0, x2 - x0, y2 - y0, x0, y0);
d18dcc963930 separation of the renderers vs. viewport slice
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 96
diff changeset
151
d18dcc963930 separation of the renderers vs. viewport slice
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 96
diff changeset
152 cairo_save(cr);
d18dcc963930 separation of the renderers vs. viewport slice
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 96
diff changeset
153 cairo_transform(cr, &transform);
d18dcc963930 separation of the renderers vs. viewport slice
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 96
diff changeset
154
d18dcc963930 separation of the renderers vs. viewport slice
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 96
diff changeset
155 if (!renderers_[i]->RenderLayer(context, view))
d18dcc963930 separation of the renderers vs. viewport slice
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 96
diff changeset
156 {
d18dcc963930 separation of the renderers vs. viewport slice
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 96
diff changeset
157 cairo_restore(cr);
d18dcc963930 separation of the renderers vs. viewport slice
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 96
diff changeset
158 return false;
d18dcc963930 separation of the renderers vs. viewport slice
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 96
diff changeset
159 }
d18dcc963930 separation of the renderers vs. viewport slice
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 96
diff changeset
160
d18dcc963930 separation of the renderers vs. viewport slice
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 96
diff changeset
161 cairo_restore(cr);
66
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
162 }
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
163
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
164 if (renderers_[i] != NULL &&
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
165 !renderers_[i]->IsFullQuality())
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
166 {
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
167 fullQuality = false;
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
168 }
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
169 }
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
170
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
171 if (!fullQuality)
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
172 {
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
173 double x, y;
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
174 view.MapDisplayToScene(x, y, static_cast<double>(view.GetDisplayWidth()) / 2.0, 10);
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
175
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
176 cairo_translate(cr, x, y);
95
f47349f4815c fix for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 93
diff changeset
177
f47349f4815c fix for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 93
diff changeset
178 #if 1
f47349f4815c fix for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 93
diff changeset
179 double s = 5.0 / view.GetZoom();
f47349f4815c fix for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 93
diff changeset
180 cairo_rectangle(cr, -s, -s, 2.0 * s, 2.0 * s);
f47349f4815c fix for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 93
diff changeset
181 #else
f47349f4815c fix for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 93
diff changeset
182 // TODO Drawing circles makes WebAssembly crash!
66
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
183 cairo_arc(cr, 0, 0, 5.0 / view.GetZoom(), 0, 2 * M_PI);
95
f47349f4815c fix for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 93
diff changeset
184 #endif
f47349f4815c fix for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 93
diff changeset
185
66
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
186 cairo_set_line_width(cr, 2.0 / view.GetZoom());
251
192e6e349e69 first usage of new message system (in SDL only)
am@osimis.io
parents: 219
diff changeset
187 cairo_set_source_rgb(cr, 1, 1, 1);
66
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
188 cairo_stroke_preserve(cr);
95
f47349f4815c fix for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 93
diff changeset
189 cairo_set_source_rgb(cr, 1, 0, 0);
66
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
190 cairo_fill(cr);
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
191 }
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
192
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
193 return true;
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
194 }
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
195
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
196 void SetLayerStyle(size_t index,
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
197 const RenderStyle& style)
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
198 {
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
199 if (renderers_[index] != NULL)
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
200 {
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
201 renderers_[index]->SetLayerStyle(style);
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
202 }
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
203 }
121
e66b2c757790 displaying rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 119
diff changeset
204
e66b2c757790 displaying rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 119
diff changeset
205 bool ContainsPlane(const CoordinateSystem3D& slice) const
e66b2c757790 displaying rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 119
diff changeset
206 {
e66b2c757790 displaying rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 119
diff changeset
207 bool isOpposite;
e66b2c757790 displaying rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 119
diff changeset
208 if (!GeometryToolbox::IsParallelOrOpposite(isOpposite,
e66b2c757790 displaying rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 119
diff changeset
209 slice.GetNormal(),
e66b2c757790 displaying rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 119
diff changeset
210 slice_.GetNormal()))
e66b2c757790 displaying rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 119
diff changeset
211 {
e66b2c757790 displaying rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 119
diff changeset
212 return false;
e66b2c757790 displaying rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 119
diff changeset
213 }
e66b2c757790 displaying rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 119
diff changeset
214 else
e66b2c757790 displaying rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 119
diff changeset
215 {
e66b2c757790 displaying rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 119
diff changeset
216 double z = (slice_.ProjectAlongNormal(slice.GetOrigin()) -
e66b2c757790 displaying rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 119
diff changeset
217 slice_.ProjectAlongNormal(slice_.GetOrigin()));
251
192e6e349e69 first usage of new message system (in SDL only)
am@osimis.io
parents: 219
diff changeset
218
121
e66b2c757790 displaying rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 119
diff changeset
219 if (z < 0)
e66b2c757790 displaying rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 119
diff changeset
220 {
e66b2c757790 displaying rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 119
diff changeset
221 z = -z;
e66b2c757790 displaying rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 119
diff changeset
222 }
e66b2c757790 displaying rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 119
diff changeset
223
e66b2c757790 displaying rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 119
diff changeset
224 return z <= thickness_;
e66b2c757790 displaying rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 119
diff changeset
225 }
e66b2c757790 displaying rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 119
diff changeset
226 }
e66b2c757790 displaying rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 119
diff changeset
227
e66b2c757790 displaying rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 119
diff changeset
228 double GetThickness() const
e66b2c757790 displaying rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 119
diff changeset
229 {
e66b2c757790 displaying rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 119
diff changeset
230 return thickness_;
e66b2c757790 displaying rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 119
diff changeset
231 }
66
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
232 };
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
233
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
234
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
235 bool LayerWidget::LookupLayer(size_t& index /* out */,
87
4a541cd4fa83 OrthancVolumeImageLoader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 86
diff changeset
236 const ILayerSource& layer) const
66
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
237 {
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
238 LayersIndex::const_iterator found = layersIndex_.find(&layer);
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
239
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
240 if (found == layersIndex_.end())
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
241 {
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
242 return false;
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
243 }
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
244 else
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
245 {
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
246 index = found->second;
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
247 assert(index < layers_.size() &&
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
248 layers_[index] == &layer);
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
249 return true;
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
250 }
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
251 }
251
192e6e349e69 first usage of new message system (in SDL only)
am@osimis.io
parents: 219
diff changeset
252
85
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 83
diff changeset
253
111
7665ccbf33db rename Extent as Extent2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 110
diff changeset
254 void LayerWidget::GetLayerExtent(Extent2D& extent,
97
d18dcc963930 separation of the renderers vs. viewport slice
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 96
diff changeset
255 ILayerSource& source) const
85
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 83
diff changeset
256 {
97
d18dcc963930 separation of the renderers vs. viewport slice
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 96
diff changeset
257 extent.Reset();
d18dcc963930 separation of the renderers vs. viewport slice
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 96
diff changeset
258
d18dcc963930 separation of the renderers vs. viewport slice
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 96
diff changeset
259 std::vector<Vector> points;
d18dcc963930 separation of the renderers vs. viewport slice
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 96
diff changeset
260 if (source.GetExtent(points, slice_))
85
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 83
diff changeset
261 {
97
d18dcc963930 separation of the renderers vs. viewport slice
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 96
diff changeset
262 for (size_t i = 0; i < points.size(); i++)
85
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 83
diff changeset
263 {
97
d18dcc963930 separation of the renderers vs. viewport slice
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 96
diff changeset
264 double x, y;
d18dcc963930 separation of the renderers vs. viewport slice
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 96
diff changeset
265 slice_.ProjectPoint(x, y, points[i]);
d18dcc963930 separation of the renderers vs. viewport slice
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 96
diff changeset
266 extent.AddPoint(x, y);
85
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 83
diff changeset
267 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 83
diff changeset
268 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 83
diff changeset
269 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 83
diff changeset
270
251
192e6e349e69 first usage of new message system (in SDL only)
am@osimis.io
parents: 219
diff changeset
271
111
7665ccbf33db rename Extent as Extent2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 110
diff changeset
272 Extent2D LayerWidget::GetSceneExtent()
66
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
273 {
111
7665ccbf33db rename Extent as Extent2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 110
diff changeset
274 Extent2D sceneExtent;
66
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
275
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
276 for (size_t i = 0; i < layers_.size(); i++)
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
277 {
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
278 assert(layers_[i] != NULL);
111
7665ccbf33db rename Extent as Extent2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 110
diff changeset
279 Extent2D layerExtent;
97
d18dcc963930 separation of the renderers vs. viewport slice
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 96
diff changeset
280 GetLayerExtent(layerExtent, *layers_[i]);
66
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
281
97
d18dcc963930 separation of the renderers vs. viewport slice
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 96
diff changeset
282 sceneExtent.Union(layerExtent);
66
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
283 }
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
284
109
53bd9277b025 using the Extent class
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 103
diff changeset
285 return sceneExtent;
66
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
286 }
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
287
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
288
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
289 bool LayerWidget::RenderScene(CairoContext& context,
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
290 const ViewportGeometry& view)
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
291 {
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
292 if (currentScene_.get() != NULL)
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
293 {
97
d18dcc963930 separation of the renderers vs. viewport slice
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 96
diff changeset
294 return currentScene_->RenderScene(context, view, slice_);
66
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
295 }
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
296 else
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
297 {
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
298 return true;
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
299 }
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
300 }
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
301
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
302
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
303 void LayerWidget::ResetPendingScene()
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
304 {
121
e66b2c757790 displaying rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 119
diff changeset
305 double thickness;
e66b2c757790 displaying rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 119
diff changeset
306 if (pendingScene_.get() == NULL)
e66b2c757790 displaying rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 119
diff changeset
307 {
e66b2c757790 displaying rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 119
diff changeset
308 thickness = 1.0;
e66b2c757790 displaying rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 119
diff changeset
309 }
e66b2c757790 displaying rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 119
diff changeset
310 else
e66b2c757790 displaying rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 119
diff changeset
311 {
e66b2c757790 displaying rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 119
diff changeset
312 thickness = pendingScene_->GetThickness();
e66b2c757790 displaying rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 119
diff changeset
313 }
e66b2c757790 displaying rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 119
diff changeset
314
e66b2c757790 displaying rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 119
diff changeset
315 pendingScene_.reset(new Scene(slice_, thickness, layers_.size()));
66
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
316 }
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
317
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
318
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
319 void LayerWidget::UpdateLayer(size_t index,
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
320 ILayerRenderer* renderer,
121
e66b2c757790 displaying rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 119
diff changeset
321 const CoordinateSystem3D& slice)
66
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
322 {
71
30c768873d47 OrthancSliceLoader::ScheduleLoadInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 66
diff changeset
323 LOG(INFO) << "Updating layer " << index;
66
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
324
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
325 std::auto_ptr<ILayerRenderer> tmp(renderer);
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
326
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
327 if (renderer == NULL)
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
328 {
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
329 throw Orthanc::OrthancException(Orthanc::ErrorCode_NullPointer);
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
330 }
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
331
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
332 if (index >= layers_.size())
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
333 {
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
334 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange);
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
335 }
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
336
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
337 assert(layers_.size() == styles_.size());
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
338 renderer->SetLayerStyle(styles_[index]);
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
339
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
340 if (currentScene_.get() != NULL &&
121
e66b2c757790 displaying rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 119
diff changeset
341 currentScene_->ContainsPlane(slice))
66
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
342 {
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
343 currentScene_->SetLayer(index, tmp.release());
278
8a86695fcbc3 renamings
am@osimis.io
parents: 273
diff changeset
344 NotifyContentChanged();
66
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
345 }
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
346 else if (pendingScene_.get() != NULL &&
121
e66b2c757790 displaying rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 119
diff changeset
347 pendingScene_->ContainsPlane(slice))
66
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
348 {
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
349 pendingScene_->SetLayer(index, tmp.release());
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
350
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
351 if (currentScene_.get() == NULL ||
89
f244018a4e4b BUGGY- trying to remove IVolumeSlicesObserver
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 87
diff changeset
352 !currentScene_->IsComplete() ||
66
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
353 pendingScene_->IsComplete())
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
354 {
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
355 currentScene_ = pendingScene_;
278
8a86695fcbc3 renamings
am@osimis.io
parents: 273
diff changeset
356 NotifyContentChanged();
66
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
357 }
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
358 }
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
359 }
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
360
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
361
271
46c5296d867e OracleWebService and BasicSdlApplicationContext using the same global mutex
am@osimis.io
parents: 268
diff changeset
362 LayerWidget::LayerWidget(MessageBroker& broker, const std::string& name) :
273
f21ba2468570 force all Widgets to have a name to ease debugging
am@osimis.io
parents: 272
diff changeset
363 WorldSceneWidget(name),
251
192e6e349e69 first usage of new message system (in SDL only)
am@osimis.io
parents: 219
diff changeset
364 IObserver(broker),
267
89d02de83c03 added declaretion of messages handled/emitted
am@osimis.io
parents: 266
diff changeset
365 IObservable(broker),
273
f21ba2468570 force all Widgets to have a name to ease debugging
am@osimis.io
parents: 272
diff changeset
366 started_(false)
66
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
367 {
267
89d02de83c03 added declaretion of messages handled/emitted
am@osimis.io
parents: 266
diff changeset
368 DeclareHandledMessage(MessageType_LayerSource_GeometryReady);
89d02de83c03 added declaretion of messages handled/emitted
am@osimis.io
parents: 266
diff changeset
369 DeclareHandledMessage(MessageType_LayerSource_ContentChanged);
89d02de83c03 added declaretion of messages handled/emitted
am@osimis.io
parents: 266
diff changeset
370 DeclareHandledMessage(MessageType_LayerSource_LayerReady);
89d02de83c03 added declaretion of messages handled/emitted
am@osimis.io
parents: 266
diff changeset
371 DeclareHandledMessage(MessageType_LayerSource_SliceChanged);
89d02de83c03 added declaretion of messages handled/emitted
am@osimis.io
parents: 266
diff changeset
372 DeclareHandledMessage(MessageType_LayerSource_GeometryError);
89d02de83c03 added declaretion of messages handled/emitted
am@osimis.io
parents: 266
diff changeset
373
89d02de83c03 added declaretion of messages handled/emitted
am@osimis.io
parents: 266
diff changeset
374 DeclareEmittableMessage(MessageType_Widget_GeometryChanged);
89d02de83c03 added declaretion of messages handled/emitted
am@osimis.io
parents: 266
diff changeset
375 DeclareEmittableMessage(MessageType_Widget_ContentChanged);
89d02de83c03 added declaretion of messages handled/emitted
am@osimis.io
parents: 266
diff changeset
376
66
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
377 SetBackgroundCleared(true);
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
378 }
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
379
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
380
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
381 LayerWidget::~LayerWidget()
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
382 {
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
383 for (size_t i = 0; i < layers_.size(); i++)
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
384 {
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
385 delete layers_[i];
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
386 }
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
387 }
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
388
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
389
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
390 size_t LayerWidget::AddLayer(ILayerSource* layer) // Takes ownership
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
391 {
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
392 if (layer == NULL)
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
393 {
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
394 throw Orthanc::OrthancException(Orthanc::ErrorCode_NullPointer);
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
395 }
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
396
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
397 size_t index = layers_.size();
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
398 layers_.push_back(layer);
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
399 styles_.push_back(RenderStyle());
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
400 layersIndex_[layer] = index;
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
401
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
402 ResetPendingScene();
251
192e6e349e69 first usage of new message system (in SDL only)
am@osimis.io
parents: 219
diff changeset
403 layer->RegisterObserver(*this);
66
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
404
103
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 99
diff changeset
405 ResetChangedLayers();
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 99
diff changeset
406
66
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
407 return index;
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
408 }
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
409
219
26e3bfe30e66 ReplaceLayer()
am@osimis.io
parents: 212
diff changeset
410 void LayerWidget::ReplaceLayer(size_t index, ILayerSource* layer) // Takes ownership
26e3bfe30e66 ReplaceLayer()
am@osimis.io
parents: 212
diff changeset
411 {
26e3bfe30e66 ReplaceLayer()
am@osimis.io
parents: 212
diff changeset
412 if (layer == NULL)
26e3bfe30e66 ReplaceLayer()
am@osimis.io
parents: 212
diff changeset
413 {
26e3bfe30e66 ReplaceLayer()
am@osimis.io
parents: 212
diff changeset
414 throw Orthanc::OrthancException(Orthanc::ErrorCode_NullPointer);
26e3bfe30e66 ReplaceLayer()
am@osimis.io
parents: 212
diff changeset
415 }
26e3bfe30e66 ReplaceLayer()
am@osimis.io
parents: 212
diff changeset
416
26e3bfe30e66 ReplaceLayer()
am@osimis.io
parents: 212
diff changeset
417 if (index >= layers_.size())
26e3bfe30e66 ReplaceLayer()
am@osimis.io
parents: 212
diff changeset
418 {
26e3bfe30e66 ReplaceLayer()
am@osimis.io
parents: 212
diff changeset
419 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange);
26e3bfe30e66 ReplaceLayer()
am@osimis.io
parents: 212
diff changeset
420 }
26e3bfe30e66 ReplaceLayer()
am@osimis.io
parents: 212
diff changeset
421
26e3bfe30e66 ReplaceLayer()
am@osimis.io
parents: 212
diff changeset
422 delete layers_[index];
26e3bfe30e66 ReplaceLayer()
am@osimis.io
parents: 212
diff changeset
423 layers_[index] = layer;
26e3bfe30e66 ReplaceLayer()
am@osimis.io
parents: 212
diff changeset
424 layersIndex_[layer] = index;
26e3bfe30e66 ReplaceLayer()
am@osimis.io
parents: 212
diff changeset
425
26e3bfe30e66 ReplaceLayer()
am@osimis.io
parents: 212
diff changeset
426 ResetPendingScene();
251
192e6e349e69 first usage of new message system (in SDL only)
am@osimis.io
parents: 219
diff changeset
427 layer->RegisterObserver(*this);
219
26e3bfe30e66 ReplaceLayer()
am@osimis.io
parents: 212
diff changeset
428
26e3bfe30e66 ReplaceLayer()
am@osimis.io
parents: 212
diff changeset
429 InvalidateLayer(index);
26e3bfe30e66 ReplaceLayer()
am@osimis.io
parents: 212
diff changeset
430 }
26e3bfe30e66 ReplaceLayer()
am@osimis.io
parents: 212
diff changeset
431
26e3bfe30e66 ReplaceLayer()
am@osimis.io
parents: 212
diff changeset
432
119
ba83e38cf3ff rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 113
diff changeset
433 const RenderStyle& LayerWidget::GetLayerStyle(size_t layer) const
ba83e38cf3ff rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 113
diff changeset
434 {
ba83e38cf3ff rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 113
diff changeset
435 if (layer >= layers_.size())
ba83e38cf3ff rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 113
diff changeset
436 {
ba83e38cf3ff rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 113
diff changeset
437 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange);
ba83e38cf3ff rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 113
diff changeset
438 }
ba83e38cf3ff rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 113
diff changeset
439
ba83e38cf3ff rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 113
diff changeset
440 assert(layers_.size() == styles_.size());
ba83e38cf3ff rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 113
diff changeset
441 return styles_[layer];
ba83e38cf3ff rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 113
diff changeset
442 }
ba83e38cf3ff rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 113
diff changeset
443
ba83e38cf3ff rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 113
diff changeset
444
66
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
445 void LayerWidget::SetLayerStyle(size_t layer,
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
446 const RenderStyle& style)
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
447 {
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
448 if (layer >= layers_.size())
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
449 {
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
450 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange);
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
451 }
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
452
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
453 assert(layers_.size() == styles_.size());
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
454 styles_[layer] = style;
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
455
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
456 if (currentScene_.get() != NULL)
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
457 {
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
458 currentScene_->SetLayerStyle(layer, style);
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
459 }
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
460
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
461 if (pendingScene_.get() != NULL)
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
462 {
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
463 pendingScene_->SetLayerStyle(layer, style);
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
464 }
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
465
278
8a86695fcbc3 renamings
am@osimis.io
parents: 273
diff changeset
466 NotifyContentChanged();
66
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
467 }
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
468
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
469
110
53025eecbc95 renamed SliceGeometry as CoordinateSystem3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 109
diff changeset
470 void LayerWidget::SetSlice(const CoordinateSystem3D& slice)
66
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
471 {
93
5945e81734a3 decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 92
diff changeset
472 LOG(INFO) << "Setting slice origin: (" << slice.GetOrigin()[0]
5945e81734a3 decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 92
diff changeset
473 << "," << slice.GetOrigin()[1]
5945e81734a3 decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 92
diff changeset
474 << "," << slice.GetOrigin()[2] << ")";
5945e81734a3 decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 92
diff changeset
475
90
64e60018943f fix and observer refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 89
diff changeset
476 Slice displayedSlice(slice_, THIN_SLICE_THICKNESS);
64e60018943f fix and observer refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 89
diff changeset
477
97
d18dcc963930 separation of the renderers vs. viewport slice
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 96
diff changeset
478 //if (!displayedSlice.ContainsPlane(slice))
66
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
479 {
90
64e60018943f fix and observer refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 89
diff changeset
480 if (currentScene_.get() == NULL ||
64e60018943f fix and observer refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 89
diff changeset
481 (pendingScene_.get() != NULL &&
64e60018943f fix and observer refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 89
diff changeset
482 pendingScene_->IsComplete()))
64e60018943f fix and observer refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 89
diff changeset
483 {
64e60018943f fix and observer refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 89
diff changeset
484 currentScene_ = pendingScene_;
64e60018943f fix and observer refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 89
diff changeset
485 }
89
f244018a4e4b BUGGY- trying to remove IVolumeSlicesObserver
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 87
diff changeset
486
90
64e60018943f fix and observer refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 89
diff changeset
487 slice_ = slice;
64e60018943f fix and observer refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 89
diff changeset
488 ResetPendingScene();
64e60018943f fix and observer refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 89
diff changeset
489
92
961ee171d933 cleaning up
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 90
diff changeset
490 InvalidateAllLayers(); // TODO Removing this line avoid loading twice the image in WASM
90
64e60018943f fix and observer refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 89
diff changeset
491 }
89
f244018a4e4b BUGGY- trying to remove IVolumeSlicesObserver
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 87
diff changeset
492 }
66
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
493
268
5bd4161bf11b removed constness of the observable when emitting a message
am@osimis.io
parents: 267
diff changeset
494 void LayerWidget::HandleMessage(IObservable& from, const IMessage& message)
251
192e6e349e69 first usage of new message system (in SDL only)
am@osimis.io
parents: 219
diff changeset
495 {
192e6e349e69 first usage of new message system (in SDL only)
am@osimis.io
parents: 219
diff changeset
496 switch (message.GetType()) {
267
89d02de83c03 added declaretion of messages handled/emitted
am@osimis.io
parents: 266
diff changeset
497 case MessageType_LayerSource_GeometryReady:
266
c9cf95b49a86 removed OrthancSlicesLoader::ISliceLoaderObserver; now using standard messages instead
am@osimis.io
parents: 252
diff changeset
498 OnGeometryReady(dynamic_cast<const ILayerSource&>(from));
251
192e6e349e69 first usage of new message system (in SDL only)
am@osimis.io
parents: 219
diff changeset
499 break;
267
89d02de83c03 added declaretion of messages handled/emitted
am@osimis.io
parents: 266
diff changeset
500 case MessageType_LayerSource_GeometryError:
251
192e6e349e69 first usage of new message system (in SDL only)
am@osimis.io
parents: 219
diff changeset
501 LOG(ERROR) << "Cannot get geometry";
192e6e349e69 first usage of new message system (in SDL only)
am@osimis.io
parents: 219
diff changeset
502 break;
267
89d02de83c03 added declaretion of messages handled/emitted
am@osimis.io
parents: 266
diff changeset
503 case MessageType_LayerSource_ContentChanged:
266
c9cf95b49a86 removed OrthancSlicesLoader::ISliceLoaderObserver; now using standard messages instead
am@osimis.io
parents: 252
diff changeset
504 OnContentChanged(dynamic_cast<const ILayerSource&>(from));
251
192e6e349e69 first usage of new message system (in SDL only)
am@osimis.io
parents: 219
diff changeset
505 break;
267
89d02de83c03 added declaretion of messages handled/emitted
am@osimis.io
parents: 266
diff changeset
506 case MessageType_LayerSource_SliceChanged:
266
c9cf95b49a86 removed OrthancSlicesLoader::ISliceLoaderObserver; now using standard messages instead
am@osimis.io
parents: 252
diff changeset
507 OnSliceChanged(dynamic_cast<const ILayerSource&>(from), dynamic_cast<const ILayerSource::SliceChangedMessage&>(message).slice_);
251
192e6e349e69 first usage of new message system (in SDL only)
am@osimis.io
parents: 219
diff changeset
508 break;
267
89d02de83c03 added declaretion of messages handled/emitted
am@osimis.io
parents: 266
diff changeset
509 case MessageType_LayerSource_LayerReady:
251
192e6e349e69 first usage of new message system (in SDL only)
am@osimis.io
parents: 219
diff changeset
510 {
192e6e349e69 first usage of new message system (in SDL only)
am@osimis.io
parents: 219
diff changeset
511 const ILayerSource::LayerReadyMessage& layerReadyMessage = dynamic_cast<const ILayerSource::LayerReadyMessage&>(message);
252
40b21c1f8b8d more usage of IObservable/IObserver
am@osimis.io
parents: 251
diff changeset
512 OnLayerReady(layerReadyMessage.layer_,
266
c9cf95b49a86 removed OrthancSlicesLoader::ISliceLoaderObserver; now using standard messages instead
am@osimis.io
parents: 252
diff changeset
513 dynamic_cast<const ILayerSource&>(from),
252
40b21c1f8b8d more usage of IObservable/IObserver
am@osimis.io
parents: 251
diff changeset
514 layerReadyMessage.slice_,
40b21c1f8b8d more usage of IObservable/IObserver
am@osimis.io
parents: 251
diff changeset
515 layerReadyMessage.isError_);
251
192e6e349e69 first usage of new message system (in SDL only)
am@osimis.io
parents: 219
diff changeset
516 }; break;
192e6e349e69 first usage of new message system (in SDL only)
am@osimis.io
parents: 219
diff changeset
517 default:
192e6e349e69 first usage of new message system (in SDL only)
am@osimis.io
parents: 219
diff changeset
518 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented);
192e6e349e69 first usage of new message system (in SDL only)
am@osimis.io
parents: 219
diff changeset
519 }
192e6e349e69 first usage of new message system (in SDL only)
am@osimis.io
parents: 219
diff changeset
520 }
89
f244018a4e4b BUGGY- trying to remove IVolumeSlicesObserver
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 87
diff changeset
521
251
192e6e349e69 first usage of new message system (in SDL only)
am@osimis.io
parents: 219
diff changeset
522 void LayerWidget::OnGeometryReady(const ILayerSource& source)
90
64e60018943f fix and observer refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 89
diff changeset
523 {
64e60018943f fix and observer refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 89
diff changeset
524 size_t i;
64e60018943f fix and observer refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 89
diff changeset
525 if (LookupLayer(i, source))
64e60018943f fix and observer refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 89
diff changeset
526 {
273
f21ba2468570 force all Widgets to have a name to ease debugging
am@osimis.io
parents: 272
diff changeset
527 LOG(INFO) << ": Geometry ready for layer " << i << " in " << GetName();
103
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 99
diff changeset
528
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 99
diff changeset
529 changedLayers_[i] = true;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 99
diff changeset
530 //layers_[i]->ScheduleLayerCreation(slice_);
90
64e60018943f fix and observer refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 89
diff changeset
531 }
267
89d02de83c03 added declaretion of messages handled/emitted
am@osimis.io
parents: 266
diff changeset
532 EmitMessage(IMessage(MessageType_Widget_GeometryChanged));
90
64e60018943f fix and observer refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 89
diff changeset
533 }
64e60018943f fix and observer refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 89
diff changeset
534
89
f244018a4e4b BUGGY- trying to remove IVolumeSlicesObserver
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 87
diff changeset
535 void LayerWidget::InvalidateAllLayers()
f244018a4e4b BUGGY- trying to remove IVolumeSlicesObserver
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 87
diff changeset
536 {
f244018a4e4b BUGGY- trying to remove IVolumeSlicesObserver
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 87
diff changeset
537 for (size_t i = 0; i < layers_.size(); i++)
f244018a4e4b BUGGY- trying to remove IVolumeSlicesObserver
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 87
diff changeset
538 {
f244018a4e4b BUGGY- trying to remove IVolumeSlicesObserver
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 87
diff changeset
539 assert(layers_[i] != NULL);
103
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 99
diff changeset
540 changedLayers_[i] = true;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 99
diff changeset
541
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 99
diff changeset
542 //layers_[i]->ScheduleLayerCreation(slice_);
66
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
543 }
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
544 }
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
545
89
f244018a4e4b BUGGY- trying to remove IVolumeSlicesObserver
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 87
diff changeset
546
f244018a4e4b BUGGY- trying to remove IVolumeSlicesObserver
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 87
diff changeset
547 void LayerWidget::InvalidateLayer(size_t layer)
66
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
548 {
89
f244018a4e4b BUGGY- trying to remove IVolumeSlicesObserver
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 87
diff changeset
549 if (layer >= layers_.size())
83
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 78
diff changeset
550 {
89
f244018a4e4b BUGGY- trying to remove IVolumeSlicesObserver
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 87
diff changeset
551 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange);
83
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 78
diff changeset
552 }
66
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
553
89
f244018a4e4b BUGGY- trying to remove IVolumeSlicesObserver
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 87
diff changeset
554 assert(layers_[layer] != NULL);
103
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 99
diff changeset
555 changedLayers_[layer] = true;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 99
diff changeset
556
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 99
diff changeset
557 //layers_[layer]->ScheduleLayerCreation(slice_);
77
f5f54ed8d307 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 71
diff changeset
558 }
89
f244018a4e4b BUGGY- trying to remove IVolumeSlicesObserver
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 87
diff changeset
559
77
f5f54ed8d307 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 71
diff changeset
560
251
192e6e349e69 first usage of new message system (in SDL only)
am@osimis.io
parents: 219
diff changeset
561 void LayerWidget::OnContentChanged(const ILayerSource& source)
66
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
562 {
87
4a541cd4fa83 OrthancVolumeImageLoader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 86
diff changeset
563 size_t index;
4a541cd4fa83 OrthancVolumeImageLoader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 86
diff changeset
564 if (LookupLayer(index, source))
4a541cd4fa83 OrthancVolumeImageLoader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 86
diff changeset
565 {
103
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 99
diff changeset
566 InvalidateLayer(index);
87
4a541cd4fa83 OrthancVolumeImageLoader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 86
diff changeset
567 }
66
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
568 }
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
569
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
570
251
192e6e349e69 first usage of new message system (in SDL only)
am@osimis.io
parents: 219
diff changeset
571 void LayerWidget::OnSliceChanged(const ILayerSource& source,
192e6e349e69 first usage of new message system (in SDL only)
am@osimis.io
parents: 219
diff changeset
572 const Slice& slice)
66
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
573 {
77
f5f54ed8d307 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 71
diff changeset
574 if (slice.ContainsPlane(slice_))
66
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
575 {
87
4a541cd4fa83 OrthancVolumeImageLoader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 86
diff changeset
576 size_t index;
4a541cd4fa83 OrthancVolumeImageLoader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 86
diff changeset
577 if (LookupLayer(index, source))
4a541cd4fa83 OrthancVolumeImageLoader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 86
diff changeset
578 {
103
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 99
diff changeset
579 InvalidateLayer(index);
87
4a541cd4fa83 OrthancVolumeImageLoader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 86
diff changeset
580 }
66
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
581 }
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
582 }
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
583
89
f244018a4e4b BUGGY- trying to remove IVolumeSlicesObserver
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 87
diff changeset
584
251
192e6e349e69 first usage of new message system (in SDL only)
am@osimis.io
parents: 219
diff changeset
585 void LayerWidget::OnLayerReady(std::auto_ptr<ILayerRenderer>& renderer,
192e6e349e69 first usage of new message system (in SDL only)
am@osimis.io
parents: 219
diff changeset
586 const ILayerSource& source,
192e6e349e69 first usage of new message system (in SDL only)
am@osimis.io
parents: 219
diff changeset
587 const CoordinateSystem3D& slice,
192e6e349e69 first usage of new message system (in SDL only)
am@osimis.io
parents: 219
diff changeset
588 bool isError)
66
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
589 {
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
590 size_t index;
121
e66b2c757790 displaying rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 119
diff changeset
591 if (LookupLayer(index, source))
66
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
592 {
96
f8bce1bebe01 removal of the NotifyLayerError callback
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 95
diff changeset
593 if (isError)
f8bce1bebe01 removal of the NotifyLayerError callback
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 95
diff changeset
594 {
f8bce1bebe01 removal of the NotifyLayerError callback
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 95
diff changeset
595 LOG(ERROR) << "Using error renderer on layer " << index;
f8bce1bebe01 removal of the NotifyLayerError callback
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 95
diff changeset
596 }
f8bce1bebe01 removal of the NotifyLayerError callback
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 95
diff changeset
597 else
f8bce1bebe01 removal of the NotifyLayerError callback
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 95
diff changeset
598 {
f8bce1bebe01 removal of the NotifyLayerError callback
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 95
diff changeset
599 LOG(INFO) << "Renderer ready for layer " << index;
f8bce1bebe01 removal of the NotifyLayerError callback
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 95
diff changeset
600 }
f8bce1bebe01 removal of the NotifyLayerError callback
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 95
diff changeset
601
99
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 97
diff changeset
602 if (renderer.get() != NULL)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 97
diff changeset
603 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 97
diff changeset
604 UpdateLayer(index, renderer.release(), slice);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 97
diff changeset
605 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 97
diff changeset
606 else if (isError)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 97
diff changeset
607 {
121
e66b2c757790 displaying rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 119
diff changeset
608 // TODO
e66b2c757790 displaying rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 119
diff changeset
609 //UpdateLayer(index, new SliceOutlineRenderer(slice), slice);
99
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 97
diff changeset
610 }
66
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
611 }
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
612 }
103
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 99
diff changeset
613
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 99
diff changeset
614
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 99
diff changeset
615 void LayerWidget::ResetChangedLayers()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 99
diff changeset
616 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 99
diff changeset
617 changedLayers_.resize(layers_.size());
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 99
diff changeset
618
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 99
diff changeset
619 for (size_t i = 0; i < changedLayers_.size(); i++)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 99
diff changeset
620 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 99
diff changeset
621 changedLayers_[i] = false;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 99
diff changeset
622 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 99
diff changeset
623 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 99
diff changeset
624
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 99
diff changeset
625
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 99
diff changeset
626 void LayerWidget::UpdateContent()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 99
diff changeset
627 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 99
diff changeset
628 assert(changedLayers_.size() <= layers_.size());
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 99
diff changeset
629
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 99
diff changeset
630 for (size_t i = 0; i < changedLayers_.size(); i++)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 99
diff changeset
631 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 99
diff changeset
632 if (changedLayers_[i])
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 99
diff changeset
633 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 99
diff changeset
634 layers_[i]->ScheduleLayerCreation(slice_);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 99
diff changeset
635 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 99
diff changeset
636 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 99
diff changeset
637
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 99
diff changeset
638 ResetChangedLayers();
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 99
diff changeset
639 }
66
298f375dcb68 LayerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
640 }