[vtkusers] A set of spheres within one actor?

Piotr Byzia piotr.byzia at gmail.com
Mon Sep 14 06:26:23 EDT 2009


Dear list members,

I'd like to say hello to everybody, as this is my first post on this  
list.

I want to use VTK to build some simple molecular viewer for biological  
structures, represented by spheres, and in the near future also by  
lines and sticks.

I succeeded in drawing a sphere representation for a couple of atoms,  
and I want to be able to add another *set* of atoms and manipulate  
them separately from the 1st set. I found the  
SetCurrentStyleToTrackballActor() property and it works fine, but for  
a single sphere.

My question is how to create a set of spheres within 1 actor?

Below is the code in Python I used, and error is:
vtkStreamingDemandDrivenPipeline (0x584c10): Input port 0 of algorithm  
vtkDataSetMapper(0x9ff800) has 38 connections but is not repeatable.

ren = vtk.vtkRenderer()
renWin.AddRenderer(ren)

iren = vtk.vtkRenderWindowInteractor()
iren.SetRenderWindow(renWin)

isty = vtk.vtkInteractorStyleSwitch()
isty.SetCurrentStyleToTrackballCamera()
isty.SetCurrentStyleToTrackballActor() # pick one actor and act only  
on it
iren.SetInteractorStyle(isty)

sphereMapper = vtk.vtkDataSetMapper()

for i in atoms:
     # Create a sphere source, mapper, and actor.
     sphere = vtk.vtkSphereSource()

     sphere.SetCenter(i[0], i[1], i[2]);
     sphere.SetRadius(1.0);

     sphere.SetThetaResolution(18)
     sphere.SetPhiResolution(18)

     sphereMapper.AddInputConnection(sphere.GetOutputPort())

sphereActor = vtk.vtkLODActor()
sphereActor.SetMapper(sphereMapper)
sphereActor.GetProperty().SetColor(0.0, 0.0, 0.6) # RGB = red green blue
sphereActor.GetProperty().SetOpacity(1)
ren.AddActor(sphereActor)


Also, how could I programmatically set which set of spheres (which  
actor) should be used by RenderWindowInteractor? In other words, I'd  
like to be able to chose a particular actor (as in shift + left mouse  
button in the window) and manipulate (rotate, transform, zoom) only  
that particular actor.

Please correct me, if I'm incorrectly using any terms related to VTK,  
I just started ;-)

Best wishes,
Piotr Byzia



More information about the vtkusers mailing list