vtkPythonCalculator.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: Copyright (c) Kitware Inc.
2 // SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
3 // SPDX-License-Identifier: BSD-3-Clause
28 #ifndef vtkPythonCalculator_h
29 #define vtkPythonCalculator_h
30 
31 #include "vtkDataObject.h" // for FIELD_ASSOCIATION_POINTS
32 #include "vtkPVVTKExtensionsFiltersPythonModule.h" //needed for exports
33 #include "vtkProgrammableFilter.h"
34 
36 {
37 public:
39  void PrintSelf(ostream& os, vtkIndent indent) override;
40  static vtkPythonCalculator* New();
41 
43 
48  vtkSetMacro(ArrayAssociation, int);
49  vtkGetMacro(ArrayAssociation, int);
51 
53 
58  vtkSetMacro(Expression, std::string);
59  vtkGetMacro(Expression, std::string);
61 
63 
67  vtkSetMacro(MultilineExpression, std::string);
68  vtkGetMacro(MultilineExpression, std::string);
70 
72 
77  vtkSetStringMacro(ArrayName);
78  vtkGetStringMacro(ArrayName);
80 
82 
86  vtkGetMacro(ResultArrayType, int);
87  vtkSetMacro(ResultArrayType, int);
89 
91 
96  vtkGetMacro(UseMultilineExpression, bool);
97  vtkSetMacro(UseMultilineExpression, bool);
99 
101 
106  void SetInputName(int index, const std::string& inputName);
107  std::string GetInputName(int index);
109 
113  void ClearInputNames();
114 
118  static void ExecuteScript(void*);
119 
120 protected:
122  ~vtkPythonCalculator() override;
123 
127  void Exec(const std::string&);
128 
129  int FillOutputPortInformation(int port, vtkInformation* info) override;
130 
131  // overridden to allow multiple inputs to port 0
132  int FillInputPortInformation(int port, vtkInformation* info) override;
133 
134  // ovveridden to set a time range so the filter is updated when a timestep changes.
135  int RequestInformation(vtkInformation* request, vtkInformationVector** inputVector,
136  vtkInformationVector* outputVector) override;
137 
138  // overridden to allow string substitutions for the Expression
139  int RequestData(vtkInformation* request, vtkInformationVector** inputVector,
140  vtkInformationVector* outputVector) override;
141 
142  // Creates whatever output data set type is selected.
143  int RequestDataObject(vtkInformation* request, vtkInformationVector** inputVector,
144  vtkInformationVector* outputVector) override;
145 
146  std::string Expression;
147  std::string MultilineExpression;
148  bool UseMultilineExpression = false;
149 
150  char* ArrayName = nullptr;
152  int ResultArrayType = VTK_DOUBLE;
153 
154 private:
155  vtkPythonCalculator(const vtkPythonCalculator&) = delete;
156  void operator=(const vtkPythonCalculator&) = delete;
157 
158  std::vector<std::string> InputsName;
159 };
160 
161 #endif
virtual int RequestInformation(vtkInformation *, vtkInformationVector **, vtkInformationVector *)
int RequestData(vtkInformation *, vtkInformationVector **, vtkInformationVector *)
void PrintSelf(ostream &os, vtkIndent indent)
Evaluates a Python expression vtkPythonCalculator uses Python to calculate an expression.
virtual int FillInputPortInformation(int port, vtkInformation *info)
#define VTKPVVTKEXTENSIONSFILTERSPYTHON_EXPORT
#define VTK_DOUBLE
virtual int RequestDataObject(vtkInformation *request, vtkInformationVector **inputVector, vtkInformationVector *outputVector)
static vtkProgrammableFilter * New()
void operator=(const vtkObjectBase &)
virtual int FillOutputPortInformation(int port, vtkInformation *info)