| 684 | } |
| 685 | } |
| 686 | void ReplaceMaskColorWithBackgroundColor(vtkImageData* finalImage, vtkWordCloud* wordCloud) |
| 687 | { |
| 688 | auto colors = vtkSmartPointer<vtkNamedColors>::New(); |
| 689 | |
| 690 | vtkColor3ub backgroundColor = colors->GetColor3ub(wordCloud->GetBackgroundColorName().c_str()); |
| 691 | unsigned char bkgR = backgroundColor.GetData()[0]; |
| 692 | unsigned char bkgG = backgroundColor.GetData()[1]; |
| 693 | unsigned char bkgB = backgroundColor.GetData()[2]; |
| 694 | |
| 695 | vtkColor3ub maskColor = colors->GetColor3ub(wordCloud->GetMaskColorName().c_str()); |
| 696 | unsigned char maskR = maskColor.GetData()[0]; |
| 697 | unsigned char maskG = maskColor.GetData()[1]; |
| 698 | unsigned char maskB = maskColor.GetData()[2]; |
| 699 | |
| 700 | vtkImageIterator<unsigned char> finalIt(finalImage, finalImage->GetExtent()); |
| 701 | while (!finalIt.IsAtEnd()) |
| 702 | { |
| 703 | auto finalSpan = finalIt.BeginSpan(); |
| 704 | while (finalSpan != finalIt.EndSpan()) |
| 705 | { |
| 706 | unsigned char R, G, B; |
| 707 | R = *finalSpan; |
| 708 | G = *(finalSpan + 1); |
| 709 | B = *(finalSpan + 2); |
| 710 | // If the pixel does not contain the background color, skip |
| 711 | // it. Otherwise replace it with the background color. |
| 712 | if (R != maskR && G != maskG && B != maskB) |
| 713 | { |
| 714 | finalSpan += 3; |
| 715 | continue; |
| 716 | } |
| 717 | else |
| 718 | { |
| 719 | *finalSpan = bkgR; |
| 720 | *(finalSpan + 1) = bkgG; |
| 721 | *(finalSpan + 2) = bkgB; |
| 722 | } |
| 723 | finalSpan += 3; |
| 724 | } |
| 725 | finalIt.NextSpan(); |
| 726 | } |
| 727 | } |
| 728 | |
| 729 | void ShowColorSeriesNames(ostream& os) |
| 730 | { |
no test coverage detected