dipy/viz/utils.py
def auto_camera(actor, zoom=10, relative='max', select_plane=None):
    """ Automatically calculate the position of the camera given an actor

    """

    bounds = actor.GetBounds()

    x_min, x_max, y_min, y_max, z_min, z_max = bounds

    bounds = np.array(bounds).reshape(3, 2)
    center_bb = bounds.mean(axis=1)
    widths_bb = np.abs(bounds[:, 0] - bounds[:, 1])

    corners = np.array([[x_min, y_min, z_min],
                        [x_min, y_min, z_max],
                        [x_min, y_max, z_min],
                        [x_min, y_max, z_max],
                        [x_max, y_min, z_min],
                        [x_max, y_min, z_max],
                        [x_max, y_max, z_min],
                        [x_max, y_max, z_max]])

    x_plane_min = np.array([[x_min, y_min, z_min],
                            [x_min, y_min, z_max],
                            [x_min, y_max, z_min],
                            [x_min, y_max, z_max]])

    x_plane_max = np.array([[x_max, y_min, z_min],
                            [x_max, y_min, z_max],
                            [x_max, y_max, z_min],
                            [x_max, y_max, z_max]])

    y_plane_min = np.array([[x_min, y_min, z_min],
                            [x_min, y_min, z_max],
                            [x_max, y_min, z_min],
                            [x_max, y_min, z_max]])

    y_plane_max = np.array([[x_min, y_max, z_min],
                            [x_min, y_max, z_max],
                            [x_max, y_max, z_min],
                            [x_max, y_max, z_max]])

    z_plane_min = np.array([[x_min, y_min, z_min],
                            [x_min, y_max, z_min],
                            [x_max, y_min, z_min],
                            [x_max, y_max, z_min]])

    z_plane_max = np.array([[x_min, y_min, z_max],
                            [x_min, y_max, z_max],
                            [x_max, y_min, z_max],
                            [x_max, y_max, z_max]])

    if select_plane is None:
        which_plane = np.argmin(widths_bb)
    else:
        which_plane = select_plane

    if which_plane == 0:
        if relative == 'max':
            plane = x_plane_max
        else:
            plane = x_plane_min
        view_up = np.array([0, 1, 0])

    if which_plane == 1:
        if relative == 'max':
            plane = y_plane_max
        else:
            plane = y_plane_min
        view_up = np.array([0, 0, 1])

    if which_plane == 2:
        if relative == 'max':
            plane = z_plane_max
        else:
            plane = z_plane_min
        view_up = np.array([0, 1, 0])

    initial_position = np.mean(plane, axis=0)

    position = center_bb + zoom * (initial_position - center_bb)

    return position, center_bb, view_up, corners, plane
 Automatically calculate the position of the camera given an actor

    
Automatically calculate the position of the camera given an actor
Automatically calculate the position of the camera given an actor
def auto_camera(actor, zoom=10, relative='max', select_plane=None):
    bounds = actor.GetBounds()
    x_min, x_max, y_min, y_max, z_min, z_max = bounds
    bounds = np.array(bounds).reshape(3, 2)
    center_bb = bounds.mean(axis=1)
    widths_bb = np.abs(bounds[:, 0] - bounds[:, 1])
    corners = np.array([[x_min, y_min, z_min],
                        [x_min, y_min, z_max],
                        [x_min, y_max, z_min],
                        [x_min, y_max, z_max],
                        [x_max, y_min, z_min],
                        [x_max, y_min, z_max],
                        [x_max, y_max, z_min],
                        [x_max, y_max, z_max]])
    x_plane_min = np.array([[x_min, y_min, z_min],
                            [x_min, y_min, z_max],
                            [x_min, y_max, z_min],
                            [x_min, y_max, z_max]])
    x_plane_max = np.array([[x_max, y_min, z_min],
                            [x_max, y_min, z_max],
                            [x_max, y_max, z_min],
                            [x_max, y_max, z_max]])
    y_plane_min = np.array([[x_min, y_min, z_min],
                            [x_min, y_min, z_max],
                            [x_max, y_min, z_min],
                            [x_max, y_min, z_max]])
    y_plane_max = np.array([[x_min, y_max, z_min],
                            [x_min, y_max, z_max],
                            [x_max, y_max, z_min],
                            [x_max, y_max, z_max]])
    z_plane_min = np.array([[x_min, y_min, z_min],
                            [x_min, y_max, z_min],
                            [x_max, y_min, z_min],
                            [x_max, y_max, z_min]])
    z_plane_max = np.array([[x_min, y_min, z_max],
                            [x_min, y_max, z_max],
                            [x_max, y_min, z_max],
                            [x_max, y_max, z_max]])
    if select_plane is None:
        which_plane = np.argmin(widths_bb)
    else:
        which_plane = select_plane
    if which_plane == 0:
        if relative == 'max':
            plane = x_plane_max
        else:
            plane = x_plane_min
        view_up = np.array([0, 1, 0])
    if which_plane == 1:
        if relative == 'max':
            plane = y_plane_max
        else:
            plane = y_plane_min
        view_up = np.array([0, 0, 1])
    if which_plane == 2:
        if relative == 'max':
            plane = z_plane_max
        else:
            plane = z_plane_min
        view_up = np.array([0, 1, 0])
    initial_position = np.mean(plane, axis=0)
    position = center_bb + zoom * (initial_position - center_bb)
    return position, center_bb, view_up, corners, plane
def auto_camera ( actor , zoom = 10 , relative = 'max' , select_plane = None ) : bounds = actor . GetBounds ( ) x_min , x_max , y_min , y_max , z_min , z_max = bounds bounds = np . array ( bounds ) . reshape ( 3 , 2 ) center_bb = bounds . mean ( axis = 1 ) widths_bb = np . abs ( bounds [ : , 0 ] - bounds [ : , 1 ] ) corners = np . array ( [ [ x_min , y_min , z_min ] , [ x_min , y_min , z_max ] , [ x_min , y_max , z_min ] , [ x_min , y_max , z_max ] , [ x_max , y_min , z_min ] , [ x_max , y_min , z_max ] , [ x_max , y_max , z_min ] , [ x_max , y_max , z_max ] ] ) x_plane_min = np . array ( [ [ x_min , y_min , z_min ] , [ x_min , y_min , z_max ] , [ x_min , y_max , z_min ] , [ x_min , y_max , z_max ] ] ) x_plane_max = np . array ( [ [ x_max , y_min , z_min ] , [ x_max , y_min , z_max ] , [ x_max , y_max , z_min ] , [ x_max , y_max , z_max ] ] ) y_plane_min = np . array ( [ [ x_min , y_min , z_min ] , [ x_min , y_min , z_max ] , [ x_max , y_min , z_min ] , [ x_max , y_min , z_max ] ] ) y_plane_max = np . array ( [ [ x_min , y_max , z_min ] , [ x_min , y_max , z_max ] , [ x_max , y_max , z_min ] , [ x_max , y_max , z_max ] ] ) z_plane_min = np . array ( [ [ x_min , y_min , z_min ] , [ x_min , y_max , z_min ] , [ x_max , y_min , z_min ] , [ x_max , y_max , z_min ] ] ) z_plane_max = np . array ( [ [ x_min , y_min , z_max ] , [ x_min , y_max , z_max ] , [ x_max , y_min , z_max ] , [ x_max , y_max , z_max ] ] ) if select_plane is None : which_plane = np . argmin ( widths_bb ) else : which_plane = select_plane if which_plane == 0 : if relative == 'max' : plane = x_plane_max else : plane = x_plane_min view_up = np . array ( [ 0 , 1 , 0 ] ) if which_plane == 1 : if relative == 'max' : plane = y_plane_max else : plane = y_plane_min view_up = np . array ( [ 0 , 0 , 1 ] ) if which_plane == 2 : if relative == 'max' : plane = z_plane_max else : plane = z_plane_min view_up = np . array ( [ 0 , 1 , 0 ] ) initial_position = np . mean ( plane , axis = 0 ) position = center_bb + zoom * ( initial_position - center_bb ) return position , center_bb , view_up , corners , plane
Automatically calculate the position of the camera given an actor
Automatically calculate the position of the camera given an actor
""" Automatically calculate the position of the camera given an actor

    """
actor
zoom
relative
select_plane