[vtkusers] vtkPolyData to be used with vtkImageStencil.

Anja Ende anja.ende at googlemail.com
Wed Oct 25 05:22:16 EDT 2006


Hi everyone,

I had asked this question a while back but did not get much response. I hope
I have better luck this time.

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.

I tried the following after looking at some of the test files:

//----------------------------------------------------------------------------------

             float pts[4][3] = {{-55.7812, 9.375, 0.0},
                {-18.2812, 49.6875, 0.0},
                {21.0938, 14.0625, 0.0},
                {5.15625, -29.0625, 0.0}};

             vtkFloatArray* pcoords = vtkFloatArray::New();
             pcoords->SetNumberOfComponents(3);
             pcoords->SetNumberOfTuples(4);
             for (int i=0; i<4; i++)
             {
                 pcoords->SetTuple(i, pts[i]);
             }
             // Create vtkPoints and assign pcoords as the internal data
array.
             vtkPoints* points = vtkPoints::New();
             points->SetData(pcoords);
             vtkPolyData* polydata = vtkPolyData::New();
             polydata->SetPoints(points);

             vtkPolyDataToImageStencil* dataToStencil =
vtkPolyDataToImageStencil::New();
             dataToStencil->SetInput(polydata);

             vtkImageStencil* stencil = vtkImageStencil::New();
             stencil->SetInput(myviewer->GetOutput());
             stencil->SetStencil(dataToStencil->GetOutput());
             stencil->ReverseStencilOff();
             stencil->SetBackgroundValue(128);

             stencil->Update();

             stencil->Delete();
             dataToStencil->Delete();
             points->Delete();
             pcoords->Delete();

//----------------------------------------------------------------------------

When I run this, it fails with the error: Can't build OBB tree- no data
available.

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.

Another question, for the vtkImageStencil to work, is it necessary that the
input polydata is 'closed' or does it close the path by itself.

I hope someone can help me with this.

Best,

Anja
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20061025/f43dd1b3/attachment.htm>


More information about the vtkusers mailing list