VTK  9.3.20240327
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
92 #ifndef vtkArrayCalculator_h
93 #define vtkArrayCalculator_h
94 
95 #include "vtkDataObject.h" // For attribute types
96 #include "vtkFiltersCoreModule.h" // For export macro
98 #include "vtkTuple.h" // needed for vtkTuple
99 #include <vector> // needed for vector
100 
101 VTK_ABI_NAMESPACE_BEGIN
102 class vtkDataSet;
103 
104 class VTKFILTERSCORE_EXPORT vtkArrayCalculator : public vtkPassInputTypeAlgorithm
105 {
106 public:
108  void PrintSelf(ostream& os, vtkIndent indent) override;
109 
111 
113 
116  vtkSetStringMacro(Function);
117  vtkGetStringMacro(Function);
119 
121 
131  void AddScalarArrayName(const char* arrayName, int component = 0);
133  const char* arrayName, int component0 = 0, int component1 = 1, int component2 = 2);
135 
137 
143  void AddScalarVariable(const char* variableName, const char* arrayName, int component = 0);
144  void AddVectorVariable(const char* variableName, const char* arrayName, int component0 = 0,
145  int component1 = 1, int component2 = 2);
147 
149 
155  void AddCoordinateScalarVariable(const char* variableName, int component = 0);
157  const char* variableName, int component0 = 0, int component1 = 1, int component2 = 2);
159 
161 
167  vtkSetStringMacro(ResultArrayName);
168  vtkGetStringMacro(ResultArrayName);
170 
172 
176  vtkGetMacro(ResultArrayType, int);
177  vtkSetMacro(ResultArrayType, int);
179 
181 
187  vtkGetMacro(CoordinateResults, vtkTypeBool);
188  vtkSetMacro(CoordinateResults, vtkTypeBool);
189  vtkBooleanMacro(CoordinateResults, vtkTypeBool);
191 
193 
198  vtkGetMacro(ResultNormals, bool);
199  vtkSetMacro(ResultNormals, bool);
200  vtkBooleanMacro(ResultNormals, bool);
202 
204 
209  vtkGetMacro(ResultTCoords, bool);
210  vtkSetMacro(ResultTCoords, bool);
211  vtkBooleanMacro(ResultTCoords, bool);
213 
218 
219  static const int DEFAULT_ATTRIBUTE_TYPE = -1;
221 
227  vtkSetMacro(AttributeType, int);
228  vtkGetMacro(AttributeType, int);
229  void SetAttributeTypeToDefault() { this->SetAttributeType(DEFAULT_ATTRIBUTE_TYPE); }
230  void SetAttributeTypeToPointData() { this->SetAttributeType(vtkDataObject::POINT); }
231  void SetAttributeTypeToCellData() { this->SetAttributeType(vtkDataObject::CELL); }
232  void SetAttributeTypeToEdgeData() { this->SetAttributeType(vtkDataObject::EDGE); }
233  void SetAttributeTypeToVertexData() { this->SetAttributeType(vtkDataObject::VERTEX); }
234  void SetAttributeTypeToRowData() { this->SetAttributeType(vtkDataObject::ROW); }
236 
241 
245  virtual void RemoveScalarVariables();
246 
250  virtual void RemoveVectorVariables();
251 
256 
261 
263 
266  const std::vector<std::string>& GetScalarArrayNames() { return this->ScalarArrayNames; }
268  const std::vector<std::string>& GetVectorArrayNames() { return this->VectorArrayNames; }
270  const std::vector<std::string>& GetScalarVariableNames() { return this->ScalarVariableNames; }
272  const std::vector<std::string>& GetVectorVariableNames() { return this->VectorVariableNames; }
274  const std::vector<int>& GetSelectedScalarComponents() { return this->SelectedScalarComponents; }
276  const std::vector<vtkTuple<int, 3>>& GetSelectedVectorComponents()
277  {
278  return this->SelectedVectorComponents;
279  }
281  int GetNumberOfScalarArrays() { return static_cast<int>(this->ScalarArrayNames.size()); }
282  int GetNumberOfVectorArrays() { return static_cast<int>(this->VectorArrayNames.size()); }
284 
286 
292  vtkSetMacro(ReplaceInvalidValues, vtkTypeBool);
293  vtkGetMacro(ReplaceInvalidValues, vtkTypeBool);
294  vtkBooleanMacro(ReplaceInvalidValues, vtkTypeBool);
295  vtkSetMacro(ReplacementValue, double);
296  vtkGetMacro(ReplacementValue, double);
298 
300 
305  vtkSetMacro(IgnoreMissingArrays, bool);
306  vtkGetMacro(IgnoreMissingArrays, bool);
307  vtkBooleanMacro(IgnoreMissingArrays, bool);
309 
314  {
315  FunctionParser, // vtkFunctionParser
316  ExprTkFunctionParser, // vtkExprTkFunctionParser
317  NumberOfFunctionParserTypes
318  };
319 
321 
325  vtkSetEnumMacro(FunctionParserType, FunctionParserTypes);
327  {
328  this->FunctionParserType = FunctionParserTypes::FunctionParser;
329  this->Modified();
330  }
332  {
333  this->FunctionParserType = FunctionParserTypes::ExprTkFunctionParser;
334  this->Modified();
335  }
336  vtkGetEnumMacro(FunctionParserType, FunctionParserTypes);
338 
344 
345 protected:
348 
350 
352 
357 
365  static std::string CheckValidVariableName(const char* variableName);
366 
368 
369  char* Function;
371  std::vector<std::string> ScalarArrayNames;
372  std::vector<std::string> VectorArrayNames;
373  std::vector<std::string> ScalarVariableNames;
374  std::vector<std::string> VectorVariableNames;
376  std::vector<int> SelectedScalarComponents;
377  std::vector<vtkTuple<int, 3>> SelectedVectorComponents;
378 
382 
386  std::vector<std::string> CoordinateScalarVariableNames;
387  std::vector<std::string> CoordinateVectorVariableNames;
389  std::vector<vtkTuple<int, 3>> SelectedCoordinateVectorComponents;
390 
392 
393 private:
394  vtkArrayCalculator(const vtkArrayCalculator&) = delete;
395  void operator=(const vtkArrayCalculator&) = delete;
396 
397  // Do the bulk of the work
398  template <typename TFunctionParser>
399  int ProcessDataObject(vtkDataObject* input, vtkDataObject* output);
400 };
401 
402 VTK_ABI_NAMESPACE_END
403 #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.
void RemoveAllVariables()
Remove all the variable names and their associated array names.
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).
vtkTuple< int, 3 > GetSelectedVectorComponents(int i)
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.
int GetNumberOfVectorArrays()
Methods to get information about the current variables.
vtkTypeBool ReplaceInvalidValues
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.
vtkTypeBool CoordinateResults
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
const std::vector< int > & GetSelectedScalarComponents()
Methods to get information about the current variables.
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 char * GetAttributeTypeAsString()
Returns a string representation of the calculator's AttributeType.
std::vector< std::string > CoordinateVectorVariableNames
int GetAttributeTypeFromInput(vtkDataObject *input)
Get the attribute type for the input.
const std::vector< vtkTuple< int, 3 > > & GetSelectedVectorComponents()
Methods to get information about the current variables.
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.
const std::vector< std::string > & GetVectorArrayNames()
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...
const std::vector< std::string > & GetScalarArrayNames()
Methods to get information about the current variables.
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.
const std::vector< std::string > & GetVectorVariableNames()
Methods to get information about the current 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:165
a simple class to control print indentation
Definition: vtkIndent.h:108
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.
@ component
Definition: vtkX3D.h:175
@ string
Definition: vtkX3D.h:490
int vtkTypeBool
Definition: vtkABI.h:64