Mercurial > hg > orthanc-stone
annotate OrthancStone/Sources/Scene2D/FloatTextureSceneLayer.cpp @ 1808:797633f48a9c
display series description if hovering pdf or video
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 20 May 2021 17:28:16 +0200 |
parents | 9ac2a65d4172 |
children | 3889ae96d2e9 |
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 | |
1739
9ac2a65d4172
upgrade to year 2021
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1641
diff
changeset
|
5 * Copyright (C) 2017-2021 Osimis S.A., Belgium |
590 | 6 * |
7 * 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
|
8 * modify it under the terms of the GNU Lesser General Public License |
590 | 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 | |
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
|
14 * 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
|
15 * Lesser General Public License for more details. |
1596
4fb8fdf03314
removed annoying whitespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1533
diff
changeset
|
16 * |
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
|
17 * 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
|
18 * 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
|
19 * <http://www.gnu.org/licenses/>. |
590 | 20 **/ |
21 | |
22 | |
23 #include "FloatTextureSceneLayer.h" | |
24 | |
1287
8e82fdc6200e
Heavy (temporary) logging in the path that leads
Benjamin Golinvaux <bgo@osimis.io>
parents:
1270
diff
changeset
|
25 #include "../Toolbox/ImageToolbox.h" |
8e82fdc6200e
Heavy (temporary) logging in the path that leads
Benjamin Golinvaux <bgo@osimis.io>
parents:
1270
diff
changeset
|
26 |
1455
30deba7bc8e2
simplifying include_directories
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1300
diff
changeset
|
27 #include <Images/Image.h> |
30deba7bc8e2
simplifying include_directories
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1300
diff
changeset
|
28 #include <Images/ImageProcessing.h> |
30deba7bc8e2
simplifying include_directories
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1300
diff
changeset
|
29 #include <OrthancException.h> |
590 | 30 |
31 namespace OrthancStone | |
32 { | |
776
0387485f048b
ILayerStyleConfigurator
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
773
diff
changeset
|
33 FloatTextureSceneLayer::FloatTextureSceneLayer(const Orthanc::ImageAccessor& texture) : |
1252
6525c0f13a3a
Fixed uninited var applyLog_
Benjamin Golinvaux <bgo@osimis.io>
parents:
1179
diff
changeset
|
34 inverted_(false), |
1533
82279abb92d0
GrayscaleWindowingSceneTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1512
diff
changeset
|
35 applyLog_(false), |
82279abb92d0
GrayscaleWindowingSceneTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1512
diff
changeset
|
36 isRangeComputed_(false), |
82279abb92d0
GrayscaleWindowingSceneTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1512
diff
changeset
|
37 minValue_(0), |
82279abb92d0
GrayscaleWindowingSceneTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1512
diff
changeset
|
38 maxValue_(0) |
590 | 39 { |
40 { | |
1298
8a0a62189f46
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1290
diff
changeset
|
41 std::unique_ptr<Orthanc::ImageAccessor> t( |
590 | 42 new Orthanc::Image(Orthanc::PixelFormat_Float32, |
43 texture.GetWidth(), | |
44 texture.GetHeight(), | |
45 false)); | |
46 | |
47 Orthanc::ImageProcessing::Convert(*t, texture); | |
1287
8e82fdc6200e
Heavy (temporary) logging in the path that leads
Benjamin Golinvaux <bgo@osimis.io>
parents:
1270
diff
changeset
|
48 |
590 | 49 SetTexture(t.release()); |
50 } | |
51 | |
52 SetCustomWindowing(128, 256); | |
53 } | |
54 | |
55 | |
56 void FloatTextureSceneLayer::SetWindowing(ImageWindowing windowing) | |
57 { | |
58 if (windowing_ != windowing) | |
59 { | |
60 if (windowing == ImageWindowing_Custom) | |
61 { | |
62 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); | |
63 } | |
64 else | |
65 { | |
66 windowing_ = windowing; | |
67 IncrementRevision(); | |
68 } | |
69 } | |
70 } | |
71 | |
72 void FloatTextureSceneLayer::SetCustomWindowing(float customCenter, | |
73 float customWidth) | |
74 { | |
75 if (customWidth <= 0) | |
76 { | |
77 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); | |
78 } | |
79 else | |
80 { | |
81 windowing_ = ImageWindowing_Custom; | |
82 customCenter_ = customCenter; | |
83 customWidth_ = customWidth; | |
84 IncrementRevision(); | |
85 } | |
86 } | |
87 | |
88 | |
89 void FloatTextureSceneLayer::GetWindowing(float& targetCenter, | |
90 float& targetWidth) const | |
91 { | |
1641 | 92 ComputeWindowing(targetCenter, targetWidth, |
93 windowing_, customCenter_, customWidth_); | |
590 | 94 } |
95 | |
96 | |
773
b8dfd966b5f4
FloatTextureSceneLayer::SetInverted()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
590
diff
changeset
|
97 void FloatTextureSceneLayer::SetInverted(bool inverted) |
b8dfd966b5f4
FloatTextureSceneLayer::SetInverted()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
590
diff
changeset
|
98 { |
b8dfd966b5f4
FloatTextureSceneLayer::SetInverted()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
590
diff
changeset
|
99 inverted_ = inverted; |
b8dfd966b5f4
FloatTextureSceneLayer::SetInverted()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
590
diff
changeset
|
100 IncrementRevision(); |
b8dfd966b5f4
FloatTextureSceneLayer::SetInverted()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
590
diff
changeset
|
101 } |
b8dfd966b5f4
FloatTextureSceneLayer::SetInverted()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
590
diff
changeset
|
102 |
1163 | 103 |
104 void FloatTextureSceneLayer::SetApplyLog(bool apply) | |
105 { | |
106 applyLog_ = apply; | |
107 IncrementRevision(); | |
108 } | |
109 | |
110 | |
590 | 111 void FloatTextureSceneLayer::FitRange() |
112 { | |
113 float minValue, maxValue; | |
1533
82279abb92d0
GrayscaleWindowingSceneTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1512
diff
changeset
|
114 GetRange(minValue, maxValue); |
82279abb92d0
GrayscaleWindowingSceneTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1512
diff
changeset
|
115 assert(minValue <= maxValue); |
590 | 116 |
117 float width; | |
118 | |
119 if (LinearAlgebra::IsCloseToZero(maxValue - minValue)) | |
120 { | |
121 width = 1; | |
122 } | |
123 else | |
124 { | |
125 width = maxValue - minValue; | |
126 } | |
127 | |
128 SetCustomWindowing((minValue + maxValue) / 2.0f, width); | |
129 } | |
130 | |
131 | |
1533
82279abb92d0
GrayscaleWindowingSceneTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1512
diff
changeset
|
132 void FloatTextureSceneLayer::GetRange(float& minValue, |
82279abb92d0
GrayscaleWindowingSceneTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1512
diff
changeset
|
133 float& maxValue) |
82279abb92d0
GrayscaleWindowingSceneTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1512
diff
changeset
|
134 { |
82279abb92d0
GrayscaleWindowingSceneTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1512
diff
changeset
|
135 if (!isRangeComputed_) |
82279abb92d0
GrayscaleWindowingSceneTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1512
diff
changeset
|
136 { |
82279abb92d0
GrayscaleWindowingSceneTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1512
diff
changeset
|
137 Orthanc::ImageProcessing::GetMinMaxFloatValue(minValue_, maxValue_, GetTexture()); |
82279abb92d0
GrayscaleWindowingSceneTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1512
diff
changeset
|
138 isRangeComputed_ = true; |
82279abb92d0
GrayscaleWindowingSceneTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1512
diff
changeset
|
139 } |
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 assert(minValue_ <= maxValue_); |
82279abb92d0
GrayscaleWindowingSceneTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1512
diff
changeset
|
142 |
82279abb92d0
GrayscaleWindowingSceneTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1512
diff
changeset
|
143 minValue = minValue_; |
82279abb92d0
GrayscaleWindowingSceneTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1512
diff
changeset
|
144 maxValue = maxValue_; |
82279abb92d0
GrayscaleWindowingSceneTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1512
diff
changeset
|
145 } |
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 |
590 | 148 ISceneLayer* FloatTextureSceneLayer::Clone() const |
149 { | |
1298
8a0a62189f46
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1290
diff
changeset
|
150 std::unique_ptr<FloatTextureSceneLayer> cloned |
590 | 151 (new FloatTextureSceneLayer(GetTexture())); |
152 | |
153 cloned->CopyParameters(*this); | |
154 cloned->windowing_ = windowing_; | |
155 cloned->customCenter_ = customCenter_; | |
156 cloned->customWidth_ = customWidth_; | |
773
b8dfd966b5f4
FloatTextureSceneLayer::SetInverted()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
590
diff
changeset
|
157 cloned->inverted_ = inverted_; |
1179
177e7d431cd1
log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1163
diff
changeset
|
158 cloned->applyLog_ = applyLog_; |
1533
82279abb92d0
GrayscaleWindowingSceneTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1512
diff
changeset
|
159 cloned->isRangeComputed_ = isRangeComputed_; |
82279abb92d0
GrayscaleWindowingSceneTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1512
diff
changeset
|
160 cloned->minValue_ = minValue_; |
82279abb92d0
GrayscaleWindowingSceneTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1512
diff
changeset
|
161 cloned->maxValue_ = maxValue_; |
590 | 162 |
163 return cloned.release(); | |
164 } | |
165 } |