Advertisement
Butanium

Python plugin paraview

Jan 26th, 2022
286
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.99 KB | None | 0 0
  1. @smproxy.filter()
  2. @smproperty.input(name="InputTable")
  3. @smdomain.datatype(dataTypes=["vtkTable"], port_index=1, composite_data_supported=False)
  4.  
  5. class AverageTable(VTKPythonAlgorithmBase):
  6.     """
  7.    Example filter demonstrating how to write a filter that preserves the input
  8.    dataset type.
  9.    """
  10.     @smproperty.intvector(name="ReductionFactor", default_values=16)
  11.     def SetReductionFactor(self, x):
  12.         if x <= 0:
  13.             print("Error : the reduction factor has to be a greater or equal to 1")
  14.             raise Exception("the reduction factor has to be a greater or equal to 1")
  15.         self._realAlgorithm.SetReductionFactor(x)
  16.         self.Modified()
  17.  
  18.  
  19.    
  20.     def __init__(self):
  21.         super().__init__(nInputPorts=1, nOutputPorts=1, outputType="vtkTable")
  22.  
  23.     def RequestDataObject(self, request, inInfo, outInfo):
  24.         inData = self.GetInputData(inInfo, 0, 0)
  25.         outData = self.GetOutputData(outInfo, 0)
  26.         assert inData is not None
  27.         if outData is None or (not outData.IsA(inData.GetClassName())):
  28.             outData = inData.NewInstance()
  29.             outInfo.GetInformationObject(0).Set(outData.DATA_OBJECT(), outData)
  30.         return super().RequestDataObject(request, inInfo, outInfo)
  31.  
  32.     def RequestData(self, request, inInfo, outInfo):
  33.         import numpy as np
  34.         inData = self.GetInputData(inInfo, 0, 0)
  35.         outData = self.GetOutputData(outInfo, 0)
  36.         for name in inData.dtype.names:
  37.             a = np.array(inData[name])
  38.             m = 1000
  39.             b=a[:len(a)//m*m].reshape(-1, m).mean(1)
  40.             # You can directly pass a NumPy array to the pipeline.
  41.             # Since ParaView expects all arrays to be named, you
  42.             # need to assign it a name in the 'append' call.
  43.             outData.RowData.append(b, name)
  44.         # print("input type =", inData.GetClassName())
  45.         # print("output type =", outData.GetClassName())
  46.         # assert outData.IsA(inData.GetClassName())
  47.         return outData
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement