本文整理汇总了Python中vtk.vtkUnsignedCharArray函数的典型用法代码示例。如果您正苦于以下问题:Python vtkUnsignedCharArray函数的具体用法?Python vtkUnsignedCharArray怎么用?Python vtkUnsignedCharArray使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了vtkUnsignedCharArray函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: write
def write(self, file_name):
writer = vtk.vtkPLYWriter()
writer.SetFileName(file_name)
writer.SetInputData(self.vtk_poly_data)
if self.is_color_mode_height:
# set lookup tbale for depth values to colors
lut = vtk.vtkLookupTable()
lut.SetTableRange(self.height_min, self.height_max)
lut.Build()
# in order to be convertable to pcd, use lut to generate colors.
# THIS IS A DIRTY HACK BUT NEEDED SINCE PCL IS STUPID
# writer.SetLookupTable(lut) only works for meshlab
cur_color_data = vtk.vtkUnsignedCharArray()
cur_color_data.SetNumberOfComponents(3)
for id in self.color_ids:
val = self.color_data.GetValue(id)
col = [0., 0., 0.]
lut.GetColor(val, col)
col = [int(c * 255) for c in col]
cur_color_data.InsertNextTuple3(col[0], col[1], col[2])
self.color_data = cur_color_data
self.color_data.SetName("Colors")
self.vtk_poly_data.GetPointData().SetActiveScalars('Colors')
self.vtk_poly_data.GetPointData().SetScalars(self.color_data)
writer.SetArrayName("Colors")
writer.Write()
示例2: 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
示例3: __init__
def __init__(self, pointlist=[]):
points = vtk.vtkPoints()
cellArr = vtk.vtkCellArray()
Colors = vtk.vtkUnsignedCharArray()
Colors.SetNumberOfComponents(3)
Colors.SetName("Colors")
n=0
for p in pointlist:
vert = vtk.vtkVertex()
points.InsertNextPoint(p.x, p.y, p.z)
vert.GetPointIds().SetId(0,n)
cellArr.InsertNextCell( vert )
col = clColor(p.cc())
Colors.InsertNextTuple3( float(255)*col[0], float(255)*col[1], float(255)*col[2] )
n=n+1
polydata= vtk.vtkPolyData()
polydata.SetPoints(points)
polydata.SetVerts( cellArr )
polydata.GetPointData().SetScalars(Colors)
polydata.Modified()
polydata.Update()
self.src=polydata
self.mapper = vtk.vtkPolyDataMapper()
self.mapper.SetInput(self.src)
self.SetMapper(self.mapper)
示例4: visualize_graph
def visualize_graph(self):
"""shows a visualization of the graph"""
self._graph.GetVertexData().AddArray(self._labels)
self._graph.GetEdgeData().AddArray(self._weights)
colors = vtk.vtkUnsignedCharArray()
colors.SetNumberOfComponents(1)
colors.SetName('Colors')
types = int(245 / len(self._color_dict))
for c in self._colors:
colors.InsertNextValue(int(c * types))
self._graph.GetVertexData().AddArray(colors)
graphLayoutView = vtk.vtkGraphLayoutView()
graphLayoutView.AddRepresentationFromInput(self._graph)
graphLayoutView.SetLayoutStrategy(vtk.vtkSpanTreeLayoutStrategy())
graphLayoutView.GetLayoutStrategy().SetEdgeWeightField("Weights")
graphLayoutView.GetLayoutStrategy().SetWeightEdges(1)
graphLayoutView.GetRenderer().GetActiveCamera().ParallelProjectionOff()
graphLayoutView.SetEdgeLabelArrayName("Weights")
graphLayoutView.SetEdgeLabelVisibility(1)
graphLayoutView.SetVertexLabelArrayName('labels')
graphLayoutView.SetVertexLabelVisibility(1)
graphLayoutView.SetVertexColorArrayName('Colors')
graphLayoutView.SetColorVertices(1)
graphLayoutView.SetInteractorStyle(MouseAndKeysInteractor(graphLayoutView))
graphLayoutView.ResetCamera()
graphLayoutView.Render()
graphLayoutView.GetInteractor().Start()
示例5: add_surface_overlay
def add_surface_overlay(self, data, colormap=None):
scalar = vtk.vtkUnsignedCharArray()
scalar.SetNumberOfComponents(3)
if colormap is None:
ran = (np.amin(data), np.amax(data))
mid = (ran[0] + ran[1]) / 2.
for val in data:
if val < mid:
gr = 255.0 * (val - ran[0]) / (mid - ran[0])
else:
gr = 255.0 * (ran[1] - val) / (ran[1] - mid)
scalar.InsertNextTuple3(
255 * (val - ran[0]) / (ran[1] - ran[0]),
gr,
255 * (ran[1] - val) / (ran[1] - ran[0]))
else:
for val in data:
if val < colormap[0][0]:
ind = 0
elif val > colormap[-1][0]:
ind = colormap.shape[0] - 1
else:
for ind in xrange(colormap.shape[0] - 1):
if val < colormap[ind + 1][0]:
break
scalar.InsertNextTuple3(255 * colormap[ind][1],
255 * colormap[ind][2],
255 * colormap[ind][3])
self.surface_overlays.append(scalar)
self.surface_overlay_data.append(data)
示例6: CheckFilter
def CheckFilter(inputDS):
numOrigCells = inputDS.GetNumberOfCells()
ghostArray = vtk.vtkUnsignedCharArray()
ghostArray.SetNumberOfTuples(numOrigCells)
ghostArray.SetName(vtk.vtkDataSetAttributes.GhostArrayName())
ghostArray.Fill(0)
inputDS.GetCellData().AddArray(ghostArray)
removeGhosts = vtk.vtkRemoveGhosts()
removeGhosts.SetInputDataObject(inputDS)
removeGhosts.Update()
outPD = removeGhosts.GetOutput()
if outPD.GetNumberOfCells() != numOrigCells:
print("Should have the same amount of cells but did not", outPD.GetNumberOfCells(), numOrigCells)
sys.exit(1)
ghostArray.SetValue(0, 1)
ghostArray.Modified()
removeGhosts.Modified()
removeGhosts.Update()
if outPD.GetNumberOfCells() != numOrigCells-1:
print("Should have had one less cell but did not", outPD.GetNumberOfCells(), numOrigCells)
sys.exit(1)
示例7: _format_output_polydata
def _format_output_polydata(output_polydata, cluster_idx, color, embed):
""" Output polydata with embedding colors, cluster numbers, and
embedding coordinates.
Cell data array names are:
EmbeddingColor
ClusterNumber
EmbeddingCoordinate
"""
embed_colors = vtk.vtkUnsignedCharArray()
embed_colors.SetNumberOfComponents(3)
embed_colors.SetName('EmbeddingColor')
cluster_colors = vtk.vtkIntArray()
cluster_colors.SetName('ClusterNumber')
embed_data = vtk.vtkFloatArray()
embed_data.SetNumberOfComponents(embed.shape[1])
embed_data.SetName('EmbeddingCoordinate')
for lidx in range(0, output_polydata.GetNumberOfLines()):
embed_colors.InsertNextTuple3(
color[lidx, 0], color[lidx, 1], color[lidx, 2])
cluster_colors.InsertNextTuple1(int(cluster_idx[lidx]))
embed_data.InsertNextTupleValue(embed[lidx, :])
output_polydata.GetCellData().AddArray(embed_data)
output_polydata.GetCellData().AddArray(cluster_colors)
output_polydata.GetCellData().AddArray(embed_colors)
output_polydata.GetCellData().SetActiveScalars('EmbeddingColor')
return output_polydata
示例8: array_to_vtk
def array_to_vtk(array_in, dtype=None):
"""Get vtkFloatArray/vtkDoubleArray from the input numpy array."""
if dtype == None:
dtype = _numpy.dtype(array_in.dtype)
else:
dtype = _numpy.dtype(dtype)
if dtype == _numpy.float32:
float_array = _vtk.vtkFloatArray()
elif dtype == _numpy.float64:
float_array = _vtk.vtkDoubleArray()
elif dtype == _numpy.uint8:
float_array = _vtk.vtkUnsignedCharArray()
elif dtype == _numpy.int8:
float_array = _vtk.vtkCharArray()
else:
raise ValueError("Wrong format of input array, must be float32 or float64")
if len(array_in.shape) != 1 and len(array_in.shape) != 2:
raise ValueError("Wrong shape: array must be 1D or 2D.")
#float_array.SetNumberOfComponents(_numpy.product(array_in.shape))
# if len(array_in.shape) == 2:
# float_array.SetNumberOfComponents(array_in.shape[1])
# elif len(array_in.shape) == 1:
# float_array.SetNumberOfComponents(1)
float_array.SetNumberOfComponents(1)
array_contiguous = _numpy.ascontiguousarray(array_in, dtype)
float_array.SetVoidArray(array_contiguous, _numpy.product(array_in.shape), 1)
float_array._contiguous_array = array_contiguous # Hack to keep the array of being garbage collected
# if len(array_in.shape) == 2:
# print "set tuple to {0}".format(array_in.shape[1])
# #float_array.SetNumberOfTuples(array_in.shape[1])
# float_array.Resize(array_in.shape[1])
# float_array.Squeeze()
return float_array
示例9: quadsActor
def quadsActor(bounds, color):
"""Create solid, axis-aligned quads at 0 in Z.
Args:
bounds: [[[xmin, ymin], [xmax, ymax]], ...]
color: [R, G, B, A]
"""
points = vtk.vtkPoints()
quads = vtk.vtkCellArray()
colors = vtk.vtkUnsignedCharArray()
colors.SetNumberOfComponents(4)
for (index, bound) in enumerate(bounds):
colors.InsertNextTuple4(*color)
(low, high) = bound
points.InsertNextPoint(low[0], low[1], 0)
points.InsertNextPoint(high[0], low[1], 0)
points.InsertNextPoint(high[0], high[1], 0)
points.InsertNextPoint(low[0], high[1], 0)
quad = vtk.vtkQuad()
for i in range(4):
quad.GetPointIds().SetId(i, 4 * index + i)
quads.InsertNextCell(quad)
poly_data = vtk.vtkPolyData()
poly_data.SetPoints(points)
poly_data.SetPolys(quads)
poly_data.GetCellData().SetScalars(colors)
mapper = vtk.vtkPolyDataMapper()
set_mapper_input(mapper, poly_data)
actor = vtk.vtkActor()
actor.SetMapper(mapper)
actor.RotateZ(180)
actor.RotateY(180)
return actor
示例10: testLinear
def testLinear(self):
pts = vtk.vtkPoints()
pts.SetNumberOfPoints(4)
pts.InsertPoint(0, (0, 0, 0))
pts.InsertPoint(1, (1, 0, 0))
pts.InsertPoint(2, (0.5, 1, 0))
pts.InsertPoint(3, (0.5, 0.5, 1))
te = vtk.vtkTetra()
ptIds = te.GetPointIds()
for i in range(4):
ptIds.SetId(i, i)
ghosts = vtk.vtkUnsignedCharArray()
ghosts.SetName("vtkGhostLevels")
ghosts.SetNumberOfTuples(4)
ghosts.SetValue(0, 1)
ghosts.SetValue(1, 1)
ghosts.SetValue(2, 1)
ghosts.SetValue(3, 0)
grid = vtk.vtkUnstructuredGrid()
grid.Allocate(1, 1)
grid.InsertNextCell(te.GetCellType(), te.GetPointIds())
grid.SetPoints(pts)
grid.GetPointData().AddArray(ghosts)
dss = vtk.vtkDataSetSurfaceFilter()
dss.SetInputData(grid)
dss.Update()
self.assertEqual(dss.GetOutput().GetNumberOfCells(), 3)
示例11: pointCloudActor
def pointCloudActor(points, color = (0, 0, 0, 255)):
"""Create a vtkActor representing a point cloud.
Args:
points: iterable of points [[x0, y0, z0], [x1, y1, z1], ...]
color: color of the points in the RBBA format
Returns:
An instance of vtkActor
"""
vtk_points = vtk.vtkPoints()
vertices = vtk.vtkCellArray()
colors = vtk.vtkUnsignedCharArray()
colors.SetNumberOfComponents(4)
colors.SetName("Colors")
for (x, y, z) in points:
point_id = vtk_points.InsertNextPoint(x, y, z)
vertices.InsertNextCell(1)
vertices.InsertCellPoint(point_id)
colors.InsertNextTuple4(color[0], color[1], color[2], color[3])
poly_data = vtk.vtkPolyData()
poly_data.SetPoints(vtk_points)
poly_data.SetVerts(vertices)
poly_data.GetPointData().SetScalars(colors)
mapper = vtk.vtkPolyDataMapper()
set_mapper_input(mapper, poly_data)
actor = vtk.vtkActor()
actor.SetMapper(mapper)
return actor
示例12: 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
示例13: getNewVtkDataArray
def getNewVtkDataArray( scalar_dtype ):
if scalar_dtype == np.ushort:
return vtk.vtkUnsignedShortArray()
if scalar_dtype == np.ubyte:
return vtk.vtkUnsignedCharArray()
if scalar_dtype == np.float:
return vtk.vtkFloatArray()
return None
示例14: set_scalars
def set_scalars(self, values):
colors = vtk.vtkUnsignedCharArray()
colors.SetNumberOfComponents(3)
for r,g,b,a in 255*self.cmapper.to_rgba(values):
colors.InsertNextTuple3(r,g,b)
self.polydata.GetPointData().SetScalars(colors)
示例15: vtk_point_cloud
def vtk_point_cloud(points, colors=[], point_size=2):
"""
Represent a point cloud in VTK
Parameters
----------
points : numpy array, each row is a point
colors : list of colors, one per point
point_size : rendering size for the points
Returns
-------
actor : vtkActor representing the point cloud
"""
nb = len(points);
vtk_points = vtk.vtkPoints();
vtk_verts = vtk.vtkCellArray();
if colors:
vtk_colors = vtk.vtkUnsignedCharArray();
vtk_colors.SetNumberOfComponents(3);
vtk_colors.SetName( "Colors");
for i in range(0,nb):
p = points[i]
if len(p) >= 3:
print "ok",p
coords = [p[0],p[1],p[2]]
elif len(p) == 2:
coords = [p[0],p[1],0]
elif len(p) == 1:
coords = [p[0],0,0]
else:
print "**ERROR** wrong dimension"
sys.exit(1)
id = vtk_points.InsertNextPoint( *coords )
vtk_verts.InsertNextCell(1)
vtk_verts.InsertCellPoint(id)
if colors:
vtk_colors.InsertNextTuple3( *colors[i] )
poly = vtk.vtkPolyData()
poly.SetPoints(vtk_points)
poly.SetVerts(vtk_verts)
if colors:
poly.GetPointData().SetScalars(vtk_colors)
poly.Update()
mapper = vtk.vtkPolyDataMapper()
mapper.SetInput(poly)
actor = vtk.vtkActor()
actor.SetMapper(mapper)
actor.GetProperty().SetRepresentationToPoints
actor.GetProperty().SetPointSize( point_size )
return actor