예제 #1
0
def paperclip_shape_rotate_midsegment(h, params):
    """
    This move rotates the midsegment of h, keeping the other segments fixed.

    Because we constrain midsegment to be aligned with the x axis, this rotation is implemented by rotating the other
    segments. Crucially, we want it to look like only the midsegment is rotated; so we rotate the viewpoint to do that.
    """
    hp = h.copy()

    # if the object has only a midsegment
    if hp.joint_count == 2:
        return hp, 1.0, 1.0

    # get random rotation axis and angle
    theta = np.random.rand() * 360.0 - 180.0
    phi = np.random.rand() * 180.0
    rotation_axis = geom_3d.spherical_to_cartesian((1.0, theta, phi))

    kappa = 1 / (params['ROTATE_MIDSEGMENT_VARIANCE'] * np.pi**2 / 180**2)
    rotation_angle = np.random.vonmises(0.0, kappa) * 180.0 / np.pi

    # rotate midsegment
    try:  # we might not be able to rotate midsegment by rotation_angle around rotation_axis
        hp.rotate_midsegment(rotation_axis, rotation_angle)
    except ValueError:
        return hp, 1.0, 1.0

    # rotate each viewpoint to correct for the rotation of the joints (we want only the midsegment to change how it
    # looks)
    for i in range(len(hp.viewpoint)):
        vp_cartesian = geom_3d.spherical_to_cartesian(hp.viewpoint[i])
        new_vp_cartesian = geom_3d.rotate_axis_angle(vp_cartesian, rotation_axis, -rotation_angle)
        hp.viewpoint[i] = geom_3d.cartesian_to_spherical(new_vp_cartesian)

    return hp, 1.0, 1.0
def get_feature_positions(forward_model, shape):
    # fix missing and ill-formed data
    shape.primitive_type = 'CUBE'
    shape.viewpoint[0] = geom_3d.cartesian_to_spherical(shape.viewpoint[0])

    # find position of each feature
    feature_list = np.zeros((2, 8))
    for i, p in enumerate(points):
        px, py = forward_model.convert_world_to_display(shape.viewpoint[0], p[0], p[1], p[2])
        # in vtk's coordinate system, left bottom corner is (0, 0)
        feature_list[:, i] = [px, IMG_SIZE[1] - py]

    return feature_list