compute the bounding box of the transform of four points
| 731 | |
| 732 | // compute the bounding box of the transform of four points |
| 733 | static void |
| 734 | transformRegionFromPoints(const Point3D p[4], |
| 735 | RectD &rod) |
| 736 | { |
| 737 | // extract the x/y bounds |
| 738 | double x1, y1, x2, y2; |
| 739 | |
| 740 | // if all z's have the same sign, we can compute a reasonable ROI, else we give the whole image (the line at infinity crosses the rectangle) |
| 741 | bool allpositive = true; |
| 742 | bool allnegative = true; |
| 743 | |
| 744 | for (int i = 0; i < 4; ++i) { |
| 745 | allnegative = allnegative && (p[i].z < 0.); |
| 746 | allpositive = allpositive && (p[i].z > 0.); |
| 747 | } |
| 748 | |
| 749 | if (!allpositive && !allnegative) { |
| 750 | // the line at infinity crosses the source RoD |
| 751 | x1 = kOfxFlagInfiniteMin; |
| 752 | x2 = kOfxFlagInfiniteMax; |
| 753 | y1 = kOfxFlagInfiniteMin; |
| 754 | y2 = kOfxFlagInfiniteMax; |
| 755 | } else { |
| 756 | OfxPointD q[4]; |
| 757 | for (int i = 0; i < 4; ++i) { |
| 758 | q[i].x = p[i].x / p[i].z; |
| 759 | q[i].y = p[i].y / p[i].z; |
| 760 | } |
| 761 | |
| 762 | x1 = x2 = q[0].x; |
| 763 | y1 = y2 = q[0].y; |
| 764 | for (int i = 1; i < 4; ++i) { |
| 765 | if (q[i].x < x1) { |
| 766 | x1 = q[i].x; |
| 767 | } else if (q[i].x > x2) { |
| 768 | x2 = q[i].x; |
| 769 | } |
| 770 | if (q[i].y < y1) { |
| 771 | y1 = q[i].y; |
| 772 | } else if (q[i].y > y2) { |
| 773 | y2 = q[i].y; |
| 774 | } |
| 775 | } |
| 776 | } |
| 777 | |
| 778 | // GENERIC |
| 779 | rod.x1 = x1; |
| 780 | rod.x2 = x2; |
| 781 | rod.y1 = y1; |
| 782 | rod.y2 = y2; |
| 783 | assert(rod.x1 <= rod.x2 && rod.y1 <= rod.y2); |
| 784 | } // transformRegionFromPoints |
| 785 | |
| 786 | // compute the bounding box of the transform of a rectangle |
| 787 | void |
no outgoing calls
no test coverage detected