[vtkusers] Example for labeling Cell Data

Darshan Pai darshanpai at gmail.com
Fri Jun 11 13:47:52 EDT 2010


I have been trying to use vtkLabeledDataMapper to label scalars which have
been defined as vtkCellData in the corresponding Polydata

I always get an error : Could not find label array (index0) in input

Not sure what I am doing wrong . Any help appreciated

Sample Code
vtkSmartPointer<vtkPlaneSource> plsrc =
vtkSmartPointer<vtkPlaneSource>::New();
  plsrc->SetNormal(1,0,0);
  plsrc->SetCenter(1,1,1);
  plsrc->SetXResolution(10);
  plsrc->SetYResolution(10);
  plsrc->Update();

  cout << "Number of Cells " << plsrc->GetOutput()->GetNumberOfCells() <<
endl;
  vtkSmartPointer<vtkDoubleArray> dblarray =
vtkSmartPointer<vtkDoubleArray>::New();

  dblarray->SetNumberOfValues(plsrc->GetOutput()->GetNumberOfCells());
  dblarray->SetName("Cel1");
  for (int i = 0 ; i < plsrc->GetOutput()->GetNumberOfCells() ; i++)
  {
      dblarray->SetValue(i,vtkMath::Random(0,100));
  }

  plsrc->GetOutput()->GetCellData()->SetScalars(dblarray);

  vtkSmartPointer<vtkLabeledDataMapper> ldm =
vtkSmartPointer<vtkLabeledDataMapper>::New();
  ldm->SetInput(plsrc->GetOutput());
  ldm->SetLabelFormat("%g");
  //ldm->SetFieldDataName("Cel1");
  ldm->SetLabelModeToLabelScalars();
  //ldm->SetFontSize(45);

  vtkSmartPointer<vtkActor2D> act2D = vtkSmartPointer<vtkActor2D>::New();
  act2D->SetMapper(ldm);


  vtkSmartPointer<vtkPolyDataMapper> mapper =
    vtkSmartPointer<vtkPolyDataMapper>::New();
  mapper->SetInputConnection( plsrc->GetOutputPort() );
  mapper->SetScalarModeToUseCellData();

  vtkSmartPointer<vtkActor> act = vtkSmartPointer<vtkActor>::New();
  act->SetMapper(mapper);

  renderer->AddActor(act);
  renderer->AddActor2D(act2D);

Regards
Darshan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20100611/f305099c/attachment.htm>


More information about the vtkusers mailing list