def test_set_camera(): s = Scene() s.render(interactive=False) cam = s.plotter.camera set_camera(s, cam) set_camera(s, "sagittal")
def setup_scene(self): """ Set scene's axes and camera """ # Get axes if self.axes: self.axes = self._make_axes() # self.scene.add_actor(ax) else: self.axes = None # Fix camera set_camera(self.scene, self.scene.plotter.camera)
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)`" )
def setup_plotter(self): """ Changes the scene's default plotter with one attached to the qtWidget in the pyqt application. """ # Get embedded plotter new_plotter = Plotter(qtWidget=self.vtkWidget) self.scene.plotter = new_plotter # Get axes if self.axes: self.axes = self._make_axes() # self.scene.add_actor(ax) else: self.axes = None # Fix camera set_camera(self.scene, self.scene.plotter.camera)
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", )
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", )