Changeset 25027 for branches/pap/magic/remove/src/Line.c
- Timestamp:
- Aug 7, 2009, 4:08:25 PM (17 years ago)
- Location:
- branches/pap
- Files:
-
- 4 edited
-
. (modified) (1 prop)
-
magic (modified) (1 prop)
-
magic/remove/src (modified) (1 prop)
-
magic/remove/src/Line.c (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/pap
- Property svn:mergeinfo changed
-
branches/pap/magic
-
Property svn:ignore
set to
magic
ssa-core-cpp
Makefile
Makefile.bak
-
Property svn:ignore
set to
-
branches/pap/magic/remove/src
- Property svn:ignore
-
old new 1 isdestreaked 1 2 streaksremove 2 3 streaksreplace 3 4 streakscompare 4 5 streaksrelease 6 makefile
-
- Property svn:ignore
-
branches/pap/magic/remove/src/Line.c
r21156 r25027 16 16 { 17 17 double temp = *first; 18 *first = *second; 19 *second = temp; 20 } 21 22 /** Internal routine to swap integer values */ 23 24 void SwapInt (int* first, int* second) 25 { 26 int temp = *first; 18 27 *first = *second; 19 28 *second = temp; … … 255 264 } 256 265 257 /** Map a line to an image for its specified width and store as a list 258 of pixel positions 266 /** Clip the line between (minX,minY) and (maxX,maxY) 267 268 @param[in,out] line line to be clipped within the bounds 269 @param[in] minX minimum X (columns) for the line 270 @param[in] minY minimum Y (rows) for the line 271 @param[in] maxX maximum X (columns) for the line 272 @param[in] maxY maximum Y (rows) for the line 273 @return true if line overlaps the clip boundaries */ 274 275 bool LineClipFull (Line *line, int minX, int minY, int maxX, int maxY) 276 { 277 unsigned int i, found = 0; 278 Line boundLine, clipLine; 279 strkPt tuple1, tuple2, vertices[4]; 280 vertices[0].x = minX; vertices[0].y = minY; 281 vertices[1].x = maxX; vertices[1].y = minY; 282 vertices[2].x = maxX; vertices[2].y = maxY; 283 vertices[3].x = minX; vertices[3].y = maxY; 284 285 for (i = 0; i < 4 && found < 2; ++i) 286 { 287 boundLine.begin = vertices[i]; 288 boundLine.end = vertices[(i + 1) % 4]; 289 if (LineIntercept (line, &boundLine, &tuple1, &tuple2, false, true)) 290 { 291 if (found == 0) 292 { 293 clipLine.begin = tuple1; 294 ++found; 295 } 296 else if (tuple1.x != clipLine.begin.x || 297 tuple1.y != clipLine.begin.y) 298 { 299 clipLine.end = tuple1; 300 ++found; 301 } 302 } 303 } 304 305 // If two endpoints are found, clip the line 306 307 if (found > 1) 308 { 309 if (clipLine.begin.x <= clipLine.end.x) 310 { 311 line->begin = clipLine.begin; 312 line->end = clipLine.end; 313 } 314 else 315 { 316 line->begin = clipLine.end; 317 line->end = clipLine.begin; 318 } 319 } 320 return found > 1; 321 } 322 323 /** Move a line by the specified X and Y offsets 324 @param[in,out] line Line to move by X and Y offsets 325 @param[in] xOffset X shift applied to both endpoints 326 @param[in] yOffset Y shift applied to both endpoints */ 327 328 void LineMove (Line *line, double xOffset, double yOffset) 329 { 330 line->begin.x += xOffset; 331 line->begin.y += yOffset; 332 line->end.x += xOffset; 333 line->end.y += yOffset; 334 } 335 336 /** Return the maximum bounds between the line endpoints and 337 current bounds 338 @param[in] line Line endpoints to compare 339 @param[in,out] xMin minimum X value to update 340 @param[in,out] xMax maximum X value to update 341 @param[in,out] yMin minimum Y value to update 342 @param[in,out] yMax maximum Y value to update */ 343 344 void MaxBounds (Line *line, int *xMin, int *xMax, int *yMin, int *yMax) 345 { 346 if (line->begin.x < *xMin) *xMin = (int) floor (line->begin.x); 347 if (line->end.x < *xMin) *xMin = (int) floor (line->end.x); 348 if (line->begin.y < *yMin) *yMin = (int) floor (line->begin.y); 349 if (line->end.y < *yMin) *yMin = (int) floor (line->end.y); 350 351 if (line->begin.x > *xMax) *xMax = (int) ceil (line->begin.x); 352 if (line->end.x > *xMax) *xMax = (int) ceil (line->end.x); 353 if (line->begin.y > *yMax) *yMax = (int) ceil (line->begin.y); 354 if (line->end.y > *yMax) *yMax = (int) ceil (line->end.y); 355 } 356 357 /** Map a line to an image for its specified width and store as 358 a list of pixel positions 259 359 260 360 @param[out] pixels list of PixelPos pointers corresponding 261 361 based on the line settings 262 @param[in] line Line to map to pixels */ 263 264 void PixelsFromLine (StreakPixels* pixels, Line *line) 265 { 362 @param[in] line Line to map to pixels 363 @param[in] numCols maximum X (columns) for the line 364 @param[in] numRows maximum Y (rows) for the line */ 365 366 void PixelsFromLine (StreakPixels* pixels, Line *line, int numCols, int numRows) 367 { 368 Line offsetLine; 266 369 PixelPos *pixel; 267 double slope, xOffset, yOffset, xMid, yMid, xBegin, yBegin, xEnd, yEnd, x, y; 370 double slope, xOffset, yOffset, xMid, yMid; 371 int x, y, xBegin = numCols, yBegin = numRows, xEnd = 0, yEnd = 0; 268 372 269 373 // Extract the endpoints … … 280 384 double dr = sqrt (dx * dx + dy * dy); 281 385 double halfWidth = line->width / 2.0; 282 double halfWidth2 = halfWidth * halfWidth;283 386 if (!dr) return; 284 387 388 // Compute the intercepts of line width bounds and determine maximum 389 // bounds in each axis 390 391 xOffset = -halfWidth * dy / dr; 392 yOffset = halfWidth * dx / dr; 393 394 offsetLine = *line; 395 LineMove (&offsetLine, xOffset, yOffset); 396 if (LineClip (&offsetLine, numCols, numRows)) 397 MaxBounds (&offsetLine, &xBegin, &xEnd, &yBegin, &yEnd); 398 399 offsetLine = *line; 400 LineMove (&offsetLine, -xOffset, -yOffset); 401 if (LineClip (&offsetLine, numCols, numRows)) 402 MaxBounds (&offsetLine, &xBegin, &xEnd, &yBegin, &yEnd); 403 285 404 // Step point by point based on the dominate axis 286 405 … … 307 426 // Compute the x and y offsets for the line width extent 308 427 309 xOffset = halfWidth * dy / dr; 310 yOffset = halfWidth * dr / dx; 311 yMid = y1 + slope * (floor (x1 - xOffset) - x1); 312 xBegin = floor (x1 - xOffset); 313 xEnd = ceil (x2 + xOffset) + 1.0; 314 315 for (x = xBegin; x < xEnd; ++x) 316 { 317 yBegin = floor (yMid - yOffset); 318 yEnd = ceil (yMid + yOffset) + 1.0; 319 for (y = yBegin; y < yEnd; ++y) 320 { 321 if (DistanceSquared (line, x, y) <= halfWidth2) 428 if (xBegin > xEnd) 429 SwapInt (&xBegin, &xEnd); 430 else 431 ++xEnd; 432 if (xBegin < 0) xBegin = 0; 433 if (xEnd > numCols) xEnd = numCols; 434 435 yMid = y1 + slope * (xBegin - x1); 436 yOffset = fabs (halfWidth * dr / dx); 437 438 for (x = xBegin; x != xEnd; ++x) 439 { 440 yBegin = (int) floor (yMid - yOffset); 441 yEnd = (int) ceil (yMid + yOffset) + 1; 442 for (y = yBegin; y != yEnd; ++y) 443 { 444 if (y >= 0 && y < numRows) 322 445 { 323 if (x >=0 && y >= 0) { 324 pixel = psAlloc (sizeof(PixelPos)); 325 pixel->x = (unsigned int) x; 326 pixel->y = (unsigned int) y; 327 psArrayAdd (pixels, 1024, pixel); 328 psFree (pixel); 329 } 446 psImageSet(pixels, x, y, 1); 330 447 } 331 448 } … … 354 471 355 472 // Compute the x and y offsets for the line width extent 356 357 xOffset = halfWidth * dr / dy; 358 yOffset = halfWidth * dx / dr; 359 360 xMid = x1 + slope * (floor (y1 - yOffset) - y1); 361 yBegin = floor (y1 - yOffset); 362 yEnd = ceil (y2 + yOffset) + 1.0; 363 364 for (y = yBegin; y < yEnd; ++y) 365 { 366 xBegin = floor (xMid - xOffset); 367 xEnd = ceil (xMid + xOffset) + 1.0; 368 for (x = xBegin; x < xEnd; ++x) 369 { 370 if (DistanceSquared (line, x, y) <= halfWidth2) 473 474 if (yBegin > yEnd) 475 SwapInt (&yBegin, &yEnd); 476 else 477 ++yEnd; 478 if (yBegin < 0) yBegin = 0; 479 if (yEnd > numRows) yEnd = numRows; 480 481 xMid = x1 + slope * (yBegin - y1); 482 xOffset = fabs (halfWidth * dr / dy); 483 484 for (y = yBegin; y != yEnd; ++y) 485 { 486 xBegin = (int) floor (xMid - xOffset); 487 xEnd = (int) ceil (xMid + xOffset) + 1; 488 for (x = xBegin; x != xEnd; ++x) 489 { 490 if (x >=0 && x < numCols) 371 491 { 372 if (x >=0 && y >= 0) { 373 pixel = psAlloc (sizeof(PixelPos)); 374 pixel->x = (unsigned int) x; 375 pixel->y = (unsigned int) y; 376 psArrayAdd (pixels, 1024, pixel); 377 psFree (pixel); 378 } 492 psImageSet(pixels, x, y, 1); 379 493 } 380 494 }
Note:
See TracChangeset
for help on using the changeset viewer.
