annotate OrthancStone/Sources/Scene2D/LookupTableTextureSceneLayer.cpp @ 1928:c73e696967b0 StoneWebViewer-2.3

StoneWebViewer-2.3
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 24 Mar 2022 09:08:51 +0100
parents ed4831e08961
children 07964689cb0b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
59f95b9ea858 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1598
diff changeset
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 {
1919
ed4831e08961 added DicomInstanceParameters::CreateOverlayTexture()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1910
diff changeset
36 if (texture.GetFormat() == Orthanc::PixelFormat_Float32)
ed4831e08961 added DicomInstanceParameters::CreateOverlayTexture()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1910
diff changeset
37 {
ed4831e08961 added DicomInstanceParameters::CreateOverlayTexture()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1910
diff changeset
38 SetTexture(Orthanc::Image::Clone(texture));
ed4831e08961 added DicomInstanceParameters::CreateOverlayTexture()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1910
diff changeset
39 }
ed4831e08961 added DicomInstanceParameters::CreateOverlayTexture()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1910
diff changeset
40 else
768
55411e7da2f7 LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
41 {
1298
8a0a62189f46 replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1270
diff changeset
42 std::unique_ptr<Orthanc::ImageAccessor> t(
1919
ed4831e08961 added DicomInstanceParameters::CreateOverlayTexture()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1910
diff changeset
43 new Orthanc::Image(Orthanc::PixelFormat_Float32, texture.GetWidth(), texture.GetHeight(), false));
768
55411e7da2f7 LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
44 Orthanc::ImageProcessing::Convert(*t, texture);
55411e7da2f7 LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
45 SetTexture(t.release());
55411e7da2f7 LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
46 }
55411e7da2f7 LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
47
1072
391fb6d6905d OrthancMultiframeVolumeLoader asks volume image to compute range +
Benjamin Golinvaux <bgo@osimis.io>
parents: 798
diff changeset
48 SetLookupTableGrayscale(); // simple ramp between 0 and 255
768
55411e7da2f7 LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
49 SetRange(0, 1);
55411e7da2f7 LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
50 }
55411e7da2f7 LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
51
55411e7da2f7 LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
52
769
4ba8892870a2 improved interface for lookup tables
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 768
diff changeset
53 void LookupTableTextureSceneLayer::SetLookupTableGrayscale()
768
55411e7da2f7 LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
54 {
55411e7da2f7 LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
55 std::vector<uint8_t> rgb(3 * 256);
55411e7da2f7 LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
56
55411e7da2f7 LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
57 for (size_t i = 0; i < 256; i++)
55411e7da2f7 LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
58 {
798
11fc84650e4b truncation warning
Benjamin Golinvaux <bgo@osimis.io>
parents: 769
diff changeset
59 rgb[3 * i] = static_cast<uint8_t>(i);
11fc84650e4b truncation warning
Benjamin Golinvaux <bgo@osimis.io>
parents: 769
diff changeset
60 rgb[3 * i + 1] = static_cast<uint8_t>(i);
11fc84650e4b truncation warning
Benjamin Golinvaux <bgo@osimis.io>
parents: 769
diff changeset
61 rgb[3 * i + 2] = static_cast<uint8_t>(i);
768
55411e7da2f7 LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
62 }
55411e7da2f7 LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
63
769
4ba8892870a2 improved interface for lookup tables
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 768
diff changeset
64 SetLookupTableRgb(rgb);
768
55411e7da2f7 LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
65 }
55411e7da2f7 LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
66
55411e7da2f7 LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
67
769
4ba8892870a2 improved interface for lookup tables
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 768
diff changeset
68 void LookupTableTextureSceneLayer::SetLookupTableRgb(const std::vector<uint8_t>& lut)
768
55411e7da2f7 LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
69 {
769
4ba8892870a2 improved interface for lookup tables
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 768
diff changeset
70 if (lut.size() != 3 * 256)
768
55411e7da2f7 LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
71 {
769
4ba8892870a2 improved interface for lookup tables
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 768
diff changeset
72 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError);
768
55411e7da2f7 LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
73 }
55411e7da2f7 LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
74
55411e7da2f7 LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
75 lut_.resize(4 * 256);
55411e7da2f7 LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
76
55411e7da2f7 LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
77 for (size_t i = 0; i < 256; i++)
55411e7da2f7 LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
78 {
55411e7da2f7 LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
79 // Premultiplied alpha
55411e7da2f7 LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
80
55411e7da2f7 LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
81 if (i == 0)
55411e7da2f7 LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
82 {
55411e7da2f7 LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
83 // Make zero transparent
55411e7da2f7 LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
84 lut_[4 * i] = 0; // R
55411e7da2f7 LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
85 lut_[4 * i + 1] = 0; // G
55411e7da2f7 LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
86 lut_[4 * i + 2] = 0; // B
55411e7da2f7 LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
87 lut_[4 * i + 3] = 0; // A
55411e7da2f7 LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
88 }
55411e7da2f7 LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
89 else
55411e7da2f7 LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
90 {
769
4ba8892870a2 improved interface for lookup tables
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 768
diff changeset
91 float a = static_cast<float>(i) / 255.0f;
4ba8892870a2 improved interface for lookup tables
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 768
diff changeset
92
4ba8892870a2 improved interface for lookup tables
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 768
diff changeset
93 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
94 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
95 float b = static_cast<float>(lut[3 * i + 2]) * a;
768
55411e7da2f7 LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
96
55411e7da2f7 LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
97 lut_[4 * i] = static_cast<uint8_t>(std::floor(r));
55411e7da2f7 LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
98 lut_[4 * i + 1] = static_cast<uint8_t>(std::floor(g));
55411e7da2f7 LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
99 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
100 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
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
55411e7da2f7 LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
104 IncrementRevision();
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
55411e7da2f7 LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
108 void LookupTableTextureSceneLayer::SetLookupTable(const std::vector<uint8_t>& lut)
55411e7da2f7 LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
109 {
769
4ba8892870a2 improved interface for lookup tables
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 768
diff changeset
110 if (lut.size() == 4 * 256)
4ba8892870a2 improved interface for lookup tables
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 768
diff changeset
111 {
4ba8892870a2 improved interface for lookup tables
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 768
diff changeset
112 lut_ = lut;
4ba8892870a2 improved interface for lookup tables
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 768
diff changeset
113 IncrementRevision();
4ba8892870a2 improved interface for lookup tables
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 768
diff changeset
114 }
4ba8892870a2 improved interface for lookup tables
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 768
diff changeset
115 else if (lut.size() == 3 * 256)
4ba8892870a2 improved interface for lookup tables
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 768
diff changeset
116 {
4ba8892870a2 improved interface for lookup tables
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 768
diff changeset
117 SetLookupTableRgb(lut);
4ba8892870a2 improved interface for lookup tables
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 768
diff changeset
118 }
4ba8892870a2 improved interface for lookup tables
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 768
diff changeset
119 else
768
55411e7da2f7 LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
120 {
55411e7da2f7 LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
121 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange);
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
55411e7da2f7 LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
125 void LookupTableTextureSceneLayer::SetRange(float minValue,
55411e7da2f7 LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
126 float maxValue)
55411e7da2f7 LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
127 {
55411e7da2f7 LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
128 if (minValue > maxValue)
55411e7da2f7 LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
129 {
55411e7da2f7 LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
130 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange);
55411e7da2f7 LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
131 }
55411e7da2f7 LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
132 else
55411e7da2f7 LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
133 {
55411e7da2f7 LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
134 minValue_ = minValue;
55411e7da2f7 LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
135 maxValue_ = maxValue;
55411e7da2f7 LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
136 IncrementRevision();
55411e7da2f7 LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
137 }
55411e7da2f7 LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
138 }
55411e7da2f7 LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
139
1179
177e7d431cd1 log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1105
diff changeset
140 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
141 {
177e7d431cd1 log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1105
diff changeset
142 applyLog_ = apply;
177e7d431cd1 log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1105
diff changeset
143 IncrementRevision();
177e7d431cd1 log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1105
diff changeset
144 }
177e7d431cd1 log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1105
diff changeset
145
768
55411e7da2f7 LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
146 void LookupTableTextureSceneLayer::FitRange()
55411e7da2f7 LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
147 {
55411e7da2f7 LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
148 Orthanc::ImageProcessing::GetMinMaxFloatValue(minValue_, maxValue_, GetTexture());
55411e7da2f7 LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
149 assert(minValue_ <= maxValue_);
1072
391fb6d6905d OrthancMultiframeVolumeLoader asks volume image to compute range +
Benjamin Golinvaux <bgo@osimis.io>
parents: 798
diff changeset
150 // TODO: debug to be removed
1081
369050c846a9 Removed erron. error log
Benjamin Golinvaux <bgo@osimis.io>
parents: 1080
diff changeset
151 if (fabs(maxValue_ - minValue_) < 0.0001) {
1910
f81cdf283859 display RT-STRUCT before the referenced slices get loaded
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1871
diff changeset
152 LOG(TRACE) << "LookupTableTextureSceneLayer::FitRange(): minValue_ = " << minValue_ << " maxValue_ = " << maxValue_;
1081
369050c846a9 Removed erron. error log
Benjamin Golinvaux <bgo@osimis.io>
parents: 1080
diff changeset
153 }
768
55411e7da2f7 LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
154 IncrementRevision();
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
55411e7da2f7 LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
158 ISceneLayer* LookupTableTextureSceneLayer::Clone() const
55411e7da2f7 LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
159 {
1298
8a0a62189f46 replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1270
diff changeset
160 std::unique_ptr<LookupTableTextureSceneLayer> cloned
768
55411e7da2f7 LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
161 (new LookupTableTextureSceneLayer(GetTexture()));
55411e7da2f7 LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
162
1072
391fb6d6905d OrthancMultiframeVolumeLoader asks volume image to compute range +
Benjamin Golinvaux <bgo@osimis.io>
parents: 798
diff changeset
163
391fb6d6905d OrthancMultiframeVolumeLoader asks volume image to compute range +
Benjamin Golinvaux <bgo@osimis.io>
parents: 798
diff changeset
164 // TODO: why is windowing_ not copied??????
768
55411e7da2f7 LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
165 cloned->CopyParameters(*this);
55411e7da2f7 LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
166 cloned->minValue_ = minValue_;
55411e7da2f7 LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
167 cloned->maxValue_ = maxValue_;
55411e7da2f7 LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
168 cloned->lut_ = lut_;
55411e7da2f7 LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
169
55411e7da2f7 LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
170 return cloned.release();
55411e7da2f7 LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
171 }
1179
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
177e7d431cd1 log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1105
diff changeset
174 // 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
175 // 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
176 template <bool IsApplyLog,
177e7d431cd1 log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1105
diff changeset
177 Orthanc::PixelFormat TargetFormat>
177e7d431cd1 log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1105
diff changeset
178 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
179 const Orthanc::ImageAccessor& source,
177e7d431cd1 log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1105
diff changeset
180 float minValue,
177e7d431cd1 log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1105
diff changeset
181 float slope,
177e7d431cd1 log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1105
diff changeset
182 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
183 {
177e7d431cd1 log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1105
diff changeset
184 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
185
177e7d431cd1 log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1105
diff changeset
186 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
187 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
188
177e7d431cd1 log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1105
diff changeset
189 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
190 {
177e7d431cd1 log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1105
diff changeset
191 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
192 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
193
177e7d431cd1 log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1105
diff changeset
194 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
195 {
177e7d431cd1 log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1105
diff changeset
196 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
197 if (v <= 0)
177e7d431cd1 log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1105
diff changeset
198 {
177e7d431cd1 log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1105
diff changeset
199 v = 0;
177e7d431cd1 log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1105
diff changeset
200 }
177e7d431cd1 log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1105
diff changeset
201 else if (v >= 255)
177e7d431cd1 log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1105
diff changeset
202 {
177e7d431cd1 log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1105
diff changeset
203 v = 255;
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
177e7d431cd1 log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1105
diff changeset
206 if (IsApplyLog)
177e7d431cd1 log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1105
diff changeset
207 {
177e7d431cd1 log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1105
diff changeset
208 // 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
209 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
210 }
177e7d431cd1 log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1105
diff changeset
211
177e7d431cd1 log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1105
diff changeset
212 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
213
177e7d431cd1 log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1105
diff changeset
214 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
215
177e7d431cd1 log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1105
diff changeset
216 switch (TargetFormat)
177e7d431cd1 log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1105
diff changeset
217 {
177e7d431cd1 log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1105
diff changeset
218 case Orthanc::PixelFormat_BGRA32:
177e7d431cd1 log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1105
diff changeset
219 // For Cairo surfaces
177e7d431cd1 log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1105
diff changeset
220 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
221 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
222 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
223 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
224 break;
177e7d431cd1 log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1105
diff changeset
225
177e7d431cd1 log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1105
diff changeset
226 case Orthanc::PixelFormat_RGBA32:
177e7d431cd1 log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1105
diff changeset
227 // For OpenGL
177e7d431cd1 log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1105
diff changeset
228 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
229 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
230 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
231 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
232 break;
177e7d431cd1 log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1105
diff changeset
233
177e7d431cd1 log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1105
diff changeset
234 default:
177e7d431cd1 log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1105
diff changeset
235 assert(0);
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
177e7d431cd1 log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1105
diff changeset
238 p++;
177e7d431cd1 log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1105
diff changeset
239 q += 4;
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
177e7d431cd1 log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1105
diff changeset
245 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
246 {
177e7d431cd1 log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1105
diff changeset
247 assert(sizeof(float) == 4);
177e7d431cd1 log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1105
diff changeset
248
177e7d431cd1 log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1105
diff changeset
249 if (!HasTexture())
177e7d431cd1 log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1105
diff changeset
250 {
177e7d431cd1 log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1105
diff changeset
251 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
252 }
177e7d431cd1 log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1105
diff changeset
253
177e7d431cd1 log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1105
diff changeset
254 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
255
177e7d431cd1 log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1105
diff changeset
256 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
257 (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
258 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
259 {
177e7d431cd1 log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1105
diff changeset
260 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
261 }
177e7d431cd1 log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1105
diff changeset
262
177e7d431cd1 log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1105
diff changeset
263 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
264 source.GetHeight() != target.GetHeight())
177e7d431cd1 log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1105
diff changeset
265 {
177e7d431cd1 log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1105
diff changeset
266 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
267 }
177e7d431cd1 log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1105
diff changeset
268
177e7d431cd1 log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1105
diff changeset
269 const float minValue = GetMinValue();
177e7d431cd1 log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1105
diff changeset
270 float slope;
177e7d431cd1 log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1105
diff changeset
271
177e7d431cd1 log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1105
diff changeset
272 if (GetMinValue() >= GetMaxValue())
177e7d431cd1 log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1105
diff changeset
273 {
177e7d431cd1 log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1105
diff changeset
274 slope = 0;
177e7d431cd1 log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1105
diff changeset
275 }
177e7d431cd1 log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1105
diff changeset
276 else
177e7d431cd1 log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1105
diff changeset
277 {
177e7d431cd1 log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1105
diff changeset
278 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
279 }
177e7d431cd1 log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1105
diff changeset
280
177e7d431cd1 log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1105
diff changeset
281 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
282 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
283 {
177e7d431cd1 log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1105
diff changeset
284 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
285 }
177e7d431cd1 log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1105
diff changeset
286
177e7d431cd1 log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1105
diff changeset
287 switch (target.GetFormat())
177e7d431cd1 log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1105
diff changeset
288 {
177e7d431cd1 log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1105
diff changeset
289 case Orthanc::PixelFormat_RGBA32:
177e7d431cd1 log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1105
diff changeset
290 if (applyLog_)
177e7d431cd1 log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1105
diff changeset
291 {
177e7d431cd1 log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1105
diff changeset
292 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
293 }
177e7d431cd1 log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1105
diff changeset
294 else
177e7d431cd1 log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1105
diff changeset
295 {
177e7d431cd1 log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1105
diff changeset
296 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
297 }
177e7d431cd1 log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1105
diff changeset
298 break;
177e7d431cd1 log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1105
diff changeset
299
177e7d431cd1 log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1105
diff changeset
300 case Orthanc::PixelFormat_BGRA32:
177e7d431cd1 log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1105
diff changeset
301 if (applyLog_)
177e7d431cd1 log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1105
diff changeset
302 {
177e7d431cd1 log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1105
diff changeset
303 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
304 }
177e7d431cd1 log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1105
diff changeset
305 else
177e7d431cd1 log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1105
diff changeset
306 {
177e7d431cd1 log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1105
diff changeset
307 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
308 }
177e7d431cd1 log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1105
diff changeset
309 break;
177e7d431cd1 log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1105
diff changeset
310
177e7d431cd1 log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1105
diff changeset
311 default:
177e7d431cd1 log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1105
diff changeset
312 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
313 }
177e7d431cd1 log scale in textures, remove redundant code for LUTs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1105
diff changeset
314 }
768
55411e7da2f7 LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
315 }