annotate OrthancStone/Sources/Scene2D/GrayscaleStyleConfigurator.cpp @ 1515:b750b6eab453

sync
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 07 Jul 2020 20:52:35 +0200
parents 244ad1e4e76a
children 85e117739eca
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
814
aead999345e0 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 /**
aead999345e0 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2 * Stone of Orthanc
aead999345e0 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
aead999345e0 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
4 * Department, University Hospital of Liege, Belgium
1270
2d8ab34c8c91 upgrade to year 2020
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1209
diff changeset
5 * Copyright (C) 2017-2020 Osimis S.A., Belgium
814
aead999345e0 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
6 *
aead999345e0 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 * This program is free software: you can redistribute it and/or
aead999345e0 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 * modify it under the terms of the GNU Affero General Public License
aead999345e0 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 * as published by the Free Software Foundation, either version 3 of
aead999345e0 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 * the License, or (at your option) any later version.
aead999345e0 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 *
aead999345e0 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 * This program is distributed in the hope that it will be useful, but
aead999345e0 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
aead999345e0 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
aead999345e0 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 * Affero General Public License for more details.
aead999345e0 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16 *
aead999345e0 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
17 * You should have received a copy of the GNU Affero General Public License
aead999345e0 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
aead999345e0 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
19 **/
aead999345e0 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20
aead999345e0 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21
aead999345e0 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22 #include "GrayscaleStyleConfigurator.h"
aead999345e0 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23
835
0965b665c653 windowing and linear interpolation in GrayscaleStyleConfigurator
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 814
diff changeset
24 #include "FloatTextureSceneLayer.h"
0965b665c653 windowing and linear interpolation in GrayscaleStyleConfigurator
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 814
diff changeset
25
1455
30deba7bc8e2 simplifying include_directories
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1300
diff changeset
26 #include <OrthancException.h>
814
aead999345e0 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27
aead999345e0 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28 namespace OrthancStone
aead999345e0 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29 {
1179
177e7d431cd1 log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1163
diff changeset
30 GrayscaleStyleConfigurator::GrayscaleStyleConfigurator() :
177e7d431cd1 log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1163
diff changeset
31 revision_(0),
177e7d431cd1 log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1163
diff changeset
32 linearInterpolation_(false),
1212
ab06dfdf3b75 integration mainline->broker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1179 1209
diff changeset
33 hasWindowingOverride_(false),
1179
177e7d431cd1 log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1163
diff changeset
34 customWindowWidth_(0),
177e7d431cd1 log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1163
diff changeset
35 customWindowCenter_(0),
1212
ab06dfdf3b75 integration mainline->broker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1179 1209
diff changeset
36 hasInversionOverride_(false),
1179
177e7d431cd1 log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1163
diff changeset
37 inverted_(false),
177e7d431cd1 log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1163
diff changeset
38 applyLog_(false)
177e7d431cd1 log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1163
diff changeset
39 {
177e7d431cd1 log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1163
diff changeset
40 }
177e7d431cd1 log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1163
diff changeset
41
836
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 835
diff changeset
42 void GrayscaleStyleConfigurator::SetWindowing(ImageWindowing windowing)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 835
diff changeset
43 {
1209
b5dec783ba08 Fixed the style configurator to only set inversion on the image if it has been
Benjamin Golinvaux <bgo@osimis.io>
parents: 1061
diff changeset
44 hasWindowingOverride_ = true;
836
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 835
diff changeset
45 windowing_ = windowing;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 835
diff changeset
46 revision_++;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 835
diff changeset
47 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 835
diff changeset
48
913
2b4b6b86520a Re-enabled gl debug output in GuiAdapter +
Benjamin Golinvaux <bgo@osimis.io>
parents: 836
diff changeset
49 void GrayscaleStyleConfigurator::SetCustomWindowing(float windowCenter, float windowWidth)
2b4b6b86520a Re-enabled gl debug output in GuiAdapter +
Benjamin Golinvaux <bgo@osimis.io>
parents: 836
diff changeset
50 {
2b4b6b86520a Re-enabled gl debug output in GuiAdapter +
Benjamin Golinvaux <bgo@osimis.io>
parents: 836
diff changeset
51 SetWindowing(ImageWindowing_Custom);
2b4b6b86520a Re-enabled gl debug output in GuiAdapter +
Benjamin Golinvaux <bgo@osimis.io>
parents: 836
diff changeset
52 customWindowCenter_ = windowCenter;
2b4b6b86520a Re-enabled gl debug output in GuiAdapter +
Benjamin Golinvaux <bgo@osimis.io>
parents: 836
diff changeset
53 customWindowWidth_ = windowWidth;
2b4b6b86520a Re-enabled gl debug output in GuiAdapter +
Benjamin Golinvaux <bgo@osimis.io>
parents: 836
diff changeset
54 }
836
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 835
diff changeset
55
1061
eb28dfe432f7 fixed typo in assert. msg. + getters for custom windowing in grayscale layer configurator.
Benjamin Golinvaux <bgo@osimis.io>
parents: 914
diff changeset
56 void GrayscaleStyleConfigurator::GetCustomWindowing(float& windowCenter, float& windowWidth) const
eb28dfe432f7 fixed typo in assert. msg. + getters for custom windowing in grayscale layer configurator.
Benjamin Golinvaux <bgo@osimis.io>
parents: 914
diff changeset
57 {
eb28dfe432f7 fixed typo in assert. msg. + getters for custom windowing in grayscale layer configurator.
Benjamin Golinvaux <bgo@osimis.io>
parents: 914
diff changeset
58 windowCenter = customWindowCenter_;
eb28dfe432f7 fixed typo in assert. msg. + getters for custom windowing in grayscale layer configurator.
Benjamin Golinvaux <bgo@osimis.io>
parents: 914
diff changeset
59 windowWidth = customWindowWidth_;
eb28dfe432f7 fixed typo in assert. msg. + getters for custom windowing in grayscale layer configurator.
Benjamin Golinvaux <bgo@osimis.io>
parents: 914
diff changeset
60 }
914
4d1f57773b5b Added image inversion support in GrayscaleStyleConfigurator + OpenGLFloatTextureProgram
Benjamin Golinvaux <bgo@osimis.io>
parents: 913
diff changeset
61
4d1f57773b5b Added image inversion support in GrayscaleStyleConfigurator + OpenGLFloatTextureProgram
Benjamin Golinvaux <bgo@osimis.io>
parents: 913
diff changeset
62 void GrayscaleStyleConfigurator::SetInverted(bool inverted)
4d1f57773b5b Added image inversion support in GrayscaleStyleConfigurator + OpenGLFloatTextureProgram
Benjamin Golinvaux <bgo@osimis.io>
parents: 913
diff changeset
63 {
1209
b5dec783ba08 Fixed the style configurator to only set inversion on the image if it has been
Benjamin Golinvaux <bgo@osimis.io>
parents: 1061
diff changeset
64 hasInversionOverride_ = true;
914
4d1f57773b5b Added image inversion support in GrayscaleStyleConfigurator + OpenGLFloatTextureProgram
Benjamin Golinvaux <bgo@osimis.io>
parents: 913
diff changeset
65 inverted_ = inverted;
4d1f57773b5b Added image inversion support in GrayscaleStyleConfigurator + OpenGLFloatTextureProgram
Benjamin Golinvaux <bgo@osimis.io>
parents: 913
diff changeset
66 revision_++;
4d1f57773b5b Added image inversion support in GrayscaleStyleConfigurator + OpenGLFloatTextureProgram
Benjamin Golinvaux <bgo@osimis.io>
parents: 913
diff changeset
67 }
4d1f57773b5b Added image inversion support in GrayscaleStyleConfigurator + OpenGLFloatTextureProgram
Benjamin Golinvaux <bgo@osimis.io>
parents: 913
diff changeset
68
835
0965b665c653 windowing and linear interpolation in GrayscaleStyleConfigurator
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 814
diff changeset
69 void GrayscaleStyleConfigurator::SetLinearInterpolation(bool enabled)
0965b665c653 windowing and linear interpolation in GrayscaleStyleConfigurator
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 814
diff changeset
70 {
0965b665c653 windowing and linear interpolation in GrayscaleStyleConfigurator
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 814
diff changeset
71 linearInterpolation_ = enabled;
0965b665c653 windowing and linear interpolation in GrayscaleStyleConfigurator
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 814
diff changeset
72 revision_++;
0965b665c653 windowing and linear interpolation in GrayscaleStyleConfigurator
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 814
diff changeset
73 }
0965b665c653 windowing and linear interpolation in GrayscaleStyleConfigurator
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 814
diff changeset
74
1163
ba9db2ad317c test log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1061
diff changeset
75 void GrayscaleStyleConfigurator::SetApplyLog(bool apply)
ba9db2ad317c test log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1061
diff changeset
76 {
ba9db2ad317c test log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1061
diff changeset
77 applyLog_ = apply;
ba9db2ad317c test log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1061
diff changeset
78 revision_++;
ba9db2ad317c test log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1061
diff changeset
79 }
ba9db2ad317c test log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1061
diff changeset
80
835
0965b665c653 windowing and linear interpolation in GrayscaleStyleConfigurator
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 814
diff changeset
81 TextureBaseSceneLayer* GrayscaleStyleConfigurator::CreateTextureFromImage(
0965b665c653 windowing and linear interpolation in GrayscaleStyleConfigurator
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 814
diff changeset
82 const Orthanc::ImageAccessor& image) const
814
aead999345e0 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
83 {
aead999345e0 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
84 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented);
aead999345e0 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
85 }
835
0965b665c653 windowing and linear interpolation in GrayscaleStyleConfigurator
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 814
diff changeset
86
0965b665c653 windowing and linear interpolation in GrayscaleStyleConfigurator
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 814
diff changeset
87 TextureBaseSceneLayer* GrayscaleStyleConfigurator::CreateTextureFromDicom(
0965b665c653 windowing and linear interpolation in GrayscaleStyleConfigurator
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 814
diff changeset
88 const Orthanc::ImageAccessor& frame,
0965b665c653 windowing and linear interpolation in GrayscaleStyleConfigurator
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 814
diff changeset
89 const DicomInstanceParameters& parameters) const
0965b665c653 windowing and linear interpolation in GrayscaleStyleConfigurator
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 814
diff changeset
90 {
1298
8a0a62189f46 replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1270
diff changeset
91 std::unique_ptr<TextureBaseSceneLayer> layer(parameters.CreateTexture(frame));
835
0965b665c653 windowing and linear interpolation in GrayscaleStyleConfigurator
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 814
diff changeset
92
0965b665c653 windowing and linear interpolation in GrayscaleStyleConfigurator
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 814
diff changeset
93 if (layer.get() == NULL ||
0965b665c653 windowing and linear interpolation in GrayscaleStyleConfigurator
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 814
diff changeset
94 layer->GetTexture().GetFormat() != Orthanc::PixelFormat_Float32)
0965b665c653 windowing and linear interpolation in GrayscaleStyleConfigurator
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 814
diff changeset
95 {
0965b665c653 windowing and linear interpolation in GrayscaleStyleConfigurator
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 814
diff changeset
96 throw Orthanc::OrthancException(Orthanc::ErrorCode_IncompatibleImageFormat);
0965b665c653 windowing and linear interpolation in GrayscaleStyleConfigurator
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 814
diff changeset
97 }
0965b665c653 windowing and linear interpolation in GrayscaleStyleConfigurator
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 814
diff changeset
98 else
0965b665c653 windowing and linear interpolation in GrayscaleStyleConfigurator
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 814
diff changeset
99 {
0965b665c653 windowing and linear interpolation in GrayscaleStyleConfigurator
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 814
diff changeset
100 return layer.release();
0965b665c653 windowing and linear interpolation in GrayscaleStyleConfigurator
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 814
diff changeset
101 }
0965b665c653 windowing and linear interpolation in GrayscaleStyleConfigurator
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 814
diff changeset
102 }
0965b665c653 windowing and linear interpolation in GrayscaleStyleConfigurator
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 814
diff changeset
103
0965b665c653 windowing and linear interpolation in GrayscaleStyleConfigurator
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 814
diff changeset
104 void GrayscaleStyleConfigurator::ApplyStyle(ISceneLayer& layer) const
0965b665c653 windowing and linear interpolation in GrayscaleStyleConfigurator
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 814
diff changeset
105 {
0965b665c653 windowing and linear interpolation in GrayscaleStyleConfigurator
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 814
diff changeset
106 FloatTextureSceneLayer& l = dynamic_cast<FloatTextureSceneLayer&>(layer);
0965b665c653 windowing and linear interpolation in GrayscaleStyleConfigurator
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 814
diff changeset
107
0965b665c653 windowing and linear interpolation in GrayscaleStyleConfigurator
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 814
diff changeset
108 l.SetLinearInterpolation(linearInterpolation_);
0965b665c653 windowing and linear interpolation in GrayscaleStyleConfigurator
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 814
diff changeset
109
1209
b5dec783ba08 Fixed the style configurator to only set inversion on the image if it has been
Benjamin Golinvaux <bgo@osimis.io>
parents: 1061
diff changeset
110 if (hasWindowingOverride_)
835
0965b665c653 windowing and linear interpolation in GrayscaleStyleConfigurator
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 814
diff changeset
111 {
913
2b4b6b86520a Re-enabled gl debug output in GuiAdapter +
Benjamin Golinvaux <bgo@osimis.io>
parents: 836
diff changeset
112 if (windowing_ != ImageWindowing_Custom)
2b4b6b86520a Re-enabled gl debug output in GuiAdapter +
Benjamin Golinvaux <bgo@osimis.io>
parents: 836
diff changeset
113 {
2b4b6b86520a Re-enabled gl debug output in GuiAdapter +
Benjamin Golinvaux <bgo@osimis.io>
parents: 836
diff changeset
114 l.SetWindowing(windowing_);
2b4b6b86520a Re-enabled gl debug output in GuiAdapter +
Benjamin Golinvaux <bgo@osimis.io>
parents: 836
diff changeset
115 }
2b4b6b86520a Re-enabled gl debug output in GuiAdapter +
Benjamin Golinvaux <bgo@osimis.io>
parents: 836
diff changeset
116 else
2b4b6b86520a Re-enabled gl debug output in GuiAdapter +
Benjamin Golinvaux <bgo@osimis.io>
parents: 836
diff changeset
117 {
2b4b6b86520a Re-enabled gl debug output in GuiAdapter +
Benjamin Golinvaux <bgo@osimis.io>
parents: 836
diff changeset
118 l.SetCustomWindowing(customWindowCenter_, customWindowWidth_);
2b4b6b86520a Re-enabled gl debug output in GuiAdapter +
Benjamin Golinvaux <bgo@osimis.io>
parents: 836
diff changeset
119 }
835
0965b665c653 windowing and linear interpolation in GrayscaleStyleConfigurator
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 814
diff changeset
120 }
1163
ba9db2ad317c test log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1061
diff changeset
121
1209
b5dec783ba08 Fixed the style configurator to only set inversion on the image if it has been
Benjamin Golinvaux <bgo@osimis.io>
parents: 1061
diff changeset
122 if (hasInversionOverride_)
b5dec783ba08 Fixed the style configurator to only set inversion on the image if it has been
Benjamin Golinvaux <bgo@osimis.io>
parents: 1061
diff changeset
123 {
b5dec783ba08 Fixed the style configurator to only set inversion on the image if it has been
Benjamin Golinvaux <bgo@osimis.io>
parents: 1061
diff changeset
124 l.SetInverted(inverted_);
b5dec783ba08 Fixed the style configurator to only set inversion on the image if it has been
Benjamin Golinvaux <bgo@osimis.io>
parents: 1061
diff changeset
125 }
1212
ab06dfdf3b75 integration mainline->broker
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1179 1209
diff changeset
126
1163
ba9db2ad317c test log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1061
diff changeset
127 l.SetApplyLog(applyLog_);
835
0965b665c653 windowing and linear interpolation in GrayscaleStyleConfigurator
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 814
diff changeset
128 }
814
aead999345e0 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
129 }