class BlockWindow(PointWindow):

    def __init__(self, *args, **kwargs):
        self.modelmat = np.eye(4)
        self.flag_drawgrid = False
        super(BlockWindow,self).__init__(*args, **kwargs)

    def draw_board(self):
        LW,LH = config.LW, config.LH
        glPolygonOffset(1.0,0.2)
        glEnable(GL_POLYGON_OFFSET_FILL)

        # Draw the gray table
        if 'bg' in config.__dict__:
            glBegin(GL_QUADS)
            glColor(0.2,0.2,0.2,1)
            for x,y,z in config.bg['boundptsM']:
                glVertex(x,y,z)
            glEnd()

        glPushMatrix()
        glMultMatrixf(np.linalg.inv(self.modelmat).transpose())
        glScale(LW,LH,LW)

        glEnable(GL_BLEND)
        glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA)
        glPushMatrix()
        glTranslate(*config.bounds[0])
        blockdraw.draw()
        glPopMatrix()

        # Draw the shadow blocks (occlusions)
        glDisable(GL_POLYGON_OFFSET_FILL)

        # Draw the axes for the model coordinate space
        glLineWidth(3)
        glBegin(GL_LINES)
        glColor3f(1,0,0); glVertex3f(0,0,0); glVertex3f(1,0,0)
        glColor3f(0,1,0); glVertex3f(0,0,0); glVertex3f(0,1,0)
        glColor3f(0,0,1); glVertex3f(0,0,0); glVertex3f(0,0,1)
        glEnd()

        # Draw a grid for the model coordinate space
        if self.flag_drawgrid:
            glLineWidth(1)
            glBegin(GL_LINES)
            GR = config.GRIDRAD/2
            glColor3f(1.0,1.0,1.0)
            for j in range(0,1):
                for i in range(-GR,GR+1):
                    glVertex(i,j,-GR); glVertex(i,j,GR)
                    glVertex(-GR,j,i); glVertex(GR,j,i)
            glEnd()
            glPopMatrix()
            pass
        glLineWidth(1)

    def on_draw(self):
        super(BlockWindow,self).set_camera()

        glClearColor(*self.clearcolor)
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
        glEnable(GL_DEPTH_TEST)

        self._wrap('pre_draw')

        if not self.modelmat is None:
            self.draw_points()
            self.draw_board()

        self._wrap('post_draw') def load(dir_path):
def save(dir_path):
LH = 0.0192
LW = 0.016
GRIDRAD = 18 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') 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)) 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)] def color_dict():
def print_colors():    
def setup():
def render_blocks(occ_grid, modelmat, rect=((0,0),(640,480))):
def stencil_carve(depth, modelmat, occ_grid, rgb=None, rect=((0,0),(640,480))):
        F = np.array([[[t, 255, 255]]], dtype='u1')
        F = cv.fromarray(F)
        F = np.asarray(F)
    (L,T),(R,B) = rect
    (L,T),(R,B) = rect
    L,T,R,B = map(int, (L,T,R,B))
    RGB = np.zeros((b_total.shape[0],
                    b_total.shape[1],
                    b_total.shape[2], 3),'u1')
    HSV = np.zeros((b_total.shape[0],
                    b_total.shape[1],
                    b_total.shape[2], 3),'u1')
        HSV = np.asarray(HSVm).reshape(HSV.shape)
        RGB = np.asarray(RGBm).reshape(RGB.shape)
        RGB = (RGB.astype('i')*4).clip(0,255) def clear():
def show_grid(name, grid,
              color=np.array([1,0,0,1]), opacity=1.0,
              line_color=np.array([1,1,1,1])):
def draw_block(blocks):
def grid_vertices(grid, color=None):
def grid_vertices_numpy(grid, color=None):
def draw(): def advance(skip=1):
def setup_opencl():
def load_dataset(pathname):
def load_gt():
def load_random_dataset():
def download(): def initialize():
def update_frame(depth, rgb=None):
    def from_rect(m,rect):
    def matrix_slerp(matA, matB, alpha=0.6): def color_map(depth): def centered_rotated(R_correct, occ):
def translated_rotated(R_correct, occ):
import numpy as np
import pylab
import opennpy
import os
import cv
            import re
from OpenGL.GL import *
from blockplayer.blockwindow import BlockWindow
from blockplayer import config
from blockplayer import opencl
from blockplayer import lattice
from blockplayer import grid
from blockplayer import stencil
from blockplayer import blockdraw
from blockplayer import dataset
from blockplayer import main
from blockplayer import colormap
from blockplayer import blockcraft
# Andrew Miller <amiller@cs.ucf.edu> 2011
#
# BlockPlayer - 3D model reconstruction using the Lattice-First algorithm
# See: 
#    "Interactive 3D Model Acquisition and Tracking of Building Block Structures"
#    Andrew Miller, Brandyn White, Emiko Charbonneau, Zach Kanzler, and Joseph J. LaViola Jr.
#    IEEE VR 2012, IEEE TVGC 2012
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this file,
# You can obtain one at http://mozilla.org/MPL/2.0/.


if not 'FOR_REAL' in globals():
    FOR_REAL = False

global window
if not 'window' in globals():
    window = BlockWindow(title='demo_grid', size=(640,480))
    window.Move((0,0))



def show_rotated():

    g = main.grid.occ