VTK  9.3.0
vtkArrayCalculator.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
2// SPDX-License-Identifier: BSD-3-Clause
63#ifndef vtkArrayCalculator_h
64#define vtkArrayCalculator_h
65
66#include "vtkDataObject.h" // For attribute types
67#include "vtkFiltersCoreModule.h" // For export macro
69#include "vtkTuple.h" // needed for vtkTuple
70#include <vector> // needed for vector
71
72VTK_ABI_NAMESPACE_BEGIN
73class vtkDataSet;
74
75class VTKFILTERSCORE_EXPORT vtkArrayCalculator : public vtkPassInputTypeAlgorithm
76{
77public:
79 void PrintSelf(ostream& os, vtkIndent indent) override;
80
82
84
87 vtkSetStringMacro(Function);
88 vtkGetStringMacro(Function);
90
92
102 void AddScalarArrayName(const char* arrayName, int component = 0);
104 const char* arrayName, int component0 = 0, int component1 = 1, int component2 = 2);
106
108
114 void AddScalarVariable(const char* variableName, const char* arrayName, int component = 0);
115 void AddVectorVariable(const char* variableName, const char* arrayName, int component0 = 0,
116 int component1 = 1, int component2 = 2);
118
120
126 void AddCoordinateScalarVariable(const char* variableName, int component = 0);
128 const char* variableName, int component0 = 0, int component1 = 1, int component2 = 2);
130
132
138 vtkSetStringMacro(ResultArrayName);
139 vtkGetStringMacro(ResultArrayName);
141
143
147 vtkGetMacro(ResultArrayType, int);
148 vtkSetMacro(ResultArrayType, int);
150
152
158 vtkGetMacro(CoordinateResults, vtkTypeBool);
159 vtkSetMacro(CoordinateResults, vtkTypeBool);
160 vtkBooleanMacro(CoordinateResults, vtkTypeBool);
162
164
169 vtkGetMacro(ResultNormals, bool);
170 vtkSetMacro(ResultNormals, bool);
171 vtkBooleanMacro(ResultNormals, bool);
173
175
180 vtkGetMacro(ResultTCoords, bool);
181 vtkSetMacro(ResultTCoords, bool);
182 vtkBooleanMacro(ResultTCoords, bool);
184
189
190 static const int DEFAULT_ATTRIBUTE_TYPE = -1;
192
198 vtkSetMacro(AttributeType, int);
199 vtkGetMacro(AttributeType, int);
200 void SetAttributeTypeToDefault() { this->SetAttributeType(DEFAULT_ATTRIBUTE_TYPE); }
201 void SetAttributeTypeToPointData() { this->SetAttributeType(vtkDataObject::POINT); }
202 void SetAttributeTypeToCellData() { this->SetAttributeType(vtkDataObject::CELL); }
203 void SetAttributeTypeToEdgeData() { this->SetAttributeType(vtkDataObject::EDGE); }
204 void SetAttributeTypeToVertexData() { this->SetAttributeType(vtkDataObject::VERTEX); }
205 void SetAttributeTypeToRowData() { this->SetAttributeType(vtkDataObject::ROW); }
207
212
216 virtual void RemoveScalarVariables();
217
221 virtual void RemoveVectorVariables();
222
227
232
234
237 const std::vector<std::string>& GetScalarArrayNames() { return this->ScalarArrayNames; }
238 std::string GetScalarArrayName(int i);
239 const std::vector<std::string>& GetVectorArrayNames() { return this->VectorArrayNames; }
240 std::string GetVectorArrayName(int i);
241 const std::vector<std::string>& GetScalarVariableNames() { return this->ScalarVariableNames; }
242 std::string GetScalarVariableName(int i);
243 const std::vector<std::string>& GetVectorVariableNames() { return this->VectorVariableNames; }
244 std::string GetVectorVariableName(int i);
245 const std::vector<int>& GetSelectedScalarComponents() { return this->SelectedScalarComponents; }
247 const std::vector<vtkTuple<int, 3>>& GetSelectedVectorComponents()
248 {
249 return this->SelectedVectorComponents;
250 }
252 int GetNumberOfScalarArrays() { return static_cast<int>(this->ScalarArrayNames.size()); }
253 int GetNumberOfVectorArrays() { return static_cast<int>(this->VectorArrayNames.size()); }
255
257
263 vtkSetMacro(ReplaceInvalidValues, vtkTypeBool);
264 vtkGetMacro(ReplaceInvalidValues, vtkTypeBool);
265 vtkBooleanMacro(ReplaceInvalidValues, vtkTypeBool);
266 vtkSetMacro(ReplacementValue, double);
267 vtkGetMacro(ReplacementValue, double);
269
271
276 vtkSetMacro(IgnoreMissingArrays, bool);
277 vtkGetMacro(IgnoreMissingArrays, bool);
278 vtkBooleanMacro(IgnoreMissingArrays, bool);
280
285 {
286 FunctionParser, // vtkFunctionParser
287 ExprTkFunctionParser, // vtkExprTkFunctionParser
288 NumberOfFunctionParserTypes
289 };
290
292
298 {
299 this->FunctionParserType = FunctionParserTypes::FunctionParser;
300 this->Modified();
301 }
303 {
304 this->FunctionParserType = FunctionParserTypes::ExprTkFunctionParser;
305 this->Modified();
306 }
309
315
316protected:
319
321
323
328
336 static std::string CheckValidVariableName(const char* variableName);
337
339
340 char* Function;
342 std::vector<std::string> ScalarArrayNames;
343 std::vector<std::string> VectorArrayNames;
344 std::vector<std::string> ScalarVariableNames;
345 std::vector<std::string> VectorVariableNames;
347 std::vector<int> SelectedScalarComponents;
348 std::vector<vtkTuple<int, 3>> SelectedVectorComponents;
349
353
357 std::vector<std::string> CoordinateScalarVariableNames;
358 std::vector<std::string> CoordinateVectorVariableNames;
360 std::vector<vtkTuple<int, 3>> SelectedCoordinateVectorComponents;
361
363
364private:
365 vtkArrayCalculator(const vtkArrayCalculator&) = delete;
366 void operator=(const vtkArrayCalculator&) = delete;
367
368 // Do the bulk of the work
369 template <typename TFunctionParser>
370 int ProcessDataObject(vtkDataObject* input, vtkDataObject* output);
371};
372
373VTK_ABI_NAMESPACE_END
374#endif
perform mathematical operations on data in field data arrays
FunctionParserTypes
Enum that includes the types of parsers that can be used.
void SetFunctionParserTypeToFunctionParser()
Set/Get the FunctionParser type that will be used.
const std::vector< std::string > & GetVectorArrayNames()
Methods to get information about the current variables.
void RemoveAllVariables()
Remove all the variable names and their associated array names.
const char * GetAttributeTypeAsString()
Returns a string representation of the calculator's AttributeType.
void SetAttributeTypeToVertexData()
Control which AttributeType the filter operates on (point data or cell data for vtkDataSets).
virtual void RemoveCoordinateVectorVariables()
Remove all the coordinate variables.
std::string GetVectorVariableName(int i)
Methods to get information about the current variables.
void SetAttributeTypeToRowData()
Control which AttributeType the filter operates on (point data or cell data for vtkDataSets).
const std::vector< vtkTuple< int, 3 > > & GetSelectedVectorComponents()
Methods to get information about the current variables.
void SetAttributeTypeToDefault()
Control which AttributeType the filter operates on (point data or cell data for vtkDataSets).
vtkSetEnumMacro(FunctionParserType, FunctionParserTypes)
Set/Get the FunctionParser type that will be used.
vtkTuple< int, 3 > GetSelectedVectorComponents(int i)
Methods to get information about the current variables.
const std::vector< std::string > & GetScalarArrayNames()
Methods to get information about the current variables.
int GetNumberOfVectorArrays()
Methods to get information about the current variables.
vtkTypeBool ReplaceInvalidValues
const std::vector< int > & GetSelectedScalarComponents()
Methods to get information about the current variables.
std::vector< std::string > VectorVariableNames
void AddScalarVariable(const char *variableName, const char *arrayName, int component=0)
Add a variable name, a corresponding array name, and which components of the array to use.
const std::vector< std::string > & GetScalarVariableNames()
Methods to get information about the current variables.
std::vector< vtkTuple< int, 3 > > SelectedVectorComponents
void SetAttributeTypeToEdgeData()
Control which AttributeType the filter operates on (point data or cell data for vtkDataSets).
vtkDataSet * GetDataSetOutput()
Returns the output of the filter downcast to a vtkDataSet or nullptr if the cast fails.
vtkGetEnumMacro(FunctionParserType, FunctionParserTypes)
Set/Get the FunctionParser type that will be used.
std::string GetScalarArrayName(int i)
Methods to get information about the current variables.
std::string GetScalarVariableName(int i)
Methods to get information about the current variables.
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
int GetNumberOfScalarArrays()
Methods to get information about the current variables.
std::vector< vtkTuple< int, 3 > > SelectedCoordinateVectorComponents
void AddVectorArrayName(const char *arrayName, int component0=0, int component1=1, int component2=2)
Add an array name to the list of arrays used in the function and specify which components of the arra...
void AddCoordinateScalarVariable(const char *variableName, int component=0)
Add a variable name, a corresponding array name, and which components of the array to use.
virtual void RemoveVectorVariables()
Remove all the scalar variable names and their associated array names.
static std::string CheckValidVariableName(const char *variableName)
A variable name is valid if it's sanitized or enclosed in quotes.
void SetAttributeTypeToCellData()
Control which AttributeType the filter operates on (point data or cell data for vtkDataSets).
std::vector< int > SelectedScalarComponents
void AddVectorVariable(const char *variableName, const char *arrayName, int component0=0, int component1=1, int component2=2)
Add a variable name, a corresponding array name, and which components of the array to use.
FunctionParserTypes FunctionParserType
const std::vector< std::string > & GetVectorVariableNames()
Methods to get information about the current variables.
std::vector< std::string > CoordinateVectorVariableNames
int GetAttributeTypeFromInput(vtkDataObject *input)
Get the attribute type for the input.
void AddCoordinateVectorVariable(const char *variableName, int component0=0, int component1=1, int component2=2)
Add a variable name, a corresponding array name, and which components of the array to use.
std::vector< std::string > ScalarVariableNames
std::vector< int > SelectedCoordinateScalarComponents
void SetFunctionParserTypeToExprTkFunctionParser()
Set/Get the FunctionParser type that will be used.
int RequestData(vtkInformation *, vtkInformationVector **, vtkInformationVector *) override
This is called within ProcessRequest when a request asks the algorithm to do its work.
std::vector< std::string > ScalarArrayNames
int GetSelectedScalarComponent(int i)
Methods to get information about the current variables.
virtual void RemoveScalarVariables()
Remove all the scalar variable names and their associated array names.
void AddScalarArrayName(const char *arrayName, int component=0)
Add an array name to the list of arrays used in the function and specify which components of the arra...
int FillInputPortInformation(int, vtkInformation *) override
Fill the input port information objects for this algorithm.
void SetAttributeTypeToPointData()
Control which AttributeType the filter operates on (point data or cell data for vtkDataSets).
~vtkArrayCalculator() override
virtual void RemoveCoordinateScalarVariables()
Remove all the coordinate variables.
std::vector< std::string > VectorArrayNames
std::string GetVectorArrayName(int i)
Methods to get information about the current variables.
std::vector< std::string > CoordinateScalarVariableNames
static vtkArrayCalculator * New()
general representation of visualization data
abstract class to specify dataset behavior
Definition vtkDataSet.h:53
a simple class to control print indentation
Definition vtkIndent.h:29
Store zero or more vtkInformation instances.
Store vtkAlgorithm input/output information.
virtual void Modified()
Update the modification time for this object.
Superclass for algorithms that produce output of the same type as input.
templated base type for containers of constant size.
Definition vtkTuple.h:27
int vtkTypeBool
Definition vtkABI.h:64