[vtkusers] vtkWarpVector/vtkGlyph3D array problem

Robby Aungst robert.aungst at gmail.com
Thu Dec 21 10:25:14 EST 2017


I've attached a simple example that shows the issue. If you toggle between
lines 46 and 47, you'll see that when warp isn't in the pipeline you end up
with 3 different glyphs with 3 different colors, scaled by the distance to
camera. If you introduce warp into the pipeline, you get an error that says
"Turning indexing off; no data to index with". The warp vector did
something to the glyphIndexes array that I don't understand and also lost
the scalar data that was on polydata points.

It's possible that I'm just doing it wrong - all I'm after is to be able to
warp the points but still be able to control the scaling/index/color of the
glyphs. I'm using VTK 8.0.1 on Python 3.5.

Thank you!

On Thu, Dec 21, 2017 at 4:50 AM, Bill Lorensen <bill.lorensen at gmail.com>
wrote:

> Robby,
>
> If you can post a complete compilable C++  or Python example with a small
> dataset we can take a look.
>
> Bill
> On Dec 20, 2017 10:42 PM, "Robby Aungst" <robert.aungst at gmail.com> wrote:
>
>> Hello,
>>
>> I'm having an issue where my end goal is to be able to have a set of
>> warped points displaying a variety of glyphs with different colors and
>> scales. I'm able to get it to work without the vtkWarpVector introduced to
>> the pipeline, but as soon as that is introduced the array that I'm using
>> for the indexes seems to no longer be found (as well as the scalar data),
>> and the glyph defaults to the first in the set and no longer uses the
>> scalar data for color. Is there something about vtkWarpVector where it
>> doesn't pass along arrays?
>>
>> My working pipeline is:
>>
>> vtkPolyData->vtkExtractSelectedIds->vtkDistanceToCamera->vtkGlyph3D
>>
>> I store a vtkIntArray on the vtkPolyData with self
>> .pointSet.GetPointData().AddArray(indexArray) and then later use it on
>> the vtkGlyph3D to set the indexes into my glyph table: self.glyph.
>> SetInputArrayToProcess(0, 0, 0, 0, "indexes"). This works great, but
>> when I change the pipeline to:
>>
>> vtkPolyData->vtkExtractSelectedIds->vtkWarpVector->vtkDistan
>> ceToCamera->vtkGlyph3D
>>
>> the vtkGlyph3D can no longer find the "indexes" array from the original
>> polydata. It can still find the "DistanceToCamera" array which is used for
>> the scale - I'm guessing because it gets created after the vtkWarpVector in
>> the pipeline?
>>
>> I don't think that vtkWarpVector is supposed to remove the arrays, so
>> what's happening? Is there any other way to get the arrays to SetInputArrayToProcess?
>> Or some other way to combine vtkWarpVector and vtkGlyph3D?
>>
>> Thanks!
>>
>> _______________________________________________
>> 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:
>> https://vtk.org/mailman/listinfo/vtkusers
>>
>>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://vtk.org/pipermail/vtkusers/attachments/20171221/3b83e0fb/attachment.html>
-------------- next part --------------
import vtk

ren = vtk.vtkRenderer()

#  create some points, indexes and colors

points = vtk.vtkPoints()
points.InsertNextPoint(0, 0, 0)
points.InsertNextPoint(5, 0, 0)
points.InsertNextPoint(10, 0, 0)

index = vtk.vtkIntArray()
index.SetName("GlyphIndexes")
index.SetNumberOfComponents(1)

index.InsertNextValue(0)
index.InsertNextValue(1)
index.InsertNextValue(2)

colors = vtk.vtkUnsignedCharArray()
colors.SetName("Colors")
colors.SetNumberOfComponents(3)

colors.InsertNextTuple((255, 0, 0))
colors.InsertNextTuple((0, 255, 0))
colors.InsertNextTuple((0, 0, 255))

#  add into the poly data

polyData = vtk.vtkPolyData()
polyData.SetPoints(points)
polyData.GetPointData().AddArray(index)
polyData.GetPointData().SetScalars(colors)

#  pass into vtkExtractSelectedIds (skipped for this example)

#  pass into warp

warp = vtk.vtkWarpVector()
warp.SetInputData(polyData)
warp.Update()

#  pass into distance2camera

wd2c = vtk.vtkDistanceToCamera()
wd2c.SetInputConnection(warp.GetOutputPort())       #  this doesn't work (all the glyphs the first index, colored by distance2camera)
#wd2c.SetInputData(polyData)                        #  this works as intended (separate colors / indexes for glyph)
wd2c.SetScreenSize(1.0)
wd2c.SetRenderer(ren)
wd2c.Update()

#  create some poly data

cs = vtk.vtkCubeSource()
cs.SetXLength(0.5)
cs.SetYLength(1)
cs.SetZLength(2)
ss = vtk.vtkSphereSource()
ss.SetRadius(0.25)
cs2 = vtk.vtkConeSource()
cs2.SetRadius(0.25)
cs2.SetHeight(0.5)

#  create the glyph. scale by the distance to camera and index with the array

glyph3D = vtk.vtkGlyph3D()
glyph3D.SetVectorModeToUseVector()
glyph3D.SetInputConnection(wd2c.GetOutputPort())
glyph3D.SetSourceConnection(0, cs.GetOutputPort())
glyph3D.SetSourceConnection(1, ss.GetOutputPort())
glyph3D.SetSourceConnection(2, cs2.GetOutputPort())
glyph3D.SetColorModeToColorByScalar()
glyph3D.SetScaleFactor(25)  # Overall scaling factor
glyph3D.SetRange(0, 3)  # Default is (0,1)
glyph3D.SetIndexModeToVector()
glyph3D.SetScaleModeToScaleByScalar()
glyph3D.SetInputArrayToProcess(0, 0, 0, 0, "DistanceToCamera")
glyph3D.SetInputArrayToProcess(1, 0, 0, 0, "GlyphIndexes")
glyph3D.Update()

#  visualize

mapper = vtk.vtkPolyDataMapper()
mapper.SetInputConnection(glyph3D.GetOutputPort())
mapper.ScalarVisibilityOn()

actor = vtk.vtkActor()
actor.SetMapper(mapper)

ren.AddActor(actor)
renWin = vtk.vtkRenderWindow()
renWin.AddRenderer(ren)
iren = vtk.vtkRenderWindowInteractor()
istyle = vtk.vtkInteractorStyleTrackballCamera()
iren.SetInteractorStyle(istyle)
iren.SetRenderWindow(renWin)
ren.ResetCamera()
renWin.Render()

iren.Start()


More information about the vtkusers mailing list