Mercurial > hg > orthanc-stone
annotate OrthancStone/Sources/Scene2D/FloatTextureSceneLayer.cpp @ 1886:ca89fec8c48f
test
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Fri, 14 Jan 2022 19:10:30 +0100 |
parents | 7053b8a0aaec |
children | 07964689cb0b |
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 | |
1871
7053b8a0aaec
upgrade to year 2022
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1870
diff
changeset
|
5 * Copyright (C) 2017-2022 Osimis S.A., Belgium |
7053b8a0aaec
upgrade to year 2022
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1870
diff
changeset
|
6 * Copyright (C) 2021-2022 Sebastien Jodogne, ICTEAM UCLouvain, Belgium |
590 | 7 * |
8 * This program is free software: you can redistribute it and/or | |
1598
8563ea5d8ae4
relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1596
diff
changeset
|
9 * modify it under the terms of the GNU Lesser General Public License |
590 | 10 * as published by the Free Software Foundation, either version 3 of |
11 * the License, or (at your option) any later version. | |
12 * | |
13 * This program is distributed in the hope that it will be useful, but | |
14 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
1598
8563ea5d8ae4
relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1596
diff
changeset
|
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
8563ea5d8ae4
relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1596
diff
changeset
|
16 * Lesser General Public License for more details. |
1596
4fb8fdf03314
removed annoying whitespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1533
diff
changeset
|
17 * |
1598
8563ea5d8ae4
relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1596
diff
changeset
|
18 * You should have received a copy of the GNU Lesser General Public |
8563ea5d8ae4
relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1596
diff
changeset
|
19 * License along with this program. If not, see |
8563ea5d8ae4
relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1596
diff
changeset
|
20 * <http://www.gnu.org/licenses/>. |
590 | 21 **/ |
22 | |
23 | |
24 #include "FloatTextureSceneLayer.h" | |
25 | |
1287
8e82fdc6200e
Heavy (temporary) logging in the path that leads
Benjamin Golinvaux <bgo@osimis.io>
parents:
1270
diff
changeset
|
26 #include "../Toolbox/ImageToolbox.h" |
8e82fdc6200e
Heavy (temporary) logging in the path that leads
Benjamin Golinvaux <bgo@osimis.io>
parents:
1270
diff
changeset
|
27 |
1455
30deba7bc8e2
simplifying include_directories
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1300
diff
changeset
|
28 #include <Images/Image.h> |
30deba7bc8e2
simplifying include_directories
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1300
diff
changeset
|
29 #include <Images/ImageProcessing.h> |
30deba7bc8e2
simplifying include_directories
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1300
diff
changeset
|
30 #include <OrthancException.h> |
590 | 31 |
32 namespace OrthancStone | |
33 { | |
776
0387485f048b
ILayerStyleConfigurator
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
773
diff
changeset
|
34 FloatTextureSceneLayer::FloatTextureSceneLayer(const Orthanc::ImageAccessor& texture) : |
1252
6525c0f13a3a
Fixed uninited var applyLog_
Benjamin Golinvaux <bgo@osimis.io>
parents:
1179
diff
changeset
|
35 inverted_(false), |
1533
82279abb92d0
GrayscaleWindowingSceneTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1512
diff
changeset
|
36 applyLog_(false), |
82279abb92d0
GrayscaleWindowingSceneTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1512
diff
changeset
|
37 isRangeComputed_(false), |
82279abb92d0
GrayscaleWindowingSceneTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1512
diff
changeset
|
38 minValue_(0), |
82279abb92d0
GrayscaleWindowingSceneTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1512
diff
changeset
|
39 maxValue_(0) |
590 | 40 { |
41 { | |
1298
8a0a62189f46
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1290
diff
changeset
|
42 std::unique_ptr<Orthanc::ImageAccessor> t( |
590 | 43 new Orthanc::Image(Orthanc::PixelFormat_Float32, |
44 texture.GetWidth(), | |
45 texture.GetHeight(), | |
46 false)); | |
47 | |
48 Orthanc::ImageProcessing::Convert(*t, texture); | |
1287
8e82fdc6200e
Heavy (temporary) logging in the path that leads
Benjamin Golinvaux <bgo@osimis.io>
parents:
1270
diff
changeset
|
49 |
590 | 50 SetTexture(t.release()); |
51 } | |
52 | |
53 SetCustomWindowing(128, 256); | |
54 } | |
55 | |
56 | |
57 void FloatTextureSceneLayer::SetWindowing(ImageWindowing windowing) | |
58 { | |
59 if (windowing_ != windowing) | |
60 { | |
61 if (windowing == ImageWindowing_Custom) | |
62 { | |
63 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); | |
64 } | |
65 else | |
66 { | |
67 windowing_ = windowing; | |
68 IncrementRevision(); | |
69 } | |
70 } | |
71 } | |
72 | |
73 void FloatTextureSceneLayer::SetCustomWindowing(float customCenter, | |
74 float customWidth) | |
75 { | |
76 if (customWidth <= 0) | |
77 { | |
78 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); | |
79 } | |
80 else | |
81 { | |
82 windowing_ = ImageWindowing_Custom; | |
83 customCenter_ = customCenter; | |
84 customWidth_ = customWidth; | |
85 IncrementRevision(); | |
86 } | |
87 } | |
88 | |
89 | |
90 void FloatTextureSceneLayer::GetWindowing(float& targetCenter, | |
91 float& targetWidth) const | |
92 { | |
1641 | 93 ComputeWindowing(targetCenter, targetWidth, |
94 windowing_, customCenter_, customWidth_); | |
590 | 95 } |
96 | |
97 | |
773
b8dfd966b5f4
FloatTextureSceneLayer::SetInverted()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
590
diff
changeset
|
98 void FloatTextureSceneLayer::SetInverted(bool inverted) |
b8dfd966b5f4
FloatTextureSceneLayer::SetInverted()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
590
diff
changeset
|
99 { |
b8dfd966b5f4
FloatTextureSceneLayer::SetInverted()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
590
diff
changeset
|
100 inverted_ = inverted; |
b8dfd966b5f4
FloatTextureSceneLayer::SetInverted()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
590
diff
changeset
|
101 IncrementRevision(); |
b8dfd966b5f4
FloatTextureSceneLayer::SetInverted()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
590
diff
changeset
|
102 } |
b8dfd966b5f4
FloatTextureSceneLayer::SetInverted()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
590
diff
changeset
|
103 |
1163 | 104 |
105 void FloatTextureSceneLayer::SetApplyLog(bool apply) | |
106 { | |
107 applyLog_ = apply; | |
108 IncrementRevision(); | |
109 } | |
110 | |
111 | |
590 | 112 void FloatTextureSceneLayer::FitRange() |
113 { | |
114 float minValue, maxValue; | |
1533
82279abb92d0
GrayscaleWindowingSceneTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1512
diff
changeset
|
115 GetRange(minValue, maxValue); |
82279abb92d0
GrayscaleWindowingSceneTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1512
diff
changeset
|
116 assert(minValue <= maxValue); |
590 | 117 |
118 float width; | |
119 | |
120 if (LinearAlgebra::IsCloseToZero(maxValue - minValue)) | |
121 { | |
122 width = 1; | |
123 } | |
124 else | |
125 { | |
126 width = maxValue - minValue; | |
127 } | |
128 | |
129 SetCustomWindowing((minValue + maxValue) / 2.0f, width); | |
130 } | |
131 | |
132 | |
1533
82279abb92d0
GrayscaleWindowingSceneTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1512
diff
changeset
|
133 void FloatTextureSceneLayer::GetRange(float& minValue, |
82279abb92d0
GrayscaleWindowingSceneTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1512
diff
changeset
|
134 float& maxValue) |
82279abb92d0
GrayscaleWindowingSceneTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1512
diff
changeset
|
135 { |
82279abb92d0
GrayscaleWindowingSceneTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1512
diff
changeset
|
136 if (!isRangeComputed_) |
82279abb92d0
GrayscaleWindowingSceneTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1512
diff
changeset
|
137 { |
82279abb92d0
GrayscaleWindowingSceneTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1512
diff
changeset
|
138 Orthanc::ImageProcessing::GetMinMaxFloatValue(minValue_, maxValue_, GetTexture()); |
82279abb92d0
GrayscaleWindowingSceneTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1512
diff
changeset
|
139 isRangeComputed_ = true; |
82279abb92d0
GrayscaleWindowingSceneTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1512
diff
changeset
|
140 } |
82279abb92d0
GrayscaleWindowingSceneTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1512
diff
changeset
|
141 |
82279abb92d0
GrayscaleWindowingSceneTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1512
diff
changeset
|
142 assert(minValue_ <= maxValue_); |
82279abb92d0
GrayscaleWindowingSceneTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1512
diff
changeset
|
143 |
82279abb92d0
GrayscaleWindowingSceneTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1512
diff
changeset
|
144 minValue = minValue_; |
82279abb92d0
GrayscaleWindowingSceneTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1512
diff
changeset
|
145 maxValue = maxValue_; |
82279abb92d0
GrayscaleWindowingSceneTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1512
diff
changeset
|
146 } |
82279abb92d0
GrayscaleWindowingSceneTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1512
diff
changeset
|
147 |
82279abb92d0
GrayscaleWindowingSceneTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1512
diff
changeset
|
148 |
590 | 149 ISceneLayer* FloatTextureSceneLayer::Clone() const |
150 { | |
1298
8a0a62189f46
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1290
diff
changeset
|
151 std::unique_ptr<FloatTextureSceneLayer> cloned |
590 | 152 (new FloatTextureSceneLayer(GetTexture())); |
153 | |
154 cloned->CopyParameters(*this); | |
155 cloned->windowing_ = windowing_; | |
156 cloned->customCenter_ = customCenter_; | |
157 cloned->customWidth_ = customWidth_; | |
773
b8dfd966b5f4
FloatTextureSceneLayer::SetInverted()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
590
diff
changeset
|
158 cloned->inverted_ = inverted_; |
1179
177e7d431cd1
log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1163
diff
changeset
|
159 cloned->applyLog_ = applyLog_; |
1533
82279abb92d0
GrayscaleWindowingSceneTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1512
diff
changeset
|
160 cloned->isRangeComputed_ = isRangeComputed_; |
82279abb92d0
GrayscaleWindowingSceneTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1512
diff
changeset
|
161 cloned->minValue_ = minValue_; |
82279abb92d0
GrayscaleWindowingSceneTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1512
diff
changeset
|
162 cloned->maxValue_ = maxValue_; |
590 | 163 |
164 return cloned.release(); | |
165 } | |
166 } |