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 
75  vtkSetStringMacro(ArrayName);
76  vtkGetStringMacro(ArrayName);
78 
80 
84  vtkGetMacro(ResultArrayType, int);
85  vtkSetMacro(ResultArrayType, int);
87 
89 
94  vtkGetMacro(UseMultilineExpression, bool);
95  vtkSetMacro(UseMultilineExpression, bool);
97 
99 
104  void SetInputName(int index, const std::string& inputName);
105  std::string GetInputName(int index);
107 
111  void ClearInputNames();
112 
116  static void ExecuteScript(void*);
117 
118 protected:
120  ~vtkPythonCalculator() override;
121 
125  void Exec(const std::string&);
126 
127  int FillOutputPortInformation(int port, vtkInformation* info) override;
128 
129  // overridden to allow multiple inputs to port 0
130  int FillInputPortInformation(int port, vtkInformation* info) override;
131 
132  // ovveridden to set a time range so the filter is updated when a timestep changes.
133  int RequestInformation(vtkInformation* request, vtkInformationVector** inputVector,
134  vtkInformationVector* outputVector) override;
135 
136  // overridden to allow string substitutions for the Expression
137  int RequestData(vtkInformation* request, vtkInformationVector** inputVector,
138  vtkInformationVector* outputVector) override;
139 
140  // Creates whatever output data set type is selected.
141  int RequestDataObject(vtkInformation* request, vtkInformationVector** inputVector,
142  vtkInformationVector* outputVector) override;
143 
144  std::string Expression;
145  std::string MultilineExpression;
146  bool UseMultilineExpression = false;
147 
148  char* ArrayName = nullptr;
150  int ResultArrayType = VTK_DOUBLE;
151 
152 private:
153  vtkPythonCalculator(const vtkPythonCalculator&) = delete;
154  void operator=(const vtkPythonCalculator&) = delete;
155 
156  std::vector<std::string> InputsName;
157 };
158 
159 #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)