annotate Framework/Deprecated/Toolbox/ViewportGeometry.cpp @ 732:c35e98d22764

move Deprecated classes to a separate folder
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 21 May 2019 14:27:35 +0200
parents Framework/Toolbox/ViewportGeometry.cpp@4f2416d519b4
children d33ae2b0db9d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 /**
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2 * Stone of Orthanc
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
351ab0da0150 initial commit
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: 340
diff changeset
5 * Copyright (C) 2017-2019 Osimis S.A., Belgium
0
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
6 *
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 * This program is free software: you can redistribute it and/or
47
28956ed68280 agpl license
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 40
diff changeset
8 * modify it under the terms of the GNU Affero General Public License
28956ed68280 agpl license
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 40
diff changeset
9 * as published by the Free Software Foundation, either version 3 of
28956ed68280 agpl license
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 40
diff changeset
10 * the License, or (at your option) any later version.
0
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 *
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 * This program is distributed in the hope that it will be useful, but
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
47
28956ed68280 agpl license
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 40
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
28956ed68280 agpl license
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 40
diff changeset
15 * Affero General Public License for more details.
28956ed68280 agpl license
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 40
diff changeset
16 *
28956ed68280 agpl license
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 40
diff changeset
17 * You should have received a copy of the GNU Affero General Public License
0
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
19 **/
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22 #include "ViewportGeometry.h"
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23
212
5412adf19980 resort to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 201
diff changeset
24 #include <Core/Logging.h>
5412adf19980 resort to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 201
diff changeset
25 #include <Core/OrthancException.h>
0
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27 #include <boost/math/special_functions/round.hpp>
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28
726
4f2416d519b4 moving layers, widgets and loaders to Deprecated namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 693
diff changeset
29 namespace Deprecated
0
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30 {
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31 void ViewportGeometry::ComputeTransform()
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32 {
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
33 // The following lines must be read in reverse order!
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34 cairo_matrix_t tmp;
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
36 // Bring the center of the scene to the center of the view
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
37 cairo_matrix_init_translate(&transform_,
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
38 panX_ + static_cast<double>(width_) / 2.0,
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
39 panY_ + static_cast<double>(height_) / 2.0);
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
40
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
41 // Apply the zoom around (0,0)
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
42 cairo_matrix_init_scale(&tmp, zoom_, zoom_);
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
43 cairo_matrix_multiply(&transform_, &tmp, &transform_);
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
44
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
45 // Bring the center of the scene to (0,0)
109
53bd9277b025 using the Extent class
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 47
diff changeset
46 cairo_matrix_init_translate(&tmp,
53bd9277b025 using the Extent class
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 47
diff changeset
47 -(sceneExtent_.GetX1() + sceneExtent_.GetX2()) / 2.0,
53bd9277b025 using the Extent class
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 47
diff changeset
48 -(sceneExtent_.GetY1() + sceneExtent_.GetY2()) / 2.0);
0
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
49 cairo_matrix_multiply(&transform_, &tmp, &transform_);
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
50 }
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
51
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
52
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
53 ViewportGeometry::ViewportGeometry()
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
54 {
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
55 width_ = 0;
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
56 height_ = 0;
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
57
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
58 zoom_ = 1;
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
59 panX_ = 0;
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
60 panY_ = 0;
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
61
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
62 ComputeTransform();
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
63 }
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
64
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
65
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
66 void ViewportGeometry::SetDisplaySize(unsigned int width,
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
67 unsigned int height)
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
68 {
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
69 if (width_ != width ||
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
70 height_ != height)
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
71 {
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
72 LOG(INFO) << "New display size: " << width << "x" << height;
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
73
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
74 width_ = width;
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
75 height_ = height;
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
76
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
77 ComputeTransform();
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
78 }
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
79 }
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
80
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
81
726
4f2416d519b4 moving layers, widgets and loaders to Deprecated namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 693
diff changeset
82 void ViewportGeometry::SetSceneExtent(const OrthancStone::Extent2D& extent)
0
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
83 {
109
53bd9277b025 using the Extent class
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 47
diff changeset
84 LOG(INFO) << "New scene extent: ("
53bd9277b025 using the Extent class
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 47
diff changeset
85 << extent.GetX1() << "," << extent.GetY1() << ") => ("
53bd9277b025 using the Extent class
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 47
diff changeset
86 << extent.GetX2() << "," << extent.GetY2() << ")";
0
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
87
109
53bd9277b025 using the Extent class
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 47
diff changeset
88 sceneExtent_ = extent;
53bd9277b025 using the Extent class
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 47
diff changeset
89 ComputeTransform();
0
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
90 }
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
91
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
92
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
93 void ViewportGeometry::MapDisplayToScene(double& sceneX /* out */,
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
94 double& sceneY /* out */,
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
95 double x,
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
96 double y) const
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
97 {
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
98 cairo_matrix_t transform = transform_;
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
99
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
100 if (cairo_matrix_invert(&transform) != CAIRO_STATUS_SUCCESS)
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
101 {
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
102 LOG(ERROR) << "Cannot invert singular matrix";
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
103 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError);
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
104 }
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
105
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
106 sceneX = x;
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
107 sceneY = y;
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
108 cairo_matrix_transform_point(&transform, &sceneX, &sceneY);
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
109 }
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
110
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
111
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
112 void ViewportGeometry::MapSceneToDisplay(int& displayX /* out */,
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
113 int& displayY /* out */,
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
114 double x,
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
115 double y) const
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
116 {
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
117 cairo_matrix_transform_point(&transform_, &x, &y);
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
118
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
119 displayX = static_cast<int>(boost::math::iround(x));
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
120 displayY = static_cast<int>(boost::math::iround(y));
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
121 }
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
122
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
123
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: 439
diff changeset
124 void ViewportGeometry::MapPixelCenterToScene(std::vector<Touch>& sceneTouches /* out */,
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: 439
diff changeset
125 const std::vector<Touch>& displayTouches) const
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: 439
diff changeset
126 {
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: 439
diff changeset
127 double sceneX, 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: 439
diff changeset
128 sceneTouches.clear();
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: 439
diff changeset
129 for (size_t t = 0; t < displayTouches.size(); t++)
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: 439
diff changeset
130 {
693
9a474e90e832 Fixed a bunch of truncation warnings in various parts of the library
Benjamin Golinvaux <bgo@osimis.io>
parents: 457
diff changeset
131 MapPixelCenterToScene(
9a474e90e832 Fixed a bunch of truncation warnings in various parts of the library
Benjamin Golinvaux <bgo@osimis.io>
parents: 457
diff changeset
132 sceneX,
9a474e90e832 Fixed a bunch of truncation warnings in various parts of the library
Benjamin Golinvaux <bgo@osimis.io>
parents: 457
diff changeset
133 sceneY,
9a474e90e832 Fixed a bunch of truncation warnings in various parts of the library
Benjamin Golinvaux <bgo@osimis.io>
parents: 457
diff changeset
134 static_cast<int>(displayTouches[t].x),
9a474e90e832 Fixed a bunch of truncation warnings in various parts of the library
Benjamin Golinvaux <bgo@osimis.io>
parents: 457
diff changeset
135 static_cast<int>(displayTouches[t].y));
9a474e90e832 Fixed a bunch of truncation warnings in various parts of the library
Benjamin Golinvaux <bgo@osimis.io>
parents: 457
diff changeset
136
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: 439
diff changeset
137 sceneTouches.push_back(Touch((float)sceneX, (float)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: 439
diff changeset
138 }
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: 439
diff changeset
139 }
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: 439
diff changeset
140
332
50e5ec1bdd46 separating ZoomMouseTracker and PanMouseTracker from WorldSceneWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 330
diff changeset
141 void ViewportGeometry::MapPixelCenterToScene(double& sceneX,
50e5ec1bdd46 separating ZoomMouseTracker and PanMouseTracker from WorldSceneWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 330
diff changeset
142 double& sceneY,
50e5ec1bdd46 separating ZoomMouseTracker and PanMouseTracker from WorldSceneWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 330
diff changeset
143 int x,
50e5ec1bdd46 separating ZoomMouseTracker and PanMouseTracker from WorldSceneWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 330
diff changeset
144 int y) const
50e5ec1bdd46 separating ZoomMouseTracker and PanMouseTracker from WorldSceneWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 330
diff changeset
145 {
50e5ec1bdd46 separating ZoomMouseTracker and PanMouseTracker from WorldSceneWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 330
diff changeset
146 // Take the center of the pixel
50e5ec1bdd46 separating ZoomMouseTracker and PanMouseTracker from WorldSceneWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 330
diff changeset
147 MapDisplayToScene(sceneX, sceneY,
50e5ec1bdd46 separating ZoomMouseTracker and PanMouseTracker from WorldSceneWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 330
diff changeset
148 static_cast<double>(x) + 0.5,
50e5ec1bdd46 separating ZoomMouseTracker and PanMouseTracker from WorldSceneWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 330
diff changeset
149 static_cast<double>(y) + 0.5);
50e5ec1bdd46 separating ZoomMouseTracker and PanMouseTracker from WorldSceneWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 330
diff changeset
150 }
50e5ec1bdd46 separating ZoomMouseTracker and PanMouseTracker from WorldSceneWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 330
diff changeset
151
50e5ec1bdd46 separating ZoomMouseTracker and PanMouseTracker from WorldSceneWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 330
diff changeset
152
330
7a364e44fbb4 renamed SetDefaultView in FitContent
am@osimis.io
parents: 212
diff changeset
153 void ViewportGeometry::FitContent()
0
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
154 {
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
155 if (width_ > 0 &&
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
156 height_ > 0 &&
109
53bd9277b025 using the Extent class
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 47
diff changeset
157 !sceneExtent_.IsEmpty())
0
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
158 {
109
53bd9277b025 using the Extent class
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 47
diff changeset
159 double zoomX = static_cast<double>(width_) / (sceneExtent_.GetX2() - sceneExtent_.GetX1());
53bd9277b025 using the Extent class
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 47
diff changeset
160 double zoomY = static_cast<double>(height_) / (sceneExtent_.GetY2() - sceneExtent_.GetY1());
0
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
161 zoom_ = zoomX < zoomY ? zoomX : zoomY;
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
162
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
163 panX_ = 0;
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
164 panY_ = 0;
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
165
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
166 ComputeTransform();
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
167 }
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
168 }
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
169
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
170
726
4f2416d519b4 moving layers, widgets and loaders to Deprecated namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 693
diff changeset
171 void ViewportGeometry::ApplyTransform(OrthancStone::CairoContext& context) const
0
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
172 {
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
173 cairo_set_matrix(context.GetObject(), &transform_);
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
174 }
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
175
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
176
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
177 void ViewportGeometry::GetPan(double& x,
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
178 double& y) const
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
179 {
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
180 x = panX_;
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
181 y = panY_;
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
182 }
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
183
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
184
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
185 void ViewportGeometry::SetPan(double x,
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
186 double y)
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
187 {
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
188 panX_ = x;
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
189 panY_ = y;
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
190 ComputeTransform();
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
191 }
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
192
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
193
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
194 void ViewportGeometry::SetZoom(double zoom)
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
195 {
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
196 zoom_ = zoom;
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
197 ComputeTransform();
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
198 }
340
f5d5814a41a0 rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 332
diff changeset
199
f5d5814a41a0 rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 332
diff changeset
200
726
4f2416d519b4 moving layers, widgets and loaders to Deprecated namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 693
diff changeset
201 OrthancStone::Matrix ViewportGeometry::GetMatrix() const
340
f5d5814a41a0 rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 332
diff changeset
202 {
726
4f2416d519b4 moving layers, widgets and loaders to Deprecated namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 693
diff changeset
203 OrthancStone::Matrix m(3, 3);
340
f5d5814a41a0 rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 332
diff changeset
204
f5d5814a41a0 rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 332
diff changeset
205 m(0, 0) = transform_.xx;
f5d5814a41a0 rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 332
diff changeset
206 m(0, 1) = transform_.xy;
f5d5814a41a0 rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 332
diff changeset
207 m(0, 2) = transform_.x0;
f5d5814a41a0 rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 332
diff changeset
208 m(1, 0) = transform_.yx;
f5d5814a41a0 rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 332
diff changeset
209 m(1, 1) = transform_.yy;
f5d5814a41a0 rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 332
diff changeset
210 m(1, 2) = transform_.y0;
f5d5814a41a0 rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 332
diff changeset
211 m(2, 0) = 0;
f5d5814a41a0 rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 332
diff changeset
212 m(2, 1) = 0;
f5d5814a41a0 rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 332
diff changeset
213 m(2, 2) = 1;
f5d5814a41a0 rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 332
diff changeset
214
f5d5814a41a0 rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 332
diff changeset
215 return m;
f5d5814a41a0 rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 332
diff changeset
216 }
0
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
217 }