[vtkusers] glyph table for molecule visiualization

Giovanni Cangiani giovanni.cangiani at epfl.ch
Wed Feb 11 10:30:59 EST 2004


Hi all,
	I would like to use vtk for plotting results from
computer simulations of molecular and/or chrystal structures.

Since there were many simila examples, it has been quite easy 
to show charge densities in various ways (isosurfaces, cut 
planes, volume rendering) and I am very happy with it.
 
The problem now is how to visualize atoms and bonds.
Let's start with atoms:
As far as I understand, the best way (at least for atoms) is
to use glyphs. I had no problems with one spherical glyph
for all atoms, the problem is that I'd like to have
a different radius and a different color depending on the
atom. Also sometime it is usefull to visialize some atoms
with different shapes (i.e. octahedron).
I read from the doc that there is the possibility to 
have a table of glyphs instead of only one and having the
program to choose which glyph to use depending on the data.

In my case this would perfectly do the job: I prepare one
glyph foreach atom "type" and in the field of atom position
I use the atom type as value for choosing the glyph.
The problem is that I could not find any example
on how to use the glyph3d tool with a table of glyphs.

I have tryied something like the following code that (in my
dreams) should show a sphere on the origin and a cube somewhere
along the x axys. What I get instead are just two identical grey 
spheres and no cube at all.

[....]
AtomPosition = vtk.vtkPoints()
AtomPosition.InsertNextPoint(0.0, 0.0, 0.0)
AtomPosition.InsertNextPoint(5.0, 0.0, 0.0)
 
AtomType = vtk.vtkIntArray()
AtomType.InsertNextValue(0)   # is is ok to start from 0 ?
AtomType.InsertNextValue(1)
 
Molecule=vtk.vtkPolyData()
Molecule.SetPoints(AtomPosition)
Molecule.GetPointData().SetScalars(AtomType)

# question: can I assign a color to my glyphs ? 
SphereLikeAtom = vtk.vtkSphereSource()
CubeLikeAtom = vtk.vtkCubeSource()
 
glyphs=vtk.vtkGlyph3D()
glyphs.SetNumberOfSources(2)
glyphs.SetSource(0,SphereLikeAtom.GetOutput())
glyphs.SetSource(1,CubeLikeAtom.GetOutput())
glyphs.SetInput(Molecule)
glyphs.ScalingOff()
glyphs.SetIndexModeToScalar
[....]

I am very new to vtk and also to this way of programming.
Can anybody send me an example (possibly in python) showing
glyph3d at work with a table of glyphs ?
 
The simplest, the better off course. Something as simple as 
my tentative above would be perfect.

If possible, I'd like also to know how to assign static
colors to my customized glyphs, and possibly how to draw
bonds between the atoms... but this is another story.

Thanks very much in advance.

	giovanni





More information about the vtkusers mailing list