[vtkusers] Help displaying Plane
Shawn Waldon
shawn.waldon at kitware.com
Fri Aug 26 09:39:51 EDT 2016
Hi Albert,
Sounds like you figured it out. Here is a clarification for future readers:
A vtkPlaneSource's output is always a parallelogram (square, rectangles and
rhombi are special cases of this). SetOrigin sets one corner of the plane.
SetPoint1 and SetPoint2 set the corners adjacent to that one. All of these
points are in world coordinates not relative to each other. The fourth
corner and the normal are computed based on the offsets to these two points
from the origin.
Shawn
On Thu, Aug 25, 2016 at 9:33 PM, Albert Palomer <albert.palo at gmail.com>
wrote:
> Ok, I figured it out after going through the source code
> <https://www.google.com/url?sa=t&rct=j&q=&esrc=s&source=web&cd=1&ved=0ahUKEwi-88WI9t3OAhVCKx4KHaXuDpYQFggdMAA&url=https%3A%2F%2Fgithub.com%2FKitware%2FVTK%2Fblob%2Fmaster%2FFilters%2FSources%2FvtkPlaneSource.cxx&usg=AFQjCNF_rx55XLQfn1is2BVZGwEbVpstxQ&sig2=B-eed3UB3r37BP6ehFWkiA&bvm=bv.130731782,d.dmo&cad=rja>.
> The SetPoint1 and SetPoint2 set the second point of the vector while the
> first one is set by SetOrigin (by default origin [-0.5 -0.5 0] ). This
> leads to the rhomboid because the two vectors of the parametric equation
> p=p0+v1*t+v2*s are computed as in v1 = point1 - origin and v2 = point2 -
> origin. So if you chose Point1 to be only in the X direction and point 2
> to the Y (which in my mind is what should give a square) gives a rhomboid
> because the director vectors of the plane are not perpendicular.
>
> So, to define the plane I do:
>
> // Add plane
>
> vtkSmartPointer<vtkPlaneSource> planeSource = vtkSmartPointer<vtkPlaneSource>::New();
>
> // Set origin for computing the two director vectors
>
> planeSource->SetOrigin(0,0,0);
>
> // Set point for first director vector
>
> planeSource->SetPoint1(x_size,0,0);
>
> // Set point for second director vector
>
> planeSource->SetPoint2(0,y_size,0);
>
> // Set center
>
> planeSource->SetCenter(5, 0.0, 0.0);
>
> // Set normal
>
> planeSource->SetNormal(0,0,1);
>
>
> Hope this helps to anybody that might be in the same trouble.
>
>
> Albert Palomer Vila
>
> 2016-08-25 17:47 GMT-07:00 Meehan, Bernard <MEEHANBT at nv.doe.gov>:
>
>> According to the vtkPlaneSource documentation, you aren’t really supposed
>> to define the plane with the SetNormal function. You are supposed to define
>> it with SetPoint1, SetPoint2 and SetCenter. Another popular way of making
>> the plane you want is to start out with the default plane – which is
>> centered at the origin, perpendicular to the z axis, and has an x-direction
>> measurement of 1, and a y-direction measurement of 1. You then use
>> vtkTransform to make it the shape you want it to be.
>>
>> I was going to give you a working example, but ran into something that I
>> didn’t understand.
>> I thought this would make a plane that was 2 units in x, 1 unit in y, and
>> had a center at (1, 0.5) - which seems to be what ParaView does with it …
>> however it seems to come out as a parallelogram?
>>
>> import vtk
>>
>> plane = vtk.vtkPlaneSource()
>> plane.SetPoint1(2.0, 0.0, 0.0)
>> plane.SetPoint2(0.0, 1.0, 0.0)
>> plane.SetCenter(0.0, 0.0, 0.0)
>> plane.Update()
>>
>> mapper = vtk.vtkPolyDataMapper()
>> mapper.SetInputData(plane.GetOutput())
>>
>> actor = vtk.vtkActor()
>> actor.SetMapper(mapper)
>>
>> renderer = vtk.vtkRenderer()
>> renderer.AddActor(actor)
>>
>> render_window = vtk.vtkRenderWindow()
>> render_window.AddRenderer(renderer)
>>
>> render_window_interactor = vtk.vtkRenderWindowInteractor()
>> render_window_interactor.SetRenderWindow(render_window)
>>
>> renderer.SetBackground(0.1, 0.3, 0.9)
>> render_window_interactor.Start()
>>
>> _______________________________________________
>> Powered by www.kitware.com
>>
>> Visit other Kitware open-source projects at
>> http://www.kitware.com/opensource/opensource.html
>>
>> Please keep messages on-topic and check the VTK FAQ at:
>> http://www.vtk.org/Wiki/VTK_FAQ
>>
>> Search the list archives at: http://markmail.org/search/?q=vtkusers
>>
>> Follow this link to subscribe/unsubscribe:
>> http://public.kitware.com/mailman/listinfo/vtkusers
>>
>>
>
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at http://www.kitware.com/
> opensource/opensource.html
>
> Please keep messages on-topic and check the VTK FAQ at:
> http://www.vtk.org/Wiki/VTK_FAQ
>
> Search the list archives at: http://markmail.org/search/?q=vtkusers
>
> Follow this link to subscribe/unsubscribe:
> http://public.kitware.com/mailman/listinfo/vtkusers
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20160826/2fa03b22/attachment.html>
More information about the vtkusers
mailing list