Mercurial > hg > orthanc-stone
annotate Framework/Radiography/RadiographyDicomLayer.cpp @ 1145:4f99c7905f8d broker
mingw qt
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 12 Nov 2019 18:28:46 +0100 |
parents | d7e06542304c |
children | 54cbffabdc45 |
rev | line source |
---|---|
430 | 1 /** |
2 * Stone of Orthanc | |
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics | |
4 * Department, University Hospital of Liege, Belgium | |
5 * Copyright (C) 2017-2018 Osimis S.A., Belgium | |
6 * | |
7 * This program is free software: you can redistribute it and/or | |
8 * modify it under the terms of the GNU Affero General Public License | |
9 * as published by the Free Software Foundation, either version 3 of | |
10 * the License, or (at your option) any later version. | |
11 * | |
12 * This program is distributed in the hope that it will be useful, but | |
13 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
15 * Affero General Public License for more details. | |
16 * | |
17 * You should have received a copy of the GNU Affero General Public License | |
18 * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
19 **/ | |
20 | |
21 | |
22 #include "RadiographyDicomLayer.h" | |
23 | |
24 #include "RadiographyScene.h" | |
732
c35e98d22764
move Deprecated classes to a separate folder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
714
diff
changeset
|
25 #include "../Deprecated/Toolbox/DicomFrameConverter.h" |
430 | 26 |
27 #include <Core/OrthancException.h> | |
28 #include <Core/Images/Image.h> | |
29 #include <Core/Images/ImageProcessing.h> | |
30 #include <Plugins/Samples/Common/DicomDatasetReader.h> | |
31 | |
32 static OrthancPlugins::DicomTag ConvertTag(const Orthanc::DicomTag& tag) | |
33 { | |
34 return OrthancPlugins::DicomTag(tag.GetGroup(), tag.GetElement()); | |
35 } | |
36 | |
37 namespace OrthancStone | |
38 { | |
39 | |
40 void RadiographyDicomLayer::ApplyConverter() | |
41 { | |
42 if (source_.get() != NULL && | |
43 converter_.get() != NULL) | |
44 { | |
45 converted_.reset(converter_->ConvertFrame(*source_)); | |
46 } | |
47 } | |
48 | |
49 | |
1066
b537002f83a9
removing broker from deprecated classes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
739
diff
changeset
|
50 RadiographyDicomLayer::RadiographyDicomLayer(const RadiographyScene& scene) : |
b537002f83a9
removing broker from deprecated classes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
739
diff
changeset
|
51 RadiographyLayer(scene) |
655
1e26bb5f2a02
Fixed truncating conversion warnings + fixed deletion of incomplete type
Benjamin Golinvaux <bgo@osimis.io>
parents:
649
diff
changeset
|
52 { |
1e26bb5f2a02
Fixed truncating conversion warnings + fixed deletion of incomplete type
Benjamin Golinvaux <bgo@osimis.io>
parents:
649
diff
changeset
|
53 |
1e26bb5f2a02
Fixed truncating conversion warnings + fixed deletion of incomplete type
Benjamin Golinvaux <bgo@osimis.io>
parents:
649
diff
changeset
|
54 } |
1e26bb5f2a02
Fixed truncating conversion warnings + fixed deletion of incomplete type
Benjamin Golinvaux <bgo@osimis.io>
parents:
649
diff
changeset
|
55 |
430 | 56 void RadiographyDicomLayer::SetDicomTags(const OrthancPlugins::FullOrthancDataset& dataset) |
57 { | |
714
d2c0e347ddc2
deprecating DicomFrameConverter
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
655
diff
changeset
|
58 converter_.reset(new Deprecated::DicomFrameConverter); |
430 | 59 converter_->ReadParameters(dataset); |
60 ApplyConverter(); | |
61 | |
62 std::string tmp; | |
63 Vector pixelSpacing; | |
64 | |
65 if (dataset.GetStringValue(tmp, ConvertTag(Orthanc::DICOM_TAG_PIXEL_SPACING)) && | |
66 LinearAlgebra::ParseVector(pixelSpacing, tmp) && | |
67 pixelSpacing.size() == 2) | |
68 { | |
69 SetPixelSpacing(pixelSpacing[0], pixelSpacing[1]); | |
70 } | |
71 | |
72 OrthancPlugins::DicomDatasetReader reader(dataset); | |
73 | |
74 unsigned int width, height; | |
75 if (!reader.GetUnsignedIntegerValue(width, ConvertTag(Orthanc::DICOM_TAG_COLUMNS)) || | |
76 !reader.GetUnsignedIntegerValue(height, ConvertTag(Orthanc::DICOM_TAG_ROWS))) | |
77 { | |
78 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat); | |
79 } | |
80 else | |
81 { | |
82 SetSize(width, height); | |
83 } | |
432
4eb96c6b4e96
improved handling of MONOCHROME1, background and invertion
am@osimis.io
parents:
430
diff
changeset
|
84 |
4eb96c6b4e96
improved handling of MONOCHROME1, background and invertion
am@osimis.io
parents:
430
diff
changeset
|
85 if (dataset.GetStringValue(tmp, ConvertTag(Orthanc::DICOM_TAG_PHOTOMETRIC_INTERPRETATION))) |
4eb96c6b4e96
improved handling of MONOCHROME1, background and invertion
am@osimis.io
parents:
430
diff
changeset
|
86 { |
4eb96c6b4e96
improved handling of MONOCHROME1, background and invertion
am@osimis.io
parents:
430
diff
changeset
|
87 if (tmp == "MONOCHROME1") |
4eb96c6b4e96
improved handling of MONOCHROME1, background and invertion
am@osimis.io
parents:
430
diff
changeset
|
88 { |
739
be9c1530d40a
deprecating enum SliceImageQuality
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
732
diff
changeset
|
89 SetPreferredPhotomotricDisplayMode(RadiographyPhotometricDisplayMode_Monochrome1); |
432
4eb96c6b4e96
improved handling of MONOCHROME1, background and invertion
am@osimis.io
parents:
430
diff
changeset
|
90 } |
4eb96c6b4e96
improved handling of MONOCHROME1, background and invertion
am@osimis.io
parents:
430
diff
changeset
|
91 else if (tmp == "MONOCHROME2") |
4eb96c6b4e96
improved handling of MONOCHROME1, background and invertion
am@osimis.io
parents:
430
diff
changeset
|
92 { |
739
be9c1530d40a
deprecating enum SliceImageQuality
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
732
diff
changeset
|
93 SetPreferredPhotomotricDisplayMode(RadiographyPhotometricDisplayMode_Monochrome2); |
432
4eb96c6b4e96
improved handling of MONOCHROME1, background and invertion
am@osimis.io
parents:
430
diff
changeset
|
94 } |
4eb96c6b4e96
improved handling of MONOCHROME1, background and invertion
am@osimis.io
parents:
430
diff
changeset
|
95 } |
430 | 96 } |
97 | |
98 void RadiographyDicomLayer::SetSourceImage(Orthanc::ImageAccessor* image) // Takes ownership | |
99 { | |
100 std::auto_ptr<Orthanc::ImageAccessor> raii(image); | |
101 | |
102 if (image == NULL) | |
103 { | |
104 throw Orthanc::OrthancException(Orthanc::ErrorCode_NullPointer); | |
105 } | |
106 | |
107 SetSize(image->GetWidth(), image->GetHeight()); | |
108 | |
109 source_ = raii; | |
110 ApplyConverter(); | |
503
77e0eb83ff63
layers are now Observable and emitting LayerEdited messages
amazy
parents:
432
diff
changeset
|
111 |
623
42dadae61fa9
renamed IObservable::EmitMessage() as BroadcastMessage()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
503
diff
changeset
|
112 BroadcastMessage(RadiographyLayer::LayerEditedMessage(*this)); |
430 | 113 } |
114 | |
1118
35e798b16b65
RadiographyDicomLayer: allow replacing low res image by high res image
Alain Mazy <alain@mazy.be>
parents:
739
diff
changeset
|
115 void RadiographyDicomLayer::SetSourceImage(Orthanc::ImageAccessor* image, double newPixelSpacingX, double newPixelSpacingY) // Takes ownership |
35e798b16b65
RadiographyDicomLayer: allow replacing low res image by high res image
Alain Mazy <alain@mazy.be>
parents:
739
diff
changeset
|
116 { |
35e798b16b65
RadiographyDicomLayer: allow replacing low res image by high res image
Alain Mazy <alain@mazy.be>
parents:
739
diff
changeset
|
117 std::auto_ptr<Orthanc::ImageAccessor> raii(image); |
35e798b16b65
RadiographyDicomLayer: allow replacing low res image by high res image
Alain Mazy <alain@mazy.be>
parents:
739
diff
changeset
|
118 |
35e798b16b65
RadiographyDicomLayer: allow replacing low res image by high res image
Alain Mazy <alain@mazy.be>
parents:
739
diff
changeset
|
119 if (image == NULL) |
35e798b16b65
RadiographyDicomLayer: allow replacing low res image by high res image
Alain Mazy <alain@mazy.be>
parents:
739
diff
changeset
|
120 { |
35e798b16b65
RadiographyDicomLayer: allow replacing low res image by high res image
Alain Mazy <alain@mazy.be>
parents:
739
diff
changeset
|
121 throw Orthanc::OrthancException(Orthanc::ErrorCode_NullPointer); |
35e798b16b65
RadiographyDicomLayer: allow replacing low res image by high res image
Alain Mazy <alain@mazy.be>
parents:
739
diff
changeset
|
122 } |
35e798b16b65
RadiographyDicomLayer: allow replacing low res image by high res image
Alain Mazy <alain@mazy.be>
parents:
739
diff
changeset
|
123 |
35e798b16b65
RadiographyDicomLayer: allow replacing low res image by high res image
Alain Mazy <alain@mazy.be>
parents:
739
diff
changeset
|
124 SetSize(image->GetWidth(), image->GetHeight()); |
35e798b16b65
RadiographyDicomLayer: allow replacing low res image by high res image
Alain Mazy <alain@mazy.be>
parents:
739
diff
changeset
|
125 |
35e798b16b65
RadiographyDicomLayer: allow replacing low res image by high res image
Alain Mazy <alain@mazy.be>
parents:
739
diff
changeset
|
126 source_ = raii; |
35e798b16b65
RadiographyDicomLayer: allow replacing low res image by high res image
Alain Mazy <alain@mazy.be>
parents:
739
diff
changeset
|
127 ApplyConverter(); |
35e798b16b65
RadiographyDicomLayer: allow replacing low res image by high res image
Alain Mazy <alain@mazy.be>
parents:
739
diff
changeset
|
128 |
35e798b16b65
RadiographyDicomLayer: allow replacing low res image by high res image
Alain Mazy <alain@mazy.be>
parents:
739
diff
changeset
|
129 SetPixelSpacing(newPixelSpacingX, newPixelSpacingY, false); |
35e798b16b65
RadiographyDicomLayer: allow replacing low res image by high res image
Alain Mazy <alain@mazy.be>
parents:
739
diff
changeset
|
130 |
35e798b16b65
RadiographyDicomLayer: allow replacing low res image by high res image
Alain Mazy <alain@mazy.be>
parents:
739
diff
changeset
|
131 BroadcastMessage(RadiographyLayer::LayerEditedMessage(*this)); |
35e798b16b65
RadiographyDicomLayer: allow replacing low res image by high res image
Alain Mazy <alain@mazy.be>
parents:
739
diff
changeset
|
132 } |
35e798b16b65
RadiographyDicomLayer: allow replacing low res image by high res image
Alain Mazy <alain@mazy.be>
parents:
739
diff
changeset
|
133 |
649
f1bfe3d1759f
Moved RadiographyDicomLayer::SetDicomFrameConverter to cpp file to prevent
Benjamin Golinvaux <bgo@osimis.io>
parents:
623
diff
changeset
|
134 |
714
d2c0e347ddc2
deprecating DicomFrameConverter
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
655
diff
changeset
|
135 void RadiographyDicomLayer::SetDicomFrameConverter(Deprecated::DicomFrameConverter* converter) |
649
f1bfe3d1759f
Moved RadiographyDicomLayer::SetDicomFrameConverter to cpp file to prevent
Benjamin Golinvaux <bgo@osimis.io>
parents:
623
diff
changeset
|
136 { |
f1bfe3d1759f
Moved RadiographyDicomLayer::SetDicomFrameConverter to cpp file to prevent
Benjamin Golinvaux <bgo@osimis.io>
parents:
623
diff
changeset
|
137 converter_.reset(converter); |
f1bfe3d1759f
Moved RadiographyDicomLayer::SetDicomFrameConverter to cpp file to prevent
Benjamin Golinvaux <bgo@osimis.io>
parents:
623
diff
changeset
|
138 } |
f1bfe3d1759f
Moved RadiographyDicomLayer::SetDicomFrameConverter to cpp file to prevent
Benjamin Golinvaux <bgo@osimis.io>
parents:
623
diff
changeset
|
139 |
430 | 140 void RadiographyDicomLayer::Render(Orthanc::ImageAccessor& buffer, |
141 const AffineTransform2D& viewTransform, | |
142 ImageInterpolation interpolation) const | |
143 { | |
144 if (converted_.get() != NULL) | |
145 { | |
146 if (converted_->GetFormat() != Orthanc::PixelFormat_Float32) | |
147 { | |
148 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); | |
149 } | |
150 | |
151 unsigned int cropX, cropY, cropWidth, cropHeight; | |
152 GetCrop(cropX, cropY, cropWidth, cropHeight); | |
153 | |
154 AffineTransform2D t = AffineTransform2D::Combine( | |
155 viewTransform, GetTransform(), | |
156 AffineTransform2D::CreateOffset(cropX, cropY)); | |
157 | |
158 Orthanc::ImageAccessor cropped; | |
159 converted_->GetRegion(cropped, cropX, cropY, cropWidth, cropHeight); | |
160 | |
161 t.Apply(buffer, cropped, interpolation, false); | |
162 } | |
163 } | |
164 | |
165 | |
166 bool RadiographyDicomLayer::GetDefaultWindowing(float& center, | |
167 float& width) const | |
168 { | |
169 if (converter_.get() != NULL && | |
170 converter_->HasDefaultWindow()) | |
171 { | |
172 center = static_cast<float>(converter_->GetDefaultWindowCenter()); | |
173 width = static_cast<float>(converter_->GetDefaultWindowWidth()); | |
174 return true; | |
175 } | |
176 else | |
177 { | |
178 return false; | |
179 } | |
180 } | |
181 | |
182 | |
183 bool RadiographyDicomLayer::GetRange(float& minValue, | |
184 float& maxValue) const | |
185 { | |
186 if (converted_.get() != NULL) | |
187 { | |
188 if (converted_->GetFormat() != Orthanc::PixelFormat_Float32) | |
189 { | |
190 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); | |
191 } | |
192 | |
193 Orthanc::ImageProcessing::GetMinMaxFloatValue(minValue, maxValue, *converted_); | |
194 return true; | |
195 } | |
196 else | |
197 { | |
198 return false; | |
199 } | |
200 } | |
201 | |
202 } |