[vtkusers] Using vtkLabeledDataMapper to display a string at each point

David Doria daviddoria+vtk at gmail.com
Wed Feb 10 16:22:48 EST 2010


I can display a scalar at every point by using:

vtkIntArray* ints = vtkIntArray::New();
... fill ints ...
polydata->GetPointData()->SetScalars(ints);

  vtkSmartPointer<vtkLabeledDataMapper> labelMapper =
      vtkSmartPointer<vtkLabeledDataMapper>::New();
  labelMapper->SetInput(polydata);
  labelMapper->SetLabelModeToLabelScalars();

Now I wanted to display a string (variable length) at each point. I was not
allowed to SetScalars to a vtkStringArray because vtkStringArray is not a
subclass of vtkDataArray. I tried to use vtkCharArray, but then only the
first character of the string is displayed near each point.

To clarify, I want to do this:

  vtkSmartPointer<vtkStringArray> strings =
      vtkSmartPointer<vtkStringArray>::New();
  strings->SetName("strings");
  strings->InsertNextValue("one");
  strings->InsertNextValue("two");
  strings->InsertNextValue("three");

 polydata->GetPointData()->SetScalars(strings);

  vtkSmartPointer<vtkLabeledDataMapper> labelMapper =
      vtkSmartPointer<vtkLabeledDataMapper>::New();
  labelMapper->SetInput(points);
  labelMapper->SetLabelModeToLabelScalars();

Anyone know how this could be accomplished?

Thanks,

David
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20100210/913d2205/attachment.htm>


More information about the vtkusers mailing list