Mercurial > hg > orthanc-stone
annotate OrthancStone/Sources/Scene2D/Internals/CairoArrowRenderer.cpp @ 2113:8ab2eb6ed354
fix for boost 1.84.0
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 24 Jan 2024 16:42:38 +0100 |
parents | 07964689cb0b |
children | c23eef785569 |
rev | line source |
---|---|
1614
ad9b425f27ae
new class: ArrowSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1 /** |
ad9b425f27ae
new class: ArrowSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2 * Stone of Orthanc |
ad9b425f27ae
new class: ArrowSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics |
ad9b425f27ae
new class: ArrowSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
4 * Department, University Hospital of Liege, Belgium |
2077
07964689cb0b
upgrade to year 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1871
diff
changeset
|
5 * Copyright (C) 2017-2023 Osimis S.A., Belgium |
07964689cb0b
upgrade to year 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1871
diff
changeset
|
6 * Copyright (C) 2021-2023 Sebastien Jodogne, ICTEAM UCLouvain, Belgium |
1614
ad9b425f27ae
new class: ArrowSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
7 * |
ad9b425f27ae
new class: ArrowSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
8 * This program is free software: you can redistribute it and/or |
ad9b425f27ae
new class: ArrowSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
9 * modify it under the terms of the GNU Lesser General Public License |
ad9b425f27ae
new class: ArrowSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
10 * as published by the Free Software Foundation, either version 3 of |
ad9b425f27ae
new class: ArrowSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
11 * the License, or (at your option) any later version. |
ad9b425f27ae
new class: ArrowSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
12 * |
ad9b425f27ae
new class: ArrowSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
13 * This program is distributed in the hope that it will be useful, but |
ad9b425f27ae
new class: ArrowSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
14 * WITHOUT ANY WARRANTY; without even the implied warranty of |
ad9b425f27ae
new class: ArrowSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
ad9b425f27ae
new class: ArrowSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
16 * Lesser General Public License for more details. |
ad9b425f27ae
new class: ArrowSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
17 * |
ad9b425f27ae
new class: ArrowSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
18 * You should have received a copy of the GNU Lesser General Public |
ad9b425f27ae
new class: ArrowSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
19 * License along with this program. If not, see |
ad9b425f27ae
new class: ArrowSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
20 * <http://www.gnu.org/licenses/>. |
ad9b425f27ae
new class: ArrowSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
21 **/ |
ad9b425f27ae
new class: ArrowSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
22 |
ad9b425f27ae
new class: ArrowSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
23 |
ad9b425f27ae
new class: ArrowSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
24 #include "CairoArrowRenderer.h" |
ad9b425f27ae
new class: ArrowSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
25 |
ad9b425f27ae
new class: ArrowSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
26 #include "../ArrowSceneLayer.h" |
ad9b425f27ae
new class: ArrowSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
27 |
ad9b425f27ae
new class: ArrowSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
28 namespace OrthancStone |
ad9b425f27ae
new class: ArrowSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
29 { |
ad9b425f27ae
new class: ArrowSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
30 namespace Internals |
ad9b425f27ae
new class: ArrowSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
31 { |
ad9b425f27ae
new class: ArrowSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
32 void CairoArrowRenderer::Render(const AffineTransform2D& transform, |
ad9b425f27ae
new class: ArrowSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
33 unsigned int canvasWidth, |
ad9b425f27ae
new class: ArrowSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
34 unsigned int canvasHeight) |
ad9b425f27ae
new class: ArrowSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
35 { |
ad9b425f27ae
new class: ArrowSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
36 const ArrowSceneLayer& layer = GetLayer<ArrowSceneLayer>(); |
ad9b425f27ae
new class: ArrowSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
37 |
ad9b425f27ae
new class: ArrowSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
38 cairo_t* cr = GetCairoContext(); |
ad9b425f27ae
new class: ArrowSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
39 |
ad9b425f27ae
new class: ArrowSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
40 cairo_set_line_width(cr, layer.GetThickness()); |
ad9b425f27ae
new class: ArrowSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
41 |
ad9b425f27ae
new class: ArrowSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
42 const Color& color = layer.GetColor(); |
ad9b425f27ae
new class: ArrowSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
43 cairo_set_source_rgb(cr, color.GetRedAsFloat(), |
ad9b425f27ae
new class: ArrowSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
44 color.GetGreenAsFloat(), |
ad9b425f27ae
new class: ArrowSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
45 color.GetBlueAsFloat()); |
ad9b425f27ae
new class: ArrowSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
46 |
ad9b425f27ae
new class: ArrowSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
47 const double zoom = transform.ComputeZoom(); |
ad9b425f27ae
new class: ArrowSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
48 |
ad9b425f27ae
new class: ArrowSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
49 ScenePoint2D axis = layer.GetB() - layer.GetA(); |
ad9b425f27ae
new class: ArrowSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
50 double n = ScenePoint2D::SquaredMagnitude(axis); |
ad9b425f27ae
new class: ArrowSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
51 |
ad9b425f27ae
new class: ArrowSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
52 if (!LinearAlgebra::IsCloseToZero(n)) |
ad9b425f27ae
new class: ArrowSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
53 { |
ad9b425f27ae
new class: ArrowSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
54 axis = axis * layer.GetArrowLength() / (sqrt(n) * zoom); |
ad9b425f27ae
new class: ArrowSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
55 |
ad9b425f27ae
new class: ArrowSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
56 const ScenePoint2D a = layer.GetA().Apply(transform); |
ad9b425f27ae
new class: ArrowSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
57 const ScenePoint2D b = layer.GetB().Apply(transform); |
ad9b425f27ae
new class: ArrowSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
58 |
ad9b425f27ae
new class: ArrowSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
59 cairo_move_to(cr, a.GetX(), a.GetY()); |
ad9b425f27ae
new class: ArrowSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
60 cairo_line_to(cr, b.GetX(), b.GetY()); |
ad9b425f27ae
new class: ArrowSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
61 |
ad9b425f27ae
new class: ArrowSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
62 AffineTransform2D r1 = AffineTransform2D::CreateRotation(layer.GetArrowAngle()); |
ad9b425f27ae
new class: ArrowSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
63 const ScenePoint2D c = (layer.GetA() + axis.Apply(r1)).Apply(transform); |
ad9b425f27ae
new class: ArrowSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
64 |
ad9b425f27ae
new class: ArrowSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
65 AffineTransform2D r2 = AffineTransform2D::CreateRotation(-layer.GetArrowAngle()); |
ad9b425f27ae
new class: ArrowSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
66 const ScenePoint2D d = (layer.GetA() + axis.Apply(r2)).Apply(transform); |
ad9b425f27ae
new class: ArrowSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
67 |
ad9b425f27ae
new class: ArrowSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
68 cairo_move_to(cr, a.GetX(), a.GetY()); |
ad9b425f27ae
new class: ArrowSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
69 cairo_line_to(cr, c.GetX(), c.GetY()); |
ad9b425f27ae
new class: ArrowSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
70 |
ad9b425f27ae
new class: ArrowSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
71 cairo_move_to(cr, a.GetX(), a.GetY()); |
ad9b425f27ae
new class: ArrowSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
72 cairo_line_to(cr, d.GetX(), d.GetY()); |
ad9b425f27ae
new class: ArrowSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
73 |
ad9b425f27ae
new class: ArrowSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
74 cairo_stroke(cr); |
ad9b425f27ae
new class: ArrowSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
75 } |
ad9b425f27ae
new class: ArrowSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
76 } |
ad9b425f27ae
new class: ArrowSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
77 } |
ad9b425f27ae
new class: ArrowSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
78 } |