VTK  9.1.0
vtkArrayCalculator.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Visualization Toolkit
4  Module: vtkArrayCalculator.h
5 
6  Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7  All rights reserved.
8  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9 
10  This software is distributed WITHOUT ANY WARRANTY; without even
11  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12  PURPOSE. See the above copyright notice for more information.
13 
14 =========================================================================*/
101 #ifndef vtkArrayCalculator_h
102 #define vtkArrayCalculator_h
103 
104 #include "vtkDataObject.h" // For attribute types
105 #include "vtkFiltersCoreModule.h" // For export macro
107 #include "vtkTuple.h" // needed for vtkTuple
108 #include <vector> // needed for vector
109 
110 class vtkDataSet;
111 
112 class VTKFILTERSCORE_EXPORT vtkArrayCalculator : public vtkPassInputTypeAlgorithm
113 {
114 public:
116  void PrintSelf(ostream& os, vtkIndent indent) override;
117 
119 
121 
124  vtkSetStringMacro(Function);
125  vtkGetStringMacro(Function);
127 
129 
139  void AddScalarArrayName(const char* arrayName, int component = 0);
141  const char* arrayName, int component0 = 0, int component1 = 1, int component2 = 2);
143 
145 
151  void AddScalarVariable(const char* variableName, const char* arrayName, int component = 0);
152  void AddVectorVariable(const char* variableName, const char* arrayName, int component0 = 0,
153  int component1 = 1, int component2 = 2);
155 
157 
163  void AddCoordinateScalarVariable(const char* variableName, int component = 0);
165  const char* variableName, int component0 = 0, int component1 = 1, int component2 = 2);
167 
169 
175  vtkSetStringMacro(ResultArrayName);
176  vtkGetStringMacro(ResultArrayName);
178 
180 
184  vtkGetMacro(ResultArrayType, int);
185  vtkSetMacro(ResultArrayType, int);
187 
189 
195  vtkGetMacro(CoordinateResults, vtkTypeBool);
196  vtkSetMacro(CoordinateResults, vtkTypeBool);
197  vtkBooleanMacro(CoordinateResults, vtkTypeBool);
199 
201 
206  vtkGetMacro(ResultNormals, bool);
207  vtkSetMacro(ResultNormals, bool);
208  vtkBooleanMacro(ResultNormals, bool);
210 
212 
217  vtkGetMacro(ResultTCoords, bool);
218  vtkSetMacro(ResultTCoords, bool);
219  vtkBooleanMacro(ResultTCoords, bool);
221 
226 
227  static const int DEFAULT_ATTRIBUTE_TYPE = -1;
229 
235  vtkSetMacro(AttributeType, int);
236  vtkGetMacro(AttributeType, int);
237  void SetAttributeTypeToDefault() { this->SetAttributeType(DEFAULT_ATTRIBUTE_TYPE); }
238  void SetAttributeTypeToPointData() { this->SetAttributeType(vtkDataObject::POINT); }
239  void SetAttributeTypeToCellData() { this->SetAttributeType(vtkDataObject::CELL); }
240  void SetAttributeTypeToEdgeData() { this->SetAttributeType(vtkDataObject::EDGE); }
241  void SetAttributeTypeToVertexData() { this->SetAttributeType(vtkDataObject::VERTEX); }
242  void SetAttributeTypeToRowData() { this->SetAttributeType(vtkDataObject::ROW); }
244 
249 
253  virtual void RemoveScalarVariables();
254 
258  virtual void RemoveVectorVariables();
259 
264 
269 
271 
274  const std::vector<std::string>& GetScalarArrayNames() { return this->ScalarArrayNames; }
276  const std::vector<std::string>& GetVectorArrayNames() { return this->VectorArrayNames; }
278  const std::vector<std::string>& GetScalarVariableNames() { return this->ScalarVariableNames; }
280  const std::vector<std::string>& GetVectorVariableNames() { return this->VectorVariableNames; }
282  const std::vector<int>& GetSelectedScalarComponents() { return this->SelectedScalarComponents; }
284  const std::vector<vtkTuple<int, 3>>& GetSelectedVectorComponents()
285  {
286  return this->SelectedVectorComponents;
287  }
289  int GetNumberOfScalarArrays() { return static_cast<int>(this->ScalarArrayNames.size()); }
290  int GetNumberOfVectorArrays() { return static_cast<int>(this->VectorArrayNames.size()); }
292 
294 
300  vtkSetMacro(ReplaceInvalidValues, vtkTypeBool);
301  vtkGetMacro(ReplaceInvalidValues, vtkTypeBool);
302  vtkBooleanMacro(ReplaceInvalidValues, vtkTypeBool);
303  vtkSetMacro(ReplacementValue, double);
304  vtkGetMacro(ReplacementValue, double);
306 
308 
313  vtkSetMacro(IgnoreMissingArrays, bool);
314  vtkGetMacro(IgnoreMissingArrays, bool);
315  vtkBooleanMacro(IgnoreMissingArrays, bool);
317 
322  {
323  FunctionParser, // vtkFunctionParser
324  ExprTkFunctionParser, // vtkExprTkFunctionParser
325  NumberOfFunctionParserTypes
326  };
327 
329 
333  vtkSetEnumMacro(FunctionParserType, FunctionParserTypes);
335  {
336  this->FunctionParserType = FunctionParserTypes::FunctionParser;
337  this->Modified();
338  }
340  {
341  this->FunctionParserType = FunctionParserTypes::ExprTkFunctionParser;
342  this->Modified();
343  }
344  vtkGetEnumMacro(FunctionParserType, FunctionParserTypes);
346 
352 
353 protected:
356 
358 
360 
365 
373  static std::string CheckValidVariableName(const char* variableName);
374 
376 
377  char* Function;
379  std::vector<std::string> ScalarArrayNames;
380  std::vector<std::string> VectorArrayNames;
381  std::vector<std::string> ScalarVariableNames;
382  std::vector<std::string> VectorVariableNames;
384  std::vector<int> SelectedScalarComponents;
385  std::vector<vtkTuple<int, 3>> SelectedVectorComponents;
386 
390 
394  std::vector<std::string> CoordinateScalarVariableNames;
395  std::vector<std::string> CoordinateVectorVariableNames;
397  std::vector<vtkTuple<int, 3>> SelectedCoordinateVectorComponents;
398 
400 
401 private:
402  vtkArrayCalculator(const vtkArrayCalculator&) = delete;
403  void operator=(const vtkArrayCalculator&) = delete;
404 
405  // Do the bulk of the work
406  template <typename TFunctionParser>
407  int ProcessDataObject(vtkDataObject* input, vtkDataObject* output);
408 };
409 
410 #endif
vtkArrayCalculator::SetAttributeTypeToDefault
void SetAttributeTypeToDefault()
Control which AttributeType the filter operates on (point data or cell data for vtkDataSets).
Definition: vtkArrayCalculator.h:237
vtkArrayCalculator::New
static vtkArrayCalculator * New()
vtkArrayCalculator::ResultTCoords
bool ResultTCoords
Definition: vtkArrayCalculator.h:393
vtkDataObject::POINT
@ POINT
Definition: vtkDataObject.h:374
vtkArrayCalculator::GetSelectedScalarComponents
const std::vector< int > & GetSelectedScalarComponents()
Methods to get information about the current variables.
Definition: vtkArrayCalculator.h:282
vtkArrayCalculator::GetNumberOfVectorArrays
int GetNumberOfVectorArrays()
Methods to get information about the current variables.
Definition: vtkArrayCalculator.h:290
vtkArrayCalculator::ResultArrayType
int ResultArrayType
Definition: vtkArrayCalculator.h:399
vtkArrayCalculator::PrintSelf
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
vtkDataObject::CELL
@ CELL
Definition: vtkDataObject.h:375
vtkArrayCalculator
perform mathematical operations on data in field data arrays
Definition: vtkArrayCalculator.h:113
vtkArrayCalculator::ScalarVariableNames
std::vector< std::string > ScalarVariableNames
Definition: vtkArrayCalculator.h:381
vtkPassInputTypeAlgorithm.h
vtkX3D::component
@ component
Definition: vtkX3D.h:181
vtkArrayCalculator::ReplaceInvalidValues
vtkTypeBool ReplaceInvalidValues
Definition: vtkArrayCalculator.h:387
vtkArrayCalculator::GetVectorArrayNames
const std::vector< std::string > & GetVectorArrayNames()
Methods to get information about the current variables.
Definition: vtkArrayCalculator.h:276
vtkArrayCalculator::GetVectorArrayName
std::string GetVectorArrayName(int i)
Methods to get information about the current variables.
vtkInformationVector
Store zero or more vtkInformation instances.
Definition: vtkInformationVector.h:145
vtkArrayCalculator::AddVectorVariable
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.
vtkArrayCalculator::ResultNormals
bool ResultNormals
Definition: vtkArrayCalculator.h:392
vtkArrayCalculator::SetAttributeTypeToEdgeData
void SetAttributeTypeToEdgeData()
Control which AttributeType the filter operates on (point data or cell data for vtkDataSets).
Definition: vtkArrayCalculator.h:240
vtkArrayCalculator::CoordinateResults
vtkTypeBool CoordinateResults
Definition: vtkArrayCalculator.h:391
vtkArrayCalculator::GetScalarArrayName
std::string GetScalarArrayName(int i)
Methods to get information about the current variables.
vtkArrayCalculator::GetVectorVariableNames
const std::vector< std::string > & GetVectorVariableNames()
Methods to get information about the current variables.
Definition: vtkArrayCalculator.h:280
vtkObject::Modified
virtual void Modified()
Update the modification time for this object.
vtkArrayCalculator::SelectedScalarComponents
std::vector< int > SelectedScalarComponents
Definition: vtkArrayCalculator.h:384
vtkArrayCalculator::GetDataSetOutput
vtkDataSet * GetDataSetOutput()
Returns the output of the filter downcast to a vtkDataSet or nullptr if the cast fails.
vtkArrayCalculator::AddScalarArrayName
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...
vtkArrayCalculator::VectorVariableNames
std::vector< std::string > VectorVariableNames
Definition: vtkArrayCalculator.h:382
vtkArrayCalculator::GetAttributeTypeFromInput
int GetAttributeTypeFromInput(vtkDataObject *input)
Get the attribute type for the input.
vtkArrayCalculator::FunctionParserType
FunctionParserTypes FunctionParserType
Definition: vtkArrayCalculator.h:375
vtkArrayCalculator::RemoveScalarVariables
virtual void RemoveScalarVariables()
Remove all the scalar variable names and their associated array names.
vtkArrayCalculator::FunctionParserTypes
FunctionParserTypes
Enum that includes the types of parsers that can be used.
Definition: vtkArrayCalculator.h:322
vtkArrayCalculator::SetFunctionParserTypeToFunctionParser
void SetFunctionParserTypeToFunctionParser()
Set/Get the FunctionParser type that will be used.
Definition: vtkArrayCalculator.h:334
vtkArrayCalculator::RemoveVectorVariables
virtual void RemoveVectorVariables()
Remove all the scalar variable names and their associated array names.
vtkArrayCalculator::AddScalarVariable
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.
vtkArrayCalculator::GetScalarVariableName
std::string GetScalarVariableName(int i)
Methods to get information about the current variables.
vtkArrayCalculator::CheckValidVariableName
static std::string CheckValidVariableName(const char *variableName)
A variable name is valid if it's sanitized or enclosed in quotes.
vtkArrayCalculator::GetNumberOfScalarArrays
int GetNumberOfScalarArrays()
Methods to get information about the current variables.
Definition: vtkArrayCalculator.h:289
vtkArrayCalculator::RemoveCoordinateScalarVariables
virtual void RemoveCoordinateScalarVariables()
Remove all the coordinate variables.
vtkArrayCalculator::AttributeType
int AttributeType
Definition: vtkArrayCalculator.h:383
vtkDataObject::VERTEX
@ VERTEX
Definition: vtkDataObject.h:378
vtkArrayCalculator::SetAttributeTypeToRowData
void SetAttributeTypeToRowData()
Control which AttributeType the filter operates on (point data or cell data for vtkDataSets).
Definition: vtkArrayCalculator.h:242
vtkArrayCalculator::GetScalarArrayNames
const std::vector< std::string > & GetScalarArrayNames()
Methods to get information about the current variables.
Definition: vtkArrayCalculator.h:274
vtkIndent
a simple class to control print indentation
Definition: vtkIndent.h:113
vtkArrayCalculator::SetAttributeTypeToCellData
void SetAttributeTypeToCellData()
Control which AttributeType the filter operates on (point data or cell data for vtkDataSets).
Definition: vtkArrayCalculator.h:239
vtkArrayCalculator::VectorArrayNames
std::vector< std::string > VectorArrayNames
Definition: vtkArrayCalculator.h:380
vtkArrayCalculator::~vtkArrayCalculator
~vtkArrayCalculator() override
vtkArrayCalculator::AddVectorArrayName
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...
vtkArrayCalculator::GetVectorVariableName
std::string GetVectorVariableName(int i)
Methods to get information about the current variables.
vtkArrayCalculator::GetSelectedScalarComponent
int GetSelectedScalarComponent(int i)
Methods to get information about the current variables.
vtkDataObject::ROW
@ ROW
Definition: vtkDataObject.h:380
vtkArrayCalculator::ResultArrayName
char * ResultArrayName
Definition: vtkArrayCalculator.h:378
vtkArrayCalculator::SelectedCoordinateVectorComponents
std::vector< vtkTuple< int, 3 > > SelectedCoordinateVectorComponents
Definition: vtkArrayCalculator.h:397
vtkArrayCalculator::AddCoordinateVectorVariable
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.
vtkArrayCalculator::GetSelectedVectorComponents
vtkTuple< int, 3 > GetSelectedVectorComponents(int i)
Methods to get information about the current variables.
vtkArrayCalculator::vtkArrayCalculator
vtkArrayCalculator()
vtkArrayCalculator::CoordinateScalarVariableNames
std::vector< std::string > CoordinateScalarVariableNames
Definition: vtkArrayCalculator.h:394
vtkDataSet
abstract class to specify dataset behavior
Definition: vtkDataSet.h:166
vtkArrayCalculator::SetAttributeTypeToVertexData
void SetAttributeTypeToVertexData()
Control which AttributeType the filter operates on (point data or cell data for vtkDataSets).
Definition: vtkArrayCalculator.h:241
vtkInformation
Store vtkAlgorithm input/output information.
Definition: vtkInformation.h:183
vtkArrayCalculator::GetAttributeTypeAsString
const char * GetAttributeTypeAsString()
Returns a string representation of the calculator's AttributeType.
vtkArrayCalculator::RemoveCoordinateVectorVariables
virtual void RemoveCoordinateVectorVariables()
Remove all the coordinate variables.
vtkX3D::string
@ string
Definition: vtkX3D.h:496
vtkDataObject::EDGE
@ EDGE
Definition: vtkDataObject.h:379
vtkTuple.h
vtkArrayCalculator::ExprTkFunctionParser
@ ExprTkFunctionParser
Definition: vtkArrayCalculator.h:324
vtkArrayCalculator::SetFunctionParserTypeToExprTkFunctionParser
void SetFunctionParserTypeToExprTkFunctionParser()
Set/Get the FunctionParser type that will be used.
Definition: vtkArrayCalculator.h:339
vtkDataObject.h
vtkArrayCalculator::RequestData
int RequestData(vtkInformation *, vtkInformationVector **, vtkInformationVector *) override
This is called within ProcessRequest when a request asks the algorithm to do its work.
vtkArrayCalculator::RemoveAllVariables
void RemoveAllVariables()
Remove all the variable names and their associated array names.
vtkArrayCalculator::vtkGetEnumMacro
vtkGetEnumMacro(FunctionParserType, FunctionParserTypes)
Set/Get the FunctionParser type that will be used.
vtkArrayCalculator::AddCoordinateScalarVariable
void AddCoordinateScalarVariable(const char *variableName, int component=0)
Add a variable name, a corresponding array name, and which components of the array to use.
vtkArrayCalculator::GetSelectedVectorComponents
const std::vector< vtkTuple< int, 3 > > & GetSelectedVectorComponents()
Methods to get information about the current variables.
Definition: vtkArrayCalculator.h:284
vtkArrayCalculator::vtkSetEnumMacro
vtkSetEnumMacro(FunctionParserType, FunctionParserTypes)
Set/Get the FunctionParser type that will be used.
vtkArrayCalculator::FunctionParser
@ FunctionParser
Definition: vtkArrayCalculator.h:323
vtkArrayCalculator::SelectedCoordinateScalarComponents
std::vector< int > SelectedCoordinateScalarComponents
Definition: vtkArrayCalculator.h:396
vtkArrayCalculator::SetAttributeTypeToPointData
void SetAttributeTypeToPointData()
Control which AttributeType the filter operates on (point data or cell data for vtkDataSets).
Definition: vtkArrayCalculator.h:238
vtkArrayCalculator::Function
char * Function
Definition: vtkArrayCalculator.h:377
vtkTuple< int, 3 >
vtkArrayCalculator::ReplacementValue
double ReplacementValue
Definition: vtkArrayCalculator.h:388
vtkDataObject
general representation of visualization data
Definition: vtkDataObject.h:169
vtkArrayCalculator::CoordinateVectorVariableNames
std::vector< std::string > CoordinateVectorVariableNames
Definition: vtkArrayCalculator.h:395
vtkArrayCalculator::SelectedVectorComponents
std::vector< vtkTuple< int, 3 > > SelectedVectorComponents
Definition: vtkArrayCalculator.h:385
vtkTypeBool
int vtkTypeBool
Definition: vtkABI.h:69
vtkArrayCalculator::FillInputPortInformation
int FillInputPortInformation(int, vtkInformation *) override
Fill the input port information objects for this algorithm.
vtkPassInputTypeAlgorithm
Superclass for algorithms that produce output of the same type as input.
Definition: vtkPassInputTypeAlgorithm.h:52
vtkArrayCalculator::IgnoreMissingArrays
bool IgnoreMissingArrays
Definition: vtkArrayCalculator.h:389
vtkArrayCalculator::ScalarArrayNames
std::vector< std::string > ScalarArrayNames
Definition: vtkArrayCalculator.h:379
vtkArrayCalculator::GetScalarVariableNames
const std::vector< std::string > & GetScalarVariableNames()
Methods to get information about the current variables.
Definition: vtkArrayCalculator.h:278