Mercurial > hg > orthanc-stone
comparison Framework/Radiography/RadiographyLayerMaskTracker.cpp @ 480:2f6ecb5037ea am-touch-events
added mouse tracker for Layer Mask. Everything seems ok
author | am@osimis.io |
---|---|
date | Thu, 14 Feb 2019 10:18:02 +0100 |
parents | |
children | aede9b042cb7 |
comparison
equal
deleted
inserted
replaced
479:e3d316ba34ba | 480:2f6ecb5037ea |
---|---|
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-2019 Osimis S.A., 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 #include "RadiographyLayerMaskTracker.h" | |
23 #include "RadiographyMaskLayer.h" | |
24 | |
25 #include "RadiographySceneCommand.h" | |
26 | |
27 #include <Core/OrthancException.h> | |
28 | |
29 namespace OrthancStone | |
30 { | |
31 class RadiographyLayerMaskTracker::UndoRedoCommand : public RadiographySceneCommand | |
32 { | |
33 private: | |
34 ControlPoint sourceSceneCp_; | |
35 ControlPoint targetSceneCp_; | |
36 | |
37 protected: | |
38 virtual void UndoInternal(RadiographyLayer& layer) const | |
39 { | |
40 RadiographyMaskLayer* maskLayer = dynamic_cast<RadiographyMaskLayer*>(&layer); | |
41 if (maskLayer == NULL) | |
42 { | |
43 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); | |
44 } | |
45 unsigned int ix, iy; // image coordinates | |
46 if (maskLayer->GetPixel(ix, iy, sourceSceneCp_.x, sourceSceneCp_.y)) | |
47 { | |
48 maskLayer->SetCorner(MaskPoint(ix, iy), sourceSceneCp_.index); | |
49 } | |
50 } | |
51 | |
52 virtual void RedoInternal(RadiographyLayer& layer) const | |
53 { | |
54 RadiographyMaskLayer* maskLayer = dynamic_cast<RadiographyMaskLayer*>(&layer); | |
55 if (maskLayer == NULL) | |
56 { | |
57 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); | |
58 } | |
59 unsigned int ix, iy; // image coordinates | |
60 if (maskLayer->GetPixel(ix, iy, targetSceneCp_.x, targetSceneCp_.y)) | |
61 { | |
62 maskLayer->SetCorner(MaskPoint(ix, iy), targetSceneCp_.index); | |
63 } | |
64 } | |
65 | |
66 public: | |
67 UndoRedoCommand(const RadiographyLayerMaskTracker& tracker) : | |
68 RadiographySceneCommand(tracker.accessor_), | |
69 sourceSceneCp_(tracker.startSceneCp_), | |
70 targetSceneCp_(tracker.endSceneCp_) | |
71 { | |
72 RadiographyMaskLayer* maskLayer = dynamic_cast<RadiographyMaskLayer*>(&(tracker.accessor_.GetLayer())); | |
73 if (maskLayer == NULL) | |
74 { | |
75 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); | |
76 } | |
77 unsigned int ix, iy; // image coordinates | |
78 if (maskLayer->GetPixel(ix, iy, targetSceneCp_.x, targetSceneCp_.y)) | |
79 { | |
80 maskLayer->SetCorner(MaskPoint(ix, iy), targetSceneCp_.index); | |
81 } | |
82 } | |
83 }; | |
84 | |
85 | |
86 RadiographyLayerMaskTracker::RadiographyLayerMaskTracker(UndoRedoStack& undoRedoStack, | |
87 RadiographyScene& scene, | |
88 const ViewportGeometry& view, | |
89 size_t layer, | |
90 const ControlPoint& startSceneControlPoint) : | |
91 undoRedoStack_(undoRedoStack), | |
92 accessor_(scene, layer), | |
93 startSceneCp_(startSceneControlPoint), | |
94 endSceneCp_(startSceneControlPoint) | |
95 { | |
96 } | |
97 | |
98 | |
99 void RadiographyLayerMaskTracker::Render(CairoContext& context, | |
100 double zoom) | |
101 { | |
102 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); | |
103 } | |
104 | |
105 | |
106 void RadiographyLayerMaskTracker::MouseUp() | |
107 { | |
108 if (accessor_.IsValid() && startSceneCp_.x != endSceneCp_.x && startSceneCp_.y != endSceneCp_.y) | |
109 { | |
110 undoRedoStack_.Add(new UndoRedoCommand(*this)); | |
111 } | |
112 } | |
113 | |
114 | |
115 void RadiographyLayerMaskTracker::MouseMove(int displayX, | |
116 int displayY, | |
117 double sceneX, | |
118 double sceneY, | |
119 const std::vector<Touch>& displayTouches, | |
120 const std::vector<Touch>& sceneTouches) | |
121 { | |
122 if (accessor_.IsValid()) | |
123 { | |
124 unsigned int ix, iy; // image coordinates | |
125 | |
126 RadiographyLayer& layer = accessor_.GetLayer(); | |
127 if (layer.GetPixel(ix, iy, sceneX, sceneY)) | |
128 { | |
129 endSceneCp_ = ControlPoint(sceneX, sceneY, startSceneCp_.index); | |
130 | |
131 RadiographyMaskLayer* maskLayer = dynamic_cast<RadiographyMaskLayer*>(&layer); | |
132 if (maskLayer == NULL) | |
133 { | |
134 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); | |
135 } | |
136 maskLayer->SetCorner(MaskPoint(ix, iy), startSceneCp_.index); | |
137 } | |
138 } | |
139 } | |
140 } |