[vtkusers] vtkPolyData to be used with vtkImageStencil.
Anja Ende
anja.ende at googlemail.com
Wed Oct 25 06:18:08 EDT 2006
Hey Hendrik,
Ya, I just managed to figure that out but I do not know how to set the cell
data.
So, my code is as follows:
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);
// Cell data.
vtkCellArray* strips = vtkCellArray::New();
strips->InsertNextCell(4);
strips->InsertCellPoint(0);
strips->InsertCellPoint(1);
strips->InsertCellPoint(2);
strips->InsertCellPoint(3);
polydata->SetStrips(strips);
vtkLinearExtrusionFilter* extrude =
vtkLinearExtrusionFilter::New();
extrude->SetInput(polydata);
extrude->SetScaleFactor(1);
extrude->SetExtrusionTypeToNormalExtrusion();
extrude->SetVector(1, 0, 0);
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 :(
>> image voxels corresponding to your point cloud directly in the image data
array.
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.
Cheers,
Anja
On 25/10/06, Hendrik Belitz <hendrik at darkon.info> wrote:
>
> Hi Anja,
>
> 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.
>
> Regards
> Hendrik
>
> 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
>
>
>
> --
> program (pro'-gram) [n] A magic spell cast over a computer allowing
> it to turn one's input into error messages.
> tr.v. To engage in a pastime similar to banging one's head against a
> wall, but with fewer opportunities for reward.
>
--
Cheers,
Anja
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20061025/cba429ed/attachment.htm>
More information about the vtkusers
mailing list