annotate Framework/Radiography/RadiographyLayerRotateTracker.cpp @ 1116:a08699daf78b broker

ParsedDicomFileCache
author Sebastien Jodogne <s.jodogne@gmail.com>
date Mon, 04 Nov 2019 15:54:35 +0100
parents 4f2416d519b4
children 2d8ab34c8c91
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
414
f7616c010056 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 /**
f7616c010056 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2 * Stone of Orthanc
f7616c010056 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
f7616c010056 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: 414
diff changeset
5 * Copyright (C) 2017-2019 Osimis S.A., Belgium
414
f7616c010056 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
6 *
f7616c010056 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 * This program is free software: you can redistribute it and/or
f7616c010056 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 * modify it under the terms of the GNU Affero General Public License
f7616c010056 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 * as published by the Free Software Foundation, either version 3 of
f7616c010056 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 * the License, or (at your option) any later version.
f7616c010056 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 *
f7616c010056 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 * This program is distributed in the hope that it will be useful, but
f7616c010056 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
f7616c010056 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
f7616c010056 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 * Affero General Public License for more details.
f7616c010056 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16 *
f7616c010056 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
17 * You should have received a copy of the GNU Affero General Public License
f7616c010056 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
f7616c010056 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
19 **/
f7616c010056 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20
f7616c010056 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21
f7616c010056 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22 #include "RadiographyLayerRotateTracker.h"
f7616c010056 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23
f7616c010056 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24 #include "RadiographySceneCommand.h"
f7616c010056 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25
f7616c010056 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26 #include <Core/OrthancException.h>
f7616c010056 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27
f7616c010056 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28 #include <boost/math/constants/constants.hpp>
f7616c010056 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29 #include <boost/math/special_functions/round.hpp>
f7616c010056 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30
f7616c010056 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31 namespace OrthancStone
f7616c010056 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32 {
f7616c010056 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
33 class RadiographyLayerRotateTracker::UndoRedoCommand : public RadiographySceneCommand
f7616c010056 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34 {
f7616c010056 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35 private:
f7616c010056 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
36 double sourceAngle_;
f7616c010056 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
37 double targetAngle_;
f7616c010056 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
38
f7616c010056 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
39 static int ToDegrees(double angle)
f7616c010056 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
40 {
f7616c010056 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
41 return boost::math::iround(angle * 180.0 / boost::math::constants::pi<double>());
f7616c010056 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
42 }
f7616c010056 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
43
f7616c010056 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
44 protected:
f7616c010056 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
45 virtual void UndoInternal(RadiographyLayer& layer) const
f7616c010056 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
46 {
f7616c010056 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
47 LOG(INFO) << "Undo - Set angle to " << ToDegrees(sourceAngle_) << " degrees";
f7616c010056 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
48 layer.SetAngle(sourceAngle_);
f7616c010056 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
49 }
f7616c010056 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
50
f7616c010056 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
51 virtual void RedoInternal(RadiographyLayer& layer) const
f7616c010056 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
52 {
f7616c010056 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
53 LOG(INFO) << "Redo - Set angle to " << ToDegrees(sourceAngle_) << " degrees";
f7616c010056 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
54 layer.SetAngle(targetAngle_);
f7616c010056 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
55 }
f7616c010056 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
56
f7616c010056 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
57 public:
f7616c010056 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
58 UndoRedoCommand(const RadiographyLayerRotateTracker& tracker) :
f7616c010056 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
59 RadiographySceneCommand(tracker.accessor_),
f7616c010056 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
60 sourceAngle_(tracker.originalAngle_),
430
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents: 414
diff changeset
61 targetAngle_(tracker.accessor_.GetLayer().GetGeometry().GetAngle())
414
f7616c010056 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
62 {
f7616c010056 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
63 }
f7616c010056 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
64 };
f7616c010056 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
65
f7616c010056 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
66
f7616c010056 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
67 bool RadiographyLayerRotateTracker::ComputeAngle(double& angle /* out */,
f7616c010056 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
68 double sceneX,
f7616c010056 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
69 double sceneY) const
f7616c010056 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
70 {
f7616c010056 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
71 Vector u;
f7616c010056 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
72 LinearAlgebra::AssignVector(u, sceneX - centerX_, sceneY - centerY_);
f7616c010056 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
73
f7616c010056 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
74 double nu = boost::numeric::ublas::norm_2(u);
f7616c010056 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
75
f7616c010056 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
76 if (!LinearAlgebra::IsCloseToZero(nu))
f7616c010056 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
77 {
f7616c010056 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
78 u /= nu;
f7616c010056 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
79 angle = atan2(u[1], u[0]);
f7616c010056 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
80 return true;
f7616c010056 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
81 }
f7616c010056 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
82 else
f7616c010056 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
83 {
f7616c010056 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
84 return false;
f7616c010056 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
85 }
f7616c010056 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
86 }
f7616c010056 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
87
f7616c010056 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
88
f7616c010056 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
89 RadiographyLayerRotateTracker::RadiographyLayerRotateTracker(UndoRedoStack& undoRedoStack,
f7616c010056 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
90 RadiographyScene& scene,
726
4f2416d519b4 moving layers, widgets and loaders to Deprecated namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 457
diff changeset
91 const Deprecated::ViewportGeometry& view,
414
f7616c010056 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
92 size_t layer,
f7616c010056 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
93 double x,
f7616c010056 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
94 double y,
f7616c010056 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
95 bool roundAngles) :
f7616c010056 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
96 undoRedoStack_(undoRedoStack),
f7616c010056 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
97 accessor_(scene, layer),
f7616c010056 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
98 roundAngles_(roundAngles)
f7616c010056 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
99 {
f7616c010056 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
100 if (accessor_.IsValid())
f7616c010056 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
101 {
f7616c010056 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
102 accessor_.GetLayer().GetCenter(centerX_, centerY_);
430
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents: 414
diff changeset
103 originalAngle_ = accessor_.GetLayer().GetGeometry().GetAngle();
414
f7616c010056 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
104
f7616c010056 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
105 double sceneX, sceneY;
f7616c010056 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
106 view.MapDisplayToScene(sceneX, sceneY, x, y);
f7616c010056 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
107
f7616c010056 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
108 if (!ComputeAngle(clickAngle_, x, y))
f7616c010056 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
109 {
f7616c010056 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
110 accessor_.Invalidate();
f7616c010056 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
111 }
f7616c010056 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
112 }
f7616c010056 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
113 }
f7616c010056 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
114
f7616c010056 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
115
f7616c010056 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
116 void RadiographyLayerRotateTracker::Render(CairoContext& context,
f7616c010056 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
117 double zoom)
f7616c010056 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
118 {
f7616c010056 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
119 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError);
f7616c010056 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
120 }
f7616c010056 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
121
f7616c010056 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
122
f7616c010056 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
123 void RadiographyLayerRotateTracker::MouseUp()
f7616c010056 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
124 {
f7616c010056 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
125 if (accessor_.IsValid())
f7616c010056 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
126 {
f7616c010056 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
127 undoRedoStack_.Add(new UndoRedoCommand(*this));
f7616c010056 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
128 }
f7616c010056 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
129 }
f7616c010056 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
130
f7616c010056 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
131
f7616c010056 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
132 void RadiographyLayerRotateTracker::MouseMove(int displayX,
f7616c010056 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
133 int displayY,
f7616c010056 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
134 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
135 double sceneY,
726
4f2416d519b4 moving layers, widgets and loaders to Deprecated namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 457
diff changeset
136 const std::vector<Deprecated::Touch>& displayTouches,
4f2416d519b4 moving layers, widgets and loaders to Deprecated namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 457
diff changeset
137 const std::vector<Deprecated::Touch>& sceneTouches)
414
f7616c010056 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
138 {
f7616c010056 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
139 static const double ROUND_ANGLE = 15.0 / 180.0 * boost::math::constants::pi<double>();
f7616c010056 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
140
f7616c010056 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
141 double angle;
f7616c010056 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
142
f7616c010056 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
143 if (accessor_.IsValid() &&
f7616c010056 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
144 ComputeAngle(angle, sceneX, sceneY))
f7616c010056 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
145 {
f7616c010056 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
146 angle = angle - clickAngle_ + originalAngle_;
f7616c010056 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
147
f7616c010056 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
148 if (roundAngles_)
f7616c010056 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
149 {
f7616c010056 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
150 angle = boost::math::round<double>((angle / ROUND_ANGLE) * ROUND_ANGLE);
f7616c010056 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
151 }
f7616c010056 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
152
f7616c010056 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
153 accessor_.GetLayer().SetAngle(angle);
f7616c010056 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
154 }
f7616c010056 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
155 }
f7616c010056 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
156 }