Mercurial > hg > orthanc-stone
annotate Framework/Radiography/RadiographyAlphaLayer.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 "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; | |
48 } | |
49 | |
50 void RadiographyAlphaLayer::Render(Orthanc::ImageAccessor& buffer, | |
51 const AffineTransform2D& viewTransform, | |
52 ImageInterpolation interpolation) const | |
53 { | |
54 if (alpha_.get() == NULL) | |
55 { | |
56 return; | |
57 } | |
58 | |
59 if (buffer.GetFormat() != Orthanc::PixelFormat_Float32) | |
60 { | |
61 throw Orthanc::OrthancException(Orthanc::ErrorCode_IncompatibleImageFormat); | |
62 } | |
63 | |
64 unsigned int cropX, cropY, cropWidth, cropHeight; | |
65 GetCrop(cropX, cropY, cropWidth, cropHeight); | |
66 | |
67 const AffineTransform2D t = AffineTransform2D::Combine( | |
68 viewTransform, GetTransform(), | |
69 AffineTransform2D::CreateOffset(cropX, cropY)); | |
70 | |
71 Orthanc::ImageAccessor cropped; | |
72 alpha_->GetRegion(cropped, cropX, cropY, cropWidth, cropHeight); | |
73 | |
74 Orthanc::Image tmp(Orthanc::PixelFormat_Grayscale8, buffer.GetWidth(), buffer.GetHeight(), false); | |
75 | |
76 t.Apply(tmp, cropped, interpolation, true /* clear */); | |
77 | |
78 // Blit | |
79 const unsigned int width = buffer.GetWidth(); | |
80 const unsigned int height = buffer.GetHeight(); | |
81 | |
82 float value = foreground_; | |
83 | |
84 if (useWindowing_) | |
85 { | |
86 float center, width; | |
87 if (scene_.GetWindowing(center, width)) | |
88 { | |
432
4eb96c6b4e96
improved handling of MONOCHROME1, background and invertion
am@osimis.io
parents:
430
diff
changeset
|
89 value = center + width / 2.0f; // set it to the maximum pixel value of the image |
430 | 90 } |
91 } | |
92 | |
93 for (unsigned int y = 0; y < height; y++) | |
94 { | |
95 float *q = reinterpret_cast<float*>(buffer.GetRow(y)); | |
96 const uint8_t *p = reinterpret_cast<uint8_t*>(tmp.GetRow(y)); | |
97 | |
98 for (unsigned int x = 0; x < width; x++, p++, q++) | |
99 { | |
100 float a = static_cast<float>(*p) / 255.0f; | |
101 | |
102 *q = (a * value + (1.0f - a) * (*q)); | |
103 } | |
104 } | |
105 } | |
106 | |
107 bool RadiographyAlphaLayer::GetRange(float& minValue, | |
108 float& maxValue) const | |
109 { | |
110 if (useWindowing_) | |
111 { | |
112 return false; | |
113 } | |
114 else | |
115 { | |
116 minValue = 0; | |
117 maxValue = 0; | |
118 | |
119 if (foreground_ < 0) | |
120 { | |
121 minValue = foreground_; | |
122 } | |
123 | |
124 if (foreground_ > 0) | |
125 { | |
126 maxValue = foreground_; | |
127 } | |
128 | |
129 return true; | |
130 } | |
131 } | |
132 } |