Mercurial > hg > orthanc-stone
comparison Framework/Radiography/RadiographyAlphaLayer.cpp @ 1196:a5f2a6b04a31
RadiographyScene: windowing is now only applied to the Dicom layer
author | Alain Mazy <alain@mazy.be> |
---|---|
date | Wed, 27 Nov 2019 17:51:33 +0100 |
parents | 42dadae61fa9 |
children | ab958fd99b07 |
comparison
equal
deleted
inserted
replaced
1191:c6a36ecd641d | 1196:a5f2a6b04a31 |
---|---|
23 | 23 |
24 #include "RadiographyScene.h" | 24 #include "RadiographyScene.h" |
25 | 25 |
26 #include <Core/Images/Image.h> | 26 #include <Core/Images/Image.h> |
27 #include <Core/OrthancException.h> | 27 #include <Core/OrthancException.h> |
28 #include "../Toolbox/ImageGeometry.h" | |
28 | 29 |
29 namespace OrthancStone | 30 namespace OrthancStone |
30 { | 31 { |
31 | 32 |
32 void RadiographyAlphaLayer::SetAlpha(Orthanc::ImageAccessor* image) | 33 void RadiographyAlphaLayer::SetAlpha(Orthanc::ImageAccessor* image) |
49 BroadcastMessage(RadiographyLayer::LayerEditedMessage(*this)); | 50 BroadcastMessage(RadiographyLayer::LayerEditedMessage(*this)); |
50 } | 51 } |
51 | 52 |
52 void RadiographyAlphaLayer::Render(Orthanc::ImageAccessor& buffer, | 53 void RadiographyAlphaLayer::Render(Orthanc::ImageAccessor& buffer, |
53 const AffineTransform2D& viewTransform, | 54 const AffineTransform2D& viewTransform, |
54 ImageInterpolation interpolation) const | 55 ImageInterpolation interpolation, |
56 float windowCenter, | |
57 float windowWidth, | |
58 bool applyWindowing) const | |
55 { | 59 { |
56 if (alpha_.get() == NULL) | 60 if (alpha_.get() == NULL) |
57 { | 61 { |
58 return; | 62 return; |
59 } | 63 } |
75 | 79 |
76 Orthanc::Image tmp(Orthanc::PixelFormat_Grayscale8, buffer.GetWidth(), buffer.GetHeight(), false); | 80 Orthanc::Image tmp(Orthanc::PixelFormat_Grayscale8, buffer.GetWidth(), buffer.GetHeight(), false); |
77 | 81 |
78 t.Apply(tmp, cropped, interpolation, true /* clear */); | 82 t.Apply(tmp, cropped, interpolation, true /* clear */); |
79 | 83 |
80 // Blit | 84 unsigned int x1, y1, x2, y2; |
81 const unsigned int width = buffer.GetWidth(); | 85 OrthancStone::GetProjectiveTransformExtent(x1, y1, x2, y2, |
82 const unsigned int height = buffer.GetHeight(); | 86 t.GetHomogeneousMatrix(), |
87 cropped.GetWidth(), | |
88 cropped.GetHeight(), | |
89 buffer.GetWidth(), | |
90 buffer.GetHeight()); | |
83 | 91 |
84 float value = foreground_; | 92 float value = foreground_; |
85 | 93 |
86 if (useWindowing_) | 94 if (!applyWindowing) // if applying the windowing, it means we are ie rendering the image for a realtime visualization -> the foreground_ value is the value we want to see on the screen -> don't change it |
87 { | 95 { |
88 float center, width; | 96 // if not applying the windowing, it means ie that we are saving a dicom image to file and the windowing will be applied by a viewer later on -> we want the "foreground" value to be correct once the windowing will be applied |
89 if (GetScene().GetWindowing(center, width)) | 97 value = windowCenter - windowWidth/2 + (foreground_ / 65535.0f) * windowWidth; |
98 | |
99 if (value < 0.0f) | |
90 { | 100 { |
91 value = center + width / 2.0f; // set it to the maximum pixel value of the image | 101 value = 0.0f; |
102 } | |
103 if (value > 65535.0f) | |
104 { | |
105 value = 65535.0f; | |
92 } | 106 } |
93 } | 107 } |
94 | 108 |
95 for (unsigned int y = 0; y < height; y++) | 109 for (unsigned int y = y1; y <= y2; y++) |
96 { | 110 { |
97 float *q = reinterpret_cast<float*>(buffer.GetRow(y)); | 111 float *q = reinterpret_cast<float*>(buffer.GetRow(y)) + x1; |
98 const uint8_t *p = reinterpret_cast<uint8_t*>(tmp.GetRow(y)); | 112 const uint8_t *p = reinterpret_cast<uint8_t*>(tmp.GetRow(y)) + x1; |
99 | 113 |
100 for (unsigned int x = 0; x < width; x++, p++, q++) | 114 for (unsigned int x = x1; x <= x2; x++, p++, q++) |
101 { | 115 { |
102 float a = static_cast<float>(*p) / 255.0f; | 116 float a = static_cast<float>(*p) / 255.0f; |
103 | 117 |
104 *q = (a * value + (1.0f - a) * (*q)); | 118 *q = (a * value + (1.0f - a) * (*q)); |
105 } | 119 } |
107 } | 121 } |
108 | 122 |
109 bool RadiographyAlphaLayer::GetRange(float& minValue, | 123 bool RadiographyAlphaLayer::GetRange(float& minValue, |
110 float& maxValue) const | 124 float& maxValue) const |
111 { | 125 { |
112 if (useWindowing_) | 126 minValue = 0; |
127 maxValue = 0; | |
128 | |
129 if (foreground_ < 0) | |
113 { | 130 { |
114 return false; | 131 minValue = foreground_; |
115 } | 132 } |
116 else | 133 |
134 if (foreground_ > 0) | |
117 { | 135 { |
118 minValue = 0; | 136 maxValue = foreground_; |
119 maxValue = 0; | 137 } |
120 | 138 |
121 if (foreground_ < 0) | 139 return true; |
122 { | |
123 minValue = foreground_; | |
124 } | |
125 | |
126 if (foreground_ > 0) | |
127 { | |
128 maxValue = foreground_; | |
129 } | |
130 | |
131 return true; | |
132 } | |
133 } | 140 } |
134 } | 141 } |