def CreatePlanet(radius, center):
    sphere = vtkSphereSource()
    sphere.SetPhiResolution(40)
    sphere.SetThetaResolution(40)
    sphere.SetCenter(center)
    sphere.SetRadius(radius)
    sphere.Update()
    sphereGeom = sphere.GetOutput()
    return sphereGeom
Beispiel #2
0
 def _sphere(self, center, color, radius):
     from vtkmodules.vtkFiltersSources import vtkSphereSource
     sphere = vtkSphereSource()
     sphere.SetThetaResolution(8)
     sphere.SetPhiResolution(8)
     sphere.SetRadius(radius)
     sphere.SetCenter(center)
     sphere.Update()
     mesh = pyvista.wrap(sphere.GetOutput())
     actor = _add_mesh(self.plotter, mesh=mesh, color=color)
     return actor, mesh
def main():
    colors = vtkNamedColors()
    renderer = vtkRenderer()
    renWin = vtkRenderWindow()
    renWin.AddRenderer(renderer)
    iren = vtkRenderWindowInteractor()
    iren.SetRenderWindow(renWin)

    sphere = vtkSphereSource()
    sphere.SetPhiResolution(100)
    sphere.SetThetaResolution(16)
    sphere.SetCenter(2, 0, 0)
    sphere.SetRadius(69)
    sphere.Update()
    sphereGeom = sphere.GetOutput()

    cone = vtkConeSource()
    cone.SetRadius(40)
    cone.SetHeight(100)
    cone.SetResolution(50)
    cone.Update()
    coneGeom = cone.GetOutput()

    print('Number of points in sphere = ', sphereGeom.GetNumberOfPoints())
    print('Number of triangles in sphere = ', sphereGeom.GetNumberOfCells())

    print('Number of points in cone = ', coneGeom.GetNumberOfPoints())
    print('Number of triangles in cone = ', coneGeom.GetNumberOfCells())

    mapperS = vtkDataSetMapper()
    mapperS.SetInputData(sphereGeom)
    actorS = vtkActor()
    actorS.SetMapper(mapperS)
    actorS.GetProperty().SetColor(1.0, 0.0, 0.0)
    actorS.GetProperty().SetOpacity(0.5)
    renderer.AddActor(actorS)

    mapperC = vtkDataSetMapper()
    mapperC.SetInputData(coneGeom)
    actorC = vtkActor()
    actorC.SetMapper(mapperC)
    actorC.GetProperty().SetOpacity(0.5)
    renderer.AddActor(actorC)

    renderer.SetBackground(colors.GetColor3d('SlateGray'))
    renWin.SetSize(640, 480)
    renWin.SetWindowName('Aarya\'s First VTK Program')

    renWin.Render()

    # Interact with the data.
    iren.Start()
Beispiel #4
0
def get_dataset(pa=None,ca=None):
    sphere = vtkSphereSource()
    sphere.Update()

    data = sphere.GetOutputDataObject(0)
    data.GetPointData().Initialize()
    data.GetCellData().Initialize()

    if pa:
        array = vtkIntArray()
        array.SetName(pa)
        array.SetNumberOfTuples(data.GetNumberOfPoints())
        data.GetPointData().AddArray(array)

    if ca:
        array = vtkIntArray()
        array.SetName(ca)
        array.SetNumberOfTuples(data.GetNumberOfCells())
        data.GetCellData().AddArray(array)
    return data
Beispiel #5
0
def get_dataset(pa=None, ca=None):
    sphere = vtkSphereSource()
    sphere.Update()

    data = sphere.GetOutputDataObject(0)
    data.GetPointData().Initialize()
    data.GetCellData().Initialize()

    if pa:
        array = vtkIntArray()
        array.SetName(pa)
        array.SetNumberOfTuples(data.GetNumberOfPoints())
        data.GetPointData().AddArray(array)

    if ca:
        array = vtkIntArray()
        array.SetName(ca)
        array.SetNumberOfTuples(data.GetNumberOfCells())
        data.GetCellData().AddArray(array)
    return data
Beispiel #6
0
 def sphere(self,
            center,
            color,
            scale,
            opacity=1.0,
            resolution=8,
            backface_culling=False,
            radius=None):
     from vtkmodules.vtkFiltersSources import vtkSphereSource
     factor = 1.0 if radius is not None else scale
     center = np.array(center, dtype=float)
     if len(center) == 0:
         return None, None
     _check_option('center.ndim', center.ndim, (1, 2))
     _check_option('center.shape[-1]', center.shape[-1], (3, ))
     with warnings.catch_warnings():
         warnings.filterwarnings("ignore", category=FutureWarning)
         sphere = vtkSphereSource()
         sphere.SetThetaResolution(resolution)
         sphere.SetPhiResolution(resolution)
         if radius is not None:
             sphere.SetRadius(radius)
         sphere.Update()
         geom = sphere.GetOutput()
         mesh = PolyData(center)
         glyph = mesh.glyph(orient=False,
                            scale=False,
                            factor=factor,
                            geom=geom)
         actor = _add_mesh(self.plotter,
                           mesh=glyph,
                           color=color,
                           opacity=opacity,
                           backface_culling=backface_culling,
                           smooth_shading=self.smooth_shading)
         return actor, glyph
Beispiel #7
0
 def quiver3d(self,
              x,
              y,
              z,
              u,
              v,
              w,
              color,
              scale,
              mode,
              resolution=8,
              glyph_height=None,
              glyph_center=None,
              glyph_resolution=None,
              opacity=1.0,
              scale_mode='none',
              scalars=None,
              colormap=None,
              backface_culling=False,
              line_width=2.,
              name=None,
              glyph_width=None,
              glyph_depth=None,
              glyph_radius=0.15,
              solid_transform=None,
              *,
              clim=None):
     _check_option('mode', mode, ALLOWED_QUIVER_MODES)
     with warnings.catch_warnings():
         warnings.filterwarnings("ignore", category=FutureWarning)
         factor = scale
         vectors = np.c_[u, v, w]
         points = np.vstack(np.c_[x, y, z])
         n_points = len(points)
         cell_type = np.full(n_points, VTK_VERTEX)
         cells = np.c_[np.full(n_points, 1), range(n_points)]
         args = (cells, cell_type, points)
         if not VTK9:
             args = (np.arange(n_points) * 3, ) + args
         grid = UnstructuredGrid(*args)
         if scalars is None:
             scalars = np.ones((n_points, ))
         _point_data(grid)['scalars'] = np.array(scalars)
         _point_data(grid)['vec'] = vectors
         if mode == '2darrow':
             return _arrow_glyph(grid, factor), grid
         elif mode == 'arrow':
             alg = _glyph(grid,
                          orient='vec',
                          scalars='scalars',
                          factor=factor)
             mesh = pyvista.wrap(alg.GetOutput())
         else:
             tr = None
             if mode == 'cone':
                 glyph = vtkConeSource()
                 glyph.SetCenter(0.5, 0, 0)
                 if glyph_radius is not None:
                     glyph.SetRadius(glyph_radius)
             elif mode == 'cylinder':
                 glyph = vtkCylinderSource()
                 if glyph_radius is not None:
                     glyph.SetRadius(glyph_radius)
             elif mode == 'oct':
                 glyph = vtkPlatonicSolidSource()
                 glyph.SetSolidTypeToOctahedron()
             else:
                 assert mode == 'sphere', mode  # guaranteed above
                 glyph = vtkSphereSource()
             if mode == 'cylinder':
                 if glyph_height is not None:
                     glyph.SetHeight(glyph_height)
                 if glyph_center is not None:
                     glyph.SetCenter(glyph_center)
                 if glyph_resolution is not None:
                     glyph.SetResolution(glyph_resolution)
                 tr = vtkTransform()
                 tr.RotateWXYZ(90, 0, 0, 1)
             elif mode == 'oct':
                 if solid_transform is not None:
                     assert solid_transform.shape == (4, 4)
                     tr = vtkTransform()
                     tr.SetMatrix(
                         solid_transform.astype(np.float64).ravel())
             if tr is not None:
                 # fix orientation
                 glyph.Update()
                 trp = vtkTransformPolyDataFilter()
                 trp.SetInputData(glyph.GetOutput())
                 trp.SetTransform(tr)
                 glyph = trp
             glyph.Update()
             geom = glyph.GetOutput()
             mesh = grid.glyph(orient='vec',
                               scale=scale_mode == 'vector',
                               factor=factor,
                               geom=geom)
         actor = _add_mesh(
             self.plotter,
             mesh=mesh,
             color=color,
             opacity=opacity,
             scalars=None,
             colormap=colormap,
             show_scalar_bar=False,
             backface_culling=backface_culling,
             clim=clim,
         )
     return actor, mesh
Beispiel #8
0
def main():
    colors = vtkNamedColors()

    operation = "intersection"
    reader = vtkUnstructuredGridReader()
    reader.SetFileName(ATRIA_VTK_FILE)
    geo_filter = vtkGeometryFilter()
    geo_filter.SetInputConnection(reader.GetOutputPort())
    geo_filter.Update()
    poly1 = geo_filter.GetOutput()

    tri1 = vtkTriangleFilter()
    tri1.SetInputData(poly1)
    clean1 = vtkCleanPolyData()
    clean1.SetInputConnection(tri1.GetOutputPort())
    clean1.Update()
    input1 = clean1.GetOutput()

    sphereSource1 = vtkSphereSource()
    sphereSource1.SetCenter(20.43808060942321, 18.333007878470767,
                            34.5753857481471)
    sphereSource1.SetRadius(0.5)
    # sphereSource1.SetPhiResolution(21)
    # sphereSource1.SetThetaResolution(21)
    sphereSource1.Update()
    input2 = sphereSource1.GetOutput()

    input1Mapper = vtkPolyDataMapper()
    input1Mapper.SetInputData(input1)
    input1Mapper.ScalarVisibilityOff()
    input1Actor = vtkActor()
    input1Actor.SetMapper(input1Mapper)
    input1Actor.GetProperty().SetDiffuseColor(colors.GetColor3d("Tomato"))
    input1Actor.GetProperty().SetSpecular(0.6)
    input1Actor.GetProperty().SetSpecularPower(20)
    # input1Actor.SetPosition(input1.GetBounds()[1] - input1.GetBounds()[0], 0, 0)

    input2Mapper = vtkPolyDataMapper()
    input2Mapper.SetInputData(input2)
    input2Mapper.ScalarVisibilityOff()
    input2Actor = vtkActor()
    input2Actor.SetMapper(input2Mapper)
    input2Actor.GetProperty().SetDiffuseColor(colors.GetColor3d("Mint"))
    input2Actor.GetProperty().SetSpecular(0.6)
    input2Actor.GetProperty().SetSpecularPower(20)
    # input2Actor.SetPosition(-(input1.GetBounds()[1] - input1.GetBounds()[0]), 0, 0)

    booleanOperation = vtkBooleanOperationPolyDataFilter()
    if operation.lower() == "union":
        booleanOperation.SetOperationToUnion()
    elif operation.lower() == "intersection":
        booleanOperation.SetOperationToIntersection()
    elif operation.lower() == "difference":
        booleanOperation.SetOperationToDifference()
    else:
        print("Unknown operation:", operation)
        return

    booleanOperation.SetInputData(0, input1)
    booleanOperation.SetInputData(1, input2)

    booleanOperationMapper = vtkPolyDataMapper()
    booleanOperationMapper.SetInputConnection(booleanOperation.GetOutputPort())
    booleanOperationMapper.ScalarVisibilityOff()

    booleanOperationActor = vtkActor()
    booleanOperationActor.SetMapper(booleanOperationMapper)
    booleanOperationActor.GetProperty().SetDiffuseColor(
        colors.GetColor3d("Banana"))
    booleanOperationActor.GetProperty().SetSpecular(0.6)
    booleanOperationActor.GetProperty().SetSpecularPower(20)

    renderer = vtkRenderer()
    renderer.AddViewProp(input1Actor)
    renderer.AddViewProp(input2Actor)
    renderer.AddViewProp(booleanOperationActor)
    renderer.SetBackground(colors.GetColor3d("Silver"))
    renderWindow = vtkRenderWindow()
    renderWindow.AddRenderer(renderer)
    renderWindow.SetSize(640, 480)
    renderWindow.SetWindowName("BooleanOperationPolyDataFilter")

    viewUp = [0.0, 0.0, 1.0]
    position = [0.0, -1.0, 0.0]
    PositionCamera(renderer, viewUp, position)
    renderer.GetActiveCamera().Dolly(1.4)
    renderer.ResetCameraClippingRange()

    renWinInteractor = vtkRenderWindowInteractor()
    renWinInteractor.SetRenderWindow(renderWindow)

    renderWindow.Render()
    renWinInteractor.Start()