Mercurial > hg > orthanc-stone
comparison Samples/Common/MeasureToolsToolbox.h @ 645:1e9ed656318e
Merge + ongoing measure work
author | Benjamin Golinvaux <bgo@osimis.io> |
---|---|
date | Mon, 13 May 2019 15:12:56 +0200 |
parents | |
children | 62f6ff016085 |
comparison
equal
deleted
inserted
replaced
644:f939f449482c | 645:1e9ed656318e |
---|---|
1 /** | |
2 * Stone of Orthanc | |
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics | |
4 * Department, University Hospital of Liege, Belgium | |
5 * Copyright (C) 2017-2019 Osimis S.A., Belgium | |
6 * | |
7 * This program is free software: you can redistribute it and/or | |
8 * modify it under the terms of the GNU Affero General Public License | |
9 * as published by the Free Software Foundation, either version 3 of | |
10 * the License, or (at your option) any later version. | |
11 * | |
12 * This program is distributed in the hope that it will be useful, but | |
13 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
15 * Affero General Public License for more details. | |
16 * | |
17 * You should have received a copy of the GNU Affero General Public License | |
18 * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
19 **/ | |
20 | |
21 #include <Framework/Scene2D/PolylineSceneLayer.h> | |
22 #include <Framework/Scene2D/Scene2D.h> | |
23 | |
24 namespace OrthancStone | |
25 { | |
26 | |
27 /** | |
28 This function will create a square around the center point supplied in | |
29 scene coordinates, with a side length given in canvas coordinates. The | |
30 square sides are parallel to the canvas boundaries. | |
31 */ | |
32 void AddSquare(PolylineSceneLayer::Chain& chain, | |
33 const Scene2D& scene, | |
34 const ScenePoint2D& centerS, | |
35 const double& sideLength); | |
36 | |
37 /** | |
38 Creates an arc centered pm c that goes | |
39 - from a point r1: | |
40 - so that r1 belongs to the p1,c line | |
41 - so that the distance from c to r1 equals radius | |
42 - to a point r2: | |
43 - so that r2 belongs to the p2,c line | |
44 - so that the distance from c to r2 equals radius | |
45 | |
46 if clockwise is true, the arc is drawn from r1 to r2 with increasing | |
47 angle values. Otherwise, the angle values decrease. | |
48 | |
49 Warning: the existing chain content will be wiped out. | |
50 */ | |
51 | |
52 void AddArc( | |
53 PolylineSceneLayer::Chain& chain | |
54 , const Scene2D& scene | |
55 , const ScenePoint2D& p1 | |
56 , const ScenePoint2D& c | |
57 , const ScenePoint2D& p2 | |
58 , const double& radiusS | |
59 , const bool clockwise | |
60 , const int subdivisionsCount = 63); | |
61 | |
62 /** | |
63 Creates an arc (open curve) with "numSubdivisions" | |
64 (N + 1 points) from start angle to end angle. | |
65 | |
66 if clockwise is true, the arc is drawn from start to end | |
67 by increasing the angle values. | |
68 | |
69 otherwise, the angle value decreases from start to end. | |
70 | |
71 Warning: the existing chain content will be wiped out. | |
72 */ | |
73 void AddArc( | |
74 PolylineSceneLayer::Chain& chain | |
75 , const Scene2D& scene | |
76 , const ScenePoint2D& centerS | |
77 , const double& radiusS | |
78 , const double startAngleRad | |
79 , const double endAngleRad | |
80 , const bool clockwise | |
81 , const int subdivisionsCount = 63); | |
82 | |
83 /** | |
84 Creates a circle (closed curve) with "numSubdivisions" | |
85 (N points) | |
86 | |
87 Warning: the existing chain content will be wiped out. | |
88 */ | |
89 void AddCircle(PolylineSceneLayer::Chain& chain, | |
90 const Scene2D& scene, | |
91 const ScenePoint2D& centerS, | |
92 const double& radiusS, | |
93 const int numSubdivisions = 63); | |
94 | |
95 /** | |
96 Adds or subtracts 2*pi as many times as need to shift the specified | |
97 angle to a value such as: 0 <= value < 2*pi | |
98 */ | |
99 double NormalizeAngle(double angle); | |
100 | |
101 /** | |
102 Returns the angle magnitude between the p1,c and p2,c lines. | |
103 The returned angle is between 0 and 2*pi | |
104 | |
105 If the angle is between 0 and pi, this means that the shortest arc | |
106 from p1 to p2 is clockwise. | |
107 | |
108 If the angle is between pi and 2*pi, this means that the shortest arc | |
109 from p1 to p2 is COUNTERclockwise. | |
110 | |
111 */ | |
112 double MeasureAngle( | |
113 const ScenePoint2D& p1 | |
114 , const ScenePoint2D& c | |
115 , const ScenePoint2D& p2); | |
116 | |
117 /** | |
118 RadiansToDegrees | |
119 */ | |
120 double RadiansToDegrees(double angleRad); | |
121 | |
122 /** | |
123 This function will return the coordinates of a point that: | |
124 - belongs to the two bisecting lines of the p1 c p2 angle. | |
125 - is a distance d from c. | |
126 Among the four possible points, the one returned will be the one belonging | |
127 to the *smallest* half-plane defined by the [c,p1[ and [c,p2[ half-lines. | |
128 */ | |
129 void GetPositionOnBisectingLine( | |
130 ScenePoint2D& result | |
131 , const ScenePoint2D& p1 | |
132 , const ScenePoint2D& c | |
133 , const ScenePoint2D& p2 | |
134 , const double d); | |
135 } |