def get_height_result_s6(in_dir, sensor_d, gridSize, convt):

    if not os.path.isdir(in_dir):
        fail('Could not find input directory: ' + in_dir)
        return

    xRange = -1
    hist_data = np.zeros((4, 16, HIST_BIN_NUM))
    hist_subplot_data = np.zeros((32, HIST_BIN_NUM))

    # parse json file
    metafile, hist, hist_subplot = analysis_utils.find_result_file_s6(
        in_dir, sensor_d, gridSize)
    if metafile == [] or hist == [] or hist_subplot == []:
        return

    metadata = analysis_utils.lower_keys(analysis_utils.load_json(metafile))
    center_position = analysis_utils.get_position(metadata)
    hist_data = np.load(hist, 'r')
    hist_subplot_data = np.load(hist_subplot, 'r')

    for i in range(PLOT_RANGE_NUM):
        xmin = convt.np_bounds_subplot[i][0][0]
        xmax = convt.np_bounds_subplot[i][0][1]
        if (center_position[0] > xmin) and (center_position[0] <= xmax):
            xRange = i + 1
            break

    return [xRange, hist_data, hist_subplot_data]
def gen_hist_analysis(ply_path, json_path, out_dir, convt):

    baseName = os.path.basename(ply_path)
    print(baseName)

    if not os.path.isdir(ply_path):
        fail('Could not find input directory: ' + ply_path)

    if not os.path.isdir(out_dir):
        os.mkdir(out_dir)

    # parse json file
    metas, ply_file_wests, ply_file_easts, gImgWests, pImgWests, gImgEasts, pImgEasts = analysis_utils.find_input_files_all(
        ply_path, json_path)

    for meta, ply_file_west, ply_file_east, gImgWest, pImgWest, gImgEast, pImgEast in zip(
            metas, ply_file_wests, ply_file_easts, gImgWests, pImgWests,
            gImgEasts, pImgEasts):
        json_dst = os.path.join(out_dir, meta)
        if os.path.exists(json_dst):
            return

        metadata = analysis_utils.lower_keys(
            analysis_utils.load_json(os.path.join(json_path, meta))
        )  # make all our keys lowercase since keys appear to change case (???)

        center_position = analysis_utils.get_position(
            metadata)  # (x, y, z) in meters
        scanDirection = analysis_utils.get_direction(
            metadata)  # scan direction

        plyData = PlyData.read(os.path.join(ply_path, ply_file_west))

        print('west')
        hist_w = gen_height_histogram(plyData, scanDirection, out_dir, 'w',
                                      center_position, convt)
        if hist_w.max() == 0.0:
            return

        histPath = os.path.join(out_dir, 'hist_w.npy')
        try:
            np.save(histPath, hist_w)
        except Exception as ex:
            fail(str(ex))

        print("east")
        plyData = PlyData.read(os.path.join(ply_path, ply_file_east))
        hist_e = gen_height_histogram(plyData, scanDirection, out_dir, 'e',
                                      center_position, convt)
        if hist_e.max() == 0.0:
            return

        histPath = os.path.join(out_dir, 'hist_e.npy')
        np.save(histPath, hist_e)

        shutil.copyfile(os.path.join(json_path, meta), json_dst)

    return
def gen_hist_s4_analysis(ply_path, json_path, out_dir, convt):

    print('start processing gen_hist_s4_analysis')

    if not os.path.isdir(ply_path):
        fail('Could not find input directory: ' + ply_path)

    if not os.path.isdir(out_dir):
        os.mkdir(out_dir)

    # parse json file
    print('parse json file')
    metas, ply_file_wests, ply_file_easts = analysis_utils.find_input_files(
        ply_path, json_path)

    for meta, ply_file_west, ply_file_east in zip(metas, ply_file_wests,
                                                  ply_file_easts):
        json_dst = os.path.join(out_dir, meta)
        if os.path.exists(json_dst):
            return

        metadata = analysis_utils.lower_keys(
            analysis_utils.load_json(os.path.join(json_path, meta))
        )  # make all our keys lowercase since keys appear to change case (???)

        center_position = analysis_utils.get_position(
            metadata)  # (x, y, z) in meters
        scanDirection = analysis_utils.get_direction(
            metadata)  # scan direction

        plywest = PlyData.read(os.path.join(ply_path, ply_file_west))
        print('gen_height_histogram_four_plot_level west')
        hist_w, hist_subplot_w = gen_height_histogram(plywest, scanDirection,
                                                      out_dir, 'w',
                                                      center_position, convt)

        print('save npy file')
        histPath = os.path.join(out_dir, 'hist_w.npy')
        try:
            np.save(histPath, hist_w)
        except Exception as ex:
            fail(str(ex))
        histPath = os.path.join(out_dir, 'hist_subplot_w.npy')
        np.save(histPath, hist_subplot_w)

        plyeast = PlyData.read(os.path.join(ply_path, ply_file_east))
        hist_e, hist_subplot_e = gen_height_histogram(plyeast, scanDirection,
                                                      out_dir, 'e',
                                                      center_position, convt)

        histPath = os.path.join(out_dir, 'hist_e.npy')
        np.save(histPath, hist_e)
        histPath = os.path.join(out_dir, 'hist_subplot_e.npy')
        np.save(histPath, hist_subplot_e)

        shutil.copyfile(os.path.join(json_path, meta), json_dst)

    return
def get_height_result(full_path, sensor_d, convt):

    xRange = -1
    metafile, hist = analysis_utils.find_result_files(full_path, sensor_d)
    if metafile == [] or hist == []:
        return

    metadata = analysis_utils.lower_keys(analysis_utils.load_json(metafile))
    center_position = analysis_utils.get_position(metadata)
    hist_data = np.load(hist, 'r')

    for i in range(convt.max_range):
        xmin = convt.np_bounds[i][0][0]
        xmax = convt.np_bounds[i][0][1]
        if (center_position[0] > xmin) and (center_position[0] <= xmax):
            xRange = i + 1
            break

    return [xRange, hist_data]
def gen_hist_s6_analysis(ply_path, json_path, out_dir, convt):

    baseName = os.path.basename(ply_path)
    print(baseName)

    if not os.path.isdir(ply_path):
        fail('Could not find input directory: ' + ply_path)

    if not os.path.isdir(out_dir):
        os.mkdir(out_dir)

    # parse json file
    metas, ply_file_wests, ply_file_easts, gImgWests, pImgWests, gImgEasts, pImgEasts = analysis_utils.find_input_files_all(
        ply_path, json_path)

    for meta, ply_file_west, ply_file_east, gImgWest, pImgWest, gImgEast, pImgEast in zip(
            metas, ply_file_wests, ply_file_easts, gImgWests, pImgWests,
            gImgEasts, pImgEasts):
        json_dst = os.path.join(out_dir, meta)
        if os.path.exists(json_dst):
            return

        metadata = analysis_utils.lower_keys(
            analysis_utils.load_json(os.path.join(json_path, meta))
        )  # make all our keys lowercase since keys appear to change case (???)

        center_position = analysis_utils.get_position(
            metadata)  # (x, y, z) in meters
        scanDirection = analysis_utils.get_direction(
            metadata)  # scan direction

        plySrc = PlyData.read(os.path.join(ply_path, ply_file_west))
        pImg = cv2.imread(os.path.join(json_path, pImgWest), -1)
        gImg = cv2.imread(os.path.join(json_path, gImgWest), -1)

        print('west')
        for gridSize in (0, 2, 4, 8, 10, 15):
            plyData = analysis_utils.ply_down_sampling(pImg, gImg,
                                                       plySrc.elements[0],
                                                       gridSize, 0)
            hist_w, hist_subplot_w = gen_height_histogram_four_plot_level(
                plyData, scanDirection, out_dir, 'w', center_position, convt)

            histPath = os.path.join(out_dir,
                                    'hist_w_' + str(gridSize * 2) + '.npy')
            try:
                np.save(histPath, hist_w)
            except Exception as ex:
                fail(str(ex))
            histPath = os.path.join(
                out_dir, 'hist_subplot_w_' + str(gridSize * 2) + '.npy')
            np.save(histPath, hist_subplot_w)

        print("east")
        plySrc = PlyData.read(os.path.join(ply_path, ply_file_east))
        pImg = cv2.imread(os.path.join(json_path, pImgEast), -1)
        gImg = cv2.imread(os.path.join(json_path, gImgEast), -1)
        for gridSize in (0, 2, 4, 8, 10, 15):
            plyData = analysis_utils.ply_down_sampling(pImg, gImg,
                                                       plySrc.elements[0],
                                                       gridSize, 0)
            hist_e, hist_subplot_e = gen_height_histogram_four_plot_level(
                plyData, scanDirection, out_dir, 'e', center_position, convt)

            histPath = os.path.join(out_dir,
                                    'hist_e_' + str(gridSize * 2) + '.npy')
            np.save(histPath, hist_e)
            histPath = os.path.join(
                out_dir, 'hist_subplot_e_' + str(gridSize * 2) + '.npy')
            np.save(histPath, hist_subplot_e)

        shutil.copyfile(os.path.join(json_path, meta), json_dst)

    return