Mercurial > hg > orthanc-stone
annotate Framework/Radiography/RadiographyMaskLayer.cpp @ 492:64d90190a08c am-touch-events
template GetLayer
author | Alain Mazy <alain@mazy.be> |
---|---|
date | Wed, 20 Feb 2019 20:57:43 +0100 |
parents | aede9b042cb7 |
children | 77e0eb83ff63 |
rev | line source |
---|---|
475
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff
changeset
|
1 /** |
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff
changeset
|
2 * Stone of Orthanc |
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff
changeset
|
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics |
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff
changeset
|
4 * Department, University Hospital of Liege, Belgium |
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff
changeset
|
5 * Copyright (C) 2017-2018 Osimis S.A., Belgium |
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff
changeset
|
6 * |
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff
changeset
|
7 * This program is free software: you can redistribute it and/or |
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff
changeset
|
8 * modify it under the terms of the GNU Affero General Public License |
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff
changeset
|
9 * as published by the Free Software Foundation, either version 3 of |
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff
changeset
|
10 * the License, or (at your option) any later version. |
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff
changeset
|
11 * |
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff
changeset
|
12 * This program is distributed in the hope that it will be useful, but |
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff
changeset
|
13 * WITHOUT ANY WARRANTY; without even the implied warranty of |
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff
changeset
|
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff
changeset
|
15 * Affero General Public License for more details. |
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff
changeset
|
16 * |
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff
changeset
|
17 * You should have received a copy of the GNU Affero General Public License |
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff
changeset
|
18 * along with this program. If not, see <http://www.gnu.org/licenses/>. |
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff
changeset
|
19 **/ |
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff
changeset
|
20 |
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff
changeset
|
21 |
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff
changeset
|
22 #include "RadiographyMaskLayer.h" |
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff
changeset
|
23 #include "RadiographyDicomLayer.h" |
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff
changeset
|
24 |
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff
changeset
|
25 #include "RadiographyScene.h" |
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff
changeset
|
26 #include "Core/Images/Image.h" |
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff
changeset
|
27 #include "Core/Images/ImageProcessing.h" |
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff
changeset
|
28 #include <Core/OrthancException.h> |
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff
changeset
|
29 |
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff
changeset
|
30 namespace OrthancStone |
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff
changeset
|
31 { |
476
a95090305dd4
Introduced ControlPoint instead of Corner in the trackers and layers + drawing mask from the ControlPoints
am@osimis.io
parents:
475
diff
changeset
|
32 const unsigned char IN_MASK_VALUE = 0x00; |
a95090305dd4
Introduced ControlPoint instead of Corner in the trackers and layers + drawing mask from the ControlPoints
am@osimis.io
parents:
475
diff
changeset
|
33 const unsigned char OUT_MASK_VALUE = 0xFF; |
a95090305dd4
Introduced ControlPoint instead of Corner in the trackers and layers + drawing mask from the ControlPoints
am@osimis.io
parents:
475
diff
changeset
|
34 |
a95090305dd4
Introduced ControlPoint instead of Corner in the trackers and layers + drawing mask from the ControlPoints
am@osimis.io
parents:
475
diff
changeset
|
35 const AffineTransform2D& RadiographyMaskLayer::GetTransform() const |
a95090305dd4
Introduced ControlPoint instead of Corner in the trackers and layers + drawing mask from the ControlPoints
am@osimis.io
parents:
475
diff
changeset
|
36 { |
a95090305dd4
Introduced ControlPoint instead of Corner in the trackers and layers + drawing mask from the ControlPoints
am@osimis.io
parents:
475
diff
changeset
|
37 return dicomLayer_.GetTransform(); |
a95090305dd4
Introduced ControlPoint instead of Corner in the trackers and layers + drawing mask from the ControlPoints
am@osimis.io
parents:
475
diff
changeset
|
38 } |
a95090305dd4
Introduced ControlPoint instead of Corner in the trackers and layers + drawing mask from the ControlPoints
am@osimis.io
parents:
475
diff
changeset
|
39 |
a95090305dd4
Introduced ControlPoint instead of Corner in the trackers and layers + drawing mask from the ControlPoints
am@osimis.io
parents:
475
diff
changeset
|
40 const AffineTransform2D& RadiographyMaskLayer::GetTransformInverse() const |
a95090305dd4
Introduced ControlPoint instead of Corner in the trackers and layers + drawing mask from the ControlPoints
am@osimis.io
parents:
475
diff
changeset
|
41 { |
a95090305dd4
Introduced ControlPoint instead of Corner in the trackers and layers + drawing mask from the ControlPoints
am@osimis.io
parents:
475
diff
changeset
|
42 return dicomLayer_.GetTransformInverse(); |
a95090305dd4
Introduced ControlPoint instead of Corner in the trackers and layers + drawing mask from the ControlPoints
am@osimis.io
parents:
475
diff
changeset
|
43 } |
475
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff
changeset
|
44 |
480
2f6ecb5037ea
added mouse tracker for Layer Mask. Everything seems ok
am@osimis.io
parents:
479
diff
changeset
|
45 bool RadiographyMaskLayer::GetPixel(unsigned int& imageX, |
2f6ecb5037ea
added mouse tracker for Layer Mask. Everything seems ok
am@osimis.io
parents:
479
diff
changeset
|
46 unsigned int& imageY, |
2f6ecb5037ea
added mouse tracker for Layer Mask. Everything seems ok
am@osimis.io
parents:
479
diff
changeset
|
47 double sceneX, |
2f6ecb5037ea
added mouse tracker for Layer Mask. Everything seems ok
am@osimis.io
parents:
479
diff
changeset
|
48 double sceneY) const |
2f6ecb5037ea
added mouse tracker for Layer Mask. Everything seems ok
am@osimis.io
parents:
479
diff
changeset
|
49 { |
2f6ecb5037ea
added mouse tracker for Layer Mask. Everything seems ok
am@osimis.io
parents:
479
diff
changeset
|
50 return dicomLayer_.GetPixel(imageX, imageY, sceneX, sceneY); |
2f6ecb5037ea
added mouse tracker for Layer Mask. Everything seems ok
am@osimis.io
parents:
479
diff
changeset
|
51 } |
2f6ecb5037ea
added mouse tracker for Layer Mask. Everything seems ok
am@osimis.io
parents:
479
diff
changeset
|
52 |
481
159a465e27bd
reworked RadiographyScene export to export to an Orthanc::Image too
am@osimis.io
parents:
480
diff
changeset
|
53 std::string RadiographyMaskLayer::GetInstanceId() const |
159a465e27bd
reworked RadiographyScene export to export to an Orthanc::Image too
am@osimis.io
parents:
480
diff
changeset
|
54 { |
159a465e27bd
reworked RadiographyScene export to export to an Orthanc::Image too
am@osimis.io
parents:
480
diff
changeset
|
55 return dicomLayer_.GetInstanceId(); |
159a465e27bd
reworked RadiographyScene export to export to an Orthanc::Image too
am@osimis.io
parents:
480
diff
changeset
|
56 } |
159a465e27bd
reworked RadiographyScene export to export to an Orthanc::Image too
am@osimis.io
parents:
480
diff
changeset
|
57 |
488 | 58 void RadiographyMaskLayer::SetCorner(const Orthanc::ImageProcessing::ImagePoint& corner, size_t index) |
480
2f6ecb5037ea
added mouse tracker for Layer Mask. Everything seems ok
am@osimis.io
parents:
479
diff
changeset
|
59 { |
2f6ecb5037ea
added mouse tracker for Layer Mask. Everything seems ok
am@osimis.io
parents:
479
diff
changeset
|
60 if (index < corners_.size()) |
2f6ecb5037ea
added mouse tracker for Layer Mask. Everything seems ok
am@osimis.io
parents:
479
diff
changeset
|
61 corners_[index] = corner; |
2f6ecb5037ea
added mouse tracker for Layer Mask. Everything seems ok
am@osimis.io
parents:
479
diff
changeset
|
62 else |
2f6ecb5037ea
added mouse tracker for Layer Mask. Everything seems ok
am@osimis.io
parents:
479
diff
changeset
|
63 corners_.push_back(corner); |
2f6ecb5037ea
added mouse tracker for Layer Mask. Everything seems ok
am@osimis.io
parents:
479
diff
changeset
|
64 invalidated_ = true; |
2f6ecb5037ea
added mouse tracker for Layer Mask. Everything seems ok
am@osimis.io
parents:
479
diff
changeset
|
65 } |
2f6ecb5037ea
added mouse tracker for Layer Mask. Everything seems ok
am@osimis.io
parents:
479
diff
changeset
|
66 |
488 | 67 void RadiographyMaskLayer::SetCorners(const std::vector<Orthanc::ImageProcessing::ImagePoint>& corners) |
475
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff
changeset
|
68 { |
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff
changeset
|
69 corners_ = corners; |
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff
changeset
|
70 invalidated_ = true; |
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff
changeset
|
71 } |
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff
changeset
|
72 |
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff
changeset
|
73 void RadiographyMaskLayer::Render(Orthanc::ImageAccessor& buffer, |
479 | 74 const AffineTransform2D& viewTransform, |
75 ImageInterpolation interpolation) const | |
475
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff
changeset
|
76 { |
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff
changeset
|
77 if (dicomLayer_.GetWidth() == 0) // nothing to do if the DICOM layer is not displayed (or not loaded) |
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff
changeset
|
78 return; |
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff
changeset
|
79 |
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff
changeset
|
80 if (invalidated_) |
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff
changeset
|
81 { |
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff
changeset
|
82 mask_.reset(new Orthanc::Image(Orthanc::PixelFormat_Grayscale8, dicomLayer_.GetWidth(), dicomLayer_.GetHeight(), false)); |
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff
changeset
|
83 |
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff
changeset
|
84 DrawMask(); |
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff
changeset
|
85 |
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff
changeset
|
86 invalidated_ = false; |
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff
changeset
|
87 } |
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff
changeset
|
88 |
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff
changeset
|
89 {// rendering |
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff
changeset
|
90 if (buffer.GetFormat() != Orthanc::PixelFormat_Float32) |
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff
changeset
|
91 { |
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff
changeset
|
92 throw Orthanc::OrthancException(Orthanc::ErrorCode_IncompatibleImageFormat); |
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff
changeset
|
93 } |
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff
changeset
|
94 |
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff
changeset
|
95 unsigned int cropX, cropY, cropWidth, cropHeight; |
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff
changeset
|
96 dicomLayer_.GetCrop(cropX, cropY, cropWidth, cropHeight); |
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff
changeset
|
97 |
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff
changeset
|
98 const AffineTransform2D t = AffineTransform2D::Combine( |
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff
changeset
|
99 viewTransform, dicomLayer_.GetTransform(), |
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff
changeset
|
100 AffineTransform2D::CreateOffset(cropX, cropY)); |
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff
changeset
|
101 |
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff
changeset
|
102 Orthanc::ImageAccessor cropped; |
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff
changeset
|
103 mask_->GetRegion(cropped, cropX, cropY, cropWidth, cropHeight); |
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff
changeset
|
104 |
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff
changeset
|
105 Orthanc::Image tmp(Orthanc::PixelFormat_Grayscale8, buffer.GetWidth(), buffer.GetHeight(), false); |
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff
changeset
|
106 |
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff
changeset
|
107 t.Apply(tmp, cropped, interpolation, true /* clear */); |
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff
changeset
|
108 |
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff
changeset
|
109 // Blit |
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff
changeset
|
110 const unsigned int width = buffer.GetWidth(); |
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff
changeset
|
111 const unsigned int height = buffer.GetHeight(); |
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff
changeset
|
112 |
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff
changeset
|
113 for (unsigned int y = 0; y < height; y++) |
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff
changeset
|
114 { |
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff
changeset
|
115 float *q = reinterpret_cast<float*>(buffer.GetRow(y)); |
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff
changeset
|
116 const uint8_t *p = reinterpret_cast<uint8_t*>(tmp.GetRow(y)); |
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff
changeset
|
117 |
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff
changeset
|
118 for (unsigned int x = 0; x < width; x++, p++, q++) |
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff
changeset
|
119 { |
476
a95090305dd4
Introduced ControlPoint instead of Corner in the trackers and layers + drawing mask from the ControlPoints
am@osimis.io
parents:
475
diff
changeset
|
120 if (*p == OUT_MASK_VALUE) |
475
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff
changeset
|
121 *q = foreground_; |
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff
changeset
|
122 // else keep the underlying pixel value |
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff
changeset
|
123 } |
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff
changeset
|
124 } |
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff
changeset
|
125 |
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff
changeset
|
126 } |
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff
changeset
|
127 } |
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff
changeset
|
128 |
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff
changeset
|
129 void RadiographyMaskLayer::DrawMask() const |
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff
changeset
|
130 { |
476
a95090305dd4
Introduced ControlPoint instead of Corner in the trackers and layers + drawing mask from the ControlPoints
am@osimis.io
parents:
475
diff
changeset
|
131 // first fill the complete image |
a95090305dd4
Introduced ControlPoint instead of Corner in the trackers and layers + drawing mask from the ControlPoints
am@osimis.io
parents:
475
diff
changeset
|
132 Orthanc::ImageProcessing::Set(*mask_, OUT_MASK_VALUE); |
475
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff
changeset
|
133 |
488 | 134 // fill mask |
135 Orthanc::ImageProcessing::FillPolygon(*mask_, corners_, IN_MASK_VALUE); | |
476
a95090305dd4
Introduced ControlPoint instead of Corner in the trackers and layers + drawing mask from the ControlPoints
am@osimis.io
parents:
475
diff
changeset
|
136 |
475
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff
changeset
|
137 } |
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff
changeset
|
138 |
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff
changeset
|
139 } |