Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from Tkinter import *
- from Canvas import *
- import sys
- import random
- WIDTH = 400 # width of canvas
- HEIGHT = 400 # height of canvas
- HPSIZE = 1 # double of point size (must be integer)
- COLOR = "#0000FF" # blue
- NOPOINTS = 1000
- objectPointList = []
- pointList = [] # list of points (used by Canvas.delete(...))
- def quit(root=None):
- """ quit programm """
- if root==None:
- sys.exit(0)
- root._root().quit()
- root._root().destroy()
- def draw():
- """ draw points """
- for i in range(1,NOPOINTS):
- x, y = random.randint(1,WIDTH), random.randint(1,HEIGHT)
- p = can.create_oval(x-HPSIZE, y-HPSIZE, x+HPSIZE, y+HPSIZE, fill=COLOR, outline=COLOR)
- pointList.insert(0,p)
- def rotYp():
- """ rotate counterclockwise around y axis """
- global NOPOINTS
- NOPOINTS += 100
- print "In rotYp: ", NOPOINTS
- can.delete(*pointList)
- draw()
- def rotYn():
- """ rotate clockwise around y axis """
- global NOPOINTS
- NOPOINTS -= 100
- print "In rotYn: ", NOPOINTS
- can.delete(*pointList)
- draw()
- def readPoints(file_object):
- global objectPointList
- f = open(file_object).readlines()
- objects_points = [e.split(" ") for e in f]
- for op in objects_points:
- single_point = []
- single_point.append(float(op[0]))
- single_point.append(float(op[1]))
- single_point.append(float(op[2]))
- objectPointList.append(tuple(single_point))
- def calculate_bounding_box():
- inf = float('inf')
- maxX, maxY, maxZ = -inf, -inf, -inf
- minX, minY, minZ = inf, inf, inf
- for point_tuple in objectPointList:
- if point_tuple[0] > maxX:
- maxX = point_tuple[0]
- if point_tuple[1] > maxY:
- maxY = point_tuple[1]
- if point_tuple[2] > maxZ:
- maxZ = point_tuple[2]
- if point_tuple[0] < minX:
- minX = point_tuple[0]
- if point_tuple[1] < minY:
- minY = point_tuple[1]
- if point_tuple[2] < minZ:
- minZ = point_tuple[2]
- return [
- (maxX, maxY, maxZ), # max - Werte
- (minX, minY, minZ) # min - Werte
- ]
- def calculate_bounding_center_point(bounding_box):
- max_values = bounding_box[0]
- min_values = bounding_box[1]
- x = (min_values[0] + max_values[0]) / 2
- y = (min_values[1] + max_values[1]) / 2
- z = (min_values[2] + max_values[2]) / 2
- return [x, y, z]
- def make_run():
- readPoints("data/elephant_points.raw")
- bounding_box = calculate_bounding_box()
- print bounding_box
- bounding_box_center_point = calculate_bounding_center_point(bounding_box)
- print bounding_box_center_point, "CENTER POINT"
- if __name__ == "__main__":
- #check parameters
- if len(sys.argv) != 1:
- print "pointViewerTemplate.py"
- sys.exit(-1)
- make_run()
- # create main window
- mw = Tk()
- # create and position canvas and buttons
- cFr = Frame(mw, width=WIDTH, height=HEIGHT, relief="sunken", bd=1)
- cFr.pack(side="top")
- can = Canvas(cFr, width=WIDTH, height=HEIGHT)
- can.pack()
- bFr = Frame(mw)
- bFr.pack(side="left")
- bRotYn = Button(bFr, text="<-", command=rotYn)
- bRotYn.pack(side="left")
- bRotYp = Button(bFr, text="->", command=rotYp)
- bRotYp.pack(side="left")
- eFr = Frame(mw)
- eFr.pack(side="right")
- bExit = Button(eFr, text="Quit", command=(lambda root=mw: quit(root)))
- bExit.pack()
- # draw points
- draw()
- # start
- mw.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement