annotate Framework/Radiography/RadiographyWidget.cpp @ 448:cc47e6eaefb0 bgo-commands-codegen

Fixed dummy change
author bgo-osimis
date Wed, 16 Jan 2019 21:08:38 +0100
parents a750f11892ec
children 64d90190a08c aaeec7be8fb7
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
413
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 /**
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2 * Stone of Orthanc
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
4 * Department, University Hospital of Liege, Belgium
439
b70e9be013e4 preparing for 2019
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 413
diff changeset
5 * Copyright (C) 2017-2019 Osimis S.A., Belgium
413
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
6 *
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 * This program is free software: you can redistribute it and/or
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 * modify it under the terms of the GNU Affero General Public License
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 * as published by the Free Software Foundation, either version 3 of
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 * the License, or (at your option) any later version.
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 *
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 * This program is distributed in the hope that it will be useful, but
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 * Affero General Public License for more details.
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16 *
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
17 * You should have received a copy of the GNU Affero General Public License
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
19 **/
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22 #include "RadiographyWidget.h"
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23
432
4eb96c6b4e96 improved handling of MONOCHROME1, background and invertion
am@osimis.io
parents: 428
diff changeset
24 #include <Core/OrthancException.h>
413
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25 #include <Core/Images/Image.h>
432
4eb96c6b4e96 improved handling of MONOCHROME1, background and invertion
am@osimis.io
parents: 428
diff changeset
26 #include <Core/Images/ImageProcessing.h>
413
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29 namespace OrthancStone
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30 {
432
4eb96c6b4e96 improved handling of MONOCHROME1, background and invertion
am@osimis.io
parents: 428
diff changeset
31
4eb96c6b4e96 improved handling of MONOCHROME1, background and invertion
am@osimis.io
parents: 428
diff changeset
32 bool RadiographyWidget::IsInvertedInternal() const
4eb96c6b4e96 improved handling of MONOCHROME1, background and invertion
am@osimis.io
parents: 428
diff changeset
33 {
4eb96c6b4e96 improved handling of MONOCHROME1, background and invertion
am@osimis.io
parents: 428
diff changeset
34 return (scene_->GetPreferredPhotomotricDisplayMode() == PhotometricDisplayMode_Monochrome1) ^ invert_; // MONOCHROME1 images must be inverted and the user can invert the image too -> XOR the two
4eb96c6b4e96 improved handling of MONOCHROME1, background and invertion
am@osimis.io
parents: 428
diff changeset
35 }
4eb96c6b4e96 improved handling of MONOCHROME1, background and invertion
am@osimis.io
parents: 428
diff changeset
36
4eb96c6b4e96 improved handling of MONOCHROME1, background and invertion
am@osimis.io
parents: 428
diff changeset
37 void RadiographyWidget::RenderBackground(Orthanc::ImageAccessor& image, float minValue, float maxValue)
4eb96c6b4e96 improved handling of MONOCHROME1, background and invertion
am@osimis.io
parents: 428
diff changeset
38 {
4eb96c6b4e96 improved handling of MONOCHROME1, background and invertion
am@osimis.io
parents: 428
diff changeset
39 // wipe background before rendering
4eb96c6b4e96 improved handling of MONOCHROME1, background and invertion
am@osimis.io
parents: 428
diff changeset
40 float backgroundValue = minValue;
4eb96c6b4e96 improved handling of MONOCHROME1, background and invertion
am@osimis.io
parents: 428
diff changeset
41
4eb96c6b4e96 improved handling of MONOCHROME1, background and invertion
am@osimis.io
parents: 428
diff changeset
42 switch (scene_->GetPreferredPhotomotricDisplayMode())
4eb96c6b4e96 improved handling of MONOCHROME1, background and invertion
am@osimis.io
parents: 428
diff changeset
43 {
4eb96c6b4e96 improved handling of MONOCHROME1, background and invertion
am@osimis.io
parents: 428
diff changeset
44 case PhotometricDisplayMode_Monochrome1:
4eb96c6b4e96 improved handling of MONOCHROME1, background and invertion
am@osimis.io
parents: 428
diff changeset
45 case PhotometricDisplayMode_Default:
4eb96c6b4e96 improved handling of MONOCHROME1, background and invertion
am@osimis.io
parents: 428
diff changeset
46 if (IsInvertedInternal())
4eb96c6b4e96 improved handling of MONOCHROME1, background and invertion
am@osimis.io
parents: 428
diff changeset
47 backgroundValue = maxValue;
4eb96c6b4e96 improved handling of MONOCHROME1, background and invertion
am@osimis.io
parents: 428
diff changeset
48 else
4eb96c6b4e96 improved handling of MONOCHROME1, background and invertion
am@osimis.io
parents: 428
diff changeset
49 backgroundValue = minValue;
4eb96c6b4e96 improved handling of MONOCHROME1, background and invertion
am@osimis.io
parents: 428
diff changeset
50 break;
4eb96c6b4e96 improved handling of MONOCHROME1, background and invertion
am@osimis.io
parents: 428
diff changeset
51 case PhotometricDisplayMode_Monochrome2:
4eb96c6b4e96 improved handling of MONOCHROME1, background and invertion
am@osimis.io
parents: 428
diff changeset
52 if (IsInvertedInternal())
4eb96c6b4e96 improved handling of MONOCHROME1, background and invertion
am@osimis.io
parents: 428
diff changeset
53 backgroundValue = minValue;
4eb96c6b4e96 improved handling of MONOCHROME1, background and invertion
am@osimis.io
parents: 428
diff changeset
54 else
4eb96c6b4e96 improved handling of MONOCHROME1, background and invertion
am@osimis.io
parents: 428
diff changeset
55 backgroundValue = maxValue;
4eb96c6b4e96 improved handling of MONOCHROME1, background and invertion
am@osimis.io
parents: 428
diff changeset
56 break;
4eb96c6b4e96 improved handling of MONOCHROME1, background and invertion
am@osimis.io
parents: 428
diff changeset
57 default:
4eb96c6b4e96 improved handling of MONOCHROME1, background and invertion
am@osimis.io
parents: 428
diff changeset
58 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented);
4eb96c6b4e96 improved handling of MONOCHROME1, background and invertion
am@osimis.io
parents: 428
diff changeset
59 }
4eb96c6b4e96 improved handling of MONOCHROME1, background and invertion
am@osimis.io
parents: 428
diff changeset
60
4eb96c6b4e96 improved handling of MONOCHROME1, background and invertion
am@osimis.io
parents: 428
diff changeset
61 Orthanc::ImageProcessing::Set(image, backgroundValue);
4eb96c6b4e96 improved handling of MONOCHROME1, background and invertion
am@osimis.io
parents: 428
diff changeset
62 }
4eb96c6b4e96 improved handling of MONOCHROME1, background and invertion
am@osimis.io
parents: 428
diff changeset
63
413
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
64 bool RadiographyWidget::RenderInternal(unsigned int width,
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
65 unsigned int height,
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
66 ImageInterpolation interpolation)
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
67 {
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
68 float windowCenter, windowWidth;
428
751fb354149e ability to change the scene of the RadiographyWidget
am@osimis.io
parents: 413
diff changeset
69 scene_->GetWindowingWithDefault(windowCenter, windowWidth);
432
4eb96c6b4e96 improved handling of MONOCHROME1, background and invertion
am@osimis.io
parents: 428
diff changeset
70
413
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
71 float x0 = windowCenter - windowWidth / 2.0f;
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
72 float x1 = windowCenter + windowWidth / 2.0f;
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
73
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
74 if (windowWidth <= 0.001f) // Avoid division by zero at (*)
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
75 {
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
76 return false;
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
77 }
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
78 else
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
79 {
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
80 if (floatBuffer_.get() == NULL ||
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
81 floatBuffer_->GetWidth() != width ||
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
82 floatBuffer_->GetHeight() != height)
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
83 {
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
84 floatBuffer_.reset(new Orthanc::Image(Orthanc::PixelFormat_Float32, width, height, false));
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
85 }
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
86
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
87 if (cairoBuffer_.get() == NULL ||
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
88 cairoBuffer_->GetWidth() != width ||
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
89 cairoBuffer_->GetHeight() != height)
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
90 {
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
91 cairoBuffer_.reset(new CairoSurface(width, height));
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
92 }
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
93
432
4eb96c6b4e96 improved handling of MONOCHROME1, background and invertion
am@osimis.io
parents: 428
diff changeset
94 RenderBackground(*floatBuffer_, x0, x1);
4eb96c6b4e96 improved handling of MONOCHROME1, background and invertion
am@osimis.io
parents: 428
diff changeset
95
428
751fb354149e ability to change the scene of the RadiographyWidget
am@osimis.io
parents: 413
diff changeset
96 scene_->Render(*floatBuffer_, GetView().GetMatrix(), interpolation);
432
4eb96c6b4e96 improved handling of MONOCHROME1, background and invertion
am@osimis.io
parents: 428
diff changeset
97
413
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
98 // Conversion from Float32 to BGRA32 (cairo). Very similar to
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
99 // GrayscaleFrameRenderer => TODO MERGE?
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
100
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
101 Orthanc::ImageAccessor target;
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
102 cairoBuffer_->GetWriteableAccessor(target);
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
103
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
104 float scaling = 255.0f / (x1 - x0);
432
4eb96c6b4e96 improved handling of MONOCHROME1, background and invertion
am@osimis.io
parents: 428
diff changeset
105
4eb96c6b4e96 improved handling of MONOCHROME1, background and invertion
am@osimis.io
parents: 428
diff changeset
106 bool invert = IsInvertedInternal();
4eb96c6b4e96 improved handling of MONOCHROME1, background and invertion
am@osimis.io
parents: 428
diff changeset
107
413
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
108 for (unsigned int y = 0; y < height; y++)
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
109 {
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
110 const float* p = reinterpret_cast<const float*>(floatBuffer_->GetConstRow(y));
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
111 uint8_t* q = reinterpret_cast<uint8_t*>(target.GetRow(y));
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
112
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
113 for (unsigned int x = 0; x < width; x++, p++, q += 4)
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
114 {
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
115 uint8_t v = 0;
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
116 if (*p >= x1)
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
117 {
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
118 v = 255;
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
119 }
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
120 else if (*p <= x0)
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
121 {
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
122 v = 0;
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
123 }
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
124 else
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
125 {
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
126 // https://en.wikipedia.org/wiki/Linear_interpolation
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
127 v = static_cast<uint8_t>(scaling * (*p - x0)); // (*)
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
128 }
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
129
432
4eb96c6b4e96 improved handling of MONOCHROME1, background and invertion
am@osimis.io
parents: 428
diff changeset
130 if (invert)
413
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
131 {
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
132 v = 255 - v;
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
133 }
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
134
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
135 q[0] = v;
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
136 q[1] = v;
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
137 q[2] = v;
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
138 q[3] = 255;
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
139 }
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
140 }
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
141
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
142 return true;
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
143 }
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
144 }
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
145
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
146
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
147 bool RadiographyWidget::RenderScene(CairoContext& context,
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
148 const ViewportGeometry& view)
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
149 {
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
150 cairo_t* cr = context.GetObject();
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
151
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
152 if (RenderInternal(context.GetWidth(), context.GetHeight(), interpolation_))
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
153 {
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
154 // https://www.cairographics.org/FAQ/#paint_from_a_surface
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
155 cairo_save(cr);
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
156 cairo_identity_matrix(cr);
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
157 cairo_set_source_surface(cr, cairoBuffer_->GetObject(), 0, 0);
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
158 cairo_paint(cr);
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
159 cairo_restore(cr);
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
160 }
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
161 else
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
162 {
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
163 // https://www.cairographics.org/FAQ/#clear_a_surface
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
164 context.SetSourceColor(0, 0, 0);
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
165 cairo_paint(cr);
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
166 }
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
167
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
168 if (hasSelection_)
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
169 {
428
751fb354149e ability to change the scene of the RadiographyWidget
am@osimis.io
parents: 413
diff changeset
170 scene_->DrawBorder(context, selectedLayer_, view.GetZoom());
413
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
171 }
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
172
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
173 return true;
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
174 }
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
175
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
176
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
177 RadiographyWidget::RadiographyWidget(MessageBroker& broker,
428
751fb354149e ability to change the scene of the RadiographyWidget
am@osimis.io
parents: 413
diff changeset
178 boost::shared_ptr<RadiographyScene> scene,
413
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
179 const std::string& name) :
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
180 WorldSceneWidget(name),
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
181 IObserver(broker),
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
182 invert_(false),
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
183 interpolation_(ImageInterpolation_Nearest),
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
184 hasSelection_(false),
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
185 selectedLayer_(0) // Dummy initialization
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
186 {
428
751fb354149e ability to change the scene of the RadiographyWidget
am@osimis.io
parents: 413
diff changeset
187 SetScene(scene);
413
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
188 }
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
189
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
190
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
191 void RadiographyWidget::Select(size_t layer)
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
192 {
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
193 hasSelection_ = true;
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
194 selectedLayer_ = layer;
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
195 }
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
196
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
197
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
198 bool RadiographyWidget::LookupSelectedLayer(size_t& layer)
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
199 {
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
200 if (hasSelection_)
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
201 {
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
202 layer = selectedLayer_;
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
203 return true;
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
204 }
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
205 else
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
206 {
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
207 return false;
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
208 }
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
209 }
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
210
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
211
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
212 void RadiographyWidget::OnGeometryChanged(const RadiographyScene::GeometryChangedMessage& message)
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
213 {
432
4eb96c6b4e96 improved handling of MONOCHROME1, background and invertion
am@osimis.io
parents: 428
diff changeset
214 LOG(INFO) << "Scene geometry has changed";
4eb96c6b4e96 improved handling of MONOCHROME1, background and invertion
am@osimis.io
parents: 428
diff changeset
215
413
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
216 FitContent();
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
217 }
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
218
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
219
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
220 void RadiographyWidget::OnContentChanged(const RadiographyScene::ContentChangedMessage& message)
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
221 {
432
4eb96c6b4e96 improved handling of MONOCHROME1, background and invertion
am@osimis.io
parents: 428
diff changeset
222 LOG(INFO) << "Scene content has changed";
413
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
223 NotifyContentChanged();
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
224 }
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
225
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
226
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
227 void RadiographyWidget::SetInvert(bool invert)
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
228 {
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
229 if (invert_ != invert)
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
230 {
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
231 invert_ = invert;
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
232 NotifyContentChanged();
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
233 }
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
234 }
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
235
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
236
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
237 void RadiographyWidget::SwitchInvert()
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
238 {
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
239 invert_ = !invert_;
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
240 NotifyContentChanged();
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
241 }
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
242
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
243
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
244 void RadiographyWidget::SetInterpolation(ImageInterpolation interpolation)
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
245 {
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
246 if (interpolation_ != interpolation)
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
247 {
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
248 interpolation_ = interpolation;
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
249 NotifyContentChanged();
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
250 }
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
251 }
428
751fb354149e ability to change the scene of the RadiographyWidget
am@osimis.io
parents: 413
diff changeset
252
751fb354149e ability to change the scene of the RadiographyWidget
am@osimis.io
parents: 413
diff changeset
253 void RadiographyWidget::SetScene(boost::shared_ptr<RadiographyScene> scene)
751fb354149e ability to change the scene of the RadiographyWidget
am@osimis.io
parents: 413
diff changeset
254 {
751fb354149e ability to change the scene of the RadiographyWidget
am@osimis.io
parents: 413
diff changeset
255 if (scene_ != NULL)
751fb354149e ability to change the scene of the RadiographyWidget
am@osimis.io
parents: 413
diff changeset
256 {
751fb354149e ability to change the scene of the RadiographyWidget
am@osimis.io
parents: 413
diff changeset
257 scene_->Unregister(this);
751fb354149e ability to change the scene of the RadiographyWidget
am@osimis.io
parents: 413
diff changeset
258 }
751fb354149e ability to change the scene of the RadiographyWidget
am@osimis.io
parents: 413
diff changeset
259
751fb354149e ability to change the scene of the RadiographyWidget
am@osimis.io
parents: 413
diff changeset
260 scene_ = scene;
751fb354149e ability to change the scene of the RadiographyWidget
am@osimis.io
parents: 413
diff changeset
261
751fb354149e ability to change the scene of the RadiographyWidget
am@osimis.io
parents: 413
diff changeset
262 scene_->RegisterObserverCallback(
432
4eb96c6b4e96 improved handling of MONOCHROME1, background and invertion
am@osimis.io
parents: 428
diff changeset
263 new Callable<RadiographyWidget, RadiographyScene::GeometryChangedMessage>
4eb96c6b4e96 improved handling of MONOCHROME1, background and invertion
am@osimis.io
parents: 428
diff changeset
264 (*this, &RadiographyWidget::OnGeometryChanged));
428
751fb354149e ability to change the scene of the RadiographyWidget
am@osimis.io
parents: 413
diff changeset
265
751fb354149e ability to change the scene of the RadiographyWidget
am@osimis.io
parents: 413
diff changeset
266 scene_->RegisterObserverCallback(
432
4eb96c6b4e96 improved handling of MONOCHROME1, background and invertion
am@osimis.io
parents: 428
diff changeset
267 new Callable<RadiographyWidget, RadiographyScene::ContentChangedMessage>
4eb96c6b4e96 improved handling of MONOCHROME1, background and invertion
am@osimis.io
parents: 428
diff changeset
268 (*this, &RadiographyWidget::OnContentChanged));
4eb96c6b4e96 improved handling of MONOCHROME1, background and invertion
am@osimis.io
parents: 428
diff changeset
269
4eb96c6b4e96 improved handling of MONOCHROME1, background and invertion
am@osimis.io
parents: 428
diff changeset
270 NotifyContentChanged();
428
751fb354149e ability to change the scene of the RadiographyWidget
am@osimis.io
parents: 413
diff changeset
271
751fb354149e ability to change the scene of the RadiographyWidget
am@osimis.io
parents: 413
diff changeset
272 // force redraw
751fb354149e ability to change the scene of the RadiographyWidget
am@osimis.io
parents: 413
diff changeset
273 FitContent();
751fb354149e ability to change the scene of the RadiographyWidget
am@osimis.io
parents: 413
diff changeset
274 }
413
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
275 }