[vtkusers] Writing text in an image
Martijn de Greef
m.d.greef at gmail.com
Thu Jul 14 07:28:41 EDT 2011
Hi Alexis,
If my understanding is correct you really want to render the text as an
image. In the case you are interested in having text as an overlay you could
look at the vtkCornerAnnotation or vtkTextActor class.
Regards,
Martijn
2011/7/8 Alexis Cheng <acheng_1221 at hotmail.com>
> Hi All,
>
> 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.
>
> //////////////////
> //2D polydata -> 3D polyData -> image data
> vtkSmartPointer<vtkVectorText> textSource =
> vtkSmartPointer<vtkVectorText>::New();
> textSource->SetText("Hello");
> textSource->Update();
>
> vtkSmartPointer<vtkLinearExtrusionFilter> linExtFilter =
> vtkSmartPointer<vtkLinearExtrusionFilter>::New();
> linExtFilter->SetCapping(1);
> linExtFilter->SetExtrusionTypeToNormalExtrusion();
> linExtFilter->SetScaleFactor(0.1);
> linExtFilter->SetInput(textSource->GetOutput());
> linExtFilter->Update();
>
> vtkSmartPointer<vtkPolyDataToImageStencil> polyToImageStencil =
> vtkSmartPointer<vtkPolyDataToImageStencil>::New();
> polyToImageStencil->SetInput(linExtFilter->GetOutput());
> polyToImageStencil->SetOutputWholeExtent(MTImage->GetExtent());
> polyToImageStencil->Update();
>
> vtkSmartPointer<vtkImageStencil> imgStencil =
> vtkSmartPointer<vtkImageStencil>::New();
> imgStencil->SetInput(BlackImage);
> imgStencil->SetStencil(polyToImageStencil->GetOutput());
> imgStencil->ReverseStencilOff();
> imgStencil->SetBackgroundValue(255);
> imgStencil->Update();
>
> vtkSmartPointer<vtkPNGWriter> textWriter =
> vtkSmartPointer<vtkPNGWriter>::New();
> textWriter->SetFileName("textImage.png");
> textWriter->SetInput(imgStencil->GetOutput());
> textWriter->Write();
> //////////////////////
> //2D polydata -> image
> vtkSmartPointer<vtkVectorText> textSource =
> vtkSmartPointer<vtkVectorText>::New();
> textSource->SetText("Hello");
> textSource->Update();
>
> vtkSmartPointer<vtkProbeFilter> textFilter =
> vtkSmartPointer<vtkProbeFilter>::New();
> textFilter->SetSource(textImage);
> textFilter->SetInputConnection(textSource->GetOutputPort());
> textFilter->Update();
>
> vtkSmartPointer<vtkImageCast> textCast =
> vtkSmartPointer<vtkImageCast>::New();
> textCast->SetOutputScalarTypeToUnsignedChar();
> textCast->SetInput(textFilter->GetOutput());
> textCast->Update();
> //////////////////////
>
> Am I using these classes and filters correctly? Are there any methods that
> facilitate annotating images with text? Thank you in advance.
>
> Regards,
> Alexis Cheng
> Electrical Engineering
> University of British Columbia
>
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the VTK FAQ at:
> http://www.vtk.org/Wiki/VTK_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtkusers
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20110714/7e5313b8/attachment.htm>
More information about the vtkusers
mailing list