Mercurial > hg > orthanc-stone
annotate OrthancStone/Sources/Scene2D/LookupTableTextureSceneLayer.cpp @ 1876:b1f510e601d2
more unit tests
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 11 Jan 2022 21:26:47 +0100 |
parents | 7053b8a0aaec |
children | f81cdf283859 |
rev | line source |
---|---|
768
55411e7da2f7
LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1 /** |
55411e7da2f7
LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2 * Stone of Orthanc |
55411e7da2f7
LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics |
55411e7da2f7
LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
4 * Department, University Hospital of Liege, Belgium |
1871
7053b8a0aaec
upgrade to year 2022
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1870
diff
changeset
|
5 * Copyright (C) 2017-2022 Osimis S.A., Belgium |
7053b8a0aaec
upgrade to year 2022
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1870
diff
changeset
|
6 * Copyright (C) 2021-2022 Sebastien Jodogne, ICTEAM UCLouvain, Belgium |
768
55411e7da2f7
LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
7 * |
55411e7da2f7
LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
8 * 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
|
9 * modify it under the terms of the GNU Lesser General Public License |
768
55411e7da2f7
LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
10 * as published by the Free Software Foundation, either version 3 of |
55411e7da2f7
LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
11 * the License, or (at your option) any later version. |
55411e7da2f7
LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
12 * |
55411e7da2f7
LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
13 * This program is distributed in the hope that it will be useful, but |
55411e7da2f7
LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
14 * 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
|
15 * 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
|
16 * Lesser General Public License for more details. |
1596
4fb8fdf03314
removed annoying whitespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1512
diff
changeset
|
17 * |
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
|
18 * 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
|
19 * 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
|
20 * <http://www.gnu.org/licenses/>. |
768
55411e7da2f7
LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
21 **/ |
55411e7da2f7
LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
22 |
55411e7da2f7
LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
23 |
55411e7da2f7
LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
24 #include "LookupTableTextureSceneLayer.h" |
55411e7da2f7
LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
25 |
1455
30deba7bc8e2
simplifying include_directories
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1300
diff
changeset
|
26 #include <Images/Image.h> |
30deba7bc8e2
simplifying include_directories
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1300
diff
changeset
|
27 #include <Images/ImageProcessing.h> |
1624 | 28 #include <Logging.h> |
1455
30deba7bc8e2
simplifying include_directories
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1300
diff
changeset
|
29 #include <OrthancException.h> |
768
55411e7da2f7
LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
30 |
55411e7da2f7
LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
31 namespace OrthancStone |
55411e7da2f7
LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
32 { |
1251
96d4f4fee5bb
fix uninitialized variable in LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1179
diff
changeset
|
33 LookupTableTextureSceneLayer::LookupTableTextureSceneLayer(const Orthanc::ImageAccessor& texture) : |
96d4f4fee5bb
fix uninitialized variable in LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1179
diff
changeset
|
34 applyLog_(false) |
768
55411e7da2f7
LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
35 { |
55411e7da2f7
LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
36 { |
1298
8a0a62189f46
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1270
diff
changeset
|
37 std::unique_ptr<Orthanc::ImageAccessor> t( |
768
55411e7da2f7
LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
38 new Orthanc::Image(Orthanc::PixelFormat_Float32, |
55411e7da2f7
LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
39 texture.GetWidth(), |
55411e7da2f7
LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
40 texture.GetHeight(), |
55411e7da2f7
LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
41 false)); |
55411e7da2f7
LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
42 |
55411e7da2f7
LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
43 Orthanc::ImageProcessing::Convert(*t, texture); |
55411e7da2f7
LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
44 SetTexture(t.release()); |
55411e7da2f7
LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
45 } |
55411e7da2f7
LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
46 |
1072
391fb6d6905d
OrthancMultiframeVolumeLoader asks volume image to compute range +
Benjamin Golinvaux <bgo@osimis.io>
parents:
798
diff
changeset
|
47 SetLookupTableGrayscale(); // simple ramp between 0 and 255 |
768
55411e7da2f7
LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
48 SetRange(0, 1); |
55411e7da2f7
LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
49 } |
55411e7da2f7
LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
50 |
55411e7da2f7
LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
51 |
769
4ba8892870a2
improved interface for lookup tables
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
768
diff
changeset
|
52 void LookupTableTextureSceneLayer::SetLookupTableGrayscale() |
768
55411e7da2f7
LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
53 { |
55411e7da2f7
LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
54 std::vector<uint8_t> rgb(3 * 256); |
55411e7da2f7
LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
55 |
55411e7da2f7
LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
56 for (size_t i = 0; i < 256; i++) |
55411e7da2f7
LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
57 { |
798 | 58 rgb[3 * i] = static_cast<uint8_t>(i); |
59 rgb[3 * i + 1] = static_cast<uint8_t>(i); | |
60 rgb[3 * i + 2] = static_cast<uint8_t>(i); | |
768
55411e7da2f7
LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
61 } |
55411e7da2f7
LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
62 |
769
4ba8892870a2
improved interface for lookup tables
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
768
diff
changeset
|
63 SetLookupTableRgb(rgb); |
768
55411e7da2f7
LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
64 } |
55411e7da2f7
LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
65 |
55411e7da2f7
LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
66 |
769
4ba8892870a2
improved interface for lookup tables
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
768
diff
changeset
|
67 void LookupTableTextureSceneLayer::SetLookupTableRgb(const std::vector<uint8_t>& lut) |
768
55411e7da2f7
LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
68 { |
769
4ba8892870a2
improved interface for lookup tables
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
768
diff
changeset
|
69 if (lut.size() != 3 * 256) |
768
55411e7da2f7
LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
70 { |
769
4ba8892870a2
improved interface for lookup tables
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
768
diff
changeset
|
71 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); |
768
55411e7da2f7
LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
72 } |
55411e7da2f7
LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
73 |
55411e7da2f7
LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
74 lut_.resize(4 * 256); |
55411e7da2f7
LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
75 |
55411e7da2f7
LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
76 for (size_t i = 0; i < 256; i++) |
55411e7da2f7
LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
77 { |
55411e7da2f7
LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
78 // Premultiplied alpha |
55411e7da2f7
LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
79 |
55411e7da2f7
LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
80 if (i == 0) |
55411e7da2f7
LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
81 { |
55411e7da2f7
LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
82 // Make zero transparent |
55411e7da2f7
LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
83 lut_[4 * i] = 0; // R |
55411e7da2f7
LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
84 lut_[4 * i + 1] = 0; // G |
55411e7da2f7
LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
85 lut_[4 * i + 2] = 0; // B |
55411e7da2f7
LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
86 lut_[4 * i + 3] = 0; // A |
55411e7da2f7
LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
87 } |
55411e7da2f7
LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
88 else |
55411e7da2f7
LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
89 { |
769
4ba8892870a2
improved interface for lookup tables
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
768
diff
changeset
|
90 float a = static_cast<float>(i) / 255.0f; |
4ba8892870a2
improved interface for lookup tables
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
768
diff
changeset
|
91 |
4ba8892870a2
improved interface for lookup tables
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
768
diff
changeset
|
92 float r = static_cast<float>(lut[3 * i]) * a; |
4ba8892870a2
improved interface for lookup tables
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
768
diff
changeset
|
93 float g = static_cast<float>(lut[3 * i + 1]) * a; |
4ba8892870a2
improved interface for lookup tables
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
768
diff
changeset
|
94 float b = static_cast<float>(lut[3 * i + 2]) * a; |
768
55411e7da2f7
LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
95 |
55411e7da2f7
LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
96 lut_[4 * i] = static_cast<uint8_t>(std::floor(r)); |
55411e7da2f7
LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
97 lut_[4 * i + 1] = static_cast<uint8_t>(std::floor(g)); |
55411e7da2f7
LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
98 lut_[4 * i + 2] = static_cast<uint8_t>(std::floor(b)); |
769
4ba8892870a2
improved interface for lookup tables
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
768
diff
changeset
|
99 lut_[4 * i + 3] = static_cast<uint8_t>(std::floor(a * 255.0f)); |
768
55411e7da2f7
LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
100 } |
55411e7da2f7
LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
101 } |
55411e7da2f7
LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
102 |
55411e7da2f7
LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
103 IncrementRevision(); |
55411e7da2f7
LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
104 } |
55411e7da2f7
LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
105 |
55411e7da2f7
LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
106 |
55411e7da2f7
LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
107 void LookupTableTextureSceneLayer::SetLookupTable(const std::vector<uint8_t>& lut) |
55411e7da2f7
LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
108 { |
769
4ba8892870a2
improved interface for lookup tables
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
768
diff
changeset
|
109 if (lut.size() == 4 * 256) |
4ba8892870a2
improved interface for lookup tables
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
768
diff
changeset
|
110 { |
4ba8892870a2
improved interface for lookup tables
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
768
diff
changeset
|
111 lut_ = lut; |
4ba8892870a2
improved interface for lookup tables
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
768
diff
changeset
|
112 IncrementRevision(); |
4ba8892870a2
improved interface for lookup tables
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
768
diff
changeset
|
113 } |
4ba8892870a2
improved interface for lookup tables
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
768
diff
changeset
|
114 else if (lut.size() == 3 * 256) |
4ba8892870a2
improved interface for lookup tables
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
768
diff
changeset
|
115 { |
4ba8892870a2
improved interface for lookup tables
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
768
diff
changeset
|
116 SetLookupTableRgb(lut); |
4ba8892870a2
improved interface for lookup tables
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
768
diff
changeset
|
117 } |
4ba8892870a2
improved interface for lookup tables
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
768
diff
changeset
|
118 else |
768
55411e7da2f7
LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
119 { |
55411e7da2f7
LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
120 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); |
55411e7da2f7
LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
121 } |
55411e7da2f7
LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
122 } |
55411e7da2f7
LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
123 |
55411e7da2f7
LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
124 void LookupTableTextureSceneLayer::SetRange(float minValue, |
55411e7da2f7
LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
125 float maxValue) |
55411e7da2f7
LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
126 { |
55411e7da2f7
LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
127 if (minValue > maxValue) |
55411e7da2f7
LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
128 { |
55411e7da2f7
LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
129 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); |
55411e7da2f7
LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
130 } |
55411e7da2f7
LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
131 else |
55411e7da2f7
LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
132 { |
55411e7da2f7
LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
133 minValue_ = minValue; |
55411e7da2f7
LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
134 maxValue_ = maxValue; |
55411e7da2f7
LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
135 IncrementRevision(); |
55411e7da2f7
LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
136 } |
55411e7da2f7
LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
137 } |
55411e7da2f7
LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
138 |
1179
177e7d431cd1
log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1105
diff
changeset
|
139 void LookupTableTextureSceneLayer::SetApplyLog(bool apply) |
177e7d431cd1
log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1105
diff
changeset
|
140 { |
177e7d431cd1
log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1105
diff
changeset
|
141 applyLog_ = apply; |
177e7d431cd1
log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1105
diff
changeset
|
142 IncrementRevision(); |
177e7d431cd1
log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1105
diff
changeset
|
143 } |
177e7d431cd1
log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1105
diff
changeset
|
144 |
768
55411e7da2f7
LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
145 void LookupTableTextureSceneLayer::FitRange() |
55411e7da2f7
LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
146 { |
55411e7da2f7
LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
147 Orthanc::ImageProcessing::GetMinMaxFloatValue(minValue_, maxValue_, GetTexture()); |
55411e7da2f7
LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
148 assert(minValue_ <= maxValue_); |
1072
391fb6d6905d
OrthancMultiframeVolumeLoader asks volume image to compute range +
Benjamin Golinvaux <bgo@osimis.io>
parents:
798
diff
changeset
|
149 // TODO: debug to be removed |
1081
369050c846a9
Removed erron. error log
Benjamin Golinvaux <bgo@osimis.io>
parents:
1080
diff
changeset
|
150 if (fabs(maxValue_ - minValue_) < 0.0001) { |
369050c846a9
Removed erron. error log
Benjamin Golinvaux <bgo@osimis.io>
parents:
1080
diff
changeset
|
151 LOG(INFO) << "LookupTableTextureSceneLayer::FitRange(): minValue_ = " << minValue_ << " maxValue_ = " << maxValue_; |
369050c846a9
Removed erron. error log
Benjamin Golinvaux <bgo@osimis.io>
parents:
1080
diff
changeset
|
152 } |
768
55411e7da2f7
LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
153 IncrementRevision(); |
55411e7da2f7
LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
154 } |
55411e7da2f7
LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
155 |
55411e7da2f7
LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
156 |
55411e7da2f7
LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
157 ISceneLayer* LookupTableTextureSceneLayer::Clone() const |
55411e7da2f7
LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
158 { |
1298
8a0a62189f46
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1270
diff
changeset
|
159 std::unique_ptr<LookupTableTextureSceneLayer> cloned |
768
55411e7da2f7
LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
160 (new LookupTableTextureSceneLayer(GetTexture())); |
55411e7da2f7
LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
161 |
1072
391fb6d6905d
OrthancMultiframeVolumeLoader asks volume image to compute range +
Benjamin Golinvaux <bgo@osimis.io>
parents:
798
diff
changeset
|
162 |
391fb6d6905d
OrthancMultiframeVolumeLoader asks volume image to compute range +
Benjamin Golinvaux <bgo@osimis.io>
parents:
798
diff
changeset
|
163 // TODO: why is windowing_ not copied?????? |
768
55411e7da2f7
LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
164 cloned->CopyParameters(*this); |
55411e7da2f7
LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
165 cloned->minValue_ = minValue_; |
55411e7da2f7
LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
166 cloned->maxValue_ = maxValue_; |
55411e7da2f7
LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
167 cloned->lut_ = lut_; |
55411e7da2f7
LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
168 |
55411e7da2f7
LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
169 return cloned.release(); |
55411e7da2f7
LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
170 } |
1179
177e7d431cd1
log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1105
diff
changeset
|
171 |
177e7d431cd1
log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1105
diff
changeset
|
172 |
177e7d431cd1
log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1105
diff
changeset
|
173 // Templatized function to speed up computations, by avoiding |
177e7d431cd1
log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1105
diff
changeset
|
174 // testing conditions on each pixel |
177e7d431cd1
log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1105
diff
changeset
|
175 template <bool IsApplyLog, |
177e7d431cd1
log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1105
diff
changeset
|
176 Orthanc::PixelFormat TargetFormat> |
177e7d431cd1
log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1105
diff
changeset
|
177 static void RenderInternal(Orthanc::ImageAccessor& target, |
177e7d431cd1
log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1105
diff
changeset
|
178 const Orthanc::ImageAccessor& source, |
177e7d431cd1
log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1105
diff
changeset
|
179 float minValue, |
177e7d431cd1
log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1105
diff
changeset
|
180 float slope, |
177e7d431cd1
log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1105
diff
changeset
|
181 const std::vector<uint8_t>& lut) |
177e7d431cd1
log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1105
diff
changeset
|
182 { |
177e7d431cd1
log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1105
diff
changeset
|
183 static const float LOG_NORMALIZATION = 255.0f / log(1.0f + 255.0f); |
177e7d431cd1
log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1105
diff
changeset
|
184 |
177e7d431cd1
log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1105
diff
changeset
|
185 const unsigned int width = source.GetWidth(); |
177e7d431cd1
log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1105
diff
changeset
|
186 const unsigned int height = source.GetHeight(); |
177e7d431cd1
log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1105
diff
changeset
|
187 |
177e7d431cd1
log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1105
diff
changeset
|
188 for (unsigned int y = 0; y < height; y++) |
177e7d431cd1
log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1105
diff
changeset
|
189 { |
177e7d431cd1
log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1105
diff
changeset
|
190 const float* p = reinterpret_cast<const float*>(source.GetConstRow(y)); |
177e7d431cd1
log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1105
diff
changeset
|
191 uint8_t* q = reinterpret_cast<uint8_t*>(target.GetRow(y)); |
177e7d431cd1
log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1105
diff
changeset
|
192 |
177e7d431cd1
log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1105
diff
changeset
|
193 for (unsigned int x = 0; x < width; x++) |
177e7d431cd1
log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1105
diff
changeset
|
194 { |
177e7d431cd1
log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1105
diff
changeset
|
195 float v = (*p - minValue) * slope; |
177e7d431cd1
log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1105
diff
changeset
|
196 if (v <= 0) |
177e7d431cd1
log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1105
diff
changeset
|
197 { |
177e7d431cd1
log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1105
diff
changeset
|
198 v = 0; |
177e7d431cd1
log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1105
diff
changeset
|
199 } |
177e7d431cd1
log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1105
diff
changeset
|
200 else if (v >= 255) |
177e7d431cd1
log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1105
diff
changeset
|
201 { |
177e7d431cd1
log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1105
diff
changeset
|
202 v = 255; |
177e7d431cd1
log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1105
diff
changeset
|
203 } |
177e7d431cd1
log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1105
diff
changeset
|
204 |
177e7d431cd1
log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1105
diff
changeset
|
205 if (IsApplyLog) |
177e7d431cd1
log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1105
diff
changeset
|
206 { |
177e7d431cd1
log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1105
diff
changeset
|
207 // https://theailearner.com/2019/01/01/log-transformation/ |
177e7d431cd1
log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1105
diff
changeset
|
208 v = LOG_NORMALIZATION * log(1.0f + static_cast<float>(v)); |
177e7d431cd1
log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1105
diff
changeset
|
209 } |
177e7d431cd1
log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1105
diff
changeset
|
210 |
177e7d431cd1
log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1105
diff
changeset
|
211 assert(v >= 0.0f && v <= 255.0f); |
177e7d431cd1
log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1105
diff
changeset
|
212 |
177e7d431cd1
log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1105
diff
changeset
|
213 uint8_t vv = static_cast<uint8_t>(v); |
177e7d431cd1
log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1105
diff
changeset
|
214 |
177e7d431cd1
log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1105
diff
changeset
|
215 switch (TargetFormat) |
177e7d431cd1
log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1105
diff
changeset
|
216 { |
177e7d431cd1
log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1105
diff
changeset
|
217 case Orthanc::PixelFormat_BGRA32: |
177e7d431cd1
log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1105
diff
changeset
|
218 // For Cairo surfaces |
177e7d431cd1
log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1105
diff
changeset
|
219 q[0] = lut[4 * vv + 2]; // B |
177e7d431cd1
log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1105
diff
changeset
|
220 q[1] = lut[4 * vv + 1]; // G |
177e7d431cd1
log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1105
diff
changeset
|
221 q[2] = lut[4 * vv + 0]; // R |
177e7d431cd1
log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1105
diff
changeset
|
222 q[3] = lut[4 * vv + 3]; // A |
177e7d431cd1
log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1105
diff
changeset
|
223 break; |
177e7d431cd1
log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1105
diff
changeset
|
224 |
177e7d431cd1
log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1105
diff
changeset
|
225 case Orthanc::PixelFormat_RGBA32: |
177e7d431cd1
log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1105
diff
changeset
|
226 // For OpenGL |
177e7d431cd1
log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1105
diff
changeset
|
227 q[0] = lut[4 * vv + 0]; // R |
177e7d431cd1
log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1105
diff
changeset
|
228 q[1] = lut[4 * vv + 1]; // G |
177e7d431cd1
log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1105
diff
changeset
|
229 q[2] = lut[4 * vv + 2]; // B |
177e7d431cd1
log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1105
diff
changeset
|
230 q[3] = lut[4 * vv + 3]; // A |
177e7d431cd1
log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1105
diff
changeset
|
231 break; |
177e7d431cd1
log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1105
diff
changeset
|
232 |
177e7d431cd1
log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1105
diff
changeset
|
233 default: |
177e7d431cd1
log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1105
diff
changeset
|
234 assert(0); |
177e7d431cd1
log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1105
diff
changeset
|
235 } |
177e7d431cd1
log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1105
diff
changeset
|
236 |
177e7d431cd1
log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1105
diff
changeset
|
237 p++; |
177e7d431cd1
log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1105
diff
changeset
|
238 q += 4; |
177e7d431cd1
log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1105
diff
changeset
|
239 } |
177e7d431cd1
log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1105
diff
changeset
|
240 } |
177e7d431cd1
log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1105
diff
changeset
|
241 } |
177e7d431cd1
log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1105
diff
changeset
|
242 |
177e7d431cd1
log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1105
diff
changeset
|
243 |
177e7d431cd1
log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1105
diff
changeset
|
244 void LookupTableTextureSceneLayer::Render(Orthanc::ImageAccessor& target) const |
177e7d431cd1
log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1105
diff
changeset
|
245 { |
177e7d431cd1
log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1105
diff
changeset
|
246 assert(sizeof(float) == 4); |
177e7d431cd1
log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1105
diff
changeset
|
247 |
177e7d431cd1
log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1105
diff
changeset
|
248 if (!HasTexture()) |
177e7d431cd1
log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1105
diff
changeset
|
249 { |
177e7d431cd1
log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1105
diff
changeset
|
250 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); |
177e7d431cd1
log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1105
diff
changeset
|
251 } |
177e7d431cd1
log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1105
diff
changeset
|
252 |
177e7d431cd1
log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1105
diff
changeset
|
253 const Orthanc::ImageAccessor& source = GetTexture(); |
177e7d431cd1
log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1105
diff
changeset
|
254 |
177e7d431cd1
log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1105
diff
changeset
|
255 if (source.GetFormat() != Orthanc::PixelFormat_Float32 || |
177e7d431cd1
log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1105
diff
changeset
|
256 (target.GetFormat() != Orthanc::PixelFormat_RGBA32 && |
177e7d431cd1
log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1105
diff
changeset
|
257 target.GetFormat() != Orthanc::PixelFormat_BGRA32)) |
177e7d431cd1
log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1105
diff
changeset
|
258 { |
177e7d431cd1
log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1105
diff
changeset
|
259 throw Orthanc::OrthancException(Orthanc::ErrorCode_IncompatibleImageFormat); |
177e7d431cd1
log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1105
diff
changeset
|
260 } |
177e7d431cd1
log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1105
diff
changeset
|
261 |
177e7d431cd1
log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1105
diff
changeset
|
262 if (source.GetWidth() != target.GetWidth() || |
177e7d431cd1
log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1105
diff
changeset
|
263 source.GetHeight() != target.GetHeight()) |
177e7d431cd1
log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1105
diff
changeset
|
264 { |
177e7d431cd1
log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1105
diff
changeset
|
265 throw Orthanc::OrthancException(Orthanc::ErrorCode_IncompatibleImageSize); |
177e7d431cd1
log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1105
diff
changeset
|
266 } |
177e7d431cd1
log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1105
diff
changeset
|
267 |
177e7d431cd1
log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1105
diff
changeset
|
268 const float minValue = GetMinValue(); |
177e7d431cd1
log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1105
diff
changeset
|
269 float slope; |
177e7d431cd1
log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1105
diff
changeset
|
270 |
177e7d431cd1
log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1105
diff
changeset
|
271 if (GetMinValue() >= GetMaxValue()) |
177e7d431cd1
log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1105
diff
changeset
|
272 { |
177e7d431cd1
log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1105
diff
changeset
|
273 slope = 0; |
177e7d431cd1
log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1105
diff
changeset
|
274 } |
177e7d431cd1
log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1105
diff
changeset
|
275 else |
177e7d431cd1
log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1105
diff
changeset
|
276 { |
177e7d431cd1
log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1105
diff
changeset
|
277 slope = 256.0f / (GetMaxValue() - GetMinValue()); |
177e7d431cd1
log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1105
diff
changeset
|
278 } |
177e7d431cd1
log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1105
diff
changeset
|
279 |
177e7d431cd1
log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1105
diff
changeset
|
280 const std::vector<uint8_t>& lut = GetLookupTable(); |
177e7d431cd1
log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1105
diff
changeset
|
281 if (lut.size() != 4 * 256) |
177e7d431cd1
log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1105
diff
changeset
|
282 { |
177e7d431cd1
log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1105
diff
changeset
|
283 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); |
177e7d431cd1
log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1105
diff
changeset
|
284 } |
177e7d431cd1
log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1105
diff
changeset
|
285 |
177e7d431cd1
log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1105
diff
changeset
|
286 switch (target.GetFormat()) |
177e7d431cd1
log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1105
diff
changeset
|
287 { |
177e7d431cd1
log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1105
diff
changeset
|
288 case Orthanc::PixelFormat_RGBA32: |
177e7d431cd1
log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1105
diff
changeset
|
289 if (applyLog_) |
177e7d431cd1
log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1105
diff
changeset
|
290 { |
177e7d431cd1
log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1105
diff
changeset
|
291 RenderInternal<true, Orthanc::PixelFormat_RGBA32>(target, source, minValue, slope, lut); |
177e7d431cd1
log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1105
diff
changeset
|
292 } |
177e7d431cd1
log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1105
diff
changeset
|
293 else |
177e7d431cd1
log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1105
diff
changeset
|
294 { |
177e7d431cd1
log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1105
diff
changeset
|
295 RenderInternal<false, Orthanc::PixelFormat_RGBA32>(target, source, minValue, slope, lut); |
177e7d431cd1
log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1105
diff
changeset
|
296 } |
177e7d431cd1
log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1105
diff
changeset
|
297 break; |
177e7d431cd1
log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1105
diff
changeset
|
298 |
177e7d431cd1
log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1105
diff
changeset
|
299 case Orthanc::PixelFormat_BGRA32: |
177e7d431cd1
log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1105
diff
changeset
|
300 if (applyLog_) |
177e7d431cd1
log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1105
diff
changeset
|
301 { |
177e7d431cd1
log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1105
diff
changeset
|
302 RenderInternal<true, Orthanc::PixelFormat_BGRA32>(target, source, minValue, slope, lut); |
177e7d431cd1
log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1105
diff
changeset
|
303 } |
177e7d431cd1
log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1105
diff
changeset
|
304 else |
177e7d431cd1
log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1105
diff
changeset
|
305 { |
177e7d431cd1
log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1105
diff
changeset
|
306 RenderInternal<false, Orthanc::PixelFormat_BGRA32>(target, source, minValue, slope, lut); |
177e7d431cd1
log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1105
diff
changeset
|
307 } |
177e7d431cd1
log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1105
diff
changeset
|
308 break; |
177e7d431cd1
log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1105
diff
changeset
|
309 |
177e7d431cd1
log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1105
diff
changeset
|
310 default: |
177e7d431cd1
log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1105
diff
changeset
|
311 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); |
177e7d431cd1
log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1105
diff
changeset
|
312 } |
177e7d431cd1
log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1105
diff
changeset
|
313 } |
768
55411e7da2f7
LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
314 } |