# 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/dataset.py
# def advance(skip=1):
# def setup_opencl():
# def load_dataset(pathname):
# def load_gt():
# def load_random_dataset():
# def download():
# 
# Path: blockplayer/config.py
# def load(dir_path):
# def save(dir_path):
# LH = 0.0192
# LW = 0.016
# GRIDRAD = 18
# 
# Path: blockplayer/preprocess.py
# def threshold_and_mask(depth,bg):
#     def m_():
#     def m2_():
#     def m3_():
# 
# Path: blockplayer/normals.py
# def normals_opencl(depth, mask=None, rect=((0,0),(640,480)), win=6):
#     def from_rect(m,rect):
# def normal_show(nx,ny,nz):
# def normals_numpy(depth, rect=((0,0),(640,480)), win=7, mat=None):
# def normals_c(depth, rect=((0,0),(640,480)), win=7):
# def color_axis(normals,d=0.1):
#     X,Y,Z,W = -dx, -dy, 0*dy+1, -(-dx*u + -dy*v + depth).astype(np.float32)
#     X,Y,Z = [normals[:,:,i] for i in range(3)]
# 
# 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: 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))


import numpy as np
import pylab
import cv
from OpenGL.GL import *
from blockplayer import expmap
from blockplayer import dataset
from blockplayer import config
from blockplayer import preprocess
from blockplayer import normals
from blockplayer import opencl
from blockplayer import lattice
from blockplayer.visuals.pointwindow import PointWindow



global window
if not 'window' in globals():
    window = PointWindow(title='flatrot_opencl', size=(640,480))


def show_flatrot():
    pass


def show_normals_sphere(n, w):
    R,G,B = color_axis(n)
    window.update_xyz(n[:,:,0], n[:,:,1], n[:,:,2], (R,G,B,w*(R+G+B)))
    window.upvec = np.array([0,1,0])

# 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/dataset.py
# def advance(skip=1):
# def setup_opencl():
# def load_dataset(pathname):
# def load_gt():
# def load_random_dataset():
# def download():
# 
# Path: blockplayer/config.py
# def load(dir_path):
# def save(dir_path):
# LH = 0.0192
# LW = 0.016
# GRIDRAD = 18
# 
# Path: blockplayer/preprocess.py
# def threshold_and_mask(depth,bg):
#     def m_():
#     def m2_():
#     def m3_():
# 
# Path: blockplayer/normals.py
# def normals_opencl(depth, mask=None, rect=((0,0),(640,480)), win=6):
#     def from_rect(m,rect):
# def normal_show(nx,ny,nz):
# def normals_numpy(depth, rect=((0,0),(640,480)), win=7, mat=None):
# def normals_c(depth, rect=((0,0),(640,480)), win=7):
# def color_axis(normals,d=0.1):
#     X,Y,Z,W = -dx, -dy, 0*dy+1, -(-dx*u + -dy*v + depth).astype(np.float32)
#     X,Y,Z = [normals[:,:,i] for i in range(3)]
# 
# 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: 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: demos/demo_flatrot.py
import numpy as np
import pylab
import cv
from OpenGL.GL import *
from blockplayer import expmap
from blockplayer import dataset
from blockplayer import config
from blockplayer import preprocess
from blockplayer import normals
from blockplayer import opencl
from blockplayer import lattice
from blockplayer.visuals.pointwindow import PointWindow




global window
if not 'window' in globals():
    window = PointWindow(title='flatrot_opencl', size=(640,480))


def show_flatrot():
    pass


def show_normals_sphere(n, w):
    R,G,B = color_axis(n)
    window.update_xyz(n[:,:,0], n[:,:,1], n[:,:,2], (R,G,B,w*(R+G+B)))
    window.upvec = np.array([0,1,0])

    window.Refresh()