# Path: ldif/datasets/process_element.py
# def load_example_dict(example_directory, log_level=None):
# def _float_feature(value):
# def _bytes_feature(value):
# def make_tf_example(d):
# def full_featurespec():
# def parse_tf_example(example_proto):
# def _example_dict_tf_func_wrapper(mesh_orig_path):
# def parse_example(filename):
# 
# Path: ldif/scripts/make_example.py
# def remove_png_dir(d):
# def write_depth_and_normals_npz(dirpath, path_out):
# def mesh_to_example(codebase_root_dir, mesh_path, dirpath, skip_existing, log_level):
# 
# 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/path_util.py
# def get_path_to_ldif_root():
# def get_path_to_ldif_parent():
# def package_to_abs(path):
# def gaps_path():
# def test_data_path():
# def util_test_data_path():
# def create_test_output_dir():
# 
# 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 glob
import random
import os
import tqdm
import tensorflow as tf
from absl import app
from absl import flags
from joblib import Parallel, delayed
from ldif.datasets import process_element
from ldif.scripts import make_example
from ldif.util import file_util
from ldif.util import path_util
from ldif.util.file_util import log

def serialize(example_dir, log_level):
  d = process_element.load_example_dict(example_dir, log_level)
  s = process_element.make_tf_example(d)
  return s

def main(argv):
  if len(argv) > 1:
    raise app.UsageError('Too many command-line arguments.')
  random.seed(2077)
  log.set_level(FLAGS.log_level)

  n_jobs = os.cpu_count()
  assert FLAGS.max_threads != 0
  if FLAGS.max_threads > 0:
    n_jobs = FLAGS.max_threads

  mesh_directory = FLAGS.mesh_directory
  if mesh_directory[-1] == '/':
    mesh_directory = mesh_directory[:-1]

  files = glob.glob(f'{mesh_directory}/*/*/*.ply')

  if not files and not FLAGS.optimize_only:
    raise ValueError(f"Didn't find any ply files in {mesh_directory}. "
                     "Please make sure the directory structure is "
                     "[mesh_directory]/[splits]/[class names]/[ply files]")

  # Make the directories first because it's not threadsafe and also might fail.
  if files and not FLAGS.optimize_only:

# Path: ldif/datasets/process_element.py
# def load_example_dict(example_directory, log_level=None):
# def _float_feature(value):
# def _bytes_feature(value):
# def make_tf_example(d):
# def full_featurespec():
# def parse_tf_example(example_proto):
# def _example_dict_tf_func_wrapper(mesh_orig_path):
# def parse_example(filename):
# 
# Path: ldif/scripts/make_example.py
# def remove_png_dir(d):
# def write_depth_and_normals_npz(dirpath, path_out):
# def mesh_to_example(codebase_root_dir, mesh_path, dirpath, skip_existing, log_level):
# 
# 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/path_util.py
# def get_path_to_ldif_root():
# def get_path_to_ldif_parent():
# def package_to_abs(path):
# def gaps_path():
# def test_data_path():
# def util_test_data_path():
# def create_test_output_dir():
# 
# 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: meshes2dataset.py
import glob
import random
import os
import tqdm
import tensorflow as tf
from absl import app
from absl import flags
from joblib import Parallel, delayed
from ldif.datasets import process_element
from ldif.scripts import make_example
from ldif.util import file_util
from ldif.util import path_util
from ldif.util.file_util import log


def serialize(example_dir, log_level):
  d = process_element.load_example_dict(example_dir, log_level)
  s = process_element.make_tf_example(d)
  return s

def main(argv):
  if len(argv) > 1:
    raise app.UsageError('Too many command-line arguments.')
  random.seed(2077)
  log.set_level(FLAGS.log_level)

  n_jobs = os.cpu_count()
  assert FLAGS.max_threads != 0
  if FLAGS.max_threads > 0:
    n_jobs = FLAGS.max_threads

  mesh_directory = FLAGS.mesh_directory
  if mesh_directory[-1] == '/':
    mesh_directory = mesh_directory[:-1]

  files = glob.glob(f'{mesh_directory}/*/*/*.ply')

  if not files and not FLAGS.optimize_only:
    raise ValueError(f"Didn't find any ply files in {mesh_directory}. "
                     "Please make sure the directory structure is "
                     "[mesh_directory]/[splits]/[class names]/[ply files]")

  # Make the directories first because it's not threadsafe and also might fail.
  if files and not FLAGS.optimize_only:

    log.info('Creating directories...')