[vtkusers] update on the vtkImageStencil and vtkPolyData
Anja Ende
anja.ende at googlemail.com
Thu Oct 26 06:33:19 EDT 2006
Hi everyone,
I finally managed to get it working.
The main key was use SetPolys instead of SetStripes with the vtkPolyData.
So, the code looks as follows:
//-----------------------------------------------------------------------------------
vtkFloatArray* pcoords = vtkFloatArray::New();
pcoords->SetNumberOfComponents(3);
// My polygon vertices
pcoords->SetNumberOfTuples(myimagePoints.size());
float * ptArray = pts;
for (int i=0; i<m_imagePoints.size(); i++)
{
pcoords->SetTuple(i, ptArray);
ptArray += 3;
}
// 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* polys = vtkCellArray::New();
polys->InsertNextCell(m_imagePoints.size());
for (int i = 0; i < myimagePoints.size(); i++)
{
polys->InsertCellPoint(i);
}
// vertices connect a polygon
polydata->SetPolys(polys);
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->ReverseStencilOff();
stencil->SetBackgroundValue(0);
stencil->Update();
//-----------------------------------------------------------------------------------
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!
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?
I hope someone will find this of some use.
Cheers,
Anja
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20061026/63421d4e/attachment.htm>
More information about the vtkusers
mailing list