comparison Applications/Samples/SingleFrameApplication.h @ 85:bd48431ac285 wasm

fix
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 26 May 2017 12:20:26 +0200
parents 4e21f6b3aa0d
children f244018a4e4b
comparison
equal deleted inserted replaced
83:c75377306598 85:bd48431ac285
20 20
21 21
22 #pragma once 22 #pragma once
23 23
24 #include "SampleApplicationBase.h" 24 #include "SampleApplicationBase.h"
25 #include "SampleInteractor.h"
25 26
26 #include "../../Framework/Layers/OrthancFrameLayerSource.h" 27 #include "../../Framework/Layers/OrthancFrameLayerSource.h"
27 #include "../../Framework/Widgets/LayerWidget.h" 28 #include "../../Framework/Widgets/LayerWidget.h"
28 #include "../../Resources/Orthanc/Core/Logging.h" 29 #include "../../Resources/Orthanc/Core/Logging.h"
29 30
34 class SingleFrameApplication : 35 class SingleFrameApplication :
35 public SampleApplicationBase, 36 public SampleApplicationBase,
36 public IVolumeSlicesObserver 37 public IVolumeSlicesObserver
37 { 38 {
38 private: 39 private:
40 class Interactor : public IWorldSceneInteractor
41 {
42 public:
43 virtual IWorldSceneMouseTracker* CreateMouseTracker(WorldSceneWidget& widget,
44 const ViewportGeometry& view,
45 MouseButton button,
46 double x,
47 double y,
48 IStatusBar* statusBar)
49 {
50 return NULL;
51 }
52
53 virtual void MouseOver(CairoContext& context,
54 WorldSceneWidget& widget,
55 const ViewportGeometry& view,
56 double x,
57 double y,
58 IStatusBar* statusBar)
59 {
60 if (statusBar != NULL)
61 {
62 Vector p = dynamic_cast<LayerWidget&>(widget).GetSlice().MapSliceToWorldCoordinates(x, y);
63
64 char buf[64];
65 sprintf(buf, "X = %.02f Y = %.02f Z = %.02f (in cm)",
66 p[0] / 10.0, p[1] / 10.0, p[2] / 10.0);
67 statusBar->SetMessage(buf);
68 }
69 }
70
71 virtual void MouseWheel(WorldSceneWidget& widget,
72 MouseWheelDirection direction,
73 KeyboardModifiers modifiers,
74 IStatusBar* statusBar)
75 {
76 }
77
78 virtual void KeyPressed(WorldSceneWidget& widget,
79 char key,
80 KeyboardModifiers modifiers,
81 IStatusBar* statusBar)
82 {
83 switch (key)
84 {
85 case 's':
86 widget.SetDefaultView();
87 break;
88
89 default:
90 break;
91 }
92 }
93 };
94
39 LayerWidget* widget_; 95 LayerWidget* widget_;
40 96
41 public: 97 public:
42 SingleFrameApplication() : widget_(NULL) 98 SingleFrameApplication() : widget_(NULL)
43 { 99 {
47 { 103 {
48 if (widget_ != NULL && 104 if (widget_ != NULL &&
49 slices.GetSliceCount() > 0) 105 slices.GetSliceCount() > 0)
50 { 106 {
51 widget_->SetSlice(slices.GetSlice(0)); 107 widget_->SetSlice(slices.GetSlice(0));
108 widget_->SetDefaultView();
52 } 109 }
53 } 110 }
54 111
55 virtual void DeclareCommandLineOptions(boost::program_options::options_description& options) 112 virtual void DeclareCommandLineOptions(boost::program_options::options_description& options)
56 { 113 {
71 IStatusBar& statusBar, 128 IStatusBar& statusBar,
72 const boost::program_options::variables_map& parameters) 129 const boost::program_options::variables_map& parameters)
73 { 130 {
74 using namespace OrthancStone; 131 using namespace OrthancStone;
75 132
133 statusBar.SetMessage("Use the key \"s\" to reinitialize the layout");
134
76 if (parameters.count("instance") != 1) 135 if (parameters.count("instance") != 1)
77 { 136 {
78 LOG(ERROR) << "The instance ID is missing"; 137 LOG(ERROR) << "The instance ID is missing";
79 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); 138 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange);
80 } 139 }
82 std::string instance = parameters["instance"].as<std::string>(); 141 std::string instance = parameters["instance"].as<std::string>();
83 int frame = parameters["frame"].as<unsigned int>(); 142 int frame = parameters["frame"].as<unsigned int>();
84 143
85 std::auto_ptr<LayerWidget> widget(new LayerWidget); 144 std::auto_ptr<LayerWidget> widget(new LayerWidget);
86 145
87 #if 0 146 #if 1
88 std::auto_ptr<OrthancFrameLayerSource> layer 147 std::auto_ptr<OrthancFrameLayerSource> layer
89 (new OrthancFrameLayerSource(context.GetWebService(), instance, frame)); 148 (new OrthancFrameLayerSource(context.GetWebService(), instance, frame));
90 layer->SetObserver(*this); 149 layer->SetObserver(*this);
91 widget->AddLayer(layer.release()); 150 widget->AddLayer(layer.release());
92 151
104 layer->SetObserver(*this); 163 layer->SetObserver(*this);
105 widget->AddLayer(layer.release()); 164 widget->AddLayer(layer.release());
106 165
107 widget->AddLayer(new OrthancFrameLayerSource(context.GetWebService(), "a1c4dc6b-255d27f0-88069875-8daed730-2f5ee5c6", 0)); 166 widget->AddLayer(new OrthancFrameLayerSource(context.GetWebService(), "a1c4dc6b-255d27f0-88069875-8daed730-2f5ee5c6", 0));
108 167
109 RenderStyle s; 168 {
110 //s.drawGrid_ = true; 169 RenderStyle s;
111 s.alpha_ = 1; 170 s.alpha_ = 1;
112 widget->SetLayerStyle(0, s); 171 widget->SetLayerStyle(0, s);
113 s.alpha_ = 0.5; 172 }
114 s.applyLut_ = true; 173
115 s.lut_ = Orthanc::EmbeddedResources::COLORMAP_JET; 174 {
116 widget->SetLayerStyle(1, s); 175 RenderStyle s;
176 s.drawGrid_ = true;
177 s.SetColor(255, 0, 0); // Draw missing PET layer in red
178 s.alpha_ = 0.5;
179 s.applyLut_ = true;
180 s.lut_ = Orthanc::EmbeddedResources::COLORMAP_JET;
181 widget->SetLayerStyle(1, s);
182 }
117 #endif 183 #endif
118 184
119 widget_ = widget.get(); 185 widget_ = widget.get();
186 widget_->SetTransmitMouseOver(true);
187 widget_->SetInteractor(context.AddInteractor(new Interactor));
120 context.SetCentralWidget(widget.release()); 188 context.SetCentralWidget(widget.release());
121 } 189 }
122 }; 190 };
123 } 191 }
124 } 192 }