comparison Framework/Radiography/RadiographyDicomLayer.cpp @ 1200:54cbffabdc45 broker

integration mainline->broker
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 29 Nov 2019 11:03:41 +0100
parents d7e06542304c a5f2a6b04a31
children b519c1c878f1
comparison
equal deleted inserted replaced
1198:4cc997207d8a 1200:54cbffabdc45
26 26
27 #include <Core/OrthancException.h> 27 #include <Core/OrthancException.h>
28 #include <Core/Images/Image.h> 28 #include <Core/Images/Image.h>
29 #include <Core/Images/ImageProcessing.h> 29 #include <Core/Images/ImageProcessing.h>
30 #include <Plugins/Samples/Common/DicomDatasetReader.h> 30 #include <Plugins/Samples/Common/DicomDatasetReader.h>
31 #include "../Toolbox/ImageGeometry.h"
31 32
32 static OrthancPlugins::DicomTag ConvertTag(const Orthanc::DicomTag& tag) 33 static OrthancPlugins::DicomTag ConvertTag(const Orthanc::DicomTag& tag)
33 { 34 {
34 return OrthancPlugins::DicomTag(tag.GetGroup(), tag.GetElement()); 35 return OrthancPlugins::DicomTag(tag.GetGroup(), tag.GetElement());
35 } 36 }
137 converter_.reset(converter); 138 converter_.reset(converter);
138 } 139 }
139 140
140 void RadiographyDicomLayer::Render(Orthanc::ImageAccessor& buffer, 141 void RadiographyDicomLayer::Render(Orthanc::ImageAccessor& buffer,
141 const AffineTransform2D& viewTransform, 142 const AffineTransform2D& viewTransform,
142 ImageInterpolation interpolation) const 143 ImageInterpolation interpolation,
144 float windowCenter,
145 float windowWidth,
146 bool applyWindowing) const
143 { 147 {
144 if (converted_.get() != NULL) 148 if (converted_.get() != NULL)
145 { 149 {
146 if (converted_->GetFormat() != Orthanc::PixelFormat_Float32) 150 if (converted_->GetFormat() != Orthanc::PixelFormat_Float32)
147 { 151 {
157 161
158 Orthanc::ImageAccessor cropped; 162 Orthanc::ImageAccessor cropped;
159 converted_->GetRegion(cropped, cropX, cropY, cropWidth, cropHeight); 163 converted_->GetRegion(cropped, cropX, cropY, cropWidth, cropHeight);
160 164
161 t.Apply(buffer, cropped, interpolation, false); 165 t.Apply(buffer, cropped, interpolation, false);
166 unsigned int x1, y1, x2, y2;
167 OrthancStone::GetProjectiveTransformExtent(x1, y1, x2, y2,
168 t.GetHomogeneousMatrix(),
169 cropped.GetWidth(),
170 cropped.GetHeight(),
171 buffer.GetWidth(),
172 buffer.GetHeight());
173
174 if (applyWindowing)
175 {
176 // apply windowing but stay in the range [0.0, 65535.0]
177 float w0 = windowCenter - windowWidth / 2.0f;
178 float w1 = windowCenter + windowWidth / 2.0f;
179
180 if (windowWidth >= 0.001f) // Avoid division by zero at (*)
181 {
182 float scaling = 1.0f / (w1 - w0) * 65535.0f;
183 for (unsigned int y = y1; y <= y2; y++)
184 {
185 float* p = reinterpret_cast<float*>(buffer.GetRow(y)) + x1;
186
187 for (unsigned int x = x1; x <= x2; x++, p++)
188 {
189 if (*p >= w1)
190 {
191 *p = 65535.0;
192 }
193 else if (*p <= w0)
194 {
195 *p = 0;
196 }
197 else
198 {
199 // https://en.wikipedia.org/wiki/Linear_interpolation
200 *p = scaling * (*p - w0); // (*)
201 }
202 }
203 }
204 }
205 }
206
162 } 207 }
163 } 208 }
164 209
165 210
166 bool RadiographyDicomLayer::GetDefaultWindowing(float& center, 211 bool RadiographyDicomLayer::GetDefaultWindowing(float& center,