• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python vtk.vtkTriangle函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中vtk.vtkTriangle函数的典型用法代码示例。如果您正苦于以下问题:Python vtkTriangle函数的具体用法?Python vtkTriangle怎么用?Python vtkTriangle使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了vtkTriangle函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: assignElements2Dlin

def assignElements2Dlin(mesh, elements):
    
    numRows, numCols = elements.shape
    
    # TODO can we do this faster?
    for i in range(numRows):
        v0, v1, v2, v3, v4, v5 = elements[i, :]
        tri1 = vtk.vtkTriangle()
        tri1.GetPointIds().SetId(0, v0)
        tri1.GetPointIds().SetId(1, v3)
        tri1.GetPointIds().SetId(2, v4)
        tri2 = vtk.vtkTriangle()
        tri2.GetPointIds().SetId(0, v3)
        tri2.GetPointIds().SetId(1, v1)
        tri2.GetPointIds().SetId(2, v5)
        tri3 = vtk.vtkTriangle()
        tri3.GetPointIds().SetId(0, v3)
        tri3.GetPointIds().SetId(1, v5)
        tri3.GetPointIds().SetId(2, v4)
        tri4 = vtk.vtkTriangle()
        tri4.GetPointIds().SetId(0, v4)
        tri4.GetPointIds().SetId(1, v5)
        tri4.GetPointIds().SetId(2, v2)
        mesh.InsertNextCell(tri1.GetCellType(), tri1.GetPointIds())
        mesh.InsertNextCell(tri1.GetCellType(), tri2.GetPointIds())
        mesh.InsertNextCell(tri1.GetCellType(), tri3.GetPointIds())
        mesh.InsertNextCell(tri1.GetCellType(), tri4.GetPointIds())
    return mesh
开发者ID:beauof,项目名称:FSIViewer,代码行数:28,代码来源:organiseData.py


示例2: setup_topography

def setup_topography(x, y, topography, xmax=None, ymax=None, decimation=1):
    # Define points, triangles and colors
    x = x[::decimation]
    y = y[::decimation]
    lonsize = len(x)-1 if not xmax else xmax
    latsize = len(y)-1 if not ymax else ymax
    colors = vtk.vtkUnsignedCharArray()
    # colors.SetNumberOfComponents(3)
    colors.SetNumberOfComponents(1)
    points = vtk.vtkPoints()
    triangles = vtk.vtkCellArray()
    zmax = topography.max()
    zmin = topography.min()
    zrange = zmax - zmin
    xmesh, ymesh = scaled_mesh(x, y)
    count = 0
    t1 = time.time()
    topography = topography.T
    topo_new = num.zeros((len(y), len(x)))
    for iy in xrange(len(y)):
        topo_new[iy, :] = topography[iy*decimation, ::decimation]
    topography = topo_new
    for i in xrange(latsize):
        print '%i / %i' % (i+1, latsize)
        for j in xrange(lonsize-3):

            d = (ymesh[i][j], xmesh[i][j], topography[i][j])
            c = (ymesh[i][j+1], xmesh[i][j+1], topography[i][j+1])
            b = (ymesh[i+1][j+1], xmesh[i+1][j+1], topography[i+1][j+1])
            a = (ymesh[i+1][j], xmesh[i+1][j], topography[i+1][j])
            points.InsertNextPoint(*a)
            points.InsertNextPoint(*b)
            points.InsertNextPoint(*c)

            triangle = vtk.vtkTriangle()
            triangle.GetPointIds().SetId(0, count)
            triangle.GetPointIds().SetId(1, count + 1)
            triangle.GetPointIds().SetId(2, count + 2)

            triangles.InsertNextCell(triangle)

            points.InsertNextPoint(*a)
            points.InsertNextPoint(*d)
            points.InsertNextPoint(*c)

            triangle = vtk.vtkTriangle()
            triangle.GetPointIds().SetId(0, count + 3)
            triangle.GetPointIds().SetId(1, count + 4)
            triangle.GetPointIds().SetId(2, count + 5)

            count += 6

            triangles.InsertNextCell(triangle)

            # rs = [[int((zmax-topography[j][i])/zrange*255)]]*6
            rs = [[int((zmax-topography[i][j])/zrange*255)]]*6
            map(colors.InsertNextTupleValue, rs)
    print 'total time needed ', time.time()-t1
    return points, triangles, colors
开发者ID:HerrMuellerluedenscheid,项目名称:contrib-snufflings,代码行数:59,代码来源:grid_topo.py


示例3: vtkTile

    def vtkTile(tile, min_temp, max_temp):
        # calcula a intensidade da cor para representar a temperatura.
        # vermelho, com pastilha. azul, estourou
        intensity = 255 - int(((tile.last_temp - min_temp) / (max_temp - min_temp)) * 256)
        if tile.bursted:
            color = (intensity, intensity, 255)
        else:
            color = (255, intensity, intensity)

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

        Points.InsertNextPoint(*tile.edges[0])
        Points.InsertNextPoint(*tile.edges[1])
        Points.InsertNextPoint(*tile.edges[2])
        Points.InsertNextPoint(*tile.edges[3])

        Triangle1 = vtk.vtkTriangle();
        Triangle1.GetPointIds().SetId(0, 0);
        Triangle1.GetPointIds().SetId(1, 1);
        Triangle1.GetPointIds().SetId(2, 2);
        Triangles.InsertNextCell(Triangle1);

        Triangle2 = vtk.vtkTriangle();
        Triangle2.GetPointIds().SetId(0, 1);
        Triangle2.GetPointIds().SetId(1, 3);
        Triangle2.GetPointIds().SetId(2, 2);
        Triangles.InsertNextCell(Triangle2);

        Colors = vtk.vtkUnsignedCharArray();
        Colors.SetNumberOfComponents(3);
        Colors.SetName("Colors");
        Colors.InsertNextTuple3(*color);
        Colors.InsertNextTuple3(*color);

        polydata = vtk.vtkPolyData()
        polydata.SetPoints(Points)
        polydata.SetPolys(Triangles)
 
        polydata.GetCellData().SetScalars(Colors);
        polydata.Modified()
        polydata.Update()

        mapper = vtk.vtkPolyDataMapper()
        mapper.SetInput(polydata)
        
        actor = vtk.vtkActor()
        actor.SetMapper(mapper)
        actor.GetProperty().SetAmbient(1.0)
        actor.GetProperty().SetDiffuse(0.0)

        return actor
开发者ID:maxrosan,项目名称:MAC5742_EP1,代码行数:52,代码来源:v0.4.py


示例4: Gen_uGrid

def Gen_uGrid(new_pt, new_fc):
    """ Generates a vtk unstructured grid given points and triangular faces"""    
    ints = np.ones(len(new_fc), 'int')*3
    cells = np.hstack((ints.reshape(-1, 1), np.vstack(new_fc)))
              
    # Generate vtk mesh
    
    # Convert points to vtkfloat object
    points = np.vstack(new_pt)
    vtkArray = VN.numpy_to_vtk(np.ascontiguousarray(points), deep=True)#, deep=True) 
    points = vtk.vtkPoints()
    points.SetData(vtkArray) 
                
    # Convert to vtk arrays
    tritype = vtk.vtkTriangle().GetCellType()*np.ones(len(new_fc), 'int')
    cell_type = np.ascontiguousarray(tritype).astype('uint8')
    cell_type = VN.numpy_to_vtk(cell_type, deep=True)
    
    offset = np.cumsum(np.hstack(ints + 1))
    offset = np.ascontiguousarray(np.delete(np.insert(offset, 0, 0), -1)).astype('int64')  # shift
    offset = VN.numpy_to_vtkIdTypeArray(offset, deep=True)
    
    cells = np.ascontiguousarray(np.hstack(cells).astype('int64'))
    vtkcells = vtk.vtkCellArray()
    vtkcells.SetCells(cells.shape[0], VN.numpy_to_vtkIdTypeArray(cells, deep=True))
    
    
    # Create unstructured grid
    uGrid = vtk.vtkUnstructuredGrid()
    uGrid.SetPoints(points)
    uGrid.SetCells(cell_type, offset, vtkcells)
    
    return uGrid
开发者ID:akaszynski,项目名称:PyACVD,代码行数:33,代码来源:Clustering.py


示例5: _create_cart3d_group

    def _create_cart3d_group(self, name, model, element_id):
        points = vtk.vtkPoints()
        points.SetNumberOfPoints(self.nNodes)
        nelements = len(element_id)
        self.grid.Allocate(nelements, 1000)

        nodes = self.model.get_nodes_associated_with_elements(element_id)
        nodes.sort()

        nid = 0
        all_nodes = self.nodes
        for i in all_nodes:
            #if nid in nodes:
            points.InsertPoint(nid, all_nodes[i, :])
            nid += 1

        from vtk import vtkTriangle
        for eid in element_id:
            elem = vtkTriangle()
            node_ids = elements[eid, :]
            elem_nodes = searchsorted(nodes, node_ids)
            elem.GetPointIds().SetId(0, elem_nodes[0])
            elem.GetPointIds().SetId(1, elem_nodes[1])
            elem.GetPointIds().SetId(2, elem_nodes[2])
            self.grid.InsertNextCell(5, elem.GetPointIds())

        self.grid[name].SetPoints(points)
        self.grid[name].Modified()
        self.grid[name].Update()
开发者ID:ClaesFredo,项目名称:pyNastran,代码行数:29,代码来源:groups.py


示例6: CreatePolyData

def CreatePolyData( pts, faces ):
    """
    Creates vtkPolyData from vertices and faces
    
    pts numpy.array: Nx3 array of vertices
    faces numpy.array: Mx3 array of faces

    Return vtkPolyData
    """
    (nv,mv) = pts.shape
    (nf,mf) = faces.shape
    cells = vtk.vtkCellArray()
    for j in range(nf):
        cell = vtk.vtkTriangle()
        cell.GetPointIds().SetNumberOfIds(3)
        cell.GetPointIds().SetId( 0, faces[j,0] )
        cell.GetPointIds().SetId( 1, faces[j,1] )
        cell.GetPointIds().SetId( 2, faces[j,2] )
        cells.InsertNextCell( cell )
    
    
    points = vtk.vtkPoints()
    points.SetNumberOfPoints(nv)
    for j in range(nv):
        points.SetPoint( j, pts[j,0], pts[j,1], pts[j,2] )
        
    new_mesh = vtk.vtkPolyData()
    new_mesh.SetPoints( points )
    new_mesh.SetPolys( cells )
    new_mesh.BuildCells()	
    
    return new_mesh
开发者ID:cbutakoff,项目名称:tools,代码行数:32,代码来源:mytools.py


示例7: createPolyData

def createPolyData(faces, vtList, verts, tcoords):

    points = vtk.vtkPoints()
    points.SetDataTypeToDouble()
    points.SetNumberOfPoints(len(vtList))

    tcoordArray = vtk.vtkDoubleArray()
    tcoordArray.SetName('tcoords')
    tcoordArray.SetNumberOfComponents(2)
    tcoordArray.SetNumberOfTuples(len(vtList))

    for i, vt in enumerate(vtList):
        vi, ti = vt
        xyz = verts[vi]
        uv = tcoords[ti]

        points.SetPoint(i, xyz)
        tcoordArray.SetTuple2(i, uv[0], uv[1])

    cells = vtk.vtkCellArray()

    for i, face in enumerate(faces):
        tri = vtk.vtkTriangle()
        tri.GetPointIds().SetId(0, face[0])
        tri.GetPointIds().SetId(1, face[1])
        tri.GetPointIds().SetId(2, face[2])
        cells.InsertNextCell(tri)

    polyData = vtk.vtkPolyData()
    polyData.SetPoints(points)
    polyData.SetPolys(cells)
    polyData.GetPointData().SetTCoords(tcoordArray)
    return polyData
开发者ID:RobotLocomotion,项目名称:Pigeon,代码行数:33,代码来源:convertCollada.py


示例8: get_polydata_from

def get_polydata_from(points, tr_re):

    numberPoints = len(points)
    Points = vtkPoints()
    ntype = get_numpy_array_type(Points.GetDataType())
    points_vtk = numpy_to_vtk(np.asarray(points, order='C',dtype=ntype), deep=1)
    Points.SetNumberOfPoints(numberPoints)
    Points.SetData(points_vtk)

    Triangles = vtkCellArray()
    for item in tr_re:
        Triangle = vtkTriangle()
        Triangle.GetPointIds().SetId(0,item[0])
        Triangle.GetPointIds().SetId(1,item[1])
        Triangle.GetPointIds().SetId(2,item[2])
        Triangles.InsertNextCell(Triangle)

    polydata = vtkPolyData()
    polydata.SetPoints(Points)
    polydata.SetPolys(Triangles)

    polydata.Modified()
    polydata.Update()

    return polydata
开发者ID:mmolero,项目名称:pcloudpy,代码行数:25,代码来源:converters.py


示例9: create_cell

 def create_cell(elem):
     triangle = vtk.vtkTriangle()
     ids = triangle.GetPointIds()
     ids.SetId(0, elem[0])
     ids.SetId(1, elem[1])
     ids.SetId(2, elem[2])
     return triangle
开发者ID:tbetcke,项目名称:PyPWDG,代码行数:7,代码来源:vtk_output.py


示例10: __init__

    def __init__(self, filename=None, triangleList=[], color=(1,1,1) ):
        self.src=[]

        points = vtk.vtkPoints()
        triangles = vtk.vtkCellArray()
        n=0
        for t in triangleList:
            triangle = vtk.vtkTriangle()
            for p in t:
                points.InsertNextPoint(p.x, p.y, p.z)
            triangle.GetPointIds().SetId(0,n)
            n=n+1
            triangle.GetPointIds().SetId(1,n)
            n=n+1
            triangle.GetPointIds().SetId(2,n)
            n=n+1
            triangles.InsertNextCell(triangle)
        polydata= vtk.vtkPolyData()
        polydata.SetPoints(points)
        polydata.SetPolys(triangles)
        polydata.Modified()
        polydata.Update()
        self.src=polydata
        self.mapper = vtk.vtkPolyDataMapper()
        self.mapper.SetInput(self.src)
        self.SetMapper(self.mapper)
            


        self.SetColor(color)
开发者ID:aewallin,项目名称:libcutsim,代码行数:30,代码来源:myvtk.py


示例11: add_triangle

    def add_triangle(self, neighbors, color, center=None, opacity=0.4,
                     draw_edges=False, edges_color=[0.0, 0.0, 0.0],
                     edges_linewidth=2):
        """
        Adds a triangular surface between three atoms.

        Args:
            atoms: Atoms between which a triangle will be drawn.
            color: Color for triangle as RGB.
            center: The "central atom" of the triangle
            opacity: opacity of the triangle
            draw_edges: If set to True, the a line will be  drawn at each edge
            edges_color: Color of the line for the edges
            edges_linewidth: Width of the line drawn for the edges
        """
        points = vtk.vtkPoints()
        triangle = vtk.vtkTriangle()
        for ii in range(3):
            points.InsertNextPoint(neighbors[ii].x, neighbors[ii].y,
                                   neighbors[ii].z)
            triangle.GetPointIds().SetId(ii, ii)
        triangles = vtk.vtkCellArray()
        triangles.InsertNextCell(triangle)

        # polydata object
        trianglePolyData = vtk.vtkPolyData()
        trianglePolyData.SetPoints( points )
        trianglePolyData.SetPolys( triangles )

        # mapper
        mapper = vtk.vtkPolyDataMapper()
        mapper.SetInput(trianglePolyData)

        ac = vtk.vtkActor()
        ac.SetMapper(mapper)
        ac.GetProperty().SetOpacity(opacity)
        if color == 'element':
            if center is None:
                raise ValueError(
                    'Color should be chosen according to the central atom, '
                    'and central atom is not provided')
            # If partial occupations are involved, the color of the specie with
            # the highest occupation is used
            myoccu = 0.0
            for specie, occu in center.species_and_occu.items():
                if occu > myoccu:
                    myspecie = specie
                    myoccu = occu
            color = [i / 255 for i in self.el_color_mapping[myspecie.symbol]]
            ac.GetProperty().SetColor(color)
        else:
            ac.GetProperty().SetColor(color)
        if draw_edges:
            ac.GetProperty().SetEdgeColor(edges_color)
            ac.GetProperty().SetLineWidth(edges_linewidth)
            ac.GetProperty().EdgeVisibilityOn()
        self.ren.AddActor(ac)
开发者ID:AtlasL,项目名称:pymatgen,代码行数:57,代码来源:structure_vtk.py


示例12: create_single_legend_actor

def create_single_legend_actor(color, line_style):
    points = vtk.vtkPoints()
    raw_points = [
         [0, 0],
         [1, 0],
         [0, 0.25],
         [1, 0.25],
         [0, 0.5],
         [1, 0.5],
         [0, 0.75],
         [1, 0.75],
         [0, 1],
         [1, 1],
         [0.5, 1],
         [0.5, 0]
    ]
    for point in raw_points:
        points.InsertNextPoint([ point[1], point[0], 1.0 ])

    p1 = [
        [0, 2, 3],
        [0, 3, 1]
    ]
    p2 = [
        [2, 4, 5],
        [2, 5, 3]
    ]
    p3 = [
        [4, 6, 7],
        [4, 7, 5]
    ]
    p4 = [
        [6, 8, 9],
        [6, 9, 7]
    ]
    triangles_raw = [
        [0, 10, 11],
        [0, 9, 10]
    ]
    triangles_raw += p1 + p2 + p3 + p4
    if line_style == 0xF0F0:
        triangles_raw = p1 + p3
    elif line_style == 0xFF00:
        triangles_raw = p1 + p2
    elif line_style == 0x000F:
        triangles_raw = p4
    triangles = vtk.vtkCellArray()
    for t in triangles_raw:
        triangle = vtk.vtkTriangle()
        triangle.GetPointIds().SetId(0, t[0])
        triangle.GetPointIds().SetId(1, t[1])
        triangle.GetPointIds().SetId(2, t[2])
        triangles.InsertNextCell(triangle)
    polydata = vtk.vtkPolyData()
    polydata.SetPoints(points)
    polydata.SetPolys(triangles)
    return polydata
开发者ID:selaux,项目名称:master-of-bones,代码行数:57,代码来源:to_vtk.py


示例13: meshToUnstructeredGrid

def meshToUnstructeredGrid(mesh):
	
	"""Converts a FiPy mesh structure to a vtkUnstructuredGrid.
	
	Works for 2D and 3D meshes.
	
	Args:
		mesh (fipy.GmshImporter3D): Some Fipy mesh object.
		
	Returns:
		vtk.vtkUnstructuredGrid	
	"""
	
	
	# Get vertex coordinates
	coords=mesh.vertexCoords
	
	if len(coords)==2:
		x,y=coords
		dim=2
	else:
		x,y,z=coords
		dim=3
		
	# Insert them as points
	points = vtk.vtkPoints()
	for i in range(len(x)):
		if dim==2:
			points.InsertNextPoint(x[i], y[i],0)
		else:	
			points.InsertNextPoint(x[i], y[i],z[i])

	# Insert tetrahedrons
	verts=mesh._getOrderedCellVertexIDs().T
		
	cellArray = vtk.vtkCellArray()
	for j,vert in enumerate(verts):
		
		if dim==3:
			tetra = vtk.vtkTetra()
		else:
			tetra = vtk.vtkTriangle()
			
		for i,v in enumerate(vert):
			tetra.GetPointIds().SetId(i, v)
		cellArray.InsertNextCell(tetra)

	# Grid
	grid = vtk.vtkUnstructuredGrid()
	grid.SetPoints(points)
	
	if dim==3:
		grid.SetCells(vtk.VTK_TETRA, cellArray)
	else:
		grid.SetCells(vtk.VTK_TRIANGLE, cellArray)
	
	return grid
开发者ID:alexblaessle,项目名称:PyFRAP,代码行数:57,代码来源:pyfrp_vtk_module.py


示例14: trim_mesh_with_cone

def trim_mesh_with_cone(mesh, cone_point, cone_normal, cone_radius):
    """
    returns a mesh that contains only the triangles that where inside of the cone
    """
    cone_end = cone_point + cone_normal*100.0
    sq_radius = cone_radius*cone_radius
    w = cone_point
    v = cone_end
    n = w - v
    v_w_sq_len = dist2(v, w)
   
    points = mesh.GetPoints().GetData()
    cell_array = mesh.GetPolys()
    polygons = cell_array.GetData()
    triangles = vtk.vtkCellArray()
    for i in xrange(0,  cell_array.GetNumberOfCells()):
        triangle = [polygons.GetValue(j) for j in xrange(i*4+1, i*4+4)]
        
        p = points.GetTuple(triangle[0])
        delta = p - (v + (((p - v).dot(n)) / v_w_sq_len) * n)
        if delta.dot(delta) > sq_radius:
            continue
        
        p = points.GetTuple(triangle[1])
        delta = p - (v + (((p - v).dot(n)) / v_w_sq_len) * n)
        if delta.dot(delta) > sq_radius:
            continue
        
        p = points.GetTuple(triangle[2])
        delta = p - (v + (((p - v).dot(n)) / v_w_sq_len) * n)
        if delta.dot(delta) > sq_radius:
            continue
        
        cell = vtk.vtkTriangle()
        pointIds = cell.GetPointIds()
        pointIds.SetId(0, triangle[0])
        pointIds.SetId(1, triangle[1])
        pointIds.SetId(2, triangle[2])
        triangles.InsertNextCell(cell)
            
    # Create a polydata object
    trianglePolyData = vtk.vtkPolyData()

    # Add the geometry and topology to the polydata
    trianglePolyData.SetPoints(mesh.GetPoints())
    trianglePolyData.SetPolys(triangles)
    trianglePolyData.Update()
    
    #run the clean function here to remove the points that are not used
    cleanPolyData = vtk.vtkCleanPolyData()
    cleanPolyData.SetInput(trianglePolyData)
    cleanPolyData.Update()
    trimmed_mesh = cleanPolyData.GetOutput()

    return trimmed_mesh
开发者ID:joshalbrecht,项目名称:shinyshell,代码行数:55,代码来源:mesh.py


示例15: RenderTriangleAsPolygon

def RenderTriangleAsPolygon(points, triangleNumber):
	print '* * * RenderTriangle: ', triangleNumber
	print 'Triangle points: ', tri
	p_triangles.InsertNextPoint(points[0])
	p_triangles.InsertNextPoint(points[1])
	p_triangles.InsertNextPoint(points[2])
	triangle = vtk.vtkTriangle();
	triangle.GetPointIds().SetId(0, 0+(triangleNumber-1)*3);
	triangle.GetPointIds().SetId(1, 1+(triangleNumber-1)*3);
	triangle.GetPointIds().SetId(2, 2+(triangleNumber-1)*3);
	triangles.InsertNextCell(triangle);
开发者ID:annaleida,项目名称:raybender,代码行数:11,代码来源:raybender.py


示例16: defineMesh

 def defineMesh(self,nodes,elements):
     self._points    = vtk.vtkPoints()
     self._triangles = vtk.vtkCellArray()
     for i in range(len(nodes)):
         self._points.InsertNextPoint(nodes[i].x(),nodes[i].y(),0.)
     for el in elements:
         tri = vtk.vtkTriangle()
         conn = el.connectivite()
         for ii,n in enumerate(conn):
             tri.GetPointIds().SetId(ii,n)
         self._triangles.InsertNextCell(tri)
开发者ID:Bordreuil,项目名称:elementsFiNimes,代码行数:11,代码来源:visuTools.py


示例17: mesh_from_arcs

def mesh_from_arcs(arcs):
    #create all of the points so they have sensible, shared indices
    points = vtk.vtkPoints()
    num_points_in_arc = len(arcs[0])
    for i in range(0, len(arcs)):
        arc = arcs[i]
        assert len(arc) == num_points_in_arc, "All arcs must be the same length"
        for j in range(0, len(arc)):
            point = arc[j]
            points.InsertNextPoint(point[0], point[1], point[2])
    
    # Build the meshgrid manually
    triangles = vtk.vtkCellArray()
    for i in range(1, len(arcs)):
        for j in range(0, len(arc)-1):
            
            triangle = vtk.vtkTriangle()
            pointIds = triangle.GetPointIds()
            pointIds.SetId(0, i * num_points_in_arc + j)
            pointIds.SetId(1, i * num_points_in_arc + j + 1)
            pointIds.SetId(2, (i-1) * num_points_in_arc + j + 1)
            triangles.InsertNextCell(triangle)

            triangle = vtk.vtkTriangle()
            pointIds = triangle.GetPointIds()
            pointIds.SetId(0, i * num_points_in_arc + j)
            pointIds.SetId(1, (i-1) * num_points_in_arc + j + 1)
            pointIds.SetId(2, (i-1) * num_points_in_arc + j)
            triangles.InsertNextCell(triangle)

    # Create a polydata object
    trianglePolyData = vtk.vtkPolyData()

    # Add the geometry and topology to the polydata
    trianglePolyData.SetPoints(points)
    trianglePolyData.SetPolys(triangles)
    trianglePolyData.Update()

    return trianglePolyData
开发者ID:joshalbrecht,项目名称:shinyshell,代码行数:39,代码来源:mesh.py


示例18: getVtkUnstructuredGrid

    def getVtkUnstructuredGrid(self):
        tPts = vtk.vtkPoints()
        ugrid = vtk.vtkUnstructuredGrid()
        tPts.SetNumberOfPoints(self.nodes.shape[0])
        for n in np.arange(self.nodes.shape[0]):
            tPts.InsertPoint(n, self.nodes[n,0], self.nodes[n,1], self.nodes[n,2])
        ugrid.SetPoints(tPts)
        tri = vtk.vtkTriangle()
        for n in np.arange(self.cells.shape[0]):
            tri.GetPointIds().SetId(0, self.cells[n,0])
            tri.GetPointIds().SetId(1, self.cells[n,1])
            tri.GetPointIds().SetId(2, self.cells[n,2])
            ugrid.InsertNextCell( tri.GetCellType(), tri.GetPointIds() )

        return ugrid
开发者ID:bernard-giroux,项目名称:ttcr,代码行数:15,代码来源:mesh.py


示例19: buildFullVTKGrid

    def buildFullVTKGrid(self):
        # Create the points for VTK
        points = vtk.vtkPoints()
        for i in range(0, len(self.mesh.coords)/3):
            p = self.mesh.coords[(i*3):(i*3+3)]
            points.InsertNextPoint(p)

        #add the points and cells to unstructured grid
        vtkgrid = vtk.vtkUnstructuredGrid()
        vtkgrid.SetPoints(points)

        #add the VTK elements to the mesh
        for element in self.mesh.elements:
            type = element.getType()
            nodes = element.nodes
            cell = vtk.vtkTriangle()
            if type == eTypes.TRI:
                cell = vtk.vtkTriangle()
            elif type == eTypes.QUAD:
                cell = vtk.vtkQuad()
            elif type == eTypes.TET:
                cell = vtk.vtkTetra()
            elif type == eTypes.PYRAMID:
                cell = vtk.vtkPyramid()
            elif type == eTypes.PRISM:
                cell = vtk.vtkWedge()  #prism
            elif type == eTypes.HEX:
                cell = vtk.vtkHexahedron()
            else:
                raise # throw an exception
            j = 0
            for n in nodes:
                cell.GetPointIds().SetId(j,n)
                j = j+1
            vtkgrid.InsertNextCell(cell.GetCellType(), cell.GetPointIds())
        return vtkgrid
开发者ID:zwghit,项目名称:ProteusCFD,代码行数:36,代码来源:guiData.py


示例20: _polydata

    def _polydata(self, inflated=False):
        """ Compute a vtk polydata of the TriSurface.

        This code uses vtk.

        Parameters
        ----------
        inflated: bool (optional, default False)
            If True use the inflated vertices.

        Returns
        -------
        polydata: vtkPolyData
            the TriSurface vtk polydata.
        """
        # Import here since vtk is not required by the package
        import vtk

        # Select the vertices to use
        labels = copy.deepcopy(self.labels)
        if inflated:
            vertices = self.inflated_vertices
        else:
            vertices = self.vertices

        # First setup points, triangles and colors.
        vtk_points = vtk.vtkPoints()
        vtk_triangles = vtk.vtkCellArray()
        vtk_colors = vtk.vtkUnsignedCharArray()
        vtk_colors.SetNumberOfComponents(1)
        labels[numpy.where(labels < 0)] = 0
        for index in range(len(vertices)):
            vtk_points.InsertNextPoint(vertices[index])
            vtk_colors.InsertNextTuple1(labels[index])
        for triangle in self.triangles:
            vtk_triangle = vtk.vtkTriangle()
            vtk_triangle.GetPointIds().SetId(0, triangle[0])
            vtk_triangle.GetPointIds().SetId(1, triangle[1])
            vtk_triangle.GetPointIds().SetId(2, triangle[2])
            vtk_triangles.InsertNextCell(vtk_triangle)

        # Create (geometry and topology) the associated polydata
        polydata = vtk.vtkPolyData()
        polydata.SetPoints(vtk_points)
        polydata.GetPointData().SetScalars(vtk_colors)
        polydata.SetPolys(vtk_triangles)

        return polydata
开发者ID:dgoyard,项目名称:pyfreesurfer,代码行数:48,代码来源:surftools.py



注:本文中的vtk.vtkTriangle函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python vtk.vtkTriangleFilter函数代码示例发布时间:2022-05-26
下一篇:
Python vtk.vtkTransformPolyDataFilter函数代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap