Mercurial > hg > orthanc-stone
comparison Framework/Toolbox/ViewportGeometry.cpp @ 109:53bd9277b025 wasm
using the Extent class
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 14 Jun 2017 15:34:08 +0200 |
parents | 28956ed68280 |
children | 7665ccbf33db |
comparison
equal
deleted
inserted
replaced
108:37d4ae7052a5 | 109:53bd9277b025 |
---|---|
41 // Apply the zoom around (0,0) | 41 // Apply the zoom around (0,0) |
42 cairo_matrix_init_scale(&tmp, zoom_, zoom_); | 42 cairo_matrix_init_scale(&tmp, zoom_, zoom_); |
43 cairo_matrix_multiply(&transform_, &tmp, &transform_); | 43 cairo_matrix_multiply(&transform_, &tmp, &transform_); |
44 | 44 |
45 // Bring the center of the scene to (0,0) | 45 // Bring the center of the scene to (0,0) |
46 cairo_matrix_init_translate(&tmp, -(x1_ + x2_) / 2.0, -(y1_ + y2_) / 2.0); | 46 cairo_matrix_init_translate(&tmp, |
47 -(sceneExtent_.GetX1() + sceneExtent_.GetX2()) / 2.0, | |
48 -(sceneExtent_.GetY1() + sceneExtent_.GetY2()) / 2.0); | |
47 cairo_matrix_multiply(&transform_, &tmp, &transform_); | 49 cairo_matrix_multiply(&transform_, &tmp, &transform_); |
48 } | 50 } |
49 | 51 |
50 | 52 |
51 ViewportGeometry::ViewportGeometry() | 53 ViewportGeometry::ViewportGeometry() |
52 { | 54 { |
53 x1_ = 0; | |
54 y1_ = 0; | |
55 x2_ = 0; | |
56 y2_ = 0; | |
57 | |
58 width_ = 0; | 55 width_ = 0; |
59 height_ = 0; | 56 height_ = 0; |
60 | 57 |
61 zoom_ = 1; | 58 zoom_ = 1; |
62 panX_ = 0; | 59 panX_ = 0; |
80 ComputeTransform(); | 77 ComputeTransform(); |
81 } | 78 } |
82 } | 79 } |
83 | 80 |
84 | 81 |
85 void ViewportGeometry::SetSceneExtent(double x1, | 82 void ViewportGeometry::SetSceneExtent(const Extent& extent) |
86 double y1, | |
87 double x2, | |
88 double y2) | |
89 { | 83 { |
90 if (x1 == x1_ && | 84 LOG(INFO) << "New scene extent: (" |
91 y1 == y1_ && | 85 << extent.GetX1() << "," << extent.GetY1() << ") => (" |
92 x2 == x2_ && | 86 << extent.GetX2() << "," << extent.GetY2() << ")"; |
93 y2 == y2_) | |
94 { | |
95 return; | |
96 } | |
97 else if (x1 > x2 || | |
98 y1 > y2) | |
99 { | |
100 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); | |
101 } | |
102 else | |
103 { | |
104 LOG(INFO) << "New scene extent: (" << x1 << "," << y1 << ") => (" << x2 << "," << y2 << ")"; | |
105 | 87 |
106 x1_ = x1; | 88 sceneExtent_ = extent; |
107 y1_ = y1; | 89 ComputeTransform(); |
108 x2_ = x2; | |
109 y2_ = y2; | |
110 | |
111 ComputeTransform(); | |
112 } | |
113 } | |
114 | |
115 | |
116 void ViewportGeometry::GetSceneExtent(double& x1, | |
117 double& y1, | |
118 double& x2, | |
119 double& y2) const | |
120 { | |
121 x1 = x1_; | |
122 y1 = y1_; | |
123 x2 = x2_; | |
124 y2 = y2_; | |
125 } | 90 } |
126 | 91 |
127 | 92 |
128 void ViewportGeometry::MapDisplayToScene(double& sceneX /* out */, | 93 void ViewportGeometry::MapDisplayToScene(double& sceneX /* out */, |
129 double& sceneY /* out */, | 94 double& sceneY /* out */, |
158 | 123 |
159 void ViewportGeometry::SetDefaultView() | 124 void ViewportGeometry::SetDefaultView() |
160 { | 125 { |
161 if (width_ > 0 && | 126 if (width_ > 0 && |
162 height_ > 0 && | 127 height_ > 0 && |
163 x2_ > x1_ + 10 * std::numeric_limits<double>::epsilon() && | 128 !sceneExtent_.IsEmpty()) |
164 y2_ > y1_ + 10 * std::numeric_limits<double>::epsilon()) | |
165 { | 129 { |
166 double zoomX = static_cast<double>(width_) / (x2_ - x1_); | 130 double zoomX = static_cast<double>(width_) / (sceneExtent_.GetX2() - sceneExtent_.GetX1()); |
167 double zoomY = static_cast<double>(height_) / (y2_ - y1_); | 131 double zoomY = static_cast<double>(height_) / (sceneExtent_.GetY2() - sceneExtent_.GetY1()); |
168 zoom_ = zoomX < zoomY ? zoomX : zoomY; | 132 zoom_ = zoomX < zoomY ? zoomX : zoomY; |
169 | 133 |
170 panX_ = 0; | 134 panX_ = 0; |
171 panY_ = 0; | 135 panY_ = 0; |
172 | 136 |