Mercurial > hg > orthanc-stone
annotate Framework/Scene2D/FloatTextureSceneLayer.cpp @ 1307:8a28a9bf8876 broker
ViewportController now gets a ref to its parent viewport for proper lock usage
author | Benjamin Golinvaux <bgo@osimis.io> |
---|---|
date | Wed, 04 Mar 2020 10:07:37 +0100 |
parents | 7ec8fea061b9 |
children | 6ab03e429f06 |
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 | |
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) : |
1252
6525c0f13a3a
Fixed uninited var applyLog_
Benjamin Golinvaux <bgo@osimis.io>
parents:
1179
diff
changeset
|
31 inverted_(false), |
6525c0f13a3a
Fixed uninited var applyLog_
Benjamin Golinvaux <bgo@osimis.io>
parents:
1179
diff
changeset
|
32 applyLog_(false) |
590 | 33 { |
34 { | |
35 std::auto_ptr<Orthanc::ImageAccessor> t( | |
36 new Orthanc::Image(Orthanc::PixelFormat_Float32, | |
37 texture.GetWidth(), | |
38 texture.GetHeight(), | |
39 false)); | |
40 | |
41 Orthanc::ImageProcessing::Convert(*t, texture); | |
42 SetTexture(t.release()); | |
43 } | |
44 | |
45 SetCustomWindowing(128, 256); | |
46 } | |
47 | |
48 | |
49 void FloatTextureSceneLayer::SetWindowing(ImageWindowing windowing) | |
50 { | |
51 if (windowing_ != windowing) | |
52 { | |
53 if (windowing == ImageWindowing_Custom) | |
54 { | |
55 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); | |
56 } | |
57 else | |
58 { | |
59 windowing_ = windowing; | |
60 IncrementRevision(); | |
61 } | |
62 } | |
63 } | |
64 | |
65 void FloatTextureSceneLayer::SetCustomWindowing(float customCenter, | |
66 float customWidth) | |
67 { | |
68 if (customWidth <= 0) | |
69 { | |
70 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); | |
71 } | |
72 else | |
73 { | |
74 windowing_ = ImageWindowing_Custom; | |
75 customCenter_ = customCenter; | |
76 customWidth_ = customWidth; | |
77 IncrementRevision(); | |
78 } | |
79 } | |
80 | |
81 | |
82 void FloatTextureSceneLayer::GetWindowing(float& targetCenter, | |
83 float& targetWidth) const | |
84 { | |
85 ::OrthancStone::ComputeWindowing(targetCenter, targetWidth, | |
86 windowing_, customCenter_, customWidth_); | |
87 } | |
88 | |
89 | |
773
b8dfd966b5f4
FloatTextureSceneLayer::SetInverted()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
590
diff
changeset
|
90 void FloatTextureSceneLayer::SetInverted(bool inverted) |
b8dfd966b5f4
FloatTextureSceneLayer::SetInverted()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
590
diff
changeset
|
91 { |
b8dfd966b5f4
FloatTextureSceneLayer::SetInverted()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
590
diff
changeset
|
92 inverted_ = inverted; |
b8dfd966b5f4
FloatTextureSceneLayer::SetInverted()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
590
diff
changeset
|
93 IncrementRevision(); |
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 |
1163 | 96 |
97 void FloatTextureSceneLayer::SetApplyLog(bool apply) | |
98 { | |
99 applyLog_ = apply; | |
100 IncrementRevision(); | |
101 } | |
102 | |
103 | |
590 | 104 void FloatTextureSceneLayer::FitRange() |
105 { | |
106 float minValue, maxValue; | |
107 Orthanc::ImageProcessing::GetMinMaxFloatValue(minValue, maxValue, GetTexture()); | |
108 | |
109 float width; | |
110 | |
111 assert(minValue <= maxValue); | |
112 if (LinearAlgebra::IsCloseToZero(maxValue - minValue)) | |
113 { | |
114 width = 1; | |
115 } | |
116 else | |
117 { | |
118 width = maxValue - minValue; | |
119 } | |
120 | |
121 SetCustomWindowing((minValue + maxValue) / 2.0f, width); | |
122 } | |
123 | |
124 | |
125 ISceneLayer* FloatTextureSceneLayer::Clone() const | |
126 { | |
127 std::auto_ptr<FloatTextureSceneLayer> cloned | |
128 (new FloatTextureSceneLayer(GetTexture())); | |
129 | |
130 cloned->CopyParameters(*this); | |
131 cloned->windowing_ = windowing_; | |
132 cloned->customCenter_ = customCenter_; | |
133 cloned->customWidth_ = customWidth_; | |
773
b8dfd966b5f4
FloatTextureSceneLayer::SetInverted()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
590
diff
changeset
|
134 cloned->inverted_ = inverted_; |
1179
177e7d431cd1
log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1163
diff
changeset
|
135 cloned->applyLog_ = applyLog_; |
590 | 136 |
137 return cloned.release(); | |
138 } | |
139 } |