------------------------------------------------------------------------------
| 792 | |
| 793 | //------------------------------------------------------------------------------ |
| 794 | void vtkPDFContextDevice2D::DrawPointSprites( |
| 795 | vtkImageData* spriteIn, float* points, int n, unsigned char* colors, int nc_comps) |
| 796 | { |
| 797 | assert(points); |
| 798 | assert(n > 0); |
| 799 | assert(nc_comps == 0 || colors); |
| 800 | assert(spriteIn); |
| 801 | |
| 802 | vtkImageData* rgb = this->PrepareImageData(spriteIn); |
| 803 | if (!rgb) |
| 804 | { |
| 805 | vtkErrorMacro("Unsupported point sprite format."); |
| 806 | return; |
| 807 | } |
| 808 | |
| 809 | assert(rgb->GetScalarType() == VTK_UNSIGNED_CHAR); |
| 810 | assert(rgb->GetNumberOfScalarComponents() == 3); |
| 811 | |
| 812 | int dims[3]; |
| 813 | rgb->GetDimensions(dims); |
| 814 | vtkIdType numPoints = rgb->GetNumberOfPoints(); |
| 815 | unsigned char* bufIn = static_cast<unsigned char*>(rgb->GetScalarPointer()); |
| 816 | |
| 817 | const float sizeFactor = this->Pen->GetWidth() / static_cast<float>(std::max(dims[0], dims[1])); |
| 818 | const float width = dims[0] * sizeFactor; |
| 819 | const float height = dims[1] * sizeFactor; |
| 820 | const float halfWidth = width * 0.5f; |
| 821 | const float halfHeight = height * 0.5f; |
| 822 | |
| 823 | this->PushGraphicsState(); |
| 824 | |
| 825 | // The HPDF_Images are cleaned up by libharu when we finish writing the file. |
| 826 | typedef std::map<vtkColor3f, HPDF_Image> SpriteMap; |
| 827 | SpriteMap spriteMap; |
| 828 | |
| 829 | for (int i = 0; i < n; ++i) |
| 830 | { |
| 831 | const float* p = points + 2 * i; |
| 832 | |
| 833 | vtkColor3f color; |
| 834 | unsigned char alpha = 255; |
| 835 | if (colors) |
| 836 | { |
| 837 | unsigned char* c = colors + nc_comps * i; |
| 838 | switch (nc_comps) |
| 839 | { |
| 840 | case 3: |
| 841 | color.Set(c[0] / 255.f, c[1] / 255.f, c[2] / 255.f); |
| 842 | break; |
| 843 | |
| 844 | case 4: |
| 845 | color.Set(c[0] / 255.f, c[1] / 255.f, c[2] / 255.f); |
| 846 | alpha = c[3]; |
| 847 | break; |
| 848 | |
| 849 | default: |
| 850 | vtkErrorMacro("Unsupported number of color components: " << nc_comps); |
| 851 | continue; |