<html>
<head>
<style><!--
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
font-size: 10pt;
font-family:Tahoma
}
--></style>
</head>
<body class='hmmessage'><div dir='ltr'>
Hi All,<br><br>I am looking for a method to write text into a vtkImage or make a vtkImage with text in it. I have tried a couple of methods with no success. Below is what I have tried.<br><br>//////////////////<br>//2D polydata -> 3D polyData -> image data<br> vtkSmartPointer<vtkVectorText> textSource = vtkSmartPointer<vtkVectorText>::New();<br> textSource->SetText("Hello");<br> textSource->Update();<br><br> vtkSmartPointer<vtkLinearExtrusionFilter> linExtFilter = vtkSmartPointer<vtkLinearExtrusionFilter>::New();<br> linExtFilter->SetCapping(1);<br> linExtFilter->SetExtrusionTypeToNormalExtrusion();<br> linExtFilter->SetScaleFactor(0.1);<br> linExtFilter->SetInput(textSource->GetOutput());<br> linExtFilter->Update();<br><br> vtkSmartPointer<vtkPolyDataToImageStencil> polyToImageStencil = vtkSmartPointer<vtkPolyDataToImageStencil>::New();<br> polyToImageStencil->SetInput(linExtFilter->GetOutput());<br> polyToImageStencil->SetOutputWholeExtent(MTImage->GetExtent());<br> polyToImageStencil->Update();<br><br> vtkSmartPointer<vtkImageStencil> imgStencil = vtkSmartPointer<vtkImageStencil>::New();<br> imgStencil->SetInput(BlackImage);<br> imgStencil->SetStencil(polyToImageStencil->GetOutput());<br> imgStencil->ReverseStencilOff();<br> imgStencil->SetBackgroundValue(255);<br> imgStencil->Update();<br> <br> vtkSmartPointer<vtkPNGWriter> textWriter = vtkSmartPointer<vtkPNGWriter>::New();<br> textWriter->SetFileName("textImage.png");<br> textWriter->SetInput(imgStencil->GetOutput());<br> textWriter->Write();<br>//////////////////////<br>//2D polydata -> image<br> vtkSmartPointer<vtkVectorText> textSource = vtkSmartPointer<vtkVectorText>::New();<br>
textSource->SetText("Hello");<br>
textSource->Update();<br><br> vtkSmartPointer<vtkProbeFilter> textFilter = vtkSmartPointer<vtkProbeFilter>::New();<br> textFilter->SetSource(textImage);<br> textFilter->SetInputConnection(textSource->GetOutputPort());<br> textFilter->Update();<br><br> vtkSmartPointer<vtkImageCast> textCast = vtkSmartPointer<vtkImageCast>::New();<br> textCast->SetOutputScalarTypeToUnsignedChar();<br> textCast->SetInput(textFilter->GetOutput());<br> textCast->Update();<br>//////////////////////<br><br>Am I using these classes and filters correctly? Are there any methods that facilitate annotating images with text? Thank you in advance.<br><br>Regards,<br>Alexis Cheng<br>Electrical Engineering<br>University of British Columbia<br>                                            </div></body>
</html>