comparison Applications/Samples/SampleInteractor.h @ 51:b340879da9bd

reorganization
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 27 Apr 2017 14:50:20 +0200
parents Samples/SampleInteractor.h@28956ed68280
children 01aa453d4d5b 4cff7b1ed31d
comparison
equal deleted inserted replaced
49:c45f368de5c0 51:b340879da9bd
1 /**
2 * Stone of Orthanc
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
4 * Department, University Hospital of Liege, Belgium
5 * Copyright (C) 2017 Osimis, Belgium
6 *
7 * This program is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU Affero General Public License
9 * as published by the Free Software Foundation, either version 3 of
10 * the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Affero General Public License for more details.
16 *
17 * You should have received a copy of the GNU Affero General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 **/
20
21
22 #pragma once
23
24 #include "SampleApplicationBase.h"
25
26 #include "../../Framework/Widgets/LayeredSceneWidget.h"
27 #include "../../Framework/Widgets/IWorldSceneInteractor.h"
28 #include "../../Framework/Toolbox/ParallelSlicesCursor.h"
29
30 namespace OrthancStone
31 {
32 namespace Samples
33 {
34 /**
35 * This is a basic mouse interactor for sample applications. It
36 * contains a set of parallel slices in the 3D space. The mouse
37 * wheel events make the widget change the slice that is
38 * displayed.
39 **/
40 class SampleInteractor : public IWorldSceneInteractor
41 {
42 private:
43 ParallelSlicesCursor cursor_;
44
45 public:
46 SampleInteractor(VolumeImage& volume,
47 VolumeProjection projection,
48 bool reverse)
49 {
50 std::auto_ptr<ParallelSlices> slices(volume.GetGeometry(projection, reverse));
51 cursor_.SetGeometry(*slices);
52 }
53
54 SampleInteractor(ISeriesLoader& series,
55 bool reverse)
56 {
57 if (reverse)
58 {
59 std::auto_ptr<ParallelSlices> slices(series.GetGeometry().Reverse());
60 cursor_.SetGeometry(*slices);
61 }
62 else
63 {
64 cursor_.SetGeometry(series.GetGeometry());
65 }
66 }
67
68 SampleInteractor(const ParallelSlices& slices)
69 {
70 cursor_.SetGeometry(slices);
71 }
72
73 ParallelSlicesCursor& GetCursor()
74 {
75 return cursor_;
76 }
77
78 void AddWidget(LayeredSceneWidget& widget)
79 {
80 widget.SetInteractor(*this);
81 widget.SetSlice(cursor_.GetCurrentSlice());
82 }
83
84 virtual IWorldSceneMouseTracker* CreateMouseTracker(WorldSceneWidget& widget,
85 const SliceGeometry& slice,
86 const ViewportGeometry& view,
87 MouseButton button,
88 double x,
89 double y,
90 IStatusBar* statusBar)
91 {
92 return NULL;
93 }
94
95 virtual void MouseOver(CairoContext& context,
96 WorldSceneWidget& widget,
97 const SliceGeometry& slice,
98 const ViewportGeometry& view,
99 double x,
100 double y,
101 IStatusBar* statusBar)
102 {
103 }
104
105 virtual void MouseWheel(WorldSceneWidget& widget,
106 MouseWheelDirection direction,
107 KeyboardModifiers modifiers,
108 IStatusBar* statusBar)
109 {
110 if (cursor_.ApplyWheelEvent(direction, modifiers))
111 {
112 dynamic_cast<LayeredSceneWidget&>(widget).SetSlice(cursor_.GetCurrentSlice());
113 }
114 }
115
116 virtual void KeyPressed(WorldSceneWidget& widget,
117 char key,
118 KeyboardModifiers modifiers,
119 IStatusBar* statusBar)
120 {
121 }
122
123 void LookupSliceContainingPoint(LayeredSceneWidget& widget,
124 const Vector& p)
125 {
126 if (cursor_.LookupSliceContainingPoint(p))
127 {
128 widget.SetSlice(cursor_.GetCurrentSlice());
129 }
130 }
131 };
132 }
133 }