Mercurial > hg > orthanc-stone
comparison Framework/Radiography/RadiographyLayerCropTracker.cpp @ 415:c0589c3173fd
finished reorganization
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 13 Nov 2018 10:36:53 +0100 |
parents | |
children | b85f635f1eb5 b70e9be013e4 |
comparison
equal
deleted
inserted
replaced
414:f7616c010056 | 415:c0589c3173fd |
---|---|
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-2018 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 "RadiographyLayerCropTracker.h" | |
23 | |
24 #include "RadiographySceneCommand.h" | |
25 | |
26 #include <Core/OrthancException.h> | |
27 | |
28 namespace OrthancStone | |
29 { | |
30 class RadiographyLayerCropTracker::UndoRedoCommand : public RadiographySceneCommand | |
31 { | |
32 private: | |
33 unsigned int sourceCropX_; | |
34 unsigned int sourceCropY_; | |
35 unsigned int sourceCropWidth_; | |
36 unsigned int sourceCropHeight_; | |
37 unsigned int targetCropX_; | |
38 unsigned int targetCropY_; | |
39 unsigned int targetCropWidth_; | |
40 unsigned int targetCropHeight_; | |
41 | |
42 protected: | |
43 virtual void UndoInternal(RadiographyLayer& layer) const | |
44 { | |
45 layer.SetCrop(sourceCropX_, sourceCropY_, sourceCropWidth_, sourceCropHeight_); | |
46 } | |
47 | |
48 virtual void RedoInternal(RadiographyLayer& layer) const | |
49 { | |
50 layer.SetCrop(targetCropX_, targetCropY_, targetCropWidth_, targetCropHeight_); | |
51 } | |
52 | |
53 public: | |
54 UndoRedoCommand(const RadiographyLayerCropTracker& tracker) : | |
55 RadiographySceneCommand(tracker.accessor_), | |
56 sourceCropX_(tracker.cropX_), | |
57 sourceCropY_(tracker.cropY_), | |
58 sourceCropWidth_(tracker.cropWidth_), | |
59 sourceCropHeight_(tracker.cropHeight_) | |
60 { | |
61 tracker.accessor_.GetLayer().GetCrop(targetCropX_, targetCropY_, | |
62 targetCropWidth_, targetCropHeight_); | |
63 } | |
64 }; | |
65 | |
66 | |
67 RadiographyLayerCropTracker::RadiographyLayerCropTracker(UndoRedoStack& undoRedoStack, | |
68 RadiographyScene& scene, | |
69 const ViewportGeometry& view, | |
70 size_t layer, | |
71 double x, | |
72 double y, | |
73 Corner corner) : | |
74 undoRedoStack_(undoRedoStack), | |
75 accessor_(scene, layer), | |
76 corner_(corner) | |
77 { | |
78 if (accessor_.IsValid()) | |
79 { | |
80 accessor_.GetLayer().GetCrop(cropX_, cropY_, cropWidth_, cropHeight_); | |
81 } | |
82 } | |
83 | |
84 | |
85 void RadiographyLayerCropTracker::Render(CairoContext& context, | |
86 double zoom) | |
87 { | |
88 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); | |
89 } | |
90 | |
91 | |
92 void RadiographyLayerCropTracker::MouseUp() | |
93 { | |
94 if (accessor_.IsValid()) | |
95 { | |
96 undoRedoStack_.Add(new UndoRedoCommand(*this)); | |
97 } | |
98 } | |
99 | |
100 | |
101 void RadiographyLayerCropTracker::MouseMove(int displayX, | |
102 int displayY, | |
103 double sceneX, | |
104 double sceneY) | |
105 { | |
106 if (accessor_.IsValid()) | |
107 { | |
108 unsigned int x, y; | |
109 | |
110 RadiographyLayer& layer = accessor_.GetLayer(); | |
111 if (layer.GetPixel(x, y, sceneX, sceneY)) | |
112 { | |
113 unsigned int targetX, targetWidth; | |
114 | |
115 if (corner_ == Corner_TopLeft || | |
116 corner_ == Corner_BottomLeft) | |
117 { | |
118 targetX = std::min(x, cropX_ + cropWidth_); | |
119 targetWidth = cropX_ + cropWidth_ - targetX; | |
120 } | |
121 else | |
122 { | |
123 targetX = cropX_; | |
124 targetWidth = std::max(x, cropX_) - cropX_; | |
125 } | |
126 | |
127 unsigned int targetY, targetHeight; | |
128 | |
129 if (corner_ == Corner_TopLeft || | |
130 corner_ == Corner_TopRight) | |
131 { | |
132 targetY = std::min(y, cropY_ + cropHeight_); | |
133 targetHeight = cropY_ + cropHeight_ - targetY; | |
134 } | |
135 else | |
136 { | |
137 targetY = cropY_; | |
138 targetHeight = std::max(y, cropY_) - cropY_; | |
139 } | |
140 | |
141 layer.SetCrop(targetX, targetY, targetWidth, targetHeight); | |
142 } | |
143 } | |
144 } | |
145 } |