Mercurial > hg > orthanc-stone
comparison Framework/Radiography/RadiographyMaskLayer.cpp @ 478:017a66a2999b am-touch-events
cleanup + avoid conversions
author | am@osimis.io |
---|---|
date | Wed, 13 Feb 2019 14:12:41 +0100 |
parents | baf8c8d68bbc |
children | e3d316ba34ba |
comparison
equal
deleted
inserted
replaced
477:baf8c8d68bbc | 478:017a66a2999b |
---|---|
259 | 259 |
260 { | 260 { |
261 // from http://alienryderflex.com/polygon_fill/ | 261 // from http://alienryderflex.com/polygon_fill/ |
262 std::auto_ptr<int> raiiNodeX(new int(corners_.size())); | 262 std::auto_ptr<int> raiiNodeX(new int(corners_.size())); |
263 | 263 |
264 // convert all control points to double only once | |
265 std::vector<double> cpx; | |
266 std::vector<double> cpy; | |
267 int cpSize = corners_.size(); | |
268 for (size_t i = 0; i < corners_.size(); i++) | |
269 { | |
270 cpx.push_back((double)corners_[i].x); | |
271 cpy.push_back((double)corners_[i].y); | |
272 } | |
273 | |
264 std::vector<int> nodeX; | 274 std::vector<int> nodeX; |
265 nodeX.resize(corners_.size()); | 275 nodeX.resize(cpSize); |
266 int nodes, pixelX, pixelY, i, j, swap ; | 276 int nodes, pixelX, pixelY, i, j, swap ; |
267 | 277 |
268 // Loop through the rows of the image. | 278 // Loop through the rows of the image. |
269 for (pixelY = (int)top; pixelY < (int)bottom; pixelY++) | 279 for (pixelY = (int)top; pixelY < (int)bottom; pixelY++) |
270 { | 280 { |
281 double y = (double)pixelY; | |
271 // Build a list of nodes. | 282 // Build a list of nodes. |
272 nodes = 0; | 283 nodes = 0; |
273 j = (int)corners_.size() - 1; | 284 j = cpSize - 1; |
274 | 285 |
275 for (i = 0; i < (int)corners_.size(); i++) | 286 for (i = 0; i < cpSize; i++) |
276 { | 287 { |
277 if ((int)corners_[i].y <= pixelY && (int)corners_[j].y >= pixelY | 288 if ((cpy[i] <= y && cpy[j] >= y) |
278 || (int)corners_[j].y <= pixelY && (int)corners_[i].y >= pixelY) | 289 || (cpy[j] <= y && cpy[i] >= y)) |
279 { | 290 { |
280 nodeX[nodes++]= (int)((double)corners_[i].x + ((double)pixelY - (double)corners_[i].y)/((double)corners_[j].y - (double)corners_[i].y) *((double)corners_[j].x - (double)corners_[i].x)); | 291 nodeX[nodes++]= (int)(cpx[i] + (y - cpy[i])/(cpy[j] - cpy[i]) *(cpx[j] - cpx[i])); |
281 } | 292 } |
282 j=i; | 293 j=i; |
283 } | 294 } |
284 | 295 |
285 // Sort the nodes, via a simple “Bubble” sort. | 296 // Sort the nodes, via a simple “Bubble” sort. |