Esempio n. 1
0
def test_get_camera_params():
    s = Scene()
    s.render(interactive=False)
    cam = s.plotter.camera

    params = get_camera_params(scene=s)
    params2 = get_camera_params(camera=cam)

    check_camera_param(params)
    check_camera_param(params2)
Esempio n. 2
0
    def render(self, interactive=None, camera=None, zoom=1.75, **kwargs):
        """
            Renders the scene.

            :param interactive: bool. If note settings.INTERACTIVE is used.
                If true the program's execution is stopped and users
                can interact with scene.
            :param camera: str, dict. If none the default camera is used.
                Pass a valid camera input to specify the camera position when
                the scene is rendered.
            :param zoom: float
            :param kwargs: additional arguments to pass to self.plotter.show
        """
        # get vedo plotter
        if self.plotter is None:
            self._get_plotter()

        # Get camera
        if camera is None:
            camera = get_camera(settings.DEFAULT_CAMERA)
        else:
            camera = check_camera_param(camera)

        if not self.jupyter:
            camera = set_camera(self, camera)

        # Apply axes correction
        self._correct_axes()

        # Apply style
        self._apply_style()

        if self.inset and not self.jupyter and not self.is_rendered:
            self._get_inset()

        # render
        self.is_rendered = True
        if not self.jupyter:
            if interactive is None:
                interactive = settings.INTERACTIVE

            for txt in self.labels:
                txt.followCamera(self.plotter.camera)

            self.plotter.show(
                *self.renderables,
                interactive=interactive,
                zoom=zoom,
                bg=settings.BACKGROUND_COLOR,
                offscreen=settings.OFFSCREEN,
                camera=camera.copy(),
                interactorStyle=0,
            )
        else:
            print(
                "Your scene is ready for rendering, use: `show(scene.renderables)`"
            )
Esempio n. 3
0
    def add_keyframe(
        self,
        time,
        duration=0,
        camera=None,
        zoom=None,
        interpol="sigma",
        callback=None,
        **kwargs,
    ):
        """
        Add a keyframe to the video.

        :param time: float, time in seconds during the video
            at which the keyframe takes place.
        :param duration: float, if >0 the key frame is repeated
            every 5ms to go from start to start+duration
        :param zoom: camera zoom
        :param camera: dictionary of camera parameters
        :param interpol: str, if `sigma` or `linear` specifies
            the interpolation mode between key frames.
        :param callback: function which takes scene, current video
            frame and total number of frames in video as arguments.
            can be used to make stuff happen during a key frame (e.g. remove
            an actor)
        """
        if camera is not None:
            camera = check_camera_param(camera)

        if time in self.keyframes.keys() and time > 0:
            print(f"[b {orange}]Keyframe {time} already exists, overwriting!")

        if zoom is None:
            previous_zoom = list(self.keyframes.values())[0]["zoom"] or 0
            zoom = previous_zoom

        if not duration:
            self.keyframes[time] = dict(
                zoom=zoom,
                camera=camera,
                callback=callback,
                interpol=interpol,
                kwargs=kwargs,
            )
        else:
            for time in np.arange(time, time + duration, 0.001):
                self.keyframes[time] = dict(
                    zoom=zoom if time == 0 else None,
                    camera=camera,
                    callback=callback,
                    interpol=interpol,
                    kwargs=kwargs,
                )
Esempio n. 4
0
def test_camera_params():
    for camera in cameras:
        check_camera_param(camera)
Esempio n. 5
0
    def render(
        self,
        interactive=None,
        camera=None,
        zoom=None,
        update_camera=True,
        **kwargs,
    ):
        """
        Renders the scene.

        :param interactive: bool. If note settings.INTERACTIVE is used.
            If true the program's execution is stopped and users
            can interact with scene.
        :param camera: str, dict. If none the default camera is used.
            Pass a valid camera input to specify the camera position when
            the scene is rendered.
        :param zoom: float, if None atlas default is used
        :param update_camera: bool, if False the camera is not changed
        :param kwargs: additional arguments to pass to self.plotter.show
        """
        logger.debug(
            f"Rendering scene. Interactive: {interactive}, camera: {camera}, zoom: {zoom}"
        )
        # get zoom
        zoom = zoom or self.atlas.zoom

        # get vedo plotter
        if self.plotter is None:
            self._get_plotter()

        # Get camera
        camera = camera or settings.DEFAULT_CAMERA
        if isinstance(camera, str):
            camera = get_camera(camera)
        else:
            camera = check_camera_param(camera)

        if camera["focalPoint"] is None:
            camera["focalPoint"] = self.root._mesh.centerOfMass()

        if not self.backend and camera is not None:
            camera = set_camera(self, camera)

        # Apply axes correction
        for actor in self.clean_actors:
            if not actor._is_transformed:
                self._prepare_actor(actor)
                self.plotter.add(actor.mesh)

            if actor._needs_silhouette or actor._needs_label:
                self._prepare_actor(actor)

        # add labels to the scene
        for label in self.labels:
            if label._is_added:
                continue
            else:
                label._mesh = label.mesh.clone()
                self._prepare_actor(label)
                self.plotter.add(label._mesh)
                label._is_added = True

        # Apply style
        self._apply_style()

        if self.inset and not self.is_rendered:
            self._get_inset()

        # render
        self.is_rendered = True
        if not self.backend:  # not running in a python script
            if interactive is None:
                interactive = settings.INTERACTIVE

            for txt in self.labels:
                txt.followCamera(self.plotter.camera)

            self.plotter.show(
                interactive=interactive,
                zoom=zoom,
                bg=settings.BACKGROUND_COLOR,
                offscreen=settings.OFFSCREEN,
                camera=camera.copy() if update_camera else None,
                interactorStyle=0,
                rate=40,
            )
        elif self.backend == "k3d":  # pragma: no cover
            # Remove silhouettes
            self.remove(*self.get_actors(br_class="silhouette"))
            print(
                f"[{teal}]Your scene is ready for rendering, use:\n",
                Syntax("from vedo import show", lexer_name="python"),
                Syntax("vedo.show(*scene.renderables)", lexer_name="python"),
                sep="\n",
            )
        else:  # pragma: no cover
            print(
                f"[{teal}]Your scene is ready for rendering, use:\n",
                Syntax("from itkwidgets import view", lexer_name="python"),
                Syntax(
                    "view(scene.plotter.show(*scene.renderables))",
                    lexer_name="python",
                ),
                sep="\n",
            )
Esempio n. 6
0
    def render(self, interactive=None, camera=None, zoom=1.75, **kwargs):
        """
            Renders the scene.

            :param interactive: bool. If note settings.INTERACTIVE is used.
                If true the program's execution is stopped and users
                can interact with scene.
            :param camera: str, dict. If none the default camera is used.
                Pass a valid camera input to specify the camera position when
                the scene is rendered.
            :param zoom: float
            :param kwargs: additional arguments to pass to self.plotter.show
        """
        # get vedo plotter
        if self.plotter is None:
            self._get_plotter()

        # Get camera
        if camera is None:
            camera = get_camera(settings.DEFAULT_CAMERA)
        else:
            camera = check_camera_param(camera)

        if not self.backend and camera is not None:
            camera = set_camera(self, camera)

        # Apply axes correction
        self._prepare_actor()

        # Apply style
        self._apply_style()

        if self.inset and not self.is_rendered:
            self._get_inset()

        # render
        self.is_rendered = True
        if not self.backend:  # not running in a python script
            if interactive is None:
                interactive = settings.INTERACTIVE

            for txt in self.labels:
                txt.followCamera(self.plotter.camera)

            self.plotter.show(
                *self.renderables,
                interactive=interactive,
                zoom=zoom,
                bg=settings.BACKGROUND_COLOR,
                offscreen=settings.OFFSCREEN,
                camera=camera.copy() if camera else None,
                interactorStyle=0,
            )
        elif self.backend == "k3d":  # pragma: no cover
            # Remove silhouettes
            self.remove(*self.get_actors(br_class="silhouette"))
            print(
                f"[{teal}]Your scene is ready for rendering, use:\n",
                Syntax("from vedo import show", lexer_name="python"),
                Syntax("vedo.show(*scene.renderables)", lexer_name="python"),
                sep="\n",
            )
        else:  # pragma: no cover
            print(
                f"[{teal}]Your scene is ready for rendering, use:\n",
                Syntax("from itkwidgets import view", lexer_name="python"),
                Syntax(
                    "view(scene.plotter.show(*scene.renderables))",
                    lexer_name="python",
                ),
                sep="\n",
            )