Python vtk.vtkActor() Examples

The following are 30 code examples of vtk.vtkActor(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module vtk , or try the search function .
Example #1
Source File: visualization.py    From CityEnergyAnalyst with MIT License 8 votes vote down vote up
def stl2actor(ageometry_path, ageometry_name, ageometry_color):

    appendfilter = vtk.vtkAppendPolyData()
    render_lib = vtk.vtkSTLReader()
    polydata = vtk.vtkPolyData()
    render_lib.SetFileName(os.path.join(ageometry_path, ageometry_name+".stl"))
    render_lib.Update()
    polydata.ShallowCopy(render_lib.GetOutput())
    appendfilter.AddInputConnection(polydata.GetProducerPort())
    appendfilter.Update()

    #  Remove any duplicate points.
    cleanfilter = vtk.vtkCleanPolyData()
    cleanfilter.SetInputConnection(appendfilter.GetOutputPort())
    cleanfilter.Update()
    mapper = vtk.vtkPolyDataMapper()
    mapper.SetInputConnection(cleanfilter.GetOutputPort())

    actor = vtk.vtkActor()
    actor.SetMapper(mapper)
    actor.GetProperty().SetColor(ageometry_color)

    return actor, polydata 
Example #2
Source File: pointobject.py    From Det3D with Apache License 2.0 6 votes vote down vote up
def SetupPipelinePose(self):
        """Set up the VTK pipeline for visualizing multiple copies of a geometric 
        representation with different poses"""

        # use vtkTensorGlyph set 3d pose for each actor instance
        tensorGlyph = vtk.vtkTensorGlyph()
        tensorGlyph.SetInputData(self.pose_pd)  # setup with AddPoses()
        tensorGlyph.SetSourceData(self.pd)
        tensorGlyph.ColorGlyphsOff()
        tensorGlyph.ThreeGlyphsOff()
        tensorGlyph.ExtractEigenvaluesOff()
        tensorGlyph.Update()

        # Set up mappers and actors
        self.mapper = vtk.vtkPolyDataMapper()
        self.mapper.SetInputData(tensorGlyph.GetOutput())
        self.mapper.Update()
        self.actor = vtk.vtkActor()
        self.actor.GetProperty().SetLineWidth(1.5)
        self.actor.SetMapper(self.mapper) 
Example #3
Source File: visualization.py    From CityEnergyAnalyst with MIT License 6 votes vote down vote up
def points2actor(xyz, apoint_size):
    import vtk
    points = vtk.vtkPoints()
    # Create the topology of the point (a vertex)
    vertices = vtk.vtkCellArray()
    # Add points
    for i in range(0, len(xyz)):
        p = xyz.loc[i].values.tolist()
        point_id = points.InsertNextPoint(p)
        vertices.InsertNextCell(1)
        vertices.InsertCellPoint(point_id)
    # Create a poly data object
    polydata = vtk.vtkPolyData()
    # Set the points and vertices we created as the geometry and topology of the polydata
    polydata.SetPoints(points)
    polydata.SetVerts(vertices)
    polydata.Modified()
    # Mapper for points
    mapper = vtk.vtkPolyDataMapper()
    mapper.SetInput(polydata)
    # ACTOR for points
    actor = vtk.vtkActor()
    actor.SetMapper(mapper)
    actor.GetProperty().SetPointSize(apoint_size)
    return actor, polydata 
Example #4
Source File: visualization.py    From CityEnergyAnalyst with MIT License 6 votes vote down vote up
def face_points2actor(fps_df):

    cell_array = vtk.vtkCellArray()
    points = vtk.vtkPoints()
    point_id = 0
    for i in range(fps_df.shape[0]):
        polygon = vtk.vtkPolygon()
        polygon.GetPointIds().SetNumberOfIds(3)
        for n in range(3):
            points.InsertNextPoint(fps_df.ix[i, 0+3*n], fps_df.ix[i, 1+3*n], fps_df.ix[i, 2+3*n])
            polygon.GetPointIds().SetId(n, point_id)
            point_id += 1
        cell_array.InsertNextCell(polygon)
    polydata = vtk.vtkPolyData()
    polydata.SetPoints(points)
    polydata.SetPolys(cell_array)

    # mapper
    mapper = vtk.vtkPolyDataMapper()
    mapper.SetInput(polydata)
    # actor
    actor = vtk.vtkActor()
    actor.SetMapper(mapper)
    return actor, polydata 
Example #5
Source File: utility.py    From ILCC with BSD 2-Clause "Simplified" License 6 votes vote down vote up
def draw_one_grd_vtk(ls):  # arr:[a,b,c,d],a:orig, b, point1, c,point 2, d,color
    source = vtk.vtkPlaneSource()
    source.SetOrigin(ls[0])
    source.SetPoint1(ls[1])
    source.SetPoint2(ls[2])
    source.Update()
    # source.SetPoint1(0, 0, 0)
    # source.SetPoint2(4, 3, 0)

    # mapper
    mapper = vtk.vtkPolyDataMapper()
    color = vtk.vtkUnsignedCharArray()
    color.SetName("colors")
    color.SetNumberOfComponents(3)

    # color_tup = np.random.randint(1, 255, 3)

    color.SetNumberOfTuples(source.GetOutput().GetNumberOfCells())
    for i in xrange(source.GetOutput().GetNumberOfCells()):
        color_tup = np.array([255, 255, 255]) * ls[3]
        color.InsertTuple(i, color_tup)

    source.GetOutput().GetCellData().SetScalars(color)

    mapper.SetInputConnection(source.GetOutputPort())

    # actor
    actor = vtk.vtkActor()
    actor.SetMapper(mapper)

    # assign actor to the renderer
    # ren.AddActor(actor)

    return actor


# generate the color list of the point cloud for different color styles. intens_rg: color by reflectance intensity (red:high green:low),
# intens: color by reflectance intensity (white:high back:low), autumn: matplotlib autumn color map,  cool: matplotlib cool color map 
Example #6
Source File: vtkpointcloud.py    From deep-prior with GNU General Public License v3.0 6 votes vote down vote up
def __init__(self, zMin=-10.0, zMax=10.0, maxNumPoints=1e6):
        """
        Initialize class
        :param zMin: minimum depth
        :param zMax: maximum depth
        :param maxNumPoints: maximum number of points
        :return: None
        """
        self.maxNumPoints = int(maxNumPoints)
        self.vtkPolyData = vtk.vtkPolyData()
        self.clearPoints()
        mapper = vtk.vtkPolyDataMapper()
        mapper.SetInputData(self.vtkPolyData)
        mapper.SetColorModeToDefault()
        mapper.SetScalarRange(zMin, zMax)
        mapper.SetScalarVisibility(1)
        self.vtkActor = vtk.vtkActor()
        self.vtkActor.SetMapper(mapper) 
Example #7
Source File: vtkpointcloud.py    From deep-prior-pp with GNU General Public License v3.0 6 votes vote down vote up
def __init__(self, pts=None, zMin=-10.0, zMax=10.0, maxNumPoints=1e6, color='depth'):
        """
        Initialize class
        :param zMin: minimum depth
        :param zMax: maximum depth
        :param maxNumPoints: maximum number of points
        :return: None
        """
        self.color = color
        self.maxNumPoints = int(maxNumPoints)
        self.vtkPolyData = vtk.vtkPolyData()
        self.clearPoints()
        mapper = vtk.vtkPolyDataMapper()
        mapper.SetInputData(self.vtkPolyData)
        mapper.SetColorModeToDefault()
        mapper.SetScalarRange(zMin, zMax)
        mapper.SetScalarVisibility(1)
        self.vtkActor = vtk.vtkActor()
        self.vtkActor.SetMapper(mapper)
        self.vtkActor.GetProperty().SetPointSize(3.0)
        self.rng = numpy.random.RandomState(23455)

        if pts is not None:
            self.addPoints(pts) 
Example #8
Source File: vtkpointcloud.py    From deep-prior-pp with GNU General Public License v3.0 6 votes vote down vote up
def viewer(pointclouds):
        assert all([isinstance(p, VtkPointCloud) for p in pointclouds])

        # Renderer
        renderer = vtk.vtkRenderer()
        renderer.SetBackground(1.0, 1.0, 1.0)

        for p in pointclouds:
            renderer.AddActor(p.vtkActor)
        renderer.ResetCamera()

        # Render Window
        renderWindow = vtk.vtkRenderWindow()
        renderWindow.AddRenderer(renderer)

        # Interactor
        renderWindowInteractor = vtk.vtkRenderWindowInteractor()
        renderWindowInteractor.SetRenderWindow(renderWindow)

        # Begin Interaction
        renderWindow.Render()
        renderWindow.SetWindowName("XYZ Data Viewer")

        renderWindowInteractor.Start() 
Example #9
Source File: Visualization.py    From PyNite with MIT License 6 votes vote down vote up
def __init__(self, node, scale_factor, text_height=5, combo_name='Combo 1'):
  
    # Calculate the node's deformed position
    newX = node.X + scale_factor*(node.DX[combo_name])
    newY = node.Y + scale_factor*(node.DY[combo_name])
    newZ = node.Z + scale_factor*(node.DZ[combo_name])

    # Generate a sphere for the node
    sphere = vtk.vtkSphereSource()
    sphere.SetCenter(newX, newY, newZ)
    sphere.SetRadius(0.6*text_height)

    # Set up a mapper for the node
    mapper = vtk.vtkPolyDataMapper()
    mapper.SetInputConnection(sphere.GetOutputPort())

    # Set up an actor for the node
    self.actor = vtk.vtkActor()
    self.actor.GetProperty().SetColor(255, 255, 0) # Yellow
    self.actor.SetMapper(mapper)
        
    # Create the text for the node label
    label = vtk.vtkVectorText()
    label.SetText(node.Name)

    # Set up a mapper for the node label
    lblMapper = vtk.vtkPolyDataMapper()
    lblMapper.SetInputConnection(label.GetOutputPort())

    # Set up an actor for the node label
    self.lblActor = vtk.vtkFollower()
    self.lblActor.SetMapper(lblMapper)
    self.lblActor.SetScale(text_height, text_height, text_height)
    self.lblActor.SetPosition(newX + 0.6*text_height, newY + 0.6*text_height, newZ)
    self.lblActor.GetProperty().SetColor(255, 255, 0) # Yellow

#%%
# Converts a member object into a member in its deformed position for the viewer 
Example #10
Source File: serial_link.py    From robopy with MIT License 6 votes vote down vote up
def __setup_pipeline_objs(self):
        """
        Internal function to initialise vtk objects.
        :return: reader_list, actor_list, mapper_list
        """
        reader_list = [0] * len(self.stl_files)
        actor_list = [0] * len(self.stl_files)
        mapper_list = [0] * len(self.stl_files)
        for i in range(len(self.stl_files)):
            reader_list[i] = vtk.vtkSTLReader()
            loc = pkg_resources.resource_filename("robopy", '/'.join(('media', self.name, self.stl_files[i])))
            reader_list[i].SetFileName(loc)
            mapper_list[i] = vtk.vtkPolyDataMapper()
            mapper_list[i].SetInputConnection(reader_list[i].GetOutputPort())
            actor_list[i] = vtk.vtkActor()
            actor_list[i].SetMapper(mapper_list[i])
            actor_list[i].GetProperty().SetColor(self.colors[i])  # (R,G,B)

        return reader_list, actor_list, mapper_list 
Example #11
Source File: wvtk.py    From pyCGNS with GNU Lesser General Public License v2.1 6 votes vote down vote up
def s_highlightPoint(self, grid, index):
        if self.actorpt is not None:
            self._vtkren.RemoveActor(self.actorpt)
        if grid is None:
            return
        (i, j, k) = index
        filter = vtk.vtkStructuredGridGeometryFilter()
        if VTK_VERSION_MAJOR < 8:
            raise RuntimeError("VTK version is too old, please upgrade")
        filter.SetInputData(grid)
        filter.SetExtent(i - 1, i - 1, j - 1, j - 1, k - 1, k - 1)
        mapper = vtk.vtkPolyDataMapper()
        mapper.SetInputConnection(filter.GetOutputPort())
        self.actorpt = vtk.vtkActor()
        self.actorpt.SetMapper(mapper)
        self.actorpt.GetProperty().SetColor(0, 1, 0)
        self.actorpt.GetProperty().SetPointSize(6)
        self.actorpt.PickableOff()
        self.actorpt.DragableOff()
        self._vtkren.AddActor(self.actorpt)
        self._iren.Render() 
Example #12
Source File: vis.py    From demon with GNU General Public License v3.0 6 votes vote down vote up
def create_pointcloud_actor(points, colors=None):
    """Creates a vtkActor with the point cloud from numpy arrays
    
    points: numpy.ndarray
        pointcloud with shape (n,3)
    
    colors: numpy.ndarray
        uint8 array with colors for each point. shape is (n,3)

    Returns vtkActor object
    """
    import vtk
    vpoly = create_pointcloud_polydata(points, colors)
    mapper = vtk.vtkPolyDataMapper()
    mapper.SetInputData(vpoly)

    actor = vtk.vtkActor()
    actor.SetMapper(mapper)
    actor.GetProperty().SetPointSize(3)

    return actor 
Example #13
Source File: vis.py    From DeepV2D with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def create_pointcloud_actor(points, colors=None):
    """Creates a vtkActor with the point cloud from numpy arrays
    
    points: numpy.ndarray
        pointcloud with shape (n,3)
    
    colors: numpy.ndarray
        uint8 array with colors for each point. shape is (n,3)

    Returns vtkActor object
    """
    vpoly = create_pointcloud_polydata(points, colors)
    mapper = vtk.vtkPolyDataMapper()
    mapper.SetInputData(vpoly)

    actor = vtk.vtkActor()
    actor.SetMapper(mapper)
    actor.GetProperty().SetPointSize(5)

    return actor 
Example #14
Source File: wvtk.py    From pyCGNS with GNU Lesser General Public License v2.1 6 votes vote down vote up
def uns_highlightPoint(self, grid, cellid):
        if self.actorpt is not None:
            self._vtkren.RemoveActor(self.actorpt)
        if grid is None:
            return
        filter = vtk.vtkUnstructuredGridGeometryFilter()
        if VTK_VERSION_MAJOR < 6:
            filter.SetInput(grid)
        else:
            filter.SetInputData(grid)
        filter.CellClippingOn()
        filter.SetCellMinimum(cellid)
        filter.SetCellMaximum(cellid)
        mapper = vtk.vtkDataSetMapper()
        mapper.SetInputConnection(filter.GetOutputPort())
        self.actorpt = vtk.vtkActor()
        self.actorpt.SetMapper(mapper)
        self.actorpt.GetProperty().SetColor(0, 1, 0)
        self.actorpt.GetProperty().SetLineWidth(2)
        self.actorpt.GetProperty().SetRepresentationToWireframe()
        self.actorpt.PickableOff()
        self.actorpt.DragableOff()
        self._vtkren.AddActor(self.actorpt)
        self._iren.Render() 
Example #15
Source File: pointobject.py    From Det3D with Apache License 2.0 6 votes vote down vote up
def CreatePolygon(self, points):
        "Create a 3D plane from Nx3 numpy array"
        self.verts = vtk.vtkPoints()
        polygon = vtk.vtkPolygon()

        polygon_pid = polygon.GetPointIds()
        for i, p in enumerate(points):
            self.verts.InsertNextPoint(*tuple(p))
            polygon_pid.InsertNextId(i)

        polygon_cell = vtk.vtkCellArray()
        polygon_cell.InsertNextCell(polygon)

        self.pd = vtk.vtkPolyData()
        self.pd.SetPoints(self.verts)
        self.pd.SetPolys(polygon_cell)

        self.mapper = vtk.vtkPolyDataMapper()
        self.mapper.SetInputData(self.pd)
        self.actor = vtk.vtkActor()
        self.actor.SetMapper(self.mapper) 
Example #16
Source File: pointobject.py    From Det3D with Apache License 2.0 6 votes vote down vote up
def CreatePolyLine(self, points):
        "Create a 3D line from Nx3 numpy array"
        self.verts = vtk.vtkPoints()
        polyline = vtk.vtkPolyLine()

        polyline_pid = polyline.GetPointIds()
        for i, p in enumerate(points):
            self.verts.InsertNextPoint(*tuple(p))
            polyline_pid.InsertNextId(i)

        polyline_cell = vtk.vtkCellArray()
        polyline_cell.InsertNextCell(polyline)

        self.pd = vtk.vtkPolyData()
        self.pd.SetPoints(self.verts)
        self.pd.SetLines(polyline_cell)

        self.mapper = vtk.vtkPolyDataMapper()
        self.mapper.SetInputData(self.pd)
        self.actor = vtk.vtkActor()
        self.actor.SetMapper(self.mapper)
        self.actor.GetProperty().SetLineStipplePattern(0xF0F0)
        self.actor.GetProperty().SetLineStippleRepeatFactor(1)
        self.actor.GetProperty().SetLineWidth(1.5) 
Example #17
Source File: pointobject.py    From Det3D with Apache License 2.0 6 votes vote down vote up
def SetupPipelineHedgeHog(self, scale=15.0):
        """Set up the VTK pipeline for visualizing points with surface normals"
        
        The surface normals are visualized as lines with the given scale"""

        hh = vtk.vtkHedgeHog()
        hh.SetInputData(self.pd)
        hh.SetVectorModeToUseNormal()
        hh.SetScaleFactor(scale)
        hh.Update()

        # Set up mappers and actors
        self.mapper = vtk.vtkPolyDataMapper()
        self.mapper.SetInputConnection(hh.GetOutputPort())
        self.mapper.Update()
        self.actor = vtk.vtkActor()
        self.actor.SetMapper(self.mapper)
        self.actor.GetProperty().SetColor(1, 0, 0)  # Default color 
Example #18
Source File: util.py    From sanet_relocal_demo with GNU General Public License v3.0 6 votes vote down vote up
def create_pointcloud_actor(points, colors=None, pt_size=3):
    """Creates a vtkActor with the point cloud from numpy arrays

    points: numpy.ndarray
        pointcloud with shape (n,3)

    colors: numpy.ndarray
        uint8 array with colors for each point. shape is (n,3)

    Returns vtkActor object
    """
    import vtk
    vpoly = create_pointcloud_polydata(points, colors)
    mapper = vtk.vtkPolyDataMapper()
    mapper.SetInputData(vpoly)

    actor = vtk.vtkActor()
    actor.SetMapper(mapper)
    actor.GetProperty().SetPointSize(pt_size)

    return actor 
Example #19
Source File: util.py    From sanet_relocal_demo with GNU General Public License v3.0 6 votes vote down vote up
def create_camera_actor(R, t, color=(1.0, 0.0, 0.0), camera_obj_scale=0.25):
    """Creates a vtkActor object with a camera mesh"""
    import vtk
    vpoly = create_camera_polydata(R, t, only_polys=False, scale=camera_obj_scale)
    mapper = vtk.vtkPolyDataMapper()
    mapper.SetInputData(vpoly)

    color = (int(255.0*color[0]), int(255.0*color[1]), int(255.0*color[2]))

    actor = vtk.vtkActor()
    actor.SetMapper(mapper)
    actor.GetProperty().LightingOff()
    actor.GetProperty().SetLineWidth(2)
    actor.GetProperty().SetColor(color[0], color[1], color[2])

    return actor 
Example #20
Source File: tessagon_vtk_demo.py    From tessagon with Apache License 2.0 6 votes vote down vote up
def tessellate(self, f, tessagon_class, **kwargs):
        extra_args = {'function': f,
                      'adaptor_class': VtkAdaptor}
        tessagon = tessagon_class(**{**kwargs, **extra_args})

        poly_data = tessagon.create_mesh()
        mapper = vtk.vtkPolyDataMapper()
        mapper.SetInputData(poly_data)
        mapper.SetLookupTable(self.lut)
        mapper.SetScalarRange(poly_data.GetScalarRange())

        actor = vtk.vtkActor()
        actor.SetMapper(mapper)
        actor.GetProperty().SetColor(tomato)
        actor.GetProperty().SetEdgeColor(0.0, 0.0, 0.0)
        actor.GetProperty().EdgeVisibilityOn()
        actor.SetPosition(kwargs['position'])

        self.ren.AddActor(actor) 
Example #21
Source File: vtkpointcloud.py    From semi-auto-anno with GNU General Public License v3.0 6 votes vote down vote up
def __init__(self, zMin=-10.0, zMax=10.0, maxNumPoints=1e6):
        """
        Initialize class
        :param zMin: minimum depth
        :param zMax: maximum depth
        :param maxNumPoints: maximum number of points
        :return: None
        """
        self.maxNumPoints = int(maxNumPoints)
        self.vtkPolyData = vtk.vtkPolyData()
        self.clearPoints()
        mapper = vtk.vtkPolyDataMapper()
        mapper.SetInputData(self.vtkPolyData)
        mapper.SetColorModeToDefault()
        mapper.SetScalarRange(zMin, zMax)
        mapper.SetScalarVisibility(1)
        self.vtkActor = vtk.vtkActor()
        self.vtkActor.SetMapper(mapper)
        self.vtkActor.GetProperty().SetPointSize(3.0)
        self.rng = numpy.random.RandomState(23455) 
Example #22
Source File: test_vtk.py    From panel with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def make_render_window():

    #cone actor
    cone = vtk.vtkConeSource()
    coneMapper = vtk.vtkPolyDataMapper()
    coneMapper.SetInputConnection(cone.GetOutputPort())
    coneActor = vtk.vtkActor()
    coneActor.SetMapper(coneMapper)

    #text actor following camera
    text = vtk.vtkVectorText()
    text.SetText("Origin")
    textMapper = vtk.vtkPolyDataMapper()
    textMapper.SetInputConnection(text.GetOutputPort())
    textActor = vtk.vtkFollower()
    textActor.SetMapper(textMapper)

    ren = vtk.vtkRenderer()
    ren.AddActor(coneActor)
    ren.AddActor(textActor)
    textActor.SetCamera(ren.GetActiveCamera())

    renWin = vtk.vtkRenderWindow()
    renWin.AddRenderer(ren)
    return renWin 
Example #23
Source File: viz.py    From 3d-semantic-segmentation with MIT License 6 votes vote down vote up
def getActorCircle(radius_inner=100, radius_outer=99, color=(1,0,0)):
    """"""
    # create source
    source = vtk.vtkDiskSource()
    source.SetInnerRadius(radius_inner)
    source.SetOuterRadius(radius_outer)
    source.SetRadialResolution(100)
    source.SetCircumferentialResolution(100)

    # Transformer
    transform = vtk.vtkTransform()
    transform.RotateWXYZ(90, 1, 0, 0)
    transformFilter = vtk.vtkTransformPolyDataFilter()
    transformFilter.SetTransform(transform)
    transformFilter.SetInputConnection(source.GetOutputPort())
    transformFilter.Update()

    # mapper
    mapper = vtk.vtkPolyDataMapper()
    mapper.SetInputConnection(transformFilter.GetOutputPort())

    # actor
    actor = vtk.vtkActor()
    actor.GetProperty().SetColor(color)
    actor.SetMapper(mapper)

    return actor 
Example #24
Source File: pc_viz.py    From deep_gcns_torch with MIT License 5 votes vote down vote up
def __init__(self, point_size=18, maxNumPoints=1e8):
        self.maxNumPoints = maxNumPoints
        self.vtkPolyData = vtk.vtkPolyData()
        self.clear_points()

        self.colors = vtk.vtkUnsignedCharArray()
        self.colors.SetNumberOfComponents(3)
        self.colors.SetName("Colors")

        mapper = vtk.vtkPolyDataMapper()
        mapper.SetInputData(self.vtkPolyData)

        self.vtkActor = vtk.vtkActor()
        self.vtkActor.SetMapper(mapper)
        self.vtkActor.GetProperty().SetPointSize(point_size) 
Example #25
Source File: viz.py    From deep_gcns with MIT License 5 votes vote down vote up
def __init__(self, point_size=18, maxNumPoints=1e8):
        self.maxNumPoints = maxNumPoints
        self.vtkPolyData = vtk.vtkPolyData()
        self.clear_points()

        self.colors = vtk.vtkUnsignedCharArray()
        self.colors.SetNumberOfComponents(3)
        self.colors.SetName("Colors")

        mapper = vtk.vtkPolyDataMapper()
        mapper.SetInputData(self.vtkPolyData)

        self.vtkActor = vtk.vtkActor()
        self.vtkActor.SetMapper(mapper)
        self.vtkActor.GetProperty().SetPointSize(point_size) 
Example #26
Source File: viz.py    From deep_gcns with MIT License 5 votes vote down vote up
def keyPressEvent(self, obj, event):
        key = self.parent.GetKeySym()
        if key == '+':
            point_size = self.pointcloud.vtkActor.GetProperty().GetPointSize()
            self.pointcloud.vtkActor.GetProperty().SetPointSize(point_size + 1)
            print(str(point_size) + " " + key)
        return 
Example #27
Source File: vtkVisualization.py    From MOTSFusion with MIT License 5 votes vote down vote up
def __init__(self, mapper: vtk.vtkMapper):
        self._actor = vtk.vtkActor()
        self._actor.SetMapper(mapper) 
Example #28
Source File: pc_viz.py    From deep_gcns_torch with MIT License 5 votes vote down vote up
def getActorCircle(radius_inner=100, radius_outer=99, color=(1, 0, 0)):
    """"""
    # create source
    source = vtk.vtkDiskSource()
    source.SetInnerRadius(radius_inner)
    source.SetOuterRadius(radius_outer)
    source.SetRadialResolution(100)
    source.SetCircumferentialResolution(100)

    # Transformer
    transform = vtk.vtkTransform()
    transform.RotateWXYZ(90, 1, 0, 0)
    transformFilter = vtk.vtkTransformPolyDataFilter()
    transformFilter.SetTransform(transform)
    transformFilter.SetInputConnection(source.GetOutputPort())
    transformFilter.Update()

    # mapper
    mapper = vtk.vtkPolyDataMapper()
    mapper.SetInputConnection(transformFilter.GetOutputPort())

    # actor
    actor = vtk.vtkActor()
    actor.GetProperty().SetColor(color)
    actor.SetMapper(mapper)

    return actor 
Example #29
Source File: test_vtk.py    From panel with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def pyvista_render_window():
    """
    Allow to download and create a more complex example easily
    """
    from pyvista import examples
    sphere = pv.Sphere() #test actor
    globe = examples.load_globe() #test texture
    head = examples.download_head() #test volume
    uniform = examples.load_uniform() #test structured grid

    scalars=sphere.points[:, 2]
    sphere._add_point_array(scalars, 'test', set_active=True) #allow to test scalars

    uniform.set_active_scalars("Spatial Cell Data")

    #test datasetmapper
    threshed = uniform.threshold_percent([0.15, 0.50], invert=True)
    bodies = threshed.split_bodies()
    mapper = vtk.vtkCompositePolyDataMapper2()
    mapper.SetInputDataObject(0, bodies)
    multiblock = vtk.vtkActor()
    multiblock.SetMapper(mapper)

    pl = pv.Plotter()
    pl.add_mesh(globe)
    pl.add_mesh(sphere)
    pl.add_mesh(uniform)
    pl.add_actor(multiblock)
    pl.add_volume(head)
    return pl.ren_win 
Example #30
Source File: utility.py    From ILCC with BSD 2-Clause "Simplified" License 5 votes vote down vote up
def vis_pcd_color_arr(array_data, color_arr=[46, 204, 113]):
    all_rows = array_data.shape[0]
    Colors = vtk.vtkUnsignedCharArray()
    Colors.SetNumberOfComponents(3)
    Colors.SetName("Colors")

    Points = vtk.vtkPoints()
    Vertices = vtk.vtkCellArray()

    for k in xrange(all_rows):
        point = array_data[k, :]
        id = Points.InsertNextPoint(point[0], point[1], point[2])
        Vertices.InsertNextCell(1)
        Vertices.InsertCellPoint(id)
        if vtk.VTK_MAJOR_VERSION >= 7:
            Colors.InsertNextTuple(color_arr)
        else:
            Colors.InsertNextTupleValue(color_arr)
    polydata = vtk.vtkPolyData()
    polydata.SetPoints(Points)
    polydata.SetVerts(Vertices)
    polydata.GetPointData().SetScalars(Colors)
    polydata.Modified()

    mapper = vtk.vtkPolyDataMapper()
    if vtk.VTK_MAJOR_VERSION <= 5:
        mapper.SetInput(polydata)
    else:
        mapper.SetInputData(polydata)
    mapper.SetColorModeToDefault()
    actor = vtk.vtkActor()
    actor.SetMapper(mapper)
    actor.GetProperty().SetPointSize(10)
    return actor


# visualize with actor: