Example #1
0
def ray_values(v, direction):
	d = v.data
	center = [0.5*(s+1) for s in d.size]
	radius = 0.5*min([s*t for s,t in zip(d.size, d.step)])
	steps = max(d.size)
	from Matrix import norm
	dn = norm(direction)
	from numpy import array, arange, float32, outer
	dir = array(direction)/dn
	spacing = radius/dn
	radii = arange(0, steps, dtype = float32)*(radius/steps)
	ray_points = outer(radii, dir)
	values = v.interpolated_values(ray_points)
	return radii, values, radius
Example #2
0
def parse_rotation(rotation, qrotation):

    if rotation:
        aa = parse_floats(rotation, 'rotation', 4)
        axis, angle = aa[:3], aa[3]
    elif qrotation:
        q = parse_floats(qrotation, 'qrotation', 4)
        from Matrix import norm
        from math import atan2, pi
        angle = (360/pi)*atan2(norm(q[:3]), q[3])
        axis = q[:3]
    else:
        axis = angle = None
    if axis and tuple(axis) == (0,0,0):
        axis = angle = None
    return axis, angle
def parse_rotation(rotation, qrotation):

    if rotation:
        aa = parse_floats(rotation, 'rotation', 4)
        axis, angle = aa[:3], aa[3]
    elif qrotation:
        q = parse_floats(qrotation, 'qrotation', 4)
        from Matrix import norm
        from math import atan2, pi
        angle = (360 / pi) * atan2(norm(q[:3]), q[3])
        axis = q[:3]
    else:
        axis = angle = None
    if axis and tuple(axis) == (0, 0, 0):
        axis = angle = None
    return axis, angle
Example #4
0
def rotation_step(points, point_weights, center, data_array,
                  xyz_to_ijk_transform, ijk_step_size, metric):

    axis = torque_axis(points, point_weights, center, data_array,
                       xyz_to_ijk_transform, metric)

    from Matrix import norm, rotation_transform
    na = norm(axis)
    if len(points) == 1 or na == 0:
        axis = (0,0,1)
        angle = 0
    else:
        axis /= na
        angle = angle_step(axis, points, center, xyz_to_ijk_transform,
                           ijk_step_size)
    move_tf = rotation_transform(axis, angle, center)
    return move_tf
Example #5
0
def translation_step(points, point_weights, center, data_array,
                     xyz_to_ijk_transform, ijk_step_size, metric):

    g = gradient_direction(points, point_weights, data_array,
                           xyz_to_ijk_transform, metric)
    from numpy import array, float, dot as matrix_multiply
    tf = array(xyz_to_ijk_transform)
    gijk = matrix_multiply(tf[:,:3], g)
    from Matrix import norm
    n = norm(gijk)
    if n > 0:
        delta = g * (ijk_step_size / n)
    else:
        delta = array((0,0,0), float)

    delta_tf = ((1,0,0,delta[0]),
                (0,1,0,delta[1]),
                (0,0,1,delta[2]))
    return delta_tf