Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @smproxy.filter()
- @smproperty.input(name="InputTable")
- @smdomain.datatype(dataTypes=["vtkTable"], port_index=1, composite_data_supported=False)
- class AverageTable(VTKPythonAlgorithmBase):
- """
- Example filter demonstrating how to write a filter that preserves the input
- dataset type.
- """
- @smproperty.intvector(name="ReductionFactor", default_values=16)
- def SetReductionFactor(self, x):
- if x <= 0:
- print("Error : the reduction factor has to be a greater or equal to 1")
- raise Exception("the reduction factor has to be a greater or equal to 1")
- self._realAlgorithm.SetReductionFactor(x)
- self.Modified()
- def __init__(self):
- super().__init__(nInputPorts=1, nOutputPorts=1, outputType="vtkTable")
- def RequestDataObject(self, request, inInfo, outInfo):
- inData = self.GetInputData(inInfo, 0, 0)
- outData = self.GetOutputData(outInfo, 0)
- assert inData is not None
- if outData is None or (not outData.IsA(inData.GetClassName())):
- outData = inData.NewInstance()
- outInfo.GetInformationObject(0).Set(outData.DATA_OBJECT(), outData)
- return super().RequestDataObject(request, inInfo, outInfo)
- def RequestData(self, request, inInfo, outInfo):
- import numpy as np
- inData = self.GetInputData(inInfo, 0, 0)
- outData = self.GetOutputData(outInfo, 0)
- for name in inData.dtype.names:
- a = np.array(inData[name])
- m = 1000
- b=a[:len(a)//m*m].reshape(-1, m).mean(1)
- # You can directly pass a NumPy array to the pipeline.
- # Since ParaView expects all arrays to be named, you
- # need to assign it a name in the 'append' call.
- outData.RowData.append(b, name)
- # print("input type =", inData.GetClassName())
- # print("output type =", outData.GetClassName())
- # assert outData.IsA(inData.GetClassName())
- return outData
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement