VTK  9.7.1
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
64 #ifndef vtkArrayCalculator_h
65 #define vtkArrayCalculator_h
66 
67 #include "vtkDataObject.h" // For attribute types
68 #include "vtkFiltersCoreModule.h" // For export macro
70 #include "vtkTuple.h" // needed for vtkTuple
71 #include "vtkWrappingHints.h" // For VTK_MARSHALAUTO
72 
73 #include <vector> // needed for vector
74 
75 VTK_ABI_NAMESPACE_BEGIN
76 class vtkDataSet;
77 
78 class VTKFILTERSCORE_EXPORT VTK_MARSHALAUTO vtkArrayCalculator : public vtkPassInputTypeAlgorithm
79 {
80 public:
82  void PrintSelf(ostream& os, vtkIndent indent) override;
83  static vtkArrayCalculator* New();
84 
86 
91  vtkSetStringMacro(Function);
92  vtkGetStringMacro(Function);
94 
96 
106  void AddScalarArrayName(const char* arrayName, int component = 0);
107  void AddVectorArrayName(const char* arrayName);
108  VTK_DEPRECATED_IN_9_6_0("Use AddVectorArrayName(const char* arrayName) instead")
109  void AddVectorArrayName(
110  const char* arrayName, int component0, int component1 = 1, int component2 = 2)
111  {
112  static_cast<void>(component0); // to avoid unused parameter warning
113  static_cast<void>(component1); // to avoid unused parameter warning
114  static_cast<void>(component2); // to avoid unused parameter warning
115  this->AddVectorArrayName(arrayName);
116  }
118 
120 
126  void AddScalarVariable(const char* variableName, const char* arrayName, int component = 0);
127  void AddVectorVariable(const char* variableName, const char* arrayName);
129  "Use AddVectorVariable(const char* variableName, const char* arrayName) instead")
130  void AddVectorVariable(const char* variableName, const char* arrayName, int component0,
131  int component1 = 1, int component2 = 2)
132  {
133  static_cast<void>(component0); // to avoid unused parameter warning
134  static_cast<void>(component1); // to avoid unused parameter warning
135  static_cast<void>(component2); // to avoid unused parameter warning
136  this->AddVectorVariable(variableName, arrayName);
137  }
139 
141 
147  void AddCoordinateScalarVariable(const char* variableName, int component = 0);
148  void AddCoordinateVectorVariable(const char* variableName);
149  VTK_DEPRECATED_IN_9_6_0("Use AddCoordinateVectorVariable(const char* variableName) instead")
150  void AddCoordinateVectorVariable(
151  const char* variableName, int component0, int component1 = 1, int component2 = 2)
152  {
153  static_cast<void>(component0); // to avoid unused parameter warning
154  static_cast<void>(component1); // to avoid unused parameter warning
155  static_cast<void>(component2); // to avoid unused parameter warning
156  this->AddCoordinateVectorVariable(variableName);
157  }
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 
217  const char* GetAttributeTypeAsString();
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 
240  void RemoveAllVariables();
241 
245  virtual void RemoveScalarVariables();
246 
250  virtual void RemoveVectorVariables();
251 
255  virtual void RemoveCoordinateScalarVariables();
256 
260  virtual void RemoveCoordinateVectorVariables();
261 
263 
266  const std::vector<std::string>& GetScalarArrayNames() { return this->ScalarArrayNames; }
267  std::string GetScalarArrayName(int i);
268  const std::vector<std::string>& GetVectorArrayNames() { return this->VectorArrayNames; }
269  std::string GetVectorArrayName(int i);
270  const std::vector<std::string>& GetScalarVariableNames() { return this->ScalarVariableNames; }
271  std::string GetScalarVariableName(int i);
272  const std::vector<std::string>& GetVectorVariableNames() { return this->VectorVariableNames; }
273  std::string GetVectorVariableName(int i);
274  const std::vector<int>& GetSelectedScalarComponents() { return this->SelectedScalarComponents; }
275  int GetSelectedScalarComponent(int i);
276  VTK_DEPRECATED_IN_9_6_0("This method no longer returns valid data")
277  const std::vector<vtkTuple<int, 3>>& GetSelectedVectorComponents();
278  VTK_DEPRECATED_IN_9_6_0("This method no longer returns valid data")
279  vtkTuple<int, 3> GetSelectedVectorComponents(int) { return {}; }
280  int GetNumberOfScalarArrays() { return static_cast<int>(this->ScalarArrayNames.size()); }
281  int GetNumberOfVectorArrays() { return static_cast<int>(this->VectorArrayNames.size()); }
282  const std::vector<std::string>& GetCoordinateScalarVariableNames()
283  {
284  return this->CoordinateScalarVariableNames;
285  }
286  std::string GetCoordinateScalarVariableName(int i);
287  const std::vector<std::string>& GetCoordinateVectorVariableNames()
288  {
289  return this->CoordinateVectorVariableNames;
290  }
291  std::string GetCoordinateVectorVariableName(int i);
292  const std::vector<int>& GetSelectedCoordinateScalarComponents()
293  {
294  return this->SelectedCoordinateScalarComponents;
295  }
296  int GetSelectedCoordinateScalarComponent(int i);
298  {
299  return static_cast<int>(this->CoordinateScalarVariableNames.size());
300  }
302  {
303  return static_cast<int>(this->CoordinateVectorVariableNames.size());
304  }
306 
308 
314  vtkSetMacro(ReplaceInvalidValues, vtkTypeBool);
315  vtkGetMacro(ReplaceInvalidValues, vtkTypeBool);
316  vtkBooleanMacro(ReplaceInvalidValues, vtkTypeBool);
317  vtkSetMacro(ReplacementValue, double);
318  vtkGetMacro(ReplacementValue, double);
320 
322 
327  vtkSetMacro(IgnoreMissingArrays, bool);
328  vtkGetMacro(IgnoreMissingArrays, bool);
329  vtkBooleanMacro(IgnoreMissingArrays, bool);
331 
336  {
337  FunctionParser, // vtkFunctionParser
338  ExprTkFunctionParser, // vtkExprTkFunctionParser
339  NumberOfFunctionParserTypes
340  };
341 
343 
347  vtkSetEnumMacro(FunctionParserType, FunctionParserTypes);
349  {
350  this->FunctionParserType = FunctionParserTypes::FunctionParser;
351  this->Modified();
352  }
354  {
355  this->FunctionParserType = FunctionParserTypes::ExprTkFunctionParser;
356  this->Modified();
357  }
358  vtkGetEnumMacro(FunctionParserType, FunctionParserTypes);
360 
365  vtkDataSet* GetDataSetOutput();
366 
367 protected:
369  ~vtkArrayCalculator() override;
370 
371  int FillInputPortInformation(int, vtkInformation*) override;
372 
374 
378  int GetAttributeTypeFromInput(vtkDataObject* input) const;
379 
387  static std::string CheckValidVariableName(const char* variableName);
388 
390 
391  char* Function;
393  std::vector<std::string> ScalarArrayNames;
394  std::vector<std::string> VectorArrayNames;
395  std::vector<std::string> ScalarVariableNames;
396  std::vector<std::string> VectorVariableNames;
398  std::vector<int> SelectedScalarComponents;
399 
403 
407  std::vector<std::string> CoordinateScalarVariableNames;
408  std::vector<std::string> CoordinateVectorVariableNames;
410 
412 
413 private:
414  vtkArrayCalculator(const vtkArrayCalculator&) = delete;
415  void operator=(const vtkArrayCalculator&) = delete;
416 
417  enum ResultTypes
418  {
419  SCALAR,
420  VECTOR
421  };
422 
423  template <typename TFunctionParser, typename TResultArray>
424  class vtkArrayCalculatorFunctor;
425 
426  template <typename TFunctionParser>
427  struct vtkArrayCalculatorWorker;
428 
429  template <typename TFunctionParser>
430  vtkSmartPointer<TFunctionParser> InitializeFunctionParser(vtkDataObject* input) const;
431 
432  // Do the bulk of the work
433  template <typename TFunctionParser>
434  int ProcessDataObject(vtkDataObject* input, vtkDataObject* output);
435 };
436 
437 VTK_ABI_NAMESPACE_END
438 #endif
vtkTypeBool ReplaceInvalidValues
std::vector< std::string > ScalarArrayNames
const std::vector< std::string > & GetCoordinateScalarVariableNames()
Methods to get information about the current variables.
int GetNumberOfCoordinateVectorVariables()
Methods to get information about the current variables.
const std::vector< std::string > & GetScalarVariableNames()
Methods to get information about the current variables.
Superclass for algorithms that produce output of the same type as input.
Store vtkAlgorithm input/output information.
perform mathematical operations on data in field data arrays
abstract class to specify dataset behavior
Definition: vtkDataSet.h:56
void SetAttributeTypeToVertexData()
Control which AttributeType the filter operates on (point data or cell data for vtkDataSets).
void SetFunctionParserTypeToFunctionParser()
Set/Get the FunctionParser type that will be used.
void SetAttributeTypeToDefault()
Control which AttributeType the filter operates on (point data or cell data for vtkDataSets).
Hold a reference to a vtkObjectBase instance.
Definition: vtkMeta.h:23
void SetAttributeTypeToPointData()
Control which AttributeType the filter operates on (point data or cell data for vtkDataSets).
const std::vector< int > & GetSelectedScalarComponents()
Methods to get information about the current variables.
void SetAttributeTypeToCellData()
Control which AttributeType the filter operates on (point data or cell data for vtkDataSets).
int GetNumberOfVectorArrays()
Methods to get information about the current variables.
std::vector< std::string > CoordinateVectorVariableNames
int vtkTypeBool
Definition: vtkABI.h:64
const std::vector< std::string > & GetVectorVariableNames()
Methods to get information about the current variables.
#define VTK_DEPRECATED_IN_9_6_0(reason)
templated base type for containers of constant size.
Definition: vtkTuple.h:29
const std::vector< int > & GetSelectedCoordinateScalarComponents()
Methods to get information about the current variables.
void SetFunctionParserTypeToExprTkFunctionParser()
Set/Get the FunctionParser type that will be used.
std::vector< std::string > VectorVariableNames
a simple class to control print indentation
Definition: vtkIndent.h:28
int FillInputPortInformation(int port, vtkInformation *info) override
Fill the input port information objects for this algorithm.
int GetNumberOfScalarArrays()
Methods to get information about the current variables.
virtual void Modified()
Update the modification time for this object.
std::vector< std::string > CoordinateScalarVariableNames
std::vector< std::string > ScalarVariableNames
FunctionParserTypes FunctionParserType
const std::vector< std::string > & GetVectorArrayNames()
Methods to get information about the current variables.
FunctionParserTypes
Enum that includes the types of parsers that can be used.
const std::vector< std::string > & GetCoordinateVectorVariableNames()
Methods to get information about the current variables.
std::vector< std::string > VectorArrayNames
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
void SetAttributeTypeToEdgeData()
Control which AttributeType the filter operates on (point data or cell data for vtkDataSets).
const std::vector< std::string > & GetScalarArrayNames()
Methods to get information about the current variables.
Store zero or more vtkInformation instances.
#define VTK_MARSHALAUTO
vtkTypeBool CoordinateResults
general representation of visualization data
Definition: vtkDataObject.h:55
virtual int RequestData(vtkInformation *, vtkInformationVector **, vtkInformationVector *)
This is called within ProcessRequest when a request asks the algorithm to do its work.
void SetAttributeTypeToRowData()
Control which AttributeType the filter operates on (point data or cell data for vtkDataSets).
std::vector< int > SelectedScalarComponents
static vtkPassInputTypeAlgorithm * New()
int GetNumberOfCoordinateScalarVariables()
Methods to get information about the current variables.
std::vector< int > SelectedCoordinateScalarComponents