#! /usr/bin/python
from vtk import *
# create a rendering window and renderer
ren = vtkRenderer()
renWin = vtkRenderWindow()
renWin.AddRenderer(ren)
renWin.SetSize(800,600)
renWin.StereoCapableWindowOn()
iren = vtkRenderWindowInteractor()
iren.SetRenderWindow(renWin)
trackcam = vtkInteractorStyleTrackballCamera()
iren.SetInteractorStyle(trackcam)
class matchstick:
"""an element in a height map"""
def __init__(self):
self.height = 1.0
#self.bottom = 0.0 #height of bottom of matchstick
self.Xoffset = 0
self.Yoffset = 0
self.source = vtkCubeSource() #looks like a cube
#now do a bunch of vtk crap to render the matchstick
#google for vtk-intro.py if you dont understand what's going on
self.source.SetCenter(1,0,(self.height/2))
self.source.SetZLength(self.height)
self.mapper = vtkPolyDataMapper()
self.actor = vtkActor()
self.actor.SetMapper(self.mapper)
self.mapper.SetInput(self.source.GetOutput())
ren.AddActor(self.actor)
def SetOffset(self, Xoffset, Yoffset, height):
"""move the cubes to the right place"""
self.source.SetCenter(Xoffset, Yoffset, height/2)
class heightmap:
def __init__(self):
self.rows = 10
self.columns = 15
self.dimensions = (self.rows, self.columns)
def add(self, Xoffset, Yoffset, height):
#create a new map element
myMatchstick = matchstick()
#move it
myMatchstick.SetOffset(Xoffset, Yoffset, height)
#save the height for later use
myMatchstick.height = height
def fill(self):
for i in range(self.rows):
for j in range(self.columns):
self.add(i, j, (i+j)) #something pretty
#just one for now
#dimensions = (rows, columns)
#myMatchsticks = [matchstick()][matchstick()]
myHeightmap = heightmap()
myHeightmap.fill()
# enable user interface interactor
iren.Initialize()
iren.Start()