Mercurial > hg > orthanc-stone
annotate OrthancStone/Sources/Scene2D/GrayscaleWindowingSceneTracker.cpp @ 1723:81273beabc9f
refactoring: WebAssemblyOracle::ProcessFetchResult()
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 01 Dec 2020 16:54:01 +0100 |
parents | d4a8e2b19a65 |
children | 9ac2a65d4172 |
rev | line source |
---|---|
1533
82279abb92d0
GrayscaleWindowingSceneTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1 /** |
82279abb92d0
GrayscaleWindowingSceneTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2 * Stone of Orthanc |
82279abb92d0
GrayscaleWindowingSceneTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics |
82279abb92d0
GrayscaleWindowingSceneTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
4 * Department, University Hospital of Liege, Belgium |
82279abb92d0
GrayscaleWindowingSceneTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
5 * Copyright (C) 2017-2020 Osimis S.A., Belgium |
82279abb92d0
GrayscaleWindowingSceneTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
6 * |
82279abb92d0
GrayscaleWindowingSceneTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
7 * This program is free software: you can redistribute it and/or |
1598
8563ea5d8ae4
relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1596
diff
changeset
|
8 * modify it under the terms of the GNU Lesser General Public License |
1533
82279abb92d0
GrayscaleWindowingSceneTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
9 * as published by the Free Software Foundation, either version 3 of |
82279abb92d0
GrayscaleWindowingSceneTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
10 * the License, or (at your option) any later version. |
82279abb92d0
GrayscaleWindowingSceneTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
11 * |
82279abb92d0
GrayscaleWindowingSceneTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
12 * This program is distributed in the hope that it will be useful, but |
82279abb92d0
GrayscaleWindowingSceneTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
13 * WITHOUT ANY WARRANTY; without even the implied warranty of |
1598
8563ea5d8ae4
relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1596
diff
changeset
|
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
8563ea5d8ae4
relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1596
diff
changeset
|
15 * Lesser General Public License for more details. |
1596
4fb8fdf03314
removed annoying whitespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1533
diff
changeset
|
16 * |
1598
8563ea5d8ae4
relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1596
diff
changeset
|
17 * You should have received a copy of the GNU Lesser General Public |
8563ea5d8ae4
relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1596
diff
changeset
|
18 * License along with this program. If not, see |
8563ea5d8ae4
relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1596
diff
changeset
|
19 * <http://www.gnu.org/licenses/>. |
1533
82279abb92d0
GrayscaleWindowingSceneTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
20 **/ |
82279abb92d0
GrayscaleWindowingSceneTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
21 |
82279abb92d0
GrayscaleWindowingSceneTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
22 |
82279abb92d0
GrayscaleWindowingSceneTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
23 #include "GrayscaleWindowingSceneTracker.h" |
82279abb92d0
GrayscaleWindowingSceneTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
24 |
82279abb92d0
GrayscaleWindowingSceneTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
25 #include "../Scene2DViewport/ViewportController.h" |
82279abb92d0
GrayscaleWindowingSceneTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
26 #include "FloatTextureSceneLayer.h" |
82279abb92d0
GrayscaleWindowingSceneTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
27 |
82279abb92d0
GrayscaleWindowingSceneTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
28 #include <OrthancException.h> |
82279abb92d0
GrayscaleWindowingSceneTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
29 |
82279abb92d0
GrayscaleWindowingSceneTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
30 namespace OrthancStone |
82279abb92d0
GrayscaleWindowingSceneTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
31 { |
82279abb92d0
GrayscaleWindowingSceneTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
32 namespace |
82279abb92d0
GrayscaleWindowingSceneTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
33 { |
82279abb92d0
GrayscaleWindowingSceneTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
34 class GrayscaleLayerAccessor : public boost::noncopyable |
82279abb92d0
GrayscaleWindowingSceneTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
35 { |
82279abb92d0
GrayscaleWindowingSceneTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
36 private: |
82279abb92d0
GrayscaleWindowingSceneTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
37 std::unique_ptr<IViewport::ILock> lock_; |
82279abb92d0
GrayscaleWindowingSceneTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
38 FloatTextureSceneLayer* layer_; |
82279abb92d0
GrayscaleWindowingSceneTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
39 |
82279abb92d0
GrayscaleWindowingSceneTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
40 public: |
1606
874e178f34e9
- ViewportController now has weak ptr to Viewport
Benjamin Golinvaux <bgo@osimis.io>
parents:
1598
diff
changeset
|
41 GrayscaleLayerAccessor(boost::weak_ptr<IViewport> viewportWeak, |
1533
82279abb92d0
GrayscaleWindowingSceneTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
42 int layerIndex) : |
82279abb92d0
GrayscaleWindowingSceneTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
43 layer_(NULL) |
82279abb92d0
GrayscaleWindowingSceneTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
44 { |
1606
874e178f34e9
- ViewportController now has weak ptr to Viewport
Benjamin Golinvaux <bgo@osimis.io>
parents:
1598
diff
changeset
|
45 boost::shared_ptr<IViewport> viewport = viewportWeak.lock(); |
1533
82279abb92d0
GrayscaleWindowingSceneTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
46 if (viewport != NULL) |
82279abb92d0
GrayscaleWindowingSceneTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
47 { |
82279abb92d0
GrayscaleWindowingSceneTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
48 lock_.reset(viewport->Lock()); |
82279abb92d0
GrayscaleWindowingSceneTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
49 |
82279abb92d0
GrayscaleWindowingSceneTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
50 if (lock_->GetController().GetScene().HasLayer(layerIndex)) |
82279abb92d0
GrayscaleWindowingSceneTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
51 { |
82279abb92d0
GrayscaleWindowingSceneTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
52 ISceneLayer& layer = lock_->GetController().GetScene().GetLayer(layerIndex); |
82279abb92d0
GrayscaleWindowingSceneTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
53 if (layer.GetType() == ISceneLayer::Type_FloatTexture) |
82279abb92d0
GrayscaleWindowingSceneTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
54 { |
82279abb92d0
GrayscaleWindowingSceneTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
55 layer_ = &dynamic_cast<FloatTextureSceneLayer&>(layer); |
82279abb92d0
GrayscaleWindowingSceneTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
56 } |
82279abb92d0
GrayscaleWindowingSceneTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
57 } |
82279abb92d0
GrayscaleWindowingSceneTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
58 } |
82279abb92d0
GrayscaleWindowingSceneTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
59 } |
82279abb92d0
GrayscaleWindowingSceneTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
60 |
82279abb92d0
GrayscaleWindowingSceneTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
61 bool IsValid() const |
82279abb92d0
GrayscaleWindowingSceneTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
62 { |
82279abb92d0
GrayscaleWindowingSceneTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
63 return layer_ != NULL; |
82279abb92d0
GrayscaleWindowingSceneTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
64 } |
82279abb92d0
GrayscaleWindowingSceneTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
65 |
82279abb92d0
GrayscaleWindowingSceneTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
66 FloatTextureSceneLayer& GetLayer() const |
82279abb92d0
GrayscaleWindowingSceneTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
67 { |
82279abb92d0
GrayscaleWindowingSceneTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
68 if (layer_ == NULL) |
82279abb92d0
GrayscaleWindowingSceneTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
69 { |
82279abb92d0
GrayscaleWindowingSceneTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
70 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); |
82279abb92d0
GrayscaleWindowingSceneTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
71 } |
82279abb92d0
GrayscaleWindowingSceneTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
72 else |
82279abb92d0
GrayscaleWindowingSceneTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
73 { |
82279abb92d0
GrayscaleWindowingSceneTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
74 return *layer_; |
82279abb92d0
GrayscaleWindowingSceneTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
75 } |
82279abb92d0
GrayscaleWindowingSceneTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
76 } |
82279abb92d0
GrayscaleWindowingSceneTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
77 |
82279abb92d0
GrayscaleWindowingSceneTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
78 void Invalidate() |
82279abb92d0
GrayscaleWindowingSceneTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
79 { |
82279abb92d0
GrayscaleWindowingSceneTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
80 if (lock_.get() != NULL) |
82279abb92d0
GrayscaleWindowingSceneTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
81 { |
82279abb92d0
GrayscaleWindowingSceneTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
82 lock_->Invalidate(); |
82279abb92d0
GrayscaleWindowingSceneTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
83 } |
82279abb92d0
GrayscaleWindowingSceneTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
84 } |
1721
d4a8e2b19a65
new "GrayscaleWindowingChanged" message from GrayscaleWindowingSceneTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1639
diff
changeset
|
85 |
d4a8e2b19a65
new "GrayscaleWindowingChanged" message from GrayscaleWindowingSceneTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1639
diff
changeset
|
86 void BroadcastGrayscaleWindowingChanged(double center, |
d4a8e2b19a65
new "GrayscaleWindowingChanged" message from GrayscaleWindowingSceneTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1639
diff
changeset
|
87 double width) |
d4a8e2b19a65
new "GrayscaleWindowingChanged" message from GrayscaleWindowingSceneTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1639
diff
changeset
|
88 { |
d4a8e2b19a65
new "GrayscaleWindowingChanged" message from GrayscaleWindowingSceneTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1639
diff
changeset
|
89 if (lock_.get() != NULL) |
d4a8e2b19a65
new "GrayscaleWindowingChanged" message from GrayscaleWindowingSceneTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1639
diff
changeset
|
90 { |
d4a8e2b19a65
new "GrayscaleWindowingChanged" message from GrayscaleWindowingSceneTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1639
diff
changeset
|
91 lock_->GetController().BroadcastGrayscaleWindowingChanged(center, width); |
d4a8e2b19a65
new "GrayscaleWindowingChanged" message from GrayscaleWindowingSceneTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1639
diff
changeset
|
92 } |
d4a8e2b19a65
new "GrayscaleWindowingChanged" message from GrayscaleWindowingSceneTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1639
diff
changeset
|
93 } |
1533
82279abb92d0
GrayscaleWindowingSceneTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
94 }; |
82279abb92d0
GrayscaleWindowingSceneTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
95 } |
82279abb92d0
GrayscaleWindowingSceneTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
96 |
82279abb92d0
GrayscaleWindowingSceneTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
97 void GrayscaleWindowingSceneTracker::SetWindowing(float center, |
82279abb92d0
GrayscaleWindowingSceneTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
98 float width) |
82279abb92d0
GrayscaleWindowingSceneTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
99 { |
82279abb92d0
GrayscaleWindowingSceneTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
100 if (active_) |
82279abb92d0
GrayscaleWindowingSceneTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
101 { |
1606
874e178f34e9
- ViewportController now has weak ptr to Viewport
Benjamin Golinvaux <bgo@osimis.io>
parents:
1598
diff
changeset
|
102 boost::shared_ptr<IViewport> viewport = viewport_.lock(); |
874e178f34e9
- ViewportController now has weak ptr to Viewport
Benjamin Golinvaux <bgo@osimis.io>
parents:
1598
diff
changeset
|
103 GrayscaleLayerAccessor accessor(viewport, layerIndex_); |
1533
82279abb92d0
GrayscaleWindowingSceneTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
104 |
82279abb92d0
GrayscaleWindowingSceneTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
105 if (accessor.IsValid()) |
82279abb92d0
GrayscaleWindowingSceneTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
106 { |
82279abb92d0
GrayscaleWindowingSceneTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
107 accessor.GetLayer().SetCustomWindowing(center, width); |
1721
d4a8e2b19a65
new "GrayscaleWindowingChanged" message from GrayscaleWindowingSceneTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1639
diff
changeset
|
108 accessor.BroadcastGrayscaleWindowingChanged(center, width); |
1533
82279abb92d0
GrayscaleWindowingSceneTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
109 accessor.Invalidate(); |
82279abb92d0
GrayscaleWindowingSceneTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
110 } |
82279abb92d0
GrayscaleWindowingSceneTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
111 } |
82279abb92d0
GrayscaleWindowingSceneTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
112 } |
82279abb92d0
GrayscaleWindowingSceneTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
113 |
82279abb92d0
GrayscaleWindowingSceneTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
114 |
1606
874e178f34e9
- ViewportController now has weak ptr to Viewport
Benjamin Golinvaux <bgo@osimis.io>
parents:
1598
diff
changeset
|
115 GrayscaleWindowingSceneTracker::GrayscaleWindowingSceneTracker(boost::weak_ptr<IViewport> viewport, |
1533
82279abb92d0
GrayscaleWindowingSceneTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
116 int layerIndex, |
82279abb92d0
GrayscaleWindowingSceneTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
117 const PointerEvent& event, |
82279abb92d0
GrayscaleWindowingSceneTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
118 unsigned int canvasWidth, |
82279abb92d0
GrayscaleWindowingSceneTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
119 unsigned int canvasHeight) : |
82279abb92d0
GrayscaleWindowingSceneTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
120 OneGesturePointerTracker(viewport), |
82279abb92d0
GrayscaleWindowingSceneTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
121 layerIndex_(layerIndex), |
82279abb92d0
GrayscaleWindowingSceneTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
122 clickX_(event.GetMainPosition().GetX()), |
82279abb92d0
GrayscaleWindowingSceneTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
123 clickY_(event.GetMainPosition().GetY()) |
82279abb92d0
GrayscaleWindowingSceneTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
124 { |
82279abb92d0
GrayscaleWindowingSceneTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
125 active_ = false; |
82279abb92d0
GrayscaleWindowingSceneTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
126 |
82279abb92d0
GrayscaleWindowingSceneTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
127 if (canvasWidth > 3 && |
82279abb92d0
GrayscaleWindowingSceneTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
128 canvasHeight > 3) |
82279abb92d0
GrayscaleWindowingSceneTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
129 { |
1639 | 130 boost::shared_ptr<IViewport> locked = viewport_.lock(); |
131 | |
132 if (locked) | |
133 { | |
134 GrayscaleLayerAccessor accessor(locked, layerIndex_); | |
1533
82279abb92d0
GrayscaleWindowingSceneTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
135 |
1639 | 136 if (accessor.IsValid()) |
137 { | |
138 FloatTextureSceneLayer& layer = accessor.GetLayer(); | |
1533
82279abb92d0
GrayscaleWindowingSceneTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
139 |
1639 | 140 layer.GetWindowing(originalCenter_, originalWidth_); |
141 | |
142 float minValue, maxValue; | |
143 layer.GetRange(minValue, maxValue); | |
1533
82279abb92d0
GrayscaleWindowingSceneTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
144 |
1639 | 145 normalization_ = (maxValue - minValue) / static_cast<double>(std::min(canvasWidth, canvasHeight) - 1); |
146 active_ = true; | |
147 } | |
148 else | |
149 { | |
150 LOG(INFO) << "Cannot create GrayscaleWindowingSceneTracker on a non-float texture"; | |
151 } | |
1533
82279abb92d0
GrayscaleWindowingSceneTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
152 } |
82279abb92d0
GrayscaleWindowingSceneTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
153 } |
82279abb92d0
GrayscaleWindowingSceneTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
154 } |
82279abb92d0
GrayscaleWindowingSceneTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
155 |
82279abb92d0
GrayscaleWindowingSceneTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
156 void GrayscaleWindowingSceneTracker::PointerMove(const PointerEvent& event) |
82279abb92d0
GrayscaleWindowingSceneTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
157 { |
82279abb92d0
GrayscaleWindowingSceneTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
158 if (active_) |
82279abb92d0
GrayscaleWindowingSceneTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
159 { |
82279abb92d0
GrayscaleWindowingSceneTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
160 const double x = event.GetMainPosition().GetX(); |
82279abb92d0
GrayscaleWindowingSceneTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
161 const double y = event.GetMainPosition().GetY(); |
82279abb92d0
GrayscaleWindowingSceneTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
162 |
1606
874e178f34e9
- ViewportController now has weak ptr to Viewport
Benjamin Golinvaux <bgo@osimis.io>
parents:
1598
diff
changeset
|
163 float center = originalCenter_ + static_cast<float>((x - clickX_) * normalization_); |
874e178f34e9
- ViewportController now has weak ptr to Viewport
Benjamin Golinvaux <bgo@osimis.io>
parents:
1598
diff
changeset
|
164 float width = originalWidth_ + static_cast<float>((y - clickY_) * normalization_); |
1533
82279abb92d0
GrayscaleWindowingSceneTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
165 |
82279abb92d0
GrayscaleWindowingSceneTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
166 if (width <= 1) |
82279abb92d0
GrayscaleWindowingSceneTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
167 { |
82279abb92d0
GrayscaleWindowingSceneTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
168 width = 1; |
82279abb92d0
GrayscaleWindowingSceneTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
169 } |
82279abb92d0
GrayscaleWindowingSceneTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
170 |
82279abb92d0
GrayscaleWindowingSceneTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
171 SetWindowing(center, width); |
82279abb92d0
GrayscaleWindowingSceneTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
172 } |
82279abb92d0
GrayscaleWindowingSceneTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
173 } |
82279abb92d0
GrayscaleWindowingSceneTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
174 |
82279abb92d0
GrayscaleWindowingSceneTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
175 void GrayscaleWindowingSceneTracker::Cancel() |
82279abb92d0
GrayscaleWindowingSceneTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
176 { |
82279abb92d0
GrayscaleWindowingSceneTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
177 SetWindowing(originalCenter_, originalWidth_); |
82279abb92d0
GrayscaleWindowingSceneTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
178 } |
82279abb92d0
GrayscaleWindowingSceneTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
179 } |