本文整理汇总了Python中vtk.vtkLine函数的典型用法代码示例。如果您正苦于以下问题:Python vtkLine函数的具体用法?Python vtkLine怎么用?Python vtkLine使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了vtkLine函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
def __init__(self, parent = None):
super(VTKFrame, self).__init__(parent)
self.vtkWidget = QVTKRenderWindowInteractor(self)
vl = QtGui.QVBoxLayout(self)
vl.addWidget(self.vtkWidget)
vl.setContentsMargins(0, 0, 0, 0)
self.ren = vtk.vtkRenderer()
self.ren.SetBackground(0.3, 0.4, 0.5)
self.vtkWidget.GetRenderWindow().AddRenderer(self.ren)
self.iren = self.vtkWidget.GetRenderWindow().GetInteractor()
# Create lines.
points = vtk.vtkPoints()
points.InsertPoint(0, 0, 0, 1)
points.InsertPoint(1, 1, 0, 0)
points.InsertPoint(2, 0, 1, 0)
points.InsertPoint(3, 1, 1, 1)
line1 = vtk.vtkLine()
line1.GetPointIds().SetId(0, 0)
line1.GetPointIds().SetId(1, 1)
line2 = vtk.vtkLine()
line2.GetPointIds().SetId(0, 2)
line2.GetPointIds().SetId(1, 3)
lines = vtk.vtkCellArray()
lines.InsertNextCell(line1)
lines.InsertNextCell(line2)
polyData = vtk.vtkPolyData()
polyData.SetPoints(points)
polyData.SetLines(lines)
ruledSurfaceFilter = vtk.vtkRuledSurfaceFilter()
ruledSurfaceFilter.SetInputConnection(polyData.GetProducerPort())
ruledSurfaceFilter.SetResolution(21, 21)
ruledSurfaceFilter.SetRuledModeToResample()
# Create a mapper
mapper = vtk.vtkPolyDataMapper()
mapper.SetInputConnection(ruledSurfaceFilter.GetOutputPort())
# Create an actor
actor = vtk.vtkActor()
actor.SetMapper(mapper)
actor.GetProperty().SetColor(0.89, 0.81, 0.34)
self.ren.AddActor(actor)
self.ren.ResetCamera()
self._initialized = False
示例2: edges
def edges(indices):
"""
Maps a numpy ndarray to an vtkCellArray of vtkLines
Args:
indices (numpy.ndarray<int>): A numpy.ndarray of shape (n,2) of indices that define n edges
Returns:
vtk_lines (vtk.vtkCellArray): VTK representation of the edges
"""
if not isinstance(indices, numpy.ndarray):
raise Numpy2VtkFormatException(
'lines needs numpy array as input'
)
if len(indices.shape) != 2 or indices.shape[1] != 2:
raise Numpy2VtkFormatException(
'lines needs a nx2 ndarray as input'
)
if indices.dtype != numpy.int:
raise Numpy2VtkFormatException(
'lines needs to be numpy array of type numpy.int'
)
vtk_lines = vtk.vtkCellArray()
for e in indices:
line = vtk.vtkLine()
line.GetPointIds().SetId(0, e[0])
line.GetPointIds().SetId(1, e[1])
vtk_lines.InsertNextCell(line)
return vtk_lines
示例3: __init__
def __init__(self, parent = None):
super(VTKFrame, self).__init__(parent)
self.vtkWidget = QVTKRenderWindowInteractor(self)
vl = QtGui.QVBoxLayout(self)
vl.addWidget(self.vtkWidget)
vl.setContentsMargins(0, 0, 0, 0)
self.ren = vtk.vtkRenderer()
self.ren.SetBackground(0.1, 0.2, 0.4)
self.vtkWidget.GetRenderWindow().AddRenderer(self.ren)
self.iren = self.vtkWidget.GetRenderWindow().GetInteractor()
# Create source
# Create five points.
origin = [0.0, 0.0, 0.0]
p0 = [1.0, 0.0, 0.0]
p1 = [0.0, 1.0, 0.0]
p2 = [0.0, 1.0, 2.0]
p3 = [1.0, 2.0, 3.0]
p4 = [1.0, 2.0, 8.0]
# Create a vtkPoints object and store the points in it
points = vtk.vtkPoints()
points.InsertNextPoint(origin)
points.InsertNextPoint(p0)
points.InsertNextPoint(p1)
points.InsertNextPoint(p2)
points.InsertNextPoint(p3)
points.InsertNextPoint(p4)
# Create a cell array to store the lines in and add the lines to it
lines = vtk.vtkCellArray()
for i in range(4):
line = vtk.vtkLine()
line.GetPointIds().SetId(0,i)
line.GetPointIds().SetId(1,i+1)
lines.InsertNextCell(line)
# Create a polydata to store everything in
linesPolyData = vtk.vtkPolyData()
# Add the points to the dataset
linesPolyData.SetPoints(points)
# Add the lines to the dataset
linesPolyData.SetLines(lines)
# Setup actor and mapper
mapper = vtk.vtkPolyDataMapper()
mapper.SetInput(linesPolyData)
actor = vtk.vtkActor()
actor.SetMapper(mapper)
self.ren.AddActor(actor)
self.ren.ResetCamera()
self._initialized = False
示例4: __init__
def __init__(self,center=(0,0,0) , radius=1, color=(0,1,1), resolution=50 ):
""" create circle """
lines =vtk.vtkCellArray()
id = 0
points = vtk.vtkPoints()
for n in xrange(0,resolution):
line = vtk.vtkLine()
angle1 = (float(n)/(float(resolution)))*2*math.pi
angle2 = (float(n+1)/(float(resolution)))*2*math.pi
p1 = (center[0]+radius*math.cos(angle1), center[1]+radius*math.sin(angle1), center[2])
p2 = (center[0]+radius*math.cos(angle2), center[1]+radius*math.sin(angle2), center[2])
points.InsertNextPoint(p1)
points.InsertNextPoint(p2)
line.GetPointIds().SetId(0,id)
id=id+1
line.GetPointIds().SetId(1,id)
id=id+1
lines.InsertNextCell(line)
self.pdata = vtk.vtkPolyData()
self.pdata.SetPoints(points)
self.pdata.SetLines(lines)
self.mapper = vtk.vtkPolyDataMapper()
self.mapper.SetInput(self.pdata)
self.SetMapper(self.mapper)
self.SetColor(color)
示例5: GetNormalLines
def GetNormalLines(vtx, normals, scale):
"""
Returns polydata with lines to visualize normals.
This can be used for either vertex or face normals;
just specify the normals start points with "vtx".
"""
linePoints = vtk.vtkPoints()
aLine = vtk.vtkLine()
aLineGrid = vtk.vtkUnstructuredGrid()
aLineGrid.Allocate(1, 1)
aLineGrid.SetPoints(linePoints)
for i in xrange(vtx.GetNumberOfTuples()):
xyz0 = vtx.GetTuple3(i)
nxyz = normals.GetTuple3(i)
linePoints.InsertNextPoint(xyz0[0], xyz0[1], xyz0[2])
linePoints.InsertNextPoint(xyz0[0]+nxyz[0]*scale,
xyz0[1]+nxyz[1]*scale,
xyz0[2]+nxyz[2]*scale)
aLine.GetPointIds().SetId(0, 2*i)
aLine.GetPointIds().SetId(1, 2*i+1)
aLineGrid.InsertNextCell(aLine.GetCellType(),
aLine.GetPointIds())
return aLineGrid
示例6: setEdgesPolydata
def setEdgesPolydata(self, vd):
self.edges = []
self.edges = vd.getEdgesGenerators()
self.epts = vtk.vtkPoints()
nid = 0
lines=vtk.vtkCellArray()
for e in self.edges:
p1 = self.scale*e[0]
p2 = self.scale*e[1]
self.epts.InsertNextPoint( p1.x, p1.y, p1.z)
self.epts.InsertNextPoint( p2.x, p2.y, p2.z)
line = vtk.vtkLine()
line.GetPointIds().SetId(0,nid)
line.GetPointIds().SetId(1,nid+1)
nid = nid+2
lines.InsertNextCell(line)
linePolyData = vtk.vtkPolyData()
linePolyData.SetPoints(self.epts)
linePolyData.SetLines(lines)
mapper = vtk.vtkPolyDataMapper()
mapper.SetInput(linePolyData)
self.edge_actor = vtk.vtkActor()
self.edge_actor.SetMapper(mapper)
self.edge_actor.GetProperty().SetColor( camvtk.cyan )
myscreen.addActor( self.edge_actor )
myscreen.render()
示例7: drawCurve2
def drawCurve2(myscreen, curve, curvecolor):
oPoints = vtk.vtkPoints()
lineCells=vtk.vtkCellArray()
idx = 0
last_idx = 0
segs=[]
first = 1
print " curve with ", len(curve)," points"
for p in curve:
oPoints.InsertNextPoint( p[0], p[1], 0)
if first==0:
seg = [last_idx,idx]
segs.append(seg)
first = 0
last_idx = idx
idx = idx + 1
# create line and cells
for seg in segs:
line = vtk.vtkLine()
line.GetPointIds().SetId(0, seg[0])
line.GetPointIds().SetId(1, seg[1])
lineCells.InsertNextCell(line)
linePolyData = vtk.vtkPolyData()
linePolyData.SetPoints(oPoints)
linePolyData.SetLines(lineCells)
linePolyData.Modified()
linePolyData.Update()
mapper = vtk.vtkPolyDataMapper()
mapper.SetInput(linePolyData)
edge_actor = vtk.vtkActor()
edge_actor.SetMapper(mapper)
edge_actor.GetProperty().SetColor( curvecolor )
myscreen.addActor( edge_actor )
示例8: draw_lines
def draw_lines(nodes, color):
points = vtk.vtkPoints()
lines = vtk.vtkCellArray()
nodecnt = 0
colors = vtk.vtkUnsignedCharArray()
colors.SetNumberOfComponents(3)
colors.SetName("Colors")
for node in nodes:
edges = node.getedges()
for edge in edges:
x0,y0,z0 = edge[0]
x1,y1,z1 = edge[1]
points.InsertNextPoint(edge[0])
points.InsertNextPoint(edge[1])
line = vtk.vtkLine()
line.GetPointIds().SetId(0,nodecnt)
line.GetPointIds().SetId(1,nodecnt+1)
lines.InsertNextCell(line)
nodecnt += 2
colors.InsertNextTupleValue(color)
# Create a polydata to store everything in
linesPolyData = vtk.vtkPolyData()
# Add the points to the dataset
linesPolyData.SetPoints(points)
# Add the lines to the dataset
linesPolyData.SetLines(lines)
linesPolyData.GetCellData().SetScalars(colors)
return linesPolyData
示例9: insertLine
def insertLine(lines, id0, id1):
line = vtk.vtkLine()
lPointIds = line.GetPointIds()
lPointIds.SetId( 0, id0)
lPointIds.SetId( 1, id1)
if( containsLine(lines, line) == 0):
lines.InsertNextCell( line )
示例10: ndarray_to_vtkcellarray
def ndarray_to_vtkcellarray(array):
bonds=vtk.vtkCellArray()
for data in array:
line = vtk.vtkLine()
line.GetPointIds().SetId(0,int(data[0]))
line.GetPointIds().SetId(1,int(data[1]))
bonds.InsertNextCell(line)
return bonds
示例11: _create_cart3d_free_edegs
def _create_cart3d_free_edegs(self, model, nodes, elements):
free_edges = model.get_free_edges(elements)
nfree_edges = len(free_edges)
if nfree_edges:
# yellow = (1., 1., 0.)
pink = (0.98, 0.4, 0.93)
npoints = 2 * nfree_edges
if 'free_edges' not in self.alt_grids:
self.create_alternate_vtk_grid('free_edges', color=pink, line_width=3, opacity=1.0,
representation='surface')
j = 0
points = vtk.vtkPoints()
points.SetNumberOfPoints(npoints)
self.alt_grids['free_edges'].Allocate(nfree_edges, 1000)
elem = vtk.vtkLine()
# elem.GetPointIds().SetId(0, nidMap[nodeIDs[0]])
# elem.GetPointIds().SetId(1, nidMap[nodeIDs[1]])
etype = vtk.vtkLine().GetCellType()
for free_edge in free_edges:
# (p1, p2) = free_edge
for ipoint, node_id in enumerate(free_edge):
point = nodes[node_id, :]
points.InsertPoint(j + ipoint, *point)
elem = vtk.vtkLine()
elem.GetPointIds().SetId(0, j)
elem.GetPointIds().SetId(1, j + 1)
self.alt_grids['free_edges'].InsertNextCell(etype, elem.GetPointIds())
j += 2
self.alt_grids['free_edges'].SetPoints(points)
else:
# TODO: clear free edges
pass
if 'free_edges' in self.alt_grids:
self._add_alt_actors(self.alt_grids)
self.geometry_actors['free_edges'].Modified()
if hasattr(self.geometry_actors['free_edges'], 'Update'):
self.geometry_actors['free_edges'].Update()
示例12: RenderRay
def RenderRay(start, end, rayNumber):
print '* * * RenderRay: ', rayNumber
print 'ray coords start: ', start
print 'ray coords end: ', end
p_rays.InsertNextPoint(start)
p_rays.InsertNextPoint(end)
ray = vtk.vtkLine()
ray.GetPointIds().SetId(0,(rayNumber -1)*2)
ray.GetPointIds().SetId(1,(rayNumber-1)*2+1)
rays.InsertNextCell(ray)
示例13: _createline
def _createline(self, pointnumbers):
if depth(pointnumbers) >= 3:
for p in pointnumbers:
self._createline(p)
else:
for i in range(len(pointnumbers) - 1):
line = vtk.vtkLine()
line.GetPointIds().SetId(0, pointnumbers[i])
line.GetPointIds().SetId(1, pointnumbers[i + 1])
self.lines.InsertNextCell(line)
i = i + 1
示例14: RenderTriangleAsLine
def RenderTriangleAsLine(points, triangleNumber):
print '* * * RenderTriangle: ', triangleNumber
print 'Triangle points: ', tri
print (triangleNumber-1)*3
p_triangles.InsertNextPoint(points[0])
p_triangles.InsertNextPoint(points[1])
p_triangles.InsertNextPoint(points[2])
line1 = vtk.vtkLine();
line1.GetPointIds().SetId(0, 0+(triangleNumber-1)*3);
line1.GetPointIds().SetId(1, 1+(triangleNumber-1)*3);
line2 = vtk.vtkLine();
line2.GetPointIds().SetId(0, 0+(triangleNumber-1)*3);
line2.GetPointIds().SetId(1, 2+(triangleNumber-1)*3);
line3 = vtk.vtkLine();
line3.GetPointIds().SetId(0, 1+(triangleNumber-1)*3);
line3.GetPointIds().SetId(1, 2+(triangleNumber-1)*3);
triangles.InsertNextCell(line1);
triangles.InsertNextCell(line2);
triangles.InsertNextCell(line3);
示例15: draw_lines
def draw_lines(nodes, color):
colors = vtk.vtkUnsignedCharArray()
colors.SetNumberOfComponents(3)
colors.SetName("Colors")
cnt = 0
noderange = 100
mod = 1
edges = nodes[0].getedges()
points = vtk.vtkPoints()
lines = vtk.vtkCellArray()
nodecnt = 0
while cnt < len(nodes):
node = nodes[cnt]
cnt += 1
edges = node.getedges()
for edge in edges:
x0,y0,z0 = edge[0]
x1,y1,z1 = edge[1]
points.InsertNextPoint(edge[0])
points.InsertNextPoint(edge[1])
line = vtk.vtkLine()
line.GetPointIds().SetId(0,nodecnt)
line.GetPointIds().SetId(1,nodecnt+1)
lines.InsertNextCell(line)
nodecnt += 2
colors.InsertNextTupleValue(color)
if cnt % mod == 0:
print "noderange", noderange, "cnt", cnt, "mod",mod
# Create a polydata to store everything in
linesPolyData = vtk.vtkPolyData()
# Add the points to the dataset
linesPolyData.SetPoints(points)
# Add the lines to the dataset
linesPolyData.SetLines(lines)
linesPolyData.GetCellData().SetScalars(colors)
mapper = vtk.vtkPolyDataMapper()
mapper.SetInput(linesPolyData)
actor = vtk.vtkActor()
actor.SetMapper(mapper)
renderer.AddActor(actor)
points = vtk.vtkPoints()
lines = vtk.vtkCellArray()
nodecnt = 0
renderWindow.Render()
camera = renderer.GetActiveCamera()
camera.Azimuth(0.1)
print "done!"