Mercurial > hg > orthanc-stone
annotate Framework/Radiography/RadiographyAlphaLayer.cpp @ 922:988fa647df21
Added tag toa2019072201 for changeset 81d30cd93b65
author | Benjamin Golinvaux <bgo@osimis.io> |
---|---|
date | Mon, 22 Jul 2019 11:22:56 +0200 |
parents | 42dadae61fa9 |
children | a5f2a6b04a31 |
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 "RadiographyAlphaLayer.h" | |
23 | |
24 #include "RadiographyScene.h" | |
25 | |
26 #include <Core/Images/Image.h> | |
27 #include <Core/OrthancException.h> | |
28 | |
29 namespace OrthancStone | |
30 { | |
31 | |
32 void RadiographyAlphaLayer::SetAlpha(Orthanc::ImageAccessor* image) | |
33 { | |
34 std::auto_ptr<Orthanc::ImageAccessor> raii(image); | |
35 | |
36 if (image == NULL) | |
37 { | |
38 throw Orthanc::OrthancException(Orthanc::ErrorCode_NullPointer); | |
39 } | |
40 | |
41 if (image->GetFormat() != Orthanc::PixelFormat_Grayscale8) | |
42 { | |
43 throw Orthanc::OrthancException(Orthanc::ErrorCode_IncompatibleImageFormat); | |
44 } | |
45 | |
46 SetSize(image->GetWidth(), image->GetHeight()); | |
47 alpha_ = raii; | |
503
77e0eb83ff63
layers are now Observable and emitting LayerEdited messages
amazy
parents:
432
diff
changeset
|
48 |
623
42dadae61fa9
renamed IObservable::EmitMessage() as BroadcastMessage()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
503
diff
changeset
|
49 BroadcastMessage(RadiographyLayer::LayerEditedMessage(*this)); |
430 | 50 } |
51 | |
52 void RadiographyAlphaLayer::Render(Orthanc::ImageAccessor& buffer, | |
53 const AffineTransform2D& viewTransform, | |
54 ImageInterpolation interpolation) const | |
55 { | |
56 if (alpha_.get() == NULL) | |
57 { | |
58 return; | |
59 } | |
60 | |
61 if (buffer.GetFormat() != Orthanc::PixelFormat_Float32) | |
62 { | |
63 throw Orthanc::OrthancException(Orthanc::ErrorCode_IncompatibleImageFormat); | |
64 } | |
65 | |
66 unsigned int cropX, cropY, cropWidth, cropHeight; | |
67 GetCrop(cropX, cropY, cropWidth, cropHeight); | |
68 | |
69 const AffineTransform2D t = AffineTransform2D::Combine( | |
70 viewTransform, GetTransform(), | |
71 AffineTransform2D::CreateOffset(cropX, cropY)); | |
72 | |
73 Orthanc::ImageAccessor cropped; | |
74 alpha_->GetRegion(cropped, cropX, cropY, cropWidth, cropHeight); | |
75 | |
76 Orthanc::Image tmp(Orthanc::PixelFormat_Grayscale8, buffer.GetWidth(), buffer.GetHeight(), false); | |
77 | |
78 t.Apply(tmp, cropped, interpolation, true /* clear */); | |
79 | |
80 // Blit | |
81 const unsigned int width = buffer.GetWidth(); | |
82 const unsigned int height = buffer.GetHeight(); | |
83 | |
84 float value = foreground_; | |
85 | |
86 if (useWindowing_) | |
87 { | |
88 float center, width; | |
503
77e0eb83ff63
layers are now Observable and emitting LayerEdited messages
amazy
parents:
432
diff
changeset
|
89 if (GetScene().GetWindowing(center, width)) |
430 | 90 { |
432
4eb96c6b4e96
improved handling of MONOCHROME1, background and invertion
am@osimis.io
parents:
430
diff
changeset
|
91 value = center + width / 2.0f; // set it to the maximum pixel value of the image |
430 | 92 } |
93 } | |
94 | |
95 for (unsigned int y = 0; y < height; y++) | |
96 { | |
97 float *q = reinterpret_cast<float*>(buffer.GetRow(y)); | |
98 const uint8_t *p = reinterpret_cast<uint8_t*>(tmp.GetRow(y)); | |
99 | |
100 for (unsigned int x = 0; x < width; x++, p++, q++) | |
101 { | |
102 float a = static_cast<float>(*p) / 255.0f; | |
103 | |
104 *q = (a * value + (1.0f - a) * (*q)); | |
105 } | |
106 } | |
107 } | |
108 | |
109 bool RadiographyAlphaLayer::GetRange(float& minValue, | |
110 float& maxValue) const | |
111 { | |
112 if (useWindowing_) | |
113 { | |
114 return false; | |
115 } | |
116 else | |
117 { | |
118 minValue = 0; | |
119 maxValue = 0; | |
120 | |
121 if (foreground_ < 0) | |
122 { | |
123 minValue = foreground_; | |
124 } | |
125 | |
126 if (foreground_ > 0) | |
127 { | |
128 maxValue = foreground_; | |
129 } | |
130 | |
131 return true; | |
132 } | |
133 } | |
134 } |