annotate Framework/Radiography/RadiographyWidget.cpp @ 1196:a5f2a6b04a31

RadiographyScene: windowing is now only applied to the Dicom layer
author Alain Mazy <alain@mazy.be>
date Wed, 27 Nov 2019 17:51:33 +0100
parents 4663f158c748
children 922d2e61aa5d
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() ==
739
be9c1530d40a deprecating enum SliceImageQuality
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 726
diff changeset
38 RadiographyPhotometricDisplayMode_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 {
739
be9c1530d40a deprecating enum SliceImageQuality
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 726
diff changeset
49 case RadiographyPhotometricDisplayMode_Monochrome1:
be9c1530d40a deprecating enum SliceImageQuality
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 726
diff changeset
50 case RadiographyPhotometricDisplayMode_Default:
432
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;
739
be9c1530d40a deprecating enum SliceImageQuality
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 726
diff changeset
56 case RadiographyPhotometricDisplayMode_Monochrome2:
432
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 {
1196
a5f2a6b04a31 RadiographyScene: windowing is now only applied to the Dicom layer
Alain Mazy <alain@mazy.be>
parents: 1131
diff changeset
73 if (floatBuffer_.get() == NULL ||
a5f2a6b04a31 RadiographyScene: windowing is now only applied to the Dicom layer
Alain Mazy <alain@mazy.be>
parents: 1131
diff changeset
74 floatBuffer_->GetWidth() != width ||
a5f2a6b04a31 RadiographyScene: windowing is now only applied to the Dicom layer
Alain Mazy <alain@mazy.be>
parents: 1131
diff changeset
75 floatBuffer_->GetHeight() != height)
a5f2a6b04a31 RadiographyScene: windowing is now only applied to the Dicom layer
Alain Mazy <alain@mazy.be>
parents: 1131
diff changeset
76 {
a5f2a6b04a31 RadiographyScene: windowing is now only applied to the Dicom layer
Alain Mazy <alain@mazy.be>
parents: 1131
diff changeset
77 floatBuffer_.reset(new Orthanc::Image(
a5f2a6b04a31 RadiographyScene: windowing is now only applied to the Dicom layer
Alain Mazy <alain@mazy.be>
parents: 1131
diff changeset
78 Orthanc::PixelFormat_Float32, width, height, false));
a5f2a6b04a31 RadiographyScene: windowing is now only applied to the Dicom layer
Alain Mazy <alain@mazy.be>
parents: 1131
diff changeset
79 }
413
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
80
1196
a5f2a6b04a31 RadiographyScene: windowing is now only applied to the Dicom layer
Alain Mazy <alain@mazy.be>
parents: 1131
diff changeset
81 if (cairoBuffer_.get() == NULL ||
a5f2a6b04a31 RadiographyScene: windowing is now only applied to the Dicom layer
Alain Mazy <alain@mazy.be>
parents: 1131
diff changeset
82 cairoBuffer_->GetWidth() != width ||
a5f2a6b04a31 RadiographyScene: windowing is now only applied to the Dicom layer
Alain Mazy <alain@mazy.be>
parents: 1131
diff changeset
83 cairoBuffer_->GetHeight() != height)
413
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
84 {
1196
a5f2a6b04a31 RadiographyScene: windowing is now only applied to the Dicom layer
Alain Mazy <alain@mazy.be>
parents: 1131
diff changeset
85 cairoBuffer_.reset(new CairoSurface(width, height, false /* no alpha */));
a5f2a6b04a31 RadiographyScene: windowing is now only applied to the Dicom layer
Alain Mazy <alain@mazy.be>
parents: 1131
diff changeset
86 }
a5f2a6b04a31 RadiographyScene: windowing is now only applied to the Dicom layer
Alain Mazy <alain@mazy.be>
parents: 1131
diff changeset
87
a5f2a6b04a31 RadiographyScene: windowing is now only applied to the Dicom layer
Alain Mazy <alain@mazy.be>
parents: 1131
diff changeset
88 RenderBackground(*floatBuffer_, 0.0, 65535.0);
a5f2a6b04a31 RadiographyScene: windowing is now only applied to the Dicom layer
Alain Mazy <alain@mazy.be>
parents: 1131
diff changeset
89
a5f2a6b04a31 RadiographyScene: windowing is now only applied to the Dicom layer
Alain Mazy <alain@mazy.be>
parents: 1131
diff changeset
90 scene_->Render(*floatBuffer_, GetView().GetMatrix(), interpolation, true);
413
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
91
1196
a5f2a6b04a31 RadiographyScene: windowing is now only applied to the Dicom layer
Alain Mazy <alain@mazy.be>
parents: 1131
diff changeset
92 // Conversion from Float32 to BGRA32 (cairo). Very similar to
a5f2a6b04a31 RadiographyScene: windowing is now only applied to the Dicom layer
Alain Mazy <alain@mazy.be>
parents: 1131
diff changeset
93 // GrayscaleFrameRenderer => TODO MERGE?
a5f2a6b04a31 RadiographyScene: windowing is now only applied to the Dicom layer
Alain Mazy <alain@mazy.be>
parents: 1131
diff changeset
94 Orthanc::ImageAccessor target;
a5f2a6b04a31 RadiographyScene: windowing is now only applied to the Dicom layer
Alain Mazy <alain@mazy.be>
parents: 1131
diff changeset
95 cairoBuffer_->GetWriteableAccessor(target);
432
4eb96c6b4e96 improved handling of MONOCHROME1, background and invertion
am@osimis.io
parents: 428
diff changeset
96
1196
a5f2a6b04a31 RadiographyScene: windowing is now only applied to the Dicom layer
Alain Mazy <alain@mazy.be>
parents: 1131
diff changeset
97 bool invert = IsInvertedInternal();
432
4eb96c6b4e96 improved handling of MONOCHROME1, background and invertion
am@osimis.io
parents: 428
diff changeset
98
1196
a5f2a6b04a31 RadiographyScene: windowing is now only applied to the Dicom layer
Alain Mazy <alain@mazy.be>
parents: 1131
diff changeset
99 for (unsigned int y = 0; y < height; y++)
a5f2a6b04a31 RadiographyScene: windowing is now only applied to the Dicom layer
Alain Mazy <alain@mazy.be>
parents: 1131
diff changeset
100 {
a5f2a6b04a31 RadiographyScene: windowing is now only applied to the Dicom layer
Alain Mazy <alain@mazy.be>
parents: 1131
diff changeset
101 const float* p = reinterpret_cast<const float*>(floatBuffer_->GetConstRow(y));
a5f2a6b04a31 RadiographyScene: windowing is now only applied to the Dicom layer
Alain Mazy <alain@mazy.be>
parents: 1131
diff changeset
102 uint8_t* q = reinterpret_cast<uint8_t*>(target.GetRow(y));
432
4eb96c6b4e96 improved handling of MONOCHROME1, background and invertion
am@osimis.io
parents: 428
diff changeset
103
1196
a5f2a6b04a31 RadiographyScene: windowing is now only applied to the Dicom layer
Alain Mazy <alain@mazy.be>
parents: 1131
diff changeset
104 for (unsigned int x = 0; x < width; x++, p++, q += 4)
413
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
105 {
1196
a5f2a6b04a31 RadiographyScene: windowing is now only applied to the Dicom layer
Alain Mazy <alain@mazy.be>
parents: 1131
diff changeset
106 uint8_t v = 0;
a5f2a6b04a31 RadiographyScene: windowing is now only applied to the Dicom layer
Alain Mazy <alain@mazy.be>
parents: 1131
diff changeset
107 if (*p >= 65535.0)
a5f2a6b04a31 RadiographyScene: windowing is now only applied to the Dicom layer
Alain Mazy <alain@mazy.be>
parents: 1131
diff changeset
108 {
a5f2a6b04a31 RadiographyScene: windowing is now only applied to the Dicom layer
Alain Mazy <alain@mazy.be>
parents: 1131
diff changeset
109 v = 255;
a5f2a6b04a31 RadiographyScene: windowing is now only applied to the Dicom layer
Alain Mazy <alain@mazy.be>
parents: 1131
diff changeset
110 }
a5f2a6b04a31 RadiographyScene: windowing is now only applied to the Dicom layer
Alain Mazy <alain@mazy.be>
parents: 1131
diff changeset
111 else if (*p <= 0.0)
413
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
112 {
1196
a5f2a6b04a31 RadiographyScene: windowing is now only applied to the Dicom layer
Alain Mazy <alain@mazy.be>
parents: 1131
diff changeset
113 v = 0;
a5f2a6b04a31 RadiographyScene: windowing is now only applied to the Dicom layer
Alain Mazy <alain@mazy.be>
parents: 1131
diff changeset
114 }
a5f2a6b04a31 RadiographyScene: windowing is now only applied to the Dicom layer
Alain Mazy <alain@mazy.be>
parents: 1131
diff changeset
115 else
a5f2a6b04a31 RadiographyScene: windowing is now only applied to the Dicom layer
Alain Mazy <alain@mazy.be>
parents: 1131
diff changeset
116 {
a5f2a6b04a31 RadiographyScene: windowing is now only applied to the Dicom layer
Alain Mazy <alain@mazy.be>
parents: 1131
diff changeset
117 v = static_cast<uint8_t>(*p / 256.0);
a5f2a6b04a31 RadiographyScene: windowing is now only applied to the Dicom layer
Alain Mazy <alain@mazy.be>
parents: 1131
diff changeset
118 }
413
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
119
1196
a5f2a6b04a31 RadiographyScene: windowing is now only applied to the Dicom layer
Alain Mazy <alain@mazy.be>
parents: 1131
diff changeset
120 if (invert)
a5f2a6b04a31 RadiographyScene: windowing is now only applied to the Dicom layer
Alain Mazy <alain@mazy.be>
parents: 1131
diff changeset
121 {
a5f2a6b04a31 RadiographyScene: windowing is now only applied to the Dicom layer
Alain Mazy <alain@mazy.be>
parents: 1131
diff changeset
122 v = 255 - v;
a5f2a6b04a31 RadiographyScene: windowing is now only applied to the Dicom layer
Alain Mazy <alain@mazy.be>
parents: 1131
diff changeset
123 }
413
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
124
1196
a5f2a6b04a31 RadiographyScene: windowing is now only applied to the Dicom layer
Alain Mazy <alain@mazy.be>
parents: 1131
diff changeset
125 q[0] = v;
a5f2a6b04a31 RadiographyScene: windowing is now only applied to the Dicom layer
Alain Mazy <alain@mazy.be>
parents: 1131
diff changeset
126 q[1] = v;
a5f2a6b04a31 RadiographyScene: windowing is now only applied to the Dicom layer
Alain Mazy <alain@mazy.be>
parents: 1131
diff changeset
127 q[2] = v;
a5f2a6b04a31 RadiographyScene: windowing is now only applied to the Dicom layer
Alain Mazy <alain@mazy.be>
parents: 1131
diff changeset
128 q[3] = 255;
413
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
129 }
1196
a5f2a6b04a31 RadiographyScene: windowing is now only applied to the Dicom layer
Alain Mazy <alain@mazy.be>
parents: 1131
diff changeset
130 }
413
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
131
1196
a5f2a6b04a31 RadiographyScene: windowing is now only applied to the Dicom layer
Alain Mazy <alain@mazy.be>
parents: 1131
diff changeset
132 return true;
413
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
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
136 bool RadiographyWidget::RenderScene(CairoContext& context,
726
4f2416d519b4 moving layers, widgets and loaders to Deprecated namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 561
diff changeset
137 const Deprecated::ViewportGeometry& view)
413
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
138 {
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
139 cairo_t* cr = context.GetObject();
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
140
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
141 if (RenderInternal(context.GetWidth(), context.GetHeight(), interpolation_))
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
142 {
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
143 // https://www.cairographics.org/FAQ/#paint_from_a_surface
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
144 cairo_save(cr);
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
145 cairo_identity_matrix(cr);
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
146 cairo_set_source_surface(cr, cairoBuffer_->GetObject(), 0, 0);
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
147 cairo_paint(cr);
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
148 cairo_restore(cr);
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
149 }
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
150 else
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
151 {
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
152 // https://www.cairographics.org/FAQ/#clear_a_surface
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
153 context.SetSourceColor(0, 0, 0);
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
154 cairo_paint(cr);
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
155 }
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
156
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
157 if (hasSelection_)
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
158 {
516
11fa6f00e33c Dummy changes (warnings, dummy dtor to check proper deletion, line wrapping) +
Benjamin Golinvaux <bgo@osimis.io>
parents: 492
diff changeset
159 scene_->DrawBorder(
11fa6f00e33c Dummy changes (warnings, dummy dtor to check proper deletion, line wrapping) +
Benjamin Golinvaux <bgo@osimis.io>
parents: 492
diff changeset
160 context, static_cast<unsigned int>(selectedLayer_), view.GetZoom());
413
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
161 }
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
162
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
163 return true;
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
164 }
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
165
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
166
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
167 RadiographyWidget::RadiographyWidget(MessageBroker& broker,
428
751fb354149e ability to change the scene of the RadiographyWidget
am@osimis.io
parents: 413
diff changeset
168 boost::shared_ptr<RadiographyScene> scene,
413
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
169 const std::string& name) :
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
170 WorldSceneWidget(name),
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
171 IObserver(broker),
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
172 invert_(false),
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
173 interpolation_(ImageInterpolation_Nearest),
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
174 hasSelection_(false),
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
175 selectedLayer_(0) // Dummy initialization
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
176 {
428
751fb354149e ability to change the scene of the RadiographyWidget
am@osimis.io
parents: 413
diff changeset
177 SetScene(scene);
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
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
181 void RadiographyWidget::Select(size_t layer)
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
182 {
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
183 hasSelection_ = true;
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
184 selectedLayer_ = layer;
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
185 }
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
186
1131
4663f158c748 RadiographyWidget is now notified when a layer is removed from the scene
Alain Mazy <alain@mazy.be>
parents: 1112
diff changeset
187 void RadiographyWidget::ClearSelectedLayer()
4663f158c748 RadiographyWidget is now notified when a layer is removed from the scene
Alain Mazy <alain@mazy.be>
parents: 1112
diff changeset
188 {
4663f158c748 RadiographyWidget is now notified when a layer is removed from the scene
Alain Mazy <alain@mazy.be>
parents: 1112
diff changeset
189 hasSelection_ = false;
4663f158c748 RadiographyWidget is now notified when a layer is removed from the scene
Alain Mazy <alain@mazy.be>
parents: 1112
diff changeset
190 }
4663f158c748 RadiographyWidget is now notified when a layer is removed from the scene
Alain Mazy <alain@mazy.be>
parents: 1112
diff changeset
191
492
64d90190a08c template GetLayer
Alain Mazy <alain@mazy.be>
parents: 440
diff changeset
192 bool RadiographyWidget::SelectMaskLayer(size_t index)
64d90190a08c template GetLayer
Alain Mazy <alain@mazy.be>
parents: 440
diff changeset
193 {
64d90190a08c template GetLayer
Alain Mazy <alain@mazy.be>
parents: 440
diff changeset
194 std::vector<size_t> layerIndexes;
64d90190a08c template GetLayer
Alain Mazy <alain@mazy.be>
parents: 440
diff changeset
195 size_t count = 0;
64d90190a08c template GetLayer
Alain Mazy <alain@mazy.be>
parents: 440
diff changeset
196 scene_->GetLayersIndexes(layerIndexes);
64d90190a08c template GetLayer
Alain Mazy <alain@mazy.be>
parents: 440
diff changeset
197
64d90190a08c template GetLayer
Alain Mazy <alain@mazy.be>
parents: 440
diff changeset
198 for (size_t i = 0; i < layerIndexes.size(); ++i)
64d90190a08c template GetLayer
Alain Mazy <alain@mazy.be>
parents: 440
diff changeset
199 {
64d90190a08c template GetLayer
Alain Mazy <alain@mazy.be>
parents: 440
diff changeset
200 const RadiographyMaskLayer* maskLayer = dynamic_cast<const RadiographyMaskLayer*>(&(scene_->GetLayer(layerIndexes[i])));
64d90190a08c template GetLayer
Alain Mazy <alain@mazy.be>
parents: 440
diff changeset
201 if (maskLayer != NULL)
64d90190a08c template GetLayer
Alain Mazy <alain@mazy.be>
parents: 440
diff changeset
202 {
64d90190a08c template GetLayer
Alain Mazy <alain@mazy.be>
parents: 440
diff changeset
203 if (count == index)
64d90190a08c template GetLayer
Alain Mazy <alain@mazy.be>
parents: 440
diff changeset
204 {
64d90190a08c template GetLayer
Alain Mazy <alain@mazy.be>
parents: 440
diff changeset
205 Select(layerIndexes[i]);
64d90190a08c template GetLayer
Alain Mazy <alain@mazy.be>
parents: 440
diff changeset
206 return true;
64d90190a08c template GetLayer
Alain Mazy <alain@mazy.be>
parents: 440
diff changeset
207 }
64d90190a08c template GetLayer
Alain Mazy <alain@mazy.be>
parents: 440
diff changeset
208 count++;
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 }
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 return false;
64d90190a08c template GetLayer
Alain Mazy <alain@mazy.be>
parents: 440
diff changeset
213 }
413
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
214
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
215 bool RadiographyWidget::LookupSelectedLayer(size_t& layer)
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
216 {
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
217 if (hasSelection_)
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
218 {
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
219 layer = selectedLayer_;
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
220 return true;
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
221 }
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
222 else
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
223 {
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
224 return false;
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
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
228
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
229 void RadiographyWidget::OnGeometryChanged(const RadiographyScene::GeometryChangedMessage& message)
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
230 {
1112
d33ae2b0db9d less logs + allow changing the size of the RadiographyLayer (to replace a low res image by a high res image)
Alain Mazy <alain@mazy.be>
parents: 739
diff changeset
231 // LOG(INFO) << "Scene geometry has changed";
413
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
232 FitContent();
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 void RadiographyWidget::OnContentChanged(const RadiographyScene::ContentChangedMessage& message)
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
237 {
1112
d33ae2b0db9d less logs + allow changing the size of the RadiographyLayer (to replace a low res image by a high res image)
Alain Mazy <alain@mazy.be>
parents: 739
diff changeset
238 // LOG(INFO) << "Scene content has changed";
413
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
239 NotifyContentChanged();
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
240 }
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
241
1131
4663f158c748 RadiographyWidget is now notified when a layer is removed from the scene
Alain Mazy <alain@mazy.be>
parents: 1112
diff changeset
242 void RadiographyWidget::OnLayerRemoved(const RadiographyScene::LayerRemovedMessage& message)
4663f158c748 RadiographyWidget is now notified when a layer is removed from the scene
Alain Mazy <alain@mazy.be>
parents: 1112
diff changeset
243 {
4663f158c748 RadiographyWidget is now notified when a layer is removed from the scene
Alain Mazy <alain@mazy.be>
parents: 1112
diff changeset
244 size_t removedLayerIndex = message.GetLayerIndex();
4663f158c748 RadiographyWidget is now notified when a layer is removed from the scene
Alain Mazy <alain@mazy.be>
parents: 1112
diff changeset
245 if (hasSelection_ && selectedLayer_ == removedLayerIndex)
4663f158c748 RadiographyWidget is now notified when a layer is removed from the scene
Alain Mazy <alain@mazy.be>
parents: 1112
diff changeset
246 {
4663f158c748 RadiographyWidget is now notified when a layer is removed from the scene
Alain Mazy <alain@mazy.be>
parents: 1112
diff changeset
247 ClearSelectedLayer();
4663f158c748 RadiographyWidget is now notified when a layer is removed from the scene
Alain Mazy <alain@mazy.be>
parents: 1112
diff changeset
248 }
4663f158c748 RadiographyWidget is now notified when a layer is removed from the scene
Alain Mazy <alain@mazy.be>
parents: 1112
diff changeset
249 }
413
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
250
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
251 void RadiographyWidget::SetInvert(bool invert)
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
252 {
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
253 if (invert_ != invert)
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
254 {
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
255 invert_ = invert;
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
256 NotifyContentChanged();
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
257 }
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
258 }
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
259
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
260
1131
4663f158c748 RadiographyWidget is now notified when a layer is removed from the scene
Alain Mazy <alain@mazy.be>
parents: 1112
diff changeset
261 void RadiographyWidget::SwitchInvert()
413
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
262 {
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
263 invert_ = !invert_;
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
264 NotifyContentChanged();
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
265 }
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
266
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
267
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
268 void RadiographyWidget::SetInterpolation(ImageInterpolation interpolation)
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
269 {
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
270 if (interpolation_ != interpolation)
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
271 {
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
272 interpolation_ = interpolation;
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
273 NotifyContentChanged();
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
274 }
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
275 }
428
751fb354149e ability to change the scene of the RadiographyWidget
am@osimis.io
parents: 413
diff changeset
276
751fb354149e ability to change the scene of the RadiographyWidget
am@osimis.io
parents: 413
diff changeset
277 void RadiographyWidget::SetScene(boost::shared_ptr<RadiographyScene> scene)
751fb354149e ability to change the scene of the RadiographyWidget
am@osimis.io
parents: 413
diff changeset
278 {
751fb354149e ability to change the scene of the RadiographyWidget
am@osimis.io
parents: 413
diff changeset
279 if (scene_ != NULL)
751fb354149e ability to change the scene of the RadiographyWidget
am@osimis.io
parents: 413
diff changeset
280 {
751fb354149e ability to change the scene of the RadiographyWidget
am@osimis.io
parents: 413
diff changeset
281 scene_->Unregister(this);
751fb354149e ability to change the scene of the RadiographyWidget
am@osimis.io
parents: 413
diff changeset
282 }
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 scene_ = scene;
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_->RegisterObserverCallback(
432
4eb96c6b4e96 improved handling of MONOCHROME1, background and invertion
am@osimis.io
parents: 428
diff changeset
287 new Callable<RadiographyWidget, RadiographyScene::GeometryChangedMessage>
4eb96c6b4e96 improved handling of MONOCHROME1, background and invertion
am@osimis.io
parents: 428
diff changeset
288 (*this, &RadiographyWidget::OnGeometryChanged));
428
751fb354149e ability to change the scene of the RadiographyWidget
am@osimis.io
parents: 413
diff changeset
289
751fb354149e ability to change the scene of the RadiographyWidget
am@osimis.io
parents: 413
diff changeset
290 scene_->RegisterObserverCallback(
432
4eb96c6b4e96 improved handling of MONOCHROME1, background and invertion
am@osimis.io
parents: 428
diff changeset
291 new Callable<RadiographyWidget, RadiographyScene::ContentChangedMessage>
4eb96c6b4e96 improved handling of MONOCHROME1, background and invertion
am@osimis.io
parents: 428
diff changeset
292 (*this, &RadiographyWidget::OnContentChanged));
4eb96c6b4e96 improved handling of MONOCHROME1, background and invertion
am@osimis.io
parents: 428
diff changeset
293
1131
4663f158c748 RadiographyWidget is now notified when a layer is removed from the scene
Alain Mazy <alain@mazy.be>
parents: 1112
diff changeset
294 scene_->RegisterObserverCallback(
4663f158c748 RadiographyWidget is now notified when a layer is removed from the scene
Alain Mazy <alain@mazy.be>
parents: 1112
diff changeset
295 new Callable<RadiographyWidget, RadiographyScene::LayerRemovedMessage>
4663f158c748 RadiographyWidget is now notified when a layer is removed from the scene
Alain Mazy <alain@mazy.be>
parents: 1112
diff changeset
296 (*this, &RadiographyWidget::OnLayerRemoved));
4663f158c748 RadiographyWidget is now notified when a layer is removed from the scene
Alain Mazy <alain@mazy.be>
parents: 1112
diff changeset
297
432
4eb96c6b4e96 improved handling of MONOCHROME1, background and invertion
am@osimis.io
parents: 428
diff changeset
298 NotifyContentChanged();
428
751fb354149e ability to change the scene of the RadiographyWidget
am@osimis.io
parents: 413
diff changeset
299
751fb354149e ability to change the scene of the RadiographyWidget
am@osimis.io
parents: 413
diff changeset
300 // force redraw
751fb354149e ability to change the scene of the RadiographyWidget
am@osimis.io
parents: 413
diff changeset
301 FitContent();
751fb354149e ability to change the scene of the RadiographyWidget
am@osimis.io
parents: 413
diff changeset
302 }
413
18b707fb8620 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
303 }