[vtkusers] vtkPolyDataToImageStencil generates noise in ImageData

Kacper Pluta kacper.pluta at gmail.com
Mon Oct 3 05:25:24 EDT 2011


I have very complex polydata and when I use vtkPolyDataToImageStencil ->
vtkImageStencil my ImageData contains much noise. I fixed it by
vtkImplicitPolyData -> vtkImplicitFunctionToImageStencil -> vtkImageStencil,
but now the whole process is very slow. How I can fix my polydata to work
with the first solution? Or, how to speed up
vtkImplicitFunctionToImageStencil?

(vtk 5.6.1)

vtkImageData *whiteImage = vtkImageData::New();
  double bounds[6];
  polyData->GetBounds(bounds);
  double spacing[3];
  spacing[0] = 0.03;
  spacing[1] =  0.03;
  spacing[2] =  0.03;
  whiteImage->SetSpacing(spacing);


  int dim[3];
  for (int i = 0; i < 3; i++)
    {
    dim[i] = static_cast<int>(ceil((bounds[i * 2 + 1] - bounds[i * 2]) /
spacing[i]));
    }

  whiteImage->SetDimensions(dim);
  whiteImage->SetExtent(0, dim[0] - 1, 0, dim[1] - 1, 0, dim[2] - 1);

  double origin[3];

  origin[0] = bounds[0] + spacing[0] / 2;
  origin[1] = bounds[2] + spacing[1] / 2;
  origin[2] = bounds[4] + spacing[2] / 2;
  whiteImage->SetOrigin(origin);

  whiteImage->SetScalarTypeToUnsignedShort();
  whiteImage->AllocateScalars();

  unsigned short inval = 255;
  unsigned short outval = 0;
  vtkIdType count = whiteImage->GetNumberOfPoints();

  for (vtkIdType i = 0; i < count; ++i)
  {
    whiteImage->GetPointData()->GetScalars()->SetTuple1(i, inval);
  }

/*
  vtkPolyDataToImageStencil *pol2stenc = vtkPolyDataToImageStencil::New();
  pol2stenc->SetInput(polyData);
  pol2stenc->SetOutputOrigin(origin);
  pol2stenc->SetOutputSpacing(spacing);
  pol2stenc->SetOutputWholeExtent(whiteImage->GetExtent());
  pol2stenc->Update();
*/

  vtkImplicitFunctionToImageStencil *func2stenc =
vtkImplicitFunctionToImageStencil::New();
  func2stenc->SetThreshold(0.1);
  func2stenc->SetInput(polyData);
  func2stenc->SetOutputOrigin(origin);
  func2stenc->SetOutputSpacing(spacing);
  func2stenc->SetOutputWholeExtent(whiteImage->GetExtent());
  func2stenc->Update();

  vtkImageStencil *imgstenc = vtkImageStencil::New();
  imgstenc->SetInput(whiteImage);
  imgstenc->SetStencil(pol2stenc->GetOutput());
  imgstenc->ReverseStencilOff();
  imgstenc->SetBackgroundValue(outval);
  imgstenc->Update();

-- 
"If you build your empire on money, it'll fall like a house of cards, if you
build it on love, you've built Taj Mahal!" - Mark Hartmaier
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20111003/82c9d617/attachment.htm>


More information about the vtkusers mailing list