
    +j$                         d dl mZ d dlmZ d dlmZ d dlmZ d dlmZ d dlm	Z	  G d de
          Z G d	 d
e	          ZdS )    )vtkInformation)vtkDataObject)vtkAlgorithm)vtkDemandDrivenPipeline) vtkStreamingDemandDrivenPipeline)vtkPythonAlgorithmc                   Z    e Zd ZdZ	 	 ddZd Zd Zd Zd	 Zd
 Z	d Z
d Zd Zd Zd ZdS )VTKAlgorithma  This is a superclass which can be derived to implement
    Python classes that work with vtkPythonAlgorithm. It implements
    Initialize(), ProcessRequest(), FillInputPortInformation() and
    FillOutputPortInformation().

    Initialize() sets the input and output ports based on data
    members.

    ProcessRequest() calls RequestXXX() methods to implement
    various pipeline passes.

    FillInputPortInformation() and FillOutputPortInformation() set
    the input and output types based on data members.
       
vtkDataSetvtkPolyDatac                 >    || _         || _        || _        || _        dS )zSets up default NumberOfInputPorts, NumberOfOutputPorts,
        InputType and OutputType that are used by various initialization
        methods.N)NumberOfInputPortsNumberOfOutputPorts	InputType
OutputTypeselfnInputPorts	inputTypenOutputPorts
outputTypes        V/DATA/AppData/hermes/venv/lib/python3.11/site-packages/vtkmodules/util/vtkAlgorithm.py__init__zVTKAlgorithm.__init__   s&     #.#/ "$    c                 n    |                     | j                   |                    | j                   dS )zeSets up number of input and output ports based on
        NumberOfInputPorts and NumberOfOutputPorts.N)SetNumberOfInputPortsr   SetNumberOfOutputPortsr   r   vtkselfs     r   
InitializezVTKAlgorithm.Initialize#   s8     	%%d&=>>>&&t'?@@@@@r   c                     ||                              |                              t          j                              S zsConvenience method that returns an input data object
        given a vector of information objects and two indices.GetInformationObjectGetr   DATA_OBJECTr   inInfoijs       r   GetInputDatazVTKAlgorithm.GetInputData*   3     ay--a0044]5N5P5PQQQr   c                 t    |                     |                              t          j                              S zgConvenience method that returns an output data object
        given an information object and an index.r$   r   outInfor*   s      r   GetOutputDatazVTKAlgorithm.GetOutputData0   /     ++A..22=3L3N3NOOOr   c                     dS zOverwritten by subclass to manage data object creation.
        There is not need to overwrite this class if the output can
        be created based on the OutputType data member.r    r   r    requestr)   r1   s        r   RequestDataObjectzVTKAlgorithm.RequestDataObject5   	     qr   c                     dS zLOverwritten by subclass to provide meta-data to downstream
        pipeline.r   r6   r7   s        r   RequestInformationzVTKAlgorithm.RequestInformation;   	     qr   c                     dS zROverwritten by subclass to modify data request going
        to upstream pipeline.r   r6   r7   s        r   RequestUpdateExtentz VTKAlgorithm.RequestUpdateExtent@   r>   r   c                      t          d          z1Overwritten by subclass to execute the algorithm.zRequestData must be implementedNotImplementedErrorr7   s        r   RequestDatazVTKAlgorithm.RequestDataE       !"CDDDr   c                    |                     t          j                              r|                     ||||          S |                     t          j                              r|                     ||||          S |                     t          j                              r|                     ||||          S |                     t          j	                              r| 
                    ||||          S dS z)Splits a request to RequestXXX() methods.r   Hasr   REQUEST_DATA_OBJECTr9   REQUEST_INFORMATIONr=   r   REQUEST_UPDATE_EXTENTrA   REQUEST_DATArF   r7   s        r   ProcessRequestzVTKAlgorithm.ProcessRequestI   s    ;;.BDDEE 	G))'7FGLLL[[0DFFGG 	G**7GVWMMM[[9OQQRR 	G++GWfgNNN[[0=??@@ 	G##GWfgFFFqr   c                 ^    |                     t          j                    | j                   dS z*Sets the required input type to InputType.r   Setr   INPUT_REQUIRED_DATA_TYPEr   r   r    portinfos       r   FillInputPortInformationz%VTKAlgorithm.FillInputPortInformationV   &    688$.IIIqr   c                 ^    |                     t          j                    | j                   dS z+Sets the default output type to OutputType.r   rT   r   DATA_TYPE_NAMEr   rV   s       r   FillOutputPortInformationz&VTKAlgorithm.FillOutputPortInformation[   &    -//AAAqr   Nr   r   r   r   )__name__
__module____qualname____doc__r   r!   r,   r2   r9   r=   rA   rF   rP   rY   r_   r6   r   r   r
   r
      s          1=2?	% 	% 	% 	%A A AR R RP P P
    
  
E E E    
    r   r
   c                   p    e Zd ZdZ G d de          Z	 	 ddZd Zd	 Zd
 Z	d Z
d Zd Zd Zd Zd ZdS )VTKPythonAlgorithmBaseai  This is a superclass which can be derived to implement
    Python classes that act as VTK algorithms in a VTK pipeline.
    It implements ProcessRequest(), FillInputPortInformation() and
    FillOutputPortInformation().

    ProcessRequest() calls RequestXXX() methods to implement
    various pipeline passes.

    FillInputPortInformation() and FillOutputPortInformation() set
    the input and output types based on data members.

    Common use is something like this:

    class HDF5Source(VTKPythonAlgorithmBase):
        def __init__(self):
            VTKPythonAlgorithmBase.__init__(self,
                nInputPorts=0,
                nOutputPorts=1, outputType='vtkImageData')

        def RequestInformation(self, request, inInfo, outInfo):
            f = h5py.File("foo.h5", 'r')
            dims = f['RTData'].shape[::-1]
            info = outInfo.GetInformationObject(0)
            info.Set(vtkmodules.vtkCommonExecutionModel.vtkStreamingDemandDrivenPipeline.WHOLE_EXTENT(),
                (0, dims[0]-1, 0, dims[1]-1, 0, dims[2]-1), 6)
            return 1

        def RequestData(self, request, inInfo, outInfo):
            f = h5py.File("foo.h5", 'r')
            data = f['RTData'][:]
            output = dsa.WrapDataObject(vtkmodules.vtkCommonDataModel.vtkImageData.GetData(outInfo))
            output.SetDimensions(data.shape)
            output.PointData.append(data.flatten(), 'RTData')
            output.PointData.SetActiveScalars('RTData')
            return 1

    alg = HDF5Source()

    cf = vtkmodules.vtkFiltersCore.vtkContourFilter()
    cf.SetInputConnection(alg.GetOutputPort())
    cf.Update()
    c                   *    e Zd ZdZd Zd Zd Zd ZdS )(VTKPythonAlgorithmBase.InternalAlgorithmzInternal class. Do not use.c                     d S Nr6   r   s     r   r!   z3VTKPythonAlgorithmBase.InternalAlgorithm.Initialize   s    Dr   c                 .    |                     ||          S rk   )rY   rV   s       r   rY   zAVTKPythonAlgorithmBase.InternalAlgorithm.FillInputPortInformation   s    33D$???r   c                 .    |                     ||          S rk   )r_   rV   s       r   r_   zBVTKPythonAlgorithmBase.InternalAlgorithm.FillOutputPortInformation   s    44T4@@@r   c                 0    |                     |||          S rk   )rP   r7   s        r   rP   z7VTKPythonAlgorithmBase.InternalAlgorithm.ProcessRequest   s    ))'67CCCr   N)rb   rc   rd   re   r!   rY   r_   rP   r6   r   r   InternalAlgorithmri      sa        %%	 	 		@ 	@ 	@	A 	A 	A	D 	D 	D 	D 	Dr   ro   r   r   r   c                     |                      t                                                     |                     |           |                     |           || _        || _        dS )zSets up default NumberOfInputPorts, NumberOfOutputPorts,
        InputType and OutputType that are used by various methods.
        Make sure to call this method from any subclass' __init__N)SetPythonObjectrg   ro   r   r   r   r   r   s        r   r   zVTKPythonAlgorithmBase.__init__   s_     	3EEGGHHH"";///##L111"$r   c                     ||                              |                              t          j                              S r#   r$   r(   s       r   r,   z#VTKPythonAlgorithmBase.GetInputData   r-   r   c                 t    |                     |                              t          j                              S r/   r$   r0   s      r   r2   z$VTKPythonAlgorithmBase.GetOutputData   r3   r   c                 ^    |                     t          j                    | j                   dS rR   rS   r   rW   rX   s      r   rY   z/VTKPythonAlgorithmBase.FillInputPortInformation   rZ   r   c                 ^    |                     t          j                    | j                   dS r\   r]   ru   s      r   r_   z0VTKPythonAlgorithmBase.FillOutputPortInformation   r`   r   c                    |                     t          j                              r|                     |||          S |                     t          j                              r|                     |||          S |                     t          j                              r|                     |||          S |                     t          j	                              r| 
                    |||          S dS rI   rJ   r   r8   r)   r1   s       r   rP   z%VTKPythonAlgorithmBase.ProcessRequest   s    ;;.BDDEE 	>))'67CCC[[0DFFGG 	>**7FGDDD[[9OQQRR 	>++GVWEEE[[0=??@@ 	>##GVW===qr   c                     dS r5   r6   rx   s       r   r9   z(VTKPythonAlgorithmBase.RequestDataObject   r:   r   c                     dS r<   r6   rx   s       r   r=   z)VTKPythonAlgorithmBase.RequestInformation   r>   r   c                     dS r@   r6   rx   s       r   rA   z*VTKPythonAlgorithmBase.RequestUpdateExtent   r>   r   c                      t          d          rC   rD   rx   s       r   rF   z"VTKPythonAlgorithmBase.RequestData   rG   r   Nra   )rb   rc   rd   re   objectro   r   r,   r2   rY   r_   rP   r9   r=   rA   rF   r6   r   r   rg   rg   `   s        ) )VD D D D DF D D D 1=2?% % % %R R RP P P
  
  
      
  
E E E E Er   rg   N)vtkmodules.vtkCommonCorer   vtkmodules.vtkCommonDataModelr   "vtkmodules.vtkCommonExecutionModelr   r   r   vtkmodules.vtkFiltersPythonr   r}   r
   rg   r6   r   r   <module>r      s    3 3 3 3 3 3 7 7 7 7 7 7 ; ; ; ; ; ; F F F F F F O O O O O O : : : : : :V V V V V6 V V Vp|E |E |E |E |E/ |E |E |E |E |Er   