------------------------------------------------------------------------------
| 424 | |
| 425 | //------------------------------------------------------------------------------ |
| 426 | int vtkParallelCoordinatesView::SetBrushLine(int line, double* p1, double* p2) |
| 427 | { |
| 428 | double p1x = p1[0], p1y = p1[1]; |
| 429 | double p2x = p2[0], p2y = p2[1]; |
| 430 | vtkParallelCoordinatesRepresentation* rep = |
| 431 | vtkParallelCoordinatesRepresentation::SafeDownCast(this->GetRepresentation()); |
| 432 | int numAxes = rep->GetNumberOfAxes(); |
| 433 | double* xs = new double[numAxes]; |
| 434 | rep->GetXCoordinatesOfPositions(xs); |
| 435 | |
| 436 | if (p1x == p2x) |
| 437 | { |
| 438 | delete[] xs; |
| 439 | return 0; |
| 440 | } |
| 441 | |
| 442 | // swap, if necessary...I don't think the splines like being out of order |
| 443 | if (p1x > p2x) |
| 444 | { |
| 445 | double tmp; |
| 446 | tmp = p1x; |
| 447 | p1x = p2x; |
| 448 | p2x = tmp; |
| 449 | tmp = p1y; |
| 450 | p1y = p2y; |
| 451 | p2y = tmp; |
| 452 | } |
| 453 | |
| 454 | // find the axis to the left of p1 |
| 455 | int left = numAxes - 1; |
| 456 | for (int i = 0; i < numAxes; i++) |
| 457 | { |
| 458 | if (p1x > xs[i]) |
| 459 | { |
| 460 | left = i; |
| 461 | } |
| 462 | else |
| 463 | { |
| 464 | break; |
| 465 | } |
| 466 | } |
| 467 | |
| 468 | int right = left + 1; |
| 469 | |
| 470 | // sanity check |
| 471 | if (right >= numAxes || left < 0) |
| 472 | { |
| 473 | delete[] xs; |
| 474 | return 0; |
| 475 | } |
| 476 | |
| 477 | // find the points that line (p1-p2) intersects on the left/right axes |
| 478 | double m = (p2y - p1y) / (p2x - p1x); |
| 479 | double lefty = p1y - m * (p1x - xs[left]); |
| 480 | double righty = p1y - m * (p1x - xs[right]); |
| 481 | |
| 482 | p1x = xs[left]; |
| 483 | p2x = xs[right]; |
no test coverage detected