Mercurial > hg > orthanc-stone
annotate Framework/Scene2D/FloatTextureSceneLayer.cpp @ 1313:f30905f5d246 broker
Added support for OnGenericSdlEvent to GuiAdapter.
This makes it possible to piggyback app-specific logic
to special events (here, to support the Viewport refresh
events)
author | Benjamin Golinvaux <bgo@osimis.io> |
---|---|
date | Mon, 16 Mar 2020 11:12:39 +0100 |
parents | 257f2c9a02ac |
children | 30deba7bc8e2 |
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 | |
1270
2d8ab34c8c91
upgrade to year 2020
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1061
diff
changeset
|
5 * Copyright (C) 2017-2020 Osimis S.A., Belgium |
590 | 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 | |
1287
8e82fdc6200e
Heavy (temporary) logging in the path that leads
Benjamin Golinvaux <bgo@osimis.io>
parents:
1270
diff
changeset
|
24 #include "../Toolbox/ImageToolbox.h" |
8e82fdc6200e
Heavy (temporary) logging in the path that leads
Benjamin Golinvaux <bgo@osimis.io>
parents:
1270
diff
changeset
|
25 |
590 | 26 #include <Core/Images/Image.h> |
27 #include <Core/Images/ImageProcessing.h> | |
28 #include <Core/OrthancException.h> | |
29 | |
30 namespace OrthancStone | |
31 { | |
776
0387485f048b
ILayerStyleConfigurator
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
773
diff
changeset
|
32 FloatTextureSceneLayer::FloatTextureSceneLayer(const Orthanc::ImageAccessor& texture) : |
1252
6525c0f13a3a
Fixed uninited var applyLog_
Benjamin Golinvaux <bgo@osimis.io>
parents:
1179
diff
changeset
|
33 inverted_(false), |
6525c0f13a3a
Fixed uninited var applyLog_
Benjamin Golinvaux <bgo@osimis.io>
parents:
1179
diff
changeset
|
34 applyLog_(false) |
590 | 35 { |
36 { | |
1298
8a0a62189f46
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1290
diff
changeset
|
37 std::unique_ptr<Orthanc::ImageAccessor> t( |
590 | 38 new Orthanc::Image(Orthanc::PixelFormat_Float32, |
39 texture.GetWidth(), | |
40 texture.GetHeight(), | |
41 false)); | |
42 | |
43 Orthanc::ImageProcessing::Convert(*t, texture); | |
1287
8e82fdc6200e
Heavy (temporary) logging in the path that leads
Benjamin Golinvaux <bgo@osimis.io>
parents:
1270
diff
changeset
|
44 |
590 | 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 | |
773
b8dfd966b5f4
FloatTextureSceneLayer::SetInverted()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
590
diff
changeset
|
93 void FloatTextureSceneLayer::SetInverted(bool inverted) |
b8dfd966b5f4
FloatTextureSceneLayer::SetInverted()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
590
diff
changeset
|
94 { |
b8dfd966b5f4
FloatTextureSceneLayer::SetInverted()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
590
diff
changeset
|
95 inverted_ = inverted; |
b8dfd966b5f4
FloatTextureSceneLayer::SetInverted()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
590
diff
changeset
|
96 IncrementRevision(); |
b8dfd966b5f4
FloatTextureSceneLayer::SetInverted()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
590
diff
changeset
|
97 } |
b8dfd966b5f4
FloatTextureSceneLayer::SetInverted()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
590
diff
changeset
|
98 |
1163 | 99 |
100 void FloatTextureSceneLayer::SetApplyLog(bool apply) | |
101 { | |
102 applyLog_ = apply; | |
103 IncrementRevision(); | |
104 } | |
105 | |
106 | |
590 | 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 { | |
1298
8a0a62189f46
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1290
diff
changeset
|
130 std::unique_ptr<FloatTextureSceneLayer> cloned |
590 | 131 (new FloatTextureSceneLayer(GetTexture())); |
132 | |
133 cloned->CopyParameters(*this); | |
134 cloned->windowing_ = windowing_; | |
135 cloned->customCenter_ = customCenter_; | |
136 cloned->customWidth_ = customWidth_; | |
773
b8dfd966b5f4
FloatTextureSceneLayer::SetInverted()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
590
diff
changeset
|
137 cloned->inverted_ = inverted_; |
1179
177e7d431cd1
log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1163
diff
changeset
|
138 cloned->applyLog_ = applyLog_; |
590 | 139 |
140 return cloned.release(); | |
141 } | |
142 } |