Mercurial > hg > orthanc-stone
annotate Framework/Layers/CircleMeasureTracker.cpp @ 370:8ac7161d5fea
integration captain->default
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Mon, 05 Nov 2018 10:04:19 +0100 |
parents | fccffbf99ba1 |
children | 2038d76bf13f |
rev | line source |
---|---|
0 | 1 /** |
2 * Stone of Orthanc | |
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics | |
4 * Department, University Hospital of Liege, Belgium | |
134
4cff7b1ed31d
upgrade to year 2018
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
47
diff
changeset
|
5 * Copyright (C) 2017-2018 Osimis S.A., Belgium |
0 | 6 * |
7 * This program is free software: you can redistribute it and/or | |
47 | 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. | |
0 | 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 | |
47 | 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 | |
0 | 18 * along with this program. If not, see <http://www.gnu.org/licenses/>. |
19 **/ | |
20 | |
21 | |
22 #define _USE_MATH_DEFINES // To access M_PI in Visual Studio | |
23 #include <cmath> | |
24 | |
25 #include "CircleMeasureTracker.h" | |
26 | |
27 #include "../Viewport/CairoFont.h" | |
28 | |
29 #include <stdio.h> | |
30 | |
31 namespace OrthancStone | |
32 { | |
33 CircleMeasureTracker::CircleMeasureTracker(IStatusBar* statusBar, | |
110
53025eecbc95
renamed SliceGeometry as CoordinateSystem3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
47
diff
changeset
|
34 const CoordinateSystem3D& slice, |
0 | 35 double x, |
36 double y, | |
37 uint8_t red, | |
38 uint8_t green, | |
39 uint8_t blue, | |
40 unsigned int fontSize) : | |
41 statusBar_(statusBar), | |
42 slice_(slice), | |
43 x1_(x), | |
44 y1_(y), | |
45 x2_(x), | |
46 y2_(y), | |
47 fontSize_(fontSize) | |
48 { | |
49 color_[0] = red; | |
50 color_[1] = green; | |
51 color_[2] = blue; | |
52 } | |
53 | |
54 | |
55 void CircleMeasureTracker::Render(CairoContext& context, | |
56 double zoom) | |
57 { | |
58 double x = (x1_ + x2_) / 2.0; | |
59 double y = (y1_ + y2_) / 2.0; | |
60 | |
61 Vector tmp; | |
158
a053ca7fa5c6
LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
135
diff
changeset
|
62 LinearAlgebra::AssignVector(tmp, x2_ - x1_, y2_ - y1_); |
0 | 63 double r = boost::numeric::ublas::norm_2(tmp) / 2.0; |
64 | |
65 context.SetSourceColor(color_[0], color_[1], color_[2]); | |
66 | |
67 cairo_t* cr = context.GetObject(); | |
68 cairo_save(cr); | |
69 cairo_set_line_width(cr, 2.0 / zoom); | |
70 cairo_translate(cr, x, y); | |
71 cairo_arc(cr, 0, 0, r, 0, 2 * M_PI); | |
72 cairo_stroke_preserve(cr); | |
73 cairo_stroke(cr); | |
74 cairo_restore(cr); | |
75 | |
76 if (fontSize_ != 0) | |
77 { | |
78 cairo_move_to(cr, x, y); | |
79 CairoFont font("sans-serif", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL); | |
80 font.Draw(context, FormatRadius(), static_cast<double>(fontSize_) / zoom); | |
81 } | |
82 } | |
83 | |
84 | |
85 double CircleMeasureTracker::GetRadius() const // In millimeters | |
86 { | |
87 Vector a = slice_.MapSliceToWorldCoordinates(x1_, y1_); | |
88 Vector b = slice_.MapSliceToWorldCoordinates(x2_, y2_); | |
89 return boost::numeric::ublas::norm_2(b - a) / 2.0; | |
90 } | |
91 | |
92 | |
93 std::string CircleMeasureTracker::FormatRadius() const | |
94 { | |
95 char buf[64]; | |
96 sprintf(buf, "%0.01f cm", GetRadius() / 10.0); | |
97 return buf; | |
98 } | |
99 | |
100 void CircleMeasureTracker::MouseMove(double x, | |
101 double y) | |
102 { | |
103 x2_ = x; | |
104 y2_ = y; | |
105 | |
106 if (statusBar_ != NULL) | |
107 { | |
108 statusBar_->SetMessage("Circle radius: " + FormatRadius()); | |
109 } | |
110 } | |
111 } |