Mercurial > hg > orthanc-stone
comparison Framework/Radiography/RadiographyLayer.cpp @ 476:a95090305dd4 am-touch-events
Introduced ControlPoint instead of Corner in the trackers and layers + drawing mask from the ControlPoints
author | am@osimis.io |
---|---|
date | Wed, 13 Feb 2019 12:04:02 +0100 |
parents | a750f11892ec |
children | 2f6ecb5037ea |
comparison
equal
deleted
inserted
replaced
475:3c28542229a3 | 476:a95090305dd4 |
---|---|
74 | 74 |
75 void RadiographyLayer::AddToExtent(Extent2D& extent, | 75 void RadiographyLayer::AddToExtent(Extent2D& extent, |
76 double x, | 76 double x, |
77 double y) const | 77 double y) const |
78 { | 78 { |
79 transform_.Apply(x, y); | 79 GetTransform().Apply(x, y); |
80 extent.AddPoint(x, y); | 80 extent.AddPoint(x, y); |
81 } | 81 } |
82 | |
83 | |
84 void RadiographyLayer::GetCornerInternal(double& x, | |
85 double& y, | |
86 Corner corner, | |
87 unsigned int cropX, | |
88 unsigned int cropY, | |
89 unsigned int cropWidth, | |
90 unsigned int cropHeight) const | |
91 { | |
92 double dx = static_cast<double>(cropX); | |
93 double dy = static_cast<double>(cropY); | |
94 double dwidth = static_cast<double>(cropWidth); | |
95 double dheight = static_cast<double>(cropHeight); | |
96 | |
97 switch (corner) | |
98 { | |
99 case Corner_TopLeft: | |
100 x = dx; | |
101 y = dy; | |
102 break; | |
103 | |
104 case Corner_TopRight: | |
105 x = dx + dwidth; | |
106 y = dy; | |
107 break; | |
108 | |
109 case Corner_BottomLeft: | |
110 x = dx; | |
111 y = dy + dheight; | |
112 break; | |
113 | |
114 case Corner_BottomRight: | |
115 x = dx + dwidth; | |
116 y = dy + dheight; | |
117 break; | |
118 | |
119 default: | |
120 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); | |
121 } | |
122 | |
123 transform_.Apply(x, y); | |
124 } | |
125 | |
126 | 82 |
127 bool RadiographyLayer::Contains(double x, | 83 bool RadiographyLayer::Contains(double x, |
128 double y) const | 84 double y) const |
129 { | 85 { |
130 transformInverse_.Apply(x, y); | 86 GetTransformInverse().Apply(x, y); |
131 | 87 |
132 unsigned int cropX, cropY, cropWidth, cropHeight; | 88 unsigned int cropX, cropY, cropWidth, cropHeight; |
133 GetCrop(cropX, cropY, cropWidth, cropHeight); | 89 GetCrop(cropX, cropY, cropWidth, cropHeight); |
134 | 90 |
135 return (x >= cropX && x <= cropX + cropWidth && | 91 return (x >= cropX && x <= cropX + cropWidth && |
138 | 94 |
139 | 95 |
140 void RadiographyLayer::DrawBorders(CairoContext& context, | 96 void RadiographyLayer::DrawBorders(CairoContext& context, |
141 double zoom) | 97 double zoom) |
142 { | 98 { |
143 unsigned int cx, cy, width, height; | 99 if (GetControlPointCount() < 3 ) |
144 GetCrop(cx, cy, width, height); | 100 return; |
145 | |
146 double dx = static_cast<double>(cx); | |
147 double dy = static_cast<double>(cy); | |
148 double dwidth = static_cast<double>(width); | |
149 double dheight = static_cast<double>(height); | |
150 | 101 |
151 cairo_t* cr = context.GetObject(); | 102 cairo_t* cr = context.GetObject(); |
152 cairo_set_line_width(cr, 2.0 / zoom); | 103 cairo_set_line_width(cr, 2.0 / zoom); |
153 | 104 |
154 double x, y; | 105 ControlPoint cp; |
155 x = dx; | 106 GetControlPoint(cp, 0); |
156 y = dy; | 107 cairo_move_to(cr, cp.x, cp.y); |
157 transform_.Apply(x, y); | 108 |
158 cairo_move_to(cr, x, y); | 109 for (size_t i = 0; i < GetControlPointCount(); i++) |
159 | 110 { |
160 x = dx + dwidth; | 111 GetControlPoint(cp, i); |
161 y = dy; | 112 cairo_line_to(cr, cp.x, cp.y); |
162 transform_.Apply(x, y); | 113 } |
163 cairo_line_to(cr, x, y); | 114 |
164 | 115 cairo_close_path(cr); |
165 x = dx + dwidth; | |
166 y = dy + dheight; | |
167 transform_.Apply(x, y); | |
168 cairo_line_to(cr, x, y); | |
169 | |
170 x = dx; | |
171 y = dy + dheight; | |
172 transform_.Apply(x, y); | |
173 cairo_line_to(cr, x, y); | |
174 | |
175 x = dx; | |
176 y = dy; | |
177 transform_.Apply(x, y); | |
178 cairo_line_to(cr, x, y); | |
179 | |
180 cairo_stroke(cr); | 116 cairo_stroke(cr); |
181 } | 117 } |
182 | 118 |
183 | 119 |
184 RadiographyLayer::RadiographyLayer() : | 120 RadiographyLayer::RadiographyLayer() : |
235 { | 171 { |
236 if (GetGeometry().HasCrop()) | 172 if (GetGeometry().HasCrop()) |
237 { | 173 { |
238 GetGeometry().GetCrop(x, y, width, height); | 174 GetGeometry().GetCrop(x, y, width, height); |
239 } | 175 } |
240 else | 176 else |
241 { | 177 { |
242 x = 0; | 178 x = 0; |
243 y = 0; | 179 y = 0; |
244 width = width_; | 180 width = width_; |
245 height = height_; | 181 height = height_; |
303 { | 239 { |
304 return false; | 240 return false; |
305 } | 241 } |
306 else | 242 else |
307 { | 243 { |
308 transformInverse_.Apply(sceneX, sceneY); | 244 GetTransformInverse().Apply(sceneX, sceneY); |
309 | 245 |
310 int x = static_cast<int>(std::floor(sceneX)); | 246 int x = static_cast<int>(std::floor(sceneX)); |
311 int y = static_cast<int>(std::floor(sceneY)); | 247 int y = static_cast<int>(std::floor(sceneY)); |
312 | 248 |
313 if (x < 0) | 249 if (x < 0) |
360 void RadiographyLayer::GetCenter(double& centerX, | 296 void RadiographyLayer::GetCenter(double& centerX, |
361 double& centerY) const | 297 double& centerY) const |
362 { | 298 { |
363 centerX = static_cast<double>(width_) / 2.0; | 299 centerX = static_cast<double>(width_) / 2.0; |
364 centerY = static_cast<double>(height_) / 2.0; | 300 centerY = static_cast<double>(height_) / 2.0; |
365 transform_.Apply(centerX, centerY); | 301 GetTransform().Apply(centerX, centerY); |
366 } | 302 } |
367 | 303 |
368 | 304 |
369 void RadiographyLayer::GetCorner(double& x /* out */, | 305 |
370 double& y /* out */, | 306 size_t RadiographyLayer::GetControlPointCount() const {return 4;} |
371 Corner corner) const | 307 |
308 void RadiographyLayer::GetControlPointInternal(ControlPoint& controlPoint, | |
309 size_t index) const | |
372 { | 310 { |
373 unsigned int cropX, cropY, cropWidth, cropHeight; | 311 unsigned int cropX, cropY, cropWidth, cropHeight; |
374 GetCrop(cropX, cropY, cropWidth, cropHeight); | 312 GetCrop(cropX, cropY, cropWidth, cropHeight); |
375 GetCornerInternal(x, y, corner, cropX, cropY, cropWidth, cropHeight); | 313 |
376 } | 314 switch (index) |
377 | 315 { |
378 | 316 case ControlPoint_TopLeftCorner: |
379 bool RadiographyLayer::LookupCorner(Corner& corner /* out */, | 317 controlPoint = ControlPoint(cropX, cropY, ControlPoint_TopLeftCorner); |
380 double x, | 318 break; |
381 double y, | 319 |
382 double zoom, | 320 case ControlPoint_TopRightCorner: |
383 double viewportDistance) const | 321 controlPoint = ControlPoint(cropX + cropWidth, cropY, ControlPoint_TopRightCorner); |
384 { | 322 break; |
385 static const Corner CORNERS[] = { | 323 |
386 Corner_TopLeft, | 324 case ControlPoint_BottomLeftCorner: |
387 Corner_TopRight, | 325 controlPoint = ControlPoint(cropX, cropY + cropHeight, ControlPoint_BottomLeftCorner); |
388 Corner_BottomLeft, | 326 break; |
389 Corner_BottomRight | 327 |
390 }; | 328 case ControlPoint_BottomRightCorner: |
391 | 329 controlPoint = ControlPoint(cropX + cropWidth, cropY + cropHeight, ControlPoint_BottomRightCorner); |
392 unsigned int cropX, cropY, cropWidth, cropHeight; | 330 break; |
393 GetCrop(cropX, cropY, cropWidth, cropHeight); | 331 |
394 | 332 default: |
333 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); | |
334 } | |
335 | |
336 } | |
337 | |
338 | |
339 | |
340 void RadiographyLayer::GetControlPoint(ControlPoint& controlPoint /* out */, | |
341 size_t index) const | |
342 { | |
343 GetControlPointInternal(controlPoint, index); | |
344 GetTransform().Apply(controlPoint.x, controlPoint.y); | |
345 } | |
346 | |
347 | |
348 bool RadiographyLayer::LookupControlPoint(ControlPoint& controlPoint /* out */, | |
349 double x, | |
350 double y, | |
351 double zoom, | |
352 double viewportDistance) const | |
353 { | |
395 double threshold = Square(viewportDistance / zoom); | 354 double threshold = Square(viewportDistance / zoom); |
396 | 355 |
397 for (size_t i = 0; i < 4; i++) | 356 for (size_t i = 0; i < GetControlPointCount(); i++) |
398 { | 357 { |
399 double cx, cy; | 358 ControlPoint cp; |
400 GetCornerInternal(cx, cy, CORNERS[i], cropX, cropY, cropWidth, cropHeight); | 359 GetControlPoint(cp, i); |
401 | 360 |
402 double d = Square(cx - x) + Square(cy - y); | 361 double d = Square(cp.x - x) + Square(cp.y - y); |
403 | 362 |
404 if (d <= threshold) | 363 if (d <= threshold) |
405 { | 364 { |
406 corner = CORNERS[i]; | 365 controlPoint = cp; |
407 return true; | 366 return true; |
408 } | 367 } |
409 } | 368 } |
410 | 369 |
411 return false; | 370 return false; |