comparison Framework/Scene2D/FloatTextureSceneLayer.cpp @ 590:5430bcffba57

FloatTextureSceneLayer
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 26 Apr 2019 11:33:57 +0200
parents
children b8dfd966b5f4
comparison
equal deleted inserted replaced
589:3080ec4ec6b9 590:5430bcffba57
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 {
30 FloatTextureSceneLayer::FloatTextureSceneLayer(const Orthanc::ImageAccessor& texture)
31 {
32 {
33 std::auto_ptr<Orthanc::ImageAccessor> t(
34 new Orthanc::Image(Orthanc::PixelFormat_Float32,
35 texture.GetWidth(),
36 texture.GetHeight(),
37 false));
38
39 Orthanc::ImageProcessing::Convert(*t, texture);
40 SetTexture(t.release());
41 }
42
43 SetCustomWindowing(128, 256);
44 }
45
46
47 void FloatTextureSceneLayer::SetWindowing(ImageWindowing windowing)
48 {
49 if (windowing_ != windowing)
50 {
51 if (windowing == ImageWindowing_Custom)
52 {
53 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange);
54 }
55 else
56 {
57 windowing_ = windowing;
58 IncrementRevision();
59 }
60 }
61 }
62
63
64 void FloatTextureSceneLayer::SetCustomWindowing(float customCenter,
65 float customWidth)
66 {
67 if (customWidth <= 0)
68 {
69 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange);
70 }
71 else
72 {
73 windowing_ = ImageWindowing_Custom;
74 customCenter_ = customCenter;
75 customWidth_ = customWidth;
76 IncrementRevision();
77 }
78 }
79
80
81 void FloatTextureSceneLayer::GetWindowing(float& targetCenter,
82 float& targetWidth) const
83 {
84 ::OrthancStone::ComputeWindowing(targetCenter, targetWidth,
85 windowing_, customCenter_, customWidth_);
86 }
87
88
89 void FloatTextureSceneLayer::FitRange()
90 {
91 float minValue, maxValue;
92 Orthanc::ImageProcessing::GetMinMaxFloatValue(minValue, maxValue, GetTexture());
93
94 float width;
95
96 assert(minValue <= maxValue);
97 if (LinearAlgebra::IsCloseToZero(maxValue - minValue))
98 {
99 width = 1;
100 }
101 else
102 {
103 width = maxValue - minValue;
104 }
105
106 SetCustomWindowing((minValue + maxValue) / 2.0f, width);
107 }
108
109
110 ISceneLayer* FloatTextureSceneLayer::Clone() const
111 {
112 std::auto_ptr<FloatTextureSceneLayer> cloned
113 (new FloatTextureSceneLayer(GetTexture()));
114
115 cloned->CopyParameters(*this);
116 cloned->windowing_ = windowing_;
117 cloned->customCenter_ = customCenter_;
118 cloned->customWidth_ = customWidth_;
119
120 return cloned.release();
121 }
122 }