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?<br clear="all">
<br>(vtk 5.6.1)<br><br>vtkImageData *whiteImage = vtkImageData::New(); <br> double bounds[6];<br> polyData->GetBounds(bounds);<br> double spacing[3];<br> spacing[0] = 0.03;<br> spacing[1] = 0.03;<br> spacing[2] = 0.03;<br>
whiteImage->SetSpacing(spacing);<br> <br><br> int dim[3];<br> for (int i = 0; i < 3; i++)<br> {<br> dim[i] = static_cast<int>(ceil((bounds[i * 2 + 1] - bounds[i * 2]) / spacing[i]));<br> }<br><br>
whiteImage->SetDimensions(dim);<br> whiteImage->SetExtent(0, dim[0] - 1, 0, dim[1] - 1, 0, dim[2] - 1);<br> <br> double origin[3];<br><br> origin[0] = bounds[0] + spacing[0] / 2;<br> origin[1] = bounds[2] + spacing[1] / 2;<br>
origin[2] = bounds[4] + spacing[2] / 2;<br> whiteImage->SetOrigin(origin);<br> <br> whiteImage->SetScalarTypeToUnsignedShort();<br> whiteImage->AllocateScalars();<br> <br> unsigned short inval = 255;<br> unsigned short outval = 0;<br>
vtkIdType count = whiteImage->GetNumberOfPoints();<br> <br> for (vtkIdType i = 0; i < count; ++i)<br> {<br> whiteImage->GetPointData()->GetScalars()->SetTuple1(i, inval);<br> }<br> <br>/* <br> vtkPolyDataToImageStencil *pol2stenc = vtkPolyDataToImageStencil::New();<br>
pol2stenc->SetInput(polyData);<br> pol2stenc->SetOutputOrigin(origin);<br> pol2stenc->SetOutputSpacing(spacing);<br> pol2stenc->SetOutputWholeExtent(whiteImage->GetExtent());<br> pol2stenc->Update();<br>
*/<br><br> vtkImplicitFunctionToImageStencil *func2stenc = vtkImplicitFunctionToImageStencil::New();<br> func2stenc->SetThreshold(0.1);<br>
func2stenc->SetInput(polyData);<br>
func2stenc->SetOutputOrigin(origin);<br>
func2stenc->SetOutputSpacing(spacing);<br>
func2stenc->SetOutputWholeExtent(whiteImage->GetExtent());<br>
func2stenc->Update();<br> <br> vtkImageStencil *imgstenc = vtkImageStencil::New();<br> imgstenc->SetInput(whiteImage);<br> imgstenc->SetStencil(pol2stenc->GetOutput());<br> imgstenc->ReverseStencilOff();<br>
imgstenc->SetBackgroundValue(outval);<br> imgstenc->Update();<br><br>-- <br>"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<br>
<br>