Skip to content

[RFC] render API #6760

Closed
Closed

Description

@massich

When working in #6714 I made some helper function to plot transformations. Here is some of the thoughts that came across with respect to the render API (as in comments of my code):

def _plot_dig_transformation(transformed, original, title=''):
    EXPECTED_HEAD_SIZE = 0.085
    from mne.viz.backends.renderer import _Renderer
    def get_data(montage):
        data, coord_frame = _get_fid_coords(montage.dig)
        data['eeg'] = np.array([ch['r'] for ch in _get_dig_eeg(montage.dig)])
        data['coord_frame'] = coord_frame

        return data

    def _plot_fid_coord(renderer, data, color):
        renderer.tube(
            # origin=data.lpa,  # XXX: why I cannot pas a (3,) ?
            origin=np.atleast_2d(data.lpa),
            destination=np.atleast_2d(data.rpa),
            # color='red',  # XXX: why I cannot do that?
            color=color,
            radius=0.001,  # XXX: why radious=1 which is default does not work?
        )
        renderer.tube(
            origin=np.atleast_2d((data.lpa+data.rpa)/2),
            destination=np.atleast_2d(data.nasion),
            color=color,
            radius=0.001,  # XXX: why radious=1 which is default does not work?
        )

    ren = _Renderer()
    ren.sphere(
        center=np.array([0, 0, 0]),
        # color=(100, 100, 100),  # XXX: is color (R,G,B) 0-255? doc needs rev.
        color=(1.0, 1.0, 1.0),  # XXX: doc don't say [0-1 or 0-255] ??
        # scale=EXPECTED_HEAD_SIZE,  # XXX: why I cannot put radius a value in mm??  # noqa
        scale=0.17,  # XXXX magic number!!
        opacity=0.3,
        resolution=20,  # XXX: why this is not callen n_poligons??
        backface_culling=False,
    )
    N_RAND_PTS = 50
    ren.sphere(
        center=_sph_to_cart(np.stack(
            [np.full((N_RAND_PTS,), EXPECTED_HEAD_SIZE),
             np.random.rand(N_RAND_PTS) * 3 * 3.1415,
             np.random.rand(N_RAND_PTS) * 3 * 3.1415,
            ],
            axis=-1,
        )),
        color=(1.0, 1.0, 1.0),
        scale=0.001
    )

    orig_data = get_data(original)
    trans_data = get_data(transformed)

    for oo, tt in zip(orig_data.eeg, trans_data.eeg):
        ren.tube(
            origin=np.atleast_2d(oo),
            destination=np.atleast_2d(tt),
            color=(.0, .1, .0),
            radius=0.0005,
        )

    _plot_fid_coord(ren, orig_data, (1.0, 0, 0))
    ren.sphere(center=orig_data.eeg, color=(1.0, .0, .0), scale=0.0022)

    _plot_fid_coord(ren, trans_data, (0, 0, 1.0))
    ren.sphere(center=trans_data.eeg, color=(.0, .0, 1.0), scale=0.0022)


    ren.text2d(
        x=0, y=0,  # XXX: why not x_window, y_window (to me x, y feels weird. They seem to belong to the scene x,y)
        text=title,
        width=.1  # XXX: This is relative to the displaying window. caThoughts on n we just pas something that is independent of wind.size
    )
    ren.show()

    return

cc: @GuillaumeFavelier

Activity

  1. GuillaumeFavelier commented on Sep 12, 2019

    @GuillaumeFavelier
    Contributor

    Thanks for your feedback @massich ! I'll populate my TODO list with your comments

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions