# 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/hashalign.py
# def features_weave(Ar):
# def find_features(A):
# def diff_coord(a, b, ashape):
# def apply_correction(grid, bx, by, bz,rot):
# def match_features(A, B, sq):
# def correction2modelmat(R_aligned, x, y, z, r):
# def find_best_alignment(occA, vacA, occB, vacB,
#                         R_aligned=None, prev_R_Correct=None):
#     def error(occA, vacA, occB, vacB):
#     def error_weave(occA, vacA, occB, vacB, bx, bz, term):
#     WX, WY, WZ = Ar.shape
#     R = expmap.axis2rot(np.array([0,-r*np.pi/2,0]))
#     A,B = occA, occB
#             R = correction2modelmat(R_aligned, 0, 0, 0, r)
# 
# 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)]


import glob
import os
import numpy as np
import cPickle as pickle
import pylab
import re
            import re
        import re
from blockplayer import dataset
from blockplayer import config
from blockplayer import hashalign
from blockplayer import grid
            gt = hashalign.apply_correction(gt, *c)
            added = hashalign.apply_correction(added, *c)
            removed = hashalign.apply_correction(removed, *c)
            should_be_there = gt | added 
            shouldnot_be_there = (~gt & ~added) | removed

            # Sanity check
            assert np.all(shouldnot_be_there ^ should_be_there)

            red = ~out & should_be_there
            yellow = out & shouldnot_be_there # Incorrect add
            purple = ~out & removed # Correct remove
            blue = out & added # Correct add
            green = out & gt # Correct block place

            # Sanity checks
            assert np.all(red+yellow+purple+blue+green <= 1)
            assert np.sum(red) + np.sum(blue) + np.sum(green) == np.sum(should_be_there)

        err = np.sum(yellow | red) 
        totalblocks = np.sum(red | green | blue)
        print err, totalblocks, float(err)/totalblocks

        #_,_,err1,_,_ = grid.xcorr_correction(out, config.GT)
        #assert err == err1/float(gt.sum())
        d[name] = {'err': err,
                   'tot': (red+green+blue).sum(),
                   'rel': err/float(totalblocks),
                   'num': number,
                   'type': kind,}

# 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/hashalign.py
# def features_weave(Ar):
# def find_features(A):
# def diff_coord(a, b, ashape):
# def apply_correction(grid, bx, by, bz,rot):
# def match_features(A, B, sq):
# def correction2modelmat(R_aligned, x, y, z, r):
# def find_best_alignment(occA, vacA, occB, vacB,
#                         R_aligned=None, prev_R_Correct=None):
#     def error(occA, vacA, occB, vacB):
#     def error_weave(occA, vacA, occB, vacB, bx, bz, term):
#     WX, WY, WZ = Ar.shape
#     R = expmap.axis2rot(np.array([0,-r*np.pi/2,0]))
#     A,B = occA, occB
#             R = correction2modelmat(R_aligned, 0, 0, 0, r)
# 
# 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: experiments/exp_avg.py
import glob
import os
import numpy as np
import cPickle as pickle
import pylab
import re
            import re
        import re
from blockplayer import dataset
from blockplayer import config
from blockplayer import hashalign
from blockplayer import grid

            gt = hashalign.apply_correction(gt, *c)
            added = hashalign.apply_correction(added, *c)
            removed = hashalign.apply_correction(removed, *c)
            should_be_there = gt | added 
            shouldnot_be_there = (~gt & ~added) | removed

            # Sanity check
            assert np.all(shouldnot_be_there ^ should_be_there)

            red = ~out & should_be_there
            yellow = out & shouldnot_be_there # Incorrect add
            purple = ~out & removed # Correct remove
            blue = out & added # Correct add
            green = out & gt # Correct block place

            # Sanity checks
            assert np.all(red+yellow+purple+blue+green <= 1)
            assert np.sum(red) + np.sum(blue) + np.sum(green) == np.sum(should_be_there)

        err = np.sum(yellow | red) 
        totalblocks = np.sum(red | green | blue)
        print err, totalblocks, float(err)/totalblocks

        #_,_,err1,_,_ = grid.xcorr_correction(out, config.GT)
        #assert err == err1/float(gt.sum())
        d[name] = {'err': err,
                   'tot': (red+green+blue).sum(),
                   'rel': err/float(totalblocks),
                   'num': number,
                   'type': kind,}

        d[name].update(dict(green=green,