[vtkusers] vtkArrowSource and vtkGlyph3D
Andrea Gavana
andrea.gavana at gmail.com
Fri Dec 2 10:18:44 EST 2016
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()
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20161202/32a8fc95/attachment.html>
More information about the vtkusers
mailing list