[vtkusers] vtkPolyData to be used with vtkImageStencil.
Dean Inglis
dean.inglis at sympatico.ca
Wed Oct 25 07:56:39 EDT 2006
Hi Anja,
have a look at VTK/Examples/GUI/Tcl/ImageTracerWidget.tcl
you need a closed polydata, and you need to extrude normal
to the plane of your points, which is the x-y plane so the extrusion
vector is 0,0,1. Also, I would back up the z-coord of the
x-y points by a small amount, say 0.5, then extrude by 1.
You could then use vtkImageAccumulate to calculate the ROI
histogram and basic image stats (min,max,mean,stdev).
Dean
So, my code is as follows:
/************************************ back up behind the x-y plane a wee bit
float zoffset =-0.5;
/************************************
float pts[4][3] = {{-55.7812, 9.375, zoffset},
{-18.2812, 49.6875,zoffset},
{21.0938, 14.0625, zoffset},
{5.15625, -29.0625, zoffset}};
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);
// Cell data.
vtkCellArray* strips = vtkCellArray::New();
strips->InsertNextCell(4);
strips->InsertCellPoint(0);
strips->InsertCellPoint(1);
strips->InsertCellPoint(2);
strips->InsertCellPoint(3);
/********************************************** close the loop
strips->InsertCellPoint(0);
/**********************************************
polydata->SetStrips(strips);
vtkLinearExtrusionFilter* extrude =
vtkLinearExtrusionFilter::New();
extrude->SetInput(polydata);
extrude->SetScaleFactor(1);
extrude->SetExtrusionTypeToNormalExtrusion();
/********************************************** k hat direction
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(128);
stencil->Update();
Now, the output from the stencil is basically the original image. So,
nothing seems to be getting done :(
More information about the vtkusers
mailing list