Python vtk.vtkAppendPolyData() Examples

The following are 3 code examples of vtk.vtkAppendPolyData(). 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: filters.py    From pyvista with MIT License 5 votes vote down vote up
def boolean_add(poly_data, mesh, inplace=False):
        """Add a mesh to the current mesh.

        Does not attempt to "join" the meshes.

        Parameters
        ----------
        mesh : pyvista.PolyData
            The mesh to add.

        inplace : bool, optional
            Updates mesh in-place while returning nothing.

        Return
        ------
        joinedmesh : pyvista.PolyData
            Initial mesh and the new mesh when inplace=False.

        """
        if not isinstance(mesh, pyvista.PolyData):
            raise TypeError("Input mesh must be PolyData.")

        vtkappend = vtk.vtkAppendPolyData()
        vtkappend.AddInputData(poly_data)
        vtkappend.AddInputData(mesh)
        vtkappend.Update()

        mesh = _get_output(vtkappend)
        if inplace:
            poly_data.overwrite(mesh)
        else:
            return mesh 
Example #3
Source File: test_wrapping.py    From BrainSpace with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
def test_cell_types():
    ss = vtk.vtkSphereSource()
    ss.Update()
    st = wrap_vtk(ss.GetOutput())
    sl = mc.to_lines(st)
    sv = mc.to_vertex(st)

    assert checks.get_cell_types(st) == np.array([VTK_TRIANGLE])
    assert checks.get_cell_types(st.VTKObject) == np.array([VTK_TRIANGLE])
    assert checks.get_cell_types(sl) == np.array([VTK_LINE])
    assert checks.get_cell_types(sv) == np.array([VTK_VERTEX])

    assert checks.get_number_of_cell_types(st) == 1
    assert checks.get_number_of_cell_types(st.VTKObject) == 1
    assert checks.get_number_of_cell_types(sl) == 1
    assert checks.get_number_of_cell_types(sv) == 1

    assert checks.has_unique_cell_type(st)
    assert checks.has_unique_cell_type(st.VTKObject)
    assert checks.has_unique_cell_type(sl)
    assert checks.has_unique_cell_type(sv)

    assert checks.has_only_triangle(st)
    assert checks.has_only_triangle(st.VTKObject)
    assert checks.has_only_line(sl)
    assert checks.has_only_vertex(sv)

    ss2 = vtk.vtkSphereSource()
    ss2.SetRadius(3)
    ss2.Update()
    s2 = ss2.GetOutput()

    app = vtk.vtkAppendPolyData()
    app.AddInputData(sl.VTKObject)
    app.AddInputData(s2)
    app.Update()
    spl = wrap_vtk(app.GetOutput())

    cell_types = np.sort([VTK_TRIANGLE, VTK_LINE])
    assert np.all(checks.get_cell_types(spl) == cell_types)
    assert checks.get_number_of_cell_types(spl) == cell_types.size
    assert checks.has_unique_cell_type(spl) is False
    assert checks.has_only_triangle(spl) is False
    assert checks.has_only_line(spl) is False
    assert checks.has_only_vertex(spl) is False