Mercurial > hg > orthanc-stone
annotate Framework/Scene2D/FloatTextureSceneLayer.cpp @ 818:e42b491f1fb2
Removed typedefs to shared_ptr by making them explicit. Removed using namespace
directives to make usage more explicit, too.
author | Benjamin Golinvaux <bgo@osimis.io> |
---|---|
date | Wed, 29 May 2019 10:51:28 +0200 |
parents | 0387485f048b |
children | 4d1f57773b5b |
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 | |
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 |
b8dfd966b5f4
FloatTextureSceneLayer::SetInverted()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
590
diff
changeset
|
96 |
590 | 97 void FloatTextureSceneLayer::FitRange() |
98 { | |
99 float minValue, maxValue; | |
100 Orthanc::ImageProcessing::GetMinMaxFloatValue(minValue, maxValue, GetTexture()); | |
101 | |
102 float width; | |
103 | |
104 assert(minValue <= maxValue); | |
105 if (LinearAlgebra::IsCloseToZero(maxValue - minValue)) | |
106 { | |
107 width = 1; | |
108 } | |
109 else | |
110 { | |
111 width = maxValue - minValue; | |
112 } | |
113 | |
114 SetCustomWindowing((minValue + maxValue) / 2.0f, width); | |
115 } | |
116 | |
117 | |
118 ISceneLayer* FloatTextureSceneLayer::Clone() const | |
119 { | |
120 std::auto_ptr<FloatTextureSceneLayer> cloned | |
121 (new FloatTextureSceneLayer(GetTexture())); | |
122 | |
123 cloned->CopyParameters(*this); | |
124 cloned->windowing_ = windowing_; | |
125 cloned->customCenter_ = customCenter_; | |
126 cloned->customWidth_ = customWidth_; | |
773
b8dfd966b5f4
FloatTextureSceneLayer::SetInverted()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
590
diff
changeset
|
127 cloned->inverted_ = inverted_; |
590 | 128 |
129 return cloned.release(); | |
130 } | |
131 } |