annotate Framework/Deprecated/Toolbox/DicomFrameConverter.cpp @ 925:4639d0bf6390

Added support for Grayscale16 in the multiframe loader (Victor)
author Benjamin Golinvaux <bgo@osimis.io>
date Mon, 22 Jul 2019 16:00:03 +0200
parents c35e98d22764
children 1f74bc3459ba
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 /**
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2 * Stone of Orthanc
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
4 * Department, University Hospital of Liege, Belgium
439
b70e9be013e4 preparing for 2019
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
5 * Copyright (C) 2017-2019 Osimis S.A., Belgium
0
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
6 *
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 * This program is free software: you can redistribute it and/or
47
28956ed68280 agpl license
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 40
diff changeset
8 * modify it under the terms of the GNU Affero General Public License
28956ed68280 agpl license
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 40
diff changeset
9 * as published by the Free Software Foundation, either version 3 of
28956ed68280 agpl license
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 40
diff changeset
10 * the License, or (at your option) any later version.
0
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 *
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 * This program is distributed in the hope that it will be useful, but
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
47
28956ed68280 agpl license
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 40
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
28956ed68280 agpl license
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 40
diff changeset
15 * Affero General Public License for more details.
28956ed68280 agpl license
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 40
diff changeset
16 *
28956ed68280 agpl license
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 40
diff changeset
17 * You should have received a copy of the GNU Affero General Public License
0
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
19 **/
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22 #include "DicomFrameConverter.h"
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23
732
c35e98d22764 move Deprecated classes to a separate folder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 714
diff changeset
24 #include "../../Toolbox/LinearAlgebra.h"
32
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 16
diff changeset
25
212
5412adf19980 resort to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 201
diff changeset
26 #include <Core/Images/Image.h>
5412adf19980 resort to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 201
diff changeset
27 #include <Core/Images/ImageProcessing.h>
5412adf19980 resort to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 201
diff changeset
28 #include <Core/OrthancException.h>
5412adf19980 resort to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 201
diff changeset
29 #include <Core/Toolbox.h>
0
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30
714
d2c0e347ddc2 deprecating DicomFrameConverter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 439
diff changeset
31 namespace Deprecated
0
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32 {
338
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 328
diff changeset
33 static const Orthanc::DicomTag IMAGE_TAGS[] =
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 328
diff changeset
34 {
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 328
diff changeset
35 Orthanc::DICOM_TAG_BITS_STORED,
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 328
diff changeset
36 Orthanc::DICOM_TAG_DOSE_GRID_SCALING,
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 328
diff changeset
37 Orthanc::DICOM_TAG_PHOTOMETRIC_INTERPRETATION,
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 328
diff changeset
38 Orthanc::DICOM_TAG_PIXEL_REPRESENTATION,
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 328
diff changeset
39 Orthanc::DICOM_TAG_RESCALE_INTERCEPT,
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 328
diff changeset
40 Orthanc::DICOM_TAG_RESCALE_SLOPE,
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 328
diff changeset
41 Orthanc::DICOM_TAG_WINDOW_CENTER,
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 328
diff changeset
42 Orthanc::DICOM_TAG_WINDOW_WIDTH
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 328
diff changeset
43 };
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 328
diff changeset
44
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 328
diff changeset
45
0
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
46 void DicomFrameConverter::SetDefaultParameters()
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
47 {
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
48 isSigned_ = true;
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
49 isColor_ = false;
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
50 hasRescale_ = false;
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
51 rescaleIntercept_ = 0;
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
52 rescaleSlope_ = 1;
338
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 328
diff changeset
53 hasDefaultWindow_ = false;
0
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
54 defaultWindowCenter_ = 128;
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
55 defaultWindowWidth_ = 256;
119
ba83e38cf3ff rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 118
diff changeset
56 expectedPixelFormat_ = Orthanc::PixelFormat_Grayscale16;
0
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
57 }
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
58
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
59
118
a4d0b6c82b29 using Orthanc::DicomMap instead of OrthancPlugins::DicomDatasetReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 113
diff changeset
60 void DicomFrameConverter::ReadParameters(const Orthanc::DicomMap& dicom)
0
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
61 {
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
62 SetDefaultParameters();
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
63
714
d2c0e347ddc2 deprecating DicomFrameConverter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 439
diff changeset
64 OrthancStone::Vector c, w;
d2c0e347ddc2 deprecating DicomFrameConverter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 439
diff changeset
65 if (OrthancStone::LinearAlgebra::ParseVector(c, dicom, Orthanc::DICOM_TAG_WINDOW_CENTER) &&
d2c0e347ddc2 deprecating DicomFrameConverter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 439
diff changeset
66 OrthancStone::LinearAlgebra::ParseVector(w, dicom, Orthanc::DICOM_TAG_WINDOW_WIDTH) &&
34
a865c7992a87 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 33
diff changeset
67 c.size() > 0 &&
a865c7992a87 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 33
diff changeset
68 w.size() > 0)
0
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
69 {
338
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 328
diff changeset
70 hasDefaultWindow_ = true;
34
a865c7992a87 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 33
diff changeset
71 defaultWindowCenter_ = static_cast<float>(c[0]);
a865c7992a87 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 33
diff changeset
72 defaultWindowWidth_ = static_cast<float>(w[0]);
0
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
73 }
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
74
118
a4d0b6c82b29 using Orthanc::DicomMap instead of OrthancPlugins::DicomDatasetReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 113
diff changeset
75 int32_t tmp;
a4d0b6c82b29 using Orthanc::DicomMap instead of OrthancPlugins::DicomDatasetReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 113
diff changeset
76 if (!dicom.ParseInteger32(tmp, Orthanc::DICOM_TAG_PIXEL_REPRESENTATION))
0
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
77 {
32
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 16
diff changeset
78 // Type 1 tag, must be present
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 16
diff changeset
79 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 16
diff changeset
80 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 16
diff changeset
81
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 16
diff changeset
82 isSigned_ = (tmp == 1);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 16
diff changeset
83
119
ba83e38cf3ff rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 118
diff changeset
84 double doseGridScaling;
ba83e38cf3ff rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 118
diff changeset
85 bool isRTDose = false;
ba83e38cf3ff rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 118
diff changeset
86
ba83e38cf3ff rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 118
diff changeset
87 if (dicom.ParseDouble(rescaleIntercept_, Orthanc::DICOM_TAG_RESCALE_INTERCEPT) &&
ba83e38cf3ff rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 118
diff changeset
88 dicom.ParseDouble(rescaleSlope_, Orthanc::DICOM_TAG_RESCALE_SLOPE))
32
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 16
diff changeset
89 {
0
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
90 hasRescale_ = true;
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
91 }
119
ba83e38cf3ff rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 118
diff changeset
92 else if (dicom.ParseDouble(doseGridScaling, Orthanc::DICOM_TAG_DOSE_GRID_SCALING))
ba83e38cf3ff rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 118
diff changeset
93 {
ba83e38cf3ff rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 118
diff changeset
94 // This is for RT-DOSE
ba83e38cf3ff rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 118
diff changeset
95 hasRescale_ = true;
ba83e38cf3ff rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 118
diff changeset
96 isRTDose = true;
ba83e38cf3ff rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 118
diff changeset
97 rescaleIntercept_ = 0;
ba83e38cf3ff rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 118
diff changeset
98 rescaleSlope_ = doseGridScaling;
0
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
99
120
063f7f3d9f14 fix 3d locations of the doses
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 119
diff changeset
100 if (!dicom.ParseInteger32(tmp, Orthanc::DICOM_TAG_BITS_STORED))
063f7f3d9f14 fix 3d locations of the doses
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 119
diff changeset
101 {
063f7f3d9f14 fix 3d locations of the doses
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 119
diff changeset
102 // Type 1 tag, must be present
063f7f3d9f14 fix 3d locations of the doses
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 119
diff changeset
103 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat);
063f7f3d9f14 fix 3d locations of the doses
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 119
diff changeset
104 }
063f7f3d9f14 fix 3d locations of the doses
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 119
diff changeset
105
063f7f3d9f14 fix 3d locations of the doses
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 119
diff changeset
106 switch (tmp)
063f7f3d9f14 fix 3d locations of the doses
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 119
diff changeset
107 {
063f7f3d9f14 fix 3d locations of the doses
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 119
diff changeset
108 case 16:
063f7f3d9f14 fix 3d locations of the doses
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 119
diff changeset
109 expectedPixelFormat_ = Orthanc::PixelFormat_Grayscale16;
063f7f3d9f14 fix 3d locations of the doses
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 119
diff changeset
110 break;
063f7f3d9f14 fix 3d locations of the doses
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 119
diff changeset
111
063f7f3d9f14 fix 3d locations of the doses
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 119
diff changeset
112 case 32:
063f7f3d9f14 fix 3d locations of the doses
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 119
diff changeset
113 expectedPixelFormat_ = Orthanc::PixelFormat_Grayscale32;
063f7f3d9f14 fix 3d locations of the doses
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 119
diff changeset
114 break;
063f7f3d9f14 fix 3d locations of the doses
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 119
diff changeset
115
063f7f3d9f14 fix 3d locations of the doses
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 119
diff changeset
116 default:
063f7f3d9f14 fix 3d locations of the doses
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 119
diff changeset
117 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented);
063f7f3d9f14 fix 3d locations of the doses
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 119
diff changeset
118 }
119
ba83e38cf3ff rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 118
diff changeset
119 }
0
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
120
118
a4d0b6c82b29 using Orthanc::DicomMap instead of OrthancPlugins::DicomDatasetReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 113
diff changeset
121 std::string photometric;
a4d0b6c82b29 using Orthanc::DicomMap instead of OrthancPlugins::DicomDatasetReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 113
diff changeset
122 if (dicom.CopyToString(photometric, Orthanc::DICOM_TAG_PHOTOMETRIC_INTERPRETATION, false))
a4d0b6c82b29 using Orthanc::DicomMap instead of OrthancPlugins::DicomDatasetReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 113
diff changeset
123 {
a4d0b6c82b29 using Orthanc::DicomMap instead of OrthancPlugins::DicomDatasetReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 113
diff changeset
124 photometric = Orthanc::Toolbox::StripSpaces(photometric);
a4d0b6c82b29 using Orthanc::DicomMap instead of OrthancPlugins::DicomDatasetReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 113
diff changeset
125 }
a4d0b6c82b29 using Orthanc::DicomMap instead of OrthancPlugins::DicomDatasetReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 113
diff changeset
126 else
a4d0b6c82b29 using Orthanc::DicomMap instead of OrthancPlugins::DicomDatasetReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 113
diff changeset
127 {
a4d0b6c82b29 using Orthanc::DicomMap instead of OrthancPlugins::DicomDatasetReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 113
diff changeset
128 // Type 1 tag, must be present
a4d0b6c82b29 using Orthanc::DicomMap instead of OrthancPlugins::DicomDatasetReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 113
diff changeset
129 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat);
a4d0b6c82b29 using Orthanc::DicomMap instead of OrthancPlugins::DicomDatasetReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 113
diff changeset
130 }
328
c80b5bddf86b support of monochrome1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 212
diff changeset
131
c80b5bddf86b support of monochrome1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 212
diff changeset
132 photometric_ = Orthanc::StringToPhotometricInterpretation(photometric.c_str());
118
a4d0b6c82b29 using Orthanc::DicomMap instead of OrthancPlugins::DicomDatasetReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 113
diff changeset
133
0
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
134 isColor_ = (photometric != "MONOCHROME1" &&
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
135 photometric != "MONOCHROME2");
119
ba83e38cf3ff rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 118
diff changeset
136
ba83e38cf3ff rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 118
diff changeset
137 // TODO Add more checks, e.g. on the number of bytes per value
ba83e38cf3ff rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 118
diff changeset
138 // (cf. DicomImageInformation.h in Orthanc)
ba83e38cf3ff rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 118
diff changeset
139
120
063f7f3d9f14 fix 3d locations of the doses
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 119
diff changeset
140 if (!isRTDose)
119
ba83e38cf3ff rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 118
diff changeset
141 {
120
063f7f3d9f14 fix 3d locations of the doses
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 119
diff changeset
142 if (isColor_)
063f7f3d9f14 fix 3d locations of the doses
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 119
diff changeset
143 {
063f7f3d9f14 fix 3d locations of the doses
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 119
diff changeset
144 expectedPixelFormat_ = Orthanc::PixelFormat_RGB24;
063f7f3d9f14 fix 3d locations of the doses
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 119
diff changeset
145 }
063f7f3d9f14 fix 3d locations of the doses
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 119
diff changeset
146 else if (isSigned_)
063f7f3d9f14 fix 3d locations of the doses
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 119
diff changeset
147 {
063f7f3d9f14 fix 3d locations of the doses
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 119
diff changeset
148 expectedPixelFormat_ = Orthanc::PixelFormat_SignedGrayscale16;
063f7f3d9f14 fix 3d locations of the doses
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 119
diff changeset
149 }
063f7f3d9f14 fix 3d locations of the doses
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 119
diff changeset
150 else
063f7f3d9f14 fix 3d locations of the doses
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 119
diff changeset
151 {
063f7f3d9f14 fix 3d locations of the doses
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 119
diff changeset
152 expectedPixelFormat_ = Orthanc::PixelFormat_Grayscale16;
063f7f3d9f14 fix 3d locations of the doses
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 119
diff changeset
153 }
119
ba83e38cf3ff rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 118
diff changeset
154 }
0
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
155 }
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
156
338
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 328
diff changeset
157
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 328
diff changeset
158 void DicomFrameConverter::ReadParameters(const OrthancPlugins::IDicomDataset& dicom)
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 328
diff changeset
159 {
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 328
diff changeset
160 Orthanc::DicomMap converted;
0
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
161
338
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 328
diff changeset
162 for (size_t i = 0; i < sizeof(IMAGE_TAGS) / sizeof(Orthanc::DicomTag); i++)
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 328
diff changeset
163 {
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 328
diff changeset
164 OrthancPlugins::DicomTag tag(IMAGE_TAGS[i].GetGroup(), IMAGE_TAGS[i].GetElement());
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 328
diff changeset
165
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 328
diff changeset
166 std::string value;
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 328
diff changeset
167 if (dicom.GetStringValue(value, tag))
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 328
diff changeset
168 {
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 328
diff changeset
169 converted.SetValue(IMAGE_TAGS[i], value, false);
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 328
diff changeset
170 }
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 328
diff changeset
171 }
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 328
diff changeset
172
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 328
diff changeset
173 ReadParameters(converted);
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 328
diff changeset
174 }
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 328
diff changeset
175
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 328
diff changeset
176
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 328
diff changeset
177 void DicomFrameConverter::ConvertFrameInplace(std::auto_ptr<Orthanc::ImageAccessor>& source) const
0
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
178 {
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
179 assert(sizeof(float) == 4);
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
180
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
181 if (source.get() == NULL)
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
182 {
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
183 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange);
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
184 }
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
185
338
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 328
diff changeset
186 if (source->GetFormat() == GetExpectedPixelFormat() &&
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 328
diff changeset
187 source->GetFormat() == Orthanc::PixelFormat_RGB24)
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 328
diff changeset
188 {
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 328
diff changeset
189 // No conversion has to be done, check out (*)
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 328
diff changeset
190 return;
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 328
diff changeset
191 }
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 328
diff changeset
192 else
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 328
diff changeset
193 {
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 328
diff changeset
194 source.reset(ConvertFrame(*source));
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 328
diff changeset
195 }
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 328
diff changeset
196 }
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 328
diff changeset
197
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 328
diff changeset
198
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 328
diff changeset
199 Orthanc::ImageAccessor* DicomFrameConverter::ConvertFrame(const Orthanc::ImageAccessor& source) const
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 328
diff changeset
200 {
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 328
diff changeset
201 assert(sizeof(float) == 4);
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 328
diff changeset
202
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 328
diff changeset
203 Orthanc::PixelFormat sourceFormat = source.GetFormat();
0
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
204
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
205 if (sourceFormat != GetExpectedPixelFormat())
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
206 {
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
207 throw Orthanc::OrthancException(Orthanc::ErrorCode_IncompatibleImageFormat);
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
208 }
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
209
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
210 if (sourceFormat == Orthanc::PixelFormat_RGB24)
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
211 {
338
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 328
diff changeset
212 // This is the case of a color image. No conversion has to be done (*)
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 328
diff changeset
213 std::auto_ptr<Orthanc::Image> converted(new Orthanc::Image(Orthanc::PixelFormat_RGB24,
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 328
diff changeset
214 source.GetWidth(),
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 328
diff changeset
215 source.GetHeight(),
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 328
diff changeset
216 false));
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 328
diff changeset
217 Orthanc::ImageProcessing::Copy(*converted, source);
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 328
diff changeset
218 return converted.release();
0
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
219 }
338
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 328
diff changeset
220 else
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 328
diff changeset
221 {
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 328
diff changeset
222 assert(sourceFormat == Orthanc::PixelFormat_Grayscale16 ||
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 328
diff changeset
223 sourceFormat == Orthanc::PixelFormat_Grayscale32 ||
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 328
diff changeset
224 sourceFormat == Orthanc::PixelFormat_SignedGrayscale16);
0
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
225
338
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 328
diff changeset
226 // This is the case of a grayscale frame. Convert it to Float32.
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 328
diff changeset
227 std::auto_ptr<Orthanc::Image> converted(new Orthanc::Image(Orthanc::PixelFormat_Float32,
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 328
diff changeset
228 source.GetWidth(),
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 328
diff changeset
229 source.GetHeight(),
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 328
diff changeset
230 false));
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 328
diff changeset
231 Orthanc::ImageProcessing::Convert(*converted, source);
0
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
232
338
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 328
diff changeset
233 // Correct rescale slope/intercept if need be
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 328
diff changeset
234 ApplyRescale(*converted, sourceFormat != Orthanc::PixelFormat_Grayscale32);
119
ba83e38cf3ff rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 118
diff changeset
235
338
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 328
diff changeset
236 return converted.release();
b3b3fa0e3689 BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 328
diff changeset
237 }
119
ba83e38cf3ff rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 118
diff changeset
238 }
ba83e38cf3ff rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 118
diff changeset
239
ba83e38cf3ff rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 118
diff changeset
240
ba83e38cf3ff rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 118
diff changeset
241 void DicomFrameConverter::ApplyRescale(Orthanc::ImageAccessor& image,
ba83e38cf3ff rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 118
diff changeset
242 bool useDouble) const
ba83e38cf3ff rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 118
diff changeset
243 {
ba83e38cf3ff rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 118
diff changeset
244 if (image.GetFormat() != Orthanc::PixelFormat_Float32)
ba83e38cf3ff rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 118
diff changeset
245 {
ba83e38cf3ff rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 118
diff changeset
246 throw Orthanc::OrthancException(Orthanc::ErrorCode_IncompatibleImageFormat);
ba83e38cf3ff rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 118
diff changeset
247 }
ba83e38cf3ff rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 118
diff changeset
248
0
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
249 if (hasRescale_)
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
250 {
119
ba83e38cf3ff rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 118
diff changeset
251 for (unsigned int y = 0; y < image.GetHeight(); y++)
0
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
252 {
119
ba83e38cf3ff rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 118
diff changeset
253 float* p = reinterpret_cast<float*>(image.GetRow(y));
0
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
254
119
ba83e38cf3ff rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 118
diff changeset
255 if (useDouble)
ba83e38cf3ff rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 118
diff changeset
256 {
ba83e38cf3ff rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 118
diff changeset
257 // Slower, accurate implementation using double
ba83e38cf3ff rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 118
diff changeset
258 for (unsigned int x = 0; x < image.GetWidth(); x++, p++)
0
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
259 {
119
ba83e38cf3ff rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 118
diff changeset
260 double value = static_cast<double>(*p);
ba83e38cf3ff rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 118
diff changeset
261 *p = static_cast<float>(value * rescaleSlope_ + rescaleIntercept_);
0
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
262 }
119
ba83e38cf3ff rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 118
diff changeset
263 }
ba83e38cf3ff rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 118
diff changeset
264 else
ba83e38cf3ff rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 118
diff changeset
265 {
ba83e38cf3ff rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 118
diff changeset
266 // Fast, approximate implementation using float
ba83e38cf3ff rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 118
diff changeset
267 for (unsigned int x = 0; x < image.GetWidth(); x++, p++)
ba83e38cf3ff rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 118
diff changeset
268 {
ba83e38cf3ff rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 118
diff changeset
269 *p = (*p) * static_cast<float>(rescaleSlope_) + static_cast<float>(rescaleIntercept_);
ba83e38cf3ff rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 118
diff changeset
270 }
0
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
271 }
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
272 }
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
273 }
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
274 }
119
ba83e38cf3ff rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 118
diff changeset
275
ba83e38cf3ff rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 118
diff changeset
276
ba83e38cf3ff rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 118
diff changeset
277 double DicomFrameConverter::Apply(double x) const
ba83e38cf3ff rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 118
diff changeset
278 {
ba83e38cf3ff rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 118
diff changeset
279 return x * rescaleSlope_ + rescaleIntercept_;
ba83e38cf3ff rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 118
diff changeset
280 }
ba83e38cf3ff rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 118
diff changeset
281
0
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
282 }