Python vtk.VTK_MAJOR_VERSION Examples

The following are 14 code examples of vtk.VTK_MAJOR_VERSION(). 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: mesh.py    From OpenWARP with Apache License 2.0 6 votes vote down vote up
def _write_vtp(self):
        '''Internal function to write VTK PolyData mesh files
        '''
        if self.VTK_installed is False:

            raise VTK_Exception('VTK must be installed write VTP/VTK meshes, please select a different output mesh_format')

        writer = vtk.vtkXMLPolyDataWriter()
        writer.SetFileName(self.files['vtp'])
        if vtk.VTK_MAJOR_VERSION >= 6:
            writer.SetInputData(self.vtp_mesh)
        else:
            writer.SetInput(self.vtp_mesh)
        writer.SetDataModeToAscii()
        writer.Write()

        print 'Wrote VTK PolyData mesh to: ' + str(self.files['vtp']) 
Example #2
Source File: mesh.py    From OpenWARP with Apache License 2.0 6 votes vote down vote up
def _write_vtp(self):
        '''Internal function to write VTK PolyData mesh files
        '''
        if self.VTK_installed is False:

            raise VTK_Exception('VTK must be installed write VTP/VTK meshes, please select a different output mesh_format')

        writer = vtk.vtkXMLPolyDataWriter()
        writer.SetFileName(self.files['vtp'])
        if vtk.VTK_MAJOR_VERSION >= 6:
            writer.SetInputData(self.vtp_mesh)
        else:
            writer.SetInput(self.vtp_mesh)
        writer.SetDataModeToAscii()
        writer.Write()

        print 'Wrote VTK PolyData mesh to: ' + str(self.files['vtp']) 
Example #3
Source File: mesh.py    From OpenWARP with Apache License 2.0 6 votes vote down vote up
def _write_vtp(self):
        '''Internal function to write VTK PolyData mesh files
        '''
        if self.VTK_installed is False:

            raise VTK_Exception('VTK must be installed write VTP/VTK meshes, please select a different output mesh_format')

        writer = vtk.vtkXMLPolyDataWriter()
        writer.SetFileName(self.files['vtp'])
        if vtk.VTK_MAJOR_VERSION >= 6:
            writer.SetInputData(self.vtp_mesh)
        else:
            writer.SetInput(self.vtp_mesh)
        writer.SetDataModeToAscii()
        writer.Write()

        print 'Wrote VTK PolyData mesh to: ' + str(self.files['vtp']) 
Example #4
Source File: utility.py    From ILCC with BSD 2-Clause "Simplified" License 5 votes vote down vote up
def vis_3D_points(full_lidar_arr, color_style="intens_rg"):
    all_rows = full_lidar_arr.shape[0]
    Colors = vtk.vtkUnsignedCharArray()
    Colors.SetNumberOfComponents(3)
    Colors.SetName("Colors")
    Points = vtk.vtkPoints()
    Vertices = vtk.vtkCellArray()

    tuple_ls = gen_color_tup_for_vis(color_style, xyzi_arr=full_lidar_arr)

    for k in xrange(all_rows):
        point = full_lidar_arr[k, :3]
        id = Points.InsertNextPoint(point[0], point[1], point[2])
        Vertices.InsertNextCell(1)
        Vertices.InsertCellPoint(id)

        rgb_tuple = tuple_ls[k]
        if vtk.VTK_MAJOR_VERSION >= 7:
            Colors.InsertNextTuple(rgb_tuple)
        else:
            Colors.InsertNextTupleValue(rgb_tuple)
    polydata = vtk.vtkPolyData()
    polydata.SetPoints(Points)
    polydata.SetVerts(Vertices)
    polydata.GetPointData().SetScalars(Colors)
    polydata.Modified()

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

    return actor


# visualize 3D points with specified color array 
Example #5
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: 
Example #6
Source File: tract_io.py    From geomloss with MIT License 5 votes vote down vote up
def save_vtk(filename, tracts, lines_indices=None, scalars = None):

	lengths = [len(p) for p in tracts]
	line_starts = ns.numpy.r_[0, ns.numpy.cumsum(lengths)]
	if lines_indices is None:
		lines_indices = [ns.numpy.arange(length) + line_start for length, line_start in izip(lengths, line_starts)]

	ids = ns.numpy.hstack([ns.numpy.r_[c[0], c[1]] for c in izip(lengths, lines_indices)])
	vtk_ids = ns.numpy_to_vtkIdTypeArray(ids, deep=True)

	cell_array = vtk.vtkCellArray()
	cell_array.SetCells(len(tracts), vtk_ids)
	points = ns.numpy.vstack(tracts).astype(ns.get_vtk_to_numpy_typemap()[vtk.VTK_DOUBLE])
	points_array = ns.numpy_to_vtk(points, deep=True)

	poly_data = vtk.vtkPolyData()
	vtk_points = vtk.vtkPoints()
	vtk_points.SetData(points_array)
	poly_data.SetPoints(vtk_points)
	poly_data.SetLines(cell_array)
	poly_data.BuildCells()

	if filename.endswith('.xml') or filename.endswith('.vtp'):
		writer = vtk.vtkXMLPolyDataWriter()
		writer.SetDataModeToBinary()
	else:
		writer = vtk.vtkPolyDataWriter()
		writer.SetFileTypeToBinary()


	writer.SetFileName(filename)
	if hasattr(vtk, 'VTK_MAJOR_VERSION') and vtk.VTK_MAJOR_VERSION > 5:
		writer.SetInputData(poly_data)
	else:
		writer.SetInput(poly_data)
	writer.Write() 
Example #7
Source File: tract_io.py    From geomloss with MIT License 5 votes vote down vote up
def save_vtk_labels(filename, tracts, scalars, lines_indices=None):

	lengths = [len(p) for p in tracts]
	line_starts = ns.numpy.r_[0, ns.numpy.cumsum(lengths)]
	if lines_indices is None:
		lines_indices = [ns.numpy.arange(length) + line_start for length, line_start in izip(lengths, line_starts)]

	ids = ns.numpy.hstack([ns.numpy.r_[c[0], c[1]] for c in izip(lengths, lines_indices)])
	vtk_ids = ns.numpy_to_vtkIdTypeArray(ids, deep=True)

	cell_array = vtk.vtkCellArray()
	cell_array.SetCells(len(tracts), vtk_ids)
	points = ns.numpy.vstack(tracts).astype(ns.get_vtk_to_numpy_typemap()[vtk.VTK_DOUBLE])
	points_array = ns.numpy_to_vtk(points, deep=True)

	poly_data = vtk.vtkPolyData()
	vtk_points = vtk.vtkPoints()
	vtk_points.SetData(points_array)
	poly_data.SetPoints(vtk_points)
	poly_data.SetLines(cell_array)
	poly_data.GetPointData().SetScalars(ns.numpy_to_vtk(scalars))
	poly_data.BuildCells()
#    poly_data.SetScalars(scalars)

	if filename.endswith('.xml') or filename.endswith('.vtp'):
		writer = vtk.vtkXMLPolyDataWriter()
		writer.SetDataModeToBinary()
	else:
		writer = vtk.vtkPolyDataWriter()
		writer.SetFileTypeToBinary()


	writer.SetFileName(filename)
	if hasattr(vtk, 'VTK_MAJOR_VERSION') and vtk.VTK_MAJOR_VERSION > 5:
		writer.SetInputData(poly_data)
	else:
		writer.SetInput(poly_data)
	writer.Write() 
Example #8
Source File: mesh.py    From OpenWARP with Apache License 2.0 5 votes vote down vote up
def calculate_center_of_gravity_vtk(self, ):
        '''Function to calculate the center of gravity

        .. Note::
            The VTK Pytnon bindings must be installed to use this function

        Examples:
            This example assumes that a mesh has been read by bemio and mesh
            data is contained in a `PanelMesh` object called `mesh`

            >>> mesh.calculate_center_of_gravity_vtk()
        '''
        if self.VTK_installed is False:
            raise VTK_Exception('VTK must be installed to access the calculate_center_of_gravity_vtk function')

        com = vtk.vtkCenterOfMass()
        if vtk.VTK_MAJOR_VERSION >= 6:
            com.SetInputData(self.vtp_mesh)
        else:
            com.SetInput(self.vtp_mesh)
        com.Update()
        self.center_of_gravity = com.GetCenter()

        print 'Calculated center of gravity assuming uniform material density'

    # def cut(self,plane=2,value=0.0,direction=1): 
Example #9
Source File: mesh.py    From OpenWARP with Apache License 2.0 5 votes vote down vote up
def calculate_center_of_gravity_vtk(self, ):
        '''Function to calculate the center of gravity

        .. Note::
            The VTK Pytnon bindings must be installed to use this function

        Examples:
            This example assumes that a mesh has been read by bemio and mesh
            data is contained in a `PanelMesh` object called `mesh`

            >>> mesh.calculate_center_of_gravity_vtk()
        '''
        if self.VTK_installed is False:
            raise VTK_Exception('VTK must be installed to access the calculate_center_of_gravity_vtk function')

        com = vtk.vtkCenterOfMass()
        if vtk.VTK_MAJOR_VERSION >= 6:
            com.SetInputData(self.vtp_mesh)
        else:
            com.SetInput(self.vtp_mesh)
        com.Update()
        self.center_of_gravity = com.GetCenter()

        print 'Calculated center of gravity assuming uniform material density'

    # def cut(self,plane=2,value=0.0,direction=1): 
Example #10
Source File: mesh.py    From OpenWARP with Apache License 2.0 5 votes vote down vote up
def calculate_center_of_gravity_vtk(self, ):
        '''Function to calculate the center of gravity

        .. Note::
            The VTK Pytnon bindings must be installed to use this function

        Examples:
            This example assumes that a mesh has been read by bemio and mesh
            data is contained in a `PanelMesh` object called `mesh`

            >>> mesh.calculate_center_of_gravity_vtk()
        '''
        if self.VTK_installed is False:
            raise VTK_Exception('VTK must be installed to access the calculate_center_of_gravity_vtk function')

        com = vtk.vtkCenterOfMass()
        if vtk.VTK_MAJOR_VERSION >= 6:
            com.SetInputData(self.vtp_mesh)
        else:
            com.SetInput(self.vtp_mesh)
        com.Update()
        self.center_of_gravity = com.GetCenter()

        print 'Calculated center of gravity assuming uniform material density'

    # def cut(self,plane=2,value=0.0,direction=1): 
Example #11
Source File: mesh.py    From OpenWARP with Apache License 2.0 5 votes vote down vote up
def calculate_center_of_gravity_vtk(self, ):
        '''Function to calculate the center of gravity

        .. Note::
            The VTK Pytnon bindings must be installed to use this function

        Examples:
            This example assumes that a mesh has been read by bemio and mesh
            data is contained in a `PanelMesh` object called `mesh`

            >>> mesh.calculate_center_of_gravity_vtk()
        '''
        if self.VTK_installed is False:
            raise VTK_Exception('VTK must be installed to access the calculate_center_of_gravity_vtk function')

        com = vtk.vtkCenterOfMass()
        if vtk.VTK_MAJOR_VERSION >= 6:
            com.SetInputData(self.vtp_mesh)
        else:
            com.SetInput(self.vtp_mesh)
        com.Update()
        self.center_of_gravity = com.GetCenter()

        print 'Calculated center of gravity assuming uniform material density'

    # def cut(self,plane=2,value=0.0,direction=1): 
Example #12
Source File: show_lidar_vtk.py    From Det3D with Apache License 2.0 5 votes vote down vote up
def draw_box(x):
    cube = vtk.vtkPolyData()
    points = vtk.vtkPoints()
    polys = vtk.vtkCellArray()
    scalars = vtk.vtkFloatArray()

    for i in range(8):
        points.InsertPoint(i, x[i])
    for i in range(6):
        polys.InsertNextCell(mkVtkIdList(pts[i]))
    for i in range(8):
        scalars.InsertTuple1(i, i)

    cube.SetPoints(points)
    del points
    cube.SetPolys(polys)
    del polys
    cube.GetPointData().SetScalars(scalars)
    del scalars

    cubeMapper = vtk.vtkPolyDataMapper()
    if vtk.VTK_MAJOR_VERSION <= 5:
        cubeMapper.SetInput(cube)
    else:
        cubeMapper.SetInputData(cube)
    cubeMapper.SetScalarRange(0, 7)
    # cubeMapper.SetScalarVisibility(2)
    cubeActor = vtk.vtkActor()
    cubeActor.SetMapper(cubeMapper)
    cubeActor.GetProperty().SetOpacity(0.4)
    return cubeActor 
Example #13
Source File: pcd_corners_est.py    From ILCC with BSD 2-Clause "Simplified" License 4 votes vote down vote up
def show_pcd_ndarray(array_data, color_arr=[0, 255, 0]):
        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 > 6:
                Colors.InsertNextTuple(color_arr)
            else:
                Colors.InsertNextTupleValue(color_arr)

            dis_tmp = np.sqrt((point ** 2).sum(0))
            # Colors.InsertNextTupleValue([0,255-dis_tmp/max_dist*255,0])
            # Colors.InsertNextTupleValue([255-abs(point[0]/x_max*255),255-abs(point[1]/y_max*255),255-abs(point[2]/z_max*255)])
            # Colors.InsertNextTupleValue([255-abs(point[0]/x_max*255),255,255])

        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(5)

        # Renderer
        renderer = vtk.vtkRenderer()
        renderer.AddActor(actor)
        renderer.SetBackground(.2, .3, .4)
        renderer.ResetCamera()

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

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

        # Begin Interaction
        renderWindow.Render()
        renderWindowInteractor.Start()


# determine whether a segment is the potential chessboard's point cloud 
Example #14
Source File: utility.py    From ILCC with BSD 2-Clause "Simplified" License 4 votes vote down vote up
def vis_with_renderer(renderer):
    # Renderer

    # renderer.SetBackground(.2, .3, .4)
    renderer.SetBackground(1, 1, 1)
    renderer.ResetCamera()

    transform = vtk.vtkTransform()
    transform.Translate(1.0, 0.0, 0.0)
    axes = vtk.vtkAxesActor()
    renderer.AddActor(axes)

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

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

    def get_camera_info(obj, ev):
        if renderWindowInteractor.GetKeyCode() == "s":
            w2if = vtk.vtkWindowToImageFilter()
            w2if.SetInput(renderWindow)
            w2if.Update()

            writer = vtk.vtkPNGWriter()
            writer.SetFileName("screenshot.png")
            if vtk.VTK_MAJOR_VERSION == 5:
                writer.SetInput(w2if.GetOutput())
            else:
                writer.SetInputData(w2if.GetOutput())
            writer.Write()
            print "screenshot saved"

    style = vtk.vtkInteractorStyleSwitch()
    renderWindowInteractor.SetInteractorStyle(style)
    # style.SetCurrentStyleToTrackballActor()
    style.SetCurrentStyleToTrackballCamera()

    # Begin Interaction
    renderWindowInteractor.AddObserver(vtk.vtkCommand.KeyPressEvent, get_camera_info, 1)
    renderWindow.Render()
    renderWindowInteractor.Start()