Ejemplo n.º 1
0
def deform_point_cloud(point_cloud,
                       strike,
                       dip,
                       d=0.01,
                       u_ss=1.0,
                       u_ds=1.0,
                       x0=None,
                       y0=None):

    from utils import get_xyz_from_pdal, put_xyz_to_pdal
    from pml import read_file

    xyz = get_xyz_from_pdal(read_file(point_cloud)) if isinstance(point_cloud, str) else \
        get_xyz_from_pdal(point_cloud[0]) if isinstance(point_cloud, list) else point_cloud if point_cloud.dtype.fields \
            is None else get_xyz_from_pdal(point_cloud)

    x = xyz[:, 0]
    y = xyz[:, 1]

    x0 = np.mean(x) if x0 is None else x0
    y0 = np.mean(y) if y0 is None else y0

    xt = x - x0
    yt = y - y0

    deltarad = np.deg2rad(dip)
    thetarad = np.deg2rad(strike)
    X1p = xt * np.cos(np.pi - thetarad) + yt * np.sin(np.pi - thetarad)
    Zeta = (X1p / d) - (1 / np.tan(deltarad))
    u1 = (u_ds / np.pi) * (np.cos(deltarad) * np.arctan(Zeta) +
                           (np.sin(deltarad) - Zeta * np.cos(deltarad)) /
                           (1 + np.power(Zeta, 2)))
    u3 = (-u_ds / np.pi) * (np.sin(deltarad) * np.arctan(Zeta) +
                            (np.cos(deltarad) + Zeta * np.sin(deltarad)) /
                            (1 + np.power(Zeta, 2)))
    u2 = (u_ss / np.pi) * (
        np.arctan2(Zeta * np.power(np.sin(deltarad), 2),
                   (1 - Zeta * np.sin(deltarad) * np.cos(deltarad))) +
        (deltarad - np.sign(deltarad) * np.pi / 2.0))

    u1p = u1 * np.cos(thetarad - np.pi) + u2 * np.sin(thetarad - np.pi)
    u2p = -u1 * np.sin(thetarad - np.pi) + u2 * np.cos(thetarad - np.pi)

    deformed_points = xyz + np.vstack((u1p, u2p, u3)).T

    return put_xyz_to_pdal(read_file(point_cloud), deformed_points) if isinstance(point_cloud, str) else \
        list(put_xyz_to_pdal(point_cloud[0])) if isinstance(point_cloud, list) \
            else put_xyz_to_pdal(point_cloud) if point_cloud.dtype.fields is not None else deformed_points
Ejemplo n.º 2
0
def test_dislocation(filename='hsl_101419_small.las',
                     strike=320,
                     dip=30,
                     ss=20.0,
                     ds=0.0,
                     d=0.01):
    from dislocation import deform_point_cloud
    from utils import get_xyz_from_pdal
    import matplotlib.pylab as plt

    pointcloud = get_xyz_from_pdal(pml.read_file(filename))
    pointcloud = pointcloud[0::1000, :]
    deformed_pointcloud = get_xyz_from_pdal(
        deform_point_cloud(filename, strike, dip, u_ss=ss, u_ds=ds,
                           d=d))[0::1000, :]

    plt.figure()
    plt.plot(pointcloud[:, 0], pointcloud[:, 1], 'k.')
    plt.figure()
    plt.plot(deformed_pointcloud[:, 0], deformed_pointcloud[:, 1], 'k.')
    plt.show()
Ejemplo n.º 3
0
def test_two_rotations(fixed, moving):

    from pml import icp, read_file, transform_pdal_array
    from utils import get_xyz_from_pdal

    fixed_array = read_file(fixed)
    moving_array = read_file(moving)

    transformed_array, (transform_matrix, center,
                        residual) = icp(fixed_array, moving_array)

    # perform second transformation:

    center_2 = center - 50.0

    transformed_array = transform_pdal_array(transformed_array,
                                             transform_matrix,
                                             center=center_2)

    # manually rotate moving points back:

    xyz_transformed = get_xyz_from_pdal(transformed_array)
    xyz_moving = get_xyz_from_pdal(moving_array) - center

    xyz_moving = np.concatenate((xyz_moving, np.ones(
        (xyz_moving.shape[0], 1))),
                                axis=1)

    xyz_manual_transform = np.matmul(xyz_moving,
                                     transform_matrix.T)[:, 0:3] + center
    xyz_manual_transform = np.concatenate(
        (xyz_manual_transform - center_2,
         np.ones((xyz_manual_transform.shape[0], 1))),
        axis=1)
    xyz_manual_transform = np.matmul(xyz_manual_transform,
                                     transform_matrix.T)[:, 0:3] + center_2

    return xyz_transformed, xyz_manual_transform
Ejemplo n.º 4
0
def test_one_rotation(fixed, moving):

    from pml import icp, read_file
    from utils import get_xyz_from_pdal

    fixed_array = read_file(fixed)
    moving_array = read_file(moving)

    transformed_array, (transform_matrix, center,
                        residual) = icp(fixed_array, moving_array)

    # manually rotate moving points back:

    xyz_transformed = get_xyz_from_pdal(transformed_array)
    xyz_moving = get_xyz_from_pdal(moving_array) - center

    xyz_moving = np.concatenate((xyz_moving, np.ones(
        (xyz_moving.shape[0], 1))),
                                axis=1)

    xyz_manual_transform = np.matmul(xyz_moving,
                                     transform_matrix.T)[:, 0:3] + center

    return xyz_transformed, xyz_manual_transform
Ejemplo n.º 5
0
def create_test_dataset(in_pt_cloud_filename=None,
                        x_a=1E-3,
                        x_b=0.5E-3,
                        x_c=-1.2E-3,
                        x_d=-0.8E-1,
                        x_e=-1.0E-1,
                        x_f=1.0,
                        y_a=-1.5E-4,
                        y_b=-1.0E-4,
                        y_c=0.72E-3,
                        y_d=0.75E-1,
                        y_e=1.4E-1,
                        y_f=-1.0,
                        z_a=1E-4,
                        z_b=-4E-4,
                        z_c=-6E-4,
                        z_d=-1E-1,
                        z_e=1E-1,
                        z_f=1.0):

    from utils import get_xyz_from_pdal, put_xyz_to_pdal
    from pml import read_file

    if in_pt_cloud_filename is None:
        in_pt_cloud = read_file('clip_small.txt')
    else:
        in_pt_cloud = read_file(in_pt_cloud_filename)

    xyz = get_xyz_from_pdal(in_pt_cloud)
    xyzm = np.mean(xyz, axis=0)
    xyz -= xyzm

    x = xyz[:, 0]
    y = xyz[:, 1]
    z = xyz[:, 2]

    dx = x_a * np.power(x, 2) + x_b * x * y + x_c * np.power(
        y, 2) + x_d * x + x_e * y + x_f
    dy = y_a * np.power(x, 2) + y_b * x * y + y_c * np.power(
        y, 2) + y_d * x + y_e * y + y_f
    dz = z_a * np.power(x, 2) + z_b * x * y + z_c * np.power(
        y, 2) + z_d * x + z_e * y + z_f

    xyz[:, 0] += dx
    xyz[:, 1] += dy
    xyz[:, 2] += dz

    return put_xyz_to_pdal(in_pt_cloud, xyz + xyzm)
Ejemplo n.º 6
0
def create_test_grid(in_pt_cloud,
                     dx=10,
                     dy=10,
                     x_a=1E-3,
                     x_b=0.5E-3,
                     x_c=-1.2E-3,
                     x_d=-0.8E-1,
                     x_e=-1.0E-1,
                     x_f=1.0,
                     y_a=-1.5E-4,
                     y_b=-1.0E-4,
                     y_c=0.72E-3,
                     y_d=0.75E-1,
                     y_e=1.4E-1,
                     y_f=-1.0,
                     z_a=1E-4,
                     z_b=-4E-4,
                     z_c=-6E-4,
                     z_d=-1E-1,
                     z_e=1E-1,
                     z_f=1.0):

    from pml import get_bounds
    from utils import get_xyz_from_pdal

    bounds = get_bounds(in_pt_cloud)

    xyz = get_xyz_from_pdal(in_pt_cloud)
    xyzm = np.mean(xyz, axis=0)

    x = np.arange(bounds[0][0], bounds[0][1], dx) - xyzm[0]
    y = np.arange(bounds[1][0], bounds[1][1], dy) - xyzm[1]

    [x, y] = np.meshgrid(x, y)

    ux = x_a * np.power(x, 2) + x_b * x * y + x_c * np.power(
        y, 2) + x_d * x + x_e * y + x_f
    uy = y_a * np.power(x, 2) + y_b * x * y + y_c * np.power(
        y, 2) + y_d * x + y_e * y + y_f
    uz = z_a * np.power(x, 2) + z_b * x * y + z_c * np.power(
        y, 2) + z_d * x + z_e * y + z_f

    return x, y, ux, uy, uz