Mercurial > hg > orthanc-stone
annotate Framework/Deprecated/Radiography/RadiographyMaskLayer.cpp @ 1452:ce167e076be4 loader-injection-feature
Work is done
author | Benjamin Golinvaux <bgo@osimis.io> |
---|---|
date | Tue, 02 Jun 2020 17:10:40 +0200 |
parents | c5403d52078c |
children | 30deba7bc8e2 |
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 |
1280
1c7ae79c426d
fix copyright years
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1259
diff
changeset
|
5 * Copyright (C) 2017-2020 Osimis S.A., Belgium |
475
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> |
1196
a5f2a6b04a31
RadiographyScene: windowing is now only applied to the Dicom layer
Alain Mazy <alain@mazy.be>
parents:
677
diff
changeset
|
29 #include "../Toolbox/ImageGeometry.h" |
475
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff
changeset
|
30 |
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff
changeset
|
31 namespace OrthancStone |
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff
changeset
|
32 { |
1196
a5f2a6b04a31
RadiographyScene: windowing is now only applied to the Dicom layer
Alain Mazy <alain@mazy.be>
parents:
677
diff
changeset
|
33 const unsigned char IN_MASK_VALUE = 0x77; |
476
a95090305dd4
Introduced ControlPoint instead of Corner in the trackers and layers + drawing mask from the ControlPoints
am@osimis.io
parents:
475
diff
changeset
|
34 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
|
35 |
a95090305dd4
Introduced ControlPoint instead of Corner in the trackers and layers + drawing mask from the ControlPoints
am@osimis.io
parents:
475
diff
changeset
|
36 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
|
37 { |
a95090305dd4
Introduced ControlPoint instead of Corner in the trackers and layers + drawing mask from the ControlPoints
am@osimis.io
parents:
475
diff
changeset
|
38 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
|
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 |
a95090305dd4
Introduced ControlPoint instead of Corner in the trackers and layers + drawing mask from the ControlPoints
am@osimis.io
parents:
475
diff
changeset
|
41 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
|
42 { |
a95090305dd4
Introduced ControlPoint instead of Corner in the trackers and layers + drawing mask from the ControlPoints
am@osimis.io
parents:
475
diff
changeset
|
43 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
|
44 } |
475
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff
changeset
|
45 |
480
2f6ecb5037ea
added mouse tracker for Layer Mask. Everything seems ok
am@osimis.io
parents:
479
diff
changeset
|
46 bool RadiographyMaskLayer::GetPixel(unsigned int& imageX, |
2f6ecb5037ea
added mouse tracker for Layer Mask. Everything seems ok
am@osimis.io
parents:
479
diff
changeset
|
47 unsigned int& imageY, |
2f6ecb5037ea
added mouse tracker for Layer Mask. Everything seems ok
am@osimis.io
parents:
479
diff
changeset
|
48 double sceneX, |
2f6ecb5037ea
added mouse tracker for Layer Mask. Everything seems ok
am@osimis.io
parents:
479
diff
changeset
|
49 double sceneY) const |
2f6ecb5037ea
added mouse tracker for Layer Mask. Everything seems ok
am@osimis.io
parents:
479
diff
changeset
|
50 { |
2f6ecb5037ea
added mouse tracker for Layer Mask. Everything seems ok
am@osimis.io
parents:
479
diff
changeset
|
51 return dicomLayer_.GetPixel(imageX, imageY, sceneX, sceneY); |
2f6ecb5037ea
added mouse tracker for Layer Mask. Everything seems ok
am@osimis.io
parents:
479
diff
changeset
|
52 } |
2f6ecb5037ea
added mouse tracker for Layer Mask. Everything seems ok
am@osimis.io
parents:
479
diff
changeset
|
53 |
481
159a465e27bd
reworked RadiographyScene export to export to an Orthanc::Image too
am@osimis.io
parents:
480
diff
changeset
|
54 std::string RadiographyMaskLayer::GetInstanceId() const |
159a465e27bd
reworked RadiographyScene export to export to an Orthanc::Image too
am@osimis.io
parents:
480
diff
changeset
|
55 { |
159a465e27bd
reworked RadiographyScene export to export to an Orthanc::Image too
am@osimis.io
parents:
480
diff
changeset
|
56 return dicomLayer_.GetInstanceId(); |
159a465e27bd
reworked RadiographyScene export to export to an Orthanc::Image too
am@osimis.io
parents:
480
diff
changeset
|
57 } |
159a465e27bd
reworked RadiographyScene export to export to an Orthanc::Image too
am@osimis.io
parents:
480
diff
changeset
|
58 |
488 | 59 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
|
60 { |
2f6ecb5037ea
added mouse tracker for Layer Mask. Everything seems ok
am@osimis.io
parents:
479
diff
changeset
|
61 if (index < corners_.size()) |
2f6ecb5037ea
added mouse tracker for Layer Mask. Everything seems ok
am@osimis.io
parents:
479
diff
changeset
|
62 corners_[index] = corner; |
2f6ecb5037ea
added mouse tracker for Layer Mask. Everything seems ok
am@osimis.io
parents:
479
diff
changeset
|
63 else |
2f6ecb5037ea
added mouse tracker for Layer Mask. Everything seems ok
am@osimis.io
parents:
479
diff
changeset
|
64 corners_.push_back(corner); |
2f6ecb5037ea
added mouse tracker for Layer Mask. Everything seems ok
am@osimis.io
parents:
479
diff
changeset
|
65 invalidated_ = true; |
503
77e0eb83ff63
layers are now Observable and emitting LayerEdited messages
amazy
parents:
488
diff
changeset
|
66 |
623
42dadae61fa9
renamed IObservable::EmitMessage() as BroadcastMessage()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
503
diff
changeset
|
67 BroadcastMessage(RadiographyLayer::LayerEditedMessage(*this)); |
480
2f6ecb5037ea
added mouse tracker for Layer Mask. Everything seems ok
am@osimis.io
parents:
479
diff
changeset
|
68 } |
2f6ecb5037ea
added mouse tracker for Layer Mask. Everything seems ok
am@osimis.io
parents:
479
diff
changeset
|
69 |
488 | 70 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
|
71 { |
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff
changeset
|
72 corners_ = corners; |
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff
changeset
|
73 invalidated_ = true; |
503
77e0eb83ff63
layers are now Observable and emitting LayerEdited messages
amazy
parents:
488
diff
changeset
|
74 |
623
42dadae61fa9
renamed IObservable::EmitMessage() as BroadcastMessage()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
503
diff
changeset
|
75 BroadcastMessage(RadiographyLayer::LayerEditedMessage(*this)); |
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 |
1330
a72c2c9af49a
minimal option for GetSceneExtent, especially for masks
Alain Mazy <alain@mazy.be>
parents:
1321
diff
changeset
|
78 Extent2D RadiographyMaskLayer::GetSceneExtent(bool minimal) const |
1321
d4e6cd35107b
Clarified GetExtent/GetSceneExtent
Alain Mazy <alain@mazy.be>
parents:
1280
diff
changeset
|
79 { |
1330
a72c2c9af49a
minimal option for GetSceneExtent, especially for masks
Alain Mazy <alain@mazy.be>
parents:
1321
diff
changeset
|
80 if (!minimal) |
1321
d4e6cd35107b
Clarified GetExtent/GetSceneExtent
Alain Mazy <alain@mazy.be>
parents:
1280
diff
changeset
|
81 { |
1330
a72c2c9af49a
minimal option for GetSceneExtent, especially for masks
Alain Mazy <alain@mazy.be>
parents:
1321
diff
changeset
|
82 return RadiographyLayer::GetSceneExtent(minimal); |
a72c2c9af49a
minimal option for GetSceneExtent, especially for masks
Alain Mazy <alain@mazy.be>
parents:
1321
diff
changeset
|
83 } |
a72c2c9af49a
minimal option for GetSceneExtent, especially for masks
Alain Mazy <alain@mazy.be>
parents:
1321
diff
changeset
|
84 else |
a72c2c9af49a
minimal option for GetSceneExtent, especially for masks
Alain Mazy <alain@mazy.be>
parents:
1321
diff
changeset
|
85 { // get the extent of the in-mask area |
a72c2c9af49a
minimal option for GetSceneExtent, especially for masks
Alain Mazy <alain@mazy.be>
parents:
1321
diff
changeset
|
86 Extent2D sceneExtent; |
1321
d4e6cd35107b
Clarified GetExtent/GetSceneExtent
Alain Mazy <alain@mazy.be>
parents:
1280
diff
changeset
|
87 |
1375 | 88 for (std::vector<Orthanc::ImageProcessing::ImagePoint>::const_iterator corner = corners_.begin(); corner != corners_.end(); ++corner) |
1330
a72c2c9af49a
minimal option for GetSceneExtent, especially for masks
Alain Mazy <alain@mazy.be>
parents:
1321
diff
changeset
|
89 { |
a72c2c9af49a
minimal option for GetSceneExtent, especially for masks
Alain Mazy <alain@mazy.be>
parents:
1321
diff
changeset
|
90 double x = static_cast<double>(corner->GetX()); |
a72c2c9af49a
minimal option for GetSceneExtent, especially for masks
Alain Mazy <alain@mazy.be>
parents:
1321
diff
changeset
|
91 double y = static_cast<double>(corner->GetY()); |
a72c2c9af49a
minimal option for GetSceneExtent, especially for masks
Alain Mazy <alain@mazy.be>
parents:
1321
diff
changeset
|
92 |
a72c2c9af49a
minimal option for GetSceneExtent, especially for masks
Alain Mazy <alain@mazy.be>
parents:
1321
diff
changeset
|
93 dicomLayer_.GetTransform().Apply(x, y); |
a72c2c9af49a
minimal option for GetSceneExtent, especially for masks
Alain Mazy <alain@mazy.be>
parents:
1321
diff
changeset
|
94 sceneExtent.AddPoint(x, y); |
a72c2c9af49a
minimal option for GetSceneExtent, especially for masks
Alain Mazy <alain@mazy.be>
parents:
1321
diff
changeset
|
95 } |
a72c2c9af49a
minimal option for GetSceneExtent, especially for masks
Alain Mazy <alain@mazy.be>
parents:
1321
diff
changeset
|
96 return sceneExtent; |
1321
d4e6cd35107b
Clarified GetExtent/GetSceneExtent
Alain Mazy <alain@mazy.be>
parents:
1280
diff
changeset
|
97 } |
d4e6cd35107b
Clarified GetExtent/GetSceneExtent
Alain Mazy <alain@mazy.be>
parents:
1280
diff
changeset
|
98 } |
d4e6cd35107b
Clarified GetExtent/GetSceneExtent
Alain Mazy <alain@mazy.be>
parents:
1280
diff
changeset
|
99 |
d4e6cd35107b
Clarified GetExtent/GetSceneExtent
Alain Mazy <alain@mazy.be>
parents:
1280
diff
changeset
|
100 |
d4e6cd35107b
Clarified GetExtent/GetSceneExtent
Alain Mazy <alain@mazy.be>
parents:
1280
diff
changeset
|
101 |
475
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff
changeset
|
102 void RadiographyMaskLayer::Render(Orthanc::ImageAccessor& buffer, |
479 | 103 const AffineTransform2D& viewTransform, |
1196
a5f2a6b04a31
RadiographyScene: windowing is now only applied to the Dicom layer
Alain Mazy <alain@mazy.be>
parents:
677
diff
changeset
|
104 ImageInterpolation interpolation, |
a5f2a6b04a31
RadiographyScene: windowing is now only applied to the Dicom layer
Alain Mazy <alain@mazy.be>
parents:
677
diff
changeset
|
105 float windowCenter, |
a5f2a6b04a31
RadiographyScene: windowing is now only applied to the Dicom layer
Alain Mazy <alain@mazy.be>
parents:
677
diff
changeset
|
106 float windowWidth, |
a5f2a6b04a31
RadiographyScene: windowing is now only applied to the Dicom layer
Alain Mazy <alain@mazy.be>
parents:
677
diff
changeset
|
107 bool applyWindowing) const |
475
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff
changeset
|
108 { |
1259
69177b10e2b9
various fixes for RadiographyScene: support text layers outside the dicom layer, fix background in this case + extract dicom from rendered scene
Alain Mazy <alain@mazy.be>
parents:
1201
diff
changeset
|
109 if (dicomLayer_.GetWidth() == 0 || dicomLayer_.GetSourceImage() == NULL) // nothing to do if the DICOM layer is not displayed (or not loaded) |
475
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff
changeset
|
110 return; |
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff
changeset
|
111 |
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff
changeset
|
112 if (invalidated_) |
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff
changeset
|
113 { |
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff
changeset
|
114 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
|
115 |
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff
changeset
|
116 DrawMask(); |
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 invalidated_ = false; |
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff
changeset
|
119 } |
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff
changeset
|
120 |
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff
changeset
|
121 {// rendering |
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff
changeset
|
122 if (buffer.GetFormat() != Orthanc::PixelFormat_Float32) |
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 throw Orthanc::OrthancException(Orthanc::ErrorCode_IncompatibleImageFormat); |
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 unsigned int cropX, cropY, cropWidth, cropHeight; |
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff
changeset
|
128 dicomLayer_.GetCrop(cropX, cropY, cropWidth, cropHeight); |
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff
changeset
|
129 |
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff
changeset
|
130 const AffineTransform2D t = AffineTransform2D::Combine( |
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff
changeset
|
131 viewTransform, dicomLayer_.GetTransform(), |
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff
changeset
|
132 AffineTransform2D::CreateOffset(cropX, cropY)); |
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff
changeset
|
133 |
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff
changeset
|
134 Orthanc::ImageAccessor cropped; |
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff
changeset
|
135 mask_->GetRegion(cropped, cropX, cropY, cropWidth, cropHeight); |
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff
changeset
|
136 |
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff
changeset
|
137 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
|
138 |
1196
a5f2a6b04a31
RadiographyScene: windowing is now only applied to the Dicom layer
Alain Mazy <alain@mazy.be>
parents:
677
diff
changeset
|
139 |
a5f2a6b04a31
RadiographyScene: windowing is now only applied to the Dicom layer
Alain Mazy <alain@mazy.be>
parents:
677
diff
changeset
|
140 unsigned int x1, y1, x2, y2; |
1201 | 141 if (!OrthancStone::GetProjectiveTransformExtent(x1, y1, x2, y2, |
142 t.GetHomogeneousMatrix(), | |
143 cropped.GetWidth(), | |
144 cropped.GetHeight(), | |
145 buffer.GetWidth(), | |
146 buffer.GetHeight())) | |
147 { | |
148 return; // layer is outside the buffer | |
149 } | |
150 | |
151 t.Apply(tmp, cropped, ImageInterpolation_Nearest, true /* clear */); | |
1196
a5f2a6b04a31
RadiographyScene: windowing is now only applied to the Dicom layer
Alain Mazy <alain@mazy.be>
parents:
677
diff
changeset
|
152 |
a5f2a6b04a31
RadiographyScene: windowing is now only applied to the Dicom layer
Alain Mazy <alain@mazy.be>
parents:
677
diff
changeset
|
153 // we have observed vertical lines at the image border (probably due to bilinear filtering of the DICOM image when it is not aligned with the buffer pixels) |
a5f2a6b04a31
RadiographyScene: windowing is now only applied to the Dicom layer
Alain Mazy <alain@mazy.be>
parents:
677
diff
changeset
|
154 // -> draw the mask one line further on each side |
a5f2a6b04a31
RadiographyScene: windowing is now only applied to the Dicom layer
Alain Mazy <alain@mazy.be>
parents:
677
diff
changeset
|
155 if (x1 >= 1) |
a5f2a6b04a31
RadiographyScene: windowing is now only applied to the Dicom layer
Alain Mazy <alain@mazy.be>
parents:
677
diff
changeset
|
156 { |
a5f2a6b04a31
RadiographyScene: windowing is now only applied to the Dicom layer
Alain Mazy <alain@mazy.be>
parents:
677
diff
changeset
|
157 x1 = x1 - 1; |
a5f2a6b04a31
RadiographyScene: windowing is now only applied to the Dicom layer
Alain Mazy <alain@mazy.be>
parents:
677
diff
changeset
|
158 } |
a5f2a6b04a31
RadiographyScene: windowing is now only applied to the Dicom layer
Alain Mazy <alain@mazy.be>
parents:
677
diff
changeset
|
159 if (x2 < buffer.GetWidth() - 2) |
a5f2a6b04a31
RadiographyScene: windowing is now only applied to the Dicom layer
Alain Mazy <alain@mazy.be>
parents:
677
diff
changeset
|
160 { |
a5f2a6b04a31
RadiographyScene: windowing is now only applied to the Dicom layer
Alain Mazy <alain@mazy.be>
parents:
677
diff
changeset
|
161 x2 = x2 + 1; |
a5f2a6b04a31
RadiographyScene: windowing is now only applied to the Dicom layer
Alain Mazy <alain@mazy.be>
parents:
677
diff
changeset
|
162 } |
475
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff
changeset
|
163 |
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff
changeset
|
164 // Blit |
1196
a5f2a6b04a31
RadiographyScene: windowing is now only applied to the Dicom layer
Alain Mazy <alain@mazy.be>
parents:
677
diff
changeset
|
165 for (unsigned int y = y1; y <= y2; y++) |
475
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff
changeset
|
166 { |
1196
a5f2a6b04a31
RadiographyScene: windowing is now only applied to the Dicom layer
Alain Mazy <alain@mazy.be>
parents:
677
diff
changeset
|
167 float *q = reinterpret_cast<float*>(buffer.GetRow(y)) + x1; |
a5f2a6b04a31
RadiographyScene: windowing is now only applied to the Dicom layer
Alain Mazy <alain@mazy.be>
parents:
677
diff
changeset
|
168 const uint8_t *p = reinterpret_cast<uint8_t*>(tmp.GetRow(y)) + x1; |
475
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff
changeset
|
169 |
1196
a5f2a6b04a31
RadiographyScene: windowing is now only applied to the Dicom layer
Alain Mazy <alain@mazy.be>
parents:
677
diff
changeset
|
170 for (unsigned int x = x1; x <= x2; x++, p++, q++) |
475
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff
changeset
|
171 { |
1196
a5f2a6b04a31
RadiographyScene: windowing is now only applied to the Dicom layer
Alain Mazy <alain@mazy.be>
parents:
677
diff
changeset
|
172 if (*p != IN_MASK_VALUE) |
475
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff
changeset
|
173 *q = foreground_; |
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff
changeset
|
174 // else keep the underlying pixel value |
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff
changeset
|
175 } |
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff
changeset
|
176 } |
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff
changeset
|
177 |
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff
changeset
|
178 } |
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff
changeset
|
179 } |
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff
changeset
|
180 |
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff
changeset
|
181 void RadiographyMaskLayer::DrawMask() const |
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff
changeset
|
182 { |
476
a95090305dd4
Introduced ControlPoint instead of Corner in the trackers and layers + drawing mask from the ControlPoints
am@osimis.io
parents:
475
diff
changeset
|
183 // 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
|
184 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
|
185 |
677 | 186 // clip corners |
187 std::vector<Orthanc::ImageProcessing::ImagePoint> clippedCorners; | |
188 for (size_t i = 0; i < corners_.size(); i++) | |
189 { | |
190 clippedCorners.push_back(corners_[i]); | |
191 clippedCorners[i].ClipTo(0, mask_->GetWidth() - 1, 0, mask_->GetHeight() - 1); | |
192 } | |
193 | |
488 | 194 // fill mask |
677 | 195 Orthanc::ImageProcessing::FillPolygon(*mask_, clippedCorners, 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
|
196 |
475
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff
changeset
|
197 } |
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff
changeset
|
198 |
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff
changeset
|
199 } |