comparison OrthancStone/Sources/Scene2D/GrayscaleStyleConfigurator.cpp @ 1512:244ad1e4e76a

reorganization of folders
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 07 Jul 2020 16:21:02 +0200
parents Framework/Scene2D/GrayscaleStyleConfigurator.cpp@30deba7bc8e2
children 85e117739eca
comparison
equal deleted inserted replaced
1511:9dfeee74c1e6 1512:244ad1e4e76a
1 /**
2 * Stone of Orthanc
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
4 * Department, University Hospital of Liege, Belgium
5 * Copyright (C) 2017-2020 Osimis S.A., Belgium
6 *
7 * This program is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU Affero General Public License
9 * as published by the Free Software Foundation, either version 3 of
10 * the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Affero General Public License for more details.
16 *
17 * You should have received a copy of the GNU Affero General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 **/
20
21
22 #include "GrayscaleStyleConfigurator.h"
23
24 #include "FloatTextureSceneLayer.h"
25
26 #include <OrthancException.h>
27
28 namespace OrthancStone
29 {
30 GrayscaleStyleConfigurator::GrayscaleStyleConfigurator() :
31 revision_(0),
32 linearInterpolation_(false),
33 hasWindowingOverride_(false),
34 customWindowWidth_(0),
35 customWindowCenter_(0),
36 hasInversionOverride_(false),
37 inverted_(false),
38 applyLog_(false)
39 {
40 }
41
42 void GrayscaleStyleConfigurator::SetWindowing(ImageWindowing windowing)
43 {
44 hasWindowingOverride_ = true;
45 windowing_ = windowing;
46 revision_++;
47 }
48
49 void GrayscaleStyleConfigurator::SetCustomWindowing(float windowCenter, float windowWidth)
50 {
51 SetWindowing(ImageWindowing_Custom);
52 customWindowCenter_ = windowCenter;
53 customWindowWidth_ = windowWidth;
54 }
55
56 void GrayscaleStyleConfigurator::GetCustomWindowing(float& windowCenter, float& windowWidth) const
57 {
58 windowCenter = customWindowCenter_;
59 windowWidth = customWindowWidth_;
60 }
61
62 void GrayscaleStyleConfigurator::SetInverted(bool inverted)
63 {
64 hasInversionOverride_ = true;
65 inverted_ = inverted;
66 revision_++;
67 }
68
69 void GrayscaleStyleConfigurator::SetLinearInterpolation(bool enabled)
70 {
71 linearInterpolation_ = enabled;
72 revision_++;
73 }
74
75 void GrayscaleStyleConfigurator::SetApplyLog(bool apply)
76 {
77 applyLog_ = apply;
78 revision_++;
79 }
80
81 TextureBaseSceneLayer* GrayscaleStyleConfigurator::CreateTextureFromImage(
82 const Orthanc::ImageAccessor& image) const
83 {
84 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented);
85 }
86
87 TextureBaseSceneLayer* GrayscaleStyleConfigurator::CreateTextureFromDicom(
88 const Orthanc::ImageAccessor& frame,
89 const DicomInstanceParameters& parameters) const
90 {
91 std::unique_ptr<TextureBaseSceneLayer> layer(parameters.CreateTexture(frame));
92
93 if (layer.get() == NULL ||
94 layer->GetTexture().GetFormat() != Orthanc::PixelFormat_Float32)
95 {
96 throw Orthanc::OrthancException(Orthanc::ErrorCode_IncompatibleImageFormat);
97 }
98 else
99 {
100 return layer.release();
101 }
102 }
103
104 void GrayscaleStyleConfigurator::ApplyStyle(ISceneLayer& layer) const
105 {
106 FloatTextureSceneLayer& l = dynamic_cast<FloatTextureSceneLayer&>(layer);
107
108 l.SetLinearInterpolation(linearInterpolation_);
109
110 if (hasWindowingOverride_)
111 {
112 if (windowing_ != ImageWindowing_Custom)
113 {
114 l.SetWindowing(windowing_);
115 }
116 else
117 {
118 l.SetCustomWindowing(customWindowCenter_, customWindowWidth_);
119 }
120 }
121
122 if (hasInversionOverride_)
123 {
124 l.SetInverted(inverted_);
125 }
126
127 l.SetApplyLog(applyLog_);
128 }
129 }