def render(self): """ """ self.apply_render_style() # Create camera and plotter if brainrender.WHOLE_SCREEN: sz = "full" else: sz = "auto" if brainrender.SHOW_AXES: axes = 4 else: axes = 0 mv = Plotter(N=2, axes=axes, size=sz, pos=brainrender.WINDOW_POS, bg=brainrender.BACKGROUND_COLOR, sharecam=True) actors = [] for scene in self.scenes: scene_actors = scene.get_actors() actors.append(scene_actors) mv.add(scene_actors) mv.show(actors[0], at=0, zoom=1.15, axes=axes, roll=180, interactive=False) mv.show(actors[1], at=1, interactive=False) interactive()
def render(self, _interactive=True, **kwargs): """ :param _interactive: (Default value = True) :param **kwargs: """ camera = kwargs.pop("camera", None) for scene in self.scenes: scene.apply_render_style() if camera is None: if scene.atlas.default_camera is None: scene_camera = brainrender.CAMERA else: scene_camera = scene.atlas.default_camera else: if camera: scene_camera = camera else: scene_camera = None if scene_camera is not None: set_camera(scene, scene_camera) if self.N > 4: print("Rendering {} scenes. Might take a few minutes.".format(self.N)) mv = Plotter(N=self.N, axes=4, size="auto", sharecam=True, bg=brainrender.BACKGROUND_COLOR) actors = [] for i, scene in enumerate(self.scenes): scene_actors = scene.get_actors() actors.append(scene_actors) mv.add(scene_actors) for i, scene_actors in enumerate(actors): mv.show(scene_actors, at=i, interactive=False) print("Rendering complete") if _interactive: interactive()
r = 20 u[...] = 1.0 U[n//2-r:n//2+r, n//2-r:n//2+r] = 0.50 V[n//2-r:n//2+r, n//2-r:n//2+r] = 0.25 u += 0.05*np.random.uniform(-1, 1, (n, n)) v += 0.05*np.random.uniform(-1, 1, (n, n)) sy, sx = V.shape grd = Grid(sx=sx, sy=sy, resx=sx, resy=sy) grd.lineWidth(0).wireframe(False).lighting(ambient=0.5) for step in range(Nsteps): for i in range(20): Lu = ( U[0:-2, 1:-1] + U[1:-1, 0:-2] - 4*U[1:-1, 1:-1] + U[1:-1, 2:] + U[2: , 1:-1]) Lv = ( V[0:-2, 1:-1] + V[1:-1, 0:-2] - 4*V[1:-1, 1:-1] + V[1:-1, 2:] + V[2: , 1:-1]) uvv = u*v*v u += (Du*Lu - uvv + F*(1-u)) v += (Dv*Lv + uvv - (F+k)*v) vvals = np.flip(V, axis=0).ravel() grd.cellColors(vvals, cmap='ocean_r').mapCellsToPoints() newpts = np.c_[grd.points()[:,[0,1]], grd.getPointArray('cellColors')*20] grd.points(newpts).show(axes=9, zoom=1.3, elevation=-.15, interactive=False) interactive()
def setCarPose(self, x, y, theta): self.lexus.pos(x=x, y=y, z=0.0).orientation(newaxis=[0, 0, 1.0], rotation=theta, rad=True) def show(self): vplt.show(self.goal, *self.obstacles, self.lexus, interactive=0) # camera={'pos':[0, 0, 10], # 'focalPoint':[0, 0, 10], # 'viewup':[0, 0, -1], # 'distance':43.871, # 'clippingRange':[33.465, 57.074]} ) def close(self): vplt.closeWindow() if __name__ == '__main__': viewer = CarWithObstacles() for x, y in [(1, 1), (1, -1), (-1, -1), (-1, 1)]: viewer.addObstacle(x, y, 0.8) N = 500 pose = np.array([2, 0, -np.pi]) step = (np.array([0, 0, 0]) - pose) / N step[2] = 0 for k in range(N): viewer.setCarPose(*(pose + k * step)) viewer.show() vplt.interactive() viewer.close()
def view_mesh( meshes: list, output_file: str, mesh_names: list = [], patient_data="", plid="", scan_path="", ): logging.info("Opening mesh viewer.") settings.useDepthPeeling = True vmeshes = [] def slider1(widget, event): value = widget.GetRepresentation().GetValue() vmeshes[index].color(value) def slider2(widget, event): value = widget.GetRepresentation().GetValue() vmeshes[index].opacity(value) def buttonfunc(): global index bu.switch() index = mesh_names.index(bu.status()) def background_swap(): bg_button.switch() vp.backgroundRenderer.SetBackground(colors.getColor( bg_button.status())) def ar_view(): save() holo_registration_wrapper.start_viewer(output_file, plid) def save(): write_mesh_as_glb_with_colour(vmeshes, output_file) def open_scan(): external_2d_viewer.start(scan_path) vp = Plotter( sharecam=False, bg="./core/client/images/hologram_icon2.png", bg2='black', shape=[1, 1], size=[640, 480], interactive=False, ) # pos = position corner number: horizontal [1-4] or vertical [11-14] vp.addSlider2D(slider1, -9, 9, value=0, pos=4, title="color number") left_side_x = 0.1 vp.addSlider2D( slider2, xmin=0.00, xmax=1.00, value=0.5, pos=14, c="blue", title="alpha value (opacity)", ) bu = vp.addButton( buttonfunc, pos=(0.5, 0.05), # x,y fraction from bottom left corner states=mesh_names, font=font_style, # arial, courier, times size=25, bold=True, italic=False, ) save_button = vp.addButton( save, pos=(left_side_x, 0.05), # x,y fraction from bottom left corner states=["Save"], font=font_style, # arial, courier, times size=25, bold=True, italic=False, ) if holo_registration_wrapper.is_supported(plid): ar_button = vp.addButton( ar_view, pos=(left_side_x, 0.20), states=["AR View"], font=font_style, size=25, bold=True, italic=False, ) if scan_path != "": scan_button = vp.addButton( open_scan, pos=(left_side_x, 0.15), states=["2D View"], font=font_style, size=25, bold=True, italic=False, ) bg_button = vp.addButton( background_swap, pos=(left_side_x, 0.10), # x,y fraction from bottom left corner states=["black", "white"], font=font_style, size=25, bold=True, italic=False, ) for i in range(0, len(meshes)): vmeshes.append(trimesh2vtk(meshes[i], alphaPerCell=True)) doc = Text2D(patient_data, pos=4, c=(0, 113, 197)) vp.show(doc) vp.backgroundRenderer.GetActiveCamera().Zoom(1.3) vp.show(vmeshes) interactive()