Mercurial > hg > orthanc-stone
comparison Applications/Samples/SingleFrameEditorApplication.h @ 336:c7fdc8bac581 am-2
creating GrayscaleBitmapStack
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 18 Oct 2018 19:29:14 +0200 |
parents | c34784e5f299 |
children | c4d4213f095c |
comparison
equal
deleted
inserted
replaced
335:3e42fc27eb91 | 336:c7fdc8bac581 |
---|---|
22 #pragma once | 22 #pragma once |
23 | 23 |
24 #include "SampleApplicationBase.h" | 24 #include "SampleApplicationBase.h" |
25 | 25 |
26 #include "../../Framework/Layers/OrthancFrameLayerSource.h" | 26 #include "../../Framework/Layers/OrthancFrameLayerSource.h" |
27 #include "../../Framework/Widgets/LayerWidget.h" | |
28 | 27 |
29 #include <Core/Logging.h> | 28 #include <Core/Logging.h> |
30 | 29 |
31 namespace OrthancStone | 30 namespace OrthancStone |
32 { | 31 { |
32 | |
33 class GrayscaleBitmapStack : | |
34 public WorldSceneWidget, | |
35 public IObservable | |
36 { | |
37 public: | |
38 typedef OriginMessage<MessageType_Widget_GeometryChanged, GrayscaleBitmapStack> GeometryChangedMessage; | |
39 typedef OriginMessage<MessageType_Widget_ContentChanged, GrayscaleBitmapStack> ContentChangedMessage; | |
40 | |
41 protected: | |
42 virtual Extent2D GetSceneExtent() | |
43 { | |
44 } | |
45 | |
46 virtual bool RenderScene(CairoContext& context, | |
47 const ViewportGeometry& view) | |
48 { | |
49 } | |
50 | |
51 public: | |
52 GrayscaleBitmapStack(MessageBroker& broker, | |
53 const std::string& name) : | |
54 WorldSceneWidget(name), | |
55 IObservable(broker) | |
56 { | |
57 } | |
58 | |
59 }; | |
60 | |
61 | |
33 namespace Samples | 62 namespace Samples |
34 { | 63 { |
35 class SingleFrameEditorApplication : | 64 class SingleFrameEditorApplication : |
36 public SampleSingleCanvasApplicationBase, | 65 public SampleSingleCanvasApplicationBase, |
37 public IObserver | 66 public IObserver |
92 double y, | 121 double y, |
93 IStatusBar* statusBar) | 122 IStatusBar* statusBar) |
94 { | 123 { |
95 if (statusBar != NULL) | 124 if (statusBar != NULL) |
96 { | 125 { |
97 Vector p = dynamic_cast<LayerWidget&>(widget).GetSlice().MapSliceToWorldCoordinates(x, y); | |
98 | |
99 char buf[64]; | 126 char buf[64]; |
100 sprintf(buf, "X = %.02f Y = %.02f Z = %.02f (in cm)", | 127 sprintf(buf, "X = %.02f Y = %.02f (in cm)", x / 10.0, y / 10.0); |
101 p[0] / 10.0, p[1] / 10.0, p[2] / 10.0); | 128 statusBar->SetMessage(buf); |
102 //statusBar->SetMessage(buf); | |
103 } | 129 } |
104 } | 130 } |
105 | 131 |
106 virtual void MouseWheel(WorldSceneWidget& widget, | 132 virtual void MouseWheel(WorldSceneWidget& widget, |
107 MouseWheelDirection direction, | 133 MouseWheelDirection direction, |
149 break; | 175 break; |
150 } | 176 } |
151 } | 177 } |
152 }; | 178 }; |
153 | 179 |
154 void OnGeometryChanged(const LayerWidget::GeometryChangedMessage& message) | 180 void OnGeometryChanged(const GrayscaleBitmapStack::GeometryChangedMessage& message) |
155 { | 181 { |
156 mainWidget_->SetSlice(source_->GetSlice(slice_).GetGeometry()); | |
157 mainWidget_->FitContent(); | 182 mainWidget_->FitContent(); |
158 } | 183 } |
159 | 184 |
160 std::auto_ptr<Interactor> mainWidgetInteractor_; | 185 std::auto_ptr<Interactor> mainWidgetInteractor_; |
161 std::auto_ptr<OrthancApiClient> orthancApiClient_; | 186 std::auto_ptr<OrthancApiClient> orthancApiClient_; |
203 | 228 |
204 std::string instance = parameters["instance"].as<std::string>(); | 229 std::string instance = parameters["instance"].as<std::string>(); |
205 int frame = parameters["frame"].as<unsigned int>(); | 230 int frame = parameters["frame"].as<unsigned int>(); |
206 | 231 |
207 orthancApiClient_.reset(new OrthancApiClient(IObserver::broker_, context_->GetWebService())); | 232 orthancApiClient_.reset(new OrthancApiClient(IObserver::broker_, context_->GetWebService())); |
208 mainWidget_ = new LayerWidget(broker_, "main-widget"); | 233 mainWidget_ = new GrayscaleBitmapStack(broker_, "main-widget"); |
209 | 234 |
210 std::auto_ptr<OrthancFrameLayerSource> layer(new OrthancFrameLayerSource(broker_, *orthancApiClient_)); | 235 dynamic_cast<GrayscaleBitmapStack*>(mainWidget_)->RegisterObserverCallback( |
211 source_ = layer.get(); | 236 new Callable<SingleFrameEditorApplication, |
212 layer->LoadFrame(instance, frame); | 237 GrayscaleBitmapStack::GeometryChangedMessage> |
213 mainWidget_->RegisterObserverCallback(new Callable<SingleFrameEditorApplication, LayerWidget::GeometryChangedMessage>(*this, &SingleFrameEditorApplication::OnGeometryChanged)); | 238 (*this, &SingleFrameEditorApplication::OnGeometryChanged)); |
214 mainWidget_->AddLayer(layer.release()); | |
215 | 239 |
216 mainWidget_->SetTransmitMouseOver(true); | 240 mainWidget_->SetTransmitMouseOver(true); |
217 | 241 |
218 mainWidgetInteractor_.reset(new Interactor(*this)); | 242 mainWidgetInteractor_.reset(new Interactor(*this)); |
219 mainWidget_->SetInteractor(*mainWidgetInteractor_); | 243 mainWidget_->SetInteractor(*mainWidgetInteractor_); |