[vtkusers] ellipsoidWidget

Denis Saussus dsaussus at fugro-jason.com
Mon Nov 29 09:35:37 EST 2004


Hi,

I am having trouble making a 3D widget that you would call
vtkEllipsoidWidget.  You might correctly guess that this widget needs
to have the same functionality as the vtkBoxWidget or the
vtkSphereWidget.

To do this, I thought it might be clever to stick a vtkSphereSource
inside a vtkBoxWidget and have it be reshaped upn InteractionEvent.
This is easy and works just fine except that I also need to know which
points are contained within the reshaped sphere/ellipse.  What I do
is:

    ...
    sphere = vtk.vtkSphereSource()
    sphere.SetRadius(1.0)
    sphereMapper = vtk.vtkPolyDataMapper()
    sphereMapper.SetInput(sphere)
    sphereActor = vtk.vtkActor()
    sphereActor.SetMapper(sphereMapper)

    t = vtk.vtkTransform()

    def reshapeSphere(obj, event):
      obj.GetTransform(t)
      sphereActor.SetUserTransform(t)

    box = vtk.vtkBoxWidget()
    box.SetInteractor(iren)
    box.SetProp3D(sphereActor)
    box.PlaceWidget()

    box.AddObserver('InteractionEvent', reshapeSphere)
    ...

Now comes the tricky bit: finding out which points lie within the
reshaped sphere.  I tried adding an implicit vtkSphere function but it
seems to not do anything at all?!  I did it by adding something like
this to the code snipet above:

    ...
    sphereFunc = vtk.vtkSphere()

    def whatIsInside(obj, event):
      ids = []
      obj.GetTransform(t)
      sphereFunc.SetTransform(t)
      for n in range(points.GetNumberOfPoints()):
        inside = sphereFunc.EvaluateFunction(points.GetPoints().GetData().GetTuple3())
        if inside < 0:
          ids.append(points.GetPoints().GetData().GetTuple3())
      return ids

    box.AddObserver('EndInteractionEvent', whatIsInside)
    ...

What am I doing wrong -- why does the sphereFunc not get updated?  Is
there a better way to accomplish what I am trying to do?  

Any help would be greatly appreciated.

Thanks!




More information about the vtkusers mailing list