Mercurial > hg > orthanc-stone
comparison OrthancStone/Sources/Scene2D/FloatTextureSceneLayer.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/FloatTextureSceneLayer.cpp@30deba7bc8e2 |
children | 82279abb92d0 |
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 "FloatTextureSceneLayer.h" | |
23 | |
24 #include "../Toolbox/ImageToolbox.h" | |
25 | |
26 #include <Images/Image.h> | |
27 #include <Images/ImageProcessing.h> | |
28 #include <OrthancException.h> | |
29 | |
30 namespace OrthancStone | |
31 { | |
32 FloatTextureSceneLayer::FloatTextureSceneLayer(const Orthanc::ImageAccessor& texture) : | |
33 inverted_(false), | |
34 applyLog_(false) | |
35 { | |
36 { | |
37 std::unique_ptr<Orthanc::ImageAccessor> t( | |
38 new Orthanc::Image(Orthanc::PixelFormat_Float32, | |
39 texture.GetWidth(), | |
40 texture.GetHeight(), | |
41 false)); | |
42 | |
43 Orthanc::ImageProcessing::Convert(*t, texture); | |
44 | |
45 SetTexture(t.release()); | |
46 } | |
47 | |
48 SetCustomWindowing(128, 256); | |
49 } | |
50 | |
51 | |
52 void FloatTextureSceneLayer::SetWindowing(ImageWindowing windowing) | |
53 { | |
54 if (windowing_ != windowing) | |
55 { | |
56 if (windowing == ImageWindowing_Custom) | |
57 { | |
58 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); | |
59 } | |
60 else | |
61 { | |
62 windowing_ = windowing; | |
63 IncrementRevision(); | |
64 } | |
65 } | |
66 } | |
67 | |
68 void FloatTextureSceneLayer::SetCustomWindowing(float customCenter, | |
69 float customWidth) | |
70 { | |
71 if (customWidth <= 0) | |
72 { | |
73 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); | |
74 } | |
75 else | |
76 { | |
77 windowing_ = ImageWindowing_Custom; | |
78 customCenter_ = customCenter; | |
79 customWidth_ = customWidth; | |
80 IncrementRevision(); | |
81 } | |
82 } | |
83 | |
84 | |
85 void FloatTextureSceneLayer::GetWindowing(float& targetCenter, | |
86 float& targetWidth) const | |
87 { | |
88 ::OrthancStone::ComputeWindowing(targetCenter, targetWidth, | |
89 windowing_, customCenter_, customWidth_); | |
90 } | |
91 | |
92 | |
93 void FloatTextureSceneLayer::SetInverted(bool inverted) | |
94 { | |
95 inverted_ = inverted; | |
96 IncrementRevision(); | |
97 } | |
98 | |
99 | |
100 void FloatTextureSceneLayer::SetApplyLog(bool apply) | |
101 { | |
102 applyLog_ = apply; | |
103 IncrementRevision(); | |
104 } | |
105 | |
106 | |
107 void FloatTextureSceneLayer::FitRange() | |
108 { | |
109 float minValue, maxValue; | |
110 Orthanc::ImageProcessing::GetMinMaxFloatValue(minValue, maxValue, GetTexture()); | |
111 | |
112 float width; | |
113 | |
114 assert(minValue <= maxValue); | |
115 if (LinearAlgebra::IsCloseToZero(maxValue - minValue)) | |
116 { | |
117 width = 1; | |
118 } | |
119 else | |
120 { | |
121 width = maxValue - minValue; | |
122 } | |
123 | |
124 SetCustomWindowing((minValue + maxValue) / 2.0f, width); | |
125 } | |
126 | |
127 | |
128 ISceneLayer* FloatTextureSceneLayer::Clone() const | |
129 { | |
130 std::unique_ptr<FloatTextureSceneLayer> cloned | |
131 (new FloatTextureSceneLayer(GetTexture())); | |
132 | |
133 cloned->CopyParameters(*this); | |
134 cloned->windowing_ = windowing_; | |
135 cloned->customCenter_ = customCenter_; | |
136 cloned->customWidth_ = customWidth_; | |
137 cloned->inverted_ = inverted_; | |
138 cloned->applyLog_ = applyLog_; | |
139 | |
140 return cloned.release(); | |
141 } | |
142 } |