[vtkusers] vtkPolyData to be used with vtkImageStencil.
Anja Ende
anja.ende at googlemail.com
Wed Oct 25 09:53:36 EDT 2006
Hi,
Thanks. Ya, I will try to visualize this. Hopefully this will provide some
clues.
There is something very weird going on... For simple triangle data, the
lines seem to become parallel.... and I am getting a really screwy stenciled
shape. I will look into it and try to figure it out. Will keep the list
updated.
Cheers and thanks again,
Anja
On 25/10/06, Dean Inglis <dean.inglis at camris.ca> wrote:
>
> Anja,
>
> sorry, I didn't look closely at your points: I thought
> they formed a square/rectangle. So the code for vtkCellArray
> really should be as you show below. The z offset is
> necessary for the vtkPolyDataToImageStencil to work:
> it does not work with polylines, but needs surfaces,
> so the extrusion makes a "ribbon". If you pass the polyData
> output of the extrusion filter to a vtkPolyDataMapper/vtkActor
> and visualize it you will see what I mean. This will also
> help with unserstanding possible errors: make sure your image
> actor can be manipulated with a interactorStyleTrackballCamera
> and not interactorStyleImage. Also, I would change the background color
> of your renerwindow to something other than black. If your 2D (?) image
> has z-thickness, you may have to change the z offset and
> extrusion scale. Also, if the triangle is too acute relative
> to the pixel dimensions, or if your closed polydata loops back on
> itself or has "knots", you can get erroneous results.
>
> Dean
>
>
> -----Original Message-----
> From: Anja Ende [mailto:anja.ende at googlemail.com]
> Sent: Wednesday, October 25, 2006 9:16 AM
> To: Dean's business account
> Cc: vtkusers at vtk.org
> Subject: Re: [vtkusers] vtkPolyData to be used with vtkImageStencil.
>
>
> Another question that I wanted to ask is why do we set the z offset?
> Clearly, this is needed as the output is completely different... But what
> does it actually do?
>
> Thanks,
> Anja
>
>
> On 25/10/06, Anja Ende <anja.ende at googlemail.com> wrote:
> 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
>
>
>
>
>
> --
> Cheers,
>
> Anja
>
--
Cheers,
Anja
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20061025/de957d0d/attachment.htm>
More information about the vtkusers
mailing list