# 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/grid.py
# def initialize():
# def gt2grid(gtstr, chars='*rR'):
# def grid2gt(occ):
# def initialize_with_groundtruth(GT):
# def window_correction(occA, vacA, occB, vacB):
#     def error(t):
# def xcorr_correction(A, B):
#     def convolve(p1, p2):
#     def best(cc):
# def show_votegrid(vg, color=(1,0,0), opacity=1):
# def has_previous_estimate():
# def apply_correction(grid, bx,bz,rot):
# def center(R_aligned, occ_new, vac_new):
# def nearest(R_previous, R_aligned):
# def align_with_previous(R_aligned, occ_new, vac_new):
# def stencil_carve(depth, rect, R_correct, occ, vac, rgb=None):
# def merge_with_previous(occ_, vac_, occ_stencil, vac_stencil, color_=None):
# def update_previous_estimate(R_correct):
#     B = apply_correction(B, x, z, r)
#     B = apply_correction(B, bx, bz, br)
#     X,Y,Z = np.array(gridmax)-gridmin
#     M = [expmap.axis2rot(np.array([0,-i*np.pi/2,0])) for i in range(4)]
# 
# Path: blockplayer/main.py
# def initialize():
# def update_frame(depth, rgb=None):
#     def from_rect(m,rect):
#     def matrix_slerp(matA, matB, alpha=0.6):


import os
import shutil
import numpy as np
import time
import json
import glob
import cPickle as pickle
import glxcontext
        import re
from blockplayer import dataset
from blockplayer import grid
from blockplayer import main
from OpenGL.GL import glGetString, GL_VERSION
        with open('data/experiments/gt/gt%d.txt' % number) as f:
            GT = grid.gt2grid(f.read())
        grid.initialize_with_groundtruth(GT)

        total = 0
        output = []
        try:
            while 1:
                try:
                    dataset.advance()
                except (IOError, ValueError):
                    break
                if dataset.frame_num % 30 == 0:
                    print name, dataset.frame_num
                t1 = time.time()
                once()
                t2 = time.time()
                total += t2-t1

                output.append((main.R_correct.copy(), grid.occ.copy()))
        except Exception as e:
            print e

        d['frames'] = dataset.frame_num
        d['time'] = total
        d['output'] = output
        with open(os.path.join(folder, 'output.pkl'),'w') as f:
            pickle.dump(d, f)

        with open(os.path.join(folder, 'final_output.txt'),'w') as f:

# 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/grid.py
# def initialize():
# def gt2grid(gtstr, chars='*rR'):
# def grid2gt(occ):
# def initialize_with_groundtruth(GT):
# def window_correction(occA, vacA, occB, vacB):
#     def error(t):
# def xcorr_correction(A, B):
#     def convolve(p1, p2):
#     def best(cc):
# def show_votegrid(vg, color=(1,0,0), opacity=1):
# def has_previous_estimate():
# def apply_correction(grid, bx,bz,rot):
# def center(R_aligned, occ_new, vac_new):
# def nearest(R_previous, R_aligned):
# def align_with_previous(R_aligned, occ_new, vac_new):
# def stencil_carve(depth, rect, R_correct, occ, vac, rgb=None):
# def merge_with_previous(occ_, vac_, occ_stencil, vac_stencil, color_=None):
# def update_previous_estimate(R_correct):
#     B = apply_correction(B, x, z, r)
#     B = apply_correction(B, bx, bz, br)
#     X,Y,Z = np.array(gridmax)-gridmin
#     M = [expmap.axis2rot(np.array([0,-i*np.pi/2,0])) for i in range(4)]
# 
# Path: blockplayer/main.py
# def initialize():
# def update_frame(depth, rgb=None):
#     def from_rect(m,rect):
#     def matrix_slerp(matA, matB, alpha=0.6):


# Path: experiments/make_output.py
import os
import shutil
import numpy as np
import time
import json
import glob
import cPickle as pickle
import glxcontext
        import re
from blockplayer import dataset
from blockplayer import grid
from blockplayer import main
from OpenGL.GL import glGetString, GL_VERSION

        with open('data/experiments/gt/gt%d.txt' % number) as f:
            GT = grid.gt2grid(f.read())
        grid.initialize_with_groundtruth(GT)

        total = 0
        output = []
        try:
            while 1:
                try:
                    dataset.advance()
                except (IOError, ValueError):
                    break
                if dataset.frame_num % 30 == 0:
                    print name, dataset.frame_num
                t1 = time.time()
                once()
                t2 = time.time()
                total += t2-t1

                output.append((main.R_correct.copy(), grid.occ.copy()))
        except Exception as e:
            print e

        d['frames'] = dataset.frame_num
        d['time'] = total
        d['output'] = output
        with open(os.path.join(folder, 'output.pkl'),'w') as f:
            pickle.dump(d, f)

        with open(os.path.join(folder, 'final_output.txt'),'w') as f:

            f.write(grid.grid2gt(grid.occ))