------------------------------------------------------------------------------ Create a local s-t coordinate system for a polygon. The point p0 is the origin of the local system, p10 is s-axis vector, and p20 is the t-axis vector. (These are expressed in the modelling coordinate system and are vectors of dimension [3].) The values l20 and l20 are the lengths of the vectors p10 and p20, and n is th
| 628 | // are vectors of dimension [3].) The values l20 and l20 are the lengths of |
| 629 | // the vectors p10 and p20, and n is the polygon normal. |
| 630 | int vtkPolygon::ParameterizePolygon( |
| 631 | double* p0, double* p10, double& l10, double* p20, double& l20, double* n) |
| 632 | { |
| 633 | int i, j; |
| 634 | double s, t, p[3], p1[3], p2[3], sbounds[2], tbounds[2]; |
| 635 | int numPts = this->Points->GetNumberOfPoints(); |
| 636 | double x1[3], x2[3]; |
| 637 | |
| 638 | if (numPts < 3) |
| 639 | { |
| 640 | return 0; |
| 641 | } |
| 642 | |
| 643 | // This is a two pass process: first create a p' coordinate system |
| 644 | // that is then adjusted to ensure that the polygon points are all in |
| 645 | // the range 0<=s,t<=1. The p' system is defined by the polygon normal, |
| 646 | // first vertex and the first edge. |
| 647 | // |
| 648 | this->ComputeNormal(this->Points, n); |
| 649 | this->Points->GetPoint(0, x1); |
| 650 | this->Points->GetPoint(1, x2); |
| 651 | for (i = 0; i < 3; i++) |
| 652 | { |
| 653 | p0[i] = x1[i]; |
| 654 | p10[i] = x2[i] - x1[i]; |
| 655 | } |
| 656 | vtkMath::Cross(n, p10, p20); |
| 657 | |
| 658 | // Determine lengths of edges |
| 659 | // |
| 660 | if ((l10 = vtkMath::Dot(p10, p10)) == 0.0 || (l20 = vtkMath::Dot(p20, p20)) == 0.0) |
| 661 | { |
| 662 | return 0; |
| 663 | } |
| 664 | |
| 665 | // Now evaluate all polygon points to determine min/max parametric |
| 666 | // coordinate values. |
| 667 | // |
| 668 | // first vertex has (s,t) = (0,0) |
| 669 | sbounds[0] = 0.0; |
| 670 | sbounds[1] = 0.0; |
| 671 | tbounds[0] = 0.0; |
| 672 | tbounds[1] = 0.0; |
| 673 | |
| 674 | for (i = 1; i < numPts; i++) |
| 675 | { |
| 676 | this->Points->GetPoint(i, x1); |
| 677 | for (j = 0; j < 3; j++) |
| 678 | { |
| 679 | p[j] = x1[j] - p0[j]; |
| 680 | } |
| 681 | s = (p[0] * p10[0] + p[1] * p10[1] + p[2] * p10[2]) / l10; |
| 682 | t = (p[0] * p20[0] + p[1] * p20[1] + p[2] * p20[2]) / l20; |
| 683 | sbounds[0] = (s < sbounds[0] ? s : sbounds[0]); |
| 684 | sbounds[1] = (s > sbounds[1] ? s : sbounds[1]); |
| 685 | tbounds[0] = (t < tbounds[0] ? t : tbounds[0]); |
| 686 | tbounds[1] = (t > tbounds[1] ? t : tbounds[1]); |
| 687 | } |
no test coverage detected