# Path: blockplayer/table_calibration.py
# def from_rect(m, rect):
# def finish_table_calib():
# def run_calib():
#     def pick(event):
# def make_mask(boundpts, size=(640,480)):
# def find_plane(depth, boundpts):
#     def draw():
#     KK = np.linalg.inv(calibkinect.projection()).astype('f')
#     KK = np.ascontiguousarray(KK)
# 
# Path: blockplayer/expmap.py
# def axis2rot(axis):
# def euler2rot(euler):
# def rot2axis(matrix):
# 	R = np.array([
# 		[ux*ux+(1-ux*ux)*c,  ux*uy*(1-c)-uz*s,  ux*uz*(1-c)+uy*s],
# 		[ux*uy*(1-c)+uz*s,   uy*uy+(1-uy*uy)*c, uy*uz*(1-c)-ux*s],
# 		[ux*uz*(1-c)-uy*s,   uz*uy*(1-c)+ux*s,  uz*uz+(1-uz*uz)*c]])
#   R = numpy.array(matrix, dtype=numpy.float32)
#   R33 = R[:3, :3]
# 
# Path: blockplayer/lattice.py
# def circular_mean(data, modulo):
# def color_axis(X,Y,Z,w,d=0.3):
# def project(X, Y, Z, mat):
# def orientation_opencl(noshow=None):
# def orientation_numpy(normals,weights):
# def translation_opencl(R_oriented, init_t=None):
#   def cmean(mxy,c):
# def is_valid_estimate():
# def translation_numpy(n,w,depth,mat,matxyz,rect,init_t=None):
#   X2,Y2,Z2 = X*X,Y*Y,Z*Z
#   X,Y,Z = project(u.astype('f'),v.astype('f'),depth[t:b,l:r].astype('f'),
#                   np.dot(modelmat, matxyz))
#     X,Y,Z = project(u.astype('f'),v.astype('f'),depth[t:b,l:r].astype('f'),
#                     np.dot(modelmat, matxyz))
#   XYZ = ((X,Y,Z))
# 
# Path: blockplayer/config.py
# def load(dir_path):
# def save(dir_path):
# LH = 0.0192
# LW = 0.016
# GRIDRAD = 18
# 
# Path: blockplayer/opencl.py
# def print_info(obj, info_cls):
# def normal_maker(name, mat, matw, matr):
#   def tup(i):
#   def tupw(i):
#   def tupr(i):
# def setup_kernel(mats=None):
#     def workaround(self):
# def print_all():
# def set_rect(_rect):
# def load_mask(mask):
# def load_raw(depth):
# def load_filt(filt):
# def get_xyz():
# def get_normals():
# def get_flatrot():
# def get_modelxyz():
# def get_face_debug():
# def get_gridinds_debug():
# def get_gridinds():
# def compute_normals():
# def compute_flatrot(mat):
#   def f(m): return m.astype('f')
# def compute_lattice2(modelmat, modulo):
#   def f(m): return m.astype('f')
# def compute_gridinds(xfix, zfix, LW, LH, gridmin, gridmax):
# def reduce_flatrot():
# def reduce_lattice2():
#     KK, RT = mats
#   (L,T),(R,B) = rect;
#   (L,T),(R,B) = rect
#   (L,T),(R,B) = rect
#   (L,T),(R,B) = rect
#   (L,T),(R,B) = rect
#     (L,T),(R,B) = rect
#     (L,T),(R,B) = rect
#   (L,T),(R,B) = rect; bounds = np.array((L,T,R,B),'f')


import numpy as np
from OpenGL.GL import *
from blockplayer import table_calibration
from blockplayer import expmap
from blockplayer import lattice
from blockplayer import config
from blockplayer import opencl
from blockplayer import flatrot
    from blockplayer.visuals.pointwindow import PointWindow
        from blockplayer.config import LW,LH
    after running normals2_opencl"""
    table_calibration.finish_cube_calib('L')
    cXYZL = np.array(lattice.cXYZ)
    table_calibration.finish_cube_calib('R')
    cXYZR = np.array(lattice.cXYZ)
    cXYZ = np.hstack((cXYZL.reshape(3,-1), cXYZR.reshape(3,-1)))

    opencl.setup_kernel((config.bgL['KK'],config.bgL['Ktable']),
                        (config.bgR['KK'],config.bgR['Ktable']))

    opencl.compute_normals('LEFT')
    opencl.compute_normals('RIGHT')

    global modelmat
    modelmat = np.eye(4,dtype='f')
    modelmat[:3,:3] = flatrot.flatrot_opencl()
    modelmat = lattice.lattice2_opencl(modelmat)

    Xo,Yo,Zo,_ = np.rollaxis(opencl.get_xyz(),1)
    cx,cy,cz = cXYZ

    cany = (cx>0)|(cz>0)
    R,G,B = cx[cany],cy[cany],cz[cany]
    update(Xo[cany],Yo[cany],Zo[cany],COLOR=(R,G,B,R+G+B))
    window.mode = 'ortho'
    window.clearcolor = [1,1,1,0]
    window.Refresh()


def cubecalib():

# Path: blockplayer/table_calibration.py
# def from_rect(m, rect):
# def finish_table_calib():
# def run_calib():
#     def pick(event):
# def make_mask(boundpts, size=(640,480)):
# def find_plane(depth, boundpts):
#     def draw():
#     KK = np.linalg.inv(calibkinect.projection()).astype('f')
#     KK = np.ascontiguousarray(KK)
# 
# Path: blockplayer/expmap.py
# def axis2rot(axis):
# def euler2rot(euler):
# def rot2axis(matrix):
# 	R = np.array([
# 		[ux*ux+(1-ux*ux)*c,  ux*uy*(1-c)-uz*s,  ux*uz*(1-c)+uy*s],
# 		[ux*uy*(1-c)+uz*s,   uy*uy+(1-uy*uy)*c, uy*uz*(1-c)-ux*s],
# 		[ux*uz*(1-c)-uy*s,   uz*uy*(1-c)+ux*s,  uz*uz+(1-uz*uz)*c]])
#   R = numpy.array(matrix, dtype=numpy.float32)
#   R33 = R[:3, :3]
# 
# Path: blockplayer/lattice.py
# def circular_mean(data, modulo):
# def color_axis(X,Y,Z,w,d=0.3):
# def project(X, Y, Z, mat):
# def orientation_opencl(noshow=None):
# def orientation_numpy(normals,weights):
# def translation_opencl(R_oriented, init_t=None):
#   def cmean(mxy,c):
# def is_valid_estimate():
# def translation_numpy(n,w,depth,mat,matxyz,rect,init_t=None):
#   X2,Y2,Z2 = X*X,Y*Y,Z*Z
#   X,Y,Z = project(u.astype('f'),v.astype('f'),depth[t:b,l:r].astype('f'),
#                   np.dot(modelmat, matxyz))
#     X,Y,Z = project(u.astype('f'),v.astype('f'),depth[t:b,l:r].astype('f'),
#                     np.dot(modelmat, matxyz))
#   XYZ = ((X,Y,Z))
# 
# Path: blockplayer/config.py
# def load(dir_path):
# def save(dir_path):
# LH = 0.0192
# LW = 0.016
# GRIDRAD = 18
# 
# Path: blockplayer/opencl.py
# def print_info(obj, info_cls):
# def normal_maker(name, mat, matw, matr):
#   def tup(i):
#   def tupw(i):
#   def tupr(i):
# def setup_kernel(mats=None):
#     def workaround(self):
# def print_all():
# def set_rect(_rect):
# def load_mask(mask):
# def load_raw(depth):
# def load_filt(filt):
# def get_xyz():
# def get_normals():
# def get_flatrot():
# def get_modelxyz():
# def get_face_debug():
# def get_gridinds_debug():
# def get_gridinds():
# def compute_normals():
# def compute_flatrot(mat):
#   def f(m): return m.astype('f')
# def compute_lattice2(modelmat, modulo):
#   def f(m): return m.astype('f')
# def compute_gridinds(xfix, zfix, LW, LH, gridmin, gridmax):
# def reduce_flatrot():
# def reduce_lattice2():
#     KK, RT = mats
#   (L,T),(R,B) = rect;
#   (L,T),(R,B) = rect
#   (L,T),(R,B) = rect
#   (L,T),(R,B) = rect
#   (L,T),(R,B) = rect
#     (L,T),(R,B) = rect
#     (L,T),(R,B) = rect
#   (L,T),(R,B) = rect; bounds = np.array((L,T,R,B),'f')


# Path: demos/demo_cubecalib.py
import numpy as np
from OpenGL.GL import *
from blockplayer import table_calibration
from blockplayer import expmap
from blockplayer import lattice
from blockplayer import config
from blockplayer import opencl
from blockplayer import flatrot
    from blockplayer.visuals.pointwindow import PointWindow
        from blockplayer.config import LW,LH

    after running normals2_opencl"""
    table_calibration.finish_cube_calib('L')
    cXYZL = np.array(lattice.cXYZ)
    table_calibration.finish_cube_calib('R')
    cXYZR = np.array(lattice.cXYZ)
    cXYZ = np.hstack((cXYZL.reshape(3,-1), cXYZR.reshape(3,-1)))

    opencl.setup_kernel((config.bgL['KK'],config.bgL['Ktable']),
                        (config.bgR['KK'],config.bgR['Ktable']))

    opencl.compute_normals('LEFT')
    opencl.compute_normals('RIGHT')

    global modelmat
    modelmat = np.eye(4,dtype='f')
    modelmat[:3,:3] = flatrot.flatrot_opencl()
    modelmat = lattice.lattice2_opencl(modelmat)

    Xo,Yo,Zo,_ = np.rollaxis(opencl.get_xyz(),1)
    cx,cy,cz = cXYZ

    cany = (cx>0)|(cz>0)
    R,G,B = cx[cany],cy[cany],cz[cany]
    update(Xo[cany],Yo[cany],Zo[cany],COLOR=(R,G,B,R+G+B))
    window.mode = 'ortho'
    window.clearcolor = [1,1,1,0]
    window.Refresh()


def cubecalib():

    table_calibration.finish_cube_calib('L')