# 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/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/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_():


import cv
import pylab
import numpy as np
import timeit
import opennpy
from OpenGL.GL import *
from blockplayer.visuals.pointwindow import PointWindow
from blockplayer import dataset
from blockplayer import normals
from blockplayer import config
from blockplayer import preprocess
    cv.SetData(im, np.dstack(3*[w]) * n[:,:,::-1]/2+.5)
    cv.ShowImage(name, im)


def show_normals_sphere(n, w):
    global axes_rotation
    axes_rotation = np.eye(4)
    window.upvec = axes_rotation[:3,1]

    R,G,B = color_axis(n)
    window.update_xyz(n[:,:,0], n[:,:,1], n[:,:,2], (R+.5,G+.5,B+.5,w*(R+G+B)))
    window.Refresh()


def go(dset=None, frame_num=0, forreal=False):
    global FOR_REAL
    FOR_REAL = forreal
    start(dset, frame_num)
    resume()


def resume():
    while 1: once()


def start(dset=None, frame_num=0):
    if not FOR_REAL:
        if dset is None:
            dataset.load_random_dataset()
        else:

# 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/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/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: demos/demo_normals.py
import cv
import pylab
import numpy as np
import timeit
import opennpy
from OpenGL.GL import *
from blockplayer.visuals.pointwindow import PointWindow
from blockplayer import dataset
from blockplayer import normals
from blockplayer import config
from blockplayer import preprocess

    cv.SetData(im, np.dstack(3*[w]) * n[:,:,::-1]/2+.5)
    cv.ShowImage(name, im)


def show_normals_sphere(n, w):
    global axes_rotation
    axes_rotation = np.eye(4)
    window.upvec = axes_rotation[:3,1]

    R,G,B = color_axis(n)
    window.update_xyz(n[:,:,0], n[:,:,1], n[:,:,2], (R+.5,G+.5,B+.5,w*(R+G+B)))
    window.Refresh()


def go(dset=None, frame_num=0, forreal=False):
    global FOR_REAL
    FOR_REAL = forreal
    start(dset, frame_num)
    resume()


def resume():
    while 1: once()


def start(dset=None, frame_num=0):
    if not FOR_REAL:
        if dset is None:
            dataset.load_random_dataset()
        else:

            dataset.load_dataset(dset)