idx int64 0 63k | question stringlengths 61 4.03k | target stringlengths 6 1.23k |
|---|---|---|
28,700 | def warp_by_scalar ( dataset , scalars = None , scale_factor = 1.0 , normal = None , inplace = False ) : if scalars is None : field , scalars = dataset . active_scalar_info arr , field = get_scalar ( dataset , scalars , preference = 'point' , info = True ) if field != vtki . POINT_DATA_FIELD : raise AssertionError ( 'D... | Warp the dataset s points by a point data scalar array s values . This modifies point coordinates by moving points along point normals by the scalar amount times the scale factor . |
28,701 | def delaunay_3d ( dataset , alpha = 0 , tol = 0.001 , offset = 2.5 ) : alg = vtk . vtkDelaunay3D ( ) alg . SetInputData ( dataset ) alg . SetAlpha ( alpha ) alg . SetTolerance ( tol ) alg . SetOffset ( offset ) alg . Update ( ) return _get_output ( alg ) | Constructs a 3D Delaunay triangulation of the mesh . This helps smooth out a rugged mesh . |
28,702 | def _load_file ( self , filename ) : filename = os . path . abspath ( os . path . expanduser ( filename ) ) if not os . path . isfile ( filename ) : raise Exception ( 'File %s does not exist' % filename ) ext = vtki . get_ext ( filename ) if ext == '.ply' : reader = vtk . vtkPLYReader ( ) elif ext == '.stl' : reader = ... | Load a surface mesh from a mesh file . |
28,703 | def faces ( self , faces ) : if faces . dtype != vtki . ID_TYPE : faces = faces . astype ( vtki . ID_TYPE ) if faces . ndim == 1 : log . debug ( 'efficiency warning' ) c = 0 nfaces = 0 while c < faces . size : c += faces [ c ] + 1 nfaces += 1 else : nfaces = faces . shape [ 0 ] vtkcells = vtk . vtkCellArray ( ) vtkcell... | set faces without copying |
28,704 | def _from_arrays ( self , vertices , faces , deep = True , verts = False ) : if deep or verts : vtkpoints = vtk . vtkPoints ( ) vtkpoints . SetData ( numpy_to_vtk ( vertices , deep = deep ) ) self . SetPoints ( vtkpoints ) vtkcells = vtk . vtkCellArray ( ) if faces . dtype != vtki . ID_TYPE : faces = faces . astype ( v... | Set polygons and points from numpy arrays |
28,705 | def edge_mask ( self , angle ) : self . point_arrays [ 'point_ind' ] = np . arange ( self . n_points ) featureEdges = vtk . vtkFeatureEdges ( ) featureEdges . SetInputData ( self ) featureEdges . FeatureEdgesOn ( ) featureEdges . BoundaryEdgesOff ( ) featureEdges . NonManifoldEdgesOff ( ) featureEdges . ManifoldEdgesOf... | Returns a mask of the points of a surface mesh that have a surface angle greater than angle |
28,706 | def boolean_cut ( self , cut , tolerance = 1E-5 , inplace = False ) : bfilter = vtk . vtkBooleanOperationPolyDataFilter ( ) bfilter . SetOperationToIntersection ( ) bfilter . SetInputData ( 1 , cut ) bfilter . SetInputData ( 0 , self ) bfilter . ReorientDifferenceCellsOff ( ) bfilter . SetTolerance ( tolerance ) bfilte... | Performs a Boolean cut using another mesh . |
28,707 | def boolean_add ( self , mesh , inplace = False ) : vtkappend = vtk . vtkAppendPolyData ( ) vtkappend . AddInputData ( self ) vtkappend . AddInputData ( mesh ) vtkappend . Update ( ) mesh = _get_output ( vtkappend ) if inplace : self . overwrite ( mesh ) else : return mesh | Add a mesh to the current mesh . Does not attempt to join the meshes . |
28,708 | def boolean_union ( self , mesh , inplace = False ) : bfilter = vtk . vtkBooleanOperationPolyDataFilter ( ) bfilter . SetOperationToUnion ( ) bfilter . SetInputData ( 1 , mesh ) bfilter . SetInputData ( 0 , self ) bfilter . ReorientDifferenceCellsOff ( ) bfilter . Update ( ) mesh = _get_output ( bfilter ) if inplace : ... | Combines two meshes and attempts to create a manifold mesh . |
28,709 | def boolean_difference ( self , mesh , inplace = False ) : bfilter = vtk . vtkBooleanOperationPolyDataFilter ( ) bfilter . SetOperationToDifference ( ) bfilter . SetInputData ( 1 , mesh ) bfilter . SetInputData ( 0 , self ) bfilter . ReorientDifferenceCellsOff ( ) bfilter . Update ( ) mesh = _get_output ( bfilter ) if ... | Combines two meshes and retains only the volume in common between the meshes . |
28,710 | def curvature ( self , curv_type = 'mean' ) : curv_type = curv_type . lower ( ) curvefilter = vtk . vtkCurvatures ( ) curvefilter . SetInputData ( self ) if curv_type == 'mean' : curvefilter . SetCurvatureTypeToMean ( ) elif curv_type == 'gaussian' : curvefilter . SetCurvatureTypeToGaussian ( ) elif curv_type == 'maxim... | Returns the pointwise curvature of a mesh |
28,711 | def smooth ( self , n_iter = 20 , convergence = 0.0 , edge_angle = 15 , feature_angle = 45 , boundary_smoothing = True , feature_smoothing = False , inplace = False ) : alg = vtk . vtkSmoothPolyDataFilter ( ) alg . SetInputData ( self ) alg . SetNumberOfIterations ( n_iter ) alg . SetConvergence ( convergence ) alg . S... | Adjust point coordinates using Laplacian smoothing . The effect is to relax the mesh making the cells better shaped and the vertices more evenly distributed . |
28,712 | def decimate_pro ( self , reduction , feature_angle = 45.0 , split_angle = 75.0 , splitting = True , pre_split_mesh = False , preserve_topology = False , inplace = False ) : alg = vtk . vtkDecimatePro ( ) alg . SetInputData ( self ) alg . SetTargetReduction ( reduction ) alg . SetPreserveTopology ( preserve_topology ) ... | Reduce the number of triangles in a triangular mesh forming a good approximation to the original geometry . Based on the algorithm originally described in Decimation of Triangle Meshes Proc Siggraph 92 . |
28,713 | def tube ( self , radius = None , scalars = None , capping = True , n_sides = 20 , radius_factor = 10 , preference = 'point' , inplace = False ) : if n_sides < 3 : n_sides = 3 tube = vtk . vtkTubeFilter ( ) tube . SetInputDataObject ( self ) tube . SetCapping ( capping ) if radius is not None : tube . SetRadius ( radiu... | Generate a tube around each input line . The radius of the tube can be set to linearly vary with a scalar value . |
28,714 | def subdivide ( self , nsub , subfilter = 'linear' , inplace = False ) : subfilter = subfilter . lower ( ) if subfilter == 'linear' : sfilter = vtk . vtkLinearSubdivisionFilter ( ) elif subfilter == 'butterfly' : sfilter = vtk . vtkButterflySubdivisionFilter ( ) elif subfilter == 'loop' : sfilter = vtk . vtkLoopSubdivi... | Increase the number of triangles in a single connected triangular mesh . |
28,715 | def extract_edges ( self , feature_angle = 30 , boundary_edges = True , non_manifold_edges = True , feature_edges = True , manifold_edges = True , inplace = False ) : featureEdges = vtk . vtkFeatureEdges ( ) featureEdges . SetInputData ( self ) featureEdges . SetFeatureAngle ( feature_angle ) featureEdges . SetManifold... | Extracts edges from a surface . From vtk documentation the edges are one of the following |
28,716 | def decimate ( self , target_reduction , volume_preservation = False , attribute_error = False , scalars = True , vectors = True , normals = False , tcoords = True , tensors = True , scalars_weight = 0.1 , vectors_weight = 0.1 , normals_weight = 0.1 , tcoords_weight = 0.1 , tensors_weight = 0.1 , inplace = False ) : de... | Reduces the number of triangles in a triangular mesh using vtkQuadricDecimation . |
28,717 | def center_of_mass ( self , scalars_weight = False ) : comfilter = vtk . vtkCenterOfMass ( ) comfilter . SetInputData ( self ) comfilter . SetUseScalarsAsWeights ( scalars_weight ) comfilter . Update ( ) return np . array ( comfilter . GetCenter ( ) ) | Returns the coordinates for the center of mass of the mesh . |
28,718 | def clip_with_plane ( self , origin , normal , value = 0 , inplace = False ) : plane = vtk . vtkPlane ( ) plane . SetOrigin ( origin ) plane . SetNormal ( normal ) plane . Modified ( ) clip = vtk . vtkClipPolyData ( ) clip . SetValue ( value ) clip . GenerateClippedOutputOn ( ) clip . SetClipFunction ( plane ) clip . S... | Clip a vtki . PolyData or vtk . vtkPolyData with a plane . |
28,719 | def extract_largest ( self , inplace = False ) : mesh = self . connectivity ( largest = True ) if inplace : self . overwrite ( mesh ) else : return mesh | Extract largest connected set in mesh . |
28,720 | def fill_holes ( self , hole_size , inplace = False ) : logging . warning ( 'vtki.pointset.PolyData.fill_holes is known to segfault. ' + 'Use at your own risk' ) fill = vtk . vtkFillHolesFilter ( ) fill . SetHoleSize ( hole_size ) fill . SetInputData ( self ) fill . Update ( ) mesh = _get_output ( fill ) if inplace : s... | Fill holes in a vtki . PolyData or vtk . vtkPolyData object . |
28,721 | def area ( self ) : mprop = vtk . vtkMassProperties ( ) mprop . SetInputData ( self ) return mprop . GetSurfaceArea ( ) | Mesh surface area |
28,722 | def geodesic ( self , start_vertex , end_vertex , inplace = False ) : if start_vertex < 0 or end_vertex > self . n_points - 1 : raise IndexError ( 'Invalid indices.' ) dijkstra = vtk . vtkDijkstraGraphGeodesicPath ( ) dijkstra . SetInputData ( self ) dijkstra . SetStartVertex ( start_vertex ) dijkstra . SetEndVertex ( ... | Calculates the geodesic path betweeen two vertices using Dijkstra s algorithm . |
28,723 | def geodesic_distance ( self , start_vertex , end_vertex ) : length = self . geodesic ( start_vertex , end_vertex ) . GetLength ( ) return length | Calculates the geodesic distance betweeen two vertices using Dijkstra s algorithm . |
28,724 | def ray_trace ( self , origin , end_point , first_point = False , plot = False , off_screen = False ) : points = vtk . vtkPoints ( ) cell_ids = vtk . vtkIdList ( ) code = self . obbTree . IntersectWithLine ( np . array ( origin ) , np . array ( end_point ) , points , cell_ids ) intersection_points = vtk_to_numpy ( poin... | Performs a single ray trace calculation given a mesh and a line segment defined by an origin and end_point . |
28,725 | def plot_boundaries ( self , ** kwargs ) : edges = self . extract_edges ( ) plotter = vtki . Plotter ( off_screen = kwargs . pop ( 'off_screen' , False ) , notebook = kwargs . pop ( 'notebook' , None ) ) plotter . add_mesh ( edges , 'r' , style = 'wireframe' , legend = 'Edges' ) plotter . add_mesh ( self , legend = 'Me... | Plots boundaries of a mesh |
28,726 | def plot_normals ( self , show_mesh = True , mag = 1.0 , flip = False , use_every = 1 , ** kwargs ) : plotter = vtki . Plotter ( off_screen = kwargs . pop ( 'off_screen' , False ) , notebook = kwargs . pop ( 'notebook' , None ) ) if show_mesh : plotter . add_mesh ( self , ** kwargs ) normals = self . point_normals if f... | Plot the point normals of a mesh . |
28,727 | def remove_points ( self , remove , mode = 'any' , keep_scalars = True , inplace = False ) : if isinstance ( remove , list ) : remove = np . asarray ( remove ) if remove . dtype == np . bool : if remove . size != self . n_points : raise AssertionError ( 'Mask different size than n_points' ) remove_mask = remove else : ... | Rebuild a mesh by removing points . Only valid for all - triangle meshes . |
28,728 | def flip_normals ( self ) : if self . faces . size % 4 : raise Exception ( 'Can only flip normals on an all triangular mesh' ) f = self . faces . reshape ( ( - 1 , 4 ) ) f [ : , 1 : ] = f [ : , 1 : ] [ : , : : - 1 ] | Flip normals of a triangular mesh by reversing the point ordering . |
28,729 | def delaunay_2d ( self , tol = 1e-05 , alpha = 0.0 , offset = 1.0 , bound = False , inplace = False ) : alg = vtk . vtkDelaunay2D ( ) alg . SetProjectionPlaneMode ( vtk . VTK_BEST_FITTING_PLANE ) alg . SetInputDataObject ( self ) alg . SetTolerance ( tol ) alg . SetAlpha ( alpha ) alg . SetOffset ( offset ) alg . SetBo... | Apply a delaunay 2D filter along the best fitting plane |
28,730 | def plot_curvature ( self , curv_type = 'mean' , ** kwargs ) : trisurf = self . extract_surface ( ) . tri_filter ( ) return trisurf . plot_curvature ( curv_type , ** kwargs ) | Plots the curvature of the external surface of the grid |
28,731 | def extract_surface ( self , pass_pointid = True , pass_cellid = True , inplace = False ) : surf_filter = vtk . vtkDataSetSurfaceFilter ( ) surf_filter . SetInputData ( self ) if pass_pointid : surf_filter . PassThroughCellIdsOn ( ) if pass_cellid : surf_filter . PassThroughPointIdsOn ( ) surf_filter . Update ( ) mesh ... | Extract surface mesh of the grid |
28,732 | def _from_arrays ( self , offset , cells , cell_type , points , deep = True ) : if offset . dtype != vtki . ID_TYPE : offset = offset . astype ( vtki . ID_TYPE ) if cells . dtype != vtki . ID_TYPE : cells = cells . astype ( vtki . ID_TYPE ) if not cells . flags [ 'C_CONTIGUOUS' ] : cells = np . ascontiguousarray ( cell... | Create VTK unstructured grid from numpy arrays |
28,733 | def _load_file ( self , filename ) : filename = os . path . abspath ( os . path . expanduser ( filename ) ) if not os . path . isfile ( filename ) : raise Exception ( '%s does not exist' % filename ) if '.vtu' in filename : reader = vtk . vtkXMLUnstructuredGridReader ( ) elif '.vtk' in filename : reader = vtk . vtkUnst... | Load an unstructured grid from a file . |
28,734 | def linear_copy ( self , deep = False ) : lgrid = self . copy ( deep ) vtk_cell_type = numpy_to_vtk ( self . GetCellTypesArray ( ) , deep = True ) celltype = vtk_to_numpy ( vtk_cell_type ) celltype [ celltype == VTK_QUADRATIC_TETRA ] = VTK_TETRA celltype [ celltype == VTK_QUADRATIC_PYRAMID ] = VTK_PYRAMID celltype [ ce... | Returns a copy of the input unstructured grid containing only linear cells . Converts the following cell types to their linear equivalents . |
28,735 | def extract_cells ( self , ind ) : if not isinstance ( ind , np . ndarray ) : ind = np . array ( ind , np . ndarray ) if ind . dtype == np . bool : ind = ind . nonzero ( ) [ 0 ] . astype ( vtki . ID_TYPE ) if ind . dtype != vtki . ID_TYPE : ind = ind . astype ( vtki . ID_TYPE ) if not ind . flags . c_contiguous : ind =... | Returns a subset of the grid |
28,736 | def merge ( self , grid = None , merge_points = True , inplace = False , main_has_priority = True ) : append_filter = vtk . vtkAppendFilter ( ) append_filter . SetMergePoints ( merge_points ) if not main_has_priority : append_filter . AddInputData ( self ) if isinstance ( grid , vtki . UnstructuredGrid ) : append_filte... | Join one or many other grids to this grid . Grid is updated in - place by default . |
28,737 | def delaunay_2d ( self , tol = 1e-05 , alpha = 0.0 , offset = 1.0 , bound = False ) : return PolyData ( self . points ) . delaunay_2d ( tol = tol , alpha = alpha , offset = offset , bound = bound ) | Apply a delaunay 2D filter along the best fitting plane . This extracts the grid s points and perfoms the triangulation on those alone . |
28,738 | def _from_arrays ( self , x , y , z ) : if not ( x . shape == y . shape == z . shape ) : raise Exception ( 'Input point array shapes must match exactly' ) points = np . empty ( ( x . size , 3 ) , x . dtype ) points [ : , 0 ] = x . ravel ( 'F' ) points [ : , 1 ] = y . ravel ( 'F' ) points [ : , 2 ] = z . ravel ( 'F' ) d... | Create VTK structured grid directly from numpy arrays . |
28,739 | def save ( self , filename , binary = True ) : filename = os . path . abspath ( os . path . expanduser ( filename ) ) if '.vtk' in filename : writer = vtk . vtkStructuredGridWriter ( ) if binary : writer . SetFileTypeToBinary ( ) else : writer . SetFileTypeToASCII ( ) elif '.vts' in filename : writer = vtk . vtkXMLStru... | Writes a structured grid to disk . |
28,740 | def dimensions ( self , dims ) : nx , ny , nz = dims [ 0 ] , dims [ 1 ] , dims [ 2 ] self . SetDimensions ( nx , ny , nz ) self . Modified ( ) | Sets the dataset dimensions . Pass a length three tuple of integers |
28,741 | def _from_arrays ( self , x , y , z ) : x = np . unique ( x . ravel ( ) ) y = np . unique ( y . ravel ( ) ) z = np . unique ( z . ravel ( ) ) self . SetDimensions ( len ( x ) , len ( y ) , len ( z ) ) self . SetXCoordinates ( numpy_to_vtk ( x ) ) self . SetYCoordinates ( numpy_to_vtk ( y ) ) self . SetZCoordinates ( nu... | Create VTK rectilinear grid directly from numpy arrays . Each array gives the uniques coordinates of the mesh along each axial direction . To help ensure you are using this correctly we take the unique values of each argument . |
28,742 | def _load_file ( self , filename ) : filename = os . path . abspath ( os . path . expanduser ( filename ) ) if not os . path . isfile ( filename ) : raise Exception ( '{} does not exist' . format ( filename ) ) if '.vtr' in filename : legacy_writer = False elif '.vtk' in filename : legacy_writer = True else : raise Exc... | Load a rectilinear grid from a file . |
28,743 | def save ( self , filename , binary = True ) : filename = os . path . abspath ( os . path . expanduser ( filename ) ) if '.vtk' in filename : writer = vtk . vtkRectilinearGridWriter ( ) legacy = True elif '.vtr' in filename : writer = vtk . vtkXMLRectilinearGridWriter ( ) legacy = False else : raise Exception ( 'Extens... | Writes a rectilinear grid to disk . |
28,744 | def origin ( self , origin ) : ox , oy , oz = origin [ 0 ] , origin [ 1 ] , origin [ 2 ] self . SetOrigin ( ox , oy , oz ) self . Modified ( ) | Set the origin . Pass a length three tuple of floats |
28,745 | def spacing ( self , spacing ) : dx , dy , dz = spacing [ 0 ] , spacing [ 1 ] , spacing [ 2 ] self . SetSpacing ( dx , dy , dz ) self . Modified ( ) | Set the spacing in each axial direction . Pass a length three tuple of floats |
28,746 | def resample_image ( arr , max_size = 400 ) : dim = np . max ( arr . shape [ 0 : 2 ] ) if dim < max_size : max_size = dim x , y , _ = arr . shape sx = int ( np . ceil ( x / max_size ) ) sy = int ( np . ceil ( y / max_size ) ) img = np . zeros ( ( max_size , max_size , 3 ) , dtype = arr . dtype ) arr = arr [ 0 : - 1 : s... | Resamples a square image to an image of max_size |
28,747 | def pad_image ( arr , max_size = 400 ) : dim = np . max ( arr . shape ) img = np . zeros ( ( dim , dim , 3 ) , dtype = arr . dtype ) xl = ( dim - arr . shape [ 0 ] ) // 2 yl = ( dim - arr . shape [ 1 ] ) // 2 img [ xl : arr . shape [ 0 ] + xl , yl : arr . shape [ 1 ] + yl , : ] = arr return resample_image ( img , max_s... | Pads an image to a square then resamples to max_size |
28,748 | def emit_accepted ( self ) : if self . result ( ) : filename = self . selectedFiles ( ) [ 0 ] if os . path . isdir ( os . path . dirname ( filename ) ) : self . dlg_accepted . emit ( filename ) | Sends signal that the file dialog was closed properly . |
28,749 | def update_scale ( self , value ) : self . plotter . set_scale ( self . x_slider_group . value , self . y_slider_group . value , self . z_slider_group . value ) | updates the scale of all actors in the plotter |
28,750 | def scale_axes_dialog ( self , show = True ) : return ScaleAxesDialog ( self . app_window , self , show = show ) | Open scale axes dialog |
28,751 | def clear_camera_positions ( self ) : for action in self . saved_camera_menu . actions ( ) : self . saved_camera_menu . removeAction ( action ) | clears all camera positions |
28,752 | def save_camera_position ( self ) : self . saved_camera_positions . append ( self . camera_position ) ncam = len ( self . saved_camera_positions ) camera_position = self . camera_position [ : ] def load_camera_position ( ) : self . camera_position = camera_position self . saved_camera_menu . addAction ( 'Camera Positio... | Saves camera position to saved camera menu for recall |
28,753 | def _spawn_background_rendering ( self , rate = 5.0 ) : self . render_trigger . connect ( self . ren_win . Render ) twait = rate ** - 1 def render ( ) : while self . active : time . sleep ( twait ) self . _render ( ) self . render_thread = Thread ( target = render ) self . render_thread . start ( ) | Spawns a thread that updates the render window . |
28,754 | def update_app_icon ( self ) : if os . name == 'nt' or not hasattr ( self , '_last_window_size' ) : return cur_time = time . time ( ) if self . _last_window_size != self . window_size : pass elif ( ( cur_time - self . _last_update_time > BackgroundPlotter . ICON_TIME_STEP ) and self . _last_camera_pos != self . camera_... | Update the app icon if the user is not trying to resize the window . |
28,755 | def _qt_export_vtkjs ( self , show = True ) : return FileDialog ( self . app_window , filefilter = [ 'VTK JS File(*.vtkjs)' ] , show = show , directory = os . getcwd ( ) , callback = self . export_vtkjs ) | Spawn an save file dialog to export a vtkjs file . |
28,756 | def window_size ( self ) : the_size = self . app_window . baseSize ( ) return the_size . width ( ) , the_size . height ( ) | returns render window size |
28,757 | def window_size ( self , window_size ) : BasePlotter . window_size . fset ( self , window_size ) self . app_window . setBaseSize ( * window_size ) | set the render window size |
28,758 | def hex_to_rgb ( h ) : h = h . lstrip ( '#' ) return tuple ( int ( h [ i : i + 2 ] , 16 ) / 255. for i in ( 0 , 2 , 4 ) ) | Returns 0 to 1 rgb from a hex list or tuple |
28,759 | def set_error_output_file ( filename ) : filename = os . path . abspath ( os . path . expanduser ( filename ) ) fileOutputWindow = vtk . vtkFileOutputWindow ( ) fileOutputWindow . SetFileName ( filename ) outputWindow = vtk . vtkOutputWindow ( ) outputWindow . SetInstance ( fileOutputWindow ) return fileOutputWindow , ... | Sets a file to write out the VTK errors |
28,760 | def log_message ( self , kind , alert ) : if kind == 'ERROR' : logging . error ( alert ) else : logging . warning ( alert ) return | Parses different event types and passes them to logging |
28,761 | def observe ( self , algorithm ) : if self . __observing : raise RuntimeError ( 'This error observer is already observing an algorithm.' ) if hasattr ( algorithm , 'GetExecutive' ) and algorithm . GetExecutive ( ) is not None : algorithm . GetExecutive ( ) . AddObserver ( self . event_type , self ) algorithm . AddObser... | Make this an observer of an algorithm |
28,762 | def get_range_info ( array , component ) : r = array . GetRange ( component ) comp_range = { } comp_range [ 'min' ] = r [ 0 ] comp_range [ 'max' ] = r [ 1 ] comp_range [ 'component' ] = array . GetComponentName ( component ) return comp_range | Get the data range of the array s component |
28,763 | def get_object_id ( obj ) : try : idx = objIds . index ( obj ) return idx + 1 except ValueError : objIds . append ( obj ) return len ( objIds ) | Get object identifier |
28,764 | def dump_data_array ( dataset_dir , data_dir , array , root = None , compress = True ) : if root is None : root = { } if not array : return None if array . GetDataType ( ) == 12 : array_size = array . GetNumberOfTuples ( ) * array . GetNumberOfComponents ( ) new_array = vtk . vtkTypeUInt32Array ( ) new_array . SetNumbe... | Dump vtkjs data arry |
28,765 | def dump_color_array ( dataset_dir , data_dir , color_array_info , root = None , compress = True ) : if root is None : root = { } root [ 'pointData' ] = { 'vtkClass' : 'vtkDataSetAttributes' , "activeGlobalIds" : - 1 , "activeNormals" : - 1 , "activePedigreeIds" : - 1 , "activeScalars" : - 1 , "activeTCoords" : - 1 , "... | Dump vtkjs color array |
28,766 | def dump_t_coords ( dataset_dir , data_dir , dataset , root = None , compress = True ) : if root is None : root = { } tcoords = dataset . GetPointData ( ) . GetTCoords ( ) if tcoords : dumped_array = dump_data_array ( dataset_dir , data_dir , tcoords , { } , compress ) root [ 'pointData' ] [ 'activeTCoords' ] = len ( r... | dump vtkjs texture coordinates |
28,767 | def dump_normals ( dataset_dir , data_dir , dataset , root = None , compress = True ) : if root is None : root = { } normals = dataset . GetPointData ( ) . GetNormals ( ) if normals : dumped_array = dump_data_array ( dataset_dir , data_dir , normals , { } , compress ) root [ 'pointData' ] [ 'activeNormals' ] = len ( ro... | dump vtkjs normal vectors |
28,768 | def dump_all_arrays ( dataset_dir , data_dir , dataset , root = None , compress = True ) : if root is None : root = { } root [ 'pointData' ] = { 'vtkClass' : 'vtkDataSetAttributes' , "activeGlobalIds" : - 1 , "activeNormals" : - 1 , "activePedigreeIds" : - 1 , "activeScalars" : - 1 , "activeTCoords" : - 1 , "activeTens... | Dump all data arrays to vtkjs |
28,769 | def dump_poly_data ( dataset_dir , data_dir , dataset , color_array_info , root = None , compress = True ) : if root is None : root = { } root [ 'vtkClass' ] = 'vtkPolyData' container = root points = dump_data_array ( dataset_dir , data_dir , dataset . GetPoints ( ) . GetData ( ) , { } , compress ) points [ 'vtkClass' ... | Dump poly data object to vtkjs |
28,770 | def dump_image_data ( dataset_dir , data_dir , dataset , color_array_info , root = None , compress = True ) : if root is None : root = { } root [ 'vtkClass' ] = 'vtkImageData' container = root container [ 'spacing' ] = dataset . GetSpacing ( ) container [ 'origin' ] = dataset . GetOrigin ( ) container [ 'extent' ] = da... | Dump image data object to vtkjs |
28,771 | def write_data_set ( file_path , dataset , output_dir , color_array_info , new_name = None , compress = True ) : fileName = new_name if new_name else os . path . basename ( file_path ) dataset_dir = os . path . join ( output_dir , fileName ) data_dir = os . path . join ( dataset_dir , 'data' ) if not os . path . exists... | write dataset to vtkjs |
28,772 | def active_vectors ( self ) : field , name = self . active_vectors_info if name : if field is POINT_DATA_FIELD : return self . point_arrays [ name ] if field is CELL_DATA_FIELD : return self . cell_arrays [ name ] | The active vectors array |
28,773 | def arrows ( self ) : if self . active_vectors is None : return arrow = vtk . vtkArrowSource ( ) arrow . Update ( ) alg = vtk . vtkGlyph3D ( ) alg . SetSourceData ( arrow . GetOutput ( ) ) alg . SetOrient ( True ) alg . SetInputData ( self ) alg . SetVectorModeToUseVector ( ) alg . SetScaleModeToScaleByVector ( ) alg .... | Returns a glyph representation of the active vector data as arrows . Arrows will be located at the points of the mesh and their size will be dependent on the length of the vector . Their direction will be the direction of the vector |
28,774 | def vectors ( self , array ) : if array . ndim != 2 : raise AssertionError ( 'vector array must be a 2-dimensional array' ) elif array . shape [ 1 ] != 3 : raise RuntimeError ( 'vector array must be 3D' ) elif array . shape [ 0 ] != self . n_points : raise RuntimeError ( 'Number of vectors be the same as the number of ... | Sets the active vector |
28,775 | def t_coords ( self , t_coords ) : if not isinstance ( t_coords , np . ndarray ) : raise TypeError ( 'Texture coordinates must be a numpy array' ) if t_coords . ndim != 2 : raise AssertionError ( 'Texture coordinates must be a 2-dimensional array' ) if t_coords . shape [ 0 ] != self . n_points : raise AssertionError ( ... | Set the array to use as the texture coordinates |
28,776 | def _activate_texture ( mesh , name ) : if name == True or isinstance ( name , int ) : keys = list ( mesh . textures . keys ( ) ) idx = 0 if not isinstance ( name , int ) or name == True else name if idx > len ( keys ) : idx = 0 try : name = keys [ idx ] except IndexError : logging . warning ( 'No textures associated w... | Grab a texture and update the active texture coordinates . This makes sure to not destroy old texture coordinates |
28,777 | def set_active_scalar ( self , name , preference = 'cell' ) : _ , field = get_scalar ( self , name , preference = preference , info = True ) if field == POINT_DATA_FIELD : self . GetPointData ( ) . SetActiveScalars ( name ) elif field == CELL_DATA_FIELD : self . GetCellData ( ) . SetActiveScalars ( name ) else : raise ... | Finds the scalar by name and appropriately sets it as active |
28,778 | def set_active_vectors ( self , name , preference = 'cell' ) : _ , field = get_scalar ( self , name , preference = preference , info = True ) if field == POINT_DATA_FIELD : self . GetPointData ( ) . SetActiveVectors ( name ) elif field == CELL_DATA_FIELD : self . GetCellData ( ) . SetActiveVectors ( name ) else : raise... | Finds the vectors by name and appropriately sets it as active |
28,779 | def rename_scalar ( self , old_name , new_name , preference = 'cell' ) : _ , field = get_scalar ( self , old_name , preference = preference , info = True ) if field == POINT_DATA_FIELD : self . point_arrays [ new_name ] = self . point_arrays . pop ( old_name ) elif field == CELL_DATA_FIELD : self . cell_arrays [ new_na... | Changes array name by searching for the array then renaming it |
28,780 | def active_scalar ( self ) : field , name = self . active_scalar_info if name is None : return None if field == POINT_DATA_FIELD : return self . _point_scalar ( name ) elif field == CELL_DATA_FIELD : return self . _cell_scalar ( name ) | Returns the active scalar as an array |
28,781 | def _add_point_scalar ( self , scalars , name , set_active = False , deep = True ) : if not isinstance ( scalars , np . ndarray ) : raise TypeError ( 'Input must be a numpy.ndarray' ) if scalars . shape [ 0 ] != self . n_points : raise Exception ( 'Number of scalars must match the number of ' + 'points' ) if scalars . ... | Adds point scalars to the mesh |
28,782 | def points_to_double ( self ) : if self . points . dtype != np . double : self . points = self . points . astype ( np . double ) | Makes points double precision |
28,783 | def rotate_x ( self , angle ) : axis_rotation ( self . points , angle , inplace = True , axis = 'x' ) | Rotates mesh about the x - axis . |
28,784 | def rotate_y ( self , angle ) : axis_rotation ( self . points , angle , inplace = True , axis = 'y' ) | Rotates mesh about the y - axis . |
28,785 | def rotate_z ( self , angle ) : axis_rotation ( self . points , angle , inplace = True , axis = 'z' ) | Rotates mesh about the z - axis . |
28,786 | def transform ( self , trans ) : if isinstance ( trans , vtk . vtkMatrix4x4 ) : t = vtki . trans_from_matrix ( trans ) elif isinstance ( trans , vtk . vtkTransform ) : t = vtki . trans_from_matrix ( trans . GetMatrix ( ) ) elif isinstance ( trans , np . ndarray ) : if trans . shape [ 0 ] != 4 or trans . shape [ 1 ] != ... | Compute a transformation in place using a 4x4 transform . |
28,787 | def _cell_scalar ( self , name = None ) : if name is None : field , name = self . active_scalar_info if field != CELL_DATA_FIELD : raise RuntimeError ( 'Must specify an array to fetch.' ) vtkarr = self . GetCellData ( ) . GetArray ( name ) if vtkarr is None : raise AssertionError ( '({}) is not a cell scalar' . format ... | Returns the cell scalars of a vtk object |
28,788 | def _add_cell_scalar ( self , scalars , name , set_active = False , deep = True ) : if not isinstance ( scalars , np . ndarray ) : raise TypeError ( 'Input must be a numpy.ndarray' ) if scalars . shape [ 0 ] != self . n_cells : raise Exception ( 'Number of scalars must match the number of cells (%d)' % self . n_cells )... | Adds cell scalars to the vtk object . |
28,789 | def copy_meta_from ( self , ido ) : self . _active_scalar_info = ido . active_scalar_info self . _active_vectors_info = ido . active_vectors_info if hasattr ( ido , '_textures' ) : self . _textures = ido . _textures | Copies vtki meta data onto this object from another object |
28,790 | def copy ( self , deep = True ) : thistype = type ( self ) newobject = thistype ( ) if deep : newobject . DeepCopy ( self ) else : newobject . ShallowCopy ( self ) newobject . copy_meta_from ( self ) return newobject | Returns a copy of the object |
28,791 | def point_arrays ( self ) : pdata = self . GetPointData ( ) narr = pdata . GetNumberOfArrays ( ) if hasattr ( self , '_point_arrays' ) : keys = list ( self . _point_arrays . keys ( ) ) if narr == len ( keys ) : if keys : if self . _point_arrays [ keys [ 0 ] ] . size == self . n_points : return self . _point_arrays else... | Returns the all point arrays |
28,792 | def cell_arrays ( self ) : cdata = self . GetCellData ( ) narr = cdata . GetNumberOfArrays ( ) if hasattr ( self , '_cell_arrays' ) : keys = list ( self . _cell_arrays . keys ( ) ) if narr == len ( keys ) : if keys : if self . _cell_arrays [ keys [ 0 ] ] . size == self . n_cells : return self . _cell_arrays else : retu... | Returns the all cell arrays |
28,793 | def get_data_range ( self , arr = None , preference = 'cell' ) : if arr is None : _ , arr = self . active_scalar_info if isinstance ( arr , str ) : arr = get_scalar ( self , arr , preference = preference ) if arr is None or arr . size == 0 : return ( np . nan , np . nan ) return np . nanmin ( arr ) , np . nanmax ( arr ... | Get the non - NaN min and max of a named scalar array |
28,794 | def scalar_names ( self ) : names = [ ] for i in range ( self . GetPointData ( ) . GetNumberOfArrays ( ) ) : names . append ( self . GetPointData ( ) . GetArrayName ( i ) ) for i in range ( self . GetCellData ( ) . GetNumberOfArrays ( ) ) : names . append ( self . GetCellData ( ) . GetArrayName ( i ) ) try : names . re... | A list of scalar names for the dataset . This makes sure to put the active scalar s name first in the list . |
28,795 | def head ( self , display = True , html = None ) : if html : fmt = "" fmt += "\n" fmt += "<table>\n" fmt += "<tr><th>{}</th><th>Information</th></tr>\n" . format ( type ( self ) . __name__ ) row = "<tr><td>{}</td><td>{}</td></tr>\n" for attr in self . _get_attrs ( ) : try : fmt += row . format ( attr [ 0 ] , attr [ 2 ]... | Return the header stats of this dataset . If in IPython this will be formatted to HTML . Otherwise returns a console friendly string |
28,796 | def _repr_html_ ( self ) : fmt = "" if self . n_scalars > 0 : fmt += "<table>" fmt += "<tr><th>Header</th><th>Data Arrays</th></tr>" fmt += "<tr><td>" fmt += self . head ( display = False , html = True ) if self . n_scalars > 0 : fmt += "</td><td>" fmt += "\n" fmt += "<table>\n" row = "<tr><th>{}</th><th>{}</th><th>{}<... | A pretty representation for Jupyter notebooks that includes header details and information about all scalar arrays |
28,797 | def overwrite ( self , mesh ) : self . DeepCopy ( mesh ) if is_vtki_obj ( mesh ) : self . copy_meta_from ( mesh ) | Overwrites this mesh inplace with the new mesh s geometries and data |
28,798 | def pop ( self , key ) : arr = dict . pop ( self , key ) . copy ( ) self . remover ( key ) return arr | Get and remove an element by key name |
28,799 | def update ( self , data ) : if not isinstance ( data , dict ) : raise TypeError ( 'Data to update must be in a dictionary.' ) for k , v in data . items ( ) : arr = np . array ( v ) try : self [ k ] = arr except TypeError : logging . warning ( "Values under key ({}) not supported by VTK" . format ( k ) ) return | Update this dictionary with th key - value pairs from a given dictionary |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.