------------------------------------------------------------------------------ Draw a Segment from point a to point b.
| 827 | //------------------------------------------------------------------------------ |
| 828 | // Draw a Segment from point a to point b. |
| 829 | void vtkImageCanvasSource2D::DrawSegment(int a0, int a1, int b0, int b1) |
| 830 | { |
| 831 | int* extent; |
| 832 | void* ptr; |
| 833 | int z = this->DefaultZ; |
| 834 | |
| 835 | vtkDebugMacro(<< "Drawing a segment: " << a0 << ", " << a1 << " to " << b0 << ", " << b1); |
| 836 | |
| 837 | // Pre-multiply coords if needed |
| 838 | if (this->Ratio[0] != 1.0) |
| 839 | { |
| 840 | a0 = static_cast<int>(static_cast<double>(a0) * this->Ratio[0]); |
| 841 | b0 = static_cast<int>(static_cast<double>(b0) * this->Ratio[0]); |
| 842 | } |
| 843 | if (this->Ratio[1] != 1.0) |
| 844 | { |
| 845 | a1 = static_cast<int>(static_cast<double>(a1) * this->Ratio[1]); |
| 846 | b1 = static_cast<int>(static_cast<double>(b1) * this->Ratio[1]); |
| 847 | } |
| 848 | if (this->Ratio[2] != 1.0) |
| 849 | { |
| 850 | z = static_cast<int>(static_cast<double>(z) * this->Ratio[2]); |
| 851 | } |
| 852 | |
| 853 | // check to make sure line segment is in bounds. |
| 854 | extent = this->ImageData->GetExtent(); |
| 855 | z = (z < extent[4]) ? extent[4] : z; |
| 856 | z = (z > extent[5]) ? extent[5] : z; |
| 857 | if (a0 < extent[0] || a0 > extent[1] || b0 < extent[0] || b0 > extent[1] || a1 < extent[2] || |
| 858 | a1 > extent[3] || b1 < extent[2] || b1 > extent[3]) |
| 859 | { |
| 860 | if (!this->ClipSegment(a0, a1, b0, b1)) |
| 861 | { |
| 862 | // non of the segment is in the data. |
| 863 | return; |
| 864 | } |
| 865 | } |
| 866 | |
| 867 | ptr = this->ImageData->GetScalarPointer(b0, b1, z); |
| 868 | a0 -= b0; |
| 869 | a1 -= b1; |
| 870 | switch (this->ImageData->GetScalarType()) |
| 871 | { |
| 872 | vtkTemplateMacro(vtkImageCanvasSource2DDrawSegment( |
| 873 | this->ImageData, this->DrawColor, static_cast<VTK_TT*>(ptr), a0, a1)); |
| 874 | default: |
| 875 | vtkErrorMacro(<< "DrawSegment: Cannot handle ScalarType."); |
| 876 | } |
| 877 | this->Modified(); |
| 878 | } |
| 879 | |
| 880 | //------------------------------------------------------------------------------ |
| 881 | // Clips a line segment so it will be in bounds. |
no test coverage detected