annotate Framework/Radiography/RadiographyLayerCropTracker.cpp @ 621:8adc8cfb50c7

fix
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 07 May 2019 11:59:46 +0200
parents a95090305dd4
children 4f2416d519b4
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
415
c0589c3173fd finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 /**
c0589c3173fd finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2 * Stone of Orthanc
c0589c3173fd finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
c0589c3173fd finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
4 * Department, University Hospital of Liege, Belgium
439
b70e9be013e4 preparing for 2019
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 415
diff changeset
5 * Copyright (C) 2017-2019 Osimis S.A., Belgium
415
c0589c3173fd finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
6 *
c0589c3173fd finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 * This program is free software: you can redistribute it and/or
c0589c3173fd finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 * modify it under the terms of the GNU Affero General Public License
c0589c3173fd finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 * as published by the Free Software Foundation, either version 3 of
c0589c3173fd finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 * the License, or (at your option) any later version.
c0589c3173fd finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 *
c0589c3173fd finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 * This program is distributed in the hope that it will be useful, but
c0589c3173fd finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
c0589c3173fd finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
c0589c3173fd finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 * Affero General Public License for more details.
c0589c3173fd finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16 *
c0589c3173fd finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
17 * You should have received a copy of the GNU Affero General Public License
c0589c3173fd finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
c0589c3173fd finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
19 **/
c0589c3173fd finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20
c0589c3173fd finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21
c0589c3173fd finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22 #include "RadiographyLayerCropTracker.h"
c0589c3173fd finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23
c0589c3173fd finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24 #include "RadiographySceneCommand.h"
c0589c3173fd finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25
c0589c3173fd finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26 #include <Core/OrthancException.h>
c0589c3173fd finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27
c0589c3173fd finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28 namespace OrthancStone
c0589c3173fd finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29 {
c0589c3173fd finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30 class RadiographyLayerCropTracker::UndoRedoCommand : public RadiographySceneCommand
c0589c3173fd finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31 {
c0589c3173fd finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32 private:
c0589c3173fd finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
33 unsigned int sourceCropX_;
c0589c3173fd finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34 unsigned int sourceCropY_;
c0589c3173fd finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35 unsigned int sourceCropWidth_;
c0589c3173fd finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
36 unsigned int sourceCropHeight_;
c0589c3173fd finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
37 unsigned int targetCropX_;
c0589c3173fd finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
38 unsigned int targetCropY_;
c0589c3173fd finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
39 unsigned int targetCropWidth_;
c0589c3173fd finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
40 unsigned int targetCropHeight_;
c0589c3173fd finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
41
c0589c3173fd finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
42 protected:
c0589c3173fd finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
43 virtual void UndoInternal(RadiographyLayer& layer) const
c0589c3173fd finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
44 {
c0589c3173fd finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
45 layer.SetCrop(sourceCropX_, sourceCropY_, sourceCropWidth_, sourceCropHeight_);
c0589c3173fd finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
46 }
c0589c3173fd finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
47
c0589c3173fd finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
48 virtual void RedoInternal(RadiographyLayer& layer) const
c0589c3173fd finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
49 {
c0589c3173fd finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
50 layer.SetCrop(targetCropX_, targetCropY_, targetCropWidth_, targetCropHeight_);
c0589c3173fd finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
51 }
c0589c3173fd finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
52
c0589c3173fd finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
53 public:
c0589c3173fd finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
54 UndoRedoCommand(const RadiographyLayerCropTracker& tracker) :
c0589c3173fd finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
55 RadiographySceneCommand(tracker.accessor_),
c0589c3173fd finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
56 sourceCropX_(tracker.cropX_),
c0589c3173fd finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
57 sourceCropY_(tracker.cropY_),
c0589c3173fd finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
58 sourceCropWidth_(tracker.cropWidth_),
c0589c3173fd finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
59 sourceCropHeight_(tracker.cropHeight_)
c0589c3173fd finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
60 {
c0589c3173fd finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
61 tracker.accessor_.GetLayer().GetCrop(targetCropX_, targetCropY_,
c0589c3173fd finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
62 targetCropWidth_, targetCropHeight_);
c0589c3173fd finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
63 }
c0589c3173fd finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
64 };
c0589c3173fd finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
65
c0589c3173fd finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
66
c0589c3173fd finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
67 RadiographyLayerCropTracker::RadiographyLayerCropTracker(UndoRedoStack& undoRedoStack,
c0589c3173fd finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
68 RadiographyScene& scene,
c0589c3173fd finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
69 const ViewportGeometry& view,
c0589c3173fd finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
70 size_t layer,
476
a95090305dd4 Introduced ControlPoint instead of Corner in the trackers and layers + drawing mask from the ControlPoints
am@osimis.io
parents: 457
diff changeset
71 const ControlPoint& startControlPoint) :
415
c0589c3173fd finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
72 undoRedoStack_(undoRedoStack),
c0589c3173fd finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
73 accessor_(scene, layer),
476
a95090305dd4 Introduced ControlPoint instead of Corner in the trackers and layers + drawing mask from the ControlPoints
am@osimis.io
parents: 457
diff changeset
74 startControlPoint_(startControlPoint)
415
c0589c3173fd finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
75 {
c0589c3173fd finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
76 if (accessor_.IsValid())
c0589c3173fd finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
77 {
436
04711a2e12cd fix crop + export photometric interpretation correctly
am@osimis.io
parents: 430
diff changeset
78 accessor_.GetLayer().GetCrop(cropX_, cropY_, cropWidth_, cropHeight_);
415
c0589c3173fd finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
79 }
c0589c3173fd finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
80 }
c0589c3173fd finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
81
c0589c3173fd finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
82
c0589c3173fd finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
83 void RadiographyLayerCropTracker::Render(CairoContext& context,
c0589c3173fd finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
84 double zoom)
c0589c3173fd finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
85 {
c0589c3173fd finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
86 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError);
c0589c3173fd finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
87 }
c0589c3173fd finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
88
c0589c3173fd finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
89
c0589c3173fd finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
90 void RadiographyLayerCropTracker::MouseUp()
c0589c3173fd finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
91 {
c0589c3173fd finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
92 if (accessor_.IsValid())
c0589c3173fd finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
93 {
c0589c3173fd finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
94 undoRedoStack_.Add(new UndoRedoCommand(*this));
c0589c3173fd finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
95 }
c0589c3173fd finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
96 }
c0589c3173fd finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
97
c0589c3173fd finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
98
c0589c3173fd finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
99 void RadiographyLayerCropTracker::MouseMove(int displayX,
c0589c3173fd finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
100 int displayY,
c0589c3173fd finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
101 double sceneX,
457
3b4df9925db6 added support for 'touch' in mouse trackers. This is still a bit hacky and we need to refactor it to make it clean. Thanks to that, Pan and zoom are available together with 2 touches
Alain Mazy <alain@mazy.be>
parents: 440
diff changeset
102 double sceneY,
3b4df9925db6 added support for 'touch' in mouse trackers. This is still a bit hacky and we need to refactor it to make it clean. Thanks to that, Pan and zoom are available together with 2 touches
Alain Mazy <alain@mazy.be>
parents: 440
diff changeset
103 const std::vector<Touch>& displayTouches,
3b4df9925db6 added support for 'touch' in mouse trackers. This is still a bit hacky and we need to refactor it to make it clean. Thanks to that, Pan and zoom are available together with 2 touches
Alain Mazy <alain@mazy.be>
parents: 440
diff changeset
104 const std::vector<Touch>& sceneTouches)
415
c0589c3173fd finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
105 {
c0589c3173fd finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
106 if (accessor_.IsValid())
c0589c3173fd finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
107 {
c0589c3173fd finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
108 unsigned int x, y;
c0589c3173fd finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
109
c0589c3173fd finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
110 RadiographyLayer& layer = accessor_.GetLayer();
c0589c3173fd finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
111 if (layer.GetPixel(x, y, sceneX, sceneY))
c0589c3173fd finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
112 {
c0589c3173fd finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
113 unsigned int targetX, targetWidth;
c0589c3173fd finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
114
476
a95090305dd4 Introduced ControlPoint instead of Corner in the trackers and layers + drawing mask from the ControlPoints
am@osimis.io
parents: 457
diff changeset
115 if (startControlPoint_.index == ControlPoint_TopLeftCorner ||
a95090305dd4 Introduced ControlPoint instead of Corner in the trackers and layers + drawing mask from the ControlPoints
am@osimis.io
parents: 457
diff changeset
116 startControlPoint_.index == ControlPoint_BottomLeftCorner)
415
c0589c3173fd finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
117 {
c0589c3173fd finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
118 targetX = std::min(x, cropX_ + cropWidth_);
c0589c3173fd finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
119 targetWidth = cropX_ + cropWidth_ - targetX;
c0589c3173fd finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
120 }
c0589c3173fd finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
121 else
c0589c3173fd finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
122 {
c0589c3173fd finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
123 targetX = cropX_;
c0589c3173fd finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
124 targetWidth = std::max(x, cropX_) - cropX_;
c0589c3173fd finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
125 }
c0589c3173fd finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
126
c0589c3173fd finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
127 unsigned int targetY, targetHeight;
c0589c3173fd finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
128
476
a95090305dd4 Introduced ControlPoint instead of Corner in the trackers and layers + drawing mask from the ControlPoints
am@osimis.io
parents: 457
diff changeset
129 if (startControlPoint_.index == ControlPoint_TopLeftCorner ||
a95090305dd4 Introduced ControlPoint instead of Corner in the trackers and layers + drawing mask from the ControlPoints
am@osimis.io
parents: 457
diff changeset
130 startControlPoint_.index == ControlPoint_TopRightCorner)
415
c0589c3173fd finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
131 {
c0589c3173fd finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
132 targetY = std::min(y, cropY_ + cropHeight_);
c0589c3173fd finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
133 targetHeight = cropY_ + cropHeight_ - targetY;
c0589c3173fd finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
134 }
c0589c3173fd finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
135 else
c0589c3173fd finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
136 {
c0589c3173fd finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
137 targetY = cropY_;
c0589c3173fd finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
138 targetHeight = std::max(y, cropY_) - cropY_;
c0589c3173fd finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
139 }
c0589c3173fd finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
140
c0589c3173fd finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
141 layer.SetCrop(targetX, targetY, targetWidth, targetHeight);
c0589c3173fd finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
142 }
c0589c3173fd finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
143 }
c0589c3173fd finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
144 }
c0589c3173fd finished reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
145 }