Mercurial > hg > orthanc-stone
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 |
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" | |
25 #include "../Toolbox/DicomFrameConverter.h" | |
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 | |
50 void RadiographyDicomLayer::SetDicomTags(const OrthancPlugins::FullOrthancDataset& dataset) | |
51 { | |
52 converter_.reset(new DicomFrameConverter); | |
53 converter_->ReadParameters(dataset); | |
54 ApplyConverter(); | |
55 | |
56 std::string tmp; | |
57 Vector pixelSpacing; | |
58 | |
59 if (dataset.GetStringValue(tmp, ConvertTag(Orthanc::DICOM_TAG_PIXEL_SPACING)) && | |
60 LinearAlgebra::ParseVector(pixelSpacing, tmp) && | |
61 pixelSpacing.size() == 2) | |
62 { | |
63 SetPixelSpacing(pixelSpacing[0], pixelSpacing[1]); | |
64 } | |
65 | |
66 OrthancPlugins::DicomDatasetReader reader(dataset); | |
67 | |
68 unsigned int width, height; | |
69 if (!reader.GetUnsignedIntegerValue(width, ConvertTag(Orthanc::DICOM_TAG_COLUMNS)) || | |
70 !reader.GetUnsignedIntegerValue(height, ConvertTag(Orthanc::DICOM_TAG_ROWS))) | |
71 { | |
72 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat); | |
73 } | |
74 else | |
75 { | |
76 SetSize(width, height); | |
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 | 90 } |
91 | |
92 void RadiographyDicomLayer::SetSourceImage(Orthanc::ImageAccessor* image) // Takes ownership | |
93 { | |
94 std::auto_ptr<Orthanc::ImageAccessor> raii(image); | |
95 | |
96 if (image == NULL) | |
97 { | |
98 throw Orthanc::OrthancException(Orthanc::ErrorCode_NullPointer); | |
99 } | |
100 | |
101 SetSize(image->GetWidth(), image->GetHeight()); | |
102 | |
103 source_ = raii; | |
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 | 107 } |
108 | |
109 void RadiographyDicomLayer::Render(Orthanc::ImageAccessor& buffer, | |
110 const AffineTransform2D& viewTransform, | |
111 ImageInterpolation interpolation) const | |
112 { | |
113 if (converted_.get() != NULL) | |
114 { | |
115 if (converted_->GetFormat() != Orthanc::PixelFormat_Float32) | |
116 { | |
117 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); | |
118 } | |
119 | |
120 unsigned int cropX, cropY, cropWidth, cropHeight; | |
121 GetCrop(cropX, cropY, cropWidth, cropHeight); | |
122 | |
123 AffineTransform2D t = AffineTransform2D::Combine( | |
124 viewTransform, GetTransform(), | |
125 AffineTransform2D::CreateOffset(cropX, cropY)); | |
126 | |
127 Orthanc::ImageAccessor cropped; | |
128 converted_->GetRegion(cropped, cropX, cropY, cropWidth, cropHeight); | |
129 | |
130 t.Apply(buffer, cropped, interpolation, false); | |
131 } | |
132 } | |
133 | |
134 | |
135 bool RadiographyDicomLayer::GetDefaultWindowing(float& center, | |
136 float& width) const | |
137 { | |
138 if (converter_.get() != NULL && | |
139 converter_->HasDefaultWindow()) | |
140 { | |
141 center = static_cast<float>(converter_->GetDefaultWindowCenter()); | |
142 width = static_cast<float>(converter_->GetDefaultWindowWidth()); | |
143 return true; | |
144 } | |
145 else | |
146 { | |
147 return false; | |
148 } | |
149 } | |
150 | |
151 | |
152 bool RadiographyDicomLayer::GetRange(float& minValue, | |
153 float& maxValue) const | |
154 { | |
155 if (converted_.get() != NULL) | |
156 { | |
157 if (converted_->GetFormat() != Orthanc::PixelFormat_Float32) | |
158 { | |
159 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); | |
160 } | |
161 | |
162 Orthanc::ImageProcessing::GetMinMaxFloatValue(minValue, maxValue, *converted_); | |
163 return true; | |
164 } | |
165 else | |
166 { | |
167 return false; | |
168 } | |
169 } | |
170 | |
171 } |