MCPcopy Create free account
hub / github.com/Kitware/VTK / ClipSegment

Method ClipSegment

Imaging/Sources/vtkImageCanvasSource2D.cxx:883–981  ·  view source on GitHub ↗

------------------------------------------------------------------------------ Clips a line segment so it will be in bounds. If the entire segment is out of bounds, the method returns 0.

Source from the content-addressed store, hash-verified

881// Clips a line segment so it will be in bounds.
882// If the entire segment is out of bounds, the method returns 0.
883int vtkImageCanvasSource2D::ClipSegment(int& a0, int& a1, int& b0, int& b1)
884{
885 int min0, max0, min1, max1, min2, max2;
886 double fract;
887
888 this->ImageData->GetExtent(min0, max0, min1, max1, min2, max2);
889
890 // Check planes
891 // Both out of bounds
892 if (a0 < min0 && b0 < min0)
893 {
894 return 0;
895 }
896 // first out of bounds.
897 if (a0 < min0 && b0 >= min0)
898 {
899 // interpolate to find point on bounding plane.
900 fract = static_cast<double>(b0 - min0) / static_cast<double>(b0 - a0);
901 a0 = min0;
902 a1 = b1 + static_cast<int>(fract * static_cast<double>(a1 - b1));
903 }
904 // second out of bounds.
905 if (b0 < min0 && a0 >= min0)
906 {
907 // interpolate to find point on bounding plane.
908 fract = static_cast<double>(a0 - min0) / static_cast<double>(a0 - b0);
909 b0 = min0;
910 b1 = a1 + static_cast<int>(fract * static_cast<double>(b1 - a1));
911 }
912
913 // Both out of bounds
914 if (a0 > max0 && b0 > max0)
915 {
916 return 0;
917 }
918 // first out of bounds.
919 if (a0 > max0 && b0 <= max0)
920 {
921 // interpolate to find point on bounding plane.
922 fract = static_cast<double>(b0 - max0) / static_cast<double>(b0 - a0);
923 a0 = max0;
924 a1 = b1 + static_cast<int>(fract * static_cast<double>(a1 - b1));
925 }
926 // second out of bounds.
927 if (b0 > max0 && a0 <= max0)
928 {
929 // interpolate to find point on bounding plane.
930 fract = static_cast<double>(a0 - max0) / static_cast<double>(a0 - b0);
931 b0 = max0;
932 b1 = a1 + static_cast<int>(fract * static_cast<double>(b1 - a1));
933 }
934
935 // Both out of bounds
936 if (a1 < min1 && b1 < min1)
937 {
938 return 0;
939 }
940 // first out of bounds.

Callers 1

DrawSegmentMethod · 0.95

Calls 2

GetExtentMethod · 0.45
ModifiedMethod · 0.45

Tested by

no test coverage detected