Advertisement
Guest User

Untitled

a guest
May 29th, 2015
248
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.51 KB | None | 0 0
  1. from Tkinter import *
  2. from Canvas import *
  3. import sys
  4. import random
  5.  
  6. WIDTH  = 400 # width of canvas
  7. HEIGHT = 400 # height of canvas
  8.  
  9. HPSIZE = 1 # double of point size (must be integer)
  10. COLOR = "#0000FF" # blue
  11.  
  12. NOPOINTS = 1000
  13.  
  14. objectPointList = []
  15.  
  16. pointList = [] # list of points (used by Canvas.delete(...))
  17.  
  18. def quit(root=None):
  19.     """ quit programm """
  20.     if root==None:
  21.         sys.exit(0)
  22.     root._root().quit()
  23.     root._root().destroy()
  24.  
  25. def draw():
  26.     """ draw points """
  27.     for i in range(1,NOPOINTS):
  28.         x, y = random.randint(1,WIDTH), random.randint(1,HEIGHT)
  29.         p = can.create_oval(x-HPSIZE, y-HPSIZE, x+HPSIZE, y+HPSIZE, fill=COLOR, outline=COLOR)
  30.         pointList.insert(0,p)
  31.  
  32. def rotYp():
  33.     """ rotate counterclockwise around y axis """
  34.     global NOPOINTS
  35.     NOPOINTS += 100
  36.     print "In rotYp: ", NOPOINTS
  37.     can.delete(*pointList)
  38.     draw()
  39.  
  40. def rotYn():
  41.     """ rotate clockwise around y axis """
  42.     global NOPOINTS
  43.     NOPOINTS -= 100
  44.     print "In rotYn: ", NOPOINTS
  45.     can.delete(*pointList)
  46.     draw()
  47.  
  48. def readPoints(file_object):
  49.     global objectPointList
  50.  
  51.     f = open(file_object).readlines()
  52.     objects_points = [e.split(" ") for e in f]
  53.  
  54.     for op in objects_points:
  55.         single_point = []
  56.         single_point.append(float(op[0]))
  57.         single_point.append(float(op[1]))
  58.         single_point.append(float(op[2]))
  59.  
  60.         objectPointList.append(tuple(single_point))
  61.  
  62. def calculate_bounding_box():
  63.     inf = float('inf')
  64.     maxX, maxY, maxZ = -inf, -inf, -inf
  65.     minX, minY, minZ = inf, inf, inf
  66.  
  67.     for point_tuple in objectPointList:
  68.         if point_tuple[0] > maxX:
  69.             maxX = point_tuple[0]
  70.         if point_tuple[1] > maxY:
  71.             maxY = point_tuple[1]
  72.         if point_tuple[2] > maxZ:
  73.             maxZ = point_tuple[2]
  74.  
  75.         if point_tuple[0] < minX:
  76.             minX = point_tuple[0]
  77.         if point_tuple[1] < minY:
  78.             minY = point_tuple[1]
  79.         if point_tuple[2] < minZ:
  80.             minZ = point_tuple[2]
  81.  
  82.     return [
  83.         (maxX, maxY, maxZ), # max - Werte
  84.         (minX, minY, minZ) # min - Werte
  85.     ]
  86.  
  87. def calculate_bounding_center_point(bounding_box):
  88.     max_values = bounding_box[0]
  89.     min_values = bounding_box[1]
  90.  
  91.     x = (min_values[0] + max_values[0]) / 2
  92.     y = (min_values[1] + max_values[1]) / 2
  93.     z = (min_values[2] + max_values[2]) / 2
  94.  
  95.     return [x, y, z]
  96.  
  97. def make_run():
  98.     readPoints("data/elephant_points.raw")
  99.     bounding_box = calculate_bounding_box()
  100.     print bounding_box
  101.     bounding_box_center_point = calculate_bounding_center_point(bounding_box)
  102.  
  103.     print bounding_box_center_point, "CENTER POINT"
  104.  
  105. if __name__ == "__main__":
  106.     #check parameters
  107.     if len(sys.argv) != 1:
  108.        print "pointViewerTemplate.py"
  109.        sys.exit(-1)
  110.  
  111.     make_run()
  112.     # create main window
  113.     mw = Tk()
  114.  
  115.     # create and position canvas and buttons
  116.     cFr = Frame(mw, width=WIDTH, height=HEIGHT, relief="sunken", bd=1)
  117.     cFr.pack(side="top")
  118.     can = Canvas(cFr, width=WIDTH, height=HEIGHT)
  119.     can.pack()
  120.     bFr = Frame(mw)
  121.     bFr.pack(side="left")
  122.     bRotYn = Button(bFr, text="<-", command=rotYn)
  123.     bRotYn.pack(side="left")
  124.     bRotYp = Button(bFr, text="->", command=rotYp)
  125.     bRotYp.pack(side="left")
  126.     eFr = Frame(mw)
  127.     eFr.pack(side="right")
  128.     bExit = Button(eFr, text="Quit", command=(lambda root=mw: quit(root)))
  129.     bExit.pack()
  130.  
  131.     # draw points
  132.     draw()
  133.  
  134.     # start
  135.     mw.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement