[vtkusers] vtkPolyData to be used with vtkImageStencil.

Anja Ende anja.ende at googlemail.com
Wed Oct 25 09:14:08 EDT 2006


Hi Dean,

Thanks for the reply and code fragmant. This really helps!

Your suggestiosn were completely on the money (as usual!). It was the
problem with not closing the loop and the extrusion vector just being copied
and pasted from example code without bothering to understand what it meant!

However, there seems to be a problem with the stencil output:

The points I have chosen are:

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

which should form a triangle.

However, the output looks very weird. The triangle is too small and very
jagged. Also, the dimensions of the triangle seem wrong. There is a
screenshot attached with this message. Please mail me if you cannot see it
on the website and I will send you the screenshot immediately.

Also, here is the latest code now:

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

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);


 vtkCellArray* strips = vtkCellArray::New();
 strips->InsertNextCell(4);
 strips->InsertCellPoint(0);
 strips->InsertCellPoint(1);
 strips->InsertCellPoint(2);
 strips->InsertCellPoint(3); // same coordinates as the first one..

polydata->SetStrips(strips);

vtkLinearExtrusionFilter* extrude = vtkLinearExtrusionFilter::New();
extrude->SetInput(polydata);
extrude->SetScaleFactor(1);
extrude->SetExtrusionTypeToNormalExtrusion();
extrude->SetVector(0, 0, 1);

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

vtkImageStencil* stencil = vtkImageStencil::New();
stencil->SetInput(m_viewer->GetOutput());
stencil->SetStencil(dataToStencil->GetOutput());
stencil->ReverseStencilOn();
stencil->SetBackgroundValue(0);

stencil->Update();

Also, when I add more points, so instead of a triangle have a quadrilateral.
I see a triangle shape being stencilled and the outside the loop some lines
through the image... but they are completely outside the loop. However, I
can see that the shape is completely closed....

Thanks for all the help!

Anja
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20061025/d9c69025/attachment.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: screen grab stencil output.png
Type: image/png
Size: 5549 bytes
Desc: not available
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20061025/d9c69025/attachment.png>


More information about the vtkusers mailing list