annotate Framework/Radiography/RadiographyDicomLayer.cpp @ 629:8d66efecd91c am-dev

rename
author Alain Mazy <alain@mazy.be>
date Wed, 08 May 2019 16:38:25 +0200
parents 77e0eb83ff63
children 42dadae61fa9
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
430
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
1 /**
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
2 * Stone of Orthanc
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
4 * Department, University Hospital of Liege, Belgium
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
5 * Copyright (C) 2017-2018 Osimis S.A., Belgium
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
6 *
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
7 * This program is free software: you can redistribute it and/or
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
8 * modify it under the terms of the GNU Affero General Public License
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
9 * as published by the Free Software Foundation, either version 3 of
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
10 * the License, or (at your option) any later version.
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
11 *
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
12 * This program is distributed in the hope that it will be useful, but
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
15 * Affero General Public License for more details.
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
16 *
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
17 * You should have received a copy of the GNU Affero General Public License
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
19 **/
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
20
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
21
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
22 #include "RadiographyDicomLayer.h"
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
23
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
24 #include "RadiographyScene.h"
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
25 #include "../Toolbox/DicomFrameConverter.h"
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
26
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
27 #include <Core/OrthancException.h>
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
28 #include <Core/Images/Image.h>
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
29 #include <Core/Images/ImageProcessing.h>
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
30 #include <Plugins/Samples/Common/DicomDatasetReader.h>
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
31
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
32 static OrthancPlugins::DicomTag ConvertTag(const Orthanc::DicomTag& tag)
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
33 {
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
34 return OrthancPlugins::DicomTag(tag.GetGroup(), tag.GetElement());
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
35 }
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
36
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
37 namespace OrthancStone
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
38 {
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
39
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
40 void RadiographyDicomLayer::ApplyConverter()
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
41 {
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
42 if (source_.get() != NULL &&
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
43 converter_.get() != NULL)
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
44 {
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
45 converted_.reset(converter_->ConvertFrame(*source_));
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
46 }
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
47 }
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
48
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
49
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
50 void RadiographyDicomLayer::SetDicomTags(const OrthancPlugins::FullOrthancDataset& dataset)
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
51 {
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
52 converter_.reset(new DicomFrameConverter);
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
53 converter_->ReadParameters(dataset);
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
54 ApplyConverter();
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
55
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
56 std::string tmp;
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
57 Vector pixelSpacing;
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
58
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
59 if (dataset.GetStringValue(tmp, ConvertTag(Orthanc::DICOM_TAG_PIXEL_SPACING)) &&
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
60 LinearAlgebra::ParseVector(pixelSpacing, tmp) &&
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
61 pixelSpacing.size() == 2)
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
62 {
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
63 SetPixelSpacing(pixelSpacing[0], pixelSpacing[1]);
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
64 }
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
65
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
66 OrthancPlugins::DicomDatasetReader reader(dataset);
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
67
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
68 unsigned int width, height;
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
69 if (!reader.GetUnsignedIntegerValue(width, ConvertTag(Orthanc::DICOM_TAG_COLUMNS)) ||
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
70 !reader.GetUnsignedIntegerValue(height, ConvertTag(Orthanc::DICOM_TAG_ROWS)))
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
71 {
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
72 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat);
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
73 }
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
74 else
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
75 {
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
76 SetSize(width, height);
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
77 }
432
4eb96c6b4e96 improved handling of MONOCHROME1, background and invertion
am@osimis.io
parents: 430
diff changeset
78
4eb96c6b4e96 improved handling of MONOCHROME1, background and invertion
am@osimis.io
parents: 430
diff changeset
79 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
80 {
4eb96c6b4e96 improved handling of MONOCHROME1, background and invertion
am@osimis.io
parents: 430
diff changeset
81 if (tmp == "MONOCHROME1")
4eb96c6b4e96 improved handling of MONOCHROME1, background and invertion
am@osimis.io
parents: 430
diff changeset
82 {
4eb96c6b4e96 improved handling of MONOCHROME1, background and invertion
am@osimis.io
parents: 430
diff changeset
83 SetPreferredPhotomotricDisplayMode(PhotometricDisplayMode_Monochrome1);
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 else if (tmp == "MONOCHROME2")
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 SetPreferredPhotomotricDisplayMode(PhotometricDisplayMode_Monochrome2);
4eb96c6b4e96 improved handling of MONOCHROME1, background and invertion
am@osimis.io
parents: 430
diff changeset
88 }
4eb96c6b4e96 improved handling of MONOCHROME1, background and invertion
am@osimis.io
parents: 430
diff changeset
89 }
430
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
90 }
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
91
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
92 void RadiographyDicomLayer::SetSourceImage(Orthanc::ImageAccessor* image) // Takes ownership
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
93 {
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
94 std::auto_ptr<Orthanc::ImageAccessor> raii(image);
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
95
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
96 if (image == NULL)
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
97 {
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
98 throw Orthanc::OrthancException(Orthanc::ErrorCode_NullPointer);
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
99 }
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
100
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
101 SetSize(image->GetWidth(), image->GetHeight());
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
102
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
103 source_ = raii;
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
104 ApplyConverter();
503
77e0eb83ff63 layers are now Observable and emitting LayerEdited messages
amazy
parents: 432
diff changeset
105
77e0eb83ff63 layers are now Observable and emitting LayerEdited messages
amazy
parents: 432
diff changeset
106 EmitMessage(RadiographyLayer::LayerEditedMessage(*this));
430
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
107 }
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
108
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
109 void RadiographyDicomLayer::Render(Orthanc::ImageAccessor& buffer,
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
110 const AffineTransform2D& viewTransform,
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
111 ImageInterpolation interpolation) const
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
112 {
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
113 if (converted_.get() != NULL)
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
114 {
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
115 if (converted_->GetFormat() != Orthanc::PixelFormat_Float32)
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
116 {
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
117 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError);
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
118 }
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
119
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
120 unsigned int cropX, cropY, cropWidth, cropHeight;
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
121 GetCrop(cropX, cropY, cropWidth, cropHeight);
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
122
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
123 AffineTransform2D t = AffineTransform2D::Combine(
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
124 viewTransform, GetTransform(),
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
125 AffineTransform2D::CreateOffset(cropX, cropY));
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
126
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
127 Orthanc::ImageAccessor cropped;
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
128 converted_->GetRegion(cropped, cropX, cropY, cropWidth, cropHeight);
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
129
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
130 t.Apply(buffer, cropped, interpolation, false);
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
131 }
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
132 }
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
133
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
134
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
135 bool RadiographyDicomLayer::GetDefaultWindowing(float& center,
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
136 float& width) const
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
137 {
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
138 if (converter_.get() != NULL &&
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
139 converter_->HasDefaultWindow())
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
140 {
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
141 center = static_cast<float>(converter_->GetDefaultWindowCenter());
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
142 width = static_cast<float>(converter_->GetDefaultWindowWidth());
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
143 return true;
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
144 }
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
145 else
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
146 {
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
147 return false;
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
148 }
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
149 }
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
150
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
151
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
152 bool RadiographyDicomLayer::GetRange(float& minValue,
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
153 float& maxValue) const
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
154 {
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
155 if (converted_.get() != NULL)
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
156 {
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
157 if (converted_->GetFormat() != Orthanc::PixelFormat_Float32)
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
158 {
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
159 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError);
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
160 }
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
161
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
162 Orthanc::ImageProcessing::GetMinMaxFloatValue(minValue, maxValue, *converted_);
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
163 return true;
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
164 }
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
165 else
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
166 {
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
167 return false;
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
168 }
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
169 }
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
170
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
171 }