idx
int64
0
63k
question
stringlengths
61
4.03k
target
stringlengths
6
1.23k
28,600
def read_legacy ( filename ) : reader = vtk . vtkDataSetReader ( ) reader . SetFileName ( filename ) reader . ReadAllScalarsOn ( ) reader . ReadAllColorScalarsOn ( ) reader . ReadAllNormalsOn ( ) reader . ReadAllTCoordsOn ( ) reader . ReadAllVectorsOn ( ) reader . Update ( ) output = reader . GetOutputDataObject ( 0 ) ...
Use VTK s legacy reader to read a file
28,601
def read ( filename , attrs = None ) : filename = os . path . abspath ( os . path . expanduser ( filename ) ) ext = get_ext ( filename ) if attrs is not None : reader = get_reader ( filename ) return standard_reader_routine ( reader , filename , attrs = attrs ) elif ext in '.vti' : return vtki . UniformGrid ( filename ...
This will read any VTK file! It will figure out what reader to use then wrap the VTK object for use in vtki .
28,602
def read_texture ( filename , attrs = None ) : filename = os . path . abspath ( os . path . expanduser ( filename ) ) try : reader = get_reader ( filename ) image = standard_reader_routine ( reader , filename , attrs = attrs ) return vtki . image_to_texture ( image ) except KeyError : pass return vtki . numpy_to_textur...
Loads a vtkTexture from an image file .
28,603
def delete_downloads ( ) : shutil . rmtree ( vtki . EXAMPLES_PATH ) os . makedirs ( vtki . EXAMPLES_PATH ) return True
Delete all downloaded examples to free space or update the files
28,604
def download_blood_vessels ( ) : local_path , _ = _download_file ( 'pvtu_blood_vessels/blood_vessels.zip' ) filename = os . path . join ( local_path , 'T0000000500.pvtu' ) mesh = vtki . read ( filename ) mesh . set_active_vectors ( 'velocity' ) return mesh
data representing the bifurcation of blood vessels .
28,605
def download_sparse_points ( ) : saved_file , _ = _download_file ( 'sparsePoints.txt' ) points_reader = vtk . vtkDelimitedTextReader ( ) points_reader . SetFileName ( saved_file ) points_reader . DetectNumericColumnsOn ( ) points_reader . SetFieldDelimiterCharacters ( '\t' ) points_reader . SetHaveHeaders ( True ) tabl...
Used with download_saddle_surface
28,606
def download_kitchen ( split = False ) : mesh = _download_and_read ( 'kitchen.vtk' ) if not split : return mesh extents = { 'door' : ( 27 , 27 , 14 , 18 , 0 , 11 ) , 'window1' : ( 0 , 0 , 9 , 18 , 6 , 12 ) , 'window2' : ( 5 , 12 , 23 , 23 , 6 , 12 ) , 'klower1' : ( 17 , 17 , 0 , 11 , 0 , 6 ) , 'klower2' : ( 19 , 19 , 0...
Download structured grid of kitchen with velocity field . Use the split argument to extract all of the furniture in the kitchen .
28,607
def _get_scalar_names ( self , limit = None ) : names = [ ] if limit == 'point' : inpnames = list ( self . input_dataset . point_arrays . keys ( ) ) elif limit == 'cell' : inpnames = list ( self . input_dataset . cell_arrays . keys ( ) ) else : inpnames = self . input_dataset . scalar_names for name in inpnames : arr =...
Only give scalar options that have a varying range
28,608
def _initialize ( self , show_bounds , reset_camera , outline ) : self . plotter . subplot ( * self . loc ) if outline is None : self . plotter . add_mesh ( self . input_dataset . outline_corners ( ) , reset_camera = False , color = vtki . rcParams [ 'outline_color' ] , loc = self . loc ) elif outline : self . plotter ...
Outlines the input dataset and sets up the scene
28,609
def _update_plotting_params ( self , ** kwargs ) : scalars = kwargs . get ( 'scalars' , None ) if scalars is not None : old = self . display_params [ 'scalars' ] self . display_params [ 'scalars' ] = scalars if old != scalars : self . plotter . subplot ( * self . loc ) self . plotter . remove_actor ( self . _data_to_up...
Some plotting parameters can be changed through the tool ; this updataes those plotting parameters .
28,610
def _remove_mapper_from_plotter ( plotter , actor , reset_camera ) : try : mapper = actor . GetMapper ( ) except AttributeError : return for name in list ( plotter . _scalar_bar_mappers . keys ( ) ) : try : plotter . _scalar_bar_mappers [ name ] . remove ( mapper ) except ValueError : pass if len ( plotter . _scalar_ba...
removes this actor s mapper from the given plotter s _scalar_bar_mappers
28,611
def add_axes_at_origin ( self ) : self . marker_actor = vtk . vtkAxesActor ( ) self . AddActor ( self . marker_actor ) self . parent . _actors [ str ( hex ( id ( self . marker_actor ) ) ) ] = self . marker_actor return self . marker_actor
Add axes actor at origin
28,612
def remove_bounding_box ( self ) : if hasattr ( self , '_box_object' ) : actor = self . bounding_box_actor self . bounding_box_actor = None del self . _box_object self . remove_actor ( actor , reset_camera = False )
Removes bounding box
28,613
def camera_position ( self ) : return [ self . camera . GetPosition ( ) , self . camera . GetFocalPoint ( ) , self . camera . GetViewUp ( ) ]
Returns camera position of active render window
28,614
def camera_position ( self , camera_location ) : if camera_location is None : return if isinstance ( camera_location , str ) : camera_location = camera_location . lower ( ) if camera_location == 'xy' : self . view_xy ( ) elif camera_location == 'xz' : self . view_xz ( ) elif camera_location == 'yz' : self . view_yz ( )...
Set camera position of all active render windows
28,615
def remove_actor ( self , actor , reset_camera = False ) : name = None if isinstance ( actor , str ) : name = actor keys = list ( self . _actors . keys ( ) ) names = [ ] for k in keys : if k . startswith ( '{}-' . format ( name ) ) : names . append ( k ) if len ( names ) > 0 : self . remove_actor ( names , reset_camera...
Removes an actor from the Renderer .
28,616
def set_scale ( self , xscale = None , yscale = None , zscale = None , reset_camera = True ) : if xscale is None : xscale = self . scale [ 0 ] if yscale is None : yscale = self . scale [ 1 ] if zscale is None : zscale = self . scale [ 2 ] self . scale = [ xscale , yscale , zscale ] transform = vtk . vtkTransform ( ) tr...
Scale all the datasets in the scene . Scaling in performed independently on the X Y and Z axis . A scale of zero is illegal and will be replaced with one .
28,617
def bounds ( self ) : the_bounds = [ np . inf , - np . inf , np . inf , - np . inf , np . inf , - np . inf ] def _update_bounds ( bounds ) : def update_axis ( ax ) : if bounds [ ax * 2 ] < the_bounds [ ax * 2 ] : the_bounds [ ax * 2 ] = bounds [ ax * 2 ] if bounds [ ax * 2 + 1 ] > the_bounds [ ax * 2 + 1 ] : the_bounds...
Bounds of all actors present in the rendering window
28,618
def center ( self ) : bounds = self . bounds x = ( bounds [ 1 ] + bounds [ 0 ] ) / 2 y = ( bounds [ 3 ] + bounds [ 2 ] ) / 2 z = ( bounds [ 5 ] + bounds [ 4 ] ) / 2 return [ x , y , z ]
Center of the bounding box around all data present in the scene
28,619
def get_default_cam_pos ( self ) : focal_pt = self . center return [ np . array ( rcParams [ 'camera' ] [ 'position' ] ) + np . array ( focal_pt ) , focal_pt , rcParams [ 'camera' ] [ 'viewup' ] ]
Returns the default focal points and viewup . Uses ResetCamera to make a useful view .
28,620
def update_bounds_axes ( self ) : if ( hasattr ( self , '_box_object' ) and self . _box_object is not None and self . bounding_box_actor is not None ) : if not np . allclose ( self . _box_object . bounds , self . bounds ) : color = self . bounding_box_actor . GetProperty ( ) . GetColor ( ) self . remove_bounding_box ( ...
Update the bounds axes of the render window
28,621
def view_isometric ( self ) : self . camera_position = self . get_default_cam_pos ( ) self . camera_set = False return self . reset_camera ( )
Resets the camera to a default isometric view showing all the actors in the scene .
28,622
def view_vector ( self , vector , viewup = None ) : focal_pt = self . center if viewup is None : viewup = rcParams [ 'camera' ] [ 'viewup' ] cpos = [ vector + np . array ( focal_pt ) , focal_pt , viewup ] self . camera_position = cpos return self . reset_camera ( )
Point the camera in the direction of the given vector
28,623
def view_xy ( self , negative = False ) : vec = np . array ( [ 0 , 0 , 1 ] ) viewup = np . array ( [ 0 , 1 , 0 ] ) if negative : vec = np . array ( [ 0 , 0 , - 1 ] ) return self . view_vector ( vec , viewup )
View the XY plane
28,624
def cell_scalar ( mesh , name ) : vtkarr = mesh . GetCellData ( ) . GetArray ( name ) if vtkarr : if isinstance ( vtkarr , vtk . vtkBitArray ) : vtkarr = vtk_bit_array_to_char ( vtkarr ) return vtk_to_numpy ( vtkarr )
Returns cell scalars of a vtk object
28,625
def vtk_points ( points , deep = True ) : if not points . flags [ 'C_CONTIGUOUS' ] : points = np . ascontiguousarray ( points ) vtkpts = vtk . vtkPoints ( ) vtkpts . SetData ( numpy_to_vtk ( points , deep = deep ) ) return vtkpts
Convert numpy points to a vtkPoints object
28,626
def lines_from_points ( points ) : npoints = points . shape [ 0 ] - 1 lines = np . vstack ( ( 2 * np . ones ( npoints , np . int ) , np . arange ( npoints ) , np . arange ( 1 , npoints + 1 ) ) ) . T . ravel ( ) return vtki . PolyData ( points , lines )
Generates line from points . Assumes points are ordered as line segments .
28,627
def vector_poly_data ( orig , vec ) : if not isinstance ( orig , np . ndarray ) : orig = np . asarray ( orig ) if not isinstance ( vec , np . ndarray ) : vec = np . asarray ( vec ) if orig . ndim != 2 : orig = orig . reshape ( ( - 1 , 3 ) ) elif orig . shape [ 1 ] != 3 : raise Exception ( 'orig array must be 3D' ) if v...
Creates a vtkPolyData object composed of vectors
28,628
def trans_from_matrix ( matrix ) : t = np . zeros ( ( 4 , 4 ) ) for i in range ( 4 ) : for j in range ( 4 ) : t [ i , j ] = matrix . GetElement ( i , j ) return t
Convert a vtk matrix to a numpy . ndarray
28,629
def wrap ( vtkdataset ) : wrappers = { 'vtkUnstructuredGrid' : vtki . UnstructuredGrid , 'vtkRectilinearGrid' : vtki . RectilinearGrid , 'vtkStructuredGrid' : vtki . StructuredGrid , 'vtkPolyData' : vtki . PolyData , 'vtkImageData' : vtki . UniformGrid , 'vtkStructuredPoints' : vtki . UniformGrid , 'vtkMultiBlockDataSe...
This is a convenience method to safely wrap any given VTK data object to its appropriate vtki data object .
28,630
def image_to_texture ( image ) : vtex = vtk . vtkTexture ( ) vtex . SetInputDataObject ( image ) vtex . Update ( ) return vtex
Converts vtkImageData to a vtkTexture
28,631
def numpy_to_texture ( image ) : if not isinstance ( image , np . ndarray ) : raise TypeError ( 'Unknown input type ({})' . format ( type ( image ) ) ) if image . ndim != 3 or image . shape [ 2 ] != 3 : raise AssertionError ( 'Input image must be nn by nm by RGB' ) grid = vtki . UniformGrid ( ( image . shape [ 1 ] , im...
Convert a NumPy image array to a vtk . vtkTexture
28,632
def is_inside_bounds ( point , bounds ) : if isinstance ( point , ( int , float ) ) : point = [ point ] if isinstance ( point , collections . Iterable ) and not isinstance ( point , collections . deque ) : if len ( bounds ) < 2 * len ( point ) or len ( bounds ) % 2 != 0 : raise AssertionError ( 'Bounds mismatch point d...
Checks if a point is inside a set of bounds . This is implemented through recursion so that this is N - dimensional .
28,633
def fit_plane_to_points ( points , return_meta = False ) : data = np . array ( points ) center = data . mean ( axis = 0 ) result = np . linalg . svd ( data - center ) normal = np . cross ( result [ 2 ] [ 0 ] , result [ 2 ] [ 1 ] ) plane = vtki . Plane ( center = center , direction = normal ) if return_meta : return pla...
Fits a plane to a set of points
28,634
def set_plot_theme ( theme ) : if theme . lower ( ) in [ 'paraview' , 'pv' ] : rcParams [ 'background' ] = PV_BACKGROUND rcParams [ 'cmap' ] = 'coolwarm' rcParams [ 'font' ] [ 'family' ] = 'arial' rcParams [ 'font' ] [ 'label_size' ] = 16 rcParams [ 'show_edges' ] = False elif theme . lower ( ) in [ 'document' , 'doc' ...
Set the plotting parameters to a predefined theme
28,635
def plot ( var_item , off_screen = None , full_screen = False , screenshot = None , interactive = True , cpos = None , window_size = None , show_bounds = False , show_axes = True , notebook = None , background = None , text = '' , return_img = False , eye_dome_lighting = False , use_panel = None , ** kwargs ) : if note...
Convenience plotting function for a vtk or numpy object .
28,636
def system_supports_plotting ( ) : try : if os . environ [ 'ALLOW_PLOTTING' ] . lower ( ) == 'true' : return True except KeyError : pass try : p = Popen ( [ "xset" , "-q" ] , stdout = PIPE , stderr = PIPE ) p . communicate ( ) return p . returncode == 0 except : return False
Check if x server is running
28,637
def single_triangle ( ) : points = np . zeros ( ( 3 , 3 ) ) points [ 1 ] = [ 1 , 0 , 0 ] points [ 2 ] = [ 0.5 , 0.707 , 0 ] cells = np . array ( [ [ 3 , 0 , 1 , 2 ] ] , ctypes . c_long ) return vtki . PolyData ( points , cells )
A single PolyData triangle
28,638
def parse_color ( color ) : if color is None : color = rcParams [ 'color' ] if isinstance ( color , str ) : return vtki . string_to_rgb ( color ) elif len ( color ) == 3 : return color else : raise Exception ( )
Parses color into a vtk friendly rgb list
28,639
def plot_compare_four ( data_a , data_b , data_c , data_d , disply_kwargs = None , plotter_kwargs = None , show_kwargs = None , screenshot = None , camera_position = None , outline = None , outline_color = 'k' , labels = ( 'A' , 'B' , 'C' , 'D' ) ) : datasets = [ [ data_a , data_b ] , [ data_c , data_d ] ] labels = [ l...
Plot a 2 by 2 comparison of data objects . Plotting parameters and camera positions will all be the same .
28,640
def set_focus ( self , point ) : if isinstance ( point , np . ndarray ) : if point . ndim != 1 : point = point . ravel ( ) self . camera . SetFocalPoint ( point ) self . _render ( )
sets focus to a point
28,641
def set_position ( self , point , reset = False ) : if isinstance ( point , np . ndarray ) : if point . ndim != 1 : point = point . ravel ( ) self . camera . SetPosition ( point ) if reset : self . reset_camera ( ) self . camera_set = True self . _render ( )
sets camera position to a point
28,642
def set_viewup ( self , vector ) : if isinstance ( vector , np . ndarray ) : if vector . ndim != 1 : vector = vector . ravel ( ) self . camera . SetViewUp ( vector ) self . _render ( )
sets camera viewup vector
28,643
def _render ( self ) : if hasattr ( self , 'ren_win' ) : if hasattr ( self , 'render_trigger' ) : self . render_trigger . emit ( ) elif not self . _first_time : self . render ( )
redraws render window if the render window exists
28,644
def add_axes ( self , interactive = None , color = None ) : if interactive is None : interactive = rcParams [ 'interactive' ] if hasattr ( self , 'axes_widget' ) : self . axes_widget . SetInteractive ( interactive ) self . _update_axes_color ( color ) return self . axes_actor = vtk . vtkAxesActor ( ) self . axes_widget...
Add an interactive axes widget
28,645
def key_press_event ( self , obj , event ) : key = self . iren . GetKeySym ( ) log . debug ( 'Key %s pressed' % key ) if key == 'q' : self . q_pressed = True self . last_image = self . screenshot ( True , return_img = True ) elif key == 'b' : self . observer = self . iren . AddObserver ( 'LeftButtonPressEvent' , self ....
Listens for key press event
28,646
def left_button_down ( self , obj , event_type ) : click_pos = self . iren . GetEventPosition ( ) picker = vtk . vtkWorldPointPicker ( ) picker . Pick ( click_pos [ 0 ] , click_pos [ 1 ] , 0 , self . renderer ) self . pickpoint = np . asarray ( picker . GetPickPosition ( ) ) . reshape ( ( - 1 , 3 ) ) if np . any ( np ....
Register the event for a left button down click
28,647
def isometric_view_interactive ( self ) : interactor = self . iren . GetInteractorStyle ( ) renderer = interactor . GetCurrentRenderer ( ) renderer . view_isometric ( )
sets the current interactive render window to isometric view
28,648
def update ( self , stime = 1 , force_redraw = True ) : if stime <= 0 : stime = 1 curr_time = time . time ( ) if Plotter . last_update_time > curr_time : Plotter . last_update_time = curr_time if not hasattr ( self , 'iren' ) : return update_rate = self . iren . GetDesiredUpdateRate ( ) if ( curr_time - Plotter . last_...
Update window redraw process messages query
28,649
def update_scalar_bar_range ( self , clim , name = None ) : if isinstance ( clim , float ) or isinstance ( clim , int ) : clim = [ - clim , clim ] if len ( clim ) != 2 : raise TypeError ( 'clim argument must be a length 2 iterable of values: (min, max).' ) if name is None : if not hasattr ( self , 'mapper' ) : raise Ru...
Update the value range of the active or named scalar bar .
28,650
def clear ( self ) : for renderer in self . renderers : renderer . RemoveAllViewProps ( ) self . _scalar_bar_slots = set ( range ( MAX_N_COLOR_BARS ) ) self . _scalar_bar_slot_lookup = { } self . _scalar_bar_ranges = { } self . _scalar_bar_mappers = { } self . _scalar_bar_actors = { } self . _scalar_bar_widgets = { }
Clears plot by removing all actors and properties
28,651
def remove_actor ( self , actor , reset_camera = False ) : for renderer in self . renderers : renderer . remove_actor ( actor , reset_camera ) return True
Removes an actor from the Plotter .
28,652
def loc_to_index ( self , loc ) : if loc is None : return self . _active_renderer_index elif isinstance ( loc , int ) : return loc elif isinstance ( loc , collections . Iterable ) : assert len ( loc ) == 2 , '"loc" must contain two items' return loc [ 0 ] * self . shape [ 0 ] + loc [ 1 ]
Return index of the render window given a location index .
28,653
def index_to_loc ( self , index ) : sz = int ( self . shape [ 0 ] * self . shape [ 1 ] ) idxs = np . array ( [ i for i in range ( sz ) ] , dtype = int ) . reshape ( self . shape ) args = np . argwhere ( idxs == index ) if len ( args ) < 1 : raise RuntimeError ( 'Index ({}) is out of range.' ) return args [ 0 ]
Convert a 1D index location to the 2D location on the plotting grid
28,654
def add_axes_at_origin ( self , loc = None ) : self . _active_renderer_index = self . loc_to_index ( loc ) return self . renderers [ self . _active_renderer_index ] . add_axes_at_origin ( )
Add axes actor at the origin of a render window .
28,655
def remove_bounding_box ( self , loc = None ) : self . _active_renderer_index = self . loc_to_index ( loc ) renderer = self . renderers [ self . _active_renderer_index ] renderer . remove_bounding_box ( )
Removes bounding box from the active renderer .
28,656
def remove_bounds_axes ( self , loc = None ) : self . _active_renderer_index = self . loc_to_index ( loc ) renderer = self . renderers [ self . _active_renderer_index ] renderer . remove_bounds_axes ( )
Removes bounds axes from the active renderer .
28,657
def subplot ( self , index_x , index_y ) : self . _active_renderer_index = self . loc_to_index ( ( index_x , index_y ) )
Sets the active subplot .
28,658
def show_grid ( self , ** kwargs ) : kwargs . setdefault ( 'grid' , 'back' ) kwargs . setdefault ( 'location' , 'outer' ) kwargs . setdefault ( 'ticks' , 'both' ) return self . show_bounds ( ** kwargs )
A wrapped implementation of show_bounds to change default behaviour to use gridlines and showing the axes labels on the outer edges . This is intended to be silimar to matplotlib s grid function .
28,659
def set_scale ( self , xscale = None , yscale = None , zscale = None , reset_camera = True ) : self . renderer . set_scale ( xscale , yscale , zscale , reset_camera )
Scale all the datasets in the scene of the active renderer .
28,660
def _update_axes_color ( self , color ) : prop_x = self . axes_actor . GetXAxisCaptionActor2D ( ) . GetCaptionTextProperty ( ) prop_y = self . axes_actor . GetYAxisCaptionActor2D ( ) . GetCaptionTextProperty ( ) prop_z = self . axes_actor . GetZAxisCaptionActor2D ( ) . GetCaptionTextProperty ( ) if color is None : colo...
Internal helper to set the axes label color
28,661
def update_scalars ( self , scalars , mesh = None , render = True ) : if mesh is None : mesh = self . mesh if isinstance ( mesh , ( collections . Iterable , vtki . MultiBlock ) ) : for m in mesh : self . update_scalars ( scalars , mesh = m , render = False ) if render : self . ren_win . Render ( ) return if isinstance ...
Updates scalars of the an object in the plotter .
28,662
def update_coordinates ( self , points , mesh = None , render = True ) : if mesh is None : mesh = self . mesh mesh . points = points if render : self . _render ( )
Updates the points of the an object in the plotter .
28,663
def close ( self ) : if hasattr ( self , 'axes_widget' ) : del self . axes_widget self . _scalar_bar_slots = set ( range ( MAX_N_COLOR_BARS ) ) self . _scalar_bar_slot_lookup = { } self . _scalar_bar_ranges = { } self . _scalar_bar_mappers = { } if hasattr ( self , 'ren_win' ) : self . ren_win . Finalize ( ) del self ....
closes render window
28,664
def add_text ( self , text , position = None , font_size = 50 , color = None , font = None , shadow = False , name = None , loc = None ) : if font is None : font = rcParams [ 'font' ] [ 'family' ] if font_size is None : font_size = rcParams [ 'font' ] [ 'size' ] if color is None : color = rcParams [ 'font' ] [ 'color' ...
Adds text to plot object in the top left corner by default
28,665
def open_movie ( self , filename , framerate = 24 ) : if isinstance ( vtki . FIGURE_PATH , str ) and not os . path . isabs ( filename ) : filename = os . path . join ( vtki . FIGURE_PATH , filename ) self . mwriter = imageio . get_writer ( filename , fps = framerate )
Establishes a connection to the ffmpeg writer
28,666
def open_gif ( self , filename ) : if filename [ - 3 : ] != 'gif' : raise Exception ( 'Unsupported filetype. Must end in .gif' ) if isinstance ( vtki . FIGURE_PATH , str ) and not os . path . isabs ( filename ) : filename = os . path . join ( vtki . FIGURE_PATH , filename ) self . _gif_filename = os . path . abspath (...
Open a gif file .
28,667
def write_frame ( self ) : if not hasattr ( self , 'mwriter' ) : raise AssertionError ( 'This plotter has not opened a movie or GIF file.' ) self . mwriter . append_data ( self . image )
Writes a single frame to the movie file
28,668
def add_lines ( self , lines , color = ( 1 , 1 , 1 ) , width = 5 , label = None , name = None ) : if not isinstance ( lines , np . ndarray ) : raise Exception ( 'Input should be an array of point segments' ) lines = vtki . lines_from_points ( lines ) mapper = vtk . vtkDataSetMapper ( ) mapper . SetInputData ( lines ) r...
Adds lines to the plotting object .
28,669
def remove_scalar_bar ( self ) : if hasattr ( self , 'scalar_bar' ) : self . remove_actor ( self . scalar_bar , reset_camera = False )
Removes scalar bar
28,670
def add_point_labels ( self , points , labels , italic = False , bold = True , font_size = None , text_color = 'k' , font_family = None , shadow = False , show_points = True , point_color = 'k' , point_size = 5 , name = None ) : if font_family is None : font_family = rcParams [ 'font' ] [ 'family' ] if font_size is Non...
Creates a point actor with one label from list labels assigned to each point .
28,671
def add_arrows ( self , cent , direction , mag = 1 , ** kwargs ) : direction = direction . copy ( ) if cent . ndim != 2 : cent = cent . reshape ( ( - 1 , 3 ) ) if direction . ndim != 2 : direction = direction . reshape ( ( - 1 , 3 ) ) direction [ : , 0 ] *= mag direction [ : , 1 ] *= mag direction [ : , 2 ] *= mag pdat...
Adds arrows to plotting object
28,672
def _save_image ( image , filename , return_img = None ) : if not image . size : raise Exception ( 'Empty image. Have you run plot() first?' ) if isinstance ( filename , str ) : if isinstance ( vtki . FIGURE_PATH , str ) and not os . path . isabs ( filename ) : filename = os . path . join ( vtki . FIGURE_PATH , filena...
Internal helper for saving a NumPy image array
28,673
def screenshot ( self , filename = None , transparent_background = None , return_img = None , window_size = None ) : if window_size is not None : self . window_size = window_size if transparent_background is None : transparent_background = rcParams [ 'transparent_background' ] self . image_transparent_background = tran...
Takes screenshot at current camera position
28,674
def add_legend ( self , labels = None , bcolor = ( 0.5 , 0.5 , 0.5 ) , border = False , size = None , name = None ) : self . legend = vtk . vtkLegendBoxActor ( ) if labels is None : if not self . _labels : raise Exception ( 'No labels input.\n\n' + 'Add labels to individual items when adding them to' + 'the plotting ob...
Adds a legend to render window . Entries must be a list containing one string and color entry for each item .
28,675
def set_background ( self , color , loc = 'all' ) : if color is None : color = rcParams [ 'background' ] if isinstance ( color , str ) : if color . lower ( ) in 'paraview' or color . lower ( ) in 'pv' : color = PV_BACKGROUND else : color = vtki . string_to_rgb ( color ) if loc == 'all' : for renderer in self . renderer...
Sets background color
28,676
def remove_legend ( self ) : if hasattr ( self , 'legend' ) : self . remove_actor ( self . legend , reset_camera = False ) self . _render ( )
Removes legend actor
28,677
def enable_cell_picking ( self , mesh = None , callback = None ) : if mesh is None : if not hasattr ( self , 'mesh' ) : raise Exception ( 'Input a mesh into the Plotter class first or ' + 'or set it in this function' ) mesh = self . mesh def pick_call_back ( picker , event_id ) : extract = vtk . vtkExtractGeometry ( ) ...
Enables picking of cells . Press r to enable retangle based selection . Press r again to turn it off . Selection will be saved to self . picked_cells .
28,678
def generate_orbital_path ( self , factor = 3. , n_points = 20 , viewup = None , z_shift = None ) : if viewup is None : viewup = rcParams [ 'camera' ] [ 'viewup' ] center = list ( self . center ) bnds = list ( self . bounds ) if z_shift is None : z_shift = ( bnds [ 5 ] - bnds [ 4 ] ) * factor center [ 2 ] = center [ 2 ...
Genrates an orbital path around the data scene
28,679
def orbit_on_path ( self , path = None , focus = None , step = 0.5 , viewup = None , bkg = True ) : if focus is None : focus = self . center if viewup is None : viewup = rcParams [ 'camera' ] [ 'viewup' ] if path is None : path = self . generate_orbital_path ( viewup = viewup ) if not is_vtki_obj ( path ) : path = vtki...
Orbit on the given path focusing on the focus point
28,680
def export_vtkjs ( self , filename , compress_arrays = False ) : if not hasattr ( self , 'ren_win' ) : raise RuntimeError ( 'Export must be called before showing/closing the scene.' ) if isinstance ( vtki . FIGURE_PATH , str ) and not os . path . isabs ( filename ) : filename = os . path . join ( vtki . FIGURE_PATH , f...
Export the current rendering scene as a VTKjs scene for rendering in a web browser
28,681
def show ( self , title = None , window_size = None , interactive = True , auto_close = True , interactive_update = False , full_screen = False , screenshot = False , return_img = False , use_panel = None ) : if use_panel is None : use_panel = rcParams [ 'use_panel' ] if self . _first_time : for renderer in self . rend...
Creates plotting window
28,682
def load_structured ( ) : x = np . arange ( - 10 , 10 , 0.25 ) y = np . arange ( - 10 , 10 , 0.25 ) x , y = np . meshgrid ( x , y ) r = np . sqrt ( x ** 2 + y ** 2 ) z = np . sin ( r ) return vtki . StructuredGrid ( x , y , z )
Loads a simple StructuredGrid
28,683
def plot_ants_plane ( off_screen = False , notebook = None ) : airplane = vtki . PolyData ( planefile ) airplane . points /= 10 ant = vtki . PolyData ( antfile ) ant . rotate_x ( 90 ) ant . translate ( [ 90 , 60 , 15 ] ) ant_copy = ant . copy ( ) ant_copy . translate ( [ 30 , 0 , - 10 ] ) plotter = vtki . Plotter ( off...
Demonstrate how to create a plot class to plot multiple meshes while adding scalars and text .
28,684
def plot_wave ( fps = 30 , frequency = 1 , wavetime = 3 , interactive = False , off_screen = False , notebook = None ) : cpos = [ ( 6.879481857604187 , - 32.143727535933195 , 23.05622921691103 ) , ( - 0.2336056403734026 , - 0.6960083534590372 , - 0.7226721553894022 ) , ( - 0.008900669873416645 , 0.6018246347860926 , 0....
Plot a 3D moving wave in a render window .
28,685
def _get_output ( algorithm , iport = 0 , iconnection = 0 , oport = 0 , active_scalar = None , active_scalar_field = 'point' ) : ido = algorithm . GetInputDataObject ( iport , iconnection ) data = wrap ( algorithm . GetOutputDataObject ( oport ) ) data . copy_meta_from ( ido ) if active_scalar is not None : data . set_...
A helper to get the algorithm s output and copy input s vtki meta info
28,686
def _generate_plane ( normal , origin ) : plane = vtk . vtkPlane ( ) plane . SetNormal ( normal [ 0 ] , normal [ 1 ] , normal [ 2 ] ) plane . SetOrigin ( origin [ 0 ] , origin [ 1 ] , origin [ 2 ] ) return plane
Returns a vtk . vtkPlane
28,687
def clip ( dataset , normal = 'x' , origin = None , invert = True ) : if isinstance ( normal , str ) : normal = NORMALS [ normal . lower ( ) ] if origin is None : origin = dataset . center plane = _generate_plane ( normal , origin ) alg = vtk . vtkClipDataSet ( ) alg . SetInputDataObject ( dataset ) alg . SetClipFuncti...
Clip a dataset by a plane by specifying the origin and normal . If no parameters are given the clip will occur in the center of that dataset
28,688
def clip_box ( dataset , bounds = None , invert = True , factor = 0.35 ) : if bounds is None : def _get_quarter ( dmin , dmax ) : return dmax - ( ( dmax - dmin ) * factor ) xmin , xmax , ymin , ymax , zmin , zmax = dataset . bounds xmin = _get_quarter ( xmin , xmax ) ymin = _get_quarter ( ymin , ymax ) zmin = _get_quar...
Clips a dataset by a bounding box defined by the bounds . If no bounds are given a corner of the dataset bounds will be removed .
28,689
def slice ( dataset , normal = 'x' , origin = None , generate_triangles = False , contour = False ) : if isinstance ( normal , str ) : normal = NORMALS [ normal . lower ( ) ] if origin is None : origin = dataset . center if not is_inside_bounds ( origin , dataset . bounds ) : raise AssertionError ( 'Slice is outside da...
Slice a dataset by a plane at the specified origin and normal vector orientation . If no origin is specified the center of the input dataset will be used .
28,690
def slice_orthogonal ( dataset , x = None , y = None , z = None , generate_triangles = False , contour = False ) : output = vtki . MultiBlock ( ) if x is None : x = dataset . center [ 0 ] if y is None : y = dataset . center [ 1 ] if z is None : z = dataset . center [ 2 ] output [ 0 , 'YZ' ] = dataset . slice ( normal =...
Creates three orthogonal slices through the dataset on the three caresian planes . Yields a MutliBlock dataset of the three slices
28,691
def slice_along_axis ( dataset , n = 5 , axis = 'x' , tolerance = None , generate_triangles = False , contour = False ) : axes = { 'x' : 0 , 'y' : 1 , 'z' : 2 } output = vtki . MultiBlock ( ) if isinstance ( axis , int ) : ax = axis axis = list ( axes . keys ( ) ) [ list ( axes . values ( ) ) . index ( ax ) ] elif isin...
Create many slices of the input dataset along a specified axis .
28,692
def threshold ( dataset , value = None , scalars = None , invert = False , continuous = False , preference = 'cell' ) : if scalars is None : field , scalars = dataset . active_scalar_info arr , field = get_scalar ( dataset , scalars , preference = preference , info = True ) if arr is None : raise AssertionError ( 'No a...
This filter will apply a vtkThreshold filter to the input dataset and return the resulting object . This extracts cells where scalar value in each cell satisfies threshold criterion . If scalars is None the inputs active_scalar is used .
28,693
def threshold_percent ( dataset , percent = 0.50 , scalars = None , invert = False , continuous = False , preference = 'cell' ) : if scalars is None : _ , tscalars = dataset . active_scalar_info else : tscalars = scalars dmin , dmax = dataset . get_data_range ( arr = tscalars , preference = preference ) def _check_perc...
Thresholds the dataset by a percentage of its range on the active scalar array or as specified
28,694
def outline ( dataset , generate_faces = False ) : alg = vtk . vtkOutlineFilter ( ) alg . SetInputDataObject ( dataset ) alg . SetGenerateFaces ( generate_faces ) alg . Update ( ) return wrap ( alg . GetOutputDataObject ( 0 ) )
Produces an outline of the full extent for the input dataset .
28,695
def outline_corners ( dataset , factor = 0.2 ) : alg = vtk . vtkOutlineCornerFilter ( ) alg . SetInputDataObject ( dataset ) alg . SetCornerFactor ( factor ) alg . Update ( ) return wrap ( alg . GetOutputDataObject ( 0 ) )
Produces an outline of the corners for the input dataset .
28,696
def extract_geometry ( dataset ) : alg = vtk . vtkGeometryFilter ( ) alg . SetInputDataObject ( dataset ) alg . Update ( ) return _get_output ( alg )
Extract the outer surface of a volume or structured grid dataset as PolyData . This will extract all 0D 1D and 2D cells producing the boundary faces of the dataset .
28,697
def elevation ( dataset , low_point = None , high_point = None , scalar_range = None , preference = 'point' , set_active = True ) : if low_point is None : low_point = list ( dataset . center ) low_point [ 2 ] = dataset . bounds [ 4 ] if high_point is None : high_point = list ( dataset . center ) high_point [ 2 ] = data...
Generate scalar values on a dataset . The scalar values lie within a user specified range and are generated by computing a projection of each dataset point onto a line . The line can be oriented arbitrarily . A typical example is to generate scalars based on elevation or height above a plane .
28,698
def contour ( dataset , isosurfaces = 10 , scalars = None , compute_normals = False , compute_gradients = False , compute_scalars = True , rng = None , preference = 'point' ) : if dataset . n_scalars < 1 : raise AssertionError ( 'Input dataset for the contour filter must have scalar data.' ) alg = vtk . vtkContourFilte...
Contours an input dataset by an array . isosurfaces can be an integer specifying the number of isosurfaces in the data range or an iterable set of values for explicitly setting the isosurfaces .
28,699
def texture_map_to_plane ( dataset , origin = None , point_u = None , point_v = None , inplace = False , name = 'Texture Coordinates' ) : alg = vtk . vtkTextureMapToPlane ( ) if origin is None or point_u is None or point_v is None : alg . SetAutomaticPlaneGeneration ( True ) else : alg . SetOrigin ( origin ) alg . SetP...
Texture map this dataset to a user defined plane . This is often used to define a plane to texture map an image to this dataset . The plane defines the spatial reference and extent of that image .