def initialize(self): # Bring used components self.registerVtkWebProtocol(vtk_protocols.vtkWebMouseHandler()) self.registerVtkWebProtocol(vtk_protocols.vtkWebViewPort()) self.registerVtkWebProtocol(vtkWebPublishImageDelivery(decode=False)) # Custom API self.registerVtkWebProtocol(MouseWheel()) # tell the C++ web app to use no encoding. # ParaViewWebPublishImageDelivery must be set to decode=False to match. self.getApplication().SetImageEncoding(0) # Update authentication key to use self.updateSecret(_Server.authKey) if not _Server.view: scene = window.Scene() scene.background((1, 1, 1)) if os.path.isfile(_Server.centersToLoad): with open(_Server.centersToLoad) as f: f_dict = json.loads(f.read()) centers = np.array(f_dict["centers"]) n_points = len(centers) colors = np.array(f_dict["colors"]) directions = np.random.rand(n_points, 3) else: n_points = 10000 translate = 100 centers = translate * np.random.rand(n_points, 3) - translate / 2 colors = 255 * np.random.rand(n_points, 3) directions = np.random.rand(n_points, 3) # scales = np.random.rand(n_points, 3) prim_type = ['sphere', 'ellipsoid', 'torus'] primitive = [random.choice(prim_type) for _ in range(n_points)] sdf_actor = actor.sdf(centers, directions, colors, primitive) scene.add(sdf_actor) scene.add(actor.axes()) showm = window.ShowManager(scene) renderWindow = showm.window showm.iren.EnableRenderOff() self.getApplication().GetObjectIdMap().SetActiveObject( "VIEW", renderWindow)
def test_sdf_actor(interactive=False): scene = window.Scene() scene.background((1, 1, 1)) 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, colors, primitive, scales) scene.add(sdf_actor) scene.add(actor.axes()) if interactive: window.show(scene) arr = window.snapshot(scene) report = window.analyze_snapshot(arr, colors=colors) npt.assert_equal(report.objects, 3)
def test_sdf_actor(interactive=False): scene = window.Scene() scene.background((1, 1, 1)) centers = np.array([[2, 0, 0], [0, 2, 0], [0, 0, 0], [2, 2, 0]]) * 11 colors = np.array([[1, 0, 0], [0, 1, 0], [0, 0, 1], [1, 1, 0]]) directions = np.array([[0, 1, 0], [1, 0, 0], [0, 0, 1], [1, 1, 0]]) scales = [1, 2, 3, 4] primitive = ['sphere', 'ellipsoid', 'torus', 'capsule'] sdf_actor = actor.sdf(centers, directions, colors, primitive, scales) scene.add(sdf_actor) scene.add(actor.axes()) if interactive: window.show(scene) arr = window.snapshot(scene) report = window.analyze_snapshot(arr, colors=colors) npt.assert_equal(report.objects, 4) # Draw 3 spheres as the primitive type is str scene.clear() primitive = 'sphere' sdf_actor = actor.sdf(centers, directions, colors, primitive, scales) scene.add(sdf_actor) scene.add(actor.axes()) if interactive: window.show(scene) arr = window.snapshot(scene) report = window.analyze_snapshot(arr, colors=colors) npt.assert_equal(report.objects, 4) # A sphere and default back to two torus # as the primitive type is list scene.clear() primitive = ['sphere'] with npt.assert_warns(UserWarning): sdf_actor = actor.sdf(centers, directions, colors, primitive, scales) scene.add(sdf_actor) scene.add(actor.axes()) if interactive: window.show(scene) arr = window.snapshot(scene) report = window.analyze_snapshot(arr, colors=colors) npt.assert_equal(report.objects, 4) # One sphere and ellipsoid each # Default to torus scene.clear() primitive = ['sphere', 'ellipsoid'] with npt.assert_warns(UserWarning): sdf_actor = actor.sdf(centers, directions, colors, primitive, scales) scene.add(sdf_actor) scene.add(actor.axes()) if interactive: window.show(scene) arr = window.snapshot(scene) report = window.analyze_snapshot(arr, colors=colors) npt.assert_equal(report.objects, 4)
colors = np.array( [categoryColors[category2index[category]] for category in categories]) radii = 1 + np.random.rand(len(positions)) edgesPositions = [] edgesColors = [] 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) sphere_actor = actor.sdf( centers=positions, colors=colors, primitives='sphere', scales=radii * 0.5, ) lines_actor = actor.line( edgesPositions, colors=edgesColors, opacity=0.1, ) scene = window.Scene() scene.add(lines_actor) scene.add(sphere_actor) scene.set_camera(position=(0, 0, 1000), focal_point=(0.0, 0.0, 0.0),
from fury import window, actor ############################################################################### # Lets define variables for the SDF Actor dirs = np.random.rand(3, 3) colors = np.random.rand(3, 3) * 255 centers = np.array([[1, 0, 0], [0, 0, 0], [-1, 0, 0]]) scales = np.random.rand(3, 1) ############################################################################### # Create SDF Actor sdfactor = actor.sdf(centers=centers, directions=dirs, colors=colors, primitives=['sphere', 'torus', 'ellipsoid'], scales=scales) ############################################################################## # Create a scene scene = window.Scene() scene.background((1.0, 0.8, 0.8)) scene.add(sdfactor) ############################################################################### # Show Manager # # Since all the elements have been initialised ,we add them to the show # manager.