parameters: (
      new_itk_object,
      inargs: Optional[Sequence[Any]] = None,
      inkargs: Optional[Dict[str, Any]] = None,
  )
docstring: Set the inputs of the given objects, according to the non named or the
      named parameters in args and kargs
  
      This function tries to assign all the non named parameters in the input of
      the new_itk_object
      - the first non named parameter in the first input, etc.
  
      The named parameters are used by calling the method with the same name
      prefixed by 'Set'.
      set_inputs( obj, kargs={'Threshold': 10} ) calls obj.SetThreshold(10)
  
      This is the function use in the enhanced New() method to manage the inputs.
      It can be used to produce a similar behavior:
  
      def SetInputs(self, *args, **kargs):
          import itk
          itk.set_inputs(self, *args, **kargs)
docstring_summary: Set the inputs of the given objects, according to the non named or the
      named parameters in args and kargs
docstring_tokens: Set the inputs of the given objects according to the non named or the named parameters in args and kargs
function: def set_inputs(
      new_itk_object,
      inargs: Optional[Sequence[Any]] = None,
      inkargs: Optional[Dict[str, Any]] = None,
  ):
      """Set the inputs of the given objects, according to the non named or the
      named parameters in args and kargs
  
      This function tries to assign all the non named parameters in the input of
      the new_itk_object
      - the first non named parameter in the first input, etc.
  
      The named parameters are used by calling the method with the same name
      prefixed by 'Set'.
      set_inputs( obj, kargs={'Threshold': 10} ) calls obj.SetThreshold(10)
  
      This is the function use in the enhanced New() method to manage the inputs.
      It can be used to produce a similar behavior:
  
      def SetInputs(self, *args, **kargs):
          import itk
          itk.set_inputs(self, *args, **kargs)
      """
  
      # Fix bug with Mutable Default Arguments
      # https://docs.python-guide.org/writing/gotchas/
      args: List[Any] = inargs if inargs else []
      kargs: Dict[str, Any] = inkargs if inkargs else {}
  
      # try to get the images from the filters in args
      args = [output(arg) for arg in args]
  
      # args without name are filter used to set input image
      #
      # count SetInput calls to call SetInput, SetInput2, SetInput3, ...
      # useful with filter which take 2 input (or more) like SubtractImageFiler
      # Ex: subtract image2.png to image1.png and save the result in result.png
      # r1 = itk.ImageFileReader.US2.New(FileName='image1.png')
      # r2 = itk.ImageFileReader.US2.New(FileName='image2.png')
      # s = itk.SubtractImageFilter.US2US2US2.New(r1, r2)
      # itk.ImageFileWriter.US2.New(s, FileName='result.png').Update()
      setInputNb: int = -1
      try:
          for setInputNb, arg in enumerate(args):
              methodName = "SetInput%i" % (setInputNb + 1)
              if methodName in dir(new_itk_object):
                  # first try to use methods called SetInput1, SetInput2, ...
                  # those method should have more chances to work in case of
                  # multiple input types
                  getattr(new_itk_object, methodName)(arg)
              else:
                  # no method called SetInput?
                  # try with the standard SetInput(nb, input)
                  new_itk_object.SetInput(setInputNb, arg)
      except TypeError as e:
          # the exception have (at least) to possible reasons:
          # + the filter don't take the input number as first argument
          # + arg is an object of wrong type
          #
          # if it's not the first input, re-raise the exception
          if setInputNb != 0:
              raise e
          # it's the first input, try to use the SetInput() method without input
          # number
          new_itk_object.SetInput(args[0])
          # but raise an exception if there is more than 1 argument
          if len(args) > 1:
              raise TypeError("Object accepts only 1 input.")
      except AttributeError:
          # There is no SetInput() method, try SetImage
          # but before, check the number of inputs
          if len(args) > 1:
              raise TypeError("Object accepts only 1 input.")
          methodList = ["SetImage", "SetInputImage"]
          methodName = None
          for m in methodList:
              if m in dir(new_itk_object):
                  methodName = m
          if methodName:
              getattr(new_itk_object, methodName)(args[0])
          else:
              raise AttributeError("No method found to set the input.")
  
      # named args : name is the function name, value is argument(s)
      for attribName, value in kargs.items():
          # use Set as prefix. It allow to use a shorter and more intuitive
          # call (Ex: itk.ImageFileReader.UC2.New(FileName='image.png')) than
          # with the full name
          # (Ex: itk.ImageFileReader.UC2.New(SetFileName='image.png'))
          if attribName not in ["auto_progress", "template_parameters"]:
              if attribName.islower():
                  attribName = _snake_to_camel(attribName)
              attrib = getattr(new_itk_object, "Set" + attribName)
  
              # Do not use try-except mechanism as this leads to
              # segfaults. Instead limit the number of types that are
              # tested. The list of tested type could maybe be replaced by
              # a test that would check for iterables.
              import itk
  
              if type(value) in [list, tuple]:
                  try:
                      output_value = [itk.output(x) for x in value]
                      attrib(*output_value)
                  except Exception:
                      attrib(itk.output(value))
              else:
                  attrib(itk.output(value))
function_tokens: def set_inputs ( new_itk_object , inargs : Optional [ Sequence [ Any ] ] = None , inkargs : Optional [ Dict [ str , Any ] ] = None , ) : # Fix bug with Mutable Default Arguments # https://docs.python-guide.org/writing/gotchas/ args : List [ Any ] = inargs if inargs else [ ] kargs : Dict [ str , Any ] = inkargs if inkargs else { } # try to get the images from the filters in args args = [ output ( arg ) for arg in args ] # args without name are filter used to set input image # # count SetInput calls to call SetInput, SetInput2, SetInput3, ... # useful with filter which take 2 input (or more) like SubtractImageFiler # Ex: subtract image2.png to image1.png and save the result in result.png # r1 = itk.ImageFileReader.US2.New(FileName='image1.png') # r2 = itk.ImageFileReader.US2.New(FileName='image2.png') # s = itk.SubtractImageFilter.US2US2US2.New(r1, r2) # itk.ImageFileWriter.US2.New(s, FileName='result.png').Update() setInputNb : int = - 1 try : for setInputNb , arg in enumerate ( args ) : methodName = "SetInput%i" % ( setInputNb + 1 ) if methodName in dir ( new_itk_object ) : # first try to use methods called SetInput1, SetInput2, ... # those method should have more chances to work in case of # multiple input types getattr ( new_itk_object , methodName ) ( arg ) else : # no method called SetInput? # try with the standard SetInput(nb, input) new_itk_object . SetInput ( setInputNb , arg ) except TypeError as e : # the exception have (at least) to possible reasons: # + the filter don't take the input number as first argument # + arg is an object of wrong type # # if it's not the first input, re-raise the exception if setInputNb != 0 : raise e # it's the first input, try to use the SetInput() method without input # number new_itk_object . SetInput ( args [ 0 ] ) # but raise an exception if there is more than 1 argument if len ( args ) > 1 : raise TypeError ( "Object accepts only 1 input." ) except AttributeError : # There is no SetInput() method, try SetImage # but before, check the number of inputs if len ( args ) > 1 : raise TypeError ( "Object accepts only 1 input." ) methodList = [ "SetImage" , "SetInputImage" ] methodName = None for m in methodList : if m in dir ( new_itk_object ) : methodName = m if methodName : getattr ( new_itk_object , methodName ) ( args [ 0 ] ) else : raise AttributeError ( "No method found to set the input." ) # named args : name is the function name, value is argument(s) for attribName , value in kargs . items ( ) : # use Set as prefix. It allow to use a shorter and more intuitive # call (Ex: itk.ImageFileReader.UC2.New(FileName='image.png')) than # with the full name # (Ex: itk.ImageFileReader.UC2.New(SetFileName='image.png')) if attribName not in [ "auto_progress" , "template_parameters" ] : if attribName . islower ( ) : attribName = _snake_to_camel ( attribName ) attrib = getattr ( new_itk_object , "Set" + attribName ) # Do not use try-except mechanism as this leads to # segfaults. Instead limit the number of types that are # tested. The list of tested type could maybe be replaced by # a test that would check for iterables. import itk if type ( value ) in [ list , tuple ] : try : output_value = [ itk . output ( x ) for x in value ] attrib ( * output_value ) except Exception : attrib ( itk . output ( value ) ) else : attrib ( itk . output ( value ) )