Mercurial > hg > orthanc-stone
annotate Framework/Radiography/RadiographyMaskLayer.cpp @ 479:e3d316ba34ba am-touch-events
cleanup
author | am@osimis.io |
---|---|
date | Wed, 13 Feb 2019 14:14:42 +0100 |
parents | 017a66a2999b |
children | 2f6ecb5037ea |
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 |
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff
changeset
|
45 void ComputeMaskExtent(unsigned int& left, unsigned int& right, unsigned int& top, unsigned int& bottom, const std::vector<MaskPoint>& corners) |
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff
changeset
|
46 { |
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff
changeset
|
47 left = std::numeric_limits<unsigned int>::max(); |
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff
changeset
|
48 right = std::numeric_limits<unsigned int>::min(); |
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff
changeset
|
49 top = std::numeric_limits<unsigned int>::max(); |
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff
changeset
|
50 bottom = std::numeric_limits<unsigned int>::min(); |
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff
changeset
|
51 |
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff
changeset
|
52 for (size_t i = 0; i < corners.size(); i++) |
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff
changeset
|
53 { |
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff
changeset
|
54 const MaskPoint& p = corners[i]; |
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff
changeset
|
55 left = std::min(p.x, left); |
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff
changeset
|
56 right = std::max(p.x, right); |
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff
changeset
|
57 bottom = std::max(p.y, bottom); |
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff
changeset
|
58 top = std::min(p.y, top); |
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff
changeset
|
59 } |
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff
changeset
|
60 } |
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff
changeset
|
61 |
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff
changeset
|
62 void RadiographyMaskLayer::SetCorners(const std::vector<MaskPoint>& corners) |
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff
changeset
|
63 { |
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff
changeset
|
64 corners_ = corners; |
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff
changeset
|
65 invalidated_ = true; |
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff
changeset
|
66 } |
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff
changeset
|
67 |
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff
changeset
|
68 void RadiographyMaskLayer::Render(Orthanc::ImageAccessor& buffer, |
479 | 69 const AffineTransform2D& viewTransform, |
70 ImageInterpolation interpolation) const | |
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 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
|
73 return; |
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff
changeset
|
74 |
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff
changeset
|
75 if (invalidated_) |
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 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
|
78 |
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff
changeset
|
79 DrawMask(); |
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff
changeset
|
80 |
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff
changeset
|
81 invalidated_ = false; |
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff
changeset
|
82 } |
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 {// rendering |
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff
changeset
|
85 if (buffer.GetFormat() != Orthanc::PixelFormat_Float32) |
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff
changeset
|
86 { |
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff
changeset
|
87 throw Orthanc::OrthancException(Orthanc::ErrorCode_IncompatibleImageFormat); |
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 |
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff
changeset
|
90 unsigned int cropX, cropY, cropWidth, cropHeight; |
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff
changeset
|
91 dicomLayer_.GetCrop(cropX, cropY, cropWidth, cropHeight); |
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff
changeset
|
92 |
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff
changeset
|
93 const AffineTransform2D t = AffineTransform2D::Combine( |
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff
changeset
|
94 viewTransform, dicomLayer_.GetTransform(), |
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff
changeset
|
95 AffineTransform2D::CreateOffset(cropX, cropY)); |
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff
changeset
|
96 |
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff
changeset
|
97 Orthanc::ImageAccessor cropped; |
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff
changeset
|
98 mask_->GetRegion(cropped, cropX, cropY, cropWidth, cropHeight); |
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff
changeset
|
99 |
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff
changeset
|
100 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
|
101 |
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff
changeset
|
102 t.Apply(tmp, cropped, interpolation, true /* clear */); |
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff
changeset
|
103 |
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff
changeset
|
104 // Blit |
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff
changeset
|
105 const unsigned int width = buffer.GetWidth(); |
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff
changeset
|
106 const unsigned int height = buffer.GetHeight(); |
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff
changeset
|
107 |
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff
changeset
|
108 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
|
109 { |
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff
changeset
|
110 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
|
111 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
|
112 |
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff
changeset
|
113 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
|
114 { |
476
a95090305dd4
Introduced ControlPoint instead of Corner in the trackers and layers + drawing mask from the ControlPoints
am@osimis.io
parents:
475
diff
changeset
|
115 if (*p == OUT_MASK_VALUE) |
475
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff
changeset
|
116 *q = foreground_; |
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff
changeset
|
117 // else keep the underlying pixel value |
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff
changeset
|
118 } |
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 } |
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff
changeset
|
122 } |
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 void RadiographyMaskLayer::DrawMask() const |
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 unsigned int left; |
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff
changeset
|
127 unsigned int right; |
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff
changeset
|
128 unsigned int top; |
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff
changeset
|
129 unsigned int bottom; |
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff
changeset
|
130 |
477 | 131 ComputeMaskExtent(left, right, top, bottom, corners_); |
475
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff
changeset
|
132 |
476
a95090305dd4
Introduced ControlPoint instead of Corner in the trackers and layers + drawing mask from the ControlPoints
am@osimis.io
parents:
475
diff
changeset
|
133 // 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
|
134 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
|
135 |
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff
changeset
|
136 { |
476
a95090305dd4
Introduced ControlPoint instead of Corner in the trackers and layers + drawing mask from the ControlPoints
am@osimis.io
parents:
475
diff
changeset
|
137 // from http://alienryderflex.com/polygon_fill/ |
a95090305dd4
Introduced ControlPoint instead of Corner in the trackers and layers + drawing mask from the ControlPoints
am@osimis.io
parents:
475
diff
changeset
|
138 std::auto_ptr<int> raiiNodeX(new int(corners_.size())); |
a95090305dd4
Introduced ControlPoint instead of Corner in the trackers and layers + drawing mask from the ControlPoints
am@osimis.io
parents:
475
diff
changeset
|
139 |
478 | 140 // convert all control points to double only once |
141 std::vector<double> cpx; | |
142 std::vector<double> cpy; | |
143 int cpSize = corners_.size(); | |
144 for (size_t i = 0; i < corners_.size(); i++) | |
145 { | |
146 cpx.push_back((double)corners_[i].x); | |
147 cpy.push_back((double)corners_[i].y); | |
148 } | |
149 | |
476
a95090305dd4
Introduced ControlPoint instead of Corner in the trackers and layers + drawing mask from the ControlPoints
am@osimis.io
parents:
475
diff
changeset
|
150 std::vector<int> nodeX; |
478 | 151 nodeX.resize(cpSize); |
476
a95090305dd4
Introduced ControlPoint instead of Corner in the trackers and layers + drawing mask from the ControlPoints
am@osimis.io
parents:
475
diff
changeset
|
152 int nodes, pixelX, pixelY, i, j, swap ; |
a95090305dd4
Introduced ControlPoint instead of Corner in the trackers and layers + drawing mask from the ControlPoints
am@osimis.io
parents:
475
diff
changeset
|
153 |
a95090305dd4
Introduced ControlPoint instead of Corner in the trackers and layers + drawing mask from the ControlPoints
am@osimis.io
parents:
475
diff
changeset
|
154 // Loop through the rows of the image. |
a95090305dd4
Introduced ControlPoint instead of Corner in the trackers and layers + drawing mask from the ControlPoints
am@osimis.io
parents:
475
diff
changeset
|
155 for (pixelY = (int)top; pixelY < (int)bottom; pixelY++) |
475
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff
changeset
|
156 { |
478 | 157 double y = (double)pixelY; |
476
a95090305dd4
Introduced ControlPoint instead of Corner in the trackers and layers + drawing mask from the ControlPoints
am@osimis.io
parents:
475
diff
changeset
|
158 // Build a list of nodes. |
a95090305dd4
Introduced ControlPoint instead of Corner in the trackers and layers + drawing mask from the ControlPoints
am@osimis.io
parents:
475
diff
changeset
|
159 nodes = 0; |
478 | 160 j = cpSize - 1; |
476
a95090305dd4
Introduced ControlPoint instead of Corner in the trackers and layers + drawing mask from the ControlPoints
am@osimis.io
parents:
475
diff
changeset
|
161 |
478 | 162 for (i = 0; i < cpSize; i++) |
476
a95090305dd4
Introduced ControlPoint instead of Corner in the trackers and layers + drawing mask from the ControlPoints
am@osimis.io
parents:
475
diff
changeset
|
163 { |
478 | 164 if ((cpy[i] <= y && cpy[j] >= y) |
479 | 165 || (cpy[j] <= y && cpy[i] >= y)) |
476
a95090305dd4
Introduced ControlPoint instead of Corner in the trackers and layers + drawing mask from the ControlPoints
am@osimis.io
parents:
475
diff
changeset
|
166 { |
478 | 167 nodeX[nodes++]= (int)(cpx[i] + (y - cpy[i])/(cpy[j] - cpy[i]) *(cpx[j] - cpx[i])); |
476
a95090305dd4
Introduced ControlPoint instead of Corner in the trackers and layers + drawing mask from the ControlPoints
am@osimis.io
parents:
475
diff
changeset
|
168 } |
a95090305dd4
Introduced ControlPoint instead of Corner in the trackers and layers + drawing mask from the ControlPoints
am@osimis.io
parents:
475
diff
changeset
|
169 j=i; |
a95090305dd4
Introduced ControlPoint instead of Corner in the trackers and layers + drawing mask from the ControlPoints
am@osimis.io
parents:
475
diff
changeset
|
170 } |
a95090305dd4
Introduced ControlPoint instead of Corner in the trackers and layers + drawing mask from the ControlPoints
am@osimis.io
parents:
475
diff
changeset
|
171 |
a95090305dd4
Introduced ControlPoint instead of Corner in the trackers and layers + drawing mask from the ControlPoints
am@osimis.io
parents:
475
diff
changeset
|
172 // Sort the nodes, via a simple “Bubble” sort. |
a95090305dd4
Introduced ControlPoint instead of Corner in the trackers and layers + drawing mask from the ControlPoints
am@osimis.io
parents:
475
diff
changeset
|
173 i=0; |
477 | 174 while (i < nodes-1) |
475
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff
changeset
|
175 { |
477 | 176 if (nodeX[i] > nodeX[i+1]) |
476
a95090305dd4
Introduced ControlPoint instead of Corner in the trackers and layers + drawing mask from the ControlPoints
am@osimis.io
parents:
475
diff
changeset
|
177 { |
477 | 178 swap = nodeX[i]; |
179 nodeX[i] = nodeX[i+1]; | |
180 nodeX[i+1] = swap; | |
181 if (i) | |
182 i--; | |
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 } |
a95090305dd4
Introduced ControlPoint instead of Corner in the trackers and layers + drawing mask from the ControlPoints
am@osimis.io
parents:
475
diff
changeset
|
184 else |
a95090305dd4
Introduced ControlPoint instead of Corner in the trackers and layers + drawing mask from the ControlPoints
am@osimis.io
parents:
475
diff
changeset
|
185 { |
a95090305dd4
Introduced ControlPoint instead of Corner in the trackers and layers + drawing mask from the ControlPoints
am@osimis.io
parents:
475
diff
changeset
|
186 i++; |
a95090305dd4
Introduced ControlPoint instead of Corner in the trackers and layers + drawing mask from the ControlPoints
am@osimis.io
parents:
475
diff
changeset
|
187 } |
a95090305dd4
Introduced ControlPoint instead of Corner in the trackers and layers + drawing mask from the ControlPoints
am@osimis.io
parents:
475
diff
changeset
|
188 } |
a95090305dd4
Introduced ControlPoint instead of Corner in the trackers and layers + drawing mask from the ControlPoints
am@osimis.io
parents:
475
diff
changeset
|
189 |
a95090305dd4
Introduced ControlPoint instead of Corner in the trackers and layers + drawing mask from the ControlPoints
am@osimis.io
parents:
475
diff
changeset
|
190 unsigned char* row = reinterpret_cast<unsigned char*>(mask_->GetRow(pixelY)); |
a95090305dd4
Introduced ControlPoint instead of Corner in the trackers and layers + drawing mask from the ControlPoints
am@osimis.io
parents:
475
diff
changeset
|
191 // Fill the pixels between node pairs. |
a95090305dd4
Introduced ControlPoint instead of Corner in the trackers and layers + drawing mask from the ControlPoints
am@osimis.io
parents:
475
diff
changeset
|
192 for (i=0; i<nodes; i+=2) |
a95090305dd4
Introduced ControlPoint instead of Corner in the trackers and layers + drawing mask from the ControlPoints
am@osimis.io
parents:
475
diff
changeset
|
193 { |
a95090305dd4
Introduced ControlPoint instead of Corner in the trackers and layers + drawing mask from the ControlPoints
am@osimis.io
parents:
475
diff
changeset
|
194 if (nodeX[i ]>=(int)right) |
a95090305dd4
Introduced ControlPoint instead of Corner in the trackers and layers + drawing mask from the ControlPoints
am@osimis.io
parents:
475
diff
changeset
|
195 break; |
477 | 196 if (nodeX[i+1]>= (int)left) |
476
a95090305dd4
Introduced ControlPoint instead of Corner in the trackers and layers + drawing mask from the ControlPoints
am@osimis.io
parents:
475
diff
changeset
|
197 { |
a95090305dd4
Introduced ControlPoint instead of Corner in the trackers and layers + drawing mask from the ControlPoints
am@osimis.io
parents:
475
diff
changeset
|
198 if (nodeX[i ]< (int)left ) |
a95090305dd4
Introduced ControlPoint instead of Corner in the trackers and layers + drawing mask from the ControlPoints
am@osimis.io
parents:
475
diff
changeset
|
199 nodeX[i ]=(int)left ; |
a95090305dd4
Introduced ControlPoint instead of Corner in the trackers and layers + drawing mask from the ControlPoints
am@osimis.io
parents:
475
diff
changeset
|
200 if (nodeX[i+1]> (int)right) |
a95090305dd4
Introduced ControlPoint instead of Corner in the trackers and layers + drawing mask from the ControlPoints
am@osimis.io
parents:
475
diff
changeset
|
201 nodeX[i+1]=(int)right; |
477 | 202 for (pixelX = nodeX[i]; pixelX <= nodeX[i+1]; pixelX++) |
476
a95090305dd4
Introduced ControlPoint instead of Corner in the trackers and layers + drawing mask from the ControlPoints
am@osimis.io
parents:
475
diff
changeset
|
203 { |
a95090305dd4
Introduced ControlPoint instead of Corner in the trackers and layers + drawing mask from the ControlPoints
am@osimis.io
parents:
475
diff
changeset
|
204 *(row + pixelX) = IN_MASK_VALUE; |
a95090305dd4
Introduced ControlPoint instead of Corner in the trackers and layers + drawing mask from the ControlPoints
am@osimis.io
parents:
475
diff
changeset
|
205 } |
a95090305dd4
Introduced ControlPoint instead of Corner in the trackers and layers + drawing mask from the ControlPoints
am@osimis.io
parents:
475
diff
changeset
|
206 } |
475
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff
changeset
|
207 } |
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff
changeset
|
208 } |
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff
changeset
|
209 } |
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff
changeset
|
210 } |
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff
changeset
|
211 |
3c28542229a3
added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff
changeset
|
212 } |