annotate Framework/Radiography/RadiographyMaskLayer.cpp @ 484:7bf001b9d244 am-touch-events

re-added ExportToCreateDicomRequest
author Alain Mazy <alain@mazy.be>
date Fri, 15 Feb 2019 11:08:44 +0100
parents 159a465e27bd
children aede9b042cb7
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
2f6ecb5037ea added mouse tracker for Layer Mask. Everything seems ok
am@osimis.io
parents: 479
diff changeset
53
475
3c28542229a3 added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff changeset
54 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
55 {
3c28542229a3 added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff changeset
56 left = std::numeric_limits<unsigned int>::max();
3c28542229a3 added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff changeset
57 right = std::numeric_limits<unsigned int>::min();
3c28542229a3 added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff changeset
58 top = std::numeric_limits<unsigned int>::max();
3c28542229a3 added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff changeset
59 bottom = std::numeric_limits<unsigned int>::min();
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 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
62 {
3c28542229a3 added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff changeset
63 const MaskPoint& p = corners[i];
3c28542229a3 added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff changeset
64 left = std::min(p.x, left);
3c28542229a3 added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff changeset
65 right = std::max(p.x, right);
3c28542229a3 added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff changeset
66 bottom = std::max(p.y, bottom);
3c28542229a3 added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff changeset
67 top = std::min(p.y, top);
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 }
3c28542229a3 added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff changeset
70
481
159a465e27bd reworked RadiographyScene export to export to an Orthanc::Image too
am@osimis.io
parents: 480
diff changeset
71 std::string RadiographyMaskLayer::GetInstanceId() const
159a465e27bd reworked RadiographyScene export to export to an Orthanc::Image too
am@osimis.io
parents: 480
diff changeset
72 {
159a465e27bd reworked RadiographyScene export to export to an Orthanc::Image too
am@osimis.io
parents: 480
diff changeset
73 return dicomLayer_.GetInstanceId();
159a465e27bd reworked RadiographyScene export to export to an Orthanc::Image too
am@osimis.io
parents: 480
diff changeset
74 }
159a465e27bd reworked RadiographyScene export to export to an Orthanc::Image too
am@osimis.io
parents: 480
diff changeset
75
480
2f6ecb5037ea added mouse tracker for Layer Mask. Everything seems ok
am@osimis.io
parents: 479
diff changeset
76 void RadiographyMaskLayer::SetCorner(const MaskPoint& corner, size_t index)
2f6ecb5037ea added mouse tracker for Layer Mask. Everything seems ok
am@osimis.io
parents: 479
diff changeset
77 {
2f6ecb5037ea added mouse tracker for Layer Mask. Everything seems ok
am@osimis.io
parents: 479
diff changeset
78 if (index < corners_.size())
2f6ecb5037ea added mouse tracker for Layer Mask. Everything seems ok
am@osimis.io
parents: 479
diff changeset
79 corners_[index] = corner;
2f6ecb5037ea added mouse tracker for Layer Mask. Everything seems ok
am@osimis.io
parents: 479
diff changeset
80 else
2f6ecb5037ea added mouse tracker for Layer Mask. Everything seems ok
am@osimis.io
parents: 479
diff changeset
81 corners_.push_back(corner);
2f6ecb5037ea added mouse tracker for Layer Mask. Everything seems ok
am@osimis.io
parents: 479
diff changeset
82 invalidated_ = true;
2f6ecb5037ea added mouse tracker for Layer Mask. Everything seems ok
am@osimis.io
parents: 479
diff changeset
83 }
2f6ecb5037ea added mouse tracker for Layer Mask. Everything seems ok
am@osimis.io
parents: 479
diff changeset
84
475
3c28542229a3 added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff changeset
85 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
86 {
3c28542229a3 added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff changeset
87 corners_ = corners;
3c28542229a3 added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff changeset
88 invalidated_ = true;
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
3c28542229a3 added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff changeset
91 void RadiographyMaskLayer::Render(Orthanc::ImageAccessor& buffer,
479
e3d316ba34ba cleanup
am@osimis.io
parents: 478
diff changeset
92 const AffineTransform2D& viewTransform,
e3d316ba34ba cleanup
am@osimis.io
parents: 478
diff changeset
93 ImageInterpolation interpolation) const
475
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 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
96 return;
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 if (invalidated_)
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 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
101
3c28542229a3 added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff changeset
102 DrawMask();
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 invalidated_ = false;
3c28542229a3 added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff changeset
105 }
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 {// rendering
3c28542229a3 added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff changeset
108 if (buffer.GetFormat() != Orthanc::PixelFormat_Float32)
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 throw Orthanc::OrthancException(Orthanc::ErrorCode_IncompatibleImageFormat);
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
3c28542229a3 added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff changeset
113 unsigned int cropX, cropY, cropWidth, cropHeight;
3c28542229a3 added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff changeset
114 dicomLayer_.GetCrop(cropX, cropY, cropWidth, cropHeight);
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 const AffineTransform2D t = AffineTransform2D::Combine(
3c28542229a3 added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff changeset
117 viewTransform, dicomLayer_.GetTransform(),
3c28542229a3 added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff changeset
118 AffineTransform2D::CreateOffset(cropX, cropY));
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 Orthanc::ImageAccessor cropped;
3c28542229a3 added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff changeset
121 mask_->GetRegion(cropped, cropX, cropY, cropWidth, cropHeight);
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 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
124
3c28542229a3 added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff changeset
125 t.Apply(tmp, cropped, interpolation, true /* clear */);
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 // Blit
3c28542229a3 added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff changeset
128 const unsigned int width = buffer.GetWidth();
3c28542229a3 added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff changeset
129 const unsigned int height = buffer.GetHeight();
3c28542229a3 added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff changeset
130
3c28542229a3 added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff changeset
131 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
132 {
3c28542229a3 added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff changeset
133 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
134 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
135
3c28542229a3 added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff changeset
136 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
137 {
476
a95090305dd4 Introduced ControlPoint instead of Corner in the trackers and layers + drawing mask from the ControlPoints
am@osimis.io
parents: 475
diff changeset
138 if (*p == OUT_MASK_VALUE)
475
3c28542229a3 added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff changeset
139 *q = foreground_;
3c28542229a3 added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff changeset
140 // else keep the underlying pixel value
3c28542229a3 added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff changeset
141 }
3c28542229a3 added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff changeset
142 }
3c28542229a3 added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff changeset
143
3c28542229a3 added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff changeset
144 }
3c28542229a3 added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff changeset
145 }
3c28542229a3 added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff changeset
146
3c28542229a3 added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff changeset
147 void RadiographyMaskLayer::DrawMask() const
3c28542229a3 added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff changeset
148 {
3c28542229a3 added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff changeset
149 unsigned int left;
3c28542229a3 added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff changeset
150 unsigned int right;
3c28542229a3 added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff changeset
151 unsigned int top;
3c28542229a3 added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff changeset
152 unsigned int bottom;
3c28542229a3 added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff changeset
153
477
baf8c8d68bbc cleanup
am@osimis.io
parents: 476
diff changeset
154 ComputeMaskExtent(left, right, top, bottom, corners_);
475
3c28542229a3 added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff changeset
155
476
a95090305dd4 Introduced ControlPoint instead of Corner in the trackers and layers + drawing mask from the ControlPoints
am@osimis.io
parents: 475
diff changeset
156 // 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
157 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
158
3c28542229a3 added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff changeset
159 {
476
a95090305dd4 Introduced ControlPoint instead of Corner in the trackers and layers + drawing mask from the ControlPoints
am@osimis.io
parents: 475
diff changeset
160 // 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
161 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
162
478
017a66a2999b cleanup + avoid conversions
am@osimis.io
parents: 477
diff changeset
163 // convert all control points to double only once
017a66a2999b cleanup + avoid conversions
am@osimis.io
parents: 477
diff changeset
164 std::vector<double> cpx;
017a66a2999b cleanup + avoid conversions
am@osimis.io
parents: 477
diff changeset
165 std::vector<double> cpy;
017a66a2999b cleanup + avoid conversions
am@osimis.io
parents: 477
diff changeset
166 int cpSize = corners_.size();
017a66a2999b cleanup + avoid conversions
am@osimis.io
parents: 477
diff changeset
167 for (size_t i = 0; i < corners_.size(); i++)
017a66a2999b cleanup + avoid conversions
am@osimis.io
parents: 477
diff changeset
168 {
017a66a2999b cleanup + avoid conversions
am@osimis.io
parents: 477
diff changeset
169 cpx.push_back((double)corners_[i].x);
017a66a2999b cleanup + avoid conversions
am@osimis.io
parents: 477
diff changeset
170 cpy.push_back((double)corners_[i].y);
017a66a2999b cleanup + avoid conversions
am@osimis.io
parents: 477
diff changeset
171 }
017a66a2999b cleanup + avoid conversions
am@osimis.io
parents: 477
diff changeset
172
476
a95090305dd4 Introduced ControlPoint instead of Corner in the trackers and layers + drawing mask from the ControlPoints
am@osimis.io
parents: 475
diff changeset
173 std::vector<int> nodeX;
478
017a66a2999b cleanup + avoid conversions
am@osimis.io
parents: 477
diff changeset
174 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
175 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
176
a95090305dd4 Introduced ControlPoint instead of Corner in the trackers and layers + drawing mask from the ControlPoints
am@osimis.io
parents: 475
diff changeset
177 // 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
178 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
179 {
478
017a66a2999b cleanup + avoid conversions
am@osimis.io
parents: 477
diff changeset
180 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
181 // 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
182 nodes = 0;
478
017a66a2999b cleanup + avoid conversions
am@osimis.io
parents: 477
diff changeset
183 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
184
478
017a66a2999b cleanup + avoid conversions
am@osimis.io
parents: 477
diff changeset
185 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
186 {
480
2f6ecb5037ea added mouse tracker for Layer Mask. Everything seems ok
am@osimis.io
parents: 479
diff changeset
187 if ((cpy[i] < y && cpy[j] >= y)
2f6ecb5037ea added mouse tracker for Layer Mask. Everything seems ok
am@osimis.io
parents: 479
diff changeset
188 || (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
189 {
478
017a66a2999b cleanup + avoid conversions
am@osimis.io
parents: 477
diff changeset
190 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
191 }
a95090305dd4 Introduced ControlPoint instead of Corner in the trackers and layers + drawing mask from the ControlPoints
am@osimis.io
parents: 475
diff changeset
192 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
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
a95090305dd4 Introduced ControlPoint instead of Corner in the trackers and layers + drawing mask from the ControlPoints
am@osimis.io
parents: 475
diff changeset
195 // 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
196 i=0;
477
baf8c8d68bbc cleanup
am@osimis.io
parents: 476
diff changeset
197 while (i < nodes-1)
475
3c28542229a3 added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff changeset
198 {
477
baf8c8d68bbc cleanup
am@osimis.io
parents: 476
diff changeset
199 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
200 {
477
baf8c8d68bbc cleanup
am@osimis.io
parents: 476
diff changeset
201 swap = nodeX[i];
baf8c8d68bbc cleanup
am@osimis.io
parents: 476
diff changeset
202 nodeX[i] = nodeX[i+1];
baf8c8d68bbc cleanup
am@osimis.io
parents: 476
diff changeset
203 nodeX[i+1] = swap;
baf8c8d68bbc cleanup
am@osimis.io
parents: 476
diff changeset
204 if (i)
baf8c8d68bbc cleanup
am@osimis.io
parents: 476
diff changeset
205 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
206 }
a95090305dd4 Introduced ControlPoint instead of Corner in the trackers and layers + drawing mask from the ControlPoints
am@osimis.io
parents: 475
diff changeset
207 else
a95090305dd4 Introduced ControlPoint instead of Corner in the trackers and layers + drawing mask from the ControlPoints
am@osimis.io
parents: 475
diff changeset
208 {
a95090305dd4 Introduced ControlPoint instead of Corner in the trackers and layers + drawing mask from the ControlPoints
am@osimis.io
parents: 475
diff changeset
209 i++;
a95090305dd4 Introduced ControlPoint instead of Corner in the trackers and layers + drawing mask from the ControlPoints
am@osimis.io
parents: 475
diff changeset
210 }
a95090305dd4 Introduced ControlPoint instead of Corner in the trackers and layers + drawing mask from the ControlPoints
am@osimis.io
parents: 475
diff changeset
211 }
a95090305dd4 Introduced ControlPoint instead of Corner in the trackers and layers + drawing mask from the ControlPoints
am@osimis.io
parents: 475
diff changeset
212
a95090305dd4 Introduced ControlPoint instead of Corner in the trackers and layers + drawing mask from the ControlPoints
am@osimis.io
parents: 475
diff changeset
213 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
214 // 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
215 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
216 {
a95090305dd4 Introduced ControlPoint instead of Corner in the trackers and layers + drawing mask from the ControlPoints
am@osimis.io
parents: 475
diff changeset
217 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
218 break;
477
baf8c8d68bbc cleanup
am@osimis.io
parents: 476
diff changeset
219 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
220 {
a95090305dd4 Introduced ControlPoint instead of Corner in the trackers and layers + drawing mask from the ControlPoints
am@osimis.io
parents: 475
diff changeset
221 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
222 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
223 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
224 nodeX[i+1]=(int)right;
477
baf8c8d68bbc cleanup
am@osimis.io
parents: 476
diff changeset
225 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
226 {
a95090305dd4 Introduced ControlPoint instead of Corner in the trackers and layers + drawing mask from the ControlPoints
am@osimis.io
parents: 475
diff changeset
227 *(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
228 }
a95090305dd4 Introduced ControlPoint instead of Corner in the trackers and layers + drawing mask from the ControlPoints
am@osimis.io
parents: 475
diff changeset
229 }
475
3c28542229a3 added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff changeset
230 }
3c28542229a3 added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff changeset
231 }
3c28542229a3 added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff changeset
232 }
3c28542229a3 added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff changeset
233 }
3c28542229a3 added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff changeset
234
3c28542229a3 added a mask layer in the RadiographyWidget (to be cleaned)
am@osimis.io
parents:
diff changeset
235 }