annotate Framework/Radiography/RadiographyWidget.cpp @ 593:6bf8f881fcb5

OpenGLBasicPolylineRenderer
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 26 Apr 2019 13:04:56 +0200
parents 1201b12eb9f8
children 4f2416d519b4
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
492
64d90190a08c template GetLayer
Alain Mazy <alain@mazy.be>
parents: 440
diff changeset
28 #include "RadiographyMaskLayer.h"
413
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30 namespace OrthancStone
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31 {
432
4eb96c6b4e96 improved handling of MONOCHROME1, background and invertion
am@osimis.io
parents: 428
diff changeset
32
4eb96c6b4e96 improved handling of MONOCHROME1, background and invertion
am@osimis.io
parents: 428
diff changeset
33 bool RadiographyWidget::IsInvertedInternal() const
4eb96c6b4e96 improved handling of MONOCHROME1, background and invertion
am@osimis.io
parents: 428
diff changeset
34 {
516
11fa6f00e33c Dummy changes (warnings, dummy dtor to check proper deletion, line wrapping) +
Benjamin Golinvaux <bgo@osimis.io>
parents: 492
diff changeset
35 // MONOCHROME1 images must be inverted and the user can invert the
11fa6f00e33c Dummy changes (warnings, dummy dtor to check proper deletion, line wrapping) +
Benjamin Golinvaux <bgo@osimis.io>
parents: 492
diff changeset
36 // image, too -> XOR the two
11fa6f00e33c Dummy changes (warnings, dummy dtor to check proper deletion, line wrapping) +
Benjamin Golinvaux <bgo@osimis.io>
parents: 492
diff changeset
37 return (scene_->GetPreferredPhotomotricDisplayMode() ==
11fa6f00e33c Dummy changes (warnings, dummy dtor to check proper deletion, line wrapping) +
Benjamin Golinvaux <bgo@osimis.io>
parents: 492
diff changeset
38 PhotometricDisplayMode_Monochrome1) ^ invert_;
432
4eb96c6b4e96 improved handling of MONOCHROME1, background and invertion
am@osimis.io
parents: 428
diff changeset
39 }
4eb96c6b4e96 improved handling of MONOCHROME1, background and invertion
am@osimis.io
parents: 428
diff changeset
40
516
11fa6f00e33c Dummy changes (warnings, dummy dtor to check proper deletion, line wrapping) +
Benjamin Golinvaux <bgo@osimis.io>
parents: 492
diff changeset
41 void RadiographyWidget::RenderBackground(
11fa6f00e33c Dummy changes (warnings, dummy dtor to check proper deletion, line wrapping) +
Benjamin Golinvaux <bgo@osimis.io>
parents: 492
diff changeset
42 Orthanc::ImageAccessor& image, float minValue, float maxValue)
432
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 // wipe background before rendering
4eb96c6b4e96 improved handling of MONOCHROME1, background and invertion
am@osimis.io
parents: 428
diff changeset
45 float backgroundValue = minValue;
4eb96c6b4e96 improved handling of MONOCHROME1, background and invertion
am@osimis.io
parents: 428
diff changeset
46
4eb96c6b4e96 improved handling of MONOCHROME1, background and invertion
am@osimis.io
parents: 428
diff changeset
47 switch (scene_->GetPreferredPhotomotricDisplayMode())
4eb96c6b4e96 improved handling of MONOCHROME1, background and invertion
am@osimis.io
parents: 428
diff changeset
48 {
4eb96c6b4e96 improved handling of MONOCHROME1, background and invertion
am@osimis.io
parents: 428
diff changeset
49 case PhotometricDisplayMode_Monochrome1:
4eb96c6b4e96 improved handling of MONOCHROME1, background and invertion
am@osimis.io
parents: 428
diff changeset
50 case PhotometricDisplayMode_Default:
4eb96c6b4e96 improved handling of MONOCHROME1, background and invertion
am@osimis.io
parents: 428
diff changeset
51 if (IsInvertedInternal())
4eb96c6b4e96 improved handling of MONOCHROME1, background and invertion
am@osimis.io
parents: 428
diff changeset
52 backgroundValue = maxValue;
4eb96c6b4e96 improved handling of MONOCHROME1, background and invertion
am@osimis.io
parents: 428
diff changeset
53 else
4eb96c6b4e96 improved handling of MONOCHROME1, background and invertion
am@osimis.io
parents: 428
diff changeset
54 backgroundValue = minValue;
4eb96c6b4e96 improved handling of MONOCHROME1, background and invertion
am@osimis.io
parents: 428
diff changeset
55 break;
4eb96c6b4e96 improved handling of MONOCHROME1, background and invertion
am@osimis.io
parents: 428
diff changeset
56 case PhotometricDisplayMode_Monochrome2:
4eb96c6b4e96 improved handling of MONOCHROME1, background and invertion
am@osimis.io
parents: 428
diff changeset
57 if (IsInvertedInternal())
4eb96c6b4e96 improved handling of MONOCHROME1, background and invertion
am@osimis.io
parents: 428
diff changeset
58 backgroundValue = minValue;
4eb96c6b4e96 improved handling of MONOCHROME1, background and invertion
am@osimis.io
parents: 428
diff changeset
59 else
4eb96c6b4e96 improved handling of MONOCHROME1, background and invertion
am@osimis.io
parents: 428
diff changeset
60 backgroundValue = maxValue;
4eb96c6b4e96 improved handling of MONOCHROME1, background and invertion
am@osimis.io
parents: 428
diff changeset
61 break;
4eb96c6b4e96 improved handling of MONOCHROME1, background and invertion
am@osimis.io
parents: 428
diff changeset
62 default:
4eb96c6b4e96 improved handling of MONOCHROME1, background and invertion
am@osimis.io
parents: 428
diff changeset
63 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented);
4eb96c6b4e96 improved handling of MONOCHROME1, background and invertion
am@osimis.io
parents: 428
diff changeset
64 }
4eb96c6b4e96 improved handling of MONOCHROME1, background and invertion
am@osimis.io
parents: 428
diff changeset
65
516
11fa6f00e33c Dummy changes (warnings, dummy dtor to check proper deletion, line wrapping) +
Benjamin Golinvaux <bgo@osimis.io>
parents: 492
diff changeset
66 Orthanc::ImageProcessing::Set(image, static_cast<int64_t>(backgroundValue));
432
4eb96c6b4e96 improved handling of MONOCHROME1, background and invertion
am@osimis.io
parents: 428
diff changeset
67 }
4eb96c6b4e96 improved handling of MONOCHROME1, background and invertion
am@osimis.io
parents: 428
diff changeset
68
413
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
69 bool RadiographyWidget::RenderInternal(unsigned int width,
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
70 unsigned int height,
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
71 ImageInterpolation interpolation)
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
72 {
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
73 float windowCenter, windowWidth;
428
751fb354149e ability to change the scene of the RadiographyWidget
am@osimis.io
parents: 413
diff changeset
74 scene_->GetWindowingWithDefault(windowCenter, windowWidth);
432
4eb96c6b4e96 improved handling of MONOCHROME1, background and invertion
am@osimis.io
parents: 428
diff changeset
75
413
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
76 float x0 = windowCenter - windowWidth / 2.0f;
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
77 float x1 = windowCenter + windowWidth / 2.0f;
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
78
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
79 if (windowWidth <= 0.001f) // Avoid division by zero at (*)
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
80 {
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
81 return false;
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
82 }
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
83 else
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
84 {
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
85 if (floatBuffer_.get() == NULL ||
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
86 floatBuffer_->GetWidth() != width ||
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
87 floatBuffer_->GetHeight() != height)
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
88 {
516
11fa6f00e33c Dummy changes (warnings, dummy dtor to check proper deletion, line wrapping) +
Benjamin Golinvaux <bgo@osimis.io>
parents: 492
diff changeset
89 floatBuffer_.reset(new Orthanc::Image(
11fa6f00e33c Dummy changes (warnings, dummy dtor to check proper deletion, line wrapping) +
Benjamin Golinvaux <bgo@osimis.io>
parents: 492
diff changeset
90 Orthanc::PixelFormat_Float32, width, height, false));
413
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
91 }
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
92
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
93 if (cairoBuffer_.get() == NULL ||
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
94 cairoBuffer_->GetWidth() != width ||
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
95 cairoBuffer_->GetHeight() != height)
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
96 {
560
aaeec7be8fb7 add support for alpha channel in CairoSurface
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 440
diff changeset
97 cairoBuffer_.reset(new CairoSurface(width, height, false /* no alpha */));
413
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
98 }
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
99
432
4eb96c6b4e96 improved handling of MONOCHROME1, background and invertion
am@osimis.io
parents: 428
diff changeset
100 RenderBackground(*floatBuffer_, x0, x1);
4eb96c6b4e96 improved handling of MONOCHROME1, background and invertion
am@osimis.io
parents: 428
diff changeset
101
428
751fb354149e ability to change the scene of the RadiographyWidget
am@osimis.io
parents: 413
diff changeset
102 scene_->Render(*floatBuffer_, GetView().GetMatrix(), interpolation);
432
4eb96c6b4e96 improved handling of MONOCHROME1, background and invertion
am@osimis.io
parents: 428
diff changeset
103
413
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
104 // Conversion from Float32 to BGRA32 (cairo). Very similar to
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
105 // GrayscaleFrameRenderer => TODO MERGE?
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
106
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
107 Orthanc::ImageAccessor target;
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
108 cairoBuffer_->GetWriteableAccessor(target);
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
109
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
110 float scaling = 255.0f / (x1 - x0);
432
4eb96c6b4e96 improved handling of MONOCHROME1, background and invertion
am@osimis.io
parents: 428
diff changeset
111
4eb96c6b4e96 improved handling of MONOCHROME1, background and invertion
am@osimis.io
parents: 428
diff changeset
112 bool invert = IsInvertedInternal();
4eb96c6b4e96 improved handling of MONOCHROME1, background and invertion
am@osimis.io
parents: 428
diff changeset
113
413
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
114 for (unsigned int y = 0; y < height; y++)
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
115 {
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
116 const float* p = reinterpret_cast<const float*>(floatBuffer_->GetConstRow(y));
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
117 uint8_t* q = reinterpret_cast<uint8_t*>(target.GetRow(y));
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
118
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
119 for (unsigned int x = 0; x < width; x++, p++, q += 4)
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
120 {
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
121 uint8_t v = 0;
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
122 if (*p >= x1)
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
123 {
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
124 v = 255;
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
125 }
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
126 else if (*p <= x0)
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
127 {
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
128 v = 0;
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
129 }
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
130 else
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
131 {
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
132 // https://en.wikipedia.org/wiki/Linear_interpolation
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
133 v = static_cast<uint8_t>(scaling * (*p - x0)); // (*)
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
134 }
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
135
432
4eb96c6b4e96 improved handling of MONOCHROME1, background and invertion
am@osimis.io
parents: 428
diff changeset
136 if (invert)
413
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
137 {
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
138 v = 255 - v;
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 q[0] = v;
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
142 q[1] = v;
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
143 q[2] = v;
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
144 q[3] = 255;
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
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
148 return true;
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
149 }
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
150 }
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
151
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
152
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
153 bool RadiographyWidget::RenderScene(CairoContext& context,
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
154 const ViewportGeometry& view)
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
155 {
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
156 cairo_t* cr = context.GetObject();
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
157
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
158 if (RenderInternal(context.GetWidth(), context.GetHeight(), interpolation_))
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
159 {
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
160 // https://www.cairographics.org/FAQ/#paint_from_a_surface
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
161 cairo_save(cr);
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
162 cairo_identity_matrix(cr);
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
163 cairo_set_source_surface(cr, cairoBuffer_->GetObject(), 0, 0);
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
164 cairo_paint(cr);
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
165 cairo_restore(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 else
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
168 {
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
169 // https://www.cairographics.org/FAQ/#clear_a_surface
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
170 context.SetSourceColor(0, 0, 0);
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
171 cairo_paint(cr);
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
172 }
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
173
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
174 if (hasSelection_)
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
175 {
516
11fa6f00e33c Dummy changes (warnings, dummy dtor to check proper deletion, line wrapping) +
Benjamin Golinvaux <bgo@osimis.io>
parents: 492
diff changeset
176 scene_->DrawBorder(
11fa6f00e33c Dummy changes (warnings, dummy dtor to check proper deletion, line wrapping) +
Benjamin Golinvaux <bgo@osimis.io>
parents: 492
diff changeset
177 context, static_cast<unsigned int>(selectedLayer_), view.GetZoom());
413
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
178 }
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
179
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
180 return true;
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
181 }
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
182
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
183
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
184 RadiographyWidget::RadiographyWidget(MessageBroker& broker,
428
751fb354149e ability to change the scene of the RadiographyWidget
am@osimis.io
parents: 413
diff changeset
185 boost::shared_ptr<RadiographyScene> scene,
413
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
186 const std::string& name) :
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
187 WorldSceneWidget(name),
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
188 IObserver(broker),
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
189 invert_(false),
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
190 interpolation_(ImageInterpolation_Nearest),
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
191 hasSelection_(false),
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
192 selectedLayer_(0) // Dummy initialization
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
193 {
428
751fb354149e ability to change the scene of the RadiographyWidget
am@osimis.io
parents: 413
diff changeset
194 SetScene(scene);
413
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 void RadiographyWidget::Select(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 hasSelection_ = true;
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
201 selectedLayer_ = layer;
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
202 }
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
203
492
64d90190a08c template GetLayer
Alain Mazy <alain@mazy.be>
parents: 440
diff changeset
204 bool RadiographyWidget::SelectMaskLayer(size_t index)
64d90190a08c template GetLayer
Alain Mazy <alain@mazy.be>
parents: 440
diff changeset
205 {
64d90190a08c template GetLayer
Alain Mazy <alain@mazy.be>
parents: 440
diff changeset
206 std::vector<size_t> layerIndexes;
64d90190a08c template GetLayer
Alain Mazy <alain@mazy.be>
parents: 440
diff changeset
207 size_t count = 0;
64d90190a08c template GetLayer
Alain Mazy <alain@mazy.be>
parents: 440
diff changeset
208 scene_->GetLayersIndexes(layerIndexes);
64d90190a08c template GetLayer
Alain Mazy <alain@mazy.be>
parents: 440
diff changeset
209
64d90190a08c template GetLayer
Alain Mazy <alain@mazy.be>
parents: 440
diff changeset
210 for (size_t i = 0; i < layerIndexes.size(); ++i)
64d90190a08c template GetLayer
Alain Mazy <alain@mazy.be>
parents: 440
diff changeset
211 {
64d90190a08c template GetLayer
Alain Mazy <alain@mazy.be>
parents: 440
diff changeset
212 const RadiographyMaskLayer* maskLayer = dynamic_cast<const RadiographyMaskLayer*>(&(scene_->GetLayer(layerIndexes[i])));
64d90190a08c template GetLayer
Alain Mazy <alain@mazy.be>
parents: 440
diff changeset
213 if (maskLayer != NULL)
64d90190a08c template GetLayer
Alain Mazy <alain@mazy.be>
parents: 440
diff changeset
214 {
64d90190a08c template GetLayer
Alain Mazy <alain@mazy.be>
parents: 440
diff changeset
215 if (count == index)
64d90190a08c template GetLayer
Alain Mazy <alain@mazy.be>
parents: 440
diff changeset
216 {
64d90190a08c template GetLayer
Alain Mazy <alain@mazy.be>
parents: 440
diff changeset
217 Select(layerIndexes[i]);
64d90190a08c template GetLayer
Alain Mazy <alain@mazy.be>
parents: 440
diff changeset
218 return true;
64d90190a08c template GetLayer
Alain Mazy <alain@mazy.be>
parents: 440
diff changeset
219 }
64d90190a08c template GetLayer
Alain Mazy <alain@mazy.be>
parents: 440
diff changeset
220 count++;
64d90190a08c template GetLayer
Alain Mazy <alain@mazy.be>
parents: 440
diff changeset
221 }
64d90190a08c template GetLayer
Alain Mazy <alain@mazy.be>
parents: 440
diff changeset
222 }
64d90190a08c template GetLayer
Alain Mazy <alain@mazy.be>
parents: 440
diff changeset
223
64d90190a08c template GetLayer
Alain Mazy <alain@mazy.be>
parents: 440
diff changeset
224 return false;
64d90190a08c template GetLayer
Alain Mazy <alain@mazy.be>
parents: 440
diff changeset
225 }
413
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
226
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
227 bool RadiographyWidget::LookupSelectedLayer(size_t& layer)
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 (hasSelection_)
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
230 {
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
231 layer = selectedLayer_;
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
232 return true;
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
233 }
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
234 else
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
235 {
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
236 return false;
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
237 }
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
238 }
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
239
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
240
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
241 void RadiographyWidget::OnGeometryChanged(const RadiographyScene::GeometryChangedMessage& message)
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
242 {
432
4eb96c6b4e96 improved handling of MONOCHROME1, background and invertion
am@osimis.io
parents: 428
diff changeset
243 LOG(INFO) << "Scene geometry has changed";
4eb96c6b4e96 improved handling of MONOCHROME1, background and invertion
am@osimis.io
parents: 428
diff changeset
244
413
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
245 FitContent();
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
246 }
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
247
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
248
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
249 void RadiographyWidget::OnContentChanged(const RadiographyScene::ContentChangedMessage& message)
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
250 {
432
4eb96c6b4e96 improved handling of MONOCHROME1, background and invertion
am@osimis.io
parents: 428
diff changeset
251 LOG(INFO) << "Scene content has changed";
413
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
252 NotifyContentChanged();
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
253 }
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
254
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
255
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
256 void RadiographyWidget::SetInvert(bool invert)
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
257 {
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
258 if (invert_ != invert)
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
259 {
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
260 invert_ = invert;
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
261 NotifyContentChanged();
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
262 }
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
263 }
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
264
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
265
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
266 void RadiographyWidget::SwitchInvert()
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
267 {
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
268 invert_ = !invert_;
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
269 NotifyContentChanged();
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
270 }
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
271
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
272
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
273 void RadiographyWidget::SetInterpolation(ImageInterpolation interpolation)
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
274 {
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
275 if (interpolation_ != interpolation)
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
276 {
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
277 interpolation_ = interpolation;
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
278 NotifyContentChanged();
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
279 }
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
280 }
428
751fb354149e ability to change the scene of the RadiographyWidget
am@osimis.io
parents: 413
diff changeset
281
751fb354149e ability to change the scene of the RadiographyWidget
am@osimis.io
parents: 413
diff changeset
282 void RadiographyWidget::SetScene(boost::shared_ptr<RadiographyScene> scene)
751fb354149e ability to change the scene of the RadiographyWidget
am@osimis.io
parents: 413
diff changeset
283 {
751fb354149e ability to change the scene of the RadiographyWidget
am@osimis.io
parents: 413
diff changeset
284 if (scene_ != NULL)
751fb354149e ability to change the scene of the RadiographyWidget
am@osimis.io
parents: 413
diff changeset
285 {
751fb354149e ability to change the scene of the RadiographyWidget
am@osimis.io
parents: 413
diff changeset
286 scene_->Unregister(this);
751fb354149e ability to change the scene of the RadiographyWidget
am@osimis.io
parents: 413
diff changeset
287 }
751fb354149e ability to change the scene of the RadiographyWidget
am@osimis.io
parents: 413
diff changeset
288
751fb354149e ability to change the scene of the RadiographyWidget
am@osimis.io
parents: 413
diff changeset
289 scene_ = scene;
751fb354149e ability to change the scene of the RadiographyWidget
am@osimis.io
parents: 413
diff changeset
290
751fb354149e ability to change the scene of the RadiographyWidget
am@osimis.io
parents: 413
diff changeset
291 scene_->RegisterObserverCallback(
432
4eb96c6b4e96 improved handling of MONOCHROME1, background and invertion
am@osimis.io
parents: 428
diff changeset
292 new Callable<RadiographyWidget, RadiographyScene::GeometryChangedMessage>
4eb96c6b4e96 improved handling of MONOCHROME1, background and invertion
am@osimis.io
parents: 428
diff changeset
293 (*this, &RadiographyWidget::OnGeometryChanged));
428
751fb354149e ability to change the scene of the RadiographyWidget
am@osimis.io
parents: 413
diff changeset
294
751fb354149e ability to change the scene of the RadiographyWidget
am@osimis.io
parents: 413
diff changeset
295 scene_->RegisterObserverCallback(
432
4eb96c6b4e96 improved handling of MONOCHROME1, background and invertion
am@osimis.io
parents: 428
diff changeset
296 new Callable<RadiographyWidget, RadiographyScene::ContentChangedMessage>
4eb96c6b4e96 improved handling of MONOCHROME1, background and invertion
am@osimis.io
parents: 428
diff changeset
297 (*this, &RadiographyWidget::OnContentChanged));
4eb96c6b4e96 improved handling of MONOCHROME1, background and invertion
am@osimis.io
parents: 428
diff changeset
298
4eb96c6b4e96 improved handling of MONOCHROME1, background and invertion
am@osimis.io
parents: 428
diff changeset
299 NotifyContentChanged();
428
751fb354149e ability to change the scene of the RadiographyWidget
am@osimis.io
parents: 413
diff changeset
300
751fb354149e ability to change the scene of the RadiographyWidget
am@osimis.io
parents: 413
diff changeset
301 // force redraw
751fb354149e ability to change the scene of the RadiographyWidget
am@osimis.io
parents: 413
diff changeset
302 FitContent();
751fb354149e ability to change the scene of the RadiographyWidget
am@osimis.io
parents: 413
diff changeset
303 }
413
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
304 }