------------------------------------------------------------------------------ This is more or less ported from vtkFreeTypeTools.
| 572 | //------------------------------------------------------------------------------ |
| 573 | // This is more or less ported from vtkFreeTypeTools. |
| 574 | bool vtkMatplotlibMathTextUtilities::PrepareImageData(vtkImageData* data, int textBbox[4]) |
| 575 | { |
| 576 | // Calculate the bbox's dimensions |
| 577 | int textDims[2]; |
| 578 | textDims[0] = (textBbox[1] - textBbox[0] + 1); |
| 579 | textDims[1] = (textBbox[3] - textBbox[2] + 1); |
| 580 | |
| 581 | // Calculate the size the image needs to be. |
| 582 | int targetDims[3]; |
| 583 | targetDims[0] = textDims[0]; |
| 584 | targetDims[1] = textDims[1]; |
| 585 | targetDims[2] = 1; |
| 586 | // Scale to the next highest power of 2 if required. |
| 587 | if (this->ScaleToPowerOfTwo) |
| 588 | { |
| 589 | targetDims[0] = vtkMath::NearestPowerOfTwo(targetDims[0]); |
| 590 | targetDims[1] = vtkMath::NearestPowerOfTwo(targetDims[1]); |
| 591 | } |
| 592 | |
| 593 | // Calculate the target extent of the image. |
| 594 | int targetExtent[6]; |
| 595 | targetExtent[0] = textBbox[0]; |
| 596 | targetExtent[1] = textBbox[0] + targetDims[0] - 1; |
| 597 | targetExtent[2] = textBbox[2]; |
| 598 | targetExtent[3] = textBbox[2] + targetDims[1] - 1; |
| 599 | targetExtent[4] = 0; |
| 600 | targetExtent[5] = 0; |
| 601 | |
| 602 | // Get the actual image extents and increments |
| 603 | int imageExtent[6]; |
| 604 | double imageSpacing[3]; |
| 605 | data->GetExtent(imageExtent); |
| 606 | data->GetSpacing(imageSpacing); |
| 607 | |
| 608 | // Do we need to reallocate the image memory? |
| 609 | if (data->GetScalarType() != VTK_UNSIGNED_CHAR || data->GetNumberOfScalarComponents() != 4 || |
| 610 | imageExtent[0] != targetExtent[0] || imageExtent[1] != targetExtent[1] || |
| 611 | imageExtent[2] != targetExtent[2] || imageExtent[3] != targetExtent[3] || |
| 612 | imageExtent[4] != targetExtent[4] || imageExtent[5] != targetExtent[5] || |
| 613 | fabs(imageSpacing[0] - 1.0) > 1e-10 || fabs(imageSpacing[1] - 1.0) > 1e-10 || |
| 614 | fabs(imageSpacing[2] - 1.0) > 1e-10) |
| 615 | { |
| 616 | data->SetSpacing(1.0, 1.0, 1.0); |
| 617 | data->SetExtent(targetExtent); |
| 618 | data->AllocateScalars(VTK_UNSIGNED_CHAR, 4); |
| 619 | } |
| 620 | |
| 621 | // Clear the image |
| 622 | memset( |
| 623 | data->GetScalarPointer(), 0, (data->GetNumberOfPoints() * data->GetNumberOfScalarComponents())); |
| 624 | |
| 625 | return true; |
| 626 | } |
| 627 | |
| 628 | //------------------------------------------------------------------------------ |
| 629 | bool vtkMatplotlibMathTextUtilities::GetBoundingBox( |
no test coverage detected