VTK  9.3.20240419
vtkMultiThreshold.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
2 // SPDX-FileCopyrightText: Copyright (c) Sandia Corporation
3 // SPDX-License-Identifier: BSD-3-Clause
4 
120 #ifndef vtkMultiThreshold_h
121 #define vtkMultiThreshold_h
122 
123 #include "vtkFiltersGeneralModule.h" // For export macro
124 #include "vtkMath.h" // for Inf() and NegInf()
126 
127 #include <map> // for IntervalRules map
128 #include <set> // for UpdateDependents()
129 #include <string> // for holding array names in NormKey
130 #include <vector> // for lists of threshold rules
131 
132 VTK_ABI_NAMESPACE_BEGIN
133 class vtkCell;
134 class vtkCellData;
135 class vtkDataArray;
136 class vtkGenericCell;
137 class vtkPointSet;
138 class vtkUnstructuredGrid;
139 
140 class VTKFILTERSGENERAL_EXPORT vtkMultiThreshold : public vtkMultiBlockDataSetAlgorithm
141 {
142 public:
145  void PrintSelf(ostream& os, vtkIndent indent) override;
146 
148  enum Closure
149  {
150  OPEN = 0,
151  CLOSED = 1
152  };
154  enum Norm
155  {
156  LINFINITY_NORM = -3,
157  L2_NORM = -2,
158  L1_NORM = -1
159  };
163  {
164  AND,
165  OR,
166  XOR,
167  WOR,
168  NAND
169  };
170 
172 
224  int AddIntervalSet(double xmin, double xmax, int omin, int omax, int assoc, const char* arrayName,
225  int component, int allScalars);
226  int AddIntervalSet(double xmin, double xmax, int omin, int omax, int assoc, int attribType,
227  int component, int allScalars);
229 
231 
238  int AddLowpassIntervalSet(
239  double xmax, int assoc, const char* arrayName, int component, int allScalars);
240  int AddHighpassIntervalSet(
241  double xmin, int assoc, const char* arrayName, int component, int allScalars);
242  int AddBandpassIntervalSet(
243  double xmin, double xmax, int assoc, const char* arrayName, int component, int allScalars);
244  int AddNotchIntervalSet(
245  double xlo, double xhi, int assoc, const char* arrayName, int component, int allScalars);
247 
251  int AddBooleanSet(int operation, int numInputs, int* inputs);
252 
256  int OutputSet(int setId);
257 
261  void Reset();
262 
265  typedef double (*TupleNorm)(vtkDataArray* arr, vtkIdType tuple, int component);
266 
267  // NormKey must be able to use TupleNorm typedef:
268  class NormKey;
269 
270  // Interval must be able to use NormKey typedef:
271  class Interval;
272 
273  // Set needs to refer to boolean set pointers
274  class BooleanSet;
275 
277  class NormKey
278  {
279  public:
280  int Association; // vtkDataObject::FIELD_ASSOCIATION_POINTS or
281  // vtkDataObject::FIELD_ASSOCIATION_CELLS
282  int Type; // -1 => use Name, otherwise: vtkDataSetAttributes::{SCALARS, VECTORS, TENSORS,
283  // NORMALS, TCOORDS, GLOBALIDS}
284  std::string Name; // Either empty or (when ArrayType == -1) an input array name
285  int Component; // LINFINITY_NORM, L1_NORM, L2_NORM or an integer component number
286  int AllScalars; // For Association == vtkDataObject::FIELD_ASSOCIATION_POINTS, must all points
287  // be in the interval?
288  int InputArrayIndex; // The number passed to vtkAlgorithm::SetInputArrayToProcess()
289  TupleNorm NormFunction; // A function pointer to compute the norm (or fetcht the correct
290  // component) of a tuple.
291 
295  vtkIdType cellId, vtkCell* cell, vtkDataArray* array, double cellNorm[2]) const;
296 
299  bool operator<(const NormKey& other) const
300  {
301  if (this->Association < other.Association)
302  return true;
303  else if (this->Association > other.Association)
304  return false;
305 
306  if (this->Component < other.Component)
307  return true;
308  else if (this->Component > other.Component)
309  return false;
310 
311  if ((!this->AllScalars) && other.AllScalars)
312  return true;
313  else if (this->AllScalars && (!other.AllScalars))
314  return false;
315 
316  if (this->Type == -1)
317  {
318  if (other.Type == -1)
319  return this->Name < other.Name;
320  return true;
321  }
322  else
323  {
324  return this->Type < other.Type;
325  }
326  }
327  };
328 
333  class Set
334  {
335  public:
336  int Id;
337  int OutputId;
339 
342  Set() { this->OutputId = -1; }
344  virtual ~Set() = default;
346  virtual void PrintNodeName(ostream& os);
348  virtual void PrintNode(ostream& os) = 0;
350  virtual BooleanSet* GetBooleanSetPointer();
351  virtual Interval* GetIntervalPointer();
352  };
353 
355  class Interval : public Set
356  {
357  public:
359  double EndpointValues[2];
361  int EndpointClosures[2];
364 
370  int Match(double cellNorm[2]);
371 
372  ~Interval() override = default;
373  void PrintNode(ostream& os) override;
374  Interval* GetIntervalPointer() override;
375  };
376 
378  class BooleanSet : public Set
379  {
380  public:
382  int Operator;
384  std::vector<int> Inputs;
385 
387  BooleanSet(int sId, int op, int* inBegin, int* inEnd)
388  : Inputs(inBegin, inEnd)
389  {
390  this->Id = sId;
391  this->Operator = op;
392  }
393  ~BooleanSet() override = default;
394  void PrintNode(ostream& os) override;
395  BooleanSet* GetBooleanSetPointer() override;
396  };
397 
398 protected:
400  ~vtkMultiThreshold() override;
401 
416  enum Ruling
417  {
418  INCONCLUSIVE = -1,
419  INCLUDE = -2,
420  EXCLUDE = -3
421  };
422 
427 
434 
441 
446 
448  typedef std::vector<Interval*> IntervalList;
450  typedef std::map<NormKey, IntervalList> RuleMap;
451 
452  typedef std::vector<int> TruthTreeValues;
453  typedef std::vector<TruthTreeValues> TruthTree;
454 
459 
465  std::vector<Set*> Sets;
466 
474 
478  void UpdateDependents(int id, std::set<int>& unresolvedOutputs, TruthTreeValues& setStates,
479  vtkCellData* inCellData, vtkIdType inCell, vtkGenericCell* cell,
480  std::vector<vtkUnstructuredGrid*>& outv);
481 
485  int AddIntervalSet(NormKey& nk, double xmin, double xmax, int omin, int omax);
486 
490  void PrintGraph(ostream& os);
491 
493  void operator=(const vtkMultiThreshold&) = delete;
494 };
495 
497  double xmax, int assoc, const char* arrayName, int component, int allScalars)
498 {
499  return this->AddIntervalSet(
500  vtkMath::NegInf(), xmax, CLOSED, CLOSED, assoc, arrayName, component, allScalars);
501 }
502 
504  double xmin, int assoc, const char* arrayName, int component, int allScalars)
505 {
506  return this->AddIntervalSet(
507  xmin, vtkMath::Inf(), CLOSED, CLOSED, assoc, arrayName, component, allScalars);
508 }
509 
511  double xmin, double xmax, int assoc, const char* arrayName, int component, int allScalars)
512 {
513  return this->AddIntervalSet(xmin, xmax, CLOSED, CLOSED, assoc, arrayName, component, allScalars);
514 }
515 
517  double xlo, double xhi, int assoc, const char* arrayName, int component, int allScalars)
518 {
519  int band =
520  this->AddIntervalSet(xlo, xhi, CLOSED, CLOSED, assoc, arrayName, component, allScalars);
521  if (band < 0)
522  {
523  return -1;
524  }
525  return this->AddBooleanSet(NAND, 1, &band);
526 }
527 
529 {
530  return nullptr;
531 }
532 
534 {
535  return nullptr;
536 }
537 
539 {
540  return this;
541 }
542 
544 {
545  return this;
546 }
547 
548 VTK_ABI_NAMESPACE_END
549 #endif // vtkMultiThreshold_h
represent and manipulate cell attribute data
Definition: vtkCellData.h:141
abstract class to specify cell behavior
Definition: vtkCell.h:130
abstract superclass for arrays of numeric data
Definition: vtkDataArray.h:155
provides thread-safe access to cells
a simple class to control print indentation
Definition: vtkIndent.h:108
Store zero or more vtkInformation instances.
Store vtkAlgorithm input/output information.
static double NegInf()
Special IEEE-754 number used to represent negative infinity.
static double Inf()
Special IEEE-754 number used to represent positive infinity.
Superclass for algorithms that produce only vtkMultiBlockDataSet as output.
A subset of a mesh represented as a boolean set operation.
int Operator
The boolean operation that will be performed on the inputs to obtain the output.
BooleanSet(int sId, int op, int *inBegin, int *inEnd)
Construct a new set with the given ID, operator, and inputs.
void PrintNode(ostream &os) override
Print a graphviz node name for use in an edge statement.
std::vector< int > Inputs
A list of input sets. These may be IntervalSets or BooleanSets.
~BooleanSet() override=default
BooleanSet * GetBooleanSetPointer() override
Avoid dynamic_casts. Subclasses must override.
A subset of a mesh represented by a range of acceptable attribute values.
void PrintNode(ostream &os) override
Print a graphviz node name for use in an edge statement.
~Interval() override=default
int Match(double cellNorm[2])
Does the specified range fall inside the interval? For cell-centered attributes, only cellNorm[0] is ...
NormKey Norm
This contains information about the attribute over which the interval is defined.
Interval * GetIntervalPointer() override
A class with comparison operator used to index input array norms used in threshold rules.
void ComputeNorm(vtkIdType cellId, vtkCell *cell, vtkDataArray *array, double cellNorm[2]) const
Compute the norm of a cell by calling NormFunction for all its points or for its single cell-centered...
bool operator<(const NormKey &other) const
A partial ordering of NormKey objects is required for them to serve as keys in the vtkMultiThreshold:...
A base class for representing threshold sets.
int OutputId
A unique identifier for this set.
virtual Interval * GetIntervalPointer()
virtual void PrintNodeName(ostream &os)
Print a graphviz node label statement (with fancy node name and shape).
virtual void PrintNode(ostream &os)=0
Print a graphviz node name for use in an edge statement.
virtual BooleanSet * GetBooleanSetPointer()
Avoid dynamic_casts. Subclasses must override.
Set()
The index of the output mesh that will hold this set or -1 if the set is not output.
virtual ~Set()=default
Virtual destructor since we have virtual members.
Threshold cells within multiple intervals.
~vtkMultiThreshold() override
TruthTree DependentSets
A list of boolean sets whose values depend on the given set.
int NumberOfOutputs
The number of output datasets.
vtkMultiThreshold(const vtkMultiThreshold &)=delete
void operator=(const vtkMultiThreshold &)=delete
Ruling
When an interval is evaluated, its value is used to update a truth table.
Norm
Norms that can be used to threshold vector attributes.
std::map< NormKey, IntervalList > RuleMap
A map describing the IntervalSets that share a common attribute and norm.
std::vector< Set * > Sets
A list of rules keyed by their unique integer ID.
std::vector< Interval * > IntervalList
A list of pointers to IntervalSets.
int NextArrayIndex
A variable used to store the next index to use when calling SetInputArrayToProcess.
RuleMap IntervalRules
A set of threshold rules sorted by the attribute+norm to which they are applied.
int AddBandpassIntervalSet(double xmin, double xmax, int assoc, const char *arrayName, int component, int allScalars)
These convenience members make it easy to insert closed intervals.
static vtkMultiThreshold * New()
std::vector< int > TruthTreeValues
void Reset()
Remove all the intervals currently defined.
int AddLowpassIntervalSet(double xmax, int assoc, const char *arrayName, int component, int allScalars)
These convenience members make it easy to insert closed intervals.
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
void PrintGraph(ostream &os)
Print out a graphviz-formatted text description of all the sets.
int RequestData(vtkInformation *, vtkInformationVector **, vtkInformationVector *) override
This function performs the actual thresholding.
int AddBooleanSet(int operation, int numInputs, int *inputs)
Create a new mesh subset using boolean operations on pre-existing sets.
int OutputSet(int setId)
Create an output mesh containing a boolean or interval subset of the input mesh.
void UpdateDependents(int id, std::set< int > &unresolvedOutputs, TruthTreeValues &setStates, vtkCellData *inCellData, vtkIdType inCell, vtkGenericCell *cell, std::vector< vtkUnstructuredGrid * > &outv)
Recursively update the setStates and unresolvedOutputs vectors based on this->DependentSets.
int AddIntervalSet(double xmin, double xmax, int omin, int omax, int assoc, int attribType, int component, int allScalars)
Add a mesh subset to be computed by thresholding an attribute of the input mesh.
int AddIntervalSet(double xmin, double xmax, int omin, int omax, int assoc, const char *arrayName, int component, int allScalars)
Add a mesh subset to be computed by thresholding an attribute of the input mesh.
int AddNotchIntervalSet(double xlo, double xhi, int assoc, const char *arrayName, int component, int allScalars)
These convenience members make it easy to insert closed intervals.
SetOperation
Operations that can be performed on sets to generate another set.
@ WOR
Include elements that belong to an odd number of input sets (a kind of "winding XOR")
@ XOR
Include an element if it belongs to exactly one input set.
@ NAND
Only include elements that don't belong to any input set.
@ AND
Only include an element if it belongs to all the input sets.
@ OR
Include an element if it belongs to any input set.
int AddHighpassIntervalSet(double xmin, int assoc, const char *arrayName, int component, int allScalars)
These convenience members make it easy to insert closed intervals.
Closure
Whether the endpoint value of an interval should be included or excluded.
@ CLOSED
Specify a closed interval.
int FillInputPortInformation(int port, vtkInformation *info) override
We accept any mesh that is descended from vtkPointSet.
std::vector< TruthTreeValues > TruthTree
int AddIntervalSet(NormKey &nk, double xmin, double xmax, int omin, int omax)
A utility method called by the public AddInterval members.
concrete class for storing a set of points
Definition: vtkPointSet.h:98
dataset represents arbitrary combinations of all possible cell types
@ component
Definition: vtkX3D.h:175
@ info
Definition: vtkX3D.h:376
@ port
Definition: vtkX3D.h:447
@ string
Definition: vtkX3D.h:490
int vtkIdType
Definition: vtkType.h:315