comparison OrthancStone/Sources/Deprecated/Radiography/RadiographyLayerCropTracker.cpp @ 1512:244ad1e4e76a

reorganization of folders
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 07 Jul 2020 16:21:02 +0200
parents Framework/Deprecated/Radiography/RadiographyLayerCropTracker.cpp@30deba7bc8e2
children
comparison
equal deleted inserted replaced
1511:9dfeee74c1e6 1512:244ad1e4e76a
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-2020 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 <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 Deprecated::ViewportGeometry& view,
70 size_t layer,
71 const ControlPoint& startControlPoint) :
72 undoRedoStack_(undoRedoStack),
73 accessor_(scene, layer),
74 startControlPoint_(startControlPoint)
75 {
76 if (accessor_.IsValid())
77 {
78 accessor_.GetLayer().GetCrop(cropX_, cropY_, cropWidth_, cropHeight_);
79 }
80 }
81
82
83 void RadiographyLayerCropTracker::Render(CairoContext& context,
84 double zoom)
85 {
86 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError);
87 }
88
89
90 void RadiographyLayerCropTracker::MouseUp()
91 {
92 if (accessor_.IsValid())
93 {
94 undoRedoStack_.Add(new UndoRedoCommand(*this));
95 }
96 }
97
98
99 void RadiographyLayerCropTracker::MouseMove(int displayX,
100 int displayY,
101 double sceneX,
102 double sceneY,
103 const std::vector<Deprecated::Touch>& displayTouches,
104 const std::vector<Deprecated::Touch>& sceneTouches)
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 (startControlPoint_.index == RadiographyControlPointType_TopLeftCorner ||
116 startControlPoint_.index == RadiographyControlPointType_BottomLeftCorner)
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 (startControlPoint_.index == RadiographyControlPointType_TopLeftCorner ||
130 startControlPoint_.index == RadiographyControlPointType_TopRightCorner)
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 }