# Path: s2p/common.py
# def remove(target):
# def garbage_cleanup():
# def tmpfile(ext=''):
# def run(cmd, env=os.environ):
# def mkdir_p(path):
# def shellquote(s):
# def matrix_translation(x, y):
# def image_size_gdal(im):
# def gdal_read_as_array_with_nans(im):
# def image_zoom_out_morpho(im, f):
# def rasterio_write(path, array, profile={}, tags={}):
# def image_apply_homography(out, im, H, w, h):
# def image_qauto(im, out=None):
# def points_apply_homography(H, pts):
# def bounding_box2D(pts):
# def image_crop_gdal(im, x, y, w, h, out=None):
# def run_binary_on_list_of_points(points, binary, option=None, env_var=None):
# def get_rectangle_coordinates(im):
# def get_roi_coordinates(img, preview):
# def cargarse_basura(inputf, outputf):
# def print_elapsed_time(since_first_call=False):
# class RunFailure(Exception):


import os
import json
import argparse
import s2p
    import tempfile
    import os.path
    import os.path
from codecs import open
from s2p import common

    The output file can be viewed with a web browser. This is useful for
    huge point clouds. The input is a list of ply files.

    If PotreeConverter is not available it doesn't fail.

    Args:
        output: path to the output folder
        input_plys: list of paths to ply files
    """
    ply2ascii       = os.path.join(bin_dir, 'plytool/ply2ascii')
    txt2las         = os.path.join(bin_dir, 'PotreeConverter/LAStools/bin/txt2las')
    PotreeConverter = os.path.join(bin_dir, 'PotreeConverter/build/PotreeConverter/PotreeConverter')

    #if (not os.path.exists(ply2ascii)) or (not os.path.exists(txt2las)) or (not os.path.exists(PotreeConverter)) :
    #    return

    outdir = os.path.dirname(output)

    plys = ' '.join(input_plys)

    las = []
    trash = []

    for p in input_plys:
        # make ascii ply if needed
        ap = tmpfile('.ply', outdir)
        lp = tmpfile('.las', outdir)

        las.append(lp)

# Path: s2p/common.py
# def remove(target):
# def garbage_cleanup():
# def tmpfile(ext=''):
# def run(cmd, env=os.environ):
# def mkdir_p(path):
# def shellquote(s):
# def matrix_translation(x, y):
# def image_size_gdal(im):
# def gdal_read_as_array_with_nans(im):
# def image_zoom_out_morpho(im, f):
# def rasterio_write(path, array, profile={}, tags={}):
# def image_apply_homography(out, im, H, w, h):
# def image_qauto(im, out=None):
# def points_apply_homography(H, pts):
# def bounding_box2D(pts):
# def image_crop_gdal(im, x, y, w, h, out=None):
# def run_binary_on_list_of_points(points, binary, option=None, env_var=None):
# def get_rectangle_coordinates(im):
# def get_roi_coordinates(img, preview):
# def cargarse_basura(inputf, outputf):
# def print_elapsed_time(since_first_call=False):
# class RunFailure(Exception):


# Path: utils/s2p_to_potree.py
import os
import json
import argparse
import s2p
    import tempfile
    import os.path
    import os.path
from codecs import open
from s2p import common


    The output file can be viewed with a web browser. This is useful for
    huge point clouds. The input is a list of ply files.

    If PotreeConverter is not available it doesn't fail.

    Args:
        output: path to the output folder
        input_plys: list of paths to ply files
    """
    ply2ascii       = os.path.join(bin_dir, 'plytool/ply2ascii')
    txt2las         = os.path.join(bin_dir, 'PotreeConverter/LAStools/bin/txt2las')
    PotreeConverter = os.path.join(bin_dir, 'PotreeConverter/build/PotreeConverter/PotreeConverter')

    #if (not os.path.exists(ply2ascii)) or (not os.path.exists(txt2las)) or (not os.path.exists(PotreeConverter)) :
    #    return

    outdir = os.path.dirname(output)

    plys = ' '.join(input_plys)

    las = []
    trash = []

    for p in input_plys:
        # make ascii ply if needed
        ap = tmpfile('.ply', outdir)
        lp = tmpfile('.las', outdir)

        las.append(lp)

        common.run("%s < %s > %s" % (ply2ascii, p, ap))