annotate OrthancStone/Sources/Deprecated/Radiography/RadiographyAlphaLayer.cpp @ 1556:8898f8f755c8

typo
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 18 Aug 2020 11:58:47 +0200
parents 244ad1e4e76a
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
430
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
1 /**
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
2 * Stone of Orthanc
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
4 * Department, University Hospital of Liege, Belgium
1280
1c7ae79c426d fix copyright years
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1238
diff changeset
5 * Copyright (C) 2017-2020 Osimis S.A., Belgium
430
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
6 *
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
7 * This program is free software: you can redistribute it and/or
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
8 * modify it under the terms of the GNU Affero General Public License
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
9 * as published by the Free Software Foundation, either version 3 of
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
10 * the License, or (at your option) any later version.
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
11 *
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
12 * This program is distributed in the hope that it will be useful, but
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
15 * Affero General Public License for more details.
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
16 *
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
17 * You should have received a copy of the GNU Affero General Public License
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
19 **/
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
20
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
21
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
22 #include "RadiographyAlphaLayer.h"
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
23
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
24 #include "RadiographyScene.h"
1455
30deba7bc8e2 simplifying include_directories
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1398
diff changeset
25 #include "../Toolbox/ImageGeometry.h"
430
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
26
1455
30deba7bc8e2 simplifying include_directories
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1398
diff changeset
27 #include <Compatibility.h>
30deba7bc8e2 simplifying include_directories
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1398
diff changeset
28 #include <Images/Image.h>
30deba7bc8e2 simplifying include_directories
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1398
diff changeset
29 #include <OrthancException.h>
1298
8a0a62189f46 replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1280
diff changeset
30
430
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
31
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
32 namespace OrthancStone
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
33 {
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
34
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
35 void RadiographyAlphaLayer::SetAlpha(Orthanc::ImageAccessor* image)
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
36 {
1298
8a0a62189f46 replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1280
diff changeset
37 std::unique_ptr<Orthanc::ImageAccessor> raii(image);
430
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
38
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
39 if (image == NULL)
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
40 {
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
41 throw Orthanc::OrthancException(Orthanc::ErrorCode_NullPointer);
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
42 }
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
43
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
44 if (image->GetFormat() != Orthanc::PixelFormat_Grayscale8)
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
45 {
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
46 throw Orthanc::OrthancException(Orthanc::ErrorCode_IncompatibleImageFormat);
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
47 }
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
48
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
49 SetSize(image->GetWidth(), image->GetHeight());
1298
8a0a62189f46 replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1280
diff changeset
50
8a0a62189f46 replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1280
diff changeset
51 #if __cplusplus < 201103L
8a0a62189f46 replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1280
diff changeset
52 alpha_.reset(raii.release());
8a0a62189f46 replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1280
diff changeset
53 #else
8a0a62189f46 replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1280
diff changeset
54 alpha_ = std::move(raii);
8a0a62189f46 replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1280
diff changeset
55 #endif
503
77e0eb83ff63 layers are now Observable and emitting LayerEdited messages
amazy
parents: 432
diff changeset
56
623
42dadae61fa9 renamed IObservable::EmitMessage() as BroadcastMessage()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 503
diff changeset
57 BroadcastMessage(RadiographyLayer::LayerEditedMessage(*this));
430
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
58 }
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
59
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
60 void RadiographyAlphaLayer::Render(Orthanc::ImageAccessor& buffer,
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
61 const AffineTransform2D& viewTransform,
1196
a5f2a6b04a31 RadiographyScene: windowing is now only applied to the Dicom layer
Alain Mazy <alain@mazy.be>
parents: 623
diff changeset
62 ImageInterpolation interpolation,
a5f2a6b04a31 RadiographyScene: windowing is now only applied to the Dicom layer
Alain Mazy <alain@mazy.be>
parents: 623
diff changeset
63 float windowCenter,
a5f2a6b04a31 RadiographyScene: windowing is now only applied to the Dicom layer
Alain Mazy <alain@mazy.be>
parents: 623
diff changeset
64 float windowWidth,
a5f2a6b04a31 RadiographyScene: windowing is now only applied to the Dicom layer
Alain Mazy <alain@mazy.be>
parents: 623
diff changeset
65 bool applyWindowing) const
430
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
66 {
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
67 if (alpha_.get() == NULL)
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
68 {
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
69 return;
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
70 }
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
71
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
72 if (buffer.GetFormat() != Orthanc::PixelFormat_Float32)
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
73 {
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
74 throw Orthanc::OrthancException(Orthanc::ErrorCode_IncompatibleImageFormat);
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
75 }
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
76
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
77 unsigned int cropX, cropY, cropWidth, cropHeight;
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
78 GetCrop(cropX, cropY, cropWidth, cropHeight);
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
79
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
80 const AffineTransform2D t = AffineTransform2D::Combine(
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
81 viewTransform, GetTransform(),
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
82 AffineTransform2D::CreateOffset(cropX, cropY));
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
83
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
84 Orthanc::ImageAccessor cropped;
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
85 alpha_->GetRegion(cropped, cropX, cropY, cropWidth, cropHeight);
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
86
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
87 Orthanc::Image tmp(Orthanc::PixelFormat_Grayscale8, buffer.GetWidth(), buffer.GetHeight(), false);
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
88
1201
ab958fd99b07 RadiographyScene fixes
Alain Mazy <alain@mazy.be>
parents: 1196
diff changeset
89 unsigned int x1, y1, x2, y2;
430
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
90
1201
ab958fd99b07 RadiographyScene fixes
Alain Mazy <alain@mazy.be>
parents: 1196
diff changeset
91 if (!OrthancStone::GetProjectiveTransformExtent(x1, y1, x2, y2,
ab958fd99b07 RadiographyScene fixes
Alain Mazy <alain@mazy.be>
parents: 1196
diff changeset
92 t.GetHomogeneousMatrix(),
ab958fd99b07 RadiographyScene fixes
Alain Mazy <alain@mazy.be>
parents: 1196
diff changeset
93 cropped.GetWidth(),
ab958fd99b07 RadiographyScene fixes
Alain Mazy <alain@mazy.be>
parents: 1196
diff changeset
94 cropped.GetHeight(),
ab958fd99b07 RadiographyScene fixes
Alain Mazy <alain@mazy.be>
parents: 1196
diff changeset
95 buffer.GetWidth(),
ab958fd99b07 RadiographyScene fixes
Alain Mazy <alain@mazy.be>
parents: 1196
diff changeset
96 buffer.GetHeight()))
ab958fd99b07 RadiographyScene fixes
Alain Mazy <alain@mazy.be>
parents: 1196
diff changeset
97 {
ab958fd99b07 RadiographyScene fixes
Alain Mazy <alain@mazy.be>
parents: 1196
diff changeset
98 return; // layer is outside the buffer
ab958fd99b07 RadiographyScene fixes
Alain Mazy <alain@mazy.be>
parents: 1196
diff changeset
99 }
ab958fd99b07 RadiographyScene fixes
Alain Mazy <alain@mazy.be>
parents: 1196
diff changeset
100
ab958fd99b07 RadiographyScene fixes
Alain Mazy <alain@mazy.be>
parents: 1196
diff changeset
101 t.Apply(tmp, cropped, interpolation, true /* clear */);
430
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
102
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
103 float value = foreground_;
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
104
1196
a5f2a6b04a31 RadiographyScene: windowing is now only applied to the Dicom layer
Alain Mazy <alain@mazy.be>
parents: 623
diff changeset
105 if (!applyWindowing) // if applying the windowing, it means we are ie rendering the image for a realtime visualization -> the foreground_ value is the value we want to see on the screen -> don't change it
430
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
106 {
1196
a5f2a6b04a31 RadiographyScene: windowing is now only applied to the Dicom layer
Alain Mazy <alain@mazy.be>
parents: 623
diff changeset
107 // if not applying the windowing, it means ie that we are saving a dicom image to file and the windowing will be applied by a viewer later on -> we want the "foreground" value to be correct once the windowing will be applied
a5f2a6b04a31 RadiographyScene: windowing is now only applied to the Dicom layer
Alain Mazy <alain@mazy.be>
parents: 623
diff changeset
108 value = windowCenter - windowWidth/2 + (foreground_ / 65535.0f) * windowWidth;
a5f2a6b04a31 RadiographyScene: windowing is now only applied to the Dicom layer
Alain Mazy <alain@mazy.be>
parents: 623
diff changeset
109
a5f2a6b04a31 RadiographyScene: windowing is now only applied to the Dicom layer
Alain Mazy <alain@mazy.be>
parents: 623
diff changeset
110 if (value < 0.0f)
430
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
111 {
1196
a5f2a6b04a31 RadiographyScene: windowing is now only applied to the Dicom layer
Alain Mazy <alain@mazy.be>
parents: 623
diff changeset
112 value = 0.0f;
a5f2a6b04a31 RadiographyScene: windowing is now only applied to the Dicom layer
Alain Mazy <alain@mazy.be>
parents: 623
diff changeset
113 }
a5f2a6b04a31 RadiographyScene: windowing is now only applied to the Dicom layer
Alain Mazy <alain@mazy.be>
parents: 623
diff changeset
114 if (value > 65535.0f)
a5f2a6b04a31 RadiographyScene: windowing is now only applied to the Dicom layer
Alain Mazy <alain@mazy.be>
parents: 623
diff changeset
115 {
a5f2a6b04a31 RadiographyScene: windowing is now only applied to the Dicom layer
Alain Mazy <alain@mazy.be>
parents: 623
diff changeset
116 value = 65535.0f;
430
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
117 }
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
118 }
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
119
1196
a5f2a6b04a31 RadiographyScene: windowing is now only applied to the Dicom layer
Alain Mazy <alain@mazy.be>
parents: 623
diff changeset
120 for (unsigned int y = y1; y <= y2; y++)
430
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
121 {
1196
a5f2a6b04a31 RadiographyScene: windowing is now only applied to the Dicom layer
Alain Mazy <alain@mazy.be>
parents: 623
diff changeset
122 float *q = reinterpret_cast<float*>(buffer.GetRow(y)) + x1;
a5f2a6b04a31 RadiographyScene: windowing is now only applied to the Dicom layer
Alain Mazy <alain@mazy.be>
parents: 623
diff changeset
123 const uint8_t *p = reinterpret_cast<uint8_t*>(tmp.GetRow(y)) + x1;
430
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
124
1196
a5f2a6b04a31 RadiographyScene: windowing is now only applied to the Dicom layer
Alain Mazy <alain@mazy.be>
parents: 623
diff changeset
125 for (unsigned int x = x1; x <= x2; x++, p++, q++)
430
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
126 {
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
127 float a = static_cast<float>(*p) / 255.0f;
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
128
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
129 *q = (a * value + (1.0f - a) * (*q));
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
130 }
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
131 }
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
132 }
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
133
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
134 bool RadiographyAlphaLayer::GetRange(float& minValue,
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
135 float& maxValue) const
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
136 {
1196
a5f2a6b04a31 RadiographyScene: windowing is now only applied to the Dicom layer
Alain Mazy <alain@mazy.be>
parents: 623
diff changeset
137 minValue = 0;
a5f2a6b04a31 RadiographyScene: windowing is now only applied to the Dicom layer
Alain Mazy <alain@mazy.be>
parents: 623
diff changeset
138 maxValue = 0;
430
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
139
1196
a5f2a6b04a31 RadiographyScene: windowing is now only applied to the Dicom layer
Alain Mazy <alain@mazy.be>
parents: 623
diff changeset
140 if (foreground_ < 0)
a5f2a6b04a31 RadiographyScene: windowing is now only applied to the Dicom layer
Alain Mazy <alain@mazy.be>
parents: 623
diff changeset
141 {
a5f2a6b04a31 RadiographyScene: windowing is now only applied to the Dicom layer
Alain Mazy <alain@mazy.be>
parents: 623
diff changeset
142 minValue = foreground_;
a5f2a6b04a31 RadiographyScene: windowing is now only applied to the Dicom layer
Alain Mazy <alain@mazy.be>
parents: 623
diff changeset
143 }
430
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
144
1196
a5f2a6b04a31 RadiographyScene: windowing is now only applied to the Dicom layer
Alain Mazy <alain@mazy.be>
parents: 623
diff changeset
145 if (foreground_ > 0)
a5f2a6b04a31 RadiographyScene: windowing is now only applied to the Dicom layer
Alain Mazy <alain@mazy.be>
parents: 623
diff changeset
146 {
a5f2a6b04a31 RadiographyScene: windowing is now only applied to the Dicom layer
Alain Mazy <alain@mazy.be>
parents: 623
diff changeset
147 maxValue = foreground_;
a5f2a6b04a31 RadiographyScene: windowing is now only applied to the Dicom layer
Alain Mazy <alain@mazy.be>
parents: 623
diff changeset
148 }
430
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
149
1196
a5f2a6b04a31 RadiographyScene: windowing is now only applied to the Dicom layer
Alain Mazy <alain@mazy.be>
parents: 623
diff changeset
150 return true;
430
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
151 }
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
152 }