class_docstr: An internal class to manage widgets.
  
  It also manages and other helper methods involving widgets.
class_docstr_tok: ["An","internal","class","to","manage","widgets",".","It","also","manages","and","other","helper","methods","involving","widgets","."]
docstr: Slice a mesh with a spline widget.
  
  Add a mesh to the scene with a spline widget that is used to slice
  the mesh interactively.
  
  The sliced mesh is saved to the ``.spline_sliced_meshes`` attribute on
  the plotter.
  
  Parameters
  ----------
  mesh : pyvista.DataSet or vtk.vtkAlgorithm
      The input dataset to add to the scene and slice along the spline
      or algorithm that produces said mesh.
  
  generate_triangles : bool, optional
      If this is enabled (``False`` by default), the output will be
      triangles otherwise, the output will be the intersection polygons.
  
  n_handles : int, optional
      The number of interactive spheres to control the spline's
      parametric function.
  
  resolution : int, optional
      The number of points to generate on the spline.
  
  widget_color : ColorLike, optional
      Color of the widget.  Either a string, RGB sequence, or
      hex color string.  For example:
  
      * ``color='white'``
      * ``color='w'``
      * ``color=[1.0, 1.0, 1.0]``
      * ``color='#FFFFFF'``
  
  show_ribbon : bool, optional
      If ``True``, the poly plane used for slicing will also be shown.
  
  ribbon_color : ColorLike, optional
      Color of the ribbon.  Either a string, RGB sequence, or
      hex color string.
  
  ribbon_opacity : float, optional
      Opacity of ribbon. Defaults to 1.0 and must be between
      ``[0, 1]``.
  
  initial_points : sequence, optional
      The points to initialize the widget placement. Must have same
      number of elements as ``n_handles``. If the first and last point
      are the same, this will be a closed loop spline.
  
  closed : bool, optional
      Make the spline a closed loop.
  
  interaction_event : vtk.vtkCommand.EventIds, optional
      The VTK interaction event to use for triggering the callback.
  
  **kwargs : dict, optional
      All additional keyword arguments are passed to
      :func:`Plotter.add_mesh` to control how the mesh is
      displayed.
  
  Returns
  -------
  vtk.vtkActor
      VTK actor of the mesh.
docstr_tok: ["Slice","a","mesh","with","a","spline","widget",".","Add","a","mesh","to","the","scene","with","a","spline","widget","that","is","used","to","slice","the","mesh","interactively",".","The","sliced","mesh","is","saved","to","the","``",".spline_sliced_meshes","``","attribute","on","the","plotter",".","Parameters","--","--","--","--","--","mesh",":","pyvista.DataSet","or","vtk.vtkAlgorithm","The","input","dataset","to","add","to","the","scene","and","slice","along","the","spline","or","algorithm","that","produces","said","mesh",".","generate_triangles",":","bool",",","optional","If","this","is","enabled","(","``","False","``","by","default",")",",","the","output","will","be","triangles","otherwise",",","the","output","will","be","the","intersection","polygons",".","n_handles",":","int",",","optional","The","number","of","interactive","spheres","to","control","the","spline's","parametric","function",".","resolution",":","int",",","optional","The","number","of","points","to","generate","on","the","spline",".","widget_color",":","ColorLike",",","optional","Color","of","the","widget",".","Either","a","string",",","RGB","sequence",",","or","hex","color","string",".","For","example",":","*","``","color='white","'","``","*","``","color=","'","w","'","``","*","``","color=","[","1.0",",","1.0",",","1.0","]","``","*","``","color=","'","#","FFFFFF","'","``","show_ribbon",":","bool",",","optional","If","``","True","``",",","the","poly","plane","used","for","slicing","will","also","be","shown",".","ribbon_color",":","ColorLike",",","optional","Color","of","the","ribbon",".","Either","a","string",",","RGB","sequence",",","or","hex","color","string",".","ribbon_opacity",":","float",",","optional","Opacity","of","ribbon",".","Defaults","to","1.0","and","must","be","between","``","[","0",",","1","]","``",".","initial_points",":","sequence",",","optional","The","points","to","initialize","the","widget","placement",".","Must","have","same","number","of","elements","as","``","n_handles","``",".","If","the","first","and","last","point","are","the","same",",","this","will","be","a","closed","loop","spline",".","closed",":","bool",",","optional","Make","the","spline","a","closed","loop",".","interaction_event",":","vtk.vtkCommand.EventIds",",","optional","The","VTK","interaction","event","to","use","for","triggering","the","callback",".","*","*","kwargs",":","dict",",","optional","All","additional","keyword","arguments","are","passed","to",":","func",":","`","Plotter.add_mesh","`","to","control","how","the","mesh","is","displayed",".","Returns","--","--","--","-","vtk.vtkActor","VTK","actor","of","the","mesh","."]
code: def add_mesh_slice_spline(
      self,
      mesh,
      generate_triangles=False,
      n_handles=5,
      resolution=25,
      widget_color=None,
      show_ribbon=False,
      ribbon_color="pink",
      ribbon_opacity=0.5,
      initial_points=None,
      closed=False,
      interaction_event=_vtk.vtkCommand.EndInteractionEvent,
      **kwargs,
  ):
      """Slice a mesh with a spline widget.
  
      Add a mesh to the scene with a spline widget that is used to slice
      the mesh interactively.
  
      The sliced mesh is saved to the ``.spline_sliced_meshes`` attribute on
      the plotter.
  
      Parameters
      ----------
      mesh : pyvista.DataSet or vtk.vtkAlgorithm
          The input dataset to add to the scene and slice along the spline
          or algorithm that produces said mesh.
  
      generate_triangles : bool, optional
          If this is enabled (``False`` by default), the output will be
          triangles otherwise, the output will be the intersection polygons.
  
      n_handles : int, optional
          The number of interactive spheres to control the spline's
          parametric function.
  
      resolution : int, optional
          The number of points to generate on the spline.
  
      widget_color : ColorLike, optional
          Color of the widget.  Either a string, RGB sequence, or
          hex color string.  For example:
  
          * ``color='white'``
          * ``color='w'``
          * ``color=[1.0, 1.0, 1.0]``
          * ``color='#FFFFFF'``
  
      show_ribbon : bool, optional
          If ``True``, the poly plane used for slicing will also be shown.
  
      ribbon_color : ColorLike, optional
          Color of the ribbon.  Either a string, RGB sequence, or
          hex color string.
  
      ribbon_opacity : float, optional
          Opacity of ribbon. Defaults to 1.0 and must be between
          ``[0, 1]``.
  
      initial_points : sequence, optional
          The points to initialize the widget placement. Must have same
          number of elements as ``n_handles``. If the first and last point
          are the same, this will be a closed loop spline.
  
      closed : bool, optional
          Make the spline a closed loop.
  
      interaction_event : vtk.vtkCommand.EventIds, optional
          The VTK interaction event to use for triggering the callback.
  
      **kwargs : dict, optional
          All additional keyword arguments are passed to
          :func:`Plotter.add_mesh` to control how the mesh is
          displayed.
  
      Returns
      -------
      vtk.vtkActor
          VTK actor of the mesh.
  
      """
      mesh, algo = algorithm_to_mesh_handler(mesh)
      name = kwargs.get("name", None)
      if name is None:
          name = mesh.memory_address
      rng = mesh.get_data_range(kwargs.get("scalars", None))
      kwargs.setdefault("clim", kwargs.pop("rng", rng))
      mesh.set_active_scalars(
          kwargs.get("scalars", mesh.active_scalars_name)
      )
  
      self.add_mesh(
          outline_algorithm(algo or mesh),
          name=f"{name}-outline",
          opacity=0.0,
      )
  
      alg = _vtk.vtkCutter()  # Construct the cutter object
      # Use the grid as the data we desire to cut
      set_algorithm_input(alg, algo or mesh)
      if not generate_triangles:
          alg.GenerateTrianglesOff()
  
      spline_sliced_mesh = pyvista.wrap(alg.GetOutput())
      self.spline_sliced_meshes.append(spline_sliced_mesh)
  
      def callback(spline):  # numpydoc ignore=GL08
          polyline = spline.GetCell(0)
          # create the plane for clipping
          polyplane = _vtk.vtkPolyPlane()
          polyplane.SetPolyLine(polyline)
          alg.SetCutFunction(
              polyplane
          )  # the cutter to use the poly planes
          alg.Update()  # Perform the Cut
          spline_sliced_mesh.shallow_copy(alg.GetOutput())
  
      self.add_spline_widget(
          callback=callback,
          bounds=mesh.bounds,
          factor=1.25,
          color=widget_color,
          n_handles=n_handles,
          resolution=resolution,
          show_ribbon=show_ribbon,
          ribbon_color=ribbon_color,
          ribbon_opacity=ribbon_opacity,
          initial_points=initial_points,
          closed=closed,
          interaction_event=interaction_event,
      )
  
      return self.add_mesh(alg, **kwargs)
  
imports: import pathlib
  from typing import Optional, Sequence, Tuple, Union
  import numpy
  import pyvista
  from pyvista.core.utilities.arrays import get_array, get_array_association
  from pyvista.core.utilities.geometric_objects import NORMALS
  from pyvista.core.utilities.helpers import generate_plane
  from pyvista.core.utilities.misc import assert_empty_kwargs, try_callback
  from .None import _vtk
  from .affine_widget import AffineWidget3D
  from .colors import Color
  from .opts import PickerType
  from .utilities.algorithms import add_ids_algorithm, algorithm_to_mesh_handler, crinkle_algorithm, outline_algorithm, pointset_to_polydata_algorithm, set_algorithm_input
label_desc: Use image node_id 20 for calling the WidgetHelper obj's underlying member method code with example usage: obj.add_mesh_slice_spline(mesh, generate_triangles, n_handles, resolution, widget_color, show_ribbon, ribbon_color, ribbon_opacity, initial_points, closed, interaction_event) and returns: self