本文整理汇总了Python中vtk.vtkUnsignedCharArray函数的典型用法代码示例。如果您正苦于以下问题:Python vtkUnsignedCharArray函数的具体用法?Python vtkUnsignedCharArray怎么用?Python vtkUnsignedCharArray使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了vtkUnsignedCharArray函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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()
开发者ID:Leeyangg,项目名称:limo,代码行数:28,代码来源:vtk_pointcloud.py
示例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
开发者ID:squeakus,项目名称:octree,代码行数:33,代码来源:stltree.py
示例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)
开发者ID:aewallin,项目名称:randompolygon,代码行数:28,代码来源:ovdvtk.py
示例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()
开发者ID:RLuckom,项目名称:python-graph-visualizer,代码行数:27,代码来源:Graph.py
示例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)
开发者ID:ohinds,项目名称:sv,代码行数:32,代码来源:sv.py
示例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)
开发者ID:ElsevierSoftwareX,项目名称:SOFTX-D-15-00004,代码行数:27,代码来源:TestRemoveGhosts.py
示例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
开发者ID:baothien,项目名称:tiensy,代码行数:33,代码来源:cluster.py
示例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
开发者ID:ekeberg,项目名称:Python-tools,代码行数:33,代码来源:vtk_tools.py
示例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
开发者ID:BenoitLBen,项目名称:runtime,代码行数:33,代码来源:vtk_utils.py
示例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)
开发者ID:timkrentz,项目名称:SunTracker,代码行数:31,代码来源:TestGhostPoints.py
示例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
开发者ID:BenoitLBen,项目名称:runtime,代码行数:29,代码来源:vtk_utils.py
示例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
开发者ID:HerrMuellerluedenscheid,项目名称:contrib-snufflings,代码行数:59,代码来源:grid_topo.py
示例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
开发者ID:imclab,项目名称:vistrails,代码行数:8,代码来源:vtUtilities.py
示例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)
开发者ID:RodericDay,项目名称:MiniPNM,代码行数:8,代码来源:graphics.py
示例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
开发者ID:151706061,项目名称:IRTK,代码行数:58,代码来源:vtkTools.py
示例16: execute
def execute(self):
output_collection = vtk.vtkCollection()
cluster=ClusterParticles(input,output_collection,feature_extractor=self.feature_extractor)
cluster._number_of_clusters=2
#cluster._method='MiniBatchKMeans'
cluster._method='KMeans'
cluster.execute()
points = vtk_to_numpy(input.GetPoints().GetData())
p_centroids = np.zeros([2,3])
for ii,ll in enumerate(cluster._unique_labels):
p_centroids[ii,:]=np.mean(points[cluster._labels==ll,:],axis=0)
if p_centroids[0,0] > p_centroids[1,0]:
self.cluster_tags=['left','right']
chest_region=[3,2]
chest_type=[3,3]
else:
self.cluster_tags=['right','left']
chest_region=[2,3]
chest_type=[3,3]
append=vtk.vtkAppendPolyData()
for k,tag,cr,ct in zip([0,1],self.cluster_tags,chest_region,chest_type):
self._out_vtk[tag]=output_collection.GetItemAsObject(k)
chest_region_arr = vtk.vtkUnsignedCharArray()
chest_region_arr.SetName('ChestRegion')
chest_type_arr = vtk.vtkUnsignedCharArray()
chest_type_arr.SetName('ChestType')
n_p = self._out_vtk[tag].GetNumberOfPoints()
chest_region_arr.SetNumberOfTuples(n_p)
chest_type_arr.SetNumberOfTuples(n_p)
for ii in xrange(self._out_vtk[tag].GetNumberOfPoints()):
chest_region_arr.SetValue(ii,cr)
chest_type_arr.SetValue(ii,ct)
self._out_vtk[tag].GetPointData().AddArray(chest_region_arr)
self._out_vtk[tag].GetPointData().AddArray(chest_type_arr)
append.AddInput(self._out_vtk[tag])
append.Update()
self._out_vtk['all']=append.GetOutput()
return self._out_vtk
开发者ID:151706061,项目名称:ChestImagingPlatform,代码行数:45,代码来源:cluster_particles.py
示例17: initScalarArray
def initScalarArray(self):
"""Sets up scalar array describing tetrahedra values."""
self.scalar = vtk.vtkUnsignedCharArray()
self.scalar.SetNumberOfComponents(3)
self.scalar.SetName("Colors")
return self.scalar
开发者ID:alexblaessle,项目名称:PyFRAP,代码行数:9,代码来源:pyfrp_gui_vtk.py
示例18: colors_to_scalars
def colors_to_scalars(colors):
colorData = vtk.vtkUnsignedCharArray()
colorData.SetName("colors")
colorData.SetNumberOfComponents(3)
for color in colors:
colorData.InsertNextTuple3(*color)
return colorData
开发者ID:devarajun,项目名称:uvcdat,代码行数:9,代码来源:colorpicker.py
示例19: generate
def generate(self):
if self.actor is not None:
self.frame.ren.RemoveActor(self.actor)
self.pts = vtk.vtkPoints()
self.radii = vtk.vtkFloatArray()
self.radii.SetName('radii')
self.colors = vtk.vtkUnsignedCharArray()
self.colors.SetNumberOfComponents(3)
self.colors.SetName('colors')
# nodes
for k, node in self.K.items():
self.pts.InsertPoint(k, *node.pos)
self.radii.InsertTuple1(k, node.radius)
if self.color_tips_in_yellow and not node.children:
self.colors.InsertTuple3(k, *name_to_rgb('yellow'))
else:
self.colors.InsertTuple3(k, *name_to_rgb(self.base_color))
# edges
lines = vtk.vtkCellArray()
for k, node in self.K.items():
if node.parent is None: continue
lines.InsertNextCell(2)
lines.InsertCellPoint(k)
lines.InsertCellPoint(node.parent)
self.polydata = vtk.vtkPolyData()
self.polydata.SetPoints(self.pts)
self.polydata.SetLines(lines)
self.polydata.GetPointData().AddArray(self.radii)
self.polydata.GetPointData().AddArray(self.colors)
self.polydata.GetPointData().SetActiveScalars('radii')
self.tubes = vtk.vtkTubeFilter()
self.tubes.SetNumberOfSides(10)
if USING_VTK6:
self.tubes.SetInputData(self.polydata)
else:
self.tubes.SetInput(self.polydata)
self.tubes.SetVaryRadiusToVaryRadiusByAbsoluteScalar()
self.tubes.CappingOn()
self.mapper = vtk.vtkPolyDataMapper()
if self.show_volume:
if USING_VTK6:
self.mapper.SetInputConnection(self.tubes.GetOutputPort())
else:
self.mapper.SetInput(self.tubes.GetOutput())
else:
if USING_VTK6:
self.mapper.SetInputData(self.polydata)
else:
self.mapper.SetInput(self.polydata)
self.mapper.ScalarVisibilityOn()
self.mapper.SetScalarModeToUsePointFieldData()
self.mapper.SelectColorArray('colors')
self.actor = vtk.vtkActor()
self.actor.GetProperty().SetColor(name_to_rgb_float(self.base_color))
self.actor.SetMapper(self.mapper)
self.frame.ren.AddActor(self.actor)
self.frame.ren_win.Render()
开发者ID:cjauvin,项目名称:pypetree,代码行数:57,代码来源:world.py
示例20: unfoldData
def unfoldData():
inputDS = filter.GetInputDataObject(0, 0)
outputDS = filter.GetImageDataOutput()
dims = inputDS.GetDimensions()
# dims[1] * dims[2]
nbSlices = (dims[1] * dims[2]) / 2048
outputDS.SetDimensions(dims[0], dims[1] * dims[2] / nbSlices, nbSlices)
outputDS.SetOrigin(0,0,0)
outputDS.SetSpacing(1,1,1)
for arrayIdx in range(inputDS.GetPointData().GetNumberOfArrays()):
array = inputDS.GetPointData().GetArray(arrayIdx)
size = dims[0] * dims[1] * dims[2]
if not array.GetName() in fieldsRange:
continue
dataRangeToUser = fieldsRange[array.GetName()]
print "Process array: ", array.GetName()
rescale = 256.0 * 256.0 * 256.0 / (dataRangeToUser[1] - dataRangeToUser[0])
newArray = vtkUnsignedCharArray()
newArray.SetName(array.GetName())
newArray.SetNumberOfComponents(3)
newArray.SetNumberOfTuples(size)
outputDS.GetPointData().AddArray(newArray)
progress = int(size / 100)
count = 0
for idx in range(size):
value = array.GetValue(idx)
if value < dataRangeToUser[0]:
newArray.SetValue(idx * 3, 0)
newArray.SetValue(idx * 3 + 1, 0)
newArray.SetValue(idx * 3 + 2, 0)
elif value > dataRangeToUser[1]:
newArray.SetValue(idx * 3, 255)
newArray.SetValue(idx * 3 + 1, 255)
newArray.SetValue(idx * 3 + 2, 255)
else:
value = (value - dataRangeToUser[0]) * rescale
newArray.SetValue(idx * 3, int(value%256))
newArray.SetValue(idx * 3 + 1, int(value/256%256))
newArray.SetValue(idx * 3 + 2, int(value/256/256))
# if idx % progress == 0:
# count = count + 1
# print count
# # sys.stdout.write('.')
# # sys.stdout.flush()
# #sys. "\rProcessing %s: %d %s" % (array.GetName(), count, "/-\\|"[count%4])
print
开发者ID:Kitware,项目名称:cinema,代码行数:57,代码来源:mpas_time_vtk_python.py
注:本文中的vtk.vtkUnsignedCharArray函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论