self.screenshot_counter += 1
        # Add your keyboard shortcuts here. If you modify any of the
        # actors or change some other parts or properties of the
        # scene, don't forget to call the render window's Render()
        # function to update the rendering.
        # elif key == ...


# Read the data into a vtkPolyData object using the functions in
# molecules_io.py
basedir = dirname(realpath(__file__)) #Get the directory of the .py file, courtesy of http://stackoverflow.com/a/5137509/4455880

data = vtk.vtkPolyData()
data.SetPoints(molecules_io.read_points(join(basedir, "coordinates.txt")))
data.GetPointData().SetScalars(molecules_io.read_scalars(join(basedir, "radii.txt")))
data.SetLines(molecules_io.read_connections(join(basedir, "connections.txt")))

pd = data.GetPointData()
pd.GetScalars().SetName("radii")
colors = vtkUnsignedCharArray()
colors.SetNumberOfComponents(3)
colors.SetName("Colors")


color_table =[[255,0,0],[128,255,0],[0,255,255],[127,0,255], [255,0,255],[255,127,0],[0,255,0], [0,127,255] ]
color_dictionary = dict()
scalars = data.GetPointData().GetScalars()
current_key = 0;
for i in range(0, scalars.GetNumberOfTuples()):
    scalar = scalars.GetTuple1(i)
    if color_dictionary.has_key(scalar):
Esempio n. 2
0
            self.png_writer.Write()
            print("Saved %s" % (screenshot_filename))
            self.screenshot_counter += 1
        # Add your keyboard shortcuts here. If you modify any of the
        # actors or change some other parts or properties of the
        # scene, don't forget to call the render window's Render()
        # function to update the rendering.
        # elif key == ...


# Read the data into a vtkPolyData object using the functions in
# molecules_io.py
data = vtk.vtkPolyData()
data.SetPoints(molecules_io.read_points("coordinates.txt"))
data.GetPointData().SetScalars(molecules_io.read_scalars("radii.txt"))
data.SetLines(molecules_io.read_connections("connections.txt"))

# Add your code here...

#Glyphs#
sphere = vtk.vtkSphereSource()
sphere.SetRadius(0.25)
sphere.SetThetaResolution(8)
sphere.SetPhiResolution(8)

sphereGlyph = vtk.vtkGlyph3D()
sphereGlyph.SetInput(data)
sphereGlyph.SetSourceConnection(sphere.GetOutputPort())
sphereGlyph.SetScaleModeToScaleByScalar()
sphereGlyph.SetColorModeToColorByScalar()
sphereGlyph.SetScaleFactor(2.0)
            self.png_writer.Write()
            print("Saved %s" % (screenshot_filename))
            self.screenshot_counter += 1
        # Add your keyboard shortcuts here. If you modify any of the
        # actors or change some other parts or properties of the
        # scene, don't forget to call the render window's Render()
        # function to update the rendering.
        # elif key == ...


# Read the data into a vtkPolyData object using the functions in
# molecules_io.py
data = vtk.vtkPolyData()
data.SetPoints(molecules_io.read_points("coordinates.txt"))
data.GetPointData().SetScalars(molecules_io.read_scalars("radii.txt"))
data.SetLines(molecules_io.read_connections("connections.txt"))

# Add your code here...

# Glyphs#
sphere = vtk.vtkSphereSource()
sphere.SetRadius(0.25)
sphere.SetThetaResolution(8)
sphere.SetPhiResolution(8)

sphereGlyph = vtk.vtkGlyph3D()
sphereGlyph.SetInput(data)
sphereGlyph.SetSourceConnection(sphere.GetOutputPort())
sphereGlyph.SetScaleModeToScaleByScalar()
sphereGlyph.SetColorModeToColorByScalar()
sphereGlyph.SetScaleFactor(2.0)