Python vtk.vtkIdList() Examples
The following are 11
code examples of vtk.vtkIdList().
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: mesh.py From OpenWARP with Apache License 2.0 | 6 votes |
def _mk_vtk_id_list(it): ''' Internal function to make vtk id list object Parameters: it : list List of nodes that define a face Returns: vil: vtkIdList A vtkIdList object ''' vil = vtk.vtkIdList() for i in it: vil.InsertNextId(int(i)) return vil
Example #2
Source File: mesh.py From OpenWARP with Apache License 2.0 | 6 votes |
def _mk_vtk_id_list(it): ''' Internal function to make vtk id list object Parameters: it : list List of nodes that define a face Returns: vil: vtkIdList A vtkIdList object ''' vil = vtk.vtkIdList() for i in it: vil.InsertNextId(int(i)) return vil
Example #3
Source File: mesh.py From OpenWARP with Apache License 2.0 | 6 votes |
def _mk_vtk_id_list(it): ''' Internal function to make vtk id list object Parameters: it : list List of nodes that define a face Returns: vil: vtkIdList A vtkIdList object ''' vil = vtk.vtkIdList() for i in it: vil.InsertNextId(int(i)) return vil
Example #4
Source File: mesh.py From OpenWARP with Apache License 2.0 | 6 votes |
def _mk_vtk_id_list(it): ''' Internal function to make vtk id list object Parameters: it : list List of nodes that define a face Returns: vil: vtkIdList A vtkIdList object ''' vil = vtk.vtkIdList() for i in it: vil.InsertNextId(int(i)) return vil
Example #5
Source File: base.py From BrainSpace with BSD 3-Clause "New" or "Revised" License | 5 votes |
def wrap_vtk_array(a): if isinstance(a, vtk.vtkIdList): return _idlist_to_numpy(a) if isinstance(a, (vtk.vtkStringArray, vtk.vtkUnicodeStringArray)): return _string_to_numpy(a) if isinstance(a, vtk.vtkVariantArray): return _variant_to_numpy(a) if isinstance(a, vtk.vtkDataArray): return dsa.vtkDataArrayToVTKArray(a) raise ValueError('Unsupported array type: {0}'.format(type(a)))
Example #6
Source File: base.py From BrainSpace with BSD 3-Clause "New" or "Revised" License | 5 votes |
def wrap_vtk(obj, **kwargs): """Wrap input object to BSVTKObjectWrapper or one of its subclasses. Parameters ---------- obj : vtkObject or BSVTKObjectWrapper Input object. kwargs : kwds, optional Additional keyword parameters are passed to vtk object. Returns ------- wrapper : BSVTKObjectWrapper The wrapped object. """ wobj = BSWrapVTKObject(obj) if len(kwargs) > 0: wobj.setVTK(**kwargs) if isinstance(obj, (vtk.vtkAbstractArray, vtk.vtkIdList)): try: return wrap_vtk_array(obj) except: pass return wobj
Example #7
Source File: vtkPointSetNormalsEstimation.py From pcloudpy with BSD 3-Clause "New" or "Revised" License | 5 votes |
def update(self): normalArray = vtkFloatArray() normalArray.SetNumberOfComponents( 3 ) normalArray.SetNumberOfTuples( self.input_.GetNumberOfPoints() ) normalArray.SetName( "Normals" ) kDTree = vtkKdTree() kDTree.BuildLocatorFromPoints(self.input_.GetPoints()) # Estimate the normal at each point. for pointId in xrange(0, self.input_.GetNumberOfPoints()): point = [0,0,0] self.input_.GetPoint(pointId, point) neighborIds = vtkIdList() if self.mode == FIXED_NUMBER: kDTree.FindClosestNPoints(self.number_neighbors, point, neighborIds) elif self.mode == RADIUS: kDTree.FindPointsWithinRadius(self.radius, point, neighborIds) #If there are not at least 3 points within the specified radius (the current # #point gets included in the neighbors set), a plane is not defined. Instead, # #force it to use 3 points. if neighborIds.GetNumberOfIds() < 3 : kDTree.FindClosestNPoints(3, point, neighborIds) bestPlane = vtkPlane() self.best_fit_plane(self.input_.GetPoints(), bestPlane, neighborIds) normal = bestPlane.GetNormal() normalArray.SetTuple( pointId, normal ) self.output_ = vtkPolyData() self.output_.ShallowCopy(self.input_) self.output_.GetPointData().SetNormals(normalArray)
Example #8
Source File: test_utilities.py From pyvista with MIT License | 5 votes |
def test_convert_id_list(): ids = np.array([4, 5, 8]) id_list = vtk.vtkIdList() id_list.SetNumberOfIds(len(ids)) for i, v in enumerate(ids): id_list.SetId(i, v) converted = helpers.vtk_id_list_to_array(id_list) assert np.allclose(converted, ids)
Example #9
Source File: common.py From pyvista with MIT License | 5 votes |
def find_closest_point(self, point, n=1): """Find index of closest point in this mesh to the given point. If wanting to query many points, use a KDTree with scipy or another library as those implementations will be easier to work with. See: https://github.com/pyvista/pyvista-support/issues/107 Parameters ---------- point : iterable(float) Length 3 coordinate of the point to query. n : int, optional If greater than ``1``, returns the indices of the ``n`` closest points. Return ------ int : the index of the point in this mesh that is closes to the given point. """ if not isinstance(point, (np.ndarray, collections.abc.Sequence)) or len(point) != 3: raise TypeError("Given point must be a length three sequence.") if not isinstance(n, int): raise TypeError("`n` must be a positive integer.") if n < 1: raise ValueError("`n` must be a positive integer.") locator = vtk.vtkPointLocator() locator.SetDataSet(self) locator.BuildLocator() if n < 2: index = locator.FindClosestPoint(point) else: id_list = vtk.vtkIdList() locator.FindClosestNPoints(n, point, id_list) index = vtk_id_list_to_array(id_list) return index
Example #10
Source File: show_lidar_vtk.py From Det3D with Apache License 2.0 | 5 votes |
def mkVtkIdList(it): vil = vtk.vtkIdList() for i in it: vil.InsertNextId(int(i)) return vil
Example #11
Source File: plot_cosipy_fields_vtk.py From cosipy with GNU General Public License v3.0 | 4 votes |
def add_scalar(var, timestamp): vtkFile = vtk.vtkXMLUnstructuredGridReader() vtkFile.SetFileName('cosipy.vtu') vtkFile.Update() # Find cellId by coordinates pointLocator = vtk.vtkPointLocator() pointLocator.SetDataSet(vtkFile.GetOutput()) pointLocator.BuildLocator() ds = xr.open_dataset('../data/output/Peru_20160601-20180530_comp4.nc') ds = ds.sel(time=timestamp) ds_sub = ds[var].stack(x=['south_north','west_east']) ds_sub = ds_sub.dropna(dim='x') lats = ds_sub.x.lat.values lons = ds_sub.x.lon.values data = ds_sub.values print(lats) numPoints = vtkFile.GetOutput().GetNumberOfPoints() scalar = np.empty(numPoints) scalar[:] = np.nan interpField = numpy_support.numpy_to_vtk(scalar) interpField.SetName(var) vtkFile.GetOutput().GetPointData().AddArray(interpField) vtkFile.Update() print('Write points \n') for i in np.arange(len(data)): # Get height alt = ds.HGT.sel(lat=lats[i],lon=lons[i]).values/6370000.0 pointId = vtk.mutable(0) Id = vtk.vtkIdList() pointId = pointLocator.FindClosestPoint([lons[i],lats[i],alt]) vtkFile.GetOutput().GetPointData().GetArray(var).InsertTuple1(pointId,data[i]) writer = vtk.vtkXMLUnstructuredGridWriter() writer.SetFileName('cosipy.vtu') writer.SetInputData(vtkFile.GetOutput()) writer.Write() #plotSurface(vtkFile)