[vtkusers] vtkArrowSource and vtkGlyph3D

Andrea Gavana andrea.gavana at gmail.com
Tue Dec 6 10:35:16 EST 2016


Hi Ken & All,

    thank you for your suggestions, vtkGlyph3DMapper worked beautifully in
the end. I have only a couple of issues (which may or may not related to
the VTK version I am using and the fact that I am using VTK through the
Python bindings):

1. If I zoom in and out (with the mouse) in the render window I can see
visual glitches for the spheres I am using (that's another
vtkGlyph3DMapper, unrelated to the arrow ones) - see attached screenshot

2. If I do the following:

>>> import vtk
>>> vtk.vtkVersion().GetVTKVersion()
'7.0.0'
>>> g = vtk.vtkGlyph3DMapper()
>>> g.SetOrientationModeToRotation()
>>> g.GetOrientationModeAsString()
'Invalid'
>>> g.SetOrientationMode(vtk.vtkGlyph3DMapper.ORIENTATION)
>>> g.GetOrientationModeAsString()
'Invalid'
>>> g.SetOrientationModeToDirection()
>>> g.GetOrientationModeAsString()
'Direction'


Notice the "Invalid" string printed out when I try to set the orientation
mode to "ORIENTATION".

Not a big deal, I can use the DIRECTION thing as well, I just wanted to let
you know...

Andrea.



On 2 December 2016 at 16:52, Ken Martin <ken.martin at kitware.com> wrote:

> It can color/scale/orient/mask on a per glyph basis. It can even index
> into multiple glyph models on a per point basis. So you should be good.
> Just takes a while to wade through all the options as there is a lot in
> there.
>
> Thanks
> Ken
>
> On Fri, Dec 2, 2016 at 10:45 AM, Andrea Gavana <andrea.gavana at gmail.com>
> wrote:
>
>> Hi Ken,
>>
>> Thank you very much for your answer. I hadn't understood that vtkGlyph3D
>> would create all the arrows in memory.
>>
>> However, it may still be the only choice I have as I would like to be
>> able to assign a different color (based on a scalar) to each arrow, and
>> some arrows should point downward while others upwards. The size of the
>> arrow will stay constant but the color I would like to be able to change it
>> on an arrow-by arrow basis, and I don't know if this can be done using
>> vtkGlyph3DMapper...
>>
>> Of course, I would be more than happy to be proven wrong 😊.
>>
>> Thank you again.
>>
>> Andrea.
>>
>> On Fri, 2 Dec 2016 at 16:30, Ken Martin <ken.martin at kitware.com> wrote:
>>
>>> Be aware Glyph3D is a filter and will actually generate all those arrows
>>> in memory. Glyph3DMapper is a mapper and uses OpenGL tricks to render the
>>> same arrow lots of times.
>>>
>>> Both classes place a glyph at the location of each input point. The
>>> orientation is controlled by a different array in your point data ala the
>>> comments below:
>>>
>>> Thanks
>>> Ken
>>>
>>>   //@{
>>>   /**
>>>    * Turn on/off orienting of input geometry.
>>>    * When turned on, the orientation array specified
>>>    * using SetOrientationArray() will be used.
>>>    */
>>>   vtkSetMacro(Orient, bool);
>>>   vtkGetMacro(Orient, bool);
>>>   vtkBooleanMacro(Orient, bool);
>>>   //@}
>>>
>>>   //@{
>>>   /**
>>>    * Orientation mode indicates if the OrientationArray provides the
>>> direction
>>>    * vector for the orientation or the rotations around each axes.
>>> Default is
>>>    * DIRECTION
>>>    */
>>>   vtkSetClampMacro(OrientationMode, int, DIRECTION, ROTATION);
>>>   vtkGetMacro(OrientationMode, int);
>>>   void SetOrientationModeToDirection()
>>>     { this->SetOrientationMode(vtkGlyph3DMapper::DIRECTION); }
>>>   void SetOrientationModeToRotation()
>>>     { this->SetOrientationMode(vtkGlyph3DMapper::ROTATION); }
>>>   const char* GetOrientationModeAsString();
>>>   //@}
>>>
>>>   enum OrientationModes
>>>   {
>>>     DIRECTION=0,
>>>     ROTATION=1
>>>   };
>>>
>>>
>>>   /**
>>>    * Tells the mapper to use an orientation array if Orient is true.
>>>    * An orientation array is a vtkDataArray with 3 components. The first
>>>    * component is the angle of rotation along the X axis. The second
>>>    * component is the angle of rotation along the Y axis. The third
>>>    * component is the angle of rotation along the Z axis. Orientation is
>>>    * specified in X,Y,Z order but the rotations are performed in Z,X an
>>> Y.
>>>    * This definition is compliant with SetOrientation method on
>>> vtkProp3D.
>>>    * By using vector or normal there is a degree of freedom or rotation
>>>    * left (underconstrained). With the orientation array, there is no
>>> degree of
>>>    * freedom left.
>>>    * This is convenience method. The same effect can be achieved by using
>>>    * SetInputArrayToProcess(vtkGlyph3DMapper::ORIENTATION, 0, 0,
>>>    * vtkDataObject::FIELD_ASSOCIATION_POINTS, orientationarrayname);
>>>    */
>>>   void SetOrientationArray(const char* orientationarrayname);
>>>
>>>
>>> On Fri, Dec 2, 2016 at 10:18 AM, Andrea Gavana <andrea.gavana at gmail.com>
>>> wrote:
>>>
>>> Dear All,
>>>
>>>     I am trying to combine a vtkArrowSource and vtkGlyph3D. I have been
>>> (naively) thinking that by specifying a polydata with two points (start and
>>> end) and assigning its points to the vtkGlyph3D I would obtain an arrow
>>> that starts at the start point and end at the end point.
>>>
>>> I have created a small, self-contained following Python script to
>>> demonstrate what I mean - I get 4 arrows, one at each point I define,
>>> instead of two arrows. What am I missing? Any suggestion is more than
>>> welcome.
>>>
>>> Thank you in advance.
>>>
>>> Andrea.
>>>
>>>
>>> import vtk
>>> import numpy
>>>
>>> # First set of points - first arrow
>>> points1 = numpy.array([[ 11271.915, 7538.686, 6245.661],
>>>                        [ 11271.915, 7538.686, 5897.034]])
>>>
>>> # Second set of points - second arrow
>>> points2 = numpy.array([[ 10532.274, 9101.572, 6313.167],
>>>                        [ 10532.274, 9101.572, 5964.539]])
>>>
>>> # Create an arrow source with some attributes
>>> arrow_source = vtk.vtkArrowSource()
>>> arrow_source.SetTipRadius(0.2)
>>> arrow_source.SetShaftRadius(0.075)
>>>
>>> # Create the vtkGlyph3D
>>> arrow_glyph = vtk.vtkGlyph3D()
>>> arrow_glyph.SetScaleModeToDataScalingOff()
>>>
>>> # Usual mapper
>>> arrow_mapper = vtk.vtkPolyDataMapper()
>>> arrow_mapper.SetInputConnection(arrow_glyph.GetOutputPort())
>>>
>>> # Usual actor
>>> arrow_actor = vtk.vtkActor()
>>> arrow_actor.SetMapper(arrow_mapper)
>>>
>>> append_poly_data = vtk.vtkAppendPolyData()
>>>
>>> # Loop through points1 and points2
>>> for p in [points1, points2]:
>>>
>>>     arrow_poly_data = vtk.vtkPolyData()
>>>     vtk_arrow_lines = vtk.vtkCellArray()
>>>
>>>     vtk_arrow_lines.InsertNextCell(2)
>>>     vtk_arrow_lines.InsertCellPoint(0)
>>>     vtk_arrow_lines.InsertCellPoint(1)
>>>
>>>     vtk_arrow_points = vtk.vtkPoints()
>>>     # Loop through the head and tail of a single arrow
>>>     for j in xrange(2):
>>>         vtk_arrow_points.InsertNextPoint(p[j])
>>>
>>>     arrow_poly_data.SetPoints(vtk_arrow_points)
>>>     arrow_poly_data.SetLines(vtk_arrow_lines)
>>>     append_poly_data.AddInputData(arrow_poly_data)
>>>
>>>
>>> arrow_glyph.SetInputConnection(append_poly_data.GetOutputPort())
>>> arrow_glyph.SetSourceConnection(arrow_source.GetOutputPort())
>>> arrow_glyph.SetScaleFactor(100)
>>> arrow_actor.GetProperty().SetColor(1, 1, 1)
>>>
>>> # ------------------------------------------------------------
>>> # Create the RenderWindow, Renderer and both Actors
>>> # ------------------------------------------------------------
>>> ren = vtk.vtkRenderer()
>>> renWin = vtk.vtkRenderWindow()
>>> renWin.AddRenderer(ren)
>>> iren = vtk.vtkRenderWindowInteractor()
>>> iren.SetRenderWindow(renWin)
>>>
>>> # add actors
>>> ren.AddActor(arrow_actor)
>>> ren.ResetCamera()
>>> iren.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
>>>
>>>
>>>
>>>
>>> --
>>> Ken Martin PhD
>>> Chairman & CFO
>>> Kitware Inc.
>>> 28 Corporate Drive
>>> Clifton Park NY 12065
>>> 518 371 3971
>>>
>>> This communication, including all attachments, contains confidential and
>>> legally privileged information, and it is intended only for the use of the
>>> addressee.  Access to this email by anyone else is unauthorized. If you are
>>> not the intended recipient, any disclosure, copying, distribution or any
>>> action taken in reliance on it is prohibited and may be unlawful. If you
>>> received this communication in error please notify us immediately and
>>> destroy the original message.  Thank you.
>>>
>>
>
>
> --
> Ken Martin PhD
> Chairman & CFO
> Kitware Inc.
> 28 Corporate Drive
> Clifton Park NY 12065
> 518 371 3971
>
> This communication, including all attachments, contains confidential and
> legally privileged information, and it is intended only for the use of the
> addressee.  Access to this email by anyone else is unauthorized. If you are
> not the intended recipient, any disclosure, copying, distribution or any
> action taken in reliance on it is prohibited and may be unlawful. If you
> received this communication in error please notify us immediately and
> destroy the original message.  Thank you.
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20161206/da825272/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: vtk_glitches.png
Type: image/png
Size: 75797 bytes
Desc: not available
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20161206/da825272/attachment-0001.png>


More information about the vtkusers mailing list