[vtkusers] How to see Unicode characters on vtkActor2D (stack overflow runtime error)

jimmigoo jimmigoo at gmail.com
Sun Oct 25 17:28:24 EDT 2015


Hi everybody!

I'm trying to see Unicode characters (depending on selected True Type Font
loaded file) on VTK, in details I would like to see these symbols on a
vtkActor2D.

I wrote the following code, using the vtkUnicodeString::from_utf8 function,
entering as input parameter, a std::string containing a UTF8 coded string.

Unfortunately, this code fails at run time, as in the attached images
(Rendering\FreeType\vtkFreeTypeUtilities.cxx is unable to create font, and
Rendering\FreeTypeOpenGL\vtkOpenGLFreeTypeTextMapper.cxx returns Render - no
font).

I tried using both

#define vtkRenderingCore_AUTOINIT
4(vtkInteractionStyle,vtkRenderingFreeType,vtkRenderingFreeTypeOpenGL,vtkRenderingOpenGL)
#define vtkRenderingVolume_AUTOINIT 1(vtkRenderingVolumeOpenGL)

and 

#include <vtkAutoInit.h>
VTK_MODULE_INIT(vtkInteractionStyle);
VTK_MODULE_INIT(vtkRenderingFreeType);
VTK_MODULE_INIT(vtkRenderingFreeTypeOpenGL);
VTK_MODULE_INIT(vtkRenderingOpenGL);

VTK_MODULE_INIT(vtkRenderingVolumeOpenGL);

So.. I need your help.. how should I do to let this code work and show the
proper Unicode characters?

I'm looking for your kind reply.

Best Regards, 

jimmigoo

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


vtkPoints*                            l_pPoints;
vtkUnicodeStringArray*          l_pStringData;
vtkIntArray*                         l_pSizes;
vtkPointSource*                    l_pPointSource;
vtkPointSetToLabelHierarchy*  l_pPointSetToLabelHierarchy;
vtkLabelPlacementMapper*      l_pLabelPlacementMapper;

std::string fontFile("DejaVuSans.ttf");

l_strFileName = "Ҋҹӂӫ";

l_strTest = l_strFileName.ToUTF8();

l_pPoints = vtkPoints::New();
l_pPoints->Allocate(1);
l_pPoints->InsertPoint(0, 0.0, 0.0, 0.0);

l_pStringData = vtkUnicodeStringArray::New();
l_pStringData->SetName("labels");
l_pStringData->InsertNextValue(vtkUnicodeString::from_utf8(l_strTest));
std::string l_strFontFile("DejaVuSans.ttf");

l_pSizes = vtkIntArray::New();
l_pSizes->SetNumberOfValues(1);
l_pSizes->SetName("sizes");
l_pSizes->SetValue(0, 0);

l_pPointSource = vtkPointSource::New();
l_pPointSource->SetNumberOfPoints(1);
l_pPointSource->Update();
l_pPointSource->GetOutput()->SetPoints(l_pPoints);
l_pPointSource->GetOutput()->GetPointData()->AddArray(l_pStringData);
l_pPointSource->GetOutput()->GetPointData()->AddArray(l_pSizes);
l_pPointSource->Update();

vtkTextProperty* l_pTextProperty = vtkTextProperty::New();
l_pTextProperty->SetFontFamily(VTK_FONT_FILE);
l_pTextProperty->SetFontFile(l_strFontFile.c_str());
l_pTextProperty->SetFontSize(24);
l_pTextProperty->BoldOn();

l_pPointSetToLabelHierarchy = vtkPointSetToLabelHierarchy::New();
l_pPointSetToLabelHierarchy->SetInputConnection(l_pPointSource->GetOutputPort());
l_pPointSetToLabelHierarchy->SetTextProperty(l_pTextProperty);
l_pPointSetToLabelHierarchy->SetLabelArrayName("labels");
l_pPointSetToLabelHierarchy->SetPriorityArrayName("sizes");
l_pPointSetToLabelHierarchy->Update();

l_pLabelPlacementMapper = vtkLabelPlacementMapper::New();
l_pLabelPlacementMapper->SetInputConnection(l_pPointSetToLabelHierarchy->GetOutputPort());
l_pLabelPlacementMapper->UseUnicodeStringsOn();
l_pLabelPlacementMapper->Update();

vtkActor2D* l_pActor = vtkActor2D::New();
l_pActor->SetMapper(l_pLabelPlacementMapper);
   
vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();
vtkRenderWindow *renWin = vtkRenderWindow::New();
iren->SetRenderWindow(renWin);
renWin->Delete();
  
vtkRenderer *renderer = vtkRenderer::New();
renWin->AddRenderer(renderer);
renderer->Delete();
  
renderer->SetBackground(0.0,0.0,0.0); 
renderer->SetAmbient(1.0,1.0,1.0); 
renWin->SetSize(300,300);

renderer->AddActor(l_pActor);
renWin->Render();
renderer->ResetCamera();
  
renWin->Render();

iren->Start();

------

<http://vtk.1045678.n5.nabble.com/file/n5734547/output1.png> 

<http://vtk.1045678.n5.nabble.com/file/n5734547/output2.png> 








--
View this message in context: http://vtk.1045678.n5.nabble.com/How-to-see-Unicode-characters-on-vtkActor2D-stack-overflow-runtime-error-tp5734547.html
Sent from the VTK - Users mailing list archive at Nabble.com.


More information about the vtkusers mailing list