Hi everyone,<br><br>I had asked this question a while back but did not get much response. I hope I have better luck this time.<br><br>I am trying to create a vtkPolyData object that can be used with vtkPolyDataToImageStencil and vtkImageStencil. Basically, I want to extract a 2D region from my image.
<br><br>I tried the following after looking at some of the test files:<br><br>//----------------------------------------------------------------------------------<br><br> float pts[4][3] = {{-55.7812, 9.375, 0.0
},<br> {-18.2812, 49.6875, 0.0},<br> {21.0938, 14.0625, 0.0},<br> {5.15625, -29.0625, 0.0}};<br><br> vtkFloatArray* pcoords = vtkFloatArray::New();<br> pcoords->SetNumberOfComponents(3);
<br> pcoords->SetNumberOfTuples(4);<br> for (int i=0; i<4; i++)<br> {<br> pcoords->SetTuple(i, pts[i]);<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> vtkPolyDataToImageStencil* dataToStencil = vtkPolyDataToImageStencil::New();<br> dataToStencil->SetInput(polydata);<br><br> vtkImageStencil* stencil = vtkImageStencil::New();<br>
stencil->SetInput(myviewer->GetOutput());<br> stencil->SetStencil(dataToStencil->GetOutput());<br> stencil->ReverseStencilOff();<br> stencil->SetBackgroundValue(128);
<br><br> stencil->Update();<br><br> stencil->Delete();<br> dataToStencil->Delete();<br> points->Delete();<br> pcoords->Delete();<br clear="all"><br>
//----------------------------------------------------------------------------<br><br>When I run this, it fails with the error: Can't build OBB tree- no data available.<br><br>I guess this is because of the way I have set up the vtkPolyData. Can someone tell me how to set it up so this primitive example is working.
<br><br>Another question, for the vtkImageStencil to work, is it necessary that the input polydata is 'closed' or does it close the path by itself.<br><br>I hope someone can help me with this.<br><br>Best,<br><br>Anja