Mercurial > hg > orthanc-stone
annotate Framework/Layers/LineMeasureTracker.cpp @ 49:c45f368de5c0
agpl
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 27 Apr 2017 11:09:43 +0200 |
parents | 28956ed68280 |
children | 53025eecbc95 4cff7b1ed31d |
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 | |
40
7207a407bcd8
shared copyright with osimis
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
5 * Copyright (C) 2017 Osimis, 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 #include "LineMeasureTracker.h" | |
23 | |
24 #include "../Viewport/CairoFont.h" | |
25 | |
26 #include <stdio.h> | |
27 | |
28 namespace OrthancStone | |
29 { | |
30 LineMeasureTracker::LineMeasureTracker(IStatusBar* statusBar, | |
31 const SliceGeometry& slice, | |
32 double x, | |
33 double y, | |
34 uint8_t red, | |
35 uint8_t green, | |
36 uint8_t blue, | |
37 unsigned int fontSize) : | |
38 statusBar_(statusBar), | |
39 slice_(slice), | |
40 x1_(x), | |
41 y1_(y), | |
42 x2_(x), | |
43 y2_(y), | |
44 fontSize_(fontSize) | |
45 { | |
46 color_[0] = red; | |
47 color_[1] = green; | |
48 color_[2] = blue; | |
49 } | |
50 | |
51 | |
52 void LineMeasureTracker::Render(CairoContext& context, | |
53 double zoom) | |
54 { | |
55 context.SetSourceColor(color_[0], color_[1], color_[2]); | |
56 | |
57 cairo_t* cr = context.GetObject(); | |
58 cairo_set_line_width(cr, 2.0 / zoom); | |
59 cairo_move_to(cr, x1_, y1_); | |
60 cairo_line_to(cr, x2_, y2_); | |
61 cairo_stroke(cr); | |
62 | |
63 if (fontSize_ != 0) | |
64 { | |
65 cairo_move_to(cr, x2_, y2_ - static_cast<double>(fontSize_) / zoom); | |
66 CairoFont font("sans-serif", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL); | |
67 font.Draw(context, FormatLength(), static_cast<double>(fontSize_) / zoom); | |
68 } | |
69 } | |
70 | |
71 | |
72 double LineMeasureTracker::GetLength() const // In millimeters | |
73 { | |
74 Vector a = slice_.MapSliceToWorldCoordinates(x1_, y1_); | |
75 Vector b = slice_.MapSliceToWorldCoordinates(x2_, y2_); | |
76 return boost::numeric::ublas::norm_2(b - a); | |
77 } | |
78 | |
79 | |
80 std::string LineMeasureTracker::FormatLength() const | |
81 { | |
82 char buf[64]; | |
83 sprintf(buf, "%0.01f cm", GetLength() / 10.0); | |
84 return buf; | |
85 } | |
86 | |
87 void LineMeasureTracker::MouseMove(double x, | |
88 double y) | |
89 { | |
90 x2_ = x; | |
91 y2_ = y; | |
92 | |
93 if (statusBar_ != NULL) | |
94 { | |
95 statusBar_->SetMessage("Line length: " + FormatLength()); | |
96 } | |
97 } | |
98 } |