Hey Hendrik,<br><br>Ya, I just managed to figure that out but I do not know how to set the cell data.<br><br>So, my code is as follows:<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> // Cell data.<br> vtkCellArray* strips = vtkCellArray::New();<br> strips->InsertNextCell(4);<br> strips->InsertCellPoint(0);<br> strips->InsertCellPoint(1);
<br> strips->InsertCellPoint(2);<br> strips->InsertCellPoint(3);<br> <br> polydata->SetStrips(strips);<br><br> vtkLinearExtrusionFilter* extrude = vtkLinearExtrusionFilter::New();
<br> extrude->SetInput(polydata);<br> extrude->SetScaleFactor(1);<br> extrude->SetExtrusionTypeToNormalExtrusion();<br> extrude->SetVector(1, 0, 0);<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(128);<br><br> stencil->Update();<br><br>Now, the output from the stencil is basically the original image. So, nothing seems to be getting done :(
<br><br>>> image voxels corresponding to your point cloud directly in the image data array.<br><br>This could be an option. I have to figure out how I can access the underlying image data, make a copy and manipulate it myself.
<br><br>Cheers,<br>Anja<br><br><div><span class="gmail_quote">On 25/10/06, <b class="gmail_sendername">Hendrik Belitz</b> <<a href="mailto:hendrik@darkon.info">hendrik@darkon.info</a>> wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div>Hi Anja,<br><br>sorry for contacting you directly, but I only have read-only access to the vtk list from my office computer. I assume your stencil operation fails because your PolyData is lacking cell data which is AFAIK needed to build the stencil. I'm not absolutely sure what to do here, maybe the best way is not to use PolyDataToImageStencil at all, but to set the image voxels corresponding to your point cloud directly in the image data array.
<br><br>Regards<br> Hendrik<br><br><table><tbody><tr><td bgcolor="blue" width="5"> </td><td>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><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
</td></tr></tbody></table><br><br><br><br><p>-- <br>program (pro'-gram) [n] A magic spell cast over a computer allowing<br>it to turn one's input into error messages.<br>tr.v. To engage in a pastime similar to banging one's head against a
<br>wall, but with fewer opportunities for reward.</p></div>
</blockquote></div><br><br clear="all"><br>-- <br>Cheers,<br><br>Anja