本文整理汇总了Python中gl_utils.trackball.Trackball.push方法的典型用法代码示例。如果您正苦于以下问题:Python Trackball.push方法的具体用法?Python Trackball.push怎么用?Python Trackball.push使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类gl_utils.trackball.Trackball
的用法示例。
在下文中一共展示了Trackball.push方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Calibration_Visualizer
# 需要导入模块: from gl_utils.trackball import Trackball [as 别名]
# 或者: from gl_utils.trackball.Trackball import push [as 别名]
class Calibration_Visualizer(Visualizer):
def __init__(self, g_pool, world_camera_intrinsics , cal_ref_points_3d, cal_observed_points_3d, eye_camera_to_world_matrix0 , cal_gaze_points0_3d, eye_camera_to_world_matrix1 = np.eye(4) , cal_gaze_points1_3d = [], run_independently = False , name = "Calibration Visualizer" ):
super(Calibration_Visualizer, self).__init__( g_pool,name, run_independently)
self.image_width = 640 # right values are assigned in update
self.focal_length = 620
self.image_height = 480
self.eye_camera_to_world_matrix0 = eye_camera_to_world_matrix0
self.eye_camera_to_world_matrix1 = eye_camera_to_world_matrix1
self.cal_ref_points_3d = cal_ref_points_3d
self.cal_observed_points_3d = cal_observed_points_3d
self.cal_gaze_points0_3d = cal_gaze_points0_3d
self.cal_gaze_points1_3d = cal_gaze_points1_3d
if world_camera_intrinsics:
self.world_camera_width = world_camera_intrinsics['resolution'][0]
self.world_camera_height = world_camera_intrinsics['resolution'][1]
self.world_camera_focal = (world_camera_intrinsics['camera_matrix'][0][0] + world_camera_intrinsics['camera_matrix'][1][1] ) / 2.0
else:
self.world_camera_width = 0
self.world_camera_height = 0
self.world_camera_focal = 0
camera_fov = math.degrees(2.0 * math.atan( self.window_size[0] / (2.0 * self.focal_length)))
self.trackball = Trackball(camera_fov)
self.trackball.distance = [0,0,-80.]
self.trackball.pitch = 210
self.trackball.roll = 0
########### Open, update, close #####################
def update_window(self, g_pool , gaze_points0 , sphere0 , gaze_points1 = [] , sphere1 = None, intersection_points = [] ):
if not self.window:
return
self.begin_update_window() #sets context
self.clear_gl_screen()
self.trackball.push()
glMatrixMode( GL_MODELVIEW )
# draw things in world camera coordinate system
glPushMatrix()
glLoadIdentity()
calibration_points_line_color = RGBA(0.5,0.5,0.5,0.1);
error_line_color = RGBA(1.0,0.0,0.0,0.5)
self.draw_coordinate_system(200)
if self.world_camera_width != 0:
self.draw_frustum( self.world_camera_width/ 10.0 , self.world_camera_height/ 10.0 , self.world_camera_focal / 10.0)
for p in self.cal_observed_points_3d:
glutils.draw_polyline( [ (0,0,0), p] , 1 , calibration_points_line_color, line_type = GL_LINES)
#draw error lines form eye gaze points to ref points
for(cal_point,ref_point) in zip(self.cal_ref_points_3d, self.cal_observed_points_3d):
glutils.draw_polyline( [ cal_point, ref_point] , 1 , error_line_color, line_type = GL_LINES)
#calibration points
glutils.draw_points( self.cal_ref_points_3d , 4 , RGBA( 0, 1, 1, 1 ) )
glPopMatrix()
if sphere0:
# eye camera
glPushMatrix()
glLoadMatrixf( self.eye_camera_to_world_matrix0.T )
self.draw_coordinate_system(60)
self.draw_frustum( self.image_width / 10.0, self.image_height / 10.0, self.focal_length /10.)
glPopMatrix()
#everything else is in world coordinates
#eye
sphere_center0 = list(sphere0['center'])
sphere_radius0 = sphere0['radius']
self.draw_sphere(sphere_center0,sphere_radius0, color = RGBA(1,1,0,1))
#gazelines
for p in self.cal_gaze_points0_3d:
glutils.draw_polyline( [ sphere_center0, p] , 1 , calibration_points_line_color, line_type = GL_LINES)
#calibration points
# glutils.draw_points( self.cal_gaze_points0_3d , 4 , RGBA( 1, 0, 1, 1 ) )
#current gaze points
glutils.draw_points( gaze_points0 , 2 , RGBA( 1, 0, 0, 1 ) )
for p in gaze_points0:
glutils.draw_polyline( [sphere_center0, p] , 1 , RGBA(0,0,0,1), line_type = GL_LINES)
#draw error lines form eye gaze points to ref points
for(cal_gaze_point,ref_point) in zip(self.cal_gaze_points0_3d, self.cal_ref_points_3d):
glutils.draw_polyline( [ cal_gaze_point, ref_point] , 1 , error_line_color, line_type = GL_LINES)
#.........这里部分代码省略.........
示例2: Eye_Visualizer
# 需要导入模块: from gl_utils.trackball import Trackball [as 别名]
# 或者: from gl_utils.trackball.Trackball import push [as 别名]
class Eye_Visualizer(Visualizer):
def __init__(self,g_pool , focal_length ):
super(Eye_Visualizer, self).__init__(g_pool , "Debug Visualizer", False)
self.focal_length = focal_length
self.image_width = 640 # right values are assigned in update
self.image_height = 480
camera_fov = math.degrees(2.0 * math.atan( self.image_height / (2.0 * self.focal_length)))
self.trackball = Trackball(camera_fov)
############## MATRIX FUNCTIONS ##############################
def get_anthropomorphic_matrix(self):
temp = np.identity(4)
temp[2,2] *= -1
return temp
def get_adjusted_pixel_space_matrix(self,scale):
# returns a homoegenous matrix
temp = self.get_anthropomorphic_matrix()
temp[3,3] *= scale
return temp
def get_image_space_matrix(self,scale=1.):
temp = self.get_adjusted_pixel_space_matrix(scale)
temp[1,1] *=-1 #image origin is top left
temp[0,3] = -self.image_width/2.0
temp[1,3] = self.image_height/2.0
temp[2,3] = -self.focal_length
return temp.T
def get_pupil_transformation_matrix(self,circle_normal,circle_center, circle_scale = 1.0):
"""
OpenGL matrix convention for typical GL software
with positive Y=up and positive Z=rearward direction
RT = right
UP = up
BK = back
POS = position/translation
US = uniform scale
float transform[16];
[0] [4] [8 ] [12]
[1] [5] [9 ] [13]
[2] [6] [10] [14]
[3] [7] [11] [15]
[RT.x] [UP.x] [BK.x] [POS.x]
[RT.y] [UP.y] [BK.y] [POS.y]
[RT.z] [UP.z] [BK.z] [POS.Z]
[ ] [ ] [ ] [US ]
"""
temp = self.get_anthropomorphic_matrix()
right = temp[:3,0]
up = temp[:3,1]
back = temp[:3,2]
translation = temp[:3,3]
back[:] = np.array(circle_normal)
back[2] *=-1 #our z axis is inverted
if np.linalg.norm(back) != 0:
back[:] /= np.linalg.norm(back)
right[:] = get_perpendicular_vector(back)/np.linalg.norm(get_perpendicular_vector(back))
up[:] = np.cross(right,back)/np.linalg.norm(np.cross(right,back))
right[:] *= circle_scale
back[:] *=circle_scale
up[:] *=circle_scale
translation[:] = np.array(circle_center)
translation[2] *= -1
return temp.T
############## DRAWING FUNCTIONS ##############################
def draw_debug_info(self, result ):
models = result['models']
eye = models[0]['sphere'];
direction = result['circle'][1];
pupil_radius = result['circle'][2];
status = ' Eyeball center : X: %.2fmm Y: %.2fmm Z: %.2fmm\n Pupil direction: X: %.2f Y: %.2f Z: %.2f\n Pupil Diameter: %.2fmm\n ' \
%(eye[0][0], eye[0][1],eye[0][2],
direction[0], direction[1],direction[2], pupil_radius*2)
self.glfont.push_state()
self.glfont.set_color_float( (0,0,0,1) )
self.glfont.draw_multi_line_text(5,20,status)
#draw model info for each model
delta_y = 20
for model in models:
modelStatus = ('Model: %d \n' % model['model_id'] ,
' age: %.1fs\n' %(self.g_pool.get_timestamp()-model['birth_timestamp']) ,
' maturity: %.3f\n' % model['maturity'] ,
' solver fit: %.6f\n' % model['solver_fit'] ,
' confidence: %.6f\n' % model['confidence'] ,
#.........这里部分代码省略.........
示例3: Visualizer
# 需要导入模块: from gl_utils.trackball import Trackball [as 别名]
# 或者: from gl_utils.trackball.Trackball import push [as 别名]
#.........这里部分代码省略.........
glMatrixMode(GL_MODELVIEW )
glLoadMatrixf(self.get_pupil_transformation_matrix(circle_normal,circle_center, circle_radius))
draw_polyline((vertices),color=color, line_type = GL_TRIANGLE_FAN) # circle
draw_polyline( [ (0,0,0), (0,0, 4) ] ,color=RGBA(0,0,0), line_type = GL_LINES) #normal
glPopMatrix()
def draw_contours(self, contours, thickness = 1, color = RGBA(0.,0.,0.,0.5) ):
glPushMatrix()
glLoadMatrixf(self.get_anthropomorphic_matrix())
for contour in contours:
draw_polyline(contour, thickness, color = color )
glPopMatrix()
def draw_contour(self, contour, thickness = 1, color = RGBA(0.,0.,0.,0.5) ):
glPushMatrix()
glLoadMatrixf(self.get_anthropomorphic_matrix())
draw_polyline(contour,thickness, color)
glPopMatrix()
def draw_debug_info(self, result ):
models = result['models']
eye = models[0]['sphere'];
direction = result['circle'][1];
pupil_radius = result['circle'][2];
status = ' Eyeball center : X: %.2fmm Y: %.2fmm Z: %.2fmm\n Pupil direction: X: %.2f Y: %.2f Z: %.2f\n Pupil Diameter: %.2fmm\n ' \
%(eye[0][0], eye[0][1],eye[0][2],
direction[0], direction[1],direction[2], pupil_radius*2)
self.glfont.push_state()
self.glfont.set_color_float( (0,0,0,1) )
self.glfont.draw_multi_line_text(5,20,status)
#draw model info for each model
delta_y = 20
for model in models:
modelStatus = ('Model: %d \n ' % model['modelID'] ,
' maturity: %.3f\n' % model['maturity'] ,
' fit: %.6f\n' % model['fit'] ,
' performance: %.6f\n' % model['performance'] ,
' perf.Grad.: %.3e\n' % model['performanceGradient'] ,
)
modeltext = ''.join( modelStatus )
self.glfont.draw_multi_line_text(self.window_size[0] - 200 ,delta_y, modeltext)
delta_y += 100
self.glfont.pop_state()
########## Setup functions I don't really understand ############
def basic_gl_setup(self):
glEnable(GL_POINT_SPRITE )
glEnable(GL_VERTEX_PROGRAM_POINT_SIZE) # overwrite pointsize
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
glEnable(GL_BLEND)
glClearColor(.8,.8,.8,1.)
glEnable(GL_LINE_SMOOTH)
# glEnable(GL_POINT_SMOOTH)
示例4: Calibration_Visualizer
# 需要导入模块: from gl_utils.trackball import Trackball [as 别名]
# 或者: from gl_utils.trackball.Trackball import push [as 别名]
#.........这里部分代码省略.........
# Register callbacks window
glfwSetFramebufferSizeCallback(self.window,self.on_resize)
glfwSetWindowIconifyCallback(self.window,self.on_iconify)
glfwSetKeyCallback(self.window,self.on_key)
glfwSetCharCallback(self.window,self.on_char)
glfwSetMouseButtonCallback(self.window,self.on_button)
glfwSetCursorPosCallback(self.window,self.on_pos)
glfwSetScrollCallback(self.window,self.on_scroll)
# get glfw started
if self.run_independently:
init()
self.basic_gl_setup()
self.glfont = fs.Context()
self.glfont.add_font('opensans',get_opensans_font_path())
self.glfont.set_size(22)
self.glfont.set_color_float((0.2,0.5,0.9,1.0))
self.on_resize(self.window,*glfwGetFramebufferSize(self.window))
glfwMakeContextCurrent(active_window)
# self.gui = ui.UI()
def update_window(self, g_pool , gaze_points0 , sphere0 , gaze_points1 = [] , sphere1 = None, intersection_points = [] ):
if self.window:
if glfwWindowShouldClose(self.window):
self.close_window()
return
active_window = glfwGetCurrentContext()
glfwMakeContextCurrent(self.window)
self.clear_gl_screen()
self.trackball.push()
# use opencv coordinate system
#glMatrixMode( GL_PROJECTION )
#glScalef( 1. ,-1. , -1. )
glMatrixMode( GL_MODELVIEW )
# draw things in world camera coordinate system
glPushMatrix()
glLoadIdentity()
calibration_points_line_color = RGBA(0.5,0.5,0.5,0.05);
error_line_color = RGBA(1.0,0.0,0.0,0.5)
self.draw_coordinate_system(200)
self.draw_frustum( self.world_camera_width/ 10.0 , self.world_camera_height/ 10.0 , self.world_camera_focal / 10.0)
for p in self.cal_ref_points_3d:
draw_polyline( [ (0,0,0), p] , 1 , calibration_points_line_color, line_type = GL_LINES)
#calibration points
draw_points( self.cal_ref_points_3d , 4 , RGBA( 0, 1, 1, 1 ) )
glPopMatrix()
if sphere0:
# draw things in first eye oordinate system
glPushMatrix()
glLoadMatrixf( self.eye_to_world_matrix0.T )
sphere_center0 = list(sphere0['center'])
sphere_radius0 = sphere0['radius']