annotate Framework/Scene2D/FloatTextureSceneLayer.cpp @ 860:238693c3bc51 am-dev

merge default -> am-dev
author Alain Mazy <alain@mazy.be>
date Mon, 24 Jun 2019 14:35:00 +0200
parents 0387485f048b
children 4d1f57773b5b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
590
5430bcffba57 FloatTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 /**
5430bcffba57 FloatTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2 * Stone of Orthanc
5430bcffba57 FloatTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
5430bcffba57 FloatTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
4 * Department, University Hospital of Liege, Belgium
5430bcffba57 FloatTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
5 * Copyright (C) 2017-2019 Osimis S.A., Belgium
5430bcffba57 FloatTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
6 *
5430bcffba57 FloatTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 * This program is free software: you can redistribute it and/or
5430bcffba57 FloatTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 * modify it under the terms of the GNU Affero General Public License
5430bcffba57 FloatTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 * as published by the Free Software Foundation, either version 3 of
5430bcffba57 FloatTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 * the License, or (at your option) any later version.
5430bcffba57 FloatTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 *
5430bcffba57 FloatTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 * This program is distributed in the hope that it will be useful, but
5430bcffba57 FloatTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
5430bcffba57 FloatTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
5430bcffba57 FloatTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 * Affero General Public License for more details.
5430bcffba57 FloatTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16 *
5430bcffba57 FloatTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
17 * You should have received a copy of the GNU Affero General Public License
5430bcffba57 FloatTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
5430bcffba57 FloatTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
19 **/
5430bcffba57 FloatTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20
5430bcffba57 FloatTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21
5430bcffba57 FloatTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22 #include "FloatTextureSceneLayer.h"
5430bcffba57 FloatTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23
5430bcffba57 FloatTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24 #include <Core/Images/Image.h>
5430bcffba57 FloatTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25 #include <Core/Images/ImageProcessing.h>
5430bcffba57 FloatTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26 #include <Core/OrthancException.h>
5430bcffba57 FloatTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27
5430bcffba57 FloatTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28 namespace OrthancStone
5430bcffba57 FloatTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
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
5430bcffba57 FloatTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32 {
5430bcffba57 FloatTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
33 {
5430bcffba57 FloatTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34 std::auto_ptr<Orthanc::ImageAccessor> t(
5430bcffba57 FloatTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35 new Orthanc::Image(Orthanc::PixelFormat_Float32,
5430bcffba57 FloatTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
36 texture.GetWidth(),
5430bcffba57 FloatTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
37 texture.GetHeight(),
5430bcffba57 FloatTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
38 false));
5430bcffba57 FloatTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
39
5430bcffba57 FloatTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
40 Orthanc::ImageProcessing::Convert(*t, texture);
5430bcffba57 FloatTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
41 SetTexture(t.release());
5430bcffba57 FloatTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
42 }
5430bcffba57 FloatTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
43
5430bcffba57 FloatTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
44 SetCustomWindowing(128, 256);
5430bcffba57 FloatTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
45 }
5430bcffba57 FloatTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
46
5430bcffba57 FloatTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
47
5430bcffba57 FloatTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
48 void FloatTextureSceneLayer::SetWindowing(ImageWindowing windowing)
5430bcffba57 FloatTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
49 {
5430bcffba57 FloatTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
50 if (windowing_ != windowing)
5430bcffba57 FloatTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
51 {
5430bcffba57 FloatTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
52 if (windowing == ImageWindowing_Custom)
5430bcffba57 FloatTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
53 {
5430bcffba57 FloatTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
54 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange);
5430bcffba57 FloatTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
55 }
5430bcffba57 FloatTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
56 else
5430bcffba57 FloatTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
57 {
5430bcffba57 FloatTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
58 windowing_ = windowing;
5430bcffba57 FloatTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
59 IncrementRevision();
5430bcffba57 FloatTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
60 }
5430bcffba57 FloatTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
61 }
5430bcffba57 FloatTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
62 }
5430bcffba57 FloatTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
63
5430bcffba57 FloatTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
64
5430bcffba57 FloatTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
65 void FloatTextureSceneLayer::SetCustomWindowing(float customCenter,
5430bcffba57 FloatTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
66 float customWidth)
5430bcffba57 FloatTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
67 {
5430bcffba57 FloatTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
68 if (customWidth <= 0)
5430bcffba57 FloatTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
69 {
5430bcffba57 FloatTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
70 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange);
5430bcffba57 FloatTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
71 }
5430bcffba57 FloatTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
72 else
5430bcffba57 FloatTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
73 {
5430bcffba57 FloatTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
74 windowing_ = ImageWindowing_Custom;
5430bcffba57 FloatTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
75 customCenter_ = customCenter;
5430bcffba57 FloatTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
76 customWidth_ = customWidth;
5430bcffba57 FloatTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
77 IncrementRevision();
5430bcffba57 FloatTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
78 }
5430bcffba57 FloatTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
79 }
5430bcffba57 FloatTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
80
5430bcffba57 FloatTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
81
5430bcffba57 FloatTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
82 void FloatTextureSceneLayer::GetWindowing(float& targetCenter,
5430bcffba57 FloatTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
83 float& targetWidth) const
5430bcffba57 FloatTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
84 {
5430bcffba57 FloatTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
85 ::OrthancStone::ComputeWindowing(targetCenter, targetWidth,
5430bcffba57 FloatTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
86 windowing_, customCenter_, customWidth_);
5430bcffba57 FloatTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
87 }
5430bcffba57 FloatTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
88
5430bcffba57 FloatTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
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
5430bcffba57 FloatTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
97 void FloatTextureSceneLayer::FitRange()
5430bcffba57 FloatTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
98 {
5430bcffba57 FloatTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
99 float minValue, maxValue;
5430bcffba57 FloatTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
100 Orthanc::ImageProcessing::GetMinMaxFloatValue(minValue, maxValue, GetTexture());
5430bcffba57 FloatTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
101
5430bcffba57 FloatTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
102 float width;
5430bcffba57 FloatTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
103
5430bcffba57 FloatTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
104 assert(minValue <= maxValue);
5430bcffba57 FloatTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
105 if (LinearAlgebra::IsCloseToZero(maxValue - minValue))
5430bcffba57 FloatTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
106 {
5430bcffba57 FloatTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
107 width = 1;
5430bcffba57 FloatTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
108 }
5430bcffba57 FloatTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
109 else
5430bcffba57 FloatTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
110 {
5430bcffba57 FloatTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
111 width = maxValue - minValue;
5430bcffba57 FloatTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
112 }
5430bcffba57 FloatTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
113
5430bcffba57 FloatTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
114 SetCustomWindowing((minValue + maxValue) / 2.0f, width);
5430bcffba57 FloatTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
115 }
5430bcffba57 FloatTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
116
5430bcffba57 FloatTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
117
5430bcffba57 FloatTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
118 ISceneLayer* FloatTextureSceneLayer::Clone() const
5430bcffba57 FloatTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
119 {
5430bcffba57 FloatTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
120 std::auto_ptr<FloatTextureSceneLayer> cloned
5430bcffba57 FloatTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
121 (new FloatTextureSceneLayer(GetTexture()));
5430bcffba57 FloatTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
122
5430bcffba57 FloatTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
123 cloned->CopyParameters(*this);
5430bcffba57 FloatTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
124 cloned->windowing_ = windowing_;
5430bcffba57 FloatTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
125 cloned->customCenter_ = customCenter_;
5430bcffba57 FloatTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
126 cloned->customWidth_ = customWidth_;
773
b8dfd966b5f4 FloatTextureSceneLayer::SetInverted()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 590
diff changeset
127 cloned->inverted_ = inverted_;
590
5430bcffba57 FloatTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
128
5430bcffba57 FloatTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
129 return cloned.release();
5430bcffba57 FloatTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
130 }
5430bcffba57 FloatTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
131 }