# Path: ldif/util/file_util.py
# def readlines(p):
# def readbin(p):
# def writebin(p, s):
# def writetxt(p, s):
# def write_np(path, arr):
# def read_grd(path):
# def read_sif_v1(path, verbose=False):
# def read_lines(p):
# def read_image(p):
# def read_npz(p):
# def read_np(p):
# def read_txt_to_np(p):
# def read_py2_pkl(p):
# def write_mesh(path, mesh):
# def read_mesh(path):
# def read_csv(path):
# def read_normals(path_to_dir, im_count=20, leading='_depth'):
# def write_points(path_ext_optional, points):
# def write_grd(path, volume, world2grid=None):
# def write_depth_image(path, depth_image):


import numpy as np
import tensorflow as tf
from ldif.util.file_util import log

  lca = np.split(lower_coords, 3, axis=-1)[::-1]
  uca = np.split(upper_coords, 3, axis=-1)[::-1]
  aca = np.split(alpha, 3, axis=-1)[::-1]  # ?

  c00 = grid[lca[0], lca[1], lca[2]] * (1 - aca[0]) + grid[uca[0], lca[1],
                                                           lca[2]] * aca[0]
  c01 = grid[lca[0], lca[1], uca[2]] * (1 - aca[0]) + grid[uca[0], lca[1],
                                                           uca[2]] * aca[0]
  c10 = grid[lca[0], uca[1], lca[2]] * (1 - aca[0]) + grid[uca[0], uca[1],
                                                           lca[2]] * aca[0]
  c11 = grid[lca[0], uca[1], uca[2]] * (1 - aca[0]) + grid[uca[0], uca[1],
                                                           uca[2]] * aca[0]

  c0 = c00 * (1 - aca[1]) + c10 * aca[1]
  c1 = c01 * (1 - aca[1]) + c11 * aca[1]

  interp = c0 * (1 - aca[2]) + c1 * aca[2]

  log.info('interpolated:')
  log.info(interp.shape)
  log.info(interp)
  log.info('lower coords:')
  log.info(np.min(lower_coords))
  log.info(np.max(lower_coords))
  log.info(np.mean(lower_coords))
  log.info('upper coords:')
  log.info(np.min(upper_coords))
  log.info(np.max(upper_coords))
  log.info(np.mean(upper_coords))

# Path: ldif/util/file_util.py
# def readlines(p):
# def readbin(p):
# def writebin(p, s):
# def writetxt(p, s):
# def write_np(path, arr):
# def read_grd(path):
# def read_sif_v1(path, verbose=False):
# def read_lines(p):
# def read_image(p):
# def read_npz(p):
# def read_np(p):
# def read_txt_to_np(p):
# def read_py2_pkl(p):
# def write_mesh(path, mesh):
# def read_mesh(path):
# def read_csv(path):
# def read_normals(path_to_dir, im_count=20, leading='_depth'):
# def write_points(path_ext_optional, points):
# def write_grd(path, volume, world2grid=None):
# def write_depth_image(path, depth_image):


# Path: ldif/util/interpolate_util.py
import numpy as np
import tensorflow as tf
from ldif.util.file_util import log


  lca = np.split(lower_coords, 3, axis=-1)[::-1]
  uca = np.split(upper_coords, 3, axis=-1)[::-1]
  aca = np.split(alpha, 3, axis=-1)[::-1]  # ?

  c00 = grid[lca[0], lca[1], lca[2]] * (1 - aca[0]) + grid[uca[0], lca[1],
                                                           lca[2]] * aca[0]
  c01 = grid[lca[0], lca[1], uca[2]] * (1 - aca[0]) + grid[uca[0], lca[1],
                                                           uca[2]] * aca[0]
  c10 = grid[lca[0], uca[1], lca[2]] * (1 - aca[0]) + grid[uca[0], uca[1],
                                                           lca[2]] * aca[0]
  c11 = grid[lca[0], uca[1], uca[2]] * (1 - aca[0]) + grid[uca[0], uca[1],
                                                           uca[2]] * aca[0]

  c0 = c00 * (1 - aca[1]) + c10 * aca[1]
  c1 = c01 * (1 - aca[1]) + c11 * aca[1]

  interp = c0 * (1 - aca[2]) + c1 * aca[2]

  log.info('interpolated:')
  log.info(interp.shape)
  log.info(interp)
  log.info('lower coords:')
  log.info(np.min(lower_coords))
  log.info(np.max(lower_coords))
  log.info(np.mean(lower_coords))
  log.info('upper coords:')
  log.info(np.min(upper_coords))
  log.info(np.max(upper_coords))
  log.info(np.mean(upper_coords))

  log.info('Interpolated SDF')