comparison Framework/Radiography/RadiographyWidget.cpp @ 428:751fb354149e am-vsol-upgrade

ability to change the scene of the RadiographyWidget
author am@osimis.io
date Wed, 28 Nov 2018 10:44:28 +0100
parents 18b707fb8620
children 4eb96c6b4e96
comparison
equal deleted inserted replaced
426:660fe6f6bf4a 428:751fb354149e
29 bool RadiographyWidget::RenderInternal(unsigned int width, 29 bool RadiographyWidget::RenderInternal(unsigned int width,
30 unsigned int height, 30 unsigned int height,
31 ImageInterpolation interpolation) 31 ImageInterpolation interpolation)
32 { 32 {
33 float windowCenter, windowWidth; 33 float windowCenter, windowWidth;
34 scene_.GetWindowingWithDefault(windowCenter, windowWidth); 34 scene_->GetWindowingWithDefault(windowCenter, windowWidth);
35 35
36 float x0 = windowCenter - windowWidth / 2.0f; 36 float x0 = windowCenter - windowWidth / 2.0f;
37 float x1 = windowCenter + windowWidth / 2.0f; 37 float x1 = windowCenter + windowWidth / 2.0f;
38 38
39 if (windowWidth <= 0.001f) // Avoid division by zero at (*) 39 if (windowWidth <= 0.001f) // Avoid division by zero at (*)
54 cairoBuffer_->GetHeight() != height) 54 cairoBuffer_->GetHeight() != height)
55 { 55 {
56 cairoBuffer_.reset(new CairoSurface(width, height)); 56 cairoBuffer_.reset(new CairoSurface(width, height));
57 } 57 }
58 58
59 scene_.Render(*floatBuffer_, GetView().GetMatrix(), interpolation); 59 scene_->Render(*floatBuffer_, GetView().GetMatrix(), interpolation);
60 60
61 // Conversion from Float32 to BGRA32 (cairo). Very similar to 61 // Conversion from Float32 to BGRA32 (cairo). Very similar to
62 // GrayscaleFrameRenderer => TODO MERGE? 62 // GrayscaleFrameRenderer => TODO MERGE?
63 63
64 Orthanc::ImageAccessor target; 64 Orthanc::ImageAccessor target;
126 cairo_paint(cr); 126 cairo_paint(cr);
127 } 127 }
128 128
129 if (hasSelection_) 129 if (hasSelection_)
130 { 130 {
131 scene_.DrawBorder(context, selectedLayer_, view.GetZoom()); 131 scene_->DrawBorder(context, selectedLayer_, view.GetZoom());
132 } 132 }
133 133
134 return true; 134 return true;
135 } 135 }
136 136
137 137
138 RadiographyWidget::RadiographyWidget(MessageBroker& broker, 138 RadiographyWidget::RadiographyWidget(MessageBroker& broker,
139 RadiographyScene& scene, 139 boost::shared_ptr<RadiographyScene> scene,
140 const std::string& name) : 140 const std::string& name) :
141 WorldSceneWidget(name), 141 WorldSceneWidget(name),
142 IObserver(broker), 142 IObserver(broker),
143 scene_(scene),
144 invert_(false), 143 invert_(false),
145 interpolation_(ImageInterpolation_Nearest), 144 interpolation_(ImageInterpolation_Nearest),
146 hasSelection_(false), 145 hasSelection_(false),
147 selectedLayer_(0) // Dummy initialization 146 selectedLayer_(0) // Dummy initialization
148 { 147 {
149 scene.RegisterObserverCallback( 148 SetScene(scene);
149 }
150
151
152 void RadiographyWidget::Select(size_t layer)
153 {
154 hasSelection_ = true;
155 selectedLayer_ = layer;
156 }
157
158
159 bool RadiographyWidget::LookupSelectedLayer(size_t& layer)
160 {
161 if (hasSelection_)
162 {
163 layer = selectedLayer_;
164 return true;
165 }
166 else
167 {
168 return false;
169 }
170 }
171
172
173 void RadiographyWidget::OnGeometryChanged(const RadiographyScene::GeometryChangedMessage& message)
174 {
175 LOG(INFO) << "Geometry has changed";
176 FitContent();
177 }
178
179
180 void RadiographyWidget::OnContentChanged(const RadiographyScene::ContentChangedMessage& message)
181 {
182 LOG(INFO) << "Content has changed";
183 NotifyContentChanged();
184 }
185
186
187 void RadiographyWidget::SetInvert(bool invert)
188 {
189 if (invert_ != invert)
190 {
191 invert_ = invert;
192 NotifyContentChanged();
193 }
194 }
195
196
197 void RadiographyWidget::SwitchInvert()
198 {
199 invert_ = !invert_;
200 NotifyContentChanged();
201 }
202
203
204 void RadiographyWidget::SetInterpolation(ImageInterpolation interpolation)
205 {
206 if (interpolation_ != interpolation)
207 {
208 interpolation_ = interpolation;
209 NotifyContentChanged();
210 }
211 }
212
213 void RadiographyWidget::SetScene(boost::shared_ptr<RadiographyScene> scene)
214 {
215 if (scene_ != NULL)
216 {
217 scene_->Unregister(this);
218 }
219
220 scene_ = scene;
221
222 scene_->RegisterObserverCallback(
150 new Callable<RadiographyWidget, RadiographyScene::GeometryChangedMessage> 223 new Callable<RadiographyWidget, RadiographyScene::GeometryChangedMessage>
151 (*this, &RadiographyWidget::OnGeometryChanged)); 224 (*this, &RadiographyWidget::OnGeometryChanged));
152 225
153 scene.RegisterObserverCallback( 226 scene_->RegisterObserverCallback(
154 new Callable<RadiographyWidget, RadiographyScene::ContentChangedMessage> 227 new Callable<RadiographyWidget, RadiographyScene::ContentChangedMessage>
155 (*this, &RadiographyWidget::OnContentChanged)); 228 (*this, &RadiographyWidget::OnContentChanged));
156 } 229
157 230 // force redraw
158
159 void RadiographyWidget::Select(size_t layer)
160 {
161 hasSelection_ = true;
162 selectedLayer_ = layer;
163 }
164
165
166 bool RadiographyWidget::LookupSelectedLayer(size_t& layer)
167 {
168 if (hasSelection_)
169 {
170 layer = selectedLayer_;
171 return true;
172 }
173 else
174 {
175 return false;
176 }
177 }
178
179
180 void RadiographyWidget::OnGeometryChanged(const RadiographyScene::GeometryChangedMessage& message)
181 {
182 LOG(INFO) << "Geometry has changed";
183 FitContent(); 231 FitContent();
184 } 232 }
185
186
187 void RadiographyWidget::OnContentChanged(const RadiographyScene::ContentChangedMessage& message)
188 {
189 LOG(INFO) << "Content has changed";
190 NotifyContentChanged();
191 }
192
193
194 void RadiographyWidget::SetInvert(bool invert)
195 {
196 if (invert_ != invert)
197 {
198 invert_ = invert;
199 NotifyContentChanged();
200 }
201 }
202
203
204 void RadiographyWidget::SwitchInvert()
205 {
206 invert_ = !invert_;
207 NotifyContentChanged();
208 }
209
210
211 void RadiographyWidget::SetInterpolation(ImageInterpolation interpolation)
212 {
213 if (interpolation_ != interpolation)
214 {
215 interpolation_ = interpolation;
216 NotifyContentChanged();
217 }
218 }
219 } 233 }