本文整理汇总了Python中vtk.vtkTriangle函数的典型用法代码示例。如果您正苦于以下问题:Python vtkTriangle函数的具体用法?Python vtkTriangle怎么用?Python vtkTriangle使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了vtkTriangle函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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
示例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
示例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
示例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
示例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()
示例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
示例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
示例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
示例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
示例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)
示例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)
示例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
示例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
示例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
示例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);