Mercurial > hg > orthanc-stone
annotate Framework/Scene2D/FloatTextureSceneLayer.cpp @ 1223:04fd875b91f4
fix
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Sat, 07 Dec 2019 18:41:54 +0100 |
parents | eb28dfe432f7 |
children | ba9db2ad317c 2d8ab34c8c91 |
rev | line source |
---|---|
590 | 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-2019 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 <Core/Images/Image.h> | |
25 #include <Core/Images/ImageProcessing.h> | |
26 #include <Core/OrthancException.h> | |
27 | |
28 namespace OrthancStone | |
29 { | |
776
0387485f048b
ILayerStyleConfigurator
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
773
diff
changeset
|
30 FloatTextureSceneLayer::FloatTextureSceneLayer(const Orthanc::ImageAccessor& texture) : |
0387485f048b
ILayerStyleConfigurator
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
773
diff
changeset
|
31 inverted_(false) |
590 | 32 { |
33 { | |
34 std::auto_ptr<Orthanc::ImageAccessor> t( | |
35 new Orthanc::Image(Orthanc::PixelFormat_Float32, | |
36 texture.GetWidth(), | |
37 texture.GetHeight(), | |
38 false)); | |
39 | |
40 Orthanc::ImageProcessing::Convert(*t, texture); | |
41 SetTexture(t.release()); | |
42 } | |
43 | |
44 SetCustomWindowing(128, 256); | |
45 } | |
46 | |
47 | |
48 void FloatTextureSceneLayer::SetWindowing(ImageWindowing windowing) | |
49 { | |
50 if (windowing_ != windowing) | |
51 { | |
52 if (windowing == ImageWindowing_Custom) | |
53 { | |
54 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); | |
55 } | |
56 else | |
57 { | |
58 windowing_ = windowing; | |
59 IncrementRevision(); | |
60 } | |
61 } | |
62 } | |
63 | |
64 void FloatTextureSceneLayer::SetCustomWindowing(float customCenter, | |
65 float customWidth) | |
66 { | |
67 if (customWidth <= 0) | |
68 { | |
69 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); | |
70 } | |
71 else | |
72 { | |
73 windowing_ = ImageWindowing_Custom; | |
74 customCenter_ = customCenter; | |
75 customWidth_ = customWidth; | |
76 IncrementRevision(); | |
77 } | |
78 } | |
79 | |
80 | |
81 void FloatTextureSceneLayer::GetWindowing(float& targetCenter, | |
82 float& targetWidth) const | |
83 { | |
84 ::OrthancStone::ComputeWindowing(targetCenter, targetWidth, | |
85 windowing_, customCenter_, customWidth_); | |
86 } | |
87 | |
88 | |
773
b8dfd966b5f4
FloatTextureSceneLayer::SetInverted()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
590
diff
changeset
|
89 void FloatTextureSceneLayer::SetInverted(bool inverted) |
b8dfd966b5f4
FloatTextureSceneLayer::SetInverted()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
590
diff
changeset
|
90 { |
b8dfd966b5f4
FloatTextureSceneLayer::SetInverted()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
590
diff
changeset
|
91 inverted_ = inverted; |
b8dfd966b5f4
FloatTextureSceneLayer::SetInverted()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
590
diff
changeset
|
92 IncrementRevision(); |
b8dfd966b5f4
FloatTextureSceneLayer::SetInverted()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
590
diff
changeset
|
93 } |
b8dfd966b5f4
FloatTextureSceneLayer::SetInverted()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
590
diff
changeset
|
94 |
590 | 95 void FloatTextureSceneLayer::FitRange() |
96 { | |
97 float minValue, maxValue; | |
98 Orthanc::ImageProcessing::GetMinMaxFloatValue(minValue, maxValue, GetTexture()); | |
99 | |
100 float width; | |
101 | |
102 assert(minValue <= maxValue); | |
103 if (LinearAlgebra::IsCloseToZero(maxValue - minValue)) | |
104 { | |
105 width = 1; | |
106 } | |
107 else | |
108 { | |
109 width = maxValue - minValue; | |
110 } | |
111 | |
112 SetCustomWindowing((minValue + maxValue) / 2.0f, width); | |
113 } | |
114 | |
115 | |
116 ISceneLayer* FloatTextureSceneLayer::Clone() const | |
117 { | |
118 std::auto_ptr<FloatTextureSceneLayer> cloned | |
119 (new FloatTextureSceneLayer(GetTexture())); | |
120 | |
121 cloned->CopyParameters(*this); | |
122 cloned->windowing_ = windowing_; | |
123 cloned->customCenter_ = customCenter_; | |
124 cloned->customWidth_ = customWidth_; | |
773
b8dfd966b5f4
FloatTextureSceneLayer::SetInverted()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
590
diff
changeset
|
125 cloned->inverted_ = inverted_; |
590 | 126 |
127 return cloned.release(); | |
128 } | |
129 } |