Mercurial > hg > orthanc-stone
annotate Framework/Radiography/RadiographyDicomLayer.cpp @ 1036:d7d3227c11a9
merge
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Mon, 07 Oct 2019 15:26:29 +0200 |
parents | be9c1530d40a |
children | b537002f83a9 35e798b16b65 |
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 | |
655
1e26bb5f2a02
Fixed truncating conversion warnings + fixed deletion of incomplete type
Benjamin Golinvaux <bgo@osimis.io>
parents:
649
diff
changeset
|
50 RadiographyDicomLayer::RadiographyDicomLayer(MessageBroker& broker, const RadiographyScene& scene) : RadiographyLayer(broker, scene) |
1e26bb5f2a02
Fixed truncating conversion warnings + fixed deletion of incomplete type
Benjamin Golinvaux <bgo@osimis.io>
parents:
649
diff
changeset
|
51 { |
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 |
430 | 55 void RadiographyDicomLayer::SetDicomTags(const OrthancPlugins::FullOrthancDataset& dataset) |
56 { | |
714
d2c0e347ddc2
deprecating DicomFrameConverter
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
655
diff
changeset
|
57 converter_.reset(new Deprecated::DicomFrameConverter); |
430 | 58 converter_->ReadParameters(dataset); |
59 ApplyConverter(); | |
60 | |
61 std::string tmp; | |
62 Vector pixelSpacing; | |
63 | |
64 if (dataset.GetStringValue(tmp, ConvertTag(Orthanc::DICOM_TAG_PIXEL_SPACING)) && | |
65 LinearAlgebra::ParseVector(pixelSpacing, tmp) && | |
66 pixelSpacing.size() == 2) | |
67 { | |
68 SetPixelSpacing(pixelSpacing[0], pixelSpacing[1]); | |
69 } | |
70 | |
71 OrthancPlugins::DicomDatasetReader reader(dataset); | |
72 | |
73 unsigned int width, height; | |
74 if (!reader.GetUnsignedIntegerValue(width, ConvertTag(Orthanc::DICOM_TAG_COLUMNS)) || | |
75 !reader.GetUnsignedIntegerValue(height, ConvertTag(Orthanc::DICOM_TAG_ROWS))) | |
76 { | |
77 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat); | |
78 } | |
79 else | |
80 { | |
81 SetSize(width, height); | |
82 } | |
432
4eb96c6b4e96
improved handling of MONOCHROME1, background and invertion
am@osimis.io
parents:
430
diff
changeset
|
83 |
4eb96c6b4e96
improved handling of MONOCHROME1, background and invertion
am@osimis.io
parents:
430
diff
changeset
|
84 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
|
85 { |
4eb96c6b4e96
improved handling of MONOCHROME1, background and invertion
am@osimis.io
parents:
430
diff
changeset
|
86 if (tmp == "MONOCHROME1") |
4eb96c6b4e96
improved handling of MONOCHROME1, background and invertion
am@osimis.io
parents:
430
diff
changeset
|
87 { |
739
be9c1530d40a
deprecating enum SliceImageQuality
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
732
diff
changeset
|
88 SetPreferredPhotomotricDisplayMode(RadiographyPhotometricDisplayMode_Monochrome1); |
432
4eb96c6b4e96
improved handling of MONOCHROME1, background and invertion
am@osimis.io
parents:
430
diff
changeset
|
89 } |
4eb96c6b4e96
improved handling of MONOCHROME1, background and invertion
am@osimis.io
parents:
430
diff
changeset
|
90 else if (tmp == "MONOCHROME2") |
4eb96c6b4e96
improved handling of MONOCHROME1, background and invertion
am@osimis.io
parents:
430
diff
changeset
|
91 { |
739
be9c1530d40a
deprecating enum SliceImageQuality
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
732
diff
changeset
|
92 SetPreferredPhotomotricDisplayMode(RadiographyPhotometricDisplayMode_Monochrome2); |
432
4eb96c6b4e96
improved handling of MONOCHROME1, background and invertion
am@osimis.io
parents:
430
diff
changeset
|
93 } |
4eb96c6b4e96
improved handling of MONOCHROME1, background and invertion
am@osimis.io
parents:
430
diff
changeset
|
94 } |
430 | 95 } |
96 | |
97 void RadiographyDicomLayer::SetSourceImage(Orthanc::ImageAccessor* image) // Takes ownership | |
98 { | |
99 std::auto_ptr<Orthanc::ImageAccessor> raii(image); | |
100 | |
101 if (image == NULL) | |
102 { | |
103 throw Orthanc::OrthancException(Orthanc::ErrorCode_NullPointer); | |
104 } | |
105 | |
106 SetSize(image->GetWidth(), image->GetHeight()); | |
107 | |
108 source_ = raii; | |
109 ApplyConverter(); | |
503
77e0eb83ff63
layers are now Observable and emitting LayerEdited messages
amazy
parents:
432
diff
changeset
|
110 |
623
42dadae61fa9
renamed IObservable::EmitMessage() as BroadcastMessage()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
503
diff
changeset
|
111 BroadcastMessage(RadiographyLayer::LayerEditedMessage(*this)); |
430 | 112 } |
113 | |
649
f1bfe3d1759f
Moved RadiographyDicomLayer::SetDicomFrameConverter to cpp file to prevent
Benjamin Golinvaux <bgo@osimis.io>
parents:
623
diff
changeset
|
114 |
714
d2c0e347ddc2
deprecating DicomFrameConverter
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
655
diff
changeset
|
115 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
|
116 { |
f1bfe3d1759f
Moved RadiographyDicomLayer::SetDicomFrameConverter to cpp file to prevent
Benjamin Golinvaux <bgo@osimis.io>
parents:
623
diff
changeset
|
117 converter_.reset(converter); |
f1bfe3d1759f
Moved RadiographyDicomLayer::SetDicomFrameConverter to cpp file to prevent
Benjamin Golinvaux <bgo@osimis.io>
parents:
623
diff
changeset
|
118 } |
f1bfe3d1759f
Moved RadiographyDicomLayer::SetDicomFrameConverter to cpp file to prevent
Benjamin Golinvaux <bgo@osimis.io>
parents:
623
diff
changeset
|
119 |
430 | 120 void RadiographyDicomLayer::Render(Orthanc::ImageAccessor& buffer, |
121 const AffineTransform2D& viewTransform, | |
122 ImageInterpolation interpolation) const | |
123 { | |
124 if (converted_.get() != NULL) | |
125 { | |
126 if (converted_->GetFormat() != Orthanc::PixelFormat_Float32) | |
127 { | |
128 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); | |
129 } | |
130 | |
131 unsigned int cropX, cropY, cropWidth, cropHeight; | |
132 GetCrop(cropX, cropY, cropWidth, cropHeight); | |
133 | |
134 AffineTransform2D t = AffineTransform2D::Combine( | |
135 viewTransform, GetTransform(), | |
136 AffineTransform2D::CreateOffset(cropX, cropY)); | |
137 | |
138 Orthanc::ImageAccessor cropped; | |
139 converted_->GetRegion(cropped, cropX, cropY, cropWidth, cropHeight); | |
140 | |
141 t.Apply(buffer, cropped, interpolation, false); | |
142 } | |
143 } | |
144 | |
145 | |
146 bool RadiographyDicomLayer::GetDefaultWindowing(float& center, | |
147 float& width) const | |
148 { | |
149 if (converter_.get() != NULL && | |
150 converter_->HasDefaultWindow()) | |
151 { | |
152 center = static_cast<float>(converter_->GetDefaultWindowCenter()); | |
153 width = static_cast<float>(converter_->GetDefaultWindowWidth()); | |
154 return true; | |
155 } | |
156 else | |
157 { | |
158 return false; | |
159 } | |
160 } | |
161 | |
162 | |
163 bool RadiographyDicomLayer::GetRange(float& minValue, | |
164 float& maxValue) const | |
165 { | |
166 if (converted_.get() != NULL) | |
167 { | |
168 if (converted_->GetFormat() != Orthanc::PixelFormat_Float32) | |
169 { | |
170 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); | |
171 } | |
172 | |
173 Orthanc::ImageProcessing::GetMinMaxFloatValue(minValue, maxValue, *converted_); | |
174 return true; | |
175 } | |
176 else | |
177 { | |
178 return false; | |
179 } | |
180 } | |
181 | |
182 } |