VTK  9.3.1
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 
91 #ifndef vtkMultiThreshold_h
92 #define vtkMultiThreshold_h
93 
94 #include "vtkFiltersGeneralModule.h" // For export macro
95 #include "vtkMath.h" // for Inf() and NegInf()
97 
98 #include <map> // for IntervalRules map
99 #include <set> // for UpdateDependents()
100 #include <string> // for holding array names in NormKey
101 #include <vector> // for lists of threshold rules
102 
103 VTK_ABI_NAMESPACE_BEGIN
104 class vtkCell;
105 class vtkCellData;
106 class vtkDataArray;
107 class vtkGenericCell;
108 class vtkPointSet;
109 class vtkUnstructuredGrid;
110 
111 class VTKFILTERSGENERAL_EXPORT vtkMultiThreshold : public vtkMultiBlockDataSetAlgorithm
112 {
113 public:
115  static vtkMultiThreshold* New();
116  void PrintSelf(ostream& os, vtkIndent indent) override;
117 
119  enum Closure
120  {
121  OPEN = 0,
122  CLOSED = 1
123  };
125  enum Norm
126  {
127  LINFINITY_NORM = -3,
128  L2_NORM = -2,
129  L1_NORM = -1
130  };
134  {
135  AND,
136  OR,
137  XOR,
138  WOR,
139  NAND
140  };
141 
143 
195  int AddIntervalSet(double xmin, double xmax, int omin, int omax, int assoc, const char* arrayName,
196  int component, int allScalars);
197  int AddIntervalSet(double xmin, double xmax, int omin, int omax, int assoc, int attribType,
198  int component, int allScalars);
200 
202 
209  int AddLowpassIntervalSet(
210  double xmax, int assoc, const char* arrayName, int component, int allScalars);
211  int AddHighpassIntervalSet(
212  double xmin, int assoc, const char* arrayName, int component, int allScalars);
213  int AddBandpassIntervalSet(
214  double xmin, double xmax, int assoc, const char* arrayName, int component, int allScalars);
215  int AddNotchIntervalSet(
216  double xlo, double xhi, int assoc, const char* arrayName, int component, int allScalars);
218 
222  int AddBooleanSet(int operation, int numInputs, int* inputs);
223 
227  int OutputSet(int setId);
228 
232  void Reset();
233 
236  typedef double (*TupleNorm)(vtkDataArray* arr, vtkIdType tuple, int component);
237 
238  // NormKey must be able to use TupleNorm typedef:
239  class NormKey;
240 
241  // Interval must be able to use NormKey typedef:
242  class Interval;
243 
244  // Set needs to refer to boolean set pointers
245  class BooleanSet;
246 
248  class NormKey
249  {
250  public:
251  int Association; // vtkDataObject::FIELD_ASSOCIATION_POINTS or
252  // vtkDataObject::FIELD_ASSOCIATION_CELLS
253  int Type; // -1 => use Name, otherwise: vtkDataSetAttributes::{SCALARS, VECTORS, TENSORS,
254  // NORMALS, TCOORDS, GLOBALIDS}
255  std::string Name; // Either empty or (when ArrayType == -1) an input array name
256  int Component; // LINFINITY_NORM, L1_NORM, L2_NORM or an integer component number
257  int AllScalars; // For Association == vtkDataObject::FIELD_ASSOCIATION_POINTS, must all points
258  // be in the interval?
259  int InputArrayIndex; // The number passed to vtkAlgorithm::SetInputArrayToProcess()
260  TupleNorm NormFunction; // A function pointer to compute the norm (or fetcht the correct
261  // component) of a tuple.
262 
265  void ComputeNorm(
266  vtkIdType cellId, vtkCell* cell, vtkDataArray* array, double cellNorm[2]) const;
267 
270  bool operator<(const NormKey& other) const
271  {
272  if (this->Association < other.Association)
273  return true;
274  else if (this->Association > other.Association)
275  return false;
276 
277  if (this->Component < other.Component)
278  return true;
279  else if (this->Component > other.Component)
280  return false;
281 
282  if ((!this->AllScalars) && other.AllScalars)
283  return true;
284  else if (this->AllScalars && (!other.AllScalars))
285  return false;
286 
287  if (this->Type == -1)
288  {
289  if (other.Type == -1)
290  return this->Name < other.Name;
291  return true;
292  }
293  else
294  {
295  return this->Type < other.Type;
296  }
297  }
298  };
299 
304  class Set
305  {
306  public:
307  int Id;
308  int OutputId;
309 
313  Set() { this->OutputId = -1; }
315  virtual ~Set() = default;
317  virtual void PrintNodeName(ostream& os);
319  virtual void PrintNode(ostream& os) = 0;
321  virtual BooleanSet* GetBooleanSetPointer();
322  virtual Interval* GetIntervalPointer();
323  };
324 
326  class Interval : public Set
327  {
328  public:
330  double EndpointValues[2];
332  int EndpointClosures[2];
335 
341  int Match(double cellNorm[2]);
342 
343  ~Interval() override = default;
344  void PrintNode(ostream& os) override;
345  Interval* GetIntervalPointer() override;
346  };
347 
349  class BooleanSet : public Set
350  {
351  public:
353  int Operator;
355  std::vector<int> Inputs;
356 
358  BooleanSet(int sId, int op, int* inBegin, int* inEnd)
359  : Inputs(inBegin, inEnd)
360  {
361  this->Id = sId;
362  this->Operator = op;
363  }
364  ~BooleanSet() override = default;
365  void PrintNode(ostream& os) override;
366  BooleanSet* GetBooleanSetPointer() override;
367  };
368 
369 protected:
371  ~vtkMultiThreshold() override;
372 
387  enum Ruling
388  {
389  INCONCLUSIVE = -1,
390  INCLUDE = -2,
391  EXCLUDE = -3
392  };
393 
398 
404  int FillInputPortInformation(int port, vtkInformation* info) override;
405 
412 
417 
419  typedef std::vector<Interval*> IntervalList;
421  typedef std::map<NormKey, IntervalList> RuleMap;
422 
423  typedef std::vector<int> TruthTreeValues;
424  typedef std::vector<TruthTreeValues> TruthTree;
425 
429  RuleMap IntervalRules;
430 
436  std::vector<Set*> Sets;
437 
444  TruthTree DependentSets;
445 
449  void UpdateDependents(int id, std::set<int>& unresolvedOutputs, TruthTreeValues& setStates,
450  vtkCellData* inCellData, vtkIdType inCell, vtkGenericCell* cell,
451  std::vector<vtkUnstructuredGrid*>& outv);
452 
456  int AddIntervalSet(NormKey& nk, double xmin, double xmax, int omin, int omax);
457 
461  void PrintGraph(ostream& os);
462 
463  vtkMultiThreshold(const vtkMultiThreshold&) = delete;
464  void operator=(const vtkMultiThreshold&) = delete;
465 };
466 
468  double xmax, int assoc, const char* arrayName, int component, int allScalars)
469 {
470  return this->AddIntervalSet(
471  vtkMath::NegInf(), xmax, CLOSED, CLOSED, assoc, arrayName, component, allScalars);
472 }
473 
475  double xmin, int assoc, const char* arrayName, int component, int allScalars)
476 {
477  return this->AddIntervalSet(
478  xmin, vtkMath::Inf(), CLOSED, CLOSED, assoc, arrayName, component, allScalars);
479 }
480 
482  double xmin, double xmax, int assoc, const char* arrayName, int component, int allScalars)
483 {
484  return this->AddIntervalSet(xmin, xmax, CLOSED, CLOSED, assoc, arrayName, component, allScalars);
485 }
486 
488  double xlo, double xhi, int assoc, const char* arrayName, int component, int allScalars)
489 {
490  int band =
491  this->AddIntervalSet(xlo, xhi, CLOSED, CLOSED, assoc, arrayName, component, allScalars);
492  if (band < 0)
493  {
494  return -1;
495  }
496  return this->AddBooleanSet(NAND, 1, &band);
497 }
498 
500 {
501  return nullptr;
502 }
503 
505 {
506  return nullptr;
507 }
508 
510 {
511  return this;
512 }
513 
515 {
516  return this;
517 }
518 
519 VTK_ABI_NAMESPACE_END
520 #endif // vtkMultiThreshold_h
std::vector< Set * > Sets
A list of rules keyed by their unique integer ID.
int NextArrayIndex
A variable used to store the next index to use when calling SetInputArrayToProcess.
static double NegInf()
Special IEEE-754 number used to represent negative infinity.
Only include elements that don't belong to any input set.
A subset of a mesh represented by a range of acceptable attribute values.
bool operator<(const NormKey &other) const
A partial ordering of NormKey objects is required for them to serve as keys in the vtkMultiThreshold:...
int Operator
The boolean operation that will be performed on the inputs to obtain the output.
A subset of a mesh represented as a boolean set operation.
std::vector< TruthTreeValues > TruthTree
int AddBooleanSet(int operation, int numInputs, int *inputs)
Create a new mesh subset using boolean operations on pre-existing sets.
Store vtkAlgorithm input/output information.
TruthTree DependentSets
A list of boolean sets whose values depend on the given set.
static double Inf()
Special IEEE-754 number used to represent positive infinity.
represent and manipulate cell attribute data
Definition: vtkCellData.h:30
int OutputId
A unique identifier for this set.
virtual Interval * GetIntervalPointer()
Set()
The index of the output mesh that will hold this set or -1 if the set is not output.
BooleanSet(int sId, int op, int *inBegin, int *inEnd)
Construct a new set with the given ID, operator, and inputs.
std::map< NormKey, IntervalList > RuleMap
A map describing the IntervalSets that share a common attribute and norm.
NormKey Norm
This contains information about the attribute over which the interval is defined. ...
virtual BooleanSet * GetBooleanSetPointer()
Avoid dynamic_casts. Subclasses must override.
std::vector< Interval * > IntervalList
A list of pointers to IntervalSets.
concrete class for storing a set of points
Definition: vtkPointSet.h:58
Include elements that belong to an odd number of input sets (a kind of "winding XOR") ...
int vtkIdType
Definition: vtkType.h:315
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.
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.
Superclass for algorithms that produce only vtkMultiBlockDataSet as output.
virtual int RequestData(vtkInformation *, vtkInformationVector **, vtkInformationVector *)
This is called by the superclass.
provides thread-safe access to cells
Ruling
When an interval is evaluated, its value is used to update a truth table.
static vtkMultiBlockDataSetAlgorithm * New()
int AddLowpassIntervalSet(double xmax, int assoc, const char *arrayName, int component, int allScalars)
These convenience members make it easy to insert closed intervals.
abstract class to specify cell behavior
Definition: vtkCell.h:49
int AddHighpassIntervalSet(double xmin, int assoc, const char *arrayName, int component, int allScalars)
These convenience members make it easy to insert closed intervals.
a simple class to control print indentation
Definition: vtkIndent.h:28
Closure
Whether the endpoint value of an interval should be included or excluded.
std::vector< int > Inputs
A list of input sets. These may be IntervalSets or BooleanSets.
dataset represents arbitrary combinations of all possible cell types
abstract superclass for arrays of numeric data
Definition: vtkDataArray.h:44
Interval * GetIntervalPointer() override
Include an element if it belongs to exactly one input set.
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
int FillInputPortInformation(int port, vtkInformation *info) override
Fill the input port information objects for this algorithm.
Specify a closed interval.
int NumberOfOutputs
The number of output datasets.
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.
BooleanSet * GetBooleanSetPointer() override
Avoid dynamic_casts. Subclasses must override.
RuleMap IntervalRules
A set of threshold rules sorted by the attribute+norm to which they are applied.
Only include an element if it belongs to all the input sets.
SetOperation
Operations that can be performed on sets to generate another set.
Store zero or more vtkInformation instances.
A class with comparison operator used to index input array norms used in threshold rules...
Norm
Norms that can be used to threshold vector attributes.
Include an element if it belongs to any input set.
Threshold cells within multiple intervals.
A base class for representing threshold sets.
std::vector< int > TruthTreeValues