Mercurial > hg > orthanc-stone
annotate Framework/Radiography/RadiographyDicomLayer.cpp @ 448:cc47e6eaefb0 bgo-commands-codegen
Fixed dummy change
author | bgo-osimis |
---|---|
date | Wed, 16 Jan 2019 21:08:38 +0100 |
parents | 4eb96c6b4e96 |
children | 77e0eb83ff63 |
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(); | |
105 } | |
106 | |
107 void RadiographyDicomLayer::Render(Orthanc::ImageAccessor& buffer, | |
108 const AffineTransform2D& viewTransform, | |
109 ImageInterpolation interpolation) const | |
110 { | |
111 if (converted_.get() != NULL) | |
112 { | |
113 if (converted_->GetFormat() != Orthanc::PixelFormat_Float32) | |
114 { | |
115 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); | |
116 } | |
117 | |
118 unsigned int cropX, cropY, cropWidth, cropHeight; | |
119 GetCrop(cropX, cropY, cropWidth, cropHeight); | |
120 | |
121 AffineTransform2D t = AffineTransform2D::Combine( | |
122 viewTransform, GetTransform(), | |
123 AffineTransform2D::CreateOffset(cropX, cropY)); | |
124 | |
125 Orthanc::ImageAccessor cropped; | |
126 converted_->GetRegion(cropped, cropX, cropY, cropWidth, cropHeight); | |
127 | |
128 t.Apply(buffer, cropped, interpolation, false); | |
129 } | |
130 } | |
131 | |
132 | |
133 bool RadiographyDicomLayer::GetDefaultWindowing(float& center, | |
134 float& width) const | |
135 { | |
136 if (converter_.get() != NULL && | |
137 converter_->HasDefaultWindow()) | |
138 { | |
139 center = static_cast<float>(converter_->GetDefaultWindowCenter()); | |
140 width = static_cast<float>(converter_->GetDefaultWindowWidth()); | |
141 return true; | |
142 } | |
143 else | |
144 { | |
145 return false; | |
146 } | |
147 } | |
148 | |
149 | |
150 bool RadiographyDicomLayer::GetRange(float& minValue, | |
151 float& maxValue) const | |
152 { | |
153 if (converted_.get() != NULL) | |
154 { | |
155 if (converted_->GetFormat() != Orthanc::PixelFormat_Float32) | |
156 { | |
157 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); | |
158 } | |
159 | |
160 Orthanc::ImageProcessing::GetMinMaxFloatValue(minValue, maxValue, *converted_); | |
161 return true; | |
162 } | |
163 else | |
164 { | |
165 return false; | |
166 } | |
167 } | |
168 | |
169 } |