Python vtk.vtkUnsignedCharArray() Examples
The following are 18
code examples of vtk.vtkUnsignedCharArray().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
vtk
, or try the search function
.
Example #1
Source File: vis.py From DeepV2D with BSD 3-Clause "New" or "Revised" License | 11 votes |
def create_pointcloud_polydata(points, colors=None): """https://github.com/lmb-freiburg/demon Creates a vtkPolyData object with the point cloud from numpy arrays points: numpy.ndarray pointcloud with shape (n,3) colors: numpy.ndarray uint8 array with colors for each point. shape is (n,3) Returns vtkPolyData object """ vpoints = vtk.vtkPoints() vpoints.SetNumberOfPoints(points.shape[0]) for i in range(points.shape[0]): vpoints.SetPoint(i, points[i]) vpoly = vtk.vtkPolyData() vpoly.SetPoints(vpoints) if not colors is None: vcolors = vtk.vtkUnsignedCharArray() vcolors.SetNumberOfComponents(3) vcolors.SetName("Colors") vcolors.SetNumberOfTuples(points.shape[0]) for i in range(points.shape[0]): vcolors.SetTuple3(i ,colors[i,0],colors[i,1], colors[i,2]) vpoly.GetPointData().SetScalars(vcolors) vcells = vtk.vtkCellArray() for i in range(points.shape[0]): vcells.InsertNextCell(1) vcells.InsertCellPoint(i) vpoly.SetVerts(vcells) return vpoly
Example #2
Source File: utility.py From ILCC with BSD 2-Clause "Simplified" License | 6 votes |
def draw_one_grd_vtk(ls): # arr:[a,b,c,d],a:orig, b, point1, c,point 2, d,color source = vtk.vtkPlaneSource() source.SetOrigin(ls[0]) source.SetPoint1(ls[1]) source.SetPoint2(ls[2]) source.Update() # source.SetPoint1(0, 0, 0) # source.SetPoint2(4, 3, 0) # mapper mapper = vtk.vtkPolyDataMapper() color = vtk.vtkUnsignedCharArray() color.SetName("colors") color.SetNumberOfComponents(3) # color_tup = np.random.randint(1, 255, 3) color.SetNumberOfTuples(source.GetOutput().GetNumberOfCells()) for i in xrange(source.GetOutput().GetNumberOfCells()): color_tup = np.array([255, 255, 255]) * ls[3] color.InsertTuple(i, color_tup) source.GetOutput().GetCellData().SetScalars(color) mapper.SetInputConnection(source.GetOutputPort()) # actor actor = vtk.vtkActor() actor.SetMapper(mapper) # assign actor to the renderer # ren.AddActor(actor) return actor # generate the color list of the point cloud for different color styles. intens_rg: color by reflectance intensity (red:high green:low), # intens: color by reflectance intensity (white:high back:low), autumn: matplotlib autumn color map, cool: matplotlib cool color map
Example #3
Source File: filters_test.py From PVGeo with BSD 3-Clause "New" or "Revised" License | 6 votes |
def test(self): """`ArraysToRGBA`: make sure no errors arise""" # create an input with three arrays that can be RGB r = np.random.randint(0, 255, 300) g = np.random.randint(0, 255, 300) b = np.random.randint(0, 255, 300) a = np.random.uniform(0, 1, 300) # now make it an arbirtray dataset df = pd.DataFrame(data=np.c_[r,g,b,r,g,b,a], columns=['x','y','z','R','G','B','A']) data = interface.points_to_poly_data(df) # Set up the algorithm colored = ArraysToRGBA().apply(data, 'R', 'G', 'B', 'A') # Make sure there is a new 'Colors' Array arr = colored.GetPointData().GetArray('Colors') self.assertTrue(isinstance(arr, vtk.vtkUnsignedCharArray)) return True ###############################################################################
Example #4
Source File: pointobject.py From Det3D with Apache License 2.0 | 5 votes |
def CreateAxesSimplified(self, length): "Create a simplified coordinate axes system with 3 lines" points = vtk.vtkPoints() lines = vtk.vtkCellArray() colors = vtk.vtkUnsignedCharArray() colors.SetNumberOfComponents(3) colors.SetName("Colors") ptIds = [None, None] end_points = length * np.eye(3) line_colors = 255 * np.eye(3, dtype="i") for i in range(3): ptIds[0] = points.InsertNextPoint([0, 0, 0]) ptIds[1] = points.InsertNextPoint(end_points[i]) lines.InsertNextCell(2, ptIds) colors.InsertNextTuple3(*line_colors[i]) colors.InsertNextTuple3(*line_colors[i]) # Add the lines to the polydata container self.pd = vtk.vtkPolyData() self.pd.SetPoints(points) self.pd.GetPointData().SetScalars(colors) self.pd.SetLines(lines) self.mapper = vtk.vtkPolyDataMapper() self.mapper.SetInputData(self.pd) self.mapper.Update() self.actor = vtk.vtkActor() self.actor.SetMapper(self.mapper)
Example #5
Source File: kinect3Dcould.py From python-urbanPlanning with MIT License | 5 votes |
def clearPoints(self): self.vtkPoints = vtk.vtkPoints() self.vtkCells = vtk.vtkCellArray() self.vtkDepth = vtk.vtkDoubleArray() self.vtkDepth.SetName('DepthArray') self.vtkPolyData.SetPoints(self.vtkPoints) self.vtkPolyData.SetVerts(self.vtkCells) self.vtkPolyData.GetPointData().SetScalars(self.vtkDepth) self.vtkPolyData.GetPointData().SetActiveScalars('DepthArray') self.Colors = vtk.vtkUnsignedCharArray() self.Colors.SetNumberOfComponents(3) self.Colors.SetName("Colors")
Example #6
Source File: gui_viewer.py From voxel-dcgan with MIT License | 5 votes |
def create_actor(self): self.points = vtk.vtkPoints() self.colors = vtk.vtkUnsignedCharArray() self.colors.SetName("colors") self.colors.SetNumberOfComponents(4) polydata = vtk.vtkPolyData() polydata.SetPoints(self.points) polydata.GetPointData().SetScalars(self.colors) # create cell voxel = self.create_voxel() self.glyph3D = vtk.vtkGlyph3D() self.glyph3D.SetColorModeToColorByScalar() self.glyph3D.SetSource(voxel.GetOutput()) self.glyph3D.SetInput(polydata) self.glyph3D.ScalingOff() self.glyph3D.Update() # mapper mapper = vtk.vtkPolyDataMapper() mapper.SetInput(self.glyph3D.GetOutput()) # actor self.actor = vtk.vtkActor() self.actor.SetMapper(mapper) self.actor.GetProperty().SetAmbient(0.15)
Example #7
Source File: util.py From sanet_relocal_demo with GNU General Public License v3.0 | 5 votes |
def create_pointcloud_polydata(points, colors=None): """Creates a vtkPolyData object with the point cloud from numpy arrays points: numpy.ndarray pointcloud with shape (n,3) colors: numpy.ndarray uint8 array with colors for each point. shape is (n,3) Returns vtkPolyData object """ import vtk vpoints = vtk.vtkPoints() vpoints.SetNumberOfPoints(points.shape[0]) for i in range(points.shape[0]): vpoints.SetPoint(i, points[i]) vpoly = vtk.vtkPolyData() vpoly.SetPoints(vpoints) if not colors is None: vcolors = vtk.vtkUnsignedCharArray() vcolors.SetNumberOfComponents(3) vcolors.SetName("Colors") vcolors.SetNumberOfTuples(points.shape[0]) for i in range(points.shape[0]): vcolors.SetTuple3(i ,colors[i,0],colors[i,1], colors[i,2]) vpoly.GetPointData().SetScalars(vcolors) vcells = vtk.vtkCellArray() for i in range(points.shape[0]): vcells.InsertNextCell(1) vcells.InsertCellPoint(i) vpoly.SetVerts(vcells) return vpoly
Example #8
Source File: viz.py From deep_gcns with MIT License | 5 votes |
def __init__(self, point_size=18, maxNumPoints=1e8): self.maxNumPoints = maxNumPoints self.vtkPolyData = vtk.vtkPolyData() self.clear_points() self.colors = vtk.vtkUnsignedCharArray() self.colors.SetNumberOfComponents(3) self.colors.SetName("Colors") mapper = vtk.vtkPolyDataMapper() mapper.SetInputData(self.vtkPolyData) self.vtkActor = vtk.vtkActor() self.vtkActor.SetMapper(mapper) self.vtkActor.GetProperty().SetPointSize(point_size)
Example #9
Source File: pc_viz.py From deep_gcns_torch with MIT License | 5 votes |
def __init__(self, point_size=18, maxNumPoints=1e8): self.maxNumPoints = maxNumPoints self.vtkPolyData = vtk.vtkPolyData() self.clear_points() self.colors = vtk.vtkUnsignedCharArray() self.colors.SetNumberOfComponents(3) self.colors.SetName("Colors") mapper = vtk.vtkPolyDataMapper() mapper.SetInputData(self.vtkPolyData) self.vtkActor = vtk.vtkActor() self.vtkActor.SetMapper(mapper) self.vtkActor.GetProperty().SetPointSize(point_size)
Example #10
Source File: viz.py From 3d-semantic-segmentation with MIT License | 5 votes |
def __init__(self, point_size=18, maxNumPoints=1e8): self.maxNumPoints = maxNumPoints self.vtkPolyData = vtk.vtkPolyData() self.clear_points() self.colors = vtk.vtkUnsignedCharArray() self.colors.SetNumberOfComponents(3) self.colors.SetName("Colors") mapper = vtk.vtkPolyDataMapper() mapper.SetInputData(self.vtkPolyData) self.vtkActor = vtk.vtkActor() self.vtkActor.SetMapper(mapper) self.vtkActor.GetProperty().SetPointSize(point_size)
Example #11
Source File: vis.py From demon with GNU General Public License v3.0 | 5 votes |
def create_pointcloud_polydata(points, colors=None): """Creates a vtkPolyData object with the point cloud from numpy arrays points: numpy.ndarray pointcloud with shape (n,3) colors: numpy.ndarray uint8 array with colors for each point. shape is (n,3) Returns vtkPolyData object """ import vtk vpoints = vtk.vtkPoints() vpoints.SetNumberOfPoints(points.shape[0]) for i in range(points.shape[0]): vpoints.SetPoint(i, points[i]) vpoly = vtk.vtkPolyData() vpoly.SetPoints(vpoints) if not colors is None: vcolors = vtk.vtkUnsignedCharArray() vcolors.SetNumberOfComponents(3) vcolors.SetName("Colors") vcolors.SetNumberOfTuples(points.shape[0]) for i in range(points.shape[0]): vcolors.SetTuple3(i ,colors[i,0],colors[i,1], colors[i,2]) vpoly.GetPointData().SetScalars(vcolors) vcells = vtk.vtkCellArray() for i in range(points.shape[0]): vcells.InsertNextCell(1) vcells.InsertCellPoint(i) vpoly.SetVerts(vcells) return vpoly
Example #12
Source File: gui_viewer.py From pix2vox with GNU General Public License v3.0 | 5 votes |
def create_actor(self): self.points = vtk.vtkPoints() self.colors = vtk.vtkUnsignedCharArray() self.colors.SetName("colors") self.colors.SetNumberOfComponents(4) polydata = vtk.vtkPolyData() polydata.SetPoints(self.points) polydata.GetPointData().SetScalars(self.colors) # create cell voxel = self.create_voxel() self.glyph3D = vtk.vtkGlyph3D() self.glyph3D.SetColorModeToColorByScalar() self.glyph3D.SetSource(voxel.GetOutput()) self.glyph3D.SetInput(polydata) self.glyph3D.ScalingOff() self.glyph3D.Update() # mapper mapper = vtk.vtkPolyDataMapper() mapper.SetInput(self.glyph3D.GetOutput()) # actor self.actor = vtk.vtkActor() self.actor.SetMapper(mapper) self.actor.GetProperty().SetAmbient(0.15)
Example #13
Source File: viz.py From vkitti3D-dataset with MIT License | 5 votes |
def __init__(self, zMin=-10.0, zMax=10.0, maxNumPoints=1e8): self.maxNumPoints = maxNumPoints self.vtkPolyData = vtk.vtkPolyData() self.clear_points() self.colors = vtk.vtkUnsignedCharArray() self.colors.SetNumberOfComponents(3) self.colors.SetName("Colors") mapper = vtk.vtkPolyDataMapper() mapper.SetInputData(self.vtkPolyData) self.vtkActor = vtk.vtkActor() self.vtkActor.SetMapper(mapper) self.vtkActor.GetProperty().SetPointSize(2)
Example #14
Source File: vtkVisualization.py From MOTSFusion with MIT License | 5 votes |
def __init__(self, points: np.ndarray=None, colors: np.ndarray=None): assert (points is None and colors is None) or (points is not None and colors is not None) self.num_points = 0 # VTK geometry representation self._points = vtk.vtkPoints() # VTK color representation self._colors = vtk.vtkUnsignedCharArray() self._colors.SetName("Colors") self._colors.SetNumberOfComponents(3) # Visualization pipeline # - Data source point_data = vtk.vtkPolyData() point_data.SetPoints(self._points) point_data.GetPointData().SetScalars(self._colors) # - Automatically generate topology cells from points mask_points = vtk.vtkMaskPoints() mask_points.SetInputData(point_data) mask_points.GenerateVerticesOn() mask_points.SingleVertexPerCellOn() mask_points.Update() # - Map the data representation to graphics primitives mapper = vtk.vtkPolyDataMapper() mapper.SetInputConnection(mask_points.GetOutputPort()) super().__init__(mapper) self.add_points(points, colors)
Example #15
Source File: utility.py From ILCC with BSD 2-Clause "Simplified" License | 5 votes |
def vis_pcd_color_arr(array_data, color_arr=[46, 204, 113]): all_rows = array_data.shape[0] Colors = vtk.vtkUnsignedCharArray() Colors.SetNumberOfComponents(3) Colors.SetName("Colors") Points = vtk.vtkPoints() Vertices = vtk.vtkCellArray() for k in xrange(all_rows): point = array_data[k, :] id = Points.InsertNextPoint(point[0], point[1], point[2]) Vertices.InsertNextCell(1) Vertices.InsertCellPoint(id) if vtk.VTK_MAJOR_VERSION >= 7: Colors.InsertNextTuple(color_arr) else: Colors.InsertNextTupleValue(color_arr) polydata = vtk.vtkPolyData() polydata.SetPoints(Points) polydata.SetVerts(Vertices) polydata.GetPointData().SetScalars(Colors) polydata.Modified() mapper = vtk.vtkPolyDataMapper() if vtk.VTK_MAJOR_VERSION <= 5: mapper.SetInput(polydata) else: mapper.SetInputData(polydata) mapper.SetColorModeToDefault() actor = vtk.vtkActor() actor.SetMapper(mapper) actor.GetProperty().SetPointSize(10) return actor # visualize with actor:
Example #16
Source File: utility.py From ILCC with BSD 2-Clause "Simplified" License | 5 votes |
def vis_3D_points(full_lidar_arr, color_style="intens_rg"): all_rows = full_lidar_arr.shape[0] Colors = vtk.vtkUnsignedCharArray() Colors.SetNumberOfComponents(3) Colors.SetName("Colors") Points = vtk.vtkPoints() Vertices = vtk.vtkCellArray() tuple_ls = gen_color_tup_for_vis(color_style, xyzi_arr=full_lidar_arr) for k in xrange(all_rows): point = full_lidar_arr[k, :3] id = Points.InsertNextPoint(point[0], point[1], point[2]) Vertices.InsertNextCell(1) Vertices.InsertCellPoint(id) rgb_tuple = tuple_ls[k] if vtk.VTK_MAJOR_VERSION >= 7: Colors.InsertNextTuple(rgb_tuple) else: Colors.InsertNextTupleValue(rgb_tuple) polydata = vtk.vtkPolyData() polydata.SetPoints(Points) polydata.SetVerts(Vertices) polydata.GetPointData().SetScalars(Colors) polydata.Modified() mapper = vtk.vtkPolyDataMapper() if vtk.VTK_MAJOR_VERSION < 6: mapper.SetInput(polydata) else: mapper.SetInputData(polydata) mapper.SetColorModeToDefault() actor = vtk.vtkActor() actor.SetMapper(mapper) actor.GetProperty().SetPointSize(8) return actor # visualize 3D points with specified color array
Example #17
Source File: visualization.py From CityEnergyAnalyst with MIT License | 4 votes |
def xy_axis(apoints_path): # print a green y-positive and a x-positive line in the centre sensor = pd.read_csv(apoints_path) mid_x = sensor[['sen_x']].mean(axis=0) mid_y = sensor[['sen_y']].mean(axis=0) mid_z = sensor[['sen_z']].mean(axis=0) min_z = sensor[['sen_z']].min(axis=0) max_x = sensor[['sen_x']].max(axis=0) max_y = sensor[['sen_y']].max(axis=0) pts = vtk.vtkPoints() pts.InsertNextPoint([mid_x, mid_y, min_z]) pts.InsertNextPoint([max_x, mid_y, min_z]) pts.InsertNextPoint([mid_x, max_y, min_z]) # Setup two colors - one for each line red = [255, 0, 0] green = [0, 255, 0] colors = vtk.vtkUnsignedCharArray() colors.SetNumberOfComponents(3) colors.SetName("Colors") colors.InsertNextTupleValue(red) colors.InsertNextTupleValue(green) line0 = vtk.vtkLine() line0.GetPointIds().SetId(0, 0) line0.GetPointIds().SetId(1, 1) line1 = vtk.vtkLine() line1.GetPointIds().SetId(0, 0) line1.GetPointIds().SetId(1, 2) lines = vtk.vtkCellArray() lines.InsertNextCell(line0) lines.InsertNextCell(line1) linespolydata = vtk.vtkPolyData() linespolydata.SetPoints(pts) linespolydata.SetLines(lines) linespolydata.GetCellData().SetScalars(colors) mapper = vtk.vtkPolyDataMapper() mapper.SetInput(linespolydata) actor = vtk.vtkActor() actor.SetMapper(mapper) mid_point = [mid_x, mid_y, mid_z] return actor, mid_point
Example #18
Source File: pcd_corners_est.py From ILCC with BSD 2-Clause "Simplified" License | 4 votes |
def show_pcd_ndarray(array_data, color_arr=[0, 255, 0]): all_rows = array_data.shape[0] Colors = vtk.vtkUnsignedCharArray() Colors.SetNumberOfComponents(3) Colors.SetName("Colors") Points = vtk.vtkPoints() Vertices = vtk.vtkCellArray() for k in xrange(all_rows): point = array_data[k, :] id = Points.InsertNextPoint(point[0], point[1], point[2]) Vertices.InsertNextCell(1) Vertices.InsertCellPoint(id) if vtk.VTK_MAJOR_VERSION > 6: Colors.InsertNextTuple(color_arr) else: Colors.InsertNextTupleValue(color_arr) dis_tmp = np.sqrt((point ** 2).sum(0)) # Colors.InsertNextTupleValue([0,255-dis_tmp/max_dist*255,0]) # Colors.InsertNextTupleValue([255-abs(point[0]/x_max*255),255-abs(point[1]/y_max*255),255-abs(point[2]/z_max*255)]) # Colors.InsertNextTupleValue([255-abs(point[0]/x_max*255),255,255]) polydata = vtk.vtkPolyData() polydata.SetPoints(Points) polydata.SetVerts(Vertices) polydata.GetPointData().SetScalars(Colors) polydata.Modified() mapper = vtk.vtkPolyDataMapper() if vtk.VTK_MAJOR_VERSION <= 5: mapper.SetInput(polydata) else: mapper.SetInputData(polydata) mapper.SetColorModeToDefault() actor = vtk.vtkActor() actor.SetMapper(mapper) actor.GetProperty().SetPointSize(5) # Renderer renderer = vtk.vtkRenderer() renderer.AddActor(actor) renderer.SetBackground(.2, .3, .4) renderer.ResetCamera() # Render Window renderWindow = vtk.vtkRenderWindow() renderWindow.AddRenderer(renderer) # Interactor renderWindowInteractor = vtk.vtkRenderWindowInteractor() renderWindowInteractor.SetRenderWindow(renderWindow) # Begin Interaction renderWindow.Render() renderWindowInteractor.Start() # determine whether a segment is the potential chessboard's point cloud