Hi everyone,<br><br>I finally managed to get it working.<br><br>The main key was use SetPolys instead of SetStripes with the vtkPolyData.<br><br>So, the code looks as follows:<br><br>//-----------------------------------------------------------------------------------
<br>vtkFloatArray* pcoords = vtkFloatArray::New();<br>pcoords->SetNumberOfComponents(3);<br>// My polygon vertices<br>pcoords->SetNumberOfTuples(myimagePoints.size());<br>float * ptArray = pts;<br>for (int i=0; i<m_imagePoints.size(); i++)
<br>{<br> pcoords->SetTuple(i, ptArray);<br> ptArray += 3;<br>}<br> <br>// Create vtkPoints and assign pcoords as the internal data array.<br>vtkPoints* points = vtkPoints::New();
<br>points->SetData(pcoords);<br>vtkPolyData* polydata = vtkPolyData::New();<br>polydata->SetPoints(points);<br><br>vtkCellArray* polys = vtkCellArray::New();<br>polys->InsertNextCell(m_imagePoints.size());<br>for (int i = 0; i <
myimagePoints.size(); i++)<br>{<br> polys->InsertCellPoint(i);<br>}<br><br>// vertices connect a polygon <br>polydata->SetPolys(polys);<br><br>vtkLinearExtrusionFilter* extrude = vtkLinearExtrusionFilter::New();
<br>extrude->SetInput(polydata);<br>extrude->SetScaleFactor(1);<br>extrude->SetExtrusionTypeToNormalExtrusion();<br>extrude->SetVector(0, 0, 1);<br><br>vtkPolyDataToImageStencil* dataToStencil = vtkPolyDataToImageStencil::New();
<br>dataToStencil->SetInput(extrude->GetOutput());<br><br>vtkImageStencil* stencil = vtkImageStencil::New();<br>stencil->SetInput(m_viewer->GetOutput());<br>stencil->SetStencil(dataToStencil->GetOutput());
<br>stencil->ReverseStencilOff();<br>stencil->SetBackgroundValue(0);<br><br>stencil->Update();<br><br>//-----------------------------------------------------------------------------------<br><br>Also, the cell data does not need to be closed as VTK closes it with the first cell automatically. Of course, probably it is always a good idea to close it though!
<br><br>The one nagging thing is that the extracted boundaries look pretty jagged. Is there a way to set some sort of anti aliasing filter on the stencil output?<br><br>I hope someone will find this of some use.<br clear="all">
<br>Cheers,<br><br>Anja