Ejemplo n.º 1
0
def test_spheres(interactive=False):

    xyzr = np.array([[0, 0, 0, 10], [100, 0, 0, 25], [200, 0, 0, 50]])
    colors = np.array([[1, 0, 0, 0.3], [0, 1, 0, 0.4], [0, 0, 1., 0.99]])

    scene = window.Scene()
    sphere_actor = actor.sphere(centers=xyzr[:, :3],
                                colors=colors[:],
                                radii=xyzr[:, 3])
    scene.add(sphere_actor)

    if interactive:
        window.show(scene, order_transparent=True)

    arr = window.snapshot(scene)
    report = window.analyze_snapshot(arr, colors=colors)
    npt.assert_equal(report.objects, 3)

    # test with an unique color for all centers
    scene.clear()
    sphere_actor = actor.sphere(centers=xyzr[:, :3],
                                colors=np.array([1, 0, 0]),
                                radii=xyzr[:, 3])
    scene.add(sphere_actor)
    arr = window.snapshot(scene)
    report = window.analyze_snapshot(arr, colors=(1, 0, 0))
    npt.assert_equal(report.colors_found, [True])
Ejemplo n.º 2
0
def test_timer():
    """ Testing add a timer and exit window and app from inside timer.
    """

    xyzr = np.array([[0, 0, 0, 10], [100, 0, 0, 50], [300, 0, 0, 100]])
    xyzr2 = np.array([[0, 200, 0, 30], [100, 200, 0, 50], [300, 200, 0, 100]])
    colors = np.array([[1, 0, 0, 0.3], [0, 1, 0, 0.4], [0, 0, 1., 0.45]])

    renderer = window.Renderer()
    global sphere_actor, tb, cnt
    sphere_actor = actor.sphere(centers=xyzr[:, :3],
                                colors=colors[:],
                                radii=xyzr[:, 3])

    sphere = get_sphere('repulsion724')

    sphere_actor2 = actor.sphere(centers=xyzr2[:, :3],
                                 colors=colors[:],
                                 radii=xyzr2[:, 3],
                                 vertices=sphere.vertices,
                                 faces=sphere.faces.astype('i8'))

    renderer.add(sphere_actor)
    renderer.add(sphere_actor2)

    tb = ui.TextBlock2D()

    cnt = 0
    global showm
    showm = window.ShowManager(renderer,
                               size=(1024, 768),
                               reset_camera=False,
                               order_transparent=True)

    showm.initialize()

    def timer_callback(obj, event):
        global cnt, sphere_actor, showm, tb

        cnt += 1
        tb.message = "Let's count to 10 and exit :" + str(cnt)
        showm.render()
        if cnt > 9:
            showm.exit()

    renderer.add(tb)

    # Run every 200 milliseconds
    showm.add_timer_callback(True, 200, timer_callback)
    showm.start()

    arr = window.snapshot(renderer)

    npt.assert_(np.sum(arr) > 0)
Ejemplo n.º 3
0
    def test(use_raw_array, ms_stream=16, whithout_iren_start=False):
        width_0 = 100
        height_0 = 200

        centers = np.array([[0, 0, 0], [-1, 0, 0], [1, 0, 0]])
        colors = np.array([[1, 0, 0], [0, 1, 0], [0, 0, 1]])
        actors = actor.sphere(centers, colors=colors, radii=.1)

        scene = window.Scene()
        scene.add(actors)
        showm = window.ShowManager(
            scene,
            reset_camera=False,
            size=(width_0, height_0),
            order_transparent=False,
        )

        showm.initialize()

        stream = FuryStreamClient(showm,
                                  use_raw_array=use_raw_array,
                                  whithout_iren_start=whithout_iren_start)

        showm.render()
        stream.start(ms_stream)
        npt.assert_equal(stream._started, True)
        # test if stop method has been called
        stream.start(ms_stream)
        npt.assert_equal(stream._started, True)
        showm.render()
        stream.stop()
        # double stop test
        npt.assert_equal(stream.stop(), False)
        stream.cleanup()
Ejemplo n.º 4
0
def test_widget():
    if not PY_VERSION_8:
        return
    width_0 = 100
    height_0 = 200

    centers = np.array([[0, 0, 0], [-1, 0, 0], [1, 0, 0]])
    colors = np.array([[1, 0, 0], [0, 1, 0], [0, 0, 1]])
    actors = actor.sphere(centers, colors=colors, radii=.1)
    scene = window.Scene()
    scene.add(actors)
    showm = window.ShowManager(
        scene,
        reset_camera=False,
        size=(width_0, height_0),
        order_transparent=False,
    )
    widget = Widget(showm)
    widget.start()
    time.sleep(2)

    npt.assert_equal(False, check_port_is_available(widget._host,
                                                    widget._port))

    widget2 = Widget(showm, port=widget._port)
    widget2.display()
    widget2.start()

    widget2.stop()
    widget.stop()
Ejemplo n.º 5
0
def test_timer():
    """Testing add a timer and exit window and app from inside timer."""
    xyzr = np.array([[0, 0, 0, 10], [100, 0, 0, 50], [300, 0, 0, 100]])
    xyzr2 = np.array([[0, 200, 0, 30], [100, 200, 0, 50], [300, 200, 0, 100]])
    colors = np.array([[1, 0, 0, 0.3], [0, 1, 0, 0.4], [0, 0, 1., 0.45]])

    scene = window.Scene()

    sphere_actor = actor.sphere(centers=xyzr[:, :3],
                                colors=colors[:],
                                radii=xyzr[:, 3])

    vertices, faces = prim_sphere('repulsion724')

    sphere_actor2 = actor.sphere(centers=xyzr2[:, :3],
                                 colors=colors[:],
                                 radii=xyzr2[:, 3],
                                 vertices=vertices,
                                 faces=faces.astype('i8'))

    scene.add(sphere_actor)
    scene.add(sphere_actor2)

    tb = ui.TextBlock2D()
    counter = itertools.count()
    showm = window.ShowManager(scene,
                               size=(1024, 768),
                               reset_camera=False,
                               order_transparent=True)

    showm.initialize()
    scene.add(tb)

    def timer_callback(_obj, _event):
        cnt = next(counter)
        tb.message = "Let's count to 10 and exit :" + str(cnt)
        showm.render()
        if cnt > 9:
            showm.exit()

    # Run every 200 milliseconds
    showm.add_timer_callback(True, 200, timer_callback)
    showm.start()

    arr = window.snapshot(scene, offscreen=True)
    npt.assert_(np.sum(arr) > 0)
Ejemplo n.º 6
0
def test_spheres(interactive=False):
    xyzr = np.array([[0, 0, 0, 10], [100, 0, 0, 25], [200, 0, 0, 50]])
    colors = np.array([[1, 0, 0, 0.3], [0, 1, 0, 0.4], [0, 0, 1., 0.99]])
    opacity = 0.5

    scene = window.Scene()
    sphere_actor = actor.sphere(centers=xyzr[:, :3], colors=colors[:],
                                radii=xyzr[:, 3], opacity=opacity)
    scene.add(sphere_actor)

    if interactive:
        window.show(scene, order_transparent=True)

    arr = window.snapshot(scene)
    report = window.analyze_snapshot(arr,
                                     colors=colors)
    npt.assert_equal(report.objects, 3)
    npt.assert_equal(sphere_actor.GetProperty().GetOpacity(), opacity)

    # test with an unique color for all centers
    scene.clear()
    sphere_actor = actor.sphere(centers=xyzr[:, :3],
                                colors=np.array([1, 0, 0]),
                                radii=xyzr[:, 3])
    scene.add(sphere_actor)
    arr = window.snapshot(scene)
    report = window.analyze_snapshot(arr, colors=(1, 0, 0))
    npt.assert_equal(report.colors_found, [True])

    # test faces and vertices
    scene.clear()
    vertices, faces = fp.prim_sphere(name='symmetric362', gen_faces=False)
    sphere_actor = actor.sphere(centers=xyzr[:, :3], colors=colors[:],
                                radii=xyzr[:, 3], opacity=opacity,
                                vertices=vertices, faces=faces)
    scene.add(sphere_actor)
    if interactive:
        window.show(scene, order_transparent=True)
    arr = window.snapshot(scene)
    report = window.analyze_snapshot(arr,
                                     colors=colors)
    npt.assert_equal(report.objects, 3)
Ejemplo n.º 7
0
    def test(use_raw_array, ms_stream=16):
        width_0 = 100
        height_0 = 200

        centers = np.array([[0, 0, 0], [-1, 0, 0], [1, 0, 0]])
        colors = np.array([[1, 0, 0], [0, 1, 0], [0, 0, 1]])

        actors = actor.sphere(centers, colors=colors, radii=.1)

        scene = window.Scene()
        scene.add(actors)
        showm = window.ShowManager(
            scene,
            reset_camera=False,
            size=(width_0, height_0),
            order_transparent=False,
        )

        showm.initialize()

        stream = FuryStreamClient(showm,
                                  use_raw_array=use_raw_array,
                                  whithout_iren_start=False)
        if use_raw_array:
            img_buffer_manager = tools.RawArrayImageBufferManager(
                info_buffer=stream.img_manager.info_buffer,
                image_buffers=stream.img_manager.image_buffers)
        else:
            img_buffer_manager = tools.SharedMemImageBufferManager(
                info_buffer_name=stream.img_manager.info_buffer_name,
                image_buffer_names=stream.img_manager.image_buffer_names)

        showm.render()
        stream.start(ms_stream)
        showm.render()
        # test jpeg method
        img_buffer_manager.get_jpeg()
        width, height, frame = img_buffer_manager.get_current_frame()

        # assert width == showm.size[0] and height == showm.size[1]
        image = np.frombuffer(frame, 'uint8')[0:width * height * 3].reshape(
            (height, width, 3))
        # image = np.flipud(image)

        # image = image[:, :, ::-1]
        # import matplotlib.pyplot as plt
        # plt.imshow(image)
        # plt.show()
        # npt.assert_allclose(arr, image)
        report = window.analyze_snapshot(image, find_objects=True)
        npt.assert_equal(report.objects, 3)
        img_buffer_manager.cleanup()
        stream.stop()
        stream.cleanup()
Ejemplo n.º 8
0
def test_rtc_video_stream_whitout_cython(loop: asyncio.AbstractEventLoop):
    if not WEBRTC_AVAILABLE:
        print('\n aiortc not available -> skipping test\n')
        return

    use_raw_array = True
    ms_stream = 0
    # creates a context whithout cython
    with mock.patch.dict(sys.modules, {'pyximport': None}):
        reload(sys.modules["fury.stream.server.main"])
        width_0 = 100
        height_0 = 200

        centers = np.array([[0, 0, 0], [-1, 0, 0], [1, 0, 0]])
        colors = np.array([[1, 0, 0], [0, 1, 0], [0, 0, 1]])
        actors = actor.sphere(centers, colors=colors, radii=.1)

        scene = window.Scene()
        scene.add(actors)
        showm = window.ShowManager(
            scene,
            reset_camera=False,
            size=(width_0, height_0),
            order_transparent=False,
        )

        showm.initialize()

        stream = FuryStreamClient(showm,
                                  use_raw_array=use_raw_array,
                                  whithout_iren_start=False)
        if use_raw_array:
            img_buffer_manager = tools.RawArrayImageBufferManager(
                info_buffer=stream.img_manager.info_buffer,
                image_buffers=stream.img_manager.image_buffers)
        else:
            img_buffer_manager = tools.SharedMemImageBufferManager(
                info_buffer_name=stream.img_manager.info_buffer_name,
                image_buffer_names=stream.img_manager.image_buffer_names)

        rtc_server = RTCServer(img_buffer_manager)
        showm.render()
        stream.start(ms_stream)
        showm.render()
        loop.run_until_complete(rtc_server.recv())
        # assert frame.width == showm.size[0] and frame.height == showm.size[1]
        rtc_server.release()
        img_buffer_manager.cleanup()
        stream.stop()
        stream.cleanup()

    reload(sys.modules["fury.stream.server.main"])
Ejemplo n.º 9
0
def create_sphere_actor(xml):
    mcds=pyMCDS(xml, load_microenv=False)
    data=mcds.get_cell_df()
    Types = np.array([mcds.data['discrete_cells']['cell_type']])
    Fibro = np.where(Types == 2)
    Organoid = np.where(Types == 1)
    #Cells
    C_xpos = np.array([pd.DataFrame.to_numpy(data['position_x'][:])])
    C_ypos = np.array([pd.DataFrame.to_numpy(data['position_y'][:])])
    C_zpos = np.array([pd.DataFrame.to_numpy(data['position_z'][:])])
    C_xyz = np.concatenate((C_xpos,C_ypos,C_zpos),axis=0)
    C_xyz=C_xyz.transpose()
    # Whole Cell
    # Cell Radius Calculation
    C_volume = np.array([pd.DataFrame.to_numpy(data['total_volume'][:])])
    C_volume = C_volume/4/np.pi*3
    C_radii = np.power(C_volume,1/3).transpose()
    # Coloring
    C_R = np.array([np.ones(len(C_radii))]).transpose()
    C_G = np.array([np.ones(len(C_radii))]).transpose()
    C_B = np.array([np.ones(len(C_radii))]).transpose()
    C_O = np.array([np.ones(len(C_radii))]).transpose()*0.6
    # Type 1 (Organoid)
    C_R[Fibro[1]] = 0
    C_G[Fibro[1]] = 0.353
    C_B[Fibro[1]] = 1
    # Type 2 (Fibroblast)
    C_R[Organoid[1]] = 1
    C_G[Organoid[1]] = 1
    C_B[Organoid[1]] = 0
    C_colors = np.concatenate((C_R,C_G,C_B,C_O),axis=1)
    # Nucleus
    N_xyz=C_xyz
    # Nucleus Radii
    N_volume = np.array([pd.DataFrame.to_numpy(data['nuclear_volume'][:])])
    N_volume = N_volume/4/np.pi*3
    N_radii = np.power(N_volume,1/3).transpose()
    N_R = np.array([np.ones(len(N_radii))]).transpose()*0.35
    N_G = np.array([np.ones(len(N_radii))]).transpose()*0.2
    N_B = np.array([np.ones(len(N_radii))]).transpose()*0.1
    N_O = np.array([np.ones(len(N_radii))]).transpose()*0.9
    N_colors = np.concatenate((N_R,N_G,N_B,N_O),axis=1)
    # Concatenations
    xyz = np.concatenate((C_xyz,N_xyz),axis=0)
    colors = np.concatenate((C_colors,N_colors),axis=0)
    radii = np.concatenate((C_radii,N_radii),axis=0)
    # Creating Sphere Actor for one time-point
    sphere_actor = actor.sphere(centers=xyz,colors=colors,radii=radii)
    return sphere_actor
Ejemplo n.º 10
0
    def test(use_raw_array):
        width_0 = 100
        height_0 = 200

        centers = np.array([[0, 0, 0], [-1, 0, 0], [1, 0, 0]])
        colors = np.array([[1, 0, 0], [0, 1, 0], [0, 0, 1]])
        actors = actor.sphere(centers, colors=colors, radii=.1)

        scene = window.Scene()
        scene.add(actors)
        showm = window.ShowManager(
            scene,
            reset_camera=False,
            size=(width_0, height_0),
            order_transparent=False,
        )
        stream = FuryStreamClient(showm, use_raw_array=use_raw_array)
        stream_interaction = FuryStreamInteraction(showm,
                                                   use_raw_array=use_raw_array)
        showm.initialize()
        if use_raw_array:
            web_server_raw_array(
                stream.img_manager.image_buffers,
                stream.img_manager.info_buffer,
                stream_interaction.circular_queue.head_tail_buffer,
                stream_interaction.circular_queue.buffer._buffer,
                8000,
                'localhost',
                True,
                True,
                run_app=False)
        else:
            web_server(stream.img_manager.image_buffer_names,
                       stream.img_manager.info_buffer_name,
                       stream_interaction.circular_queue.head_tail_buffer_name,
                       stream_interaction.circular_queue.buffer.buffer_name,
                       8000,
                       'localhost',
                       True,
                       True,
                       True,
                       run_app=False)

        stream.stop()
        stream_interaction.stop()
        stream.cleanup()
Ejemplo n.º 11
0
def test_spheres(interactive=False):

    xyzr = np.array([[0, 0, 0, 10], [100, 0, 0, 25], [200, 0, 0, 50]])
    colors = np.array([[1, 0, 0, 0.3], [0, 1, 0, 0.4], [0, 0, 1., 0.99]])

    renderer = window.Renderer()
    sphere_actor = actor.sphere(centers=xyzr[:, :3], colors=colors[:],
                                radii=xyzr[:, 3])
    renderer.add(sphere_actor)

    if interactive:
        window.show(renderer, order_transparent=True)

    arr = window.snapshot(renderer)
    report = window.analyze_snapshot(arr,
                                     colors=colors)
    npt.assert_equal(report.objects, 3)
Ejemplo n.º 12
0
    def test(use_raw_array, ms_stream=16):
        width_0 = 100
        height_0 = 200

        centers = np.array([[0, 0, 0], [-1, 0, 0], [1, 0, 0]])
        colors = np.array([[1, 0, 0], [0, 1, 0], [0, 0, 1]])
        actors = actor.sphere(centers, colors=colors, radii=.1)

        scene = window.Scene()
        scene.add(actors)
        showm = window.ShowManager(
            scene,
            reset_camera=False,
            size=(width_0, height_0),
            order_transparent=False,
        )

        showm.initialize()

        stream = FuryStreamClient(showm,
                                  use_raw_array=use_raw_array,
                                  whithout_iren_start=False)
        if use_raw_array:
            img_buffer_manager = tools.RawArrayImageBufferManager(
                info_buffer=stream.img_manager.info_buffer,
                image_buffers=stream.img_manager.image_buffers)
        else:
            img_buffer_manager = tools.SharedMemImageBufferManager(
                info_buffer_name=stream.img_manager.info_buffer_name,
                image_buffer_names=stream.img_manager.image_buffer_names)

        rtc_server = RTCServer(img_buffer_manager)
        showm.render()
        stream.start(ms_stream)
        showm.render()
        loop.run_until_complete(rtc_server.recv())
        # sassert frame.width == width_0 and frame.height == height_0
        rtc_server.release()
        img_buffer_manager.cleanup()
        stream.stop()
        stream.cleanup()
Ejemplo n.º 13
0
    def test(use_raw_array, ms_stream, whitouth_iren_start):
        width_0 = 300
        height_0 = 200

        centers = np.array([[0, 0, 0], [-1, 0, 0], [1, 0, 0]])
        colors = np.array([[1, 0, 0], [0, 1, 0], [0, 0, 1]])
        actors = actor.sphere(centers, colors=colors, radii=.1)

        scene = window.Scene()
        scene.add(actors)
        showm = window.ShowManager(scene, size=(width_0, height_0))

        showm.initialize()

        stream = FuryStreamClient(showm,
                                  use_raw_array=use_raw_array,
                                  whithout_iren_start=whitouth_iren_start)
        stream_interaction = FuryStreamInteraction(
            max_queue_size=500,
            showm=showm,
            use_raw_array=use_raw_array,
            whithout_iren_start=whitouth_iren_start)

        showm.render()

        # ms should always be greather than 0
        with npt.assert_raises(ValueError):
            stream_interaction.start(-1)

        stream_interaction.start(ms_stream)
        # test double start
        stream_interaction.start(ms_stream)
        while stream_interaction.circular_queue.head != -1:
            showm.render()
            time.sleep(.01)
        stream_interaction.stop()
        # double stop test
        npt.assert_equal(stream_interaction.stop(), False)
        stream.stop()
        stream.cleanup()
        stream_interaction.cleanup()
Ejemplo n.º 14
0
def test_save_screenshot():
    xyzr = np.array([[0, 0, 0, 10], [100, 0, 0, 25], [200, 0, 0, 50]])
    colors = np.array([[1, 0, 0, 1], [0, 1, 0, 1], [0, 0, 1., 1]])
    sphere_actor = actor.sphere(centers=xyzr[:, :3],
                                colors=colors[:],
                                radii=xyzr[:, 3],
                                phi=10,
                                theta=30)
    scene = window.Scene()
    scene.add(sphere_actor)

    window_sz = (400, 400)
    show_m = window.ShowManager(scene, size=window_sz)
    show_m.initialize()

    with InTemporaryDirectory():
        fname = 'test.png'
        # Basic test
        show_m.save_screenshot(fname)
        npt.assert_equal(os.path.exists(fname), True)
        data = io.load_image(fname)
        report = window.analyze_snapshot(data,
                                         colors=[(0, 255, 0), (255, 0, 0)])
        npt.assert_equal(report.objects, 3)
        npt.assert_equal(report.colors_found, (True, True))
        # Test size
        ss_sz = (200, 200)
        show_m.save_screenshot(fname, size=ss_sz)
        npt.assert_equal(os.path.isfile(fname), True)
        data = io.load_image(fname)
        npt.assert_equal(data.shape[:2], ss_sz)
        # Test magnification
        magnification = 2
        show_m.save_screenshot(fname, magnification=magnification)
        npt.assert_equal(os.path.isfile(fname), True)
        data = io.load_image(fname)
        desired_sz = tuple(np.array(window_sz) * magnification)
        npt.assert_equal(data.shape[:2], desired_sz)
Ejemplo n.º 15
0
def test_stream_client_resize():
    width_0 = 100
    height_0 = 200
    centers = np.array([[0, 0, 0], [-1, 0, 0], [1, 0, 0]])
    colors = np.array([[1, 0, 0], [0, 1, 0], [0, 0, 1]])

    actors = actor.sphere(centers, colors=colors, radii=.1)
    scene = window.Scene()
    scene.add(actors)
    showm = window.ShowManager(
        scene,
        reset_camera=False,
        size=(width_0, height_0),
        order_transparent=False,
    )

    with npt.assert_raises(ValueError):
        FuryStreamClient(showm,
                         use_raw_array=True,
                         max_window_size=(width_0 - 10, height_0),
                         whithout_iren_start=False)

    stream = FuryStreamClient(showm,
                              use_raw_array=True,
                              max_window_size=(width_0, height_0),
                              whithout_iren_start=False)

    showm.window.SetSize((width_0 + 210, height_0 + 210))
    showm.initialize()
    npt.assert_equal(0, stream.img_manager.buffer_index)
    stream.start()
    showm.render()
    showm.scene.azimuth(1)
    showm.render()
    showm.render()

    stream.stop()
    stream.cleanup()
Ejemplo n.º 16
0
from fury import window, actor, ui
import itertools
import pybullet as p

client = p.connect(p.DIRECT)

###############################################################################
# Parameters and definition of red and blue balls.

red_radius = 0.5
blue_radius = 0.5
duration = 50

# Red Ball
red_ball_actor = actor.sphere(centers=np.array([[0, 0, 0]]),
                              colors=np.array([[1, 0, 0]]),
                              radii=red_radius)

red_ball_coll = p.createCollisionShape(p.GEOM_SPHERE, radius=red_radius)

red_ball = p.createMultiBody(baseMass=0.5,
                             baseCollisionShapeIndex=red_ball_coll,
                             basePosition=[10, 0, 0],
                             baseOrientation=[0, 0, 0, 1])

# Blue ball
blue_ball_actor = actor.sphere(centers=np.array([[0, 0, 0]]),
                               colors=np.array([[0, 0, 1]]),
                               radii=blue_radius)

blue_ball_coll = p.createCollisionShape(p.GEOM_SPHERE, radius=blue_radius)
Ejemplo n.º 17
0
                                   velocityGain=1,
                                   force=friction_vec)

###############################################################################
# We add the following constraint to keep the cubical hinge fixed.

root_robe_c = p.createConstraint(rope, -1, -1, -1, p.JOINT_FIXED, [0, 0, 0],
                                 [0, 0, 0], [0, 0, 2])

box_actor = actor.box(centers=np.array([[0, 0, 0]]),
                      directions=np.array([[0, 0, 0]]),
                      scales=(0.02, 0.02, 0.02),
                      colors=np.array([[1, 0, 0]]))

ball_actor = actor.sphere(centers=np.array([[0, 0, 0]]),
                          radii=ball_radius,
                          colors=np.array([1, 0, 1]))

###############################################################################
# Now we add the necessary actors to the scene and set the camera for better
# visualization.

scene = window.Scene()
scene.set_camera((10.28, -7.10, 6.39), (0.0, 0.0, 0.4), (-0.35, 0.26, 1.0))
scene.add(actor.axes(scale=(0.5, 0.5, 0.5)), base_actor, brick_actor)
scene.add(rope_actor, box_actor, ball_actor)

showm = window.ShowManager(scene,
                           size=(900, 768),
                           reset_camera=False,
                           order_transparent=True)
Ejemplo n.º 18
0
for source, target in edges:
    edgesPositions.append(np.array([positions[source], positions[target]]))
    edgesColors.append(np.array([colors[source], colors[target]]))

edgesPositions = np.array(edgesPositions)
edgesColors = np.average(np.array(edgesColors), axis=1)

###############################################################################
# Our data preparation is ready, it is time to visualize them all. We start to
# build 2 actors that we represent our data : sphere_actor for the nodes and
# lines_actor for the edges.

sphere_actor = actor.sphere(
    centers=positions,
    colors=colors,
    radii=radii * 0.5,
    theta=8,
    phi=8,
)

lines_actor = actor.line(
    edgesPositions,
    colors=edgesColors,
    opacity=0.1,
)

###############################################################################
# All actors need to be added in a scene, so we build one and add our
# lines_actor and sphere_actor.

scene = window.Scene()
Ejemplo n.º 19
0
    #     rgb[idx,0] = 1.0
    #     # rgb[idx,1] = (onco[idx] - onco_min)/onco_range
    #     # rgb[idx,1] = rgb[idx,0]
    #     rgb[idx,1] = 0
    #     rgb[idx,2] = 0
    # elif cycle_model[idx] == 100:
    #     rgb[idx,0] = 1
    #     rgb[idx,1] = 0
    #     rgb[idx,2] = 0
    # elif cycle_model[idx] > 100:
    #     rgb[idx,0] = 0.54   # 139./255
    #     rgb[idx,1] = 0.27   # 69./255
    #     rgb[idx,2] = 0.075  # 19./255

#-----------------------------
scene = window.Scene()

# https://fury.gl/latest/reference/fury.actor.html?highlight=sphere#fury.actor.sphere
colors = (1,0,0)
#sphere_actor = actor.sphere(centers=xyz, colors=colors, radii=1.0)
#sphere_actor = actor.sphere(centers=xyz, colors=colors, radii=cell_radii)
sphere_actor = actor.sphere(centers=xyz, colors=rgb, radii=cell_radii)
scene.add(sphere_actor)
showm = window.ShowManager(scene,
                           size=(800, 800), reset_camera=True,
                           order_transparent=False)
showm.initialize()
showm.start()

## window.record(showm.scene, size=(900, 768), out_path="viz_timer.png")
Ejemplo n.º 20
0
##############################################################################
# Use ``set_camera`` to ensure the camera is in the optimal position for the
# scene.

scene.set_camera(position=(0.24, 0.00, 4.34),
                 focal_point=(0.00, 0.00, 0.00),
                 view_up=(0.00, 1.00, 0.00))

##############################################################################
# Let's create a sphere actor to add to the Earth. We will place this sphere
# on the Earth's surface on Bloomington, IN, home of FURY's headquarters!

center = [[-0.39, 0.3175, 0.025]]
radius = 0.002
sphere_actor = actor.sphere(center, window.colors.blue_medium, radius)

##############################################################################
# Also creating a text actor to add below the sphere.

text_actor = actor.text_3d("Bloomington, Indiana", (-0.42, 0.31, 0.03),
                           window.colors.white, 0.004)
utils.rotate(text_actor, (-90, 0, 1, 0))

##############################################################################
# Let's also import a model of a satellite to visualize circling the moon.

fetch_viz_models()
satellite_filename = read_viz_models("satellite_obj.obj")
satellite = io.load_polydata(satellite_filename)
satellite_actor = utils.get_actor_from_polydata(satellite)
Ejemplo n.º 21
0
The timer will call this user defined callback every 200 milliseconds. The
application will exit after the callback has been called 100 times.
"""

import numpy as np
from fury import window, actor, ui
import itertools

xyz = 10 * np.random.rand(100, 3)
colors = np.random.rand(100, 4)
radii = np.random.rand(100) + 0.5

scene = window.Scene()

sphere_actor = actor.sphere(centers=xyz, colors=colors, radii=radii)

scene.add(sphere_actor)

showm = window.ShowManager(scene,
                           size=(900, 768),
                           reset_camera=False,
                           order_transparent=True)

showm.initialize()

tb = ui.TextBlock2D(bold=True)

# use itertools to avoid global variables
counter = itertools.count()
Ejemplo n.º 22
0
"""

import numpy as np
from fury import window, actor


############################################################################
# First thing, you have to specify centers and colors of the sphere

centers = np.zeros([1, 3])
colors = np.array([0, 0, 1])

############################################################################
# The below sphere actor is generated by repeating the sphere primitive.

prim_sphere_actor = actor.sphere(centers, colors=colors, radii=5)

############################################################################
# This time, we're using vtkSphereSource to generate the sphere actor

cen2 = np.add(centers, np.array([12, 0, 0]))
cols2 = np.array([1, 0, 0])

vtk_sphere_actor = actor.sphere(cen2, colors=cols2,
                                radii=5, use_primitive=False)

scene = window.Scene()

############################################################################
# Adding our sphere actors to scene.
Ejemplo n.º 23
0
def test_manifest_standard(interactive=False):
    scene = window.Scene()  # Setup scene

    # Setup surface
    surface_actor = _generate_surface()
    material.manifest_standard(surface_actor, ambient_level=.3,
                               diffuse_level=.25)
    scene.add(surface_actor)
    arr = window.snapshot(scene)
    report = window.analyze_snapshot(arr)
    npt.assert_equal(report.objects, 1)

    scene.clear()  # Reset scene

    # Contour from roi setup
    data = np.zeros((50, 50, 50))
    data[20:30, 25, 25] = 1.
    data[25, 20:30, 25] = 1.
    affine = np.eye(4)
    surface = actor.contour_from_roi(data, affine, color=np.array([1, 0, 1]))
    material.manifest_standard(surface_actor, ambient_level=.3,
                               diffuse_level=.25)
    scene.add(surface)
    scene.reset_camera()
    scene.reset_clipping_range()
    arr = window.snapshot(scene)
    report = window.analyze_snapshot(arr)
    npt.assert_equal(report.objects, 1)

    scene.clear()  # Reset scene

    # Contour from label setup
    data = np.zeros((50, 50, 50))
    data[5:15, 1:10, 25] = 1.
    data[25:35, 1:10, 25] = 2.
    data[40:49, 1:10, 25] = 3.
    color = np.array([[255, 0, 0],
                      [0, 255, 0],
                      [0, 0, 255]])
    surface = actor.contour_from_label(data, color=color)
    material.manifest_standard(surface_actor, ambient_level=.3,
                               diffuse_level=.25)
    scene.add(surface)
    scene.reset_camera()
    scene.reset_clipping_range()
    arr = window.snapshot(scene)
    report = window.analyze_snapshot(arr)
    npt.assert_equal(report.objects, 3)

    scene.clear()  # Reset scene

    # Streamtube setup
    data1 = np.array([[0, 0, 0], [1, 1, 1], [2, 2, 2.]])
    data2 = data1 + np.array([0.5, 0., 0.])
    data = [data1, data2]
    colors = np.array([[1, 0, 0], [0, 0, 1.]])
    tubes = actor.streamtube(data, colors, linewidth=.1)
    material.manifest_standard(surface_actor, ambient_level=.3,
                               diffuse_level=.25)
    scene.add(tubes)
    scene.reset_camera()
    scene.reset_clipping_range()
    arr = window.snapshot(scene)
    report = window.analyze_snapshot(arr)
    npt.assert_equal(report.objects, 2)

    scene.clear()  # Reset scene

    # ODF slicer setup
    if have_dipy:
        from dipy.data import get_sphere
        from tempfile import mkstemp
        sphere = get_sphere('symmetric362')
        shape = (11, 11, 11, sphere.vertices.shape[0])
        fid, fname = mkstemp(suffix='_odf_slicer.mmap')
        odfs = np.memmap(fname, dtype=np.float64, mode='w+', shape=shape)
        odfs[:] = 1
        affine = np.eye(4)
        mask = np.ones(odfs.shape[:3])
        mask[:4, :4, :4] = 0
        odfs[..., 0] = 1
        odf_actor = actor.odf_slicer(odfs, affine, mask=mask, sphere=sphere,
                                     scale=.25, colormap='blues')
        material.manifest_standard(surface_actor, ambient_level=.3,
                                   diffuse_level=.25)
        k = 5
        I, J, _ = odfs.shape[:3]
        odf_actor.display_extent(0, I, 0, J, k, k)
        odf_actor.GetProperty().SetOpacity(1.0)
        scene.add(odf_actor)
        scene.reset_camera()
        scene.reset_clipping_range()
        arr = window.snapshot(scene)
        report = window.analyze_snapshot(arr)
        npt.assert_equal(report.objects, 11 * 11)

    scene.clear()  # Reset scene

    # Tensor slicer setup
    if have_dipy:
        from dipy.data import get_sphere
        sphere = get_sphere('symmetric724')
        evals = np.array([1.4, .35, .35]) * 10 ** (-3)
        evecs = np.eye(3)
        mevals = np.zeros((3, 2, 4, 3))
        mevecs = np.zeros((3, 2, 4, 3, 3))
        mevals[..., :] = evals
        mevecs[..., :, :] = evecs
        affine = np.eye(4)
        scene = window.Scene()
        tensor_actor = actor.tensor_slicer(mevals, mevecs, affine=affine,
                                           sphere=sphere, scale=.3)
        material.manifest_standard(surface_actor, ambient_level=.3,
                                   diffuse_level=.25)
        _, J, K = mevals.shape[:3]
        tensor_actor.display_extent(0, 1, 0, J, 0, K)
        scene.add(tensor_actor)
        scene.reset_camera()
        scene.reset_clipping_range()
        arr = window.snapshot(scene)
        report = window.analyze_snapshot(arr)
        npt.assert_equal(report.objects, 4)

    scene.clear()  # Reset scene

    # Point setup
    points = np.array([[0, 0, 0], [0, 1, 0], [1, 0, 0]])
    colors = np.array([[1, 0, 0], [0, 1, 0], [0, 0, 1]])
    opacity = 0.5
    points_actor = actor.point(points, colors, opacity=opacity)
    material.manifest_standard(surface_actor, ambient_level=.3,
                               diffuse_level=.25)
    scene.add(points_actor)
    arr = window.snapshot(scene)
    report = window.analyze_snapshot(arr)
    npt.assert_equal(report.objects, 3)

    scene.clear()  # Reset scene

    # Sphere setup
    xyzr = np.array([[0, 0, 0, 10], [100, 0, 0, 25], [200, 0, 0, 50]])
    colors = np.array([[1, 0, 0, 0.3], [0, 1, 0, 0.4], [0, 0, 1., 0.99]])
    opacity = 0.5
    sphere_actor = actor.sphere(centers=xyzr[:, :3], colors=colors[:],
                                radii=xyzr[:, 3], opacity=opacity)
    material.manifest_standard(surface_actor, ambient_level=.3,
                               diffuse_level=.25)
    scene.add(sphere_actor)
    scene.reset_camera()
    scene.reset_clipping_range()
    arr = window.snapshot(scene)
    report = window.analyze_snapshot(arr)
    npt.assert_equal(report.objects, 3)

    scene.clear()  # Reset scene

    # Advanced geometry actors setup (Arrow, cone, cylinder)
    xyz = np.array([[0, 0, 0], [50, 0, 0], [100, 0, 0]])
    dirs = np.array([[0, 1, 0], [1, 0, 0], [0, 0.5, 0.5]])
    colors = np.array([[1, 0, 0, 0.3], [0, 1, 0, 0.4], [1, 1, 0, 1]])
    heights = np.array([5, 7, 10])
    actor_list = [[actor.cone, {'directions': dirs, 'resolution': 8}],
                  [actor.arrow, {'directions': dirs, 'resolution': 9}],
                  [actor.cylinder, {'directions': dirs}]]
    for act_func, extra_args in actor_list:
        aga_actor = act_func(centers=xyz, colors=colors[:], heights=heights,
                             **extra_args)
        material.manifest_standard(surface_actor, ambient_level=.3,
                                   diffuse_level=.25)
        scene.add(aga_actor)
        scene.reset_camera()
        scene.reset_clipping_range()
        arr = window.snapshot(scene)
        report = window.analyze_snapshot(arr)
        npt.assert_equal(report.objects, 3)
        scene.clear()

    # Basic geometry actors (Box, cube, frustum, octagonalprism, rectangle,
    # square)
    centers = np.array([[4, 0, 0], [0, 4, 0], [0, 0, 0]])
    colors = np.array([[1, 0, 0, 0.4], [0, 1, 0, 0.8], [0, 0, 1, 0.5]])
    directions = np.array([[1, 1, 0]])
    scale_list = [1, 2, (1, 1, 1), [3, 2, 1], np.array([1, 2, 3]),
                  np.array([[1, 2, 3], [1, 3, 2], [3, 1, 2]])]
    actor_list = [[actor.box, {}], [actor.cube, {}], [actor.frustum, {}],
                  [actor.octagonalprism, {}], [actor.rectangle, {}],
                  [actor.square, {}]]
    for act_func, extra_args in actor_list:
        for scale in scale_list:
            scene = window.Scene()
            bga_actor = act_func(centers=centers, directions=directions,
                                 colors=colors, scales=scale, **extra_args)
            material.manifest_standard(surface_actor, ambient_level=.3,
                                       diffuse_level=.25)
            scene.add(bga_actor)
            arr = window.snapshot(scene)
            report = window.analyze_snapshot(arr)
            msg = 'Failed with {}, scale={}'.format(act_func.__name__, scale)
            npt.assert_equal(report.objects, 3, err_msg=msg)
            scene.clear()

    # Cone setup using vertices
    centers = np.array([[0, 0, 0], [20, 0, 0], [40, 0, 0]])
    directions = np.array([[0, 1, 0], [1, 0, 0], [0, 0, 1]])
    colors = np.array([[1, 0, 0, 0.3], [0, 1, 0, 0.4], [0, 0, 1., 0.99]])
    vertices = np.array([[0.0, 0.0, 0.0], [0.0, 10.0, 0.0],
                         [10.0, 0.0, 0.0], [0.0, 0.0, 10.0]])
    faces = np.array([[0, 1, 3], [0, 1, 2]])
    cone_actor = actor.cone(centers=centers, directions=directions,
                            colors=colors[:], vertices=vertices, faces=faces)
    material.manifest_standard(surface_actor, ambient_level=.3,
                               diffuse_level=.25)
    scene.add(cone_actor)
    scene.reset_camera()
    scene.reset_clipping_range()
    arr = window.snapshot(scene)
    report = window.analyze_snapshot(arr)
    npt.assert_equal(report.objects, 3)

    scene.clear()  # Reset scene

    # Superquadric setup
    centers = np.array([[8, 0, 0], [0, 8, 0], [0, 0, 0]])
    colors = np.array([[1, 0, 0], [0, 1, 0], [0, 0, 1]])
    directions = np.random.rand(3, 3)
    scales = [1, 2, 3]
    roundness = np.array([[1, 1], [1, 2], [2, 1]])
    sq_actor = actor.superquadric(centers, roundness=roundness,
                                  directions=directions,
                                  colors=colors.astype(np.uint8),
                                  scales=scales)
    material.manifest_standard(surface_actor, ambient_level=.3,
                               diffuse_level=.25)
    scene.add(sq_actor)
    scene.reset_camera()
    scene.reset_clipping_range()
    arr = window.snapshot(scene)
    report = window.analyze_snapshot(arr)
    ft.assert_greater_equal(report.objects, 3)

    scene.clear()  # Reset scene

    # Label setup
    text_actor = actor.label("Hello")
    material.manifest_standard(surface_actor, ambient_level=.3,
                               diffuse_level=.25)
    scene.add(text_actor)
    scene.reset_camera()
    scene.reset_clipping_range()
    arr = window.snapshot(scene)
    report = window.analyze_snapshot(arr)
    npt.assert_equal(report.objects, 5)

    scene.clear()  # Reset scene

    # Texture setup
    arr = (255 * np.ones((512, 212, 4))).astype('uint8')
    arr[20:40, 20:40, :] = np.array([255, 0, 0, 255], dtype='uint8')
    tp2 = actor.texture(arr)
    material.manifest_standard(surface_actor, ambient_level=.3,
                               diffuse_level=.25)
    scene.add(tp2)
    scene.reset_camera()
    scene.reset_clipping_range()
    arr = window.snapshot(scene)
    report = window.analyze_snapshot(arr)
    npt.assert_equal(report.objects, 1)

    scene.clear()  # Reset scene

    # Texture on sphere setup
    arr = 255 * np.ones((810, 1620, 3), dtype='uint8')
    rows, cols, _ = arr.shape
    rs = rows // 2
    cs = cols // 2
    w = 150 // 2
    arr[rs - w: rs + w, cs - 10 * w: cs + 10 * w] = np.array([255, 127, 0])
    tsa = actor.texture_on_sphere(arr)
    material.manifest_standard(surface_actor, ambient_level=.3,
                               diffuse_level=.25)
    scene.add(tsa)
    scene.reset_camera()
    scene.reset_clipping_range()
    arr = window.snapshot(scene)
    report = window.analyze_snapshot(arr)
    npt.assert_equal(report.objects, 1)

    # NOTE: From this point on, these actors don't have full support for PBR
    # interpolation. This is, the test passes but there is no evidence of the
    # desired effect.

    """
    # Setup slicer
    data = (255 * np.random.rand(50, 50, 50))
    affine = np.eye(4)
    slicer = actor.slicer(data, affine, value_range=[data.min(), data.max()])
    slicer.display(None, None, 25)
    material.manifest_standard(surface_actor, ambient_level=.3,
                               diffuse_level=.25)
    scene.add(slicer)
    """

    """
    # Line setup
    data1 = np.array([[0, 0, 0], [1, 1, 1], [2, 2, 2.]])
    data2 = data1 + np.array([0.5, 0., 0.])
    data = [data1, data2]
    colors = np.array([[1, 0, 0], [0, 0, 1.]])
    lines = actor.line(data, colors, linewidth=5)
    material.manifest_standard(surface_actor, ambient_level=.3,
                               diffuse_level=.25)
    scene.add(lines)
    """

    """
    # Scalar bar setup
    lut = actor.colormap_lookup_table(
        scale_range=(0., 100.), hue_range=(0., 0.1), saturation_range=(1, 1),
        value_range=(1., 1))
    sb_actor = actor.scalar_bar(lut, ' ')
    material.manifest_standard(surface_actor, ambient_level=.3,
                               diffuse_level=.25)
    scene.add(sb_actor)
    """

    """
    # Axes setup
    axes = actor.axes()
    material.manifest_standard(surface_actor, ambient_level=.3,
                               diffuse_level=.25)
    scene.add(axes)
    """

    """
    # Peak slicer setup
    _peak_dirs = np.array([[1, 0, 0], [0, 1, 0], [0, 0, 1]], dtype='f4')
    # peak_dirs.shape = (1, 1, 1) + peak_dirs.shape
    peak_dirs = np.zeros((11, 11, 11, 3, 3))
    peak_dirs[:, :, :] = _peak_dirs
    peak_actor = actor.peak_slicer(peak_dirs)
    material.manifest_standard(surface_actor, ambient_level=.3,
                               diffuse_level=.25)
    scene.add(peak_actor)
    """

    """
    # Dots setup
    points = np.array([[0, 0, 0], [0, 1, 0], [1, 0, 0]])
    dots_actor = actor.dots(points, color=(0, 255, 0))
    material.manifest_standard(surface_actor, ambient_level=.3,
                               diffuse_level=.25)
    scene.add(dots_actor)
    """

    """
    # Text3D setup
    msg = 'I \nlove\n FURY'
    txt_actor = actor.text_3d(msg)
    material.manifest_standard(surface_actor, ambient_level=.3,
                               diffuse_level=.25)
    scene.add(txt_actor)
    """

    """
    # Figure setup
    arr = (255 * np.ones((512, 212, 4))).astype('uint8')
    arr[20:40, 20:40, 3] = 0
    tp = actor.figure(arr)
    material.manifest_standard(surface_actor, ambient_level=.3,
                               diffuse_level=.25)
    scene.add(tp)
    """

    """
    # SDF setup
    centers = np.array([[2, 0, 0], [0, 2, 0], [0, 0, 0]]) * 11
    colors = np.array([[1, 0, 0], [0, 1, 0], [0, 0, 1]])
    directions = np.array([[0, 1, 0], [1, 0, 0], [0, 0, 1]])
    scales = [1, 2, 3]
    primitive = ['sphere', 'ellipsoid', 'torus']

    sdf_actor = actor.sdf(centers, directions=directions, colors=colors,
                          primitives=primitive, scales=scales)
    material.manifest_standard(surface_actor, ambient_level=.3,
                               diffuse_level=.25)
    scene.add(sdf_actor)
    """

    # NOTE: For these last set of actors, there is not support for PBR
    # interpolation at all.

    """
    # Billboard setup
    centers = np.array([[0, 0, 0], [5, -5, 5], [-7, 7, -7], [10, 10, 10],
                        [10.5, 11.5, 11.5], [12, -12, -12], [-17, 17, 17],
                        [-22, -22, 22]])
    colors = np.array([[1, 1, 0], [0, 0, 0], [1, 0, 1], [0, 0, 1], [1, 1, 1],
                       [1, 0, 0], [0, 1, 0], [0, 1, 1]])
    scales = [6, .4, 1.2, 1, .2, .7, 3, 2]
    """
    fake_sphere = \
        """
        float len = length(point);
        float radius = 1.;
        if (len > radius)
            discard;
        vec3 normalizedPoint = normalize(vec3(point.xy, sqrt(1. - len)));
        vec3 direction = normalize(vec3(1., 1., 1.));
        float df_1 = max(0, dot(direction, normalizedPoint));
        float sf_1 = pow(df_1, 24);
        fragOutput0 = vec4(max(df_1 * color, sf_1 * vec3(1)), 1);
        """
    """
    billboard_actor = actor.billboard(centers, colors=colors, scales=scales,
                                      fs_impl=fake_sphere)
    material.manifest_pbr(billboard_actor)
    scene.add(billboard_actor)
    """

    if interactive:
        window.show(scene)
Ejemplo n.º 24
0
"""

import time
import asyncio
import platform
import numpy as np
from fury import actor, window
from fury.stream.widget import Widget

interactive = False
window_size = (720, 500)
N = 4
centers = np.random.normal(size=(N, 3))
colors = np.random.uniform(0.1, 1.0, size=(N, 3))
actors = actor.sphere(centers, opacity=.5, radii=.4, colors=colors)
scene = window.Scene()
scene.add(actors)
showm = window.ShowManager(scene, size=(window_size[0], window_size[1]))

##########################################################################
# Create a stream widget

widget = Widget(showm, port=8000)

# if you want to use webRTC, you can pass the argument to choose this encoding
# which is a more robust option.
# `widget = Widget(showm, port=8000, encoding='webrtc')`

time_sleep = 1000 if interactive else 1
Ejemplo n.º 25
0
def test_record():
    xyzr = np.array([[0, 0, 0, 10], [100, 0, 0, 25], [200, 0, 0, 50]])
    colors = np.array([[1, 0, 0, 1], [0, 1, 0, 1], [0, 0, 1., 1]])
    sphere_actor = actor.sphere(centers=xyzr[:, :3],
                                colors=colors[:],
                                radii=xyzr[:, 3])
    scene = window.Scene()
    scene.add(sphere_actor)

    def test_content(filename='fury.png', colors_found=(True, True)):
        npt.assert_equal(os.path.isfile(filename), True)
        arr = io.load_image(filename)
        report = window.analyze_snapshot(arr,
                                         colors=[(0, 255, 0), (255, 0, 0)])
        npt.assert_equal(report.objects, 3)
        npt.assert_equal(report.colors_found, colors_found)
        return arr

    # Basic test
    with InTemporaryDirectory():
        window.record(scene)
        test_content()

    # test out_path and path_numbering, n_frame
    with InTemporaryDirectory():
        filename = "tmp_snapshot.png"
        window.record(scene, out_path=filename)
        test_content(filename)
        window.record(scene, out_path=filename, path_numbering=True)
        test_content(filename + "000000.png")
        window.record(scene,
                      out_path=filename,
                      path_numbering=True,
                      n_frames=3)
        test_content(filename + "000000.png")
        test_content(filename + "000001.png")
        test_content(filename + "000002.png")
        npt.assert_equal(os.path.isfile(filename + "000003.png"), False)

    # test verbose
    with captured_output() as (out, _):
        window.record(scene, verbose=True)

    npt.assert_equal(
        out.getvalue().strip(), "Camera Position (315.14, 0.00, 536.43)\n"
        "Camera Focal Point (119.89, 0.00, 0.00)\n"
        "Camera View Up (0.00, 1.00, 0.00)")
    # test camera option
    with InTemporaryDirectory():
        window.record(scene,
                      cam_pos=(310, 0, 530),
                      cam_focal=(120, 0, 0),
                      cam_view=(0, 0, 1))
        test_content()

    # test size and clipping
    # Skip it on Mac mainly due to offscreen case on Travis. It works well
    # with a display. Need to check if screen_clip works. Need to check if
    # ReadFrontBufferOff(), ShouldRerenderOn() could improved this OSX case.
    if not skip_osx:
        with InTemporaryDirectory():
            window.record(scene,
                          out_path='fury_1.png',
                          size=(1000, 1000),
                          magnification=5)
            npt.assert_equal(os.path.isfile('fury_1.png'), True)
            arr = io.load_image('fury_1.png')

            npt.assert_equal(arr.shape, (5000, 5000, 3))

            window.record(scene,
                          out_path='fury_2.png',
                          size=(5000, 5000),
                          screen_clip=True)
            npt.assert_equal(os.path.isfile('fury_2.png'), True)
            arr = io.load_image('fury_2.png')

            assert_less_equal(arr.shape[0], 5000)
            assert_less_equal(arr.shape[1], 5000)
Ejemplo n.º 26
0
client = p.connect(p.GUI)
p.setGravity(0, 0, -10, physicsClientId=client)
xyz = np.array([[0, 0, 0]])
enableCol = 1
f = 1


class storage:
    f = 1
    orn_prev = 0


#BALL
ball = actor.sphere(centers=np.array([[2, 3, 3]]),
                    colors=np.array([1, 1, 1]),
                    radii=0.6)
ball_coll = p.createCollisionShape(p.GEOM_SPHERE, radius=0.3)
ball_vis = p.createVisualShape(p.GEOM_SPHERE, radius=0.3)
ball_ = p.createMultiBody(baseMass=3,
                          baseCollisionShapeIndex=ball_coll,
                          baseVisualShapeIndex=ball_vis,
                          basePosition=[2, 3, 3],
                          baseOrientation=[0, 0, 0, 1])
p.changeDynamics(ball_, -1, lateralFriction=0.3, restitution=0.5)

#BASE
base = actor.box(centers=np.array([[-4, 3, -0.1]]),
                 directions=[1.57, 0, 0],
                 size=(20, 15, 0.2),
                 colors=(0, 1, 0))
Ejemplo n.º 27
0
    async def test(use_raw_array, ms_stream=16):
        width_0 = 300
        height_0 = 200

        centers = np.array([[0, 0, 0], [-1, 0, 0], [1, 0, 0]])
        colors = np.array([[1, 0, 0], [0, 1, 0], [0, 0, 1]])
        actors = actor.sphere(centers, colors=colors, radii=.1)

        scene = window.Scene()
        scene.add(actors)
        showm = window.ShowManager(
            scene,
            reset_camera=False,
            size=(width_0, height_0),
            order_transparent=False,
        )

        showm.initialize()

        stream = FuryStreamClient(showm,
                                  use_raw_array=use_raw_array,
                                  whithout_iren_start=True)
        stream_interaction = FuryStreamInteraction(max_queue_size=500,
                                                   showm=showm,
                                                   use_raw_array=use_raw_array,
                                                   whithout_iren_start=True)

        showm.render()
        # test jpeg method
        for _ in range(10):
            stream_interaction.circular_queue.enqueue(
                np.array([_CQUEUE.event_ids.mouse_weel, 1, 0, 0, 0, 0, .1, 0],
                         dtype='d'))
        for _ in range(10):
            stream_interaction.circular_queue.enqueue(
                np.array([_CQUEUE.event_ids.mouse_weel, -1, 0, 0, 0, 0, .1, 0],
                         dtype='d'))
        dxs = []
        for shift, ctrl in ((0, 1), (1, 0), (0, 0)):
            x = width_0 / 2
            y = height_0 / 2
            stream_interaction.circular_queue.enqueue(
                np.array([
                    _CQUEUE.event_ids.left_btn_press, 0, x, y, ctrl, shift, .1,
                    0
                ],
                         dtype='d'))
            for i in range(50):
                if ctrl == 1:
                    x = x + i / 50 * width_0 / 4
                else:
                    if i < 25:
                        dx = +i / 50
                        dxs.append(dx)
                        x = x - dx
                    else:
                        x = x + dxs[::-1][i - 25]
                stream_interaction.circular_queue.enqueue(
                    np.array([
                        _CQUEUE.event_ids.mouse_move, 0, x, y, ctrl, shift, .1,
                        0
                    ],
                             dtype='d'))
            stream_interaction.circular_queue.enqueue(
                np.array([
                    _CQUEUE.event_ids.left_btn_release, 0, x, y, ctrl, shift,
                    .1, 0
                ],
                         dtype='d'))

        stream_interaction.start(ms_stream, use_asyncio=True)
        while stream_interaction.circular_queue.head != -1:
            showm.render()
            await asyncio.sleep(.01)
        stream_interaction.stop()
        stream.stop()
        stream.cleanup()
        stream_interaction.cleanup()
Ejemplo n.º 28
0
base_color = np.array([1, 1, 1])
base_position = np.array([0, 0, -0.1])
base_orientation = np.array([0, 0, 0, 1])

# Wall Parameters
wall_height = 10
wall_width = 10
brick_mass = 0.5
brick_size = np.array([0.2, 0.4, 0.2])

###############################################################################
# Now we define the required parameters to render the Ball.

# Ball actor
ball_actor = actor.sphere(centers=np.array([[0, 0, 0]]),
                          colors=ball_color,
                          radii=ball_radius)

# Collision shape for the ball.
ball_coll = p.createCollisionShape(p.GEOM_SPHERE, radius=ball_radius)

# Creating a multi-body which will be tracked by pybullet.
ball = p.createMultiBody(baseMass=3,
                         baseCollisionShapeIndex=ball_coll,
                         basePosition=ball_position,
                         baseOrientation=ball_orientation)

# Change the dynamics of the ball by adding friction and restitution.
p.changeDynamics(ball, -1, lateralFriction=0.3, restitution=0.5)

###############################################################################
Ejemplo n.º 29
0
# The colors of each edge are interpolated between the two endpoints.

edges_colors = []
for source, target in edges:
    edges_colors.append(np.array([colors[source], colors[target]]))

edges_colors = np.average(np.array(edges_colors), axis=1)

###############################################################################
# Our data preparation is ready, it is time to visualize them all. We start to
# build 2 actors that we represent our data : sphere_actor for the nodes and
# lines_actor for the edges.

sphere_actor = actor.sphere(centers=np.zeros(positions.shape),
                            colors=colors,
                            radii=radii * 0.5,
                            theta=8,
                            phi=8)

lines_actor = actor.line(np.zeros((len(edges), 2, 3)),
                         colors=edges_colors,
                         lod=False,
                         fake_tube=True,
                         linewidth=3)

###############################################################################
# Defining timer callback and layout iterator


def new_layout_timer(showm,
                     edges_list,
Ejemplo n.º 30
0
import pybullet as p
import time

# Pybullet client
client = p.connect(p.DIRECT)
p.setGravity(0, 0, -10, physicsClientId=client)


class storage:
    f = 1  # F determines if the force has been applied or not.
    orn_prev = 0  # to keep track of the previous orientation.(No use for now)


# BALL
ball_actor = actor.sphere(centers=np.array([[0, 0, 0]]),
                          colors=np.array([1, 0, 0]),
                          radii=0.3)
ball_coll = p.createCollisionShape(p.GEOM_SPHERE, radius=0.3)
ball = p.createMultiBody(baseMass=3,
                         baseCollisionShapeIndex=ball_coll,
                         basePosition=[2, 0, 1.5],
                         baseOrientation=[0, 0, 0, 1])
p.changeDynamics(ball, -1, lateralFriction=0.3, restitution=0.5)

# BASE Plane
base_actor = actor.box(centers=np.array([[0, 0, 0]]),
                       directions=[0, 0, 0],
                       size=(5, 5, 0.2),
                       colors=(1, 1, 1))
base_coll = p.createCollisionShape(p.GEOM_BOX,
                                   halfExtents=[2.5, 2.5, 0.1