Пример #1
0
 def __init__(self, module_manager):
     SimpleVTKClassModuleBase.__init__(
         self, module_manager,
         vtk.vtkPlatonicSolidSource(), 'Processing.',
         (), ('vtkPolyData',),
         replaceDoc=True,
         inputFunctions=None, outputFunctions=None)
Пример #2
0
def nice_sphere(radius, subdivisions, center=(0, 0, 0)):
    platonic_solid = vtk.vtkPlatonicSolidSource()
    platonic_solid.SetSolidTypeToIcosahedron()
    platonic_solid = platonic_solid.GetOutput()
    platonic_solid.Update()

    points = []
    for i in range(platonic_solid.GetNumberOfCells()):
        cell = platonic_solid.GetCell(i)
        a = platonic_solid.GetPoint(cell.GetPointId(0))
        b = platonic_solid.GetPoint(cell.GetPointId(1))
        c = platonic_solid.GetPoint(cell.GetPointId(2))

        points += [a, b, c] \
               + subdivide(a, b, c, subdivisions)

    vtkPoints = vtk.vtkPoints()
    for point in points:
        vtkPoints.InsertNextPoint(center[0] + point[0] * radius,
                                  center[1] + point[1] * radius,
                                  center[2] + point[2] * radius)
    poly = vtk.vtkPolyData()
    poly.SetPoints(vtkPoints)
    cells = vtk.vtkCellArray()
    for i in range(len(points)):
        vertex = vtk.vtkVertex()
        vertex.GetPointIds().SetId(0, i)
        cells.InsertNextCell(vertex)
    poly.SetVerts(cells)
    return poly
Пример #3
0
def vtk_ellipsoid_topomesh(ellipsoid_radius=50.0, ellipsoid_scales=[1,1,1], ellipsoid_axes=np.diag(np.ones(3)), ellipsoid_center=np.zeros(3)):
    """
    """      
    import vtk
    from openalea.cellcomplex.property_topomesh.utils.image_tools import vtk_polydata_to_triangular_mesh

    ico = vtk.vtkPlatonicSolidSource()
    ico.SetSolidTypeToIcosahedron()
    ico.Update()

    subdivide = vtk.vtkLoopSubdivisionFilter()
    subdivide.SetNumberOfSubdivisions(3)
    subdivide.SetInputConnection(ico.GetOutputPort())
    subdivide.Update()

    scale_transform = vtk.vtkTransform()
    scale_factor = ellipsoid_radius/(np.sqrt(2)/2.)
    scale_transform.Scale(scale_factor,scale_factor,scale_factor)

    ellipsoid_sphere = vtk.vtkTransformPolyDataFilter()
    ellipsoid_sphere.SetInput(subdivide.GetOutput())
    ellipsoid_sphere.SetTransform(scale_transform)
    ellipsoid_sphere.Update()

    ellipsoid_transform = vtk.vtkTransform()
    axes_transform = vtk.vtkLandmarkTransform()
    source_points = vtk.vtkPoints()
    source_points.InsertNextPoint([1,0,0])
    source_points.InsertNextPoint([0,1,0])
    source_points.InsertNextPoint([0,0,1])
    target_points = vtk.vtkPoints()
    target_points.InsertNextPoint(ellipsoid_axes[0])
    target_points.InsertNextPoint(ellipsoid_axes[1])
    target_points.InsertNextPoint(ellipsoid_axes[2])
    axes_transform.SetSourceLandmarks(source_points)
    axes_transform.SetTargetLandmarks(target_points)
    axes_transform.SetModeToRigidBody()
    axes_transform.Update()
    ellipsoid_transform.SetMatrix(axes_transform.GetMatrix())
    ellipsoid_transform.Scale(ellipsoid_scales[0],ellipsoid_scales[1],ellipsoid_scales[2])
    center_transform = vtk.vtkTransform()
    center_transform.Translate(ellipsoid_center[0],ellipsoid_center[1],ellipsoid_center[2])
    center_transform.Concatenate(ellipsoid_transform)
    ellipsoid_ellipsoid = vtk.vtkTransformPolyDataFilter()
    ellipsoid_ellipsoid.SetInput(ellipsoid_sphere.GetOutput())
    ellipsoid_ellipsoid.SetTransform(center_transform)
    ellipsoid_ellipsoid.Update()

    ellipsoid_mesh = vtk_polydata_to_triangular_mesh(ellipsoid_ellipsoid.GetOutput())

    topomesh = triangle_topomesh(ellipsoid_mesh.triangles.values(),ellipsoid_mesh.points)

    return topomesh
Пример #4
0
def CreateIcosahedron(radius, sl):
    icosahedronsource = vtk.vtkPlatonicSolidSource()
    icosahedronsource.SetSolidTypeToIcosahedron()
    icosahedronsource.Update()
    icosahedron = icosahedronsource.GetOutput()

    subdivfilter = lsf.LinearSubdivisionFilter()
    subdivfilter.SetInputData(icosahedron)
    subdivfilter.SetNumberOfSubdivisions(sl)
    subdivfilter.Update()

    icosahedron = subdivfilter.GetOutput()
    icosahedron = normalize_points(icosahedron, radius)

    return icosahedron
Пример #5
0
def sphere2points(
    params, min_radius
):  #input [X,Y,Z,Radius],min #output array[[0..#points],[x,y,z,nx,ny,nz]]
    vtk.vtkMultiThreader.SetGlobalMaximumNumberOfThreads(
        1)  # parallelized otherwise
    resolution = 1 + int(math.ceil(params[3] / min_radius)**0.5)
    ico = vtk.vtkPlatonicSolidSource()
    ico.SetSolidTypeToIcosahedron()
    subdivide = vtk.vtkLoopSubdivisionFilter()
    subdivide.SetNumberOfSubdivisions(resolution)
    subdivide.SetInputConnection(ico.GetOutputPort())
    subdivide.Update()
    points = np.asarray(subdivide.GetOutput().GetPoints().GetData())
    x = points[:, 0]
    y = points[:, 1]
    z = points[:, 2]
    r = ne.evaluate("sqrt(x**2 + y**2 + z**2)")
    points = np.divide(points[:, :], r[:, None])
    normals = points
    points = points * params[3] + params[0:3]  # scale and translation
    result = np.concatenate((points, normals), axis=1)
    return result
Пример #6
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,
              backface_culling=False,
              line_width=2.,
              name=None,
              glyph_width=None,
              glyph_depth=None,
              solid_transform=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.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)
         grid.point_arrays['vec'] = vectors
         if scale_mode == 'scalar':
             grid.point_arrays['mag'] = np.array(scalars)
             scale = 'mag'
         else:
             scale = False
         if mode == '2darrow':
             return _arrow_glyph(grid, factor), grid
         elif mode == 'arrow':
             alg = _glyph(grid, orient='vec', scalars=scale, factor=factor)
             mesh = pyvista.wrap(alg.GetOutput())
         else:
             tr = None
             if mode == 'cone':
                 glyph = vtk.vtkConeSource()
                 glyph.SetCenter(0.5, 0, 0)
                 glyph.SetRadius(0.15)
             elif mode == 'cylinder':
                 glyph = vtk.vtkCylinderSource()
                 glyph.SetRadius(0.15)
             elif mode == 'oct':
                 glyph = vtk.vtkPlatonicSolidSource()
                 glyph.SetSolidTypeToOctahedron()
             else:
                 assert mode == 'sphere', mode  # guaranteed above
                 glyph = vtk.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 = vtk.vtkTransform()
                 tr.RotateWXYZ(90, 0, 0, 1)
             elif mode == 'oct':
                 if solid_transform is not None:
                     assert solid_transform.shape == (4, 4)
                     tr = vtk.vtkTransform()
                     tr.SetMatrix(
                         solid_transform.astype(np.float64).ravel())
             if tr is not None:
                 # fix orientation
                 glyph.Update()
                 trp = vtk.vtkTransformPolyDataFilter()
                 trp.SetInputData(glyph.GetOutput())
                 trp.SetTransform(tr)
                 glyph = trp
             glyph.Update()
             geom = glyph.GetOutput()
             mesh = grid.glyph(orient='vec',
                               scale=scale,
                               factor=factor,
                               geom=geom)
         _add_mesh(self.plotter,
                   mesh=mesh,
                   color=color,
                   opacity=opacity,
                   backface_culling=backface_culling)
    def __init__(self, parent = None):
        super(VTKFrame, self).__init__(parent)

        self.vtkWidget = QVTKRenderWindowInteractor(self)
        self.iren = self.vtkWidget.GetRenderWindow().GetInteractor()
        vl = QtGui.QVBoxLayout(self)
        vl.addWidget(self.vtkWidget)
        vl.setContentsMargins(0, 0, 0, 0)
 
        # Create source
        # Each face has a different cell scalar
        # So create a lookup table with a different colour
        # for each face.
        lut = vtk.vtkLookupTable()
        lut.SetNumberOfTableValues(20)
        lut.SetTableRange(0.0, 19.0)
        lut.Build()
        lut.SetTableValue(0, 0, 0, 0)
        lut.SetTableValue(1, 0, 0, 1)
        lut.SetTableValue(2, 0, 1, 0)
        lut.SetTableValue(3, 0, 1, 1)
        lut.SetTableValue(4, 1, 0, 0)
        lut.SetTableValue(5, 1, 0, 1)
        lut.SetTableValue(6, 1, 1, 0)
        lut.SetTableValue(7, 1, 1, 1)
        lut.SetTableValue(8, 0.7, 0.7, 0.7)
        lut.SetTableValue(9, 0, 0, 0.7)
        lut.SetTableValue(10, 0, 0.7, 0)
        lut.SetTableValue(11, 0, 0.7, 0.7)
        lut.SetTableValue(12, 0.7, 0, 0)
        lut.SetTableValue(13, 0.7, 0, 0.7)
        lut.SetTableValue(14, 0.7, 0.7, 0)
        lut.SetTableValue(15, 0, 0, 0.4)
        lut.SetTableValue(16, 0, 0.4, 0)
        lut.SetTableValue(17, 0, 0.4, 0.4)
        lut.SetTableValue(18, 0.4, 0, 0)
        lut.SetTableValue(19, 0.4, 0, 0.4)
        
        platonicSolids = list()
        # There are five Platonic solids.
        platonicSolids.append(vtk.vtkPlatonicSolidSource())
        platonicSolids.append(vtk.vtkPlatonicSolidSource())
        platonicSolids.append(vtk.vtkPlatonicSolidSource())
        platonicSolids.append(vtk.vtkPlatonicSolidSource())
        platonicSolids.append(vtk.vtkPlatonicSolidSource())
        # Specify the Platonic Solid to create.
        for idx, item in enumerate(platonicSolids):
            platonicSolids[idx].SetSolidType(idx)
        names = ["Tetrahedron","Cube","Octahedron","Icosahedron", "Dodecahedron"]
        
        renderers = list()
        mappers = list()
        actors = list()
        textmappers = list()
        textactors = list()
        
        # Create a common text property.
        textProperty = vtk.vtkTextProperty()
        textProperty.SetFontSize(10)
        textProperty.SetJustificationToCentered()
        
        # Create a parametric function source, renderer, mapper 
        # and actor for each object.
        for idx, item in enumerate(platonicSolids):
            platonicSolids[idx].Update()
        
            mappers.append(vtk.vtkPolyDataMapper())
            mappers[idx].SetInputConnection(platonicSolids[idx].GetOutputPort())
            mappers[idx].SetLookupTable(lut)
            mappers[idx].SetScalarRange(0, 20)
        
            actors.append(vtk.vtkActor())
            actors[idx].SetMapper(mappers[idx])
        
            textmappers.append(vtk.vtkTextMapper())
            textmappers[idx].SetInput(names[idx])
            textmappers[idx].SetTextProperty(textProperty)
        
            textactors.append(vtk.vtkActor2D())
            textactors[idx].SetMapper(textmappers[idx])
            textactors[idx].SetPosition(120, 16)
        
            renderers.append(vtk.vtkRenderer())
        
        rowDimensions = 3
        colDimensions = 2
        
        for idx in range(rowDimensions * colDimensions):
            if idx >= len(platonicSolids):
                renderers.append(vtk.vtkRenderer)
        
        rendererSize = 300
        
        # Setup the RenderWindow
        self.vtkWidget.GetRenderWindow().SetSize(rendererSize * rowDimensions / colDimensions, rendererSize * colDimensions )
        
        # Add and position the renders to the render window.
        viewport = list()
        idx = -1
        for row in range(rowDimensions):
            for col in range(colDimensions):
                idx += 1
                viewport[:] = []
                viewport.append(float(col) * rendererSize / (colDimensions * rendererSize))
                viewport.append(float(rowDimensions - (row+1)) * rendererSize / (rowDimensions * rendererSize))
                viewport.append(float(col+1)*rendererSize / (colDimensions * rendererSize))
                viewport.append(float(rowDimensions - row) * rendererSize / (rowDimensions * rendererSize))
        
                if idx > (len(platonicSolids) - 1):
                    continue
        
                renderers[idx].SetViewport(viewport)
                self.vtkWidget.GetRenderWindow().AddRenderer(renderers[idx])
        
                renderers[idx].AddActor(actors[idx])
                renderers[idx].AddActor(textactors[idx])
                renderers[idx].SetBackground(0.4,0.3,0.2)
        
        self._initialized = False
Пример #8
0
    def testPlatonicSolids(self):

        # Create five instances of vtkPlatonicSolidSource
        # corresponding to each of the five Platonic solids.
        #
        tet = vtk.vtkPlatonicSolidSource()
        tet.SetSolidTypeToTetrahedron()
        tetMapper = vtk.vtkPolyDataMapper()
        tetMapper.SetInputConnection(tet.GetOutputPort())
        tetActor = vtk.vtkActor()
        tetActor.SetMapper(tetMapper)

        cube = vtk.vtkPlatonicSolidSource()
        cube.SetSolidTypeToCube()
        cubeMapper = vtk.vtkPolyDataMapper()
        cubeMapper.SetInputConnection(cube.GetOutputPort())
        cubeActor = vtk.vtkActor()
        cubeActor.SetMapper(cubeMapper)
        cubeActor.AddPosition(2.0, 0, 0)

        oct = vtk.vtkPlatonicSolidSource()
        oct.SetSolidTypeToOctahedron()
        octMapper = vtk.vtkPolyDataMapper()
        octMapper.SetInputConnection(oct.GetOutputPort())
        octActor = vtk.vtkActor()
        octActor.SetMapper(octMapper)
        octActor.AddPosition(4.0, 0, 0)

        icosa = vtk.vtkPlatonicSolidSource()
        icosa.SetSolidTypeToIcosahedron()
        icosaMapper = vtk.vtkPolyDataMapper()
        icosaMapper.SetInputConnection(icosa.GetOutputPort())
        icosaActor = vtk.vtkActor()
        icosaActor.SetMapper(icosaMapper)
        icosaActor.AddPosition(6.0, 0, 0)

        dode = vtk.vtkPlatonicSolidSource()
        dode.SetSolidTypeToDodecahedron()
        dodeMapper = vtk.vtkPolyDataMapper()
        dodeMapper.SetInputConnection(dode.GetOutputPort())
        dodeActor = vtk.vtkActor()
        dodeActor.SetMapper(dodeMapper)
        dodeActor.AddPosition(8.0, 0, 0)

        # Create rendering stuff
        #
        ren = vtk.vtkRenderer()
        renWin = vtk.vtkRenderWindow()
        renWin.AddRenderer(ren)

        # Add the actors to the renderer, set the background and size
        #
        ren.AddActor(tetActor)
        ren.AddActor(cubeActor)
        ren.AddActor(octActor)
        ren.AddActor(icosaActor)
        ren.AddActor(dodeActor)

        colors = self.Colors()

        # Create a lookup table with colors for each face
        #
        math = vtk.vtkMath()
        lut = vtk.vtkLookupTable()
        lut.SetNumberOfColors(20)
        lut.Build()
        lut.SetTableValue(0, colors.GetRGBAColor("red"))
        lut.SetTableValue(1, colors.GetRGBAColor("lime"))
        lut.SetTableValue(2, colors.GetRGBAColor("yellow"))
        lut.SetTableValue(3, colors.GetRGBAColor("blue"))
        lut.SetTableValue(4, colors.GetRGBAColor("magenta"))
        lut.SetTableValue(5, colors.GetRGBAColor("cyan"))
        lut.SetTableValue(6, colors.GetRGBAColor("spring_green"))
        lut.SetTableValue(7, colors.GetRGBAColor("lavender"))
        lut.SetTableValue(8, colors.GetRGBAColor("mint_cream"))
        lut.SetTableValue(9, colors.GetRGBAColor("violet"))
        lut.SetTableValue(10, colors.GetRGBAColor("ivory_black"))
        lut.SetTableValue(11, colors.GetRGBAColor("coral"))
        lut.SetTableValue(12, colors.GetRGBAColor("pink"))
        lut.SetTableValue(13, colors.GetRGBAColor("salmon"))
        lut.SetTableValue(14, colors.GetRGBAColor("sepia"))
        lut.SetTableValue(15, colors.GetRGBAColor("carrot"))
        lut.SetTableValue(16, colors.GetRGBAColor("gold"))
        lut.SetTableValue(17, colors.GetRGBAColor("forest_green"))
        lut.SetTableValue(18, colors.GetRGBAColor("turquoise"))
        lut.SetTableValue(19, colors.GetRGBAColor("plum"))

        lut.SetTableRange(0, 19)
        tetMapper.SetLookupTable(lut)
        tetMapper.SetScalarRange(0, 19)
        cubeMapper.SetLookupTable(lut)
        cubeMapper.SetScalarRange(0, 19)
        octMapper.SetLookupTable(lut)
        octMapper.SetScalarRange(0, 19)
        icosaMapper.SetLookupTable(lut)
        icosaMapper.SetScalarRange(0, 19)
        dodeMapper.SetLookupTable(lut)
        dodeMapper.SetScalarRange(0, 19)

        cam = ren.GetActiveCamera()
        cam.SetPosition(3.89696, 7.20771, 1.44123)
        cam.SetFocalPoint(3.96132, 0, 0)
        cam.SetViewUp(-0.0079335, 0.196002, -0.980571)
        cam.SetClippingRange(5.42814, 9.78848)

        ren.SetBackground(colors.GetRGBColor("black"))
        renWin.SetSize(400, 150)

        # render and interact with data

        iRen = vtk.vtkRenderWindowInteractor()
        iRen.SetRenderWindow(renWin);
        renWin.Render()

        img_file = "TestPlatonicSolids.png"
        vtk.test.Testing.compareImage(iRen.GetRenderWindow(), vtk.test.Testing.getAbsImagePath(img_file), threshold=25)
        vtk.test.Testing.interact()
    def __init__(self, parent=None):
        super(VTKFrame, self).__init__(parent)

        self.vtkWidget = QVTKRenderWindowInteractor(self)
        self.iren = self.vtkWidget.GetRenderWindow().GetInteractor()
        vl = QtGui.QVBoxLayout(self)
        vl.addWidget(self.vtkWidget)
        vl.setContentsMargins(0, 0, 0, 0)

        # Create source
        # Each face has a different cell scalar
        # So create a lookup table with a different colour
        # for each face.
        lut = vtk.vtkLookupTable()
        lut.SetNumberOfTableValues(20)
        lut.SetTableRange(0.0, 19.0)
        lut.Build()
        lut.SetTableValue(0, 0, 0, 0)
        lut.SetTableValue(1, 0, 0, 1)
        lut.SetTableValue(2, 0, 1, 0)
        lut.SetTableValue(3, 0, 1, 1)
        lut.SetTableValue(4, 1, 0, 0)
        lut.SetTableValue(5, 1, 0, 1)
        lut.SetTableValue(6, 1, 1, 0)
        lut.SetTableValue(7, 1, 1, 1)
        lut.SetTableValue(8, 0.7, 0.7, 0.7)
        lut.SetTableValue(9, 0, 0, 0.7)
        lut.SetTableValue(10, 0, 0.7, 0)
        lut.SetTableValue(11, 0, 0.7, 0.7)
        lut.SetTableValue(12, 0.7, 0, 0)
        lut.SetTableValue(13, 0.7, 0, 0.7)
        lut.SetTableValue(14, 0.7, 0.7, 0)
        lut.SetTableValue(15, 0, 0, 0.4)
        lut.SetTableValue(16, 0, 0.4, 0)
        lut.SetTableValue(17, 0, 0.4, 0.4)
        lut.SetTableValue(18, 0.4, 0, 0)
        lut.SetTableValue(19, 0.4, 0, 0.4)

        platonicSolids = list()
        # There are five Platonic solids.
        platonicSolids.append(vtk.vtkPlatonicSolidSource())
        platonicSolids.append(vtk.vtkPlatonicSolidSource())
        platonicSolids.append(vtk.vtkPlatonicSolidSource())
        platonicSolids.append(vtk.vtkPlatonicSolidSource())
        platonicSolids.append(vtk.vtkPlatonicSolidSource())
        # Specify the Platonic Solid to create.
        for idx, item in enumerate(platonicSolids):
            platonicSolids[idx].SetSolidType(idx)
        names = [
            "Tetrahedron", "Cube", "Octahedron", "Icosahedron", "Dodecahedron"
        ]

        renderers = list()
        mappers = list()
        actors = list()
        textmappers = list()
        textactors = list()

        # Create a common text property.
        textProperty = vtk.vtkTextProperty()
        textProperty.SetFontSize(10)
        textProperty.SetJustificationToCentered()

        # Create a parametric function source, renderer, mapper
        # and actor for each object.
        for idx, item in enumerate(platonicSolids):
            platonicSolids[idx].Update()

            mappers.append(vtk.vtkPolyDataMapper())
            mappers[idx].SetInputConnection(
                platonicSolids[idx].GetOutputPort())
            mappers[idx].SetLookupTable(lut)
            mappers[idx].SetScalarRange(0, 20)

            actors.append(vtk.vtkActor())
            actors[idx].SetMapper(mappers[idx])

            textmappers.append(vtk.vtkTextMapper())
            textmappers[idx].SetInput(names[idx])
            textmappers[idx].SetTextProperty(textProperty)

            textactors.append(vtk.vtkActor2D())
            textactors[idx].SetMapper(textmappers[idx])
            textactors[idx].SetPosition(120, 16)

            renderers.append(vtk.vtkRenderer())

        rowDimensions = 3
        colDimensions = 2

        for idx in range(rowDimensions * colDimensions):
            if idx >= len(platonicSolids):
                renderers.append(vtk.vtkRenderer)

        rendererSize = 300

        # Setup the RenderWindow
        self.vtkWidget.GetRenderWindow().SetSize(
            rendererSize * rowDimensions / colDimensions,
            rendererSize * colDimensions)

        # Add and position the renders to the render window.
        viewport = list()
        idx = -1
        for row in range(rowDimensions):
            for col in range(colDimensions):
                idx += 1
                viewport[:] = []
                viewport.append(
                    float(col) * rendererSize / (colDimensions * rendererSize))
                viewport.append(
                    float(rowDimensions - (row + 1)) * rendererSize /
                    (rowDimensions * rendererSize))
                viewport.append(
                    float(col + 1) * rendererSize /
                    (colDimensions * rendererSize))
                viewport.append(
                    float(rowDimensions - row) * rendererSize /
                    (rowDimensions * rendererSize))

                if idx > (len(platonicSolids) - 1):
                    continue

                renderers[idx].SetViewport(viewport)
                self.vtkWidget.GetRenderWindow().AddRenderer(renderers[idx])

                renderers[idx].AddActor(actors[idx])
                renderers[idx].AddActor(textactors[idx])
                renderers[idx].SetBackground(0.4, 0.3, 0.2)

        self._initialized = False
Пример #10
0
    def testPlatonicSolids(self):

        # Create five instances of vtkPlatonicSolidSource
        # corresponding to each of the five Platonic solids.
        #
        tet = vtk.vtkPlatonicSolidSource()
        tet.SetSolidTypeToTetrahedron()
        tetMapper = vtk.vtkPolyDataMapper()
        tetMapper.SetInputConnection(tet.GetOutputPort())
        tetActor = vtk.vtkActor()
        tetActor.SetMapper(tetMapper)

        cube = vtk.vtkPlatonicSolidSource()
        cube.SetSolidTypeToCube()
        cubeMapper = vtk.vtkPolyDataMapper()
        cubeMapper.SetInputConnection(cube.GetOutputPort())
        cubeActor = vtk.vtkActor()
        cubeActor.SetMapper(cubeMapper)
        cubeActor.AddPosition(2.0, 0, 0)

        oct = vtk.vtkPlatonicSolidSource()
        oct.SetSolidTypeToOctahedron()
        octMapper = vtk.vtkPolyDataMapper()
        octMapper.SetInputConnection(oct.GetOutputPort())
        octActor = vtk.vtkActor()
        octActor.SetMapper(octMapper)
        octActor.AddPosition(4.0, 0, 0)

        icosa = vtk.vtkPlatonicSolidSource()
        icosa.SetSolidTypeToIcosahedron()
        icosaMapper = vtk.vtkPolyDataMapper()
        icosaMapper.SetInputConnection(icosa.GetOutputPort())
        icosaActor = vtk.vtkActor()
        icosaActor.SetMapper(icosaMapper)
        icosaActor.AddPosition(6.0, 0, 0)

        dode = vtk.vtkPlatonicSolidSource()
        dode.SetSolidTypeToDodecahedron()
        dodeMapper = vtk.vtkPolyDataMapper()
        dodeMapper.SetInputConnection(dode.GetOutputPort())
        dodeActor = vtk.vtkActor()
        dodeActor.SetMapper(dodeMapper)
        dodeActor.AddPosition(8.0, 0, 0)

        # Create rendering stuff
        #
        ren = vtk.vtkRenderer()
        renWin = vtk.vtkRenderWindow()
        renWin.AddRenderer(ren)

        # Add the actors to the renderer, set the background and size
        #
        ren.AddActor(tetActor)
        ren.AddActor(cubeActor)
        ren.AddActor(octActor)
        ren.AddActor(icosaActor)
        ren.AddActor(dodeActor)

        colors = self.Colors()

        # Create a lookup table with colors for each face
        #
        math = vtk.vtkMath()
        lut = vtk.vtkLookupTable()
        lut.SetNumberOfColors(20)
        lut.Build()
        lut.SetTableValue(0, colors.GetRGBAColor("red"))
        lut.SetTableValue(1, colors.GetRGBAColor("lime"))
        lut.SetTableValue(2, colors.GetRGBAColor("yellow"))
        lut.SetTableValue(3, colors.GetRGBAColor("blue"))
        lut.SetTableValue(4, colors.GetRGBAColor("magenta"))
        lut.SetTableValue(5, colors.GetRGBAColor("cyan"))
        lut.SetTableValue(6, colors.GetRGBAColor("spring_green"))
        lut.SetTableValue(7, colors.GetRGBAColor("lavender"))
        lut.SetTableValue(8, colors.GetRGBAColor("mint_cream"))
        lut.SetTableValue(9, colors.GetRGBAColor("violet"))
        lut.SetTableValue(10, colors.GetRGBAColor("ivory_black"))
        lut.SetTableValue(11, colors.GetRGBAColor("coral"))
        lut.SetTableValue(12, colors.GetRGBAColor("pink"))
        lut.SetTableValue(13, colors.GetRGBAColor("salmon"))
        lut.SetTableValue(14, colors.GetRGBAColor("sepia"))
        lut.SetTableValue(15, colors.GetRGBAColor("carrot"))
        lut.SetTableValue(16, colors.GetRGBAColor("gold"))
        lut.SetTableValue(17, colors.GetRGBAColor("forest_green"))
        lut.SetTableValue(18, colors.GetRGBAColor("turquoise"))
        lut.SetTableValue(19, colors.GetRGBAColor("plum"))

        lut.SetTableRange(0, 19)
        tetMapper.SetLookupTable(lut)
        tetMapper.SetScalarRange(0, 19)
        cubeMapper.SetLookupTable(lut)
        cubeMapper.SetScalarRange(0, 19)
        octMapper.SetLookupTable(lut)
        octMapper.SetScalarRange(0, 19)
        icosaMapper.SetLookupTable(lut)
        icosaMapper.SetScalarRange(0, 19)
        dodeMapper.SetLookupTable(lut)
        dodeMapper.SetScalarRange(0, 19)

        cam = ren.GetActiveCamera()
        cam.SetPosition(3.89696, 7.20771, 1.44123)
        cam.SetFocalPoint(3.96132, 0, 0)
        cam.SetViewUp(-0.0079335, 0.196002, -0.980571)
        cam.SetClippingRange(5.42814, 9.78848)

        ren.SetBackground(colors.GetRGBColor("black"))
        renWin.SetSize(400, 150)

        # render and interact with data

        iRen = vtk.vtkRenderWindowInteractor()
        iRen.SetRenderWindow(renWin)
        renWin.Render()

        img_file = "TestPlatonicSolids.png"
        vtk.test.Testing.compareImage(
            iRen.GetRenderWindow(),
            vtk.test.Testing.getAbsImagePath(img_file),
            threshold=25)
        vtk.test.Testing.interact()
Пример #11
0
world['topomesh'].set_attribute('property_name_1','boundary')
world['topomesh'].set_attribute('display_1',True)
world['topomesh_edges'].set_attribute('intensity_range',(0,1))
world['topomesh_edges'].set_attribute('polydata_colormap',load_colormaps()['Reds'])
world['topomesh_edges'].set_attribute('linewidth',3)
world['topomesh_edges'].set_attribute('polydata_alpha',0.5)


import vtk

dome_radius = 50.0
dome_scales = [2,2,2]
dome_axes = np.diag(np.ones(3))
dome_center = np.zeros(3)

ico = vtk.vtkPlatonicSolidSource()
ico.SetSolidTypeToIcosahedron()
#ico.SetSolidTypeToOctahedron()
ico.Update()

sphere = vtk.vtkSphereSource()
# #dome_sphere.SetCenter(meristem_model.shape_model['dome_center'])
sphere.SetRadius(1)
sphere.SetThetaResolution(16)
sphere.SetPhiResolution(16)
sphere.Update()

#subdivide = vtk.vtkLoopSubdivisionFilter()
#subdivide = vtk.vtkButterflySubdivisionFilter()
subdivide = vtk.vtkLinearSubdivisionFilter()
subdivide.SetNumberOfSubdivisions(2)
Пример #12
0
def main():
    colors = vtk.vtkNamedColors()

    # Each face has a different cell scalar
    # Here we create a lookup table with a different colour
    # for each face. The colors have been carefully
    # chosen so that adjacent cells are colored distinctly.
    lut = vtk.vtkLookupTable()
    lut.SetNumberOfTableValues(20)
    lut.SetTableRange(0.0, 19.0)
    lut.Build()
    lut.SetTableValue(0, 0.1, 0.1, 0.1)
    lut.SetTableValue(1, 0, 0, 1)
    lut.SetTableValue(2, 0, 1, 0)
    lut.SetTableValue(3, 0, 1, 1)
    lut.SetTableValue(4, 1, 0, 0)
    lut.SetTableValue(5, 1, 0, 1)
    lut.SetTableValue(6, 1, 1, 0)
    lut.SetTableValue(7, 0.9, 0.7, 0.9)
    lut.SetTableValue(8, 0.5, 0.5, 0.5)
    lut.SetTableValue(9, 0.0, 0.0, 0.7)
    lut.SetTableValue(10, 0.5, 0.7, 0.5)
    lut.SetTableValue(11, 0, 0.7, 0.7)
    lut.SetTableValue(12, 0.7, 0, 0)
    lut.SetTableValue(13, 0.7, 0, 0.7)
    lut.SetTableValue(14, 0.7, 0.7, 0)
    lut.SetTableValue(15, 0, 0, 0.4)
    lut.SetTableValue(16, 0, 0.4, 0)
    lut.SetTableValue(17, 0, 0.4, 0.4)
    lut.SetTableValue(18, 0.4, 0, 0)
    lut.SetTableValue(19, 0.4, 0, 0.4)

    mappers = list()
    actors = list()
    textMappers = list()
    textActors = list()
    renderers = list()

    # Create a common text property.
    textProperty = vtk.vtkTextProperty()
    textProperty.SetFontSize(16)
    textProperty.SetJustificationToCentered()

    # Create the render window and interactor.
    renWin = vtk.vtkRenderWindow()
    renWin.SetWindowName("Platonic Solids")

    iRen = vtk.vtkRenderWindowInteractor()
    iRen.SetRenderWindow(renWin)

    # Create the source, renderer, mapper
    # and actor for each object.
    PlatonicSolids = list()
    # There are five Platonic solids.
    names = [
        "Tetrahedron", "Cube", "Octahedron", "Icosahedron", "Dodecahedron"
    ]
    for i in range(0, len(names)):
        PlatonicSolids.append(vtk.vtkPlatonicSolidSource())
        PlatonicSolids[i].SetSolidType(i)

        mappers.append(vtk.vtkPolyDataMapper())
        mappers[i].SetInputConnection(PlatonicSolids[i].GetOutputPort())
        mappers[i].SetLookupTable(lut)
        mappers[i].SetScalarRange(0, 19)

        actors.append(vtk.vtkActor())
        actors[i].SetMapper(mappers[i])

        textMappers.append(vtk.vtkTextMapper())
        textMappers[i].SetInput(names[i])
        textMappers[i].SetTextProperty(textProperty)

        textActors.append(vtk.vtkActor2D())
        textActors[i].SetMapper(textMappers[i])
        textActors[i].SetPosition(120, 16)

        renderers.append(vtk.vtkRenderer())
        renderers[i].AddActor(actors[i])
        renderers[i].AddViewProp(textActors[i])

        renWin.AddRenderer(renderers[i])

    # Setup the viewports
    xGridDimensions = 3
    yGridDimensions = 2
    rendererSize = 300
    renWin.SetSize(rendererSize * xGridDimensions,
                   rendererSize * yGridDimensions)
    for row in range(0, yGridDimensions):
        for col in range(0, xGridDimensions):
            index = row * xGridDimensions + col

            # (xmin, ymin, xmax, ymax)
            viewport = [
                float(col) / xGridDimensions,
                float(yGridDimensions - (row + 1)) / yGridDimensions,
                float(col + 1) / xGridDimensions,
                float(yGridDimensions - row) / yGridDimensions
            ]

            if index > (len(actors) - 1):
                # Add a renderer even if there is no actor.
                # This makes the render window background all the same color.
                ren = vtk.vtkRenderer()
                ren.SetBackground(colors.GetColor3d("SlateGray"))
                ren.SetViewport(viewport)
                renWin.AddRenderer(ren)
                continue

            renderers[index].SetViewport(viewport)
            renderers[index].SetBackground(colors.GetColor3d("SlateGray"))
            renderers[index].ResetCamera()
            renderers[index].GetActiveCamera().Azimuth(4.5)
            renderers[index].GetActiveCamera().Elevation(-18)
            renderers[index].ResetCameraClippingRange()

    iRen.Initialize()
    renWin.Render()
    iRen.Start()
Пример #13
0
def main():

    colors = vtk.vtkNamedColors()

    bkg = map(lambda x: x / 256.0, [51, 77, 102])
    # bkg = map(lambda x: x / 256.0, [26, 51, 77])
    colors.SetColor("BkgColor", *bkg)

    sourceObjects = list()

    subdivisionlevel = 6

    icosahedronsource = vtk.vtkPlatonicSolidSource()
    icosahedronsource.SetSolidTypeToIcosahedron()
    icosahedronsource.Update()

    sourceObjects.append(icosahedronsource.GetOutput())
    icosahedron = sourceObjects[-1]

    for sl in range(2, subdivisionlevel):

        # subdivfilter = vtk.vtkLinearSubdivisionFilter()
        subdivfilter = LinearSubdivisionFilter.LinearSubdivisionFilter()
        subdivfilter.SetInputData(icosahedron)
        subdivfilter.SetNumberOfSubdivisions(sl)
        subdivfilter.Update()

        subdivpoly = subdivfilter.GetOutput()
        subdivpoly = normalize_points(subdivpoly)

        print("\nlevel", sl)
        print("Points", subdivpoly.GetNumberOfPoints())
        print("Polys", subdivpoly.GetNumberOfPolys())

        sourceObjects.append(subdivpoly)

    renderers = list()
    mappers = list()
    actors = list()
    textmappers = list()
    textactors = list()

    # Create one text property for all.
    textProperty = vtk.vtkTextProperty()
    textProperty.SetFontSize(16)
    textProperty.SetJustificationToCentered()

    backProperty = vtk.vtkProperty()
    backProperty.SetColor(colors.GetColor3d("Red"))

    reader = vtk.vtkPolyDataReader()
    reader.SetFileName("ALLM_rotSphere.vtk")
    reader.Update()
    sourceObjects.append(reader.GetOutput())

    # Create a source, renderer, mapper, and actor
    # for each object.
    for i in range(0, len(sourceObjects)):
        mappers.append(vtk.vtkPolyDataMapper())
        mappers[i].SetInputData(sourceObjects[i])

        actors.append(vtk.vtkActor())
        actors[i].SetMapper(mappers[i])
        actors[i].GetProperty().SetColor(colors.GetColor3d("Seashell"))
        actors[i].SetBackfaceProperty(backProperty)

        textmappers.append(vtk.vtkTextMapper())
        textmappers[i].SetInput(sourceObjects[i].GetClassName())
        textmappers[i].SetTextProperty(textProperty)

        textactors.append(vtk.vtkActor2D())
        textactors[i].SetMapper(textmappers[i])
        textactors[i].SetPosition(120, 16)
        renderers.append(vtk.vtkRenderer())

    gridDimensions = 3

    # We need a renderer even if there is no actor.
    for i in range(len(sourceObjects), gridDimensions**2):
        renderers.append(vtk.vtkRenderer())

    renderWindow = vtk.vtkRenderWindow()
    renderWindow.SetWindowName("Icosahedron demo")
    rendererSize = 300
    renderWindow.SetSize(rendererSize * gridDimensions,
                         rendererSize * gridDimensions)

    for row in range(0, gridDimensions):
        for col in range(0, gridDimensions):
            index = row * gridDimensions + col
            x0 = float(col) / gridDimensions
            y0 = float(gridDimensions - row - 1) / gridDimensions
            x1 = float(col + 1) / gridDimensions
            y1 = float(gridDimensions - row) / gridDimensions
            renderWindow.AddRenderer(renderers[index])
            renderers[index].SetViewport(x0, y0, x1, y1)

            if index > (len(sourceObjects) - 1):
                continue

            renderers[index].AddActor(actors[index])
            renderers[index].AddActor(actors[0])
            renderers[index].AddActor(textactors[index])
            renderers[index].SetBackground(colors.GetColor3d("BkgColor"))
            renderers[index].ResetCamera()
            renderers[index].GetActiveCamera().Azimuth(30)
            renderers[index].GetActiveCamera().Elevation(30)
            renderers[index].GetActiveCamera().Zoom(0.8)
            renderers[index].ResetCameraClippingRange()

    interactor = vtk.vtkRenderWindowInteractor()
    interactor.SetRenderWindow(renderWindow)

    renderWindow.Render()
    interactor.Start()
Пример #14
0
from vtk.util.misc import vtkGetDataRoot
VTK_DATA_ROOT = vtkGetDataRoot()

# The resolution of the density function volume
res = 100

# Parameters for debugging
NPts = 1000000
math = vtk.vtkMath()
math.RandomSeed(31415)

# create pipeline
#
# Eight points forming a cube (the regular vtkCubeSource
# produces duplicate points)
cube = vtk.vtkPlatonicSolidSource()
cube.SetSolidTypeToCube()

sphere = vtk.vtkSphereSource()
sphere.SetRadius(0.05)

glyphs = vtk.vtkGlyph3D()
glyphs.SetInputConnection(cube.GetOutputPort())
glyphs.SetSourceConnection(sphere.GetOutputPort())
glyphs.ScalingOff()
glyphs.OrientOff()

mapper = vtk.vtkPolyDataMapper()
mapper.SetInputConnection(glyphs.GetOutputPort())

actor = vtk.vtkActor()