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

Method DrawPointSprites

IO/ExportPDF/vtkPDFContextDevice2D.cxx:794–907  ·  view source on GitHub ↗

------------------------------------------------------------------------------

Source from the content-addressed store, hash-verified

792
793//------------------------------------------------------------------------------
794void 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;

Callers 1

PaintMethod · 0.45

Calls 15

PrepareImageDataMethod · 0.95
PushGraphicsStateMethod · 0.95
PopGraphicsStateMethod · 0.95
ApplyFillAlphaMethod · 0.95
HPDF_LoadRawImageFromMemFunction · 0.85
HPDF_Page_DrawImageFunction · 0.85
GetScalarPointerMethod · 0.80
assertFunction · 0.50
maxFunction · 0.50
GetScalarTypeMethod · 0.45
GetDimensionsMethod · 0.45

Tested by 1

PaintMethod · 0.36